Whamcloud - gitweb
LU-6824 ldiskfs: give warning with dir htree growing
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_compat.c
index 235fb0e..d58b6c8 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/
@@ -225,6 +225,7 @@ int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd,
        struct osd_thread_info  *oti = osd_oti_get(env);
        struct lustre_mdt_attrs *lma = &oti->oti_mdt_attrs;
        char                    *name = oti->oti_name;
+       struct osd_thread_info  *info = osd_oti_get(env);
        struct dentry           *dentry;
        struct dentry           *parent;
        int                     rc;
@@ -247,8 +248,8 @@ int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd,
        dentry = osd_child_dentry_by_inode(env, parent->d_inode,
                                           name, strlen(name));
        mutex_lock(&parent->d_inode->i_mutex);
-       rc = osd_ldiskfs_add_entry(oh->ot_handle, dentry, obj->oo_inode,
-                                  NULL);
+       rc = osd_ldiskfs_add_entry(info, oh->ot_handle, dentry,
+                                  obj->oo_inode, NULL);
        CDEBUG(D_INODE, "%s: add %s:%lu to remote parent %lu.\n", osd_name(osd),
               name, obj->oo_inode->i_ino, parent->d_inode->i_ino);
        ldiskfs_inc_count(oh->ot_handle, parent->d_inode);
@@ -369,10 +370,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 +384,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 +392,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 +405,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 +478,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 +564,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 +594,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
@@ -666,10 +713,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);
@@ -688,7 +736,7 @@ static int osd_obj_add_entry(struct osd_thread_info *info,
 
        ll_vfs_dq_init(dir->d_inode);
        mutex_lock(&dir->d_inode->i_mutex);
-       rc = osd_ldiskfs_add_entry(th, child, inode, NULL);
+       rc = osd_ldiskfs_add_entry(info, th, child, inode, NULL);
        mutex_unlock(&dir->d_inode->i_mutex);
 
        RETURN(rc);
@@ -1132,7 +1180,7 @@ int osd_obj_map_recover(struct osd_thread_info *info,
        if (rc != 0)
                GOTO(unlock, rc);
 
-       rc = osd_ldiskfs_add_entry(jh, tgt_child, inode, NULL);
+       rc = osd_ldiskfs_add_entry(info, jh, tgt_child, inode, NULL);
 
        GOTO(unlock, rc);