diff mbox series

[7/9] lustre: obdclass: add option %H for jobid

Message ID 1612832067-1449-8-git-send-email-jsimmons@infradead.org (mailing list archive)
State New, archived
Headers show
Series Sync to OpenSFS as of Feb 8, 2021 | expand

Commit Message

James Simmons Feb. 9, 2021, 12:54 a.m. UTC
From: Yang Sheng <ys@whamcloud.com>

Add a option %H to avoid jobid too long in some cases.

WC-bug-id: https://jira.whamcloud.com/browse/LU-14339
Lustre-commit: cf72ee174bbf7e6 ("LU-14339 obdclass: add option %H for jobid")
Signed-off-by: Yang Sheng <ys@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/41262
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 fs/lustre/obdclass/jobid.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fs/lustre/obdclass/jobid.c b/fs/lustre/obdclass/jobid.c
index 3ee9d40..52ba398 100644
--- a/fs/lustre/obdclass/jobid.c
+++ b/fs/lustre/obdclass/jobid.c
@@ -206,6 +206,7 @@  static void jobid_prune_expedite(void)
  *   %e = executable
  *   %g = gid
  *   %h = hostname
+ *   %H = short hostname
  *   %j = per-session
  *   %p = pid
  *   %u = uid
@@ -222,7 +223,7 @@  static int jobid_interpret_string(const char *jobfmt, char *jobid,
 	char c;
 
 	while ((c = *jobfmt++) && joblen > 1) {
-		char f;
+		char f, *p;
 		int l;
 
 		if (isspace(c)) /* Don't allow embedded spaces */
@@ -232,6 +233,7 @@  static int jobid_interpret_string(const char *jobfmt, char *jobid,
 			*jobid = c;
 			joblen--;
 			jobid++;
+			*jobid = '\0';
 			continue;
 		}
 
@@ -247,6 +249,15 @@  static int jobid_interpret_string(const char *jobfmt, char *jobid,
 			l = snprintf(jobid, joblen, "%s",
 				     init_utsname()->nodename);
 			break;
+		case 'H': /* short hostname. Cut at first dot */
+			l = snprintf(jobid, joblen, "%s",
+				     init_utsname()->nodename);
+			p = strnchr(jobid, joblen, '.');
+			if (p) {
+				*p = '\0';
+				l = p - jobid;
+			}
+			break;
 		case 'j': /* jobid requested by process */
 			l = snprintf(jobid, joblen, "%s",
 				     jobid_current() ?: "jobid");