| 1 | /* |
|---|
| 2 | * (C) 2001 Clemson University and The University of Chicago |
|---|
| 3 | * |
|---|
| 4 | * See COPYING in top-level directory. |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #include <stdio.h> |
|---|
| 8 | |
|---|
| 9 | #include "pvfs2-sysint.h" |
|---|
| 10 | #include "pint-sysint-utils.h" |
|---|
| 11 | #include "trove.h" |
|---|
| 12 | #include "server-config.h" |
|---|
| 13 | #include "PINT-reqproto-encode.h" |
|---|
| 14 | #include "pint-cached-config.h" |
|---|
| 15 | #include "pvfs2-util.h" |
|---|
| 16 | #include "pvfs2-internal.h" |
|---|
| 17 | |
|---|
| 18 | #define MAX_NUM_FS 67 |
|---|
| 19 | |
|---|
| 20 | /* determines how many times to call '_get_next_meta' */ |
|---|
| 21 | #define NUM_META_SERVERS_TO_QUERY 3 |
|---|
| 22 | |
|---|
| 23 | /* determines how many i/o servers to request from '_get_next_io' */ |
|---|
| 24 | #define NUM_DATA_SERVERS_TO_QUERY 3 |
|---|
| 25 | |
|---|
| 26 | /* |
|---|
| 27 | determines which handles to test mappings on. the handles |
|---|
| 28 | placed below MUST be within a valid range of a filesystem |
|---|
| 29 | in the server's fs.conf for this test to pass. |
|---|
| 30 | */ |
|---|
| 31 | #define NUM_TEST_HANDLES 5 |
|---|
| 32 | static PVFS_handle test_handles[NUM_TEST_HANDLES] = {0}; |
|---|
| 33 | static int test_handle_index = 0; |
|---|
| 34 | |
|---|
| 35 | /* allocated in client-state-machine.c */ |
|---|
| 36 | extern job_context_id pint_client_sm_context; |
|---|
| 37 | |
|---|
| 38 | /* this is a test program that exercises the cached_config interface and |
|---|
| 39 | * demonstrates how to use it. |
|---|
| 40 | */ |
|---|
| 41 | int main(int argc, char **argv) |
|---|
| 42 | { |
|---|
| 43 | int i = 0, j = 0, k = 0, n = 0, m = 0, num_file_systems = 0; |
|---|
| 44 | const PVFS_util_tab* tab; |
|---|
| 45 | struct server_configuration_s server_config; |
|---|
| 46 | PINT_llist *cur = NULL; |
|---|
| 47 | struct filesystem_configuration_s *cur_fs = NULL; |
|---|
| 48 | int fs_ids[MAX_NUM_FS] = {0}; |
|---|
| 49 | int num_meta_servers = 0, num_data_servers = 0; |
|---|
| 50 | PVFS_BMI_addr_t addr, m_addr, d_addr[NUM_DATA_SERVERS_TO_QUERY]; |
|---|
| 51 | char server_name[PVFS_MAX_SERVER_ADDR_LEN] = {0}; |
|---|
| 52 | int test_handles_verified[NUM_TEST_HANDLES] = {0}; |
|---|
| 53 | PVFS_handle_extent_array meta_handle_extent_array; |
|---|
| 54 | PVFS_handle_extent_array data_handle_extent_array[ |
|---|
| 55 | NUM_DATA_SERVERS_TO_QUERY]; |
|---|
| 56 | |
|---|
| 57 | tab = PVFS_util_parse_pvfstab(NULL); |
|---|
| 58 | if(!tab) |
|---|
| 59 | { |
|---|
| 60 | fprintf(stderr, "PVFS_util_parse_pvfstab failure.\n"); |
|---|
| 61 | return(-1); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | if (BMI_initialize("bmi_tcp",NULL,0)) |
|---|
| 65 | { |
|---|
| 66 | fprintf(stderr, "BMI_initialize failure.\n"); |
|---|
| 67 | return(-1); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | if (PINT_encode_initialize()) |
|---|
| 71 | { |
|---|
| 72 | fprintf(stderr, "PINT_encoded_initialize failure.\n"); |
|---|
| 73 | return(-1); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | if (job_initialize(0)) |
|---|
| 77 | { |
|---|
| 78 | fprintf(stderr, "job_initialize failure.\n"); |
|---|
| 79 | return(-1); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | if (job_open_context(&pint_client_sm_context)) |
|---|
| 83 | { |
|---|
| 84 | fprintf(stderr, "job_open_context failure.\n"); |
|---|
| 85 | return(-1); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | if (PINT_cached_config_initialize()) |
|---|
| 89 | { |
|---|
| 90 | fprintf(stderr, "PINT_cached_config_initialize() failure.\n"); |
|---|
| 91 | return(-1); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | memset(&server_config,0,sizeof(struct server_configuration_s)); |
|---|
| 95 | for(i=0; i<tab->mntent_count; i++) |
|---|
| 96 | { |
|---|
| 97 | if (PINT_server_get_config(&server_config, &(tab->mntent_array[i]), NULL)) |
|---|
| 98 | { |
|---|
| 99 | fprintf(stderr, "PINT_server_get_config failure.\n"); |
|---|
| 100 | return(-1); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | cur = server_config.file_systems; |
|---|
| 105 | while(cur) |
|---|
| 106 | { |
|---|
| 107 | cur_fs = PINT_llist_head(cur); |
|---|
| 108 | if (!cur_fs) |
|---|
| 109 | { |
|---|
| 110 | break; |
|---|
| 111 | } |
|---|
| 112 | printf("Loading mappings of filesystem %s\n", |
|---|
| 113 | cur_fs->file_system_name); |
|---|
| 114 | if (PINT_cached_config_handle_load_mapping(cur_fs)) |
|---|
| 115 | { |
|---|
| 116 | fprintf(stderr, "PINT_handle_load_mapping failure.\n"); |
|---|
| 117 | return(-1); |
|---|
| 118 | } |
|---|
| 119 | fs_ids[i++] = (int)cur_fs->coll_id; |
|---|
| 120 | cur = PINT_llist_next(cur); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | num_file_systems = PINT_llist_count(server_config.file_systems); |
|---|
| 124 | for(i = 0; i < num_file_systems; i++) |
|---|
| 125 | { |
|---|
| 126 | printf("\nOUTPUT OF TEST (filesystem ID is %d):\n",fs_ids[i]); |
|---|
| 127 | printf("***************************************\n"); |
|---|
| 128 | |
|---|
| 129 | if (PINT_cached_config_get_num_meta(fs_ids[i],&num_meta_servers)) |
|---|
| 130 | { |
|---|
| 131 | fprintf(stderr, "PINT_cached_config_get_num_meta failure.\n"); |
|---|
| 132 | return(-1); |
|---|
| 133 | } |
|---|
| 134 | else |
|---|
| 135 | { |
|---|
| 136 | printf("\nNumber of meta servers available: %d\n", |
|---|
| 137 | num_meta_servers); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | if (PINT_cached_config_get_num_io(fs_ids[i],&num_data_servers)) |
|---|
| 141 | { |
|---|
| 142 | fprintf(stderr, "PINT_cached_config_get_num_io failure.\n"); |
|---|
| 143 | return(-1); |
|---|
| 144 | } |
|---|
| 145 | else |
|---|
| 146 | { |
|---|
| 147 | printf("Number of I/O servers available: %d\n", |
|---|
| 148 | num_data_servers); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | printf("\n"); |
|---|
| 152 | for(j = 0; j < NUM_META_SERVERS_TO_QUERY; j++) |
|---|
| 153 | { |
|---|
| 154 | if (PINT_cached_config_get_next_meta( |
|---|
| 155 | fs_ids[i], &m_addr, &meta_handle_extent_array)) |
|---|
| 156 | { |
|---|
| 157 | fprintf(stderr, "PINT_cached_config_get_next_meta failure.\n"); |
|---|
| 158 | return(-1); |
|---|
| 159 | } |
|---|
| 160 | else |
|---|
| 161 | { |
|---|
| 162 | printf("\nNext meta server address : %lu (%d meta ranges)\n", |
|---|
| 163 | (long)m_addr, meta_handle_extent_array.extent_count); |
|---|
| 164 | for(n = 0; n < meta_handle_extent_array.extent_count; n++) |
|---|
| 165 | { |
|---|
| 166 | printf("Meta server %d handle range: %s-%s\n", j, |
|---|
| 167 | PVFS_handle_to_str(meta_handle_extent_array.extent_array[n].first), |
|---|
| 168 | PVFS_handle_to_str(meta_handle_extent_array.extent_array[n].last)); |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | if (PINT_cached_config_get_next_io( |
|---|
| 174 | fs_ids[i], NUM_DATA_SERVERS_TO_QUERY, |
|---|
| 175 | d_addr, data_handle_extent_array)) |
|---|
| 176 | { |
|---|
| 177 | fprintf(stderr, "PINT_cached_config_get_next_io failure.\n"); |
|---|
| 178 | return(-1); |
|---|
| 179 | } |
|---|
| 180 | else |
|---|
| 181 | { |
|---|
| 182 | printf("\nAsked for %d I/O servers and got the following:\n", |
|---|
| 183 | NUM_DATA_SERVERS_TO_QUERY); |
|---|
| 184 | for(j = 0; j < NUM_DATA_SERVERS_TO_QUERY; j++) |
|---|
| 185 | { |
|---|
| 186 | printf("\nI/O server %d address : %lu " |
|---|
| 187 | "(%d data ranges)\n",j,(long)d_addr[j], |
|---|
| 188 | data_handle_extent_array[j].extent_count); |
|---|
| 189 | for(n = 0; n < data_handle_extent_array[j].extent_count; n++) |
|---|
| 190 | { |
|---|
| 191 | printf("Data server %d handle range: %s-%s\n", n, |
|---|
| 192 | PVFS_handle_to_str(data_handle_extent_array[j].extent_array[n].first), |
|---|
| 193 | PVFS_handle_to_str(data_handle_extent_array[j].extent_array[n].last)); |
|---|
| 194 | /* get some contrived test handles */ |
|---|
| 195 | if (test_handle_index < NUM_TEST_HANDLES) |
|---|
| 196 | { |
|---|
| 197 | test_handles[test_handle_index++] = |
|---|
| 198 | data_handle_extent_array[j].extent_array[n].first; |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | printf("\n"); |
|---|
| 205 | for(j = 0; j < NUM_TEST_HANDLES; j++) |
|---|
| 206 | { |
|---|
| 207 | /* |
|---|
| 208 | make sure we can find the server name for the test handle, |
|---|
| 209 | regardless of which fs it's on |
|---|
| 210 | */ |
|---|
| 211 | for(m = 0; m < num_file_systems; m++) |
|---|
| 212 | { |
|---|
| 213 | if (PINT_cached_config_get_server_name( |
|---|
| 214 | server_name,PVFS_MAX_SERVER_ADDR_LEN, |
|---|
| 215 | test_handles[j],fs_ids[m]) == 0) |
|---|
| 216 | { |
|---|
| 217 | break; |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | if (m != num_file_systems) |
|---|
| 221 | { |
|---|
| 222 | printf("Retrieved name of server managing handle " |
|---|
| 223 | "%lld is %s\n",lld(test_handles[j]),server_name); |
|---|
| 224 | test_handles_verified[j]++; |
|---|
| 225 | } |
|---|
| 226 | else |
|---|
| 227 | { |
|---|
| 228 | printf("Error retrieving name of server managing handle " |
|---|
| 229 | "%lld!\n",lld(test_handles[j])); |
|---|
| 230 | } |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | printf("\n"); |
|---|
| 234 | for(j = 0; j < NUM_TEST_HANDLES; j++) |
|---|
| 235 | { |
|---|
| 236 | for(m = 0; m < num_file_systems; m++) |
|---|
| 237 | { |
|---|
| 238 | if (PINT_cached_config_map_to_server( |
|---|
| 239 | &addr,test_handles[j],fs_ids[m]) == 0) |
|---|
| 240 | { |
|---|
| 241 | continue; |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | if (m != num_file_systems) |
|---|
| 245 | { |
|---|
| 246 | fprintf(stderr, "PINT_cached_config_map_to_server failure.\n"); |
|---|
| 247 | } |
|---|
| 248 | else |
|---|
| 249 | { |
|---|
| 250 | /* |
|---|
| 251 | make sure the returned address is either a known |
|---|
| 252 | meta or data server address |
|---|
| 253 | */ |
|---|
| 254 | for(k = 0; k < NUM_TEST_HANDLES; k++) |
|---|
| 255 | { |
|---|
| 256 | if (d_addr[k] == addr) |
|---|
| 257 | { |
|---|
| 258 | break; |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | if ((k == NUM_TEST_HANDLES) && (m_addr != addr)) |
|---|
| 262 | { |
|---|
| 263 | printf("*** Failed to verify ability to map servers " |
|---|
| 264 | "to handles.\n"); |
|---|
| 265 | return(-1); |
|---|
| 266 | } |
|---|
| 267 | else |
|---|
| 268 | { |
|---|
| 269 | printf("Retrieved address of server managing handle " |
|---|
| 270 | "%lld is %lu\n",lld(test_handles[j]),(long)addr); |
|---|
| 271 | test_handles_verified[j]++; |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | printf("\n"); |
|---|
| 277 | for(j = 0; j < NUM_TEST_HANDLES; j++) |
|---|
| 278 | { |
|---|
| 279 | if (test_handles_verified[j] != 2) |
|---|
| 280 | { |
|---|
| 281 | break; |
|---|
| 282 | } |
|---|
| 283 | test_handles_verified[j] = 0; |
|---|
| 284 | } |
|---|
| 285 | if (j == NUM_TEST_HANDLES) |
|---|
| 286 | { |
|---|
| 287 | printf("Successfully verified ability to map servers to handles.\n"); |
|---|
| 288 | } |
|---|
| 289 | else |
|---|
| 290 | { |
|---|
| 291 | printf("** Failed to verify ability to map servers to handles.\n"); |
|---|
| 292 | printf("** Handle value %lld failed -- cannot be mapped.\n", |
|---|
| 293 | lld(j ? test_handles[j-1] : test_handles[j])); |
|---|
| 294 | return -1; |
|---|
| 295 | } |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | if (PINT_cached_config_finalize()) |
|---|
| 299 | { |
|---|
| 300 | fprintf(stderr, "PINT_cached_config_finalize() failure.\n"); |
|---|
| 301 | return(-1); |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | job_finalize(); |
|---|
| 305 | BMI_finalize(); |
|---|
| 306 | return(0); |
|---|
| 307 | } |
|---|