Whamcloud - gitweb
LU-6263 lmv: fix parent FID for migration 17/13817/8
authorwang di <di.wang@intel.com>
Wed, 18 Feb 2015 18:58:29 +0000 (10:58 -0800)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 26 Feb 2015 17:56:42 +0000 (17:56 +0000)
If the migrating directory is under striped directory, it needs
to set right stripe FID for its parent.

Update migration test script (sanity test_230) to do migration
under striped dir.

Add -i to test_mkdir().

Signed-off-by: wang di <di.wang@intel.com>
Change-Id: Ic230f9b63bc21c1391e397a0d3ff689e3f0ba5dc
Reviewed-on: http://review.whamcloud.com/13817
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Lai Siyao <lai.siyao@intel.com>
Tested-by: Jenkins
lustre/lmv/lmv_obd.c
lustre/tests/sanity.sh
lustre/tests/test-framework.sh

index 64b6f15..a31ceb7 100644 (file)
@@ -1712,6 +1712,8 @@ lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
        const struct lmv_oinfo  *oinfo;
 
        if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NAME_HASH)) {
+               if (cfs_fail_val >= lsm->lsm_md_stripe_count)
+                       RETURN(ERR_PTR(-EBADF));
                oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
        } else {
                oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
@@ -1719,11 +1721,15 @@ lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
                        RETURN(ERR_CAST(oinfo));
        }
 
-       *fid = oinfo->lmo_fid;
-       *mds = oinfo->lmo_mds;
-       tgt = lmv_get_target(lmv, *mds, NULL);
+       if (fid != NULL)
+               *fid = oinfo->lmo_fid;
+       if (mds != NULL)
+               *mds = oinfo->lmo_mds;
+
+       tgt = lmv_get_target(lmv, oinfo->lmo_mds, NULL);
 
-       CDEBUG(D_INFO, "locate on mds %u "DFID"\n", *mds, PFID(fid));
+       CDEBUG(D_INFO, "locate on mds %u "DFID"\n", oinfo->lmo_mds,
+              PFID(&oinfo->lmo_fid));
        return tgt;
 }
 
@@ -2085,10 +2091,25 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
        if (op_data->op_cli_flags & CLI_MIGRATE) {
                LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
                         PFID(&op_data->op_fid3));
+
+               if (op_data->op_mea1 != NULL) {
+                       struct lmv_stripe_md    *lsm = op_data->op_mea1;
+                       struct lmv_tgt_desc     *tmp;
+
+                       /* Fix the parent fid for striped dir */
+                       tmp = lmv_locate_target_for_name(lmv, lsm, old,
+                                                        oldlen,
+                                                        &op_data->op_fid1,
+                                                        NULL);
+                       if (IS_ERR(tmp))
+                               RETURN(PTR_ERR(tmp));
+               }
+
                rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
-               if (rc)
+               if (rc != 0)
                        RETURN(rc);
