Skip to content
Snippets Groups Projects
slurm_protocol_pack.c 69 KiB
Newer Older
/****************************************************************************\
 *  slurm_protocol_pack.c - functions to pack and unpack structures for RPCs
 *****************************************************************************
 *  Copyright (C) 2002 The Regents of the University of California.
 *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
 *  Written by Kevin Tew <tew1@llnl.gov>, Moe Jette <jette1@llnl.gov>, et. al.
 *  UCRL-CODE-2002-040.
 *  
 *  This file is part of SLURM, a resource management program.
 *  For details, see <http://www.llnl.gov/linux/slurm/>.
 *  
 *  SLURM is free software; you can redistribute it and/or modify it under
 *  the terms of the GNU General Public License as published by the Free
 *  Software Foundation; either version 2 of the License, or (at your option)
 *  any later version.
 *  
 *  SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
 *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 *  details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with SLURM; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
\*****************************************************************************/
#if HAVE_CONFIG_H
#  include "config.h"
#endif

#include <stdlib.h>
#include <errno.h>
#include <string.h>

#include "src/common/bitstring.h"
#include "src/common/log.h"
#include "src/common/pack.h"
#include "src/common/slurm_auth.h"
#include "src/common/slurm_cred.h"
#include "src/common/slurm_protocol_api.h"
#include "src/common/slurm_protocol_defs.h"
#include "src/common/slurm_protocol_pack.h"
#include "src/common/xmalloc.h"

#if HAVE_ELAN
#  include "src/common/qsw.h"
#endif

#define _pack_job_info_msg(msg,buf)		_pack_buffer_msg(msg,buf)
#define _pack_job_step_info_msg(msg,buf)	_pack_buffer_msg(msg,buf)

static void _pack_update_node_msg(update_node_msg_t * msg, Buf buffer);
static int _unpack_update_node_msg(update_node_msg_t ** msg, Buf buffer);

static void
 _pack_node_registration_status_msg(slurm_node_registration_status_msg_t *
				    msg, Buf buffer);
static int
 _unpack_node_registration_status_msg(slurm_node_registration_status_msg_t
				      ** msg, Buf buffer);

static void
 _pack_resource_allocation_response_msg(resource_allocation_response_msg_t *
					msg, Buf buffer);
static int
 _unpack_resource_allocation_response_msg(resource_allocation_response_msg_t
					  ** msg, Buf buffer);

static void
 _pack_resource_allocation_and_run_response_msg
    (resource_allocation_and_run_response_msg_t * msg, Buf buffer);
static int
 _unpack_resource_allocation_and_run_response_msg
    (resource_allocation_and_run_response_msg_t ** msg, Buf buffer);

static void _pack_submit_response_msg(submit_response_msg_t * msg,
				      Buf buffer);
static int _unpack_submit_response_msg(submit_response_msg_t ** msg,
				       Buf buffer);

static void _pack_node_info_msg(slurm_msg_t * msg, Buf buffer);
static int _unpack_node_info_msg(node_info_msg_t ** msg, Buf buffer);
static int _unpack_node_info_members(node_info_t * node, Buf buffer);

static void _pack_update_partition_msg(update_part_msg_t * msg, Buf buffer);
static int _unpack_update_partition_msg(update_part_msg_t ** msg, Buf buffer);

static void _pack_job_step_create_request_msg(job_step_create_request_msg_t
					      * msg, Buf buffer);
static int
 _unpack_job_step_create_request_msg(job_step_create_request_msg_t ** msg,
				     Buf buffer);

static void _pack_kill_job_msg(kill_job_msg_t * msg, Buf buffer);
static int _unpack_kill_job_msg(kill_job_msg_t ** msg, Buf buffer);
static void _pack_epilog_comp_msg(epilog_complete_msg_t * msg, Buf buffer);
static int  _unpack_epilog_comp_msg(epilog_complete_msg_t ** msg, Buf buffer);

static void _pack_update_job_time_msg(job_time_msg_t * msg, Buf buffer);
static int _unpack_update_job_time_msg(job_time_msg_t ** msg, Buf buffer);

static void
 _pack_job_step_create_response_msg(job_step_create_response_msg_t * msg,
				    Buf buffer);
static int
 _unpack_job_step_create_response_msg(job_step_create_response_msg_t ** msg,
				      Buf buffer);

static void _pack_partition_info_msg(slurm_msg_t * msg, Buf buffer);
static int _unpack_partition_info_msg(partition_info_msg_t ** msg,
				      Buf buffer);
static int _unpack_partition_info_members(partition_info_t * part,
					  Buf buffer);

static void _pack_launch_tasks_request_msg(launch_tasks_request_msg_t *
					   msg, Buf buffer);
static int _unpack_launch_tasks_request_msg(launch_tasks_request_msg_t **
					    msg_ptr, Buf buffer);

static void _pack_cancel_tasks_msg(kill_tasks_msg_t * msg, Buf buffer);
static int _unpack_cancel_tasks_msg(kill_tasks_msg_t ** msg_ptr, Buf buffer);

