Whamcloud - gitweb
LU-11739 lod: don't inherit default layout from root directory 56/33956/7
authorJian Yu <yujian@whamcloud.com>
Wed, 23 Jan 2019 01:44:26 +0000 (17:44 -0800)
committerOleg Drokin <green@whamcloud.com>
Wed, 30 Jan 2019 02:41:03 +0000 (02:41 +0000)
There is no need to inherit the default directory layout from
the root directory when subdirectories are created therein.
This consumes xattr space on the subdirectories, and makes it
more complex to change the filesystem default layout in the future.

This patch fixes the above issue in lod_ah_init() to check if
the parent directory is the root directory and not copy
the default layout xattr to the new subdirectory.

Change-Id: Ie0d286785bdbcd73e2ae60b429e66d5d54b44eef
Signed-off-by: Jian Yu <yujian@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/33956
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Jenkins
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/doc/lfs-setstripe.1
lustre/lod/lod_internal.h
lustre/lod/lod_object.c
lustre/tests/sanity.sh

index 5118ac4..eaa109a 100644 (file)
@@ -40,8 +40,11 @@ Files with composite layouts allow different
 to be specified for non-overlapping extents of the file. Files will
 inherit options not explicitly specified on the command line either from
 the default layout on the parent directory, or from the filesystem-wide
-default.  The default layout set on a directory will be copied to any new
-subdirectories created within that directory at the time they are created.
+default. New subdirectories created under root directory will not explicitly
+copy the default layout at creation time, but will implicitly inherit the
+default layout at runtime. The default layout set on a non-root directory
+will be copied to any new subdirectories created within that directory
+at the time they are created.
 .TP
 .B lfs setstripe \fR[\fISTRIPE_OPTIONS\fR ...] <\fIdirectory\fR|\fIfile\fR>
 Create a new
index a240b72..454b752 100644 (file)
@@ -551,6 +551,15 @@ lod_name_get(const struct lu_env *env, const void *area, int len)
        return lname;
 }
 
