From 1aef1561e03bf55432ccec219d2fdd88068d0c43 Mon Sep 17 00:00:00 2001 From: James Nunez Date: Fri, 18 Jul 2014 09:06:36 -0600 Subject: [PATCH] LU-4298 utils: do not create file with no striping info 'lfs setstripe' should not create a file with no striping information if bad values are given. The input parameter check in llapi_file_open_pool is moved before the file open to catch bad parameters before the file is created. A check is added to sanity test 27f to make sure 'lfs setstripe -s' does not create a file with no striping information. Lustre-commit: 823147fa760752c8c2ff11a5bd74f71f819f9e4e Lustre-change: http://review.whamcloud.com/8375 Signed-off-by: Sebastien Buisson Signed-off-by: James Nunez Signed-off-by: Bob Glossman Change-Id: I19beef973dc3a62bf2cb443e02195896772702fc Reviewed-by: Andreas Dilger Reviewed-on: http://review.whamcloud.com/12335 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/tests/sanity.sh | 11 +++++++---- lustre/utils/liblustreapi.c | 25 +++++++++++++------------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index fffee4b..c2d3eb3 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -1275,10 +1275,13 @@ test_27e() { run_test 27e "setstripe existing file (should return error) ======" test_27f() { - test_mkdir -p $DIR/d27 - $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed" - dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed" - $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed" + test_mkdir $DIR/$tdir + $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile && + error "$SETSTRIPE $DIR/$tdir/$tfile failed" + $CHECKSTAT -t file $DIR/$tdir/$tfile && + error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail" + dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed" + $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed" } run_test 27f "setstripe with bad stripe size (should return error)" diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index e386702..90f28fe 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -684,7 +684,8 @@ int llapi_file_open_pool(const char *name, int flags, int mode, int stripe_count, int stripe_pattern, char *pool_name) { struct lov_user_md_v3 lum = { 0 }; - int fd, rc = 0; + int fd = -1; + int rc = 0; /* Make sure we have a good pool */ if (pool_name != NULL) { @@ -723,6 +724,11 @@ int llapi_file_open_pool(const char *name, int flags, int mode, } } + rc = llapi_stripe_limit_check(stripe_size, stripe_offset, stripe_count, + stripe_pattern); + if (rc != 0) + return rc; + retry_open: fd = open(name, flags | O_LOV_DELAY_CREATE, mode); if (fd < 0) { @@ -738,11 +744,6 @@ retry_open: return rc; } - rc = llapi_stripe_limit_check(stripe_size, stripe_offset, stripe_count, - stripe_pattern); - if (rc != 0) - goto out; - /* Initialize IOCTL striping pattern structure */ lum.lmm_magic = LOV_USER_MAGIC_V3; lum.lmm_pattern = stripe_pattern; @@ -766,13 +767,13 @@ retry_open: "error on ioctl "LPX64" for '%s' (%d): %s", (__u64)LL_IOC_LOV_SETSTRIPE, name, fd,errmsg); } -out: - if (rc) { - close(fd); - fd = rc; - } - return fd; + if (rc) { + close(fd); + fd = rc; + } + + return fd; } int llapi_file_open(const char *name, int flags, int mode, -- 1.8.3.1