X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdclass%2Fjobid.c;h=e29c51cc0f99bb9a8717e20c82eca9a10b2099b7;hb=4cfe77df6f2499effa1644e6ad5a594abb11be23;hp=939fec1ddf75911b89d924027a03fedee613daad;hpb=57bb3024613831d5d7f8f085bb0c7ebc33796790;p=fs%2Flustre-release.git diff --git a/lustre/obdclass/jobid.c b/lustre/obdclass/jobid.c index 939fec1..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) @@ -697,26 +708,19 @@ int lustre_get_jobid(char *jobid, size_t joblen) rc = jobid_interpret_string(obd_jobid_name, jobid, joblen); } else if (strcmp(obd_jobid_var, JOBSTATS_PROCNAME_UID) == 0) { rc = jobid_interpret_string("%e.%u", jobid, joblen); - } else if (strcmp(obd_jobid_var, JOBSTATS_SESSION) == 0) { - char *jid; - - rcu_read_lock(); - jid = jobid_current(); - if (jid) - strlcpy(jobid, jid, sizeof(jobid)); - rcu_read_unlock(); - } else if (jobid_name_is_valid(current->comm)) { + } else if (strcmp(obd_jobid_var, JOBSTATS_SESSION) == 0 || + jobid_name_is_valid(current->comm)) { /* - * obd_jobid_var holds the jobid environment variable name. - * Skip initial check if obd_jobid_name already uses "%j", - * otherwise try just "%j" first, then fall back to whatever - * is in obd_jobid_name if obd_jobid_var is not found. + * per-process jobid wanted, either from environment or from + * per-session setting. + * If obd_jobid_name contains "%j" or if getting the pre-process + * jobid directly fails, fall back to using obd_jobid_name. */ rc = -EAGAIN; if (!strnstr(obd_jobid_name, "%j", joblen)) rc = jobid_get_from_cache(jobid, joblen); - /* fall back to jobid_node if jobid_var not in environment */ + /* fall back to jobid_node if jobid_var not available */ if (rc < 0) { int rc2 = jobid_interpret_string(obd_jobid_name, jobid, joblen);