Whamcloud - gitweb
LU-7268 scrub: NOT assign LMA for EA inode
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_compat.c
index da016a3..0779f25 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -477,6 +477,8 @@ int osd_obj_map_init(const struct lu_env *env, struct osd_device *dev)
 
        /* prepare structures for MDS */
        rc = osd_mdt_init(env, dev);
+       if (rc)
+               osd_ost_fini(dev);
 
         RETURN(rc);
 }
@@ -561,25 +563,29 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
                GOTO(out, rc);
        }
 
+       /* The EA inode should NOT be in OI, old OI scrub may added
+        * such OI mapping by wrong, replace it. */
+       if (unlikely(osd_is_ea_inode(inode))) {
+               iput(inode);
+               goto update;
+       }
+
        rc = osd_get_lma(info, inode, dentry, lma);
        if (rc == -ENODATA) {
                rc = osd_get_idif(info, inode, dentry, oi_fid);
-               if (rc > 0) {
+               if (rc > 0 || rc == -ENODATA) {
                        oi_fid = NULL;
                        rc = 0;
                }
        }
        iput(inode);
 
-       /* If the OST-object has neither FID-in-LMA nor FID-in-ff, it is
-        * either a crashed object or a uninitialized one. Replace it. */
-       if (rc == -ENODATA || oi_fid == NULL)
-               goto update;
-
        if (rc != 0)
                GOTO(out, rc);
 
-       if (lu_fid_eq(fid, oi_fid)) {
+       /* If the OST-object has neither FID-in-LMA nor FID-in-ff, it is
+        * either a crashed object or a uninitialized one. Replace it. */
+       if (oi_fid != NULL && lu_fid_eq(fid, oi_fid)) {
                CERROR("%s: the FID "DFID" is used by two objects: "
                       "%u/%u %u/%u\n", osd_name(osd), PFID(fid),
                       oi_id->oii_ino, oi_id->oii_gen,
@@ -587,6 +593,45 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
                GOTO(out, rc = -EEXIST);
        }
 
+       if (fid_is_idif(fid) && oi_fid != NULL && fid_is_idif(oi_fid)) {
+               __u32 idx1 = fid_idif_ost_idx(fid);
+               __u32 idx2 = fid_idif_ost_idx(oi_fid);
+               struct ost_id *ostid = &info->oti_ostid;
+               struct lu_fid *tfid = &info->oti_fid3;
+
+               LASSERTF(idx1 == 0 || idx1 == osd->od_index,
+                        "invalid given FID "DFID", not match the "
+                        "device index %u\n", PFID(fid), osd->od_index);
+
+               if (idx1 != idx2) {
+                       if (idx1 == 0 && idx2 == osd->od_index) {
+                               fid_to_ostid(fid, ostid);
+                               ostid_to_fid(tfid, ostid, idx2);
+                               if (lu_fid_eq(tfid, oi_fid)) {
+                                       CERROR("%s: the FID "DFID" is used by "
+                                              "two objects(2): %u/%u %u/%u\n",
+                                              osd_name(osd), PFID(fid),
+                                              oi_id->oii_ino, oi_id->oii_gen,
+                                              id->oii_ino, id->oii_gen);
+
+                                       GOTO(out, rc = -EEXIST);
+                               }
+                       } else if (idx2 == 0 && idx1 == osd->od_index) {
+                               fid_to_ostid(oi_fid, ostid);
+                               ostid_to_fid(tfid, ostid, idx1);
+                               if (lu_fid_eq(tfid, fid)) {
+                                       CERROR("%s: the FID "DFID" is used by "
+                                              "two objects(2): %u/%u %u/%u\n",
+                                              osd_name(osd), PFID(fid),
+                                              oi_id->oii_ino, oi_id->oii_gen,
+                                              id->oii_ino, id->oii_gen);
+
+                                       GOTO(out, rc = -EEXIST);
+                               }
+                       }
+               }
+       }
+
 update:
        /* There may be temporary inconsistency: On one hand, the new
         * object may be referenced by multiple entries, which is out
@@ -667,10 +712,11 @@ static int osd_obj_add_entry(struct osd_thread_info *info,
 
        inode = info->oti_inode;
        if (unlikely(inode == NULL)) {
-               OBD_ALLOC_PTR(inode);
-               if (inode == NULL)
+               struct ldiskfs_inode_info *lii;
+               OBD_ALLOC_PTR(lii);
+               if (lii == NULL)
                        RETURN(-ENOMEM);
-               info->oti_inode = inode;
+               inode = info->oti_inode = &lii->vfs_inode;
        }
 
        inode->i_sb = osd_sb(osd);