From 8ed1b303288e5de210ce9db2baf9c94c191a7213 Mon Sep 17 00:00:00 2001
From: Don Albert <Don.Albert@Bull.com>
Date: Fri, 25 May 2012 09:03:30 -0700
Subject: [PATCH] Modify scontrol show job to require -dd option to print batch
 script.

I have implemented the changes as you suggested:   using a "-dd" option to indicate that the display of the script is wanted, and setting both the "SHOW_DETAIL" and a new "SHOW_DETAIL2" flag.

Since "scontrol" can be run interactively as well,  I added a new "script" option to indicate that display of both the script and the details is wanted if the job is a batch job.

Here are the man page updates for "man scontrol".   For the "-d, --details" option:

       -d, --details
              Causes  the  show command to provide additional details where available.  Repeating the option more than
              once (e.g., "-dd") will cause the show job command to also list the batch script, if the job was a batch
              job.

For the interactive "details" option:

       details
              Causes  the  show  command  to provide additional details where available.  Job information will include
              CPUs and NUMA memory allocated on each node.  Note that on computers  with  hyperthreading  enabled  and
              SLURM  configured  to allocate cores, each listed CPU represents one physical core.  Each hyperthread on
              that core can be allocated a separate task, so a job's CPU count and task count  may  differ.   See  the
              --cpu_bind  and  --mem_bind  option  descriptions  in  srun man pages for more information.  The details
              option is currently only supported for the show job command. To also list the  batch  script  for  batch
              jobs, in addition to the details, use the script option described below instead of this option.

And for the new interactive "script" option:

       script Causes the show job command to list the batch script for batch jobs in addition to the  detail  informa-
              tion described under the details option above.

Attached are the patch file for the changes and a text file with the results of the tests I did to check out the changes.   The patches are against SLURM 2.4.0-rc1.

        -Don Albert-
---
 NEWS                    |  2 ++
 RELEASE_NOTES           |  4 +++-
 doc/man/man1/scontrol.1 | 15 +++++++++++----
 slurm/slurm.h.in        |  1 +
 src/scontrol/info_job.c |  5 ++++-
 src/scontrol/scontrol.c | 14 ++++++++++++--
 src/slurmctld/job_mgr.c |  2 +-
 7 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index a697c525011..ff577aad7be 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,8 @@ documents those changes that are of interest to users and admins.
     Bringhurst (LANL).
  -- BGQ - Fix issue when running with AllowSubBlockAllocations=Yes without
     compiling with --enable-debug
+ -- Modify scontrol to require "-dd" option to report batch job's script. Patch
+    from Don Albert, Bull.
 
 * Changes in SLURM 2.4.0.rc1
 =============================
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index dc4247c55e2..97eab8841bf 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -1,5 +1,5 @@
 RELEASE NOTES FOR SLURM VERSION 2.4
-10 May 2012
+25 May 2012
 
 
 IMPORTANT NOTE:
@@ -70,6 +70,8 @@ COMMAND CHANGES (see man pages for details)
   was specified. Added output format of "%R" to print partition name only
   without identifying the default partition with "*").
 * Added cpu_run_min to the output of sshare --long.
+* Modify scontrol to require "-dd" option to report batch job's script.
+
 
 OTHER CHANGES
 =============
diff --git a/doc/man/man1/scontrol.1 b/doc/man/man1/scontrol.1
index 7ade312b815..0d7147855f1 100644
--- a/doc/man/man1/scontrol.1
+++ b/doc/man/man1/scontrol.1
@@ -30,7 +30,9 @@ that are configured as hidden and partitions that are unavailable to user's
 group.
 .TP
 \fB\-d\fR, \fB\-\-details\fR
-Causes the \fBshow\fR command to provide additional details where available.
+Causes the \fIshow\fR command to provide additional details where available.
+Repeating the option more than once (e.g., "\-dd") will cause the \fIshow job\fR
+command to also list the batch script, if the job was a batch job.
 .TP
 \fB\-h\fR, \fB\-\-help\fR
 Print a help message describing the usage of scontrol.
@@ -151,8 +153,6 @@ If the specified partition is in use, the request is denied.
 .TP
 \fBdetails\fP
 Causes the \fIshow\fP command to provide additional details where available.
-Batch job information will include the batch script for jobs the user is
-authorized to view.
 Job information will include CPUs and NUMA memory allocated on each node.
 Note that on computers with hyperthreading enabled and SLURM configured to
 allocate cores, each listed CPU represents one physical core.
@@ -161,7 +161,8 @@ CPU count and task count may differ.
 See the \fB\-\-cpu_bind\fR and \fB\-\-mem_bind\fR option descriptions in
 srun man pages for more information.
 The \fBdetails\fP option is currently only supported for the \fIshow job\fP
