/*---------------------------------------------------------------------------*/ HG_TEST_RPC_CB(hg_test_bulk_write, handle) { struct hg_info *hg_info = NULL; hg_bulk_t origin_bulk_handle = HG_BULK_NULL; hg_bulk_t local_bulk_handle = HG_BULK_NULL; struct hg_test_bulk_args *bulk_args = NULL; bulk_write_in_t in_struct; hg_return_t ret = HG_SUCCESS; int fildes; hg_op_id_t hg_bulk_op_id; bulk_args = (struct hg_test_bulk_args *) malloc( sizeof(struct hg_test_bulk_args)); /* Keep handle to pass to callback */ bulk_args->handle = handle; /* Get info from handle */ hg_info = HG_Get_info(handle); /* Get input parameters and data */ ret = HG_Get_input(handle, &in_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get input\n"); return ret; } /* Get parameters */ fildes = in_struct.fildes; origin_bulk_handle = in_struct.bulk_handle; bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle); bulk_args->fildes = fildes; /* Create a new block handle to read the data */ HG_Bulk_create(hg_info->hg_class, 1, NULL, (hg_size_t *) &bulk_args->nbytes, HG_BULK_READWRITE, &local_bulk_handle); /* Pull bulk data */ ret = HG_Bulk_transfer(hg_info->context, hg_test_bulk_transfer_cb, bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, 0, local_bulk_handle, 0, bulk_args->nbytes, &hg_bulk_op_id); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not read bulk data\n"); return ret; } /* Test HG_Bulk_Cancel() */ if (fildes < 0) { ret = HG_Bulk_cancel(hg_bulk_op_id); if (ret != HG_SUCCESS){ fprintf(stderr, "Could not cancel bulk data\n"); return ret; } } HG_Free_input(handle, &in_struct); return ret; }
/** * The routine that sets up the routines that actually do the work. * This 'handle' parameter is the only value passed to this callback, but * Mercury routines allow us to query information about the context in which * we are called. */ static hg_return_t snappy_compress_cb(hg_handle_t handle) { struct snappy_transfer_args *snappy_transfer_args; size_t input_length; snappy_transfer_args = (struct snappy_transfer_args *) malloc(sizeof(struct snappy_transfer_args)); snappy_transfer_args->handle = handle; /* Get input parameters sent on origin through on HG_Forward() */ HG_Get_input(handle, &snappy_transfer_args->snappy_compress_input); /* Now set up the bulk transfer and get the input length */ input_length = HG_Bulk_get_size( snappy_transfer_args->snappy_compress_input.input_bulk_handle); /* The bulk 'handle' is basically a pointer, with the addition that 'handle' * could refer to more than one memory region. */ HG_Bulk_create(HG_Get_info(handle)->hg_bulk_class, 1, NULL, &input_length, HG_BULK_READWRITE, &snappy_transfer_args->local_input_bulk_handle); /* Pull data from origin's memory into our own */ /* Another way to do this is via HG_Bulk_access, which would allow mercury, * if "co-resident" to avoid a copy of data */ HG_Bulk_transfer(HG_Get_info(handle)->bulk_context, snappy_pull_cb, snappy_transfer_args, HG_BULK_PULL, HG_Get_info(handle)->addr, snappy_transfer_args->snappy_compress_input.input_bulk_handle, 0, /* origin */ snappy_transfer_args->local_input_bulk_handle, 0, /* local */ input_length, HG_OP_ID_IGNORE); return HG_SUCCESS; }
/*---------------------------------------------------------------------------*/ HG_TEST_RPC_CB(hg_test_posix_write, handle) { hg_return_t ret = HG_SUCCESS; struct hg_info *hg_info = NULL; hg_bulk_t origin_bulk_handle = HG_BULK_NULL; hg_bulk_t local_bulk_handle = HG_BULK_NULL; struct hg_test_bulk_args *bulk_args = NULL; bulk_write_in_t in_struct; bulk_args = (struct hg_test_bulk_args *) malloc( sizeof(struct hg_test_bulk_args)); /* Keep handle to pass to callback */ bulk_args->handle = handle; /* Get info from handle */ hg_info = HG_Get_info(handle); /* Get input struct */ ret = HG_Get_input(handle, &in_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get input struct\n"); return ret; } origin_bulk_handle = in_struct.bulk_handle; /* Create a new block handle to read the data */ bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle); bulk_args->fildes = in_struct.fildes; /* Create a new bulk handle to read the data */ HG_Bulk_create(hg_info->hg_class, 1, NULL, (hg_size_t *) &bulk_args->nbytes, HG_BULK_READWRITE, &local_bulk_handle); /* Pull bulk data */ ret = HG_Bulk_transfer(hg_info->context, hg_test_posix_write_transfer_cb, bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, 0, local_bulk_handle, 0, bulk_args->nbytes, HG_OP_ID_IGNORE); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not read bulk data\n"); return ret; } HG_Free_input(handle, &in_struct); return ret; }
HG_TEST_RPC_CB(hg_test_posix_open, handle) { hg_return_t ret = HG_SUCCESS; open_in_t in_struct; open_out_t out_struct; const char *path; int flags; mode_t mode; int open_ret; /* Get input struct */ ret = HG_Get_input(handle, &in_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get input struct\n"); return ret; } path = in_struct.path; flags = in_struct.flags; mode = in_struct.mode; /* Call open */ printf("Calling open with path: %s\n", path); open_ret = open(path, flags, mode); /* Fill output structure */ out_struct.ret = open_ret; /* Send response back */ ret = HG_Respond(handle, NULL, NULL, &out_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not respond\n"); return ret; } HG_Free_input(handle, &in_struct); HG_Destroy(handle); return ret; }
/*---------------------------------------------------------------------------*/ HG_TEST_RPC_CB(hg_test_rpc_open, handle) { hg_return_t ret = HG_SUCCESS; rpc_open_in_t in_struct; rpc_open_out_t out_struct; hg_const_string_t path; rpc_handle_t rpc_handle; int event_id; int open_ret; /* Get input buffer */ ret = HG_Get_input(handle, &in_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get input\n"); return ret; } /* Get parameters */ path = in_struct.path; rpc_handle = in_struct.handle; /* Call rpc_open */ open_ret = rpc_open(path, rpc_handle, &event_id); /* Fill output structure */ out_struct.event_id = event_id; out_struct.ret = open_ret; /* Send response back */ ret = HG_Respond(handle, NULL, NULL, &out_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not respond\n"); return ret; } HG_Free_input(handle, &in_struct); HG_Destroy(handle); return ret; }
/* HG_svrec_add_ult() -- handler */ void HG_svrec_add_ult(hg_handle_t h) { int ret; sv_rec_remove_in_t in; sv_rec_remove_out_t out; struct hg_info *hgi; margo_instance_id mid; hg_size_t sz; hg_bulk_t lbh; /* local bulk handle */ void *p; ret = HG_Get_input(h, &in); assert(ret == HG_SUCCESS); hgi = HG_Get_info(h); mid = margo_hg_class_to_instance(hgi->hg_class); assert(rec_list != NULL); assert(rec_ct < rec_list_sz); p = &rec_list[rec_ct]; sz = sizeof(hg_sv_rec_t); ret = HG_Bulk_create(hgi->hg_class, 1, (void **) &p, &sz, HG_BULK_READWRITE, &lbh); assert(ret == HG_SUCCESS); ret = margo_bulk_transfer(mid, HG_BULK_PULL, hgi->addr, in.b, 0, lbh, 0, sz); assert(!ret); printf(" added %s\n", rec_list[rec_ct].addr); rec_ct++; out.ret = 0; ret = margo_respond(mid, h, &out); assert(!ret); ret = HG_Destroy(h); assert(ret == HG_SUCCESS); return; }
/*---------------------------------------------------------------------------*/ HG_TEST_RPC_CB(hg_test_posix_close, handle) { hg_return_t ret = HG_SUCCESS; close_in_t in_struct; close_out_t out_struct; int fd; int close_ret; /* Get input struct */ ret = HG_Get_input(handle, &in_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get input struct\n"); return ret; } fd = in_struct.fd; /* Call close */ printf("Calling close with fd: %d\n", fd); close_ret = close(fd); /* Fill output structure */ out_struct.ret = close_ret; /* Send response back */ ret = HG_Respond(handle, NULL, NULL, &out_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not respond\n"); return ret; } HG_Free_input(handle, &in_struct); HG_Destroy(handle); return ret; }
/*---------------------------------------------------------------------------*/ HG_TEST_RPC_CB(hg_test_posix_read, handle) { hg_return_t ret = HG_SUCCESS; struct hg_info *hg_info = NULL; hg_bulk_t origin_bulk_handle = HG_BULK_NULL; hg_bulk_t local_bulk_handle = HG_BULK_NULL; struct hg_test_bulk_args *bulk_args = NULL; bulk_write_in_t in_struct; void *buf; ssize_t read_ret; /* for debug */ int i; const int *buf_ptr; bulk_args = (struct hg_test_bulk_args *) malloc( sizeof(struct hg_test_bulk_args)); /* Keep handle to pass to callback */ bulk_args->handle = handle; /* Get info from handle */ hg_info = HG_Get_info(handle); /* Get input struct */ ret = HG_Get_input(handle, &in_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get input struct\n"); return ret; } origin_bulk_handle = in_struct.bulk_handle; /* Create a new block handle to read the data */ bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle); bulk_args->fildes = in_struct.fildes; /* Create a new bulk handle to read the data */ HG_Bulk_create(hg_info->hg_class, 1, NULL, (hg_size_t *) &bulk_args->nbytes, HG_BULK_READ_ONLY, &local_bulk_handle); /* Call bulk_write */ HG_Bulk_access(local_bulk_handle, 0, bulk_args->nbytes, HG_BULK_READWRITE, 1, &buf, NULL, NULL); printf("Calling read with fd: %d\n", in_struct.fildes); read_ret = read(in_struct.fildes, buf, bulk_args->nbytes); /* Check bulk buf */ buf_ptr = (const int*) buf; for (i = 0; i < (int)(bulk_args->nbytes / sizeof(int)); i++) { if (buf_ptr[i] != i) { printf("Error detected after read, buf[%d] = %d, was expecting %d!\n", i, buf_ptr[i], i); break; } } /* Fill output structure */ bulk_args->ret = read_ret; /* Push bulk data */ ret = HG_Bulk_transfer(hg_info->context, hg_test_posix_read_transfer_cb, bulk_args, HG_BULK_PUSH, hg_info->addr, origin_bulk_handle, 0, local_bulk_handle, 0, bulk_args->nbytes, HG_OP_ID_IGNORE); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not read bulk data\n"); return ret; } HG_Free_input(handle, &in_struct); return ret; }
/*---------------------------------------------------------------------------*/ HG_TEST_RPC_CB(hg_test_bulk_seg_write, handle) { struct hg_info *hg_info = NULL; hg_bulk_t origin_bulk_handle = HG_BULK_NULL; hg_bulk_t local_bulk_handle = HG_BULK_NULL; struct hg_test_bulk_args *bulk_args = NULL; size_t nbytes_read; size_t offset; hg_return_t ret = HG_SUCCESS; bulk_write_in_t in_struct; bulk_args = (struct hg_test_bulk_args *) malloc( sizeof(struct hg_test_bulk_args)); /* Keep handle to pass to callback */ bulk_args->handle = handle; /* Get info from handle */ hg_info = HG_Get_info(handle); /* Get input parameters and data */ ret = HG_Get_input(handle, &in_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get input\n"); return ret; } /* Get parameters */ origin_bulk_handle = in_struct.bulk_handle; hg_atomic_set32(&bulk_args->completed_transfers, 0); /* Create a new block handle to read the data */ bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle); bulk_args->fildes = in_struct.fildes; /* For testing purposes try to read the data in two blocks of different sizes */ nbytes_read = bulk_args->nbytes / 2 + 16; printf("Start reading first chunk of %lu bytes...\n", nbytes_read); /* Create a new bulk handle to read the data */ HG_Bulk_create(hg_info->hg_class, 1, NULL, (hg_size_t *) &bulk_args->nbytes, HG_BULK_READWRITE, &local_bulk_handle); /* Pull bulk data */ ret = HG_Bulk_transfer(hg_info->context, hg_test_bulk_seg_transfer_cb, bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, 0, local_bulk_handle, 0, nbytes_read, HG_OP_ID_IGNORE); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not read bulk data\n"); return ret; } offset = nbytes_read; nbytes_read = bulk_args->nbytes - nbytes_read; printf("Start reading second chunk of %lu bytes...\n", nbytes_read); ret = HG_Bulk_transfer(hg_info->context, hg_test_bulk_seg_transfer_cb, bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, offset, local_bulk_handle, offset, nbytes_read, HG_OP_ID_IGNORE); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not read bulk data\n"); return ret; } HG_Free_input(handle, &in_struct); return ret; }
/*---------------------------------------------------------------------------*/ HG_TEST_RPC_CB(hg_test_perf_bulk, handle) { hg_return_t ret = HG_SUCCESS; struct hg_info *hg_info = NULL; hg_bulk_t origin_bulk_handle = HG_BULK_NULL; hg_bulk_t local_bulk_handle = HG_BULK_NULL; struct hg_test_bulk_args *bulk_args = NULL; bulk_write_in_t in_struct; bulk_args = (struct hg_test_bulk_args *) malloc( sizeof(struct hg_test_bulk_args)); /* Keep handle to pass to callback */ bulk_args->handle = handle; /* Get info from handle */ hg_info = HG_Get_info(handle); /* Get input struct */ ret = HG_Get_input(handle, &in_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get input struct\n"); return ret; } origin_bulk_handle = in_struct.bulk_handle; hg_atomic_set32(&bulk_args->completed_transfers, 0); /* Create a new block handle to read the data */ bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle); bulk_args->fildes = in_struct.fildes; #ifdef MERCURY_TESTING_USE_LOCAL_BULK /* Create a new bulk handle to read the data */ HG_Bulk_create(hg_info->hg_class, 1, NULL, &bulk_args->nbytes, HG_BULK_READWRITE, &local_bulk_handle); #else #ifdef MERCURY_TESTING_HAS_THREAD_POOL hg_thread_mutex_lock(&hg_test_local_bulk_handle_mutex_g); #endif local_bulk_handle = hg_test_local_bulk_handle_g; #endif /* Pull bulk data */ ret = HG_Bulk_transfer(hg_info->context, hg_test_perf_bulk_transfer_cb, bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, 0, local_bulk_handle, 0, bulk_args->nbytes, HG_OP_ID_IGNORE); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not read bulk data\n"); return ret; } #ifndef MERCURY_TESTING_USE_LOCAL_BULK #ifdef MERCURY_TESTING_HAS_THREAD_POOL hg_thread_mutex_unlock(&hg_test_local_bulk_handle_mutex_g); #endif #endif HG_Free_input(handle, &in_struct); return ret; }
/*---------------------------------------------------------------------------*/ static hg_return_t hg_test_drc_grant_cb(hg_handle_t handle) { const struct hg_info *hg_info = NULL; struct hg_test_info *hg_test_info = NULL; hg_test_drc_grant_in_t in_struct; hg_test_drc_grant_out_t out_struct; hg_return_t ret = HG_SUCCESS; #ifdef HG_TEST_DRC_USE_TOKEN hg_string_t token; #endif #ifndef HG_TEST_DRC_IGNORE int rc; #endif /* Get info from handle */ hg_info = HG_Get_info(handle); /* Get test info */ hg_test_info = (struct hg_test_info *) HG_Class_get_data(hg_info->hg_class); /* Get input buffer */ ret = HG_Get_input(handle, &in_struct); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not get input"); goto done; } /* Get parameters */ hg_test_info->wlm_id = in_struct.wlm_id; /* Grant access to another job */ printf("# Granting access to wlm_id %u...\n", hg_test_info->wlm_id); fflush(stdout); #ifndef HG_TEST_DRC_IGNORE drc_grant_again: rc = drc_grant(hg_test_info->credential, hg_test_info->wlm_id, DRC_FLAGS_TARGET_WLM); if (rc != DRC_SUCCESS && rc != -DRC_ALREADY_GRANTED) { if (rc == -DRC_EINVAL) { sleep(1); goto drc_grant_again; } HG_LOG_ERROR("drc_grant() to %d failed (%d, %s)", hg_test_info->wlm_id, rc, drc_strerror(-rc)); ret = HG_PROTOCOL_ERROR; goto done; } #endif #ifdef HG_TEST_DRC_USE_TOKEN /* Get the token to pass around to processes in other job */ #ifndef HG_TEST_DRC_IGNORE rc = drc_get_credential_token(hg_test_info->credential, &token); if (rc != DRC_SUCCESS) { HG_LOG_ERROR("drc_get_credential_token() failed (%d, %s)", rc, drc_strerror(-rc)); ret = HG_PROTOCOL_ERROR; goto done; } #else token = "my_test_token"; #endif /* Fill output structure */ printf("# Access granted, token is %s\n", token); fflush(stdout); out_struct.token = token; #else out_struct.credential = hg_test_info->credential; #endif /* Free handle and send response back */ ret = HG_Respond(handle, NULL, NULL, &out_struct); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not respond"); goto done; } HG_Free_input(handle, &in_struct); HG_Destroy(handle); done: return ret; }