From 470f86ef81cdc33840b36587a6987b0b827927d4 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Wed, 20 Sep 2006 18:21:53 +0000
Subject: [PATCH] Added new job field, "comment". Set by srun, salloc and
 sbatch. See     with "scontrol show job". Used in sched/wiki2.

---
 NEWS                               |  2 ++
 doc/man/man1/salloc.1              |  4 ++++
 doc/man/man1/sbatch.1              |  4 ++++
 doc/man/man1/srun.1                |  8 +++++++-
 slurm/slurm.h.in                   |  2 ++
 src/api/init_msg.c                 |  1 +
 src/api/job_info.c                 | 10 ++++++++++
 src/common/slurm_protocol_defs.c   | 25 +++----------------------
 src/common/slurm_protocol_pack.c   |  4 ++++
 src/plugins/sched/wiki2/get_jobs.c |  4 ++--
 src/salloc/opt.c                   | 11 ++++++++++-
 src/salloc/opt.h                   |  1 +
 src/salloc/salloc.c                |  2 ++
 src/sbatch/opt.c                   | 11 ++++++++++-
 src/sbatch/opt.h                   |  1 +
 src/sbatch/sbatch.c                |  2 ++
 src/slurmctld/job_mgr.c            | 13 +++++++++++--
 src/slurmctld/slurmctld.h          |  1 +
 src/srun/allocate.c                |  3 +++
 src/srun/opt.c                     | 13 +++++++------
 src/srun/opt.h                     |  1 +
 21 files changed, 88 insertions(+), 35 deletions(-)

diff --git a/NEWS b/NEWS
index 72bc9e32b79..e4db47c3ab9 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ documents those changes that are of interest to users and admins.
  -- fixed certain tests in test suite to not run with bluegene or front-end 
     systems
  -- removed addresses from slurm_step_layout_t
+ -- Added new job field, "comment". Set by srun, salloc and sbatch. See 
+    with "scontrol show job". Used in sched/wiki2.
 
 * Changes in SLURM 1.2.0-pre2
 =============================
diff --git a/doc/man/man1/salloc.1 b/doc/man/man1/salloc.1
index 32f0d357f60..980cd8f8460 100644
--- a/doc/man/man1/salloc.1
+++ b/doc/man/man1/salloc.1
@@ -252,6 +252,10 @@ and you can tell SLURM to run the job today with the keyword
 The value may be changed after job submission using the
 \fBscontrol\fR command.
 
+.TP
+\fB\-\-comment\fR
+An arbitrary comment.
+
 .TP 
 \fB\-\-nice\fR[=]<\fIadjustment\fR>
 Run the job with an adjusted scheduling priority.  With no adjustment
diff --git a/doc/man/man1/sbatch.1 b/doc/man/man1/sbatch.1
index 9440384b210..1bdc3f5efb8 100644
--- a/doc/man/man1/sbatch.1
+++ b/doc/man/man1/sbatch.1
@@ -265,6 +265,10 @@ and you can tell SLURM to run the job today with the keyword
 The value may be changed after job submission using the
 \fBscontrol\fR command.
 
+.TP
+\fB\-\-comment\fR
+An arbitrary comment.
+
 .TP 
 \fB\-\-nice\fR[=]<\fIadjustment\fR>
 Run the job with an adjusted scheduling priority.  With no adjustment
diff --git a/doc/man/man1/srun.1 b/doc/man/man1/srun.1
index 87fca18cc4b..ebc5d754831 100644
--- a/doc/man/man1/srun.1
+++ b/doc/man/man1/srun.1
@@ -1,6 +1,6 @@
 \." $Id$
 .\"
-.TH SRUN "1" "June 2006" "srun 1.2" "slurm components"
+.TH SRUN "1" "September 2006" "srun 1.2" "slurm components"
 .SH "NAME"
 srun \- run parallel jobs
 .SH SYNOPSIS
@@ -111,12 +111,18 @@ and you can tell SLURM to run the job today with the keyword
 \fItomorrow\fR.
 The value may be changed after job submission using the
 \fBscontrol\fR command.
+
 .TP
 \fB\-U\fR, \fB\-\-account\fR=\fIaccount\fR
 Change resource use by this job to specified account.
 The \fIaccount\fR is an arbitrary string. The may 
 be changed after job submission using the \fBscontrol\fR 
 command.
