int ibp_sync_command(ibp_op_t *iop) { op_generic_t *gop = ibp_get_gop(iop); op_status_t status; //** Submit if for execution // gop->base.started_execution = 1; //** Mark it as being submitted // submit_hportal_sync(gop->op->pc, gop); gop_set_exec_mode(gop, OP_EXEC_DIRECT); gop_start_execution(gop); //** and Wait for completion gop_waitany(gop); status = gop_get_status(gop); IBP_errno = status.error_code; if (gop->op->cmd.hostport != NULL) { free(gop->op->cmd.hostport); gop->op->cmd.hostport = NULL; } log_printf(10, "ibp_sync_command: IBP_errno=%d\n", IBP_errno); //tbx_log_flush(); return(IBP_errno); }
op_generic_t *gop_waitany(op_generic_t *g) { op_generic_t *gop = g; callback_t *cb; lock_gop(g); if (gop_get_type(g) == Q_TYPE_QUE) { log_printf(15, "sync_exec_que_check gid=%d stack_size=%d started_exec=%d\n", gop_id(g), stack_size(g->q->opque->qd.list), g->base.started_execution); if ((stack_size(g->q->opque->qd.list) == 1) && (g->base.started_execution == 0)) { //** See if we can directly exec g->base.started_execution = 1; cb = (callback_t *)pop(g->q->opque->qd.list); gop = (op_generic_t *)cb->priv; log_printf(15, "sync_exec_que -- waiting for pgid=%d cgid=%d to complete\n", gop_id(g), gop_id(gop)); unlock_gop(g); gop_waitany(gop); pop(g->q->finished); //** Remove it from the finished list. return(gop); } else { _gop_start_execution(g); //** Make sure things have been submitted while (((gop = (op_generic_t *)pop(g->q->finished)) == NULL) && (g->q->nleft > 0)) { apr_thread_cond_wait(g->base.ctl->cond, g->base.ctl->lock); //** Sleep until something completes } } if (gop != NULL) log_printf(15, "POP finished qid=%d gid=%d\n", gop_id(g), gop_id(gop)); //log_printf(15, "Printing qid=%d finished stack\n", gop_id(g)); //_opque_print_stack(g->q->finished); } else { log_printf(15, "gop_waitany: BEFORE (type=op) While gid=%d state=%d\n", gop_id(g), g->base.state); flush_log(); if ((g->base.pc->fn->sync_exec != NULL) && (g->base.started_execution == 0)) { //** See if we can directly exec unlock_gop(g); //** Don't need this for a direct exec log_printf(15, "sync_exec -- waiting for gid=%d to complete\n", gop_id(g)); g->base.pc->fn->sync_exec(g->base.pc, g); log_printf(15, "sync_exec -- gid=%d completed with err=%d\n", gop_id(g), g->base.state); return(g); } else { //** Got to submit it normally unlock_gop(g); //** It's a single task so no need to hold the lock. Otherwise we can deadlock _gop_start_execution(g); //** Make sure things have been submitted lock_gop(g); //** but we do need it for detecting when we're finished. while (g->base.state == 0) { apr_thread_cond_wait(g->base.ctl->cond, g->base.ctl->lock); //** Sleep until something completes } } log_printf(15, "gop_waitany: AFTER (type=op) While gid=%d state=%d\n", gop_id(g), g->base.state); flush_log(); } unlock_gop(g); return(gop); }
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 mq_stream_read_wait(mq_stream_t *mqs) { int err = 0; apr_interval_time_t dt; op_status_t status; //** If 1st time make all the variables if (mqs->mpool == NULL) { apr_pool_create(&mqs->mpool, NULL); apr_thread_mutex_create(&(mqs->lock), APR_THREAD_MUTEX_DEFAULT, mqs->mpool); apr_thread_cond_create(&(mqs->cond), mqs->mpool); } dt = apr_time_from_sec(1); //** Flag the just processed gop to clean up apr_thread_mutex_lock(mqs->lock); log_printf(5, "START msid=%d waiting=%d processed=%d gop_processed=%p\n", mqs->msid, mqs->waiting, mqs->processed, mqs->gop_processed); if (mqs->gop_processed != NULL) mqs->processed = 1; apr_thread_cond_broadcast(mqs->cond); if (mqs->data) { if (mqs->data[MQS_STATE_INDEX] != MQS_MORE) err = 1; } apr_thread_mutex_unlock(mqs->lock); if (mqs->gop_processed != NULL) { gop_waitany(mqs->gop_processed); gop_free(mqs->gop_processed, OP_DESTROY); mqs->gop_processed = NULL; } if (err != 0) { log_printf(2, "ERROR no more data available!\n"); return(-1); } //** Now handle the waiting gop apr_thread_mutex_lock(mqs->lock); log_printf(5, "before loop msid=%d waiting=%d processed=%d\n", mqs->msid, mqs->waiting, mqs->processed); while (mqs->waiting == 1) { log_printf(5, "LOOP msid=%d waiting=%d processed=%d\n", mqs->msid, mqs->waiting, mqs->processed); if (gop_will_block(mqs->gop_waiting) == 0) { //** Oops! failed request status = gop_get_status(mqs->gop_waiting); log_printf(2, "msid=%d gid=%d status=%d\n", mqs->msid, gop_id(mqs->gop_waiting), status.op_status); if (status.op_status != OP_STATE_SUCCESS) { mqs->waiting = -3; err = 1; } else { apr_thread_cond_timedwait(mqs->cond, mqs->lock, dt); } } else { apr_thread_cond_timedwait(mqs->cond, mqs->lock, dt); } } if (mqs->waiting == 0) { //** Flag the receiver to accept the data mqs->waiting = -1; apr_thread_cond_broadcast(mqs->cond); //** Let the receiver know we're ready to accept the data //** Wait for the data to be accepted while (mqs->waiting != -2) { apr_thread_cond_wait(mqs->cond, mqs->lock); } } else if (mqs->waiting == -3) { //**error occured err = 1; } apr_thread_mutex_unlock(mqs->lock); //** Flip states mqs->gop_processed = mqs->gop_waiting; mqs->gop_waiting = NULL; //** This shouldn't get triggered but just in case lets throw an error. if ((mqs->gop_processed == NULL) && (mqs->data != NULL)) { if ((mqs->data[MQS_STATE_INDEX] == MQS_MORE) && (mqs->want_more == MQS_MORE)) { err = 3; log_printf(0, "ERROR: MQS gop processed=waiting=NULL want_more set!!!!!! err=%d\n", err); fprintf(stderr, "ERROR: MQS gop processed=waiting=NULL want_more set!!!!!! err=%d\n", err); } } //** Check if we need to fire off the next request if (mqs->data != NULL) { if ((mqs->data[MQS_STATE_INDEX] == MQS_MORE) && (mqs->want_more == MQS_MORE)) { mq_stream_read_request(mqs); } } log_printf(5, "err=%d\n", err); return(err); }
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); }