/* Pack individual burst buffer usage records into a buffer (used for limits) */
extern int bb_pack_usage(uid_t uid, bb_state_t *state_ptr, Buf buffer,
			 uint16_t protocol_version)
{
	int i, rec_count = 0;
	bb_user_t *bb_usage;
	int eof, offset;

	xassert(state_ptr);
	offset = get_buf_offset(buffer);
	pack32(rec_count,  buffer);
	if (!state_ptr->bb_uhash)
		return rec_count;

	for (i = 0; i < BB_HASH_SIZE; i++) {
		bb_usage = state_ptr->bb_uhash[i];
		while (bb_usage) {
			if (((uid == 0) || (uid == bb_usage->user_id)) &&
			    (bb_usage->size != 0)) {
				pack64(bb_usage->size,          buffer);
				pack32(bb_usage->user_id,       buffer);
				rec_count++;
			}
			bb_usage = bb_usage->next;
		}
	}
	if (rec_count != 0) {
		eof = get_buf_offset(buffer);
		set_buf_offset(buffer, offset);
		pack32(rec_count, buffer);
		set_buf_offset(buffer, eof);
	}

	return rec_count;
}
Ejemplo n.º 2
0
/* 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;
}
Ejemplo n.º 3
0
/*
 * Pack current burst buffer state information for network transmission to
 * user (e.g. "scontrol show burst")
 *
 * Returns a SLURM errno.
 */
extern int bb_p_state_pack(uid_t uid, Buf buffer, uint16_t protocol_version)
{
	uint32_t rec_count = 0;
	int eof, offset;

	pthread_mutex_lock(&bb_state.bb_mutex);
	packstr(bb_state.name, buffer);
	offset = get_buf_offset(buffer);
	pack32(rec_count,        buffer);
	bb_pack_state(&bb_state, buffer, protocol_version);
	if (bb_state.bb_config.private_data == 0)
		uid = 0;	/* User can see all data */
	rec_count = bb_pack_bufs(uid, bb_state.bb_hash,buffer,protocol_version);
	if (rec_count != 0) {
		eof = get_buf_offset(buffer);
		set_buf_offset(buffer, offset);
		pack32(rec_count, buffer);
		set_buf_offset(buffer, eof);
	}
	if (bb_state.bb_config.debug_flag) {
		debug("%s: %s: record_count:%u",
		      plugin_type,  __func__, rec_count);
	}
	pthread_mutex_unlock(&bb_state.bb_mutex);

	return SLURM_SUCCESS;
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
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_MIN_PROTOCOL_VERSION) {
		uint32_t x;
		uint32_t y;
		uint32_t z;
		uint32_t size;

		size = 0;
		pack16(CHECK_POE, buffer);
		x = get_buf_offset(buffer);
		pack32(size, buffer);

		y = get_buf_offset(buffer);

		pack16(check_ptr->disabled, buffer);
		pack16(check_ptr->node_cnt, buffer);
		pack16(check_ptr->reply_cnt, buffer);
		pack16(check_ptr->wait_time, buffer);
		pack32(check_ptr->error_code, buffer);
		packstr(check_ptr->error_msg, buffer);
		pack_time(check_ptr->time_stamp, buffer);

		z = get_buf_offset(buffer);
		set_buf_offset(buffer, x);
		pack32(z - y, buffer);
		set_buf_offset(buffer, z);
	}

	return SLURM_SUCCESS;
}
/* Pack individual burst buffer records into a buffer */
extern int bb_pack_bufs(uid_t uid, bb_state_t *state_ptr, Buf buffer,
			uint16_t protocol_version)
{
	int i, rec_count = 0;
	struct bb_alloc *bb_alloc;
	int eof, offset;

	xassert(state_ptr);
	offset = get_buf_offset(buffer);
	pack32(rec_count,  buffer);
	if (!state_ptr->bb_ahash)
		return rec_count;

	for (i = 0; i < BB_HASH_SIZE; i++) {
		bb_alloc = state_ptr->bb_ahash[i];
		while (bb_alloc) {
			if ((uid == 0) || (uid == bb_alloc->user_id)) {
				_pack_alloc(bb_alloc, buffer, protocol_version);
				rec_count++;
			}
			bb_alloc = bb_alloc->next;
		}
	}
	if (rec_count != 0) {
		eof = get_buf_offset(buffer);
		set_buf_offset(buffer, offset);
		pack32(rec_count, buffer);
		set_buf_offset(buffer, eof);
	}

	return rec_count;
}
Ejemplo n.º 7
0
/*
 * pack_all_front_end - dump all front_end node information for all nodes
 *	in machine independent form (for network transmission)
 * OUT buffer_ptr - pointer to the stored data
 * OUT buffer_size - set to size of the buffer in bytes
 * IN protocol_version - slurm protocol version of client
 * NOTE: the caller must xfree the buffer at *buffer_ptr
 * NOTE: READ lock_slurmctld config before entry
 */
