Whamcloud - gitweb
LU-7268 scrub: NOT assign LMA for EA inode
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_compat.c
index 9e0c0d7..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/
@@ -369,10 +369,8 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
 
        /* to get subdir count from last_rcvd */
        rc = osd_last_rcvd_subdir_count(dev);
-       if (rc < 0) {
-               OBD_FREE_PTR(dev->od_ost_map);
-               RETURN(rc);
-       }
+       if (rc < 0)
+               GOTO(cleanup_alloc, rc);
 
        dev->od_ost_map->om_subdir_count = rc;
         rc = 0;
@@ -385,7 +383,7 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
 
        d = ll_lookup_one_len("O", rootd, strlen("O"));
        if (IS_ERR(d))
-               GOTO(cleanup, rc = PTR_ERR(d));
+               GOTO(cleanup_ctxt, rc = PTR_ERR(d));
        if (d->d_inode == NULL) {
                dput(d);
                /* The lookup() may be called again inside simple_mkdir().
@@ -393,7 +391,7 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
                 * mount time, it will not affect the whole performance. */
                d = simple_mkdir(rootd, dev->od_mnt, "O", 0755, 1);
                if (IS_ERR(d))
-                       GOTO(cleanup, rc = PTR_ERR(d));
+                       GOTO(cleanup_ctxt, rc = PTR_ERR(d));
 
                /* It is quite probably that the device is new formatted. */
                dev->od_maybe_new = 1;
@@ -406,16 +404,19 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
         * has no OI mapping, and only is visible inside the OSD.*/
        lu_igif_build(fid, inode->i_ino, inode->i_generation);
        rc = osd_ea_fid_set(info, inode, fid,
-                           LMAC_NOT_IN_OI | LMAC_FID_ON_OST, 0);
+                   LMAC_NOT_IN_OI | LMAC_FID_ON_OST, 0);
+       if (rc)
+               GOTO(cleanup_dentry, rc);
 
-       GOTO(cleanup, rc);
+       pop_ctxt(&save, &new);
+       RETURN(0);
 
-cleanup:
+cleanup_dentry:
+       dput(d);
+cleanup_ctxt:
        pop_ctxt(&save, &new);
-        if (IS_ERR(d)) {
-                OBD_FREE_PTR(dev->od_ost_map);
-                RETURN(PTR_ERR(d));
-        }
+cleanup_alloc:
+       OBD_FREE_PTR(dev->od_ost_map);
        return rc;
 }
 
@@ -476,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);
 }
@@ -560,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,
@@ -586,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
@@ -664,7 +710,15 @@ static int osd_obj_add_entry(struct osd_thread_info *info,
        LASSERT(th != NULL);
        LASSERT(th->h_transaction != NULL);
 
-       inode = &info->oti_inode;
+       inode = info->oti_inode;
+       if (unlikely(inode == NULL)) {
+               struct ldiskfs_inode_info *lii;
+               OBD_ALLOC_PTR(lii);
+               if (lii == NULL)
+                       RETURN(-ENOMEM);
+               inode = info->oti_inode = &lii->vfs_inode;
+       }
+
        inode->i_sb = osd_sb(osd);
        osd_id_to_inode(inode, id);
        inode->i_mode = S_IFREG; /* for type in ldiskfs dir entry */