Whamcloud - gitweb
LU-3683 libcfs: improve validity test for valid file descriptors 75/7275/4
authorBob Glossman <bob.glossman@intel.com>
Thu, 8 Aug 2013 17:59:59 +0000 (10:59 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 14 Aug 2013 18:24:31 +0000 (18:24 +0000)
File descriptor members of struct lustre_kernelcomm aren't set to
anything special at start time.
This leads to incorrect tests and skipping valid fd closes at stop time.
Fixed by defining, setting, and testing against a specific LK_NOFD value.

Signed-off-by: Bob Glossman <bob.glossman@intel.com>
Change-Id: I9306ce380c5e049ef442b99ac20e51271deafbc5
Reviewed-on: http://review.whamcloud.com/7275
Tested-by: Hudson
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Keith Mannthey <keith.mannthey@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
libcfs/include/libcfs/libcfs_kernelcomm.h
libcfs/libcfs/kernel_user_comm.c
lustre/utils/liblustreapi.c
lustre/utils/liblustreapi_hsm.c

index f7be4b7..acf4779 100644 (file)
@@ -97,6 +97,7 @@ extern int libcfs_kkuc_group_foreach(int group, libcfs_kkuc_cb_t cb_func,
                                     void *cb_arg);
 
 #define LK_FLG_STOP 0x01
                                     void *cb_arg);
 
 #define LK_FLG_STOP 0x01
+#define LK_NOFD -1U
 
 /* kernelcomm control structure, passed from userspace to kernel */
 typedef struct lustre_kernelcomm {
 
 /* kernelcomm control structure, passed from userspace to kernel */
 typedef struct lustre_kernelcomm {
index 4cac2e5..e819be0 100644 (file)
  */
 int libcfs_ukuc_start(lustre_kernelcomm *link, int group)
 {
  */
 int libcfs_ukuc_start(lustre_kernelcomm *link, int group)
 {
-        int pfd[2];
+       int pfd[2];
 
 
-        if (pipe(pfd) < 0)
-                return -errno;
+       link->lk_rfd = link->lk_wfd = LK_NOFD;
 
 
-        memset(link, 0, sizeof(*link));
-        link->lk_rfd = pfd[0];
-        link->lk_wfd = pfd[1];
-        link->lk_group = group;
-        link->lk_uid = getpid();
-        return 0;
+       if (pipe(pfd) < 0)
+               return -errno;
+
+       memset(link, 0, sizeof(*link));
+       link->lk_rfd = pfd[0];
+       link->lk_wfd = pfd[1];
+       link->lk_group = group;
+       link->lk_uid = getpid();
+       return 0;
 }
 
 int libcfs_ukuc_stop(lustre_kernelcomm *link)
 {
 }
 
 int libcfs_ukuc_stop(lustre_kernelcomm *link)
 {
-        if (link->lk_wfd > 0)
-                close(link->lk_wfd);
-        return close(link->lk_rfd);
+       int rc;
+
+       if (link->lk_wfd != LK_NOFD)
+               close(link->lk_wfd);
+        rc = close(link->lk_rfd);
+       link->lk_rfd = link->lk_wfd = LK_NOFD;
+       return rc;
 }
 
 #define lhsz sizeof(*kuch)
 }
 
 #define lhsz sizeof(*kuch)
index 05e9929..a02f344 100644 (file)
@@ -3889,7 +3889,7 @@ int llapi_changelog_start(void **priv, int flags, const char *device,
                              startrec, flags);
         /* Only the kernel reference keeps the write side open */
         close(cp->kuc.lk_wfd);
                              startrec, flags);
         /* Only the kernel reference keeps the write side open */
         close(cp->kuc.lk_wfd);
-        cp->kuc.lk_wfd = 0;
+        cp->kuc.lk_wfd = LK_NOFD;
         if (rc < 0) {
                 /* frees and clears priv */
                 llapi_changelog_fini(priv);
         if (rc < 0) {
                 /* frees and clears priv */
                 llapi_changelog_fini(priv);
index 72b64cc..751680d 100644 (file)
@@ -155,7 +155,7 @@ int llapi_hsm_copytool_register(struct hsm_copytool_private **priv,
 
        /* Only the kernel reference keeps the write side open */
        close(ct->kuc.lk_wfd);
 
        /* Only the kernel reference keeps the write side open */
        close(ct->kuc.lk_wfd);
-       ct->kuc.lk_wfd = 0;
+       ct->kuc.lk_wfd = LK_NOFD;
        if (rc < 0)
                goto out_kuc;
 
        if (rc < 0)
                goto out_kuc;