static int builtin_posix_module_process_reqs (hio_dataset_t dataset, hio_internal_request_t **reqs, int req_count) { builtin_posix_module_t *posix_module = (builtin_posix_module_t *) dataset->ds_module; hioi_object_lock (&dataset->ds_object); for (int i = 0 ; i < req_count ; ++i) { hio_internal_request_t *req = reqs[i]; if (HIO_REQUEST_TYPE_READ == req->ir_type) { req->ir_status = builtin_posix_module_element_read_strided_internal (posix_module, req->ir_element, req->ir_offset, req->ir_data.r, req->ir_count, req->ir_size, req->ir_stride); } else { req->ir_status = builtin_posix_module_element_write_strided_internal (posix_module, req->ir_element, req->ir_offset, req->ir_data.w, req->ir_count, req->ir_size, req->ir_stride); } if (req->ir_status < 0) { hioi_object_unlock (&dataset->ds_object); return (int) req->ir_status; } } hioi_object_unlock (&dataset->ds_object); return HIO_SUCCESS; }
int hio_err_get_last (hio_context_t context, char **error) { hio_error_stack_item_t *stack_error; int hrc; if (NULL == context) { pthread_mutex_lock (&hio_error_stack_mutex); stack_error = hio_error_stack_head; if (NULL != stack_error) { hio_error_stack_head = stack_error->next; } pthread_mutex_unlock (&hio_error_stack_mutex); } else { hioi_object_lock (&context->c_object); stack_error = (hio_error_stack_item_t *) context->c_estack; if (NULL != stack_error) { context->c_estack = (void *) stack_error->next; } hioi_object_unlock (&context->c_object); } if (NULL == stack_error) { /* no error */ *error = NULL; return HIO_SUCCESS; } *error = stack_error->error_string; hrc = stack_error->hrc; free (stack_error); return hrc; }
void hioi_err_push_mpi (int mpirc, hio_object_t object, char *format, ...) { hio_context_t context = object ? hioi_object_context (object) : NULL; hio_error_stack_item_t *new_item; char mpi_error[MPI_MAX_ERROR_STRING] = "Unknown error"; int resultlen = MPI_MAX_ERROR_STRING; va_list vargs; char *temp; int rc; va_start (vargs, format); rc = vasprintf (&temp, format, vargs); va_end (vargs); if (0 >= rc) { /* couldn't allocate error string */ return; } /* ignore the error code for this */ (void) MPI_Error_string (mpirc, mpi_error, &resultlen); new_item = calloc (1, sizeof (hio_error_stack_item_t)); if (NULL == new_item) { /* not much can be done here. we are just plain OOM. */ return; } new_item->hrc = hioi_err_mpi(mpirc); /* TODO -- Should probably do something smarter here */ new_item->error_string = malloc (strlen (temp) + 3 + resultlen); if (NULL == temp) { free (new_item); free (temp); return; } /* append the mpi error to the hio error string */ strcpy (new_item->error_string, temp); strcat (new_item->error_string, ": "); strcat (new_item->error_string, mpi_error); /* done with this now */ free (temp); /* push the error message onto the stack */ if (NULL == context) { pthread_mutex_lock (&hio_error_stack_mutex); new_item->next = hio_error_stack_head; hio_error_stack_head = new_item; pthread_mutex_unlock (&hio_error_stack_mutex); } else { hioi_object_lock (&context->c_object); new_item->next = (hio_error_stack_item_t *) context->c_estack; context->c_estack = (void *) new_item; hioi_object_unlock (&context->c_object); } }
static int builtin_posix_module_process_reqs (hio_dataset_t dataset, hio_internal_request_t **reqs, int req_count) { builtin_posix_module_dataset_t *posix_dataset = (builtin_posix_module_dataset_t *) dataset; builtin_posix_module_t *posix_module = (builtin_posix_module_t *) dataset->ds_module; hio_context_t context = hioi_object_context (&dataset->ds_object); uint64_t start, stop; int rc = HIO_SUCCESS; start = hioi_gettime (); hioi_object_lock (&dataset->ds_object); for (int i = 0 ; i < req_count ; ++i) { hio_internal_request_t *req = reqs[i]; if (HIO_REQUEST_TYPE_READ == req->ir_type) { POSIX_TRACE_CALL(posix_dataset, req->ir_status = builtin_posix_module_element_read_strided_internal (posix_module, req->ir_element, req->ir_offset, req->ir_data.r, req->ir_count, req->ir_size, req->ir_stride), "element_read", req->ir_offset, req->ir_count * req->ir_size); } else { POSIX_TRACE_CALL(posix_dataset, req->ir_status = builtin_posix_module_element_write_strided_internal (posix_module, req->ir_element, req->ir_offset, req->ir_data.w, req->ir_count, req->ir_size, req->ir_stride), "element_write", req->ir_offset, req->ir_count * req->ir_size); } if (req->ir_urequest && req->ir_status > 0) { hio_request_t new_request = hioi_request_alloc (context); if (NULL == new_request) { rc = HIO_ERR_OUT_OF_RESOURCE; break; } req->ir_urequest[0] = new_request; new_request->req_transferred = req->ir_status; new_request->req_complete = true; new_request->req_status = HIO_SUCCESS; } if (req->ir_status < 0) { rc = (int) req->ir_status; break; } } hioi_object_unlock (&dataset->ds_object); stop = hioi_gettime (); builtin_posix_trace (posix_dataset, "process_requests", req_count, 0, start, stop); return rc; }
void hioi_err_push (int hrc, hio_object_t object, char *format, ...) { hio_context_t context = object ? hioi_object_context (object) : NULL; hio_error_stack_item_t *new_item; va_list vargs; int rc; new_item = calloc (1, sizeof (hio_error_stack_item_t)); if (NULL == new_item) { /* not much can be done here. we are just plain OOM. */ return; } va_start (vargs, format); rc = vasprintf (&new_item->error_string, format, vargs); va_end (vargs); if (0 >= rc) { /* couldn't allocate error string */ free (new_item); return; } if (context) { hioi_log (context, HIO_VERBOSE_ERROR, "%s", new_item->error_string); } new_item->hrc = hrc; /* push the error message onto the stack */ if (NULL == context) { pthread_mutex_lock (&hio_error_stack_mutex); new_item->next = hio_error_stack_head; hio_error_stack_head = new_item; pthread_mutex_unlock (&hio_error_stack_mutex); } else { hioi_object_lock (&context->c_object); new_item->next = (hio_error_stack_item_t *) context->c_estack; context->c_estack = (void *) new_item; hioi_object_unlock (&context->c_object); } }
static int builtin_posix_module_element_read_strided_nb (hio_element_t element, hio_request_t *request, off_t offset, void *ptr, size_t count, size_t size, size_t stride) { builtin_posix_module_dataset_t *posix_dataset = (builtin_posix_module_dataset_t *) hioi_element_dataset (element); builtin_posix_module_t *posix_module = (builtin_posix_module_t *) posix_dataset->base.ds_module; hio_context_t context = hioi_object_context (&element->e_object); ssize_t bytes_read; hio_request_t new_request; int rc = HIO_SUCCESS; if (!(posix_dataset->base.ds_flags & HIO_FLAG_READ)) { return HIO_ERR_PERM; } if (stride == 0) { size *= count; count = 1; } hioi_object_lock (&posix_dataset->base.ds_object); bytes_read = builtin_posix_module_element_read_strided_internal (posix_module, element, offset, ptr, count, size, stride); hioi_object_unlock (&posix_dataset->base.ds_object); if (0 > bytes_read) { rc = (int) bytes_read; } /* see if a request was requested */ if (request) { new_request = hioi_request_alloc (context); if (NULL == new_request) { return HIO_ERR_OUT_OF_RESOURCE; } *request = new_request; new_request->req_transferred = bytes_read; new_request->req_complete = true; } return rc; }
int hio_config_set_value (hio_object_t object, const char *variable, const char *value) { int rc = HIO_SUCCESS; hio_var_t *var; int config_index; if (NULL == object || NULL == variable || NULL == value) { return HIO_ERR_BAD_PARAM; } hioi_object_lock (object); do { /* go ahead and push this value into the object's key-value store. if the * configuration parameter has not yet been registered it will be read from * this key-valye store after the file store is checked. */ hioi_config_list_kv_push (&object->config_set, hioi_object_identifier (object), object->type, variable, value); config_index = hioi_var_lookup (&object->configuration, variable); if (0 > config_index) { /* variable does not exist (yet). nothing more to do */ break; } var = object->configuration.vars + config_index; if (HIO_VAR_FLAG_READONLY & var->var_flags) { hioi_err_push (HIO_ERR_PERM, object, "could not set read-only parameter: %s", variable); rc = HIO_ERR_PERM; break; } rc = hioi_config_set_value_internal (hioi_object_context(object), var, value); } while (0); hioi_object_unlock (object); return rc; }
int hio_config_get_value (hio_object_t object, char *variable, char **value) { int config_index, rc = HIO_SUCCESS; hio_var_t *var; if (NULL == object || NULL == variable || NULL == value) { return HIO_ERR_BAD_PARAM; } hioi_object_lock (object); do { /* try looking up the variable */ config_index = hioi_var_lookup (&object->configuration, variable); if (0 > config_index) { /* variable does not exist (yet). look up the the key-value store */ rc = hioi_config_list_kv_lookup (&object->config_set, variable, value); break; } var = object->configuration.vars + config_index; if (var->var_enum) { /* look up the value in the associated enumerator */ for (int i = 0 ; i < var->var_enum->count ; ++i) { if (var->var_storage->int32val == var->var_enum->values[i].value) { *value = strdup (var->var_enum->values[i].string_value); if (NULL == *value) { rc = HIO_ERR_OUT_OF_RESOURCE; } break; } } break; } /* create string representation of the value */ switch (var->var_type) { case HIO_CONFIG_TYPE_BOOL: rc = asprintf (value, "%s", var->var_storage->boolval ? "true" : "false"); break; case HIO_CONFIG_TYPE_STRING: *value = strdup (var->var_storage->strval); if (NULL == *value) { rc = -1; } break; case HIO_CONFIG_TYPE_INT32: rc = asprintf (value, "%i", var->var_storage->int32val); break; case HIO_CONFIG_TYPE_UINT32: rc = asprintf (value, "%u", var->var_storage->uint32val); break; case HIO_CONFIG_TYPE_INT64: rc = asprintf (value, "%" PRId64, var->var_storage->int64val); break; case HIO_CONFIG_TYPE_UINT64: rc = asprintf (value, "%" PRIu64, var->var_storage->uint64val); break; case HIO_CONFIG_TYPE_FLOAT: rc = asprintf (value, "%f", var->var_storage->floatval); break; case HIO_CONFIG_TYPE_DOUBLE: rc = asprintf (value, "%lf", var->var_storage->doubleval); break; } rc = (rc < 0) ? HIO_ERROR : HIO_SUCCESS; } while (0); hioi_object_unlock (object); return rc; }