int main(int argc, char **argv) { int ret = -1; int count; char *mybuffer, *verify_buffer; int i; char path_name[PATH_SIZE]; TROVE_op_id op_id; TROVE_coll_id coll_id; TROVE_handle file_handle, parent_handle; TROVE_ds_state state; char *file_name; TROVE_keyval_s key, val; TROVE_context_id trove_context = -1; char *mem_offset_array[2] = {0}; TROVE_size mem_size_array[2] = { 10*MB, 10*MB }; int mem_count = 2; TROVE_offset stream_offset_array[4] = {0, 5*MB, 10*MB, 15*MB}; TROVE_size stream_size_array[4] = { 5*MB, 5*MB, 5*MB, 5*MB }; int stream_count = 4; TROVE_size output_size; void *user_ptr_array[1] = { (char *) 13 }; int test_failed = 0; TROVE_extent cur_extent; TROVE_handle_extent_array extent_array; /*************************************************************/ /* initialization stuff */ ret = trove_initialize( TROVE_METHOD_DBPF, NULL, storage_space, storage_space, 0); if (ret < 0) { fprintf(stderr, "initialize failed: run trove-mkfs first.\n"); return -1; } /* try to look up collection used to store file system */ ret = trove_collection_lookup( TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id); if (ret < 0) { fprintf(stderr, "collection lookup failed.\n"); return -1; } ret = trove_open_context(coll_id, &trove_context); if (ret < 0) { fprintf(stderr, "trove_open_context failed\n"); return -1; } /* find the parent directory name */ strcpy(path_name, path_to_file); for (i=strlen(path_name); i >= 0; i--) { if (path_name[i] != '/') path_name[i] = '\0'; else break; } file_name = path_to_file + strlen(path_name); printf("path is %s\n", path_name); printf("file is %s\n", file_name); /* find the parent directory handle */ ret = path_lookup(coll_id, trove_context, path_name, &parent_handle); if (ret < 0) { return -1; } file_handle = 0; cur_extent.first = cur_extent.last = requested_file_handle; extent_array.extent_count = 1; extent_array.extent_array = &cur_extent; ret = trove_dspace_create(coll_id, &extent_array, &file_handle, TROVE_TEST_FILE, NULL, TROVE_FORCE_REQUESTED_HANDLE, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "dspace create failed.\n"); return -1; } /* TODO: set attributes of file? */ /* add new file name/handle pair to parent directory */ key.buffer = file_name; key.buffer_sz = strlen(file_name) + 1; val.buffer = &file_handle; val.buffer_sz = sizeof(file_handle); ret = trove_keyval_write(coll_id, parent_handle, &key, &val, 0, NULL, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "keyval write failed.\n"); return -1; } /* memory buffer to xfer */ mybuffer = (char *)malloc(TEST_SIZE); if (!mybuffer) { fprintf(stderr, "mem.\n"); return(-1); } verify_buffer = (char *)malloc(TEST_SIZE); if (!verify_buffer) { fprintf(stderr, "mem.\n"); return(-1); } mem_offset_array[0] = mybuffer; mem_offset_array[1] = (mem_offset_array[0] + 10*MB); memset(mem_offset_array[0], 0xFE, 10*MB); memset(mem_offset_array[1], 0xFD, 10*MB); /********************************/ ret = trove_bstream_write_list(coll_id, parent_handle, mem_offset_array, mem_size_array, mem_count, stream_offset_array, stream_size_array, stream_count, &output_size, 0, /* flags */ NULL, /* vtag */ user_ptr_array, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "listio write failed\n"); return -1; } mem_offset_array[0] = verify_buffer; mem_offset_array[1] = (mem_offset_array[0] + 10*MB); memset(mem_offset_array[0], 0xDE, 10*MB); memset(mem_offset_array[1], 0xDD, 10*MB); /* should read this back out and verify here */ ret = trove_bstream_read_list(coll_id, parent_handle, mem_offset_array, mem_size_array, mem_count, stream_offset_array, stream_size_array, stream_count, &output_size, 0, /* flags */ NULL, /* vtag */ user_ptr_array, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "listio read failed\n"); return -1; } for(i = 0; i < TEST_SIZE; i++) { if (mybuffer[i] != verify_buffer[i]) { fprintf(stderr,"data mismatch at index %d (%x != %x)\n", i,mybuffer[i],verify_buffer[i]); test_failed = 1; break; } /* fprintf(stderr,"data match at index %d (%x == %x)\n", */ /* i,mybuffer[i],verify_buffer[i]); */ } free(mybuffer); free(verify_buffer); fprintf(stderr,"This bstream listio test %s\n", (test_failed ? "failed miserably" : "passed")); trove_close_context(coll_id, trove_context); trove_finalize(TROVE_METHOD_DBPF); return 0; }
int main( int argc, char **argv) { int ret = -1; int outcount = 0, count; struct BMI_unexpected_info request_info; flow_descriptor *flow_d = NULL; double time1, time2; int i; PINT_Request *req; char path_name[PATH_SIZE]; TROVE_op_id op_id; TROVE_coll_id coll_id; TROVE_handle file_handle, parent_handle; TROVE_ds_state state; char *file_name; TROVE_keyval_s key, val; bmi_context_id context; TROVE_context_id trove_context; PVFS_handle_extent cur_extent; PVFS_handle_extent_array extent_array; /*************************************************************/ /* initialization stuff */ /* set debugging level */ gossip_enable_stderr(); gossip_set_debug_mask(0, GOSSIP_FLOW_PROTO_DEBUG | GOSSIP_BMI_DEBUG_TCP ); /* start up BMI */ ret = BMI_initialize("bmi_tcp", "tcp://NULL:3335", BMI_INIT_SERVER); if (ret < 0) { fprintf(stderr, "BMI init failure.\n"); return (-1); } ret = BMI_open_context(&context); if (ret < 0) { fprintf(stderr, "BMI_open_context() failure.\n"); return (-1); } ret = trove_initialize( TROVE_METHOD_DBPF, NULL, storage_space, 0); if (ret < 0) { fprintf(stderr, "initialize failed: run trove-mkfs first.\n"); return -1; } /* initialize the flow interface. protocol specific */ ret = PINT_flow_initialize("flowproto_bmi_cache", 0); if (ret < 0) { fprintf(stderr, "flow init failure.\n"); return (-1); } /* try to look up collection used to store file system */ ret = trove_collection_lookup( TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id); if (ret < 0) { fprintf(stderr, "collection lookup failed.\n"); return -1; } ret = trove_open_context(coll_id, &trove_context); if (ret < 0) { fprintf(stderr, "TROVE_open_context() failure.\n"); return (-1); } /* find the parent directory name */ strcpy(path_name, path_to_file); for (i = strlen(path_name); i >= 0; i--) { if (path_name[i] != '/') path_name[i] = '\0'; else break; } file_name = path_to_file + strlen(path_name); printf("path is %s\n", path_name); printf("file is %s\n", file_name); /* find the parent directory handle */ ret = path_lookup(coll_id, trove_context, path_name, &parent_handle); if (ret < 0) { return -1; } file_handle = 0; cur_extent.first = cur_extent.last = requested_file_handle; extent_array.extent_count = 1; extent_array.extent_array = &cur_extent; ret = trove_dspace_create(coll_id, &extent_array, &file_handle, TROVE_TEST_FILE, NULL, TROVE_FORCE_REQUESTED_HANDLE, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "dspace create failed.\n"); return -1; } /* TODO: set attributes of file? */ /* add new file name/handle pair to parent directory */ key.buffer = file_name; key.buffer_sz = strlen(file_name) + 1; val.buffer = &file_handle; val.buffer_sz = sizeof(file_handle); ret = trove_keyval_write(coll_id, parent_handle, &key, &val, 0, NULL, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "keyval write failed.\n"); return -1; } /* wait for an initial communication via BMI */ /* we don't give a crap about that message except that it tells us * where to find the client */ do { ret = BMI_testunexpected(1, &outcount, &request_info, 10); } while (ret == 0 && outcount == 0); if (ret < 0 || request_info.error_code != 0) { fprintf(stderr, "waitunexpected failure.\n"); return (-1); } BMI_unexpected_free(request_info.addr, request_info.buffer); /******************************************************/ /* setup request/dist stuff */ /* request description */ /* just want one contiguous region */ ret = PVFS_Request_contiguous(TEST_SIZE, PVFS_BYTE, &req); if (ret < 0) { fprintf(stderr, "PVFS_Request_contiguous() failure.\n"); return (-1); } /******************************************************/ /* setup communicaton stuff */ /* create a flow descriptor */ flow_d = PINT_flow_alloc(); if (!flow_d) { fprintf(stderr, "flow_alloc failed.\n"); return (-1); } /* file data */ flow_d->file_data.fsize = TEST_SIZE; flow_d->file_data.server_nr = 0; flow_d->file_data.server_ct = 1; flow_d->file_data.extend_flag = 1; flow_d->file_data.dist = PINT_dist_create("basic_dist"); if (!flow_d->file_data.dist) { fprintf(stderr, "Error: failed to create dist.\n"); return (-1); } ret = PINT_dist_lookup(flow_d->file_data.dist); if (ret != 0) { fprintf(stderr, "Error: failed to lookup dist.\n"); return (-1); } flow_d->file_req = req; flow_d->tag = 0; flow_d->user_ptr = NULL; flow_d->aggregate_size = TEST_SIZE; /* fill in flow details */ flow_d->src.endpoint_id = BMI_ENDPOINT; flow_d->src.u.bmi.address = request_info.addr; flow_d->dest.endpoint_id = TROVE_ENDPOINT; flow_d->dest.u.trove.handle = file_handle; flow_d->dest.u.trove.coll_id = coll_id; /*************************************************** * test bmi to file (analogous to a client side write) */ time1 = Wtime(); ret = block_on_flow(flow_d); if (ret < 0) { return (-1); } time2 = Wtime(); #if 0 printf("Server bw (recv): %f MB/sec\n", ((TEST_SIZE) / ((time2 - time1) * 1000000.0))); #endif /*******************************************************/ /* final cleanup and output */ PINT_flow_free(flow_d); /* shut down flow interface */ ret = PINT_flow_finalize(); if (ret < 0) { fprintf(stderr, "flow finalize failure.\n"); return (-1); } /* shut down BMI */ BMI_close_context(context); BMI_finalize(); trove_close_context(coll_id, trove_context); trove_finalize(TROVE_METHOD_DBPF); gossip_disable(); return (0); }
int main(int argc, char **argv) { int ret, count, no_root_handle = 0; TROVE_op_id op_id; TROVE_coll_id coll_id; TROVE_handle root_handle; TROVE_ds_state state; TROVE_keyval_s key, val; TROVE_context_id trove_context = -1; ret = parse_args(argc, argv); if (ret < 0) { fprintf(stderr, "%s: error: argument parsing failed; aborting!\n", argv[0]); return -1; } /* initialize trove, verifying storage space exists */ ret = trove_initialize( TROVE_METHOD_DBPF, NULL, storage_space, 0); if (ret < 0) { fprintf(stderr, "%s: error: trove initialize failed; aborting!\n", argv[0]); return -1; } if (verbose) fprintf(stderr, "%s: info: initialized with storage space '%s'.\n", argv[0], storage_space); /* if no collection was specified, simply print out the collections and exit */ if (!got_collection) { ret = print_collections(); if (ret != 0) { fprintf(stderr, "%s: error: collection iterate failed; aborting!\n", argv[0]); trove_finalize(TROVE_METHOD_DBPF); return -1; } trove_finalize(TROVE_METHOD_DBPF); return 0; } /* a collection was specified. * - look up the collection * - find the root handle (or maybe show all the collection attribs?) * - print out information on the dataspaces in the collection */ ret = trove_collection_lookup(TROVE_METHOD_DBPF, collection, &coll_id, NULL, &op_id); if (ret != 1) { fprintf(stderr, "%s: error: collection lookup failed for collection '%s'; aborting!.\n", argv[0], collection); trove_finalize(TROVE_METHOD_DBPF); return -1; } if (verbose) fprintf(stderr, "%s: info: found collection '%s'.\n", argv[0], collection); ret = trove_open_context(coll_id, &trove_context); if (ret < 0) { fprintf(stderr, "trove_open_context failed\n"); return -1; } /* find root handle */ key.buffer = ROOT_HANDLE_KEYSTR; key.buffer_sz = ROOT_HANDLE_KEYLEN; val.buffer = &root_handle; val.buffer_sz = sizeof(root_handle); ret = trove_collection_geteattr(coll_id, &key, &val, 0, NULL, trove_context, &op_id); while (ret == 0) { ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); } if (ret != 1) { if (verbose) fprintf(stderr, "%s: warning: collection geteattr (for root handle) failed; aborting!\n", argv[0]); no_root_handle = 1; } /* TODO: NEED ITERATE FOR EATTRS? */ /* TODO: GET A COUNT OF DATASPACES? */ /* print basic stats on collection */ if (no_root_handle) { fprintf(stdout, "Storage space %s, collection %s (coll_id = %d, " "*** no root_handle found ***):\n", storage_space, collection, coll_id); } else { fprintf(stdout, "Storage space %s, collection %s (coll_id = %d, " "root_handle = 0x%08llx):\n", storage_space, collection, coll_id, llu(root_handle)); } if (got_dspace_handle) { ret = print_dspace(coll_id, dspace_handle, trove_context); } else { ret = print_dspaces(coll_id, root_handle, trove_context, no_root_handle); } trove_close_context(coll_id, trove_context); trove_finalize(TROVE_METHOD_DBPF); return 0; }
/** * Migrates an entire 0.0.1 DBPF collection * \return 0 on succes, -1 on failure */ static int translate_0_0_1( char* storage_space, /**< path to storage space */ char* old_coll_path, /**< path to old collection */ char* coll_name, /**< collection name */ TROVE_coll_id coll_id) /**< collection id in string format */ { int ret = -1; /* choose a handle range big enough to encompass anything pvfs2-genconfig * will create */ char handle_range[] = "4-64000000000"; TROVE_op_id op_id; TROVE_context_id trove_context = -1; char current_path[PATH_MAX]; /* rename old collection */ snprintf(current_path, PATH_MAX, "%s/%08x", storage_space, coll_id); if(access(current_path, F_OK) != 0) { fprintf(stderr, "Error: could not find old collection: %s\n" " fs: %s (%08x)\n", old_coll_path, coll_name, coll_id); return -1; } if(verbose) printf("VERBOSE Renaming old collection.\n"); ret = rename(current_path, old_coll_path); if(ret < 0) { perror("rename"); return(-1); } ret = remove_collection_entry(storage_space, coll_name); if(ret < 0) { fprintf(stderr, "Error: failed to remove collection entry: %s\n", coll_name); return(-1); } /* create new collection */ /* NOTE: deliberately not specifying root handle; it will get translated * later as a normal directory if applicable */ if(verbose) printf("VERBOSE Creating temporary collection to migrate to.\n"); ret = pvfs2_mkspace( storage_space, coll_name, coll_id, TROVE_HANDLE_NULL, handle_range, NULL, 1, 0); if(ret != 0) { fprintf(stderr, "Error: failed to create new collection.\n"); return(-1); } /* initialize distribution infrastructure */ /* NOTE: server config argument is not required here */ ret = PINT_dist_initialize(NULL); if (ret < 0) { PVFS_perror("PINT_dist_initialize", ret); if(verbose) printf("VERBOSE Destroying temporary collection.\n"); pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0); return(-1); } /* initialize trove and lookup collection */ ret = trove_initialize( TROVE_METHOD_DBPF, NULL, storage_space, 0); if (ret < 0) { PVFS_perror("trove_initialize", ret); if(verbose) printf("VERBOSE Destroying temporary collection.\n"); pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0); return(-1); } ret = trove_collection_lookup( TROVE_METHOD_DBPF, coll_name, &coll_id, NULL, &op_id); if (ret != 1) { fprintf(stderr, "Error: failed to lookup new collection.\n"); if(verbose) printf("VERBOSE Destroying temporary collection.\n"); pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0); return -1; } ret = trove_open_context(coll_id, &trove_context); if (ret < 0) { PVFS_perror("trove_open_context", ret); return(-1); } /* convert collection xattrs */ ret = translate_coll_eattr_0_0_1( old_coll_path, coll_id, coll_name, trove_context); if(ret < 0) { fprintf(stderr, "Error: failed to migrate collection extended attributes.\n"); if(verbose) printf("VERBOSE Destroying temporary collection.\n"); pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0); return(-1); } /* convert dspace attrs */ ret = translate_dspace_attr_0_0_1( old_coll_path, coll_id, coll_name, trove_context); if(ret < 0) { fprintf(stderr, "Error: failed to migrate dspace attributes.\n"); if(verbose) printf("VERBOSE Destroying temporary collection.\n"); pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0); return(-1); } /* convert dspace keyvals */ ret = translate_keyvals_0_0_1( old_coll_path, coll_id, coll_name, trove_context); if(ret < 0) { fprintf(stderr, "Error: failed to migrate keyvals.\n"); if(verbose) printf("VERBOSE Destroying temporary collection.\n"); pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0); return(-1); } /* at this point, we are done with the Trove API */ trove_close_context(coll_id, trove_context); trove_finalize(TROVE_METHOD_DBPF); PINT_dist_finalize(); /* convert bstreams */ ret = translate_bstreams_0_0_1( storage_space, old_coll_path, coll_id, coll_name, trove_context); if(ret < 0) { fprintf(stderr, "Error: failed to migrate bstreams.\n"); if(verbose) printf("VERBOSE Destroying temporary collection.\n"); pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0); return(-1); } printf("Migration successful.\n"); if(!opts.cleanup_set) { printf("===================================================================\n"); printf("IMPORTANT!!! IMPORTANT!!! IMPORTANT!!! IMPORTANT!!!\n"); printf("Please delete the old collection once you have tested and confirmed\n"); printf("the results of the migration.\n"); printf("Command: \"pvfs2-migrate-collection -cleanup <fs config> <server config>\"\n"); printf("===================================================================\n"); } return(0); }
int main(int argc, char **argv) { int ret = -1; int count; void* mybuffer; int i; char path_name[PATH_SIZE]; TROVE_op_id op_id; TROVE_coll_id coll_id; TROVE_handle file_handle, parent_handle; TROVE_ds_state state; char *file_name; TROVE_keyval_s key, val; TROVE_context_id trove_context = -1; char *mem_offset_array[1]; TROVE_size mem_size_array[1] = { 4*1048576 }; int mem_count = 1; TROVE_offset stream_offset_array[1] = { 0 }; TROVE_size stream_size_array[1] = { 4*1048576 }; int stream_count = 1; TROVE_size output_size; void *user_ptr_array[1] = { (char *) 13 }; TROVE_extent cur_extent; TROVE_handle_extent_array extent_array; /*************************************************************/ /* initialization stuff */ ret = trove_initialize( TROVE_METHOD_DBPF, NULL, storage_space, 0); if (ret < 0) { fprintf(stderr, "initialize failed: run trove-mkfs first.\n"); return -1; } /* try to look up collection used to store file system */ ret = trove_collection_lookup( TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id); if (ret < 0) { fprintf(stderr, "collection lookup failed.\n"); return -1; } ret = trove_open_context(coll_id, &trove_context); if (ret < 0) { fprintf(stderr, "trove_open_context failed\n"); return -1; } /* find the parent directory name */ strcpy(path_name, path_to_file); for (i=strlen(path_name); i >= 0; i--) { if (path_name[i] != '/') path_name[i] = '\0'; else break; } file_name = path_to_file + strlen(path_name); printf("path is %s\n", path_name); printf("file is %s\n", file_name); /* find the parent directory handle */ ret = path_lookup(coll_id, trove_context, path_name, &parent_handle); if (ret < 0) { return -1; } file_handle = 0; cur_extent.first = cur_extent.last = requested_file_handle; extent_array.extent_count = 1; extent_array.extent_array = &cur_extent; ret = trove_dspace_create(coll_id, &extent_array, &file_handle, TROVE_TEST_FILE, NULL, TROVE_FORCE_REQUESTED_HANDLE, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "dspace create failed.\n"); return -1; } /* TODO: set attributes of file? */ /* add new file name/handle pair to parent directory */ key.buffer = file_name; key.buffer_sz = strlen(file_name) + 1; val.buffer = &file_handle; val.buffer_sz = sizeof(file_handle); ret = trove_keyval_write(coll_id, parent_handle, &key, &val, 0, NULL, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "keyval write failed.\n"); return -1; } /* memory buffer to xfer */ mybuffer = (void*)malloc(TEST_SIZE); if(!mybuffer) { fprintf(stderr, "mem.\n"); return(-1); } memset(mybuffer, 0, TEST_SIZE); mem_offset_array[0] = mybuffer; /********************************/ ret = trove_bstream_write_list(coll_id, parent_handle, mem_offset_array, mem_size_array, mem_count, stream_offset_array, stream_size_array, stream_count, &output_size, 0, /* flags */ NULL, /* vtag */ user_ptr_array, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "listio write failed\n"); return -1; } trove_close_context(coll_id, trove_context); trove_finalize(TROVE_METHOD_DBPF); return 0; }
int main(int argc, char * argv[]) { PVFS_offset offarr[100]; PVFS_size sizearr[100]; cache_read_desc_t desc; cache_request_t request[100]; cache_reply_t reply[100]; NCAC_info_t info; int ret; int flag; TROVE_coll_id coll_id; TROVE_handle file_handle; TROVE_context_id trove_context; trove_init( &coll_id, &file_handle, &trove_context ); info.max_req_num = 1000; info.extsize = 32768; info.cachesize = 1048576; cache_init(&info); desc.coll_id = coll_id; desc.handle = file_handle; desc.context_id = trove_context; desc.buffer = 0; desc.len = 0; desc.stream_array_count=1; desc.stream_offset_array = offarr; desc.stream_size_array = sizearr; offarr[0] = 1024; sizearr[0] = 32768; ret = cache_read_post(&desc, &request[0], &reply[0], NULL); if (ret<0){ fprintf(stderr, "cache_read_post error\n"); }else{ fprintf(stderr, "cache_read_post ok: status: %d, cbufcnt=%d\n", request[0].status, reply[0].count); } #if 1 while ( 1 ){ ret = cache_req_test(&request[0], &flag, &reply[0], NULL); if (ret<0){ fprintf(stderr, "cache_req_test error\n"); }else{ if (flag){ fprintf(stderr, "cache_req_test ok: flag=%d, status: %d, cbufcnt=%d\n", flag, request[0].status, reply[0].count); break; } } } if (flag){ ret = cache_req_done(&request[0]); if (ret<0){ fprintf(stderr, "cache_req_done error\n"); }else fprintf(stderr, "cache_req_done ok---\n"); } #endif trove_close_context(coll_id, trove_context); trove_finalize(TROVE_METHOD_DBPF); return 0; }
int main(int argc, char **argv) { int ret, count, i, myuid, mygid; TROVE_op_id op_id; TROVE_coll_id coll_id; TROVE_handle file_handle, parent_handle; TROVE_ds_state state; TROVE_keyval_s key, val; TROVE_ds_attributes_s s_attr; char *file_name; char path_name[PATH_SIZE]; time_t mytime; TROVE_extent cur_extent; TROVE_handle_extent_array extent_array; TROVE_context_id trove_context = -1; ret = parse_args(argc, argv); if (ret < 0) { fprintf(stderr, "argument parsing failed.\n"); return -1; } ret = trove_initialize( TROVE_METHOD_DBPF, NULL, storage_space, 0); if (ret < 0) { fprintf(stderr, "initialize failed.\n"); return -1; } /* try to look up collection used to store file system */ ret = trove_collection_lookup( TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id); if (ret < 0) { fprintf(stderr, "collection lookup failed.\n"); return -1; } ret = trove_open_context(coll_id, &trove_context); if (ret < 0) { fprintf(stderr, "trove_open_context failed\n"); return -1; } myuid = getuid(); mygid = getgid(); mytime = time(NULL); /* find the parent directory name */ strcpy(path_name, path_to_file); for (i=strlen(path_name); i >= 0; i--) { if (path_name[i] != '/') path_name[i] = '\0'; else break; } file_name = path_to_file + strlen(path_name); #if 0 printf("path is %s\n", path_name); printf("file is %s\n", file_name); #endif /* find the parent directory handle */ ret = path_lookup(coll_id, path_name, &parent_handle); if (ret < 0) { return -1; } /* TODO: verify that this is in fact a directory! */ for (i=0; i < file_count; i++) { char tmp_file_name[PATH_SIZE]; file_handle = 0; cur_extent.first = cur_extent.last = requested_file_handle; extent_array.extent_count = 1; extent_array.extent_array = &cur_extent; ret = trove_dspace_create(coll_id, &extent_array, &file_handle, TROVE_TEST_FILE, NULL, TROVE_FORCE_REQUESTED_HANDLE, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "dspace create failed.\n"); return -1; } s_attr.fs_id = coll_id; /* for now */ s_attr.handle = file_handle; s_attr.type = TROVE_TEST_FILE; /* shouldn't need to fill this one in. */ s_attr.uid = myuid; s_attr.gid = mygid; s_attr.mode = 0755; s_attr.ctime = mytime; count = 1; ret = trove_dspace_setattr(coll_id, file_handle, &s_attr, 0 /* flags */, NULL /* user ptr */, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) return -1; /* add new file name/handle pair to parent directory */ snprintf(tmp_file_name, PATH_SIZE, "%s/file%d", path_name, i); key.buffer = tmp_file_name; key.buffer_sz = strlen(tmp_file_name) + 1; val.buffer = &file_handle; val.buffer_sz = sizeof(file_handle); ret = trove_keyval_write(coll_id, parent_handle, &key, &val, 0, NULL, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "keyval write failed.\n"); return -1; } } trove_close_context(coll_id, trove_context); trove_finalize(TROVE_METHOD_DBPF); return 0; }
int main(int argc, char **argv) { int ret, count, i, fd; TROVE_op_id op_id; TROVE_coll_id coll_id; TROVE_handle file_handle, parent_handle; TROVE_ds_state state; TROVE_keyval_s key, val; TROVE_ds_attributes_s s_attr; TROVE_size f_size; char *file_name; char path_name[PATH_SIZE]; char *buf; TROVE_context_id trove_context = -1; ret = parse_args(argc, argv); if (ret < 0) { fprintf(stderr, "argument parsing failed.\n"); return -1; } if (optind + 1 >= argc) return -1; strcpy(path_to_file, argv[optind]); strcpy(path_to_unix, argv[optind+1]); ret = trove_initialize( TROVE_METHOD_DBPF, NULL, storage_space, 0); if (ret < 0) { fprintf(stderr, "initialize failed.\n"); return -1; } /* try to look up collection used to store file system */ ret = trove_collection_lookup( TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id); if (ret < 0) { fprintf(stderr, "collection lookup failed.\n"); return -1; } ret = trove_open_context(coll_id, &trove_context); if (ret < 0) { fprintf(stderr, "trove_open_context failed\n"); return -1; } /* find the parent directory name */ strcpy(path_name, path_to_file); for (i=strlen(path_name); i >= 0; i--) { if (path_name[i] != '/') path_name[i] = '\0'; else break; } file_name = path_to_file + strlen(path_name); #if 0 printf("path is %s\n", path_name); printf("file is %s\n", file_name); #endif /* find the parent directory handle */ ret = path_lookup(coll_id, path_name, &parent_handle); if (ret < 0) { return -1; } /* add new file name/handle pair to parent directory */ key.buffer = file_name; key.buffer_sz = strlen(file_name) + 1; val.buffer = &file_handle; val.buffer_sz = sizeof(file_handle); ret = trove_keyval_read(coll_id, parent_handle, &key, &val, 0, NULL, NULL, trove_context, &op_id, NULL); count = 1; while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "keyval read failed.\n"); return -1; } ret = trove_dspace_getattr(coll_id, file_handle, &s_attr, 0 /* flags */, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) return -1; /* get a buffer */ buf = (char *) malloc((size_t) s_attr.u.datafile.b_size); if (buf == NULL) return -1; f_size = s_attr.u.datafile.b_size; /* read data from trove file */ ret = trove_bstream_read_at(coll_id, file_handle, buf, &f_size, 0, /* offset */ 0, /* flags */ NULL, /* vtag */ NULL, /* user ptr */ trove_context, &op_id, NULL); count = 1; while ( ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0 ) { fprintf(stderr, "bstream write failed.\n"); return -1; } /* open up the unix file */ fd = open(path_to_unix, O_RDWR | O_CREAT, 0644); if (fd < 0) { perror("open"); return -1; } /* write data to file */ write(fd, buf, f_size); close(fd); trove_close_context(coll_id, trove_context); trove_finalize(TROVE_METHOD_DBPF); #if 0 printf("created file %s (handle = %d)\n", file_name, (int) file_handle); #endif return 0; }
int main(int argc, char **argv) { int ret = -1; struct request_foo* req = NULL; struct ack_foo* ack = NULL; PVFS_BMI_addr_t server_addr; job_status_s status1; job_id_t tmp_id; job_context_id context; /* set debugging level */ gossip_enable_stderr(); gossip_set_debug_mask(0, 0); /* start the BMI interface */ ret = BMI_initialize("bmi_tcp", NULL, 0); if(ret < 0) { fprintf(stderr, "BMI_initialize failure.\n"); return(-1); } ret = trove_initialize( TROVE_METHOD_DBPF, NULL, "/tmp/pvfs2-test-space", 0); if(ret < 0) { fprintf(stderr, "trove_initialize failure.\n"); return(-1); } /* start the job interface */ ret = job_initialize(0); if(ret < 0) { fprintf(stderr, "job_initialize failure.\n"); return(-1); } ret = job_open_context(&context); if(ret < 0) { fprintf(stderr, "job_open_context() failure.\n"); return(-1); } /* lookup the server to get a BMI style address for it */ ret = BMI_addr_lookup(&server_addr, "tcp://localhost:3414"); if(ret < 0) { fprintf(stderr, "BMI_addr_lookup failure.\n"); return(-1); } /* allocate some buffers for the req and ack */ req = BMI_memalloc(server_addr, sizeof(struct request_foo), BMI_SEND); ack = BMI_memalloc(server_addr, sizeof(struct ack_foo), BMI_RECV); if(!ack || ! req) { fprintf(stderr, "BMI_memalloc failure.\n"); return(-1); } /* send a message */ ret = job_bmi_send(server_addr, req, sizeof(struct request_foo), 0, BMI_PRE_ALLOC, 1, NULL, 0, &status1, &tmp_id, context, JOB_TIMEOUT_INF, NULL); if(ret < 0) { fprintf(stderr, "job_bmi_send() failure.\n"); return(-1); } if(ret == 0) { int count = 0; ret = job_test(tmp_id, &count, NULL, &status1, -1, context); if(ret < 0) { fprintf(stderr, "job_test() failure.\n"); return(-1); } } /* check status */ if(status1.error_code != 0) { fprintf(stderr, "job failure.\n"); return(-1); } /* receive a message */ ret = job_bmi_recv(server_addr, ack, sizeof(struct ack_foo), 0, BMI_PRE_ALLOC, NULL, 0, &status1, &tmp_id, context, JOB_TIMEOUT_INF, NULL); if(ret < 0) { fprintf(stderr, "job_bmi_recv() failure.\n"); return(-1); } if(ret == 0) { int count = 0; ret = job_test(tmp_id, &count, NULL, &status1, -1, context); if(ret < 0) { fprintf(stderr, "job_test() failure.\n"); return(-1); } } /* check status */ if(status1.error_code != 0) { fprintf(stderr, "job failure.\n"); return(-1); } /* check the size */ if(status1.actual_size != sizeof(struct ack_foo)) { fprintf(stderr, "short recv.\n"); return(-1); } /* free memory buffers */ BMI_memfree(server_addr, req, sizeof(struct request_foo), BMI_SEND); BMI_memfree(server_addr, ack, sizeof(struct ack_foo), BMI_RECV); /* shut down the interfaces */ job_close_context(context); job_finalize(); BMI_finalize(); trove_finalize(TROVE_METHOD_DBPF); return(0); }
int main(int argc, char **argv) { int ret, count, i; char *file_name; char path_name[PATH_SIZE]; TROVE_op_id op_id; TROVE_coll_id coll_id; TROVE_handle file_handle, parent_handle; TROVE_ds_state state; TROVE_keyval_s key, val; TROVE_ds_attributes_s s_attr; TROVE_context_id trove_context = -1; ret = parse_args(argc, argv); if (ret < 0) { fprintf(stderr, "argument parsing failed.\n"); return -1; } ret = trove_initialize( TROVE_METHOD_DBPF, NULL, storage_space, storage_space, 0); if (ret < 0) { fprintf(stderr, "initialize failed.\n"); return -1; } /* try to look up collection used to store file system */ ret = trove_collection_lookup( TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id); if (ret < 0) { fprintf(stderr, "collection lookup failed.\n"); return -1; } ret = trove_open_context(coll_id, &trove_context); if (ret < 0) { fprintf(stderr, "trove_open_context failed\n"); return -1; } /* find the parent directory name */ strcpy(path_name, path_to_file); for (i=strlen(path_name); i >= 0; i--) { if (path_name[i] != '/') path_name[i] = '\0'; else break; } file_name = path_to_file + strlen(path_name); #if 0 printf("path is %s\n", path_name); printf("file is %s\n", file_name); #endif /* find the parent directory handle */ ret = path_lookup(coll_id, path_name, &parent_handle); if (ret < 0) { return -1; } /* TODO: make a is_dir function... maybe make a full blown stat(2)? */ /* look up the handle for the file */ memset(&key, 0, sizeof(key)); memset(&val, 0, sizeof(val)); key.buffer = file_name; key.buffer_sz = strlen(file_name)+1; val.buffer = &file_handle; val.buffer_sz = sizeof(TROVE_handle); /* it would be smart to verify that this is a directory first... */ ret = trove_keyval_read(coll_id, parent_handle, &key, &val, 0, NULL, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if ( ret < 0 || state == -1) { fprintf(stderr, "read failed for key %s\n", file_name); return -1; } ret = trove_dspace_getattr(coll_id, file_handle, &s_attr, 0 /* flags */, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) return -1; /* 'handles are everything': now that we've gotten a handle from the * file_name, we can wipe the keyval (via name) and the dspace (via * handle)*/ key.buffer = file_name; key.buffer_sz = strlen(file_name)+1; ret = trove_keyval_remove(coll_id, parent_handle, &key, NULL, 0, NULL, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0 ) { fprintf(stderr, "removal failed for %s\n", file_name); return -1; } /* the question: is it up to the caller to clean up the dspace if it removed the last entry? no no no*/ /* gar gar being dense: the dspace gets removed. */ ret = trove_dspace_remove(coll_id, file_handle, TROVE_SYNC, NULL, trove_context, &op_id, NULL); while (ret == 0) ret = trove_dspace_test( coll_id, op_id, trove_context, &count, NULL, NULL, &state, TROVE_DEFAULT_TEST_TIMEOUT); if (ret < 0) { fprintf(stderr, "dspace remove failed.\n"); return -1; } trove_close_context(coll_id, trove_context); trove_finalize(TROVE_METHOD_DBPF); printf("file %s removed (file handle = %d, parent handle = %d).\n", file_name, (int) file_handle, (int) parent_handle); return 0; }
int main(int argc, char **argv) { int ret = -1; struct ack_foo* ack = NULL; job_status_s status1; struct BMI_unexpected_info req_info; job_id_t job_id; int outcount; job_id_t tmp_id; job_context_id context; /* set debugging level */ gossip_enable_stderr(); gossip_set_debug_mask(0, 0); /* start the BMI interface */ ret = BMI_initialize("bmi_tcp", "tcp://NULL:3414", BMI_INIT_SERVER); if(ret < 0) { fprintf(stderr, "BMI_initialize failure.\n"); return(-1); } ret = trove_initialize( TROVE_METHOD_DBPF, NULL, "/tmp/pvfs2-test-space", 0); if(ret < 0) { fprintf(stderr, "trove_initialize failure.\n"); return(-1); } /* start the flow interface */ ret = PINT_flow_initialize("flowproto_multiqueue", 0); if(ret < 0) { fprintf(stderr, "flow_init failure.\n"); return(-1); } /* start the job interface */ ret = job_initialize(0); if(ret < 0) { fprintf(stderr, "job_initialize failure.\n"); return(-1); } ret = job_open_context(&context); if(ret < 0) { fprintf(stderr, "job_open_context() failure.\n"); return(-1); } /* post a job for unexpected receive */ ret = job_bmi_unexp(&req_info, NULL, 0, &status1, &job_id, 0, context); if(ret < 0) { fprintf(stderr, "job_bmi_unexp() failure.\n"); return(-1); } if(ret != 1) { #if 0 /* exercise testworld() interface, block indefinitely */ outcount = 1; ret = job_testworld(&job_id, &outcount, NULL, &status1, -1); if(ret < 0 || outcount == 0) { fprintf(stderr, "job_testworld() failure.\n"); return(-1); } /* alternatively, try out the testsome interface */ outcount = 1; ret = job_testsome(&job_id, &outcount, &foo, NULL, &status1, -1); if(ret < 0 || outcount == 0) { fprintf(stderr, "job_testsome() failure.\n"); return(-1); } #else /* ... or maybe even give job_test() a whirl */ ret = job_test(job_id, &outcount, NULL, &status1, 5000, context); if(ret < 0 || outcount == 0) { fprintf(stderr, "job_test() failure.\n"); return(-1); } #endif } /* check status */ if(status1.error_code != 0) { fprintf(stderr, "Bad status in unexp recv.\n"); return(-1); } /* allocate a buffer for the ack */ ack = BMI_memalloc(req_info.addr, sizeof(struct ack_foo), BMI_SEND); if(!ack) { fprintf(stderr, "BMI_memalloc failure.\n"); return(-1); } /* send a message */ ret = job_bmi_send(req_info.addr, ack, sizeof(struct ack_foo), 0, BMI_PRE_ALLOC, 0, NULL, 0, &status1, &tmp_id, context, JOB_TIMEOUT_INF, NULL); if(ret < 0) { fprintf(stderr, "job_bmi_send() failure.\n"); return(-1); } if(ret == 0) { int count = 0; ret = job_test(tmp_id, &count, NULL, &status1, -1, context); if(ret < 0) { fprintf(stderr, "job_test() failure.\n"); return(-1); } } /* check status */ if(status1.error_code != 0) { fprintf(stderr, "job failure.\n"); return(-1); } BMI_memfree(req_info.addr, ack, sizeof(struct ack_foo), BMI_RECV); BMI_unexpected_free(req_info.addr, req_info.buffer); /* shut down the interfaces */ job_close_context(context); job_finalize(); PINT_flow_finalize(); BMI_finalize(); trove_finalize(TROVE_METHOD_DBPF); return(0); }