Whamcloud - gitweb
LU-6866 hsm: prevent migration of HSM archived files 11/17511/3
authorJohn L. Hammond <john.hammond@intel.com>
Tue, 8 Dec 2015 17:23:44 +0000 (11:23 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 18 Dec 2015 05:28:09 +0000 (05:28 +0000)
The reference copytool cannot handle migration of HSM archive
files. In the MDT migration path check for HSM attributes and fail if
they are present. In the LMV layer allow creation of volatile files
with any MDT index. Add a test to sanity-hsm to ensure that attempting
to migrate an HSM archive file is handled safely.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: Ia133bfb345ce17473f54bd9a0ea0fbff5e5a5c58
Reviewed-on: http://review.whamcloud.com/17511
Tested-by: Jenkins
Reviewed-by: wangdi <di.wang@intel.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/lmv/lmv_obd.c
lustre/mdt/mdt_reint.c
lustre/tests/sanity-hsm.sh

index 6ad6aba..3cde2fd 100644 (file)
@@ -1742,26 +1742,27 @@ lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
         * index if the file under striped dir is being restored, see
         * ct_restore(). */
        if (op_data->op_bias & MDS_CREATE_VOLATILE &&
-           (int)op_data->op_mds != -1 && lsm != NULL) {
+           (int)op_data->op_mds != -1) {
                int i;
                tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
                if (IS_ERR(tgt))
                        return tgt;
 
-               /* refill the right parent fid */
-               for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
-                       struct lmv_oinfo *oinfo;
+               if (lsm != NULL) {
+                       /* refill the right parent fid */
+                       for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
+                               struct lmv_oinfo *oinfo;
 
-                       oinfo = &lsm->lsm_md_oinfo[i];
-                       if (oinfo->lmo_mds == op_data->op_mds) {
-                               *fid = oinfo->lmo_fid;
-                               break;
+                               oinfo = &lsm->lsm_md_oinfo[i];
+                               if (oinfo->lmo_mds == op_data->op_mds) {
+                                       *fid = oinfo->lmo_fid;
+                                       break;
+                               }
                        }
-               }
 
-               /* Hmm, can not find the stripe by mdt_index(op_mds) */
-               if (i == lsm->lsm_md_stripe_count)
-                       tgt = ERR_PTR(-EINVAL);
+                       if (i == lsm->lsm_md_stripe_count)
+                               *fid = lsm->lsm_md_oinfo[0].lmo_fid;
+               }
 
                return tgt;
        }
index 3413ebd..2ad5259 100644 (file)
@@ -1547,6 +1547,20 @@ out_lease:
        if (rc != 0)
                GOTO(out_unlock_child, rc);
 
+       /* Migration is incompatible with HSM. */
+       ma->ma_need = MA_HSM;
+       ma->ma_valid = 0;
+       rc = mdt_attr_get_complex(info, mold, ma);
+       if (rc != 0)
+               GOTO(out_unlock_child, rc);
+
+       if ((ma->ma_valid & MA_HSM) && ma->ma_hsm.mh_flags != 0) {
+               rc = -ENOSYS;
+               CERROR("%s: cannot migrate HSM archived file "DFID": rc = %d\n",
+                      mdt_obd_name(info->mti_mdt), PFID(old_fid), rc);
+               GOTO(out_unlock_child, rc);
+       }
+
        ma->ma_need = MA_LMV;
        ma->ma_valid = 0;
        ma->ma_lmv = (union lmv_mds_md *)info->mti_xattr_buf;
index e9e1b46..c580554 100755 (executable)
@@ -4615,6 +4615,66 @@ test_405() {
 }
 run_test 405 "archive and release under striped directory"
 
+test_406() {
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
+               skip "need MDS version at least 2.7.64" && return 0
+
+       local fid
+       local mdt_index
+
+       copytool_setup
+       mkdir -p $DIR/$tdir
+       fid=$(make_small $DIR/$tdir/$tfile)
+       echo "old fid $fid"
+
+       $LFS hsm_archive $DIR/$tdir/$tfile
+       wait_request_state "$fid" ARCHIVE SUCCEED
+       $LFS hsm_release $DIR/$tdir/$tfile
+
+       # Should migrate $tdir but not $tfile.
+       $LFS mv -M1 $DIR/$tdir &&
+               error "migrating HSM an archived file should fail"
+
+       $LFS hsm_restore $DIR/$tdir/$tfile
+       wait_request_state "$fid" RESTORE SUCCEED
+
+       $LFS hsm_remove $DIR/$tdir/$tfile ||
+               error "cannot remove $DIR/$tdir/$tfile from archive"
+
+       cat $DIR/$tdir/$tfile > /dev/null ||
+               error "cannot read $DIR/$tdir/$tfile"
+
+       $LFS mv -M1 $DIR/$tdir/$tfile ||
+               error "cannot complete migration after HSM remove"
+
+       mdt_index=$($LFS getstripe -M $DIR/$tdir)
+       if ((mdt_index != 1)); then
+               error "expected MDT index 1, got $mdt_index"
+       fi
+
+       # Refresh fid after migration.
+       fid=$(path2fid $DIR/$tdir/$tfile)
+       echo "new fid $fid"
+
+       $LFS hsm_archive $DIR/$tdir/$tfile
+       wait_request_state "$fid" ARCHIVE SUCCEED 1
+
+       lctl set_param debug=+trace
+       $LFS hsm_release $DIR/$tdir/$tfile ||
+               error "cannot release $DIR/$tdir/$tfile"
+
+       $LFS hsm_restore $DIR/$tdir/$tfile
+       wait_request_state "$fid" RESTORE SUCCEED 1
+
+       cat $DIR/$tdir/$tfile > /dev/null ||
+               error "cannot read $DIR/$tdir/$tfile"
+
+       copytool_cleanup
+}
+run_test 406 "attempting to migrate HSM archived files is safe"
+
 test_500()
 {
        [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&