Whamcloud - gitweb
LU-4929 llite: use the correct mode for striped directory 28/10028/8
authorwang di <di.wang@intel.com>
Fri, 18 Apr 2014 21:33:59 +0000 (14:33 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 30 May 2014 01:47:41 +0000 (01:47 +0000)
Create striped directory with correct mode, which should be
handling same as mkdir.

Add -m option to setdirstripe so the user can create stripedir
with specified mode.

Signed-off-by: wang di <di.wang@intel.com>
Change-Id: I4d7d186d4c820cfbdddd0aac9012e7e5e2454278
Reviewed-on: http://review.whamcloud.com/10028
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
lustre/llite/dir.c
lustre/tests/sanity.sh
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 22c4a42..5a5079a 100644 (file)
@@ -399,13 +399,23 @@ static int ll_send_mgc_param(struct obd_export *mgc, char *string)
         return rc;
 }
 
-static int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
-                              const char *filename)
+/**
+ * Create striped directory with specified stripe(@lump)
+ *
+ * param[in]parent     the parent of the directory.
+ * param[in]lump       the specified stripes.
+ * param[in]dirname    the name of the directory.
+ * param[in]mode       the specified mode of the directory.
+ *
+ * retval              =0 if striped directory is being created successfully.
+ *                      <0 if the creation is failed.
+ */
+static int ll_dir_setdirstripe(struct inode *parent, struct lmv_user_md *lump,
+                              const char *dirname, umode_t mode)
 {
        struct ptlrpc_request *request = NULL;
        struct md_op_data *op_data;
-       struct ll_sb_info *sbi = ll_i2sbi(dir);
-       int mode;
+       struct ll_sb_info *sbi = ll_i2sbi(parent);
        int err;
        ENTRY;
 
@@ -414,15 +424,17 @@ static int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
 
        CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) name %s"
               "stripe_offset %d, stripe_count: %u\n",
-              PFID(ll_inode2fid(dir)), dir, filename,
+              PFID(ll_inode2fid(parent)), parent, dirname,
               (int)lump->lum_stripe_offset, lump->lum_stripe_count);
 
        if (lump->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
                lustre_swab_lmv_user_md(lump);
 
-       mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
-       op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
-                                    strlen(filename), mode, LUSTRE_OPC_MKDIR,
+       if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
+               mode &= ~current_umask();
+       mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
+       op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
+                                    strlen(dirname), mode, LUSTRE_OPC_MKDIR,
                                     lump);
        if (IS_ERR(op_data))
                GOTO(err_exit, err = PTR_ERR(op_data));
@@ -1097,6 +1109,7 @@ out_free:
                char            *filename;
                int              namelen = 0;
                int              lumlen = 0;
+               umode_t          mode;
                int              len;
                int              rc;
 
@@ -1126,11 +1139,12 @@ out_free:
                        GOTO(lmv_out_free, rc = -EINVAL);
                }
 
-               /**
-                * ll_dir_setdirstripe will be used to set dir stripe
-                *  mdc_create--->mdt_reint_create (with dirstripe)
-                */
-               rc = ll_dir_setdirstripe(inode, lum, filename);
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 50, 0)
+               mode = data->ioc_type != 0 ? data->ioc_type : S_IRWXUGO;
+#else
+               mode = data->ioc_type;
+#endif
+               rc = ll_dir_setdirstripe(inode, lum, filename, mode);
 lmv_out_free:
                obd_ioctl_freedata(buf, len);
                RETURN(rc);
index 433c330..144e5e7 100644 (file)
@@ -2660,6 +2660,52 @@ test_33d() {
 }
 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
 
