Revert to Fedora kernel-2.6.17-1.2187_FC5 patched with vs2.0.2.1; there are too many...
[linux-2.6.git] / fs / hfs / bnode.c
index b47ab42..1e44dcf 100644 (file)
@@ -13,8 +13,6 @@
 
 #include "btree.h"
 
-#define REF_PAGES      0
-
 void hfs_bnode_read(struct hfs_bnode *node, void *buf,
                int off, int len)
 {
@@ -200,7 +198,7 @@ void hfs_bnode_unlink(struct hfs_bnode *node)
 
        // move down?
        if (!node->prev && !node->next) {
-               printk("hfs_btree_del_level\n");
+               printk(KERN_DEBUG "hfs_btree_del_level\n");
        }
        if (!node->parent) {
                tree->root = 0;
@@ -221,7 +219,7 @@ struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *tree, u32 cnid)
        struct hfs_bnode *node;
 
        if (cnid >= tree->node_count) {
-               printk("HFS: request for non-existent node %d in B*Tree\n", cnid);
+               printk(KERN_ERR "hfs: request for non-existent node %d in B*Tree\n", cnid);
                return NULL;
        }
 
@@ -244,7 +242,7 @@ static struct hfs_bnode *__hfs_bnode_create(struct hfs_btree *tree, u32 cnid)
        loff_t off;
 
        if (cnid >= tree->node_count) {
-               printk("HFS: request for non-existent node %d in B*Tree\n", cnid);
+               printk(KERN_ERR "hfs: request for non-existent node %d in B*Tree\n", cnid);
                return NULL;
        }
 
@@ -285,9 +283,11 @@ static struct hfs_bnode *__hfs_bnode_create(struct hfs_btree *tree, u32 cnid)
                page = read_cache_page(mapping, block++, (filler_t *)mapping->a_ops->readpage, NULL);
                if (IS_ERR(page))
                        goto fail;
-#if !REF_PAGES
+               if (PageError(page)) {
+                       page_cache_release(page);
+                       goto fail;
+               }
                page_cache_release(page);
-#endif
                node->page[i] = page;
        }
 
@@ -306,8 +306,7 @@ void hfs_bnode_unhash(struct hfs_bnode *node)
        for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)];
             *p && *p != node; p = &(*p)->next_hash)
                ;
-       if (!*p)
-               BUG();
+       BUG_ON(!*p);
        *p = node->next_hash;
        node->tree->node_hash_cnt--;
 }
@@ -326,12 +325,16 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num)
                hfs_bnode_get(node);
                spin_unlock(&tree->hash_lock);
                wait_event(node->lock_wq, !test_bit(HFS_BNODE_NEW, &node->flags));
+               if (test_bit(HFS_BNODE_ERROR, &node->flags))
+                       goto node_error;
                return node;
        }
        spin_unlock(&tree->hash_lock);
        node = __hfs_bnode_create(tree, num);
        if (!node)
                return ERR_PTR(-ENOMEM);
+       if (test_bit(HFS_BNODE_ERROR, &node->flags))
+               goto node_error;
        if (!test_bit(HFS_BNODE_NEW, &node->flags))
                return node;
 
@@ -411,11 +414,14 @@ struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num)
        spin_lock(&tree->hash_lock);
        node = hfs_bnode_findhash(tree, num);
        spin_unlock(&tree->hash_lock);
-       if (node)
-               BUG();
+       BUG_ON(node);
        node = __hfs_bnode_create(tree, num);
        if (!node)
                return ERR_PTR(-ENOMEM);
+       if (test_bit(HFS_BNODE_ERROR, &node->flags)) {
+               hfs_bnode_put(node);
+               return ERR_PTR(-EIO);
+       }
 
        pagep = node->page;
        memset(kmap(*pagep) + node->page_offset, 0,
@@ -437,13 +443,6 @@ void hfs_bnode_get(struct hfs_bnode *node)
 {
        if (node) {
                atomic_inc(&node->refcnt);
-#if REF_PAGES
-               {
-               int i;
-               for (i = 0; i < node->tree->pages_per_bnode; i++)
-                       get_page(node->page[i]);
-               }
-#endif
                dprint(DBG_BNODE_REFS, "get_node(%d:%d): %d\n",
                       node->tree->cnid, node->this, atomic_read(&node->refcnt));
        }
@@ -458,20 +457,13 @@ void hfs_bnode_put(struct hfs_bnode *node)
 
                dprint(DBG_BNODE_REFS, "put_node(%d:%d): %d\n",
                       node->tree->cnid, node->this, atomic_read(&node->refcnt));
-               if (!atomic_read(&node->refcnt))
-                       BUG();
-               if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock)) {
-#if REF_PAGES
-                       for (i = 0; i < tree->pages_per_bnode; i++)
-                               put_page(node->page[i]);
-#endif
+               BUG_ON(!atomic_read(&node->refcnt));
+               if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock))
                        return;
-               }
                for (i = 0; i < tree->pages_per_bnode; i++) {
+                       if (!node->page[i])
+                               continue;
                        mark_page_accessed(node->page[i]);
-#if REF_PAGES
-                       put_page(node->page[i]);
-#endif
                }
 
                if (test_bit(HFS_BNODE_DELETED, &node->flags)) {