void test20(void) { int rc; int fd; struct llapi_layout *deflayout; struct llapi_layout *filelayout; char path[PATH_MAX]; uint64_t fsize; uint64_t fcount; uint64_t dsize; uint64_t dcount; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T20FILE); rc = unlink(path); ASSERTF(rc == 0 || errno == ENOENT, "errno = %d", errno); filelayout = llapi_layout_alloc(); ASSERTF(filelayout != NULL, "errno = %d", errno); rc = llapi_layout_stripe_size_set(filelayout, LLAPI_LAYOUT_DEFAULT); ASSERTF(rc == 0, "rc = %d, errno = %d", rc, errno); rc = llapi_layout_stripe_count_set(filelayout, LLAPI_LAYOUT_DEFAULT); ASSERTF(rc == 0, "rc = %d, errno = %d", rc, errno); fd = llapi_layout_file_create(path, 0, 0640, filelayout); ASSERTF(fd >= 0, "errno = %d", errno); rc = close(fd); ASSERTF(rc == 0, "errno = %d", errno); llapi_layout_free(filelayout); deflayout = llapi_layout_get_by_path(lustre_dir, LAYOUT_GET_EXPECTED); ASSERTF(deflayout != NULL, "errno = %d", errno); filelayout = llapi_layout_get_by_path(path, 0); ASSERTF(filelayout != NULL, "errno = %d", errno); rc = llapi_layout_stripe_count_get(filelayout, &fcount); ASSERTF(rc == 0, "errno = %d", errno); rc = llapi_layout_stripe_count_get(deflayout, &dcount); ASSERTF(rc == 0, "errno = %d", errno); ASSERTF(fcount == dcount || dcount == LLAPI_LAYOUT_DEFAULT || dcount == LLAPI_LAYOUT_WIDE, "%"PRIu64" != %"PRIu64, fcount, dcount); rc = llapi_layout_stripe_size_get(filelayout, &fsize); ASSERTF(rc == 0, "errno = %d", errno); rc = llapi_layout_stripe_size_get(deflayout, &dsize); ASSERTF(rc == 0, "errno = %d", errno); ASSERTF(fsize == dsize, "%"PRIu64" != %"PRIu64, fsize, dsize); llapi_layout_free(filelayout); llapi_layout_free(deflayout); }
void test1(void) { char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T0FILE); struct llapi_layout *layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout != NULL, "errno = %d", errno); __test1_helper(layout); llapi_layout_free(layout); }
void test4(void) { int rc; uint64_t ost0; uint64_t ost1; uint64_t count; uint64_t size; const char *lfs = getenv("LFS"); char mypool[LOV_MAXPOOLNAME + 1] = { '\0' }; char cmd[4096]; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T4FILE); if (lfs == NULL) lfs = "/usr/bin/lfs"; rc = unlink(path); ASSERTF(rc == 0 || errno == ENOENT, "errno = %d", errno); snprintf(cmd, sizeof(cmd), "%s setstripe %s %s -c %d -S %d %s", lfs, strlen(poolname) > 0 ? "-p" : "", poolname, T4_STRIPE_COUNT, T4_STRIPE_SIZE, path); rc = system(cmd); ASSERTF(rc == 0, "system(%s): exit status %d", cmd, WEXITSTATUS(rc)); errno = 0; struct llapi_layout *layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout != NULL, "errno = %d", errno); rc = llapi_layout_stripe_count_get(layout, &count); ASSERTF(count == T4_STRIPE_COUNT, "%"PRIu64" != %d", count, T4_STRIPE_COUNT); rc = llapi_layout_stripe_size_get(layout, &size); ASSERTF(size == T4_STRIPE_SIZE, "%"PRIu64" != %d", size, T4_STRIPE_SIZE); rc = llapi_layout_pool_name_get(layout, mypool, sizeof(mypool)); ASSERTF(rc == 0, "errno = %d", errno); rc = strcmp(mypool, poolname); ASSERTF(rc == 0, "%s != %s", mypool, poolname); 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(ost1 != ost0, "%"PRIu64" == %"PRIu64, ost0, ost1); llapi_layout_free(layout); }
void test5(void) { int rc; char path[PATH_MAX]; struct llapi_layout *layout; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T5FILE); rc = unlink(path); ASSERTF(rc == 0 || errno == ENOENT, "errno = %d", errno); errno = 0; layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout == NULL && errno == ENOENT, "errno = %d", errno); }
void test18(void) { int rc; int fd; struct llapi_layout *layout = llapi_layout_alloc(); char path[PATH_MAX]; char pool[LOV_MAXPOOLNAME*2 + 1]; char mypool[LOV_MAXPOOLNAME + 1] = { '\0' }; snprintf(pool, sizeof(pool), "lustre.%s", poolname); snprintf(path, sizeof(path), "%s/%s", lustre_dir, T18FILE); ASSERTF(layout != NULL, "errno = %d", errno); rc = unlink(path); ASSERTF(rc == 0 || errno == ENOENT, "errno = %d", errno); rc = llapi_layout_pool_name_set(layout, pool); ASSERTF(rc == 0, "errno = %d", errno); rc = llapi_layout_pool_name_get(layout, mypool, sizeof(mypool)); ASSERTF(rc == 0, "errno = %d", errno); rc = strcmp(mypool, poolname); ASSERTF(rc == 0, "%s != %s", mypool, poolname); fd = llapi_layout_file_create(path, 0, 0640, layout); ASSERTF(fd >= 0, "errno = %d", errno); rc = close(fd); ASSERTF(rc == 0, "errno = %d", errno); llapi_layout_free(layout); layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout != NULL, "errno = %d", errno); rc = llapi_layout_pool_name_get(layout, mypool, sizeof(mypool)); ASSERTF(rc == 0, "errno = %d", errno); rc = strcmp(mypool, poolname); ASSERTF(rc == 0, "%s != %s", mypool, poolname); llapi_layout_free(layout); }
void test17(void) { int rc; int fd; int osts_all; uint64_t osts_layout; struct llapi_layout *layout; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T17FILE); rc = unlink(path); ASSERTF(rc == 0 || errno == ENOENT, "errno = %d", errno); layout = llapi_layout_alloc(); ASSERTF(layout != NULL, "errno = %d", errno); rc = llapi_layout_stripe_count_set(layout, LLAPI_LAYOUT_WIDE); ASSERTF(rc == 0, "errno = %d", errno); fd = llapi_layout_file_create(path, 0, 0640, layout); ASSERTF(fd >= 0, "errno = %d", errno); rc = close(fd); ASSERTF(rc == 0, "errno = %d", errno); llapi_layout_free(layout); /* Get number of available OSTs */ fd = open(path, O_RDONLY); ASSERTF(fd >= 0, "errno = %d", errno); rc = llapi_lov_get_uuids(fd, NULL, &osts_all); ASSERTF(rc == 0, "rc = %d, errno = %d", rc, errno); rc = close(fd); ASSERTF(rc == 0, "errno = %d", errno); layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout != NULL, "errno = %d", errno); rc = llapi_layout_stripe_count_get(layout, &osts_layout); ASSERTF(osts_layout == osts_all, "%"PRIu64" != %d", osts_layout, osts_all); llapi_layout_free(layout); }
void test15(void) { int rc; int fd; uint64_t count; struct llapi_layout *layout; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T15FILE); rc = unlink(path); ASSERTF(rc >= 0 || errno == ENOENT, "errno = %d", errno); layout = llapi_layout_alloc(); ASSERTF(layout != NULL, "errno = %d", errno); rc = llapi_layout_stripe_count_set(layout, T15_STRIPE_COUNT); ASSERTF(rc == 0, "errno = %d", errno); errno = 0; fd = llapi_layout_file_create(path, 0, 0640, layout); ASSERTF(fd >= 0, "fd = %d, errno = %d", fd, errno); rc = close(fd); ASSERTF(rc == 0, "errno = %d", errno); rc = llapi_layout_stripe_count_set(layout, T15_STRIPE_COUNT - 1); errno = 0; fd = llapi_layout_file_open(path, 0, 0640, layout); ASSERTF(fd >= 0, "fd = %d, errno = %d", fd, errno); rc = close(fd); ASSERTF(rc == 0, "errno = %d", errno); llapi_layout_free(layout); layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout != NULL, "errno = %d", errno); rc = llapi_layout_stripe_count_get(layout, &count); ASSERTF(rc == 0 && count == T15_STRIPE_COUNT, "rc = %d, %"PRIu64" != %d", rc, count, T15_STRIPE_COUNT); llapi_layout_free(layout); }
void test7(void) { int fd; int rc; uid_t myuid = getuid(); char path[PATH_MAX]; const char *runas = getenv("RUNAS_ID"); struct passwd *pw; uid_t uid; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T7FILE); ASSERTF(myuid == 0, "myuid = %d", myuid); /* Need root for this test. */ /* Create file as root */ rc = unlink(path); ASSERTF(rc == 0 || errno == ENOENT, "errno = %d", errno); fd = open(path, O_CREAT, 0400); ASSERTF(fd > 0, "errno = %d", errno); rc = close(fd); ASSERTF(rc == 0, "errno = %d", errno); /* Become unprivileged user */ if (runas != NULL) { uid = atoi(runas); ASSERTF(uid != 0, "runas = %s", runas); } else { pw = getpwnam("nobody"); ASSERTF(pw != NULL, "errno = %d", errno); uid = pw->pw_uid; } rc = seteuid(uid); ASSERTF(rc == 0, "errno = %d", errno); errno = 0; struct llapi_layout *layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout == NULL && errno == EACCES, "errno = %d", errno); rc = seteuid(myuid); ASSERTF(rc == 0, "errno = %d", errno); }
void test8(void) { int fd; int rc; struct llapi_layout *layout; uint64_t count; uint64_t size; uint64_t pattern; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T8FILE); rc = unlink(path); ASSERTF(rc >= 0 || errno == ENOENT, "errno = %d", errno); fd = open(path, O_CREAT, 0640); ASSERTF(fd >= 0, "errno = %d", errno); rc = close(fd); ASSERTF(rc == 0, "errno = %d", errno); layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout != NULL, "errno = %d\n", errno); rc = llapi_layout_stripe_count_get(layout, &count); ASSERTF(rc == 0, "errno = %d\n", errno); ASSERTF(count == LLAPI_LAYOUT_DEFAULT, "count = %"PRIu64"\n", count); rc = llapi_layout_stripe_size_get(layout, &size); ASSERTF(rc == 0, "errno = %d\n", errno); ASSERTF(size == LLAPI_LAYOUT_DEFAULT, "size = %"PRIu64"\n", size); rc = llapi_layout_pattern_get(layout, &pattern); ASSERTF(rc == 0, "errno = %d\n", errno); ASSERTF(pattern == LLAPI_LAYOUT_DEFAULT, "pattern = %"PRIu64"\n", pattern); llapi_layout_free(layout); }
/** * Get the expected striping layout for a file at \a path. * * Substitute expected inherited attribute values for unspecified * attributes. Unspecified attributes may belong to directories and * never-written-to files, and indicate that default values will be * assigned when files are created or first written to. A default value * is inherited from the parent directory if the attribute is specified * there, otherwise it is inherited from the filesystem root. * Unspecified attributes normally have the value LLAPI_LAYOUT_DEFAULT. * * The complete \a path need not refer to an existing file or directory, * but some leading portion of it must reside within a lustre filesystem. * A use case for this interface would be to obtain the literal striping * values that would be assigned to a new file in a given directory. * * \param[in] path path for which to get the expected layout * * \retval valid llapi_layout pointer on success * \retval NULL if an error occurs */ static struct llapi_layout *llapi_layout_expected(const char *path) { struct llapi_layout *path_layout = NULL; struct llapi_layout *donor_layout; char donor_path[PATH_MAX]; struct stat st; int fd; int rc; fd = open(path, O_RDONLY); if (fd < 0 && errno != ENOENT) return NULL; if (fd >= 0) { int tmp; path_layout = llapi_layout_get_by_fd(fd, 0); tmp = errno; close(fd); errno = tmp; } if (path_layout == NULL) { if (errno != ENODATA && errno != ENOENT) return NULL; path_layout = llapi_layout_alloc(); if (path_layout == NULL) return NULL; } if (is_fully_specified(path_layout)) return path_layout; rc = stat(path, &st); if (rc < 0 && errno != ENOENT) { llapi_layout_free(path_layout); return NULL; } /* If path is a not a directory or doesn't exist, inherit unspecified * attributes from parent directory. */ if ((rc == 0 && !S_ISDIR(st.st_mode)) || (rc < 0 && errno == ENOENT)) { get_parent_dir(path, donor_path, sizeof(donor_path)); donor_layout = llapi_layout_get_by_path(donor_path, 0); if (donor_layout != NULL) { inherit_layout_attributes(donor_layout, path_layout); llapi_layout_free(donor_layout); if (is_fully_specified(path_layout)) return path_layout; } } /* Inherit remaining unspecified attributes from the filesystem root. */ rc = llapi_search_mounts(path, 0, donor_path, NULL); if (rc < 0) { llapi_layout_free(path_layout); return NULL; } donor_layout = llapi_layout_get_by_path(donor_path, 0); if (donor_layout == NULL) { llapi_layout_free(path_layout); return NULL; } inherit_layout_attributes(donor_layout, path_layout); llapi_layout_free(donor_layout); return path_layout; }
void test13(void) { int rc; int fd; uint64_t idx; struct llapi_layout *layout; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T13FILE); layout = llapi_layout_alloc(); ASSERTF(layout != NULL, "errno = %d", errno); /* invalid OST index */ errno = 0; rc = llapi_layout_ost_index_set(layout, 0, LLAPI_LAYOUT_INVALID); ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc, errno); errno = 0; rc = llapi_layout_ost_index_set(layout, 0, -1); ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc, errno); /* NULL layout */ errno = 0; rc = llapi_layout_ost_index_set(NULL, 0, 1); ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc, errno); errno = 0; rc = llapi_layout_ost_index_get(NULL, 0, &idx); ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc, errno); /* NULL index */ errno = 0; rc = llapi_layout_ost_index_get(layout, 0, NULL); ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc, errno); /* Layout not read from file so has no OST data. */ errno = 0; rc = llapi_layout_stripe_count_set(layout, T13_STRIPE_COUNT); ASSERTF(rc == 0, "errno = %d", errno); rc = llapi_layout_ost_index_get(layout, 0, &idx); ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc, errno); /* n greater than stripe count*/ rc = unlink(path); ASSERTF(rc >= 0 || errno == ENOENT, "errno = %d", errno); rc = llapi_layout_stripe_count_set(layout, T13_STRIPE_COUNT); ASSERTF(rc == 0, "errno = %d", errno); fd = llapi_layout_file_create(path, 0, 0644, layout); ASSERTF(fd >= 0, "errno = %d", errno); rc = close(fd); ASSERTF(rc == 0, "errno = %d", errno); llapi_layout_free(layout); layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout != NULL, "errno = %d", errno); errno = 0; rc = llapi_layout_ost_index_get(layout, T13_STRIPE_COUNT + 1, &idx); ASSERTF(rc == -1 && errno == EINVAL, "rc = %d, errno = %d", rc, errno); llapi_layout_free(layout); }