From: Henri Doreau Date: Fri, 31 Jan 2014 08:51:12 +0000 (+0100) Subject: LU-4569 hsm: Specify import source by FID. X-Git-Tag: 2.5.59~82 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=a847e69c3b3853f547f99fcbb9c77259c4f3aa05 LU-4569 hsm: Specify import source by FID. Make the posix CT also accept a FID as import source parameter (from which the path can be rebuilt) to allow easy "undeletion" of archived files: lhsmtool_posix --import /mnt/lustre/undelete ... This patch also fixes a typo and replaces a bulky path construction by a single asprintf() statement. Signed-off-by: Henri Doreau Change-Id: Id6d92bea59a6cae628c2b3e5449d8dad3b06a364 Reviewed-on: http://review.whamcloud.com/9075 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Faccini Bruno Reviewed-by: John L. Hammond Reviewed-by: Oleg Drokin --- diff --git a/lustre/tests/sanity-hsm.sh b/lustre/tests/sanity-hsm.sh index 0e4735f..94d1368 100755 --- a/lustre/tests/sanity-hsm.sh +++ b/lustre/tests/sanity-hsm.sh @@ -983,7 +983,7 @@ test_10d() { } run_test 10d "Archive a file on the default archive id" -test_11() { +test_11a() { mkdir -p $DIR/$tdir copy2archive /etc/hosts $tdir/$tfile local f=$DIR/$tdir/$tfile @@ -1007,7 +1007,31 @@ test_11() { local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) || error "fid $fid not in archive $HSM_ARCHIVE" } -run_test 11 "Import a file" +run_test 11a "Import a file" + +test_11b() { + # test needs a running copytool + copytool_setup + + mkdir -p $DIR/$tdir + local f=$DIR/$tdir/$tfile + local fid=$(copy_file /etc/hosts $f) + $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f || + error "hsm_archive failed" + wait_request_state $fid ARCHIVE SUCCEED + + local FILE_HASH=$(md5sum $f) + rm -f $f + + import_file $fid $f + + echo "$FILE_HASH" | md5sum -c + + [[ $? -eq 0 ]] || error "Restored file differs" + + copytool_cleanup +} +run_test 11b "Import a deleted file using its FID" test_12a() { # test needs a running copytool diff --git a/lustre/utils/lhsmtool_posix.c b/lustre/utils/lhsmtool_posix.c index 36fe50f..91ec7b5 100644 --- a/lustre/utils/lhsmtool_posix.c +++ b/lustre/utils/lhsmtool_posix.c @@ -32,6 +32,11 @@ * * This particular tool can also import an existing HSM archive. */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include #include #include #include @@ -153,9 +158,10 @@ static void usage(const char *name, int rc) "into a Lustre filesystem.\n" " Usage:\n" " %s [options] --import \n" - " import an archived subtree at\n" - " (relative to hsm_root) into the Lustre filesystem at\n" - " (absolute)\n" + " import an archived subtree from\n" + " (FID or relative path to hsm_root) into the Lustre\n" + " filesystem at\n" + " (absolute path)\n" " %s [options] --rebind \n" " rebind an entry in the HSM to a new FID\n" " old FID the HSM entry is bound to\n" @@ -1375,29 +1381,43 @@ static int ct_import_one(const char *src, const char *dst) static char *path_concat(const char *dirname, const char *basename) { char *result; - int dirlen = strlen(dirname); + int rc; - result = malloc(dirlen + strlen(basename) + 2); - if (result == NULL) + rc = asprintf(&result, "%s/%s", dirname, basename); + if (rc < 0) return NULL; - memcpy(result, dirname, dirlen); - result[dirlen] = '/'; - strcpy(result + dirlen + 1, basename); - return result; } +static int ct_import_fid(const lustre_fid *import_fid) +{ + char fid_path[PATH_MAX]; + + ct_path_archive(fid_path, sizeof(fid_path), opt.o_hsm_root, + import_fid); + CT_TRACE("Resolving "DFID" to %s", PFID(import_fid), fid_path); + + return ct_import_one(fid_path, opt.o_dst); +} + static int ct_import_recurse(const char *relpath) { DIR *dir; struct dirent ent, *cookie = NULL; char *srcpath, *newpath; + lustre_fid import_fid; int rc; if (relpath == NULL) return -EINVAL; + /* Is relpath a FID? In which case SFID should expand to three + * elements. */ + rc = sscanf(relpath, SFID, RFID(&import_fid)); + if (rc == 3) + return ct_import_fid(&import_fid); + srcpath = path_concat(opt.o_hsm_root, relpath); if (srcpath == NULL) { err_major++; @@ -1502,7 +1522,7 @@ static int ct_rebind_one(const lustre_fid *old_fid, const lustre_fid *new_fid) strncat(src, ".lov", sizeof(src) - strlen(src) - 1); strncat(dst, ".lov", sizeof(dst) - strlen(dst) - 1); if (rename(src, dst)) - CT_ERROR(errno, "cannot '%s' rename to '%s'", src, dst); + CT_ERROR(errno, "cannot rename '%s' to '%s'", src, dst); } return 0;