+
+.TP
+\fB\-\-comment\fR
+An arbitrary comment.
+
 .TP
 \fB\-t\fR, \fB\-\-time\fR=\fIminutes\fR
 Establish a time limit to terminate the job after the specified number of 
diff --git a/slurm/slurm.h.in b/slurm/slurm.h.in
index dc39a08e7cb..f040a3c734a 100644
--- a/slurm/slurm.h.in
+++ b/slurm/slurm.h.in
@@ -409,6 +409,7 @@ typedef struct job_descriptor {	/* For submit, allocate, and update requests */
 				 * NICE_OFFSET == no change */
 	char *account;		/* charge to specified account */
 	char *network;		/* network use spec */
+	char *comment;		/* arbitrary comment (used by Moab scheduler) */
 	time_t begin_time;	/* delay initiation until this time */
 	uint16_t mail_type;	/* see MAIL_JOB_ definitions above */
 	char *mail_user;	/* user to receive notification */
@@ -475,6 +476,7 @@ typedef struct job_info {
 	uint16_t wait_reason;	/* reason job still pending, see
 				 * slurm.h:enum job_wait_reason */
 	char *network;		/* network specification */
+	char *comment;		/* arbitrary comment (used by Moab scheduler) */
 	select_jobinfo_t select_jobinfo; /* opaque data type,
 			* process using select_g_get_jobinfo() */
 } job_info_t;
diff --git a/src/api/init_msg.c b/src/api/init_msg.c
index 92f9149efb9..959d149f666 100644
--- a/src/api/init_msg.c
+++ b/src/api/init_msg.c
@@ -58,6 +58,7 @@ void slurm_init_job_desc_msg(job_desc_msg_t * job_desc_msg)
 	job_desc_msg->account     = NULL;
 	job_desc_msg->alloc_node  = NULL;
 	job_desc_msg->alloc_sid   = NO_VAL;
+	job_desc_msg->comment     = NULL;
 	job_desc_msg->contiguous  = (uint16_t) NO_VAL;
 	job_desc_msg->cpus_per_task = (uint16_t) NO_VAL;
 	job_desc_msg->dependency  = NO_VAL;
diff --git a/src/api/job_info.c b/src/api/job_info.c
index 2ec603ecd27..92e007e51a5 100644
--- a/src/api/job_info.c
+++ b/src/api/job_info.c
@@ -336,6 +336,16 @@ slurm_sprint_job_info ( job_info_t * job_ptr, int one_liner )
 	xstrcat(out, tmp_line);
 
 	/****** Line 13 (optional) ******/
+	if (job_ptr->comment) {
+		if (one_liner)
+			xstrcat(out, " ");
+		else
+			xstrcat(out, "\n   ");
+		sprintf(tmp_line, "Comment=%s ", job_ptr->comment);
+		xstrcat(out, tmp_line);
+	}
+
+	/****** Line 14 (optional) ******/
 	select_g_sprint_jobinfo(job_ptr->select_jobinfo,
 		select_buf, sizeof(select_buf), SELECT_PRINT_MIXED);
 	if (select_buf[0] != '\0') {
diff --git a/src/common/slurm_protocol_defs.c b/src/common/slurm_protocol_defs.c
index d1521c9bdca..44f7b5e7131 100644
--- a/src/common/slurm_protocol_defs.c
+++ b/src/common/slurm_protocol_defs.c
@@ -60,7 +60,6 @@
 #include "src/common/forward.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);
@@ -202,6 +201,7 @@ void slurm_free_job_desc_msg(job_desc_msg_t * msg)
 		xfree(msg->other_hostname);
 		xfree(msg->account);
 		xfree(msg->network);
+		xfree(msg->comment);
 		xfree(msg);
 	}
 }
@@ -261,6 +261,7 @@ void slurm_free_job_info_members(job_info_t * job)
 		xfree(job->exc_nodes);
 		xfree(job->exc_node_inx);
 		xfree(job->network);
+		xfree(job->comment);
 	}
 }
 
@@ -861,29 +862,9 @@ static void _free_all_job_info(job_info_msg_t *msg)
 		return;
 
 	for (i = 0; i < msg->record_count; i++)
