| 1 | /* |
|---|
| 2 | * (C) 2001 Clemson University and The University of Chicago |
|---|
| 3 | * |
|---|
| 4 | * See COPYING in top-level directory. |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | /* this is a simple test harness that operates on top of the flow |
|---|
| 8 | * interface |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | #include <errno.h> |
|---|
| 12 | #include <stdio.h> |
|---|
| 13 | #include <string.h> |
|---|
| 14 | #include <sys/time.h> |
|---|
| 15 | #include <unistd.h> |
|---|
| 16 | #include <time.h> |
|---|
| 17 | |
|---|
| 18 | #include "gossip.h" |
|---|
| 19 | #include "flow.h" |
|---|
| 20 | #include "flowproto-support.h" |
|---|
| 21 | #include "pint-distribution.h" |
|---|
| 22 | #include "pint-dist-utils.h" |
|---|
| 23 | #include "pvfs2-request.h" |
|---|
| 24 | |
|---|
| 25 | #include "trove.h" |
|---|
| 26 | #include "pvfs2-internal.h" |
|---|
| 27 | |
|---|
| 28 | static int block_on_flow( |
|---|
| 29 | flow_descriptor * flow_d); |
|---|
| 30 | static double Wtime( |
|---|
| 31 | void); |
|---|
| 32 | int path_lookup( |
|---|
| 33 | TROVE_coll_id coll_id, |
|---|
| 34 | TROVE_context_id trove_context, |
|---|
| 35 | char *path, |
|---|
| 36 | TROVE_handle * out_handle_p); |
|---|
| 37 | |
|---|
| 38 | enum |
|---|
| 39 | { |
|---|
| 40 | TEST_SIZE = 1024 * 1024 * 20, |
|---|
| 41 | SSPACE_SIZE = 64, |
|---|
| 42 | FS_SIZE = 64, |
|---|
| 43 | PATH_SIZE = 256, |
|---|
| 44 | FS_COLL_ID = 9, |
|---|
| 45 | ADMIN_COLL_ID = 10 |
|---|
| 46 | }; |
|---|
| 47 | |
|---|
| 48 | enum |
|---|
| 49 | { |
|---|
| 50 | TROVE_TEST_DIR = 1, |
|---|
| 51 | TROVE_TEST_FILE = 2, |
|---|
| 52 | TROVE_TEST_BSTREAM = 3 |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | char storage_space[SSPACE_SIZE] = "/tmp/pvfs2-test-space"; |
|---|
| 56 | char file_system[FS_SIZE] = "pvfs2-fs"; |
|---|
| 57 | char path_to_file[PATH_SIZE] = "/bar"; |
|---|
| 58 | TROVE_handle requested_file_handle = 4095; |
|---|
| 59 | |
|---|
| 60 | int main( |
|---|
| 61 | int argc, |
|---|
| 62 | char **argv) |
|---|
| 63 | { |
|---|
| 64 | int ret = -1; |
|---|
| 65 | int outcount = 0, count; |
|---|
| 66 | struct BMI_unexpected_info request_info; |
|---|
| 67 | flow_descriptor *flow_d = NULL; |
|---|
| 68 | double time1, time2; |
|---|
| 69 | int i; |
|---|
| 70 | PINT_Request *req; |
|---|
| 71 | char path_name[PATH_SIZE]; |
|---|
| 72 | TROVE_op_id op_id; |
|---|
| 73 | TROVE_coll_id coll_id; |
|---|
| 74 | TROVE_handle file_handle, parent_handle; |
|---|
| 75 | TROVE_ds_state state; |
|---|
| 76 | char *file_name; |
|---|
| 77 | TROVE_keyval_s key, val; |
|---|
| 78 | bmi_context_id context; |
|---|
| 79 | TROVE_context_id trove_context; |
|---|
| 80 | PVFS_handle_extent cur_extent; |
|---|
| 81 | PVFS_handle_extent_array extent_array; |
|---|
| 82 | |
|---|
| 83 | /*************************************************************/ |
|---|
| 84 | /* initialization stuff */ |
|---|
| 85 | |
|---|
| 86 | /* set debugging level */ |
|---|
| 87 | gossip_enable_stderr(); |
|---|
| 88 | gossip_set_debug_mask( |
|---|
| 89 | 0, (GOSSIP_FLOW_PROTO_DEBUG | GOSSIP_BMI_DEBUG_TCP)); |
|---|
| 90 | |
|---|
| 91 | /* Init dists */ |
|---|
| 92 | PINT_dist_initialize(NULL); |
|---|
| 93 | |
|---|
| 94 | /* start up BMI */ |
|---|
| 95 | ret = BMI_initialize("bmi_tcp", "tcp://NULL:3335", BMI_INIT_SERVER); |
|---|
| 96 | if (ret < 0) |
|---|
| 97 | { |
|---|
| 98 | fprintf(stderr, "BMI init failure.\n"); |
|---|
| 99 | return (-1); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | ret = BMI_open_context(&context); |
|---|
| 103 | if (ret < 0) |
|---|
| 104 | { |
|---|
| 105 | fprintf(stderr, "BMI_open_context() failure.\n"); |
|---|
| 106 | return (-1); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | ret = trove_initialize( |
|---|
| 110 | TROVE_METHOD_DBPF, NULL, storage_space, storage_space, 0); |
|---|
| 111 | if (ret < 0) |
|---|
| 112 | { |
|---|
| 113 | fprintf(stderr, "initialize failed: run trove-mkfs first.\n"); |
|---|
| 114 | return -1; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | /* initialize the flow interface */ |
|---|
| 118 | ret = PINT_flow_initialize("flowproto_multiqueue", 0); |
|---|
| 119 | if (ret < 0) |
|---|
| 120 | { |
|---|
| 121 | fprintf(stderr, "flow init failure.\n"); |
|---|
| 122 | return (-1); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | /* try to look up collection used to store file system */ |
|---|
| 126 | ret = trove_collection_lookup( |
|---|
| 127 | TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id); |
|---|
| 128 | if (ret < 0) |
|---|
| 129 | { |
|---|
| 130 | fprintf(stderr, "collection lookup failed.\n"); |
|---|
| 131 | return -1; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | ret = trove_open_context(coll_id, &trove_context); |
|---|
| 135 | if (ret < 0) |
|---|
| 136 | { |
|---|
| 137 | fprintf(stderr, "TROVE_open_context() failure.\n"); |
|---|
| 138 | return (-1); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | /* find the parent directory name */ |
|---|
| 142 | strcpy(path_name, path_to_file); |
|---|
| 143 | for (i = strlen(path_name); i >= 0; i--) |
|---|
| 144 | { |
|---|
| 145 | if (path_name[i] != '/') |
|---|
| 146 | path_name[i] = '\0'; |
|---|
| 147 | else |
|---|
| 148 | break; |
|---|
| 149 | } |
|---|
| 150 | file_name = path_to_file + strlen(path_name); |
|---|
| 151 | printf("path is %s\n", path_name); |
|---|
| 152 | printf("file is %s\n", file_name); |
|---|
| 153 | |
|---|
| 154 | /* find the parent directory handle */ |
|---|
| 155 | ret = path_lookup(coll_id, trove_context, path_name, &parent_handle); |
|---|
| 156 | if (ret < 0) |
|---|
| 157 | { |
|---|
| 158 | return -1; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | file_handle = 0; |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | cur_extent.first = cur_extent.last = requested_file_handle; |
|---|
| 165 | extent_array.extent_count = 1; |
|---|
| 166 | extent_array.extent_array = &cur_extent; |
|---|
| 167 | ret = trove_dspace_create(coll_id, |
|---|
| 168 | &extent_array, |
|---|
| 169 | &file_handle, |
|---|
| 170 | TROVE_TEST_FILE, |
|---|
| 171 | NULL, |
|---|
| 172 | TROVE_FORCE_REQUESTED_HANDLE, |
|---|
| 173 | NULL, trove_context, &op_id, NULL); |
|---|
| 174 | while (ret == 0) |
|---|
| 175 | ret = |
|---|
| 176 | trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL, |
|---|
| 177 | &state, TROVE_DEFAULT_TEST_TIMEOUT); |
|---|
| 178 | if (ret < 0) |
|---|
| 179 | { |
|---|
| 180 | fprintf(stderr, "dspace create failed.\n"); |
|---|
| 181 | return -1; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | /* TODO: set attributes of file? */ |
|---|
| 185 | |
|---|
| 186 | /* add new file name/handle pair to parent directory */ |
|---|
| 187 | key.buffer = file_name; |
|---|
| 188 | key.buffer_sz = strlen(file_name) + 1; |
|---|
| 189 | val.buffer = &file_handle; |
|---|
| 190 | val.buffer_sz = sizeof(file_handle); |
|---|
| 191 | ret = |
|---|
| 192 | trove_keyval_write(coll_id, parent_handle, &key, &val, 0, NULL, NULL, |
|---|
| 193 | trove_context, &op_id, NULL); |
|---|
| 194 | while (ret == 0) |
|---|
| 195 | ret = |
|---|
| 196 | trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL, |
|---|
| 197 | &state, TROVE_DEFAULT_TEST_TIMEOUT); |
|---|
| 198 | if (ret < 0) |
|---|
| 199 | { |
|---|
| 200 | fprintf(stderr, "keyval write failed.\n"); |
|---|
| 201 | return -1; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | /* wait for an initial communication via BMI */ |
|---|
| 206 | /* we don't give a crap about that message except that it tells us |
|---|
| 207 | * where to find the client |
|---|
| 208 | */ |
|---|
| 209 | do |
|---|
| 210 | { |
|---|
| 211 | ret = BMI_testunexpected(1, &outcount, &request_info, 10); |
|---|
| 212 | } while (ret == 0 && outcount == 0); |
|---|
| 213 | if (ret < 0 || request_info.error_code != 0) |
|---|
| 214 | { |
|---|
| 215 | fprintf(stderr, "waitunexpected failure.\n"); |
|---|
| 216 | return (-1); |
|---|
| 217 | } |
|---|
| 218 | BMI_unexpected_free(request_info.addr, request_info.buffer); |
|---|
| 219 | |
|---|
| 220 | /******************************************************/ |
|---|
| 221 | /* setup request/dist stuff */ |
|---|
| 222 | |
|---|
| 223 | /* request description */ |
|---|
| 224 | /* just want one contiguous region */ |
|---|
| 225 | ret = PVFS_Request_contiguous(TEST_SIZE, PVFS_BYTE, &req); |
|---|
| 226 | if (ret < 0) |
|---|
| 227 | { |
|---|
| 228 | fprintf(stderr, "PVFS_Request_contiguous() failure.\n"); |
|---|
| 229 | return (-1); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | /******************************************************/ |
|---|
| 234 | /* setup communicaton stuff */ |
|---|
| 235 | |
|---|
| 236 | /* create a flow descriptor */ |
|---|
| 237 | flow_d = PINT_flow_alloc(); |
|---|
| 238 | if (!flow_d) |
|---|
| 239 | { |
|---|
| 240 | fprintf(stderr, "flow_alloc failed.\n"); |
|---|
| 241 | return (-1); |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | /* file data */ |
|---|
| 245 | flow_d->file_data.fsize = TEST_SIZE; |
|---|
| 246 | flow_d->file_data.server_nr = 0; |
|---|
| 247 | flow_d->file_data.server_ct = 1; |
|---|
| 248 | flow_d->file_data.extend_flag = 1; |
|---|
| 249 | flow_d->file_data.dist = PINT_dist_create("basic_dist"); |
|---|
| 250 | if (!flow_d->file_data.dist) |
|---|
| 251 | { |
|---|
| 252 | fprintf(stderr, "Error: failed to create dist.\n"); |
|---|
| 253 | return (-1); |
|---|
| 254 | } |
|---|
| 255 | ret = PINT_dist_lookup(flow_d->file_data.dist); |
|---|
| 256 | if (ret != 0) |
|---|
| 257 | { |
|---|
| 258 | fprintf(stderr, "Error: failed to lookup dist.\n"); |
|---|
| 259 | return (-1); |
|---|
| 260 | } |
|---|
| 261 | flow_d->file_req = req; |
|---|
| 262 | flow_d->tag = 0; |
|---|
| 263 | flow_d->user_ptr = NULL; |
|---|
| 264 | flow_d->aggregate_size = TEST_SIZE; |
|---|
| 265 | |
|---|
| 266 | /* fill in flow details */ |
|---|
| 267 | flow_d->src.endpoint_id = BMI_ENDPOINT; |
|---|
| 268 | flow_d->src.u.bmi.address = request_info.addr; |
|---|
| 269 | flow_d->dest.endpoint_id = TROVE_ENDPOINT; |
|---|
| 270 | flow_d->dest.u.trove.handle = file_handle; |
|---|
| 271 | flow_d->dest.u.trove.coll_id = coll_id; |
|---|
| 272 | |
|---|
| 273 | /*************************************************** |
|---|
| 274 | * test bmi to file (analogous to a client side write) |
|---|
| 275 | */ |
|---|
| 276 | |
|---|
| 277 | time1 = Wtime(); |
|---|
| 278 | ret = block_on_flow(flow_d); |
|---|
| 279 | if (ret < 0) |
|---|
| 280 | { |
|---|
| 281 | return (-1); |
|---|
| 282 | } |
|---|
| 283 | time2 = Wtime(); |
|---|
| 284 | |
|---|
| 285 | #if 0 |
|---|
| 286 | printf("Server bw (recv): %f MB/sec\n", |
|---|
| 287 | ((TEST_SIZE) / ((time2 - time1) * 1000000.0))); |
|---|
| 288 | #endif |
|---|
| 289 | |
|---|
| 290 | /*******************************************************/ |
|---|
| 291 | /* final cleanup and output */ |
|---|
| 292 | |
|---|
| 293 | PINT_flow_free(flow_d); |
|---|
| 294 | |
|---|
| 295 | /* shut down flow interface */ |
|---|
| 296 | ret = PINT_flow_finalize(); |
|---|
| 297 | if (ret < 0) |
|---|
| 298 | { |
|---|
| 299 | fprintf(stderr, "flow finalize failure.\n"); |
|---|
| 300 | return (-1); |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | /* shut down BMI */ |
|---|
| 304 | BMI_close_context(context); |
|---|
| 305 | BMI_finalize(); |
|---|
| 306 | |
|---|
| 307 | trove_close_context(coll_id, trove_context); |
|---|
| 308 | trove_finalize(TROVE_METHOD_DBPF); |
|---|
| 309 | |
|---|
| 310 | gossip_disable(); |
|---|
| 311 | return (0); |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | static int done_flag = 0; |
|---|
| 315 | static void callback_fn(flow_descriptor* flow_d) |
|---|
| 316 | { |
|---|
| 317 | done_flag = 1; |
|---|
| 318 | return; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | static int block_on_flow( |
|---|
| 322 | flow_descriptor * flow_d) |
|---|
| 323 | { |
|---|
| 324 | int ret = -1; |
|---|
| 325 | struct timespec req = {0, 1000}; |
|---|
| 326 | |
|---|
| 327 | flow_d->callback = (void *)callback_fn; |
|---|
| 328 | ret = PINT_flow_post(flow_d); |
|---|
| 329 | if (ret == 1) |
|---|
| 330 | { |
|---|
| 331 | return (0); |
|---|
| 332 | } |
|---|
| 333 | if (ret < 0) |
|---|
| 334 | { |
|---|
| 335 | fprintf(stderr, "flow post failure.\n"); |
|---|
| 336 | return (ret); |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | while(!done_flag) |
|---|
| 340 | { |
|---|
| 341 | nanosleep(&req, NULL); |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | if (flow_d->state != FLOW_COMPLETE) |
|---|
| 345 | { |
|---|
| 346 | fprintf(stderr, "flow finished in error state: %d\n", flow_d->state); |
|---|
| 347 | return (-1); |
|---|
| 348 | } |
|---|
| 349 | return (0); |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | static double Wtime( |
|---|
| 353 | void) |
|---|
| 354 | { |
|---|
| 355 | struct timeval t; |
|---|
| 356 | |
|---|
| 357 | gettimeofday(&t, NULL); |
|---|
| 358 | return ((double) t.tv_sec + (double) t.tv_usec / 1000000); |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | int path_lookup( |
|---|
| 362 | TROVE_coll_id coll_id, |
|---|
| 363 | TROVE_context_id trove_context, |
|---|
| 364 | char *path, |
|---|
| 365 | TROVE_handle * out_handle_p) |
|---|
| 366 | { |
|---|
| 367 | int ret, count; |
|---|
| 368 | TROVE_ds_state state; |
|---|
| 369 | TROVE_keyval_s key, val; |
|---|
| 370 | TROVE_op_id op_id; |
|---|
| 371 | TROVE_handle handle; |
|---|
| 372 | |
|---|
| 373 | /* get root */ |
|---|
| 374 | key.buffer = ROOT_HANDLE_KEYSTR; |
|---|
| 375 | key.buffer_sz = ROOT_HANDLE_KEYLEN; |
|---|
| 376 | val.buffer = &handle; |
|---|
| 377 | val.buffer_sz = sizeof(handle); |
|---|
| 378 | |
|---|
| 379 | ret = trove_collection_geteattr(coll_id, &key, &val, 0, |
|---|
| 380 | NULL, trove_context, &op_id); |
|---|
| 381 | while (ret == 0) |
|---|
| 382 | ret = |
|---|
| 383 | trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL, |
|---|
| 384 | &state, TROVE_DEFAULT_TEST_TIMEOUT); |
|---|
| 385 | if (ret < 0) |
|---|
| 386 | { |
|---|
| 387 | fprintf(stderr, "collection geteattr (for root handle) failed.\n"); |
|---|
| 388 | return -1; |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | /* TODO: handle more than just a root handle! */ |
|---|
| 392 | |
|---|
| 393 | *out_handle_p = handle; |
|---|
| 394 | return 0; |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | /* |
|---|
| 398 | * Local variables: |
|---|
| 399 | * c-indent-level: 4 |
|---|
| 400 | * c-basic-offset: 4 |
|---|
| 401 | * End: |
|---|
| 402 | * |
|---|
| 403 | * vim: ts=8 sts=4 sw=4 expandtab |
|---|
| 404 | */ |
|---|