Whamcloud - gitweb
LU-11380 llite: zero lum for stripeless files 72/33172/3
authorJohn L. Hammond <jhammond@whamcloud.com>
Fri, 14 Sep 2018 20:49:37 +0000 (15:49 -0500)
committerOleg Drokin <green@whamcloud.com>
Fri, 5 Oct 2018 22:27:38 +0000 (22:27 +0000)
In the IOC_MDC_GETFILEINFO/LL_IOC_MDC_GETINFO case of ll_dir_ioctl(),
if the file has no striping then zero out the lum buffer so that
userspace won't be confused by garbage.

Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Change-Id: I4574b8bfdee122ec1ac571ae3714026c6fa0a7f0
Reviewed-on: https://review.whamcloud.com/33172
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
lustre/llite/dir.c
lustre/tests/sanity.sh

index cb73a4d..9e07036 100644 (file)
@@ -1514,13 +1514,14 @@ out_rmdir:
                         GOTO(out_req, rc);
                 }
 
-                if (rc < 0) {
-                        if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
-                                               cmd == LL_IOC_MDC_GETINFO))
-                                GOTO(skip_lmm, rc = 0);
-                        else
-                                GOTO(out_req, rc);
-                }
+               if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
+                                      cmd == LL_IOC_MDC_GETINFO)) {
+                       lmmsize = 0;
+                       rc = 0;
+               }
+
+               if (rc < 0)
+                       GOTO(out_req, rc);
 
                if (cmd == IOC_MDC_GETFILESTRIPE ||
                    cmd == LL_IOC_LOV_GETSTRIPE ||
@@ -1531,12 +1532,18 @@ out_rmdir:
                        lmdp = (struct lov_user_mds_data __user *)arg;
                         lump = &lmdp->lmd_lmm;
                 }
-               if (copy_to_user(lump, lmm, lmmsize)) {
+
+               if (lmmsize == 0) {
+                       /* If the file has no striping then zero out *lump so
+                        * that the caller isn't confused by garbage. */
+                       if (clear_user(lump, sizeof(*lump)))
+                               GOTO(out_req, rc = -EFAULT);
+               } else if (copy_to_user(lump, lmm, lmmsize)) {
                        if (copy_to_user(lump, lmm, sizeof(*lump)))
-                                GOTO(out_req, rc = -EFAULT);
-                        rc = -EOVERFLOW;
-                }
-        skip_lmm:
+                               GOTO(out_req, rc = -EFAULT);
+                       rc = -EOVERFLOW;
+               }
+
                 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
                        struct lov_user_mds_data __user *lmdp;
                         lstat_t st = { 0 };
index 2ff71db..1b0dfab 100755 (executable)
@@ -13586,6 +13586,20 @@ test_184e() {
 }
 run_test 184e "Recreate layout after stripeless layout swaps"
 
+test_184f() {
+       # Create a file with name longer than sizeof(struct stat) ==
+       # 144 to see if we can get chars from the file name to appear
+       # in the returned striping. Note that 'f' == 0x66.
+       local file=$(for ((i = 0; i < 200; i++)); do echo -n f; done)
+
+       mkdir -p $DIR/$tdir
+       mcreate $DIR/$tdir/$file
+       if lfs find --stripe-count 0x6666 $DIR/$tdir | grep $file; then
+               error "IOC_MDC_GETFILEINFO returned garbage striping"
+       fi
+}
+run_test 184f "IOC_MDC_GETFILEINFO for files with long names but no striping"
+
 test_185() { # LU-2441
        # LU-3553 - no volatile file support in old servers
        [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||