* (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
* alternatives
*
+ * Copyright (c) 2013, 2014, Intel Corporation.
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 or (at your discretion) any later version.
/* initialized in llapi_hsm_register_event_fifo() */
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_write_json_event(struct llapi_json_item_list **event)
+static int llapi_hsm_write_json_event(struct llapi_json_item_list **event)
{
int rc;
char time_string[40];
* \retval 0 on success.
* \retval -errno on error.
*/
-int llapi_hsm_log_ct_registration(struct hsm_copytool_private **priv,
- __u32 event_type)
+static int llapi_hsm_log_ct_registration(struct hsm_copytool_private **priv,
+ __u32 event_type)
{
int rc;
char agent_uuid[UUID_MAX];
struct hsm_copytool_private *ct;
struct llapi_json_item_list *json_items;
+ /* Noop unless the event fd was initialized */
+ if (llapi_hsm_event_fd < 0)
+ return 0;
+
if (priv == NULL || *priv == NULL)
return -EINVAL;
* \retval 0 on success.
* \retval -errno on error.
*/
-int llapi_hsm_log_ct_progress(struct hsm_copyaction_private **phcp,
- const struct hsm_action_item *hai, __u32 progress_type,
- __u64 total, __u64 current)
+static int llapi_hsm_log_ct_progress(struct hsm_copyaction_private **phcp,
+ const struct hsm_action_item *hai,
+ __u32 progress_type,
+ __u64 total, __u64 current)
{
int rc;
int linkno = 0;
struct hsm_copyaction_private *hcp;
struct llapi_json_item_list *json_items;
+ /* Noop unless the event fd was initialized */
+ if (llapi_hsm_event_fd < 0)
+ return 0;
+
if (phcp == NULL || *phcp == NULL)
return -EINVAL;
"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
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 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)
+ * \param[out] priv Opaque private control structure
+ * \param mnt Lustre filesystem mount point
+ * \param archive_count Number of valid archive IDs in \a archives
+ * \param archives Which archive numbers this copytool is
+ * responsible for
+ * \param rfd_flags flags applied to read fd of pipe
+ * (e.g. O_NONBLOCK)
+ *
+ * \retval 0 on success.
+ * \retval -errno on error.
*/
int llapi_hsm_copytool_register(struct hsm_copytool_private **priv,
const char *mnt, int archive_count,
llapi_err_noerrno(LLAPI_MSG_ERROR,
"maximum of %zu archives supported",
8 * sizeof(ct->archives));
+ rc = -EINVAL;
goto out_err;
}
/* in the list we have a all archive wildcard
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
"cannot start copytool on '%s'", mnt);
- goto out_err;
- } else {
- rc = 0;
+ goto out_kuc;
}
llapi_hsm_log_ct_registration(&ct, CT_REGISTER);
/* Only the kernel reference keeps the write side open */
close(ct->kuc.lk_wfd);
ct->kuc.lk_wfd = LK_NOFD;
- if (rc < 0)
- goto out_kuc;
-
*priv = ct;
+
return 0;
out_kuc: