static int bad_contact_test(void) { int rc; struct monitor monitor; globus_mutex_init(&monitor.mutex, NULL); globus_cond_init(&monitor.cond, NULL); monitor.done = GLOBUS_FALSE; monitor.job_state = GLOBUS_GRAM_PROTOCOL_JOB_STATE_UNSUBMITTED; monitor.protocol_error_code = GLOBUS_SUCCESS; rc = globus_gram_client_register_job_status_with_info( "https://grid.example.org:123/1234/1234/", NULL /* can be NULL, optional param */, info_callback, &monitor); test_assert(rc == GLOBUS_GRAM_PROTOCOL_ERROR_CONTACTING_JOB_MANAGER, ("Unexpected response to bad job contact \"%s\" (%d)", globus_gram_protocol_error_string(rc), rc)); rc = GLOBUS_SUCCESS; return rc; }
/** * @brief Initialize a recursive mutex * @ingroup globus_mutex * * @details * The globus_rmutex_init() function initializes a recursive mutex, * that is, one which may be locked multiple times by a single thread * without causing deadlock. * @param rmutex * A pointer to the mutex to initialize * @param rattr * IGNORED * * @return * On success, globus_rmutex_init() initializes the mutex and returns * GLOBUS_SUCCESS; otherwise, it returns a non-zero error code. */ int globus_rmutex_init( globus_rmutex_t * rmutex, globus_rmutexattr_t * rattr) { int rc; rc = globus_mutex_init(&rmutex->mutex, GLOBUS_NULL); if(rc) { goto err_init; } rc = globus_cond_init(&rmutex->cond, GLOBUS_NULL); if(rc) { goto err_cond; } rmutex->level = 0; memset(&rmutex->thread_id,0,sizeof(rmutex->thread_id)); rmutex->waiting = 0; return 0; err_cond: globus_mutex_destroy(&rmutex->mutex); err_init: return rc; }
static int job_status_with_info_test(void) { int rc; char * job_contact = NULL; struct monitor monitor; globus_mutex_init(&monitor.mutex, NULL); globus_cond_init(&monitor.cond, NULL); monitor.done = GLOBUS_FALSE; monitor.job_state = GLOBUS_GRAM_PROTOCOL_JOB_STATE_UNSUBMITTED; monitor.protocol_error_code = GLOBUS_SUCCESS; rc = globus_gram_client_job_request( rm_contact, "&(executable=/bin/sleep)(arguments=60)", 0, NULL, &job_contact); test_assert(rc == GLOBUS_SUCCESS, ("Failed submitting sleep job because %s (%d)", globus_gram_protocol_error_string(rc), rc)); rc = globus_gram_client_register_job_status_with_info( job_contact, NULL, info_callback, &monitor); free(job_contact); test_assert(rc == GLOBUS_SUCCESS, ("Failed registering job_status because %s (%d)", globus_gram_protocol_error_string(rc), rc)); globus_mutex_lock(&monitor.mutex); while (!monitor.done) { globus_cond_wait(&monitor.cond, &monitor.mutex); } globus_mutex_unlock(&monitor.mutex); test_assert(monitor.protocol_error_code == GLOBUS_SUCCESS, ("Failed to determine job status because %s (%d)", globus_gram_protocol_error_string( monitor.protocol_error_code), monitor.protocol_error_code)); test_assert(monitor.job_state != 0, ("Failed to determine job status")); rc = GLOBUS_SUCCESS; return rc; }
/* * globus_l_module_mutex_init() */ static void globus_l_module_mutex_init( globus_l_module_mutex_t * mutex) { globus_mutex_init(&mutex->mutex, (globus_mutexattr_t *) GLOBUS_NULL); globus_cond_init(&mutex->cond, (globus_condattr_t *) GLOBUS_NULL); mutex->level = 0; }
int main(int argc, char * argv[]) { globus_ftp_client_handle_t handle; globus_ftp_client_operationattr_t attr; globus_result_t result; globus_ftp_client_handleattr_t handle_attr; char * src; char * dst; globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); globus_ftp_client_handleattr_init(&handle_attr); globus_ftp_client_operationattr_init(&attr); globus_mutex_init(&lock, GLOBUS_NULL); globus_cond_init(&cond, GLOBUS_NULL); test_parse_args(argc, argv, &handle_attr, &attr, &src, &dst); globus_ftp_client_operationattr_set_type(&attr, GLOBUS_FTP_CONTROL_TYPE_ASCII); globus_ftp_client_handle_init(&handle, &handle_attr); done = GLOBUS_FALSE; result = globus_ftp_client_symlink(&handle, src, dst, &attr, done_cb, 0); if(result != GLOBUS_SUCCESS) { done = GLOBUS_TRUE; } globus_mutex_lock(&lock); while(!done) { globus_cond_wait(&cond, &lock); } globus_mutex_unlock(&lock); globus_ftp_client_handle_destroy(&handle); globus_module_deactivate_all(); if(test_abort_count && error) { return 0; } return error; }
globus_result_t globus_dsi_rest_test_server_init( char **contact) { globus_result_t result = GLOBUS_SUCCESS; globus_thread_t thread; globus_xio_attr_t xio_attr; server_done = false; globus_mutex_init(&server_done_mutex, NULL); globus_cond_init(&server_done_cond, NULL); result = globus_hashtable_init( &server_routes, 43, globus_hashtable_string_hash, globus_hashtable_string_keyeq); if (result != GLOBUS_SUCCESS) { goto hashtable_init_fail; } result = globus_xio_driver_load("tcp", &tcp_driver); if (result != GLOBUS_SUCCESS) { goto tcp_load_fail; } result = globus_xio_driver_load("http", &http_driver); if (result != GLOBUS_SUCCESS) { goto http_load_fail; } result = globus_xio_stack_init(&xio_stack, NULL); if (result != GLOBUS_SUCCESS) { goto stack_init_fail; } result = globus_xio_stack_push_driver(xio_stack, tcp_driver); if (result != GLOBUS_SUCCESS) { goto stack_push_fail; } result = globus_xio_stack_push_driver(xio_stack, http_driver); if (result != GLOBUS_SUCCESS) { goto stack_push_fail; } result = globus_xio_attr_init( &xio_attr); result = globus_xio_attr_cntl( xio_attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_ACCEPT, NULL, &(globus_reltime_t) { .tv_sec = 1 },
void test_monitor_initialize( test_monitor_t * monitor, void * user_data) { globus_mutex_init(&monitor->mutex, GLOBUS_NULL); globus_cond_init(&monitor->cond, GLOBUS_NULL); monitor->err = GLOBUS_NULL; monitor->use_err = GLOBUS_FALSE; monitor->done = GLOBUS_FALSE; monitor->ready = GLOBUS_FALSE; monitor->nbytes = 0; monitor->user_data = user_data; }
globus_bool_t async_control_test( globus_ftp_control_handle_t * handle) { globus_ftp_control_handle_t control_handle; globus_result_t result; globus_mutex_init(&end_mutex, GLOBUS_NULL); globus_cond_init(&end_cond, GLOBUS_NULL); end_done = GLOBUS_FALSE; result = globus_ftp_control_handle_init(&control_handle); if (result != GLOBUS_SUCCESS) { printf("error: could not initialize\n"); exit(1); } result = globus_ftp_control_connect( &control_handle, login_info.hostname, login_info.port, connect_callback, GLOBUS_NULL); if (result != GLOBUS_SUCCESS) { printf("error: could not connect\n"); return GLOBUS_FALSE; } globus_mutex_lock(&end_mutex); { while(!end_done) { globus_cond_wait(&end_cond, &end_mutex); } } globus_mutex_unlock(&end_mutex); globus_ftp_control_handle_destroy(&control_handle); return GLOBUS_TRUE; }
/** * Operator: Initialize */ ngemResult_t ngrcOperatorInitialize( ngrcOperator_t *op, globus_xio_handle_t handle) { globus_result_t gResult; ngLog_t *log; bool mutexInitialized = false; NGEM_FNAME(ngrcOperatorInitialize); log = ngemLogGetDefault(); NGEM_ASSERT(op != NULL); NGEM_ASSERT(handle != NULL); op->ngo_handle = handle; op->ngo_canceled = false; gResult = globus_mutex_init(&op->ngo_mutex, NULL); if (gResult != GLOBUS_SUCCESS) { ngcpLogGlobusError(log, NGRC_LOGCAT_GT, fName, "globus_mutex_init", gResult); goto error; } mutexInitialized = true; globus_cond_init(&op->ngo_cond, NULL); if (gResult != GLOBUS_SUCCESS) { ngcpLogGlobusError(log, NGRC_LOGCAT_GT, fName, "globus_cond_init", gResult); goto error; } return NGEM_SUCCESS; error: if (mutexInitialized) { gResult = globus_mutex_destroy(&op->ngo_mutex); if (gResult != GLOBUS_SUCCESS) { ngcpLogGlobusError(log, NGRC_LOGCAT_GT, fName, "globus_mutex_destroy", gResult); } } return NGEM_FAILED; }
int main(int argc, char *argv[]) { globus_ftp_client_handle_t handle; globus_ftp_client_operationattr_t attr; globus_byte_t buffer[1024]; globus_size_t buffer_length = sizeof(buffer); globus_result_t result; char * src; char * dst; globus_ftp_client_handleattr_t handle_attr; LTDL_SET_PRELOADED_SYMBOLS(); globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); globus_ftp_client_handleattr_init(&handle_attr); globus_ftp_client_operationattr_init(&attr); test_parse_args(argc, argv, &handle_attr, &attr, &src, &dst); globus_mutex_init(&lock, GLOBUS_NULL); globus_cond_init(&cond, GLOBUS_NULL); globus_ftp_client_handle_init(&handle, &handle_attr); done = GLOBUS_FALSE; result = globus_ftp_client_get(&handle, src, &attr, GLOBUS_NULL, done_cb, 0); globus_module_deactivate_all(); return done; }
cond() : cond_() { globus_cond_init(&cond_, NULL); }
int framework_main( int argc, char ** argv) { int rc; globus_xio_stack_t stack; globus_xio_handle_t handle; globus_xio_attr_t attr; globus_result_t res; globus_xio_server_t server; globus_l_closed = GLOBUS_FALSE; globus_l_accepted = GLOBUS_FALSE; rc = globus_module_activate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); globus_mutex_init(&globus_l_mutex, NULL); globus_cond_init(&globus_l_cond, NULL); res = globus_xio_attr_init(&attr); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); res = globus_xio_stack_init(&stack, NULL); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); parse_parameters(argc, argv, stack, attr); if(globus_l_test_info.server) { res = globus_xio_server_create(&server, attr, stack); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); res = globus_xio_server_register_accept( server, accept_cb, &handle); test_res(GLOBUS_XIO_TEST_FAIL_PASS_ACCEPT, res, __LINE__, __FILE__); globus_mutex_lock(&globus_l_mutex); { while(!globus_l_accepted) { globus_cond_wait(&globus_l_cond, &globus_l_mutex); } } globus_mutex_unlock(&globus_l_mutex); } else { res = globus_xio_handle_create(&handle, stack); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); } res = globus_xio_register_open( handle, "whatever", attr, open_cb, (void *)&globus_l_test_info); test_res(GLOBUS_XIO_TEST_FAIL_PASS_OPEN, res, __LINE__, __FILE__); globus_mutex_lock(&globus_l_mutex); { while(!globus_l_closed) { globus_cond_wait(&globus_l_cond, &globus_l_mutex); } } globus_mutex_unlock(&globus_l_mutex); globus_xio_attr_destroy(attr); globus_xio_stack_destroy(stack); if(globus_l_test_info.server) { res = globus_xio_server_close(server); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); } test_common_end(); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); fprintf(stdout, "Success.\n"); return 0; }
int main( int argc, char * argv[]) { int i; int nitems; long thread_id; globus_thread_t thread; globus_thread_set_model("pthread"); globus_module_activate(GLOBUS_COMMON_MODULE); if (argc != 4) { globus_stdio_lock(); { printf("\nusage: globus_thread_test " "nproducers nconsumers nitems\n\n"); } globus_stdio_unlock(); exit(1); } nproducers = atoi(argv[1]); nconsumers = atoi(argv[2]); nitems = atoi(argv[3]); /* * Initialize queue and queue concurrency control structures */ globus_fifo_init(&queue); globus_mutex_init(&queue_mutex, (globus_mutexattr_t *) GLOBUS_NULL); globus_cond_init(&queue_cond, (globus_condattr_t *) GLOBUS_NULL); /* * Initialize shared (common) concurrency control structures */ globus_mutex_init(&common_mutex, (globus_mutexattr_t *) GLOBUS_NULL); globus_cond_init(&common_cond, (globus_condattr_t *) GLOBUS_NULL); /* * Assign a thread id to the main thread so that it's output is uniquely * tagged. Note: we do not use the return value of globus_thread_self() * since it could be a pointer or a structure, the latter which is * extremely hard to print without knowing the implementation details. */ thread_id_assign(); thread_id = thread_id_get(); /* * Start producer and consumer threads */ globus_stdio_lock(); { printf("%04ld: main() - starting %d producer and %d consumer threads\n", thread_id, nproducers, nconsumers); } globus_stdio_unlock(); for (i = 0 ; i < nproducers ; i ++) { int rc; int nitems_per_thread; nitems_per_thread = nitems / nproducers + ((i < nitems % nproducers) ? 1 : 0); rc = globus_thread_create( &thread, NULL, producer, (void *) nitems_per_thread); if (rc != 0) { globus_stdio_lock(); { printf("%04ld: main() - ERROR: " "unable to create producer thread %d\n", thread_id, i); exit(1); } globus_stdio_unlock(); } } for (i = 0 ; i < nconsumers ; i ++) { int rc; int nitems_per_thread; nitems_per_thread = nitems / nconsumers + ((i < nitems % nconsumers) ? 1 : 0); rc = globus_thread_create( &thread, NULL, consumer, (void *) nitems_per_thread); if (rc != 0) { globus_stdio_lock(); { printf("%04ld: main() - ERROR: " "unable to create consumer thread %d\n", thread_id, i); exit(1); } globus_stdio_unlock(); } } /* * Wait for all threads to be started */ wait_for_all(); globus_stdio_lock(); { printf("%04ld: main() - all threads started\n", thread_id); } globus_stdio_unlock(); /* * Wait for all threads to complete their work */ wait_for_all(); globus_stdio_lock(); { printf("%04ld: main() - all threads have completed their work\n", thread_id); } globus_stdio_unlock(); /* * Wait for all thread id data to be destroyed */ while (thread_ids_destruct_cnt < nproducers + nconsumers) { globus_thread_yield(); } globus_stdio_lock(); { printf("%04ld: main() - all threads terminated\n", thread_id); } globus_stdio_unlock(); globus_cond_destroy(&common_cond); globus_mutex_destroy(&common_mutex); globus_cond_destroy(&queue_cond); globus_mutex_destroy(&queue_mutex); globus_fifo_destroy(&queue); globus_module_deactivate(GLOBUS_COMMON_MODULE); exit(0); }
void * producer( void * nitems_arg) { long i; long nitems; prod_data_t data; long thread_id; nitems = (long) nitems_arg; globus_mutex_init(&data.mutex, (globus_mutexattr_t *) GLOBUS_NULL); globus_cond_init(&data.cond, (globus_condattr_t *) GLOBUS_NULL); thread_id_assign(); thread_id = thread_id_get(); wait_for_all(); for (i = 0; i < nitems ; i++) { data.done = GLOBUS_FALSE; globus_mutex_lock(&queue_mutex); { globus_fifo_enqueue(&queue, &data); globus_cond_signal(&queue_cond); } globus_mutex_unlock(&queue_mutex); globus_mutex_lock(&data.mutex); { while(data.done == GLOBUS_FALSE) { # if (DEBUG_LEVEL > 1) { globus_stdio_lock(); { printf("%04ld: producer() - " "waiting for confirmation %d\n", thread_id, i); } globus_stdio_unlock(); } # endif globus_cond_wait(&data.cond, &data.mutex); } } globus_mutex_unlock(&data.mutex); } globus_cond_destroy(&data.cond); globus_mutex_destroy(&data.mutex); wait_for_all(); return NULL; }
void ADIOI_GRIDFTP_WriteDiscontig(ADIO_File fd, void *buf, int count, MPI_Datatype datatype, int file_ptr_type, ADIO_Offset offset, ADIO_Status *status, int *error_code) { char myname[]="ADIOI_GRIDFTP_WriteDiscontig"; int myrank,nprocs; MPI_Aint btype_size,btype_extent; MPI_Aint ftype_size,ftype_extent; MPI_Aint etype_size; MPI_Aint extent; ADIOI_Flatlist_node *flat_file; int buf_contig,boff,i,nblks; globus_off_t start,end,goff; globus_size_t bytes_written; globus_result_t result; MPI_Comm_rank(fd->comm,&myrank); MPI_Comm_size(fd->comm,&nprocs); etype_size=fd->etype_size; MPI_Type_size(fd->filetype,&ftype_size); MPI_Type_extent(fd->filetype,&ftype_extent); /* This is arguably unnecessary, as this routine assumes that the buffer in memory is contiguous */ MPI_Type_size(datatype,&btype_size); MPI_Type_extent(datatype,&btype_extent); ADIOI_Datatype_iscontig(datatype,&buf_contig); if ( ( btype_extent!=btype_size ) || ( ! buf_contig ) ) { FPRINTF(stderr,"[%d/%d] %s called with discontigous memory buffer\n", myrank,nprocs,myname); fflush(stderr); *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* from here we can assume btype_extent==btype_size */ /* Flatten out fd->filetype so we know which blocks to skip */ ADIOI_Flatten_datatype(fd->filetype); flat_file = ADIOI_Flatlist; while (flat_file->type != fd->filetype && flat_file->next!=NULL) flat_file = flat_file->next; /* Figure out how big the area to write is */ /* ASSUMPTION: ftype_size is an integer multiple of btype_size or vice versa. */ start=(globus_off_t)(offset*etype_size); goff=start; boff=0; extent=0; nblks=0; while ( boff < (count*btype_size) ) { int blklen; for (i=0;i<flat_file->count;i++) { if ( (boff+flat_file->blocklens[i]) < (count*btype_size) ) blklen=flat_file->blocklens[i]; else blklen=(count*btype_size)-boff; boff+=blklen; extent=MAX(extent,nblks*ftype_extent+flat_file->indices[i]+blklen); if ( boff>=(count*btype_size) ) break; } nblks++; } if ( extent < count*btype_size ) { FPRINTF(stderr,"[%d/%d] %s error in computing extent -- extent %d is smaller than total bytes requested %d!\n", myrank,nprocs,myname,extent,count*btype_size); fflush(stderr); *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } end=start+(globus_off_t)extent; FPRINTF(stderr,"[%d/%d] %s writing %d bytes into extent of %d bytes starting at offset %Ld\n", myrank,nprocs,myname,count*btype_size,extent,(long long)start); fflush(stderr); /* start up the globus partial write */ globus_mutex_init(&writediscontig_ctl_lock, GLOBUS_NULL); globus_cond_init(&writediscontig_ctl_cond, GLOBUS_NULL); writediscontig_ctl_done=GLOBUS_FALSE; if ( (result=globus_ftp_client_partial_put(&(gridftp_fh[fd->fd_sys]), fd->filename, &(oattr[fd->fd_sys]), GLOBUS_NULL, start, end, writediscontig_ctl_cb, GLOBUS_NULL))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_partial_get",myname,result); *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* Do all the actual I/Os */ boff=0; nblks=0; while ( boff < (count*btype_size) ) { int i,blklen; for (i=0;i<flat_file->count;i++) { if ( (boff+flat_file->blocklens[i]) < (count*btype_size) ) blklen=flat_file->blocklens[i]; else blklen=(count*btype_size)-boff; if ( blklen > 0 ) { goff=start+nblks*ftype_extent+((globus_off_t)flat_file->indices[i]); /* FPRINTF(stderr,"[%d/%d] %s writing %d bytes from boff=%d at goff=%Ld\n",myrank,nprocs,myname,blklen,boff,goff); */ if ( (result=globus_ftp_client_register_write(&(gridftp_fh[fd->fd_sys]), ((globus_byte_t *)buf)+boff, (globus_size_t)blklen, goff, GLOBUS_TRUE, writediscontig_data_cb, (void *)(&bytes_written)))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_register_write",myname,result); *error_code=MPI_ERR_IO; ADIOI_Error(fd,*error_code,myname); return; } boff+=blklen; if ( boff>=(count*btype_size) ) break; } } nblks++; } /* The ctl callback won't start till the data callbacks complete, so it's safe to wait on just the ctl callback */ globus_mutex_lock(&writediscontig_ctl_lock); while ( writediscontig_ctl_done!=GLOBUS_TRUE ) globus_cond_wait(&writediscontig_ctl_cond,&writediscontig_ctl_lock); globus_mutex_unlock(&writediscontig_ctl_lock); globus_mutex_destroy(&writediscontig_ctl_lock); globus_cond_destroy(&writediscontig_ctl_cond); #ifdef HAVE_STATUS_SET_BYTES MPIR_Status_set_bytes(status, datatype, bytes_written); #endif if (file_ptr_type != ADIO_EXPLICIT_OFFSET) { fd->fp_ind += extent; fd->fp_sys_posn = fd->fp_ind; } else { fd->fp_sys_posn = offset + extent; } }
int space_main( int argc, char ** argv) { int rc; globus_xio_stack_t stack; globus_xio_handle_t handle; globus_result_t res; globus_xio_attr_t attr; globus_condattr_t condattr; globus_l_closed = GLOBUS_FALSE; globus_l_close_called = GLOBUS_FALSE; rc = globus_module_activate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); res = globus_xio_attr_init(&attr); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); res = globus_xio_stack_init(&stack, NULL); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); parse_parameters(argc, argv, stack, attr); globus_callback_space_init(&globus_l_space, NULL); globus_condattr_init(&condattr); globus_condattr_setspace(&condattr, globus_l_space); globus_mutex_init(&globus_l_mutex, NULL); globus_cond_init(&globus_l_cond, &condattr); res = globus_xio_handle_create(&handle, stack); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); res = globus_xio_attr_cntl(attr, NULL, GLOBUS_XIO_ATTR_SET_SPACE, globus_l_space); res = globus_xio_register_open( handle, "whatever", attr, open_cb, argv[argc-1]); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); globus_mutex_lock(&globus_l_mutex); { while(!globus_l_closed) { globus_cond_wait(&globus_l_cond, &globus_l_mutex); } } globus_mutex_unlock(&globus_l_mutex); globus_xio_attr_destroy(attr); globus_xio_stack_destroy(stack); test_common_end(); globus_callback_space_destroy(globus_l_space); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); fprintf(stdout, "Success.\n"); return 0; }
void ADIOI_GRIDFTP_Open(ADIO_File fd, int *error_code) { static char myname[]="ADIOI_GRIDFTP_Open"; int myrank, nprocs, keyfound; char hintval[MPI_MAX_INFO_VAL+1]; globus_ftp_client_handleattr_t hattr; globus_result_t result; MPI_Comm_size(fd->comm, &nprocs); MPI_Comm_rank(fd->comm, &myrank); /* activate Globus ftp client module -- can be called multiple times, so it's safest to call once per file/connection */ globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); fd->fd_sys = num_gridftp_handles; /* No shared file pointers for now */ fd->shared_fp_fname = NULL; *error_code = MPI_SUCCESS; /* Access modes here mean something very different here than they would on a "real" filesystem... As a result, the amode and hint processing here is intermingled and a little weird because many of them have to do with the connection rather than the file itself. The thing that sucks about this is that read and write ops will have to check themselves if the file is being accessed rdonly, rdwr, or wronly. */ result=globus_ftp_client_handleattr_init(&hattr); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_handleattr_init", myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } result = globus_ftp_client_operationattr_init(&(oattr[fd->fd_sys])); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_operationattr_init", myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* Always use connection caching unless told otherwise */ result=globus_ftp_client_handleattr_set_cache_all(&hattr,GLOBUS_TRUE); if ( result !=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_handleattr_set_cache_all",myname,result); /* Assume that it's safe to cache a file if it's read-only */ if ( (fd->access_mode&ADIO_RDONLY) && (result=globus_ftp_client_handleattr_add_cached_url(&hattr,fd->filename))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_handleattr_add_cached_url",myname,result); /* Since we're (almost by definition) doing things that FTP S (stream) control mode can't handle, default to E (extended block) control mode for gsiftp:// URLs. ftp:// URLs use standard stream control mode by default. This behavior can be overridden by the ftp_control_mode hint. */ /* if ( !strncmp(fd->filename,"gsiftp:",7) && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_EXTENDED_BLOCK))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strncmp(fd->filename,"ftp:",4) && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_STREAM))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); */ /* Set append mode if necessary */ if ( (fd->access_mode&ADIO_APPEND) && ((result=globus_ftp_client_operationattr_set_append(&(oattr[fd->fd_sys]),GLOBUS_TRUE))!=GLOBUS_SUCCESS) ) globus_err_handler("globus_ftp_client_operationattr_set_append",myname,result); /* Other hint and amode processing that would affect hattr and/or oattr[] (eg. parallelism, striping, etc.) goes here */ if ( fd->info!=MPI_INFO_NULL ) { ADIOI_Info_get(fd->info,"ftp_control_mode",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { if ( ( !strcmp(hintval,"extended") || !strcmp(hintval,"extended_block") ) && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_EXTENDED_BLOCK))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strcmp(hintval,"block") && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_BLOCK))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strcmp(hintval,"compressed") && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_COMPRESSED))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strcmp(hintval,"stream") && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_STREAM))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); } ADIOI_Info_get(fd->info,"parallelism",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { int nftpthreads; if ( sscanf(hintval,"%d",&nftpthreads)==1 ) { globus_ftp_control_parallelism_t parallelism; parallelism.mode = GLOBUS_FTP_CONTROL_PARALLELISM_FIXED; parallelism.fixed.size = nftpthreads; if ( (result=globus_ftp_client_operationattr_set_parallelism(&(oattr[fd->fd_sys]), ¶llelism))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_parallelism",myname,result); } } ADIOI_Info_get(fd->info,"striped_ftp",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { /* if set to "true" or "enable", set up round-robin block layout */ if ( !strncmp("true",hintval,4) || !strncmp("TRUE",hintval,4) || !strncmp("enable",hintval,4) || !strncmp("ENABLE",hintval,4) ) { ADIOI_Info_get(fd->info,"striping_factor",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { int striping_factor; if ( sscanf(hintval,"%d",&striping_factor)==1 ) { globus_ftp_control_layout_t layout; layout.mode = GLOBUS_FTP_CONTROL_STRIPING_BLOCKED_ROUND_ROBIN; layout.round_robin.block_size = striping_factor; if ( (result=globus_ftp_client_operationattr_set_layout(&(oattr[fd->fd_sys]), &layout))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_layout", myname,result); } } } } ADIOI_Info_get(fd->info,"tcp_buffer",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { /* set tcp buffer size */ int buffer_size; if ( sscanf(hintval,"%d",&buffer_size)==1 ) { globus_ftp_control_tcpbuffer_t tcpbuf; tcpbuf.mode = GLOBUS_FTP_CONTROL_TCPBUFFER_FIXED; tcpbuf.fixed.size = buffer_size; if ( (result=globus_ftp_client_operationattr_set_tcp_buffer(&(oattr[fd->fd_sys]), &tcpbuf))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_tcp_buffer",myname,result); } } ADIOI_Info_get(fd->info,"transfer_type",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { globus_ftp_control_type_t filetype; /* set transfer type (i.e. ASCII or binary) */ if ( !strcmp("ascii",hintval) || !strcmp("ASCII",hintval) ) { filetype=GLOBUS_FTP_CONTROL_TYPE_ASCII; } else { filetype=GLOBUS_FTP_CONTROL_TYPE_IMAGE; } if ( (result=globus_ftp_client_operationattr_set_type(&(oattr[fd->fd_sys]),filetype))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_type",myname,result); } } else FPRINTF(stderr,"no MPI_Info object associated with %s\n",fd->filename); /* Create the ftp handle */ result=globus_ftp_client_handle_init(&(gridftp_fh[fd->fd_sys]),&hattr); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_handle_init",myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* Check for existence of the file */ globus_mutex_init(&lock, GLOBUS_NULL); globus_cond_init(&cond, GLOBUS_NULL); file_exists=GLOBUS_FALSE; exists_done=GLOBUS_FALSE; if ( myrank==0 ) { if ( (result=globus_ftp_client_exists(&(gridftp_fh[fd->fd_sys]), fd->filename, &(oattr[fd->fd_sys]), exists_cb, GLOBUS_NULL))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_exists",myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* wait till the callback completes */ globus_mutex_lock(&lock); while ( exists_done!=GLOBUS_TRUE ) globus_cond_wait(&cond,&lock); globus_mutex_unlock(&lock); } MPI_Barrier(fd->comm); MPI_Bcast(&file_exists,1,MPI_INT,0,fd->comm); /* It turns out that this is handled by MPI_File_open() directly */ if ( (file_exists!=GLOBUS_TRUE) && (fd->access_mode&ADIO_CREATE) && !(fd->access_mode&ADIO_EXCL) && !(fd->access_mode&ADIO_RDONLY) ) { if ( myrank==0 ) { /* if the file doesn't exist, write a single NULL to it */ globus_byte_t touchbuf=(globus_byte_t)'\0'; touch_ctl_done=GLOBUS_FALSE; if ( (result=globus_ftp_client_put(&(gridftp_fh[fd->fd_sys]), fd->filename, &(oattr[fd->fd_sys]), GLOBUS_NULL, touch_ctl_cb, GLOBUS_NULL))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_put",myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } result=globus_ftp_client_register_write(&(gridftp_fh[fd->fd_sys]), (globus_byte_t *)&touchbuf, 0, (globus_off_t)0, GLOBUS_TRUE, touch_data_cb, GLOBUS_NULL); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_register_write",myname,result); *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } globus_mutex_lock(&lock); while ( touch_ctl_done!=GLOBUS_TRUE ) globus_cond_wait(&cond,&lock); globus_mutex_unlock(&lock); } MPI_Barrier(fd->comm); } else if ( (fd->access_mode&ADIO_EXCL) && (file_exists==GLOBUS_TRUE) ) { fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", 0); return; } else if ( (fd->access_mode&ADIO_RDONLY) && (file_exists!=GLOBUS_TRUE) ) { if ( myrank==0 ) { FPRINTF(stderr,"WARNING: read-only file %s does not exist!\n",fd->filename); } } num_gridftp_handles++; }
/* submit a job without a callback contact, register a callback * contact, wait for job to terminate */ int test1() { char * callback_contact; char * job_contact; int rc; monitor_t monitor; rc = globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE); if(rc) { goto out; } globus_mutex_init(&monitor.mutex ,GLOBUS_NULL); globus_cond_init(&monitor.cond, GLOBUS_NULL); monitor.state = GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING; rc = globus_gram_client_callback_allow(gram_state_callback, &monitor, &callback_contact); if(rc != GLOBUS_SUCCESS) { fprintf(stderr, "Error creating callback contact %s.\n", globus_gram_client_error_string(rc)); goto error_exit; } globus_mutex_lock(&monitor.mutex); rc = globus_gram_client_job_request( resource_manager_contact, "&(executable=/bin/sleep)(arguments=10)", GLOBUS_GRAM_PROTOCOL_JOB_STATE_ALL, GLOBUS_NULL, &job_contact); if(rc != GLOBUS_SUCCESS) { fprintf(stderr, "Failed submitting job request because %s.\n", globus_gram_client_error_string(rc)); goto destroy_callback_contact; } rc = globus_gram_client_job_callback_register( job_contact, GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED| GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE, callback_contact, &monitor.state, &monitor.errorcode); if(rc != GLOBUS_SUCCESS) { fprintf(stderr, "Error registering callback contact because %s.\n", globus_gram_client_error_string(rc)); goto destroy_callback_contact; } while(monitor.state != GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED && monitor.state != GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE) { globus_cond_wait(&monitor.cond, &monitor.mutex); } rc = monitor.errorcode; destroy_callback_contact: globus_gram_client_callback_disallow(callback_contact); globus_libc_free(callback_contact); globus_libc_free(job_contact); globus_mutex_unlock(&monitor.mutex); error_exit: globus_mutex_destroy(&monitor.mutex); globus_cond_destroy(&monitor.cond); globus_module_deactivate(GLOBUS_GRAM_CLIENT_MODULE); out: return rc; }
globus_bool_t simple_dir_test( globus_ftp_control_handle_t * handle) { int ctr; int hi; int low; globus_result_t result; globus_ftp_control_host_port_t addr; char portmsg[256]; globus_mutex_init(&monitor.mutex, GLOBUS_NULL); globus_cond_init(&monitor.cond, GLOBUS_NULL); monitor.done = GLOBUS_FALSE; globus_mutex_init(&data_monitor.mutex, GLOBUS_NULL); globus_cond_init(&data_monitor.cond, GLOBUS_NULL); data_monitor.done = GLOBUS_FALSE; for(ctr = 0; ctr < TEST_ITERATIONS; ctr++) { monitor.done = GLOBUS_FALSE; monitor.rc = GLOBUS_TRUE; data_monitor.done = GLOBUS_FALSE; monitor.count = 0; globus_ftp_control_host_port_init(&addr, "localhost", 0); result = globus_ftp_control_local_pasv(handle, &addr); if (result != GLOBUS_SUCCESS) { verbose_printf(1, "globus_ftp_control_host_port_init failed\n"); return GLOBUS_FALSE; } hi = addr.port / 256; low = addr.port - (hi * 256); sprintf(portmsg, "PORT %d,%d,%d,%d,%d,%d\r\n", addr.host[0], addr.host[1], addr.host[2], addr.host[3], hi, low); verbose_printf(2, "@@@%s\n", portmsg); result = globus_ftp_control_send_command( handle, portmsg, simple_dir_response_callback, GLOBUS_NULL); if(result != GLOBUS_SUCCESS) { verbose_printf(1, "send_command PORT failed\n"); return GLOBUS_FALSE; } globus_mutex_lock(&monitor.mutex); { while(!monitor.done) { globus_cond_wait(&monitor.cond, &monitor.mutex); } } globus_mutex_unlock(&monitor.mutex); if (!monitor.rc) { return GLOBUS_FALSE; } } return GLOBUS_TRUE; }
int main( int argc, char ** argv) { globus_xio_driver_t tcp_driver; globus_xio_stack_t stack; globus_xio_handle_t xio_handle; globus_xio_server_t xio_server; globus_result_t res; char * cs; globus_gridftp_server_control_attr_t ftp_attr; globus_gridftp_server_control_t ftp_server; globus_xio_system_socket_t system_handle; globus_module_activate(GLOBUS_XIO_MODULE); globus_module_activate(GLOBUS_GRIDFTP_SERVER_CONTROL_MODULE); globus_mutex_init(&gs_l_mutex, NULL); globus_cond_init(&gs_l_cond, NULL); /* * set up the xio handle */ res = globus_xio_driver_load("tcp", &tcp_driver); test_res(res, __LINE__); res = globus_xio_stack_init(&stack, NULL); test_res(res, __LINE__); res = globus_xio_stack_push_driver(stack, tcp_driver); test_res(res, __LINE__); res = globus_xio_server_create(&xio_server, NULL, stack); test_res(res, __LINE__); globus_xio_stack_destroy(stack); res = globus_xio_server_get_contact_string(xio_server, &cs); test_res(res, __LINE__); fprintf(stdout, "%s\n", cs); globus_free(cs); res = globus_xio_server_accept(&xio_handle, xio_server); test_res(res, __LINE__); fprintf(stdout, "xio connection esstablished.\n"); /* * server connection is all set up, hand it to server_lib */ res = globus_gridftp_server_control_init(&ftp_server); test_res(res, __LINE__); res = globus_gridftp_server_control_attr_init(&ftp_attr); test_res(res, __LINE__); globus_xio_server_close(xio_server); if(argc > 1) { globus_gridftp_server_control_attr_set_security( ftp_attr, GLOBUS_GRIDFTP_SERVER_LIBRARY_GSSAPI | GLOBUS_GRIDFTP_SERVER_LIBRARY_NONE); } else { globus_gridftp_server_control_attr_set_security( ftp_attr, GLOBUS_GRIDFTP_SERVER_LIBRARY_NONE); } res = globus_gridftp_server_control_attr_set_auth( ftp_attr, auth_func, NULL); test_res(res, __LINE__); res = globus_gridftp_server_control_attr_set_resource( ftp_attr, globus_l_resource_cb, NULL); test_res(res, __LINE__); res = globus_gridftp_server_control_attr_set_list( ftp_attr, list_cb, NULL); test_res(res, __LINE__); res = globus_gridftp_server_control_attr_set_idle_time( ftp_attr, 900, 60); test_res(res, __LINE__); res = globus_gridftp_server_control_attr_set_banner( ftp_attr, "This is 1 line of banner\nthis is line 2\nline 3"); test_res(res, __LINE__); res = globus_gridftp_server_control_attr_set_message( ftp_attr, "Setting the message after login, 1 line\n"); test_res(res, __LINE__); res = globus_gridftp_server_control_attr_set_log( ftp_attr, logging_func, GLOBUS_GRIDFTP_SERVER_CONTROL_LOG_ALL, NULL); test_res(res, __LINE__); res = globus_gridftp_server_control_attr_data_functions( ftp_attr, active_connect, NULL, passive_connect, NULL, data_destroy_cb, NULL); res = globus_gridftp_server_control_attr_add_send( ftp_attr, NULL, transfer, NULL); test_res(res, __LINE__); res = globus_gridftp_server_control_attr_add_recv( ftp_attr, NULL, transfer, NULL); test_res(res, __LINE__); res = globus_xio_handle_cntl(xio_handle, tcp_driver, GLOBUS_XIO_TCP_GET_HANDLE, &system_handle); test_res(res, __LINE__); globus_gsc_959_command_add( ftp_server, "SITE MINE", globus_gs_cmd_site, GLOBUS_GSC_COMMAND_POST_AUTH, 2, 2, "SITE <sp> MINE!!!!", NULL); globus_mutex_lock(&globus_l_mutex); { res = globus_gridftp_server_control_start( ftp_server, ftp_attr, system_handle, globus_l_done_cb, FTP_USER_ARG); test_res(res, __LINE__); while(!globus_l_done) { globus_cond_wait(&globus_l_cond, &globus_l_mutex); } } globus_mutex_unlock(&globus_l_mutex); globus_xio_close(xio_handle, NULL); fprintf(stdout, "Ending...\n"); res = globus_gridftp_server_control_attr_destroy(ftp_attr); test_res(res, __LINE__); res = globus_gridftp_server_control_destroy(ftp_server); test_res(res, __LINE__); globus_module_deactivate(GLOBUS_GRIDFTP_SERVER_CONTROL_MODULE); globus_module_deactivate(GLOBUS_XIO_MODULE); return 0; }
int main( int argc, char * argv[]) { globus_io_handle_t listener; globus_io_handle_t server_handle; globus_io_handle_t client_handle; globus_io_attr_t attr; unsigned short port = 0; globus_result_t result; globus_io_secure_authorization_data_t auth_data; globus_l_io_authorization_test_monitor_t monitor; char greeting[] = "Hello, my friend."; char reply_buffer[256]; globus_size_t written; globus_size_t read_amt; LTDL_SET_PRELOADED_SYMBOLS(); globus_module_activate(GLOBUS_COMMON_MODULE); globus_module_activate(GLOBUS_IO_MODULE); /* Initialize monitor */ globus_mutex_init(&monitor.mutex, GLOBUS_NULL); globus_cond_init(&monitor.cond, GLOBUS_NULL); monitor.connected = GLOBUS_FALSE; /* Prepare attributes */ globus_io_secure_authorization_data_initialize(&auth_data); globus_io_tcpattr_init(&attr); globus_io_attr_set_secure_authentication_mode( &attr, GLOBUS_IO_SECURE_AUTHENTICATION_MODE_GSSAPI, GSS_C_NO_CREDENTIAL); if(argc >= 2) { if(! strcasecmp(argv[1], "self")) { globus_io_attr_set_secure_authorization_mode( &attr, GLOBUS_IO_SECURE_AUTHORIZATION_MODE_SELF, &auth_data); } else if(argc > 2 && ! strcasecmp(argv[1], "identity") ) { globus_io_secure_authorization_data_set_identity(&auth_data, argv[2]); globus_io_attr_set_secure_authorization_mode( &attr, GLOBUS_IO_SECURE_AUTHORIZATION_MODE_IDENTITY, &auth_data); } else if(! strcasecmp(argv[1], "callback")) { globus_io_secure_authorization_data_set_callback( &auth_data, globus_l_io_authorization_test_callback, GLOBUS_NULL); globus_io_attr_set_secure_authorization_mode( &attr, GLOBUS_IO_SECURE_AUTHORIZATION_MODE_CALLBACK, &auth_data); } else if(! strcasecmp(argv[1], "-callback")) { globus_io_secure_authorization_data_set_callback( &auth_data, globus_l_io_authorization_test_callback, (void *) 0x1); globus_io_attr_set_secure_authorization_mode( &attr, GLOBUS_IO_SECURE_AUTHORIZATION_MODE_CALLBACK, &auth_data); } else { goto no_authorization_mode; } } else { goto no_authorization_mode; } result = globus_io_tcp_create_listener( &port, -1, &attr, &listener); if(result != GLOBUS_SUCCESS) { char *msg = globus_error_print_friendly(globus_error_peek(result)); globus_libc_fprintf(stderr, "# Could not create listener: %s\n", msg); free(msg); goto error_exit; } result = globus_io_tcp_register_connect( "localhost", port, &attr, globus_l_io_authorization_test_connect_callback, &monitor, &client_handle); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not register connect\n"); goto error_exit; } result = globus_io_tcp_listen(&listener); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not listen for connections\n"); goto error_exit; } result = globus_io_tcp_accept(&listener, &attr, &server_handle); if(result != GLOBUS_SUCCESS) { if(strcasecmp(argv[1], "-callback") == 0) { globus_module_deactivate_all(); exit(0); } else { globus_libc_printf("# Could not accept connection\n"); goto error_exit; } } globus_mutex_lock(&monitor.mutex); while(! monitor.connected) { globus_cond_wait(&monitor.cond, &monitor.mutex); } result = globus_io_close(&listener); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not close listener\n"); goto error_exit; } result = globus_io_write(&server_handle, greeting, sizeof(greeting), &written); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not write greeting\n"); goto error_exit; } result = globus_io_close(&server_handle); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not close server\n"); goto error_exit; } result = globus_io_read(&client_handle, reply_buffer, sizeof(reply_buffer), sizeof(reply_buffer), &read_amt); if(result != GLOBUS_SUCCESS) { globus_object_t * err; err = globus_error_get(result); if(! globus_io_eof(err)) { globus_libc_printf("# Could not read greeting\n"); goto error_exit; } } result = globus_io_close(&client_handle); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not close client\n"); goto error_exit; } if(!memcmp(greeting, reply_buffer, sizeof(greeting)) == 0) { result = GLOBUS_FAILURE; goto error_exit; } globus_module_deactivate_all(); exit(0); no_authorization_mode: globus_libc_printf( "Usage: %s AUTHORIZATION\n" " AUTHORIZATION is one of\n" " self use Globus I/O's self-authorization mode\n" " identity \"subject\" use Globus I/O's subject-based authorization\n" " callback use Globus I/O's callback authorization\n" " -callback use Globus I/O's callback authorization with\n" " a failure callback\n", argv[0]); error_exit: globus_module_deactivate_all(); exit(1); }
int main( int argc, char ** argv) { globus_xio_stack_t stack; globus_xio_stack_t mode_e_stack; globus_xio_handle_t xio_handle; globus_xio_server_t server; globus_xio_attr_t attr = NULL; char * cs = NULL; globus_result_t res; int ctr; int num_streams = 1; globus_bool_t be_server = GLOBUS_FALSE; int rc; char filename[FILE_NAME_LEN]; FILE * fp; rc = globus_module_activate(GLOBUS_XIO_MODULE); globus_assert(rc == GLOBUS_SUCCESS); res = globus_xio_driver_load("mode_e", &mode_e_driver); test_res(res); res = globus_xio_driver_load("ordering", &ordering_driver); test_res(res); res = globus_xio_stack_init(&stack, NULL); test_res(res); res = globus_xio_stack_push_driver(stack, mode_e_driver); test_res(res); res = globus_xio_stack_push_driver(stack, ordering_driver); test_res(res); res = globus_xio_driver_load("tcp", &tcp_driver); test_res(res); res = globus_xio_stack_init(&mode_e_stack, NULL); test_res(res); res = globus_xio_stack_push_driver(mode_e_stack, tcp_driver); test_res(res); if (argc < 4) { help(); exit(1); } test_res(globus_xio_attr_init(&attr)); test_res(globus_xio_attr_cntl( attr, mode_e_driver, GLOBUS_XIO_MODE_E_SET_STACK, mode_e_stack)); for(ctr = 1; ctr < argc; ctr++) { if(strcmp(argv[ctr], "-h") == 0) { help(); return 0; } else if(strcmp(argv[ctr], "-c") == 0) { if (argc < 5) { help(); exit(1); } cs = argv[ctr + 1]; ctr++; } else if(strcmp(argv[ctr], "-s") == 0) { be_server = GLOBUS_TRUE; } else if(strcmp(argv[ctr], "-p") == 0) { if (argc < 6) { help(); exit(1); } port = atoi(argv[ctr+1]); /* test_res(globus_xio_attr_cntl( attr, mode_e_driver, GLOBUS_XIO_MODE_E_APPLY_ATTR_CNTLS, attr_cntl_cb));*/ } else if(strcmp(argv[ctr], "-P") == 0) { if (argc < 6) { help(); exit(1); } num_streams = atoi(argv[ctr+1]); test_res(globus_xio_attr_init(&attr)); test_res(globus_xio_attr_cntl( attr, ordering_driver, GLOBUS_XIO_ORDERING_SET_MAX_READ_COUNT, num_streams)); test_res(globus_xio_attr_cntl( attr, mode_e_driver, GLOBUS_XIO_MODE_E_SET_NUM_STREAMS, num_streams)); } else if(strcmp(argv[ctr], "-f") == 0) { if (ctr + 1 < argc) { strcpy(filename, argv[ctr + 1]); } else { help(); exit(1); } } } if (!be_server && (!cs || !*cs)) { help(); exit(1); } if(be_server) { globus_size_t size = CHUNK_SIZE + 1; int i, nbytes; res = globus_xio_server_create(&server, attr, stack); test_res(res); globus_xio_server_get_contact_string(server, &cs); fprintf(stdout, "Contact: %s\n", cs); res = globus_xio_server_accept(&xio_handle, server); test_res(res); res = globus_xio_open(xio_handle, NULL, attr); test_res(res); fp = fopen(filename, "w"); while(1) { char * buffer; buffer = (char *) globus_malloc(size); for (i=0; i<size; i++) buffer[i] = '\0'; res = globus_xio_read( xio_handle, buffer, size - 1, 1, &nbytes, NULL); fputs(buffer, fp); if (res != GLOBUS_SUCCESS) break; } res = globus_xio_close(xio_handle, NULL); test_res(res); res = globus_xio_server_close(server); test_res(res); res = globus_xio_driver_unload(mode_e_driver); test_res(res); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == GLOBUS_SUCCESS); } else { globus_size_t size = CHUNK_SIZE + 1; int nbytes; int i,x; res = globus_xio_handle_create(&xio_handle, stack); test_res(res); res = globus_xio_stack_destroy(stack); test_res(res); res = globus_xio_open(xio_handle, cs, attr); test_res(res); globus_mutex_init(&mutex, NULL); globus_cond_init(&cond, NULL); fp = fopen(filename, "r"); globus_mutex_lock(&mutex); while(!feof(fp)) { char * buffer; buffer = (char *) globus_malloc(size); for (i = 0; i < size; i++) buffer[i] = '\0'; x = fread(buffer, CHUNK_SIZE, 1, fp); nbytes = strlen(buffer); res = globus_xio_register_write( xio_handle, buffer, nbytes, nbytes, NULL, write_cb, NULL); test_res(res); ++y; } fclose(fp); /* test_res(globus_xio_data_descriptor_init(&dd, xio_handle)); test_res(globus_xio_data_descriptor_cntl( dd, mode_e_driver, GLOBUS_XIO_MODE_E_SEND_EOD, GLOBUS_TRUE)); res = globus_xio_write( xio_handle, buffer, nbytes, nbytes, &nbytes, NULL); test_res(res); */ while(y) { globus_cond_wait(&mutex, &cond); } globus_mutex_unlock(&mutex); res = globus_xio_close(xio_handle, attr); test_res(res); res = globus_xio_driver_unload(mode_e_driver); test_res(res); res = globus_xio_driver_unload(ordering_driver); test_res(res); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == GLOBUS_SUCCESS); globus_mutex_destroy(&mutex); globus_cond_destroy(&cond); } return 0; }
/* * Timeout test: * -t server|client * Configure the server or client to cause a timeout. If server is * selected, then it will delay its part of the operation longer than the * timeout value, causing the client to time out (and vice versa). * -T timeout-in-ms * Set the timeout value in ms * -a * Expect / cause the accept operation to delay longer than the timeout. * -r * Expect / cause a read operation to delay longer than the timeout. * */ int main( int argc, char * argv[]) { int rc; char * contact = NULL; globus_result_t result; globus_l_timeout_info_t client_timeout_info; globus_l_timeout_info_t server_timeout_info; globus_reltime_t timeout; client_timeout_info.cause_timeout = GLOBUS_TRUE; client_timeout_info.expect_timeout = GLOBUS_FALSE; server_timeout_info.cause_timeout = GLOBUS_FALSE; server_timeout_info.expect_timeout = GLOBUS_TRUE; client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; server_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; client_timeout_info.timeout = 1000; server_timeout_info.timeout = 1000; while ((rc = getopt(argc, argv, "t:T:arh")) != EOF) { switch (rc) { case 'h': usage(argv[0]); exit(0); case 't': if (strcmp(optarg, "client") == 0) { client_timeout_info.cause_timeout = GLOBUS_TRUE; client_timeout_info.expect_timeout = GLOBUS_FALSE; server_timeout_info.cause_timeout = GLOBUS_FALSE; server_timeout_info.expect_timeout = GLOBUS_TRUE; } else if (strcmp(optarg, "server") == 0) { client_timeout_info.cause_timeout = GLOBUS_FALSE; client_timeout_info.expect_timeout = GLOBUS_TRUE; server_timeout_info.cause_timeout = GLOBUS_TRUE; server_timeout_info.expect_timeout = GLOBUS_FALSE; } else { usage(argv[0]); exit(1); } break; case 'T': client_timeout_info.timeout = atoi(optarg); server_timeout_info.timeout = atoi(optarg); break; case 'a': client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; server_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; break; case 'r': client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_READ; server_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_READ; break; default: usage(argv[0]); exit(1); } } rc = http_test_initialize( &globus_l_tcp_driver, &globus_l_http_driver, &globus_l_http_stack); if (rc != GLOBUS_SUCCESS) { exit(2); } globus_mutex_init(&lock, NULL); globus_cond_init(&cond, NULL); GlobusTimeReltimeSet(timeout, 0, (server_timeout_info.timeout * 1000)); globus_xio_attr_init(&client_timeout_info.attr); globus_xio_attr_init(&server_timeout_info.attr); switch (server_timeout_info.timeout_state) { case GLOBUS_XIO_OPERATION_TYPE_ACCEPT: if (client_timeout_info.cause_timeout) { globus_xio_attr_cntl( server_timeout_info.attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_ACCEPT, globus_l_timeout_callback, &timeout, NULL); } else { fprintf(stderr, "Unable to handle server-caused accept timeout\n"); exit(6); } break; case GLOBUS_XIO_OPERATION_TYPE_READ: if (client_timeout_info.cause_timeout) { globus_xio_attr_cntl( server_timeout_info.attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_READ, globus_l_timeout_callback, &timeout, NULL); } else { globus_xio_attr_cntl( client_timeout_info.attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_READ, globus_l_timeout_callback, &timeout, NULL); } break; default: fprintf(stderr, "Error: invalid timeout state\n"); exit(3); } /* Set up client attributes */ globus_xio_attr_cntl( client_timeout_info.attr, globus_l_http_driver, GLOBUS_XIO_HTTP_ATTR_SET_REQUEST_METHOD, "POST"); /* Modulate timeout state to causer's related state for delaying */ if (client_timeout_info.cause_timeout) { switch (client_timeout_info.timeout_state) { case GLOBUS_XIO_OPERATION_TYPE_ACCEPT: client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_OPEN; break; case GLOBUS_XIO_OPERATION_TYPE_READ: client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_WRITE; break; case GLOBUS_XIO_OPERATION_TYPE_WRITE: case GLOBUS_XIO_OPERATION_TYPE_OPEN: case GLOBUS_XIO_OPERATION_TYPE_CLOSE: case GLOBUS_XIO_OPERATION_TYPE_FINISHED: case GLOBUS_XIO_OPERATION_TYPE_NONE: case GLOBUS_XIO_OPERATION_TYPE_DRIVER: case GLOBUS_XIO_OPERATION_TYPE_DD: case GLOBUS_XIO_OPERATION_TYPE_SERVER_INIT: fprintf(stderr, "Error: unexpected state: %d\n", client_timeout_info.state); exit(4); } } else { globus_assert(server_timeout_info.cause_timeout); switch (server_timeout_info.timeout_state) { case GLOBUS_XIO_OPERATION_TYPE_ACCEPT: fprintf(stderr, "Invalid option (server-caused accept timeout)\n"); exit(5); case GLOBUS_XIO_OPERATION_TYPE_READ: server_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_WRITE; break; case GLOBUS_XIO_OPERATION_TYPE_WRITE: case GLOBUS_XIO_OPERATION_TYPE_OPEN: case GLOBUS_XIO_OPERATION_TYPE_CLOSE: case GLOBUS_XIO_OPERATION_TYPE_FINISHED: case GLOBUS_XIO_OPERATION_TYPE_NONE: case GLOBUS_XIO_OPERATION_TYPE_DRIVER: case GLOBUS_XIO_OPERATION_TYPE_DD: case GLOBUS_XIO_OPERATION_TYPE_SERVER_INIT: fprintf(stderr, "Error: unexpected state: %d\n", server_timeout_info.state); exit(4); } } /* create server */ server_timeout_info.state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; server_timeout_info.handle = NULL; server_timeout_info.result = GLOBUS_SUCCESS; server_timeout_info.contact = NULL; result = globus_xio_server_create( &server_timeout_info.server, server_timeout_info.attr, globus_l_http_stack); result = globus_xio_server_get_contact_string( server_timeout_info.server, &contact); client_timeout_info.contact = globus_common_create_string("http://%s/%s", contact, "ok"); /* create client handle */ client_timeout_info.state = GLOBUS_XIO_OPERATION_TYPE_OPEN; client_timeout_info.handle = NULL; client_timeout_info.result = GLOBUS_SUCCESS; client_timeout_info.server = NULL; result = globus_xio_handle_create( &client_timeout_info.handle, globus_l_http_stack); /* oneshot to start server state machine */ result = globus_callback_register_oneshot( NULL, &globus_i_reltime_zero, state_machine, &server_timeout_info); /* oneshot to start client state machine */ result = globus_callback_register_oneshot( NULL, &globus_i_reltime_zero, state_machine, &client_timeout_info); /* wait for both state machines to terminate */ globus_mutex_lock(&lock); while (client_timeout_info.state != GLOBUS_XIO_OPERATION_TYPE_NONE && server_timeout_info.state != GLOBUS_XIO_OPERATION_TYPE_NONE) { globus_cond_wait(&cond, &lock); } globus_mutex_unlock(&lock); globus_mutex_destroy(&lock); globus_module_deactivate_all(); return (client_timeout_info.result || server_timeout_info.result || client_timeout_info.expect_timeout || server_timeout_info.expect_timeout); }
int main(int argc, char * argv[]) { globus_ftp_client_handle_t handle; globus_ftp_client_operationattr_t attr; globus_result_t result; globus_ftp_client_handleattr_t handle_attr; char * src = NULL; char * dst = NULL; struct tm modtime; extern char * optarg; extern int optind; int c; globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); globus_ftp_client_handleattr_init(&handle_attr); globus_ftp_client_operationattr_init(&attr); globus_mutex_init(&lock, GLOBUS_NULL); globus_cond_init(&cond, GLOBUS_NULL); test_parse_args(argc, argv, &handle_attr, &attr, &src, &dst); optind = 1; while((c = getopt(argc, argv, "T:")) != -1) { switch(c) { case 'T': memset(&modtime, 0, sizeof(modtime)); if (sscanf(optarg, "%4d%2d%2d%2d%2d%2d", &modtime.tm_year, &modtime.tm_mon, &modtime.tm_mday, &modtime.tm_hour, &modtime.tm_min, &modtime.tm_sec) != 6) { printf("Invalid time format\n"); return GLOBUS_TRUE; } modtime.tm_year -= 1900; modtime.tm_mon -= 1; break; } } globus_ftp_client_operationattr_set_type(&attr, GLOBUS_FTP_CONTROL_TYPE_ASCII); globus_ftp_client_handleattr_set_cache_all(&handle_attr, GLOBUS_TRUE); globus_ftp_client_handle_init(&handle, &handle_attr); done = GLOBUS_FALSE; result = globus_ftp_client_utime(&handle, src, &modtime, &attr, done_cb, 0); if(result != GLOBUS_SUCCESS) { done = GLOBUS_TRUE; } globus_mutex_lock(&lock); while(!done) { globus_cond_wait(&cond, &lock); } globus_mutex_unlock(&lock); globus_ftp_client_handle_destroy(&handle); globus_module_deactivate_all(); if(test_abort_count && error) { return 0; } return error; }
static int globus_l_job_manager_module_activate(void) { time_t timestamp_val; globus_l_job_manager_logfile_state_t * logfile_state; int rc; globus_reltime_t delay; globus_result_t result; char * scheduler; rc = globus_module_activate(GLOBUS_COMMON_MODULE); if (rc != GLOBUS_SUCCESS) { goto activate_common_failed; } rc = globus_mutex_init(&globus_l_job_manager_mutex, NULL); if (rc != GLOBUS_SUCCESS) { goto mutex_init_failed; } rc = globus_cond_init(&globus_l_job_manager_cond, NULL); if (rc != GLOBUS_SUCCESS) { goto cond_init_failed; } shutdown_called = GLOBUS_FALSE; callback_count = 0; GlobusDebugInit( SEG_JOB_MANAGER, SEG_JOB_MANAGER_DEBUG_INFO SEG_JOB_MANAGER_DEBUG_WARN SEG_JOB_MANAGER_DEBUG_ERROR SEG_JOB_MANAGER_DEBUG_TRACE); logfile_state = calloc(1, sizeof(globus_l_job_manager_logfile_state_t)); if (logfile_state == NULL) { goto calloc_state_failed; } /* Configuration info */ result = globus_scheduler_event_generator_get_timestamp(×tamp_val); if (result != GLOBUS_SUCCESS) { goto get_timestamp_failed; } if (timestamp_val != 0) { if (globus_libc_gmtime_r( ×tamp_val, &logfile_state->start_timestamp) == NULL) { goto gmtime_failed; } } scheduler = globus_libc_getenv(JOB_MANAGER_SEG_SCHEDULER); if (scheduler == NULL) { SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_ERROR, ("Error: %s not set\n", JOB_MANAGER_SEG_SCHEDULER)); result = GLOBUS_FAILURE; goto get_scheduler_failed; } if (getenv(JOB_MANAGER_SEG_LOG_PATH)) { logfile_state->log_dir = strdup(getenv(JOB_MANAGER_SEG_LOG_PATH)); } else { char * log_dir_pattern = globus_common_create_string( "${localstatedir}/lib/globus/globus-seg-%s", scheduler); globus_eval_path(log_dir_pattern, &logfile_state->log_dir); free(log_dir_pattern); } if (logfile_state->log_dir == NULL) { SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_ERROR, ("Error: out of memory\n")); goto get_path_failed; } /* Convert timestamp to filename */ rc = globus_l_job_manager_find_logfile(logfile_state); if (rc == GLOBUS_SUCCESS) { logfile_state->fp = fopen(logfile_state->path, "r"); if (logfile_state->fp == NULL) { rc = SEG_JOB_MANAGER_ERROR_OUT_OF_MEMORY; goto fopen_failed; } GlobusTimeReltimeSet(delay, 0, 0); } else if(rc == SEG_JOB_MANAGER_ERROR_LOG_NOT_PRESENT) { GlobusTimeReltimeSet(delay, 1, 0); } else { goto bad_log_path; } result = globus_callback_register_oneshot( &logfile_state->callback, &delay, globus_l_job_manager_poll_callback, logfile_state); if (result != GLOBUS_SUCCESS) { goto oneshot_failed; } callback_count++; return 0; oneshot_failed: if (logfile_state->fp) { fclose(logfile_state->fp); } fopen_failed: if (logfile_state->path) { free(logfile_state->path); } bad_log_path: free(logfile_state->log_dir); get_path_failed: get_scheduler_failed: get_timestamp_failed: gmtime_failed: free(logfile_state); calloc_state_failed: globus_cond_destroy(&globus_l_job_manager_cond); cond_init_failed: globus_mutex_destroy(&globus_l_job_manager_mutex); mutex_init_failed: globus_module_deactivate(GLOBUS_COMMON_MODULE); activate_common_failed: return 1; }
int main() { gss_cred_id_t credential; int listen_fd; int accept_fd; struct sockaddr_in address = {0}; globus_sockaddr_t connect_address; globus_socklen_t connect_address_len = sizeof(connect_address); struct thread_arg * arg = NULL; globus_thread_t thread_handle; int i; int ret; int error; LTDL_SET_PRELOADED_SYMBOLS(); globus_thread_set_model(THREAD_MODEL); globus_module_activate(GLOBUS_COMMON_MODULE); globus_module_activate(GLOBUS_GSI_GSSAPI_MODULE); printf("1..%d\n", NUM_CLIENTS); /* initialize global mutex */ globus_mutex_init(&mutex, NULL); /* and the condition variable */ globus_cond_init(&done, NULL); /* setup listener */ address.sin_family = AF_INET; address.sin_port = 0; address.sin_addr.s_addr = htonl(INADDR_LOOPBACK); listen_fd = socket(AF_INET, SOCK_STREAM, 0); if (listen_fd == 0) { perror("socket"); exit(EXIT_FAILURE); } ret = bind(listen_fd, (struct sockaddr *) &address, sizeof(struct sockaddr_in)); if (ret != 0) { perror("bind"); exit(EXIT_FAILURE); } ret = getsockname(listen_fd, (struct sockaddr *) &connect_address, &connect_address_len); if (ret != 0) { perror("getsockname"); exit(EXIT_FAILURE); } ret = listen(listen_fd, -1); if (ret != 0) { perror("listen"); exit(EXIT_FAILURE); } /* acquire credentials */ credential = globus_gsi_gssapi_test_acquire_credential(); if(credential == GSS_C_NO_CREDENTIAL) { fprintf(stderr,"Unable to aquire credential\n"); exit(-1); } /* start the clients here */ for(i=0;i<NUM_CLIENTS;i++) { arg = malloc(sizeof(struct thread_arg)); arg->address = &connect_address; arg->len = connect_address_len; arg->credential = credential; globus_mutex_lock(&mutex); { client_thread_count++; } globus_mutex_unlock(&mutex); globus_thread_create(&thread_handle,NULL,client_func,(void *) arg); } /* accept connections */ globus_mutex_lock(&mutex); while (client_thread_count > 0) { while (pending_connects > 0) { accept_fd = accept(listen_fd,NULL,0); if(accept_fd < 0) { perror("accept"); abort(); } arg = malloc(sizeof(struct thread_arg)); arg->fd = accept_fd; arg->credential = credential; server_thread_count++; pending_connects--; globus_thread_create(&thread_handle,NULL,server_func,(void *) arg); } globus_cond_wait(&done, &mutex); } /* wait for last thread to terminate */ while (server_thread_count > 0) { globus_cond_wait(&done, &mutex); } globus_mutex_unlock(&mutex); /* destroy global mutex */ globus_mutex_destroy(&mutex); /* and the condition variable */ globus_cond_destroy(&done); /* close the listener */ close(listen_fd); /* release credentials */ globus_gsi_gssapi_test_release_credential(&credential); globus_module_deactivate_all(); exit(client_failed); }
int main(int argc, char *argv[]) { globus_ftp_client_handle_t handle; globus_ftp_client_operationattr_t attr; globus_byte_t * buffer; globus_size_t buffer_length; globus_result_t result; char * src; char * dst; globus_ftp_client_handleattr_t handle_attr; globus_ftp_control_mode_t mode; int i; globus_ftp_control_parallelism_t parallelism; globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); globus_ftp_client_handleattr_init(&handle_attr); globus_ftp_client_operationattr_init(&attr); parallelism.mode = GLOBUS_FTP_CONTROL_PARALLELISM_FIXED; parallelism.fixed.size = 1; mode = GLOBUS_FTP_CONTROL_MODE_STREAM; for(i = 1; i < argc; i++) { if(strcmp(argv[i], "-P") == 0 && i + 1 < argc) { mode = GLOBUS_FTP_CONTROL_MODE_EXTENDED_BLOCK; parallelism.mode = GLOBUS_FTP_CONTROL_PARALLELISM_FIXED; parallelism.fixed.size = atoi(argv[i+1]); test_remove_arg(&argc, argv, &i, 1); } } test_parse_args(argc, argv, &handle_attr, &attr, &src, &dst); buffer = globus_libc_malloc(SIZE); buffer_length = SIZE; globus_mutex_init(&lock, GLOBUS_NULL); globus_cond_init(&cond, GLOBUS_NULL); globus_ftp_client_operationattr_set_mode(&attr, mode); globus_ftp_client_operationattr_set_parallelism(&attr, ¶llelism); globus_ftp_client_operationattr_set_read_all(&attr, GLOBUS_TRUE, intermediate_cb, GLOBUS_NULL); globus_ftp_client_handle_init(&handle, &handle_attr); done = GLOBUS_FALSE; result = globus_ftp_client_get(&handle, src, &attr, GLOBUS_NULL, done_cb, 0); if(result != GLOBUS_SUCCESS) { fprintf(stderr, globus_object_printable_to_string(globus_error_get(result))); error = GLOBUS_TRUE; done = GLOBUS_TRUE; } else { globus_ftp_client_register_read( &handle, buffer, buffer_length, data_cb, 0); } globus_mutex_lock(&lock); while(!done) { globus_cond_wait(&cond, &lock); } globus_mutex_unlock(&lock); globus_ftp_client_handle_destroy(&handle); globus_libc_free(buffer); globus_module_deactivate_all(); if(test_abort_count && error) { return 0; } return error; }
globus_result_t gridftp_init(gridftp_op_type_t OpType, globus_gfs_operation_t Operation, globus_gfs_transfer_info_t * TransferInfo, buffer_handle_t * BufferHandle, msg_handle_t * MsgHandle, gridftp_eof_callback_t EofCallbackFunc, void * EofCallbackArg, gridftp_t ** GridFTP) { globus_off_t offset = 0; globus_off_t length = 0; globus_result_t result = GLOBUS_SUCCESS; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); /* Allocate the handle. */ *GridFTP = (gridftp_t *) globus_calloc(1, sizeof(gridftp_t)); if (*GridFTP == NULL) { result = GlobusGFSErrorMemory("gridftp_t"); goto cleanup; } /* Initialize the entries. */ (*GridFTP)->OpType = OpType; (*GridFTP)->Operation = Operation; (*GridFTP)->BufferHandle = BufferHandle; (*GridFTP)->MsgHandle = MsgHandle; (*GridFTP)->EofCallbackFunc = EofCallbackFunc; (*GridFTP)->EofCallbackArg = EofCallbackArg; (*GridFTP)->EofCallbackCalled = GLOBUS_FALSE; (*GridFTP)->Eof = GLOBUS_FALSE; (*GridFTP)->Stop = GLOBUS_FALSE; (*GridFTP)->Result = GLOBUS_SUCCESS; (*GridFTP)->OpCount = 0; (*GridFTP)->PrivateBufferID = buffer_create_private_list(BufferHandle); globus_mutex_init(&(*GridFTP)->Lock, NULL); globus_cond_init(&(*GridFTP)->Cond, NULL); /* On retrieves... */ if (OpType == GRIDFTP_OP_TYPE_RETR) { /* Generate the stream range list. */ result = range_list_init(&(*GridFTP)->StreamRanges); if (result != GLOBUS_SUCCESS) goto cleanup; /* Fill the range list. */ result = range_list_fill_retr_range((*GridFTP)->StreamRanges, TransferInfo); if (result != GLOBUS_SUCCESS) goto cleanup; } /* * We need to call the appropriate _get_read/write_range() function. * It will setup Operation to return the correct file offsets. Without * this call, our first read callback would always return 0 for streams mode * regardless of REST commands. And since we can not tell streams mode from * extended block mode, this is critical. We do not need to use offset or * length; just making the call is good enough. */ switch (OpType) { case GRIDFTP_OP_TYPE_RETR: globus_gridftp_server_get_read_range(Operation, &offset, &length); break; case GRIDFTP_OP_TYPE_STOR: globus_gridftp_server_get_write_range(Operation, &offset, &length); break; } cleanup: if (result != GLOBUS_SUCCESS) { GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return GLOBUS_SUCCESS; }
int main(int argc, char *argv[]) { globus_ftp_client_handle_t handle; globus_ftp_client_operationattr_t attr; globus_ftp_client_handleattr_t handle_attr; globus_byte_t buffer[SIZE]; globus_size_t buffer_length = sizeof(buffer); globus_result_t result; globus_off_t size; char * src; char * dst; LTDL_SET_PRELOADED_SYMBOLS(); globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); globus_ftp_client_handleattr_init(&handle_attr); globus_ftp_client_operationattr_init(&attr); test_parse_args(argc, argv, &handle_attr, &attr, &src, &dst); globus_mutex_init(&lock, GLOBUS_NULL); globus_cond_init(&cond, GLOBUS_NULL); globus_ftp_client_handle_init(&handle, &handle_attr); done = GLOBUS_FALSE; result = globus_ftp_client_size(&handle, src, &attr, &size, done_cb, 0); if(result != GLOBUS_SUCCESS) { fprintf(stderr, "%s", globus_object_printable_to_string(globus_error_get(result))); error = GLOBUS_TRUE; done = GLOBUS_TRUE; } globus_mutex_lock(&lock); while(!done) { globus_cond_wait(&cond, &lock); } globus_mutex_unlock(&lock); globus_ftp_client_handle_destroy(&handle); globus_module_deactivate_all(); if(test_abort_count && error) { return 0; } if(error == GLOBUS_SUCCESS) { printf("%"GLOBUS_OFF_T_FORMAT"\n", size); } return error; }
void ADIOI_GRIDFTP_WriteContig(ADIO_File fd, void *buf, int count, MPI_Datatype datatype, int file_ptr_type, ADIO_Offset offset, ADIO_Status *status, int *error_code) { char myname[]="ADIOI_GRIDFTP_WriteContig"; int myrank, nprocs, datatype_size; globus_size_t len,bytes_written=0; globus_off_t goff; globus_result_t result; if ( fd->access_mode&ADIO_RDONLY ) { *error_code=MPI_ERR_AMODE; return; } *error_code = MPI_SUCCESS; MPI_Comm_size(fd->comm, &nprocs); MPI_Comm_rank(fd->comm, &myrank); MPI_Type_size(datatype, &datatype_size); if (file_ptr_type != ADIO_EXPLICIT_OFFSET) { offset = fd->fp_ind; } /* Do the gridftp I/O transfer */ goff = (globus_off_t)offset; len = ((globus_size_t)datatype_size)*((globus_size_t)count); globus_mutex_init(&writecontig_ctl_lock, GLOBUS_NULL); globus_cond_init(&writecontig_ctl_cond, GLOBUS_NULL); writecontig_ctl_done=GLOBUS_FALSE; if ( (result=globus_ftp_client_partial_put(&(gridftp_fh[fd->fd_sys]), fd->filename, &(oattr[fd->fd_sys]), GLOBUS_NULL, goff, goff+(globus_off_t)len, writecontig_ctl_cb, GLOBUS_NULL))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_partial_put",myname,result); *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } if ( (result=globus_ftp_client_register_write(&(gridftp_fh[fd->fd_sys]), (globus_byte_t *)buf, len, goff, GLOBUS_TRUE, writecontig_data_cb, (void *)(&bytes_written)))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_register_write",myname,result); *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* The ctl callback won't start till the data callbacks complete, so it's safe to wait on just the ctl callback */ globus_mutex_lock(&writecontig_ctl_lock); while ( writecontig_ctl_done!=GLOBUS_TRUE ) globus_cond_wait(&writecontig_ctl_cond,&writecontig_ctl_lock); globus_mutex_unlock(&writecontig_ctl_lock); globus_mutex_destroy(&writecontig_ctl_lock); globus_cond_destroy(&writecontig_ctl_cond); #ifdef HAVE_STATUS_SET_BYTES MPIR_Status_set_bytes(status, datatype, bytes_written); #endif if (file_ptr_type != ADIO_EXPLICIT_OFFSET) { offset = fd->fp_ind; fd->fp_ind += bytes_written; fd->fp_sys_posn = fd->fp_ind; } else { fd->fp_sys_posn = offset + bytes_written; } }