From dd23c31e1c996f671d7e7ecf5c8216b87b326924 Mon Sep 17 00:00:00 2001
From: Nate Rini <nate@schedmd.com>
Date: Thu, 24 Jun 2021 12:33:32 -0600
Subject: [PATCH] sacct - add container field

Bug 11380
---
 doc/man/man1/sacct.1 | 51 ++++++++++++++++++++++++--------------------
 src/sacct/print.c    | 17 +++++++++++++++
 src/sacct/sacct.c    |  1 +
 src/sacct/sacct.h    |  1 +
 4 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/doc/man/man1/sacct.1 b/doc/man/man1/sacct.1
index 83d21dfb6ec..bfa9ac99ca8 100644
--- a/doc/man/man1/sacct.1
+++ b/doc/man/man1/sacct.1
@@ -142,29 +142,30 @@ Account             AdminComment        AllocCPUS           AllocNodes
 AllocTRES           AssocID             AveCPU              AveCPUFreq
 AveDiskRead         AveDiskWrite        AvePages            AveRSS
 AveVMSize           BlockID             Cluster             Comment
-Constraints         ConsumedEnergy      ConsumedEnergyRaw   CPUTime
-CPUTimeRAW          DBIndex             DerivedExitCode     Elapsed
-ElapsedRaw          Eligible            End                 ExitCode
-Flags               GID                 Group               JobID
-JobIDRaw            JobName             Layout              MaxDiskRead
-MaxDiskReadNode     MaxDiskReadTask     MaxDiskWrite        MaxDiskWriteNode
-MaxDiskWriteTask    MaxPages            MaxPagesNode        MaxPagesTask
-MaxRSS              MaxRSSNode          MaxRSSTask          MaxVMSize
-MaxVMSizeNode       MaxVMSizeTask       McsLabel            MinCPU
-MinCPUNode          MinCPUTask          NCPUS               NNodes
-NodeList            NTasks              Priority            Partition
-QOS                 QOSRAW              Reason              ReqCPUFreq
-ReqCPUFreqMin       ReqCPUFreqMax       ReqCPUFreqGov       ReqCPUS
-ReqMem              ReqNodes            ReqTRES             Reservation
-ReservationId       Reserved            ResvCPU             ResvCPURAW
-Start               State               Submit              SubmitLine
-Suspended           SystemCPU           SystemComment       Timelimit
-TimelimitRaw        TotalCPU            TRESUsageInAve      TRESUsageInMax
-TRESUsageInMaxNode  TRESUsageInMaxTask  TRESUsageInMin      TRESUsageInMinNode
-TRESUsageInMinTask  TRESUsageInTot      TRESUsageOutAve     TRESUsageOutMax
-TRESUsageOutMaxNode TRESUsageOutMaxTask TRESUsageOutMin     TRESUsageOutMinNode
-TRESUsageOutMinTask TRESUsageOutTot     UID                 User
-UserCPU             WCKey               WCKeyID             WorkDir
+Constraints         Container           ConsumedEnergy      ConsumedEnergyRaw
+CPUTime             CPUTimeRAW          DBIndex             DerivedExitCode
+Elapsed             ElapsedRaw          Eligible            End
+ExitCode            Flags               GID                 Group
+JobID               JobIDRaw            JobName             Layout
+MaxDiskRead         MaxDiskReadNode     MaxDiskReadTask     MaxDiskWrite
+MaxDiskWriteNode    MaxDiskWriteTask    MaxPages            MaxPagesNode
+MaxPagesTask        MaxRSS              MaxRSSNode          MaxRSSTask
+MaxVMSize           MaxVMSizeNode       MaxVMSizeTask       McsLabel
+MinCPU              MinCPUNode          MinCPUTask          NCPUS
+NNodes              NodeList            NTasks              Priority
+Partition           QOS                 QOSRAW              Reason
+ReqCPUFreq          ReqCPUFreqMin       ReqCPUFreqMax       ReqCPUFreqGov
+ReqCPUS             ReqMem              ReqNodes            ReqTRES
+Reservation         ReservationId       Reserved            ResvCPU
+ResvCPURAW          Start               State               Submit
+SubmitLine          Suspended           SystemCPU           SystemComment
+Timelimit           TimelimitRaw        TotalCPU            TRESUsageInAve
+TRESUsageInMax      TRESUsageInMaxNode  TRESUsageInMaxTask  TRESUsageInMin
+TRESUsageInMinNode  TRESUsageInMinTask  TRESUsageInTot      TRESUsageOutAve
+TRESUsageOutMax     TRESUsageOutMaxNode TRESUsageOutMaxTask TRESUsageOutMin
+TRESUsageOutMinNode TRESUsageOutMinTask TRESUsageOutTot     UID
+User                UserCPU             WCKey               WCKeyID
+WorkDir
 .ft 1
 .fi
 .RE
@@ -560,6 +561,10 @@ Total energy consumed by all tasks in job, in joules.
 Note: Only in case of exclusive job allocation this value
 reflects the jobs' real energy consumption.
 
+.TP
+\f3Container\fP
+Path to OCI Container Bundle requested.
+
 .TP
 \f3CPUTime\fP
 Time used (Elapsed time * CPU count) by a job or step in HH:MM:SS format.
diff --git a/src/sacct/print.c b/src/sacct/print.c
index 54dd630595e..9a66565ba61 100644
--- a/src/sacct/print.c
+++ b/src/sacct/print.c
@@ -634,6 +634,23 @@ extern void print_fields(type_t type, void *object)
 					     tmp_char,
 					     (curr_inx == field_count));
 			break;
+		case PRINT_CONTAINER:
+			switch(type) {
+			case JOB:
+				tmp_char = job->container;
+				break;
+			case JOBSTEP:
+				tmp_char = step->container;
+				break;
+			case JOBCOMP:
+			default:
+				tmp_char = NULL;
+				break;
+			}
+			field->print_routine(field,
+					     tmp_char,
+					     (curr_inx == field_count));
+			break;
 		case PRINT_CONSUMED_ENERGY:
 			switch (type) {
 			case JOB:
diff --git a/src/sacct/sacct.c b/src/sacct/sacct.c
index 91efeda278d..f3b2e8983d2 100644
--- a/src/sacct/sacct.c
+++ b/src/sacct/sacct.c
@@ -59,6 +59,7 @@ print_field_t fields[] = {
 	{10, "Cluster", print_fields_str, PRINT_CLUSTER},
 	{14, "Comment", print_fields_str, PRINT_COMMENT},
 	{19, "Constraints", print_fields_str, PRINT_CONSTRAINTS},
+	{19, "Container", print_fields_str, PRINT_CONTAINER},
 	{14, "ConsumedEnergy", print_fields_str, PRINT_CONSUMED_ENERGY},
 	{17, "ConsumedEnergyRaw", print_fields_uint64,
 	 PRINT_CONSUMED_ENERGY_RAW},
diff --git a/src/sacct/sacct.h b/src/sacct/sacct.h
index 3d79dc7664c..3699e998b54 100644
--- a/src/sacct/sacct.h
+++ b/src/sacct/sacct.h
@@ -105,6 +105,7 @@ typedef enum {
 		PRINT_CLUSTER,
 		PRINT_COMMENT,
 		PRINT_CONSTRAINTS,
+		PRINT_CONTAINER,
 		PRINT_CONSUMED_ENERGY,
 		PRINT_CONSUMED_ENERGY_RAW,
 		PRINT_CPU_TIME,
-- 
GitLab