Merge branch 'for-linus-4.9' of git://git.kernel.org/pub/scm/linux/kernel/git/mason...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 11 Oct 2016 18:23:06 +0000 (11:23 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 11 Oct 2016 18:23:06 +0000 (11:23 -0700)
Pull btrfs updates from Chris Mason:
 "This is a big variety of fixes and cleanups.

  Liu Bo continues to fixup fuzzer related problems, and some of Josef's
  cleanups are prep for his bigger extent buffer changes (slated for
  v4.10)"

* 'for-linus-4.9' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (39 commits)
  Revert "btrfs: let btrfs_delete_unused_bgs() to clean relocated bgs"
  Btrfs: remove unnecessary btrfs_mark_buffer_dirty in split_leaf
  Btrfs: don't BUG() during drop snapshot
  btrfs: fix btrfs_no_printk stub helper
  Btrfs: memset to avoid stale content in btree leaf
  btrfs: parent_start initialization cleanup
  btrfs: Remove already completed TODO comment
  btrfs: Do not reassign count in btrfs_run_delayed_refs
  btrfs: fix a possible umount deadlock
  Btrfs: fix memory leak in do_walk_down
  btrfs: btrfs_debug should consume fs_info when DEBUG is not defined
  btrfs: convert send's verbose_printk to btrfs_debug
  btrfs: convert pr_* to btrfs_* where possible
  btrfs: convert printk(KERN_* to use pr_* calls
  btrfs: unsplit printed strings
  btrfs: clean the old superblocks before freeing the device
  Btrfs: kill BUG_ON in run_delayed_tree_ref
  Btrfs: don't leak reloc root nodes on error
  btrfs: squash lines for simple wrapper functions
  Btrfs: improve check_node to avoid reading corrupted nodes
  ...

1  2 
fs/btrfs/ctree.h
fs/btrfs/file.c
fs/btrfs/inode.c
fs/btrfs/ioctl.c
fs/btrfs/send.c
fs/btrfs/transaction.c
fs/btrfs/tree-log.c

diff --combined fs/btrfs/ctree.h
@@@ -37,6 -37,7 +37,7 @@@
  #include <linux/workqueue.h>
  #include <linux/security.h>
  #include <linux/sizes.h>
+ #include <linux/dynamic_debug.h>
  #include "extent_io.h"
  #include "extent_map.h"
  #include "async-thread.h"
@@@ -676,9 -677,25 +677,25 @@@ struct btrfs_device
  struct btrfs_fs_devices;
  struct btrfs_balance_control;
  struct btrfs_delayed_root;
+ #define BTRFS_FS_BARRIER                      1
+ #define BTRFS_FS_CLOSING_START                        2
+ #define BTRFS_FS_CLOSING_DONE                 3
+ #define BTRFS_FS_LOG_RECOVERING                       4
+ #define BTRFS_FS_OPEN                         5
+ #define BTRFS_FS_QUOTA_ENABLED                        6
+ #define BTRFS_FS_QUOTA_ENABLING                       7
+ #define BTRFS_FS_QUOTA_DISABLING              8
+ #define BTRFS_FS_UPDATE_UUID_TREE_GEN         9
+ #define BTRFS_FS_CREATING_FREE_SPACE_TREE     10
+ #define BTRFS_FS_BTREE_ERR                    11
+ #define BTRFS_FS_LOG1_ERR                     12
+ #define BTRFS_FS_LOG2_ERR                     13
  struct btrfs_fs_info {
        u8 fsid[BTRFS_FSID_SIZE];
        u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
+       unsigned long flags;
        struct btrfs_root *extent_root;
        struct btrfs_root *tree_root;
        struct btrfs_root *chunk_root;
        int thread_pool_size;
  
        struct kobject *space_info_kobj;
-       int do_barriers;
-       int closing;
-       int log_root_recovering;
-       int open;
  
        u64 total_pinned;
  
  #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
        u32 check_integrity_print_mask;
  #endif
-       /*
-        * quota information
-        */
-       unsigned int quota_enabled:1;
-       /*
-        * quota_enabled only changes state after a commit. This holds the
-        * next state.
-        */
-       unsigned int pending_quota_state:1;
        /* is qgroup tracking in a consistent state? */
        u64 qgroup_flags;
  
        wait_queue_head_t replace_wait;
  
        struct semaphore uuid_tree_rescan_sem;
-       unsigned int update_uuid_tree_gen:1;
  
        /* Used to reclaim the metadata space in the background. */
        struct work_struct async_reclaim_work;
         */
        struct list_head pinned_chunks;
  
-       int creating_free_space_tree;
        /* Used to record internally whether fs has been frozen */
        int fs_frozen;
  };
@@@ -1435,13 -1435,13 +1435,13 @@@ static inline void btrfs_init_map_toke
  #define cpu_to_le8(v) (v)
  #define __le8 u8
  
- #define read_eb_member(eb, ptr, type, member, result) (                       \
+ #define read_eb_member(eb, ptr, type, member, result) (\
        read_extent_buffer(eb, (char *)(result),                        \
                           ((unsigned long)(ptr)) +                     \
                            offsetof(type, member),                     \
                           sizeof(((type *)0)->member)))
  
- #define write_eb_member(eb, ptr, type, member, result) (              \
+ #define write_eb_member(eb, ptr, type, member, result) (\
        write_extent_buffer(eb, (char *)(result),                       \
                           ((unsigned long)(ptr)) +                     \
                            offsetof(type, member),                     \
@@@ -2293,6 -2293,21 +2293,21 @@@ static inline unsigned long btrfs_leaf_
        return offsetof(struct btrfs_leaf, items);
  }
  
+ /*
+  * The leaf data grows from end-to-front in the node.
+  * this returns the address of the start of the last item,
+  * which is the stop of the leaf data stack
+  */
+ static inline unsigned int leaf_data_end(struct btrfs_root *root,
+                                        struct extent_buffer *leaf)
+ {
+       u32 nr = btrfs_header_nritems(leaf);
+       if (nr == 0)
+               return BTRFS_LEAF_DATA_SIZE(root);
+       return btrfs_item_offset_nr(leaf, nr - 1);
+ }
  /* struct btrfs_file_extent_item */
  BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
  BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr,
