From c37e5cd727890cae7f23722bc8e4f327d91283d8 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Mon, 12 Dec 2016 12:22:02 -0700
Subject: [PATCH] Burst buffer on emulated cray

If running burst_buffer/cray plugin on emulated Cray (NOT a real
   Cray system with Cray APIs) and the burst buffer state information
   includes information about buffers associated with jobs which
   are either completed or no longer exist (i.e. the burst buffer
   state information is old), then ignore that old state information.
   This might possibly be related to bug 3295 if their configuration
   is bad.
---
 .../burst_buffer/cray/burst_buffer_cray.c     | 24 ++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/plugins/burst_buffer/cray/burst_buffer_cray.c b/src/plugins/burst_buffer/cray/burst_buffer_cray.c
index 3f3e0329bad..3d829d23de5 100644
--- a/src/plugins/burst_buffer/cray/burst_buffer_cray.c
+++ b/src/plugins/burst_buffer/cray/burst_buffer_cray.c
@@ -851,6 +851,23 @@ static int _open_part_state_file(char **state_file)
 	return state_fd;
 }
 
+/* Return true if the burst buffer name is that of a job (i.e. numeric) and
+ * and that job is complete. Otherwise return false. */
+static bool _is_complete_job(char *name)
+{
+	char *end_ptr = NULL;
+	uint32_t job_id = 0;
+	struct job_record *job_ptr;
+
+	if (name && (name[0] >='0') && (name[0] <='9')) {
+		job_id = strtol(name, &end_ptr, 10);
+		job_ptr = find_job_record(job_id);
+		if (!job_ptr || IS_JOB_COMPLETED(job_ptr))
+			return true;
+	}
+	return false;
+}
+
 /* Recover saved burst buffer state and use it to preserve account, partition,
  * and QOS information for persistent burst buffers. */
 static void _recover_bb_state(void)
@@ -931,7 +948,12 @@ static void _recover_bb_state(void)
 			pool = xstrdup(bb_state.bb_config.default_pool);
 		}
 
-		if (bb_state.bb_config.flags & BB_FLAG_EMULATE_CRAY) {
+		if ((bb_state.bb_config.flags & BB_FLAG_EMULATE_CRAY) &&
+		    _is_complete_job(name)) {
+			info("%s, Ignoring burst buffer state for completed job %s",
+			     __func__, name);
+			bb_alloc = NULL;
+		} else if (bb_state.bb_config.flags & BB_FLAG_EMULATE_CRAY) {
 			bb_alloc = bb_alloc_name_rec(&bb_state, name, user_id);
 			bb_alloc->id = id;
 			last_persistent_id = MAX(last_persistent_id, id);
-- 
GitLab