From 56d0f3df87f4fecae028d7aace73f8979f54ae94 Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Fri, 8 Dec 2017 13:59:43 -0600 Subject: [PATCH] LU-10357 hsm: open file to be archived before starting In the archive case of llapi_hsm_action_begin(), open the file to be archived before calling the LL_IOC_HSM_COPY_START ioctl. Store the open FD in struct hsm_copyaction_private, return a dup of it llapi_hsm_action_get_fd(), and close it in llapi_hsm_action_end(). Calling open() first avoids 3 extra RPCs (MDS_GETATTR, LDLM_ENQUEUE for layout to get data version, LDLM_ENQUEUE for fstat()) when archiving. Lustre-change: https://review.whamcloud.com/30456 Lustre-commit: 77cd1a21e312ca00b37b33689091734a12eec048 Signed-off-by: John L. Hammond Change-Id: Idea0a7f4cb63bd9d712ff2ce9fcb59a3b278d0f2 Reviewed-by: Quentin Bouget Reviewed-by: Dmitry Eremin Signed-off-by: Minh Diep Reviewed-on: https://review.whamcloud.com/30721 Tested-by: Jenkins Tested-by: Maloo --- lustre/utils/liblustreapi_hsm.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lustre/utils/liblustreapi_hsm.c b/lustre/utils/liblustreapi_hsm.c index 8fe05b4..635e4b24 100644 --- a/lustre/utils/liblustreapi_hsm.c +++ b/lustre/utils/liblustreapi_hsm.c @@ -79,6 +79,7 @@ struct hsm_copytool_private { #define CP_PRIV_MAGIC 0x19880429 struct hsm_copyaction_private { __u32 magic; + __u32 source_fd; __s32 data_fd; const struct hsm_copytool_private *ct_priv; struct hsm_copy copy; @@ -1100,13 +1101,15 @@ int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp, int restore_mdt_index, int restore_open_flags, bool is_error) { - struct hsm_copyaction_private *hcp; - int rc; + struct hsm_copyaction_private *hcp; + int fd; + int rc; hcp = calloc(1, sizeof(*hcp)); if (hcp == NULL) return -ENOMEM; + hcp->source_fd = -1; hcp->data_fd = -1; hcp->ct_priv = ct; hcp->copy.hc_hai = *hai; @@ -1115,7 +1118,16 @@ int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp, if (is_error) goto ok_out; - if (hai->hai_action == HSMA_RESTORE) { + if (hai->hai_action == HSMA_ARCHIVE) { + fd = ct_open_by_fid(hcp->ct_priv, &hai->hai_dfid, + O_RDONLY | O_NOATIME | O_NOFOLLOW | O_NONBLOCK); + if (fd < 0) { + rc = fd; + goto err_out; + } + + hcp->source_fd = fd; + } else if (hai->hai_action == HSMA_RESTORE) { rc = ct_md_getattr(hcp->ct_priv, &hai->hai_fid, &hcp->stat); if (rc < 0) goto err_out; @@ -1124,12 +1136,11 @@ int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp, restore_open_flags); if (rc < 0) goto err_out; - } - - /* Since remove is atomic there is no need to send an initial - * MDS_HSM_PROGRESS RPC. */ - if (hai->hai_action == HSMA_REMOVE) + } else if (hai->hai_action == HSMA_REMOVE) { + /* Since remove is atomic there is no need to send an + * initial MDS_HSM_PROGRESS RPC. */ goto out_log; + } rc = ioctl(ct->mnt_fd, LL_IOC_HSM_COPY_START, &hcp->copy); if (rc < 0) { @@ -1146,6 +1157,9 @@ ok_out: return 0; err_out: + if (!(hcp->source_fd < 0)) + close(hcp->source_fd); + if (!(hcp->data_fd < 0)) close(hcp->data_fd); @@ -1227,6 +1241,9 @@ end: llapi_hsm_log_ct_progress(&hcp, hai, CT_FINISH, 0, 0); err_cleanup: + if (!(hcp->source_fd < 0)) + close(hcp->source_fd); + if (!(hcp->data_fd < 0)) close(hcp->data_fd); @@ -1312,8 +1329,8 @@ int llapi_hsm_action_get_fd(const struct hsm_copyaction_private *hcp) return -EINVAL; if (hai->hai_action == HSMA_ARCHIVE) { - return ct_open_by_fid(hcp->ct_priv, &hai->hai_dfid, - O_RDONLY | O_NOATIME | O_NOFOLLOW | O_NONBLOCK); + fd = dup(hcp->source_fd); + return fd < 0 ? -errno : fd; } else if (hai->hai_action == HSMA_RESTORE) { fd = dup(hcp->data_fd); return fd < 0 ? -errno : fd; -- 1.8.3.1