int main(int argc, char **argv) { int i; char *fname = NULL; lio_exnode_t *ex; lio_exnode_exchange_t *exp; lio_exnode_exchange_t *exp_in; if (argc < 4) { printf("\n"); printf("ex_load LIO_COMMON_OPTIONS file.ex3\n"); lio_print_options(stdout); printf("\n"); return(1); } lio_init(&argc, &argv); //** Load the fixed options i = 1; fname = argv[i]; i++; if (fname == NULL) { printf("Missing input filename!\n"); return(2); } //** Create a blank exnode ex = lio_exnode_create(); //** Load it exp_in = lio_exnode_exchange_load_file(fname); printf("Initial exnode=====================================\n"); printf("%s", exp_in->text.text); printf("===================================================\n"); lio_exnode_deserialize(ex, exp_in, lio_gc->ess); //** Print it exp = lio_exnode_exchange_create(EX_TEXT); lio_exnode_serialize(ex, exp); printf("Loaded exnode=====================================\n"); printf("%s", exp->text.text); printf("===================================================\n"); lio_exnode_exchange_destroy(exp_in); lio_exnode_exchange_destroy(exp); lio_exnode_destroy(ex); lio_shutdown(); return(0); }
int main(int argc, char **argv) { int i, start_option, print_exnode, errors; char *section = "rw_params"; //printf("argc=%d\n", argc); if (argc < 2) { printf("\n"); printf("ex_rw_test LIO_COMMON_OPTIONS [-ex] [-s section]\n"); lio_print_options(stdout); printf(" -ex Print the final exnode to the screen before truncation\n"); printf(" -s section SEction in the config file to usse. Defaults to %s.\n", section); printf("\n"); return(1); } lio_init(&argc, &argv); //*** Parse the args print_exnode = 0; i=1; if (argc > 1) { do { start_option = i; if (strcmp(argv[i], "-ex") == 0) { //** Show the final exnode i++; print_exnode = 1; } else if (strcmp(argv[i], "-s") == 0) { //** Change the default section to use i++; section = argv[i]; i++; } } while ((start_option < i) && (i<argc)); } errors = segment_rw_test_exec(print_exnode, section); lio_shutdown(); return(errors); }
int main(int argc, char **argv) { int i, start_option; int mode; char *clone_arg = NULL; char *sfname = NULL; char *cfname = NULL; lio_exnode_t *ex, *cex; lio_exnode_exchange_t *exp, *exp_out; gop_op_generic_t *gop; gop_op_status_t status; FILE *fd; if (argc < 3) { printf("\n"); printf("ex_clone LIO_COMMON_OPTIONS [-structure|-data] [-a clone_attr] source_file.ex3 clone_file.ex3\n"); lio_print_options(stdout); printf(" -structure - Clone the structure only [default mode]\n"); printf(" -data - Clone the structure and copy the data\n"); printf(" -a clone_attr - Segment specific attribute passed to the clone routine. Not used for all Segment types.\n"); printf(" source_file.ex3 - File to clone\n"); printf(" clone_file.ex3 - DEstination cloned file\n"); return(1); } lio_init(&argc, &argv); mode = CLONE_STRUCTURE; //*** Parse the args i=1; do { start_option = i; if (strcmp(argv[i], "-structure") == 0) { //** Clone the structure only i++; mode = CLONE_STRUCTURE; } else if (strcmp(argv[i], "-data") == 0) { //** Clone the structure and the data i++; mode = CLONE_STRUCT_AND_DATA; } else if (strcmp(argv[i], "-a") == 0) { //** Alternate query attribute i++; clone_arg = argv[i]; i++; } } while (start_option < i); //** This is the source file sfname = argv[i]; i++; if (sfname == NULL) { printf("Missing source file!\n"); return(2); } //** This is the cloned file cfname = argv[i]; i++; if (cfname == NULL) { printf("Missing cloned file!\n"); return(2); } //** Load the source exp = lio_exnode_exchange_load_file(sfname); ex = lio_exnode_create(); lio_exnode_deserialize(ex, exp, lio_gc->ess); //** Execute the clone operation gop = lio_exnode_clone_gop(lio_gc->tpc_unlimited, ex, lio_gc->da, &cex, (void *)clone_arg, mode, lio_gc->timeout); gop_waitany(gop); status = gop_get_status(gop); gop_free(gop, OP_DESTROY); if (status.op_status != OP_STATE_SUCCESS) { printf("Error with clone! source=%s mode=%d\n", sfname, mode); abort(); } //** Store the updated exnode back to disk exp_out = lio_exnode_exchange_create(EX_TEXT); lio_exnode_serialize(cex, exp_out); fd = fopen(cfname, "w"); fprintf(fd, "%s", exp_out->text.text); fclose(fd); lio_exnode_exchange_destroy(exp_out); //** Clean up lio_exnode_exchange_destroy(exp); lio_exnode_destroy(ex); lio_exnode_destroy(cex); lio_shutdown(); return(0); }
int main(int argc, char **argv) { int chunk_size = 10; int n_chunks = 10; int bufsize= n_chunks * chunk_size; char base_data[bufsize+1]; char buffer[bufsize+1]; char log1_data[bufsize+1]; char log2_data[bufsize+1]; char log3_data[bufsize+1]; tbuffer_t tbuf; ex_iovec_t ex_iov, ex_iov_table[n_chunks]; int i, err; char *fname = NULL; exnode_t *ex; exnode_exchange_t *exp; segment_t *seg, *clone, *clone2, *clone3; seglog_priv_t *s; opque_t *q; if (argc < 2) { printf("\n"); printf("log_test LIO_COMMON_OPTIONS log.ex3\n"); lio_print_options(stdout); printf(" log.ex3 - Log file to use. IF the file is not empty all it's contents are truncated\n"); printf("\n"); return(1); } lio_init(&argc, &argv); //*** Parse the args //** This is the remote file to download i = 1; fname = argv[i]; i++; if (fname == NULL) { printf("Missing log file!\n"); return(2); } //** Load it exp = exnode_exchange_load_file(fname); //** and parse the remote exnode ex = exnode_create(); if (exnode_deserialize(ex, exp, lio_gc->ess) != 0) { printf("ERROR parsing exnode! Aborting!\n"); abort(); } //** Get the default view to use seg = exnode_get_default(ex); if (seg == NULL) { printf("No default segment! Aborting!\n"); abort(); } s = (seglog_priv_t *)seg->priv; //** Verify the type if (strcmp(segment_type(seg), SEGMENT_TYPE_LOG) != 0) { printf("Invalid exnode type. Segment should be a single level log but got a type of %s\n", segment_type(seg)); abort(); } //** Now get the base type. It should NOT be a log if (strcmp(segment_type(s->base_seg), SEGMENT_TYPE_LOG) == 0) { printf("Log segments base should NOT be another log segment!\n"); abort(); } //** Truncate the log and base q = new_opque(); opque_add(q, segment_truncate(s->table_seg, lio_gc->da, 0, lio_gc->timeout)); opque_add(q, segment_truncate(s->data_seg, lio_gc->da, 0, lio_gc->timeout)); opque_add(q, segment_truncate(s->base_seg, lio_gc->da, 0, lio_gc->timeout)); err = opque_waitall(q); if (err != OP_STATE_SUCCESS) { printf("Error with truncate of initial log segment!\n"); abort(); } s->file_size = 0; s->data_size = 0; s->log_size = 0; //************************************************************************* //--------------------- Testing starts here ------------------------------- //************************************************************************* //************************************************************************* //------- Generate a base with an empty log and read back ----------------- //************************************************************************* //** Make the base buffer and write it memset(base_data, 'B', bufsize); base_data[bufsize] = '\0'; tbuffer_single(&tbuf, bufsize, base_data); ex_iovec_single(&ex_iov, 0, bufsize); { int result = gop_sync_exec(segment_write(s->base_seg, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } s->file_size = bufsize; //** Since we're peeking we have to adjust the file size tbuffer_single(&tbuf, bufsize, buffer); //** Read it directly back fro mthe base to make sure that works { int result = gop_sync_exec(segment_read(s->base_seg, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } buffer[bufsize] = '\0'; { int result = strcmp(buffer, base_data); assert(result == 0); } //** Do the same for the log { int result = gop_sync_exec(segment_read(seg, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, base_data, bufsize, 0); assert(result == 0); } //************************************************************************* //-- Clone the base structure and the use segment_copy to copy the data and verify -- //************************************************************************* clone = NULL; { int result = gop_sync_exec(segment_clone(seg, lio_gc->da, &clone, CLONE_STRUCTURE, NULL, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = gop_sync_exec(segment_copy(lio_gc->tpc_unlimited, lio_gc->da, NULL, seg, clone, 0, 0, bufsize, chunk_size, buffer, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(clone, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, base_data, bufsize, 0); assert(result == 0); } //************************************************************************* //-------------------- Write to the log and read back --------------------- //************************************************************************* //** We are writing 1's to the even chunks memcpy(log1_data, base_data, bufsize); memset(buffer, '1', chunk_size); for (i=0; i<n_chunks; i+=2) { memcpy(&(log1_data[i*chunk_size]), buffer, chunk_size); ex_iovec_single(&(ex_iov_table[i]), i*chunk_size, chunk_size); opque_add(q, segment_write(seg, lio_gc->da, NULL, 1, &(ex_iov_table[i]), &tbuf, 0, lio_gc->timeout)); } { int result = opque_waitall(q); assert(result == OP_STATE_SUCCESS); } //** Read it back memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(seg, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, log1_data, bufsize, 0); assert(result == 0); } //************************************************************************* //------------------- Merge_with base and verify -------------------------- //************************************************************************* { int result = gop_sync_exec(slog_merge_with_base(seg, lio_gc->da, chunk_size, buffer, 1, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } //** Read it back memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(seg, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, log1_data, bufsize, 0); assert(result == 0); } //************************************************************************* //--------------- Write to the new empty log and verify ------------------- //************************************************************************* //** We are writing 2's to *most* of the odd chunks memcpy(log1_data, buffer, bufsize); memset(buffer, '2', chunk_size); for (i=1; i<n_chunks; i+=2) { memcpy(&(log1_data[i*chunk_size]), buffer, chunk_size); ex_iovec_single(&(ex_iov_table[i]), i*chunk_size, chunk_size); opque_add(q, segment_write(seg, lio_gc->da, NULL, 1, &(ex_iov_table[i]), &tbuf, 0, lio_gc->timeout)); } { int result = opque_waitall(q); assert(result == OP_STATE_SUCCESS); } //** Read it back memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(seg, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, log1_data, bufsize, 0); assert(result == 0); } //************************************************************************* //---------- Replace the clones base with seg(Log1) and verify ------------ //************************************************************************* { int result = gop_sync_exec(segment_remove(clone, lio_gc->da, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } segment_destroy(clone); clone = NULL; { int result = gop_sync_exec(segment_clone(seg, lio_gc->da, &clone, CLONE_STRUCTURE, NULL, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } s = (seglog_priv_t *)clone->priv; s->base_seg = seg; s->file_size = segment_size(seg); //** Read it back memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(clone, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, log1_data, bufsize, 0); assert(result == 0); } //************************************************************************* //---------- Write to the clones log and verify (now have 2 logs) --------- //************************************************************************* memcpy(log2_data, log1_data, bufsize); memset(buffer, '3', 1.5*chunk_size); for (i=0; i<n_chunks; i+=4) { memcpy(&(log2_data[i*chunk_size]), buffer, 1.5*chunk_size); ex_iovec_single(&(ex_iov_table[i]), i*chunk_size, 1.5*chunk_size); opque_add(q, segment_write(clone, lio_gc->da, NULL, 1, &(ex_iov_table[i]), &tbuf, 0, lio_gc->timeout)); } { int result = opque_waitall(q); assert(result == OP_STATE_SUCCESS); } //** Read it back memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(clone, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, log2_data, bufsize, 0); assert(result == 0); } //************************************************************************* //---- clone2 = clone (structure and data). Verify the contents ----------- //************************************************************************* clone2 = NULL; { int result = gop_sync_exec(segment_clone(clone, lio_gc->da, &clone2, CLONE_STRUCT_AND_DATA, NULL, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(clone2, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, log2_data, bufsize, 0); assert(result == 0); } //** We don't need this anymore so destroy it { int result = gop_sync_exec(segment_remove(clone2, lio_gc->da, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } segment_destroy(clone2); //************************************************************************* //---------------- Clone2 = clone's structure *only* ---------------------- //************************************************************************* clone2 = NULL; { int result = gop_sync_exec(segment_clone(clone, lio_gc->da, &clone2, CLONE_STRUCTURE, NULL, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } //************************************************************************* //-------------- Replace clone2's base with clone and verify -------------- //************************************************************************* s = (seglog_priv_t *)clone2->priv; { int result = gop_sync_exec(segment_remove(s->base_seg, lio_gc->da, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } segment_destroy(s->base_seg); s->base_seg = clone; s->file_size = segment_size(clone); //** Read it back memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(clone2, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, log2_data, bufsize, 0); assert(result == 0); } //************************************************************************* //----------- Write to Clone2 and verify (now have 3 logs) ---------------- //************************************************************************* memcpy(log3_data, log2_data, bufsize); memset(buffer, '4', chunk_size); for (i=0; i<n_chunks; i+=2) { memcpy(&(log3_data[i*chunk_size + chunk_size/3]), buffer, chunk_size); ex_iovec_single(&(ex_iov_table[i]), i*chunk_size + chunk_size/3, chunk_size); opque_add(q, segment_write(clone2, lio_gc->da, NULL, 1, &(ex_iov_table[i]), &tbuf, 0, lio_gc->timeout)); } { int result = opque_waitall(q); assert(result == OP_STATE_SUCCESS); } //** Read it back memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(clone2, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, log3_data, bufsize, 0); assert(result == 0); } //************************************************************************* // -- clone3 = clone2 structure and contents and verify //************************************************************************* clone3 = NULL; { int result = gop_sync_exec(segment_clone(clone2, lio_gc->da, &clone3, CLONE_STRUCT_AND_DATA, NULL, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } memset(buffer, 0, bufsize); { int result = gop_sync_exec(segment_read(clone3, lio_gc->da, NULL, 1, &ex_iov, &tbuf, 0, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = compare_buffers_print(buffer, log3_data, bufsize, 0); assert(result == 0); } //************************************************************************* //--------------------- Testing Finished ------------------------------- //************************************************************************* //** Clean up { int result = gop_sync_exec(segment_remove(clone3, lio_gc->da, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } { int result = gop_sync_exec(segment_remove(clone2, lio_gc->da, lio_gc->timeout)); assert(result == OP_STATE_SUCCESS); } segment_destroy(clone3); segment_destroy(clone2); segment_destroy(seg); exnode_exchange_destroy(exp); lio_shutdown(); return(0); }
int main(int argc, char **argv) { int i, start_option; int n_rid; char *query_text = NULL; rs_query_t *rq; ex_off_t block_size, total_size; lio_exnode_t *ex; lio_segment_create_fn_t *screate; char *fname_out = NULL; lio_exnode_exchange_t *exp; lio_segment_t *seg = NULL; gop_op_generic_t *gop; if (argc < 5) { printf("\n"); printf("mk_linear LIO_COMMON_OPTIONS -q rs_query_string n_rid block_size total_size file.ex3\n"); lio_print_options(stdout); printf("\n"); return(1); } lio_init(&argc, &argv); //*** Parse the args i=1; do { start_option = i; if (strcmp(argv[i], "-q") == 0) { //** Load the query i++; query_text = argv[i]; i++; } } while (start_option - i < 0); //** Load the fixed options n_rid = atoi(argv[i]); i++; block_size = atoi(argv[i]); i++; total_size = atoi(argv[i]); i++; fname_out = argv[i]; i++; //** Do some simple sanity checks //** Make sure we loaded a simple res service if (fname_out == NULL) { printf("Missing output filename!\n"); return(2); } //** Create an empty linear segment screate = lio_lookup_service(lio_gc->ess, SEG_SM_CREATE, SEGMENT_TYPE_LINEAR); seg = (*screate)(lio_gc->ess); //** Parse the query rq = rs_query_parse(lio_gc->rs, query_text); if (rq == NULL) { printf("Error parsing RS query: %s\n", query_text); printf("Exiting!\n"); exit(1); } //** Make the actual segment gop = lio_segment_linear_make_gop(seg, NULL, rq, n_rid, block_size, total_size, lio_gc->timeout); i = gop_waitall(gop); if (i != 0) { printf("ERROR making segment! nerr=%d\n", i); return(-1); } gop_free(gop, OP_DESTROY); //** Make an empty exnode ex = lio_exnode_create(); //** and insert it lio_view_insert(ex, seg); //** Print it exp = lio_exnode_exchange_create(EX_TEXT); lio_exnode_serialize(ex, exp); printf("%s", exp->text.text); //** and Save if back to disk FILE *fd = fopen(fname_out, "w"); fprintf(fd, "%s", exp->text.text); fclose(fd); lio_exnode_exchange_destroy(exp); //** Clean up lio_exnode_destroy(ex); rs_query_destroy(lio_gc->rs, rq); lio_shutdown(); return(0); }
int main(int argc, char **argv) { int i, j, ftype, rg_mode, start_option, start_index, prefix_len, nopre; char *fname; lio_path_tuple_t tuple; os_regex_table_t *rp_single, *ro_single; os_object_iter_t *it; int recurse_depth = 10000; int obj_types = OS_OBJECT_FILE; //printf("argc=%d\n", argc); if (argc < 2) { printf("\n"); printf("lio_find LIO_COMMON_OPTIONS [-rd recurse_depth] [-t object_types] [-nopre] LIO_PATH_OPTIONS\n"); lio_print_options(stdout); lio_print_path_options(stdout); printf("\n"); printf(" -rd recurse_depth - Max recursion depth on directories. Defaults to %d\n", recurse_depth); printf(" -t object_types - Types of objects to list bitwise OR of 1=Files, 2=Directories, 4=symlink, 8=hardlink. Default is %d.\n", obj_types); printf(" -nopre - Don't print the scan common prefix\n"); return(1); } lio_init(&argc, &argv); //*** Parse the args rp_single = ro_single = NULL; nopre = 0; rg_mode = lio_parse_path_options(&argc, argv, lio_gc->auto_translate, &tuple, &rp_single, &ro_single); i=1; do { start_option = i; if (strcmp(argv[i], "-rd") == 0) { //** Recurse depth i++; recurse_depth = atoi(argv[i]); i++; } else if (strcmp(argv[i], "-t") == 0) { //** Object types i++; obj_types = atoi(argv[i]); i++; } else if (strcmp(argv[i], "-nopre") == 0) { //** Strip off the path prefix i++; nopre = 1; } } while ((start_option < i) && (i<argc)); start_index = i; if (rg_mode == 0) { if (i>=argc) { info_printf(lio_ifd, 0, "Missing directory!\n"); return(2); } } else { start_index--; //** Ther 1st entry will be the rp created in lio_parse_path_options } for (j=start_index; j<argc; j++) { log_printf(5, "path_index=%d argc=%d rg_mode=%d\n", j, argc, rg_mode); if (rg_mode == 0) { //** Create the simple path iterator tuple = lio_path_resolve(lio_gc->auto_translate, argv[j]); lio_path_wildcard_auto_append(&tuple); rp_single = os_path_glob2regex(tuple.path); } else { rg_mode = 0; //** Use the initial rp } it = lio_create_object_iter(tuple.lc, tuple.creds, rp_single, ro_single, obj_types, NULL, recurse_depth, NULL, 0); if (it == NULL) { log_printf(0, "ERROR: Failed with object_iter creation\n"); goto finished; } while ((ftype = lio_next_object(tuple.lc, it, &fname, &prefix_len)) > 0) { // printf("len=%d full=%s nopref=%s\n", prefix_len, fname, &(fname[prefix_len+1])); if (nopre == 1) { info_printf(lio_ifd, 0, "%s\n", &(fname[prefix_len+1])); } else { info_printf(lio_ifd, 0, "%s\n", fname); } free(fname); } lio_destroy_object_iter(tuple.lc, it); lio_path_release(&tuple); if (rp_single != NULL) { os_regex_table_destroy(rp_single); rp_single = NULL; } if (ro_single != NULL) { os_regex_table_destroy(ro_single); ro_single = NULL; } } finished: lio_shutdown(); return((it == NULL) ? EIO : 0); }
int main(int argc, char **argv) { if (argc < 2) { printf("\n"); printf("rs_test LIO_COMMON_OPTIONS\n"); lio_print_options(stdout); return(1); } int thread_nbr; lio_init(&argc, &argv); thread_nbr = lio_parallel_task_count; //*** Parses the args char *svr_proto, *svr_addr, *svr_port, *zmq_svr; //** Retrieves remote zmq server name, transport protocol, and lisenting port svr_proto = inip_get_string(lio_gc->ifd, "zmq_server", "protocol", RS_ZMQ_DFT_PROTO); svr_addr = inip_get_string(lio_gc->ifd, "zmq_server", "server", NULL); svr_port = inip_get_string(lio_gc->ifd, "zmq_server", "port", RS_ZMQ_DFT_PORT); asprintf(&zmq_svr, "%s://%s:%s", string_trim(svr_proto), string_trim(svr_addr), string_trim(svr_port)); //** Creates zmq context void *context = zmq_ctx_new(); assert(context != NULL); //** Creates zmq router and binds it to tcp://*:5555 //** It talks to rs client void *router = zmq_socket(context, ZMQ_ROUTER); assert(router != NULL); int rc = zmq_bind(router, zmq_svr); assert(rc != -1); printf("ZMQ router socket created.\n"); // Creates and binds DEALER socket to inproc://worker // It talks to workers void *dealer = zmq_socket(context, ZMQ_DEALER); assert(dealer != NULL); rc = zmq_bind(dealer, "inproc://worker"); assert(rc != -1); printf("ZMQ dealer socket created.\n"); //** Blocks the SIGINT, SIGTERM signals sigemptyset(&signal_mask); sigaddset(&signal_mask, SIGINT); sigaddset(&signal_mask, SIGTERM); rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); assert(rc == 0); //** Launches thread pool printf("Launching threads...\n"); int thread_count; rs_zmq_thread_arg_t **arg; type_malloc_clear(arg, rs_zmq_thread_arg_t *, thread_nbr); pthread_t *workers; type_malloc_clear(workers, pthread_t, thread_nbr); for (thread_count = 0; thread_count < thread_nbr; thread_count++) { type_malloc_clear(arg[thread_count], rs_zmq_thread_arg_t, 1); arg[thread_count]->zmq_context = context; arg[thread_count]->rs = lio_gc->rs; arg[thread_count]->da = ds_attr_create(lio_gc->ds); arg[thread_count]->ds = lio_gc->ds; arg[thread_count]->timeout = lio_gc->timeout; pthread_create(&workers[thread_count], NULL, rs_zmq_worker_routine, (void *)arg[thread_count]); } printf("Launched all %d threads.\n", thread_nbr); //** Unblocks the SIGINT, SIGTERM signals rc = pthread_sigmask(SIG_UNBLOCK, &signal_mask, NULL); assert(rc == 0); //** Catches the SIGNIT, SIGTERM signals catch_signals(); //** Uses a QUEUE device to connect router and dealer zmq_device(ZMQ_QUEUE, router, dealer); if (s_interrupted == 1) printf("Interrupt received, killing server...\n"); //** Shutdown zmq should go before cleaning thread resources zmq_close(router); zmq_close(dealer); printf("Destroied ZMQ router and dealer\n"); zmq_ctx_destroy(context); //** This "trigers" the exit of all threads, because it makes all blocking operations on sockets return printf("Destroied ZMQ context\n"); fflush(stdout); //** Waits for all threads to exit for (thread_count = 0; thread_count < thread_nbr; thread_count++) { pthread_join(workers[thread_count], NULL); } //** Destroys allocations for threads for (thread_count = 0; thread_count < thread_nbr; thread_count++) { ds_attr_destroy(lio_gc->ds, arg[thread_count]->da); free(arg[thread_count]); } free(arg); free(workers); free(svr_proto); free(svr_addr); free(svr_port); free(zmq_svr); lio_shutdown(); return(0); }
int main(int argc, char **argv) { int start_option, i, watch, summary, base; rs_mapping_notify_t notify, me; apr_time_t dt; char *config; //printf("argc=%d\n", argc); if (argc < 2) { printf("\n"); printf("lio_rs LIO_COMMON_OPTIONS [-w] [-b2 | -b10] [-s | -f]\n"); lio_print_options(stdout); printf(" -w - Watch for RID configuration changes. Press ^C to exit\n"); printf(" -b2 - Use powers of 2 for units(default)\n"); printf(" -b10 - Use powers of 10 for units\n"); printf(" -s - Print a RID space usage summary\n"); printf(" -f - Print the full RID configuration\n"); return(1); } lio_init(&argc, &argv); watch = 0; summary = 0; base = 1024; i=1; do { start_option = i; if (strcmp(argv[i], "-w") == 0) { //** Watch for any RID changes i++; watch = 1; } else if (strcmp(argv[i], "-s") == 0) { //** Print space summary instead of full conifg i++; summary = 1; } else if (strcmp(argv[i], "-b2") == 0) { //** base-2 units i++; base = 1024; } else if (strcmp(argv[i], "-b10") == 0) { //** base-10 units i++; base = 1000; } } while ((start_option < i) && (i<argc)); //** Make the APR stuff assert_result(apr_pool_create(&mpool, NULL), APR_SUCCESS); apr_thread_mutex_create(&lock, APR_THREAD_MUTEX_DEFAULT, mpool); apr_thread_cond_create(&cond, mpool); //if (watch == 1) { // printf("Sleeping for 60s\n"); fflush(stdout); // sleep(60); // printf("Woken up\n"); fflush(stdout); //} memset(¬ify, 0, sizeof(notify)); notify.lock = lock; notify.cond = cond; me = notify; me.map_version = 1; //** This triggers the initial load rs_register_mapping_updates(lio_gc->rs, ¬ify); dt = apr_time_from_sec(1); do { //** Check for an update apr_thread_mutex_lock(lock); if (watch == 1) apr_thread_cond_timedwait(notify.cond, notify.lock, dt); i = ((me.map_version != notify.map_version) || (me.status_version != notify.status_version)) ? 1 : 0; me = notify; apr_thread_mutex_unlock(lock); if (i != 0) { config = rs_get_rid_config(lio_gc->rs); printf("Map Version: %d Status Version: %d\n", me.map_version, me.status_version); printf("--------------------------------------------------------------------------------------------------\n"); if (config == NULL) { printf("ERROR NULL config!\n"); } else if (summary == 1) { print_rid_summary(config, base); } else { printf("%s", config); } printf("--------------------------------------------------------------------------------------------------\n"); if (config != NULL) free(config); } } while (watch == 1); info_printf(lio_ifd, 5, "BEFORE unregister\n"); tbx_info_flush(lio_ifd); rs_unregister_mapping_updates(lio_gc->rs, ¬ify); info_printf(lio_ifd, 5, "AFTER unregister\n"); tbx_info_flush(lio_ifd); //** Cleanup apr_pool_destroy(mpool); // info_printf(lio_ifd, 5, "AFTER shutdown\n"); tbx_info_flush(lio_ifd); lio_shutdown(); return(0); }
int main(int argc, char **argv) { int i = 1, d, recurse_depth = 10000, start_option = 0, start_index, obj_types; char *regex_path = NULL; char *regex_object = NULL; char *tag_file = NULL; char *tag_name = NULL; lio_init(&argc, &argv); obj_types = OS_OBJECT_ANY; if (argc < 2) { print_usage(); } else { do { start_option = i; if (strcmp(argv[i], "-h") == 0) { print_usage(); } else if (strcmp(argv[i], "-t") == 0) { i++; tag_file = argv[i]; i++; } else if (strcmp(argv[i], "-n") == 0) { i++; tag_name = argv[i]; i++; } else if (strcmp(argv[i], "-rd") == 0) { i++; recurse_depth = atoi(argv[i]); i++; } else if (strcmp(argv[i], "-o") == 0) { i++; obj_types = atoi(argv[i]); i++; } else if (strcmp(argv[i], "-rp") == 0) { i++; regex_path = argv[i]; i++; } else if (strcmp(argv[i], "-ro") == 0) { i++; regex_object = argv[i]; i++; } else if (strcmp(argv[i], "-gp") == 0) { i++; regex_path = os_glob2regex(argv[i]); i++; } else if (strcmp(argv[i], "-go") == 0) { i++; regex_object = os_glob2regex(argv[i]); i++; } } while ((start_option < i) && (i < argc)); if (tag_name == NULL) { printf("ERROR: tag name not specified!\n"); print_usage(); } start_index = i; if (tag_file == NULL) { char *homedir = getenv("HOME"); tag_file = concat(homedir, "/.arc_tag_file.txt"); } if (((access (tag_file, F_OK)) == -1) || ((access(tag_file, W_OK)) == -1)) { printf("ERROR: %s does not exist! Please run arc_tag_create\n", tag_file); return(1); } else if ((access(tag_file, W_OK)) == -1) { printf("ERROR: Permission Denied!\n"); return(1); } else { if (i>=argc) { printf("Missing target path(s)!\n\n"); print_usage(); } else { if ((regex_path != NULL) || (regex_object != NULL)) add_tag(tag_file, tag_name, NULL, regex_path, regex_object, obj_types, recurse_depth); for (d=start_index; d<argc; d++) { add_tag(tag_file, tag_name, argv[d], NULL, NULL, obj_types, recurse_depth); } } } } lio_shutdown(); return(0); }
int main(int argc, char **argv) { char *path; int i, mode, n, nfailed; os_fsck_iter_t *it; char *fname; op_generic_t *gop; op_status_t status; int ftype, err; if (argc < 2) { printf("\n"); printf("os_fsck LIO_COMMON_OPTIONS [-fix manual|delete|repair] path\n"); lio_print_options(stdout); printf(" -fix - How to handle issues. Default is manual. Can also be delete or repair.\n"); printf(" path - Path prefix to use\n"); printf("\n"); return(1); } lio_init(&argc, &argv); if (argc < 2) { printf("Missing path!\n"); return(1); } mode = OS_FSCK_MANUAL; i = 1; if (strcmp(argv[i], "-fix") == 0) { i++; if (strcmp(argv[i], "delete") == 0) { mode = OS_FSCK_REMOVE; } else if (strcmp(argv[i], "repair") == 0) { mode = OS_FSCK_REPAIR; } i++; } path = argv[i]; info_printf(lio_ifd, 0, "--------------------------------------------------------------------\n"); info_printf(lio_ifd, 0, "Using path=%s and mode=%d (%d=manual, %d=delete, %d=repair)\n", path, mode, OS_FSCK_MANUAL, OS_FSCK_REMOVE, OS_FSCK_REPAIR); info_printf(lio_ifd, 0, "Possible error states: %d=missing attr, %d=missing object\n", OS_FSCK_MISSING_ATTR, OS_FSCK_MISSING_OBJECT); info_printf(lio_ifd, 0, "--------------------------------------------------------------------\n"); tbx_info_flush(lio_ifd); n = 0; nfailed = 0; it = os_create_fsck_iter(lio_gc->os, lio_gc->creds, path, OS_FSCK_MANUAL); //** WE use reolve to clean up so we can see the problem objects while ((err = os_next_fsck(lio_gc->os, it, &fname, &ftype)) != OS_FSCK_GOOD) { info_printf(lio_ifd, 0, "err:%d type:%d object:%s\n", err, ftype, fname); if (err == OS_FSCK_ERROR) { //** Internal error so abort! info_printf(lio_ifd, 0, "Internal FSCK error! Aborting!\n"); break; } if (mode != OS_FSCK_MANUAL) { gop = os_fsck_object(lio_gc->os, lio_gc->creds, fname, ftype, mode); gop_waitany(gop); status = gop_get_status(gop); gop_free(gop, OP_DESTROY); if (status.error_code != OS_FSCK_GOOD) nfailed++; info_printf(lio_ifd, 0, " resolve:%d object:%s\n", status.error_code, fname); } free(fname); fname = NULL; n++; } os_destroy_fsck_iter(lio_gc->os, it); info_printf(lio_ifd, 0, "--------------------------------------------------------------------\n"); info_printf(lio_ifd, 0, "Problem objects: %d Repair Failed count: %d\n", n, nfailed); info_printf(lio_ifd, 0, "--------------------------------------------------------------------\n"); lio_shutdown(); return(0); }
int main(int argc, char **argv) { int i, j, ftype, rg_mode, start_option, start_index, prefix_len, nosort, err; ex_off_t fcount; char *fname; ls_entry_t *lse; tbx_list_t *table; // lio_path_tuple_t tuple; os_regex_table_t *rp_single, *ro_single; os_object_iter_t *it; tbx_list_iter_t lit; opque_t *q; op_generic_t *gop; char *keys[] = { "system.owner", "system.exnode.size", "system.modify_data", "os.create", "os.link_count" }; char *vals[5]; int v_size[5]; int n_keys = 5; int recurse_depth = 0; int obj_types = OS_OBJECT_ANY; int return_code = 0; //printf("argc=%d\n", argc); if (argc < 2) { printf("\n"); printf("lio_ls LIO_COMMON_OPTIONS [-rd recurse_depth] [-ns] LIO_PATH_OPTIONS\n"); lio_print_options(stdout); lio_print_path_options(stdout); printf("\n"); printf(" -rd recurse_depth - Max recursion depth on directories. Defaults to %d\n", recurse_depth); printf(" -t object_types - Types of objects to list bitwise OR of 1=Files, 2=Directories, 4=symlink, 8=hardlink. Default is %d.\n", obj_types); printf(" -ns - Don't sort the output\n"); return(1); } lio_init(&argc, &argv); //*** Parse the args rp_single = ro_single = NULL; nosort = 0; rg_mode = lio_parse_path_options(&argc, argv, lio_gc->auto_translate, &tuple, &rp_single, &ro_single); i=1; do { start_option = i; if (strcmp(argv[i], "-rd") == 0) { //** Recurse depth i++; recurse_depth = atoi(argv[i]); i++; } else if (strcmp(argv[i], "-t") == 0) { //** Object types i++; obj_types = atoi(argv[i]); i++; } else if (strcmp(argv[i], "-ns") == 0) { //** Strip off the path prefix i++; nosort = 1; } } while ((start_option < i) && (i<argc)); start_index = i; if (rg_mode == 0) { if (i>=argc) { info_printf(lio_ifd, 0, "Missing directory!\n"); return(2); } } else { start_index--; //** Ther 1st entry will be the rp created in lio_parse_path_options } fcount = 0; q = new_opque(); table = tbx_list_create(0, &tbx_list_string_compare, NULL, tbx_list_no_key_free, tbx_list_no_data_free); for (j=start_index; j<argc; j++) { log_printf(5, "path_index=%d argc=%d rg_mode=%d\n", j, argc, rg_mode); if (rg_mode == 0) { //** Create the simple path iterator tuple = lio_path_resolve(lio_gc->auto_translate, argv[j]); lio_path_wildcard_auto_append(&tuple); rp_single = os_path_glob2regex(tuple.path); } else { rg_mode = 0; //** Use the initial rp } for (i=0; i<n_keys; i++) v_size[i] = -tuple.lc->max_attr; memset(vals, 0, sizeof(vals)); it = lio_create_object_iter_alist(tuple.lc, tuple.creds, rp_single, ro_single, obj_types, recurse_depth, keys, (void **)vals, v_size, n_keys); if (it == NULL) { info_printf(lio_ifd, 0, "ERROR: Failed with object_iter creation\n"); return_code = EIO; goto finished; } while ((ftype = lio_next_object(tuple.lc, it, &fname, &prefix_len)) > 0) { tbx_type_malloc_clear(lse, ls_entry_t, 1); lse->fname = fname; lse->ftype = ftype; lse->prefix_len = prefix_len; memcpy(lse->v_size, v_size, sizeof(v_size)); memcpy(lse->vals, vals, sizeof(vals)); for (i=0; i<n_keys; i++) v_size[i] = -tuple.lc->max_attr; memset(vals, 0, sizeof(vals)); //** Check if we have a link. If so we need to resolve the link path if ((ftype & OS_OBJECT_SYMLINK) > 0) { lse->link_size = -64*1024; gop = gop_lio_get_attr(tuple.lc, tuple.creds, lse->fname, NULL, "os.link", (void **)&(lse->link), &(lse->link_size)); gop_set_private(gop, lse); opque_add(q, gop); if (nosort == 1) opque_waitall(q); } if (fcount == 0) { info_printf(lio_ifd, 0, " Perms Ref Owner Size Creation date Modify date Filename [-> link]\n"); info_printf(lio_ifd, 0, "---------- --- ---------- ---------- ------------------------ ------------------------ ------------------------------\n"); } fcount++; if (nosort == 1) { ls_format_entry(lio_ifd, lse); } else { tbx_list_insert(table, lse->fname, lse); } } lio_destroy_object_iter(tuple.lc, it); lio_path_release(&tuple); if (rp_single != NULL) { os_regex_table_destroy(rp_single); rp_single = NULL; } if (ro_single != NULL) { os_regex_table_destroy(ro_single); ro_single = NULL; } } //** Wait for any readlinks to complete err = (opque_task_count(q) > 0) ? opque_waitall(q) : OP_STATE_SUCCESS; if (err != OP_STATE_SUCCESS) { info_printf(lio_ifd, 0, "ERROR: Failed with readlink operation!\n"); return_code = EIO; } //** Now sort and print things if needed if (nosort == 0) { lit = tbx_list_iter_search(table, NULL, 0); while ((tbx_list_next(&lit, (tbx_list_key_t **)&fname, (tbx_list_data_t **)&lse)) == 0) { ls_format_entry(lio_ifd, lse); } } tbx_list_destroy(table); if (fcount == 0) return_code = 2; finished: opque_free(q, OP_DESTROY); lio_shutdown(); return(return_code); }