Whamcloud - gitweb
LU-5095 hsm: Allow receiving messages to be non-blocking
[fs/lustre-release.git] / libcfs / libcfs / kernel_user_comm.c
index fc92e2f..1c5e0ee 100644 (file)
  * @param link Private descriptor for pipe/socket.
  * @param groups KUC broadcast group to listen to
  *          (can be null for unicast to this pid)
  * @param link Private descriptor for pipe/socket.
  * @param groups KUC broadcast group to listen to
  *          (can be null for unicast to this pid)
+ * @param rfd_flags flags for read side of pipe (e.g. O_NONBLOCK)
  */
  */
-int libcfs_ukuc_start(lustre_kernelcomm *link, int group)
+int libcfs_ukuc_start(lustre_kernelcomm *link, int group, int rfd_flags)
 {
        int pfd[2];
 {
        int pfd[2];
+       int rc;
 
        link->lk_rfd = link->lk_wfd = LK_NOFD;
 
        if (pipe(pfd) < 0)
                return -errno;
 
 
        link->lk_rfd = link->lk_wfd = LK_NOFD;
 
        if (pipe(pfd) < 0)
                return -errno;
 
+       if (fcntl(pfd[0], F_SETFL, rfd_flags) < 0) {
+               rc = -errno;
+               close(pfd[0]);
+               close(pfd[1]);
+               return rc;
+       }
+
        memset(link, 0, sizeof(*link));
        link->lk_rfd = pfd[0];
        link->lk_wfd = pfd[1];
        memset(link, 0, sizeof(*link));
        link->lk_rfd = pfd[0];
        link->lk_wfd = pfd[1];
@@ -80,6 +89,15 @@ int libcfs_ukuc_stop(lustre_kernelcomm *link)
        return rc;
 }
 
        return rc;
 }
 
+/** Returns the file descriptor for the read side of the pipe,
+ *  to be used with poll/select.
+ * @param link Private descriptor for pipe/socket.
+ */
+int libcfs_ukuc_get_rfd(lustre_kernelcomm *link)
+{
+       return link->lk_rfd;
+}
+
 #define lhsz sizeof(*kuch)
 
 /** Read a message from the link.
 #define lhsz sizeof(*kuch)
 
 /** Read a message from the link.