From: Yang Sheng Date: Mon, 18 Jan 2021 17:46:05 +0000 (+0800) Subject: LU-14339 obdclass: add option %H for jobid X-Git-Tag: 2.14.0-RC1~9 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=cf72ee174bbf7e60301ddff211b0685dc6c7adab;p=fs%2Flustre-release.git LU-14339 obdclass: add option %H for jobid Add a option %H to avoid jobid too long in some cases. Signed-off-by: Yang Sheng Change-Id: Iaf70da5de25fd321a21e6e6cd7f7d211dca1adf3 Reviewed-on: https://review.whamcloud.com/41262 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo Reviewed-by: Jian Yu --- diff --git a/lustre/obdclass/jobid.c b/lustre/obdclass/jobid.c index 2ba4141..e29c51c 100644 --- a/lustre/obdclass/jobid.c +++ b/lustre/obdclass/jobid.c @@ -464,6 +464,7 @@ out: * %e = executable * %g = gid * %h = hostname + * %H = short hostname * %j = jobid from environment * %p = pid * %u = uid @@ -480,7 +481,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 */ @@ -490,6 +491,7 @@ static int jobid_interpret_string(const char *jobfmt, char *jobid, *jobid = c; joblen--; jobid++; + *jobid = '\0'; continue; } @@ -505,6 +507,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) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 54ffef7..878796c 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -16893,6 +16893,13 @@ test_205a() { # Job stats verify_jobstats "touch $DIR/$tfile" $SINGLEMDS fi + 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 + # test '%j' access to per-session jobid - if supported if lctl list_param jobid_this_session > /dev/null 2>&1 then