From c862639c571b93ec48a8d9bf57e947bc6ebef07c Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Thu, 20 Nov 2003 20:53:29 +0000
Subject: [PATCH] Move all slurm message free calls into slurm_protocol_defs.
 Remove src/api/free_msg.c.

---
 src/api/Makefile.am              |   1 -
 src/api/free_msg.c               | 327 -------------------------------
 src/common/slurm_protocol_defs.c | 288 +++++++++++++++++++++++++++
 src/common/slurm_protocol_defs.h |  14 ++
 src/slurmctld/Makefile.am        |   1 -
 src/slurmctld/agent.c            |   2 -
 6 files changed, 302 insertions(+), 331 deletions(-)
 delete mode 100644 src/api/free_msg.c

diff --git a/src/api/Makefile.am b/src/api/Makefile.am
index 34bfa77aacc..9364a6a8e5e 100644
--- a/src/api/Makefile.am
+++ b/src/api/Makefile.am
@@ -31,7 +31,6 @@ libslurm_la_SOURCES =    \
 	cancel.c         \
 	complete.c       \
 	config_info.c    \
-	free_msg.c       \
 	init_msg.c       \
 	job_info.c       \
 	job_step_info.c  \
diff --git a/src/api/free_msg.c b/src/api/free_msg.c
deleted file mode 100644
index 8e60ad99173..00000000000
--- a/src/api/free_msg.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/*****************************************************************************\
- *  free_msg.c - free RPC response messages including all allocated memory
- *****************************************************************************
- *  Copyright (C) 2002 The Regents of the University of California.
- *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
- *  Written by moe jette <jette1@llnl.gov>.
- *  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.
-\*****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#  include "config.h"
-#endif
-
-#include <errno.h>
-#include <stdio.h>
-
-#include <slurm/slurm.h>
-
-#include "src/common/slurm_cred.h"
-#include "src/common/slurm_protocol_api.h"
-#include "src/common/xmalloc.h"
-
-static void _free_all_job_info (job_info_msg_t *msg);
-static void _slurm_free_job_info_members (job_info_t * job);
-
-static void _free_all_node_info (node_info_msg_t *msg);
-static void _slurm_free_node_info_members (node_info_t * node);
-
-static void _free_all_partitions (partition_info_msg_t *msg);
-static void _slurm_free_partition_info_members (partition_info_t * part);
-
-static void _free_all_step_info (job_step_info_response_msg_t *msg);
-static void _slurm_free_job_step_info_members (job_step_info_t * msg);
-
-
-/*
- * slurm_free_resource_allocation_response_msg - free slurm resource
- *	allocation response message
- * IN msg - pointer to allocation response message
- * NOTE: buffer is loaded by slurm_allocate_resources
- */
-void slurm_free_resource_allocation_response_msg ( 
-				resource_allocation_response_msg_t * msg)
-{
-	if (msg) {
-		xfree(msg->node_list);
-		xfree(msg->cpus_per_node);
-		xfree(msg->cpu_count_reps);
-		xfree(msg->node_addr);
-		xfree(msg);
-	}
-}
-
-
-/*
- * slurm_free_resource_allocation_and_run_response_msg - free slurm 
- *	resource allocation and run job step response message
- * IN msg - pointer to allocation and run job step response message
- * NOTE: buffer is loaded by slurm_allocate_resources_and_run
- */
-void slurm_free_resource_allocation_and_run_response_msg ( 
-			resource_allocation_and_run_response_msg_t * msg)
-{
-	if (msg) {
-		xfree(msg->node_list);
-		xfree(msg->cpus_per_node);
-		xfree(msg->cpu_count_reps);
-		xfree(msg->node_addr);
-		slurm_cred_destroy(msg->cred);
-#		ifdef HAVE_LIBELAN3
-		if (msg->qsw_job)
-			qsw_free_jobinfo(msg->qsw_job);
-#		endif
-		xfree(msg);
-	}
-}
-
-
-/*
- * slurm_free_job_step_create_response_msg - free slurm 
- *	job step create response message
- * IN msg - pointer to job step create response message
- * NOTE: buffer is loaded by slurm_job_step_create
- */
-void slurm_free_job_step_create_response_msg(
-		job_step_create_response_msg_t * msg)
-{
-	if (msg) {
-		slurm_cred_destroy(msg->cred);
-
-#		ifdef HAVE_LIBELAN3
-		if (msg->qsw_job)
-			qsw_free_jobinfo(msg->qsw_job);
-#		endif
-
-		xfree(msg);
-	}
-
-}
-
-
-/*
- * slurm_free_submit_response_response_msg - free slurm 
- *	job submit response message
- * IN msg - pointer to job submit response message
- * NOTE: buffer is loaded by slurm_submit_batch_job
- */
-void slurm_free_submit_response_response_msg(submit_response_msg_t * msg)
-{
-	if (msg)
-		xfree(msg);
-}
-
-
-/*
- * slurm_free_ctl_conf - free slurm control information response message
- * IN msg - pointer to slurm control information response message
- * NOTE: buffer is loaded by slurm_load_jobs
- */
-void slurm_free_ctl_conf(slurm_ctl_conf_info_msg_t * config_ptr)
-{
-	if (config_ptr) {
-		xfree(config_ptr->authtype);
-		xfree(config_ptr->backup_addr);
-		xfree(config_ptr->backup_controller);
-		xfree(config_ptr->control_addr);
-		xfree(config_ptr->control_machine);
-		xfree(config_ptr->epilog);
-		xfree(config_ptr->job_comp_loc);
-		xfree(config_ptr->job_comp_type);
-		xfree(config_ptr->job_credential_private_key);
-		xfree(config_ptr->job_credential_public_certificate);
-		xfree(config_ptr->plugindir);
-		xfree(config_ptr->prolog);
-		xfree(config_ptr->slurm_user_name);
-		xfree(config_ptr->slurmctld_pidfile);
-		xfree(config_ptr->slurmctld_logfile);
-		xfree(config_ptr->slurmd_logfile);
-		xfree(config_ptr->slurmd_pidfile);
-		xfree(config_ptr->slurmd_spooldir);
-		xfree(config_ptr->slurm_conf);
-		xfree(config_ptr->state_save_location);
-		xfree(config_ptr->tmp_fs);
-		xfree(config_ptr);
-	}
-}
-
-
-/*
- * slurm_free_job_info - free the job information response message
- * IN msg - pointer to job information response message
- * NOTE: buffer is loaded by slurm_load_job.
- */
-void slurm_free_job_info_msg(job_info_msg_t * job_buffer_ptr)
-{
-	if (job_buffer_ptr) {
-		if (job_buffer_ptr->job_array) {
-			_free_all_job_info(job_buffer_ptr);
-			xfree(job_buffer_ptr->job_array);
-		}
-		xfree(job_buffer_ptr);
-	}
-}
-
-static void _free_all_job_info(job_info_msg_t *msg)
-{
-	int i;
-
-	if ((msg == NULL) ||
-	    (msg->job_array == NULL))
-		return;
-
-	for (i = 0; i < msg->record_count; i++)
-		_slurm_free_job_info_members (&msg->job_array[i]);
-}
-
-static void _slurm_free_job_info_members(job_info_t * job)
-{
-	if (job) {
-		xfree(job->nodes);
-		xfree(job->partition);
-		xfree(job->alloc_node);
-		xfree(job->name);
-		xfree(job->node_inx);
-		xfree(job->req_nodes);
-		xfree(job->features);
-		xfree(job->req_node_inx);
-	}
-}
-
-
-/*
- * slurm_free_job_step_info_response_msg - free the job step 
- *	information response message
- * IN msg - pointer to job step information response message
- * NOTE: buffer is loaded by slurm_get_job_steps.
- */
-void slurm_free_job_step_info_response_msg(job_step_info_response_msg_t *
-					   msg)
-{
-	if (msg != NULL) {
-		if (msg->job_steps != NULL) {
-			_free_all_step_info(msg);
-			xfree(msg->job_steps);
-		}
-		xfree(msg);
-	}
-}
-
-static void _free_all_step_info (job_step_info_response_msg_t *msg)
-{
-	int i;
-
-	if ((msg == NULL) ||
-	    (msg->job_steps == NULL))
-		return;
-
-	for (i = 0; i < msg->job_step_count; i++)
-		_slurm_free_job_step_info_members (&msg->job_steps[i]);
-}
-
-static void _slurm_free_job_step_info_members (job_step_info_t * msg)
-{
-	if (msg != NULL) {
-		xfree(msg->partition);
-		xfree(msg->nodes);
-	}
-}
-
-
-/*
- * slurm_free_node_info - free the node information response message
- * IN msg - pointer to node information response message
- * NOTE: buffer is loaded by slurm_load_node.
- */
-void slurm_free_node_info_msg(node_info_msg_t * msg)
-{
-	if (msg) {
-		if (msg->node_array) {
-			_free_all_node_info(msg);
-			xfree(msg->node_array);
-		}
-		xfree(msg);
-	}
-}
-
-static void _free_all_node_info(node_info_msg_t *msg)
-{
-	int i;
-
-	if ((msg == NULL) ||
-	    (msg->node_array == NULL))
-		return;
-	
-	for (i = 0; i < msg->record_count; i++) 
-		_slurm_free_node_info_members(&msg->node_array[i]);
-}
-
-static void _slurm_free_node_info_members(node_info_t * node)
-{
-	if (node) {
-		xfree(node->name);
-		xfree(node->features);
-		xfree(node->partition);
-		xfree(node->reason);
-	}
-}
-
-
-/*
- * slurm_free_partition_info_msg - free the partition information 
- *	response message
- * IN msg - pointer to partition information response message
- * NOTE: buffer is loaded by slurm_load_partitions
- */
-void slurm_free_partition_info_msg(partition_info_msg_t * msg)
-{
-	if (msg) {
-		if (msg->partition_array) {
-			_free_all_partitions(msg);
-			xfree(msg->partition_array);
-		}
-		xfree(msg);
-	}
-}
-
-static void  _free_all_partitions(partition_info_msg_t *msg)
-{
-	int i;
-
-	if ((msg == NULL) ||
-	    (msg->partition_array == NULL))
-		return;
-
-	for (i = 0; i < msg->record_count; i++)
-		_slurm_free_partition_info_members(
-			&msg->partition_array[i]);
-
-}
-
-static void _slurm_free_partition_info_members(partition_info_t * part)
-{
-	if (part) {
-		xfree(part->name);
-		xfree(part->allow_groups);
-		xfree(part->nodes);
-		xfree(part->node_inx);
-	}
-}
-
diff --git a/src/common/slurm_protocol_defs.c b/src/common/slurm_protocol_defs.c
index bdad7d0a955..594cada2f0e 100644
--- a/src/common/slurm_protocol_defs.c
+++ b/src/common/slurm_protocol_defs.c
@@ -41,6 +41,18 @@
 #include "src/common/slurm_protocol_defs.h"
 #include "src/common/xmalloc.h"
 
