From a857446dc6480841ab1e832970d3958f3962a885 Mon Sep 17 00:00:00 2001 From: Lai Siyao Date: Mon, 22 Oct 2018 06:48:17 +0800 Subject: [PATCH] LU-11642 lmv: allocate fid on parent MDT in migrate During directory migration, if the migrated file is not directory, the target should be allocated on its parent MDT, not user specified MDT. Because if it's parent is striped, this file should be migrated to the MDT by its name hash, not the starting MDT of its parent. Add sanity 230k to check file data not changed after migration. Signed-off-by: Lai Siyao Change-Id: Ic7d3de8ea982b7cf4da758e4d3ab8d8ee15ecfdb Reviewed-on: https://review.whamcloud.com/33641 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Mike Pershin Reviewed-by: Oleg Drokin --- lustre/lmv/lmv_obd.c | 5 ++++- lustre/tests/sanity.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 090f3b1..329965e 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -2006,7 +2006,10 @@ static int lmv_migrate(struct obd_export *exp, struct md_op_data *op_data, if (IS_ERR(child_tgt)) RETURN(PTR_ERR(child_tgt)); - rc = lmv_fid_alloc(NULL, exp, &target_fid, op_data); + if (!S_ISDIR(op_data->op_mode) && tp_tgt) + rc = __lmv_fid_alloc(lmv, &target_fid, tp_tgt->ltd_idx); + else + rc = lmv_fid_alloc(NULL, exp, &target_fid, op_data); if (rc) RETURN(rc); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 18ad4eb..7e9c572 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -15468,6 +15468,56 @@ test_230j() { } run_test 230j "DoM file data not changed after dir migration" +test_230k() { + [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" + [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] && + skip "Need MDS version at least 2.11.56" + + local total=20 + local files_on_starting_mdt=0 + + $LFS mkdir -i -1 -c 2 $DIR/$tdir || error "mkdir failed" + $LFS getdirstripe $DIR/$tdir + for i in $(seq $total); do + echo $((i*i - i)) > $DIR/$tdir/$tfile.$i || error "write failed" + [[ $($LFS getstripe -m $DIR/$tdir/$tfile.$i) -eq 0 ]] && + files_on_starting_mdt=$((files_on_starting_mdt + 1)) + done + + echo "$files_on_starting_mdt files on MDT0" + + $LFS migrate -m 1,3 $DIR/$tdir || error "migrate -m 1,3 failed" + $LFS getdirstripe $DIR/$tdir + + files_on_starting_mdt=0 + for i in $(seq $total); do + $(echo $((i*i - i)) | cmp $DIR/$tdir/$tfile.$i -) || + error "file $tfile.$i mismatch after migration" + [[ $($LFS getstripe -m $DIR/$tdir/$tfile.$i) -eq 1 ]] && + files_on_starting_mdt=$((files_on_starting_mdt + 1)) + done + + echo "$files_on_starting_mdt files on MDT1 after migration" + [[ $files_on_starting_mdt -eq $total ]] && error "all files on MDT1" + + $LFS migrate -m 0 -c 2 $DIR/$tdir || error "migrate -m 0 -c 2 failed" + $LFS getdirstripe $DIR/$tdir + + files_on_starting_mdt=0 + for i in $(seq $total); do + $(echo $((i*i - i)) | cmp $DIR/$tdir/$tfile.$i -) || + error "file $tfile.$i mismatch after 2nd migration" + [[ $($LFS getstripe -m $DIR/$tdir/$tfile.$i) -eq 0 ]] && + files_on_starting_mdt=$((files_on_starting_mdt + 1)) + done + + echo "$files_on_starting_mdt files on MDT0 after 2nd migration" + [[ $files_on_starting_mdt -eq $total ]] && error "all files on MDT0" + + true +} +run_test 230k "file data not changed after dir migration" + test_231a() { # For simplicity this test assumes that max_pages_per_rpc -- 1.8.3.1