Whamcloud - gitweb
LU-12225 obdclass: fix race access vs removal of jobid_hash
[fs/lustre-release.git] / lustre / obdclass / jobid.c
index 75fd29b..07a6c57 100644 (file)
@@ -91,9 +91,8 @@ int jobid_get_from_environ(char *jobid_var, char *jobid, int *jobid_len)
                 * larger temp buffer for cfs_get_environ(), then
                 * truncating the string at some separator to fit into
                 * the specified jobid_len.  Fix later if needed. */
-               LCONSOLE_ERROR_MSG(0x16b,
-                                  "jobid: '%s' value too large (%d)\n",
-                                  obd_jobid_var, *jobid_len);
+               LCONSOLE_WARN("jobid: '%s' value too large (%d)\n",
+                             obd_jobid_var, *jobid_len);
                printed = true;
                rc = 0;
        }
@@ -214,6 +213,12 @@ static int jobid_get_from_cache(char *jobid, size_t joblen)
                pidmap->jp_jobid[0] = '\0';
                spin_lock_init(&pidmap->jp_lock);
                INIT_HLIST_NODE(&pidmap->jp_hash);
+               /*
+                * @pidmap might be reclaimed just after it is added into
+                * hash list, init @jp_refcount as 1 to make sure memory
+                * could be not freed during access.
+                */
+               atomic_set(&pidmap->jp_refcount, 1);
 
                /*
                 * Add the newly created map to the hash, on key collision we
@@ -227,8 +232,6 @@ static int jobid_get_from_cache(char *jobid, size_t joblen)
                               pid);
                        OBD_FREE_PTR(pidmap);
                        pidmap = pidmap2;
-               } else {
-                       cfs_hash_get(jobid_hash, &pidmap->jp_hash);
                }
        }