Whamcloud - gitweb
LU-14339 obdclass: add option %H for jobid 75/50375/2
authorYang Sheng <ys@whamcloud.com>
Mon, 18 Jan 2021 17:46:05 +0000 (01:46 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 27 Feb 2024 05:43:34 +0000 (05:43 +0000)
Add a option %H to avoid jobid too long in some cases.

Lustre-change: https://review.whamcloud.com/41262
Lustre-commit: cf72ee174bbf7e60301ddff211b0685dc6c7adab

Signed-off-by: Yang Sheng <ys@whamcloud.com>
Change-Id: Iaf70da5de25fd321a21e6e6cd7f7d211dca1adf3
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Signed-off-by: Etienne AUJAMES <eaujames@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50375
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/obdclass/jobid.c
lustre/tests/sanity.sh

index b7a08d4..fc3ac27 100644 (file)
@@ -304,6 +304,7 @@ out:
  *   %e = executable
  *   %g = gid
  *   %h = hostname
+ *   %H = short hostname
  *   %j = jobid from environment
  *   %p = pid
  *   %u = uid
@@ -320,7 +321,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 */
@@ -330,6 +331,7 @@ static int jobid_interpret_string(const char *jobfmt, char *jobid,
                        *jobid = c;
                        joblen--;
                        jobid++;
+                       *jobid = '\0';
                        continue;
                }
 
@@ -345,6 +347,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 stored in process environment */
                        l = jobid_get_from_cache(jobid, joblen);
                        if (l < 0)
index ac0d38c..5b29047 100755 (executable)
@@ -15405,6 +15405,13 @@ test_205a() { # Job stats
        JOBCOMPLEX="S.$USER.touch.$(id -u).$(hostname).E"
 
        verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
+
+       if lctl set_param jobid_var=USER jobid_name="S.%j.%e.%u.%H.E"; then
+               JOBENV="JOBCOMPLEX"
+               JOBCOMPLEX="S.$USER.touch.$(id -u).$(hostname -s).E"
+
+               verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
+       fi
 }
 run_test 205a "Verify job stats"