diff --git a/lustre/ChangeLog b/lustre/ChangeLog index 7f7c51cc2c1549463e9670c986395e485c053f20..8e3b01250f2d96ce23d3b3407dd9b18f9efd8122 100644 --- a/lustre/ChangeLog +++ b/lustre/ChangeLog @@ -111,6 +111,12 @@ Bugzilla : 12932 Description: obd_health_check_timeout too short Details : set obd_health_check_timeout as 1.5x of obd_timeout +Severity : normal +Bugzilla : 12192 +Description: llapi_file_create() does not allow some changes +Details : add llapi_file_open() that allows specifying the mode and + open flags, and also returns an open file handle. + -------------------------------------------------------------------------------- 2007-08-10 Cluster File Systems, Inc. <info@clusterfs.com> diff --git a/lustre/include/lustre/liblustreapi.h b/lustre/include/lustre/liblustreapi.h index 5371b8750fd56b57754b3230c61ac66d814d22fa..27433f7d9f27245ab0d15643b28a4820bbc29150 100644 --- a/lustre/include/lustre/liblustreapi.h +++ b/lustre/include/lustre/liblustreapi.h @@ -14,6 +14,9 @@ typedef void (*llapi_cb_t)(char *obd_type_name, char *obd_name, char *obd_uuid, extern int llapi_file_create(const char *name, unsigned long stripe_size, int stripe_offset, int stripe_count, int stripe_pattern); +extern int llapi_file_open(const char *name, int flags, int mode, + unsigned long stripe_size, int stripe_offset, + int stripe_count, int stripe_pattern); extern int llapi_file_get_stripe(const char *path, struct lov_user_md *lum); #define HAVE_LLAPI_FILE_LOOKUP extern int llapi_file_lookup(int dirfd, const char *name); diff --git a/lustre/tests/Makefile.am b/lustre/tests/Makefile.am index d3d60f00326608361c1b0495d05ab393bb155469..acf01cecd3e558da13e0c66b063ab8555fdf848a 100644 --- a/lustre/tests/Makefile.am +++ b/lustre/tests/Makefile.am @@ -54,6 +54,7 @@ mmap_sanity_SOURCES= mmap_sanity.c LIBLUSTREAPI := $(top_builddir)/lustre/utils/liblustreapi.a ll_getstripe_info_LDADD=$(LIBLUSTREAPI) +multiop_LDADD=$(LIBLUSTREAPI) if MPITESTS LAM_LD_FLAGS=-L/opt/lam/lib -lmpi -llam -lpthread diff --git a/lustre/tests/multiop.c b/lustre/tests/multiop.c index 389e26ff46bf9913d3e30ca6cbad6e7e993705fb..765c00b43271235f80fef0c65e8da41ad7ff75cc 100755 --- a/lustre/tests/multiop.c +++ b/lustre/tests/multiop.c @@ -14,6 +14,7 @@ #include <signal.h> #include <stdlib.h> #include <unistd.h> +#include <lustre/liblustreapi.h> #define T1 "write data before unlink\n" #define T2 "write data after unlink\n" @@ -26,6 +27,7 @@ char usage[] = "Usage: %s filename command-sequence\n" " command-sequence items:\n" " c close\n" +" C[num] create with optional stripes\n" " d mkdir\n" " D open(O_DIRECTORY)\n" " L link\n" @@ -169,6 +171,16 @@ int main(int argc, char **argv) } fd = -1; break; + case 'C': + len = atoi(commands+1); + fd = llapi_file_open(fname, O_CREAT | O_WRONLY, 0644, + 0, 0, len, 0); + if (fd == -1) { + save_errno = errno; + perror("create stripe file"); + exit(save_errno); + } + break; case 'd': if (mkdir(fname, 0755) == -1) { save_errno = errno; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 4660081682e0ba1a0f337172dee6975790778f39..af3abfed00250693da56b3738768891f6d60a5e5 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -843,6 +843,12 @@ test_24t() { } run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a =" +test_24u() { # bug12192 + multiop $DIR/$tfile C2w$((2048 * 1024))c || error + $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size" +} +run_test 24u "create stripe file" + test_25a() { echo '== symlink sanity =============================================' diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 406c6294e1763284265c9adf4b06dd5862eda44c..c5e410e615e34d93f2fa3cb5a88efcd8bccbcd86 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -69,16 +69,17 @@ static void err_msg(char *fmt, ...) fprintf(stderr, ": %s (%d)\n", strerror(tmp_errno), tmp_errno); } -int llapi_file_create(const char *name, unsigned long stripe_size, int stripe_offset, - int stripe_count, int stripe_pattern) +int llapi_file_open(const char *name, int flags, int mode, + unsigned long stripe_size, int stripe_offset, + int stripe_count, int stripe_pattern) { struct lov_user_md lum = { 0 }; int fd, rc = 0; int isdir = 0; int page_size; - fd = open(name, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644); - if (errno == EISDIR) { + fd = open(name, flags | O_LOV_DELAY_CREATE, mode); + if (fd < 0 && errno == EISDIR) { fd = open(name, O_DIRECTORY | O_RDONLY); isdir++; } @@ -138,12 +139,26 @@ int llapi_file_create(const char *name, unsigned long stripe_size, int stripe_of (__u64)LL_IOC_LOV_SETSTRIPE, name, fd, errmsg); } out: - if (close(fd) < 0) { - if (rc == 0) - rc = -errno; - err_msg("error on close for '%s' (%d)", name, fd); + if (rc) { + close(fd); + fd = rc; } - return rc; + + return fd; +} + +int llapi_file_create(const char *name, unsigned long stripe_size, + int stripe_offset, int stripe_count, int stripe_pattern) +{ + int fd; + + fd = llapi_file_open(name, O_CREAT | O_WRONLY, 0644, stripe_size, + stripe_offset, stripe_count, stripe_pattern); + if (fd < 0) + return fd; + + close(fd); + return 0; } typedef int (semantic_func_t)(char *path, DIR *parent, DIR *d, void *data);