Hi everyone.

I'm using job names as a simple way to group job batches. "scancel" already 
allows to kill by name, so it made sense to implement job selection by name in 
squeue too, in order to restrict the view to a particular batch.

"-n" was already taken in squeue (sadly, since most other commands use 'w' for 
the node list), so I only added the long "--name" option to mimic scancel's 
usage.

Diffed against 2.4.0-0.pre1.

Bests.
diff -rud slurm-2.4.0-0.pre1.Orig2/doc/man/man1/squeue.1 slurm-2.4.0-0.pre1/doc/man/man1/squeue.1
--- slurm-2.4.0-0.pre1.Orig2/doc/man/man1/squeue.1	2011-10-24 19:39:19.000000000 +0200
+++ slurm-2.4.0-0.pre1/doc/man/man1/squeue.1	2011-11-21 12:52:00.325874436 +0100
@@ -404,6 +404,11 @@
 list can consist of user names or user id numbers.
 
 .TP
+\fB\-\-name=<name_list>\fR
+Request jobs or job steps having one of the specified names.  The
+list consists of a comma separated list of job names.
+
+.TP
 \fB\-\-usage\fR
 Print a brief help message listing the \fBsqueue\fR options.
 
diff -rud slurm-2.4.0-0.pre1.Orig2/src/squeue/opts.c slurm-2.4.0-0.pre1/src/squeue/opts.c
--- slurm-2.4.0-0.pre1.Orig2/src/squeue/opts.c	2011-10-24 19:39:19.000000000 +0200
+++ slurm-2.4.0-0.pre1/src/squeue/opts.c	2011-11-21 12:47:05.071874567 +0100
@@ -69,6 +69,7 @@
 #define OPT_LONG_USAGE 0x101
 #define OPT_LONG_HIDE  0x102
 #define OPT_LONG_START 0x103
+#define OPT_LONG_NAME  0x104
 
 /* FUNCTIONS */
 static List  _build_job_list( char* str );
@@ -120,6 +121,7 @@
 		{"usage",      no_argument,       0, OPT_LONG_USAGE},
 		{"user",       required_argument, 0, 'u'},
 		{"users",      required_argument, 0, 'u'},
+		{"name",       required_argument, 0, OPT_LONG_NAME},
 		{"verbose",    no_argument,       0, 'v'},
 		{"version",    no_argument,       0, 'V'},
 		{NULL,         0,                 0, 0}
@@ -254,6 +256,12 @@
 			params.user_list =
 				_build_user_list( params.users );
 			break;
+		case OPT_LONG_NAME:
+			xfree(params.names);
+			params.names = xstrdup(optarg);
+			params.name_list =
+				_build_str_list( params.names );
+			break;
 		case (int) 'v':
 			params.verbose++;
 			break;
@@ -369,6 +377,12 @@
 		params.user_list = _build_user_list( params.users );
 	}
 
+	if ( ( params.names == NULL ) &&
+	     ( env_val = getenv("SQUEUE_NAMES") ) ) {
+		params.names = xstrdup(env_val);
+		params.name_list = _build_str_list( params.names );
+	}
+
 	if ( params.start_flag && !params.step_flag ) {
 		/* Set more defaults */
 		if (params.format == NULL)
@@ -843,7 +857,7 @@
 {
 	ListIterator iterator;
 	int i;
-	char *part;
+	char *part, *name;
 	uint32_t *user;
 	enum job_states *state_id;
 	squeue_job_step_t *job_step_id;
@@ -872,6 +886,7 @@
 	printf( "step_flag   = %d\n", params.step_flag );
 	printf( "steps       = %s\n", params.steps );
 	printf( "users       = %s\n", params.users );
+	printf( "names       = %s\n", params.names );
 	printf( "verbose     = %d\n", params.verbose );
 
 	if ((params.verbose > 1) && params.job_list) {
@@ -921,6 +936,15 @@
 		list_iterator_destroy( iterator );
 	}
 
+	if ((params.verbose > 1) && params.name_list) {
+		i = 0;
+		iterator = list_iterator_create( params.name_list );
+		while ( (name = list_next( iterator )) ) {
+			printf( "name_list[%d] = %u\n", i++, *name);
+		}
+		list_iterator_destroy( iterator );
+	}
+
 	printf( "-----------------------------\n\n\n" );
 } ;
 
@@ -1156,6 +1180,7 @@
 				  default is pending and running,\n\
 				  '--states=all' reports all states\n\
   -u, --user=user_name(s)         comma separated list of users to view\n\
+      --name=job_name(s)          comma separated list of job names to view\n\
   -v, --verbose                   verbosity level\n\
   -V, --version                   output version information and exit\n\
 \nHelp options:\n\
diff -rud slurm-2.4.0-0.pre1.Orig2/src/squeue/print.c slurm-2.4.0-0.pre1/src/squeue/print.c
--- slurm-2.4.0-0.pre1.Orig2/src/squeue/print.c	2011-10-24 19:39:19.000000000 +0200
+++ slurm-2.4.0-0.pre1/src/squeue/print.c	2011-11-21 12:45:45.231874588 +0100
@@ -1367,7 +1367,7 @@
 	ListIterator iterator;
 	uint32_t *job_id, *user;
 	uint16_t *state_id;
-	char *account, *part, *qos;
+	char *account, *part, *qos, *name;
 
 	if (params.job_list) {
 		filter = 1;
@@ -1487,6 +1487,21 @@
 		}
 	}
 
+	if (params.name_list) {
+		filter = 1;
+		iterator = list_iterator_create(params.name_list);
+		while ((name = list_next(iterator))) {
+			if ((job->name != NULL) &&
+			     (strcasecmp(name, job->name) == 0)) {
+				filter = 0;
+				break;
+			}
+		}
+		list_iterator_destroy(iterator);
+		if (filter == 1)
+			return 8;
+	}
+
 	return 0;
 }
 
diff -rud slurm-2.4.0-0.pre1.Orig2/src/squeue/squeue.h slurm-2.4.0-0.pre1/src/squeue/squeue.h
--- slurm-2.4.0-0.pre1.Orig2/src/squeue/squeue.h	2011-10-24 19:39:19.000000000 +0200
+++ slurm-2.4.0-0.pre1/src/squeue/squeue.h	2011-11-21 12:30:17.409874855 +0100
@@ -100,6 +100,7 @@
 	char* states;
 	char* steps;
 	char* users;
+	char* names;
 
 	List  account_list;
 	List  format_list;
@@ -109,6 +110,7 @@
 	List  state_list;
 	List  step_list;
 	List  user_list;
+	List  name_list;
 };
 
 extern struct squeue_parameters params;

Reply via email to