-command.
+command. To also list the batch script for batch jobs, in addition to the
+details, use the \fBscript\fP option described below instead of this option.
 
 .TP
 \fBexit\fP
@@ -275,6 +276,12 @@ daemon reads the slurm.conf configuration file (e.g. when the daemon
 is restarted or \fBscontrol reconfigure\fR is executed) if the
 SlurmSchedLogLevel parameter is present.
 
+.TP
+\fBscript\fP
+Causes the \fIshow job\fP command to list the batch script for batch
+jobs in addition to the detail information described under the
+\fBdetails\fP option above.
+
 .TP
 \fBsetdebug\fP \fILEVEL\fP
 Change the debug level of the slurmctld daemon.
diff --git a/slurm/slurm.h.in b/slurm/slurm.h.in
index 62f55f3eefd..3df3d08d273 100644
--- a/slurm/slurm.h.in
+++ b/slurm/slurm.h.in
@@ -526,6 +526,7 @@ enum node_states {
  * Values can be can be ORed */
 #define SHOW_ALL	0x0001	/* Show info for "hidden" partitions */
 #define SHOW_DETAIL	0x0002	/* Show detailed resource information */
+#define SHOW_DETAIL2	0x0004	/* Show batch script listing */
 
 /* Define keys for ctx_key argument of slurm_step_ctx_get() */
 enum ctx_keys {
diff --git a/src/scontrol/info_job.c b/src/scontrol/info_job.c
index 97caab696a1..3f9e8b05fd8 100644
--- a/src/scontrol/info_job.c
+++ b/src/scontrol/info_job.c
@@ -84,8 +84,11 @@ _scontrol_load_jobs(job_info_msg_t ** job_buffer_pptr, uint32_t job_id)
 	if (all_flag)
 		show_flags |= SHOW_ALL;
 
-	if (detail_flag)
+	if (detail_flag) {
 		show_flags |= SHOW_DETAIL;
+		if (detail_flag > 1)
+			show_flags |= SHOW_DETAIL2;
+	}
 
 	if (old_job_info_ptr) {
 		if (last_show_flags != show_flags)
diff --git a/src/scontrol/scontrol.c b/src/scontrol/scontrol.c
index 63c8e74ec8a..96a33d785b5 100644
--- a/src/scontrol/scontrol.c
+++ b/src/scontrol/scontrol.c
@@ -143,7 +143,7 @@ main (int argc, char *argv[])
 			all_flag = 1;
 			break;
 		case (int)'d':
-			detail_flag = 1;
+			detail_flag++;
 			break;
 		case (int)'h':
 			_usage ();
@@ -706,6 +706,16 @@ _process_command (int argc, char *argv[])
 		}
 		detail_flag = 1;
 	}
+	else if (strncasecmp (tag, "script", MAX(tag_len, 3)) == 0) {
+		if (argc > 1) {
+			exit_code = 1;
+			fprintf (stderr,
+				 "too many arguments for keyword:%s\n",
+				 tag);
+			return 0;
+		}
+		detail_flag = 2;
+	}
 	else if (strncasecmp (tag, "exit", MAX(tag_len, 1)) == 0) {
 		if (argc > 1) {
 			exit_code = 1;
@@ -1039,7 +1049,7 @@ _process_command (int argc, char *argv[])
 			}
 		}
 	}
-	else if (strncasecmp (tag, "schedloglevel", MAX(tag_len, 2)) == 0) {
+	else if (strncasecmp (tag, "schedloglevel", MAX(tag_len, 3)) == 0) {
 		if (argc > 2) {
 			exit_code = 1;
 			if (quiet_flag != 1)
diff --git a/src/slurmctld/job_mgr.c b/src/slurmctld/job_mgr.c
index 8fc346f0e85..a106debde4e 100644
--- a/src/slurmctld/job_mgr.c
+++ b/src/slurmctld/job_mgr.c
@@ -5740,7 +5740,7 @@ void pack_job(struct job_record *dump_job_ptr, uint16_t show_flags, Buf buffer,
 		packstr(dump_job_ptr->gres, buffer);
 		packstr(dump_job_ptr->batch_host, buffer);
 		if (!IS_JOB_COMPLETED(dump_job_ptr) &&
-		    (show_flags & SHOW_DETAIL) &&
+		    (show_flags & SHOW_DETAIL2) &&
 		    ((dump_job_ptr->user_id == (uint32_t) uid) ||
 		     validate_slurm_user(uid))) {
 			char *batch_script = get_job_script(dump_job_ptr);
-- 
GitLab