-		_slurm_free_job_info_members (&msg->job_array[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->account);
-		xfree(job->name);
-		xfree(job->alloc_node);
-		xfree(job->node_inx);
-		select_g_free_jobinfo(&job->select_jobinfo);
-		xfree(job->features);
-		xfree(job->req_nodes);
-		xfree(job->req_node_inx);
-		xfree(job->exc_nodes);
-		xfree(job->exc_node_inx);
-		xfree(job->network);
-	}
-}
-
-
 /*
  * slurm_free_job_step_info_response_msg - free the job step 
  *	information response message
diff --git a/src/common/slurm_protocol_pack.c b/src/common/slurm_protocol_pack.c
index 13805949592..45ce37b94f1 100644
--- a/src/common/slurm_protocol_pack.c
+++ b/src/common/slurm_protocol_pack.c
@@ -1929,6 +1929,7 @@ _unpack_job_info_members(job_info_t * job, Buf buffer)
 	safe_unpackstr_xmalloc(&job->partition, &uint16_tmp, buffer);
 	safe_unpackstr_xmalloc(&job->account, &uint16_tmp, buffer);
 	safe_unpackstr_xmalloc(&job->network, &uint16_tmp, buffer);
+	safe_unpackstr_xmalloc(&job->comment, &uint16_tmp, buffer);
 	safe_unpack32(&job->dependency, buffer);
 
 	safe_unpackstr_xmalloc(&job->name, &uint16_tmp, buffer);
@@ -1991,6 +1992,7 @@ unpack_error:
 	xfree(job->exc_nodes);
 	xfree(job->exc_node_inx);
 	xfree(job->network);
+	xfree(job->comment);
 	return SLURM_ERROR;
 }
 
@@ -2235,6 +2237,7 @@ _pack_job_desc_msg(job_desc_msg_t * job_desc_ptr, Buf buffer)
 	pack32((uint32_t)job_desc_ptr->priority, buffer);
 	pack32((uint32_t)job_desc_ptr->dependency, buffer);
 	packstr(job_desc_ptr->account, buffer);
+	packstr(job_desc_ptr->comment, buffer);
 	pack16((uint16_t)job_desc_ptr->nice, buffer);
 	pack16((uint16_t)job_desc_ptr->overcommit, buffer);
 	pack32((uint32_t)job_desc_ptr->num_tasks, buffer);
@@ -2329,6 +2332,7 @@ _unpack_job_desc_msg(job_desc_msg_t ** job_desc_buffer_ptr, Buf buffer)
 	safe_unpack32(&job_desc_ptr->priority, buffer);
 	safe_unpack32(&job_desc_ptr->dependency, buffer);
 	safe_unpackstr_xmalloc(&job_desc_ptr->account, &uint16_tmp, buffer);
+	safe_unpackstr_xmalloc(&job_desc_ptr->comment, &uint16_tmp, buffer);
 	safe_unpack16(&job_desc_ptr->nice, buffer);
 	safe_unpack16(&job_desc_ptr->overcommit, buffer);
 	safe_unpack32(&job_desc_ptr->num_tasks, buffer);
diff --git a/src/plugins/sched/wiki2/get_jobs.c b/src/plugins/sched/wiki2/get_jobs.c
index ff86c89c3dd..914f5bd7df1 100644
--- a/src/plugins/sched/wiki2/get_jobs.c
+++ b/src/plugins/sched/wiki2/get_jobs.c
@@ -190,9 +190,9 @@ static char *	_dump_job(struct job_record *job_ptr)
 		_get_job_min_disk(job_ptr));
 	xstrcat(buf, tmp);
 
-	if (job_ptr->account && job_ptr->account[0]) {
+	if (job_ptr->comment && job_ptr->comment[0]) {
 		snprintf(tmp, sizeof(tmp),
-			"COMMENT=%s;", job_ptr->account);
+			"COMMENT=%s;", job_ptr->comment);
 		xstrcat(buf, tmp);
 	}
 
diff --git a/src/salloc/opt.c b/src/salloc/opt.c
index 42e77544241..9fa7d607a54 100644
--- a/src/salloc/opt.c
+++ b/src/salloc/opt.c
@@ -102,6 +102,7 @@
 #define LONG_OPT_BELL        0x124
 #define LONG_OPT_NO_BELL     0x125
 #define LONG_OPT_JOBID       0x126
+#define LONG_OPT_COMMENT     0x127
 
 /*---- global variables, defined in opt.h ----*/
 opt_t opt;