extern void pack_all_front_end(char **buffer_ptr, int *buffer_size, uid_t uid,
			       uint16_t protocol_version)
{
	time_t now = time(NULL);
	uint32_t nodes_packed = 0;
	Buf buffer;
#ifdef HAVE_FRONT_END
	uint32_t tmp_offset;
	front_end_record_t *front_end_ptr;
	int i;

	buffer_ptr[0] = NULL;
	*buffer_size = 0;

	buffer = init_buf(BUF_SIZE * 2);
	nodes_packed = 0;

	if (protocol_version >= SLURM_2_5_PROTOCOL_VERSION) {
		/* write header: count and time */
		pack32(nodes_packed, buffer);
		pack_time(now, buffer);

		/* write records */
		for (i = 0, front_end_ptr = front_end_nodes;
		     i < front_end_node_cnt; i++, front_end_ptr++) {
			xassert(front_end_ptr->magic == FRONT_END_MAGIC);
			_pack_front_end(front_end_ptr, buffer,
					protocol_version);
			nodes_packed++;
		}
	} else {
		error("pack_all_front_end: Unsupported slurm version %u",
		      protocol_version);
	}

	tmp_offset = get_buf_offset (buffer);
	set_buf_offset(buffer, 0);
	pack32(nodes_packed, buffer);
	set_buf_offset(buffer, tmp_offset);

	*buffer_size = get_buf_offset(buffer);
	buffer_ptr[0] = xfer_buf_data(buffer);
#else
	buffer_ptr[0] = NULL;
	*buffer_size = 0;
	buffer = init_buf(64);
	pack32(nodes_packed, buffer);
	pack_time(now, buffer);
	*buffer_size = get_buf_offset(buffer);
	buffer_ptr[0] = xfer_buf_data(buffer);
#endif
}
Ejemplo n.º 8
0
/*
 * Pack current burst buffer state information for network transmission to
 * user (e.g. "scontrol show burst")
 *
 * Returns a SLURM errno.
 */
