Whamcloud - gitweb
LU-14291 lustre: clean up lustre_eacl.h and make server-only
[fs/lustre-release.git] / lustre / obdclass / jobid.c
index e1b5ff4..e29c51c 100644 (file)
@@ -33,9 +33,7 @@
 
 #define DEBUG_SUBSYSTEM S_RPC
 #include <linux/user_namespace.h>
-#ifdef HAVE_UIDGID_HEADER
 #include <linux/uidgid.h>
-#endif
 #include <linux/utsname.h>
 
 #include <libcfs/libcfs.h>
@@ -240,7 +238,7 @@ int jobid_get_from_environ(char *jobid_var, char *jobid, int *jobid_len)
                if (unlikely(ktime_to_ns(printed) == 0 ||
                             ktime_after(ktime_get(),
                                         ktime_add_ns(printed,
-                                                     3600*24*NSEC_PER_SEC)))) {
+                                            3600ULL * 24 * NSEC_PER_SEC)))) {
                        LCONSOLE_WARN("jobid: '%s' value too large (%d)\n",
                                      obd_jobid_var, *jobid_len);
                        printed = ktime_get();
@@ -336,7 +334,7 @@ static int jobid_get_from_cache(char *jobid, size_t joblen)
 {
        static time64_t last_expire;
        bool expire_cache = false;
-       pid_t pid = current_pid();
+       pid_t pid = current->pid;
        struct jobid_pid_map *pidmap = NULL;
        time64_t now = ktime_get_real_seconds();
        int rc = 0;
@@ -466,6 +464,7 @@ out:
  *   %e = executable
  *   %g = gid
  *   %h = hostname
+ *   %H = short hostname
  *   %j = jobid from environment
  *   %p = pid
  *   %u = uid
@@ -482,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 */
@@ -492,12 +491,13 @@ static int jobid_interpret_string(const char *jobfmt, char *jobid,
                        *jobid = c;
                        joblen--;
                        jobid++;
+                       *jobid = '\0';
                        continue;
                }
 
                switch ((f = *jobfmt++)) {
                case 'e': /* executable name */
-                       l = snprintf(jobid, joblen, "%s", current_comm());
+                       l = snprintf(jobid, joblen, "%s", current->comm);
                        break;
                case 'g': /* group ID */
                        l = snprintf(jobid, joblen, "%u",
@@ -507,13 +507,22 @@ 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)
                                l = 0;
                        break;
                case 'p': /* process ID */
-                       l = snprintf(jobid, joblen, "%u", current_pid());
+                       l = snprintf(jobid, joblen, "%u", current->pid);
                        break;
                case 'u': /* user ID */
                        l = snprintf(jobid, joblen, "%u",
@@ -699,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);