static int _base_hdr_unpack_fixed(Buf packbuf, pmixp_base_hdr_t *hdr) { if (unpack32(&hdr->magic, packbuf)) { return -EINVAL; } xassert(PMIXP_SERVER_MSG_MAGIC == hdr->magic); if (unpack32(&hdr->type, packbuf)) { return -EINVAL; } if (unpack32(&hdr->seq, packbuf)) { return -EINVAL; } if (unpack32(&hdr->nodeid, packbuf)) { return -EINVAL; } if (unpack32(&hdr->msgsize, packbuf)) { return -EINVAL; } if (unpack8(&hdr->ext_flag, packbuf)) { return -EINVAL; } return 0; }
skey_t CTimeSetMember::get_key() const { skey_t skey = 0; if(getKeyLength() == 4) { #ifdef PGSQL_ORM unpack4((char*)&skey, (char*)key); #else DWORD t; memcpy(&t, key, sizeof(DWORD)); skey = (skey_t)t; #endif } else { #ifdef PGSQL_ORM unpack8((char*)&skey, (char*)key); #else time_t t; memcpy(&t, key, sizeof(time_t)); skey = t; #endif } return skey; }
static int _read_type(Buf buf, dmdx_type_t *type) { unsigned char t; int rc; /* 1. unpack message type */ if (SLURM_SUCCESS != (rc = unpack8(&t, buf))) { PMIXP_ERROR("Cannot unpack message type!"); return SLURM_ERROR; } *type = (dmdx_type_t)t; return SLURM_SUCCESS; }
static int cli_get(int statement, int cmd) { statement_desc* s = statements.get(statement); if (s == NULL) { return cli_bad_descriptor; } if (!s->prepared) { return cli_not_fetched; } cli_request req; req.length = sizeof(cli_request); req.cmd = cmd; req.stmt_id = statement; req.pack(); if (!s->session->sock->write(&req, sizeof req)) { return cli_network_error; } int4 response; if (!s->session->sock->read(&response, sizeof response)) { return cli_network_error; } unpack4(response); if (response <= 0) { return response; } dbSmallBuffer buf(response-4); if (!s->session->sock->read(buf, response-4)) { return cli_network_error; } char* p = buf; s->oid = unpack_oid(p); if (s->oid == 0) { return cli_not_found; } p += sizeof(cli_oid_t); for (column_binding* cb = s->columns; cb != NULL; cb = cb->next) { if (cb->set_fnc != NULL) { int len = unpack4(p); p += 4; char* dst = (char*)cb->set_fnc(cb->var_type, cb->var_ptr, len); if (cb->var_type >= cli_array_of_oid) { switch (sizeof_type[cb->var_type-cli_array_of_oid]) { case 2: while (--len >= 0) { p = unpack2(dst, p); dst += 2; } break; case 4: while (--len >= 0) { p = unpack4(dst, p); dst += 4; } break; case 8: while (--len >= 0) { p = unpack8(dst, p); dst += 8; } break; default: memcpy(dst, p, len); p += len; } } else { memcpy(dst, p, len); p += len; } } else { if (cb->var_type >= cli_asciiz) { int len = unpack4(p); p += 4; char* dst = (char*)cb->var_ptr; char* src = p; int n = len; if (cb->var_len != NULL) { if (n > *cb->var_len) { n = *cb->var_len; } *cb->var_len = n; } if (cb->var_type >= cli_array_of_oid) { switch (sizeof_type[cb->var_type-cli_array_of_oid]) { case 2: while (--n >= 0) { src = unpack2(dst, src); dst += 2; } p += len*2; break; case 4: while (--n >= 0) { src = unpack4(dst, src); dst += 4; } p += len*4; break; case 8: while (--n >= 0) { src = unpack8(dst, src); dst += 8; } p += len*8; break; default: memcpy(dst, p, n); p += len; } } else { if (cb->var_type == cli_pasciiz) { dst = *(char**)dst; } memcpy(dst, p, n); p += len; } } else { switch (sizeof_type[cb->var_type]) { case 2: p = unpack2((char*)cb->var_ptr, p); break; case 4: p = unpack4((char*)cb->var_ptr, p); break; case 8: p = unpack8((char*)cb->var_ptr, p); break; default: *(char*)cb->var_ptr = *p++; } } } } return cli_ok; }
mca_btl_openib_proc_t* mca_btl_openib_proc_get_locked(opal_proc_t* proc) { mca_btl_openib_proc_t *ib_proc = NULL, *ib_proc_ret = NULL; size_t msg_size; uint32_t size; int rc, i, j; void *message; char *offset; int modex_message_size; mca_btl_openib_modex_message_t dummy; bool is_new = false; /* Check if we have already created a IB proc * structure for this ompi process */ ib_proc = ibproc_lookup_and_lock(proc); if (NULL != ib_proc) { /* Gotcha! */ return ib_proc; } /* All initialization has to be an atomic operation. we do the following assumption: * - we let all concurent threads to try to do the initialization; * - when one has finished it locks ib_lock and checks if corresponding * process is still missing; * - if so - new proc is added, otherwise - initialized proc struct is released. */ /* First time, gotta create a new IB proc * out of the opal_proc ... */ ib_proc = OBJ_NEW(mca_btl_openib_proc_t); if (NULL == ib_proc) { return NULL; } /* Initialize number of peer */ ib_proc->proc_endpoint_count = 0; ib_proc->proc_opal = proc; /* query for the peer address info */ OPAL_MODEX_RECV(rc, &mca_btl_openib_component.super.btl_version, &proc->proc_name, &message, &msg_size); if (OPAL_SUCCESS != rc) { BTL_VERBOSE(("[%s:%d] opal_modex_recv failed for peer %s", __FILE__, __LINE__, OPAL_NAME_PRINT(proc->proc_name))); goto no_err_exit; } if (0 == msg_size) { goto no_err_exit; } /* Message was packed in btl_openib_component.c; the format is listed in a comment in that file */ modex_message_size = ((char *) &(dummy.end)) - ((char*) &dummy); /* Unpack the number of modules in the message */ offset = (char *) message; unpack8(&offset, &(ib_proc->proc_port_count)); BTL_VERBOSE(("unpack: %d btls", ib_proc->proc_port_count)); if (ib_proc->proc_port_count > 0) { ib_proc->proc_ports = (mca_btl_openib_proc_modex_t *) malloc(sizeof(mca_btl_openib_proc_modex_t) * ib_proc->proc_port_count); } else { ib_proc->proc_ports = NULL; } /* Loop over unpacking all the ports */ for (i = 0; i < ib_proc->proc_port_count; i++) { /* Unpack the modex comment message struct */ size = modex_message_size; memcpy(&(ib_proc->proc_ports[i].pm_port_info), offset, size); #if !defined(WORDS_BIGENDIAN) && OPAL_ENABLE_HETEROGENEOUS_SUPPORT MCA_BTL_OPENIB_MODEX_MSG_NTOH(ib_proc->proc_ports[i].pm_port_info); #endif offset += size; BTL_VERBOSE(("unpacked btl %d: modex message, offset now %d", i, (int)(offset-((char*)message)))); /* Unpack the number of CPCs that follow */ unpack8(&offset, &(ib_proc->proc_ports[i].pm_cpc_data_count)); BTL_VERBOSE(("unpacked btl %d: number of cpcs to follow %d (offset now %d)", i, ib_proc->proc_ports[i].pm_cpc_data_count, (int)(offset-((char*)message)))); ib_proc->proc_ports[i].pm_cpc_data = (opal_btl_openib_connect_base_module_data_t *) calloc(ib_proc->proc_ports[i].pm_cpc_data_count, sizeof(opal_btl_openib_connect_base_module_data_t)); if (NULL == ib_proc->proc_ports[i].pm_cpc_data) { goto err_exit; } /* Unpack the CPCs */ for (j = 0; j < ib_proc->proc_ports[i].pm_cpc_data_count; ++j) { uint8_t u8; opal_btl_openib_connect_base_module_data_t *cpcd; cpcd = ib_proc->proc_ports[i].pm_cpc_data + j; unpack8(&offset, &u8); BTL_VERBOSE(("unpacked btl %d: cpc %d: index %d (offset now %d)", i, j, u8, (int)(offset-(char*)message))); cpcd->cbm_component = opal_btl_openib_connect_base_get_cpc_byindex(u8); BTL_VERBOSE(("unpacked btl %d: cpc %d: component %s", i, j, cpcd->cbm_component->cbc_name)); unpack8(&offset, &cpcd->cbm_priority); unpack8(&offset, &cpcd->cbm_modex_message_len); BTL_VERBOSE(("unpacked btl %d: cpc %d: priority %d, msg len %d (offset now %d)", i, j, cpcd->cbm_priority, cpcd->cbm_modex_message_len, (int)(offset-(char*)message))); if (cpcd->cbm_modex_message_len > 0) { cpcd->cbm_modex_message = malloc(cpcd->cbm_modex_message_len); if (NULL == cpcd->cbm_modex_message) { BTL_ERROR(("Failed to malloc")); goto err_exit; } memcpy(cpcd->cbm_modex_message, offset, cpcd->cbm_modex_message_len); offset += cpcd->cbm_modex_message_len; BTL_VERBOSE(("unpacked btl %d: cpc %d: blob unpacked %d %x (offset now %d)", i, j, ((uint32_t*)cpcd->cbm_modex_message)[0], ((uint32_t*)cpcd->cbm_modex_message)[1], (int)(offset-((char*)message)))); } } } if (0 == ib_proc->proc_port_count) { ib_proc->proc_endpoints = NULL; } else { ib_proc->proc_endpoints = (volatile mca_btl_base_endpoint_t**) malloc(ib_proc->proc_port_count * sizeof(mca_btl_base_endpoint_t*)); } if (NULL == ib_proc->proc_endpoints) { goto err_exit; } BTL_VERBOSE(("unpacking done!")); /* Finally add this process to the initialized procs list */ opal_mutex_lock(&mca_btl_openib_component.ib_lock); ib_proc_ret = ibproc_lookup_no_lock(proc); if (NULL == ib_proc_ret) { /* if process can't be found in this list - insert it locked * it is safe to lock ib_proc here because this thread is * the only one who knows about it so far */ opal_mutex_lock(&ib_proc->proc_lock); opal_list_append(&mca_btl_openib_component.ib_procs, &ib_proc->super); ib_proc_ret = ib_proc; is_new = true; } else { /* otherwise - release module_proc */ OBJ_RELEASE(ib_proc); } opal_mutex_unlock(&mca_btl_openib_component.ib_lock); /* if we haven't insert the process - lock it here so we * won't lock mca_btl_openib_component.ib_lock */ if( !is_new ){ opal_mutex_lock(&ib_proc_ret->proc_lock); } return ib_proc_ret; err_exit: BTL_ERROR(("%d: error exit from mca_btl_openib_proc_create", OPAL_PROC_MY_NAME.vpid)); no_err_exit: OBJ_RELEASE(ib_proc); return NULL; }
static int cli_get_fdb(int statement, int cmd, cli_oid_t value = 0) { statement_desc* s = statements.get(statement); if (s == NULL) { return cli_bad_descriptor; } if (!s->prepared) { return cli_not_fetched; } struct get_req { cli_request req; cli_oid_t value; } get; int length = sizeof(cli_request); if (cmd == cli_cmd_skip) { length += 4; pack4((char*)(&get.req+1), (int)value); } else if (cmd == cli_cmd_seek) { length += sizeof(cli_oid_t); pack_oid((char*)(&get.req+1), value); } get.req.length = length; get.req.cmd = cmd; get.req.stmt_id = statement; get.req.pack(); if (!s->session->sock->write(&get.req, length)) { return cli_network_error; } int4 response; if (!s->session->sock->read(&response, sizeof response)) { return cli_network_error; } unpack4(response); if (response <= 0) { return response; } if (s->buf_size < (size_t)response-4) { delete[] s->buf; s->buf_size = response-4 < DEFAULT_BUF_SIZE ? DEFAULT_BUF_SIZE : response-4; s->buf = new char[s->buf_size]; } char* buf = s->buf; if (!s->session->sock->read(buf, response-4)) { return cli_network_error; } char* p = buf; int result = cli_ok; if (cmd == cli_cmd_seek) { s->oid = value; result = unpack_oid(p); } else { s->oid = unpack_oid(p); if (s->oid == 0) { return cli_not_found; } } p += sizeof(cli_oid_t); for (column_binding* cb = s->columns; cb != NULL; cb = cb->next) { int type = *p++; if (cb->var_type == cli_any) { cb->var_type = type; } else { assert(cb->var_type == type); } if (cb->set_fnc != NULL) { int len = unpack4(p); p += 4; char* dst = (char*)cb->set_fnc(cb->var_type, cb->var_ptr, len, cb->name, statement, p, cb->user_data); if (dst == NULL) { continue; } if (cb->var_type == cli_array_of_string) { char** s = (char**)dst; while (--len >= 0) { *s++ = p; p += strlen(p) + 1; } } else if (cb->var_type == cli_array_of_wstring) { wchar_t** s = (wchar_t**)dst; while (--len >= 0) { *s++ = (wchar_t*)p; p += (wcslen((wchar_t*)p) + 1)*sizeof(wchar_t); } } else if (cb->var_type >= cli_array_of_oid && cb->var_type < cli_array_of_string) { switch (sizeof_type[cb->var_type-cli_array_of_oid]) { case 2: while (--len >= 0) { p = unpack2(dst, p); dst += 2; } break; case 4: while (--len >= 0) { p = unpack4(dst, p); dst += 4; } break; case 8: while (--len >= 0) { p = unpack8(dst, p); dst += 8; } break; default: memcpy(dst, p, len); p += len; } } else { memcpy(dst, p, len); p += len; } } else { if (cb->var_type >= cli_asciiz && (cb->var_type <= cli_array_of_string || cb->var_type == cli_array_of_wstring)) { int len = unpack4(p); p += 4; char* dst = (char*)cb->var_ptr; char* src = p; int n = len; if (cb->var_len != NULL) { if (n > *cb->var_len) { n = *cb->var_len; } *cb->var_len = n; } if (cb->var_type == cli_wstring || cb->var_type == cli_pwstring) { if (cb->var_type == cli_pwstring) { dst = *(char**)dst; } memcpy(dst, p, n*sizeof(wchar_t)); p += len*sizeof(wchar_t); } else if (cb->var_type >= cli_array_of_oid) { if (cb->var_type == cli_array_of_string) { char** s = (char**)dst; len -= n; while (--n >= 0) { *s++ = p; p += strlen(p) + 1; } while (--len >= 0) { p += strlen(p) + 1; } } else if (cb->var_type == cli_array_of_wstring) { wchar_t** s = (wchar_t**)dst; len -= n; while (--n >= 0) { *s++ = (wchar_t*)p; p += (wcslen((wchar_t*)p) + 1)*sizeof(wchar_t); } while (--len >= 0) { p += (wcslen((wchar_t*)p) + 1)*sizeof(wchar_t); } } else { switch (sizeof_type[cb->var_type-cli_array_of_oid]) { case 2: while (--n >= 0) { src = unpack2(dst, src); dst += 2; } p += len*2; break; case 4: while (--n >= 0) { src = unpack4(dst, src); dst += 4; } p += len*4; break; case 8: while (--n >= 0) { src = unpack8(dst, src); dst += 8; } p += len*8; break; default: memcpy(dst, p, n); p += len; } } } else { if (cb->var_type == cli_pasciiz) { dst = *(char**)dst; } memcpy(dst, p, n); p += len; } } else if (cb->var_type == cli_rectangle) { p = unpack_rectangle((cli_rectangle_t*)cb->var_ptr, p); } else { switch (sizeof_type[cb->var_type]) { case 2: p = unpack2((char*)cb->var_ptr, p); break; case 4: p = unpack4((char*)cb->var_ptr, p); break; case 8: p = unpack8((char*)cb->var_ptr, p); break; default: *(char*)cb->var_ptr = *p++; } } } } s->updated = false; return result; }
mca_btl_openib_proc_t* mca_btl_openib_proc_create(opal_proc_t* proc) { mca_btl_openib_proc_t* module_proc = NULL; size_t msg_size; uint32_t size; int rc, i, j; void *message; char *offset; int modex_message_size; mca_btl_openib_modex_message_t dummy; /* Check if we have already created a IB proc * structure for this ompi process */ module_proc = mca_btl_openib_proc_lookup_proc(proc); if (NULL != module_proc) { /* Gotcha! */ return module_proc; } /* Oops! First time, gotta create a new IB proc * out of the opal_proc ... */ module_proc = OBJ_NEW(mca_btl_openib_proc_t); /* Initialize number of peer */ module_proc->proc_endpoint_count = 0; module_proc->proc_opal = proc; /* query for the peer address info */ OPAL_MODEX_RECV(rc, &mca_btl_openib_component.super.btl_version, proc, &message, &msg_size); if (OPAL_SUCCESS != rc) { BTL_ERROR(("[%s:%d] opal_modex_recv failed for peer %s", __FILE__, __LINE__, OPAL_NAME_PRINT(proc->proc_name))); OBJ_RELEASE(module_proc); return NULL; } if (0 == msg_size) { return NULL; } /* Message was packed in btl_openib_component.c; the format is listed in a comment in that file */ modex_message_size = ((char *) &(dummy.end)) - ((char*) &dummy); /* Unpack the number of modules in the message */ offset = (char *) message; unpack8(&offset, &(module_proc->proc_port_count)); BTL_VERBOSE(("unpack: %d btls", module_proc->proc_port_count)); if (module_proc->proc_port_count > 0) { module_proc->proc_ports = (mca_btl_openib_proc_modex_t *) malloc(sizeof(mca_btl_openib_proc_modex_t) * module_proc->proc_port_count); } else { module_proc->proc_ports = NULL; } /* Loop over unpacking all the ports */ for (i = 0; i < module_proc->proc_port_count; i++) { /* Unpack the modex comment message struct */ size = modex_message_size; memcpy(&(module_proc->proc_ports[i].pm_port_info), offset, size); #if !defined(WORDS_BIGENDIAN) && OPAL_ENABLE_HETEROGENEOUS_SUPPORT MCA_BTL_OPENIB_MODEX_MSG_NTOH(module_proc->proc_ports[i].pm_port_info); #endif offset += size; BTL_VERBOSE(("unpacked btl %d: modex message, offset now %d", i, (int)(offset-((char*)message)))); /* Unpack the number of CPCs that follow */ unpack8(&offset, &(module_proc->proc_ports[i].pm_cpc_data_count)); BTL_VERBOSE(("unpacked btl %d: number of cpcs to follow %d (offset now %d)", i, module_proc->proc_ports[i].pm_cpc_data_count, (int)(offset-((char*)message)))); module_proc->proc_ports[i].pm_cpc_data = (opal_btl_openib_connect_base_module_data_t *) calloc(module_proc->proc_ports[i].pm_cpc_data_count, sizeof(opal_btl_openib_connect_base_module_data_t)); if (NULL == module_proc->proc_ports[i].pm_cpc_data) { return NULL; } /* Unpack the CPCs */ for (j = 0; j < module_proc->proc_ports[i].pm_cpc_data_count; ++j) { uint8_t u8; opal_btl_openib_connect_base_module_data_t *cpcd; cpcd = module_proc->proc_ports[i].pm_cpc_data + j; unpack8(&offset, &u8); BTL_VERBOSE(("unpacked btl %d: cpc %d: index %d (offset now %d)", i, j, u8, (int)(offset-(char*)message))); cpcd->cbm_component = opal_btl_openib_connect_base_get_cpc_byindex(u8); BTL_VERBOSE(("unpacked btl %d: cpc %d: component %s", i, j, cpcd->cbm_component->cbc_name)); unpack8(&offset, &cpcd->cbm_priority); unpack8(&offset, &cpcd->cbm_modex_message_len); BTL_VERBOSE(("unpacked btl %d: cpc %d: priority %d, msg len %d (offset now %d)", i, j, cpcd->cbm_priority, cpcd->cbm_modex_message_len, (int)(offset-(char*)message))); if (cpcd->cbm_modex_message_len > 0) { cpcd->cbm_modex_message = malloc(cpcd->cbm_modex_message_len); if (NULL == cpcd->cbm_modex_message) { BTL_ERROR(("Failed to malloc")); return NULL; } memcpy(cpcd->cbm_modex_message, offset, cpcd->cbm_modex_message_len); offset += cpcd->cbm_modex_message_len; BTL_VERBOSE(("unpacked btl %d: cpc %d: blob unpacked %d %x (offset now %d)", i, j, ((uint32_t*)cpcd->cbm_modex_message)[0], ((uint32_t*)cpcd->cbm_modex_message)[1], (int)(offset-((char*)message)))); } } } if (0 == module_proc->proc_port_count) { module_proc->proc_endpoints = NULL; } else { module_proc->proc_endpoints = (mca_btl_base_endpoint_t**) malloc(module_proc->proc_port_count * sizeof(mca_btl_base_endpoint_t*)); } if (NULL == module_proc->proc_endpoints) { OBJ_RELEASE(module_proc); return NULL; } BTL_VERBOSE(("unpacking done!")); return module_proc; }