extern int bb_p_state_pack(Buf buffer, uint16_t protocol_version)
{
	struct bb_alloc *bb_next;
	uint32_t rec_count = 0;
	int i, eof, offset;

	pthread_mutex_lock(&bb_mutex);
	if (debug_flag)
		info("%s: %s",  __func__, plugin_type);
	packstr((char *)plugin_type, buffer);	/* Remove "const" qualifier */
	offset = get_buf_offset(buffer);
	pack32(rec_count,        buffer);
	packstr(allow_users_str, buffer);
	packstr(deny_users_str,  buffer);
	packstr(get_sys_state,   buffer);
	packstr(start_stage_in,  buffer);
	packstr(start_stage_out, buffer);
	packstr(stop_stage_in,   buffer);
	packstr(stop_stage_out,  buffer);
	pack32(job_size_limit,   buffer);
	pack32(prio_boost,       buffer);
	pack32(total_space,      buffer);
	pack32(user_size_limit,  buffer);
	if (bb_hash) {
		for (i = 0; i < BB_HASH_SIZE; i++) {
			bb_next = bb_hash[i];
			while (bb_next) {
				pack32(bb_next->array_job_id,  buffer);
				pack32(bb_next->array_task_id, buffer);
				pack32(bb_next->job_id,        buffer);
				packstr(bb_next->name,         buffer);
				pack32(bb_next->size,          buffer);
				pack16(bb_next->state,         buffer);
				pack32(bb_next->user_id,       buffer);
				rec_count++;
				bb_next = bb_next->next;
			}
		}
		if (rec_count != 0) {
			eof = get_buf_offset(buffer);
			set_buf_offset(buffer, offset);
			pack32(rec_count, buffer);
			set_buf_offset(buffer, eof);
		}
	}
	info("%s: record_count:%u",  __func__, rec_count);
	pthread_mutex_unlock(&bb_mutex);

	return SLURM_SUCCESS;
}
Ejemplo n.º 9
0
END_TEST



