} __attribute__((packed)) lustre_kernelcomm;
/* Userspace methods */
-extern int libcfs_ukuc_start(lustre_kernelcomm *l, int groups);
+extern int libcfs_ukuc_start(lustre_kernelcomm *l, int groups, int rfd_flags);
extern int libcfs_ukuc_stop(lustre_kernelcomm *l);
+int libcfs_ukuc_get_rfd(lustre_kernelcomm *link);
extern int libcfs_ukuc_msg_get(lustre_kernelcomm *l, char *buf, int maxsize,
int transport);
* @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];
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.
struct hsm_copyaction_private;
extern int llapi_hsm_copytool_register(struct hsm_copytool_private **priv,
- const char *mnt, int flags,
- int archive_count, int *archives);
+ const char *mnt, int archive_count,
+ int *archives, int rfd_flags);
extern int llapi_hsm_copytool_unregister(struct hsm_copytool_private **priv);
+extern int llapi_hsm_copytool_get_fd(struct hsm_copytool_private *ct);
extern int llapi_hsm_copytool_recv(struct hsm_copytool_private *priv,
struct hsm_action_list **hal, int *msgsize);
extern int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp,
llapi_error_callback_set(llapi_hsm_log_error);
}
- rc = llapi_hsm_copytool_register(&ctdata, opt.o_mnt, 0,
- opt.o_archive_cnt, opt.o_archive_id);
+ rc = llapi_hsm_copytool_register(&ctdata, opt.o_mnt,
+ opt.o_archive_cnt,
+ opt.o_archive_id, 0);
if (rc < 0) {
CT_ERROR(rc, "cannot start copytool interface");
return rc;
if (rc == -ESHUTDOWN) {
CT_TRACE("shutting down");
break;
- } else if (rc == -EAGAIN) {
- continue; /* msg not for us */
} else if (rc < 0) {
CT_WARN("cannot receive action list: %s",
strerror(-rc));
cp->flags = flags;
/* Set up the receiver */
- rc = libcfs_ukuc_start(&cp->kuc, 0 /* no group registration */);
+ rc = libcfs_ukuc_start(&cp->kuc, 0 /* no group registration */, 0);
if (rc < 0)
goto out_free;
/** Register a copytool
* \param[out] priv Opaque private control structure
* \param mnt Lustre filesystem mount point
- * \param flags Open flags, currently unused (e.g. O_NONBLOCK)
* \param archive_count
* \param archives Which archive numbers this copytool is responsible for
+ * \param rfd_flags flags applied to read fd of pipe (e.g. O_NONBLOCK)
*/
int llapi_hsm_copytool_register(struct hsm_copytool_private **priv,
- const char *mnt, int flags, int archive_count,
- int *archives)
+ const char *mnt, int archive_count,
+ int *archives, int rfd_flags)
{
struct hsm_copytool_private *ct;
int rc;
ct->archives |= (1 << (archives[rc] - 1));
}
- rc = libcfs_ukuc_start(&ct->kuc, KUC_GRP_HSM);
+ rc = libcfs_ukuc_start(&ct->kuc, KUC_GRP_HSM, rfd_flags);
if (rc < 0)
goto out_err;
return 0;
}
+/** Returns a file descriptor to poll/select on.
+ * \param ct Opaque private control structure
+ * \retval -EINVAL on error
+ * \retval the file descriptor for reading HSM events from the kernel
+ */
+int llapi_hsm_copytool_get_fd(struct hsm_copytool_private *ct)
+{
+ if (ct == NULL || ct->magic != CT_PRIV_MAGIC)
+ return -EINVAL;
+
+ return libcfs_ukuc_get_rfd(&ct->kuc);
+}
+
/** Wait for the next hsm_action_list
* \param ct Opaque private control structure
* \param halh Action list handle, will be allocated here
kuch = ct->kuch;
+repeat:
rc = libcfs_ukuc_msg_get(&ct->kuc, (char *)kuch,
HAL_MAXSIZE + sizeof(*kuch),
KUC_TRANSPORT_HSM);
" ignoring this request."
" Mask of served archive is 0x%.8X",
hal->hal_archive_id, ct->archives);
- rc = -EAGAIN;
- goto out_err;
+ goto repeat;
}
*halh = hal;