@@ -426,6 +427,7 @@ static void _opt_default()
 	opt.jobid = NO_VAL;
 	opt.dependency = NO_VAL;
 	opt.account  = NULL;
+	opt.comment  = NULL;
 
 	opt.shared = (uint16_t)NO_VAL;
 	opt.no_kill = false;
@@ -671,6 +673,7 @@ void set_options(const int argc, char **argv)
 		{"bell",             no_argument,       0, LONG_OPT_BELL},
 		{"no-bell",          no_argument,       0, LONG_OPT_NO_BELL},
 		{"jobid",            required_argument, 0, LONG_OPT_JOBID},
+		{"comment",          required_argument, 0, LONG_OPT_COMMENT},
 		{NULL,               0,                 0, 0}
 	};
 	char *opt_string = "+a:c:C:d:F:g:hHIJ:kK::n:N:p:qR:st:uU:vVw:W:x:";
@@ -872,6 +875,10 @@ void set_options(const int argc, char **argv)
 		case LONG_OPT_JOBID:
 			opt.jobid = _get_int(optarg, "jobid");
 			break;
+		case LONG_OPT_COMMENT:
+			xfree(opt.comment);
+			opt.comment = xstrdup(optarg);
+			break;
 		default:
 			fatal("Unrecognized command line parameter %c",
 			      opt_char);
@@ -1179,6 +1186,7 @@ static void _opt_list()
 	if (opt.nice)
 		info("nice           : %d", opt.nice);
 	info("account        : %s", opt.account);
+	info("comment        : %s", opt.comment);
 	if (opt.dependency == NO_VAL)
 		info("dependency     : none");
 	else
@@ -1215,7 +1223,7 @@ static void _usage(void)
 "              [--verbose]\n"
 "              [-W sec]\n"
 "              [--contiguous] [--mincpus=n] [--mem=MB] [--tmp=MB] [-C list]\n"
-"              [--account=name] [--dependency=jobid]\n"
+"              [--account=name] [--dependency=jobid] [--comment=name]\n"
 #ifdef HAVE_BG		/* Blue gene specific options */
 "              [--geometry=XxYxZ] [--conn-type=type] [--no-rotate]\n"
 #endif
@@ -1248,6 +1256,7 @@ static void _help(void)
 "      --nice[=value]          decrease secheduling priority by value\n"
 "  -U, --account=name          charge job to specified account\n"
 "      --begin=time            defer job until HH:MM DD/MM/YY\n"
+"      --comment=name          arbitrary comment\n"
 "      --mail-type=type        notify on state change: BEGIN, END, FAIL or ALL\n"
 "      --mail-user=user        who to send email notification for job state changes\n"
 "\n"
