void usage(char *prog)
{
- printf("Usage: %s [-d lustre_dir] [-p pool_name] [-o num_osts]\n",
- prog);
+ printf("Usage: %s [-d lustre_dir] [-p pool_name] [-o num_osts] "
+ "[-s $n,$m,..]\n", prog);
exit(0);
}
llapi_layout_free(layout);
}
-
#define T2_DESC "Read test0 file by FD and verify attributes"
void test2(void)
{
llapi_layout_free(layout);
}
-
#define T4FILE "t4"
#define T4_STRIPE_COUNT 2
#define T4_STRIPE_SIZE 2097152
ASSERTF(layout == NULL && errno == EBADF, "errno = %d", errno);
}
-
#define T7FILE "t7"
#define T7_DESC "llapi_layout_get_by_path EACCES handling"
void test7(void)
ASSERTF(rc == 0, "errno = %d", errno);
}
-
/* llapi_layout_get_by_path() returns default layout for file with no
* striping attributes. */
#define T8FILE "t8"
llapi_layout_free(layout);
}
-/* Setting pattern > 0 returns EOPNOTSUPP in errno. */
-#define T9_DESC "llapi_layout_pattern_set() EOPNOTSUPP handling"
+/* Verify llapi_layout_patter_set() return values for various inputs. */
+#define T9_DESC "verify llapi_layout_pattern_set() return values"
void test9(void)
{
struct llapi_layout *layout;
layout = llapi_layout_alloc();
ASSERTF(layout != NULL, "errno = %d\n", errno);
+
errno = 0;
- rc = llapi_layout_pattern_set(layout, 1);
+ rc = llapi_layout_pattern_set(layout, LLAPI_LAYOUT_INVALID);
ASSERTF(rc == -1 && errno == EOPNOTSUPP, "rc = %d, errno = %d", rc,
errno);
+
+ errno = 0;
+ rc = llapi_layout_pattern_set(NULL, LLAPI_LAYOUT_DEFAULT);
+ ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc,
+ errno);
+
+ errno = 0;
+ rc = llapi_layout_pattern_set(layout, LLAPI_LAYOUT_DEFAULT);
+ ASSERTF(rc == 0, "rc = %d, errno = %d", rc, errno);
+
+ errno = 0;
+ rc = llapi_layout_pattern_set(layout, LLAPI_LAYOUT_RAID0);
+ ASSERTF(rc == 0, "rc = %d, errno = %d", rc, errno);
+
llapi_layout_free(layout);
}
-
/* Verify stripe_count interfaces return errors as expected */
#define T10_DESC "stripe_count error handling"
void test10(void)
/* Pool name too long*/
errno = 0;
- rc = llapi_layout_pool_name_set(layout, "0123456789abcdef0");
+ rc = llapi_layout_pool_name_set(layout, "0123456789abcdef");
ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc, errno);
llapi_layout_free(layout);
layout = llapi_layout_alloc();
ASSERTF(layout != NULL, "errno = %d", errno);
- /* Only setting OST index for stripe 0 is supported for now. */
- errno = 0;
- rc = llapi_layout_ost_index_set(layout, 1, 1);
- ASSERTF(rc == -1 && errno == EOPNOTSUPP, "rc = %d, errno = %d",
- rc, errno);
-
/* invalid OST index */
errno = 0;
rc = llapi_layout_ost_index_set(layout, 0, LLAPI_LAYOUT_INVALID);
void test19(void)
{
struct llapi_layout *layout;
- char *name = "0123456789abcdef";
+ char *name = "0123456789abcde";
char mypool[LOV_MAXPOOLNAME + 1] = { '\0' };
int rc;
llapi_layout_free(layout);
}
+#define T29FILE "f29"
+#define T29_DESC "set ost index to non-zero stripe number"
+void test29(void)
+{
+ int rc, fd, i;
+ uint64_t ost0, ost1, nost;
+ struct llapi_layout *layout;
+ char path[PATH_MAX];
+
+ if (num_osts < 2)
+ return;
+
+ layout = llapi_layout_alloc();
+ ASSERTF(layout != NULL, "errno %d", errno);
+
+ snprintf(path, sizeof(path), "%s/%s", lustre_dir, T29FILE);
+
+ rc = unlink(path);
+ ASSERTF(rc >= 0 || errno == ENOENT, "errno = %d", errno);
+
+ /* set ost index to LLAPI_LAYOUT_IDX_MAX should fail */
+ rc = llapi_layout_ost_index_set(layout, 1, LLAPI_LAYOUT_IDX_MAX);
+ ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d\n",
+ rc, errno);
+
+ /* specify ost index partially */
+ rc = llapi_layout_ost_index_set(layout, 1, 0);
+ ASSERTF(rc == 0, "errno = %d", errno);
+
+ /* create a partially specified layout will fail */
+ fd = llapi_layout_file_create(path, 0, 0660, layout);
+ ASSERTF(fd == -1 && errno == EINVAL, "path = %s, fd = %d, errno = %d",
+ path, fd, errno);
+
+ rc = unlink(path);
+ ASSERTF(rc >= 0 || errno == ENOENT, "errno = %d", errno);
+
+ /* specify all stripes */
+ rc = llapi_layout_ost_index_set(layout, 0, 1);
+ ASSERTF(rc == 0, "errno = %d", errno);
+
+ /* create */
+ fd = llapi_layout_file_create(path, 0, 0660, layout);
+ ASSERTF(fd >= 0, "path = %s, fd = %d, errno = %d", path, fd, errno);
+
+ rc = close(fd);
+ ASSERTF(rc == 0, "errno = %d", errno);
+ llapi_layout_free(layout);
+
+ /* get layout from file */
+ layout = llapi_layout_get_by_path(path, 0);
+ ASSERTF(layout != NULL, "errno = %d", errno);
+
+ rc = llapi_layout_ost_index_get(layout, 0, &ost0);
+ ASSERTF(rc == 0, "errno = %d", errno);
+ rc = llapi_layout_ost_index_get(layout, 1, &ost1);
+ ASSERTF(rc == 0, "errno = %d", errno);
+ ASSERTF(ost0 == 1, "%"PRIu64" != %d", ost0, 1);
+ ASSERTF(ost1 == 0, "%"PRIu64" != %d", ost1, 0);
+ llapi_layout_free(layout);
+
+ /* specify more ost indexes to test realloc */
+ nost = 0;
+ layout = llapi_layout_alloc();
+ ASSERTF(layout != NULL, "errno %d", errno);
+ for (i = 0; i < LOV_MAX_STRIPE_COUNT; i++) {
+ rc = llapi_layout_ost_index_set(layout, i, nost);
+ ASSERTF(rc == 0, "errno = %d", errno);
+ rc = llapi_layout_ost_index_get(layout, i, &ost0);
+ ASSERTF(rc == 0, "errno = %d", errno);
+ nost++;
+ if (nost == num_osts)
+ nost = 0;
+ }
+
+ nost = 0;
+ for (i = 0; i < LOV_MAX_STRIPE_COUNT; i++) {
+ rc = llapi_layout_ost_index_get(layout, i, &ost0);
+ ASSERTF(rc == 0, "errno = %d", errno);
+ ASSERTF(ost0 == nost, "ost=%"PRIu64" nost=%"PRIu64"",
+ ost0, nost);
+ nost++;
+ if (nost == num_osts)
+ nost = 0;
+ }
+ llapi_layout_free(layout);
+
+ nost = 0;
+ layout = llapi_layout_alloc();
+ ASSERTF(layout != NULL, "errno %d", errno);
+ for (i = LOV_MAX_STRIPE_COUNT-1; i >= 0; i--) {
+ rc = llapi_layout_ost_index_set(layout, i, nost);
+ ASSERTF(rc == 0, "errno = %d", errno);
+ rc = llapi_layout_ost_index_get(layout, i, &ost0);
+ ASSERTF(rc == 0, "errno = %d", errno);
+ nost++;
+ if (nost == num_osts)
+ nost = 0;
+ }
+
+ nost = 0;
+ for (i = LOV_MAX_STRIPE_COUNT-1; i <= 0; i--) {
+ rc = llapi_layout_ost_index_get(layout, i, &ost0);
+ ASSERTF(rc == 0, "errno = %d", errno);
+ ASSERTF(ost0 == nost, "ost=%"PRIu64", nost=%"PRIu64"",
+ ost0, nost);
+ nost++;
+ if (nost == num_osts)
+ nost = 0;
+ }
+ llapi_layout_free(layout);
+}
+
#define TEST_DESC_LEN 50
struct test_tbl_entry {
void (*tte_fn)(void);
{ &test26, T26_DESC, false },
{ &test27, T27_DESC, false },
{ &test28, T28_DESC, false },
+ { &test29, T29_DESC, false },
};
#define NUM_TESTS (sizeof(test_tbl) / sizeof(struct test_tbl_entry))
return rc;
}
+/* 'str_tests' are the tests to be skipped, such as "1,3,4,.." */
+static void set_tests_skipped(char *str_tests)
+{
+ char *ptr = str_tests;
+ int tstno;
+
+ if (ptr == NULL || strlen(ptr) == 0)
+ return;
+
+ while (*ptr != '\0') {
+ tstno = strtoul(ptr, &ptr, 0);
+ if (tstno >= 0 && tstno < NUM_TESTS)
+ test_tbl[tstno].tte_skip = true;
+ if (*ptr == ',')
+ ptr++;
+ else
+ break;
+ }
+}
+
static void process_args(int argc, char *argv[])
{
int c;
- while ((c = getopt(argc, argv, "d:p:o:")) != -1) {
+ while ((c = getopt(argc, argv, "d:p:o:s:")) != -1) {
switch (c) {
case 'd':
lustre_dir = optarg;
case 'o':
num_osts = atoi(optarg);
break;
+ case 's':
+ set_tests_skipped(optarg);
+ break;
case '?':
fprintf(stderr, "Unknown option '%c'\n", optopt);
usage(argv[0]);
int rc = 0;
int i;
struct stat s;
- char fsname[8];
+ char fsname[8 + 1];
llapi_msg_set_level(LLAPI_MSG_OFF);