Esempio n. 1
0
extern int select_p_select_jobinfo_unpack(select_jobinfo_t **jobinfo_pptr,
					  Buf buffer, uint16_t protocol_version)
{
	int rc = SLURM_ERROR;
	select_jobinfo_t *jobinfo = xmalloc(sizeof(struct select_jobinfo));

	*jobinfo_pptr = jobinfo;

	jobinfo->magic = JOBINFO_MAGIC;
	if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) {
		safe_unpack8(&jobinfo->confirmed, buffer);
		safe_unpack32(&jobinfo->reservation_id, buffer);
		safe_unpack64(&jobinfo->confirm_cookie, buffer);
		rc = other_select_jobinfo_unpack(&jobinfo->other_jobinfo,
						 buffer, protocol_version);
	} else {
 		error("select_p_select_jobinfo_unpack: protocol_version "
 		      "%hu not supported", protocol_version);
	}

	if (rc != SLURM_SUCCESS)
		goto unpack_error;

	return SLURM_SUCCESS;

unpack_error:
	select_p_select_jobinfo_free(jobinfo);
	*jobinfo_pptr = NULL;

	return SLURM_ERROR;
}
Esempio n. 2
0
static void _state_read_buf(Buf buffer)
{
    uint16_t protocol_version = (uint16_t) NO_VAL;
    uint32_t min_port, max_port;
    int i;

    /* Validate state version */
    safe_unpack16(&protocol_version, buffer);
    debug3("Version in switch_cray header is %u", protocol_version);
    if (protocol_version < SLURM_MIN_PROTOCOL_VERSION) {
        error("******************************************************");
        error("Can't recover switch/cray state, incompatible version");
        error("******************************************************");
        return;
    }
    if (protocol_version >= SLURM_14_11_PROTOCOL_VERSION) {
        safe_unpack32(&min_port, buffer);
        safe_unpack32(&max_port, buffer);
        safe_unpack32(&last_alloc_port, buffer);
        unpack_bit_str(&port_resv, buffer);
    } else if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) {
        uint8_t port_set = 0;
        safe_unpack32(&min_port, buffer);
        safe_unpack32(&max_port, buffer);
        safe_unpack32(&last_alloc_port, buffer);
        port_resv = bit_alloc(PORT_CNT);
        for (i = 0; i < PORT_CNT; i++) {
            safe_unpack8(&port_set, buffer);
            if (port_set)
                bit_set(port_resv, i);
        }
    }
    if ((min_port != MIN_PORT) || (max_port != MAX_PORT)) {
        error("******************************************************");
        error("Can not recover switch/cray state");
        error("Changed MIN_PORT (%u != %u) and/or MAX_PORT (%u != %u)",
              min_port, MIN_PORT, max_port, MAX_PORT);
        error("******************************************************");
        return;
    }

    return;

