Whamcloud - gitweb
LU-7482 tests: fix uninitialized value in llapi_hsm_test
[fs/lustre-release.git] / lustre / tests / llapi_hsm_test.c
index 397dc8c..1d90e60 100644 (file)
  * GPL HEADER END
  */
 
-/* Copyright 2014, 2015 Cray Inc, all rights reserved. */
+/*
+ * Copyright 2014, 2015 Cray Inc, all rights reserved.
+ *
+ * Copyright (c) 2015, Intel Corporation.
+ */
 /* Some portions are extracted from llapi_layout_test.c */
 
 /* The purpose of this test is to check some HSM functions. HSM must
  * be enabled before running it:
- *   echo enabled > /proc/fs/lustre/mdt/lustre-MDT0000/hsm_control
+ *   lctl set_param mdt.$FSNAME-MDT0000.hsm_control=enabled
  */
 
 /* All tests return 0 on success and non zero on error. The program will
@@ -373,53 +377,94 @@ void test51(void)
                        hus.hus_archive_id, i);
        }
 
-       /* Bugs following. This should not succeed. Builds the following file:
-        *
-        *   $ ../utils/lfs hsm_state /mnt/lustre/hsm_check_test
-        *
-        *   /mnt/lustre/hsm_check_test: (0x8008007d) released exists
-        *     archived never_release never_archive lost_from_hsm,
-        *     archive_id:-1789
-        */
-
        /* Invalid archive numbers */
        rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, 33);
-       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc));
 
        rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, 151);
-       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc));
 
        rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, -1789);
-       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc));
 
-       /* Setable + Unsettable flags */
+       /* Settable flags, with respect of the HSM file state transition rules:
+        *      DIRTY without EXISTS: no dirty if no archive was created
+        *      DIRTY and RELEASED: a dirty file could not be released
+        *      RELEASED without ARCHIVED: do not release a non-archived file
+        *      LOST without ARCHIVED: cannot lost a non-archived file.
+        */
        rc = llapi_hsm_state_set_fd(fd, HS_DIRTY, 0, 0);
        ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
 
+       rc = llapi_hsm_state_set_fd(fd, 0, HS_EXISTS, 0);
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
+               strerror(-rc));
+
        rc = llapi_hsm_state_set_fd(fd, 0, HS_DIRTY, 0);
        ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
 
+       rc = llapi_hsm_state_set_fd(fd, 0, HS_EXISTS, 0);
+       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+
+       rc = llapi_hsm_state_set_fd(fd, HS_DIRTY, 0, 0);
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
+               strerror(-rc));
+
+       rc = llapi_hsm_state_set_fd(fd, HS_RELEASED, 0, 0);
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
+               strerror(-rc));
+
+       rc = llapi_hsm_state_set_fd(fd, HS_LOST, 0, 0);
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
+               strerror(-rc));
+
        rc = llapi_hsm_state_set_fd(fd, HS_ARCHIVED, 0, 0);
        ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
 
        rc = llapi_hsm_state_set_fd(fd, HS_RELEASED, 0, 0);
        ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
 
+       rc = llapi_hsm_state_set_fd(fd, HS_LOST, 0, 0);
+       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+
+       rc = llapi_hsm_state_set_fd(fd, HS_DIRTY|HS_EXISTS, 0, 0);
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
+               strerror(-rc));
+
+       rc = llapi_hsm_state_set_fd(fd, 0, HS_RELEASED, 0);
+       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+
+       rc = llapi_hsm_state_set_fd(fd, HS_DIRTY|HS_EXISTS, 0, 0);
+       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+
+       rc = llapi_hsm_state_set_fd(fd, 0, HS_ARCHIVED, 0);
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
+               strerror(-rc));
+
+       rc = llapi_hsm_state_set_fd(fd, 0, HS_LOST, 0);
+       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+
+       rc = llapi_hsm_state_set_fd(fd, 0, HS_ARCHIVED, 0);
+       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+
        rc = llapi_hsm_state_set_fd(fd, HS_NORELEASE, 0, 0);
        ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
 
+       rc = llapi_hsm_state_set_fd(fd, 0, HS_NORELEASE, 0);
+       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+
        rc = llapi_hsm_state_set_fd(fd, HS_NOARCHIVE, 0, 0);
        ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
 
-       rc = llapi_hsm_state_set_fd(fd, HS_LOST, 0, 0);
+       rc = llapi_hsm_state_set_fd(fd, 0, HS_NOARCHIVE, 0);
        ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
 
        /* Bogus flags for good measure. */
        rc = llapi_hsm_state_set_fd(fd, 0x00080000, 0, 0);
-       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc));
 
        rc = llapi_hsm_state_set_fd(fd, 0x80000000, 0, 0);
-       ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
+       ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc));
 
        close(fd);
 }
@@ -477,6 +522,7 @@ void helper_archiving(void (*progress)
        hur->hur_request.hr_flags = 0;
        hur->hur_request.hr_itemcount = 1;
        hur->hur_request.hr_data_len = 0;
+       hur->hur_user_item[0].hui_extent.offset = 0;
        hur->hur_user_item[0].hui_extent.length = -1;
 
        rc = llapi_fd2fid(fd, &hur->hur_user_item[0].hui_fid);
@@ -983,7 +1029,7 @@ static void process_args(int argc, char *argv[])
 
 int main(int argc, char *argv[])
 {
-       char fsname[8];
+       char fsname[8 + 1];
        int rc;
 
        process_args(argc, argv);