static void _pack_launch_tasks_response_msg(launch_tasks_response_msg_t *
					    msg, Buf buffer);
static int _unpack_launch_tasks_response_msg(launch_tasks_response_msg_t **
					     msg_ptr, Buf buffer);

static void _pack_shutdown_msg(shutdown_msg_t * msg, Buf buffer);
static int _unpack_shutdown_msg(shutdown_msg_t ** msg_ptr, Buf buffer);

static void _pack_reattach_tasks_request_msg(reattach_tasks_request_msg_t *,
					     Buf);
static int _unpack_reattach_tasks_request_msg(reattach_tasks_request_msg_t **,
					      Buf);

static void
 _pack_reattach_tasks_response_msg(reattach_tasks_response_msg_t *, Buf);
static int
 _unpack_reattach_tasks_response_msg(reattach_tasks_response_msg_t **, Buf);

static void _pack_task_exit_msg(task_exit_msg_t * msg, Buf buffer);
static int _unpack_task_exit_msg(task_exit_msg_t ** msg_ptr, Buf buffer);

static void _pack_old_job_desc_msg(old_job_alloc_msg_t * job_desc_ptr,
				   Buf buffer);
static int _unpack_old_job_desc_msg(old_job_alloc_msg_t **
				    job_desc_buffer_ptr, Buf buffer);

static void _pack_return_code_msg(return_code_msg_t * msg, Buf buffer);
static int _unpack_return_code_msg(return_code_msg_t ** msg, Buf buffer);

static void _pack_slurm_ctl_conf_msg(slurm_ctl_conf_info_msg_t * build_ptr,
				     Buf buffer);
static int _unpack_slurm_ctl_conf_msg(slurm_ctl_conf_info_msg_t **
				      build_buffer_ptr, Buf buffer);

static void _pack_job_step_id_msg(job_step_id_t * msg, Buf buffer);
static int _unpack_job_step_id_msg(job_step_id_t ** msg_ptr, Buf buffer);

static void _pack_get_job_step_info_msg(job_step_info_request_msg_t * msg,
					Buf buffer);
static int _unpack_get_job_step_info_msg(job_step_info_request_msg_t **
					 msg, Buf buffer);
static int _unpack_job_step_info_response_msg(job_step_info_response_msg_t
					      ** msg, Buf buffer);
static int _unpack_job_step_info_members(job_step_info_t * step, Buf buffer);

static void _pack_complete_job_step_msg(complete_job_step_msg_t * msg,
					Buf buffer);
static int _unpack_complete_job_step_msg(complete_job_step_msg_t **
					 msg_ptr, Buf buffer);
static int _unpack_job_info_members(job_info_t * job, Buf buffer);

static void _pack_batch_job_launch_msg(batch_job_launch_msg_t * msg,
				       Buf buffer);
static int _unpack_batch_job_launch_msg(batch_job_launch_msg_t ** msg,
					Buf buffer);

static void _pack_job_desc_msg(job_desc_msg_t * job_desc_ptr, Buf buffer);
static int _unpack_job_desc_msg(job_desc_msg_t ** job_desc_buffer_ptr,
				Buf buffer);
static int _unpack_job_info_msg(job_info_msg_t ** msg, Buf buffer);

static void _pack_last_update_msg(last_update_msg_t * msg, Buf buffer);
static int _unpack_last_update_msg(last_update_msg_t ** msg, Buf buffer);

static void _pack_slurm_addr_array(slurm_addr * slurm_address,
				   uint16_t size_val, Buf buffer);
static int _unpack_slurm_addr_array(slurm_addr ** slurm_address,
				    uint16_t * size_val, Buf buffer);

static void _pack_job_id_request_msg(job_id_request_msg_t * msg, Buf buffer);
static int  _unpack_job_id_request_msg(job_id_request_msg_t ** msg, Buf buffer);

static void _pack_job_id_response_msg(job_id_response_msg_t * msg, Buf buffer);
static int  _unpack_job_id_response_msg(job_id_response_msg_t ** msg, 
					Buf buffer);

static void _pack_job_step_kill_msg(job_step_kill_msg_t * msg, Buf buffer);
static int  _unpack_job_step_kill_msg(job_step_kill_msg_t ** msg_ptr, 
				      Buf buffer);

static void _pack_buffer_msg(slurm_msg_t * msg, Buf buffer);
tewk's avatar
tewk committed
/* pack_header
 * packs a slurm protocol header that proceeds every slurm message
 * IN header - the header structure to pack
 * IN/OUT buffer - destination of the pack, contains pointers that are
 *			automatically updated
tewk's avatar
tewk committed
 */
void
pack_header(header_t * header, Buf buffer)
	pack16(header->version, buffer);
	pack16(header->flags, buffer);
	pack16((uint16_t) header->msg_type, buffer);
	pack32(header->body_length, buffer);
tewk's avatar
tewk committed
/* unpack_header
 * unpacks a slurm protocol header that proceeds every slurm message
 * OUT header - the header structure to unpack
 * IN/OUT buffer - source of the unpack data, contains pointers that are
 *			automatically updated
 * RET 0 or error code
tewk's avatar
tewk committed
 */