+static inline struct lod_default_striping *
+lod_lds_buf_get(const struct lu_env *env)
+{
+       struct lod_thread_info *info = lod_env_info(env);
+
+       memset(&info->lti_def_striping, 0, sizeof(info->lti_def_striping));
+       return &info->lti_def_striping;
+}
+
 static inline void lod_layout_get_pool(struct lod_layout_component *entries,
                                       int count, char *pool, int len)
 {
index d7fdad2..84a7e80 100644 (file)
@@ -4125,8 +4125,7 @@ static int lod_xattr_set(const struct lu_env *env,
                RETURN(rc);
        } else if (S_ISDIR(dt->do_lu.lo_header->loh_attr) &&
            strcmp(name, XATTR_NAME_LOV) == 0) {
-               struct lod_thread_info *info = lod_env_info(env);
-               struct lod_default_striping *lds = &info->lti_def_striping;
+               struct lod_default_striping *lds = lod_lds_buf_get(env);
                struct lov_user_md_v1 *v1 = buf->lb_buf;
                char pool[LOV_MAXPOOLNAME + 1];
                bool is_del;
@@ -4728,7 +4727,7 @@ static void lod_ah_init(const struct lu_env *env,
 {
        struct lod_device *d = lu2lod_dev(child->do_lu.lo_dev);
        struct lod_thread_info *info = lod_env_info(env);
-       struct lod_default_striping *lds = &info->lti_def_striping;
+       struct lod_default_striping *lds = lod_lds_buf_get(env);
        struct dt_object *nextp = NULL;
        struct dt_object *nextc;
        struct lod_object *lp = NULL;
@@ -4763,8 +4762,11 @@ static void lod_ah_init(const struct lu_env *env,
                /* other default values are 0 */
                lc->ldo_dir_stripe_offset = -1;
 
-               /* get default striping from parent object */
-               if (likely(lp != NULL))
+               /*
+                * If parent object is not root directory,
+                * then get default striping from parent object.
+                */
+               if (likely(lp != NULL) && !fid_is_root(lod_object_fid(lp)))
                        lod_get_default_striping(env, lp, lds);
 
                /* set child default striping info, default value is NULL */
index da48ab8..8a4dde1 100755 (executable)
@@ -6756,6 +6756,100 @@ test_65m() {
 }
 run_test 65m "normal user can't set filesystem default stripe"
 
+test_65n() {
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.12.50) ]] ||
+               skip "Need MDS version at least 2.12.50"
+       [[ $PARALLEL != "yes" ]] || skip "skip parallel run"
+
+       [[ $OSTCOUNT -ge 2 ]] || skip_env "needs >= 2 OSTs"
+       which getfattr > /dev/null 2>&1 || skip_env "no getfattr command"
+       which setfattr > /dev/null 2>&1 || skip_env "no setfattr command"
+
+       local root_layout=$(save_layout $MOUNT)
+       stack_trap "restore_layout $MOUNT $root_layout" EXIT
+
+       # new subdirectory under root directory should not inherit
+       # the default layout from root
+       local dir1=$MOUNT/$tdir-1
+       mkdir $dir1 || error "mkdir $dir1 failed"
+       ! getfattr -n trusted.lov $dir1 &> /dev/null ||
+               error "$dir1 shouldn't have LOV EA"
+
+       # delete the default layout on root directory
+       $LFS setstripe -d $MOUNT || error "delete root default layout failed"
+
+       local dir2=$MOUNT/$tdir-2
+       mkdir $dir2 || error "mkdir $dir2 failed"
+       ! getfattr -n trusted.lov $dir2 &> /dev/null ||
+               error "$dir2 shouldn't have LOV EA"
+
+       # set a new striping pattern on root directory
+       local def_stripe_size=$($LFS getstripe -S $MOUNT)
+       local new_def_stripe_size=$((def_stripe_size * 2))
+       $LFS setstripe -S $new_def_stripe_size $MOUNT ||
+               error "set stripe size on $MOUNT failed"
+
+       # new file created in $dir2 should inherit the new stripe size from
+       # the filesystem default
+       local file2=$dir2/$tfile-2
+       touch $file2 || error "touch $file2 failed"
+
+       local file2_stripe_size=$($LFS getstripe -S $file2)
+       [[ $file2_stripe_size -eq $new_def_stripe_size ]] ||
+               error "$file2 didn't inherit stripe size $new_def_stripe_size"
+
+       local dir3=$MOUNT/$tdir-3
+       mkdir $dir3 || error "mkdir $dir3 failed"
+       ! getfattr -n trusted.lov $dir3 &> /dev/null ||
+               error "$dir3 shouldn't have LOV EA"
+
+       # set OST pool on root directory
+       local pool=$TESTNAME
+       pool_add $pool || error "add $pool failed"
+       pool_add_targets $pool 0 $((OSTCOUNT - 1)) 1 ||
+               error "add targets to $pool failed"
+
+       $LFS setstripe -p $pool $MOUNT ||
+               error "set OST pool on $MOUNT failed"
+
+       # new file created in $dir3 should inherit the pool from
+       # the filesystem default
+       local file3=$dir3/$tfile-3
+       touch $file3 || error "touch $file3 failed"
+
+       local file3_pool=$($LFS getstripe -p $file3)
+       [[ "$file3_pool" = "$pool" ]] ||
+               error "$file3 didn't inherit OST pool $pool"
+
+       local dir4=$MOUNT/$tdir-4
+       mkdir $dir4 || error "mkdir $dir4 failed"
+       ! getfattr -n trusted.lov $dir4 &> /dev/null ||
+               error "$dir4 shouldn't have LOV EA"
+
+       # new file created in $dir4 should inherit the pool from
+       # the filesystem default
+       local file4=$dir4/$tfile-4
+       touch $file4 || error "touch $file4 failed"
+
+       local file4_pool=$($LFS getstripe -p $file4)
+       [[ "$file4_pool" = "$pool" ]] ||
+               error "$file4 didn't inherit OST pool $pool"
+
+       # new subdirectory under non-root directory should inherit
+       # the default layout from its parent directory
+       $LFS setstripe -S $new_def_stripe_size -p $pool $dir4 ||
+               error "set directory layout on $dir4 failed"
+
+       local dir5=$dir4/$tdir-5
+       mkdir $dir5 || error "mkdir $dir5 failed"
+
+       local dir4_layout=$(get_layout_param $dir4)
+       local dir5_layout=$(get_layout_param $dir5)
+       [[ "$dir4_layout" = "$dir5_layout" ]] ||
+               error "$dir5 should inherit the default layout from $dir4"
+}
+run_test 65n "don't inherit default layout from root for new subdirectories"
+
 # bug 2543 - update blocks count on client
 test_66() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"