| 1 | /* |
|---|
| 2 | * Copyright (c) Acxiom Corporation, 2005 |
|---|
| 3 | * |
|---|
| 4 | * See COPYING in top-level directory |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | /** |
|---|
| 8 | * |
|---|
| 9 | * This file provides wrapper functions for things that are common across many |
|---|
| 10 | * of the test programs. Each call can execute via the kernel module or the |
|---|
| 11 | * PVFS2 API, depending on the use_pvfs2_lib flag. |
|---|
| 12 | * |
|---|
| 13 | * @{ |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | /** \file |
|---|
| 17 | * Declarations for the test-common interface. |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #ifndef __TEST_COMMON_H |
|---|
| 21 | #define __TEST_COMMON_H |
|---|
| 22 | |
|---|
| 23 | #include <sys/types.h> |
|---|
| 24 | #include <unistd.h> |
|---|
| 25 | #include <grp.h> |
|---|
| 26 | #include <pwd.h> |
|---|
| 27 | |
|---|
| 28 | #include <pvfs2.h> |
|---|
| 29 | |
|---|
| 30 | /** Encapsulates the file descriptor. PVFS2 uses file handles (64 bit integer). |
|---|
| 31 | * Key off the use_pvfs2_lib flag to determine which value to use for the file |
|---|
| 32 | * descriptor. |
|---|
| 33 | */ |
|---|
| 34 | struct file_ref |
|---|
| 35 | { |
|---|
| 36 | int fd; /**< Used for all VFS layer calls */ |
|---|
| 37 | PVFS_handle handle; /**< Used for all PVFS2 API calls */ |
|---|
| 38 | }; |
|---|
| 39 | |
|---|
| 40 | struct common_options |
|---|
| 41 | { |
|---|
| 42 | char * directory; /**< --directory argument |
|---|
| 43 | * Root directory for tests */ |
|---|
| 44 | int verbose; /**< --verbose option. |
|---|
| 45 | * Turns on verbose logging. Also turns on --print-results */ |
|---|
| 46 | int printResults; /**< --print-results option. |
|---|
| 47 | * Always print results of tests */ |
|---|
| 48 | int use_pvfs2_lib;/**< --use-lib option. |
|---|
| 49 | * Enables use of PVFS2 API. Defaults to zero */ |
|---|
| 50 | char * hostname; /**< --hostname option. |
|---|
| 51 | * PVFS2 metasever hostname. Defaults to NULL */ |
|---|
| 52 | char * fsname; /**< --fs-name option. |
|---|
| 53 | * PVFS2 filesystem. Defaults to pvfs2-fs */ |
|---|
| 54 | int port; /**< --port option. |
|---|
| 55 | * PVFS2 metaserver port. Defaults to 3334 */ |
|---|
| 56 | char * networkProto; /**< --network-proto option. |
|---|
| 57 | * PVFS2 network protocol. Defaults to "tcp" */ |
|---|
| 58 | char * exePath; /**< --exe-path option. |
|---|
| 59 | * Path location of PVFS2 utils. Defaults to NULL */ |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | #define TEST_COMMON_SUCCESS 0 /**< Generic success return code */ |
|---|
| 63 | #define TEST_COMMON_FAIL -1 /**< Generic failure return code */ |
|---|
| 64 | |
|---|
| 65 | int set_util_path(const char * utility_path); |
|---|
| 66 | |
|---|
| 67 | int create_pvfs2tab_file(char* pvfs2tab_name, |
|---|
| 68 | int len, |
|---|
| 69 | const int port, |
|---|
| 70 | const char* networkProto, |
|---|
| 71 | const char* hostname, |
|---|
| 72 | const char* fsname, |
|---|
| 73 | const char* fs_file); |
|---|
| 74 | |
|---|
| 75 | int destroy_pvfs2tab_file(const char* pvfs2tab_name); |
|---|
| 76 | |
|---|
| 77 | /* Definition of the print_error macro */ |
|---|
| 78 | #define print_error(format...) \ |
|---|
| 79 | fprintf(stderr, "----------------------------------------\n"); \ |
|---|
| 80 | fprintf(stderr, format); \ |
|---|
| 81 | fprintf(stderr, "\n"); \ |
|---|
| 82 | fprintf(stderr, "Function : %s\n", __FUNCTION__); \ |
|---|
| 83 | fprintf(stderr, "File : %s\n", __FILE__); \ |
|---|
| 84 | fprintf(stderr, "Line : %d\n", __LINE__); \ |
|---|
| 85 | fprintf(stderr, "----------------------------------------\n"); |
|---|
| 86 | |
|---|
| 87 | #if PVFS2_SIZEOF_VOIDP == 32 |
|---|
| 88 | # define llu(x) (x) |
|---|
| 89 | # define lld(x) (x) |
|---|
| 90 | # define SCANF_lld "%lld" |
|---|
| 91 | #elif PVFS2_SIZEOF_VOIDP == 64 |
|---|
| 92 | # define llu(x) (unsigned long long)(x) |
|---|
| 93 | # define lld(x) (long long)(x) |
|---|
| 94 | # define SCANF_lld "%ld" |
|---|
| 95 | #else |
|---|
| 96 | # error Unexpected sizeof(void*) |
|---|
| 97 | #endif |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | int initialize(const int use_pvfs2_lib, const int verbose); |
|---|
| 101 | |
|---|
| 102 | int is_pvfs2(const char * fileName, |
|---|
| 103 | PVFS_fs_id * cur_fs, |
|---|
| 104 | char * relativeName, |
|---|
| 105 | const int relativeNameSize, |
|---|
| 106 | const int use_pvfs2_lib, |
|---|
| 107 | const int verbose); |
|---|
| 108 | |
|---|
| 109 | int finalize(int use_pvfs2_lib); |
|---|
| 110 | |
|---|
| 111 | int close_file(struct file_ref *stFileRef, |
|---|
| 112 | const int use_pvfs2_lib, |
|---|
| 113 | const int verbose); |
|---|
| 114 | |
|---|
| 115 | int stat_file(const char * fileName, |
|---|
| 116 | struct stat * fileStats, |
|---|
| 117 | const int followLink, |
|---|
| 118 | const int use_pvfs2_lib, |
|---|
| 119 | const int verbose); |
|---|
| 120 | |
|---|
| 121 | int pvfs2_open(const char * fileName, |
|---|
| 122 | const int accessFlags, |
|---|
| 123 | const int mode, |
|---|
| 124 | const int verbose, |
|---|
| 125 | const int followLink, |
|---|
| 126 | struct file_ref * stFileRef); |
|---|
| 127 | |
|---|
| 128 | int pvfs2_create_file(const char * fileName, |
|---|
| 129 | const PVFS_fs_id fs_id, |
|---|
| 130 | const PVFS_credentials * credentials, |
|---|
| 131 | const int mode, |
|---|
| 132 | const int verbose, |
|---|
| 133 | struct file_ref * pstFileRef); |
|---|
| 134 | |
|---|
| 135 | int open_file(const char * fileName, |
|---|
| 136 | const int accessFlags, |
|---|
| 137 | const int mode, |
|---|
| 138 | const int use_pvfs2_lib, |
|---|
| 139 | const int verbose, |
|---|
| 140 | const int followLink, |
|---|
| 141 | struct file_ref * stFileRef); |
|---|
| 142 | |
|---|
| 143 | int create_directory(const char * directory, |
|---|
| 144 | const int mode, |
|---|
| 145 | const int use_pvfs2_lib, |
|---|
| 146 | const int verbose); |
|---|
| 147 | |
|---|
| 148 | int remove_directory(const char * directory, |
|---|
| 149 | const int use_pvfs2_lib, |
|---|
| 150 | const int verbose); |
|---|
| 151 | |
|---|
| 152 | int create_file(const char * fileName, |
|---|
| 153 | const int mode, |
|---|
| 154 | const int use_pvfs2_lib, |
|---|
| 155 | const int verbose); |
|---|
| 156 | |
|---|
| 157 | int remove_file(const char * fileName, |
|---|
| 158 | const int use_pvfs2_lib, |
|---|
| 159 | const int verbose); |
|---|
| 160 | |
|---|
| 161 | int remove_symlink(const char * linkName, |
|---|
| 162 | const int use_pvfs2_lib, |
|---|
| 163 | const int verbose); |
|---|
| 164 | |
|---|
| 165 | int change_mode(const char * fileName, |
|---|
| 166 | const int mode, |
|---|
| 167 | int* error_code, |
|---|
| 168 | const int use_pvfs2_lib, |
|---|
| 169 | const int verbose); |
|---|
| 170 | |
|---|
| 171 | int change_owner(const char * fileName, |
|---|
| 172 | const char * ownerName, |
|---|
| 173 | const uid_t owner_id, |
|---|
| 174 | const char * groupName, |
|---|
| 175 | const gid_t group_id, |
|---|
| 176 | const int use_pvfs2_lib, |
|---|
| 177 | const int verbose); |
|---|
| 178 | |
|---|
| 179 | int change_group(const char * fileName, |
|---|
| 180 | const uid_t group_id, |
|---|
| 181 | const int use_pvfs2_lib, |
|---|
| 182 | const int verbose); |
|---|
| 183 | |
|---|
| 184 | void print_stats(const struct stat stats, const int verbose); |
|---|
| 185 | |
|---|
| 186 | int lookup_parent(char * filename, |
|---|
| 187 | PVFS_fs_id fs_id, |
|---|
| 188 | PVFS_credentials * credentials, |
|---|
| 189 | PVFS_handle * handle, |
|---|
| 190 | int verbose); |
|---|
| 191 | |
|---|
| 192 | int get_base_dir(char * pathName, |
|---|
| 193 | char * baseDir, |
|---|
| 194 | int baseDirSize); |
|---|
| 195 | |
|---|
| 196 | int remove_base_dir(char * pathName, |
|---|
| 197 | char * baseDir, |
|---|
| 198 | int baseDirSize); |
|---|
| 199 | |
|---|
| 200 | int create_symlink(const char * linkName, |
|---|
| 201 | const char * linkTarget, |
|---|
| 202 | const int use_pvfs2_lib, |
|---|
| 203 | const int verbose); |
|---|
| 204 | |
|---|
| 205 | int parse_common_args(int argc, char** argv, struct common_options* opts); |
|---|
| 206 | |
|---|
| 207 | #endif /* __TEST_COMMON_H */ |
|---|
| 208 | |
|---|
| 209 | /* @} */ |
|---|
| 210 | |
|---|
| 211 | /* |
|---|
| 212 | * Local variables: |
|---|
| 213 | * c-indent-level: 4 |
|---|
| 214 | * c-basic-offset: 4 |
|---|
| 215 | * End: |
|---|
| 216 | * |
|---|
| 217 | * vim: ts=8 sts=4 sw=4 expandtab |
|---|
| 218 | */ |
|---|