static void _save_dbd_state(void) { char *dbd_fname; Buf buffer; int fd, rc, wrote = 0; uint16_t msg_type; uint32_t offset; dbd_fname = slurm_get_state_save_location(); xstrcat(dbd_fname, "/dbd.messages"); (void) unlink(dbd_fname); /* clear save state */ fd = open(dbd_fname, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd < 0) { error("slurmdbd: Creating state save file %s", dbd_fname); } else if (agent_list && list_count(agent_list)) { char curr_ver_str[10]; snprintf(curr_ver_str, sizeof(curr_ver_str), "VER%d", SLURM_PROTOCOL_VERSION); buffer = init_buf(strlen(curr_ver_str)); packstr(curr_ver_str, buffer); rc = _save_dbd_rec(fd, buffer); free_buf(buffer); if (rc != SLURM_SUCCESS) goto end_it; while ((buffer = list_dequeue(agent_list))) { /* * We do not want to store registration messages. If an * admin puts in an incorrect cluster name we can get a * deadlock unless they add the bogus cluster name to * the accounting system. */ offset = get_buf_offset(buffer); if (offset < 2) { free_buf(buffer); continue; } set_buf_offset(buffer, 0); (void) unpack16(&msg_type, buffer); /* checked by offset */ set_buf_offset(buffer, offset); if (msg_type == DBD_REGISTER_CTLD) { free_buf(buffer); continue; } rc = _save_dbd_rec(fd, buffer); free_buf(buffer); if (rc != SLURM_SUCCESS) break; wrote++; } } end_it: if (fd >= 0) { verbose("slurmdbd: saved %d pending RPCs", wrote); (void) close(fd); } xfree(dbd_fname); }
static int _send_resp(slurm_fd_t fd, Buf buffer) { uint32_t msg_size, nw_size; ssize_t msg_wrote; char *out_buf; if ((fd < 0) || (!fd_writeable(fd))) goto io_err; msg_size = get_buf_offset(buffer); nw_size = htonl(msg_size); if (!fd_writeable(fd)) goto io_err; msg_wrote = write(fd, &nw_size, sizeof(nw_size)); if (msg_wrote != sizeof(nw_size)) goto io_err; out_buf = get_buf_data(buffer); while (msg_size > 0) { if (!fd_writeable(fd)) goto io_err; msg_wrote = write(fd, out_buf, msg_size); if (msg_wrote <= 0) goto io_err; out_buf += msg_wrote; msg_size -= msg_wrote; } free_buf(buffer); return SLURM_SUCCESS; io_err: free_buf(buffer); return SLURM_ERROR; }
extern int name_publish_up(char *name, char *port) { Buf buf = NULL, resp_buf = NULL; uint32_t size, tmp_32; int rc; buf = init_buf(1024); pack16((uint16_t)TREE_CMD_NAME_PUBLISH, buf); packstr(name, buf); packstr(port, buf); size = get_buf_offset(buf); rc = tree_msg_to_srun_with_resp(size, get_buf_data(buf), &resp_buf); free_buf(buf); if (rc == SLURM_SUCCESS) { safe_unpack32(&tmp_32, resp_buf); rc = (int) tmp_32; } unpack_error: if (resp_buf) free_buf(resp_buf); return rc; }
extern int slurm_ckpt_unpack_job(check_jobinfo_t jobinfo, Buf buffer, uint16_t protocol_version) { uint32_t uint32_tmp; struct check_job_info *check_ptr = (struct check_job_info *)jobinfo; if (protocol_version >= SLURM_14_03_PROTOCOL_VERSION) { uint16_t id; uint32_t size; safe_unpack16(&id, buffer); safe_unpack32(&size, buffer); if (id != CHECK_OMPI) { uint32_t x; x = get_buf_offset(buffer); set_buf_offset(buffer, x + size); } else { safe_unpack16(&check_ptr->disabled, buffer); safe_unpack16(&check_ptr->reply_cnt, buffer); safe_unpack16(&check_ptr->wait_time, buffer); safe_unpack32(&check_ptr->error_code, buffer); safe_unpackstr_xmalloc(&check_ptr->error_msg, &uint32_tmp, buffer); safe_unpack_time(&check_ptr->time_stamp, buffer); } } return SLURM_SUCCESS; unpack_error: xfree(check_ptr->error_msg); return SLURM_ERROR; }
/* Purge queued job start records from the agent queue * RET number of records purged */ static int _purge_job_start_req(void) { int purged = 0; ListIterator iter; uint16_t msg_type; uint32_t offset; Buf buffer; iter = list_iterator_create(agent_list); while ((buffer = list_next(iter))) { offset = get_buf_offset(buffer); if (offset < 2) continue; set_buf_offset(buffer, 0); (void) unpack16(&msg_type, buffer); /* checked by offset */ set_buf_offset(buffer, offset); if (msg_type == DBD_JOB_START) { list_remove(iter); purged++; } } list_iterator_destroy(iter); info("slurmdbd: purge %d job start records", purged); return purged; }
/* Get FAT table for a given sector */ int* get_fat(int sector) { char *fat=NULL; int difatn=0; if (sector<(sectorsize/4)) { fat=get_buf_offset(difat[0]); return (int*)fat; } while ((!fat)&&(difatn<109)) { if (sector>(((difatn+2)*sectorsize)/4)) difatn++; else fat=get_buf_offset(difat[difatn]); } return (int*)fat; }
static void _pack_buffer(void *in, uint16_t rpc_version, Buf buffer) { Buf object = (Buf)in; packmem(get_buf_data(object), get_buf_offset(object), buffer); }
extern int slurm_persist_send_msg( slurm_persist_conn_t *persist_conn, Buf buffer) { uint32_t msg_size, nw_size; char *msg; ssize_t msg_wrote; int rc, retry_cnt = 0; xassert(persist_conn); if (persist_conn->fd < 0) return EAGAIN; if (!buffer) return SLURM_ERROR; rc = slurm_persist_conn_writeable(persist_conn); if (rc == -1) { re_open: if (retry_cnt++ > 3) return EAGAIN; /* if errno is ACCESS_DENIED do not try to reopen to connection just return that */ if (errno == ESLURM_ACCESS_DENIED) return ESLURM_ACCESS_DENIED; if (persist_conn->flags & PERSIST_FLAG_RECONNECT) { slurm_persist_conn_reopen(persist_conn, true); rc = slurm_persist_conn_writeable(persist_conn); } else return SLURM_ERROR; } if (rc < 1) return EAGAIN; msg_size = get_buf_offset(buffer); nw_size = htonl(msg_size); msg_wrote = write(persist_conn->fd, &nw_size, sizeof(nw_size)); if (msg_wrote != sizeof(nw_size)) return EAGAIN; msg = get_buf_data(buffer); while (msg_size > 0) { rc = slurm_persist_conn_writeable(persist_conn); if (rc == -1) goto re_open; if (rc < 1) return EAGAIN; msg_wrote = write(persist_conn->fd, msg, msg_size); if (msg_wrote <= 0) return EAGAIN; msg += msg_wrote; msg_size -= msg_wrote; } return SLURM_SUCCESS; }
/* * pack_all_part - dump all partition information for all partitions in * machine independent form (for network transmission) * OUT buffer_ptr - the pointer is set to the allocated buffer. * OUT buffer_size - set to size of the buffer in bytes * IN show_flags - partition filtering options * IN uid - uid of user making request (for partition filtering) * global: part_list - global list of partition records * NOTE: the buffer at *buffer_ptr must be xfreed by the caller * NOTE: change slurm_load_part() in api/part_info.c if data format changes */ extern void pack_all_part(char **buffer_ptr, int *buffer_size, uint16_t show_flags, uid_t uid, uint16_t protocol_version) { ListIterator part_iterator; struct part_record *part_ptr; uint32_t parts_packed; int tmp_offset; Buf buffer; time_t now = time(NULL); buffer_ptr[0] = NULL; *buffer_size = 0; buffer = init_buf(BUF_SIZE); /* write header: version and time */ parts_packed = 0; pack32(parts_packed, buffer); pack_time(now, buffer); /* write individual partition records */ part_iterator = list_iterator_create(part_list); while ((part_ptr = (struct part_record *) list_next(part_iterator))) { xassert (part_ptr->magic == PART_MAGIC); if (((show_flags & SHOW_ALL) == 0) && (uid != 0) && ((part_ptr->flags & PART_FLAG_HIDDEN) || (validate_group (part_ptr, uid) == 0))) continue; pack_part(part_ptr, buffer, protocol_version); parts_packed++; } list_iterator_destroy(part_iterator); /* put the real record count in the message body header */ tmp_offset = get_buf_offset(buffer); set_buf_offset(buffer, 0); pack32(parts_packed, buffer); set_buf_offset(buffer, tmp_offset); *buffer_size = get_buf_offset(buffer); buffer_ptr[0] = xfer_buf_data(buffer); }
int pmixp_dmdx_get(const char *nspace, int rank, pmix_modex_cbfunc_t cbfunc, void *cbdata) { dmdx_req_info_t *req; char *addr, *host; Buf buf; int rc; uint32_t seq; /* need to send the request */ host = pmixp_nspace_resolve(nspace, rank); xassert(NULL != host); if (NULL == host) { return SLURM_ERROR; } buf = pmixp_server_new_buf(); /* setup message header */ _setup_header(buf, DMDX_REQUEST, nspace, rank, SLURM_SUCCESS); /* generate namespace usocket name */ addr = pmixp_info_nspace_usock(nspace); /* store cur seq. num and move to the next request */ seq = _dmdx_seq_num++; /* track this request */ req = xmalloc(sizeof(dmdx_req_info_t)); req->seq_num = seq; req->cbfunc = cbfunc; req->cbdata = cbdata; req->ts = time(NULL); #ifndef NDEBUG strncpy(req->nspace, nspace, PMIX_MAX_NSLEN); req->rank = rank; #endif list_append(_dmdx_requests, req); /* send the request */ rc = pmixp_server_send(host, PMIXP_MSG_DMDX, seq, addr, get_buf_data(buf), get_buf_offset(buf), 1); /* cleanup the resources */ xfree(addr); free_buf(buf); /* check the return status */ if (SLURM_SUCCESS != rc) { PMIXP_ERROR("Cannot send direct modex request to %s", host); cbfunc(PMIX_ERROR, NULL, 0, cbdata, NULL, NULL); return SLURM_ERROR; } return rc; }
static int _copy_payload(Buf inbuf, size_t offs, Buf *outbuf) { size_t total_size, copy_size; char *ptr; pmix_proc_t *procs = NULL; size_t nprocs = 0; pmixp_coll_type_t type = 0; Buf buf; total_size = get_buf_offset(inbuf); set_buf_offset(inbuf, offs); int rc = pmixp_coll_unpack_ranges(inbuf, &type, &procs, &nprocs); xfree(procs); ptr = get_buf_data(inbuf) + get_buf_offset(inbuf); copy_size = total_size - get_buf_offset(inbuf); buf = init_buf(copy_size); memcpy(get_buf_data(buf), ptr, copy_size); *outbuf = buf; set_buf_offset(inbuf, total_size); return rc; }
/* * * Returns SLURM_SUCCESS if successful. On error returns SLURM_ERROR * and sets errno. */ int stepd_completion(int fd, uint16_t protocol_version, step_complete_msg_t *sent) { int req = REQUEST_STEP_COMPLETION_V2; int rc; int errnum = 0; Buf buffer; int len = 0; buffer = init_buf(0); debug("Entering stepd_completion for %u.%u, range_first = %d, range_last = %d", sent->job_id, sent->job_step_id, sent->range_first, sent->range_last); if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) { safe_write(fd, &req, sizeof(int)); safe_write(fd, &sent->range_first, sizeof(int)); safe_write(fd, &sent->range_last, sizeof(int)); safe_write(fd, &sent->step_rc, sizeof(int)); /* * We must not use setinfo over a pipe with slurmstepd here * Indeed, slurmd does a large use of getinfo over a pipe * with slurmstepd and doing the reverse can result in * a deadlock scenario with slurmstepd : * slurmd(lockforread,write)/slurmstepd(write,lockforread) * Do pack/unpack instead to be sure of independances of * slurmd and slurmstepd */ jobacctinfo_pack(sent->jobacct, protocol_version, PROTOCOL_TYPE_SLURM, buffer); len = get_buf_offset(buffer); safe_write(fd, &len, sizeof(int)); safe_write(fd, get_buf_data(buffer), len); free_buf(buffer); /* Receive the return code and errno */ safe_read(fd, &rc, sizeof(int)); safe_read(fd, &errnum, sizeof(int)); } else { error("%s: bad protocol version %hu", __func__, protocol_version); rc = SLURM_ERROR; } errno = errnum; return rc; rwfail: FREE_NULL_BUFFER(buffer); return -1; }
extern int archive_write_file(Buf buffer, char *cluster_name, time_t period_start, time_t period_end, char *arch_dir, char *arch_type, uint32_t archive_period) { int fd = 0; int rc = SLURM_SUCCESS; char *new_file = NULL; static pthread_mutex_t local_file_lock = PTHREAD_MUTEX_INITIALIZER; xassert(buffer); slurm_mutex_lock(&local_file_lock); /* write the buffer to file */ new_file = _make_archive_name(period_start, period_end, cluster_name, arch_dir, arch_type, archive_period); if (!new_file) { error("%s: Unable to make archive file name.", __func__); return SLURM_ERROR; } debug("Storing %s archive for %s at %s", arch_type, cluster_name, new_file); fd = creat(new_file, 0600); if (fd < 0) { error("Can't save archive, create file %s error %m", new_file); rc = SLURM_ERROR; } else { int amount; uint32_t pos = 0, nwrite = get_buf_offset(buffer); char *data = (char *)get_buf_data(buffer); while (nwrite > 0) { amount = write(fd, &data[pos], nwrite); if ((amount < 0) && (errno != EINTR)) { error("Error writing file %s, %m", new_file); rc = SLURM_ERROR; break; } nwrite -= amount; pos += amount; } fsync(fd); close(fd); } xfree(new_file); slurm_mutex_unlock(&local_file_lock); return rc; }
/* * Pack message header. * Returns packed size * Note: asymmetric to _recv_unpack_hdr because of additional SLURM header */ static int _slurm_pack_hdr(pmixp_base_hdr_t *hdr, void *net) { Buf buf = create_buf(net, PMIXP_BASE_HDR_MAX); int size = 0; _base_hdr_pack_full(buf, hdr); size = get_buf_offset(buf); /* free the Buf packbuf, but not the memory it points to */ buf->head = NULL; free_buf(buf); return size; }
/* * switch functions for global state save/restore */ int switch_p_libstate_save(char *dir_name) { #ifdef HAVE_NATIVE_CRAY Buf buffer; char *file_name; int ret = SLURM_SUCCESS; int state_fd; xassert(dir_name != NULL); if (debug_flags & DEBUG_FLAG_SWITCH) CRAY_INFO("save to %s", dir_name); buffer = init_buf(SWITCH_BUF_SIZE); _state_write_buf(buffer); file_name = xstrdup(dir_name); xstrcat(file_name, "/switch_cray_state"); (void) unlink(file_name); state_fd = creat(file_name, 0600); if (state_fd < 0) { CRAY_ERR("Can't save state, error creating file %s %m", file_name); ret = SLURM_ERROR; } else { char *buf = get_buf_data(buffer); size_t len = get_buf_offset(buffer); while (1) { int wrote = write(state_fd, buf, len); if ((wrote < 0) && (errno == EINTR)) continue; if (wrote == 0) break; if (wrote < 0) { CRAY_ERR("Can't save switch state: %m"); ret = SLURM_ERROR; break; } buf += wrote; len -= wrote; } close(state_fd); } xfree(file_name); if (buffer) free_buf(buffer); return ret; #else return SLURM_SUCCESS; #endif }
inline static int _pmixp_coll_contrib(pmixp_coll_ring_ctx_t *coll_ctx, int contrib_id, uint32_t hop, char *data, size_t size) { pmixp_coll_t *coll = _ctx_get_coll(coll_ctx); char *data_ptr = NULL; int ret; /* change the state */ coll->ts = time(NULL); /* save contribution */ if (!size_buf(coll_ctx->ring_buf)) { grow_buf(coll_ctx->ring_buf, size * coll->peers_cnt); } else if(remaining_buf(coll_ctx->ring_buf) < size) { uint32_t new_size = size_buf(coll_ctx->ring_buf) + size * _ring_remain_contrib(coll_ctx); grow_buf(coll_ctx->ring_buf, new_size); } grow_buf(coll_ctx->ring_buf, size); data_ptr = get_buf_data(coll_ctx->ring_buf) + get_buf_offset(coll_ctx->ring_buf); memcpy(data_ptr, data, size); set_buf_offset(coll_ctx->ring_buf, get_buf_offset(coll_ctx->ring_buf) + size); /* check for ring is complete */ if (contrib_id != _ring_next_id(coll)) { /* forward data to the next node */ ret = _ring_forward_data(coll_ctx, contrib_id, hop, data_ptr, size); if (ret) { PMIXP_ERROR("Cannot forward ring data"); return SLURM_ERROR; } } return SLURM_SUCCESS; }
/* * Pack message header. Returns packed size */ static size_t _direct_hdr_pack_portable(pmixp_base_hdr_t *hdr, void *net) { Buf buf = create_buf(net, PMIXP_BASE_HDR_MAX); int size = 0; _base_hdr_pack_full(buf, hdr); size = get_buf_offset(buf); xassert(size >= PMIXP_BASE_HDR_SIZE); xassert(size <= PMIXP_BASE_HDR_MAX); /* free the Buf packbuf, but not the memory it points to */ buf->head = NULL; free_buf(buf); return size; }
static int _ring_forward_data(pmixp_coll_ring_ctx_t *coll_ctx, uint32_t contrib_id, uint32_t hop_seq, void *data, size_t size) { pmixp_coll_ring_msg_hdr_t hdr; pmixp_coll_t *coll = _ctx_get_coll(coll_ctx); pmixp_coll_ring_t *ring = &coll->state.ring; hdr.nodeid = coll->my_peerid; hdr.msgsize = size; hdr.seq = coll_ctx->seq; hdr.hop_seq = hop_seq; hdr.contrib_id = contrib_id; pmixp_ep_t *ep = (pmixp_ep_t*)xmalloc(sizeof(*ep)); pmixp_coll_ring_cbdata_t *cbdata = NULL; uint32_t offset = 0; Buf buf = _get_fwd_buf(coll_ctx); int rc = SLURM_SUCCESS; pmixp_coll_ring_ctx_sanity_check(coll_ctx); #ifdef PMIXP_COLL_DEBUG PMIXP_DEBUG("%p: transit data to nodeid=%d, seq=%d, hop=%d, size=%lu, contrib=%d", coll_ctx, _ring_next_id(coll), hdr.seq, hdr.hop_seq, hdr.msgsize, hdr.contrib_id); #endif if (!buf) { rc = SLURM_ERROR; goto exit; } ep->type = PMIXP_EP_NOIDEID; ep->ep.nodeid = ring->next_peerid; /* pack ring info */ _pack_coll_ring_info(coll, &hdr, buf); /* insert payload to buf */ offset = get_buf_offset(buf); pmixp_server_buf_reserve(buf, size); memcpy(get_buf_data(buf) + offset, data, size); set_buf_offset(buf, offset + size); cbdata = xmalloc(sizeof(pmixp_coll_ring_cbdata_t)); cbdata->buf = buf; cbdata->coll = coll; cbdata->coll_ctx = coll_ctx; cbdata->seq = coll_ctx->seq; rc = pmixp_server_send_nb(ep, PMIXP_MSG_RING, coll_ctx->seq, buf, _ring_sent_cb, cbdata); exit: return rc; }
int pmixp_coll_contrib_local(pmixp_coll_t *coll, char *data, size_t size) { PMIXP_DEBUG("%s:%d: get local contribution", pmixp_info_namespace(), pmixp_info_nodeid()); /* sanity check */ pmixp_coll_sanity_check(coll); /* lock the structure */ slurm_mutex_lock(&coll->lock); /* change the collective state if need */ if (PMIXP_COLL_SYNC == coll->state) { PMIXP_DEBUG( "%s:%d: get local contribution: switch to PMIXP_COLL_FAN_IN", pmixp_info_namespace(), pmixp_info_nodeid()); coll->state = PMIXP_COLL_FAN_IN; coll->ts = time(NULL); } xassert(PMIXP_COLL_FAN_IN == coll->state); /* save & mark local contribution */ coll->contrib_local = true; grow_buf(coll->buf, size); memcpy(get_buf_data(coll->buf) + get_buf_offset(coll->buf), data, size); set_buf_offset(coll->buf, get_buf_offset(coll->buf) + size); /* unlock the structure */ slurm_mutex_unlock(&coll->lock); /* check if the collective is ready to progress */ _progress_fan_in(coll); PMIXP_DEBUG("%s:%d: get local contribution: finish", pmixp_info_namespace(), pmixp_info_nodeid()); return SLURM_SUCCESS; }
static void _reset_coll_ufwd(pmixp_coll_t *coll) { /* upward status */ coll->contrib_children = 0; coll->contrib_local = false; memset(coll->contrib_chld, 0, sizeof(coll->contrib_chld[0]) * coll->chldrn_cnt); coll->serv_offs = pmixp_server_buf_reset(coll->ufwd_buf); if (SLURM_SUCCESS != _pack_coll_info(coll, coll->ufwd_buf)) { PMIXP_ERROR("Cannot pack ranges to message header!"); } coll->ufwd_offset = get_buf_offset(coll->ufwd_buf); coll->ufwd_status = PMIXP_COLL_SND_NONE; }
static void _reset_coll_dfwd(pmixp_coll_t *coll) { /* downwards status */ (void)pmixp_server_buf_reset(coll->dfwd_buf); if (SLURM_SUCCESS != _pack_coll_info(coll, coll->dfwd_buf)) { PMIXP_ERROR("Cannot pack ranges to message header!"); } coll->dfwd_cb_cnt = 0; coll->dfwd_cb_wait = 0; coll->dfwd_status = PMIXP_COLL_SND_NONE; coll->contrib_prnt = false; /* Save the toal service offset */ coll->dfwd_offset = get_buf_offset(coll->dfwd_buf); }
extern int slurm_ckpt_pack_job(check_jobinfo_t jobinfo, Buf buffer, uint16_t protocol_version) { struct check_job_info *check_ptr = (struct check_job_info *)jobinfo; if (protocol_version >= SLURM_14_03_PROTOCOL_VERSION) { uint32_t x; uint32_t y; uint32_t z; uint32_t size; size = 0; pack16(CHECK_BLCR, buffer); x = get_buf_offset(buffer); pack32(size, buffer); y = get_buf_offset(buffer); pack16(check_ptr->disabled, buffer); pack_time(check_ptr->time_stamp, buffer); pack32(check_ptr->error_code, buffer); packstr(check_ptr->error_msg, buffer); z = get_buf_offset(buffer); set_buf_offset(buffer, x); pack32(z - y, buffer); set_buf_offset(buffer, z); } else if (protocol_version >= SLURM_2_6_PROTOCOL_VERSION) { pack16(check_ptr->disabled, buffer); pack_time(check_ptr->time_stamp, buffer); pack32(check_ptr->error_code, buffer); packstr(check_ptr->error_msg, buffer); } return SLURM_SUCCESS; }
static void *_buf_finalize(Buf buf, void *nhdr, size_t hsize, size_t *dsize) { size_t offset; uint32_t *service = (uint32_t*)get_buf_data(buf); char *ptr = get_buf_data(buf); if (!service[0]) { offset = PMIXP_SERVER_BUFFER_OFFS - hsize; #ifdef PMIXP_DEBUG_SERVER xassert(PMIXP_BASE_HDR_MAX >= hsize); xassert(PMIXP_BASE_HDR_MAX <= get_buf_offset(buf)); /* Makesure that we only use buffers allocated through * this call, because we reserve the space for the * header here */ xassert(PMIXP_SERVER_BUF_MAGIC == service[1]); #endif /* Enough space for any header was reserved at the * time of buffer initialization in `pmixp_server_new_buf` * put the header in place and return proper pointer */ if (hsize) { memcpy(ptr + offset, nhdr, hsize); } service[0] = offset; } else { /* This buffer was already finalized */ offset = service[0]; #ifdef PMIXP_DEBUG_SERVER /* We expect header to be the same */ xassert(0 == memcmp(ptr+offset, nhdr, hsize)); #endif } *dsize = get_buf_offset(buf) - offset; return ptr + offset; }
size_t pmixp_server_buf_reset(Buf buf) { uint32_t *service = (uint32_t*)get_buf_data(buf); service[0] = 0; #ifdef PMIXP_DEBUG_SERVER xassert( PMIXP_BASE_HDR_MAX >= sizeof(uint32_t)); xassert( PMIXP_BASE_HDR_MAX <= get_buf_offset(buf) ); /* Makesure that we only use buffers allocated through * this call, because we reserve the space for the * header here */ service[1] = PMIXP_SERVER_BUF_MAGIC; #endif set_buf_offset(buf, PMIXP_SERVER_BUFFER_OFFS); return PMIXP_SERVER_BUFFER_OFFS; }
extern int temp_kvs_init(void) { uint16_t cmd; uint32_t nodeid, num_children, size; Buf buf = NULL; xfree(temp_kvs_buf); temp_kvs_cnt = 0; temp_kvs_size = TEMP_KVS_SIZE_INC; temp_kvs_buf = xmalloc(temp_kvs_size); /* put the tree cmd here to simplify message sending */ if (in_stepd()) { cmd = TREE_CMD_KVS_FENCE; } else { cmd = TREE_CMD_KVS_FENCE_RESP; } buf = init_buf(1024); pack16(cmd, buf); if (in_stepd()) { nodeid = job_info.nodeid; /* XXX: TBC */ num_children = tree_info.num_children + 1; pack32(nodeid, buf); /* from_nodeid */ packstr(tree_info.this_node, buf); /* from_node */ pack32(num_children, buf); /* num_children */ pack32(kvs_seq, buf); } else { pack32(kvs_seq, buf); } size = get_buf_offset(buf); if (temp_kvs_cnt + size > temp_kvs_size) { temp_kvs_size += TEMP_KVS_SIZE_INC; xrealloc(temp_kvs_buf, temp_kvs_size); } memcpy(&temp_kvs_buf[temp_kvs_cnt], get_buf_data(buf), size); temp_kvs_cnt += size; free_buf(buf); tasks_to_wait = 0; children_to_wait = 0; return SLURM_SUCCESS; }
/* * Pack message header. * Returns packed size * Note: asymmetric to _recv_unpack_hdr because of additional SLURM header */ static int _send_pack_hdr(void *host, void *net) { send_header_t *ptr = (send_header_t *)host; Buf packbuf = create_buf(net, sizeof(send_header_t)); int size = 0; pack32(ptr->magic, packbuf); pack32(ptr->type, packbuf); pack32(ptr->seq, packbuf); pack32(ptr->nodeid, packbuf); pack32(ptr->msgsize, packbuf); size = get_buf_offset(packbuf); xassert(size == SEND_HDR_SIZE); /* free the Buf packbuf, but not the memory to which it points */ packbuf->head = NULL; free_buf(packbuf); return size; }
extern int spawn_resp_send_to_srun(spawn_resp_t *resp) { Buf buf; int rc; uint16_t cmd; buf = init_buf(1024); cmd = TREE_CMD_SPAWN_RESP; pack16(cmd, buf); spawn_resp_pack(resp, buf); rc = tree_msg_to_srun(get_buf_offset(buf), get_buf_data(buf)); free_buf(buf); return rc; }
char* read_stream_mini(int start, int size) { char *lbuf=malloc(4); int lsize=0; int *mtab=NULL; // current minitab int sector; sector=start; while (lsize<size) { lbuf = realloc(lbuf,lsize+64); memcpy(lbuf + lsize,get_buf_offset(get_minisection_sector(sector)) + get_mini_offset(sector), 64); lsize += 64; mtab = get_mtab(sector); sector = mtab[sector]; } return lbuf; }
static void _base_hdr_pack_full(Buf packbuf, pmixp_base_hdr_t *hdr) { if (hdr->ext_flag) { hdr->msgsize += PMIXP_BASE_HDR_EXT_SIZE(pmixp_dconn_ep_len()); } pack32(hdr->magic, packbuf); pack32(hdr->type, packbuf); pack32(hdr->seq, packbuf); pack32(hdr->nodeid, packbuf); pack32(hdr->msgsize, packbuf); pack8(hdr->ext_flag, packbuf); if (hdr->ext_flag) { packmem(pmixp_dconn_ep_data(), pmixp_dconn_ep_len(), packbuf); xassert(get_buf_offset(packbuf) == (PMIXP_BASE_HDR_SIZE + PMIXP_BASE_HDR_EXT_SIZE(pmixp_dconn_ep_len()))); } }
extern int spawn_resp_send_to_fd(spawn_resp_t *resp, int fd) { Buf buf; int rc; buf = init_buf(1024); /* sync with spawn_req_send_to_srun */ /* cmd = TREE_CMD_SPAWN_RESP; */ /* pack16(cmd, buf); */ spawn_resp_pack(resp, buf); rc = slurm_msg_sendto(fd, get_buf_data(buf), get_buf_offset(buf), SLURM_PROTOCOL_NO_SEND_RECV_FLAGS); free_buf(buf); return rc; }