[PATCH 08/39] staging/lustre/libcfs: improve validity test for valid file descriptors

From: Peng Tao
Date: Thu Nov 14 2013 - 11:39:45 EST


From: Bob Glossman <bob.glossman@xxxxxxxxx>

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.

Lustre-change: http://review.whamcloud.com/7275
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-3683
Signed-off-by: Bob Glossman <bob.glossman@xxxxxxxxx>
Reviewed-by: John L. Hammond <john.hammond@xxxxxxxxx>
Reviewed-by: Keith Mannthey <keith.mannthey@xxxxxxxxx>
Reviewed-by: Oleg Drokin <oleg.drokin@xxxxxxxxx>
Signed-off-by: Peng Tao <bergwolf@xxxxxxxxx>
Signed-off-by: Andreas Dilger <andreas.dilger@xxxxxxxxx>
---
.../include/linux/libcfs/libcfs_kernelcomm.h | 1 +
.../lustre/lustre/libcfs/kernel_user_comm.c | 10 ++++++++--
2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h
index 596a15f..4e12ffc 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h
@@ -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
+#define LK_NOFD -1U

/* kernelcomm control structure, passed from userspace to kernel */
typedef struct lustre_kernelcomm {
diff --git a/drivers/staging/lustre/lustre/libcfs/kernel_user_comm.c b/drivers/staging/lustre/lustre/libcfs/kernel_user_comm.c
index 74a0db5..9e5e3cc 100644
--- a/drivers/staging/lustre/lustre/libcfs/kernel_user_comm.c
+++ b/drivers/staging/lustre/lustre/libcfs/kernel_user_comm.c
@@ -56,6 +56,8 @@ int libcfs_ukuc_start(lustre_kernelcomm *link, int group)
{
int pfd[2];

+ link->lk_rfd = link->lk_wfd = LK_NOFD;
+
if (pipe(pfd) < 0)
return -errno;

@@ -69,9 +71,13 @@ int libcfs_ukuc_start(lustre_kernelcomm *link, int group)

int libcfs_ukuc_stop(lustre_kernelcomm *link)
{
- if (link->lk_wfd > 0)
+ int rc;
+
+ if (link->lk_wfd != LK_NOFD)
close(link->lk_wfd);
- return close(link->lk_rfd);
+ rc = close(link->lk_rfd);
+ link->lk_rfd = link->lk_wfd = LK_NOFD;
+ return rc;
}

#define lhsz sizeof(*kuch)
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/