};
/* initialized in llapi_hsm_register_event_fifo() */
-int llapi_hsm_event_fd = -1;
+static int llapi_hsm_event_fd = -1;
+static bool created_hsm_event_fifo;
static inline const char *llapi_hsm_ct_ev2str(int type)
{
* \retval 0 on success.
* \retval -errno on error.
*/
-int llapi_hsm_register_event_fifo(char *path)
+int llapi_hsm_register_event_fifo(const char *path)
{
int read_fd;
struct stat statbuf;
"not a pipe or has a wrong mode", path);
return -errno;
}
+ } else {
+ created_hsm_event_fifo = true;
}
/* Open the FIFO for read so that the subsequent open for write
* \retval 0 on success.
* \retval -errno on error.
*/
-int llapi_hsm_unregister_event_fifo(char *path)
+int llapi_hsm_unregister_event_fifo(const char *path)
{
/* Noop unless the event fd was initialized */
if (llapi_hsm_event_fd < 0)
if (close(llapi_hsm_event_fd) < 0)
return -errno;
- unlink(path);
+ if (created_hsm_event_fifo) {
+ unlink(path);
+ created_hsm_event_fifo = false;
+ }
llapi_hsm_event_fd = -1;
/** 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;