Btrfs: Include the device in most error printk()s
[linux-2.6-block.git] / fs / btrfs / inode.c
index ca1b767d51f760672f8de72c48efbf3df8e58a75..84f056e5d3db3a8fe90ddf8aae2c240adc78fe5b 100644 (file)
@@ -353,6 +353,7 @@ static noinline int compress_file_range(struct inode *inode,
        int i;
        int will_compress;
        int compress_type = root->fs_info->compress_type;
+       int redirty = 0;
 
        /* if this is a small write inside eof, kick off a defrag */
        if ((end - start + 1) < 16 * 1024 &&
@@ -415,6 +416,17 @@ again:
                if (BTRFS_I(inode)->force_compress)
                        compress_type = BTRFS_I(inode)->force_compress;
 
+               /*
+                * we need to call clear_page_dirty_for_io on each
+                * page in the range.  Otherwise applications with the file
+                * mmap'd can wander in and change the page contents while
+                * we are compressing them.
+                *
+                * If the compression fails for any reason, we set the pages
+                * dirty again later on.
+                */
+               extent_range_clear_dirty_for_io(inode, start, end);
+               redirty = 1;
                ret = btrfs_compress_pages(compress_type,
                                           inode->i_mapping, start,
                                           total_compressed, pages,
@@ -554,6 +566,8 @@ cleanup_and_bail_uncompressed:
                        __set_page_dirty_nobuffers(locked_page);
                        /* unlocked later on in the async handlers */
                }
+               if (redirty)
+                       extent_range_redirty_for_io(inode, start, end);
                add_async_extent(async_cow, start, end - start + 1,
                                 0, NULL, 0, BTRFS_COMPRESS_NONE);
                *num_added += 1;
@@ -1743,8 +1757,10 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
        struct btrfs_ordered_sum *sum;
 
        list_for_each_entry(sum, list, list) {
+               trans->adding_csums = 1;
                btrfs_csum_file_blocks(trans,
                       BTRFS_I(inode)->root->fs_info->csum_root, sum);
+               trans->adding_csums = 0;
        }
        return 0;
 }
@@ -2777,6 +2793,8 @@ static int btrfs_readpage_end_io_hook(struct page *page, u64 start, u64 end,
        int ret;
        struct btrfs_root *root = BTRFS_I(inode)->root;
        u32 csum = ~(u32)0;
+       static DEFINE_RATELIMIT_STATE(_rs, DEFAULT_RATELIMIT_INTERVAL,
+                                     DEFAULT_RATELIMIT_BURST);
 
        if (PageChecked(page)) {
                ClearPageChecked(page);
@@ -2803,7 +2821,7 @@ static int btrfs_readpage_end_io_hook(struct page *page, u64 start, u64 end,
        if (ret)
                goto zeroit;
 
-       csum = btrfs_csum_data(root, kaddr + offset, csum,  end - start + 1);
+       csum = btrfs_csum_data(kaddr + offset, csum,  end - start + 1);
        btrfs_csum_final(csum, (char *)&csum);
        if (csum != private)
                goto zeroit;
@@ -2813,11 +2831,11 @@ good:
        return 0;
 
 zeroit:
-       printk_ratelimited(KERN_INFO "btrfs csum failed ino %llu off %llu csum %u "
-                      "private %llu\n",
-                      (unsigned long long)btrfs_ino(page->mapping->host),
-                      (unsigned long long)start, csum,
-                      (unsigned long long)private);
+       if (__ratelimit(&_rs))
+               btrfs_info(root->fs_info, "csum failed ino %llu off %llu csum %u private %llu",
+                       (unsigned long long)btrfs_ino(page->mapping->host),
+                       (unsigned long long)start, csum,
+                       (unsigned long long)private);
        memset(kaddr + offset, 1, end - start + 1);
        flush_dcache_page(page);
        kunmap_atomic(kaddr);
@@ -3098,8 +3116,8 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
                 */
 
                if (found_key.offset == last_objectid) {
-                       printk(KERN_ERR "btrfs: Error removing orphan entry, "
-                              "stopping orphan cleanup\n");
+                       btrfs_err(root->fs_info,
+                               "Error removing orphan entry, stopping orphan cleanup");
                        ret = -EINVAL;
                        goto out;
                }
@@ -3156,8 +3174,8 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
                                ret = PTR_ERR(trans);
                                goto out;
                        }
-                       printk(KERN_ERR "auto deleting %Lu\n",
-                              found_key.objectid);
+                       btrfs_debug(root->fs_info, "auto deleting %Lu",
+                               found_key.objectid);
                        ret = btrfs_del_orphan_item(trans, root,
                                                    found_key.objectid);
                        BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */
@@ -3221,13 +3239,14 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
        }
 
        if (nr_unlink)
-               printk(KERN_INFO "btrfs: unlinked %d orphans\n", nr_unlink);
+               btrfs_info(root->fs_info, "unlinked %d orphans", nr_unlink);
        if (nr_truncate)
-               printk(KERN_INFO "btrfs: truncated %d orphans\n", nr_truncate);
+               btrfs_info(root->fs_info, "truncated %d orphans", nr_truncate);
 
 out:
        if (ret)
-               printk(KERN_CRIT "btrfs: could not do orphan cleanup %d\n", ret);
+               btrfs_crit(root->fs_info,
+                       "could not do orphan cleanup %d", ret);
        btrfs_free_path(path);
        return ret;
 }
@@ -3575,9 +3594,10 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans,
        ret = btrfs_del_inode_ref(trans, root, name, name_len, ino,
                                  dir_ino, &index);
        if (ret) {
-               printk(KERN_INFO "btrfs failed to delete reference to %.*s, "
-                      "inode %llu parent %llu\n", name_len, name,
-                      (unsigned long long)ino, (unsigned long long)dir_ino);
+               btrfs_info(root->fs_info,
+                       "failed to delete reference to %.*s, inode %llu parent %llu",
+                       name_len, name,
+                       (unsigned long long)ino, (unsigned long long)dir_ino);
                btrfs_abort_transaction(trans, root, ret);
                goto err;
        }
@@ -3644,7 +3664,7 @@ static int check_path_shared(struct btrfs_root *root,
                eb = path->nodes[level];
                if (!btrfs_block_can_be_shared(root, eb))
                        continue;
-               ret = btrfs_lookup_extent_info(NULL, root, eb->start, eb->len,
+               ret = btrfs_lookup_extent_info(NULL, root, eb->start, level, 1,
                                               &refs, NULL);
                if (refs > 1)
                        return 1;
@@ -3679,11 +3699,9 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir,
         * 1 for the dir item
         * 1 for the dir index
         * 1 for the inode ref
-        * 1 for the inode ref in the tree log
-        * 2 for the dir entries in the log
         * 1 for the inode
         */
-       trans = btrfs_start_transaction(root, 8);
+       trans = btrfs_start_transaction(root, 5);
        if (!IS_ERR(trans) || PTR_ERR(trans) != -ENOSPC)
                return trans;
 
@@ -4656,8 +4674,9 @@ void btrfs_evict_inode(struct inode *inode)
                        ret = btrfs_block_rsv_migrate(global_rsv, rsv, min_size);
 
                if (ret) {
-                       printk(KERN_WARNING "Could not get space for a "
-                              "delete, will truncate on mount %d\n", ret);
+                       btrfs_warn(root->fs_info,
+                               "Could not get space for a delete, will truncate on mount %d",
+                               ret);
                        btrfs_orphan_del(NULL, inode);
                        btrfs_free_block_rsv(root, rsv);
                        goto no_delete;
@@ -6245,11 +6264,11 @@ not_found_em:
 insert:
        btrfs_release_path(path);
        if (em->start > start || extent_map_end(em) <= start) {
-               printk(KERN_ERR "Btrfs: bad extent! em: [%llu %llu] passed "
-                      "[%llu %llu]\n", (unsigned long long)em->start,
-                      (unsigned long long)em->len,
-                      (unsigned long long)start,
-                      (unsigned long long)len);
+               btrfs_err(root->fs_info, "bad extent! em: [%llu %llu] passed [%llu %llu]",
+                       (unsigned long long)em->start,
+                       (unsigned long long)em->len,
+                       (unsigned long long)start,
+                       (unsigned long long)len);
                err = -EIO;
                goto out;
        }
@@ -6922,7 +6941,7 @@ static void btrfs_endio_direct_read(struct bio *bio, int err)
                                goto failed;
                        local_irq_save(flags);
                        kaddr = kmap_atomic(page);
-                       csum = btrfs_csum_data(root, kaddr + bvec->bv_offset,
+                       csum = btrfs_csum_data(kaddr + bvec->bv_offset,
                                               csum, bvec->bv_len);
                        btrfs_csum_final(csum, (char *)&csum);
                        kunmap_atomic(kaddr);
@@ -6931,11 +6950,10 @@ static void btrfs_endio_direct_read(struct bio *bio, int err)
                        flush_dcache_page(bvec->bv_page);
                        if (csum != private) {
 failed:
-                               printk(KERN_ERR "btrfs csum failed ino %llu off"
-                                     " %llu csum %u private %u\n",
-                                     (unsigned long long)btrfs_ino(inode),
-                                     (unsigned long long)start,
-                                     csum, (unsigned)private);
+                               btrfs_err(root->fs_info, "csum failed ino %llu off %llu csum %u private %u",
+                                       (unsigned long long)btrfs_ino(inode),
+                                       (unsigned long long)start,
+                                       csum, (unsigned)private);
                                err = -EIO;
                        }
                }
@@ -7927,8 +7945,8 @@ void btrfs_destroy_inode(struct inode *inode)
 
        if (test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
                     &BTRFS_I(inode)->runtime_flags)) {
-               printk(KERN_INFO "BTRFS: inode %llu still on the orphan list\n",
-                      (unsigned long long)btrfs_ino(inode));
+               btrfs_info(root->fs_info, "inode %llu still on the orphan list",
+                       (unsigned long long)btrfs_ino(inode));
                atomic_dec(&root->orphan_inodes);
        }
 
@@ -7937,10 +7955,9 @@ void btrfs_destroy_inode(struct inode *inode)
                if (!ordered)
                        break;
                else {
-                       printk(KERN_ERR "btrfs found ordered "
-                              "extent %llu %llu on inode cleanup\n",
-                              (unsigned long long)ordered->file_offset,
-                              (unsigned long long)ordered->len);
+                       btrfs_err(root->fs_info, "found ordered extent %llu %llu on inode cleanup",
+                               (unsigned long long)ordered->file_offset,
+                               (unsigned long long)ordered->len);
                        btrfs_remove_ordered_extent(inode, ordered);
                        btrfs_put_ordered_extent(ordered);
                        btrfs_put_ordered_extent(ordered);
@@ -8127,7 +8144,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
         * inodes.  So 5 * 2 is 10, plus 1 for the new link, so 11 total items
         * should cover the worst case number of items we'll modify.
         */
-       trans = btrfs_start_transaction(root, 20);
+       trans = btrfs_start_transaction(root, 11);
        if (IS_ERR(trans)) {
                 ret = PTR_ERR(trans);
                 goto out_notrans;