diff --git a/src/salloc/opt.h b/src/salloc/opt.h
index eedcfbb0d88..5927a9d8972 100644
--- a/src/salloc/opt.h
+++ b/src/salloc/opt.h
@@ -71,6 +71,7 @@ typedef struct salloc_options {
 	unsigned int dependency;/* --dependency, -P jobid	*/
 	int nice;		/* --nice			*/
 	char *account;		/* --account, -U acct_name	*/
+	char *comment;		/* --comment			*/
 
 	int immediate;		/* -i, --immediate      	*/
 
diff --git a/src/salloc/salloc.c b/src/salloc/salloc.c
index 349519f1f0c..ec3c431c10f 100644
--- a/src/salloc/salloc.c
+++ b/src/salloc/salloc.c
@@ -229,6 +229,8 @@ static int fill_job_desc_from_opts(job_desc_msg_t *desc)
 		desc->begin_time = opt.begin;
 	if (opt.account)
 		desc->account = xstrdup(opt.account);
+	if (opt.comment)
+		desc->comment = xstrdup(opt.comment);
 
 	if (opt.hold)
 		desc->priority     = 0;
diff --git a/src/sbatch/opt.c b/src/sbatch/opt.c
index 6449854a3d7..b4cdeb3cbc3 100644
--- a/src/sbatch/opt.c
+++ b/src/sbatch/opt.c
@@ -98,6 +98,7 @@
 #define LONG_OPT_MAIL_USER   0x11b
 #define LONG_OPT_NICE        0x11e
 #define LONG_OPT_NO_REQUEUE  0x123
+#define LONG_OPT_COMMENT     0x124
 
 /*---- global variables, defined in opt.h ----*/
 opt_t opt;
@@ -387,6 +388,7 @@ static void _opt_default()
 	opt.jobid_set = false;
 	opt.dependency = NO_VAL;
 	opt.account  = NULL;
+	opt.comment  = NULL;
 
 	opt.shared = (uint16_t)NO_VAL;
 	opt.no_kill = false;
@@ -597,6 +599,7 @@ static struct option long_options[] = {
 	{"mail-user",        required_argument, 0, LONG_OPT_MAIL_USER},
 	{"nice",             optional_argument, 0, LONG_OPT_NICE},
 	{"no-requeue",       no_argument,       0, LONG_OPT_NO_REQUEUE},
+	{"comment",          required_argument, 0, LONG_OPT_COMMENT},
 	{NULL,               0,                 0, 0}
 };
 
@@ -1080,6 +1083,10 @@ static void _set_options(int argc, char **argv)
 		case LONG_OPT_NO_REQUEUE:
 			opt.no_requeue = true;
 			break;
+		case LONG_OPT_COMMENT:
+			xfree(opt.comment);
+			opt.comment = xstrdup(optarg);
+			break;
 		default:
 			fatal("Unrecognized command line parameter %c",
 			      opt_char);
@@ -1428,6 +1435,7 @@ static void _opt_list()
 	if (opt.nice)
 		info("nice           : %d", opt.nice);
 	info("account        : %s", opt.account);
+	info("comment        : %s", opt.comment);
 	if (opt.dependency == NO_VAL)
 		info("dependency     : none");
 	else
@@ -1465,7 +1473,7 @@ static void _usage(void)
 "              [--jobid=id] [--verbose]\n"
 "              [-W sec]\n"
 "              [--contiguous] [--mincpus=n] [--mem=MB] [--tmp=MB] [-C list]\n"
-"              [--account=name] [--dependency=jobid]\n"
+"              [--account=name] [--dependency=jobid] [--comment=name]\n"
 #ifdef HAVE_BG		/* Blue gene specific options */
 "              [--geometry=XxYxZ] [--conn-type=type] [--no-rotate]\n"
 #endif
@@ -1501,6 +1509,7 @@ static void _help(void)
 "      --nice[=value]          decrease secheduling priority by value\n"
 "  -U, --account=name          charge job to specified account\n"
 "      --begin=time            defer job until HH:MM DD/MM/YY\n"
+"      --comment=name          arbitrary comment\n"
 "      --mail-type=type        notify on state change: BEGIN, END, FAIL or ALL\n"
 "      --mail-user=user        who to send email notification for job state changes\n"
 "      --no-requeue            if set, do not permit the job to be requeued\n"
diff --git a/src/sbatch/opt.h b/src/sbatch/opt.h
index 8c2c5900578..262c4165687 100644
--- a/src/sbatch/opt.h
+++ b/src/sbatch/opt.h
@@ -72,6 +72,7 @@ typedef struct sbatch_options {
 	unsigned int dependency;/* --dependency, -P jobid	*/
 	int nice;		/* --nice			*/
 	char *account;		/* --account, -U acct_name	*/
+	char *comment;		/* --comment			*/
 
 	int immediate;		/* -i, --immediate      	*/
 
diff --git a/src/sbatch/sbatch.c b/src/sbatch/sbatch.c
index 0c101808c01..2a1fee5752e 100644
--- a/src/sbatch/sbatch.c
+++ b/src/sbatch/sbatch.c
@@ -129,6 +129,8 @@ static int fill_job_desc_from_opts(job_desc_msg_t *desc)
 		desc->begin_time = opt.begin;
 	if (opt.account)
 		desc->account = xstrdup(opt.account);
+	if (opt.comment)
+		desc->comment = xstrdup(opt.comment);
 
 	if (opt.hold)
 		desc->priority     = 0;
diff --git a/src/slurmctld/job_mgr.c b/src/slurmctld/job_mgr.c
index 956d11f4410..dc1c4c301e2 100644
--- a/src/slurmctld/job_mgr.c
+++ b/src/slurmctld/job_mgr.c
@@ -520,6 +520,7 @@ Update JOB_STATE_VERSION
 	packstr(dump_job_ptr->name, buffer);
 	packstr(dump_job_ptr->alloc_node, buffer);
 	packstr(dump_job_ptr->account, buffer);
+	packstr(dump_job_ptr->comment, buffer);
 	packstr(dump_job_ptr->network, buffer);
 	packstr(dump_job_ptr->mail_user, buffer);
 
@@ -558,6 +559,7 @@ static int _load_job_state(Buf buffer)
 	char *nodes = NULL, *partition = NULL, *name = NULL;
 	char *alloc_node = NULL, *alloc_resp_host = NULL, *other_host = NULL;
 	char *account = NULL, *network = NULL, *mail_user = NULL;
+	char *comment = NULL;
 	struct job_record *job_ptr;
 	struct part_record *part_ptr;
 	int error_code;
@@ -600,6 +602,7 @@ job_ptr->exit_code = exit_code;
 	safe_unpackstr_xmalloc(&name, &name_len, buffer);
 	safe_unpackstr_xmalloc(&alloc_node, &name_len, buffer);
 	safe_unpackstr_xmalloc(&account, &name_len, buffer);
+	safe_unpackstr_xmalloc(&comment, &name_len, buffer);
 	safe_unpackstr_xmalloc(&network, &name_len, buffer);
 	safe_unpackstr_xmalloc(&mail_user, &name_len, buffer);
 
@@ -684,6 +687,8 @@ job_ptr->exit_code = exit_code;
 	xfree(partition);
 	job_ptr->account = account;
 	account          = NULL;  /* reused, nothing left to free */
+	job_ptr->comment = comment;
+	comment          = NULL;  /* reused, nothing left to free */
 	job_ptr->network = network;
 	network          = NULL;  /* reused, nothing left to free */
 	job_ptr->part_ptr = part_ptr;
@@ -722,6 +727,7 @@ job_ptr->exit_code = exit_code;
 	xfree(name);
 	xfree(alloc_node);
 	xfree(account);
+	xfree(comment);
 	xfree(mail_user);
 	select_g_free_jobinfo(&select_jobinfo);
 	return SLURM_FAILURE;
@@ -1283,8 +1289,8 @@ void dump_job_desc(job_desc_msg_t * job_specs)
 	       job_specs->alloc_resp_hostname, job_specs->alloc_resp_port);
 	debug3("   other_hostname=%s other_port=%u",
 	       job_specs->other_hostname, job_specs->other_port);
-	debug3("   dependency=%ld account=%s",
-	       dependency, job_specs->account);
+	debug3("   dependency=%ld account=%s comment=%s",
+	       dependency, job_specs->account, job_specs->comment);
 
 	num_tasks = (job_specs->num_tasks != (uint16_t) NO_VAL) ?
 			(long) job_specs->num_tasks : -1L;
@@ -2329,6 +2335,7 @@ _copy_job_desc_to_job_record(job_desc_msg_t * job_desc,
 	job_ptr->alloc_node = xstrdup(job_desc->alloc_node);
 	job_ptr->account    = xstrdup(job_desc->account);
 	job_ptr->network    = xstrdup(job_desc->network);
+	job_ptr->comment    = xstrdup(job_desc->comment);
 	if (job_desc->dependency != NO_VAL) /* leave as zero */
 		job_ptr->dependency = job_desc->dependency;
 
@@ -2618,6 +2625,7 @@ static void _list_delete_job(void *job_entry)
 	xfree(job_ptr->account);
 	xfree(job_ptr->mail_user);
 	xfree(job_ptr->network);
+	xfree(job_ptr->comment);
 	xfree(job_ptr->ntask);
 	select_g_free_jobinfo(&job_ptr->select_jobinfo);
 	if (job_ptr->step_list) {
@@ -2782,6 +2790,7 @@ void pack_job(struct job_record *dump_job_ptr, Buf buffer)
 	packstr(dump_job_ptr->partition, buffer);
 	packstr(dump_job_ptr->account, buffer);
 	packstr(dump_job_ptr->network, buffer);
+	packstr(dump_job_ptr->comment, buffer);
 	pack32((uint32_t)dump_job_ptr->dependency, buffer);
 
 	packstr(dump_job_ptr->name, buffer);
diff --git a/src/slurmctld/slurmctld.h b/src/slurmctld/slurmctld.h
index 92651ea2eaa..67ecc367373 100644
--- a/src/slurmctld/slurmctld.h
+++ b/src/slurmctld/slurmctld.h
@@ -333,6 +333,7 @@ struct job_record {
 	uint16_t other_port;		/* port for client communications */
 	char *other_host;		/* host for client communications */
 	char *account;			/* account number to charge */
+	char *comment;			/* arbitrary comment */
 	uint32_t dependency;		/* defer until this job completes */
 	char *network;			/* network/switch requirement spec */
 	struct job_record *job_next;	/* next entry with same hash index */
diff --git a/src/srun/allocate.c b/src/srun/allocate.c
index 2d23ac9b3fd..db22359fdc2 100644
--- a/src/srun/allocate.c
+++ b/src/srun/allocate.c
@@ -466,6 +466,8 @@ job_desc_msg_create_from_opts (char *script)
 		j->network = xstrdup(opt.network);
 	if (opt.account)
 		j->account = xstrdup(opt.account);
+	if (opt.comment)
+		j->comment = xstrdup(opt.comment);
 
 	if (opt.hold)
 		j->priority     = 0;
@@ -550,6 +552,7 @@ job_desc_msg_destroy(job_desc_msg_t *j)
 {
 	if (j) {
 		xfree(j->account);
+		xfree(j->comment);
 		xfree(j->alloc_resp_hostname);
 		xfree(j->other_hostname);
 		xfree(j);
diff --git a/src/srun/opt.c b/src/srun/opt.c
index 2c4ce139fbf..8711ab871a9 100644
--- a/src/srun/opt.c
+++ b/src/srun/opt.c
@@ -718,6 +718,7 @@ static void _opt_default()
 	opt.jobid_set = false;
 	opt.dependency = NO_VAL;
 	opt.account  = NULL;
+	opt.comment  = NULL;
 
 	opt.distribution = -1;
 
@@ -1537,12 +1538,10 @@ void set_options(const int argc, char **argv, int first)
 			opt.no_requeue = true;
 			break;
 		case LONG_OPT_COMMENT:
-			/* Use account for Moab until job comment field
-			 * is actually available in slurm v1.2 */
-			if(!first && opt.account)
+			if(!first && opt.comment)
 				break;
-			xfree(opt.account);
-			opt.account = xstrdup(optarg);
+			xfree(opt.comment);
+			opt.comment = xstrdup(optarg);
 			break;
 		default:
 			if (spank_process_option (opt_char, optarg) < 0) {
@@ -2044,6 +2043,7 @@ static void _opt_list()
 	if (opt.nice)
 		info("nice           : %d", opt.nice);
 	info("account        : %s", opt.account);
+	info("comment        : %s", opt.comment);
 	if (opt.dependency == NO_VAL)
 		info("dependency     : none");
 	else
@@ -2096,7 +2096,7 @@ static void _usage(void)
 "            [--core=type] [-T threads] [-W sec] [--attach] [--join] \n"
 "            [--contiguous] [--mincpus=n] [--mem=MB] [--tmp=MB] [-C list]\n"
 "            [--mpi=type] [--account=name] [--dependency=jobid]\n"
-"            [--kill-on-bad-exit] [--propagate[=rlimits] ]\n"
+"            [--kill-on-bad-exit] [--propagate[=rlimits] [--comment=name]\n"
 "            [--cpu_bind=...] [--mem_bind=...]\n"
 #ifdef HAVE_BG		/* Blue gene specific options */
 "            [--geometry=XxYxZ] [--conn-type=type] [--no-rotate]\n"
@@ -2152,6 +2152,7 @@ static void _help(void)
 "  -P, --dependency=jobid      defer job until specified jobid completes\n"
 "      --nice[=value]          decrease secheduling priority by value\n"
 "  -U, --account=name          charge job to specified account\n"
+"      --comment=name          arbitrary comment\n"
 "      --propagate[=rlimits]   propagate all [or specific list of] rlimits\n"
 "      --mpi=type              specifies version of MPI to use\n"
 "      --prolog=program        run \"program\" before launching job step\n"
diff --git a/src/srun/opt.h b/src/srun/opt.h
index b3f21a6181e..c3b3ecf2269 100644
--- a/src/srun/opt.h
+++ b/src/srun/opt.h
@@ -113,6 +113,7 @@ typedef struct srun_options {
 	unsigned int dependency;/* --dependency, -P jobid	*/
 	int nice;		/* --nice			*/
 	char *account;		/* --account, -U acct_name	*/
+	char *comment;		/* --comment			*/
 
 	char *ofname;		/* --output -o filename         */
 	char *ifname;		/* --input  -i filename         */
-- 
GitLab