unpack_error:
    CRAY_ERR("unpack error");
    return;
}
Esempio n. 3
0
extern int unpack_job_resources(job_resources_t **job_resrcs_pptr,
				Buf buffer, uint16_t protocol_version)
{
	char *bit_fmt = NULL;
	uint32_t empty, tmp32;
	job_resources_t *job_resrcs;
	uint32_t cluster_flags = slurmdb_setup_cluster_flags();

	xassert(job_resrcs_pptr);
	if (protocol_version >= SLURM_2_5_PROTOCOL_VERSION) {
		safe_unpack32(&empty, buffer);
		if (empty == NO_VAL) {
			*job_resrcs_pptr = NULL;
			return SLURM_SUCCESS;
		}

		job_resrcs = xmalloc(sizeof(struct job_resources));
		job_resrcs->nhosts = empty;
		safe_unpack32(&job_resrcs->ncpus, buffer);
		safe_unpack32(&job_resrcs->node_req, buffer);
		safe_unpackstr_xmalloc(&job_resrcs->nodes, &tmp32, buffer);

		safe_unpack32_array(&job_resrcs->cpu_array_reps,
				    &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->cpu_array_reps);
		job_resrcs->cpu_array_cnt = tmp32;

		safe_unpack16_array(&job_resrcs->cpu_array_value,
				    &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->cpu_array_value);

		if (tmp32 != job_resrcs->cpu_array_cnt)
			goto unpack_error;

		safe_unpack16_array(&job_resrcs->cpus, &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->cpus);
		if (tmp32 != job_resrcs->nhosts)
			goto unpack_error;
		safe_unpack16_array(&job_resrcs->cpus_used, &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->cpus_used);

		safe_unpack32_array(&job_resrcs->memory_allocated,
				    &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->memory_allocated);
		safe_unpack32_array(&job_resrcs->memory_used, &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->memory_used);

		if (!(cluster_flags & CLUSTER_FLAG_BG)) {
			safe_unpack16_array(&job_resrcs->sockets_per_node,
					    &tmp32, buffer);
			if (tmp32 == 0)
				xfree(job_resrcs->sockets_per_node);
			safe_unpack16_array(&job_resrcs->cores_per_socket,
					    &tmp32, buffer);
			if (tmp32 == 0)
				xfree(job_resrcs->cores_per_socket);
			safe_unpack32_array(&job_resrcs->sock_core_rep_count,
					    &tmp32, buffer);
			if (tmp32 == 0)
				xfree(job_resrcs->sock_core_rep_count);

			unpack_bit_str(&job_resrcs->core_bitmap, buffer);
			unpack_bit_str(&job_resrcs->core_bitmap_used, buffer);
		}
	} else if (protocol_version >= SLURM_2_3_PROTOCOL_VERSION) {
		uint8_t tmp_8;
		safe_unpack32(&empty, buffer);
		if (empty == NO_VAL) {
			*job_resrcs_pptr = NULL;
			return SLURM_SUCCESS;
		}

		job_resrcs = xmalloc(sizeof(struct job_resources));
		job_resrcs->nhosts = empty;
		safe_unpack32(&job_resrcs->ncpus, buffer);
		safe_unpack8(&tmp_8, buffer);
		if (tmp_8 < 100)		/* Not NODE_CR_RESERVED */
			job_resrcs->node_req = tmp_8;	/* 32-bit in v2.5 */
		else
			job_resrcs->node_req = NODE_CR_RESERVED;
		safe_unpackstr_xmalloc(&job_resrcs->nodes, &tmp32, buffer);

		safe_unpack32_array(&job_resrcs->cpu_array_reps,
				    &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->cpu_array_reps);
		job_resrcs->cpu_array_cnt = tmp32;

		safe_unpack16_array(&job_resrcs->cpu_array_value,
				    &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->cpu_array_value);

		if (tmp32 != job_resrcs->cpu_array_cnt)
			goto unpack_error;

		safe_unpack16_array(&job_resrcs->cpus, &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->cpus);
		if (tmp32 != job_resrcs->nhosts)
			goto unpack_error;
		safe_unpack16_array(&job_resrcs->cpus_used, &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->cpus_used);

		safe_unpack32_array(&job_resrcs->memory_allocated,
				    &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->memory_allocated);
		safe_unpack32_array(&job_resrcs->memory_used, &tmp32, buffer);
		if (tmp32 == 0)
			xfree(job_resrcs->memory_used);

		if (!(cluster_flags & CLUSTER_FLAG_BG)) {
			safe_unpack16_array(&job_resrcs->sockets_per_node,
					    &tmp32, buffer);
			if (tmp32 == 0)
				xfree(job_resrcs->sockets_per_node);
			safe_unpack16_array(&job_resrcs->cores_per_socket,
					    &tmp32, buffer);
			if (tmp32 == 0)
				xfree(job_resrcs->cores_per_socket);
			safe_unpack32_array(&job_resrcs->sock_core_rep_count,
					    &tmp32, buffer);
			if (tmp32 == 0)
				xfree(job_resrcs->sock_core_rep_count);

			unpack_bit_str(&job_resrcs->core_bitmap, buffer);
			unpack_bit_str(&job_resrcs->core_bitmap_used, buffer);
		}
	} else {
		error("unpack_job_resources: protocol_version %hu not "
		      "supported", protocol_version);
		goto unpack_error;
	}

	*job_resrcs_pptr = job_resrcs;
	return SLURM_SUCCESS;

unpack_error:
	error("unpack_job_resources: unpack error");
	free_job_resources(&job_resrcs);
	xfree(bit_fmt);
	*job_resrcs_pptr = NULL;
	return SLURM_ERROR;
}
Esempio n. 4
0
extern int jobacctinfo_unpack(jobacctinfo_t **jobacct,
			      uint16_t rpc_version, uint16_t protocol_type,
			      Buf buffer, bool alloc)
{
	uint32_t uint32_tmp;
	uint8_t  uint8_tmp;

	if (jobacct_gather_init() < 0)
		return SLURM_ERROR;

	if (rpc_version >= SLURM_MIN_PROTOCOL_VERSION) {
		safe_unpack8(&uint8_tmp, buffer);
		if (uint8_tmp == (uint8_t) 0)
			return SLURM_SUCCESS;
		if (alloc)
			*jobacct = xmalloc(sizeof(struct jobacctinfo));
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->user_cpu_sec = uint32_tmp;
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->user_cpu_usec = uint32_tmp;
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->sys_cpu_sec = uint32_tmp;
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->sys_cpu_usec = uint32_tmp;
		safe_unpack64(&(*jobacct)->max_vsize, buffer);
		safe_unpack64(&(*jobacct)->tot_vsize, buffer);
		safe_unpack64(&(*jobacct)->max_rss, buffer);
		safe_unpack64(&(*jobacct)->tot_rss, buffer);
		safe_unpack64(&(*jobacct)->max_pages, buffer);
		safe_unpack64(&(*jobacct)->tot_pages, buffer);
		safe_unpack32(&(*jobacct)->min_cpu, buffer);
		safe_unpackdouble(&(*jobacct)->tot_cpu, buffer);
		safe_unpack32(&(*jobacct)->act_cpufreq, buffer);
		safe_unpack64(&(*jobacct)->energy.consumed_energy, buffer);

		safe_unpackdouble(&(*jobacct)->max_disk_read, buffer);
		safe_unpackdouble(&(*jobacct)->tot_disk_read, buffer);
		safe_unpackdouble(&(*jobacct)->max_disk_write, buffer);
		safe_unpackdouble(&(*jobacct)->tot_disk_write, buffer);

		if (_unpack_jobacct_id(&(*jobacct)->max_vsize_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_rss_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_pages_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->min_cpu_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_disk_read_id,
			rpc_version, buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_disk_write_id,
			rpc_version, buffer) != SLURM_SUCCESS)
			goto unpack_error;
	} else {
		info("jobacctinfo_unpack version %u not supported",
		     rpc_version);
		return SLURM_ERROR;
	}

	return SLURM_SUCCESS;

unpack_error:
	debug2("jobacctinfo_unpack: unpack_error: size_buf(buffer) %u",
	       size_buf(buffer));
	if (alloc)
		xfree(*jobacct);
       	return SLURM_ERROR;
}
Esempio n. 5
0
extern int jobacctinfo_unpack(jobacctinfo_t **jobacct,
			      uint16_t rpc_version, uint16_t protocol_type,
			      Buf buffer, bool alloc)
{
	uint32_t uint32_tmp;
	uint8_t  uint8_tmp;
	bool no_pack;

	jobacct_gather_init();
	no_pack = (!plugin_polling && (protocol_type != PROTOCOL_TYPE_DBD));

	/* The function can take calls from both DBD and from regular
	 * SLURM functions.  We choose to standardize on using the
	 * SLURM_PROTOCOL_VERSION here so if PROTOCOL_TYPE_DBD comes
	 * in we need to translate the DBD rpc_version to use the
	 * SLURM protocol_version.
	 *
	 * If this function ever changes make sure the
	 * slurmdbd_translate_rpc function has been updated with the
	 * new protocol version.
	 */
	if (protocol_type == PROTOCOL_TYPE_DBD)
		rpc_version = slurmdbd_translate_rpc(rpc_version);

	if (rpc_version >= SLURM_14_03_PROTOCOL_VERSION) {
		safe_unpack8(&uint8_tmp, buffer);
		if (uint8_tmp == (uint8_t) 0)
			return SLURM_SUCCESS;
		if (alloc)
			*jobacct = xmalloc(sizeof(struct jobacctinfo));
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->user_cpu_sec = uint32_tmp;
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->user_cpu_usec = uint32_tmp;
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->sys_cpu_sec = uint32_tmp;
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->sys_cpu_usec = uint32_tmp;
		safe_unpack64(&(*jobacct)->max_vsize, buffer);
		safe_unpack64(&(*jobacct)->tot_vsize, buffer);
		safe_unpack64(&(*jobacct)->max_rss, buffer);
		safe_unpack64(&(*jobacct)->tot_rss, buffer);
		safe_unpack64(&(*jobacct)->max_pages, buffer);
		safe_unpack64(&(*jobacct)->tot_pages, buffer);
		safe_unpack32(&(*jobacct)->min_cpu, buffer);
		safe_unpack32(&(*jobacct)->tot_cpu, buffer);
		safe_unpack32(&(*jobacct)->act_cpufreq, buffer);
		safe_unpack32(&(*jobacct)->energy.consumed_energy, buffer);

		safe_unpackdouble(&(*jobacct)->max_disk_read, buffer);
		safe_unpackdouble(&(*jobacct)->tot_disk_read, buffer);
		safe_unpackdouble(&(*jobacct)->max_disk_write, buffer);
		safe_unpackdouble(&(*jobacct)->tot_disk_write, buffer);

		if (_unpack_jobacct_id(&(*jobacct)->max_vsize_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_rss_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_pages_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->min_cpu_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_disk_read_id,
			rpc_version, buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_disk_write_id,
			rpc_version, buffer) != SLURM_SUCCESS)
			goto unpack_error;
	} else if (rpc_version >= SLURM_2_6_PROTOCOL_VERSION) {
		if (no_pack)
			return SLURM_SUCCESS;
		if (alloc)
			*jobacct = xmalloc(sizeof(struct jobacctinfo));
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->user_cpu_sec = uint32_tmp;
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->user_cpu_usec = uint32_tmp;
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->sys_cpu_sec = uint32_tmp;
		safe_unpack32(&uint32_tmp, buffer);
		(*jobacct)->sys_cpu_usec = uint32_tmp;
		safe_unpack32((uint32_t *)&(*jobacct)->max_vsize, buffer);
		safe_unpack32((uint32_t *)&(*jobacct)->tot_vsize, buffer);
		safe_unpack32((uint32_t *)&(*jobacct)->max_rss, buffer);
		safe_unpack32((uint32_t *)&(*jobacct)->tot_rss, buffer);
		safe_unpack32((uint32_t *)&(*jobacct)->max_pages, buffer);
		safe_unpack32((uint32_t *)&(*jobacct)->tot_pages, buffer);
		safe_unpack32(&(*jobacct)->min_cpu, buffer);
		safe_unpack32(&(*jobacct)->tot_cpu, buffer);
		safe_unpack32(&(*jobacct)->act_cpufreq, buffer);
		safe_unpack32(&(*jobacct)->energy.consumed_energy, buffer);

		safe_unpackdouble(&(*jobacct)->max_disk_read, buffer);
		safe_unpackdouble(&(*jobacct)->tot_disk_read, buffer);
		safe_unpackdouble(&(*jobacct)->max_disk_write, buffer);
		safe_unpackdouble(&(*jobacct)->tot_disk_write, buffer);

		if (_unpack_jobacct_id(&(*jobacct)->max_vsize_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_rss_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_pages_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->min_cpu_id, rpc_version,
			buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_disk_read_id,
			rpc_version, buffer) != SLURM_SUCCESS)
			goto unpack_error;
		if (_unpack_jobacct_id(&(*jobacct)->max_disk_write_id,
			rpc_version, buffer) != SLURM_SUCCESS)
			goto unpack_error;
	} else {
		info("jobacctinfo_unpack version %u not supported",
		     rpc_version);
		return SLURM_ERROR;
	}

	return SLURM_SUCCESS;

unpack_error:
	debug2("jobacctinfo_unpack: unpack_error: size_buf(buffer) %u",
	       size_buf(buffer));
	if (alloc)
		xfree(*jobacct);
       	return SLURM_ERROR;
}
Esempio n. 6
0
static void _state_read_buf(Buf buffer)
{
	uint16_t protocol_version = (uint16_t) NO_VAL;
	uint32_t min_port, max_port;
	int i;

	/* Validate state version */
	safe_unpack16(&protocol_version, buffer);
	debug3("Version in switch_cray header is %u", protocol_version);
	if (protocol_version < SLURM_MIN_PROTOCOL_VERSION) {
		error("******************************************************");
		error("Can't recover switch/cray state, incompatible version");
		error("******************************************************");
		return;
	}

	pthread_mutex_lock(&port_mutex);
	if (protocol_version >= SLURM_14_11_PROTOCOL_VERSION) {
		safe_unpack32(&min_port, buffer);
		safe_unpack32(&max_port, buffer);
		safe_unpack32(&last_alloc_port, buffer);
		/* make sure we are NULL here */
		FREE_NULL_BITMAP(port_resv);
		unpack_bit_str_hex(&port_resv, buffer);
	} else if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) {
		uint8_t port_set = 0;
		safe_unpack32(&min_port, buffer);
		safe_unpack32(&max_port, buffer);
		safe_unpack32(&last_alloc_port, buffer);
		/* make sure we are NULL here */
		FREE_NULL_BITMAP(port_resv);
		port_resv = bit_alloc(PORT_CNT);
		for (i = 0; i < PORT_CNT; i++) {
			safe_unpack8(&port_set, buffer);
			if (port_set)
				bit_set(port_resv, i);
		}
	}

	if (!port_resv || (bit_size(port_resv) != PORT_CNT)) {
		error("_state_read_buf: Reserve Port size was %d not %d, "
		      "reallocating",
		      port_resv ? bit_size(port_resv) : -1, PORT_CNT);
		port_resv = bit_realloc(port_resv, PORT_CNT);
	}
	pthread_mutex_unlock(&port_mutex);

	if ((min_port != MIN_PORT) || (max_port != MAX_PORT)) {
		error("******************************************************");
		error("Can not recover switch/cray state");
		error("Changed MIN_PORT (%u != %u) and/or MAX_PORT (%u != %u)",
		      min_port, MIN_PORT, max_port, MAX_PORT);
		error("******************************************************");
		return;
	}

	return;

unpack_error:
	CRAY_ERR("unpack error");
	return;
}