Whamcloud - gitweb
LU-5577 obdclass: change loop indexes to unsigned
[fs/lustre-release.git] / libcfs / libcfs / kernel_user_comm.c
index fc92e2f..5ac789e 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 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 rc;
 
        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];
@@ -80,6 +89,15 @@ int libcfs_ukuc_stop(lustre_kernelcomm *link)
        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.
@@ -288,7 +306,7 @@ int libcfs_kkuc_group_put(int group, void *payload)
        int one_success = 0;
        ENTRY;
 
-       down_read(&kg_sem);
+       down_write(&kg_sem);
        list_for_each_entry(reg, &kkuc_groups[group], kr_chain) {
                if (reg->kr_fp != NULL) {
                        rc = libcfs_kkuc_msg_put(reg->kr_fp, payload);
@@ -300,7 +318,7 @@ int libcfs_kkuc_group_put(int group, void *payload)
                        }
                }
        }
-       up_read(&kg_sem);
+       up_write(&kg_sem);
 
        /* don't return an error if the message has been delivered
         * at least to one agent */