Whamcloud - gitweb
b=19069 save nid string into buffer before creating dir
authorhongchao.zhang <Hongchao.Zhang@Sun.COM>
Thu, 11 Feb 2010 20:41:06 +0000 (12:41 -0800)
committerRobert Read <rread@sun.com>
Thu, 11 Feb 2010 20:41:06 +0000 (12:41 -0800)
in lprocfs_exp_setup, save the nid string gotten from
libcfs_nid2str into a temporary buffer before calling
lprocfs_register to create proc directory, then to
avoid the race on the internal nid string buffer.

i=johann@sun.com
i=zhen.liang@sun.com

libcfs/libcfs/nidstrings.c
lnet/include/lnet/lnet.h
lustre/obdclass/lprocfs_status.c

index 68c2ebc..36009d4 100644 (file)
@@ -64,9 +64,6 @@
  * between getting its string and using it.
  */
 
-#define LNET_NIDSTR_COUNT  128     /* # of nidstrings */
-#define LNET_NIDSTR_SIZE   32      /* size of each one (see below for usage) */
-
 static char      libcfs_nidstrings[LNET_NIDSTR_COUNT][LNET_NIDSTR_SIZE];
 static int       libcfs_nidstring_idx = 0;
 
index b30d737..5c3f46d 100644 (file)
@@ -55,4 +55,7 @@
 #include <lnet/types.h>
 #include <lnet/api.h>
 
+#define LNET_NIDSTR_COUNT  1024    /* # of nidstrings */
+#define LNET_NIDSTR_SIZE   32      /* size of each one (see below for usage) */
+
 #endif
index 754c515..9510296 100644 (file)
@@ -1768,6 +1768,7 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
         struct nid_stat *new_stat, *old_stat;
         struct obd_device *obd = NULL;
         cfs_proc_dir_entry_t *entry;
+        char *buffer = NULL;
         int rc = 0;
         ENTRY;
 
@@ -1820,9 +1821,16 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
                 GOTO(destroy_new, rc = -EALREADY);
         }
         /* not found - create */
-        new_stat->nid_proc = lprocfs_register(libcfs_nid2str(*nid),
+        OBD_ALLOC(buffer, LNET_NIDSTR_SIZE);
+        if (buffer == NULL)
+                GOTO(destroy_new, rc = -ENOMEM);
+
+        memcpy(buffer, libcfs_nid2str(*nid), LNET_NIDSTR_SIZE);
+        new_stat->nid_proc = lprocfs_register(buffer, 
                                               obd->obd_proc_exports_entry,
                                               NULL, NULL);
+        OBD_FREE(buffer, LNET_NIDSTR_SIZE);
+
         if (new_stat->nid_proc == NULL) {
                 CERROR("Error making export directory for nid %s\n",
                        libcfs_nid2str(*nid));