Whamcloud - gitweb
LU-10256 hsm: enable setting archive_id in hsm_set 50/30150/5
authorThomas Stibor <t.stibor@gsi.de>
Fri, 17 Nov 2017 14:31:39 +0000 (15:31 +0100)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 1 Dec 2017 05:16:46 +0000 (05:16 +0000)
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 <t.stibor@gsi.de>
Change-Id: I2145a18ecf32479527bb045140e5e881e58dd115
Reviewed-on: https://review.whamcloud.com/30150
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Stephan Thiell <sthiell@stanford.edu>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/doc/lfs-hsm.1
lustre/tests/sanity-hsm.sh
lustre/utils/lfs.c

index dc18373..8ac85f6 100644 (file)
@@ -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 <FILE> ...
 .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:
index 5ddc833..fcca8fe 100755 (executable)
@@ -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
 
index dac8589..912b833 100644 (file)
@@ -334,7 +334,7 @@ command_t cmdlist[] = {
         "undergoing actions) for given files.\n usage: hsm_state <file> ..."},
        {"hsm_set", lfs_hsm_set, 0, "Set HSM user flag on specified files.\n"
         "usage: hsm_set [--norelease] [--noarchive] [--dirty] [--exists] "
-        "[--archived] [--lost] <file> ..."},
+        "[--archived] [--lost] [--archive-id NUM] <file> ..."},
        {"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);