@@@ -2867,10 -2882,14 +2882,14 @@@ int btrfs_drop_subtree(struct btrfs_tra
  static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
  {
        /*
-        * Get synced with close_ctree()
+        * Do it this way so we only ever do one test_bit in the normal case.
         */
-       smp_mb();
-       return fs_info->closing;
+       if (test_bit(BTRFS_FS_CLOSING_START, &fs_info->flags)) {
+               if (test_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags))
+                       return 2;
+               return 1;
+       }
+       return 0;
  }
  
  /*
@@@ -3118,7 -3137,7 +3137,7 @@@ int btrfs_start_delalloc_inodes(struct 
  int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int delay_iput,
                               int nr);
  int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end,
-                             struct extent_state **cached_state);
+                             struct extent_state **cached_state, int dedupe);
  int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
                             struct btrfs_root *new_root,
                             struct btrfs_root *parent_root,
@@@ -3161,6 -3180,7 +3180,6 @@@ int btrfs_prealloc_file_range_trans(str
                                    struct btrfs_trans_handle *trans, int mode,
                                    u64 start, u64 num_bytes, u64 min_size,
                                    loff_t actual_len, u64 *alloc_hint);
 -int btrfs_inode_check_errors(struct inode *inode);
  extern const struct dentry_operations btrfs_dentry_operations;
  #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
  void btrfs_test_inode_set_ops(struct inode *inode);
@@@ -3236,14 -3256,17 +3255,17 @@@ int btrfs_parse_options(struct btrfs_ro
                        unsigned long new_flags);
  int btrfs_sync_fs(struct super_block *sb, int wait);
  
+ static inline __printf(2, 3)
+ void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
+ {
+ }
  #ifdef CONFIG_PRINTK
  __printf(2, 3)
  void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
  #else
- static inline __printf(2, 3)
- void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
- {
- }
+ #define btrfs_printk(fs_info, fmt, args...) \
+       btrfs_no_printk(fs_info, fmt, ##args)
  #endif
  
  #define btrfs_emerg(fs_info, fmt, args...) \
        btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
  #define btrfs_info_rl(fs_info, fmt, args...) \
        btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
- #ifdef DEBUG
+ #if defined(CONFIG_DYNAMIC_DEBUG)
+ #define btrfs_debug(fs_info, fmt, args...)                            \
+ do {                                                                  \
+         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);               \
+         if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT))        \
+               btrfs_printk(fs_info, KERN_DEBUG fmt, ##args);          \
+ } while (0)
+ #define btrfs_debug_in_rcu(fs_info, fmt, args...)                     \
+ do {                                                                  \
+         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);               \
+         if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT))                \
+               btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args);   \
+ } while (0)
+ #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...)                  \
+ do {                                                                  \
+         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);               \
+         if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT))        \
+               btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt,         \
+                                      ##args);\
+ } while (0)
+ #define btrfs_debug_rl(fs_info, fmt, args...)                                 \
+ do {                                                                  \
+         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);               \
+         if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT))        \
+               btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt,       \
+                                        ##args);                       \
+ } while (0)
+ #elif defined(DEBUG)
  #define btrfs_debug(fs_info, fmt, args...) \
        btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
  #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
        btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
  #else
  #define btrfs_debug(fs_info, fmt, args...) \
-     no_printk(KERN_DEBUG fmt, ##args)
+       btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
  #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
-       no_printk(KERN_DEBUG fmt, ##args)
+       btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
  #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
-       no_printk(KERN_DEBUG fmt, ##args)
+       btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
  #define btrfs_debug_rl(fs_info, fmt, args...) \
-       no_printk(KERN_DEBUG fmt, ##args)
+       btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
  #endif
  
  #define btrfs_printk_in_rcu(fs_info, fmt, args...)    \
@@@ -3362,7 -3413,7 +3412,7 @@@ do {                                                            
  __cold
  static inline void assfail(char *expr, char *file, int line)
  {
-       pr_err("BTRFS: assertion failed: %s, file: %s, line: %d",
+       pr_err("assertion failed: %s, file: %s, line: %d\n",
               expr, file, line);
        BUG();
  }
diff --combined fs/btrfs/file.c
@@@ -503,7 -503,7 +503,7 @@@ int btrfs_dirty_pages(struct btrfs_roo
  
        end_of_last_block = start_pos + num_bytes - 1;
        err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block,
-                                       cached);
+                                       cached, 0);
        if (err)
                return err;
  
@@@ -1110,13 -1110,25 +1110,25 @@@ again
  
        leaf = path->nodes[0];
        btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
-       BUG_ON(key.objectid != ino || key.type != BTRFS_EXTENT_DATA_KEY);
+       if (key.objectid != ino ||
+           key.type != BTRFS_EXTENT_DATA_KEY) {
+               ret = -EINVAL;
+               btrfs_abort_transaction(trans, ret);
+               goto out;
+       }
        fi = btrfs_item_ptr(leaf, path->slots[0],
                            struct btrfs_file_extent_item);
-       BUG_ON(btrfs_file_extent_type(leaf, fi) !=
-              BTRFS_FILE_EXTENT_PREALLOC);
+       if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_PREALLOC) {
+               ret = -EINVAL;
+               btrfs_abort_transaction(trans, ret);
+               goto out;
+       }
        extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
-       BUG_ON(key.offset > start || extent_end < end);
+       if (key.offset > start || extent_end < end) {
+               ret = -EINVAL;
+               btrfs_abort_transaction(trans, ret);
+               goto out;
+       }
  
        bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
        num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi);
                ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0,
                                           root->root_key.objectid,
                                           ino, orig_offset);
-               BUG_ON(ret); /* -ENOMEM */
+               if (ret) {
+                       btrfs_abort_transaction(trans, ret);
+                       goto out;
+               }
  
                if (split == start) {
                        key.offset = start;
                } else {
-                       BUG_ON(start != key.offset);
+                       if (start != key.offset) {
+                               ret = -EINVAL;
+                               btrfs_abort_transaction(trans, ret);
+                               goto out;
+                       }
                        path->slots[0]--;
                        extent_end = end;
                }
                ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
                                        0, root->root_key.objectid,
                                        ino, orig_offset);
-               BUG_ON(ret); /* -ENOMEM */
+               if (ret) {
+                       btrfs_abort_transaction(trans, ret);
+                       goto out;
+               }
        }
        other_start = 0;
        other_end = start;
                ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
                                        0, root->root_key.objectid,
                                        ino, orig_offset);
