X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Futils%2Fliblustreapi_hsm.c;h=5d089498aec0ed6f7f2401f1f614ac894f3dd44f;hp=695c0bcbf3f2b1c5b3411f84099268439112cbe2;hb=d39b08def6512ee6ae883a0db62cebd808646208;hpb=3c0b5e5a734da58e86bf46dffda9913ba4932d13 diff --git a/lustre/utils/liblustreapi_hsm.c b/lustre/utils/liblustreapi_hsm.c index 695c0bc..5d08949 100644 --- a/lustre/utils/liblustreapi_hsm.c +++ b/lustre/utils/liblustreapi_hsm.c @@ -397,52 +397,57 @@ int llapi_hsm_progress(char *mnt, struct hsm_progress *hp) * be used. * \param newfid[out] Filled with new Lustre fid. */ -int llapi_hsm_import(const char *dst, int archive, struct stat *st, +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 utimbuf time; - int fd; - int rc = 0; + struct hsm_user_import hui; + int fd; + int rc = 0; - /* Create a non-striped file */ - fd = open(dst, O_CREAT | O_EXCL | O_LOV_DELAY_CREATE | O_NONBLOCK, - st->st_mode); + if (stripe_pattern == 0) + stripe_pattern = LOV_PATTERN_RAID0; - if (fd < 0) + /* Create a non-striped file */ + fd = llapi_file_open_pool(dst, O_CREAT | O_WRONLY, st->st_mode, + stripe_size, stripe_offset, stripe_count, + stripe_pattern | LOV_PATTERN_F_RELEASED, + pool_name); + if (fd < 0) { + llapi_error(LLAPI_MSG_ERROR, -errno, + "cannot create '%s' for import", dst); return -errno; - close(fd); - - /* set size on MDT */ - if (truncate(dst, st->st_size) != 0) { - rc = -errno; - goto out_unlink; } - /* Mark archived */ - rc = llapi_hsm_state_set(dst, HS_EXISTS | HS_RELEASED | HS_ARCHIVED, 0, - archive); - if (rc) - goto out_unlink; - /* Get the new fid in the archive. Caller needs to use this fid + /* Get the new fid in Lustre. Caller needs to use this fid from now on. */ - rc = llapi_path2fid(dst, newfid); - if (rc) + rc = llapi_fd2fid(fd, newfid); + if (rc != 0) { + llapi_error(LLAPI_MSG_ERROR, rc, + "cannot get fid of '%s' for import", dst); goto out_unlink; + } - /* Copy the file attributes */ - time.actime = st->st_atime; - time.modtime = st->st_mtime; - if (utime(dst, &time) == -1 || - chmod(dst, st->st_mode) == -1 || - chown(dst, st->st_uid, st->st_gid) == -1) { - /* we might fail here because we change perms/owner */ + hui.hui_uid = st->st_uid; + hui.hui_gid = st->st_gid; + hui.hui_mode = st->st_mode; + hui.hui_size = st->st_size; + hui.hui_archive_id = archive; + hui.hui_atime = st->st_atime; + hui.hui_atime_ns = st->st_atim.tv_nsec; + hui.hui_mtime = st->st_mtime; + hui.hui_mtime_ns = st->st_mtim.tv_nsec; + rc = ioctl(fd, LL_IOC_HSM_IMPORT, &hui); + if (rc != 0) { + llapi_error(LLAPI_MSG_ERROR, rc, "cannot import '%s'", dst); rc = -errno; goto out_unlink; } out_unlink: + if (fd >= 0) + close(fd); if (rc) unlink(dst); return rc; @@ -458,6 +463,23 @@ out_unlink: * \retval 0 on success. * \retval -errno on error. */ +int llapi_hsm_state_get_fd(int fd, struct hsm_user_state *hus) +{ + int rc; + + rc = ioctl(fd, LL_IOC_HSM_STATE_GET, hus); + /* If error, save errno value */ + rc = rc ? -errno : 0; + + return rc; +} + +/** + * Return the current HSM states and HSM requests related to file pointed by \a + * path. + * + * see llapi_hsm_state_get_fd() for args use and return + */ int llapi_hsm_state_get(const char *path, struct hsm_user_state *hus) { int fd; @@ -467,16 +489,14 @@ int llapi_hsm_state_get(const char *path, struct hsm_user_state *hus) if (fd < 0) return -errno; - rc = ioctl(fd, LL_IOC_HSM_STATE_GET, hus); - /* If error, save errno value */ - rc = rc ? -errno : 0; + rc = llapi_hsm_state_get_fd(fd, hus); close(fd); return rc; } /** - * Set HSM states of file pointed by \a path. + * Set HSM states of file pointed by \a fd * * Using the provided bitmasks, the current HSM states for this file will be * changed. \a archive_id could be used to change the archive number also. Set @@ -489,16 +509,11 @@ int llapi_hsm_state_get(const char *path, struct hsm_user_state *hus) * \retval 0 on success. * \retval -errno on error. */ -int llapi_hsm_state_set(const char *path, __u64 setmask, __u64 clearmask, - __u32 archive_id) +int llapi_hsm_state_set_fd(int fd, __u64 setmask, __u64 clearmask, + __u32 archive_id) { - struct hsm_state_set hss; - int fd; - int rc; - - fd = open(path, O_WRONLY | O_LOV_DELAY_CREATE | O_NONBLOCK); - if (fd < 0) - return -errno; + struct hsm_state_set hss; + int rc; hss.hss_valid = HSS_SETMASK|HSS_CLEARMASK; hss.hss_setmask = setmask; @@ -513,10 +528,29 @@ int llapi_hsm_state_set(const char *path, __u64 setmask, __u64 clearmask, /* If error, save errno value */ rc = rc ? -errno : 0; - close(fd); return rc; } +/** + * Set HSM states of file pointed by \a path. + * + * see llapi_hsm_state_set_fd() for args use and return + */ +int llapi_hsm_state_set(const char *path, __u64 setmask, __u64 clearmask, + __u32 archive_id) +{ + int fd; + int rc; + + fd = open(path, O_WRONLY | O_LOV_DELAY_CREATE | O_NONBLOCK); + if (fd < 0) + return -errno; + + rc = llapi_hsm_state_set_fd(fd, setmask, clearmask, archive_id); + + close(fd); + return rc; +} /** * Return the current HSM request related to file pointed by \a path.