+test_33e() {
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+
+       mkdir $DIR/$tdir
+
+       $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
+       $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
+       mkdir $DIR/$tdir/local_dir
+
+       local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
+       local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
+       local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
+
+       [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
+               error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
+
+       rmdir $DIR/$tdir/* || error "rmdir failed"
+
+       umask 777
+       $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
+       $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
+       mkdir $DIR/$tdir/local_dir
+
+       s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
+       s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
+       l_mode=$(stat -c%f $DIR/$tdir/local_dir)
+
+       [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
+               error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
+
+       rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
+
+       umask 000
+       $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
+       $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
+       mkdir $DIR/$tdir/local_dir
+
+       s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
+       s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
+       l_mode=$(stat -c%f $DIR/$tdir/local_dir)
+
+       [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
+               error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
+}
+run_test 33e "mkdir and striped directory should have same mode"
+
 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
 test_34a() {
        rm -f $DIR/f34
@@ -12597,15 +12643,27 @@ test_238() {
 }
 run_test 238 "Verify linkea consistency"
 
+cleanup_test_300() {
+       trap 0
+       umask $SAVE_UMASK
+}
 test_striped_dir() {
        local mdt_index=$1
        local stripe_count
        local stripe_index
 
        mkdir -p $DIR/$tdir
-       $LFS setdirstripe -i $mdt_index -c 2 -t all_char $DIR/$tdir/striped_dir ||
+
+       SAVE_UMASK=$(umask)
+       trap cleanup_test_300 RETURN EXIT
+
+       $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
+                                               $DIR/$tdir/striped_dir ||
                error "set striped dir error"
 
+       local mode=$(stat -c%a $DIR/$tdir/striped_dir)
+       [ "$mode" = "755" ] || error "expect 755 got $mode"
+
        stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
        if [ "$stripe_count" != "2" ]; then
                error "stripe_count is $stripe_count, expect 2"
@@ -12640,6 +12698,9 @@ test_striped_dir() {
 
        rmdir $DIR/$tdir/striped_dir ||
                error "rmdir striped dir error"
+
+       cleanup_test_300
+
        true
 }
 
index cb684a1..3c71801 100644 (file)
@@ -1483,19 +1483,24 @@ static int lfs_setdirstripe(int argc, char **argv)
        char                    *stripe_offset_opt = NULL;
        char                    *stripe_count_opt = NULL;
        char                    *stripe_hash_opt = NULL;
+       char                    *mode_opt = NULL;
        int                     default_stripe = 0;
+       mode_t                  mode = S_IRWXU | S_IRWXG | S_IRWXO;
+       mode_t                  previous_mode = 0;
 
        struct option long_opts[] = {
                {"count",       required_argument, 0, 'c'},
                {"index",       required_argument, 0, 'i'},
+               {"mode",        required_argument, 0, 'm'},
                {"hash-type",   required_argument, 0, 't'},
-               {"default_stripe", required_argument, 0, 'D'},
+               {"default_stripe", no_argument, 0, 'D'},
                {0, 0, 0, 0}
        };
 
        optind = 0;
 
-       while ((c = getopt_long(argc, argv, "c:Di:t:", long_opts, NULL)) >= 0) {
+       while ((c = getopt_long(argc, argv, "c:Di:m:t:", long_opts,
+                               NULL)) >= 0) {
                switch (c) {
                case 0:
                        /* Long options. */
@@ -1509,6 +1514,9 @@ static int lfs_setdirstripe(int argc, char **argv)
                case 'i':
                        stripe_offset_opt = optarg;
                        break;
+               case 'm':
+                       mode_opt = optarg;
+                       break;
                case 't':
                        stripe_hash_opt = optarg;
                        break;
@@ -1542,6 +1550,16 @@ static int lfs_setdirstripe(int argc, char **argv)
                }
        }
 
+       if (mode_opt != NULL) {
+               mode = strtoul(mode_opt, &end, 8);
+               if (*end != '\0') {
+                       fprintf(stderr, "error: %s: bad mode '%s'\n",
+                               argv[0], mode_opt);
+                       return CMD_HELP;
+               }
+               previous_mode = umask(0);
+       }
+
        if (stripe_hash_opt == NULL ||
            strcmp(stripe_hash_opt, LMV_HASH_NAME_FNV_1A_64) == 0) {
                hash_type = LMV_HASH_TYPE_FNV_1A_64;
@@ -1570,7 +1588,8 @@ static int lfs_setdirstripe(int argc, char **argv)
                                                    stripe_offset, stripe_count,
                                                    hash_type, NULL);
                } else {
-                       result = llapi_dir_create_pool(dname, 0, stripe_offset,
+                       result = llapi_dir_create_pool(dname, mode,
+                                                      stripe_offset,
                                                       stripe_count, hash_type,
                                                       NULL);
                }
@@ -1583,6 +1602,9 @@ static int lfs_setdirstripe(int argc, char **argv)
                dname = argv[++optind];
        } while (dname != NULL);
 
+       if (mode_opt != NULL)
+               umask(previous_mode);
+
        return result;
 }
 
index 7610693..6b06ebb 100644 (file)
@@ -817,7 +817,7 @@ int llapi_dir_set_default_lmv_stripe(const char *name, int stripe_offset,
        return rc;
 }
 
-int llapi_dir_create_pool(const char *name, int flags, int stripe_offset,
+int llapi_dir_create_pool(const char *name, int mode, int stripe_offset,
                          int stripe_count, int stripe_pattern,
                          const char *pool_name)
 {
@@ -859,6 +859,7 @@ int llapi_dir_create_pool(const char *name, int flags, int stripe_offset,
        data.ioc_inllen1 = strlen(filename) + 1;
        data.ioc_inlbuf2 = (char *)&lmu;
        data.ioc_inllen2 = sizeof(struct lmv_user_md);
+       data.ioc_type = mode;
        rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
        if (rc) {
                llapi_error(LLAPI_MSG_ERROR, rc,