-               BUG_ON(ret); /* -ENOMEM */
+               if (ret) {
+                       btrfs_abort_transaction(trans, ret);
+                       goto out;
+               }
        }
        if (del_nr == 0) {
                fi = btrfs_item_ptr(leaf, path->slots[0],
@@@ -1757,7 -1782,7 +1782,7 @@@ static void update_time_for_write(struc
        if (IS_NOCMTIME(inode))
                return;
  
 -      now = current_fs_time(inode->i_sb);
 +      now = current_time(inode);
        if (!timespec_equal(&inode->i_mtime, &now))
                inode->i_mtime = now;
  
@@@ -2040,7 -2065,7 +2065,7 @@@ int btrfs_sync_file(struct file *file, 
                 * flags for any errors that might have happened while doing
                 * writeback of file data.
                 */
 -              ret = btrfs_inode_check_errors(inode);
 +              ret = filemap_check_errors(inode->i_mapping);
                inode_unlock(inode);
                goto out;
        }
@@@ -2578,7 -2603,7 +2603,7 @@@ out_trans
                goto out_free;
  
        inode_inc_iversion(inode);
 -      inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
 +      inode->i_mtime = inode->i_ctime = current_time(inode);
  
        trans->block_rsv = &root->fs_info->trans_block_rsv;
        ret = btrfs_update_inode(trans, root, inode);
@@@ -2842,7 -2867,7 +2867,7 @@@ static long btrfs_fallocate(struct fil
                if (IS_ERR(trans)) {
                        ret = PTR_ERR(trans);
                } else {
 -                      inode->i_ctime = current_fs_time(inode->i_sb);
 +                      inode->i_ctime = current_time(inode);
                        i_size_write(inode, actual_end);
                        btrfs_ordered_update_i_size(inode, actual_end, NULL);
                        ret = btrfs_update_inode(trans, root, inode);
diff --combined fs/btrfs/inode.c
@@@ -560,8 -560,9 +560,9 @@@ cont
                         * we don't need to create any more async work items.
                         * Unlock and free up our temp pages.
                         */
-                       extent_clear_unlock_delalloc(inode, start, end, NULL,
-                                                    clear_flags, PAGE_UNLOCK |
+                       extent_clear_unlock_delalloc(inode, start, end, end,
+                                                    NULL, clear_flags,
+                                                    PAGE_UNLOCK |
                                                     PAGE_CLEAR_DIRTY |
                                                     PAGE_SET_WRITEBACK |
                                                     page_error_op |
@@@ -835,6 -836,8 +836,8 @@@ retry
                 * clear dirty, set writeback and unlock the pages.
                 */
                extent_clear_unlock_delalloc(inode, async_extent->start,
+                               async_extent->start +
+                               async_extent->ram_size - 1,
                                async_extent->start +
                                async_extent->ram_size - 1,
                                NULL, EXTENT_LOCKED | EXTENT_DELALLOC,
                        tree->ops->writepage_end_io_hook(p, start, end,
                                                         NULL, 0);
                        p->mapping = NULL;
-                       extent_clear_unlock_delalloc(inode, start, end, NULL, 0,
+                       extent_clear_unlock_delalloc(inode, start, end, end,
+                                                    NULL, 0,
                                                     PAGE_END_WRITEBACK |
                                                     PAGE_SET_ERROR);
                        free_async_extent_pages(async_extent);
@@@ -871,6 -875,8 +875,8 @@@ out_free_reserve
        btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1);
  out_free:
        extent_clear_unlock_delalloc(inode, async_extent->start,
+                                    async_extent->start +
+                                    async_extent->ram_size - 1,
                                     async_extent->start +
                                     async_extent->ram_size - 1,
                                     NULL, EXTENT_LOCKED | EXTENT_DELALLOC |
@@@ -966,7 -972,8 +972,8 @@@ static noinline int cow_file_range(stru
                ret = cow_file_range_inline(root, inode, start, end, 0, 0,
                                            NULL);
                if (ret == 0) {
-                       extent_clear_unlock_delalloc(inode, start, end, NULL,
+                       extent_clear_unlock_delalloc(inode, start, end,
+                                    delalloc_end, NULL,
                                     EXTENT_LOCKED | EXTENT_DELALLOC |
                                     EXTENT_DEFRAG, PAGE_UNLOCK |
                                     PAGE_CLEAR_DIRTY | PAGE_SET_WRITEBACK |
                op |= PAGE_SET_PRIVATE2;
  
                extent_clear_unlock_delalloc(inode, start,
-                                            start + ram_size - 1, locked_page,
+                                            start + ram_size - 1,
+                                            delalloc_end, locked_page,
                                             EXTENT_LOCKED | EXTENT_DELALLOC,
                                             op);
                disk_num_bytes -= cur_alloc_size;
@@@ -1079,7 -1087,8 +1087,8 @@@ out_reserve
        btrfs_dec_block_group_reservations(root->fs_info, ins.objectid);
        btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1);
  out_unlock:
-       extent_clear_unlock_delalloc(inode, start, end, locked_page,
+       extent_clear_unlock_delalloc(inode, start, end, delalloc_end,
+                                    locked_page,
                                     EXTENT_LOCKED | EXTENT_DO_ACCOUNTING |
                                     EXTENT_DELALLOC | EXTENT_DEFRAG,
                                     PAGE_UNLOCK | PAGE_CLEAR_DIRTY |
@@@ -1258,7 -1267,8 +1267,8 @@@ static noinline int run_delalloc_nocow(
  
        path = btrfs_alloc_path();
        if (!path) {
-               extent_clear_unlock_delalloc(inode, start, end, locked_page,
+               extent_clear_unlock_delalloc(inode, start, end, end,
+                                            locked_page,
                                             EXTENT_LOCKED | EXTENT_DELALLOC |
                                             EXTENT_DO_ACCOUNTING |
                                             EXTENT_DEFRAG, PAGE_UNLOCK |
                trans = btrfs_join_transaction(root);
  
        if (IS_ERR(trans)) {
-               extent_clear_unlock_delalloc(inode, start, end, locked_page,
+               extent_clear_unlock_delalloc(inode, start, end, end,
+                                            locked_page,
                                             EXTENT_LOCKED | EXTENT_DELALLOC |
                                             EXTENT_DO_ACCOUNTING |
                                             EXTENT_DEFRAG, PAGE_UNLOCK |
@@@ -1490,7 -1501,7 +1501,7 @@@ out_check
                }
  
                extent_clear_unlock_delalloc(inode, cur_offset,
-                                            cur_offset + num_bytes - 1,
+                                            cur_offset + num_bytes - 1, end,
                                             locked_page, EXTENT_LOCKED |
                                             EXTENT_DELALLOC |
                                             EXTENT_CLEAR_DATA_RESV,
@@@ -1522,7 -1533,7 +1533,7 @@@ error
                ret = err;
  
        if (ret && cur_offset < end)
-               extent_clear_unlock_delalloc(inode, cur_offset, end,
+               extent_clear_unlock_delalloc(inode, cur_offset, end, end,
                                             locked_page, EXTENT_LOCKED |
                                             EXTENT_DELALLOC | EXTENT_DEFRAG |
                                             EXTENT_DO_ACCOUNTING, PAGE_UNLOCK |
@@@ -1988,7 -1999,7 +1999,7 @@@ static noinline int add_pending_csums(s
  }
  
  int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end,
-                             struct extent_state **cached_state)
+                             struct extent_state **cached_state, int dedupe)
  {
        WARN_ON((end & (PAGE_SIZE - 1)) == 0);
        return set_extent_delalloc(&BTRFS_I(inode)->io_tree, start, end,
@@@ -2052,7 -2063,8 +2063,8 @@@ again
                goto out;
         }
  
-       btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state);
+       btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state,
+                                 0);
        ClearPageChecked(page);
        set_page_dirty(page);
  out:
@@@ -2309,7 -2321,7 +2321,7 @@@ static noinline int record_one_backref(
                if (PTR_ERR(root) == -ENOENT)
                        return 0;
                WARN_ON(1);
-               pr_debug("inum=%llu, offset=%llu, root_id=%llu\n",
+               btrfs_debug(fs_info, "inum=%llu, offset=%llu, root_id=%llu",
                         inum, offset, root_id);
                return PTR_ERR(root);
        }
@@@ -3936,7 -3948,7 +3948,7 @@@ noinline int btrfs_update_inode(struct 
         */
        if (!btrfs_is_free_space_inode(inode)
            && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID
-           && !root->fs_info->log_root_recovering) {
+           && !test_bit(BTRFS_FS_LOG_RECOVERING, &root->fs_info->flags)) {
                btrfs_update_root_times(trans, root);
  
                ret = btrfs_delayed_update_inode(trans, root, inode);
@@@ -4059,7 -4071,7 +4071,7 @@@ err
        inode_inc_iversion(inode);
        inode_inc_iversion(dir);
        inode->i_ctime = dir->i_mtime =
 -              dir->i_ctime = current_fs_time(inode->i_sb);
 +              dir->i_ctime = current_time(inode);
        ret = btrfs_update_inode(trans, root, dir);
  out:
        return ret;
@@@ -4202,7 -4214,7 +4214,7 @@@ int btrfs_unlink_subvol(struct btrfs_tr
  
        btrfs_i_size_write(dir, dir->i_size - name_len * 2);
        inode_inc_iversion(dir);
 -      dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
 +      dir->i_mtime = dir->i_ctime = current_time(dir);
        ret = btrfs_update_inode_fallback(trans, root, dir);
        if (ret)
                btrfs_abort_transaction(trans, ret);
@@@ -4757,7 -4769,7 +4769,7 @@@ again
                          0, 0, &cached_state, GFP_NOFS);
  
        ret = btrfs_set_extent_delalloc(inode, block_start, block_end,
-                                       &cached_state);
+                                       &cached_state, 0);
        if (ret) {
                unlock_extent_cached(io_tree, block_start, block_end,
                                     &cached_state, GFP_NOFS);
@@@ -4965,7 -4977,7 +4977,7 @@@ static int btrfs_setsize(struct inode *
                inode_inc_iversion(inode);
                if (!(mask & (ATTR_CTIME | ATTR_MTIME)))
                        inode->i_ctime = inode->i_mtime =
 -                              current_fs_time(inode->i_sb);
 +                              current_time(inode);
        }
  
        if (newsize > oldsize) {
@@@ -5072,7 -5084,7 +5084,7 @@@ static int btrfs_setattr(struct dentry 
        if (btrfs_root_readonly(root))
                return -EROFS;
  
 -      err = inode_change_ok(inode, attr);
 +      err = setattr_prepare(dentry, attr);
        if (err)
                return err;
  
@@@ -5223,7 -5235,7 +5235,7 @@@ void btrfs_evict_inode(struct inode *in
  
        btrfs_free_io_failure_record(inode, 0, (u64)-1);
  
-       if (root->fs_info->log_root_recovering) {
+       if (test_bit(BTRFS_FS_LOG_RECOVERING, &root->fs_info->flags)) {
                BUG_ON(test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
                                 &BTRFS_I(inode)->runtime_flags));
                goto no_delete;
@@@ -5672,7 -5684,7 +5684,7 @@@ static struct inode *new_simple_dir(str
        inode->i_op = &btrfs_dir_ro_inode_operations;
        inode->i_fop = &simple_dir_operations;
        inode->i_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
 -      inode->i_mtime = current_fs_time(inode->i_sb);
 +      inode->i_mtime = current_time(inode);
        inode->i_atime = inode->i_mtime;
        inode->i_ctime = inode->i_mtime;
        BTRFS_I(inode)->i_otime = inode->i_mtime;
@@@ -6258,7 -6270,7 +6270,7 @@@ static struct inode *btrfs_new_inode(st
        inode_init_owner(inode, dir, mode);
        inode_set_bytes(inode, 0);
  
 -      inode->i_mtime = current_fs_time(inode->i_sb);
 +      inode->i_mtime = current_time(inode);
        inode->i_atime = inode->i_mtime;
        inode->i_ctime = inode->i_mtime;
        BTRFS_I(inode)->i_otime = inode->i_mtime;
@@@ -6372,7 -6384,7 +6384,7 @@@ int btrfs_add_link(struct btrfs_trans_h
                           name_len * 2);
        inode_inc_iversion(parent_inode);
        parent_inode->i_mtime = parent_inode->i_ctime =
 -              current_fs_time(parent_inode->i_sb);
 +              current_time(parent_inode);
        ret = btrfs_update_inode(trans, root, parent_inode);
        if (ret)
                btrfs_abort_transaction(trans, ret);
@@@ -6590,7 -6602,7 +6602,7 @@@ static int btrfs_link(struct dentry *ol
        BTRFS_I(inode)->dir_index = 0ULL;
        inc_nlink(inode);
        inode_inc_iversion(inode);
 -      inode->i_ctime = current_fs_time(inode->i_sb);
 +      inode->i_ctime = current_time(inode);
        ihold(inode);
        set_bit(BTRFS_INODE_COPY_EVERYTHING, &BTRFS_I(inode)->runtime_flags);
  
@@@ -7012,8 -7024,9 +7024,9 @@@ not_found_em
  insert:
        btrfs_release_path(path);
        if (em->start > start || extent_map_end(em) <= start) {
-               btrfs_err(root->fs_info, "bad extent! em: [%llu %llu] passed [%llu %llu]",
-                       em->start, em->len, start, len);
+               btrfs_err(root->fs_info,
+                         "bad extent! em: [%llu %llu] passed [%llu %llu]",
+                         em->start, em->len, start, len);
                err = -EIO;
                goto out;
        }
@@@ -7865,18 -7878,19 +7878,19 @@@ static int btrfs_check_dio_repairable(s
                                      struct io_failure_record *failrec,
                                      int failed_mirror)
  {
+       struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
        int num_copies;
  
-       num_copies = btrfs_num_copies(BTRFS_I(inode)->root->fs_info,
-                                     failrec->logical, failrec->len);
+       num_copies = btrfs_num_copies(fs_info, failrec->logical, failrec->len);
        if (num_copies == 1) {
                /*
                 * we only have a single copy of the data, so don't bother with
                 * all the retry and error correction code that follows. no
                 * matter what the error is, it is very likely to persist.
                 */
-               pr_debug("Check DIO Repairable: cannot repair, num_copies=%d, next_mirror %d, failed_mirror %d\n",
-                        num_copies, failrec->this_mirror, failed_mirror);
+               btrfs_debug(fs_info,
+                       "Check DIO Repairable: cannot repair, num_copies=%d, next_mirror %d, failed_mirror %d",
+                       num_copies, failrec->this_mirror, failed_mirror);
                return 0;
        }
  
                failrec->this_mirror++;
  
        if (failrec->this_mirror > num_copies) {
-               pr_debug("Check DIO Repairable: (fail) num_copies=%d, next_mirror %d, failed_mirror %d\n",
-                        num_copies, failrec->this_mirror, failed_mirror);
+               btrfs_debug(fs_info,
+                       "Check DIO Repairable: (fail) num_copies=%d, next_mirror %d, failed_mirror %d",
+                       num_copies, failrec->this_mirror, failed_mirror);
                return 0;
        }
  
@@@ -8412,7 -8427,7 +8427,7 @@@ static int btrfs_submit_direct_hook(str
        if (!bio)
                return -ENOMEM;
  
 -      bio_set_op_attrs(bio, bio_op(orig_bio), orig_bio->bi_opf);
 +      bio_set_op_attrs(bio, bio_op(orig_bio), bio_flags(orig_bio));
        bio->bi_private = dip;
        bio->bi_end_io = btrfs_end_dio_bio;
        btrfs_io_bio(bio)->logical = file_offset;
@@@ -8450,8 -8465,7 +8465,8 @@@ next_block
                                                  start_sector, GFP_NOFS);
                        if (!bio)
                                goto out_err;
 -                      bio_set_op_attrs(bio, bio_op(orig_bio), orig_bio->bi_opf);
 +                      bio_set_op_attrs(bio, bio_op(orig_bio),
 +                                       bio_flags(orig_bio));
                        bio->bi_private = dip;
                        bio->bi_end_io = btrfs_end_dio_bio;
                        btrfs_io_bio(bio)->logical = file_offset;
@@@ -8619,7 -8633,7 +8634,7 @@@ static ssize_t check_direct_IO(struct b
                goto out;
  
        /* If this is a write we don't need to check anymore */
 -      if (iov_iter_rw(iter) == WRITE)
 +      if (iov_iter_rw(iter) != READ || !iter_is_iovec(iter))
                return 0;
        /*
         * Check to make sure we don't have duplicate iov_base's in this
@@@ -9055,7 -9069,7 +9070,7 @@@ again
                          0, 0, &cached_state, GFP_NOFS);
  
        ret = btrfs_set_extent_delalloc(inode, page_start, end,
-                                       &cached_state);
+                                       &cached_state, 0);
        if (ret) {
                unlock_extent_cached(io_tree, page_start, page_end,
                                     &cached_state, GFP_NOFS);
@@@ -9377,8 -9391,9 +9392,9 @@@ void btrfs_destroy_inode(struct inode *
                if (!ordered)
                        break;
                else {
-                       btrfs_err(root->fs_info, "found ordered extent %llu %llu on inode cleanup",
-                               ordered->file_offset, ordered->len);
+                       btrfs_err(root->fs_info,
+                                 "found ordered extent %llu %llu on inode cleanup",
+                                 ordered->file_offset, ordered->len);
                        btrfs_remove_ordered_extent(inode, ordered);
                        btrfs_put_ordered_extent(ordered);
                        btrfs_put_ordered_extent(ordered);
@@@ -9493,7 -9508,7 +9509,7 @@@ static int btrfs_rename_exchange(struc
        struct btrfs_root *dest = BTRFS_I(new_dir)->root;
        struct inode *new_inode = new_dentry->d_inode;
        struct inode *old_inode = old_dentry->d_inode;
 -      struct timespec ctime = CURRENT_TIME;
 +      struct timespec ctime = current_time(old_inode);
        struct dentry *parent;
        u64 old_ino = btrfs_ino(old_inode);
        u64 new_ino = btrfs_ino(new_inode);
@@@ -9861,7 -9876,7 +9877,7 @@@ static int btrfs_rename(struct inode *o
        inode_inc_iversion(old_inode);
        old_dir->i_ctime = old_dir->i_mtime =
        new_dir->i_ctime = new_dir->i_mtime =
 -      old_inode->i_ctime = current_fs_time(old_dir->i_sb);
 +      old_inode->i_ctime = current_time(old_dir);
  
        if (old_dentry->d_parent != new_dentry->d_parent)
                btrfs_record_unlink_dir(trans, old_dir, old_inode, 1);
  
        if (new_inode) {
                inode_inc_iversion(new_inode);
 -              new_inode->i_ctime = current_fs_time(new_inode->i_sb);
 +              new_inode->i_ctime = current_time(new_inode);
                if (unlikely(btrfs_ino(new_inode) ==
                             BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
                        root_objectid = BTRFS_I(new_inode)->location.objectid;
@@@ -10404,7 -10419,7 +10420,7 @@@ next
                *alloc_hint = ins.objectid + ins.offset;
  
                inode_inc_iversion(inode);
 -              inode->i_ctime = current_fs_time(inode->i_sb);
 +              inode->i_ctime = current_time(inode);
                BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC;
                if (!(mode & FALLOC_FL_KEEP_SIZE) &&
                    (actual_len > inode->i_size) &&
@@@ -10544,6 -10559,21 +10560,6 @@@ out_inode
  
  }
  
 -/* Inspired by filemap_check_errors() */
 -int btrfs_inode_check_errors(struct inode *inode)
 -{
 -      int ret = 0;
 -
 -      if (test_bit(AS_ENOSPC, &inode->i_mapping->flags) &&
 -          test_and_clear_bit(AS_ENOSPC, &inode->i_mapping->flags))
 -              ret = -ENOSPC;
 -      if (test_bit(AS_EIO, &inode->i_mapping->flags) &&
 -          test_and_clear_bit(AS_EIO, &inode->i_mapping->flags))
 -              ret = -EIO;
 -
 -      return ret;
 -}
 -
  static const struct inode_operations btrfs_dir_inode_operations = {
        .getattr        = btrfs_getattr,
        .lookup         = btrfs_lookup,
        .link           = btrfs_link,
        .mkdir          = btrfs_mkdir,
        .rmdir          = btrfs_rmdir,
 -      .rename2        = btrfs_rename2,
 +      .rename         = btrfs_rename2,
        .symlink        = btrfs_symlink,
        .setattr        = btrfs_setattr,
        .mknod          = btrfs_mknod,
 -      .setxattr       = generic_setxattr,
 -      .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
 -      .removexattr    = generic_removexattr,
        .permission     = btrfs_permission,
        .get_acl        = btrfs_get_acl,
        .set_acl        = btrfs_set_acl,
@@@ -10630,7 -10663,10 +10646,7 @@@ static const struct address_space_opera
  static const struct inode_operations btrfs_file_inode_operations = {
        .getattr        = btrfs_getattr,
        .setattr        = btrfs_setattr,
 -      .setxattr       = generic_setxattr,
 -      .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
 -      .removexattr    = generic_removexattr,
        .permission     = btrfs_permission,
        .fiemap         = btrfs_fiemap,
        .get_acl        = btrfs_get_acl,
@@@ -10641,7 -10677,10 +10657,7 @@@ static const struct inode_operations bt
        .getattr        = btrfs_getattr,
        .setattr        = btrfs_setattr,
        .permission     = btrfs_permission,
 -      .setxattr       = generic_setxattr,
 -      .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
 -      .removexattr    = generic_removexattr,
        .get_acl        = btrfs_get_acl,
        .set_acl        = btrfs_set_acl,
        .update_time    = btrfs_update_time,
@@@ -10652,7 -10691,10 +10668,7 @@@ static const struct inode_operations bt
        .getattr        = btrfs_getattr,
        .setattr        = btrfs_setattr,
        .permission     = btrfs_permission,
 -      .setxattr       = generic_setxattr,
 -      .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
 -      .removexattr    = generic_removexattr,
        .update_time    = btrfs_update_time,
  };
  
diff --combined fs/btrfs/ioctl.c
@@@ -349,7 -349,7 +349,7 @@@ static int btrfs_ioctl_setflags(struct 
  
        btrfs_update_iflags(inode);
        inode_inc_iversion(inode);
 -      inode->i_ctime = current_fs_time(inode->i_sb);
 +      inode->i_ctime = current_time(inode);
        ret = btrfs_update_inode(trans, root, inode);
  
        btrfs_end_transaction(trans, root);
@@@ -445,7 -445,7 +445,7 @@@ static noinline int create_subvol(struc
        struct btrfs_root *root = BTRFS_I(dir)->root;
        struct btrfs_root *new_root;
        struct btrfs_block_rsv block_rsv;
 -      struct timespec cur_time = current_fs_time(dir->i_sb);
 +      struct timespec cur_time = current_time(dir);
        struct inode *inode;
        int ret;
        int err;
@@@ -1903,8 -1903,9 +1903,9 @@@ static noinline int may_destroy_subvol(
                btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key);
                if (key.objectid == root->root_key.objectid) {
                        ret = -EPERM;
-                       btrfs_err(root->fs_info, "deleting default subvolume "
-                                 "%llu is not allowed", key.objectid);
+                       btrfs_err(root->fs_info,
+                                 "deleting default subvolume %llu is not allowed",
+                                 key.objectid);
                        goto out;
                }
                btrfs_release_path(path);
@@@ -3291,7 -3292,7 +3292,7 @@@ static int clone_finish_inode_update(st
  
        inode_inc_iversion(inode);
        if (!no_time_update)
 -              inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
 +              inode->i_mtime = inode->i_ctime = current_time(inode);
        /*
         * We round up to the block size at eof when determining which
         * extents to clone above, but shouldn't round up the file size.
@@@ -4097,8 -4098,8 +4098,8 @@@ static long btrfs_ioctl_default_subvol(
        if (IS_ERR_OR_NULL(di)) {
                btrfs_free_path(path);
                btrfs_end_transaction(trans, root);
-               btrfs_err(new_root->fs_info, "Umm, you don't have the default dir"
-                          "item, this isn't going to work");
+               btrfs_err(new_root->fs_info,
+                         "Umm, you don't have the default diritem, this isn't going to work");
                ret = -ENOENT;
                goto out;
        }
@@@ -5106,7 -5107,7 +5107,7 @@@ static long _btrfs_ioctl_set_received_s
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_root_item *root_item = &root->root_item;
        struct btrfs_trans_handle *trans;
 -      struct timespec ct = current_fs_time(inode->i_sb);
 +      struct timespec ct = current_time(inode);
        int ret = 0;
        int received_uuid_changed;
  
@@@ -5307,8 -5308,9 +5308,9 @@@ static int btrfs_ioctl_set_fslabel(stru
                return -EFAULT;
  
        if (strnlen(label, BTRFS_LABEL_SIZE) == BTRFS_LABEL_SIZE) {
-               btrfs_err(root->fs_info, "unable to set label with more than %d bytes",
-                      BTRFS_LABEL_SIZE - 1);
+               btrfs_err(root->fs_info,
+                         "unable to set label with more than %d bytes",
+                         BTRFS_LABEL_SIZE - 1);
                return -EINVAL;
        }
  
diff --combined fs/btrfs/send.c
  #include "transaction.h"
  #include "compression.h"
  
- static int g_verbose = 0;
- #define verbose_printk(...) if (g_verbose) printk(__VA_ARGS__)
  /*
   * A fs_path is a helper to dynamically build path names with unknown size.
   * It reallocates the internal buffer on demand.
@@@ -727,9 -723,10 +723,10 @@@ static int send_cmd(struct send_ctx *sc
  static int send_rename(struct send_ctx *sctx,
                     struct fs_path *from, struct fs_path *to)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret;
  
verbose_printk("btrfs: send_rename %s -> %s\n", from->start, to->start);
      btrfs_debug(fs_info, "send_rename %s -> %s", from->start, to->start);
  
        ret = begin_cmd(sctx, BTRFS_SEND_C_RENAME);
        if (ret < 0)
@@@ -751,9 -748,10 +748,10 @@@ out
  static int send_link(struct send_ctx *sctx,
                     struct fs_path *path, struct fs_path *lnk)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret;
  
verbose_printk("btrfs: send_link %s -> %s\n", path->start, lnk->start);
      btrfs_debug(fs_info, "send_link %s -> %s", path->start, lnk->start);
  
        ret = begin_cmd(sctx, BTRFS_SEND_C_LINK);
        if (ret < 0)
@@@ -774,9 -772,10 +772,10 @@@ out
   */
  static int send_unlink(struct send_ctx *sctx, struct fs_path *path)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret;
  
verbose_printk("btrfs: send_unlink %s\n", path->start);
      btrfs_debug(fs_info, "send_unlink %s", path->start);
  
        ret = begin_cmd(sctx, BTRFS_SEND_C_UNLINK);
        if (ret < 0)
@@@ -796,9 -795,10 +795,10 @@@ out
   */
  static int send_rmdir(struct send_ctx *sctx, struct fs_path *path)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret;
  
verbose_printk("btrfs: send_rmdir %s\n", path->start);
      btrfs_debug(fs_info, "send_rmdir %s", path->start);
  
        ret = begin_cmd(sctx, BTRFS_SEND_C_RMDIR);
        if (ret < 0)
@@@ -1313,6 -1313,7 +1313,7 @@@ static int find_extent_clone(struct sen
                             u64 ino_size,
                             struct clone_root **found)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret;
        int extent_type;
        u64 logical;
        }
        logical = disk_byte + btrfs_file_extent_offset(eb, fi);
  
-       down_read(&sctx->send_root->fs_info->commit_root_sem);
-       ret = extent_from_logical(sctx->send_root->fs_info, disk_byte, tmp_path,
+       down_read(&fs_info->commit_root_sem);
+       ret = extent_from_logical(fs_info, disk_byte, tmp_path,
                                  &found_key, &flags);
-       up_read(&sctx->send_root->fs_info->commit_root_sem);
+       up_read(&fs_info->commit_root_sem);
        btrfs_release_path(tmp_path);
  
        if (ret < 0)
                extent_item_pos = logical - found_key.objectid;
        else
                extent_item_pos = 0;
-       ret = iterate_extent_inodes(sctx->send_root->fs_info,
+       ret = iterate_extent_inodes(fs_info,
                                        found_key.objectid, extent_item_pos, 1,
                                        __iterate_backrefs, backref_ctx);
  
        if (!backref_ctx->found_itself) {
                /* found a bug in backref code? */
                ret = -EIO;
-               btrfs_err(sctx->send_root->fs_info, "did not find backref in "
-                               "send_root. inode=%llu, offset=%llu, "
-                               "disk_byte=%llu found extent=%llu",
-                               ino, data_offset, disk_byte, found_key.objectid);
+               btrfs_err(fs_info,
+                         "did not find backref in send_root. inode=%llu, offset=%llu, disk_byte=%llu found extent=%llu",
+                         ino, data_offset, disk_byte, found_key.objectid);
                goto out;
        }
  
- verbose_printk(KERN_DEBUG "btrfs: find_extent_clone: data_offset=%llu, "
-               "ino=%llu, "
-               "num_bytes=%llu, logical=%llu\n",
-               data_offset, ino, num_bytes, logical);
+       btrfs_debug(fs_info,
+                   "find_extent_clone: data_offset=%llu, ino=%llu, num_bytes=%llu, logical=%llu",
+                   data_offset, ino, num_bytes, logical);
  
        if (!backref_ctx->found)
-               verbose_printk("btrfs:    no clones found\n");
+               btrfs_debug(fs_info, "no clones found");
  
        cur_clone_root = NULL;
        for (i = 0; i < sctx->clone_roots_cnt; i++) {
  
  static int send_truncate(struct send_ctx *sctx, u64 ino, u64 gen, u64 size)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret = 0;
        struct fs_path *p;
  
verbose_printk("btrfs: send_truncate %llu size=%llu\n", ino, size);
      btrfs_debug(fs_info, "send_truncate %llu size=%llu", ino, size);
  
        p = fs_path_alloc();
        if (!p)
  
  static int send_chmod(struct send_ctx *sctx, u64 ino, u64 gen, u64 mode)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret = 0;
        struct fs_path *p;
  
verbose_printk("btrfs: send_chmod %llu mode=%llu\n", ino, mode);
      btrfs_debug(fs_info, "send_chmod %llu mode=%llu", ino, mode);
  
        p = fs_path_alloc();
        if (!p)
  
  static int send_chown(struct send_ctx *sctx, u64 ino, u64 gen, u64 uid, u64 gid)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret = 0;
        struct fs_path *p;
  
- verbose_printk("btrfs: send_chown %llu uid=%llu, gid=%llu\n", ino, uid, gid);
+       btrfs_debug(fs_info, "send_chown %llu uid=%llu, gid=%llu",
+                   ino, uid, gid);
  
        p = fs_path_alloc();
        if (!p)
@@@ -2511,6 -2514,7 +2514,7 @@@ out
  
  static int send_utimes(struct send_ctx *sctx, u64 ino, u64 gen)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret = 0;
        struct fs_path *p = NULL;
        struct btrfs_inode_item *ii;
        struct btrfs_key key;
        int slot;
  
verbose_printk("btrfs: send_utimes %llu\n", ino);
      btrfs_debug(fs_info, "send_utimes %llu", ino);
  
        p = fs_path_alloc();
        if (!p)
@@@ -2573,6 -2577,7 +2577,7 @@@ out
   */
  static int send_create_inode(struct send_ctx *sctx, u64 ino)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret = 0;
        struct fs_path *p;
        int cmd;
        u64 mode;
        u64 rdev;
  
verbose_printk("btrfs: send_create_inode %llu\n", ino);
      btrfs_debug(fs_info, "send_create_inode %llu", ino);
  
        p = fs_path_alloc();
        if (!p)
@@@ -3638,6 -3643,7 +3643,7 @@@ out
   */
  static int process_recorded_refs(struct send_ctx *sctx, int *pending_move)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret = 0;
        struct recorded_ref *cur;
        struct recorded_ref *cur2;
        u64 last_dir_ino_rm = 0;
        bool can_rename = true;
  
verbose_printk("btrfs: process_recorded_refs %llu\n", sctx->cur_ino);
      btrfs_debug(fs_info, "process_recorded_refs %llu", sctx->cur_ino);
  
        /*
         * This should never happen as the root dir always has the same ref
@@@ -4329,7 -4335,7 +4335,7 @@@ static int __process_new_xattr(int num
        int ret;
        struct send_ctx *sctx = ctx;
        struct fs_path *p;
 -      posix_acl_xattr_header dummy_acl;
 +      struct posix_acl_xattr_header dummy_acl;
  
        p = fs_path_alloc();
        if (!p)
@@@ -4398,12 -4404,8 +4404,8 @@@ static int process_new_xattr(struct sen
  
  static int process_deleted_xattr(struct send_ctx *sctx)
  {
-       int ret;
-       ret = iterate_dir_item(sctx->parent_root, sctx->right_path,
-                              sctx->cmp_key, __process_deleted_xattr, sctx);
-       return ret;
+       return iterate_dir_item(sctx->parent_root, sctx->right_path,
+                               sctx->cmp_key, __process_deleted_xattr, sctx);
  }
  
  struct find_xattr_ctx {
@@@ -4664,6 -4666,7 +4666,7 @@@ out
   */
  static int send_write(struct send_ctx *sctx, u64 offset, u32 len)
  {
+       struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
        int ret = 0;
        struct fs_path *p;
        ssize_t num_read = 0;
        if (!p)
                return -ENOMEM;
  
verbose_printk("btrfs: send_write offset=%llu, len=%d\n", offset, len);
      btrfs_debug(fs_info, "send_write offset=%llu, len=%d", offset, len);
  
        num_read = fill_read_buf(sctx, offset, len);
        if (num_read <= 0) {
@@@ -4714,10 -4717,10 +4717,10 @@@ static int send_clone(struct send_ctx *
        struct fs_path *p;
        u64 gen;
  
- verbose_printk("btrfs: send_clone offset=%llu, len=%d, clone_root=%llu, "
-              "clone_inode=%llu, clone_offset=%llu\n", offset, len,
-               clone_root->root->objectid, clone_root->ino,
-               clone_root->offset);
+       btrfs_debug(sctx->send_root->fs_info,
+                   "send_clone offset=%llu, len=%d, clone_root=%llu, clone_inode=%llu, clone_offset=%llu",
+                   offset, len, clone_root->root->objectid, clone_root->ino,
+                   clone_root->offset);
  
        p = fs_path_alloc();
        if (!p)
diff --combined fs/btrfs/transaction.c
@@@ -65,8 -65,9 +65,9 @@@ void btrfs_put_transaction(struct btrfs
                BUG_ON(!list_empty(&transaction->list));
                WARN_ON(!RB_EMPTY_ROOT(&transaction->delayed_refs.href_root));
                if (transaction->delayed_refs.pending_csums)
-                       printk(KERN_ERR "pending csums is %llu\n",
-                              transaction->delayed_refs.pending_csums);
+                       btrfs_err(transaction->fs_info,
+                                 "pending csums is %llu",
+                                 transaction->delayed_refs.pending_csums);
                while (!list_empty(&transaction->pending_chunks)) {
                        struct extent_map *em;
  
@@@ -245,6 -246,7 +246,7 @@@ loop
                return -EROFS;
        }
  
+       cur_trans->fs_info = fs_info;
        atomic_set(&cur_trans->num_writers, 1);
        extwriter_counter_init(cur_trans, type);
        init_waitqueue_head(&cur_trans->writer_wait);
         */
        smp_mb();
        if (!list_empty(&fs_info->tree_mod_seq_list))
-               WARN(1, KERN_ERR "BTRFS: tree_mod_seq_list not empty when "
-                       "creating a fresh transaction\n");
+               WARN(1, KERN_ERR "BTRFS: tree_mod_seq_list not empty when creating a fresh transaction\n");
        if (!RB_EMPTY_ROOT(&fs_info->tree_mod_log))
-               WARN(1, KERN_ERR "BTRFS: tree_mod_log rb tree not empty when "
-                       "creating a fresh transaction\n");
+               WARN(1, KERN_ERR "BTRFS: tree_mod_log rb tree not empty when creating a fresh transaction\n");
        atomic64_set(&fs_info->tree_mod_seq, 0);
  
        spin_lock_init(&cur_trans->delayed_refs.lock);
@@@ -441,7 -441,7 +441,7 @@@ static void wait_current_trans(struct b
  
  static int may_wait_transaction(struct btrfs_root *root, int type)
  {
-       if (root->fs_info->log_root_recovering)
+       if (test_bit(BTRFS_FS_LOG_RECOVERING, &root->fs_info->flags))
                return 0;
  
        if (type == TRANS_USERSPACE)
@@@ -549,11 -549,8 +549,8 @@@ again
                }
        } while (ret == -EBUSY);
  
-       if (ret < 0) {
-               /* We must get the transaction if we are JOIN_NOLOCK. */
-               BUG_ON(type == TRANS_JOIN_NOLOCK);
+       if (ret < 0)
                goto join_fail;
-       }
  
        cur_trans = root->fs_info->running_transaction;
  
@@@ -993,7 -990,6 +990,6 @@@ int btrfs_wait_marked_extents(struct bt
        struct extent_state *cached_state = NULL;
        u64 start = 0;
        u64 end;
-       struct btrfs_inode *btree_ino = BTRFS_I(root->fs_info->btree_inode);
        bool errors = false;
  
        while (!find_first_extent_bit(dirty_pages, start, &start, &end,
  
        if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) {
                if ((mark & EXTENT_DIRTY) &&
-                   test_and_clear_bit(BTRFS_INODE_BTREE_LOG1_ERR,
-                                      &btree_ino->runtime_flags))
+                   test_and_clear_bit(BTRFS_FS_LOG1_ERR,
+                                      &root->fs_info->flags))
                        errors = true;
  
                if ((mark & EXTENT_NEW) &&
-                   test_and_clear_bit(BTRFS_INODE_BTREE_LOG2_ERR,
-                                      &btree_ino->runtime_flags))
+                   test_and_clear_bit(BTRFS_FS_LOG2_ERR,
+                                      &root->fs_info->flags))
                        errors = true;
        } else {
-               if (test_and_clear_bit(BTRFS_INODE_BTREE_ERR,
-                                      &btree_ino->runtime_flags))
+               if (test_and_clear_bit(BTRFS_FS_BTREE_ERR,
+                                      &root->fs_info->flags))
                        errors = true;
        }
  
@@@ -1300,11 -1296,11 +1296,11 @@@ int btrfs_defrag_root(struct btrfs_roo
                btrfs_btree_balance_dirty(info->tree_root);
                cond_resched();
  
-               if (btrfs_fs_closing(root->fs_info) || ret != -EAGAIN)
+               if (btrfs_fs_closing(info) || ret != -EAGAIN)
                        break;
  
-               if (btrfs_defrag_cancelled(root->fs_info)) {
-                       pr_debug("BTRFS: defrag_root cancelled\n");
+               if (btrfs_defrag_cancelled(info)) {
+                       btrfs_debug(info, "defrag_root cancelled");
                        ret = -EAGAIN;
                        break;
                }
@@@ -1335,7 -1331,7 +1331,7 @@@ static int qgroup_account_snapshot(stru
         * kick in anyway.
         */
        mutex_lock(&fs_info->qgroup_ioctl_lock);
-       if (!fs_info->quota_enabled) {
+       if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) {
                mutex_unlock(&fs_info->qgroup_ioctl_lock);
                return 0;
        }
@@@ -1474,7 -1470,7 +1470,7 @@@ static noinline int create_pending_snap
        parent_root = BTRFS_I(parent_inode)->root;
        record_root_in_trans(trans, parent_root, 0);
  
 -      cur_time = current_fs_time(parent_inode->i_sb);
 +      cur_time = current_time(parent_inode);
  
        /*
         * insert the directory item
        btrfs_i_size_write(parent_inode, parent_inode->i_size +
                                         dentry->d_name.len * 2);
        parent_inode->i_mtime = parent_inode->i_ctime =
 -              current_fs_time(parent_inode->i_sb);
 +              current_time(parent_inode);
        ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode);
        if (ret) {
                btrfs_abort_transaction(trans, ret);
@@@ -1712,7 -1708,7 +1708,7 @@@ static void update_super_roots(struct b
        super->root_level = root_item->level;
        if (btrfs_test_opt(root->fs_info, SPACE_CACHE))
                super->cache_generation = root_item->generation;
-       if (root->fs_info->update_uuid_tree_gen)
+       if (test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &root->fs_info->flags))
                super->uuid_tree_generation = root_item->generation;
  }
  
@@@ -1919,7 -1915,6 +1915,6 @@@ int btrfs_commit_transaction(struct btr
  {
        struct btrfs_transaction *cur_trans = trans->transaction;
        struct btrfs_transaction *prev_trans = NULL;
-       struct btrfs_inode *btree_ino = BTRFS_I(root->fs_info->btree_inode);
        int ret;
  
        /* Stop the commit early if ->aborted is set */
        btrfs_update_commit_device_size(root->fs_info);
        btrfs_update_commit_device_bytes_used(root, cur_trans);
  
-       clear_bit(BTRFS_INODE_BTREE_LOG1_ERR, &btree_ino->runtime_flags);
-       clear_bit(BTRFS_INODE_BTREE_LOG2_ERR, &btree_ino->runtime_flags);
+       clear_bit(BTRFS_FS_LOG1_ERR, &root->fs_info->flags);
+       clear_bit(BTRFS_FS_LOG2_ERR, &root->fs_info->flags);
  
        btrfs_trans_release_chunk_metadata(trans);
  
@@@ -2328,7 -2323,7 +2323,7 @@@ int btrfs_clean_one_deleted_snapshot(st
        list_del_init(&root->root_list);
        spin_unlock(&fs_info->trans_lock);
  
-       pr_debug("BTRFS: cleaner removing %llu\n", root->objectid);
+       btrfs_debug(fs_info, "cleaner removing %llu", root->objectid);
  
        btrfs_kill_all_delayed_nodes(root);
  
diff --combined fs/btrfs/tree-log.c
@@@ -3961,7 -3961,7 +3961,7 @@@ static int wait_ordered_extents(struct 
                         * i_mapping flags, so that the next fsync won't get
                         * an outdated io error too.
                         */
 -                      btrfs_inode_check_errors(inode);
 +                      filemap_check_errors(inode->i_mapping);
                        *ordered_io_error = true;
                        break;
                }
@@@ -4198,7 -4198,7 +4198,7 @@@ static int btrfs_log_changed_extents(st
         * without writing to the log tree and the fsync must report the
         * file data write error and not commit the current transaction.
         */
 -      ret = btrfs_inode_check_errors(inode);
 +      ret = filemap_check_errors(inode->i_mapping);
        if (ret)
                ctx->io_err = ret;
  process:
@@@ -5579,7 -5579,7 +5579,7 @@@ int btrfs_recover_log_trees(struct btrf
        if (!path)
                return -ENOMEM;
  
-       fs_info->log_root_recovering = 1;
+       set_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags);
  
        trans = btrfs_start_transaction(fs_info->tree_root, 0);
        if (IS_ERR(trans)) {
  
        ret = walk_log_tree(trans, log_root_tree, &wc);
        if (ret) {
-               btrfs_handle_fs_error(fs_info, ret, "Failed to pin buffers while "
-                           "recovering log root tree.");
+               btrfs_handle_fs_error(fs_info, ret,
+                       "Failed to pin buffers while recovering log root tree.");
                goto error;
        }
  
@@@ -5639,8 -5639,8 +5639,8 @@@ again
                        free_extent_buffer(log->node);
                        free_extent_buffer(log->commit_root);
                        kfree(log);
-                       btrfs_handle_fs_error(fs_info, ret, "Couldn't read target root "
-                                   "for tree log recovery.");
+                       btrfs_handle_fs_error(fs_info, ret,
+                               "Couldn't read target root for tree log recovery.");
                        goto error;
                }
  
  
        free_extent_buffer(log_root_tree->node);
        log_root_tree->log_root = NULL;
-       fs_info->log_root_recovering = 0;
+       clear_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags);
        kfree(log_root_tree);
  
        return 0;