From d1855f8e22a929066a69470c7e3d082c70478575 Mon Sep 17 00:00:00 2001 From: Thomas Stibor Date: Fri, 17 Nov 2017 15:31:39 +0100 Subject: [PATCH] LU-10256 hsm: enable setting archive_id in hsm_set Setting HSM flags in lfs_hsm_change_flags(...,LFS_HSM_SET) does not allow to specify the archive_id, that is, in llapi_hsm_state_set(path, mask, 0, 0 /* archive_id */) archive_id = 0 is always set, which means no identifier change. For having full flexibility (e.g. for debugging), introduce the additional option --archive-id in hsm_set. If the option is not provided, the default behavior (archive_id = 0) is used and no archive identifier change is done. In addition a test case is provided to check the functionality and shell function get_hsm_archive_id() is modified in favor of more robust grep for contents after pattern approach. Test-Parameters: trivial testlist=sanity-hsm Signed-off-by: Thomas Stibor Change-Id: I2145a18ecf32479527bb045140e5e881e58dd115 Reviewed-on: https://review.whamcloud.com/30150 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Stephan Thiell Reviewed-by: Oleg Drokin --- lustre/doc/lfs-hsm.1 | 6 +++++- lustre/tests/sanity-hsm.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++-- lustre/utils/lfs.c | 17 ++++++++++++++--- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/lustre/doc/lfs-hsm.1 b/lustre/doc/lfs-hsm.1 index dc18373..8ac85f6 100644 --- a/lustre/doc/lfs-hsm.1 +++ b/lustre/doc/lfs-hsm.1 @@ -1,4 +1,4 @@ -.TH lfs-hsm 1 "November 9, 2012" Lustre "Lustre/HSM binding utility" +.TH lfs-hsm 1 "November 20, 2017" Lustre "Lustre/HSM binding utility" .SH NAME .Blfs hsm_command lfs commands used to interact with HSM features @@ -16,6 +16,7 @@ lfs commands used to interact with HSM features .RB [ --exists ] .RB [ --archived ] .RB [ --lost ] +.RB [ --archive-id ] .RB ... .br .SH DESCRIPTION @@ -59,6 +60,9 @@ An up-to-date file copy exists in HSM backend. Useful mostly for debugging. (roo .TP .B \\--lost File copy in HSM backend is not usable anymore and file could not be restored. It should be archived again. (root only) +.TP +.B \\--archive-id +Set archive number identifier in hsm_set command. If archive-id is 0 or option is not provided, then default identifier 0 is used and means no identifier change. .SH EXAMPLES .TP .B Display current HSM flag for foo: diff --git a/lustre/tests/sanity-hsm.sh b/lustre/tests/sanity-hsm.sh index 5ddc833d..fcca8fe 100755 --- a/lustre/tests/sanity-hsm.sh +++ b/lustre/tests/sanity-hsm.sh @@ -678,8 +678,7 @@ get_hsm_archive_id() { st=$($LFS hsm_state $f) [[ $? == 0 ]] || error "$LFS hsm_state $f failed" - local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " | - cut -f2 -d:) + local ar=$(echo $st | grep -oP '(?<=archive_id:).*') echo $ar } @@ -993,6 +992,50 @@ test_1b() { } run_test 1b "Archive, Release & Restore composite file" +test_1c() { + mkdir -p $DIR/$tdir + chmod 777 $DIR/$tdir + + local f=$DIR/$tdir/$tfile + $RUNAS touch $f + + # Test whether we can set the maximum archive number. + local LOCAL_HSM_ARCHIVE_NUMBER=32 + $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f || + error "root could not change hsm flags" + check_hsm_flags_user $f "0x00000001" + echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER" + local st=$(get_hsm_archive_id $f) + [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] || + error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER" + + # Test whether setting archive number 0 results in no change. + $LFS hsm_set --exists --archive-id 0 $f || + error "root could not change hsm flags" + check_hsm_flags_user $f "0x00000001" + echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER" + st=$(get_hsm_archive_id $f) + [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] || + error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER" + + # Test whether setting archive number > 32 results in error. + $LFS hsm_set --exists --archive-id 33 $f && + error "archive number is larger than 32" + check_hsm_flags_user $f "0x00000001" + + # Test whether setting archive number 16 and archived flag. + LOCAL_HSM_ARCHIVE_NUMBER=16 + $LFS hsm_set --exists --archived \ + --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f || + error "root could not change hsm flags" + check_hsm_flags_user $f "0x00000009" + echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER" + st=$(get_hsm_archive_id $f) + [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] || + error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER" +} +run_test 1c "Check setting archive-id in lfs hsm_set" + test_2() { local f=$DIR/$tdir/$tfile diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index dac8589..912b833 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -334,7 +334,7 @@ command_t cmdlist[] = { "undergoing actions) for given files.\n usage: hsm_state ..."}, {"hsm_set", lfs_hsm_set, 0, "Set HSM user flag on specified files.\n" "usage: hsm_set [--norelease] [--noarchive] [--dirty] [--exists] " - "[--archived] [--lost] ..."}, + "[--archived] [--lost] [--archive-id NUM] ..."}, {"hsm_clear", lfs_hsm_clear, 0, "Clear HSM user flag on specified " "files.\n" "usage: hsm_clear [--norelease] [--noarchive] [--dirty] [--exists] " @@ -4858,11 +4858,14 @@ static int lfs_hsm_change_flags(int argc, char **argv, int mode) { .val = 'e', .name = "exists", .has_arg = no_argument }, { .val = 'l', .name = "lost", .has_arg = no_argument }, { .val = 'r', .name = "norelease", .has_arg = no_argument }, + { .val = 'i', .name = "archive-id", .has_arg = required_argument }, { .name = NULL } }; - char short_opts[] = "lraAde"; + char short_opts[] = "lraAdei:"; __u64 mask = 0; int c, rc; char *path; + __u32 archive_id = 0; + char *end = NULL; if (argc < 3) return CMD_HELP; @@ -4888,6 +4891,14 @@ static int lfs_hsm_change_flags(int argc, char **argv, int mode) case 'e': mask |= HS_EXISTS; break; + case 'i': + archive_id = strtol(optarg, &end, 10); + if (*end != '\0') { + fprintf(stderr, "invalid archive_id: '%s'\n", + end); + return CMD_HELP; + } + break; case '?': return CMD_HELP; default: @@ -4907,7 +4918,7 @@ static int lfs_hsm_change_flags(int argc, char **argv, int mode) /* If mode == 0, this means we apply the mask. */ if (mode == LFS_HSM_SET) - rc = llapi_hsm_state_set(path, mask, 0, 0); + rc = llapi_hsm_state_set(path, mask, 0, archive_id); else rc = llapi_hsm_state_set(path, 0, mask, 0); -- 1.8.3.1