From b29e1970fad26d5e5c7d6d6e28f326450d1c9ab9 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Thu, 18 Oct 2012 11:36:58 -0700
Subject: [PATCH] Reservations with both user and account filters to be ANDed
 rather than ORed

---
 doc/man/man1/scontrol.1     | 16 ++++++++++------
 src/slurmctld/reservation.c | 16 +++++++++++++---
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/doc/man/man1/scontrol.1 b/doc/man/man1/scontrol.1
index 66d293eaa23..1d8f8179cb3 100644
--- a/doc/man/man1/scontrol.1
+++ b/doc/man/man1/scontrol.1
@@ -1078,9 +1078,11 @@ For create, if you do not want to give a reservation name, use
 List of accounts permitted to use the reserved nodes.
 E.g.  Accounts=physcode1,physcode2.  A user in any of the accounts
 may use the reserved nodes.
-A new reservation must specify Users and/or Accounts.  You can add or
-remove individual accounts from an existing reservation by adding
-a '+' or '\-' sign before the '=' sign.
+A new reservation must specify Users and/or Accounts.
+If both Users and Accounts are specified, a job must match both in order to
+use the reservation.
+You can add or remove individual accounts from an existing reservation by
+adding a '+' or '\-' sign before the '=' sign.
 
 .TP
 \fICoreCnt\fP=<num>
@@ -1219,9 +1221,11 @@ Value may be cleared with blank data value, "Features=".
 \fIUsers\fP=<user list>
 List of users permitted to use the reserved nodes.
 E.g.  Users=jones1,smith2.
-A new reservation must specify Users and/or Accounts.  You can add or
-remove individual users from an existing reservation by adding a '+'
-or '\-' sign before the '=' sign.
+A new reservation must specify Users and/or Accounts. 
+If both Users and Accounts are specified, a job must match both in order to
+use the reservation.
+You can add or remove individual users from an existing reservation by adding
+a '+' or '\-' sign before the '=' sign.
 
 .TP
 \fBSPECIFICATIONS FOR UPDATE BLOCK/SUBMP \fR
diff --git a/src/slurmctld/reservation.c b/src/slurmctld/reservation.c
index 9fe83ec7a24..07f670ff796 100644
--- a/src/slurmctld/reservation.c
+++ b/src/slurmctld/reservation.c
@@ -3034,6 +3034,7 @@ fini:	FREE_NULL_BITMAP(save_bitmap);
 static int _valid_job_access_resv(struct job_record *job_ptr,
 				  slurmctld_resv_t *resv_ptr)
 {
+	bool uid_match = false;
 	int i;
 
 	/* Determine if we have access */
@@ -3072,10 +3073,19 @@ static int _valid_job_access_resv(struct job_record *job_ptr,
 			assoc = assoc->usage->parent_assoc_ptr;
 		}
 	} else {
-no_assocs:	for (i=0; i<resv_ptr->user_cnt; i++) {
-			if (job_ptr->user_id == resv_ptr->user_list[i])
-				return SLURM_SUCCESS;
+no_assocs:	if (resv_ptr->user_cnt == 0)
+			uid_match = true;
+		for (i = 0; i < resv_ptr->user_cnt; i++) {
+			if (job_ptr->user_id == resv_ptr->user_list[i]) {
+				uid_match = true;
+				break;
+			}
 		}
+		if (!uid_match)
+			goto end_it;
+		if ((resv_ptr->user_cnt != 0) && (resv_ptr->account_cnt == 0))
+			return SLURM_SUCCESS;
+
 		for (i=0; (i<resv_ptr->account_cnt) && job_ptr->account; i++) {
 			if (resv_ptr->account_list[i] &&
 			    (strcmp(job_ptr->account,
-- 
GitLab