Whamcloud - gitweb
LU-4298 utils: do not create file with no striping info 35/12335/3
authorJames Nunez <james.a.nunez@intel.com>
Fri, 18 Jul 2014 15:06:36 +0000 (09:06 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 6 Nov 2014 18:39:48 +0000 (18:39 +0000)
'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 <sebastien.buisson@bull.net>
Signed-off-by: James Nunez <james.a.nunez@intel.com>
Signed-off-by: Bob Glossman <bob.glossman@intel.com>
Change-Id: I19beef973dc3a62bf2cb443e02195896772702fc
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-on: http://review.whamcloud.com/12335
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index fffee4b..c2d3eb3 100644 (file)
@@ -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)"
 
index e386702..90f28fe 100644 (file)
@@ -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,