Whamcloud - gitweb
LU-11376 lmv: new foreign LMV format
[fs/lustre-release.git] / lustre / llite / llite_lib.c
index 273af31..da0db39 100644 (file)
@@ -1412,8 +1412,12 @@ static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
        /*
         * if dir layout mismatch, check whether version is increased, which
         * means layout is changed, this happens in dir migration and lfsck.
+        *
+        * foreign LMV should not change.
         */
-       if (lli->lli_lsm_md && !lsm_md_eq(lli->lli_lsm_md, lsm)) {
+       if (lli->lli_lsm_md &&
+           lli->lli_lsm_md->lsm_md_magic != LMV_MAGIC_FOREIGN &&
+          !lsm_md_eq(lli->lli_lsm_md, lsm)) {
                if (lsm->lsm_md_layout_version <=
                    lli->lli_lsm_md->lsm_md_layout_version) {
                        CERROR("%s: "DFID" dir layout mismatch:\n",
@@ -1434,6 +1438,15 @@ static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
        if (!lli->lli_lsm_md) {
                struct cl_attr  *attr;
 
+               if (lsm->lsm_md_magic == LMV_MAGIC_FOREIGN) {
+                       /* set md->lmv to NULL, so the following free lustre_md
+                        * will not free this lsm */
+                       md->lmv = NULL;
+                       lli->lli_lsm_md = lsm;
+                       up_write(&lli->lli_lsm_sem);
+                       RETURN(0);
+               }
+
                rc = ll_init_lsm_md(inode, md);
                up_write(&lli->lli_lsm_sem);
                if (rc != 0)
@@ -2396,7 +2409,7 @@ int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
        rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
                              sbi->ll_md_exp, &md);
        if (rc != 0)
-               GOTO(cleanup, rc);
+               GOTO(out, rc);
 
        if (*inode) {
                rc = ll_update_inode(*inode, &md);
@@ -2464,9 +2477,9 @@ int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
        GOTO(out, rc = 0);
 
 out:
+       /* cleanup will be done if necessary */
        md_free_lustre_md(sbi->ll_md_exp, &md);
 
-cleanup:
        if (rc != 0 && it != NULL && it->it_op & IT_OPEN)
                ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, req);