Whamcloud - gitweb
LU-12458 kernel: kernel update RHEL7.6 [3.10.0-957.21.3.el7]
[fs/lustre-release.git] / lustre / tests / llapi_layout_test.c
index d5258a9..3352fa5 100644 (file)
@@ -20,6 +20,9 @@
  * GPL HEADER END
  */
 /*
+ * Copyright (c) 2016, 2017, Intel Corporation.
+ */
+/*
  * These tests exercise the llapi_layout API which abstracts the layout
  * of a Lustre file behind an opaque data type.  They assume a Lustre
  * file system with at least 2 OSTs and a pool containing at least the
@@ -46,6 +49,7 @@
 #include <sys/stat.h>
 #include <getopt.h>
 #include <inttypes.h>
+#include <sys/ioctl.h>
 
 #define ERROR(fmt, ...)                                                        \
        fprintf(stderr, "%s: %s:%d: %s: " fmt "\n",                     \
@@ -200,7 +204,7 @@ void test3(void)
 {
        int rc;
        struct llapi_layout *layout;
-       lustre_fid fid;
+       struct lu_fid fid;
        char fidstr[4096];
        char path[PATH_MAX];
 
@@ -231,7 +235,7 @@ void test4(void)
        uint64_t size;
        const char *lfs = getenv("LFS");
        char mypool[LOV_MAXPOOLNAME + 1] = { '\0' };
-       char cmd[4096];
+       char cmd[PATH_MAX + 128];
        char path[PATH_MAX];
 
        snprintf(path, sizeof(path), "%s/%s", lustre_dir, T4FILE);
@@ -1080,7 +1084,7 @@ void test26(void)
        uint64_t size;
        uint64_t pattern;
        char dir[PATH_MAX];
-       char cmd[4096];
+       char cmd[PATH_MAX + 64];
 
        snprintf(dir, sizeof(dir), "%s/%s", lustre_dir, T26DIR);
        rc = rmdir(dir);
@@ -1127,11 +1131,11 @@ void test27(void)
        uint64_t count;
        uint64_t size;
        uint64_t pattern;
-       char dirpath[PATH_MAX];
-       char filepath[PATH_MAX];
-       char cmd[4096];
+       char dirpath[PATH_MAX + 128];
+       char filepath[PATH_MAX * 2];
+       char cmd[PATH_MAX * 2];
 
-       snprintf(dirpath, sizeof(dirpath), "%s/%s", lustre_dir, T27DIR);
+       snprintf(dirpath, sizeof(dirpath) - 1, "%s/%s", lustre_dir, T27DIR);
        snprintf(filepath, sizeof(filepath), "%s/nonesuch", dirpath);
 
        rc = rmdir(dirpath);
@@ -1176,7 +1180,7 @@ void test28(void)
        const char *lfs = getenv("LFS");
        uint64_t count;
        char dirpath[PATH_MAX];
-       char cmd[4096];
+       char cmd[PATH_MAX + 64];
 
        snprintf(dirpath, sizeof(dirpath), "%s/%s", lustre_dir, T28DIR);
 
@@ -1526,7 +1530,99 @@ void test31(void)
                "s: %"PRIu64", e: %"PRIu64"", s, e);
 }
 
-#define TEST_DESC_LEN  50
+#define T32FILE                        "t32"
+#define T32_STRIPE_COUNT       (num_osts*2)
+#define T32_DESC               "Test overstriping with layout_file_create"
+void test32(void)
+{
+       int rc;
+       int fd;
+       uint64_t count;
+       struct llapi_layout *layout = llapi_layout_alloc();
+       void *lmdbuf = NULL;
+       struct lov_user_md *lmd;
+       char path[PATH_MAX];
+
+       ASSERTF(layout != NULL, "errno %d", errno);
+
+       /* Maximum possible, to be on the safe side - num_osts could be large */
+       lmdbuf = malloc(XATTR_SIZE_MAX);
+       ASSERTF(lmdbuf != NULL, "errno %d", errno);
+       lmd = lmdbuf;
+
+       snprintf(path, sizeof(path), "%s/%s", lustre_dir, T32FILE);
+
+       rc = unlink(path);
+       ASSERTF(rc >= 0 || errno == ENOENT, "errno = %d", errno);
+
+       /* stripe count */
+       rc = llapi_layout_stripe_count_set(layout, T32_STRIPE_COUNT);
+       ASSERTF(rc == 0, "errno = %d", errno);
+       rc = llapi_layout_stripe_count_get(layout, &count);
+       ASSERTF(rc == 0 && count == T32_STRIPE_COUNT, "%"PRIu64" != %d", count,
+               T32_STRIPE_COUNT);
+
+       rc = llapi_layout_pattern_set(layout, LLAPI_LAYOUT_OVERSTRIPING);
+       ASSERTF(rc == 0, "errno = %d", errno);
+
+       /* create */
+       fd = llapi_layout_file_create(path, 0, 0660, layout);
+       ASSERTF(fd >= 0, "path = %s, errno = %d", path, errno);
+
+       rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE_NEW, lmdbuf);
+       ASSERTF(rc == 0, "errno = %d", errno);
+
+       count = lmd->lmm_stripe_count;
+       ASSERTF(count == T32_STRIPE_COUNT,
+               "stripe count (%"PRIu64") not equal to expected (%d)",
+               count, T32_STRIPE_COUNT);
+
+       rc = close(fd);
+       ASSERTF(rc == 0, "errno = %d", errno);
+       llapi_layout_free(layout);
+       free(lmdbuf);
+}
+
+#define T33FILE                        "t33"
+#define T33_STRIPE_COUNT       (num_osts*2)
+#define T33_DESC               "Test overstriping with llapi_file_open"
+void test33(void)
+{
+       int rc;
+       int fd;
+       uint64_t count;
+       void *lmdbuf = NULL;
+       struct lov_user_md *lmd;
+       char path[PATH_MAX];
+
+       /* Maximum possible, to be on the safe side - num_osts could be large */
+       lmdbuf = malloc(XATTR_SIZE_MAX);
+       ASSERTF(lmdbuf != NULL, "errno %d", errno);
+       lmd = lmdbuf;
+
+       snprintf(path, sizeof(path), "%s/%s", lustre_dir, T33FILE);
+
+       rc = unlink(path);
+       ASSERTF(rc >= 0 || errno == ENOENT, "errno = %d", errno);
+
+       fd = llapi_file_open(path, O_CREAT | O_RDWR, 0660, 0, -1, num_osts*2,
+                            LOV_PATTERN_RAID0 | LOV_PATTERN_OVERSTRIPING);
+       ASSERTF(fd >= 0, "path = %s, errno = %d", path, errno);
+
+       rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE_NEW, lmdbuf);
+       ASSERTF(rc == 0, "errno = %d", errno);
+
+       count = lmd->lmm_stripe_count;
+       ASSERTF(count == T33_STRIPE_COUNT,
+               "stripe count (%"PRIu64") not equal to expected (%d)",
+               count, T33_STRIPE_COUNT);
+
+       rc = close(fd);
+       ASSERTF(rc == 0, "errno = %d", errno);
+       free(lmdbuf);
+}
+
+#define TEST_DESC_LEN  80
 struct test_tbl_entry {
        void (*tte_fn)(void);
        char tte_desc[TEST_DESC_LEN];
@@ -1566,6 +1662,8 @@ static struct test_tbl_entry test_tbl[] = {
        { .tte_fn = &test29, .tte_desc = T29_DESC, .tte_skip = false },
        { .tte_fn = &test30, .tte_desc = T30_DESC, .tte_skip = false },
        { .tte_fn = &test31, .tte_desc = T31_DESC, .tte_skip = false },
+       { .tte_fn = &test32, .tte_desc = T32_DESC, .tte_skip = false },
+       { .tte_fn = &test33, .tte_desc = T33_DESC, .tte_skip = false },
 };
 
 #define NUM_TESTS      (sizeof(test_tbl) / sizeof(struct test_tbl_entry))
@@ -1710,5 +1808,6 @@ int main(int argc, char *argv[])
                if (test(tst->tte_fn, tst->tte_desc, tst->tte_skip, i) != 0)
                        rc++;
        }
+
        return rc;
 }