int
unpack_header(header_t * header, Buf buffer)
	uint16_t tmp = 0;
	safe_unpack16(&header->version, buffer);
	safe_unpack16(&header->flags, buffer);
	safe_unpack16(&tmp, buffer);
	header->msg_type = (slurm_msg_type_t) tmp;
	safe_unpack32(&header->body_length, buffer);
tewk's avatar
tewk committed
/* pack_msg
 * packs a generic slurm protocol message body
 * IN msg - the body structure to pack (note: includes message type)
 * IN/OUT buffer - destination of the pack, contains pointers that are 
 *			automatically updated
 * RET 0 or error code
tewk's avatar
tewk committed
 */
int
pack_msg(slurm_msg_t const *msg, Buf buffer)
{
	switch (msg->msg_type) {
	 case REQUEST_BUILD_INFO:
	 case REQUEST_NODE_INFO:
	 case REQUEST_PARTITION_INFO:
	 case REQUEST_ACCTING_INFO:
		 _pack_last_update_msg((last_update_msg_t *)
				       msg->data, buffer);
		 break;
	 case RESPONSE_BUILD_INFO:
		 _pack_slurm_ctl_conf_msg((slurm_ctl_conf_info_msg_t *)
					  msg->data, buffer);
		 break;
	 case RESPONSE_JOB_INFO:
		 _pack_job_info_msg((slurm_msg_t *) msg, buffer);
		 break;
	 case RESPONSE_PARTITION_INFO:
		 _pack_partition_info_msg((slurm_msg_t *) msg, buffer);
		 break;
	 case RESPONSE_NODE_INFO:
		 _pack_node_info_msg((slurm_msg_t *) msg, buffer);
		 break;
	 case MESSAGE_NODE_REGISTRATION_STATUS:
		 _pack_node_registration_status_msg(
			(slurm_node_registration_status_msg_t *) msg->data, 
			buffer);
		 break;
	 case REQUEST_RESOURCE_ALLOCATION:
	 case REQUEST_SUBMIT_BATCH_JOB:
	 case REQUEST_JOB_WILL_RUN:
	 case REQUEST_ALLOCATION_AND_RUN_JOB_STEP:
	 case REQUEST_UPDATE_JOB:
		 _pack_job_desc_msg((job_desc_msg_t *)
				    msg->data, buffer);
		 break;
	 case REQUEST_OLD_JOB_RESOURCE_ALLOCATION:
		 _pack_old_job_desc_msg((old_job_alloc_msg_t *) msg->data,
					buffer);
		 break;
	 case REQUEST_NODE_REGISTRATION_STATUS:
	 case REQUEST_RECONFIGURE:
	 case REQUEST_SHUTDOWN_IMMEDIATE:
	 case REQUEST_PING:
	 case REQUEST_CONTROL:
		 /* Message contains no body/information */
		 break;
	 case REQUEST_SHUTDOWN:
		 _pack_shutdown_msg((shutdown_msg_t *) msg->data, buffer);
		 break;
	 case RESPONSE_SUBMIT_BATCH_JOB:
		 _pack_submit_response_msg((submit_response_msg_t *) 
					   msg->data, buffer);
		 break;
	 case RESPONSE_RESOURCE_ALLOCATION:
	 case RESPONSE_JOB_WILL_RUN:
		 _pack_resource_allocation_response_msg
		     ((resource_allocation_response_msg_t *) msg->data,
		      buffer);
		 break;
	 case RESPONSE_ALLOCATION_AND_RUN_JOB_STEP:
		 _pack_resource_allocation_and_run_response_msg(
			(resource_allocation_and_run_response_msg_t *) 
			msg->data, buffer);
		 break;
	 case REQUEST_UPDATE_NODE:
		 _pack_update_node_msg((update_node_msg_t *) msg->data,
				       buffer);
		 break;
	 case REQUEST_UPDATE_PARTITION:
		 _pack_update_partition_msg((update_part_msg_t *) msg->
					    data, buffer);
		 break;
	 case REQUEST_REATTACH_TASKS:
		 _pack_reattach_tasks_request_msg(
			(reattach_tasks_request_msg_t *) msg->data, buffer);
		 break;
	 case RESPONSE_REATTACH_TASKS:
		 _pack_reattach_tasks_response_msg(
			(reattach_tasks_response_msg_t *) msg->data, buffer);
		 break;
	 case REQUEST_LAUNCH_TASKS:
		 _pack_launch_tasks_request_msg(
				(launch_tasks_request_msg_t *) msg->data, 
				buffer);
		 break;
	 case RESPONSE_LAUNCH_TASKS:
		 _pack_launch_tasks_response_msg((launch_tasks_response_msg_t
						  *) msg->data, buffer);
		 break;
	 case REQUEST_KILL_TASKS:
		 _pack_cancel_tasks_msg((kill_tasks_msg_t *) msg->data,
					buffer);
		 break;
	 case REQUEST_JOB_STEP_INFO:
		 _pack_get_job_step_info_msg((job_step_info_request_msg_t
					      *) msg->data, buffer);
		 break;
Loading
Loading full blame...