X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fliblustreapi_hsm.c;h=d3dc44925618dca93bc6daa56d665a9497625abb;hb=8d1639b5cf1edbc885876956dcd6189173c00955;hp=b7678d7b3be28e26f83ef967be0af6fd22fc63c3;hpb=62752bf3b143630560adfdb568606a661fdafafb;p=fs%2Flustre-release.git diff --git a/lustre/utils/liblustreapi_hsm.c b/lustre/utils/liblustreapi_hsm.c index b7678d7..d3dc449 100644 --- a/lustre/utils/liblustreapi_hsm.c +++ b/lustre/utils/liblustreapi_hsm.c @@ -6,7 +6,7 @@ * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies * alternatives * - * Copyright (c) 2013, 2015, Intel Corporation. + * Copyright (c) 2013, 2017, Intel Corporation. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser General Public License @@ -57,8 +57,7 @@ #include #endif -#include -#include +#include #include #include "lustreapi_internal.h" @@ -79,6 +78,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; @@ -429,11 +429,12 @@ static int llapi_hsm_log_ct_progress(struct hsm_copyaction_private **phcp, goto err; } - if (progress_type == CT_RUNNING) + if (progress_type == CT_RUNNING) { rc = llapi_json_add_item(&json_items, "current_bytes", LLAPI_JSON_BIGNUM, ¤t); if (rc < 0) goto err; + } cancel: rc = llapi_json_add_item(&json_items, "event_type", LLAPI_JSON_STRING, @@ -472,9 +473,10 @@ out_free: */ int llapi_hsm_register_event_fifo(const char *path) { - int rc; int read_fd; struct stat statbuf; + struct sigaction ignore_action; + int rc; /* Create the FIFO if necessary. */ if ((mkfifo(path, 0644) < 0) && (errno != EEXIST)) { @@ -523,7 +525,10 @@ int llapi_hsm_register_event_fifo(const char *path) } /* Ignore SIGPIPEs -- can occur if the reader goes away. */ - signal(SIGPIPE, SIG_IGN); + memset(&ignore_action, 0, sizeof(ignore_action)); + ignore_action.sa_handler = SIG_IGN; + sigemptyset(&ignore_action.sa_mask); + sigaction(SIGPIPE, &ignore_action, NULL); return 0; } @@ -929,7 +934,7 @@ out_err: * \param parent_len Destination buffer size. * \return 0 on success. */ -static int fid_parent(const char *mnt, const lustre_fid *fid, char *parent, +static int fid_parent(const char *mnt, const struct lu_fid *fid, char *parent, size_t parent_len) { int rc; @@ -1095,13 +1100,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; @@ -1110,7 +1117,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; @@ -1119,6 +1135,10 @@ int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp, restore_open_flags); if (rc < 0) goto err_out; + } 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); @@ -1127,6 +1147,7 @@ int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp, goto err_out; } +out_log: llapi_hsm_log_ct_progress(&hcp, hai, CT_START, 0, 0); ok_out: @@ -1135,6 +1156,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); @@ -1180,13 +1204,14 @@ int llapi_hsm_action_end(struct hsm_copyaction_private **phcp, .lfu_ctime_nsec = hcp->stat.st_ctim.tv_nsec, }; - /* Set {a,m,c}time of volatile file to that of original. */ - if (ioctl(hcp->data_fd, LL_IOC_FUTIMES_3, &lfu) < 0) { + rc = fsync(hcp->data_fd); + if (rc < 0) { errval = -errno; goto end; } - rc = fsync(hcp->data_fd); + /* Set {a,m,c}time of volatile file to that of original. */ + rc = ioctl(hcp->data_fd, LL_IOC_FUTIMES_3, &lfu); if (rc < 0) { errval = -errno; goto end; @@ -1215,6 +1240,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); @@ -1269,7 +1297,7 @@ int llapi_hsm_action_progress(struct hsm_copyaction_private *hcp, * @return error code if the action is not a copy operation. */ int llapi_hsm_action_get_dfid(const struct hsm_copyaction_private *hcp, - lustre_fid *fid) + struct lu_fid *fid) { const struct hsm_action_item *hai = &hcp->copy.hc_hai; @@ -1300,8 +1328,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; @@ -1326,7 +1354,7 @@ int llapi_hsm_action_get_fd(const struct hsm_copyaction_private *hcp) int llapi_hsm_import(const char *dst, int archive, const struct stat *st, unsigned long long stripe_size, int stripe_offset, int stripe_count, int stripe_pattern, char *pool_name, - lustre_fid *newfid) + struct lu_fid *newfid) { struct hsm_user_import hui; int fd;