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); }
/** * Create a file with a given \a layout. * * Force O_CREAT and O_EXCL flags on so caller is assured that file was * created with the given \a layout on successful function return. * * \param[in] path name of the file to open * \param[in] open_flags open() flags * \param[in] mode permissions to create new file with * \param[in] layout layout to create new file with * * \retval non-negative file descriptor on successful open * \retval -1 if an error occurred */ int llapi_layout_file_create(const char *path, int open_flags, int mode, const struct llapi_layout *layout) { return llapi_layout_file_open(path, open_flags|O_CREAT|O_EXCL, mode, layout); }