Whamcloud - gitweb
LU-9167 hsm: use a new environment during HSM purge
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_iam.c
index 2c2ff27..bf217eb 100644 (file)
  * in the LICENSE file that accompanied this code).
  *
  * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see [sun.com URL with a
- * copy of GPLv2].
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -174,20 +170,21 @@ iam_load_idle_blocks(struct iam_container *c, iam_ptr_t blk)
        struct inode *inode = c->ic_object;
        struct iam_idle_head *head;
        struct buffer_head *bh;
-       int err = 0;
 
        LASSERT(mutex_is_locked(&c->ic_idle_mutex));
 
        if (blk == 0)
                return NULL;
 
-       bh = ldiskfs_bread(NULL, inode, blk, 0, &err);
-       if (bh == NULL) {
-               CERROR("%.16s: cannot load idle blocks, blk = %u, err = %d\n",
-                      LDISKFS_SB(inode->i_sb)->s_es->s_volume_name, blk, err);
+       bh = __ldiskfs_bread(NULL, inode, blk, 0);
+       if (IS_ERR_OR_NULL(bh)) {
+               CERROR("%.16s: cannot load idle blocks, blk = %u, err = %ld\n",
+                      LDISKFS_SB(inode->i_sb)->s_es->s_volume_name, blk,
+                      bh ? PTR_ERR(bh) : -EIO);
                c->ic_idle_failed = 1;
-               err = err ? err : -EIO;
-               return ERR_PTR(err);
+               if (bh == NULL)
+                       bh = ERR_PTR(-EIO);
+               return bh;
        }
 
        head = (struct iam_idle_head *)(bh->b_data);
@@ -359,8 +356,6 @@ void iam_ipd_free(struct iam_path_descr *ipd)
 int iam_node_read(struct iam_container *c, iam_ptr_t ptr,
                   handle_t *h, struct buffer_head **bh)
 {
-        int result = 0;
-
         /* NB: it can be called by iam_lfix_guess() which is still at
          * very early stage, c->ic_root_bh and c->ic_descr->id_ops
          * haven't been intialized yet.
@@ -373,10 +368,14 @@ int iam_node_read(struct iam_container *c, iam_ptr_t ptr,
                 return 0;
         }
 
-        *bh = ldiskfs_bread(h, c->ic_object, (int)ptr, 0, &result);
-        if (*bh == NULL)
-               result = result ? result : -EIO;
-        return result;
+       *bh = __ldiskfs_bread(h, c->ic_object, (int)ptr, 0);
+       if (IS_ERR(*bh))
+               return PTR_ERR(*bh);
+
+       if (*bh == NULL)
+               return -EIO;
+
+       return 0;
 }
 
 /*
@@ -424,32 +423,31 @@ static int iam_leaf_keyeq(const struct iam_leaf *leaf,
 }
 
 #if LDISKFS_INVARIANT_ON
-static int iam_leaf_check(struct iam_leaf *leaf);
 extern int dx_node_check(struct iam_path *p, struct iam_frame *f);
 
 static int iam_path_check(struct iam_path *p)
 {
-        int i;
-        int result;
-        struct iam_frame *f;
-        struct iam_descr *param;
+       int i;
+       int result;
+       struct iam_frame *f;
+       struct iam_descr *param;
+
+       result = 1;
+       param = iam_path_descr(p);
+       for (i = 0; result && i < ARRAY_SIZE(p->ip_frames); ++i) {
+               f = &p->ip_frames[i];
+               if (f->bh != NULL) {
+                       result = dx_node_check(p, f);
+                       if (result)
+                               result = !param->id_ops->id_node_check(p, f);
+               }
+       }
+       if (result && p->ip_leaf.il_bh != NULL)
+               result = 1;
+       if (result == 0)
+               ldiskfs_std_error(iam_path_obj(p)->i_sb, result);
 
-        result = 1;
-        param = iam_path_descr(p);
-        for (i = 0; result && i < ARRAY_SIZE(p->ip_frames); ++i) {
-                f = &p->ip_frames[i];
-                if (f->bh != NULL) {
-                        result = dx_node_check(p, f);
-                        if (result)
-                                result = !param->id_ops->id_node_check(p, f);
-                }
-        }
-        if (result && p->ip_leaf.il_bh != NULL)
-                result = iam_leaf_check(&p->ip_leaf);
-        if (result == 0) {
-                ldiskfs_std_error(iam_path_obj(p)->i_sb, result);
-        }
-        return result;
+       return result;
 }
 #endif
 
@@ -479,7 +477,6 @@ static int iam_leaf_load(struct iam_path *path)
                leaf->il_bh = bh;
                leaf->il_curidx = block;
                err = iam_leaf_ops(leaf)->init(leaf);
-               assert_inv(ergo(err == 0, iam_leaf_check(leaf)));
        }
        return err;
 }
@@ -506,7 +503,6 @@ static void iam_leaf_fini(struct iam_leaf *leaf)
 {
         if (leaf->il_path != NULL) {
                 iam_leaf_unlock(leaf);
-                assert_inv(ergo(leaf->il_bh != NULL, iam_leaf_check(leaf)));
                 iam_leaf_ops(leaf)->fini(leaf);
                 if (leaf->il_bh) {
                         brelse(leaf->il_bh);
@@ -559,46 +555,6 @@ int iam_leaf_can_add(const struct iam_leaf *l,
         return iam_leaf_ops(l)->can_add(l, k, r);
 }
 
-#if LDISKFS_INVARIANT_ON
-static int iam_leaf_check(struct iam_leaf *leaf)
-{
-        return 1;
-#if 0
-        struct iam_lentry    *orig;
-        struct iam_path      *path;
-        struct iam_container *bag;
-        struct iam_ikey       *k0;
-        struct iam_ikey       *k1;
-        int result;
-        int first;
-
-        orig = leaf->il_at;
-        path = iam_leaf_path(leaf);
-        bag  = iam_leaf_container(leaf);
-
-        result = iam_leaf_ops(leaf)->init(leaf);
-        if (result != 0)
-                return result;
-
-        first = 1;
-        iam_leaf_start(leaf);
-        k0 = iam_path_ikey(path, 0);
-        k1 = iam_path_ikey(path, 1);
-        while (!iam_leaf_at_end(leaf)) {
-                iam_ikeycpy(bag, k0, k1);
-                iam_ikeycpy(bag, k1, iam_leaf_ikey(leaf, k1));
-                if (!first && iam_ikeycmp(bag, k0, k1) > 0) {
-                        return 0;
-                }
-                first = 0;
-                iam_leaf_next(leaf);
-        }
-        leaf->il_at = orig;
-        return 1;
-#endif
-}
-#endif
-
 static int iam_txn_dirty(handle_t *handle,
                          struct iam_path *path, struct buffer_head *bh)
 {
@@ -1067,18 +1023,15 @@ static int iam_lookup_lock(struct iam_path *path,
  */
 static int iam_path_lookup(struct iam_path *path, int index)
 {
-        struct iam_container *c;
         struct iam_leaf  *leaf;
         int result;
 
-        c = path->ip_container;
         leaf = &path->ip_leaf;
         result = iam_lookup_lock(path, &leaf->il_lock, DLT_WRITE);
         assert_inv(iam_path_check(path));
         do_corr(schedule());
         if (result == 0) {
                 result = iam_leaf_load(path);
-                assert_inv(ergo(result == 0, iam_leaf_check(leaf)));
                 if (result == 0) {
                         do_corr(schedule());
                         if (index)
@@ -1408,13 +1361,11 @@ int iam_index_next(struct iam_container *c, struct iam_path *path)
         iam_ptr_t cursor;
        struct dynlock_handle *lh[DX_MAX_TREE_HEIGHT] = { NULL, };
         int result;
-        struct inode *object;
 
         /*
          * Locking for iam_index_next()... is to be described.
          */
 
-        object = c->ic_object;
         cursor = path->ip_frame->leaf;
 
         while (1) {
@@ -1676,9 +1627,12 @@ iam_new_node(handle_t *h, struct iam_container *c, iam_ptr_t *b, int *e)
                        goto fail;
 
                mutex_unlock(&c->ic_idle_mutex);
-               bh = ldiskfs_bread(NULL, inode, *b, 0, e);
-               if (bh == NULL) {
-                       *e = *e ? *e : -EIO;
+               bh = __ldiskfs_bread(NULL, inode, *b, 0);
+               if (IS_ERR_OR_NULL(bh)) {
+                       if (IS_ERR(bh))
+                               *e = PTR_ERR(bh);
+                       else
+                               *e = -EIO;
                        return NULL;
                }
                goto got;
@@ -1732,7 +1686,12 @@ got:
        return bh;
 
 newblock:
-       bh = osd_ldiskfs_append(h, inode, b, e);
+       bh = osd_ldiskfs_append(h, inode, b);
+       if (IS_ERR(bh)) {
+               *e = PTR_ERR(bh);
+               bh = NULL;
+       }
+
        return bh;
 
 fail:
@@ -1777,8 +1736,6 @@ static int iam_new_leaf(handle_t *handle, struct iam_leaf *leaf)
         struct inode         *obj;
         struct iam_path      *path;
 
-        assert_inv(iam_leaf_check(leaf));
-
         c = iam_leaf_container(leaf);
         path = leaf->il_path;
 
@@ -1813,8 +1770,6 @@ static int iam_new_leaf(handle_t *handle, struct iam_leaf *leaf)
                         err = -ENOMEM;
                brelse(new_leaf);
         }
-        assert_inv(iam_leaf_check(leaf));
-        assert_inv(iam_leaf_check(&iam_leaf_path(leaf)->ip_leaf));
         assert_inv(iam_path_check(iam_leaf_path(leaf)));
         return err;
 }
@@ -2148,7 +2103,6 @@ static int iam_add_rec(handle_t *handle, struct iam_iterator *it,
         struct iam_leaf *leaf;
 
         leaf = &path->ip_leaf;
-        assert_inv(iam_leaf_check(leaf));
         assert_inv(iam_path_check(path));
         err = iam_txn_add(handle, path, leaf->il_bh);
         if (err == 0) {
@@ -2191,8 +2145,6 @@ static int iam_add_rec(handle_t *handle, struct iam_iterator *it,
                         err = iam_txn_dirty(handle, path, leaf->il_bh);
                 }
         }
-        assert_inv(iam_leaf_check(leaf));
-        assert_inv(iam_leaf_check(&path->ip_leaf));
         assert_inv(iam_path_check(path));
         return err;
 }
@@ -2435,7 +2387,6 @@ int iam_it_rec_delete(handle_t *h, struct iam_iterator *it)
         path = &it->ii_path;
         leaf = &path->ip_leaf;
 
-        assert_inv(iam_leaf_check(leaf));
         assert_inv(iam_path_check(path));
 
         result = iam_txn_add(h, path, leaf->il_bh);
@@ -2462,7 +2413,6 @@ int iam_it_rec_delete(handle_t *h, struct iam_iterator *it)
                        }
                }
         }
-        assert_inv(iam_leaf_check(leaf));
         assert_inv(iam_path_check(path));
         assert_corr(it_state(it) == IAM_IT_ATTACHED ||
                     it_state(it) == IAM_IT_DETACHED);