-               src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid3);
+
+               src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
        } else {
                if (op_data->op_mea1 != NULL) {
                        struct lmv_stripe_md    *lsm = op_data->op_mea1;
index 1f06a98..26eeb26 100644 (file)
@@ -12408,7 +12408,8 @@ test_230a() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        local MDTIDX=1
 
-       mkdir -p $DIR/$tdir/test_230_local
+       test_mkdir $DIR/$tdir
+       test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
        local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
        [ $mdt_idx -ne 0 ] &&
                error "create local directory on wrong MDT $mdt_idx"
@@ -12439,8 +12440,9 @@ test_230b() {
        local migrate_dir=$DIR/$tdir/migrate_dir
        local other_dir=$DIR/$tdir/other_dir
 
-       mkdir -p $migrate_dir
-       mkdir -p $other_dir
+       test_mkdir $DIR/$tdir
+       test_mkdir -i0 -c1 $migrate_dir
+       test_mkdir -i0 -c1 $other_dir
        for ((i=0; i<10; i++)); do
                mkdir -p $migrate_dir/dir_${i}
                createmany -o $migrate_dir/dir_${i}/f 10 ||
@@ -12595,36 +12597,38 @@ test_230c() {
        local MDTIDX=1
        local mdt_index
        local file
+       local migrate_dir=$DIR/$tdir/migrate_dir
 
        #If migrating directory fails in the middle, all entries of
        #the directory is still accessiable.
-       mkdir -p $DIR/$tdir
-       stat $DIR/$tdir
-       createmany -o $DIR/$tdir/f 10 ||
-               error "create files under ${tdir} failed"
+       test_mkdir $DIR/$tdir
+       test_mkdir -i0 -c1 $migrate_dir
+       stat $migrate_dir
+       createmany -o $migrate_dir/f 10 ||
+               error "create files under ${migrate_dir} failed"
 
        #failed after migrating 5 entries
        #OBD_FAIL_MIGRATE_ENTRIES       0x1801
        do_facet mds1 lctl set_param fail_loc=0x20001801
        do_facet mds1 lctl  set_param fail_val=5
-       local t=$(ls $DIR/$tdir | wc -l)
-       $LFS mv --mdt-index $MDTIDX $DIR/$tdir &&
+       local t=$(ls $migrate_dir | wc -l)
+       $LFS mv --mdt-index $MDTIDX $migrate_dir &&
                error "migrate should fail after 5 entries"
-       local u=$(ls $DIR/$tdir | wc -l)
+       local u=$(ls $migrate_dir | wc -l)
        [ "$u" == "$t" ] || error "$u != $t during migration"
 
-       for file in $(find $DIR/$tdir); do
+       for file in $(find $migrate_dir); do
                stat $file || error "stat $file failed"
        done
 
        do_facet mds1 lctl set_param fail_loc=0
        do_facet mds1 lctl set_param fail_val=0
 
-       $LFS mv -M $MDTIDX $DIR/$tdir ||
+       $LFS mv -M $MDTIDX $migrate_dir ||
                error "migrate open files should failed with open files"
 
        echo "Finish migration, then checking.."
-       for file in $(find $DIR/$tdir); do
+       for file in $(find $migrate_dir); do
                mdt_index=$($LFS getstripe -M $file)
                [ $mdt_index == $MDTIDX ] ||
                        error "$file is not on MDT${MDTIDX}"
@@ -12639,21 +12643,23 @@ test_230d() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        local MDTIDX=1
        local mdt_index
+       local migrate_dir=$DIR/$tdir/migrate_dir
        local i
        local j
 
-       mkdir -p $DIR/$tdir
+       test_mkdir $DIR/$tdir
+       test_mkdir -i0 -c1 $migrate_dir
 
        for ((i=0; i<100; i++)); do
-               mkdir -p $DIR/$tdir/dir_${i}
-               createmany -o $DIR/$tdir/dir_${i}/f 100 ||
+               test_mkdir -i0 -c1 $migrate_dir/dir_${i}
+               createmany -o $migrate_dir/dir_${i}/f 100 ||
                        error "create files under remote dir failed $i"
        done
 
-       $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
+       $LFS mv -M $MDTIDX -v $migrate_dir || error "migrate remote dir error"
 
        echo "Finish migration, then checking.."
-       for file in $(find $DIR/$tdir); do
+       for file in $(find $migrate_dir); do
                mdt_index=$($LFS getstripe -M $file)
                [ $mdt_index == $MDTIDX ] ||
                        error "$file is not on MDT${MDTIDX}"
index d9af277..ee32957 100755 (executable)
@@ -6882,62 +6882,46 @@ generate_logname() {
 
 # make directory on different MDTs
 test_mkdir() {
-       local option
-       local parent
-       local child
        local path
        local p_option
-       local option2
        local stripe_count=2
-       local rc=0
-
-       case $# in
-               1) path=$1;;
-               2) option=$1
-                  path=$2;;
-               3) option=$1
-                  option2=$2
-                  path=$3;;
-               *) error "Only creating single directory is supported";;
-       esac
-
-       child=$(basename $path)
-       parent=$(dirname $path)
+       local stripe_index=-1
+       local OPTIND=1
+
+       while getopts "c:i:p" opt; do
+               case $opt in
+                       c) stripe_count=$OPTARG;;
+                       i) stripe_index=$OPTARG;;
+                       p) p_option="-p";;
+                       \?) error "only support -i -c -p";;
+               esac
+       done
 
-       if [ "$option" == "-p" -o "$option2" == "-p" ]; then
-               if [ -d $parent/$child ]; then
-                       return $rc
-               fi
-               p_option="-p"
-       fi
+       shift $((OPTIND - 1))
+       [ $# -eq 1 ] || error "Only creating single directory is supported"
+       path="$*"
 
-       if [ "${option:0:2}" == "-c" ]; then
-               stripe_count=$(echo $option | sed 's/^-c//')
-       fi
+       if [ "$p_option" == "-p" ]; then
+               local parent=$(dirname $path)
 
-       if [ "${option2:0:2}" == "-c" ]; then
-               stripe_count=$(echo $option2 | sed 's/^-c//')
-       fi
-
-       if [ ! -d ${parent} ]; then
-               if [ "$p_option" == "-p" ]; then
-                       mkdir -p ${parent}
-               else
-                       return 1
-               fi
+               [ -d $path ] && return 0
+               [ ! -d ${parent} ] && mkdir -p ${parent}
        fi
 
        if [ $MDSCOUNT -le 1 ]; then
-               mkdir $p_option $parent/$child || rc=$?
+               mkdir $path
        else
-               local mdt_idx=$($LFS getstripe -M $parent)
                local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
+               local mdt_index
 
-               mdt_idx=$((test_num % MDSCOUNT))
-               echo "striped dir -i$mdt_idx -c$stripe_count $path"
-               $LFS setdirstripe -i$mdt_idx -c$stripe_count $path || rc=$?
+               if [ $stripe_index -eq -1 ]; then
+                       mdt_index=$((test_num % MDSCOUNT))
+               else
+                       mdt_index=$stripe_index
+               fi
+               echo "striped dir -i$mdt_index -c$stripe_count $path"
+               $LFS setdirstripe -i$mdt_index -c$stripe_count $path
        fi
-       return $rc
 }
 
 # find the smallest and not in use file descriptor