START_TEST(pack_1702_null_clus_res_rec)
{
	int rc;
	Buf buf = init_buf(1024);
	slurmdb_clus_res_rec_t pack_crr = {0};

	slurmdb_pack_clus_res_rec(NULL, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_clus_res_rec_t *unpack_crr;
	rc = slurmdb_unpack_clus_res_rec((void **)&unpack_crr, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc               == SLURM_SUCCESS);
	ck_assert(pack_crr.cluster == unpack_crr->cluster);

	/* when given a NULL pointer, the pack function sets percent_allowed to
	 * NO_VAL16, not 0. */
	ck_assert(NO_VAL16         == unpack_crr->percent_allowed);

	free_buf(buf);
	slurmdb_destroy_clus_res_rec(unpack_crr);
}
Ejemplo n.º 10
0
END_TEST

START_TEST(pack_1702_clus_res_rec)
{
	int rc;

	slurmdb_clus_res_rec_t *pack_crr = xmalloc(sizeof(slurmdb_clus_res_rec_t));
	pack_crr->percent_allowed = 12;
	pack_crr->cluster         = xstrdup("Diogenes");

	Buf buf = init_buf(1024);
	slurmdb_pack_clus_res_rec(pack_crr, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_clus_res_rec_t *unpack_crr;
	rc = slurmdb_unpack_clus_res_rec((void **)&unpack_crr, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc                        == SLURM_SUCCESS);
	ck_assert(pack_crr->percent_allowed == unpack_crr->percent_allowed);
	ck_assert_str_eq(pack_crr->cluster, unpack_crr->cluster);

	free_buf(buf);
	slurmdb_destroy_clus_res_rec(pack_crr);
	slurmdb_destroy_clus_res_rec(unpack_crr);
}
Ejemplo n.º 11
0
Buf pmixp_server_new_buf(void)
{
	Buf buf = create_buf(xmalloc(SEND_HDR_SIZE), SEND_HDR_SIZE);
	/* Skip header. It will be filled right before the sending */
	set_buf_offset(buf, SEND_HDR_SIZE);
	return buf;
}
Ejemplo n.º 12
0
END_TEST

START_TEST(pack_1702_rec_null_ptrs)
{
	slurmdb_user_rec_t pack_rec = {0};
	pack_rec.admin_level   = 1;
	pack_rec.uid           = 12345;

	Buf buf = init_buf(1024);
	slurmdb_pack_user_rec(&pack_rec, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_user_rec_t *unpack_rec;
	int rc = slurmdb_unpack_user_rec((void **)&unpack_rec, SLURM_MIN_PROTOCOL_VERSION, buf);

	ck_assert_int_eq(rc, SLURM_SUCCESS);
	ck_assert_uint_eq(pack_rec.admin_level, unpack_rec->admin_level);
	ck_assert(pack_rec.assoc_list    == unpack_rec->assoc_list);
	ck_assert(pack_rec.coord_accts   == unpack_rec->coord_accts);
	ck_assert(pack_rec.wckey_list    == unpack_rec->wckey_list);
	ck_assert(pack_rec.default_acct  == unpack_rec->default_acct);
	ck_assert(pack_rec.default_wckey == unpack_rec->default_wckey);
	ck_assert(pack_rec.name          == unpack_rec->name);
	ck_assert(pack_rec.old_name      == unpack_rec->old_name);
	ck_assert_uint_eq(pack_rec.uid,  unpack_rec->uid);

	free_buf(buf);
	slurmdb_destroy_user_rec(unpack_rec);

}
Ejemplo n.º 13
0
int pmixp_server_pp_send(int nodeid, int size)
{
	Buf buf = pmixp_server_buf_new();
	int rc;
	pmixp_ep_t ep;
	struct pp_cbdata *cbdata = xmalloc(sizeof(*cbdata));

	grow_buf(buf, size);
	ep.type = PMIXP_EP_NOIDEID;
	ep.ep.nodeid = nodeid;
	cbdata->buf = buf;
	cbdata->size = size;
	set_buf_offset(buf,get_buf_offset(buf) + size);
	rc = pmixp_server_send_nb(&ep, PMIXP_MSG_PINGPONG,
				  _pmixp_pp_count, buf, pingpong_complete,
				  (void*)cbdata);
	if (SLURM_SUCCESS != rc) {
		char *nodename = pmixp_info_job_host(nodeid);
		PMIXP_ERROR("Was unable to wait for the parent %s to "
			    "become alive",
			    nodename);
		xfree(nodename);
	}
	return rc;
}
Ejemplo n.º 14
0
Buf pmixp_server_buf_new(void)
{
	size_t offset = PMIXP_SERVER_BUFFER_OFFS;
	Buf buf = create_buf(xmalloc(offset), offset);
	uint32_t *service = (uint32_t*)get_buf_data(buf);
	/* Use the first size_t cell to identify the payload
	 * offset. Value 0 is special meaning that buffer wasn't
	 * yet finalized
	 */
	service[0] = 0;

#ifdef PMIXP_DEBUG_SERVER
	xassert( PMIXP_BASE_HDR_MAX >= sizeof(uint32_t));

	/* 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

	/* Skip header. It will be filled right before the sending */
	set_buf_offset(buf, offset);
	return buf;
}
Ejemplo n.º 15
0
static void _reset_coll(pmixp_coll_t *coll)
{
	switch (coll->state) {
	case PMIXP_COLL_SYNC:
		/* already reset */
		break;
	case PMIXP_COLL_FAN_IN:
	case PMIXP_COLL_FAN_OUT:
		set_buf_offset(coll->buf, coll->serv_offs);
		if (SLURM_SUCCESS != _pack_ranges(coll)) {
			PMIXP_ERROR(
					"Cannot pack ranges to coll message header!");
		}
		coll->state = PMIXP_COLL_SYNC;
		memset(coll->ch_contribs, 0, sizeof(int) * coll->children_cnt);
		coll->seq++; /* move to the next collective */
		coll->contrib_cntr = 0;
		coll->contrib_local = 0;
		coll->cbdata = NULL;
		coll->cbfunc = NULL;
		break;
	default:
		PMIXP_ERROR("Bad collective state = %d", coll->state);
	}
}
Ejemplo n.º 16
0
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_MIN_PROTOCOL_VERSION) {
		uint16_t id;
		uint32_t size;

		safe_unpack16(&id, buffer);
		safe_unpack32(&size, buffer);
		if (id != CHECK_POE) {
			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->node_cnt, 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;
}
Ejemplo n.º 17
0
END_TEST

START_TEST(pack_1702_coord_rec)
{
	int rc;

	slurmdb_coord_rec_t *pack_cr = xmalloc(sizeof(slurmdb_coord_rec_t));
	pack_cr->direct                = 12;
	pack_cr->name                  = xstrdup("Gottlob Frege");

	Buf buf = init_buf(1024);
	slurmdb_pack_coord_rec(pack_cr, SLURM_17_02_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_coord_rec_t *unpack_cr;
	rc = slurmdb_unpack_coord_rec((void **)&unpack_cr, SLURM_17_02_PROTOCOL_VERSION, buf);
	ck_assert(rc                        == SLURM_SUCCESS);
	ck_assert_str_eq(pack_cr->name,        unpack_cr->name);
	ck_assert(pack_cr->direct           == unpack_cr->direct);

	free_buf(buf);
	slurmdb_destroy_coord_rec(pack_cr);
	slurmdb_destroy_coord_rec(unpack_cr);
}
Ejemplo n.º 18
0
END_TEST

START_TEST(pack_1702_assoc_usage)
{
	int rc;
	Buf buf = init_buf(1024);
	slurmdb_assoc_usage_t *pack_au = xmalloc(sizeof(slurmdb_assoc_usage_t));

	pack_au->children_list          = NULL;
	pack_au->grp_used_tres          = NULL;
	pack_au->grp_used_tres_run_secs = NULL;
	pack_au->grp_used_wall          = 77;
	pack_au->fs_factor              = 0;
	pack_au->level_shares           = 0;
	pack_au->parent_assoc_ptr       = NULL;
	pack_au->fs_assoc_ptr           = NULL;
	pack_au->shares_norm            = 0;
	pack_au->tres_cnt               = 0;
	pack_au->usage_efctv            = 123123;
	pack_au->usage_norm             = 4857;
	pack_au->usage_raw              = 4747;
	pack_au->usage_tres_raw         = NULL;
	pack_au->used_jobs              = 234;
	pack_au->used_submit_jobs       = 433;
	pack_au->level_fs               = 3333;
	pack_au->valid_qos              = NULL;

	slurmdb_pack_assoc_usage(pack_au, SLURM_17_02_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_assoc_usage_t *unpack_au;
	rc = slurmdb_unpack_assoc_usage((void **)&unpack_au, SLURM_17_02_PROTOCOL_VERSION, buf);
	ck_assert(rc                              == SLURM_SUCCESS);
	ck_assert(pack_au->children_list          == unpack_au->children_list);
	ck_assert(pack_au->grp_used_tres          == unpack_au->grp_used_tres);
	ck_assert(pack_au->grp_used_tres_run_secs == unpack_au->grp_used_tres_run_secs);
	ck_assert(pack_au->grp_used_wall          == unpack_au->grp_used_wall);
	ck_assert(pack_au->fs_factor              == unpack_au->fs_factor);
	ck_assert(pack_au->level_shares           == unpack_au->level_shares);
	ck_assert(pack_au->parent_assoc_ptr       == unpack_au->parent_assoc_ptr);
	ck_assert(pack_au->fs_assoc_ptr           == unpack_au->fs_assoc_ptr);
	ck_assert(pack_au->shares_norm            == unpack_au->shares_norm);
	ck_assert(pack_au->tres_cnt               == unpack_au->tres_cnt);
	ck_assert(pack_au->usage_efctv            == unpack_au->usage_efctv);
	ck_assert(pack_au->usage_norm             == unpack_au->usage_norm);
	ck_assert(pack_au->usage_raw              == unpack_au->usage_raw);
	ck_assert(pack_au->usage_tres_raw         == unpack_au->usage_tres_raw);
	ck_assert(pack_au->used_jobs              == unpack_au->used_jobs);
	ck_assert(pack_au->used_submit_jobs       == unpack_au->used_submit_jobs);
	ck_assert(pack_au->level_fs               == unpack_au->level_fs);
	ck_assert(pack_au->valid_qos              == unpack_au->valid_qos);

	free_buf(buf);
	slurmdb_destroy_assoc_usage(pack_au);
	slurmdb_destroy_assoc_usage(unpack_au);
}
Ejemplo n.º 19
0
/*
 * 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);
}
Ejemplo n.º 20
0
END_TEST


START_TEST(pack_1702_null_assoc_rec)
{
	int rc;
	Buf buf = init_buf(1024);
	slurmdb_assoc_rec_t pack_ar = {0};

	slurmdb_pack_assoc_rec(NULL, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_assoc_rec_t *unpack_ar;
	rc = slurmdb_unpack_assoc_rec((void **)&unpack_ar, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc                     	 == SLURM_SUCCESS);
	ck_assert(pack_ar.accounting_list	 == unpack_ar->accounting_list);
	ck_assert(pack_ar.acct           	 == unpack_ar->acct);
	ck_assert(pack_ar.assoc_next     	 == unpack_ar->assoc_next);
	ck_assert(pack_ar.assoc_next_id  	 == unpack_ar->assoc_next_id);
	ck_assert(pack_ar.cluster        	 == unpack_ar->cluster);
	ck_assert(NO_VAL                 	 == unpack_ar->def_qos_id);
	ck_assert(NO_VAL                 	 == unpack_ar->grp_jobs);
	ck_assert(NO_VAL                	 == unpack_ar->grp_submit_jobs);
	ck_assert(pack_ar.grp_tres       	 == unpack_ar->grp_tres);
	ck_assert(pack_ar.grp_tres_ctld  	 == unpack_ar->grp_tres_ctld);
	ck_assert(pack_ar.grp_tres_run_mins      == unpack_ar->grp_tres_run_mins);
	ck_assert(NO_VAL                         == unpack_ar->grp_wall);
	ck_assert(pack_ar.id                     == unpack_ar->id);
	ck_assert(pack_ar.is_def                 == unpack_ar->is_def);
	ck_assert(pack_ar.lft                    == unpack_ar->lft);
	ck_assert(NO_VAL                         == unpack_ar->max_jobs);
	ck_assert(NO_VAL                         == unpack_ar->max_submit_jobs);
	ck_assert(pack_ar.max_tres_mins_pj       == unpack_ar->max_tres_mins_pj);
	ck_assert(pack_ar.max_tres_mins_ctld     == unpack_ar->max_tres_mins_ctld);
	ck_assert(pack_ar.max_tres_run_mins      == unpack_ar->max_tres_run_mins);
	ck_assert(pack_ar.max_tres_run_mins_ctld == unpack_ar->max_tres_run_mins_ctld);
	ck_assert(pack_ar.max_tres_pj            == unpack_ar->max_tres_pj);
	ck_assert(pack_ar.max_tres_ctld          == unpack_ar->max_tres_ctld);
	ck_assert(pack_ar.max_tres_pn            == unpack_ar->max_tres_pn);
	ck_assert(pack_ar.max_tres_pn_ctld       == unpack_ar->max_tres_pn_ctld);
	ck_assert(NO_VAL                         == unpack_ar->max_wall_pj);
	ck_assert(pack_ar.parent_acct            == unpack_ar->parent_acct);
	ck_assert(pack_ar.parent_id              == unpack_ar->parent_id);
	ck_assert(pack_ar.partition              == unpack_ar->partition);
	ck_assert(pack_ar.qos_list               == unpack_ar->qos_list);
	ck_assert(pack_ar.rgt                    == unpack_ar->rgt);
	ck_assert(NO_VAL                         == unpack_ar->shares_raw);
	ck_assert(pack_ar.uid                    == unpack_ar->uid);
	ck_assert(pack_ar.usage                  == unpack_ar->usage);
	ck_assert(pack_ar.user                   == unpack_ar->user);

	free_buf(buf);
	slurmdb_destroy_assoc_rec(unpack_ar);
}
Ejemplo n.º 21
0
static void _fan_in_finished(pmixp_coll_t *coll)
{
	xassert(PMIXP_COLL_FAN_IN == coll->state);
	coll->state = PMIXP_COLL_FAN_OUT;
	memset(coll->ch_contribs, 0, sizeof(int) * coll->children_cnt);
	coll->contrib_cntr = 0;
	coll->contrib_local = 0;
	set_buf_offset(coll->buf, coll->serv_offs);
	if (SLURM_SUCCESS != _pack_ranges(coll)) {
		PMIXP_ERROR("Cannot pack ranges to coll message header!");
	}
}
Ejemplo n.º 22
0
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;
}
Ejemplo n.º 23
0
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;
}
Ejemplo n.º 24
0
END_TEST

START_TEST(pack_1702_rec)
{
	int rc;
	slurmdb_user_rec_t pack_rec;
	pack_rec.admin_level   = 1;

	slurmdb_assoc_rec_t assoc_rec = {0};
	pack_rec.assoc_list    = list_create(NULL);
	list_append(pack_rec.assoc_list, &assoc_rec);

	slurmdb_coord_rec_t coord_rec = {0};
	pack_rec.coord_accts   = list_create(NULL);
	list_append(pack_rec.coord_accts, &coord_rec);

	slurmdb_wckey_rec_t wckey_rec = {0};
	pack_rec.wckey_list    = list_create(NULL);
	list_append(pack_rec.wckey_list, &wckey_rec);

	pack_rec.default_acct  = xstrdup("default_acct");
	pack_rec.default_wckey = xstrdup("default_wckey");
	pack_rec.name          = xstrdup("name");
	pack_rec.old_name      = xstrdup("old_name");
	pack_rec.uid           = 12345;

	Buf buf = init_buf(1024);
	slurmdb_pack_user_rec(&pack_rec, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_user_rec_t *unpack_rec;
	rc = slurmdb_unpack_user_rec((void **)&unpack_rec, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert_int_eq(rc, SLURM_SUCCESS);
	ck_assert_uint_eq(pack_rec.admin_level,            unpack_rec->admin_level);
	ck_assert_int_eq(list_count(pack_rec.assoc_list),  list_count(unpack_rec->assoc_list));
	ck_assert_int_eq(list_count(pack_rec.coord_accts), list_count(unpack_rec->coord_accts));
	ck_assert_int_eq(list_count(pack_rec.wckey_list),  list_count(unpack_rec->wckey_list));
	ck_assert_uint_eq(pack_rec.uid,                    unpack_rec->uid);
	ck_assert_str_eq(pack_rec.default_acct,            unpack_rec->default_acct);
	ck_assert_str_eq(pack_rec.default_wckey,           unpack_rec->default_wckey);
	ck_assert_str_eq(pack_rec.name,                    unpack_rec->name);
	ck_assert_str_eq(pack_rec.old_name,                unpack_rec->old_name);

	free_buf(buf);
	xfree(pack_rec.default_acct);
	xfree(pack_rec.default_wckey);
	xfree(pack_rec.name);
	xfree(pack_rec.old_name);
	slurmdb_destroy_user_rec(unpack_rec);
}
Ejemplo n.º 25
0
/****************************************************************************
 * Functions for agent to manage queue of pending message for the Slurm DBD
 ****************************************************************************/
static Buf _load_dbd_rec(int fd)
{
	ssize_t size, rd_size;
	uint32_t msg_size, magic;
	char *msg;
	Buf buffer;

	size = sizeof(msg_size);
	rd_size = read(fd, &msg_size, size);
	if (rd_size == 0)
		return (Buf) NULL;
	if (rd_size != size) {
		error("slurmdbd: state recover error: %m");
		return (Buf) NULL;
	}
	if (msg_size > MAX_DBD_MSG_LEN) {
		error("slurmdbd: state recover error, msg_size=%u", msg_size);
		return (Buf) NULL;
	}

	buffer = init_buf((int) msg_size);
	set_buf_offset(buffer, msg_size);
	msg = get_buf_data(buffer);
	size = msg_size;
	while (size) {
		rd_size = read(fd, msg, size);
		if ((rd_size > 0) && (rd_size <= size)) {
			msg += rd_size;
			size -= rd_size;
		} else if ((rd_size == -1) && (errno == EINTR))
			continue;
		else {
			error("slurmdbd: state recover error: %m");
			free_buf(buffer);
			return (Buf) NULL;
		}
	}

	size = sizeof(magic);
	rd_size = read(fd, &magic, size);
	if ((rd_size != size) || (magic != DBD_MAGIC)) {
		error("slurmdbd: state recover error");
		free_buf(buffer);
		return (Buf) NULL;
	}

	return buffer;
}
Ejemplo n.º 26
0
END_TEST

START_TEST(pack_1702_account_rec)
{
	int rc;

	slurmdb_account_rec_t *pack_ar = xmalloc(sizeof(slurmdb_account_rec_t));
	pack_ar->description           = xstrdup("default_acct");
	pack_ar->name                  = xstrdup("default_name");
	pack_ar->organization          = xstrdup("default_organization");
	pack_ar->assoc_list            = list_create(slurmdb_destroy_assoc_rec);
	pack_ar->coordinators          = list_create(slurmdb_destroy_coord_rec);
	slurmdb_coord_rec_t * j = xmalloc(sizeof(slurmdb_coord_rec_t));
	slurmdb_assoc_rec_t * k = xmalloc(sizeof(slurmdb_assoc_rec_t));

	k->lft    = 88;
	j->name   = xstrdup("Bertrand Russell");
	j->direct = 5;

	list_append(pack_ar->coordinators, (void *)j);
	list_append(pack_ar->assoc_list,   (void *)k);

	Buf buf = init_buf(1024);
	slurmdb_pack_account_rec(pack_ar, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_account_rec_t *unpack_ar;
	rc = slurmdb_unpack_account_rec((void **)&unpack_ar, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc                              == SLURM_SUCCESS);
	ck_assert_str_eq(pack_ar->description ,      unpack_ar->description);
	ck_assert_str_eq(pack_ar->name        ,      unpack_ar->name);
	ck_assert_str_eq(pack_ar->organization,      unpack_ar->organization);
	ck_assert(list_count(pack_ar->assoc_list) == list_count(unpack_ar->assoc_list));

	slurmdb_assoc_rec_t bar          = *(slurmdb_assoc_rec_t *)list_peek(pack_ar->assoc_list);
	slurmdb_assoc_rec_t aar          = *(slurmdb_assoc_rec_t *)list_peek(unpack_ar->assoc_list);
	slurmdb_coord_rec_t bc           = *(slurmdb_coord_rec_t *)list_peek(pack_ar->coordinators);
	slurmdb_coord_rec_t ac           = *(slurmdb_coord_rec_t *)list_peek(unpack_ar->coordinators);

	ck_assert_str_eq(bc.name,            ac.name);
	ck_assert(bc.direct              == ac.direct);
	ck_assert(bar.lft                == aar.lft);

	free_buf(buf);
	slurmdb_destroy_account_rec(pack_ar);
	slurmdb_destroy_account_rec(unpack_ar);
}
Ejemplo n.º 27
0
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;
}
Ejemplo n.º 28
0
extern int slurm_ckpt_unpack_job(check_jobinfo_t jobinfo, Buf buffer,
				 uint16_t protocol_version)
{
	uint16_t id;
	uint32_t x;
	uint32_t size;

	if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) {
		safe_unpack16(&id, buffer);
		safe_unpack32(&size, buffer);
		if (id != CHECK_NONE) {
			x = get_buf_offset(buffer);
			set_buf_offset(buffer, x + size);
		}
	}
	return SLURM_SUCCESS;

unpack_error:
	return SLURM_ERROR;
}
Ejemplo n.º 29
0
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;
}
Ejemplo n.º 30
0
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;
}