X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Futils%2Fliblustreapi_hsm.c;h=c4b5437b3f4e3b1252060045999e4a3703a4b1e8;hp=f0653598f1df67060b3dea6a79c3b5b9cee2bdae;hb=848f9e20320cb7c01eaf7f1b5c27f5efd54e4818;hpb=c42b426c87c3d3b1dc9eda612cc831293dc80d68;ds=sidebyside diff --git a/lustre/utils/liblustreapi_hsm.c b/lustre/utils/liblustreapi_hsm.c index f065359..c4b5437 100644 --- a/lustre/utils/liblustreapi_hsm.c +++ b/lustre/utils/liblustreapi_hsm.c @@ -76,8 +76,8 @@ struct hsm_copytool_private { * \param archive_count * \param archives Which archive numbers this copytool is responsible for */ -int llapi_hsm_copytool_start(void **priv, char *fsname, int flags, - int archive_count, int *archives) +int llapi_hsm_copytool_start(struct hsm_copytool_private **priv, char *fsname, + int flags, int archive_count, int *archives) { struct hsm_copytool_private *ct; int rc; @@ -128,18 +128,18 @@ int llapi_hsm_copytool_start(void **priv, char *fsname, int flags, ct->kuc.lk_data = ct->archives; rc = root_ioctl(ct->fsname, LL_IOC_HSM_CT_START, &(ct->kuc), NULL, WANT_ERROR); - /* ignore if it was already registered on coordinator */ - if (rc == -EEXIST) - rc = 0; /* Only the kernel reference keeps the write side open */ close(ct->kuc.lk_wfd); ct->kuc.lk_wfd = 0; if (rc < 0) - goto out_err; + goto out_kuc; *priv = ct; return 0; +out_kuc: + /* cleanup the kuc channel */ + libcfs_ukuc_stop(&ct->kuc); out_err: if (ct->fsname) free(ct->fsname); @@ -152,11 +152,11 @@ out_err: * killed), the libcfs module will be referenced and unremovable, * even after Lustre services stop. */ -int llapi_hsm_copytool_fini(void **priv) +int llapi_hsm_copytool_fini(struct hsm_copytool_private **priv) { struct hsm_copytool_private *ct; - ct = (struct hsm_copytool_private *)priv; + ct = *priv; if (!ct || (ct->magic != CT_PRIV_MAGIC)) return -EINVAL; @@ -174,21 +174,19 @@ int llapi_hsm_copytool_fini(void **priv) } /** Wait for the next hsm_action_list - * \param priv Opaque private control structure + * \param ct Opaque private control structure * \param halh Action list handle, will be allocated here * \param msgsize Number of bytes in the message, will be set here * \return 0 valid message received; halh and msgsize are set * <0 error code */ -int llapi_hsm_copytool_recv(void *priv, struct hsm_action_list **halh, - int *msgsize) +int llapi_hsm_copytool_recv(struct hsm_copytool_private *ct, + struct hsm_action_list **halh, int *msgsize) { - struct hsm_copytool_private *ct; struct kuc_hdr *kuch; struct hsm_action_list *hal; int rc = 0; - ct = (struct hsm_copytool_private *)priv; if (!ct || (ct->magic != CT_PRIV_MAGIC)) return -EINVAL; if (halh == NULL || msgsize == NULL) @@ -235,12 +233,12 @@ int llapi_hsm_copytool_recv(void *priv, struct hsm_action_list **halh, /* Check that we have registered for this archive # * if 0 registered, we serve any archive */ if (ct->archives && - ((1 << (hal->hal_archive_num - 1)) & ct->archives) == 0) { + ((1 << (hal->hal_archive_id - 1)) & ct->archives) == 0) { llapi_err_noerrno(LLAPI_MSG_INFO, "This copytool does not service archive #%d," " ignoring this request." " Mask of served archive is 0x%.8X", - hal->hal_archive_num, ct->archives); + hal->hal_archive_id, ct->archives); rc = -EAGAIN; goto out_free; @@ -443,7 +441,6 @@ out_unlink: return rc; } - /** * Return the current HSM states and HSM requests related to file pointed by \a * path. @@ -513,3 +510,73 @@ int llapi_hsm_state_set(const char *path, __u64 setmask, __u64 clearmask, return rc; } + +/** + * Return the current HSM request related to file pointed by \a path. + * + * \param hca Should be allocated by caller. Will be filled with current file + * actions. + * + * \retval 0 on success. + * \retval -errno on error. + */ +int llapi_hsm_current_action(const char *path, struct hsm_current_action *hca) +{ + int fd; + int rc; + + fd = open(path, O_RDONLY | O_NONBLOCK); + if (fd < 0) + return -errno; + + rc = ioctl(fd, LL_IOC_HSM_ACTION, hca); + /* If error, save errno value */ + rc = rc ? -errno : 0; + + close(fd); + return rc; +} + +/** + * Allocate a hsm_user_request with the specified carateristics. + * This structure should be freed with free(). + * + * \return an allocated structure on success, NULL otherwise. + */ +struct hsm_user_request *llapi_hsm_user_request_alloc(int itemcount, + int data_len) +{ + int len = 0; + + len += sizeof(struct hsm_user_request); + len += sizeof(struct hsm_user_item) * itemcount; + len += data_len; + + return (struct hsm_user_request *)malloc(len); +} + +/** + * Send a HSM request to Lustre, described in \param request. + * + * This request should be allocated with llapi_hsm_user_request_alloc(). + * + * \param mnt Should be the Lustre moint point. + * \return 0 on success, an error code otherwise. + */ +int llapi_hsm_request(char *mnt, struct hsm_user_request *request) +{ + int rc; + int fd; + + rc = get_root_path(WANT_FD, NULL, &fd, mnt, -1); + if (rc) + return rc; + + rc = ioctl(fd, LL_IOC_HSM_REQUEST, request); + /* If error, save errno value */ + rc = rc ? -errno : 0; + + close(fd); + return rc; +} +