+static void _free_all_job_info (job_info_msg_t *msg);
+static void _slurm_free_job_info_members (job_info_t * job);
+
+static void _free_all_node_info (node_info_msg_t *msg);
+static void _slurm_free_node_info_members (node_info_t * node);
+
+static void _free_all_partitions (partition_info_msg_t *msg);
+static void _slurm_free_partition_info_members (partition_info_t * part);
+
+static void _free_all_step_info (job_step_info_response_msg_t *msg);
+static void _slurm_free_job_step_info_members (job_step_info_t * msg);
+
 
 void slurm_free_last_update_msg(last_update_msg_t * msg)
 {
@@ -426,3 +438,279 @@ char *node_state_string_compact(enum node_states inx)
 	else
 		return node_state_string[inx];
 }
+
+/*
+ * slurm_free_resource_allocation_response_msg - free slurm resource
+ *	allocation response message
+ * IN msg - pointer to allocation response message
+ * NOTE: buffer is loaded by slurm_allocate_resources
+ */
+void slurm_free_resource_allocation_response_msg ( 
+				resource_allocation_response_msg_t * msg)
+{
+	if (msg) {
+		xfree(msg->node_list);
+		xfree(msg->cpus_per_node);
+		xfree(msg->cpu_count_reps);
+		xfree(msg->node_addr);
+		xfree(msg);
+	}
+}
+
+
+/*
+ * slurm_free_resource_allocation_and_run_response_msg - free slurm 
+ *	resource allocation and run job step response message
+ * IN msg - pointer to allocation and run job step response message
+ * NOTE: buffer is loaded by slurm_allocate_resources_and_run
+ */
+void slurm_free_resource_allocation_and_run_response_msg ( 
+			resource_allocation_and_run_response_msg_t * msg)
+{
+	if (msg) {
+		xfree(msg->node_list);
+		xfree(msg->cpus_per_node);
+		xfree(msg->cpu_count_reps);
+		xfree(msg->node_addr);
+		slurm_cred_destroy(msg->cred);
+#		ifdef HAVE_LIBELAN3
+		if (msg->qsw_job)
+			qsw_free_jobinfo(msg->qsw_job);
+#		endif
+		xfree(msg);
+	}
+}
+
+
+/*
+ * slurm_free_job_step_create_response_msg - free slurm 
+ *	job step create response message
+ * IN msg - pointer to job step create response message
+ * NOTE: buffer is loaded by slurm_job_step_create
+ */
+void slurm_free_job_step_create_response_msg(
+		job_step_create_response_msg_t * msg)
+{
+	if (msg) {
+		slurm_cred_destroy(msg->cred);
+
+#		ifdef HAVE_LIBELAN3
+		if (msg->qsw_job)
+			qsw_free_jobinfo(msg->qsw_job);
+#		endif
+
+		xfree(msg);
+	}
+
+}
+
+
+/*
+ * slurm_free_submit_response_response_msg - free slurm 
+ *	job submit response message
+ * IN msg - pointer to job submit response message
+ * NOTE: buffer is loaded by slurm_submit_batch_job
+ */
+void slurm_free_submit_response_response_msg(submit_response_msg_t * msg)
+{
+	if (msg)
+		xfree(msg);
+}
+
+
+/*
+ * slurm_free_ctl_conf - free slurm control information response message
+ * IN msg - pointer to slurm control information response message
+ * NOTE: buffer is loaded by slurm_load_jobs
+ */
+void slurm_free_ctl_conf(slurm_ctl_conf_info_msg_t * config_ptr)
+{
+	if (config_ptr) {
+		xfree(config_ptr->authtype);
+		xfree(config_ptr->backup_addr);
+		xfree(config_ptr->backup_controller);
+		xfree(config_ptr->control_addr);
+		xfree(config_ptr->control_machine);
+		xfree(config_ptr->epilog);
+		xfree(config_ptr->job_comp_loc);
+		xfree(config_ptr->job_comp_type);
+		xfree(config_ptr->job_credential_private_key);
+		xfree(config_ptr->job_credential_public_certificate);
+		xfree(config_ptr->plugindir);
+		xfree(config_ptr->prolog);
+		xfree(config_ptr->slurm_user_name);
+		xfree(config_ptr->slurmctld_pidfile);
+		xfree(config_ptr->slurmctld_logfile);
+		xfree(config_ptr->slurmd_logfile);
+		xfree(config_ptr->slurmd_pidfile);
+		xfree(config_ptr->slurmd_spooldir);
+		xfree(config_ptr->slurm_conf);
+		xfree(config_ptr->state_save_location);
+		xfree(config_ptr->tmp_fs);
+		xfree(config_ptr);
+	}
+}
+
+
+/*
+ * slurm_free_job_info - free the job information response message
+ * IN msg - pointer to job information response message
+ * NOTE: buffer is loaded by slurm_load_job.
+ */
+void slurm_free_job_info_msg(job_info_msg_t * job_buffer_ptr)
+{
+	if (job_buffer_ptr) {
+		if (job_buffer_ptr->job_array) {
+			_free_all_job_info(job_buffer_ptr);
+			xfree(job_buffer_ptr->job_array);
+		}
+		xfree(job_buffer_ptr);
+	}
+}
+
+static void _free_all_job_info(job_info_msg_t *msg)
+{
+	int i;
+
+	if ((msg == NULL) ||
+	    (msg->job_array == NULL))
+		return;
+
+	for (i = 0; i < msg->record_count; i++)
+		_slurm_free_job_info_members (&msg->job_array[i]);
+}
+
+static void _slurm_free_job_info_members(job_info_t * job)
+{
+	if (job) {
+		xfree(job->nodes);
+		xfree(job->partition);
+		xfree(job->alloc_node);
+		xfree(job->name);
+		xfree(job->node_inx);
+		xfree(job->req_nodes);
+		xfree(job->features);
+		xfree(job->req_node_inx);
+	}
+}
+
+
+/*
+ * slurm_free_job_step_info_response_msg - free the job step 
+ *	information response message
+ * IN msg - pointer to job step information response message
+ * NOTE: buffer is loaded by slurm_get_job_steps.
+ */
+void slurm_free_job_step_info_response_msg(job_step_info_response_msg_t *
+					   msg)
+{
+	if (msg != NULL) {
+		if (msg->job_steps != NULL) {
+			_free_all_step_info(msg);
+			xfree(msg->job_steps);
+		}
+		xfree(msg);
+	}
+}
+
+static void _free_all_step_info (job_step_info_response_msg_t *msg)
+{
+	int i;
+
+	if ((msg == NULL) ||
+	    (msg->job_steps == NULL))
+		return;
+
+	for (i = 0; i < msg->job_step_count; i++)
+		_slurm_free_job_step_info_members (&msg->job_steps[i]);
+}
+
+static void _slurm_free_job_step_info_members (job_step_info_t * msg)
+{
+	if (msg != NULL) {
+		xfree(msg->partition);
+		xfree(msg->nodes);
+	}
+}
+
+
+/*
+ * slurm_free_node_info - free the node information response message
+ * IN msg - pointer to node information response message
+ * NOTE: buffer is loaded by slurm_load_node.
+ */
+void slurm_free_node_info_msg(node_info_msg_t * msg)
+{
+	if (msg) {
+		if (msg->node_array) {
+			_free_all_node_info(msg);
+			xfree(msg->node_array);
+		}
+		xfree(msg);
+	}
+}
+
+static void _free_all_node_info(node_info_msg_t *msg)
+{
+	int i;
+
+	if ((msg == NULL) ||
+	    (msg->node_array == NULL))
+		return;
+	
+	for (i = 0; i < msg->record_count; i++) 
+		_slurm_free_node_info_members(&msg->node_array[i]);
+}
+
+static void _slurm_free_node_info_members(node_info_t * node)
+{
+	if (node) {
+		xfree(node->name);
+		xfree(node->features);
+		xfree(node->partition);
+		xfree(node->reason);
+	}
+}
+
+
+/*
+ * slurm_free_partition_info_msg - free the partition information 
+ *	response message
+ * IN msg - pointer to partition information response message
+ * NOTE: buffer is loaded by slurm_load_partitions
+ */
+void slurm_free_partition_info_msg(partition_info_msg_t * msg)
+{
+	if (msg) {
+		if (msg->partition_array) {
+			_free_all_partitions(msg);
+			xfree(msg->partition_array);
+		}
+		xfree(msg);
+	}
+}
+
+static void  _free_all_partitions(partition_info_msg_t *msg)
+{
+	int i;
+
+	if ((msg == NULL) ||
+	    (msg->partition_array == NULL))
+		return;
+
+	for (i = 0; i < msg->record_count; i++)
+		_slurm_free_partition_info_members(
+			&msg->partition_array[i]);
+
+}
+
+static void _slurm_free_partition_info_members(partition_info_t * part)
+{
+	if (part) {
+		xfree(part->name);
+		xfree(part->allow_groups);
+		xfree(part->nodes);
+		xfree(part->node_inx);
+	}
+}
+
diff --git a/src/common/slurm_protocol_defs.h b/src/common/slurm_protocol_defs.h
index b911ffca056..938183df33f 100644
--- a/src/common/slurm_protocol_defs.h
+++ b/src/common/slurm_protocol_defs.h
@@ -433,6 +433,20 @@ void inline slurm_free_srun_ping_msg(srun_ping_msg_t * msg);
 void inline slurm_free_srun_node_fail_msg(srun_node_fail_msg_t * msg);
 void inline slurm_free_srun_timeout_msg(srun_timeout_msg_t * msg);
 
+void slurm_free_resource_allocation_response_msg (
+		resource_allocation_response_msg_t * msg);
+void slurm_free_resource_allocation_and_run_response_msg (
+		resource_allocation_and_run_response_msg_t * msg);
+void slurm_free_job_step_create_response_msg(
+		job_step_create_response_msg_t * msg);
+void slurm_free_submit_response_response_msg(submit_response_msg_t * msg);
+void slurm_free_ctl_conf(slurm_ctl_conf_info_msg_t * config_ptr);
+void slurm_free_job_info_msg(job_info_msg_t * job_buffer_ptr);
+void slurm_free_job_step_info_response_msg(
+		job_step_info_response_msg_t * msg);
+void slurm_free_node_info_msg(node_info_msg_t * msg);
+void slurm_free_partition_info_msg(partition_info_msg_t * msg);
+
 extern char *job_dist_string(uint16_t inx);
 extern char *job_state_string(enum job_states inx);
 extern char *job_state_string_compact(enum job_states inx);
diff --git a/src/slurmctld/Makefile.am b/src/slurmctld/Makefile.am
index 92841c856b0..21f3906d06a 100644
--- a/src/slurmctld/Makefile.am
+++ b/src/slurmctld/Makefile.am
@@ -12,7 +12,6 @@ sbin_PROGRAMS = slurmctld
 slurmctld_LDADD = 					\
 	$(top_builddir)/src/common/libcommon.la    	\
 	$(top_builddir)/src/common/libhostlist.la      	\
-	$(top_builddir)/src/api/libslurm.la		\
 	$(top_builddir)/src/common/libdaemonize.la 
 
 
diff --git a/src/slurmctld/agent.c b/src/slurmctld/agent.c
index d112335b7bf..57c67a55523 100644
--- a/src/slurmctld/agent.c
+++ b/src/slurmctld/agent.c
@@ -58,8 +58,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <slurm/slurm.h>
-
 #include "src/common/list.h"
 #include "src/common/log.h"
 #include "src/common/macros.h"
-- 
GitLab