All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers
@ 2016-06-24 22:14 jeffm
  2016-06-24 22:14 ` [PATCH 01/31] btrfs: plumb fs_info into btrfs_work jeffm
                   ` (31 more replies)
  0 siblings, 32 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:14 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

One of the common complaints I've heard from new and experienced
developers alike about the btrfs code is the ubiquity of
struct btrfs_root.  There is one for every tree on disk and it's not
always obvious which root is needed in a particular call path.  It can
be frustrating to spend time figuring out which root is required only
to discover that it's not actually used for anything other than
getting the fs-global struct btrfs_fs_info.

The patchset contains several sections.

1) The fsid trace event patchset I posted earlier; I can rebase without this
   but I'd prefer not to.

2) Converting btrfs_test_opt and friends to use an fs_info.

3) Converting tests to use an fs_info pointer whenever a root is used.

4) Moving sectorsize and nodesize to fs_info and cleaning up the
   macros used to access them.

5) General cleanups and small fixes to make the later patches easier to
   review.

6) Adding an "fs_info" convenience variable to every functiont that
   references root->fs_info more than once.  As new references appear
   in functions, more of these are added later.

7) Call functions that always overwrite their root parameter with
   an fs_info instead.

8) Call functions that are always called using the same root with
   an fs_info instead, retreiving the root internally.

9) Convert every function that accepts a root argument but only uses it
   to retreive an fs_info to accept an fs_info instead.  This is a
   recursive process as the changes percolate up.

10) Separately convert btrfs_commit_transaction and btrfs_end_transaction
    to use trans->root instead of a root parameter.  Both are always called
    with the same root that was passed to btrfs_{start,join}_transaction.

This series of patches in email format is the "squashed" version of
the full development series.  That series is available at:

git://git.kernel.org/pub/scm/linux/kernel/git/jeffm/linux-btrfs.git

There are two branches of interest:
- btrfs-testing/root-fsinfo-cleanup-squashed contains this series
- btrfs-testing/root-fsinfo-cleanup contains the full series

The btrfs-testing/root-fsinfo-cleanup branch is easier to review if using
git as each change is discrete.  As a whole, the patchset is invasive but
should change execution minimally.  It passes and fails the same xfstests
that the unpatched kernel does across multiple runs.

Thanks,

-Jeff

---

Jeff Mahoney (31):
  btrfs: plumb fs_info into btrfs_work
  btrfs: prefix fsid to all trace events
  btrfs: btrfs_test_opt and friends should take a btrfs_fs_info
  btrfs: tests, move initialization into tests/
  btrfs: tests, require fs_info for root
  btrfs: tests, use BTRFS_FS_STATE_DUMMY_FS_INFO instead of dummy root
  btrfs: simpilify btrfs_subvol_inherit_props
  btrfs: copy_to_sk drop unused root parameter
  btrfs: cleanup, remove prototype for btrfs_find_root_ref
  btrfs: introduce BTRFS_MAX_ITEM_SIZE
  btrfs: convert nodesize macros to static inlines
  btrfs: btrfs_relocate_chunk pass extent_root to btrfs_end_transaction
  btrfs: add btrfs_trans_handle->fs_info pointer
  btrfs: btrfs_abort_transaction, drop root parameter
  btrfs: call functions that overwrite their root parameter with fs_info
  btrfs: call functions that always use the same root with fs_info
    instead
  btrfs: btrfs_init_new_device should use fs_info->dev_root
  btrfs: alloc_reserved_file_extent trace point should use extent_root
  btrfs: struct btrfsic_state->root should be an fs_info
  btrfs: struct reada_control.root -> reada_control.fs_info
  btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere
  btrfs: root->fs_info cleanup, io_ctl_init
  btrfs: pull node/sector/stripe sizes out of root and into fs_info
  btrfs: root->fs_info cleanup, btrfs_calc_{trans,trunc}_metadata_size
  btrfs: root->fs_info cleanup, lock/unlock_chunks
  btrfs: root->fs_info cleanup, update_block_group{,flags}
  btrfs: root->fs_info cleanup, add fs_info convenience variables
  btrfs: root->fs_info cleanup, access fs_info->delayed_root directly
  btrfs: take an fs_info parameter directly when the root is not used
    otherwise
  btrfs: root->fs_info cleanup, btrfs_commit_transaction already has
    root
  btrfs: root->fs_info cleanup, btrfs_end_transaction{,_throttle} use
    trans->fs_info instead of parameter

 fs/btrfs/async-thread.c                |   31 +-
 fs/btrfs/async-thread.h                |    6 +-
 fs/btrfs/backref.c                     |   12 +-
 fs/btrfs/check-integrity.c             |   41 +-
 fs/btrfs/check-integrity.h             |    5 +-
 fs/btrfs/compression.c                 |   54 +-
 fs/btrfs/ctree.c                       |  483 ++++++------
 fs/btrfs/ctree.h                       |  281 +++----
 fs/btrfs/delayed-inode.c               |  147 ++--
 fs/btrfs/delayed-inode.h               |   19 +-
 fs/btrfs/delayed-ref.c                 |    9 +-
 fs/btrfs/dev-replace.c                 |   68 +-
 fs/btrfs/dev-replace.h                 |    4 +-
 fs/btrfs/dir-item.c                    |   44 +-
 fs/btrfs/disk-io.c                     |  593 ++++++++-------
 fs/btrfs/disk-io.h                     |   27 +-
 fs/btrfs/export.c                      |   10 +-
 fs/btrfs/extent-tree.c                 | 1297 ++++++++++++++++----------------
 fs/btrfs/extent_io.c                   |   41 +-
 fs/btrfs/extent_io.h                   |    4 +-
 fs/btrfs/file-item.c                   |  164 ++--
 fs/btrfs/file.c                        |  220 +++---
 fs/btrfs/free-space-cache.c            |  116 +--
 fs/btrfs/free-space-cache.h            |    6 +-
 fs/btrfs/free-space-tree.c             |   60 +-
 fs/btrfs/inode-item.c                  |   11 +-
 fs/btrfs/inode-map.c                   |   48 +-
 fs/btrfs/inode.c                       |  834 ++++++++++----------
 fs/btrfs/ioctl.c                       |  613 ++++++++-------
 fs/btrfs/ordered-data.c                |   38 +-
 fs/btrfs/ordered-data.h                |    4 +-
 fs/btrfs/print-tree.c                  |   21 +-
 fs/btrfs/print-tree.h                  |    4 +-
 fs/btrfs/props.c                       |   11 +-
 fs/btrfs/qgroup.c                      |   60 +-
 fs/btrfs/qgroup.h                      |    9 +-
 fs/btrfs/raid56.c                      |   60 +-
 fs/btrfs/raid56.h                      |    8 +-
 fs/btrfs/reada.c                       |   36 +-
 fs/btrfs/relocation.c                  |  261 ++++---
 fs/btrfs/root-tree.c                   |   36 +-
 fs/btrfs/scrub.c                       |  177 +++--
 fs/btrfs/send.c                        |   45 +-
 fs/btrfs/super.c                       |  308 ++++----
 fs/btrfs/tests/btrfs-tests.c           |   72 +-
 fs/btrfs/tests/btrfs-tests.h           |   38 +-
 fs/btrfs/tests/extent-buffer-tests.c   |   23 +-
 fs/btrfs/tests/free-space-tests.c      |   14 +-
 fs/btrfs/tests/free-space-tree-tests.c |   18 +-
 fs/btrfs/tests/inode-tests.c           |   46 +-
 fs/btrfs/tests/qgroup-tests.c          |   23 +-
 fs/btrfs/transaction.c                 |  531 ++++++-------
 fs/btrfs/transaction.h                 |   16 +-
 fs/btrfs/tree-log.c                    |  193 ++---
 fs/btrfs/uuid-tree.c                   |   20 +-
 fs/btrfs/volumes.c                     |  813 ++++++++++----------
 fs/btrfs/volumes.h                     |   42 +-
 fs/btrfs/xattr.c                       |   21 +-
 include/trace/events/btrfs.h           |  296 ++++----
 59 files changed, 4383 insertions(+), 4109 deletions(-)

-- 
2.7.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH 01/31] btrfs: plumb fs_info into btrfs_work
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
@ 2016-06-24 22:14 ` jeffm
  2016-06-24 22:14 ` [PATCH 02/31] btrfs: prefix fsid to all trace events jeffm
                   ` (30 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:14 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

In order to provide an fsid for trace events, we'll need a btrfs_fs_info
pointer.  The most lightweight way to do that for btrfs_work structures
is to associate it with the __btrfs_workqueue structure.  Each queued
btrfs_work structure has a workqueue associated with it, so that's
a natural fit.  It's a privately defined structures, so we add accessors
to retrieve the fs_info pointer.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/async-thread.c | 31 +++++++++++++++++++++++++------
 fs/btrfs/async-thread.h |  6 +++++-
 fs/btrfs/disk-io.c      | 47 ++++++++++++++++++++++++++++-------------------
 fs/btrfs/scrub.c        | 10 +++++-----
 4 files changed, 63 insertions(+), 31 deletions(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 5fb60ea..e0f071f 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -34,6 +34,10 @@
 
 struct __btrfs_workqueue {
 	struct workqueue_struct *normal_wq;
+
+	/* File system this workqueue services */
+	struct btrfs_fs_info *fs_info;
+
 	/* List head pointing to ordered work list */
 	struct list_head ordered_list;
 
@@ -70,6 +74,18 @@ void btrfs_##name(struct work_struct *arg)				\
 	normal_work_helper(work);					\
 }
 
+struct btrfs_fs_info *
+btrfs_workqueue_owner(struct __btrfs_workqueue *wq)
+{
+	return wq->fs_info;
+}
+
+struct btrfs_fs_info *
+btrfs_work_owner(struct btrfs_work *work)
+{
+	return work->wq->fs_info;
+}
+
 BTRFS_WORK_HELPER(worker_helper);
 BTRFS_WORK_HELPER(delalloc_helper);
 BTRFS_WORK_HELPER(flush_delalloc_helper);
@@ -94,14 +110,15 @@ BTRFS_WORK_HELPER(scrubnc_helper);
 BTRFS_WORK_HELPER(scrubparity_helper);
 
 static struct __btrfs_workqueue *
-__btrfs_alloc_workqueue(const char *name, unsigned int flags, int limit_active,
-			 int thresh)
+__btrfs_alloc_workqueue(struct btrfs_fs_info *fs_info, const char *name,
+			unsigned int flags, int limit_active, int thresh)
 {
 	struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_KERNEL);
 
 	if (!ret)
 		return NULL;
 
+	ret->fs_info = fs_info;
 	ret->limit_active = limit_active;
 	atomic_set(&ret->pending, 0);
 	if (thresh == 0)
@@ -143,7 +160,8 @@ __btrfs_alloc_workqueue(const char *name, unsigned int flags, int limit_active,
 static inline void
 __btrfs_destroy_workqueue(struct __btrfs_workqueue *wq);
 
-struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
+struct btrfs_workqueue *btrfs_alloc_workqueue(struct btrfs_fs_info *fs_info,
+					      const char *name,
 					      unsigned int flags,
 					      int limit_active,
 					      int thresh)
@@ -153,7 +171,8 @@ struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
 	if (!ret)
 		return NULL;
 
-	ret->normal = __btrfs_alloc_workqueue(name, flags & ~WQ_HIGHPRI,
+	ret->normal = __btrfs_alloc_workqueue(fs_info, name,
+					      flags & ~WQ_HIGHPRI,
 					      limit_active, thresh);
 	if (!ret->normal) {
 		kfree(ret);
@@ -161,8 +180,8 @@ struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
 	}
 
 	if (flags & WQ_HIGHPRI) {
-		ret->high = __btrfs_alloc_workqueue(name, flags, limit_active,
-						    thresh);
+		ret->high = __btrfs_alloc_workqueue(fs_info, name, flags,
+						    limit_active, thresh);
 		if (!ret->high) {
 			__btrfs_destroy_workqueue(ret->normal);
 			kfree(ret);
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index ad4d064..8e52484 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -21,6 +21,7 @@
 #define __BTRFS_ASYNC_THREAD_
 #include <linux/workqueue.h>
 
+struct btrfs_fs_info;
 struct btrfs_workqueue;
 /* Internal use only */
 struct __btrfs_workqueue;
@@ -67,7 +68,8 @@ BTRFS_WORK_HELPER_PROTO(scrubnc_helper);
 BTRFS_WORK_HELPER_PROTO(scrubparity_helper);
 
 
-struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
+struct btrfs_workqueue *btrfs_alloc_workqueue(struct btrfs_fs_info *fs_info,
+					      const char *name,
 					      unsigned int flags,
 					      int limit_active,
 					      int thresh);
@@ -80,4 +82,6 @@ void btrfs_queue_work(struct btrfs_workqueue *wq,
 void btrfs_destroy_workqueue(struct btrfs_workqueue *wq);
 void btrfs_workqueue_set_max(struct btrfs_workqueue *wq, int max);
 void btrfs_set_work_high_priority(struct btrfs_work *work);
+struct btrfs_fs_info *btrfs_work_owner(struct btrfs_work *work);
+struct btrfs_fs_info *btrfs_workqueue_owner(struct __btrfs_workqueue *wq);
 #endif
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 54cca7a..685c81a 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2316,17 +2316,19 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
 	unsigned int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND;
 
 	fs_info->workers =
-		btrfs_alloc_workqueue("worker", flags | WQ_HIGHPRI,
-				      max_active, 16);
+		btrfs_alloc_workqueue(fs_info, "worker",
+				      flags | WQ_HIGHPRI, max_active, 16);
 
 	fs_info->delalloc_workers =
-		btrfs_alloc_workqueue("delalloc", flags, max_active, 2);
+		btrfs_alloc_workqueue(fs_info, "delalloc",
+				      flags, max_active, 2);
 
 	fs_info->flush_workers =
-		btrfs_alloc_workqueue("flush_delalloc", flags, max_active, 0);
+		btrfs_alloc_workqueue(fs_info, "flush_delalloc",
+				      flags, max_active, 0);
 
 	fs_info->caching_workers =
-		btrfs_alloc_workqueue("cache", flags, max_active, 0);
+		btrfs_alloc_workqueue(fs_info, "cache", flags, max_active, 0);
 
 	/*
 	 * a higher idle thresh on the submit workers makes it much more
@@ -2334,41 +2336,48 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
 	 * devices
 	 */
 	fs_info->submit_workers =
-		btrfs_alloc_workqueue("submit", flags,
+		btrfs_alloc_workqueue(fs_info, "submit", flags,
 				      min_t(u64, fs_devices->num_devices,
 					    max_active), 64);
 
 	fs_info->fixup_workers =
-		btrfs_alloc_workqueue("fixup", flags, 1, 0);
+		btrfs_alloc_workqueue(fs_info, "fixup", flags, 1, 0);
 
 	/*
 	 * endios are largely parallel and should have a very
 	 * low idle thresh
 	 */
 	fs_info->endio_workers =
-		btrfs_alloc_workqueue("endio", flags, max_active, 4);
+		btrfs_alloc_workqueue(fs_info, "endio", flags, max_active, 4);
 	fs_info->endio_meta_workers =
-		btrfs_alloc_workqueue("endio-meta", flags, max_active, 4);
+		btrfs_alloc_workqueue(fs_info, "endio-meta", flags,
+				      max_active, 4);
 	fs_info->endio_meta_write_workers =
-		btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2);
+		btrfs_alloc_workqueue(fs_info, "endio-meta-write", flags,
+				      max_active, 2);
 	fs_info->endio_raid56_workers =
-		btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4);
+		btrfs_alloc_workqueue(fs_info, "endio-raid56", flags,
+				      max_active, 4);
 	fs_info->endio_repair_workers =
-		btrfs_alloc_workqueue("endio-repair", flags, 1, 0);
+		btrfs_alloc_workqueue(fs_info, "endio-repair", flags, 1, 0);
 	fs_info->rmw_workers =
-		btrfs_alloc_workqueue("rmw", flags, max_active, 2);
+		btrfs_alloc_workqueue(fs_info, "rmw", flags, max_active, 2);
 	fs_info->endio_write_workers =
-		btrfs_alloc_workqueue("endio-write", flags, max_active, 2);
+		btrfs_alloc_workqueue(fs_info, "endio-write", flags,
+				      max_active, 2);
 	fs_info->endio_freespace_worker =
-		btrfs_alloc_workqueue("freespace-write", flags, max_active, 0);
+		btrfs_alloc_workqueue(fs_info, "freespace-write", flags,
+				      max_active, 0);
 	fs_info->delayed_workers =
-		btrfs_alloc_workqueue("delayed-meta", flags, max_active, 0);
+		btrfs_alloc_workqueue(fs_info, "delayed-meta", flags,
+				      max_active, 0);
 	fs_info->readahead_workers =
-		btrfs_alloc_workqueue("readahead", flags, max_active, 2);
+		btrfs_alloc_workqueue(fs_info, "readahead", flags,
+				      max_active, 2);
 	fs_info->qgroup_rescan_workers =
-		btrfs_alloc_workqueue("qgroup-rescan", flags, 1, 0);
+		btrfs_alloc_workqueue(fs_info, "qgroup-rescan", flags, 1, 0);
 	fs_info->extent_workers =
-		btrfs_alloc_workqueue("extent-refs", flags,
+		btrfs_alloc_workqueue(fs_info, "extent-refs", flags,
 				      min_t(u64, fs_devices->num_devices,
 					    max_active), 8);
 
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 70427ef..86270c6 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3781,27 +3781,27 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
 	if (fs_info->scrub_workers_refcnt == 0) {
 		if (is_dev_replace)
 			fs_info->scrub_workers =
-				btrfs_alloc_workqueue("scrub", flags,
+				btrfs_alloc_workqueue(fs_info, "scrub", flags,
 						      1, 4);
 		else
 			fs_info->scrub_workers =
-				btrfs_alloc_workqueue("scrub", flags,
+				btrfs_alloc_workqueue(fs_info, "scrub", flags,
 						      max_active, 4);
 		if (!fs_info->scrub_workers)
 			goto fail_scrub_workers;
 
 		fs_info->scrub_wr_completion_workers =
-			btrfs_alloc_workqueue("scrubwrc", flags,
+			btrfs_alloc_workqueue(fs_info, "scrubwrc", flags,
 					      max_active, 2);
 		if (!fs_info->scrub_wr_completion_workers)
 			goto fail_scrub_wr_completion_workers;
 
 		fs_info->scrub_nocow_workers =
-			btrfs_alloc_workqueue("scrubnc", flags, 1, 0);
+			btrfs_alloc_workqueue(fs_info, "scrubnc", flags, 1, 0);
 		if (!fs_info->scrub_nocow_workers)
 			goto fail_scrub_nocow_workers;
 		fs_info->scrub_parity_workers =
-			btrfs_alloc_workqueue("scrubparity", flags,
+			btrfs_alloc_workqueue(fs_info, "scrubparity", flags,
 					      max_active, 2);
 		if (!fs_info->scrub_parity_workers)
 			goto fail_scrub_parity_workers;
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 02/31] btrfs: prefix fsid to all trace events
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
  2016-06-24 22:14 ` [PATCH 01/31] btrfs: plumb fs_info into btrfs_work jeffm
@ 2016-06-24 22:14 ` jeffm
  2016-06-27  1:50   ` Qu Wenruo
  2016-06-24 22:14 ` [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info jeffm
                   ` (29 subsequent siblings)
  31 siblings, 1 reply; 44+ messages in thread
From: jeffm @ 2016-06-24 22:14 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

When using trace events to debug a problem, it's impossible to determine
which file system generated a particular event.  This patch adds a
macro to prefix standard information to the head of a trace event.

The extent_state alloc/free events are all that's left without an
fs_info available.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/delayed-ref.c       |   9 +-
 fs/btrfs/extent-tree.c       |  10 +-
 fs/btrfs/qgroup.c            |  19 +--
 fs/btrfs/qgroup.h            |   9 +-
 fs/btrfs/super.c             |   2 +-
 include/trace/events/btrfs.h | 282 ++++++++++++++++++++++++-------------------
 6 files changed, 182 insertions(+), 149 deletions(-)

diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 430b368..e7b1ec0 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -606,7 +606,8 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
 		qrecord->num_bytes = num_bytes;
 		qrecord->old_roots = NULL;
 
-		qexisting = btrfs_qgroup_insert_dirty_extent(delayed_refs,
+		qexisting = btrfs_qgroup_insert_dirty_extent(fs_info,
+							     delayed_refs,
 							     qrecord);
 		if (qexisting)
 			kfree(qrecord);
@@ -615,7 +616,7 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
 	spin_lock_init(&head_ref->lock);
 	mutex_init(&head_ref->mutex);
 
-	trace_add_delayed_ref_head(ref, head_ref, action);
+	trace_add_delayed_ref_head(fs_info, ref, head_ref, action);
 
 	existing = htree_insert(&delayed_refs->href_root,
 				&head_ref->href_node);
@@ -682,7 +683,7 @@ add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
 		ref->type = BTRFS_TREE_BLOCK_REF_KEY;
 	full_ref->level = level;
 
-	trace_add_delayed_tree_ref(ref, full_ref, action);
+	trace_add_delayed_tree_ref(fs_info, ref, full_ref, action);
 
 	ret = add_delayed_ref_tail_merge(trans, delayed_refs, head_ref, ref);
 
@@ -739,7 +740,7 @@ add_delayed_data_ref(struct btrfs_fs_info *fs_info,
 	full_ref->objectid = owner;
 	full_ref->offset = offset;
 
-	trace_add_delayed_data_ref(ref, full_ref, action);
+	trace_add_delayed_data_ref(fs_info, ref, full_ref, action);
 
 	ret = add_delayed_ref_tail_merge(trans, delayed_refs, head_ref, ref);
 
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 29e5d00..39308a8 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2194,7 +2194,7 @@ static int run_delayed_data_ref(struct btrfs_trans_handle *trans,
 	ins.type = BTRFS_EXTENT_ITEM_KEY;
 
 	ref = btrfs_delayed_node_to_data_ref(node);
-	trace_run_delayed_data_ref(node, ref, node->action);
+	trace_run_delayed_data_ref(root->fs_info, node, ref, node->action);
 
 	if (node->type == BTRFS_SHARED_DATA_REF_KEY)
 		parent = ref->parent;
@@ -2349,7 +2349,7 @@ static int run_delayed_tree_ref(struct btrfs_trans_handle *trans,
 						 SKINNY_METADATA);
 
 	ref = btrfs_delayed_node_to_tree_ref(node);
-	trace_run_delayed_tree_ref(node, ref, node->action);
+	trace_run_delayed_tree_ref(root->fs_info, node, ref, node->action);
 
 	if (node->type == BTRFS_SHARED_BLOCK_REF_KEY)
 		parent = ref->parent;
@@ -2413,7 +2413,8 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
 		 */
 		BUG_ON(extent_op);
 		head = btrfs_delayed_node_to_head(node);
-		trace_run_delayed_ref_head(node, head, node->action);
+		trace_run_delayed_ref_head(root->fs_info, node, head,
+					   node->action);
 
 		if (insert_reserved) {
 			btrfs_pin_extent(root, node->bytenr,
@@ -8317,7 +8318,8 @@ static int record_one_subtree_extent(struct btrfs_trans_handle *trans,
 
 	delayed_refs = &trans->transaction->delayed_refs;
 	spin_lock(&delayed_refs->lock);
-	if (btrfs_qgroup_insert_dirty_extent(delayed_refs, qrecord))
+	if (btrfs_qgroup_insert_dirty_extent(trans->root->fs_info,
+					     delayed_refs, qrecord))
 		kfree(qrecord);
 	spin_unlock(&delayed_refs->lock);
 
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 9d4c05b..13e28d8 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1453,9 +1453,10 @@ int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
-struct btrfs_qgroup_extent_record
-*btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs,
-				  struct btrfs_qgroup_extent_record *record)
+struct btrfs_qgroup_extent_record *
+btrfs_qgroup_insert_dirty_extent(struct btrfs_fs_info *fs_info,
+				 struct btrfs_delayed_ref_root *delayed_refs,
+				 struct btrfs_qgroup_extent_record *record)
 {
 	struct rb_node **p = &delayed_refs->dirty_extent_root.rb_node;
 	struct rb_node *parent_node = NULL;
@@ -1463,7 +1464,7 @@ struct btrfs_qgroup_extent_record
 	u64 bytenr = record->bytenr;
 
 	assert_spin_locked(&delayed_refs->lock);
-	trace_btrfs_qgroup_insert_dirty_extent(record);
+	trace_btrfs_qgroup_insert_dirty_extent(fs_info, record);
 
 	while (*p) {
 		parent_node = *p;
@@ -1595,8 +1596,8 @@ static int qgroup_update_counters(struct btrfs_fs_info *fs_info,
 		cur_old_count = btrfs_qgroup_get_old_refcnt(qg, seq);
 		cur_new_count = btrfs_qgroup_get_new_refcnt(qg, seq);
 
-		trace_qgroup_update_counters(qg->qgroupid, cur_old_count,
-					     cur_new_count);
+		trace_qgroup_update_counters(fs_info, qg->qgroupid,
+					     cur_old_count, cur_new_count);
 
 		/* Rfer update part */
 		if (cur_old_count == 0 && cur_new_count > 0) {
@@ -1687,8 +1688,8 @@ btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
 		goto out_free;
 	BUG_ON(!fs_info->quota_root);
 
-	trace_btrfs_qgroup_account_extent(bytenr, num_bytes, nr_old_roots,
-					  nr_new_roots);
+	trace_btrfs_qgroup_account_extent(fs_info, bytenr, num_bytes,
+					  nr_old_roots, nr_new_roots);
 
 	qgroups = ulist_alloc(GFP_NOFS);
 	if (!qgroups) {
@@ -1759,7 +1760,7 @@ int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans,
 		record = rb_entry(node, struct btrfs_qgroup_extent_record,
 				  node);
 
-		trace_btrfs_qgroup_account_extents(record);
+		trace_btrfs_qgroup_account_extents(fs_info, record);
 
 		if (!ret) {
 			/*
diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h
index ecb2c14..710887c 100644
--- a/fs/btrfs/qgroup.h
+++ b/fs/btrfs/qgroup.h
@@ -63,9 +63,10 @@ void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info);
 struct btrfs_delayed_extent_op;
 int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
 					 struct btrfs_fs_info *fs_info);
-struct btrfs_qgroup_extent_record
-*btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs,
-				  struct btrfs_qgroup_extent_record *record);
+struct btrfs_qgroup_extent_record *
+btrfs_qgroup_insert_dirty_extent(struct btrfs_fs_info *fs_info,
+				 struct btrfs_delayed_ref_root *delayed_refs,
+				 struct btrfs_qgroup_extent_record *record);
 int
 btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
 			    struct btrfs_fs_info *fs_info,
@@ -88,7 +89,7 @@ static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info,
 						 u64 ref_root, u64 num_bytes)
 {
 	btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes);
-	trace_btrfs_qgroup_free_delayed_ref(ref_root, num_bytes);
+	trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes);
 }
 void assert_qgroups_uptodate(struct btrfs_trans_handle *trans);
 
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 60e7179..ee56b0e 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1149,7 +1149,7 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
 	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
 	struct btrfs_root *root = fs_info->tree_root;
 
-	trace_btrfs_sync_fs(wait);
+	trace_btrfs_sync_fs(fs_info, wait);
 
 	if (!wait) {
 		filemap_flush(fs_info->btree_inode->i_mapping);
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index e90e82a..eba0c65 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -66,6 +66,21 @@ struct btrfs_qgroup_extent_record;
 	{ BTRFS_BLOCK_GROUP_RAID6,	"RAID6"}
 
 #define BTRFS_UUID_SIZE 16
+#define TP_STRUCT__entry_fsid __array(u8, fsid, BTRFS_UUID_SIZE)
+
+#define TP_fast_assign_fsid(fs_info)					\
+	memcpy(__entry->fsid, fs_info->fsid, BTRFS_UUID_SIZE)
+
+#define TP_STRUCT__entry_btrfs(args...)					\
+	TP_STRUCT__entry(						\
+		TP_STRUCT__entry_fsid					\
+		args)
+#define TP_fast_assign_btrfs(fs_info, args...)				\
+	TP_fast_assign(							\
+		TP_fast_assign_fsid(fs_info);				\
+		args)
+#define TP_printk_btrfs(fmt, args...) \
+	TP_printk("%pU: " fmt, __entry->fsid, args)
 
 TRACE_EVENT(btrfs_transaction_commit,
 
@@ -73,17 +88,17 @@ TRACE_EVENT(btrfs_transaction_commit,
 
 	TP_ARGS(root),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  generation		)
 		__field(	u64,  root_objectid		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(root->fs_info,
 		__entry->generation	= root->fs_info->generation;
 		__entry->root_objectid	= root->root_key.objectid;
 	),
 
-	TP_printk("root = %llu(%s), gen = %llu",
+	TP_printk_btrfs("root = %llu(%s), gen = %llu",
 		  show_root_type(__entry->root_objectid),
 		  (unsigned long long)__entry->generation)
 );
@@ -94,7 +109,7 @@ DECLARE_EVENT_CLASS(btrfs__inode,
 
 	TP_ARGS(inode),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	ino_t,  ino			)
 		__field(	blkcnt_t,  blocks		)
 		__field(	u64,  disk_i_size		)
@@ -104,7 +119,7 @@ DECLARE_EVENT_CLASS(btrfs__inode,
 		__field(	u64,  root_objectid		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
 		__entry->ino	= inode->i_ino;
 		__entry->blocks	= inode->i_blocks;
 		__entry->disk_i_size  = BTRFS_I(inode)->disk_i_size;
@@ -115,7 +130,7 @@ DECLARE_EVENT_CLASS(btrfs__inode,
 				BTRFS_I(inode)->root->root_key.objectid;
 	),
 
-	TP_printk("root = %llu(%s), gen = %llu, ino = %lu, blocks = %llu, "
+	TP_printk_btrfs("root = %llu(%s), gen = %llu, ino = %lu, blocks = %llu, "
 		  "disk_i_size = %llu, last_trans = %llu, logged_trans = %llu",
 		  show_root_type(__entry->root_objectid),
 		  (unsigned long long)__entry->generation,
@@ -175,7 +190,7 @@ TRACE_EVENT_CONDITION(btrfs_get_extent,
 
 	TP_CONDITION(map),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  root_objectid	)
 		__field(	u64,  start		)
 		__field(	u64,  len		)
@@ -187,7 +202,7 @@ TRACE_EVENT_CONDITION(btrfs_get_extent,
 		__field(	unsigned int,  compress_type	)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(root->fs_info,
 		__entry->root_objectid	= root->root_key.objectid;
 		__entry->start 		= map->start;
 		__entry->len		= map->len;
@@ -199,7 +214,7 @@ TRACE_EVENT_CONDITION(btrfs_get_extent,
 		__entry->compress_type	= map->compress_type;
 	),
 
-	TP_printk("root = %llu(%s), start = %llu, len = %llu, "
+	TP_printk_btrfs("root = %llu(%s), start = %llu, len = %llu, "
 		  "orig_start = %llu, block_start = %llu(%s), "
 		  "block_len = %llu, flags = %s, refs = %u, "
 		  "compress_type = %u",
@@ -233,7 +248,7 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent,
 
 	TP_ARGS(inode, ordered),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	ino_t,  ino		)
 		__field(	u64,  file_offset	)
 		__field(	u64,  start		)
@@ -246,7 +261,7 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent,
 		__field(	u64,  root_objectid	)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
 		__entry->ino 		= inode->i_ino;
 		__entry->file_offset	= ordered->file_offset;
 		__entry->start		= ordered->start;
@@ -260,7 +275,7 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent,
 				BTRFS_I(inode)->root->root_key.objectid;
 	),
 
-	TP_printk("root = %llu(%s), ino = %llu, file_offset = %llu, "
+	TP_printk_btrfs("root = %llu(%s), ino = %llu, file_offset = %llu, "
 		  "start = %llu, len = %llu, disk_len = %llu, "
 		  "bytes_left = %llu, flags = %s, compress_type = %d, "
 		  "refs = %d",
@@ -310,7 +325,7 @@ DECLARE_EVENT_CLASS(btrfs__writepage,
 
 	TP_ARGS(page, inode, wbc),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	ino_t,  ino			)
 		__field(	pgoff_t,  index			)
 		__field(	long,   nr_to_write		)
@@ -324,7 +339,7 @@ DECLARE_EVENT_CLASS(btrfs__writepage,
 		__field(	u64,    root_objectid		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
 		__entry->ino		= inode->i_ino;
 		__entry->index		= page->index;
 		__entry->nr_to_write	= wbc->nr_to_write;
@@ -339,7 +354,7 @@ DECLARE_EVENT_CLASS(btrfs__writepage,
 				 BTRFS_I(inode)->root->root_key.objectid;
 	),
 
-	TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, "
+	TP_printk_btrfs("root = %llu(%s), ino = %lu, page_index = %lu, "
 		  "nr_to_write = %ld, pages_skipped = %ld, range_start = %llu, "
 		  "range_end = %llu, for_kupdate = %d, "
 		  "for_reclaim = %d, range_cyclic = %d, writeback_index = %lu",
@@ -366,7 +381,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook,
 
 	TP_ARGS(page, start, end, uptodate),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	ino_t,	 ino		)
 		__field(	pgoff_t, index		)
 		__field(	u64,	 start		)
@@ -375,7 +390,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook,
 		__field(	u64,    root_objectid	)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_sb(page->mapping->host->i_sb),
 		__entry->ino	= page->mapping->host->i_ino;
 		__entry->index	= page->index;
 		__entry->start	= start;
@@ -385,7 +400,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook,
 			 BTRFS_I(page->mapping->host)->root->root_key.objectid;
 	),
 
-	TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, start = %llu, "
+	TP_printk_btrfs("root = %llu(%s), ino = %lu, page_index = %lu, start = %llu, "
 		  "end = %llu, uptodate = %d",
 		  show_root_type(__entry->root_objectid),
 		  (unsigned long)__entry->ino, (unsigned long)__entry->index,
@@ -399,7 +414,7 @@ TRACE_EVENT(btrfs_sync_file,
 
 	TP_ARGS(file, datasync),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	ino_t,  ino		)
 		__field(	ino_t,  parent		)
 		__field(	int,    datasync	)
@@ -410,6 +425,7 @@ TRACE_EVENT(btrfs_sync_file,
 		struct dentry *dentry = file->f_path.dentry;
 		struct inode *inode = d_inode(dentry);
 
+		TP_fast_assign_fsid(btrfs_sb(file->f_path.dentry->d_sb));
 		__entry->ino		= inode->i_ino;
 		__entry->parent		= d_inode(dentry->d_parent)->i_ino;
 		__entry->datasync	= datasync;
@@ -417,7 +433,7 @@ TRACE_EVENT(btrfs_sync_file,
 				 BTRFS_I(inode)->root->root_key.objectid;
 	),
 
-	TP_printk("root = %llu(%s), ino = %ld, parent = %ld, datasync = %d",
+	TP_printk_btrfs("root = %llu(%s), ino = %ld, parent = %ld, datasync = %d",
 		  show_root_type(__entry->root_objectid),
 		  (unsigned long)__entry->ino, (unsigned long)__entry->parent,
 		  __entry->datasync)
@@ -425,19 +441,19 @@ TRACE_EVENT(btrfs_sync_file,
 
 TRACE_EVENT(btrfs_sync_fs,
 
-	TP_PROTO(int wait),
+	TP_PROTO(struct btrfs_fs_info *fs_info, int wait),
 
-	TP_ARGS(wait),
+	TP_ARGS(fs_info, wait),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	int,  wait		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(fs_info,
 		__entry->wait	= wait;
 	),
 
-	TP_printk("wait = %d", __entry->wait)
+	TP_printk_btrfs("wait = %d", __entry->wait)
 );
 
 #define show_ref_action(action)						\
@@ -450,13 +466,14 @@ TRACE_EVENT(btrfs_sync_fs,
 
 DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
 
-	TP_PROTO(struct btrfs_delayed_ref_node *ref,
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_delayed_ref_node *ref,
 		 struct btrfs_delayed_tree_ref *full_ref,
 		 int action),
 
-	TP_ARGS(ref, full_ref, action),
+	TP_ARGS(fs_info, ref, full_ref, action),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  bytenr		)
 		__field(	u64,  num_bytes		)
 		__field(	int,  action		) 
@@ -467,7 +484,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
 		__field(	u64,  seq		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(fs_info,
 		__entry->bytenr		= ref->bytenr;
 		__entry->num_bytes	= ref->num_bytes;
 		__entry->action		= action;
@@ -478,7 +495,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
 		__entry->seq		= ref->seq;
 	),
 
-	TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, "
+	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, action = %s, "
 		  "parent = %llu(%s), ref_root = %llu(%s), level = %d, "
 		  "type = %s, seq = %llu",
 		  (unsigned long long)__entry->bytenr,
@@ -492,31 +509,34 @@ DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
 
 DEFINE_EVENT(btrfs_delayed_tree_ref,  add_delayed_tree_ref,
 
-	TP_PROTO(struct btrfs_delayed_ref_node *ref,
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_delayed_ref_node *ref,
 		 struct btrfs_delayed_tree_ref *full_ref,
 		 int action),
 
-	TP_ARGS(ref, full_ref, action)
+	TP_ARGS(fs_info, ref, full_ref, action)
 );
 
 DEFINE_EVENT(btrfs_delayed_tree_ref,  run_delayed_tree_ref,
 
-	TP_PROTO(struct btrfs_delayed_ref_node *ref,
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_delayed_ref_node *ref,
 		 struct btrfs_delayed_tree_ref *full_ref,
 		 int action),
 
-	TP_ARGS(ref, full_ref, action)
+	TP_ARGS(fs_info, ref, full_ref, action)
 );
 
 DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
 
-	TP_PROTO(struct btrfs_delayed_ref_node *ref,
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_delayed_ref_node *ref,
 		 struct btrfs_delayed_data_ref *full_ref,
 		 int action),
 
-	TP_ARGS(ref, full_ref, action),
+	TP_ARGS(fs_info, ref, full_ref, action),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  bytenr		)
 		__field(	u64,  num_bytes		)
 		__field(	int,  action		) 
@@ -528,7 +548,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
 		__field(	u64,  seq		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(fs_info,
 		__entry->bytenr		= ref->bytenr;
 		__entry->num_bytes	= ref->num_bytes;
 		__entry->action		= action;
@@ -540,7 +560,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
 		__entry->seq		= ref->seq;
 	),
 
-	TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, "
+	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, action = %s, "
 		  "parent = %llu(%s), ref_root = %llu(%s), owner = %llu, "
 		  "offset = %llu, type = %s, seq = %llu",
 		  (unsigned long long)__entry->bytenr,
@@ -556,45 +576,48 @@ DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
 
 DEFINE_EVENT(btrfs_delayed_data_ref,  add_delayed_data_ref,
 
-	TP_PROTO(struct btrfs_delayed_ref_node *ref,
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_delayed_ref_node *ref,
 		 struct btrfs_delayed_data_ref *full_ref,
 		 int action),
 
-	TP_ARGS(ref, full_ref, action)
+	TP_ARGS(fs_info, ref, full_ref, action)
 );
 
 DEFINE_EVENT(btrfs_delayed_data_ref,  run_delayed_data_ref,
 
-	TP_PROTO(struct btrfs_delayed_ref_node *ref,
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_delayed_ref_node *ref,
 		 struct btrfs_delayed_data_ref *full_ref,
 		 int action),
 
-	TP_ARGS(ref, full_ref, action)
+	TP_ARGS(fs_info, ref, full_ref, action)
 );
 
 DECLARE_EVENT_CLASS(btrfs_delayed_ref_head,
 
-	TP_PROTO(struct btrfs_delayed_ref_node *ref,
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_delayed_ref_node *ref,
 		 struct btrfs_delayed_ref_head *head_ref,
 		 int action),
 
-	TP_ARGS(ref, head_ref, action),
+	TP_ARGS(fs_info, ref, head_ref, action),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  bytenr		)
 		__field(	u64,  num_bytes		)
 		__field(	int,  action		) 
 		__field(	int,  is_data		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(fs_info,
 		__entry->bytenr		= ref->bytenr;
 		__entry->num_bytes	= ref->num_bytes;
 		__entry->action		= action;
 		__entry->is_data	= head_ref->is_data;
 	),
 
-	TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, is_data = %d",
+	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, action = %s, is_data = %d",
 		  (unsigned long long)__entry->bytenr,
 		  (unsigned long long)__entry->num_bytes,
 		  show_ref_action(__entry->action),
@@ -603,20 +626,22 @@ DECLARE_EVENT_CLASS(btrfs_delayed_ref_head,
 
 DEFINE_EVENT(btrfs_delayed_ref_head,  add_delayed_ref_head,
 
-	TP_PROTO(struct btrfs_delayed_ref_node *ref,
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_delayed_ref_node *ref,
 		 struct btrfs_delayed_ref_head *head_ref,
 		 int action),
 
-	TP_ARGS(ref, head_ref, action)
+	TP_ARGS(fs_info, ref, head_ref, action)
 );
 
 DEFINE_EVENT(btrfs_delayed_ref_head,  run_delayed_ref_head,
 
-	TP_PROTO(struct btrfs_delayed_ref_node *ref,
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_delayed_ref_node *ref,
 		 struct btrfs_delayed_ref_head *head_ref,
 		 int action),
 
-	TP_ARGS(ref, head_ref, action)
+	TP_ARGS(fs_info, ref, head_ref, action)
 );
 
 #define show_chunk_type(type)					\
@@ -638,7 +663,7 @@ DECLARE_EVENT_CLASS(btrfs__chunk,
 
 	TP_ARGS(root, map, offset, size),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	int,  num_stripes		)
 		__field(	u64,  type			)
 		__field(	int,  sub_stripes		)
@@ -647,7 +672,7 @@ DECLARE_EVENT_CLASS(btrfs__chunk,
 		__field(	u64,  root_objectid		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(root->fs_info,
 		__entry->num_stripes	= map->num_stripes;
 		__entry->type		= map->type;
 		__entry->sub_stripes	= map->sub_stripes;
@@ -656,7 +681,7 @@ DECLARE_EVENT_CLASS(btrfs__chunk,
 		__entry->root_objectid	= root->root_key.objectid;
 	),
 
-	TP_printk("root = %llu(%s), offset = %llu, size = %llu, "
+	TP_printk_btrfs("root = %llu(%s), offset = %llu, size = %llu, "
 		  "num_stripes = %d, sub_stripes = %d, type = %s",
 		  show_root_type(__entry->root_objectid),
 		  (unsigned long long)__entry->offset,
@@ -688,7 +713,7 @@ TRACE_EVENT(btrfs_cow_block,
 
 	TP_ARGS(root, buf, cow),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  root_objectid		)
 		__field(	u64,  buf_start			)
 		__field(	int,  refs			)
@@ -697,7 +722,7 @@ TRACE_EVENT(btrfs_cow_block,
 		__field(	int,  cow_level			)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(root->fs_info,
 		__entry->root_objectid	= root->root_key.objectid;
 		__entry->buf_start	= buf->start;
 		__entry->refs		= atomic_read(&buf->refs);
@@ -706,7 +731,7 @@ TRACE_EVENT(btrfs_cow_block,
 		__entry->cow_level	= btrfs_header_level(cow);
 	),
 
-	TP_printk("root = %llu(%s), refs = %d, orig_buf = %llu "
+	TP_printk_btrfs("root = %llu(%s), refs = %d, orig_buf = %llu "
 		  "(orig_level = %d), cow_buf = %llu (cow_level = %d)",
 		  show_root_type(__entry->root_objectid),
 		  __entry->refs,
@@ -723,25 +748,23 @@ TRACE_EVENT(btrfs_space_reservation,
 
 	TP_ARGS(fs_info, type, val, bytes, reserve),
 
-	TP_STRUCT__entry(
-		__array(	u8,	fsid,	BTRFS_UUID_SIZE	)
+	TP_STRUCT__entry_btrfs(
 		__string(	type,	type			)
 		__field(	u64,	val			)
 		__field(	u64,	bytes			)
 		__field(	int,	reserve			)
 	),
 
-	TP_fast_assign(
-		memcpy(__entry->fsid, fs_info->fsid, BTRFS_UUID_SIZE);
+	TP_fast_assign_btrfs(fs_info,
 		__assign_str(type, type);
 		__entry->val		= val;
 		__entry->bytes		= bytes;
 		__entry->reserve	= reserve;
 	),
 
-	TP_printk("%pU: %s: %Lu %s %Lu", __entry->fsid, __get_str(type),
-		  __entry->val, __entry->reserve ? "reserve" : "release",
-		  __entry->bytes)
+	TP_printk_btrfs("%s: %Lu %s %Lu", __get_str(type), __entry->val,
+			__entry->reserve ? "reserve" : "release",
+			__entry->bytes)
 );
 
 DECLARE_EVENT_CLASS(btrfs__reserved_extent,
@@ -750,19 +773,19 @@ DECLARE_EVENT_CLASS(btrfs__reserved_extent,
 
 	TP_ARGS(root, start, len),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  root_objectid		)
 		__field(	u64,  start			)
 		__field(	u64,  len			)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(root->fs_info,
 		__entry->root_objectid	= root->root_key.objectid;
 		__entry->start		= start;
 		__entry->len		= len;
 	),
 
-	TP_printk("root = %llu(%s), start = %llu, len = %llu",
+	TP_printk_btrfs("root = %llu(%s), start = %llu, len = %llu",
 		  show_root_type(__entry->root_objectid),
 		  (unsigned long long)__entry->start,
 		  (unsigned long long)__entry->len)
@@ -789,21 +812,21 @@ TRACE_EVENT(find_free_extent,
 
 	TP_ARGS(root, num_bytes, empty_size, data),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,	root_objectid		)
 		__field(	u64,	num_bytes		)
 		__field(	u64,	empty_size		)
 		__field(	u64,	data			)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(root->fs_info,
 		__entry->root_objectid	= root->root_key.objectid;
 		__entry->num_bytes	= num_bytes;
 		__entry->empty_size	= empty_size;
 		__entry->data		= data;
 	),
 
-	TP_printk("root = %Lu(%s), len = %Lu, empty_size = %Lu, "
+	TP_printk_btrfs("root = %Lu(%s), len = %Lu, empty_size = %Lu, "
 		  "flags = %Lu(%s)", show_root_type(__entry->root_objectid),
 		  __entry->num_bytes, __entry->empty_size, __entry->data,
 		  __print_flags((unsigned long)__entry->data, "|",
@@ -818,7 +841,7 @@ DECLARE_EVENT_CLASS(btrfs__reserve_extent,
 
 	TP_ARGS(root, block_group, start, len),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,	root_objectid		)
 		__field(	u64,	bg_objectid		)
 		__field(	u64,	flags			)
@@ -826,7 +849,7 @@ DECLARE_EVENT_CLASS(btrfs__reserve_extent,
 		__field(	u64,	len			)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(root->fs_info,
 		__entry->root_objectid	= root->root_key.objectid;
 		__entry->bg_objectid	= block_group->key.objectid;
 		__entry->flags		= block_group->flags;
@@ -834,7 +857,7 @@ DECLARE_EVENT_CLASS(btrfs__reserve_extent,
 		__entry->len		= len;
 	),
 
-	TP_printk("root = %Lu(%s), block_group = %Lu, flags = %Lu(%s), "
+	TP_printk_btrfs("root = %Lu(%s), block_group = %Lu, flags = %Lu(%s), "
 		  "start = %Lu, len = %Lu",
 		  show_root_type(__entry->root_objectid), __entry->bg_objectid,
 		  __entry->flags, __print_flags((unsigned long)__entry->flags,
@@ -867,7 +890,7 @@ TRACE_EVENT(btrfs_find_cluster,
 
 	TP_ARGS(block_group, start, bytes, empty_size, min_bytes),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,	bg_objectid		)
 		__field(	u64,	flags			)
 		__field(	u64,	start			)
@@ -876,7 +899,7 @@ TRACE_EVENT(btrfs_find_cluster,
 		__field(	u64,	min_bytes		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(block_group->fs_info,
 		__entry->bg_objectid	= block_group->key.objectid;
 		__entry->flags		= block_group->flags;
 		__entry->start		= start;
@@ -885,7 +908,7 @@ TRACE_EVENT(btrfs_find_cluster,
 		__entry->min_bytes	= min_bytes;
 	),
 
-	TP_printk("block_group = %Lu, flags = %Lu(%s), start = %Lu, len = %Lu,"
+	TP_printk_btrfs("block_group = %Lu, flags = %Lu(%s), start = %Lu, len = %Lu,"
 		  " empty_size = %Lu, min_bytes = %Lu", __entry->bg_objectid,
 		  __entry->flags,
 		  __print_flags((unsigned long)__entry->flags, "|",
@@ -899,15 +922,15 @@ TRACE_EVENT(btrfs_failed_cluster_setup,
 
 	TP_ARGS(block_group),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,	bg_objectid		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(block_group->fs_info,
 		__entry->bg_objectid	= block_group->key.objectid;
 	),
 
-	TP_printk("block_group = %Lu", __entry->bg_objectid)
+	TP_printk_btrfs("block_group = %Lu", __entry->bg_objectid)
 );
 
 TRACE_EVENT(btrfs_setup_cluster,
@@ -917,7 +940,7 @@ TRACE_EVENT(btrfs_setup_cluster,
 
 	TP_ARGS(block_group, cluster, size, bitmap),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,	bg_objectid		)
 		__field(	u64,	flags			)
 		__field(	u64,	start			)
@@ -926,7 +949,7 @@ TRACE_EVENT(btrfs_setup_cluster,
 		__field(	int,	bitmap			)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(block_group->fs_info,
 		__entry->bg_objectid	= block_group->key.objectid;
 		__entry->flags		= block_group->flags;
 		__entry->start		= cluster->window_start;
@@ -935,7 +958,7 @@ TRACE_EVENT(btrfs_setup_cluster,
 		__entry->bitmap		= bitmap;
 	),
 
-	TP_printk("block_group = %Lu, flags = %Lu(%s), window_start = %Lu, "
+	TP_printk_btrfs("block_group = %Lu, flags = %Lu(%s), window_start = %Lu, "
 		  "size = %Lu, max_size = %Lu, bitmap = %d",
 		  __entry->bg_objectid,
 		  __entry->flags,
@@ -993,7 +1016,7 @@ DECLARE_EVENT_CLASS(btrfs__work,
 
 	TP_ARGS(work),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	void *,	work			)
 		__field(	void *, wq			)
 		__field(	void *,	func			)
@@ -1002,7 +1025,7 @@ DECLARE_EVENT_CLASS(btrfs__work,
 		__field(	void *,	normal_work		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_work_owner(work),
 		__entry->work		= work;
 		__entry->wq		= work->wq;
 		__entry->func		= work->func;
@@ -1011,7 +1034,7 @@ DECLARE_EVENT_CLASS(btrfs__work,
 		__entry->normal_work	= &work->normal_work;
 	),
 
-	TP_printk("work=%p (normal_work=%p), wq=%p, func=%pf, ordered_func=%p,"
+	TP_printk_btrfs("work=%p (normal_work=%p), wq=%p, func=%pf, ordered_func=%p,"
 		  " ordered_free=%p",
 		  __entry->work, __entry->normal_work, __entry->wq,
 		   __entry->func, __entry->ordered_func, __entry->ordered_free)
@@ -1024,15 +1047,15 @@ DECLARE_EVENT_CLASS(btrfs__work__done,
 
 	TP_ARGS(work),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	void *,	work			)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_work_owner(work),
 		__entry->work		= work;
 	),
 
-	TP_printk("work->%p", __entry->work)
+	TP_printk_btrfs("work->%p", __entry->work)
 );
 
 DEFINE_EVENT(btrfs__work, btrfs_work_queued,
@@ -1069,19 +1092,19 @@ DECLARE_EVENT_CLASS(btrfs__workqueue,
 
 	TP_ARGS(wq, name, high),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	void *,	wq			)
 		__string(	name,	name			)
 		__field(	int ,	high			)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
 		__entry->wq		= wq;
 		__assign_str(name, name);
 		__entry->high		= high;
 	),
 
-	TP_printk("name=%s%s, wq=%p", __get_str(name),
+	TP_printk_btrfs("name=%s%s, wq=%p", __get_str(name),
 		  __print_flags(__entry->high, "",
 				{(WQ_HIGHPRI),	"-high"}),
 		  __entry->wq)
@@ -1100,15 +1123,15 @@ DECLARE_EVENT_CLASS(btrfs__workqueue_done,
 
 	TP_ARGS(wq),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	void *,	wq			)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
 		__entry->wq		= wq;
 	),
 
-	TP_printk("wq=%p", __entry->wq)
+	TP_printk_btrfs("wq=%p", __entry->wq)
 );
 
 DEFINE_EVENT(btrfs__workqueue_done, btrfs_workqueue_destroy,
@@ -1124,19 +1147,19 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_data_map,
 
 	TP_ARGS(inode, free_reserved),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,		rootid		)
 		__field(	unsigned long,	ino		)
 		__field(	u64,		free_reserved	)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
 		__entry->rootid		=	BTRFS_I(inode)->root->objectid;
 		__entry->ino		=	inode->i_ino;
 		__entry->free_reserved	=	free_reserved;
 	),
 
-	TP_printk("rootid=%llu, ino=%lu, free_reserved=%llu",
+	TP_printk_btrfs("rootid=%llu, ino=%lu, free_reserved=%llu",
 		  __entry->rootid, __entry->ino, __entry->free_reserved)
 );
 
@@ -1165,7 +1188,7 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data,
 
 	TP_ARGS(inode, start, len, reserved, op),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,		rootid		)
 		__field(	unsigned long,	ino		)
 		__field(	u64,		start		)
@@ -1174,7 +1197,7 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data,
 		__field(	int,		op		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
 		__entry->rootid		= BTRFS_I(inode)->root->objectid;
 		__entry->ino		= inode->i_ino;
 		__entry->start		= start;
@@ -1183,7 +1206,7 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data,
 		__entry->op		= op;
 	),
 
-	TP_printk("root=%llu, ino=%lu, start=%llu, len=%llu, reserved=%llu, op=%s",
+	TP_printk_btrfs("root=%llu, ino=%lu, start=%llu, len=%llu, reserved=%llu, op=%s",
 		  __entry->rootid, __entry->ino, __entry->start, __entry->len,
 		  __entry->reserved,
 		  __print_flags((unsigned long)__entry->op, "",
@@ -1207,86 +1230,90 @@ DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_release_data,
 
 DECLARE_EVENT_CLASS(btrfs__qgroup_delayed_ref,
 
-	TP_PROTO(u64 ref_root, u64 reserved),
+	TP_PROTO(struct btrfs_fs_info *fs_info, u64 ref_root, u64 reserved),
 
-	TP_ARGS(ref_root, reserved),
+	TP_ARGS(fs_info, ref_root, reserved),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,		ref_root	)
 		__field(	u64,		reserved	)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(fs_info,
 		__entry->ref_root	= ref_root;
 		__entry->reserved	= reserved;
 	),
 
-	TP_printk("root=%llu, reserved=%llu, op=free",
+	TP_printk_btrfs("root=%llu, reserved=%llu, op=free",
 		  __entry->ref_root, __entry->reserved)
 );
 
 DEFINE_EVENT(btrfs__qgroup_delayed_ref, btrfs_qgroup_free_delayed_ref,
 
-	TP_PROTO(u64 ref_root, u64 reserved),
+	TP_PROTO(struct btrfs_fs_info *fs_info, u64 ref_root, u64 reserved),
 
-	TP_ARGS(ref_root, reserved)
+	TP_ARGS(fs_info, ref_root, reserved)
 );
 
 DECLARE_EVENT_CLASS(btrfs_qgroup_extent,
-	TP_PROTO(struct btrfs_qgroup_extent_record *rec),
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_qgroup_extent_record *rec),
 
-	TP_ARGS(rec),
+	TP_ARGS(fs_info, rec),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  bytenr		)
 		__field(	u64,  num_bytes		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(fs_info,
 		__entry->bytenr		= rec->bytenr,
 		__entry->num_bytes	= rec->num_bytes;
 	),
 
-	TP_printk("bytenr = %llu, num_bytes = %llu",
+	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu",
 		  (unsigned long long)__entry->bytenr,
 		  (unsigned long long)__entry->num_bytes)
 );
 
 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents,
 
-	TP_PROTO(struct btrfs_qgroup_extent_record *rec),
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_qgroup_extent_record *rec),
 
-	TP_ARGS(rec)
+	TP_ARGS(fs_info, rec)
 );
 
 DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_insert_dirty_extent,
 
-	TP_PROTO(struct btrfs_qgroup_extent_record *rec),
+	TP_PROTO(struct btrfs_fs_info *fs_info,
+		 struct btrfs_qgroup_extent_record *rec),
 
-	TP_ARGS(rec)
+	TP_ARGS(fs_info, rec)
 );
 
 TRACE_EVENT(btrfs_qgroup_account_extent,
 
-	TP_PROTO(u64 bytenr, u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots),
+	TP_PROTO(struct btrfs_fs_info *fs_info, u64 bytenr,
+		 u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots),
 
-	TP_ARGS(bytenr, num_bytes, nr_old_roots, nr_new_roots),
+	TP_ARGS(fs_info, bytenr, num_bytes, nr_old_roots, nr_new_roots),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  bytenr			)
 		__field(	u64,  num_bytes			)
 		__field(	u64,  nr_old_roots		)
 		__field(	u64,  nr_new_roots		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(fs_info,
 		__entry->bytenr		= bytenr;
 		__entry->num_bytes	= num_bytes;
 		__entry->nr_old_roots	= nr_old_roots;
 		__entry->nr_new_roots	= nr_new_roots;
 	),
 
-	TP_printk("bytenr = %llu, num_bytes = %llu, nr_old_roots = %llu, "
+	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, nr_old_roots = %llu, "
 		  "nr_new_roots = %llu",
 		  __entry->bytenr,
 		  __entry->num_bytes,
@@ -1296,23 +1323,24 @@ TRACE_EVENT(btrfs_qgroup_account_extent,
 
 TRACE_EVENT(qgroup_update_counters,
 
-	TP_PROTO(u64 qgid, u64 cur_old_count, u64 cur_new_count),
+	TP_PROTO(struct btrfs_fs_info *fs_info, u64 qgid,
+		 u64 cur_old_count, u64 cur_new_count),
 
-	TP_ARGS(qgid, cur_old_count, cur_new_count),
+	TP_ARGS(fs_info, qgid, cur_old_count, cur_new_count),
 
-	TP_STRUCT__entry(
+	TP_STRUCT__entry_btrfs(
 		__field(	u64,  qgid			)
 		__field(	u64,  cur_old_count		)
 		__field(	u64,  cur_new_count		)
 	),
 
-	TP_fast_assign(
+	TP_fast_assign_btrfs(fs_info,
 		__entry->qgid		= qgid;
 		__entry->cur_old_count	= cur_old_count;
 		__entry->cur_new_count	= cur_new_count;
 	),
 
-	TP_printk("qgid = %llu, cur_old_count = %llu, cur_new_count = %llu",
+	TP_printk_btrfs("qgid = %llu, cur_old_count = %llu, cur_new_count = %llu",
 		  __entry->qgid,
 		  __entry->cur_old_count,
 		  __entry->cur_new_count)
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
  2016-06-24 22:14 ` [PATCH 01/31] btrfs: plumb fs_info into btrfs_work jeffm
  2016-06-24 22:14 ` [PATCH 02/31] btrfs: prefix fsid to all trace events jeffm
@ 2016-06-24 22:14 ` jeffm
  2016-06-27  2:14   ` Qu Wenruo
  2016-06-24 22:14 ` [PATCH 04/31] btrfs: tests, move initialization into tests/ jeffm
                   ` (28 subsequent siblings)
  31 siblings, 1 reply; 44+ messages in thread
From: jeffm @ 2016-06-24 22:14 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

btrfs_test_opt and friends only use the root pointer to access
the fs_info.  Let's pass the fs_info directly in preparation to
eliminate similar patterns all over btrfs.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h            |  22 ++++----
 fs/btrfs/delayed-inode.c    |   2 +-
 fs/btrfs/dev-replace.c      |   4 +-
 fs/btrfs/disk-io.c          |  22 ++++----
 fs/btrfs/extent-tree.c      |  32 +++++------
 fs/btrfs/file.c             |   2 +-
 fs/btrfs/free-space-cache.c |   6 +-
 fs/btrfs/inode-map.c        |  12 ++--
 fs/btrfs/inode.c            |  12 ++--
 fs/btrfs/ioctl.c            |   2 +-
 fs/btrfs/super.c            | 132 +++++++++++++++++++++++---------------------
 fs/btrfs/transaction.c      |   6 +-
 fs/btrfs/tree-log.c         |   4 +-
 fs/btrfs/volumes.c          |  11 ++--
 14 files changed, 137 insertions(+), 132 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 101c3cf..100d2ea 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1297,21 +1297,21 @@ struct btrfs_root {
 #define btrfs_clear_opt(o, opt)		((o) &= ~BTRFS_MOUNT_##opt)
 #define btrfs_set_opt(o, opt)		((o) |= BTRFS_MOUNT_##opt)
 #define btrfs_raw_test_opt(o, opt)	((o) & BTRFS_MOUNT_##opt)
-#define btrfs_test_opt(root, opt)	((root)->fs_info->mount_opt & \
+#define btrfs_test_opt(fs_info, opt)	((fs_info)->mount_opt & \
 					 BTRFS_MOUNT_##opt)
 
-#define btrfs_set_and_info(root, opt, fmt, args...)			\
+#define btrfs_set_and_info(fs_info, opt, fmt, args...)			\
 {									\
-	if (!btrfs_test_opt(root, opt))					\
-		btrfs_info(root->fs_info, fmt, ##args);			\
-	btrfs_set_opt(root->fs_info->mount_opt, opt);			\
+	if (!btrfs_test_opt(fs_info, opt))				\
+		btrfs_info(fs_info, fmt, ##args);			\
+	btrfs_set_opt(fs_info->mount_opt, opt);				\
 }
 
-#define btrfs_clear_and_info(root, opt, fmt, args...)			\
+#define btrfs_clear_and_info(fs_info, opt, fmt, args...)		\
 {									\
-	if (btrfs_test_opt(root, opt))					\
-		btrfs_info(root->fs_info, fmt, ##args);			\
-	btrfs_clear_opt(root->fs_info->mount_opt, opt);			\
+	if (btrfs_test_opt(fs_info, opt))				\
+		btrfs_info(fs_info, fmt, ##args);			\
+	btrfs_clear_opt(fs_info->mount_opt, opt);			\
 }
 
 #ifdef CONFIG_BTRFS_DEBUG
@@ -1319,9 +1319,9 @@ static inline int
 btrfs_should_fragment_free_space(struct btrfs_root *root,
 				 struct btrfs_block_group_cache *block_group)
 {
-	return (btrfs_test_opt(root, FRAGMENT_METADATA) &&
+	return (btrfs_test_opt(root->fs_info, FRAGMENT_METADATA) &&
 		block_group->flags & BTRFS_BLOCK_GROUP_METADATA) ||
-	       (btrfs_test_opt(root, FRAGMENT_DATA) &&
+	       (btrfs_test_opt(root->fs_info, FRAGMENT_DATA) &&
 		block_group->flags &  BTRFS_BLOCK_GROUP_DATA);
 }
 #endif
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 61561c2..ed67717 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -653,7 +653,7 @@ static int btrfs_delayed_inode_reserve_metadata(
 		if (!ret)
 			goto out;
 
-		if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
+		if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
 			btrfs_debug(root->fs_info,
 				    "block rsv migrate returned %d", ret);
 			WARN_ON(1);
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 63ef9cd..e9bbff3 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -142,7 +142,7 @@ no_valid_dev_replace_entry_found:
 		 * missing
 		 */
 		if (!dev_replace->srcdev &&
-		    !btrfs_test_opt(dev_root, DEGRADED)) {
+		    !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
 			ret = -EIO;
 			btrfs_warn(fs_info,
 			   "cannot mount because device replace operation is ongoing and");
@@ -151,7 +151,7 @@ no_valid_dev_replace_entry_found:
 			   src_devid);
 		}
 		if (!dev_replace->tgtdev &&
-		    !btrfs_test_opt(dev_root, DEGRADED)) {
+		    !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
 			ret = -EIO;
 			btrfs_warn(fs_info,
 			   "cannot mount because device replace operation is ongoing and");
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 685c81a..8f27127 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3025,8 +3025,8 @@ retry_root_backup:
 	if (IS_ERR(fs_info->transaction_kthread))
 		goto fail_cleaner;
 
-	if (!btrfs_test_opt(tree_root, SSD) &&
-	    !btrfs_test_opt(tree_root, NOSSD) &&
+	if (!btrfs_test_opt(tree_root->fs_info, SSD) &&
+	    !btrfs_test_opt(tree_root->fs_info, NOSSD) &&
 	    !fs_info->fs_devices->rotating) {
 		btrfs_info(fs_info, "detected SSD devices, enabling SSD mode");
 		btrfs_set_opt(fs_info->mount_opt, SSD);
@@ -3039,9 +3039,9 @@ retry_root_backup:
 	btrfs_apply_pending_changes(fs_info);
 
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
-	if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) {
+	if (btrfs_test_opt(tree_root->fs_info, CHECK_INTEGRITY)) {
 		ret = btrfsic_mount(tree_root, fs_devices,
-				    btrfs_test_opt(tree_root,
+				    btrfs_test_opt(tree_root->fs_info,
 					CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
 				    1 : 0,
 				    fs_info->check_integrity_print_mask);
@@ -3057,7 +3057,7 @@ retry_root_backup:
 
 	/* do not make disk changes in broken FS or nologreplay is given */
 	if (btrfs_super_log_root(disk_super) != 0 &&
-	    !btrfs_test_opt(tree_root, NOLOGREPLAY)) {
+	    !btrfs_test_opt(tree_root->fs_info, NOLOGREPLAY)) {
 		ret = btrfs_replay_log(fs_info, fs_devices);
 		if (ret) {
 			err = ret;
@@ -3098,7 +3098,7 @@ retry_root_backup:
 	if (sb->s_flags & MS_RDONLY)
 		return 0;
 
-	if (btrfs_test_opt(tree_root, FREE_SPACE_TREE) &&
+	if (btrfs_test_opt(tree_root->fs_info, FREE_SPACE_TREE) &&
 	    !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
 		btrfs_info(fs_info, "creating free space tree");
 		ret = btrfs_create_free_space_tree(fs_info);
@@ -3135,7 +3135,7 @@ retry_root_backup:
 
 	btrfs_qgroup_rescan_resume(fs_info);
 
-	if (btrfs_test_opt(tree_root, CLEAR_CACHE) &&
+	if (btrfs_test_opt(tree_root->fs_info, CLEAR_CACHE) &&
 	    btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
 		btrfs_info(fs_info, "clearing free space tree");
 		ret = btrfs_clear_free_space_tree(fs_info);
@@ -3156,7 +3156,7 @@ retry_root_backup:
 			close_ctree(tree_root);
 			return ret;
 		}
-	} else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) ||
+	} else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) ||
 		   fs_info->generation !=
 				btrfs_super_uuid_tree_generation(disk_super)) {
 		btrfs_info(fs_info, "checking UUID tree");
@@ -3233,7 +3233,7 @@ fail:
 	return err;
 
 recovery_tree_root:
-	if (!btrfs_test_opt(tree_root, USEBACKUPROOT))
+	if (!btrfs_test_opt(tree_root->fs_info, USEBACKUPROOT))
 		goto fail_tree_roots;
 
 	free_root_pointers(fs_info, 0);
@@ -3648,7 +3648,7 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors)
 	int total_errors = 0;
 	u64 flags;
 
-	do_barriers = !btrfs_test_opt(root, NOBARRIER);
+	do_barriers = !btrfs_test_opt(root->fs_info, NOBARRIER);
 	backup_super_roots(root->fs_info);
 
 	sb = root->fs_info->super_for_commit;
@@ -3932,7 +3932,7 @@ void close_ctree(struct btrfs_root *root)
 	iput(fs_info->btree_inode);
 
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
-	if (btrfs_test_opt(root, CHECK_INTEGRITY))
+	if (btrfs_test_opt(root->fs_info, CHECK_INTEGRITY))
 		btrfsic_unmount(root, fs_info->fs_devices);
 #endif
 
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 39308a8..efb5459 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3427,7 +3427,7 @@ again:
 
 	spin_lock(&block_group->lock);
 	if (block_group->cached != BTRFS_CACHE_FINISHED ||
-	    !btrfs_test_opt(root, SPACE_CACHE)) {
+	    !btrfs_test_opt(root->fs_info, SPACE_CACHE)) {
 		/*
 		 * don't bother trying to write stuff out _if_
 		 * a) we're not cached,
@@ -3504,7 +3504,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
 	struct btrfs_path *path;
 
 	if (list_empty(&cur_trans->dirty_bgs) ||
-	    !btrfs_test_opt(root, SPACE_CACHE))
+	    !btrfs_test_opt(root->fs_info, SPACE_CACHE))
 		return 0;
 
 	path = btrfs_alloc_path();
@@ -4417,7 +4417,7 @@ void check_system_chunk(struct btrfs_trans_handle *trans,
 	thresh = btrfs_calc_trunc_metadata_size(root, num_devs) +
 		btrfs_calc_trans_metadata_size(root, 1);
 
-	if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) {
+	if (left < thresh && btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
 		btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
 			left, thresh, type);
 		dump_space_info(info, 0, 0);
@@ -6009,7 +6009,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
 		spin_lock(&cache->space_info->lock);
 		spin_lock(&cache->lock);
 
-		if (btrfs_test_opt(root, SPACE_CACHE) &&
+		if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
 		    cache->disk_cache_state < BTRFS_DC_CLEAR)
 			cache->disk_cache_state = BTRFS_DC_CLEAR;
 
@@ -6388,7 +6388,7 @@ fetch_cluster_info(struct btrfs_root *root, struct btrfs_space_info *space_info,
 		   u64 *empty_cluster)
 {
 	struct btrfs_free_cluster *ret = NULL;
-	bool ssd = btrfs_test_opt(root, SSD);
+	bool ssd = btrfs_test_opt(root->fs_info, SSD);
 
 	*empty_cluster = 0;
 	if (btrfs_mixed_space_info(space_info))
@@ -6518,7 +6518,7 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
 			break;
 		}
 
-		if (btrfs_test_opt(root, DISCARD))
+		if (btrfs_test_opt(root->fs_info, DISCARD))
 			ret = btrfs_discard_extent(root, start,
 						   end + 1 - start, NULL);
 
@@ -7737,7 +7737,7 @@ again:
 			if (num_bytes == min_alloc_size)
 				final_tried = true;
 			goto again;
-		} else if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
+		} else if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
 			struct btrfs_space_info *sinfo;
 
 			sinfo = __find_space_info(root->fs_info, flags);
@@ -7768,7 +7768,7 @@ static int __btrfs_free_reserved_extent(struct btrfs_root *root,
 	if (pin)
 		pin_down_extent(root, cache, start, len, 1);
 	else {
-		if (btrfs_test_opt(root, DISCARD))
+		if (btrfs_test_opt(root->fs_info, DISCARD))
 			ret = btrfs_discard_extent(root, start, len, NULL);
 		btrfs_add_free_space(cache, start, len);
 		btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc);
@@ -8078,7 +8078,7 @@ again:
 		goto again;
 	}
 
-	if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
+	if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
 		static DEFINE_RATELIMIT_STATE(_rs,
 				DEFAULT_RATELIMIT_INTERVAL * 10,
 				/*DEFAULT_RATELIMIT_BURST*/ 1);
@@ -9510,7 +9510,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
 	int full = 0;
 	int ret = 0;
 
-	debug = btrfs_test_opt(root, ENOSPC_DEBUG);
+	debug = btrfs_test_opt(root->fs_info, ENOSPC_DEBUG);
 
 	block_group = btrfs_lookup_block_group(root->fs_info, bytenr);
 
@@ -9782,7 +9782,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
 		space_info = list_entry(info->space_info.next,
 					struct btrfs_space_info,
 					list);
-		if (btrfs_test_opt(info->tree_root, ENOSPC_DEBUG)) {
+		if (btrfs_test_opt(info, ENOSPC_DEBUG)) {
 			if (WARN_ON(space_info->bytes_pinned > 0 ||
 			    space_info->bytes_reserved > 0 ||
 			    space_info->bytes_may_use > 0)) {
@@ -9906,10 +9906,10 @@ int btrfs_read_block_groups(struct btrfs_root *root)
 	path->reada = READA_FORWARD;
 
 	cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
-	if (btrfs_test_opt(root, SPACE_CACHE) &&
+	if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
 	    btrfs_super_generation(root->fs_info->super_copy) != cache_gen)
 		need_clear = 1;
-	if (btrfs_test_opt(root, CLEAR_CACHE))
+	if (btrfs_test_opt(root->fs_info, CLEAR_CACHE))
 		need_clear = 1;
 
 	while (1) {
@@ -9940,7 +9940,7 @@ int btrfs_read_block_groups(struct btrfs_root *root)
 			 * b) Setting 'dirty flag' makes sure that we flush
 			 *    the new space cache info onto disk.
 			 */
-			if (btrfs_test_opt(root, SPACE_CACHE))
+			if (btrfs_test_opt(root->fs_info, SPACE_CACHE))
 				cache->disk_cache_state = BTRFS_DC_CLEAR;
 		}
 
@@ -10406,7 +10406,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
 	spin_lock(&block_group->space_info->lock);
 	list_del_init(&block_group->ro_list);
 
-	if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
+	if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
 		WARN_ON(block_group->space_info->total_bytes
 			< block_group->key.offset);
 		WARN_ON(block_group->space_info->bytes_readonly
@@ -10674,7 +10674,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
 		spin_unlock(&space_info->lock);
 
 		/* DISCARD can flip during remount */
-		trimming = btrfs_test_opt(root, DISCARD);
+		trimming = btrfs_test_opt(root->fs_info, DISCARD);
 
 		/* Implicit trim during transaction commit. */
 		if (trimming)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e0c9bd3..ffd9001 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -132,7 +132,7 @@ static int __btrfs_add_inode_defrag(struct inode *inode,
 
 static inline int __need_auto_defrag(struct btrfs_root *root)
 {
-	if (!btrfs_test_opt(root, AUTO_DEFRAG))
+	if (!btrfs_test_opt(root->fs_info, AUTO_DEFRAG))
 		return 0;
 
 	if (btrfs_fs_closing(root->fs_info))
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 69d270f..cee2049 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -3026,7 +3026,7 @@ int btrfs_find_space_cluster(struct btrfs_root *root,
 	 * For metadata, allow allocates with smaller extents.  For
 	 * data, keep it dense.
 	 */
-	if (btrfs_test_opt(root, SSD_SPREAD)) {
+	if (btrfs_test_opt(root->fs_info, SSD_SPREAD)) {
 		cont1_bytes = min_bytes = bytes + empty_size;
 	} else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) {
 		cont1_bytes = bytes;
@@ -3470,7 +3470,7 @@ int load_free_ino_cache(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
 	int ret = 0;
 	u64 root_gen = btrfs_root_generation(&root->root_item);
 
-	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
+	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
 		return 0;
 
 	/*
@@ -3514,7 +3514,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
 	struct btrfs_io_ctl io_ctl;
 	bool release_metadata = true;
 
-	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
+	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
 		return 0;
 
 	memset(&io_ctl, 0, sizeof(io_ctl));
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index 70107f7..e3ad8c1 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -38,7 +38,7 @@ static int caching_kthread(void *data)
 	int slot;
 	int ret;
 
-	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
+	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
 		return 0;
 
 	path = btrfs_alloc_path();
@@ -141,7 +141,7 @@ static void start_caching(struct btrfs_root *root)
 	int ret;
 	u64 objectid;
 
-	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
+	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
 		return;
 
 	spin_lock(&root->ino_cache_lock);
@@ -185,7 +185,7 @@ static void start_caching(struct btrfs_root *root)
 
 int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid)
 {
-	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
+	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
 		return btrfs_find_free_objectid(root, objectid);
 
 again:
@@ -211,7 +211,7 @@ void btrfs_return_ino(struct btrfs_root *root, u64 objectid)
 {
 	struct btrfs_free_space_ctl *pinned = root->free_ino_pinned;
 
-	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
+	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
 		return;
 again:
 	if (root->ino_cache_state == BTRFS_CACHE_FINISHED) {
@@ -251,7 +251,7 @@ void btrfs_unpin_free_ino(struct btrfs_root *root)
 	struct rb_node *n;
 	u64 count;
 
-	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
+	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
 		return;
 
 	while (1) {
@@ -412,7 +412,7 @@ int btrfs_save_ino_cache(struct btrfs_root *root,
 	if (btrfs_root_refs(&root->root_item) == 0)
 		return 0;
 
-	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
+	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
 		return 0;
 
 	path = btrfs_alloc_path();
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d2be95c..141a233 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -374,12 +374,12 @@ static inline int inode_need_compress(struct inode *inode)
 	struct btrfs_root *root = BTRFS_I(inode)->root;
 
 	/* force compress */
-	if (btrfs_test_opt(root, FORCE_COMPRESS))
+	if (btrfs_test_opt(root->fs_info, FORCE_COMPRESS))
 		return 1;
 	/* bad compression ratios */
 	if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS)
 		return 0;
-	if (btrfs_test_opt(root, COMPRESS) ||
+	if (btrfs_test_opt(root->fs_info, COMPRESS) ||
 	    BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS ||
 	    BTRFS_I(inode)->force_compress)
 		return 1;
@@ -602,7 +602,7 @@ cont:
 		nr_pages_ret = 0;
 
 		/* flag the file so we don't compress in the future */
-		if (!btrfs_test_opt(root, FORCE_COMPRESS) &&
+		if (!btrfs_test_opt(root->fs_info, FORCE_COMPRESS) &&
 		    !(BTRFS_I(inode)->force_compress)) {
 			BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
 		}
@@ -1156,7 +1156,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
 		async_cow->start = start;
 
 		if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS &&
-		    !btrfs_test_opt(root, FORCE_COMPRESS))
+		    !btrfs_test_opt(root->fs_info, FORCE_COMPRESS))
 			cur_end = end;
 		else
 			cur_end = min(end, start + SZ_512K - 1);
@@ -6237,9 +6237,9 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
 	btrfs_inherit_iflags(inode, dir);
 
 	if (S_ISREG(mode)) {
-		if (btrfs_test_opt(root, NODATASUM))
+		if (btrfs_test_opt(root->fs_info, NODATASUM))
 			BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
-		if (btrfs_test_opt(root, NODATACOW))
+		if (btrfs_test_opt(root->fs_info, NODATACOW))
 			BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW |
 				BTRFS_INODE_NODATASUM;
 	}
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0517356..ffb1628 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2406,7 +2406,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 		 * rmdir(2).
 		 */
 		err = -EPERM;
-		if (!btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED))
+		if (!btrfs_test_opt(root->fs_info, USER_SUBVOL_RM_ALLOWED))
 			goto out_dput;
 
 		/*
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index ee56b0e..a7b9a15 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -432,12 +432,12 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			 */
 			break;
 		case Opt_nodatasum:
-			btrfs_set_and_info(root, NODATASUM,
+			btrfs_set_and_info(info, NODATASUM,
 					   "setting nodatasum");
 			break;
 		case Opt_datasum:
-			if (btrfs_test_opt(root, NODATASUM)) {
-				if (btrfs_test_opt(root, NODATACOW))
+			if (btrfs_test_opt(info, NODATASUM)) {
+				if (btrfs_test_opt(info, NODATACOW))
 					btrfs_info(root->fs_info, "setting datasum, datacow enabled");
 				else
 					btrfs_info(root->fs_info, "setting datasum");
@@ -446,9 +446,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			btrfs_clear_opt(info->mount_opt, NODATASUM);
 			break;
 		case Opt_nodatacow:
-			if (!btrfs_test_opt(root, NODATACOW)) {
-				if (!btrfs_test_opt(root, COMPRESS) ||
-				    !btrfs_test_opt(root, FORCE_COMPRESS)) {
+			if (!btrfs_test_opt(info, NODATACOW)) {
+				if (!btrfs_test_opt(info, COMPRESS) ||
+				    !btrfs_test_opt(info, FORCE_COMPRESS)) {
 					btrfs_info(root->fs_info,
 						   "setting nodatacow, compression disabled");
 				} else {
@@ -461,7 +461,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			btrfs_set_opt(info->mount_opt, NODATASUM);
 			break;
 		case Opt_datacow:
-			btrfs_clear_and_info(root, NODATACOW,
+			btrfs_clear_and_info(info, NODATACOW,
 					     "setting datacow");
 			break;
 		case Opt_compress_force:
@@ -470,10 +470,11 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			/* Fallthrough */
 		case Opt_compress:
 		case Opt_compress_type:
-			saved_compress_type = btrfs_test_opt(root, COMPRESS) ?
+			saved_compress_type = btrfs_test_opt(info,
+							     COMPRESS) ?
 				info->compress_type : BTRFS_COMPRESS_NONE;
 			saved_compress_force =
-				btrfs_test_opt(root, FORCE_COMPRESS);
+				btrfs_test_opt(info, FORCE_COMPRESS);
 			if (token == Opt_compress ||
 			    token == Opt_compress_force ||
 			    strcmp(args[0].from, "zlib") == 0) {
@@ -513,10 +514,10 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 				 */
 				btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
 			}
-			if ((btrfs_test_opt(root, COMPRESS) &&
+			if ((btrfs_test_opt(info, COMPRESS) &&
 			     (info->compress_type != saved_compress_type ||
 			      compress_force != saved_compress_force)) ||
-			    (!btrfs_test_opt(root, COMPRESS) &&
+			    (!btrfs_test_opt(info, COMPRESS) &&
 			     no_compress == 1)) {
 				btrfs_info(root->fs_info,
 					   "%s %s compression",
@@ -526,25 +527,25 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			compress_force = false;
 			break;
 		case Opt_ssd:
-			btrfs_set_and_info(root, SSD,
+			btrfs_set_and_info(info, SSD,
 					   "use ssd allocation scheme");
 			break;
 		case Opt_ssd_spread:
-			btrfs_set_and_info(root, SSD_SPREAD,
+			btrfs_set_and_info(info, SSD_SPREAD,
 					   "use spread ssd allocation scheme");
 			btrfs_set_opt(info->mount_opt, SSD);
 			break;
 		case Opt_nossd:
-			btrfs_set_and_info(root, NOSSD,
+			btrfs_set_and_info(info, NOSSD,
 					     "not using ssd allocation scheme");
 			btrfs_clear_opt(info->mount_opt, SSD);
 			break;
 		case Opt_barrier:
-			btrfs_clear_and_info(root, NOBARRIER,
+			btrfs_clear_and_info(info, NOBARRIER,
 					     "turning on barriers");
 			break;
 		case Opt_nobarrier:
-			btrfs_set_and_info(root, NOBARRIER,
+			btrfs_set_and_info(info, NOBARRIER,
 					   "turning off barriers");
 			break;
 		case Opt_thread_pool:
@@ -604,24 +605,24 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			root->fs_info->sb->s_flags &= ~MS_POSIXACL;
 			break;
 		case Opt_notreelog:
-			btrfs_set_and_info(root, NOTREELOG,
+			btrfs_set_and_info(info, NOTREELOG,
 					   "disabling tree log");
 			break;
 		case Opt_treelog:
-			btrfs_clear_and_info(root, NOTREELOG,
+			btrfs_clear_and_info(info, NOTREELOG,
 					     "enabling tree log");
 			break;
 		case Opt_norecovery:
 		case Opt_nologreplay:
-			btrfs_set_and_info(root, NOLOGREPLAY,
+			btrfs_set_and_info(info, NOLOGREPLAY,
 					   "disabling log replay at mount time");
 			break;
 		case Opt_flushoncommit:
-			btrfs_set_and_info(root, FLUSHONCOMMIT,
+			btrfs_set_and_info(info, FLUSHONCOMMIT,
 					   "turning on flush-on-commit");
 			break;
 		case Opt_noflushoncommit:
-			btrfs_clear_and_info(root, FLUSHONCOMMIT,
+			btrfs_clear_and_info(info, FLUSHONCOMMIT,
 					     "turning off flush-on-commit");
 			break;
 		case Opt_ratio:
@@ -638,11 +639,11 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			}
 			break;
 		case Opt_discard:
-			btrfs_set_and_info(root, DISCARD,
+			btrfs_set_and_info(info, DISCARD,
 					   "turning on discard");
 			break;
 		case Opt_nodiscard:
-			btrfs_clear_and_info(root, DISCARD,
+			btrfs_clear_and_info(info, DISCARD,
 					     "turning off discard");
 			break;
 		case Opt_space_cache:
@@ -651,12 +652,13 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			    strcmp(args[0].from, "v1") == 0) {
 				btrfs_clear_opt(root->fs_info->mount_opt,
 						FREE_SPACE_TREE);
-				btrfs_set_and_info(root, SPACE_CACHE,
+				btrfs_set_and_info(info, SPACE_CACHE,
 						   "enabling disk space caching");
 			} else if (strcmp(args[0].from, "v2") == 0) {
 				btrfs_clear_opt(root->fs_info->mount_opt,
 						SPACE_CACHE);
-				btrfs_set_and_info(root, FREE_SPACE_TREE,
+				btrfs_set_and_info(info,
+						   FREE_SPACE_TREE,
 						   "enabling free space tree");
 			} else {
 				ret = -EINVAL;
@@ -667,12 +669,14 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE);
 			break;
 		case Opt_no_space_cache:
-			if (btrfs_test_opt(root, SPACE_CACHE)) {
-				btrfs_clear_and_info(root, SPACE_CACHE,
+			if (btrfs_test_opt(info, SPACE_CACHE)) {
+				btrfs_clear_and_info(info,
+						     SPACE_CACHE,
 						     "disabling disk space caching");
 			}
-			if (btrfs_test_opt(root, FREE_SPACE_TREE)) {
-				btrfs_clear_and_info(root, FREE_SPACE_TREE,
+			if (btrfs_test_opt(info, FREE_SPACE_TREE)) {
+				btrfs_clear_and_info(info,
+						     FREE_SPACE_TREE,
 						     "disabling free space tree");
 			}
 			break;
@@ -685,7 +689,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 					     "disabling inode map caching");
 			break;
 		case Opt_clear_cache:
-			btrfs_set_and_info(root, CLEAR_CACHE,
+			btrfs_set_and_info(info, CLEAR_CACHE,
 					   "force clearing of disk cache");
 			break;
 		case Opt_user_subvol_rm_allowed:
@@ -698,11 +702,11 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,
 			btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG);
 			break;
 		case Opt_defrag:
-			btrfs_set_and_info(root, AUTO_DEFRAG,
+			btrfs_set_and_info(info, AUTO_DEFRAG,
 					   "enabling auto defrag");
 			break;
 		case Opt_nodefrag:
-			btrfs_clear_and_info(root, AUTO_DEFRAG,
+			btrfs_clear_and_info(info, AUTO_DEFRAG,
 					     "disabling auto defrag");
 			break;
 		case Opt_recovery:
@@ -810,22 +814,22 @@ check:
 	/*
 	 * Extra check for current option against current flag
 	 */
-	if (btrfs_test_opt(root, NOLOGREPLAY) && !(new_flags & MS_RDONLY)) {
+	if (btrfs_test_opt(info, NOLOGREPLAY) && !(new_flags & MS_RDONLY)) {
 		btrfs_err(root->fs_info,
 			  "nologreplay must be used with ro mount option");
 		ret = -EINVAL;
 	}
 out:
 	if (btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE) &&
-	    !btrfs_test_opt(root, FREE_SPACE_TREE) &&
-	    !btrfs_test_opt(root, CLEAR_CACHE)) {
+	    !btrfs_test_opt(info, FREE_SPACE_TREE) &&
+	    !btrfs_test_opt(info, CLEAR_CACHE)) {
 		btrfs_err(root->fs_info, "cannot disable free space tree");
 		ret = -EINVAL;
 
 	}
-	if (!ret && btrfs_test_opt(root, SPACE_CACHE))
+	if (!ret && btrfs_test_opt(info, SPACE_CACHE))
 		btrfs_info(root->fs_info, "disk space caching is enabled");
-	if (!ret && btrfs_test_opt(root, FREE_SPACE_TREE))
+	if (!ret && btrfs_test_opt(info, FREE_SPACE_TREE))
 		btrfs_info(root->fs_info, "using free space tree");
 	kfree(orig);
 	return ret;
@@ -1192,13 +1196,13 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
 	struct btrfs_root *root = info->tree_root;
 	char *compress_type;
 
-	if (btrfs_test_opt(root, DEGRADED))
+	if (btrfs_test_opt(info, DEGRADED))
 		seq_puts(seq, ",degraded");
-	if (btrfs_test_opt(root, NODATASUM))
+	if (btrfs_test_opt(info, NODATASUM))
 		seq_puts(seq, ",nodatasum");
-	if (btrfs_test_opt(root, NODATACOW))
+	if (btrfs_test_opt(info, NODATACOW))
 		seq_puts(seq, ",nodatacow");
-	if (btrfs_test_opt(root, NOBARRIER))
+	if (btrfs_test_opt(info, NOBARRIER))
 		seq_puts(seq, ",nobarrier");
 	if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE)
 		seq_printf(seq, ",max_inline=%llu", info->max_inline);
@@ -1207,56 +1211,56 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
 	if (info->thread_pool_size !=  min_t(unsigned long,
 					     num_online_cpus() + 2, 8))
 		seq_printf(seq, ",thread_pool=%d", info->thread_pool_size);
-	if (btrfs_test_opt(root, COMPRESS)) {
+	if (btrfs_test_opt(info, COMPRESS)) {
 		if (info->compress_type == BTRFS_COMPRESS_ZLIB)
 			compress_type = "zlib";
 		else
 			compress_type = "lzo";
-		if (btrfs_test_opt(root, FORCE_COMPRESS))
+		if (btrfs_test_opt(info, FORCE_COMPRESS))
 			seq_printf(seq, ",compress-force=%s", compress_type);
 		else
 			seq_printf(seq, ",compress=%s", compress_type);
 	}
-	if (btrfs_test_opt(root, NOSSD))
+	if (btrfs_test_opt(info, NOSSD))
 		seq_puts(seq, ",nossd");
-	if (btrfs_test_opt(root, SSD_SPREAD))
+	if (btrfs_test_opt(info, SSD_SPREAD))
 		seq_puts(seq, ",ssd_spread");
-	else if (btrfs_test_opt(root, SSD))
+	else if (btrfs_test_opt(info, SSD))
 		seq_puts(seq, ",ssd");
-	if (btrfs_test_opt(root, NOTREELOG))
+	if (btrfs_test_opt(info, NOTREELOG))
 		seq_puts(seq, ",notreelog");
-	if (btrfs_test_opt(root, NOLOGREPLAY))
+	if (btrfs_test_opt(info, NOLOGREPLAY))
 		seq_puts(seq, ",nologreplay");
-	if (btrfs_test_opt(root, FLUSHONCOMMIT))
+	if (btrfs_test_opt(info, FLUSHONCOMMIT))
 		seq_puts(seq, ",flushoncommit");
-	if (btrfs_test_opt(root, DISCARD))
+	if (btrfs_test_opt(info, DISCARD))
 		seq_puts(seq, ",discard");
 	if (!(root->fs_info->sb->s_flags & MS_POSIXACL))
 		seq_puts(seq, ",noacl");
-	if (btrfs_test_opt(root, SPACE_CACHE))
+	if (btrfs_test_opt(info, SPACE_CACHE))
 		seq_puts(seq, ",space_cache");
-	else if (btrfs_test_opt(root, FREE_SPACE_TREE))
+	else if (btrfs_test_opt(info, FREE_SPACE_TREE))
 		seq_puts(seq, ",space_cache=v2");
 	else
 		seq_puts(seq, ",nospace_cache");
-	if (btrfs_test_opt(root, RESCAN_UUID_TREE))
+	if (btrfs_test_opt(info, RESCAN_UUID_TREE))
 		seq_puts(seq, ",rescan_uuid_tree");
-	if (btrfs_test_opt(root, CLEAR_CACHE))
+	if (btrfs_test_opt(info, CLEAR_CACHE))
 		seq_puts(seq, ",clear_cache");
-	if (btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED))
+	if (btrfs_test_opt(info, USER_SUBVOL_RM_ALLOWED))
 		seq_puts(seq, ",user_subvol_rm_allowed");
-	if (btrfs_test_opt(root, ENOSPC_DEBUG))
+	if (btrfs_test_opt(info, ENOSPC_DEBUG))
 		seq_puts(seq, ",enospc_debug");
-	if (btrfs_test_opt(root, AUTO_DEFRAG))
+	if (btrfs_test_opt(info, AUTO_DEFRAG))
 		seq_puts(seq, ",autodefrag");
-	if (btrfs_test_opt(root, INODE_MAP_CACHE))
+	if (btrfs_test_opt(info, INODE_MAP_CACHE))
 		seq_puts(seq, ",inode_cache");
-	if (btrfs_test_opt(root, SKIP_BALANCE))
+	if (btrfs_test_opt(info, SKIP_BALANCE))
 		seq_puts(seq, ",skip_balance");
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
-	if (btrfs_test_opt(root, CHECK_INTEGRITY_INCLUDING_EXTENT_DATA))
+	if (btrfs_test_opt(info, CHECK_INTEGRITY_INCLUDING_EXTENT_DATA))
 		seq_puts(seq, ",check_int_data");
-	else if (btrfs_test_opt(root, CHECK_INTEGRITY))
+	else if (btrfs_test_opt(info, CHECK_INTEGRITY))
 		seq_puts(seq, ",check_int");
 	if (info->check_integrity_print_mask)
 		seq_printf(seq, ",check_int_print_mask=%d",
@@ -1265,14 +1269,14 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
 	if (info->metadata_ratio)
 		seq_printf(seq, ",metadata_ratio=%d",
 				info->metadata_ratio);
-	if (btrfs_test_opt(root, PANIC_ON_FATAL_ERROR))
+	if (btrfs_test_opt(info, PANIC_ON_FATAL_ERROR))
 		seq_puts(seq, ",fatal_errors=panic");
 	if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL)
 		seq_printf(seq, ",commit=%d", info->commit_interval);
 #ifdef CONFIG_BTRFS_DEBUG
-	if (btrfs_test_opt(root, FRAGMENT_DATA))
+	if (btrfs_test_opt(info, FRAGMENT_DATA))
 		seq_puts(seq, ",fragment=data");
-	if (btrfs_test_opt(root, FRAGMENT_METADATA))
+	if (btrfs_test_opt(info, FRAGMENT_METADATA))
 		seq_puts(seq, ",fragment=metadata");
 #endif
 	seq_printf(seq, ",subvolid=%llu",
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 7658457..db26eff 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1708,7 +1708,7 @@ static void update_super_roots(struct btrfs_root *root)
 	super->root = root_item->bytenr;
 	super->generation = root_item->generation;
 	super->root_level = root_item->level;
-	if (btrfs_test_opt(root, SPACE_CACHE))
+	if (btrfs_test_opt(root->fs_info, SPACE_CACHE))
 		super->cache_generation = root_item->generation;
 	if (root->fs_info->update_uuid_tree_gen)
 		super->uuid_tree_generation = root_item->generation;
@@ -1894,14 +1894,14 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,
 
 static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
 {
-	if (btrfs_test_opt(fs_info->tree_root, FLUSHONCOMMIT))
+	if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
 		return btrfs_start_delalloc_roots(fs_info, 1, -1);
 	return 0;
 }
 
 static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info)
 {
-	if (btrfs_test_opt(fs_info->tree_root, FLUSHONCOMMIT))
+	if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
 		btrfs_wait_ordered_roots(fs_info, -1, 0, (u64)-1);
 }
 
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index c05f69a..5893018 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2757,7 +2757,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 	while (1) {
 		int batch = atomic_read(&root->log_batch);
 		/* when we're on an ssd, just kick the log commit out */
-		if (!btrfs_test_opt(root, SSD) &&
+		if (!btrfs_test_opt(root->fs_info, SSD) &&
 		    test_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state)) {
 			mutex_unlock(&root->log_mutex);
 			schedule_timeout_uninterruptible(1);
@@ -5301,7 +5301,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
 
 	sb = inode->i_sb;
 
-	if (btrfs_test_opt(root, NOTREELOG)) {
+	if (btrfs_test_opt(root->fs_info, NOTREELOG)) {
 		ret = 1;
 		goto end_no_trans;
 	}
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 2f631b5..ca98cac 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3885,7 +3885,7 @@ int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info)
 	}
 	spin_unlock(&fs_info->balance_lock);
 
-	if (btrfs_test_opt(fs_info->tree_root, SKIP_BALANCE)) {
+	if (btrfs_test_opt(fs_info, SKIP_BALANCE)) {
 		btrfs_info(fs_info, "force skipping balance");
 		return 0;
 	}
@@ -6396,7 +6396,8 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
 				   BTRFS_UUID_SIZE);
 		map->stripes[i].dev = btrfs_find_device(root->fs_info, devid,
 							uuid, NULL);
-		if (!map->stripes[i].dev && !btrfs_test_opt(root, DEGRADED)) {
+		if (!map->stripes[i].dev &&
+		    !btrfs_test_opt(root->fs_info, DEGRADED)) {
 			free_extent_map(em);
 			return -EIO;
 		}
@@ -6464,7 +6465,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_root *root,
 
 	fs_devices = find_fsid(fsid);
 	if (!fs_devices) {
-		if (!btrfs_test_opt(root, DEGRADED))
+		if (!btrfs_test_opt(root->fs_info, DEGRADED))
 			return ERR_PTR(-ENOENT);
 
 		fs_devices = alloc_fs_devices(fsid);
@@ -6526,7 +6527,7 @@ static int read_one_dev(struct btrfs_root *root,
 
 	device = btrfs_find_device(root->fs_info, devid, dev_uuid, fs_uuid);
 	if (!device) {
-		if (!btrfs_test_opt(root, DEGRADED))
+		if (!btrfs_test_opt(root->fs_info, DEGRADED))
 			return -EIO;
 
 		device = add_missing_dev(root, fs_devices, devid, dev_uuid);
@@ -6535,7 +6536,7 @@ static int read_one_dev(struct btrfs_root *root,
 		btrfs_warn(root->fs_info, "devid %llu uuid %pU missing",
 				devid, dev_uuid);
 	} else {
-		if (!device->bdev && !btrfs_test_opt(root, DEGRADED))
+		if (!device->bdev && !btrfs_test_opt(root->fs_info, DEGRADED))
 			return -EIO;
 
 		if(!device->bdev && !device->missing) {
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 04/31] btrfs: tests, move initialization into tests/
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (2 preceding siblings ...)
  2016-06-24 22:14 ` [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info jeffm
@ 2016-06-24 22:14 ` jeffm
  2016-06-27  2:17   ` Qu Wenruo
  2016-06-24 22:14 ` [PATCH 05/31] btrfs: tests, require fs_info for root jeffm
                   ` (27 subsequent siblings)
  31 siblings, 1 reply; 44+ messages in thread
From: jeffm @ 2016-06-24 22:14 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

We have all these stubs that only exist because they're called from
btrfs_run_sanity_tests, which is a static inside super.c.  Let's just
move it all into tests/btrfs-tests.c and only have one stub.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/super.c             | 43 ----------------------------------------
 fs/btrfs/tests/btrfs-tests.c | 47 ++++++++++++++++++++++++++++++++++++++++++--
 fs/btrfs/tests/btrfs-tests.h | 35 +++------------------------------
 3 files changed, 48 insertions(+), 77 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index a7b9a15..d8e48bb 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2323,49 +2323,6 @@ static void btrfs_print_mod_info(void)
 			btrfs_crc32c_impl());
 }
 
-static int btrfs_run_sanity_tests(void)
-{
-	int ret, i;
-	u32 sectorsize, nodesize;
-	u32 test_sectorsize[] = {
-		PAGE_SIZE,
-	};
-	ret = btrfs_init_test_fs();
-	if (ret)
-		return ret;
-	for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) {
-		sectorsize = test_sectorsize[i];
-		for (nodesize = sectorsize;
-		     nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE;
-		     nodesize <<= 1) {
-			pr_info("BTRFS: selftest: sectorsize: %u  nodesize: %u\n",
-				sectorsize, nodesize);
-			ret = btrfs_test_free_space_cache(sectorsize, nodesize);
-			if (ret)
-				goto out;
-			ret = btrfs_test_extent_buffer_operations(sectorsize,
-				nodesize);
-			if (ret)
-				goto out;
-			ret = btrfs_test_extent_io(sectorsize, nodesize);
-			if (ret)
-				goto out;
-			ret = btrfs_test_inodes(sectorsize, nodesize);
-			if (ret)
-				goto out;
-			ret = btrfs_test_qgroups(sectorsize, nodesize);
-			if (ret)
-				goto out;
-			ret = btrfs_test_free_space_tree(sectorsize, nodesize);
-			if (ret)
-				goto out;
-		}
-	}
-out:
-	btrfs_destroy_test_fs();
-	return ret;
-}
-
 static int __init init_btrfs_fs(void)
 {
 	int err;
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
index 10eb249..d90c951 100644
--- a/fs/btrfs/tests/btrfs-tests.c
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -54,7 +54,7 @@ struct inode *btrfs_new_test_inode(void)
 	return new_inode(test_mnt->mnt_sb);
 }
 
-int btrfs_init_test_fs(void)
+static int btrfs_init_test_fs(void)
 {
 	int ret;
 
@@ -73,7 +73,7 @@ int btrfs_init_test_fs(void)
 	return 0;
 }
 
-void btrfs_destroy_test_fs(void)
+static void btrfs_destroy_test_fs(void)
 {
 	kern_unmount(test_mnt);
 	unregister_filesystem(&test_type);
@@ -220,3 +220,46 @@ void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans)
 	INIT_LIST_HEAD(&trans->qgroup_ref_list);
 	trans->type = __TRANS_DUMMY;
 }
+
+int btrfs_run_sanity_tests(void)
+{
+	int ret, i;
+	u32 sectorsize, nodesize;
+	u32 test_sectorsize[] = {
+		PAGE_SIZE,
+	};
+	ret = btrfs_init_test_fs();
+	if (ret)
+		return ret;
+	for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) {
+		sectorsize = test_sectorsize[i];
+		for (nodesize = sectorsize;
+		     nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE;
+		     nodesize <<= 1) {
+			pr_info("BTRFS: selftest: sectorsize: %u  nodesize: %u\n",
+				sectorsize, nodesize);
+			ret = btrfs_test_free_space_cache(sectorsize, nodesize);
+			if (ret)
+				goto out;
+			ret = btrfs_test_extent_buffer_operations(sectorsize,
+				nodesize);
+			if (ret)
+				goto out;
+			ret = btrfs_test_extent_io(sectorsize, nodesize);
+			if (ret)
+				goto out;
+			ret = btrfs_test_inodes(sectorsize, nodesize);
+			if (ret)
+				goto out;
+			ret = btrfs_test_qgroups(sectorsize, nodesize);
+			if (ret)
+				goto out;
+			ret = btrfs_test_free_space_tree(sectorsize, nodesize);
+			if (ret)
+				goto out;
+		}
+	}
+out:
+	btrfs_destroy_test_fs();
+	return ret;
+}
diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h
index 66fb6b70..e7d364f 100644
--- a/fs/btrfs/tests/btrfs-tests.h
+++ b/fs/btrfs/tests/btrfs-tests.h
@@ -20,20 +20,19 @@
 #define __BTRFS_TESTS
 
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
+int btrfs_run_sanity_tests(void);
 
 #define test_msg(fmt, ...) pr_info("BTRFS: selftest: " fmt, ##__VA_ARGS__)
 
 struct btrfs_root;
 struct btrfs_trans_handle;
 
-int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize);
 int btrfs_test_extent_buffer_operations(u32 sectorsize, u32 nodesize);
+int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize);
 int btrfs_test_extent_io(u32 sectorsize, u32 nodesize);
 int btrfs_test_inodes(u32 sectorsize, u32 nodesize);
 int btrfs_test_qgroups(u32 sectorsize, u32 nodesize);
 int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
-int btrfs_init_test_fs(void);
-void btrfs_destroy_test_fs(void);
 struct inode *btrfs_new_test_inode(void);
 struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void);
 void btrfs_free_dummy_root(struct btrfs_root *root);
@@ -42,35 +41,7 @@ btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize);
 void btrfs_free_dummy_block_group(struct btrfs_block_group_cache *cache);
 void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans);
 #else
-static inline int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
-{
-	return 0;
-}
-static inline int btrfs_test_extent_buffer_operations(u32 sectorsize,
-	u32 nodesize)
-{
-	return 0;
-}
-static inline int btrfs_init_test_fs(void)
-{
-	return 0;
-}
-static inline void btrfs_destroy_test_fs(void)
-{
-}
-static inline int btrfs_test_extent_io(u32 sectorsize, u32 nodesize)
-{
-	return 0;
-}
-static inline int btrfs_test_inodes(u32 sectorsize, u32 nodesize)
-{
-	return 0;
-}
-static inline int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
-{
-	return 0;
-}
-static inline int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize)
+static inline int btrfs_run_sanity_tests(void)
 {
 	return 0;
 }
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 05/31] btrfs: tests, require fs_info for root
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (3 preceding siblings ...)
  2016-06-24 22:14 ` [PATCH 04/31] btrfs: tests, move initialization into tests/ jeffm
@ 2016-06-24 22:14 ` jeffm
  2016-07-08  1:32   ` Jeff Mahoney
  2016-06-24 22:14 ` [PATCH 06/31] btrfs: tests, use BTRFS_FS_STATE_DUMMY_FS_INFO instead of dummy root jeffm
                   ` (26 subsequent siblings)
  31 siblings, 1 reply; 44+ messages in thread
From: jeffm @ 2016-06-24 22:14 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

This allows the upcoming patchset to push nodesize and sectorsize into
fs_info.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h                       |  1 +
 fs/btrfs/disk-io.c                     | 15 +++++++----
 fs/btrfs/disk-io.h                     |  3 ++-
 fs/btrfs/tests/btrfs-tests.c           | 20 ++++++++++++---
 fs/btrfs/tests/btrfs-tests.h           |  1 +
 fs/btrfs/tests/extent-buffer-tests.c   | 23 +++++++++++------
 fs/btrfs/tests/free-space-tests.c      | 14 +++++++----
 fs/btrfs/tests/free-space-tree-tests.c | 18 +++++++------
 fs/btrfs/tests/inode-tests.c           | 46 ++++++++++++++++++----------------
 fs/btrfs/tests/qgroup-tests.c          | 23 +++++++++--------
 10 files changed, 103 insertions(+), 61 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 100d2ea..4781057 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -117,6 +117,7 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
 #define BTRFS_FS_STATE_REMOUNTING	1
 #define BTRFS_FS_STATE_TRANS_ABORTED	2
 #define BTRFS_FS_STATE_DEV_REPLACING	3
+#define BTRFS_FS_STATE_DUMMY_FS_INFO	4
 
 #define BTRFS_BACKREF_REV_MAX		256
 #define BTRFS_BACKREF_REV_SHIFT		56
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8f27127..418163d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1233,6 +1233,7 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
 			 struct btrfs_root *root, struct btrfs_fs_info *fs_info,
 			 u64 objectid)
 {
+	bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
 	root->node = NULL;
 	root->commit_root = NULL;
 	root->sectorsize = sectorsize;
@@ -1287,14 +1288,14 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
 	root->log_transid = 0;
 	root->log_transid_committed = -1;
 	root->last_log_commit = 0;
-	if (fs_info)
+	if (dummy)
 		extent_io_tree_init(&root->dirty_log_pages,
 				     fs_info->btree_inode->i_mapping);
 
 	memset(&root->root_key, 0, sizeof(root->root_key));
 	memset(&root->root_item, 0, sizeof(root->root_item));
 	memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
-	if (fs_info)
+	if (dummy)
 		root->defrag_trans_start = fs_info->generation;
 	else
 		root->defrag_trans_start = 0;
@@ -1315,15 +1316,19 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
 
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
 /* Should only be used by the testing infrastructure */
-struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize)
+struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info,
+					  u32 sectorsize, u32 nodesize)
 {
 	struct btrfs_root *root;
 
-	root = btrfs_alloc_root(NULL, GFP_KERNEL);
+	if (!fs_info)
+		return ERR_PTR(-EINVAL);
+
+	root = btrfs_alloc_root(fs_info, GFP_KERNEL);
 	if (!root)
 		return ERR_PTR(-ENOMEM);
 	/* We don't use the stripesize in selftest, set it as sectorsize */
-	__setup_root(nodesize, sectorsize, sectorsize, root, NULL,
+	__setup_root(nodesize, sectorsize, sectorsize, root, fs_info,
 			BTRFS_ROOT_TREE_OBJECTID);
 	set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
 	root->alloc_bytenr = 0;
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index acba821..c9d42c9 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -90,7 +90,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
 void btrfs_free_fs_root(struct btrfs_root *root);
 
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
-struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize);
+struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info,
+					  u32 sectorsize, u32 nodesize);
 #endif
 
 /*
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
index d90c951..c3783c3 100644
--- a/fs/btrfs/tests/btrfs-tests.c
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -128,14 +128,27 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void)
 	extent_io_tree_init(&fs_info->freed_extents[0], NULL);
 	extent_io_tree_init(&fs_info->freed_extents[1], NULL);
 	fs_info->pinned_extents = &fs_info->freed_extents[0];
+	set_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
+
+	test_mnt->mnt_sb->s_fs_info = fs_info;
+
 	return fs_info;
 }
 
-static void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)
+void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)
 {
 	struct radix_tree_iter iter;
 	void **slot;
 
+	if (!fs_info)
+		return;
+
+	if (WARN_ON(!test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO,
+			      &fs_info->fs_state)))
+		return;
+
+	test_mnt->mnt_sb->s_fs_info = NULL;
+
 	spin_lock(&fs_info->buffer_lock);
 	radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) {
 		struct extent_buffer *eb;
@@ -167,10 +180,11 @@ void btrfs_free_dummy_root(struct btrfs_root *root)
 {
 	if (!root)
 		return;
+	/* Will be freed by btrfs_free_fs_roots */
+	if (WARN_ON(test_bit(BTRFS_ROOT_IN_RADIX, &root->state)))
+		return;
 	if (root->node)
 		free_extent_buffer(root->node);
-	if (root->fs_info)
-		btrfs_free_dummy_fs_info(root->fs_info);
 	kfree(root);
 }
 
diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h
index e7d364f..b17ffbe 100644
--- a/fs/btrfs/tests/btrfs-tests.h
+++ b/fs/btrfs/tests/btrfs-tests.h
@@ -35,6 +35,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize);
 int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
 struct inode *btrfs_new_test_inode(void);
 struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void);
+void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info);
 void btrfs_free_dummy_root(struct btrfs_root *root);
 struct btrfs_block_group_cache *
 btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize);
diff --git a/fs/btrfs/tests/extent-buffer-tests.c b/fs/btrfs/tests/extent-buffer-tests.c
index 4f8cbd1..1995691 100644
--- a/fs/btrfs/tests/extent-buffer-tests.c
+++ b/fs/btrfs/tests/extent-buffer-tests.c
@@ -24,8 +24,9 @@
 
 static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
 {
-	struct btrfs_path *path;
-	struct btrfs_root *root;
+	struct btrfs_fs_info *fs_info;
+	struct btrfs_path *path = NULL;
+	struct btrfs_root *root = NULL;
 	struct extent_buffer *eb;
 	struct btrfs_item *item;
 	char *value = "mary had a little lamb";
@@ -40,17 +41,24 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
 
 	test_msg("Running btrfs_split_item tests\n");
 
-	root = btrfs_alloc_dummy_root(sectorsize, nodesize);
+	fs_info = btrfs_alloc_dummy_fs_info();
+	if (!fs_info) {
+		test_msg("Could not allocate fs_info\n");
+		return -ENOMEM;
+	}
+
+	root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
 	if (IS_ERR(root)) {
 		test_msg("Could not allocate root\n");
-		return PTR_ERR(root);
+		ret = PTR_ERR(root);
+		goto out;
 	}
 
 	path = btrfs_alloc_path();
 	if (!path) {
 		test_msg("Could not allocate path\n");
-		kfree(root);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out;
 	}
 
 	path->nodes[0] = eb = alloc_dummy_extent_buffer(NULL, nodesize,
@@ -219,7 +227,8 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
 	}
 out:
 	btrfs_free_path(path);
-	kfree(root);
+	btrfs_free_dummy_root(root);
+	btrfs_free_dummy_fs_info(fs_info);
 	return ret;
 }
 
diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
index 3956bb2..3221c8d 100644
--- a/fs/btrfs/tests/free-space-tests.c
+++ b/fs/btrfs/tests/free-space-tests.c
@@ -837,6 +837,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache,
 
 int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
 {
+	struct btrfs_fs_info *fs_info;
 	struct btrfs_block_group_cache *cache;
 	struct btrfs_root *root = NULL;
 	int ret = -ENOMEM;
@@ -855,15 +856,17 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
 		return 0;
 	}
 
-	root = btrfs_alloc_dummy_root(sectorsize, nodesize);
-	if (IS_ERR(root)) {
-		ret = PTR_ERR(root);
+	fs_info = btrfs_alloc_dummy_fs_info();
+	if (!fs_info) {
+		ret = -ENOMEM;
 		goto out;
 	}
 
-	root->fs_info = btrfs_alloc_dummy_fs_info();
-	if (!root->fs_info)
+	root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
+	if (IS_ERR(root)) {
+		ret = PTR_ERR(root);
 		goto out;
+	}
 
 	root->fs_info->extent_root = root;
 	cache->fs_info = root->fs_info;
@@ -882,6 +885,7 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
 out:
 	btrfs_free_dummy_block_group(cache);
 	btrfs_free_dummy_root(root);
+	btrfs_free_dummy_fs_info(fs_info);
 	test_msg("Free space cache tests finished\n");
 	return ret;
 }
diff --git a/fs/btrfs/tests/free-space-tree-tests.c b/fs/btrfs/tests/free-space-tree-tests.c
index aac5070..7508d3b 100644
--- a/fs/btrfs/tests/free-space-tree-tests.c
+++ b/fs/btrfs/tests/free-space-tree-tests.c
@@ -443,23 +443,24 @@ typedef int (*test_func_t)(struct btrfs_trans_handle *,
 static int run_test(test_func_t test_func, int bitmaps,
 		u32 sectorsize, u32 nodesize)
 {
+	struct btrfs_fs_info *fs_info;
 	struct btrfs_root *root = NULL;
 	struct btrfs_block_group_cache *cache = NULL;
 	struct btrfs_trans_handle trans;
 	struct btrfs_path *path = NULL;
 	int ret;
 
-	root = btrfs_alloc_dummy_root(sectorsize, nodesize);
-	if (IS_ERR(root)) {
-		test_msg("Couldn't allocate dummy root\n");
-		ret = PTR_ERR(root);
+	fs_info = btrfs_alloc_dummy_fs_info();
+	if (!fs_info) {
+		test_msg("Couldn't allocate dummy fs info\n");
+		ret = -ENOMEM;
 		goto out;
 	}
 
-	root->fs_info = btrfs_alloc_dummy_fs_info();
-	if (!root->fs_info) {
-		test_msg("Couldn't allocate dummy fs info\n");
-		ret = -ENOMEM;
+	root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
+	if (IS_ERR(root)) {
+		test_msg("Couldn't allocate dummy root\n");
+		ret = PTR_ERR(root);
 		goto out;
 	}
 
@@ -534,6 +535,7 @@ out:
 	btrfs_free_path(path);
 	btrfs_free_dummy_block_group(cache);
 	btrfs_free_dummy_root(root);
+	btrfs_free_dummy_fs_info(fs_info);
 	return ret;
 }
 
diff --git a/fs/btrfs/tests/inode-tests.c b/fs/btrfs/tests/inode-tests.c
index 29648c0..9f72aed 100644
--- a/fs/btrfs/tests/inode-tests.c
+++ b/fs/btrfs/tests/inode-tests.c
@@ -230,6 +230,7 @@ static unsigned long vacancy_only = 0;
 
 static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
 {
+	struct btrfs_fs_info *fs_info = NULL;
 	struct inode *inode = NULL;
 	struct btrfs_root *root = NULL;
 	struct extent_map *em = NULL;
@@ -248,19 +249,15 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
 	BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
 	BTRFS_I(inode)->location.offset = 0;
 
-	root = btrfs_alloc_dummy_root(sectorsize, nodesize);
-	if (IS_ERR(root)) {
-		test_msg("Couldn't allocate root\n");
+	fs_info = btrfs_alloc_dummy_fs_info();
+	if (!fs_info) {
+		test_msg("Couldn't allocate dummy fs info\n");
 		goto out;
 	}
 
-	/*
-	 * We do this since btrfs_get_extent wants to assign em->bdev to
-	 * root->fs_info->fs_devices->latest_bdev.
-	 */
-	root->fs_info = btrfs_alloc_dummy_fs_info();
-	if (!root->fs_info) {
-		test_msg("Couldn't allocate dummy fs info\n");
+	root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
+	if (IS_ERR(root)) {
+		test_msg("Couldn't allocate root\n");
 		goto out;
 	}
 
@@ -835,11 +832,13 @@ out:
 		free_extent_map(em);
 	iput(inode);
 	btrfs_free_dummy_root(root);
+	btrfs_free_dummy_fs_info(fs_info);
 	return ret;
 }
 
 static int test_hole_first(u32 sectorsize, u32 nodesize)
 {
+	struct btrfs_fs_info *fs_info = NULL;
 	struct inode *inode = NULL;
 	struct btrfs_root *root = NULL;
 	struct extent_map *em = NULL;
@@ -855,15 +854,15 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
 	BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
 	BTRFS_I(inode)->location.offset = 0;
 
-	root = btrfs_alloc_dummy_root(sectorsize, nodesize);
-	if (IS_ERR(root)) {
-		test_msg("Couldn't allocate root\n");
+	fs_info = btrfs_alloc_dummy_fs_info();
+	if (!fs_info) {
+		test_msg("Couldn't allocate dummy fs info\n");
 		goto out;
 	}
 
-	root->fs_info = btrfs_alloc_dummy_fs_info();
-	if (!root->fs_info) {
-		test_msg("Couldn't allocate dummy fs info\n");
+	root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
+	if (IS_ERR(root)) {
+		test_msg("Couldn't allocate root\n");
 		goto out;
 	}
 
@@ -934,11 +933,13 @@ out:
 		free_extent_map(em);
 	iput(inode);
 	btrfs_free_dummy_root(root);
+	btrfs_free_dummy_fs_info(fs_info);
 	return ret;
 }
 
 static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 {
+	struct btrfs_fs_info *fs_info = NULL;
 	struct inode *inode = NULL;
 	struct btrfs_root *root = NULL;
 	int ret = -ENOMEM;
@@ -949,15 +950,15 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 		return ret;
 	}
 
-	root = btrfs_alloc_dummy_root(sectorsize, nodesize);
-	if (IS_ERR(root)) {
-		test_msg("Couldn't allocate root\n");
+	fs_info = btrfs_alloc_dummy_fs_info();
+	if (!fs_info) {
+		test_msg("Couldn't allocate dummy fs info\n");
 		goto out;
 	}
 
-	root->fs_info = btrfs_alloc_dummy_fs_info();
-	if (!root->fs_info) {
-		test_msg("Couldn't allocate dummy fs info\n");
+	root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
+	if (IS_ERR(root)) {
+		test_msg("Couldn't allocate root\n");
 		goto out;
 	}
 
@@ -1132,6 +1133,7 @@ out:
 				 NULL, GFP_KERNEL);
 	iput(inode);
 	btrfs_free_dummy_root(root);
+	btrfs_free_dummy_fs_info(fs_info);
 	return ret;
 }
 
diff --git a/fs/btrfs/tests/qgroup-tests.c b/fs/btrfs/tests/qgroup-tests.c
index 57a12c0..4407fef 100644
--- a/fs/btrfs/tests/qgroup-tests.c
+++ b/fs/btrfs/tests/qgroup-tests.c
@@ -453,22 +453,24 @@ static int test_multiple_refs(struct btrfs_root *root,
 
 int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 {
+	struct btrfs_fs_info *fs_info = NULL;
 	struct btrfs_root *root;
 	struct btrfs_root *tmp_root;
 	int ret = 0;
 
-	root = btrfs_alloc_dummy_root(sectorsize, nodesize);
-	if (IS_ERR(root)) {
-		test_msg("Couldn't allocate root\n");
-		return PTR_ERR(root);
+	fs_info = btrfs_alloc_dummy_fs_info();
+	if (!fs_info) {
+		test_msg("Couldn't allocate dummy fs info\n");
+		return -ENOMEM;
 	}
 
-	root->fs_info = btrfs_alloc_dummy_fs_info();
-	if (!root->fs_info) {
-		test_msg("Couldn't allocate dummy fs info\n");
-		ret = -ENOMEM;
+	root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
+	if (IS_ERR(root)) {
+		test_msg("Couldn't allocate root\n");
+		ret = PTR_ERR(root);
 		goto out;
 	}
+
 	/* We are using this root as our extent root */
 	root->fs_info->extent_root = root;
 
@@ -495,7 +497,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 	btrfs_set_header_nritems(root->node, 0);
 	root->alloc_bytenr += 2 * nodesize;
 
-	tmp_root = btrfs_alloc_dummy_root(sectorsize, nodesize);
+	tmp_root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
 	if (IS_ERR(tmp_root)) {
 		test_msg("Couldn't allocate a fs root\n");
 		ret = PTR_ERR(tmp_root);
@@ -510,7 +512,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 		goto out;
 	}
 
-	tmp_root = btrfs_alloc_dummy_root(sectorsize, nodesize);
+	tmp_root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
 	if (IS_ERR(tmp_root)) {
 		test_msg("Couldn't allocate a fs root\n");
 		ret = PTR_ERR(tmp_root);
@@ -531,5 +533,6 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 	ret = test_multiple_refs(root, sectorsize, nodesize);
 out:
 	btrfs_free_dummy_root(root);
+	btrfs_free_dummy_fs_info(fs_info);
 	return ret;
 }
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 06/31] btrfs: tests, use BTRFS_FS_STATE_DUMMY_FS_INFO instead of dummy root
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (4 preceding siblings ...)
  2016-06-24 22:14 ` [PATCH 05/31] btrfs: tests, require fs_info for root jeffm
@ 2016-06-24 22:14 ` jeffm
  2016-06-24 22:15 ` [PATCH 07/31] btrfs: simpilify btrfs_subvol_inherit_props jeffm
                   ` (25 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:14 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

Now that we have a dummy fs_info associated with each test that
uses a root, we don't need the DUMMY_ROOT bit anymore.  This lets
us make choices without needing an actual root like in e.g.
btrfs_find_create_tree_block.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/backref.c     |  2 +-
 fs/btrfs/ctree.c       |  2 +-
 fs/btrfs/ctree.h       | 17 ++++++++---------
 fs/btrfs/disk-io.c     |  3 +--
 fs/btrfs/extent-tree.c |  8 ++++----
 fs/btrfs/inode.c       |  4 ++--
 fs/btrfs/qgroup.c      |  4 ++--
 7 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 8bb3509..8637069 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -361,7 +361,7 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
 		goto out;
 	}
 
-	if (btrfs_test_is_dummy_root(root)) {
+	if (btrfs_is_testing(fs_info)) {
 		srcu_read_unlock(&fs_info->subvol_srcu, index);
 		ret = -ENOENT;
 		goto out;
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 6276add..2bf3d58 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1505,7 +1505,7 @@ static inline int should_cow_block(struct btrfs_trans_handle *trans,
 				   struct btrfs_root *root,
 				   struct extent_buffer *buf)
 {
-	if (btrfs_test_is_dummy_root(root))
+	if (btrfs_is_testing(root->fs_info))
 		return 0;
 
 	/* ensure we can see the force_cow */
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 4781057..0b107d1 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1113,12 +1113,11 @@ struct btrfs_subvolume_writers {
 #define BTRFS_ROOT_REF_COWS		1
 #define BTRFS_ROOT_TRACK_DIRTY		2
 #define BTRFS_ROOT_IN_RADIX		3
-#define BTRFS_ROOT_DUMMY_ROOT		4
-#define BTRFS_ROOT_ORPHAN_ITEM_INSERTED	5
-#define BTRFS_ROOT_DEFRAG_RUNNING	6
-#define BTRFS_ROOT_FORCE_COW		7
-#define BTRFS_ROOT_MULTI_LOG_TASKS	8
-#define BTRFS_ROOT_DIRTY		9
+#define BTRFS_ROOT_ORPHAN_ITEM_INSERTED	4
+#define BTRFS_ROOT_DEFRAG_RUNNING	5
+#define BTRFS_ROOT_FORCE_COW		6
+#define BTRFS_ROOT_MULTI_LOG_TASKS	7
+#define BTRFS_ROOT_DIRTY		8
 
 /*
  * in ram representation of the tree.  extent_root is used for all allocations
@@ -3600,13 +3599,13 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
 void btrfs_test_destroy_inode(struct inode *inode);
 #endif
 
-static inline int btrfs_test_is_dummy_root(struct btrfs_root *root)
+static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
 {
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
-	if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state)))
+	if (unlikely(test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO,
+			      &fs_info->fs_state)))
 		return 1;
 #endif
 	return 0;
 }
-
 #endif
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 418163d..e1b36e1 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1146,7 +1146,7 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
 struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
 						 u64 bytenr)
 {
-	if (btrfs_test_is_dummy_root(root))
+	if (btrfs_is_testing(root->fs_info))
 		return alloc_test_extent_buffer(root->fs_info, bytenr,
 				root->nodesize);
 	return alloc_extent_buffer(root->fs_info, bytenr);
@@ -1330,7 +1330,6 @@ struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info,
 	/* We don't use the stripesize in selftest, set it as sectorsize */
 	__setup_root(nodesize, sectorsize, sectorsize, root, fs_info,
 			BTRFS_ROOT_TREE_OBJECTID);
-	set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
 	root->alloc_bytenr = 0;
 
 	return root;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index efb5459..ee8cd29 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3214,7 +3214,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
 			    u64, u64, u64, u64, u64, u64);
 
 
-	if (btrfs_test_is_dummy_root(root))
+	if (btrfs_is_testing(root->fs_info))
 		return 0;
 
 	ref_root = btrfs_header_owner(buf);
@@ -5894,7 +5894,7 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes)
 	if (dropped > 0)
 		to_free += btrfs_calc_trans_metadata_size(root, dropped);
 
-	if (btrfs_test_is_dummy_root(root))
+	if (btrfs_is_testing(root->fs_info))
 		return;
 
 	trace_btrfs_space_reservation(root->fs_info, "delalloc",
@@ -6992,7 +6992,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 	int ret;
 	struct btrfs_fs_info *fs_info = root->fs_info;
 
-	if (btrfs_test_is_dummy_root(root))
+	if (btrfs_is_testing(fs_info))
 		return 0;
 
 	add_pinned_bytes(root->fs_info, num_bytes, owner, root_objectid);
@@ -8132,7 +8132,7 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
 	bool skinny_metadata = btrfs_fs_incompat(root->fs_info,
 						 SKINNY_METADATA);
 
-	if (btrfs_test_is_dummy_root(root)) {
+	if (btrfs_is_testing(root->fs_info)) {
 		buf = btrfs_init_new_buffer(trans, root, root->alloc_bytenr,
 					    level);
 		if (!IS_ERR(buf))
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 141a233..1acba51 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1740,7 +1740,7 @@ static void btrfs_set_bit_hook(struct inode *inode,
 		}
 
 		/* For sanity tests */
-		if (btrfs_test_is_dummy_root(root))
+		if (btrfs_is_testing(root->fs_info))
 			return;
 
 		__percpu_counter_add(&root->fs_info->delalloc_bytes, len,
@@ -1799,7 +1799,7 @@ static void btrfs_clear_bit_hook(struct inode *inode,
 			btrfs_delalloc_release_metadata(inode, len);
 
 		/* For sanity tests. */
-		if (btrfs_test_is_dummy_root(root))
+		if (btrfs_is_testing(root->fs_info))
 			return;
 
 		if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 13e28d8..3a83631 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -571,7 +571,7 @@ static int add_qgroup_item(struct btrfs_trans_handle *trans,
 	struct extent_buffer *leaf;
 	struct btrfs_key key;
 
-	if (btrfs_test_is_dummy_root(quota_root))
+	if (btrfs_is_testing(quota_root->fs_info))
 		return 0;
 
 	path = btrfs_alloc_path();
@@ -728,7 +728,7 @@ static int update_qgroup_info_item(struct btrfs_trans_handle *trans,
 	int ret;
 	int slot;
 
-	if (btrfs_test_is_dummy_root(root))
+	if (btrfs_is_testing(root->fs_info))
 		return 0;
 
 	key.objectid = 0;
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 07/31] btrfs: simpilify btrfs_subvol_inherit_props
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (5 preceding siblings ...)
  2016-06-24 22:14 ` [PATCH 06/31] btrfs: tests, use BTRFS_FS_STATE_DUMMY_FS_INFO instead of dummy root jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 08/31] btrfs: copy_to_sk drop unused root parameter jeffm
                   ` (24 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

We just need a superblock, but we look it up using two different
roots depending on the call site.  Let's just use a superblock
pointer initialized at the outset.

This is mostly for Coccinelle not to choke on my root push up set.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/props.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
index 3699212..cf0b444 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -350,6 +350,7 @@ int btrfs_subvol_inherit_props(struct btrfs_trans_handle *trans,
 			       struct btrfs_root *root,
 			       struct btrfs_root *parent_root)
 {
+	struct super_block *sb = root->fs_info->sb;
 	struct btrfs_key key;
 	struct inode *parent_inode, *child_inode;
 	int ret;
@@ -358,12 +359,11 @@ int btrfs_subvol_inherit_props(struct btrfs_trans_handle *trans,
 	key.type = BTRFS_INODE_ITEM_KEY;
 	key.offset = 0;
 
-	parent_inode = btrfs_iget(parent_root->fs_info->sb, &key,
-				  parent_root, NULL);
+	parent_inode = btrfs_iget(sb, &key, parent_root, NULL);
 	if (IS_ERR(parent_inode))
 		return PTR_ERR(parent_inode);
 
-	child_inode = btrfs_iget(root->fs_info->sb, &key, root, NULL);
+	child_inode = btrfs_iget(sb, &key, root, NULL);
 	if (IS_ERR(child_inode)) {
 		iput(parent_inode);
 		return PTR_ERR(child_inode);
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 08/31] btrfs: copy_to_sk drop unused root parameter
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (6 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 07/31] btrfs: simpilify btrfs_subvol_inherit_props jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 09/31] btrfs: cleanup, remove prototype for btrfs_find_root_ref jeffm
                   ` (23 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

The root parameter for copy_to_sk is not used at all.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ioctl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index ffb1628..81413e6 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1948,8 +1948,7 @@ static noinline int key_in_sk(struct btrfs_key *key,
 	return 1;
 }
 
-static noinline int copy_to_sk(struct btrfs_root *root,
-			       struct btrfs_path *path,
+static noinline int copy_to_sk(struct btrfs_path *path,
 			       struct btrfs_key *key,
 			       struct btrfs_ioctl_search_key *sk,
 			       size_t *buf_size,
@@ -2120,7 +2119,7 @@ static noinline int search_ioctl(struct inode *inode,
 				ret = 0;
 			goto err;
 		}
-		ret = copy_to_sk(root, path, &key, sk, buf_size, ubuf,
+		ret = copy_to_sk(path, &key, sk, buf_size, ubuf,
 				 &sk_offset, &num_found);
 		btrfs_release_path(path);
 		if (ret)
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 09/31] btrfs: cleanup, remove prototype for btrfs_find_root_ref
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (7 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 08/31] btrfs: copy_to_sk drop unused root parameter jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 10/31] btrfs: introduce BTRFS_MAX_ITEM_SIZE jeffm
                   ` (22 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

The function isn't implemented anywhere.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0b107d1..bff6ce6 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2875,9 +2875,6 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
 int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq);
 
 /* root-item.c */
-int btrfs_find_root_ref(struct btrfs_root *tree_root,
-			struct btrfs_path *path,
-			u64 root_id, u64 ref_id);
 int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
 		       struct btrfs_root *tree_root,
 		       u64 root_id, u64 ref_id, u64 dirid, u64 sequence,
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 10/31] btrfs: introduce BTRFS_MAX_ITEM_SIZE
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (8 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 09/31] btrfs: cleanup, remove prototype for btrfs_find_root_ref jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 11/31] btrfs: convert nodesize macros to static inlines jeffm
                   ` (21 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

We use BTRFS_LEAF_DATA_SIZE - sizeof(struct btrfs_item) in
several places.  This introduces a BTRFS_MAX_ITEM_SIZE macro to do the
same.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h       | 8 ++++----
 fs/btrfs/extent-tree.c | 2 +-
 fs/btrfs/file-item.c   | 5 ++---
 fs/btrfs/volumes.c     | 3 +--
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index bff6ce6..1d3c4b5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -150,13 +150,13 @@ struct btrfs_header {
 				     sizeof(struct btrfs_key_ptr))
 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize))
+#define BTRFS_MAX_ITEM_SIZE(r) \
+	(BTRFS_LEAF_DATA_SIZE(r) - sizeof(struct btrfs_item))
 #define BTRFS_FILE_EXTENT_INLINE_DATA_START		\
 		(offsetof(struct btrfs_file_extent_item, disk_bytenr))
-#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
-					sizeof(struct btrfs_item) - \
+#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_MAX_ITEM_SIZE(r) - \
 					BTRFS_FILE_EXTENT_INLINE_DATA_START)
-#define BTRFS_MAX_XATTR_SIZE(r)	(BTRFS_LEAF_DATA_SIZE(r) - \
-				 sizeof(struct btrfs_item) -\
+#define BTRFS_MAX_XATTR_SIZE(r)	(BTRFS_MAX_ITEM_SIZE(r) - \
 				 sizeof(struct btrfs_dir_item))
 
 
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index ee8cd29..e4af375 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2769,7 +2769,7 @@ u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes)
 	u64 num_csums_per_leaf;
 	u64 num_csums;
 
-	csum_size = BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item);
+	csum_size = BTRFS_MAX_ITEM_SIZE(root);
 	num_csums_per_leaf = div64_u64(csum_size,
 			(u64)btrfs_super_csum_size(root->fs_info->super_copy));
 	num_csums = div64_u64(csum_bytes, root->sectorsize);
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 62a81ee..fc6390e 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -27,9 +27,8 @@
 #include "print-tree.h"
 #include "compression.h"
 
-#define __MAX_CSUM_ITEMS(r, size) ((unsigned long)(((BTRFS_LEAF_DATA_SIZE(r) - \
-				   sizeof(struct btrfs_item) * 2) / \
-				  size) - 1))
+#define __MAX_CSUM_ITEMS(r, size) \
+	((unsigned long)(((BTRFS_MAX_ITEM_SIZE(r) * 2) / size) - 1))
 
 #define MAX_CSUM_ITEMS(r, size) (min_t(u32, __MAX_CSUM_ITEMS(r, size), \
 				       PAGE_SIZE))
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index ca98cac..49c9851 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4514,8 +4514,7 @@ static void check_raid56_incompat_flag(struct btrfs_fs_info *info, u64 type)
 	btrfs_set_fs_incompat(info, RAID56);
 }
 
-#define BTRFS_MAX_DEVS(r) ((BTRFS_LEAF_DATA_SIZE(r)		\
-			- sizeof(struct btrfs_item)		\
+#define BTRFS_MAX_DEVS(r) ((BTRFS_MAX_ITEM_SIZE(r)		\
 			- sizeof(struct btrfs_chunk))		\
 			/ sizeof(struct btrfs_stripe) + 1)
 
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 11/31] btrfs: convert nodesize macros to static inlines
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (9 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 10/31] btrfs: introduce BTRFS_MAX_ITEM_SIZE jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 12/31] btrfs: btrfs_relocate_chunk pass extent_root to btrfs_end_transaction jeffm
                   ` (20 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

This patch converts the macros used to calculate various node
size limits to static inlines.  That way we get type checking for free.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h | 48 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 1d3c4b5..95fe439 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -145,21 +145,6 @@ struct btrfs_header {
 	u8 level;
 } __attribute__ ((__packed__));
 
-#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
-				      sizeof(struct btrfs_header)) / \
-				     sizeof(struct btrfs_key_ptr))
-#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
-#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize))
-#define BTRFS_MAX_ITEM_SIZE(r) \
-	(BTRFS_LEAF_DATA_SIZE(r) - sizeof(struct btrfs_item))
-#define BTRFS_FILE_EXTENT_INLINE_DATA_START		\
-		(offsetof(struct btrfs_file_extent_item, disk_bytenr))
-#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_MAX_ITEM_SIZE(r) - \
-					BTRFS_FILE_EXTENT_INLINE_DATA_START)
-#define BTRFS_MAX_XATTR_SIZE(r)	(BTRFS_MAX_ITEM_SIZE(r) - \
-				 sizeof(struct btrfs_dir_item))
-
-
 /*
  * this is a very generous portion of the super block, giving us
  * room to translate 14 chunks with 3 stripes each.
@@ -1257,6 +1242,39 @@ struct btrfs_root {
 	atomic_t qgroup_meta_rsv;
 };
 
+static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 blocksize)
+{
+	return blocksize - sizeof(struct btrfs_header);
+}
+
+static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_root *root)
+{
+	return __BTRFS_LEAF_DATA_SIZE(root->nodesize);
+}
+
+static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_root *root)
+{
+	return BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item);
+}
+
+static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_root *root)
+{
+	return BTRFS_LEAF_DATA_SIZE(root) / sizeof(struct btrfs_key_ptr);
+}
+
+#define BTRFS_FILE_EXTENT_INLINE_DATA_START		\
+		(offsetof(struct btrfs_file_extent_item, disk_bytenr))
+static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_root *root)
+{
+	return BTRFS_MAX_ITEM_SIZE(root) -
+	       BTRFS_FILE_EXTENT_INLINE_DATA_START;
+}
+
+static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_root *root)
+{
+	return BTRFS_MAX_ITEM_SIZE(root) - sizeof(struct btrfs_dir_item);
+}
+
 /*
  * Flags for mount options.
  *
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 12/31] btrfs: btrfs_relocate_chunk pass extent_root to btrfs_end_transaction
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (10 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 11/31] btrfs: convert nodesize macros to static inlines jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 13/31] btrfs: add btrfs_trans_handle->fs_info pointer jeffm
                   ` (19 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

In btrfs_relocate_chunk, we get a transaction handle via
btrfs_start_trans_remove_block_group, which starts the transaction
using the extent root.  When we call btrfs_end_transaction, we're calling
it using the chunk root.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/volumes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 49c9851..e0332c9 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2902,7 +2902,7 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset)
 	 * chunk tree entries
 	 */
 	ret = btrfs_remove_chunk(trans, root, chunk_offset);
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans, extent_root);
 	return ret;
 }
 
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 13/31] btrfs: add btrfs_trans_handle->fs_info pointer
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (11 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 12/31] btrfs: btrfs_relocate_chunk pass extent_root to btrfs_end_transaction jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 14/31] btrfs: btrfs_abort_transaction, drop root parameter jeffm
                   ` (18 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

btrfs_trans_handle->root is documented as for use for confirming
that the root passed in to start the transaction is the same as the
one ending it.  It's used in several places when an fs_info pointer
is needed, so let's just add an fs_info pointer directly.  Eventually,
the root pointer can be removed.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/extent-tree.c | 6 +++---
 fs/btrfs/qgroup.c      | 2 +-
 fs/btrfs/transaction.c | 1 +
 fs/btrfs/transaction.h | 1 +
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index e4af375..2081ed4 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4562,7 +4562,7 @@ out:
 	 */
 	if (trans->can_flush_pending_bgs &&
 	    trans->chunk_bytes_reserved >= (u64)SZ_2M) {
-		btrfs_create_pending_block_groups(trans, trans->root);
+		btrfs_create_pending_block_groups(trans, extent_root);
 		btrfs_trans_release_chunk_metadata(trans);
 	}
 	return ret;
@@ -5527,7 +5527,7 @@ void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans,
  */
 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans)
 {
-	struct btrfs_fs_info *fs_info = trans->root->fs_info;
+	struct btrfs_fs_info *fs_info = trans->fs_info;
 
 	if (!trans->chunk_bytes_reserved)
 		return;
@@ -8318,7 +8318,7 @@ static int record_one_subtree_extent(struct btrfs_trans_handle *trans,
 
 	delayed_refs = &trans->transaction->delayed_refs;
 	spin_lock(&delayed_refs->lock);
-	if (btrfs_qgroup_insert_dirty_extent(trans->root->fs_info,
+	if (btrfs_qgroup_insert_dirty_extent(trans->fs_info,
 					     delayed_refs, qrecord))
 		kfree(qrecord);
 	spin_unlock(&delayed_refs->lock);
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 3a83631..93ee1c1 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2196,7 +2196,7 @@ void assert_qgroups_uptodate(struct btrfs_trans_handle *trans)
 {
 	if (list_empty(&trans->qgroup_ref_list) && !trans->delayed_ref_elem.seq)
 		return;
-	btrfs_err(trans->root->fs_info,
+	btrfs_err(trans->fs_info,
 		"qgroups not uptodate in trans handle %p:  list is%s empty, "
 		"seq is %#x.%x",
 		trans, list_empty(&trans->qgroup_ref_list) ? "" : " not",
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index db26eff..db0eb1f 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -561,6 +561,7 @@ again:
 	h->transaction = cur_trans;
 	h->root = root;
 	h->use_count = 1;
+	h->fs_info = root->fs_info;
 
 	h->type = type;
 	h->can_flush_pending_bgs = true;
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index c5abee4..efb1226 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -128,6 +128,7 @@ struct btrfs_trans_handle {
 	 * Subvolume quota depends on this
 	 */
 	struct btrfs_root *root;
+	struct btrfs_fs_info *fs_info;
 	struct seq_list delayed_ref_elem;
 	struct list_head qgroup_ref_list;
 	struct list_head new_bgs;
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 14/31] btrfs: btrfs_abort_transaction, drop root parameter
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (12 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 13/31] btrfs: add btrfs_trans_handle->fs_info pointer jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 15/31] btrfs: call functions that overwrite their root parameter with fs_info jeffm
                   ` (17 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

__btrfs_abort_transaction doesn't use its root parameter except to
obtain an fs_info pointer.  We can obtain that from trans->root->fs_info
for now and from trans->fs_info in a later patch.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.c            | 12 +++----
 fs/btrfs/ctree.h            |  8 ++---
 fs/btrfs/delayed-inode.c    |  2 +-
 fs/btrfs/extent-tree.c      | 47 ++++++++++++++-------------
 fs/btrfs/file-item.c        |  2 +-
 fs/btrfs/file.c             |  8 ++---
 fs/btrfs/free-space-cache.c |  2 +-
 fs/btrfs/free-space-tree.c  | 16 +++++-----
 fs/btrfs/inode-map.c        |  4 +--
 fs/btrfs/inode.c            | 77 ++++++++++++++++++++++-----------------------
 fs/btrfs/ioctl.c            | 33 +++++++++----------
 fs/btrfs/relocation.c       |  4 +--
 fs/btrfs/root-tree.c        | 10 +++---
 fs/btrfs/super.c            | 12 ++++---
 fs/btrfs/transaction.c      | 30 +++++++++---------
 fs/btrfs/tree-log.c         | 14 ++++-----
 fs/btrfs/volumes.c          | 18 +++++------
 17 files changed, 147 insertions(+), 152 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 2bf3d58..904b924 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1153,14 +1153,14 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
 
 	ret = update_ref_for_cow(trans, root, buf, cow, &last_ref);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
 
 	if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) {
 		ret = btrfs_reloc_cow_block(trans, root, buf, cow);
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			return ret;
 		}
 	}
@@ -1198,7 +1198,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
 		if (last_ref) {
 			ret = tree_mod_log_free_eb(root->fs_info, buf);
 			if (ret) {
-				btrfs_abort_transaction(trans, root, ret);
+				btrfs_abort_transaction(trans, ret);
 				return ret;
 			}
 		}
@@ -3236,7 +3236,7 @@ static int push_node_left(struct btrfs_trans_handle *trans,
 	ret = tree_mod_log_eb_copy(root->fs_info, dst, src, dst_nritems, 0,
 				   push_items);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
 	copy_extent_buffer(dst, src,
@@ -3311,7 +3311,7 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
 	ret = tree_mod_log_eb_copy(root->fs_info, dst, src, 0,
 				   src_nritems - push_items, push_items);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
 	copy_extent_buffer(dst, src,
@@ -3515,7 +3515,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans,
 	ret = tree_mod_log_eb_copy(root->fs_info, split, c, 0,
 				   mid, c_nritems - mid);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
 	copy_extent_buffer(split, c,
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 95fe439..679135d 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3366,23 +3366,23 @@ const char *btrfs_decode_error(int errno);
 
 __cold
 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
-			       struct btrfs_root *root, const char *function,
+			       const char *function,
 			       unsigned int line, int errno);
 
 /*
  * Call btrfs_abort_transaction as early as possible when an error condition is
  * detected, that way the exact line number is reported.
  */
-#define btrfs_abort_transaction(trans, root, errno)		\
+#define btrfs_abort_transaction(trans, errno)		\
 do {								\
 	/* Report first abort since mount */			\
 	if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED,	\
-			&((root)->fs_info->fs_state))) {	\
+			&((trans)->fs_info->fs_state))) {	\
 		WARN(1, KERN_DEBUG				\
 		"BTRFS: Transaction aborted (error %d)\n",	\
 		(errno));					\
 	}							\
-	__btrfs_abort_transaction((trans), (root), __func__,	\
+	__btrfs_abort_transaction((trans), __func__,		\
 				  __LINE__, (errno));		\
 } while (0)
 
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index ed67717..316ca24 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1188,7 +1188,7 @@ static int __btrfs_run_delayed_items(struct btrfs_trans_handle *trans,
 		if (ret) {
 			btrfs_release_delayed_node(curr_node);
 			curr_node = NULL;
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			break;
 		}
 
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 2081ed4..56d7b32 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2170,7 +2170,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
 				    path, bytenr, parent, root_objectid,
 				    owner, offset, refs_to_add);
 	if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 out:
 	btrfs_free_path(path);
 	return ret;
@@ -2950,7 +2950,7 @@ again:
 	trans->can_flush_pending_bgs = false;
 	ret = __btrfs_run_delayed_refs(trans, root, count);
 	if (ret < 0) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
 
@@ -3409,7 +3409,7 @@ again:
 		 * transaction, this only happens in really bad situations
 		 * anyway.
 		 */
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_put;
 	}
 	WARN_ON(ret);
@@ -3649,7 +3649,7 @@ again:
 				}
 				spin_unlock(&cur_trans->dirty_bgs_lock);
 			} else if (ret) {
-				btrfs_abort_transaction(trans, root, ret);
+				btrfs_abort_transaction(trans, ret);
 			}
 		}
 
@@ -3795,7 +3795,7 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
 							    cache);
 			}
 			if (ret)
-				btrfs_abort_transaction(trans, root, ret);
+				btrfs_abort_transaction(trans, ret);
 		}
 
 		/* if its not on the io list, we need to put the block group */
@@ -6656,7 +6656,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 						    NULL, refs_to_drop,
 						    is_data, &last_ref);
 			if (ret) {
-				btrfs_abort_transaction(trans, extent_root, ret);
+				btrfs_abort_transaction(trans, ret);
 				goto out;
 			}
 			btrfs_release_path(path);
@@ -6705,7 +6705,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 							 path->nodes[0]);
 			}
 			if (ret < 0) {
-				btrfs_abort_transaction(trans, extent_root, ret);
+				btrfs_abort_transaction(trans, ret);
 				goto out;
 			}
 			extent_slot = path->slots[0];
@@ -6716,10 +6716,10 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 			"unable to find ref byte nr %llu parent %llu root %llu  owner %llu offset %llu",
 			bytenr, parent, root_objectid, owner_objectid,
 			owner_offset);
-		btrfs_abort_transaction(trans, extent_root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	} else {
-		btrfs_abort_transaction(trans, extent_root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 
@@ -6731,7 +6731,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 		ret = convert_extent_item_v0(trans, extent_root, path,
 					     owner_objectid, 0);
 		if (ret < 0) {
-			btrfs_abort_transaction(trans, extent_root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 
@@ -6750,7 +6750,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 			btrfs_print_leaf(extent_root, path->nodes[0]);
 		}
 		if (ret < 0) {
-			btrfs_abort_transaction(trans, extent_root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 
@@ -6775,7 +6775,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 		btrfs_err(info, "trying to drop %d refs but we only have %Lu "
 			  "for bytenr %Lu", refs_to_drop, refs, bytenr);
 		ret = -EINVAL;
-		btrfs_abort_transaction(trans, extent_root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 	refs -= refs_to_drop;
@@ -6798,7 +6798,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 						    iref, refs_to_drop,
 						    is_data, &last_ref);
 			if (ret) {
-				btrfs_abort_transaction(trans, extent_root, ret);
+				btrfs_abort_transaction(trans, ret);
 				goto out;
 			}
 		}
@@ -6821,7 +6821,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 		ret = btrfs_del_items(trans, extent_root, path, path->slots[0],
 				      num_to_del);
 		if (ret) {
-			btrfs_abort_transaction(trans, extent_root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 		btrfs_release_path(path);
@@ -6829,7 +6829,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 		if (is_data) {
 			ret = btrfs_del_csums(trans, root, bytenr, num_bytes);
 			if (ret) {
-				btrfs_abort_transaction(trans, extent_root, ret);
+				btrfs_abort_transaction(trans, ret);
 				goto out;
 			}
 		}
@@ -6837,13 +6837,13 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 		ret = add_to_free_space_tree(trans, root->fs_info, bytenr,
 					     num_bytes);
 		if (ret) {
-			btrfs_abort_transaction(trans, extent_root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 
 		ret = update_block_group(trans, root, bytenr, num_bytes, 0);
 		if (ret) {
-			btrfs_abort_transaction(trans, extent_root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 	}
@@ -7627,8 +7627,7 @@ loop:
 			 * can do more things.
 			 */
 			if (ret < 0 && ret != -ENOSPC)
-				btrfs_abort_transaction(trans,
-							root, ret);
+				btrfs_abort_transaction(trans, ret);
 			else
 				ret = 0;
 			if (!exist)
@@ -9104,7 +9103,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 						&root->root_key,
 						root_item);
 			if (ret) {
-				btrfs_abort_transaction(trans, tree_root, ret);
+				btrfs_abort_transaction(trans, ret);
 				err = ret;
 				goto out_end_trans;
 			}
@@ -9131,7 +9130,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 
 	ret = btrfs_del_root(trans, tree_root, &root->root_key);
 	if (ret) {
-		btrfs_abort_transaction(trans, tree_root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_end_trans;
 	}
 
@@ -9139,7 +9138,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 		ret = btrfs_find_root(tree_root, &root->root_key, path,
 				      NULL, NULL);
 		if (ret < 0) {
-			btrfs_abort_transaction(trans, tree_root, ret);
+			btrfs_abort_transaction(trans, ret);
 			err = ret;
 			goto out_end_trans;
 		} else if (ret > 0) {
@@ -10084,11 +10083,11 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans,
 		ret = btrfs_insert_item(trans, extent_root, &key, &item,
 					sizeof(item));
 		if (ret)
-			btrfs_abort_transaction(trans, extent_root, ret);
+			btrfs_abort_transaction(trans, ret);
 		ret = btrfs_finish_chunk_alloc(trans, extent_root,
 					       key.objectid, key.offset);
 		if (ret)
-			btrfs_abort_transaction(trans, extent_root, ret);
+			btrfs_abort_transaction(trans, ret);
 		add_block_group_free_space(trans, root->fs_info, block_group);
 		/* already aborted the transaction if it failed. */
 next:
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index fc6390e..e4b8e77 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -698,7 +698,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
 			 */
 			ret = btrfs_split_item(trans, root, path, &key, offset);
 			if (ret && ret != -EAGAIN) {
-				btrfs_abort_transaction(trans, root, ret);
+				btrfs_abort_transaction(trans, ret);
 				goto out;
 			}
 
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index ffd9001..cc928aa 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -950,7 +950,7 @@ delete_extent_item:
 			ret = btrfs_del_items(trans, root, path, del_slot,
 					      del_nr);
 			if (ret) {
-				btrfs_abort_transaction(trans, root, ret);
+				btrfs_abort_transaction(trans, ret);
 				break;
 			}
 
@@ -974,7 +974,7 @@ delete_extent_item:
 		path->slots[0] = del_slot;
 		ret = btrfs_del_items(trans, root, path, del_slot, del_nr);
 		if (ret)
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 	}
 
 	leaf = path->nodes[0];
@@ -1190,7 +1190,7 @@ again:
 			goto again;
 		}
 		if (ret < 0) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 
@@ -1278,7 +1278,7 @@ again:
 
 		ret = btrfs_del_items(trans, root, path, del_slot, del_nr);
 		if (ret < 0) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 	}
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index cee2049..d571bd2 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -280,7 +280,7 @@ fail:
 	if (locked)
 		mutex_unlock(&trans->transaction->cache_write_mutex);
 	if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 
 	return ret;
 }
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index 53dbeaf..87e7e3d 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -305,7 +305,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
 out:
 	kvfree(bitmap);
 	if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 	return ret;
 }
 
@@ -454,7 +454,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans,
 out:
 	kvfree(bitmap);
 	if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 	return ret;
 }
 
@@ -851,7 +851,7 @@ int remove_from_free_space_tree(struct btrfs_trans_handle *trans,
 out:
 	btrfs_free_path(path);
 	if (ret)
-		btrfs_abort_transaction(trans, fs_info->free_space_root, ret);
+		btrfs_abort_transaction(trans, ret);
 	return ret;
 }
 
@@ -1047,7 +1047,7 @@ int add_to_free_space_tree(struct btrfs_trans_handle *trans,
 out:
 	btrfs_free_path(path);
 	if (ret)
-		btrfs_abort_transaction(trans, fs_info->free_space_root, ret);
+		btrfs_abort_transaction(trans, ret);
 	return ret;
 }
 
@@ -1193,7 +1193,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
 
 abort:
 	fs_info->creating_free_space_tree = 0;
-	btrfs_abort_transaction(trans, tree_root, ret);
+	btrfs_abort_transaction(trans, ret);
 	btrfs_end_transaction(trans, tree_root);
 	return ret;
 }
@@ -1280,7 +1280,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
 	return 0;
 
 abort:
-	btrfs_abort_transaction(trans, tree_root, ret);
+	btrfs_abort_transaction(trans, ret);
 	btrfs_end_transaction(trans, tree_root);
 	return ret;
 }
@@ -1333,7 +1333,7 @@ out:
 	btrfs_free_path(path);
 	mutex_unlock(&block_group->free_space_lock);
 	if (ret)
-		btrfs_abort_transaction(trans, fs_info->free_space_root, ret);
+		btrfs_abort_transaction(trans, ret);
 	return ret;
 }
 
@@ -1410,7 +1410,7 @@ int remove_block_group_free_space(struct btrfs_trans_handle *trans,
 out:
 	btrfs_free_path(path);
 	if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 	return ret;
 }
 
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index e3ad8c1..aa6faba 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -458,7 +458,7 @@ again:
 	BTRFS_I(inode)->generation = 0;
 	ret = btrfs_update_inode(trans, root, inode);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_put;
 	}
 
@@ -466,7 +466,7 @@ again:
 		ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode);
 		if (ret) {
 			if (ret != -ENOSPC)
-				btrfs_abort_transaction(trans, root, ret);
+				btrfs_abort_transaction(trans, ret);
 			goto out_put;
 		}
 	}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 1acba51..322ee50 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -294,7 +294,7 @@ static noinline int cow_file_range_inline(struct btrfs_root *root,
 				   start, aligned_end, NULL,
 				   1, 1, extent_item_size, &extent_inserted);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 
@@ -305,7 +305,7 @@ static noinline int cow_file_range_inline(struct btrfs_root *root,
 				   inline_len, compressed_size,
 				   compress_type, compressed_pages);
 	if (ret && ret != -ENOSPC) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	} else if (ret == -ENOSPC) {
 		ret = 1;
@@ -2595,7 +2595,7 @@ again:
 	ret = btrfs_insert_empty_item(trans, root, path, &key,
 					sizeof(*extent));
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_free_path;
 	}
 
@@ -2622,7 +2622,7 @@ again:
 			backref->root_id, backref->inum,
 			new->file_pos);	/* start - extent_offset */
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_free_path;
 	}
 
@@ -2891,7 +2891,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
 		trans->block_rsv = &root->fs_info->delalloc_block_rsv;
 		ret = btrfs_update_inode_fallback(trans, root, inode);
 		if (ret) /* -ENOMEM or corruption */
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 
@@ -2951,7 +2951,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
 			   ordered_extent->file_offset, ordered_extent->len,
 			   trans->transid);
 	if (ret < 0) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_unlock;
 	}
 
@@ -2961,7 +2961,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
 	btrfs_ordered_update_i_size(inode, 0, ordered_extent);
 	ret = btrfs_update_inode_fallback(trans, root, inode);
 	if (ret) { /* -ENOMEM or corruption */
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_unlock;
 	}
 	ret = 0;
@@ -3205,7 +3205,7 @@ void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans,
 		ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root,
 					    root->root_key.objectid);
 		if (ret)
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 		else
 			clear_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
 				  &root->state);
@@ -3296,7 +3296,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
 			if (ret != -EEXIST) {
 				clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
 					  &BTRFS_I(inode)->runtime_flags);
-				btrfs_abort_transaction(trans, root, ret);
+				btrfs_abort_transaction(trans, ret);
 				return ret;
 			}
 		}
@@ -3308,7 +3308,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
 		ret = btrfs_insert_orphan_item(trans, root->fs_info->tree_root,
 					       root->root_key.objectid);
 		if (ret && ret != -EEXIST) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			return ret;
 		}
 	}
@@ -4007,20 +4007,20 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans,
 		btrfs_info(root->fs_info,
 			"failed to delete reference to %.*s, inode %llu parent %llu",
 			name_len, name, ino, dir_ino);
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto err;
 	}
 skip_backref:
 	ret = btrfs_delete_delayed_dir_index(trans, root, dir, index);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto err;
 	}
 
 	ret = btrfs_del_inode_ref_in_log(trans, root, name, name_len,
 					 inode, dir_ino);
 	if (ret != 0 && ret != -ENOENT) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto err;
 	}
 
@@ -4029,7 +4029,7 @@ skip_backref:
 	if (ret == -ENOENT)
 		ret = 0;
 	else if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 err:
 	btrfs_free_path(path);
 	if (ret)
@@ -4143,7 +4143,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
 	WARN_ON(key.type != BTRFS_ROOT_ITEM_KEY || key.objectid != objectid);
 	ret = btrfs_delete_one_dir_name(trans, root, path, di);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 	btrfs_release_path(path);
@@ -4153,7 +4153,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
 				 dir_ino, &index, name, name_len);
 	if (ret < 0) {
 		if (ret != -ENOENT) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 		di = btrfs_search_dir_index_item(root, path, dir_ino,
@@ -4163,7 +4163,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
 				ret = -ENOENT;
 			else
 				ret = PTR_ERR(di);
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 
@@ -4176,7 +4176,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_delete_delayed_dir_index(trans, root, dir, index);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 
@@ -4185,7 +4185,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
 	dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
 	ret = btrfs_update_inode_fallback(trans, root, dir);
 	if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 out:
 	btrfs_free_path(path);
 	return ret;
@@ -4506,7 +4506,6 @@ search_again:
 							      pending_del_nr);
 					if (err) {
 						btrfs_abort_transaction(trans,
-									root,
 									err);
 						goto error;
 					}
@@ -4518,8 +4517,7 @@ search_again:
 							     item_end,
 							     new_size);
 				if (err) {
-					btrfs_abort_transaction(trans,
-								root, err);
+					btrfs_abort_transaction(trans, err);
 					goto error;
 				}
 			} else if (test_bit(BTRFS_ROOT_REF_COWS,
@@ -4582,8 +4580,7 @@ delete:
 						pending_del_slot,
 						pending_del_nr);
 				if (ret) {
-					btrfs_abort_transaction(trans,
-								root, ret);
+					btrfs_abort_transaction(trans, ret);
 					goto error;
 				}
 				pending_del_nr = 0;
@@ -4616,7 +4613,7 @@ out:
 		ret = btrfs_del_items(trans, root, path, pending_del_slot,
 				      pending_del_nr);
 		if (ret)
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 	}
 error:
 	if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID)
@@ -4785,7 +4782,7 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode,
 
 	ret = btrfs_drop_extents(trans, root, inode, offset, offset + len, 1);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		btrfs_end_transaction(trans, root);
 		return ret;
 	}
@@ -4793,7 +4790,7 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode,
 	ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode), offset,
 				       0, 0, len, 0, len, 0, 0, 0);
 	if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 	else
 		btrfs_update_inode(trans, root, inode);
 	btrfs_end_transaction(trans, root);
@@ -5020,7 +5017,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
 			i_size_write(inode, BTRFS_I(inode)->disk_i_size);
 			err = btrfs_orphan_del(trans, inode);
 			if (err)
-				btrfs_abort_transaction(trans, root, err);
+				btrfs_abort_transaction(trans, err);
 			btrfs_end_transaction(trans, root);
 		}
 	}
@@ -6317,7 +6314,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
 	if (ret == -EEXIST || ret == -EOVERFLOW)
 		goto fail_dir_item;
 	else if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
 
@@ -6328,7 +6325,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
 		current_fs_time(parent_inode->i_sb);
 	ret = btrfs_update_inode(trans, root, parent_inode);
 	if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 	return ret;
 
 fail_dir_item:
@@ -9551,7 +9548,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 			ret = btrfs_update_inode(trans, root, old_inode);
 	}
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_fail;
 	}
 
@@ -9571,7 +9568,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 			ret = btrfs_update_inode(trans, dest, new_inode);
 	}
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_fail;
 	}
 
@@ -9579,7 +9576,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 			     new_dentry->d_name.name,
 			     new_dentry->d_name.len, 0, old_idx);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_fail;
 	}
 
@@ -9587,7 +9584,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 			     old_dentry->d_name.name,
 			     old_dentry->d_name.len, 0, new_idx);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_fail;
 	}
 
@@ -9826,7 +9823,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 			ret = btrfs_update_inode(trans, root, old_inode);
 	}
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_fail;
 	}
 
@@ -9850,7 +9847,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 		if (!ret && new_inode->i_nlink == 0)
 			ret = btrfs_orphan_add(trans, d_inode(new_dentry));
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out_fail;
 		}
 	}
@@ -9859,7 +9856,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 			     new_dentry->d_name.name,
 			     new_dentry->d_name.len, 0, index);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_fail;
 	}
 
@@ -9879,7 +9876,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 						old_dentry);
 
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out_fail;
 		}
 	}
@@ -10305,7 +10302,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
 		if (ret) {
 			btrfs_free_reserved_extent(root, ins.objectid,
 						   ins.offset, 0);
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			if (own_trans)
 				btrfs_end_transaction(trans, root);
 			break;
@@ -10365,7 +10362,7 @@ next:
 		ret = btrfs_update_inode(trans, root, inode);
 
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			if (own_trans)
 				btrfs_end_transaction(trans, root);
 			break;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 81413e6..14ed1e9 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -561,7 +561,7 @@ static noinline int create_subvol(struct inode *dir,
 	new_root = btrfs_read_fs_root_no_name(root->fs_info, &key);
 	if (IS_ERR(new_root)) {
 		ret = PTR_ERR(new_root);
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -570,7 +570,7 @@ static noinline int create_subvol(struct inode *dir,
 	ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid);
 	if (ret) {
 		/* We potentially lose an unused inode item here */
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -583,7 +583,7 @@ static noinline int create_subvol(struct inode *dir,
 	 */
 	ret = btrfs_set_inode_index(dir, &index);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -591,7 +591,7 @@ static noinline int create_subvol(struct inode *dir,
 				    name, namelen, dir, &key,
 				    BTRFS_FT_DIR, index);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -608,7 +608,7 @@ static noinline int create_subvol(struct inode *dir,
 				  root_item->uuid, BTRFS_UUID_KEY_SUBVOL,
 				  objectid);
 	if (ret)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 
 fail:
 	kfree(root_item);
@@ -2488,7 +2488,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 				dentry->d_name.len);
 	if (ret) {
 		err = ret;
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_end_trans;
 	}
 
@@ -2504,7 +2504,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 					root->fs_info->tree_root,
 					dest->root_key.objectid);
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			err = ret;
 			goto out_end_trans;
 		}
@@ -2514,7 +2514,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 				  dest->root_item.uuid, BTRFS_UUID_KEY_SUBVOL,
 				  dest->root_key.objectid);
 	if (ret && ret != -ENOENT) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		err = ret;
 		goto out_end_trans;
 	}
@@ -2524,7 +2524,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 					  BTRFS_UUID_KEY_RECEIVED_SUBVOL,
 					  dest->root_key.objectid);
 		if (ret && ret != -ENOENT) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			err = ret;
 			goto out_end_trans;
 		}
@@ -3291,7 +3291,7 @@ static int clone_finish_inode_update(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_update_inode(trans, root, inode);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		btrfs_end_transaction(trans, root);
 		goto out;
 	}
@@ -3693,7 +3693,7 @@ process_slot:
 				if (ret) {
 					if (ret != -EOPNOTSUPP)
 						btrfs_abort_transaction(trans,
-								root, ret);
+									ret);
 					btrfs_end_transaction(trans, root);
 					goto out;
 				}
@@ -3701,8 +3701,7 @@ process_slot:
 				ret = btrfs_insert_empty_item(trans, root, path,
 							      &new_key, size);
 				if (ret) {
-					btrfs_abort_transaction(trans, root,
-								ret);
+					btrfs_abort_transaction(trans, ret);
 					btrfs_end_transaction(trans, root);
 					goto out;
 				}
@@ -3734,7 +3733,6 @@ process_slot:
 							new_key.offset - datao);
 					if (ret) {
 						btrfs_abort_transaction(trans,
-									root,
 									ret);
 						btrfs_end_transaction(trans,
 								      root);
@@ -3771,7 +3769,6 @@ process_slot:
 				if (ret) {
 					if (ret != -EOPNOTSUPP)
 						btrfs_abort_transaction(trans,
-									root,
 									ret);
 					btrfs_end_transaction(trans, root);
 					goto out;
@@ -3827,7 +3824,7 @@ process_slot:
 					 last_dest_end, destoff + len, 1);
 		if (ret) {
 			if (ret != -EOPNOTSUPP)
-				btrfs_abort_transaction(trans, root, ret);
+				btrfs_abort_transaction(trans, ret);
 			btrfs_end_transaction(trans, root);
 			goto out;
 		}
@@ -5163,13 +5160,13 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,
 					  BTRFS_UUID_KEY_RECEIVED_SUBVOL,
 					  root->root_key.objectid);
 		if (ret < 0 && ret != -EEXIST) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 	}
 	ret = btrfs_commit_transaction(trans, root);
 	if (ret < 0) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 0477dca..9d07953 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1719,7 +1719,7 @@ int replace_file_extents(struct btrfs_trans_handle *trans,
 					   btrfs_header_owner(leaf),
 					   key.objectid, key.offset);
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			break;
 		}
 
@@ -1727,7 +1727,7 @@ int replace_file_extents(struct btrfs_trans_handle *trans,
 					parent, btrfs_header_owner(leaf),
 					key.objectid, key.offset);
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			break;
 		}
 	}
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index f1c3086..7fd7e18 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -150,7 +150,7 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
 
 	ret = btrfs_search_slot(trans, root, key, path, 0, 1);
 	if (ret < 0) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 
@@ -176,20 +176,20 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
 		ret = btrfs_search_slot(trans, root, key, path,
 				-1, 1);
 		if (ret < 0) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 
 		ret = btrfs_del_item(trans, root, path);
 		if (ret < 0) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 		btrfs_release_path(path);
 		ret = btrfs_insert_empty_item(trans, root, path,
 				key, sizeof(*item));
 		if (ret < 0) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 		l = path->nodes[0];
@@ -448,7 +448,7 @@ again:
 	ret = btrfs_insert_empty_item(trans, tree_root, path, &key,
 				      sizeof(*ref) + name_len);
 	if (ret) {
-		btrfs_abort_transaction(trans, tree_root, ret);
+		btrfs_abort_transaction(trans, ret);
 		btrfs_free_path(path);
 		return ret;
 	}
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index d8e48bb..4c031d7 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -229,9 +229,11 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
  */
 __cold
 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
-			       struct btrfs_root *root, const char *function,
+			       const char *function,
 			       unsigned int line, int errno)
 {
+	struct btrfs_fs_info *fs_info = trans->fs_info;
+
 	trans->aborted = errno;
 	/* Nothing used. The other threads that have joined this
 	 * transaction may be able to continue. */
@@ -239,16 +241,16 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
 		const char *errstr;
 
 		errstr = btrfs_decode_error(errno);
-		btrfs_warn(root->fs_info,
+		btrfs_warn(fs_info,
 		           "%s:%d: Aborting unused transaction(%s).",
 		           function, line, errstr);
 		return;
 	}
 	ACCESS_ONCE(trans->transaction->aborted) = errno;
 	/* Wake up anybody who may be waiting on this transaction */
-	wake_up(&root->fs_info->transaction_wait);
-	wake_up(&root->fs_info->transaction_blocked_wait);
-	__btrfs_handle_fs_error(root->fs_info, function, line, errno, NULL);
+	wake_up(&fs_info->transaction_wait);
+	wake_up(&fs_info->transaction_blocked_wait);
+	__btrfs_handle_fs_error(fs_info, function, line, errno, NULL);
 }
 /*
  * __btrfs_panic decodes unexpected, fatal errors from the caller,
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index db0eb1f..ad2b6d1 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1491,7 +1491,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 		goto dir_item_existed;
 	} else if (IS_ERR(dir_item)) {
 		ret = PTR_ERR(dir_item);
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 	btrfs_release_path(path);
@@ -1504,7 +1504,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	 */
 	ret = btrfs_run_delayed_items(trans, root);
 	if (ret) {	/* Transaction aborted */
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -1543,7 +1543,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	if (ret) {
 		btrfs_tree_unlock(old);
 		free_extent_buffer(old);
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -1554,7 +1554,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	btrfs_tree_unlock(old);
 	free_extent_buffer(old);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 	/* see comments in should_cow_block() */
@@ -1568,7 +1568,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	btrfs_tree_unlock(tmp);
 	free_extent_buffer(tmp);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -1580,7 +1580,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 				 btrfs_ino(parent_inode), index,
 				 dentry->d_name.name, dentry->d_name.len);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -1588,19 +1588,19 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	pending->snap = btrfs_read_fs_root_no_name(root->fs_info, &key);
 	if (IS_ERR(pending->snap)) {
 		ret = PTR_ERR(pending->snap);
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
 	ret = btrfs_reloc_post_snapshot(trans, pending);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
 	ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -1622,7 +1622,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	/* We have check then name at the beginning, so it is impossible. */
 	BUG_ON(ret == -EEXIST || ret == -EOVERFLOW);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -1632,13 +1632,13 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 		current_fs_time(parent_inode->i_sb);
 	ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 	ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, new_uuid.b,
 				  BTRFS_UUID_KEY_SUBVOL, objectid);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 	if (!btrfs_is_empty_uuid(new_root_item->received_uuid)) {
@@ -1647,14 +1647,14 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 					  BTRFS_UUID_KEY_RECEIVED_SUBVOL,
 					  objectid);
 		if (ret && ret != -EEXIST) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto fail;
 		}
 	}
 
 	ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 
@@ -1850,7 +1850,7 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,
 
 	WARN_ON(trans->use_count > 1);
 
-	btrfs_abort_transaction(trans, root, err);
+	btrfs_abort_transaction(trans, err);
 
 	spin_lock(&root->fs_info->trans_lock);
 
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 5893018..697d7f6 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2788,7 +2788,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 	ret = btrfs_write_marked_extents(log, &log->dirty_log_pages, mark);
 	if (ret) {
 		blk_finish_plug(&plug);
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		btrfs_free_logged_extents(log, log_transid);
 		btrfs_set_log_full_commit(root->fs_info, trans);
 		mutex_unlock(&root->log_mutex);
@@ -2838,7 +2838,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 		btrfs_set_log_full_commit(root->fs_info, trans);
 
 		if (ret != -ENOSPC) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			mutex_unlock(&log_root_tree->log_mutex);
 			goto out;
 		}
@@ -2898,7 +2898,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 	blk_finish_plug(&plug);
 	if (ret) {
 		btrfs_set_log_full_commit(root->fs_info, trans);
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		btrfs_free_logged_extents(log, log_transid);
 		mutex_unlock(&log_root_tree->log_mutex);
 		goto out_wake_log_root;
@@ -2934,7 +2934,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 	ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
 	if (ret) {
 		btrfs_set_log_full_commit(root->fs_info, trans);
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out_wake_log_root;
 	}
 
@@ -2991,7 +2991,7 @@ static void free_log_tree(struct btrfs_trans_handle *trans,
 	ret = walk_log_tree(trans, log, &wc);
 	/* I don't think this can happen but just in case */
 	if (ret)
-		btrfs_abort_transaction(trans, log, ret);
+		btrfs_abort_transaction(trans, ret);
 
 	while (1) {
 		ret = find_first_extent_bit(&log->dirty_log_pages,
@@ -3160,7 +3160,7 @@ out_unlock:
 		btrfs_set_log_full_commit(root->fs_info, trans);
 		ret = 0;
 	} else if (ret < 0)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 
 	btrfs_end_log_trans(root);
 
@@ -3193,7 +3193,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
 		btrfs_set_log_full_commit(root->fs_info, trans);
 		ret = 0;
 	} else if (ret < 0 && ret != -ENOENT)
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 	btrfs_end_log_trans(root);
 
 	return ret;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index e0332c9..0f4f99a 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2399,14 +2399,14 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 		ret = init_first_rw_device(trans, root, device);
 		unlock_chunks(root);
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto error_trans;
 		}
 	}
 
 	ret = btrfs_add_device(trans, root, device);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto error_trans;
 	}
 
@@ -2415,7 +2415,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 
 		ret = btrfs_finish_sprout(trans, root);
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto error_trans;
 		}
 
@@ -2801,7 +2801,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 					    &dev_extent_len);
 		if (ret) {
 			mutex_unlock(&fs_devices->device_list_mutex);
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 
@@ -2820,7 +2820,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 			ret = btrfs_update_device(trans, map->stripes[i].dev);
 			if (ret) {
 				mutex_unlock(&fs_devices->device_list_mutex);
-				btrfs_abort_transaction(trans, root, ret);
+				btrfs_abort_transaction(trans, ret);
 				goto out;
 			}
 		}
@@ -2829,7 +2829,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_free_chunk(trans, root, chunk_objectid, chunk_offset);
 	if (ret) {
-		btrfs_abort_transaction(trans, root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 
@@ -2838,14 +2838,14 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 	if (map->type & BTRFS_BLOCK_GROUP_SYSTEM) {
 		ret = btrfs_del_sys_chunk(root, chunk_objectid, chunk_offset);
 		if (ret) {
-			btrfs_abort_transaction(trans, root, ret);
+			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 	}
 
 	ret = btrfs_remove_block_group(trans, extent_root, chunk_offset, em);
 	if (ret) {
-		btrfs_abort_transaction(trans, extent_root, ret);
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 
@@ -4240,7 +4240,7 @@ int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info)
 				      BTRFS_UUID_TREE_OBJECTID);
 	if (IS_ERR(uuid_root)) {
 		ret = PTR_ERR(uuid_root);
-		btrfs_abort_transaction(trans, tree_root, ret);
+		btrfs_abort_transaction(trans, ret);
 		btrfs_end_transaction(trans, tree_root);
 		return ret;
 	}
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 15/31] btrfs: call functions that overwrite their root parameter with fs_info
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (13 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 14/31] btrfs: btrfs_abort_transaction, drop root parameter jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-09-06 17:40   ` David Sterba
  2016-06-24 22:15 ` [PATCH 16/31] btrfs: call functions that always use the same root with fs_info instead jeffm
                   ` (16 subsequent siblings)
  31 siblings, 1 reply; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

There are 11 functions that accept a root parameter and immediately
overwrite it.  We can pass those an fs_info pointer instead.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h            |  4 ++--
 fs/btrfs/disk-io.c          |  4 ++--
 fs/btrfs/extent-tree.c      | 17 +++++++-------
 fs/btrfs/file-item.c        |  5 ++---
 fs/btrfs/free-space-cache.c |  5 ++---
 fs/btrfs/free-space-cache.h |  2 +-
 fs/btrfs/transaction.c      |  9 ++++----
 fs/btrfs/tree-log.c         |  6 ++---
 fs/btrfs/volumes.c          | 55 +++++++++++++++++++++------------------------
 fs/btrfs/volumes.h          |  4 ++--
 10 files changed, 52 insertions(+), 59 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 679135d..cc2d8f5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2611,7 +2611,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
 			    struct btrfs_root *root);
 int btrfs_extent_readonly(struct btrfs_root *root, u64 bytenr);
 int btrfs_free_block_groups(struct btrfs_fs_info *info);
-int btrfs_read_block_groups(struct btrfs_root *root);
+int btrfs_read_block_groups(struct btrfs_fs_info *info);
 int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr);
 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
 			   struct btrfs_root *root, u64 bytes_used,
@@ -3014,7 +3014,7 @@ int btrfs_find_name_in_ext_backref(struct btrfs_path *path,
 /* file-item.c */
 struct btrfs_dio_private;
 int btrfs_del_csums(struct btrfs_trans_handle *trans,
-		    struct btrfs_root *root, u64 bytenr, u64 len);
+		    struct btrfs_fs_info *fs_info, u64 bytenr, u64 len);
 int btrfs_lookup_bio_sums(struct btrfs_root *root, struct inode *inode,
 			  struct bio *bio, u32 *dst);
 int btrfs_lookup_bio_sums_dio(struct btrfs_root *root, struct inode *inode,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index e1b36e1..42d4a31 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2900,7 +2900,7 @@ int open_ctree(struct super_block *sb,
 	read_extent_buffer(chunk_root->node, fs_info->chunk_tree_uuid,
 	   btrfs_header_chunk_tree_uuid(chunk_root->node), BTRFS_UUID_SIZE);
 
-	ret = btrfs_read_chunk_tree(chunk_root);
+	ret = btrfs_read_chunk_tree(fs_info);
 	if (ret) {
 		btrfs_err(fs_info, "failed to read chunk tree: %d", ret);
 		goto fail_tree_roots;
@@ -3001,7 +3001,7 @@ retry_root_backup:
 		goto fail_sysfs;
 	}
 
-	ret = btrfs_read_block_groups(fs_info->extent_root);
+	ret = btrfs_read_block_groups(fs_info);
 	if (ret) {
 		btrfs_err(fs_info, "failed to read block groups: %d", ret);
 		goto fail_sysfs;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 56d7b32..0b493c4 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2420,7 +2420,7 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
 			btrfs_pin_extent(root, node->bytenr,
 					 node->num_bytes, 1);
 			if (head->is_data) {
-				ret = btrfs_del_csums(trans, root,
+				ret = btrfs_del_csums(trans, root->fs_info,
 						      node->bytenr,
 						      node->num_bytes);
 			}
@@ -3610,7 +3610,8 @@ again:
 
 		if (cache->disk_cache_state == BTRFS_DC_SETUP) {
 			cache->io_ctl.inode = NULL;
-			ret = btrfs_write_out_cache(root, trans, cache, path);
+			ret = btrfs_write_out_cache(root->fs_info, trans,
+						    cache, path);
 			if (ret == 0 && cache->io_ctl.inode) {
 				num_started++;
 				should_put = 0;
@@ -3760,7 +3761,8 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
 
 		if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) {
 			cache->io_ctl.inode = NULL;
-			ret = btrfs_write_out_cache(root, trans, cache, path);
+			ret = btrfs_write_out_cache(root->fs_info, trans,
+						    cache, path);
 			if (ret == 0 && cache->io_ctl.inode) {
 				num_started++;
 				should_put = 0;
@@ -6827,7 +6829,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 		btrfs_release_path(path);
 
 		if (is_data) {
-			ret = btrfs_del_csums(trans, root, bytenr, num_bytes);
+			ret = btrfs_del_csums(trans, info, bytenr, num_bytes);
 			if (ret) {
 				btrfs_abort_transaction(trans, ret);
 				goto out;
@@ -9882,12 +9884,12 @@ btrfs_create_block_group_cache(struct btrfs_root *root, u64 start, u64 size)
 	return cache;
 }
 
-int btrfs_read_block_groups(struct btrfs_root *root)
+int btrfs_read_block_groups(struct btrfs_fs_info *info)
 {
+	struct btrfs_root *root = info->extent_root;
 	struct btrfs_path *path;
 	int ret;
 	struct btrfs_block_group_cache *cache;
-	struct btrfs_fs_info *info = root->fs_info;
 	struct btrfs_space_info *space_info;
 	struct btrfs_key key;
 	struct btrfs_key found_key;
@@ -9895,7 +9897,6 @@ int btrfs_read_block_groups(struct btrfs_root *root)
 	int need_clear = 0;
 	u64 cache_gen;
 
-	root = info->extent_root;
 	key.objectid = 0;
 	key.offset = 0;
 	key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
@@ -10683,7 +10684,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
 		 * Btrfs_remove_chunk will abort the transaction if things go
 		 * horribly wrong.
 		 */
-		ret = btrfs_remove_chunk(trans, root,
+		ret = btrfs_remove_chunk(trans, fs_info,
 					 block_group->key.objectid);
 
 		if (ret) {
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index e4b8e77..1160d96 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -600,8 +600,9 @@ static noinline void truncate_one_csum(struct btrfs_root *root,
  * range of bytes.
  */
 int btrfs_del_csums(struct btrfs_trans_handle *trans,
-		    struct btrfs_root *root, u64 bytenr, u64 len)
+		    struct btrfs_fs_info *fs_info, u64 bytenr, u64 len)
 {
+	struct btrfs_root *root = fs_info->csum_root;
 	struct btrfs_path *path;
 	struct btrfs_key key;
 	u64 end_byte = bytenr + len;
@@ -611,8 +612,6 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
 	u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
 	int blocksize_bits = root->fs_info->sb->s_blocksize_bits;
 
-	root = root->fs_info->csum_root;
-
 	path = btrfs_alloc_path();
 	if (!path)
 		return -ENOMEM;
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index d571bd2..5cbfa64 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -1351,17 +1351,16 @@ out_nospc:
 	goto out;
 }
 
-int btrfs_write_out_cache(struct btrfs_root *root,
+int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
 			  struct btrfs_trans_handle *trans,
 			  struct btrfs_block_group_cache *block_group,
 			  struct btrfs_path *path)
 {
+	struct btrfs_root *root = fs_info->tree_root;
 	struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
 	struct inode *inode;
 	int ret = 0;
 
-	root = root->fs_info->tree_root;
-
 	spin_lock(&block_group->lock);
 	if (block_group->disk_cache_state < BTRFS_DC_SETUP) {
 		spin_unlock(&block_group->lock);
diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h
index 3af651c..92e2d1a 100644
--- a/fs/btrfs/free-space-cache.h
+++ b/fs/btrfs/free-space-cache.h
@@ -72,7 +72,7 @@ int btrfs_wait_cache_io(struct btrfs_root *root,
 			struct btrfs_block_group_cache *block_group,
 			struct btrfs_io_ctl *io_ctl,
 			struct btrfs_path *path, u64 offset);
-int btrfs_write_out_cache(struct btrfs_root *root,
+int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
 			  struct btrfs_trans_handle *trans,
 			  struct btrfs_block_group_cache *block_group,
 			  struct btrfs_path *path);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index ad2b6d1..b540de1 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1222,10 +1222,9 @@ void btrfs_add_dead_root(struct btrfs_root *root)
  * update all the cowonly tree roots on disk
  */
 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans,
-				    struct btrfs_root *root)
+				    struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_root *gang[8];
-	struct btrfs_fs_info *fs_info = root->fs_info;
 	int i;
 	int ret;
 	int err = 0;
@@ -1239,7 +1238,7 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans,
 		if (ret == 0)
 			break;
 		for (i = 0; i < ret; i++) {
-			root = gang[i];
+			struct btrfs_root *root = gang[i];
 			radix_tree_tag_clear(&fs_info->fs_roots_radix,
 					(unsigned long)root->root_key.objectid,
 					BTRFS_ROOT_TRANS_TAG);
@@ -1346,7 +1345,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,
 	 */
 	mutex_lock(&fs_info->tree_log_mutex);
 
-	ret = commit_fs_roots(trans, src);
+	ret = commit_fs_roots(trans, fs_info);
 	if (ret)
 		goto out;
 	ret = btrfs_qgroup_prepare_account_extents(trans, fs_info);
@@ -2136,7 +2135,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
 	 */
 	mutex_lock(&root->fs_info->tree_log_mutex);
 
-	ret = commit_fs_roots(trans, root);
+	ret = commit_fs_roots(trans, root->fs_info);
 	if (ret) {
 		mutex_unlock(&root->fs_info->tree_log_mutex);
 		mutex_unlock(&root->fs_info->reloc_mutex);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 697d7f6..bdacbc3 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -781,9 +781,9 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
 						list);
 				if (!ret)
 					ret = btrfs_del_csums(trans,
-						      root->fs_info->csum_root,
-						      sums->bytenr,
-						      sums->len);
+							      root->fs_info,
+							      sums->bytenr,
+							      sums->len);
 				if (!ret)
 					ret = btrfs_csum_file_blocks(trans,
 						root->fs_info->csum_root,
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 0f4f99a..befe4a7 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1610,9 +1610,10 @@ error:
  * the btrfs_device struct should be fully filled in
  */
 static int btrfs_add_device(struct btrfs_trans_handle *trans,
-			    struct btrfs_root *root,
+			    struct btrfs_fs_info *fs_info,
 			    struct btrfs_device *device)
 {
+	struct btrfs_root *root = fs_info->chunk_root;
 	int ret;
 	struct btrfs_path *path;
 	struct btrfs_dev_item *dev_item;
@@ -1620,8 +1621,6 @@ static int btrfs_add_device(struct btrfs_trans_handle *trans,
 	struct btrfs_key key;
 	unsigned long ptr;
 
-	root = root->fs_info->chunk_root;
-
 	path = btrfs_alloc_path();
 	if (!path)
 		return -ENOMEM;
@@ -1680,16 +1679,15 @@ static void update_dev_time(char *path_name)
 	filp_close(filp, NULL);
 }
 
-static int btrfs_rm_dev_item(struct btrfs_root *root,
+static int btrfs_rm_dev_item(struct btrfs_fs_info *fs_info,
 			     struct btrfs_device *device)
 {
+	struct btrfs_root *root = fs_info->chunk_root;
 	int ret;
 	struct btrfs_path *path;
 	struct btrfs_key key;
 	struct btrfs_trans_handle *trans;
 
-	root = root->fs_info->chunk_root;
-
 	path = btrfs_alloc_path();
 	if (!path)
 		return -ENOMEM;
@@ -1858,7 +1856,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 	 * counter although write_all_supers() is not locked out. This
 	 * could give a filesystem state which requires a degraded mount.
 	 */
-	ret = btrfs_rm_dev_item(root->fs_info->chunk_root, device);
+	ret = btrfs_rm_dev_item(root->fs_info, device);
 	if (ret)
 		goto error_undo;
 
@@ -2193,8 +2191,9 @@ static int btrfs_prepare_sprout(struct btrfs_root *root)
  * Store the expected generation for seed devices in device items.
  */
 static int btrfs_finish_sprout(struct btrfs_trans_handle *trans,
-			       struct btrfs_root *root)
+			       struct btrfs_fs_info *fs_info)
 {
+	struct btrfs_root *root = fs_info->chunk_root;
 	struct btrfs_path *path;
 	struct extent_buffer *leaf;
 	struct btrfs_dev_item *dev_item;
@@ -2209,7 +2208,6 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans,
 	if (!path)
 		return -ENOMEM;
 
-	root = root->fs_info->chunk_root;
 	key.objectid = BTRFS_DEV_ITEMS_OBJECTID;
 	key.offset = 0;
 	key.type = BTRFS_DEV_ITEM_KEY;
@@ -2404,7 +2402,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 		}
 	}
 
-	ret = btrfs_add_device(trans, root, device);
+	ret = btrfs_add_device(trans, root->fs_info, device);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
 		goto error_trans;
@@ -2413,7 +2411,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 	if (seeding_dev) {
 		char fsid_buf[BTRFS_UUID_UNPARSED_SIZE];
 
-		ret = btrfs_finish_sprout(trans, root);
+		ret = btrfs_finish_sprout(trans, root->fs_info);
 		if (ret) {
 			btrfs_abort_transaction(trans, ret);
 			goto error_trans;
@@ -2668,14 +2666,14 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
 }
 
 static int btrfs_free_chunk(struct btrfs_trans_handle *trans,
-			    struct btrfs_root *root, u64 chunk_objectid,
+			    struct btrfs_fs_info *fs_info, u64 chunk_objectid,
 			    u64 chunk_offset)
 {
+	struct btrfs_root *root = fs_info->chunk_root;
 	int ret;
 	struct btrfs_path *path;
 	struct btrfs_key key;
 
-	root = root->fs_info->chunk_root;
 	path = btrfs_alloc_path();
 	if (!path)
 		return -ENOMEM;
@@ -2752,8 +2750,9 @@ static int btrfs_del_sys_chunk(struct btrfs_root *root, u64 chunk_objectid, u64
 }
 
 int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
-		       struct btrfs_root *root, u64 chunk_offset)
+		       struct btrfs_fs_info *fs_info, u64 chunk_offset)
 {
+	struct btrfs_root *root = fs_info->chunk_root;
 	struct extent_map_tree *em_tree;
 	struct extent_map *em;
 	struct btrfs_root *extent_root = root->fs_info->extent_root;
@@ -2764,8 +2763,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 	struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
 
 	/* Just in case */
-	root = root->fs_info->chunk_root;
-	em_tree = &root->fs_info->mapping_tree.map_tree;
+	em_tree = &fs_info->mapping_tree.map_tree;
 
 	read_lock(&em_tree->lock);
 	em = lookup_extent_mapping(em_tree, chunk_offset, 1);
@@ -2827,7 +2825,8 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 	}
 	mutex_unlock(&fs_devices->device_list_mutex);
 
-	ret = btrfs_free_chunk(trans, root, chunk_objectid, chunk_offset);
+	ret = btrfs_free_chunk(trans, root->fs_info, chunk_objectid,
+			       chunk_offset);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
 		goto out;
@@ -2855,15 +2854,13 @@ out:
 	return ret;
 }
 
-static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset)
+static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
 {
-	struct btrfs_root *extent_root;
+	struct btrfs_root *root = fs_info->chunk_root;
+	struct btrfs_root *extent_root = fs_info->extent_root;
 	struct btrfs_trans_handle *trans;
 	int ret;
 
-	root = root->fs_info->chunk_root;
-	extent_root = root->fs_info->extent_root;
-
 	/*
 	 * Prevent races with automatic removal of unused block groups.
 	 * After we relocate and before we remove the chunk with offset
@@ -2901,7 +2898,7 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset)
 	 * step two, delete the device extents and the
 	 * chunk tree entries
 	 */
-	ret = btrfs_remove_chunk(trans, root, chunk_offset);
+	ret = btrfs_remove_chunk(trans, root->fs_info, chunk_offset);
 	btrfs_end_transaction(trans, extent_root);
 	return ret;
 }
@@ -2955,7 +2952,7 @@ again:
 		btrfs_release_path(path);
 
 		if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) {
-			ret = btrfs_relocate_chunk(chunk_root,
+			ret = btrfs_relocate_chunk(root->fs_info,
 						   found_key.offset);
 			if (ret == -ENOSPC)
 				failed++;
@@ -3601,8 +3598,7 @@ again:
 			chunk_reserved = 1;
 		}
 
-		ret = btrfs_relocate_chunk(chunk_root,
-					   found_key.offset);
+		ret = btrfs_relocate_chunk(fs_info, found_key.offset);
 		mutex_unlock(&fs_info->delete_unused_bgs_mutex);
 		if (ret && ret != -ENOSPC)
 			goto error;
@@ -4370,7 +4366,7 @@ again:
 		chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent);
 		btrfs_release_path(path);
 
-		ret = btrfs_relocate_chunk(root, chunk_offset);
+		ret = btrfs_relocate_chunk(root->fs_info, chunk_offset);
 		mutex_unlock(&root->fs_info->delete_unused_bgs_mutex);
 		if (ret && ret != -ENOSPC)
 			goto done;
@@ -6703,8 +6699,9 @@ out_short_read:
 	return -EIO;
 }
 
-int btrfs_read_chunk_tree(struct btrfs_root *root)
+int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
 {
+	struct btrfs_root *root = fs_info->chunk_root;
 	struct btrfs_path *path;
 	struct extent_buffer *leaf;
 	struct btrfs_key key;
@@ -6713,8 +6710,6 @@ int btrfs_read_chunk_tree(struct btrfs_root *root)
 	int slot;
 	u64 total_dev = 0;
 
-	root = root->fs_info->chunk_root;
-
 	path = btrfs_alloc_path();
 	if (!path)
 		return -ENOMEM;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 0ac90f8..b0605cb 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -386,7 +386,7 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
 		     u64 chunk_start, u64 physical, u64 devid,
 		     u64 **logical, int *naddrs, int *stripe_len);
 int btrfs_read_sys_array(struct btrfs_root *root);
-int btrfs_read_chunk_tree(struct btrfs_root *root);
+int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
 int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 		      struct btrfs_root *extent_root, u64 type);
 void btrfs_mapping_init(struct btrfs_mapping_tree *tree);
@@ -462,7 +462,7 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
 				struct btrfs_root *extent_root,
 				u64 chunk_offset, u64 chunk_size);
 int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
-		       struct btrfs_root *root, u64 chunk_offset);
+		       struct btrfs_fs_info *fs_info, u64 chunk_offset);
 
 static inline int btrfs_dev_stats_dirty(struct btrfs_device *dev)
 {
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 16/31] btrfs: call functions that always use the same root with fs_info instead
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (14 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 15/31] btrfs: call functions that overwrite their root parameter with fs_info jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 17/31] btrfs: btrfs_init_new_device should use fs_info->dev_root jeffm
                   ` (15 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

There are many functions that are always called with the same root
argument.  Rather than passing the same root every time, we can
pass an fs_info pointer instead and have the function get the root
pointer itself.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h             | 16 +++++++--------
 fs/btrfs/disk-io.c           | 44 ++++++++++++++++++++++--------------------
 fs/btrfs/disk-io.h           |  4 ++--
 fs/btrfs/extent-tree.c       | 20 ++++++++++---------
 fs/btrfs/inode.c             |  6 +++---
 fs/btrfs/ioctl.c             | 18 ++++++++---------
 fs/btrfs/relocation.c        |  4 ++--
 fs/btrfs/root-tree.c         |  9 ++++++---
 fs/btrfs/super.c             | 13 +++++++------
 fs/btrfs/transaction.c       |  6 +++---
 fs/btrfs/uuid-tree.c         | 10 ++++++----
 fs/btrfs/volumes.c           | 46 +++++++++++++++++++++++++-------------------
 fs/btrfs/volumes.h           |  4 ++--
 include/trace/events/btrfs.h | 16 +++++++--------
 14 files changed, 115 insertions(+), 101 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index cc2d8f5..7063c55 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2612,7 +2612,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
 int btrfs_extent_readonly(struct btrfs_root *root, u64 bytenr);
 int btrfs_free_block_groups(struct btrfs_fs_info *info);
 int btrfs_read_block_groups(struct btrfs_fs_info *info);
-int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr);
+int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr);
 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
 			   struct btrfs_root *root, u64 bytes_used,
 			   u64 type, u64 chunk_objectid, u64 chunk_offset,
@@ -2621,7 +2621,7 @@ struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(
 				struct btrfs_fs_info *fs_info,
 				const u64 chunk_offset);
 int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
-			     struct btrfs_root *root, u64 group_start,
+			     struct btrfs_fs_info *fs_info, u64 group_start,
 			     struct extent_map *em);
 void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info);
 void btrfs_get_block_group_trimming(struct btrfs_block_group_cache *cache);
@@ -2894,11 +2894,11 @@ int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq);
 
 /* root-item.c */
 int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
-		       struct btrfs_root *tree_root,
+		       struct btrfs_fs_info *fs_info,
 		       u64 root_id, u64 ref_id, u64 dirid, u64 sequence,
 		       const char *name, int name_len);
 int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
-		       struct btrfs_root *tree_root,
+		       struct btrfs_fs_info *fs_info,
 		       u64 root_id, u64 ref_id, u64 dirid, u64 *sequence,
 		       const char *name, int name_len);
 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -2913,7 +2913,7 @@ int __must_check btrfs_update_root(struct btrfs_trans_handle *trans,
 int btrfs_find_root(struct btrfs_root *root, struct btrfs_key *search_key,
 		    struct btrfs_path *path, struct btrfs_root_item *root_item,
 		    struct btrfs_key *root_key);
-int btrfs_find_orphan_roots(struct btrfs_root *tree_root);
+int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info);
 void btrfs_set_root_node(struct btrfs_root_item *item,
 			 struct extent_buffer *node);
 void btrfs_check_and_init_root_item(struct btrfs_root_item *item);
@@ -2922,10 +2922,10 @@ void btrfs_update_root_times(struct btrfs_trans_handle *trans,
 
 /* uuid-tree.c */
 int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans,
-			struct btrfs_root *uuid_root, u8 *uuid, u8 type,
+			struct btrfs_fs_info *fs_info, u8 *uuid, u8 type,
 			u64 subid);
 int btrfs_uuid_tree_rem(struct btrfs_trans_handle *trans,
-			struct btrfs_root *uuid_root, u8 *uuid, u8 type,
+			struct btrfs_fs_info *fs_info, u8 *uuid, u8 type,
 			u64 subid);
 int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info,
 			    int (*check_func)(struct btrfs_fs_info *, u8 *, u8,
@@ -3542,7 +3542,7 @@ static inline int btrfs_init_acl(struct btrfs_trans_handle *trans,
 #endif
 
 /* relocation.c */
-int btrfs_relocate_block_group(struct btrfs_root *root, u64 group_start);
+int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start);
 int btrfs_init_reloc_root(struct btrfs_trans_handle *trans,
 			  struct btrfs_root *root);
 int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 42d4a31..5a71cb8 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2258,8 +2258,7 @@ static void btrfs_init_balance(struct btrfs_fs_info *fs_info)
 	init_waitqueue_head(&fs_info->balance_wait_q);
 }
 
-static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info,
-				   struct btrfs_root *tree_root)
+static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
 {
 	fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
 	set_nlink(fs_info->btree_inode, 1);
@@ -2279,7 +2278,7 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info,
 
 	BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
 
-	BTRFS_I(fs_info->btree_inode)->root = tree_root;
+	BTRFS_I(fs_info->btree_inode)->root = fs_info->tree_root;
 	memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
 	       sizeof(struct btrfs_key));
 	set_bit(BTRFS_INODE_DUMMY,
@@ -2448,7 +2447,7 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
 	}
 
 	if (fs_info->sb->s_flags & MS_RDONLY) {
-		ret = btrfs_commit_super(tree_root);
+		ret = btrfs_commit_super(fs_info);
 		if (ret)
 			return ret;
 	}
@@ -2456,13 +2455,15 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
 	return 0;
 }
 
-static int btrfs_read_roots(struct btrfs_fs_info *fs_info,
-			    struct btrfs_root *tree_root)
+static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
 {
+	struct btrfs_root *tree_root = fs_info->tree_root;
 	struct btrfs_root *root;
 	struct btrfs_key location;
 	int ret;
 
+	BUG_ON(!fs_info->tree_root);
+
 	location.objectid = BTRFS_EXTENT_TREE_OBJECTID;
 	location.type = BTRFS_ROOT_ITEM_KEY;
 	location.offset = 0;
@@ -2672,7 +2673,7 @@ int open_ctree(struct super_block *sb,
 	sb->s_blocksize_bits = blksize_bits(4096);
 	sb->s_bdi = &fs_info->bdi;
 
-	btrfs_init_btree_inode(fs_info, tree_root);
+	btrfs_init_btree_inode(fs_info);
 
 	spin_lock_init(&fs_info->block_group_cache_lock);
 	fs_info->block_group_cache_tree = RB_ROOT;
@@ -2871,7 +2872,7 @@ int open_ctree(struct super_block *sb,
 	sb->s_blocksize_bits = blksize_bits(sectorsize);
 
 	mutex_lock(&fs_info->chunk_mutex);
-	ret = btrfs_read_sys_array(tree_root);
+	ret = btrfs_read_sys_array(fs_info);
 	mutex_unlock(&fs_info->chunk_mutex);
 	if (ret) {
 		btrfs_err(fs_info, "failed to read the system array: %d", ret);
@@ -2948,7 +2949,7 @@ retry_root_backup:
 
 	mutex_unlock(&tree_root->objectid_mutex);
 
-	ret = btrfs_read_roots(fs_info, tree_root);
+	ret = btrfs_read_roots(fs_info);
 	if (ret)
 		goto recovery_tree_root;
 
@@ -3069,7 +3070,7 @@ retry_root_backup:
 		}
 	}
 
-	ret = btrfs_find_orphan_roots(tree_root);
+	ret = btrfs_find_orphan_roots(fs_info);
 	if (ret)
 		goto fail_qgroup;
 
@@ -3109,7 +3110,7 @@ retry_root_backup:
 		if (ret) {
 			btrfs_warn(fs_info,
 				"failed to create free space tree: %d", ret);
-			close_ctree(tree_root);
+			close_ctree(fs_info);
 			return ret;
 		}
 	}
@@ -3118,7 +3119,7 @@ retry_root_backup:
 	if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) ||
 	    (ret = btrfs_orphan_cleanup(fs_info->tree_root))) {
 		up_read(&fs_info->cleanup_work_sem);
-		close_ctree(tree_root);
+		close_ctree(fs_info);
 		return ret;
 	}
 	up_read(&fs_info->cleanup_work_sem);
@@ -3126,14 +3127,14 @@ retry_root_backup:
 	ret = btrfs_resume_balance_async(fs_info);
 	if (ret) {
 		btrfs_warn(fs_info, "failed to resume balance: %d", ret);
-		close_ctree(tree_root);
+		close_ctree(fs_info);
 		return ret;
 	}
 
 	ret = btrfs_resume_dev_replace_async(fs_info);
 	if (ret) {
 		btrfs_warn(fs_info, "failed to resume device replace: %d", ret);
-		close_ctree(tree_root);
+		close_ctree(fs_info);
 		return ret;
 	}
 
@@ -3146,7 +3147,7 @@ retry_root_backup:
 		if (ret) {
 			btrfs_warn(fs_info,
 				"failed to clear free space tree: %d", ret);
-			close_ctree(tree_root);
+			close_ctree(fs_info);
 			return ret;
 		}
 	}
@@ -3157,7 +3158,7 @@ retry_root_backup:
 		if (ret) {
 			btrfs_warn(fs_info,
 				"failed to create the UUID tree: %d", ret);
-			close_ctree(tree_root);
+			close_ctree(fs_info);
 			return ret;
 		}
 	} else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) ||
@@ -3168,7 +3169,7 @@ retry_root_backup:
 		if (ret) {
 			btrfs_warn(fs_info,
 				"failed to check the UUID tree: %d", ret);
-			close_ctree(tree_root);
+			close_ctree(fs_info);
 			return ret;
 		}
 	} else {
@@ -3834,8 +3835,9 @@ int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info)
 	return err;
 }
 
-int btrfs_commit_super(struct btrfs_root *root)
+int btrfs_commit_super(struct btrfs_fs_info *fs_info)
 {
+	struct btrfs_root *root = fs_info->tree_root;
 	struct btrfs_trans_handle *trans;
 
 	mutex_lock(&root->fs_info->cleaner_mutex);
@@ -3853,9 +3855,9 @@ int btrfs_commit_super(struct btrfs_root *root)
 	return btrfs_commit_transaction(trans, root);
 }
 
-void close_ctree(struct btrfs_root *root)
+void close_ctree(struct btrfs_fs_info *fs_info)
 {
-	struct btrfs_fs_info *fs_info = root->fs_info;
+	struct btrfs_root *root = fs_info->tree_root;
 	int ret;
 
 	fs_info->closing = 1;
@@ -3893,7 +3895,7 @@ void close_ctree(struct btrfs_root *root)
 		 */
 		btrfs_delete_unused_bgs(root->fs_info);
 
-		ret = btrfs_commit_super(root);
+		ret = btrfs_commit_super(fs_info);
 		if (ret)
 			btrfs_err(fs_info, "commit super ret %d", ret);
 	}
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index c9d42c9..25cb43c 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -56,13 +56,13 @@ void clean_tree_block(struct btrfs_trans_handle *trans,
 int open_ctree(struct super_block *sb,
 	       struct btrfs_fs_devices *fs_devices,
 	       char *options);
-void close_ctree(struct btrfs_root *root);
+void close_ctree(struct btrfs_fs_info *fs_info);
 int write_ctree_super(struct btrfs_trans_handle *trans,
 		      struct btrfs_root *root, int max_mirrors);
 struct buffer_head *btrfs_read_dev_super(struct block_device *bdev);
 int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
 			struct buffer_head **bh_ret);
-int btrfs_commit_super(struct btrfs_root *root);
+int btrfs_commit_super(struct btrfs_fs_info *fs_info);
 struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
 					    u64 bytenr);
 struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root,
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 0b493c4..e6ad776 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -9495,8 +9495,9 @@ void btrfs_dec_block_group_ro(struct btrfs_root *root,
  * @return - -1 if it's not a good idea to relocate this block group, 0 if its
  * ok to go ahead and try.
  */
-int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
+int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr)
 {
+	struct btrfs_root *root = fs_info->extent_root;
 	struct btrfs_block_group_cache *block_group;
 	struct btrfs_space_info *space_info;
 	struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
@@ -9640,9 +9641,11 @@ out:
 	return ret;
 }
 
-static int find_first_block_group(struct btrfs_root *root,
-		struct btrfs_path *path, struct btrfs_key *key)
+static int find_first_block_group(struct btrfs_fs_info *fs_info,
+				  struct btrfs_path *path,
+				  struct btrfs_key *key)
 {
+	struct btrfs_root *root = fs_info->extent_root;
 	int ret = 0;
 	struct btrfs_key found_key;
 	struct extent_buffer *leaf;
@@ -9913,7 +9916,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
 		need_clear = 1;
 
 	while (1) {
-		ret = find_first_block_group(root, path, &key);
+		ret = find_first_block_group(info, path, &key);
 		if (ret > 0)
 			break;
 		if (ret != 0)
@@ -10085,7 +10088,7 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans,
 					sizeof(item));
 		if (ret)
 			btrfs_abort_transaction(trans, ret);
-		ret = btrfs_finish_chunk_alloc(trans, extent_root,
+		ret = btrfs_finish_chunk_alloc(trans, extent_root->fs_info,
 					       key.objectid, key.offset);
 		if (ret)
 			btrfs_abort_transaction(trans, ret);
@@ -10213,9 +10216,10 @@ static void clear_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
 }
 
 int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
-			     struct btrfs_root *root, u64 group_start,
+			     struct btrfs_fs_info *fs_info, u64 group_start,
 			     struct extent_map *em)
 {
+	struct btrfs_root *root = fs_info->extent_root;
 	struct btrfs_path *path;
 	struct btrfs_block_group_cache *block_group;
 	struct btrfs_free_cluster *cluster;
@@ -10229,9 +10233,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
 	struct btrfs_caching_control *caching_ctl = NULL;
 	bool remove_em;
 
-	root = root->fs_info->extent_root;
-
-	block_group = btrfs_lookup_block_group(root->fs_info, group_start);
+	block_group = btrfs_lookup_block_group(fs_info, group_start);
 	BUG_ON(!block_group);
 	BUG_ON(!block_group->ro);
 
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 322ee50..4a9ebb7 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4148,7 +4148,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
 	}
 	btrfs_release_path(path);
 
-	ret = btrfs_del_root_ref(trans, root->fs_info->tree_root,
+	ret = btrfs_del_root_ref(trans, root->fs_info,
 				 objectid, root->root_key.objectid,
 				 dir_ino, &index, name, name_len);
 	if (ret < 0) {
@@ -6296,7 +6296,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
 	}
 
 	if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) {
-		ret = btrfs_add_root_ref(trans, root->fs_info->tree_root,
+		ret = btrfs_add_root_ref(trans, root->fs_info,
 					 key.objectid, root->root_key.objectid,
 					 parent_ino, index, name, name_len);
 	} else if (add_backref) {
@@ -6332,7 +6332,7 @@ fail_dir_item:
 	if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) {
 		u64 local_index;
 		int err;
-		err = btrfs_del_root_ref(trans, root->fs_info->tree_root,
+		err = btrfs_del_root_ref(trans, root->fs_info,
 				 key.objectid, root->root_key.objectid,
 				 parent_ino, &local_index, name, name_len);
 
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 14ed1e9..2ce7c18 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -599,14 +599,13 @@ static noinline int create_subvol(struct inode *dir,
 	ret = btrfs_update_inode(trans, root, dir);
 	BUG_ON(ret);
 
-	ret = btrfs_add_root_ref(trans, root->fs_info->tree_root,
+	ret = btrfs_add_root_ref(trans, root->fs_info,
 				 objectid, root->root_key.objectid,
 				 btrfs_ino(dir), index, name, namelen);
 	BUG_ON(ret);
 
-	ret = btrfs_uuid_tree_add(trans, root->fs_info->uuid_root,
-				  root_item->uuid, BTRFS_UUID_KEY_SUBVOL,
-				  objectid);
+	ret = btrfs_uuid_tree_add(trans, root->fs_info, root_item->uuid,
+				  BTRFS_UUID_KEY_SUBVOL, objectid);
 	if (ret)
 		btrfs_abort_transaction(trans, ret);
 
@@ -2510,8 +2509,8 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 		}
 	}
 
-	ret = btrfs_uuid_tree_rem(trans, root->fs_info->uuid_root,
-				  dest->root_item.uuid, BTRFS_UUID_KEY_SUBVOL,
+	ret = btrfs_uuid_tree_rem(trans, root->fs_info, dest->root_item.uuid,
+				  BTRFS_UUID_KEY_SUBVOL,
 				  dest->root_key.objectid);
 	if (ret && ret != -ENOENT) {
 		btrfs_abort_transaction(trans, ret);
@@ -2519,7 +2518,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 		goto out_end_trans;
 	}
 	if (!btrfs_is_empty_uuid(dest->root_item.received_uuid)) {
-		ret = btrfs_uuid_tree_rem(trans, root->fs_info->uuid_root,
+		ret = btrfs_uuid_tree_rem(trans, root->fs_info,
 					  dest->root_item.received_uuid,
 					  BTRFS_UUID_KEY_RECEIVED_SUBVOL,
 					  dest->root_key.objectid);
@@ -5136,7 +5135,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,
 				       BTRFS_UUID_SIZE);
 	if (received_uuid_changed &&
 	    !btrfs_is_empty_uuid(root_item->received_uuid))
-		btrfs_uuid_tree_rem(trans, root->fs_info->uuid_root,
+		btrfs_uuid_tree_rem(trans, root->fs_info,
 				    root_item->received_uuid,
 				    BTRFS_UUID_KEY_RECEIVED_SUBVOL,
 				    root->root_key.objectid);
@@ -5155,8 +5154,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,
 		goto out;
 	}
 	if (received_uuid_changed && !btrfs_is_empty_uuid(sa->uuid)) {
-		ret = btrfs_uuid_tree_add(trans, root->fs_info->uuid_root,
-					  sa->uuid,
+		ret = btrfs_uuid_tree_add(trans, root->fs_info, sa->uuid,
 					  BTRFS_UUID_KEY_RECEIVED_SUBVOL,
 					  root->root_key.objectid);
 		if (ret < 0 && ret != -EEXIST) {
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 9d07953..8ee2c2f 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -4197,9 +4197,9 @@ static struct reloc_control *alloc_reloc_control(struct btrfs_fs_info *fs_info)
 /*
  * function to relocate all extents in a block group.
  */
-int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start)
+int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start)
 {
-	struct btrfs_fs_info *fs_info = extent_root->fs_info;
+	struct btrfs_root *extent_root = fs_info->extent_root;
 	struct reloc_control *rc;
 	struct inode *inode;
 	struct btrfs_path *path;
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 7fd7e18..a2a99da 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -220,8 +220,9 @@ int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 	return btrfs_insert_item(trans, root, key, item, sizeof(*item));
 }
 
-int btrfs_find_orphan_roots(struct btrfs_root *tree_root)
+int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
 {
+	struct btrfs_root *tree_root = fs_info->tree_root;
 	struct extent_buffer *leaf;
 	struct btrfs_path *path;
 	struct btrfs_key key;
@@ -355,11 +356,12 @@ out:
 }
 
 int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
-		       struct btrfs_root *tree_root,
+		       struct btrfs_fs_info *fs_info,
 		       u64 root_id, u64 ref_id, u64 dirid, u64 *sequence,
 		       const char *name, int name_len)
 
 {
+	struct btrfs_root *tree_root = fs_info->tree_root;
 	struct btrfs_path *path;
 	struct btrfs_root_ref *ref;
 	struct extent_buffer *leaf;
@@ -426,10 +428,11 @@ out:
  * Will return 0, -ENOMEM, or anything from the CoW path
  */
 int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
-		       struct btrfs_root *tree_root,
+		       struct btrfs_fs_info *fs_info,
 		       u64 root_id, u64 ref_id, u64 dirid, u64 sequence,
 		       const char *name, int name_len)
 {
+	struct btrfs_root *tree_root = fs_info->tree_root;
 	struct btrfs_key key;
 	int ret;
 	struct btrfs_path *path;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 4c031d7..1cdb9a2 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -284,7 +284,7 @@ void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
 
 static void btrfs_put_super(struct super_block *sb)
 {
-	close_ctree(btrfs_sb(sb)->tree_root);
+	close_ctree(btrfs_sb(sb));
 }
 
 enum {
@@ -1145,7 +1145,7 @@ static int btrfs_fill_super(struct super_block *sb,
 	return 0;
 
 fail_close:
-	close_ctree(fs_info->tree_root);
+	close_ctree(fs_info);
 	return err;
 }
 
@@ -1754,7 +1754,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
 		btrfs_scrub_cancel(fs_info);
 		btrfs_pause_balance(fs_info);
 
-		ret = btrfs_commit_super(root);
+		ret = btrfs_commit_super(fs_info);
 		if (ret)
 			goto restore;
 	} else {
@@ -1869,9 +1869,10 @@ static inline void btrfs_descending_sort_devices(
  * The helper to calc the free space on the devices that can be used to store
  * file data.
  */
-static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
+static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
+				       u64 *free_bytes)
 {
-	struct btrfs_fs_info *fs_info = root->fs_info;
+	struct btrfs_root *root = fs_info->tree_root;
 	struct btrfs_device_info *devices_info;
 	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
 	struct btrfs_device *device;
@@ -2112,7 +2113,7 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	spin_unlock(&block_rsv->lock);
 
 	buf->f_bavail = div_u64(total_free_data, factor);
-	ret = btrfs_calc_avail_data_space(fs_info->tree_root, &total_free_data);
+	ret = btrfs_calc_avail_data_space(fs_info, &total_free_data);
 	if (ret)
 		return ret;
 	buf->f_bavail += div_u64(total_free_data, factor);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index b540de1..4b18a20 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1574,7 +1574,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	/*
 	 * insert root back/forward references
 	 */
-	ret = btrfs_add_root_ref(trans, tree_root, objectid,
+	ret = btrfs_add_root_ref(trans, fs_info, objectid,
 				 parent_root->root_key.objectid,
 				 btrfs_ino(parent_inode), index,
 				 dentry->d_name.name, dentry->d_name.len);
@@ -1634,14 +1634,14 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
-	ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, new_uuid.b,
+	ret = btrfs_uuid_tree_add(trans, fs_info, new_uuid.b,
 				  BTRFS_UUID_KEY_SUBVOL, objectid);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
 	if (!btrfs_is_empty_uuid(new_root_item->received_uuid)) {
-		ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root,
+		ret = btrfs_uuid_tree_add(trans, fs_info,
 					  new_root_item->received_uuid,
 					  BTRFS_UUID_KEY_RECEIVED_SUBVOL,
 					  objectid);
diff --git a/fs/btrfs/uuid-tree.c b/fs/btrfs/uuid-tree.c
index 7782829..27cfd7c 100644
--- a/fs/btrfs/uuid-tree.c
+++ b/fs/btrfs/uuid-tree.c
@@ -91,9 +91,10 @@ out:
 }
 
 int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans,
-			struct btrfs_root *uuid_root, u8 *uuid, u8 type,
+			struct btrfs_fs_info *fs_info, u8 *uuid, u8 type,
 			u64 subid_cpu)
 {
+	struct btrfs_root *uuid_root = fs_info->uuid_root;
 	int ret;
 	struct btrfs_path *path = NULL;
 	struct btrfs_key key;
@@ -137,7 +138,7 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans,
 		offset = btrfs_item_ptr_offset(eb, slot);
 		offset += btrfs_item_size_nr(eb, slot) - sizeof(subid_le);
 	} else if (ret < 0) {
-		btrfs_warn(uuid_root->fs_info, "insert uuid item failed %d "
+		btrfs_warn(fs_info, "insert uuid item failed %d "
 			"(0x%016llx, 0x%016llx) type %u!",
 			ret, (unsigned long long)key.objectid,
 			(unsigned long long)key.offset, type);
@@ -155,9 +156,10 @@ out:
 }
 
 int btrfs_uuid_tree_rem(struct btrfs_trans_handle *trans,
-			struct btrfs_root *uuid_root, u8 *uuid, u8 type,
+			struct btrfs_fs_info *fs_info, u8 *uuid, u8 type,
 			u64 subid)
 {
+	struct btrfs_root *uuid_root = fs_info->uuid_root;
 	int ret;
 	struct btrfs_path *path = NULL;
 	struct btrfs_key key;
@@ -248,7 +250,7 @@ static int btrfs_uuid_iter_rem(struct btrfs_root *uuid_root, u8 *uuid, u8 type,
 		goto out;
 	}
 
-	ret = btrfs_uuid_tree_rem(trans, uuid_root, uuid, type, subid);
+	ret = btrfs_uuid_tree_rem(trans, uuid_root->fs_info, uuid, type, subid);
 	btrfs_end_transaction(trans, uuid_root);
 
 out:
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index befe4a7..ae18210 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2701,9 +2701,10 @@ out:
 	return ret;
 }
 
-static int btrfs_del_sys_chunk(struct btrfs_root *root, u64 chunk_objectid, u64
-			chunk_offset)
+static int btrfs_del_sys_chunk(struct btrfs_fs_info *fs_info,
+			       u64 chunk_objectid, u64 chunk_offset)
 {
+	struct btrfs_root *root = fs_info->chunk_root;
 	struct btrfs_super_block *super_copy = root->fs_info->super_copy;
 	struct btrfs_disk_key *disk_key;
 	struct btrfs_chunk *chunk;
@@ -2832,17 +2833,18 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 		goto out;
 	}
 
-	trace_btrfs_chunk_free(root, map, chunk_offset, em->len);
+	trace_btrfs_chunk_free(fs_info, map, chunk_offset, em->len);
 
 	if (map->type & BTRFS_BLOCK_GROUP_SYSTEM) {
-		ret = btrfs_del_sys_chunk(root, chunk_objectid, chunk_offset);
+		ret = btrfs_del_sys_chunk(fs_info, chunk_objectid,
+					  chunk_offset);
 		if (ret) {
 			btrfs_abort_transaction(trans, ret);
 			goto out;
 		}
 	}
 
-	ret = btrfs_remove_block_group(trans, extent_root, chunk_offset, em);
+	ret = btrfs_remove_block_group(trans, fs_info, chunk_offset, em);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
 		goto out;
@@ -2875,13 +2877,13 @@ static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
 	 */
 	ASSERT(mutex_is_locked(&root->fs_info->delete_unused_bgs_mutex));
 
-	ret = btrfs_can_relocate(extent_root, chunk_offset);
+	ret = btrfs_can_relocate(root->fs_info, chunk_offset);
 	if (ret)
 		return -ENOSPC;
 
 	/* step one, relocate all the extents inside this chunk */
 	btrfs_scrub_pause(root);
-	ret = btrfs_relocate_block_group(extent_root, chunk_offset);
+	ret = btrfs_relocate_block_group(root->fs_info, chunk_offset);
 	btrfs_scrub_continue(root);
 	if (ret)
 		return ret;
@@ -2978,9 +2980,10 @@ error:
 	return ret;
 }
 
-static int insert_balance_item(struct btrfs_root *root,
+static int insert_balance_item(struct btrfs_fs_info *fs_info,
 			       struct btrfs_balance_control *bctl)
 {
+	struct btrfs_root *root = fs_info->tree_root;
 	struct btrfs_trans_handle *trans;
 	struct btrfs_balance_item *item;
 	struct btrfs_disk_balance_args disk_bargs;
@@ -3031,8 +3034,9 @@ out:
 	return ret;
 }
 
-static int del_balance_item(struct btrfs_root *root)
+static int del_balance_item(struct btrfs_fs_info *fs_info)
 {
+	struct btrfs_root *root = fs_info->tree_root;
 	struct btrfs_trans_handle *trans;
 	struct btrfs_path *path;
 	struct btrfs_key key;
@@ -3669,7 +3673,7 @@ static void __cancel_balance(struct btrfs_fs_info *fs_info)
 	int ret;
 
 	unset_balance_control(fs_info);
-	ret = del_balance_item(fs_info->tree_root);
+	ret = del_balance_item(fs_info);
 	if (ret)
 		btrfs_handle_fs_error(fs_info, ret, NULL);
 
@@ -3801,7 +3805,7 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
 				bctl->sys.target));
 	}
 
-	ret = insert_balance_item(fs_info->tree_root, bctl);
+	ret = insert_balance_item(fs_info, bctl);
 	if (ret && ret != -EEXIST)
 		goto out;
 
@@ -4093,7 +4097,7 @@ static int btrfs_uuid_scan_kthread(void *data)
 		}
 update_tree:
 		if (!btrfs_is_empty_uuid(root_item.uuid)) {
-			ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root,
+			ret = btrfs_uuid_tree_add(trans, fs_info,
 						  root_item.uuid,
 						  BTRFS_UUID_KEY_SUBVOL,
 						  key.objectid);
@@ -4105,7 +4109,7 @@ update_tree:
 		}
 
 		if (!btrfs_is_empty_uuid(root_item.received_uuid)) {
-			ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root,
+			ret = btrfs_uuid_tree_add(trans, fs_info,
 						  root_item.received_uuid,
 						 BTRFS_UUID_KEY_RECEIVED_SUBVOL,
 						  key.objectid);
@@ -4748,7 +4752,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 
 	num_bytes = stripe_size * data_stripes;
 
-	trace_btrfs_chunk_alloc(info->chunk_root, map, start, num_bytes);
+	trace_btrfs_chunk_alloc(info, map, start, num_bytes);
 
 	em = alloc_extent_map();
 	if (!em) {
@@ -4816,11 +4820,12 @@ error:
 }
 
 int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
-				struct btrfs_root *extent_root,
+				struct btrfs_fs_info *fs_info,
 				u64 chunk_offset, u64 chunk_size)
 {
+	struct btrfs_root *extent_root = fs_info->extent_root;
+	struct btrfs_root *chunk_root = fs_info->chunk_root;
 	struct btrfs_key key;
-	struct btrfs_root *chunk_root = extent_root->fs_info->chunk_root;
 	struct btrfs_device *device;
 	struct btrfs_chunk *chunk;
 	struct btrfs_stripe *stripe;
@@ -6580,8 +6585,9 @@ static int read_one_dev(struct btrfs_root *root,
 	return ret;
 }
 
-int btrfs_read_sys_array(struct btrfs_root *root)
+int btrfs_read_sys_array(struct btrfs_fs_info *fs_info)
 {
+	struct btrfs_root *root = fs_info->tree_root;
 	struct btrfs_super_block *super_copy = root->fs_info->super_copy;
 	struct extent_buffer *sb;
 	struct btrfs_disk_key *disk_key;
@@ -6874,9 +6880,10 @@ out:
 }
 
 static int update_dev_stat_item(struct btrfs_trans_handle *trans,
-				struct btrfs_root *dev_root,
+				struct btrfs_fs_info *fs_info,
 				struct btrfs_device *device)
 {
+	struct btrfs_root *dev_root = fs_info->dev_root;
 	struct btrfs_path *path;
 	struct btrfs_key key;
 	struct extent_buffer *eb;
@@ -6942,7 +6949,6 @@ out:
 int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
 			struct btrfs_fs_info *fs_info)
 {
-	struct btrfs_root *dev_root = fs_info->dev_root;
 	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
 	struct btrfs_device *device;
 	int stats_cnt;
@@ -6954,7 +6960,7 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
 			continue;
 
 		stats_cnt = atomic_read(&device->dev_stats_ccnt);
-		ret = update_dev_stat_item(trans, dev_root, device);
+		ret = update_dev_stat_item(trans, fs_info, device);
 		if (!ret)
 			atomic_sub(stats_cnt, &device->dev_stats_ccnt);
 	}
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index b0605cb..c5d310d 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -385,7 +385,7 @@ int btrfs_map_sblock(struct btrfs_fs_info *fs_info, int rw,
 int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
 		     u64 chunk_start, u64 physical, u64 devid,
 		     u64 **logical, int *naddrs, int *stripe_len);
-int btrfs_read_sys_array(struct btrfs_root *root);
+int btrfs_read_sys_array(struct btrfs_fs_info *fs_info);
 int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
 int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 		      struct btrfs_root *extent_root, u64 type);
@@ -459,7 +459,7 @@ unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
 				    struct btrfs_mapping_tree *map_tree,
 				    u64 logical);
 int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
-				struct btrfs_root *extent_root,
+				struct btrfs_fs_info *fs_info,
 				u64 chunk_offset, u64 chunk_size);
 int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 		       struct btrfs_fs_info *fs_info, u64 chunk_offset);
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index eba0c65..72ca3a8 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -658,10 +658,10 @@ DEFINE_EVENT(btrfs_delayed_ref_head,  run_delayed_ref_head,
 
 DECLARE_EVENT_CLASS(btrfs__chunk,
 
-	TP_PROTO(struct btrfs_root *root, struct map_lookup *map,
+	TP_PROTO(struct btrfs_fs_info *fs_info, struct map_lookup *map,
 		 u64 offset, u64 size),
 
-	TP_ARGS(root, map, offset, size),
+	TP_ARGS(fs_info, map, offset, size),
 
 	TP_STRUCT__entry_btrfs(
 		__field(	int,  num_stripes		)
@@ -672,13 +672,13 @@ DECLARE_EVENT_CLASS(btrfs__chunk,
 		__field(	u64,  root_objectid		)
 	),
 
-	TP_fast_assign_btrfs(root->fs_info,
+	TP_fast_assign_btrfs(fs_info,
 		__entry->num_stripes	= map->num_stripes;
 		__entry->type		= map->type;
 		__entry->sub_stripes	= map->sub_stripes;
 		__entry->offset		= offset;
 		__entry->size		= size;
-		__entry->root_objectid	= root->root_key.objectid;
+		__entry->root_objectid	= fs_info->chunk_root->root_key.objectid;
 	),
 
 	TP_printk_btrfs("root = %llu(%s), offset = %llu, size = %llu, "
@@ -692,18 +692,18 @@ DECLARE_EVENT_CLASS(btrfs__chunk,
 
 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_alloc,
 
-	TP_PROTO(struct btrfs_root *root, struct map_lookup *map,
+	TP_PROTO(struct btrfs_fs_info *fs_info, struct map_lookup *map,
 		 u64 offset, u64 size),
 
-	TP_ARGS(root, map, offset, size)
+	TP_ARGS(fs_info, map, offset, size)
 );
 
 DEFINE_EVENT(btrfs__chunk,  btrfs_chunk_free,
 
-	TP_PROTO(struct btrfs_root *root, struct map_lookup *map,
+	TP_PROTO(struct btrfs_fs_info *fs_info, struct map_lookup *map,
 		 u64 offset, u64 size),
 
-	TP_ARGS(root, map, offset, size)
+	TP_ARGS(fs_info, map, offset, size)
 );
 
 TRACE_EVENT(btrfs_cow_block,
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 17/31] btrfs: btrfs_init_new_device should use fs_info->dev_root
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (15 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 16/31] btrfs: call functions that always use the same root with fs_info instead jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 18/31] btrfs: alloc_reserved_file_extent trace point should use extent_root jeffm
                   ` (14 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

btrfs_init_new_device only uses the root passed in via the ioctl to
start the transaction.  Nothing else that happens is related to whatever
root the user used to initiate the ioctl.  We can drop the root requirement
and just use fs_info->dev_root instead.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ioctl.c   | 2 +-
 fs/btrfs/volumes.c | 3 ++-
 fs/btrfs/volumes.h | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 2ce7c18..2fce760 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2662,7 +2662,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
 	}
 
 	vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
-	ret = btrfs_init_new_device(root, vol_args->name);
+	ret = btrfs_init_new_device(root->fs_info, vol_args->name);
 
 	if (!ret)
 		btrfs_info(root->fs_info, "disk added %s",vol_args->name);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index ae18210..9a155d2 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2262,8 +2262,9 @@ error:
 	return ret;
 }
 
-int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
+int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
 {
+	struct btrfs_root *root = fs_info->dev_root;
 	struct request_queue *q;
 	struct btrfs_trans_handle *trans;
 	struct btrfs_device *device;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index c5d310d..6c765c0 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -418,7 +418,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
 struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
 				       u8 *uuid, u8 *fsid);
 int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
-int btrfs_init_new_device(struct btrfs_root *root, char *path);
+int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *path);
 int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path,
 				  struct btrfs_device *srcdev,
 				  struct btrfs_device **device_out);
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 18/31] btrfs: alloc_reserved_file_extent trace point should use extent_root
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (16 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 17/31] btrfs: btrfs_init_new_device should use fs_info->dev_root jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 19/31] btrfs: struct btrfsic_state->root should be an fs_info jeffm
                   ` (13 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

Even though a separate root is passed in, we're still operating on the
extent root.  Let's use that for the trace point.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/extent-tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index e6ad776..49775d4 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -7866,7 +7866,8 @@ static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
 			ins->objectid, ins->offset);
 		BUG();
 	}
-	trace_btrfs_reserved_extent_alloc(root, ins->objectid, ins->offset);
+	trace_btrfs_reserved_extent_alloc(fs_info->extent_root,
+					  ins->objectid, ins->offset);
 	return ret;
 }
 
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 19/31] btrfs: struct btrfsic_state->root should be an fs_info
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (17 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 18/31] btrfs: alloc_reserved_file_extent trace point should use extent_root jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 20/31] btrfs: struct reada_control.root -> reada_control.fs_info jeffm
                   ` (12 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

The root member is never used except for obtaining an fs_info pointer.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/check-integrity.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 7706c8d..656e6fa 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -254,7 +254,7 @@ struct btrfsic_state {
 	struct list_head all_blocks_list;
 	struct btrfsic_block_hashtable block_hashtable;
 	struct btrfsic_block_link_hashtable block_link_hashtable;
-	struct btrfs_root *root;
+	struct btrfs_fs_info *fs_info;
 	u64 max_superblock_generation;
 	struct btrfsic_block *latest_superblock;
 	u32 metablock_size;
@@ -717,7 +717,7 @@ static int btrfsic_process_superblock(struct btrfsic_state *state,
 		}
 
 		num_copies =
-		    btrfs_num_copies(state->root->fs_info,
+		    btrfs_num_copies(state->fs_info,
 				     next_bytenr, state->metablock_size);
 		if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
 			printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
@@ -891,7 +891,7 @@ static int btrfsic_process_superblock_dev_mirror(
 		}
 
 		num_copies =
-		    btrfs_num_copies(state->root->fs_info,
+		    btrfs_num_copies(state->fs_info,
 				     next_bytenr, state->metablock_size);
 		if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
 			printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
@@ -1272,7 +1272,7 @@ static int btrfsic_create_link_to_next_block(
 	*next_blockp = NULL;
 	if (0 == *num_copiesp) {
 		*num_copiesp =
-		    btrfs_num_copies(state->root->fs_info,
+		    btrfs_num_copies(state->fs_info,
 				     next_bytenr, state->metablock_size);
 		if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
 			printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
@@ -1474,7 +1474,7 @@ static int btrfsic_handle_extent_data(
 			chunk_len = num_bytes;
 
 		num_copies =
-		    btrfs_num_copies(state->root->fs_info,
+		    btrfs_num_copies(state->fs_info,
 				     next_bytenr, state->datablock_size);
 		if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
 			printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
@@ -1565,7 +1565,7 @@ static int btrfsic_map_block(struct btrfsic_state *state, u64 bytenr, u32 len,
 	struct btrfs_device *device;
 
 	length = len;
-	ret = btrfs_map_block(state->root->fs_info, READ,
+	ret = btrfs_map_block(state->fs_info, READ,
 			      bytenr, &length, &multi, mirror_num);
 
 	if (ret) {
@@ -1774,7 +1774,7 @@ static int btrfsic_test_for_metadata(struct btrfsic_state *state,
 	num_pages = state->metablock_size >> PAGE_SHIFT;
 	h = (struct btrfs_header *)datav[0];
 
-	if (memcmp(h->fsid, state->root->fs_info->fsid, BTRFS_UUID_SIZE))
+	if (memcmp(h->fsid, state->fs_info->fsid, BTRFS_UUID_SIZE))
 		return 1;
 
 	for (i = 0; i < num_pages; i++) {
@@ -2342,7 +2342,7 @@ static int btrfsic_process_written_superblock(
 		}
 
 		num_copies =
-		    btrfs_num_copies(state->root->fs_info,
+		    btrfs_num_copies(state->fs_info,
 				     next_bytenr, BTRFS_SUPER_INFO_SIZE);
 		if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
 			printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
@@ -2802,7 +2802,7 @@ static void btrfsic_cmp_log_and_dev_bytenr(struct btrfsic_state *state,
 	struct btrfsic_block_data_ctx block_ctx;
 	int match = 0;
 
-	num_copies = btrfs_num_copies(state->root->fs_info,
+	num_copies = btrfs_num_copies(state->fs_info,
 				      bytenr, state->metablock_size);
 
 	for (mirror_num = 1; mirror_num <= num_copies; mirror_num++) {
@@ -3064,7 +3064,7 @@ int btrfsic_mount(struct btrfs_root *root,
 		btrfsic_is_initialized = 1;
 	}
 	mutex_lock(&btrfsic_mutex);
-	state->root = root;
+	state->fs_info = root->fs_info;
 	state->print_mask = print_mask;
 	state->include_extent_data = including_extent_data;
 	state->csum_size = 0;
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 20/31] btrfs: struct reada_control.root -> reada_control.fs_info
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (18 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 19/31] btrfs: struct btrfsic_state->root should be an fs_info jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 21/31] btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere jeffm
                   ` (11 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

The root is never used.  We substitute extent_root in for the reada_find_extent
call, since it's only ever used to obtain the node size.  This call site
will be changed to use fs_info in a later patch.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h |  2 +-
 fs/btrfs/reada.c | 13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 7063c55..784f003 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3581,7 +3581,7 @@ static inline void btrfs_bio_counter_dec(struct btrfs_fs_info *fs_info)
 
 /* reada.c */
 struct reada_control {
-	struct btrfs_root	*root;		/* tree to prefetch */
+	struct btrfs_fs_info	*fs_info;		/* tree to prefetch */
 	struct btrfs_key	key_start;
 	struct btrfs_key	key_end;	/* exclusive */
 	atomic_t		elems;
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index 8428db7..4965d59 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -554,17 +554,18 @@ static void reada_control_release(struct kref *kref)
 static int reada_add_block(struct reada_control *rc, u64 logical,
 			   struct btrfs_key *top, u64 generation)
 {
-	struct btrfs_root *root = rc->root;
+	struct btrfs_fs_info *fs_info = rc->fs_info;
 	struct reada_extent *re;
 	struct reada_extctl *rec;
 
-	re = reada_find_extent(root, logical, top); /* takes one ref */
+	/* takes one ref */
+	re = reada_find_extent(fs_info->tree_root, logical, top);
 	if (!re)
 		return -1;
 
 	rec = kzalloc(sizeof(*rec), GFP_KERNEL);
 	if (!rec) {
-		reada_extent_put(root->fs_info, re);
+		reada_extent_put(fs_info, re);
 		return -ENOMEM;
 	}
 
@@ -926,7 +927,7 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root,
 	if (!rc)
 		return ERR_PTR(-ENOMEM);
 
-	rc->root = root;
+	rc->fs_info = root->fs_info;
 	rc->key_start = *key_start;
 	rc->key_end = *key_end;
 	atomic_set(&rc->elems, 0);
@@ -954,7 +955,7 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root,
 int btrfs_reada_wait(void *handle)
 {
 	struct reada_control *rc = handle;
-	struct btrfs_fs_info *fs_info = rc->root->fs_info;
+	struct btrfs_fs_info *fs_info = rc->fs_info;
 
 	while (atomic_read(&rc->elems)) {
 		if (!atomic_read(&fs_info->reada_works_cnt))
@@ -975,7 +976,7 @@ int btrfs_reada_wait(void *handle)
 int btrfs_reada_wait(void *handle)
 {
 	struct reada_control *rc = handle;
-	struct btrfs_fs_info *fs_info = rc->root->fs_info;
+	struct btrfs_fs_info *fs_info = rc->fs_info;
 
 	while (atomic_read(&rc->elems)) {
 		if (!atomic_read(&fs_info->reada_works_cnt))
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 21/31] btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (19 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 20/31] btrfs: struct reada_control.root -> reada_control.fs_info jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 22/31] btrfs: root->fs_info cleanup, io_ctl_init jeffm
                   ` (10 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/check-integrity.c |  2 +-
 fs/btrfs/disk-io.c         |  4 +--
 fs/btrfs/extent-tree.c     |  2 +-
 fs/btrfs/scrub.c           | 87 +++++++++++++++++++++++-----------------------
 fs/btrfs/volumes.c         | 41 +++++++++++-----------
 fs/btrfs/volumes.h         |  3 +-
 6 files changed, 68 insertions(+), 71 deletions(-)

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 656e6fa..1c8be44 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -835,7 +835,7 @@ static int btrfsic_process_superblock_dev_mirror(
 		superblock_tmp->never_written = 0;
 		superblock_tmp->mirror_num = 1 + superblock_mirror_num;
 		if (state->print_mask & BTRFSIC_PRINT_MASK_SUPERBLOCK_WRITE)
-			btrfs_info_in_rcu(device->dev_root->fs_info,
+			btrfs_info_in_rcu(device->fs_info,
 				"new initial S-block (bdev %p, %s) @%llu (%s/%llu/%d)",
 				     superblock_bdev,
 				     rcu_str_deref(device->name), dev_bytenr,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 5a71cb8..3503455 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3264,7 +3264,7 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate)
 		struct btrfs_device *device = (struct btrfs_device *)
 			bh->b_private;
 
-		btrfs_warn_rl_in_rcu(device->dev_root->fs_info,
+		btrfs_warn_rl_in_rcu(device->fs_info,
 				"lost page write due to IO error on %s",
 					  rcu_str_deref(device->name));
 		/* note, we don't set_buffer_write_io_error because we have
@@ -3409,7 +3409,7 @@ static int write_dev_supers(struct btrfs_device *device,
 			bh = __getblk(device->bdev, bytenr / 4096,
 				      BTRFS_SUPER_INFO_SIZE);
 			if (!bh) {
-				btrfs_err(device->dev_root->fs_info,
+				btrfs_err(device->fs_info,
 				    "couldn't get super buffer head for bytenr %llu",
 				    bytenr);
 				errors++;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 49775d4..17afd22 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -10803,7 +10803,7 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
 	ret = 0;
 
 	while (1) {
-		struct btrfs_fs_info *fs_info = device->dev_root->fs_info;
+		struct btrfs_fs_info *fs_info = device->fs_info;
 		struct btrfs_transaction *trans;
 		u64 bytes;
 
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 86270c6..a30c850 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -171,7 +171,7 @@ struct scrub_wr_ctx {
 
 struct scrub_ctx {
 	struct scrub_bio	*bios[SCRUB_BIOS_PER_SCTX];
-	struct btrfs_root	*dev_root;
+	struct btrfs_fs_info	*fs_info;
 	int			first_free;
 	int			curr;
 	atomic_t		bios_in_flight;
@@ -356,7 +356,7 @@ static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info)
  */
 static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx)
 {
-	struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sctx->fs_info;
 
 	atomic_inc(&sctx->refs);
 	/*
@@ -388,7 +388,7 @@ static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx)
 /* used for workers that require transaction commits */
 static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx)
 {
-	struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sctx->fs_info;
 
 	/*
 	 * see scrub_pending_trans_workers_inc() why we're pretending
@@ -458,7 +458,7 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
 {
 	struct scrub_ctx *sctx;
 	int		i;
-	struct btrfs_fs_info *fs_info = dev->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = dev->fs_info;
 	int ret;
 
 	sctx = kzalloc(sizeof(*sctx), GFP_KERNEL);
@@ -468,7 +468,7 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
 	sctx->is_dev_replace = is_dev_replace;
 	sctx->pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO;
 	sctx->curr = -1;
-	sctx->dev_root = dev->dev_root;
+	sctx->fs_info = dev->fs_info;
 	for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
 		struct scrub_bio *sbio;
 
@@ -489,8 +489,8 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
 			sctx->bios[i]->next_free = -1;
 	}
 	sctx->first_free = 0;
-	sctx->nodesize = dev->dev_root->nodesize;
-	sctx->sectorsize = dev->dev_root->sectorsize;
+	sctx->nodesize = dev->fs_info->dev_root->nodesize;
+	sctx->sectorsize = dev->fs_info->dev_root->sectorsize;
 	atomic_set(&sctx->bios_in_flight, 0);
 	atomic_set(&sctx->workers_pending, 0);
 	atomic_set(&sctx->cancel_req, 0);
@@ -524,7 +524,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root,
 	struct extent_buffer *eb;
 	struct btrfs_inode_item *inode_item;
 	struct scrub_warning *swarn = warn_ctx;
-	struct btrfs_fs_info *fs_info = swarn->dev->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = swarn->dev->fs_info;
 	struct inode_fs_paths *ipath = NULL;
 	struct btrfs_root *local_root;
 	struct btrfs_key root_key;
@@ -616,7 +616,7 @@ static void scrub_print_warning(const char *errstr, struct scrub_block *sblock)
 
 	WARN_ON(sblock->page_count < 1);
 	dev = sblock->pagev[0]->dev;
-	fs_info = sblock->sctx->dev_root->fs_info;
+	fs_info = sblock->sctx->fs_info;
 
 	path = btrfs_alloc_path();
 	if (!path)
@@ -842,10 +842,9 @@ out:
 		spin_lock(&sctx->stat_lock);
 		++sctx->stat.uncorrectable_errors;
 		spin_unlock(&sctx->stat_lock);
-		btrfs_dev_replace_stats_inc(
-			&sctx->dev_root->fs_info->dev_replace.
-			num_uncorrectable_read_errors);
-		btrfs_err_rl_in_rcu(sctx->dev_root->fs_info,
+		btrfs_dev_replace_stats_inc(&sctx->fs_info->dev_replace.
+						num_uncorrectable_read_errors);
+		btrfs_err_rl_in_rcu(sctx->fs_info,
 		    "unable to fixup (nodatasum) error at logical %llu on dev %s",
 			fixup->logical, rcu_str_deref(fixup->dev->name));
 	}
@@ -897,7 +896,7 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
 				      DEFAULT_RATELIMIT_BURST);
 
 	BUG_ON(sblock_to_check->page_count < 1);
-	fs_info = sctx->dev_root->fs_info;
+	fs_info = sctx->fs_info;
 	if (sblock_to_check->pagev[0]->flags & BTRFS_EXTENT_FLAG_SUPER) {
 		/*
 		 * if we find an error in a super block, we just report it.
@@ -1176,8 +1175,7 @@ nodatasum_case:
 			if (scrub_write_page_to_dev_replace(sblock_other,
 							    page_num) != 0) {
 				btrfs_dev_replace_stats_inc(
-					&sctx->dev_root->
-					fs_info->dev_replace.
+					&sctx->fs_info->dev_replace.
 					num_write_errors);
 				success = 0;
 			}
@@ -1301,7 +1299,7 @@ static int scrub_setup_recheck_block(struct scrub_block *original_sblock,
 				     struct scrub_block *sblocks_for_recheck)
 {
 	struct scrub_ctx *sctx = original_sblock->sctx;
-	struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sctx->fs_info;
 	u64 length = original_sblock->page_count * PAGE_SIZE;
 	u64 logical = original_sblock->pagev[0]->logical;
 	u64 generation = original_sblock->pagev[0]->generation;
@@ -1572,7 +1570,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
 		int ret;
 
 		if (!page_bad->dev->bdev) {
-			btrfs_warn_rl(sblock_bad->sctx->dev_root->fs_info,
+			btrfs_warn_rl(sblock_bad->sctx->fs_info,
 				"scrub_repair_page_from_good_copy(bdev == NULL) "
 				"is unexpected");
 			return -EIO;
@@ -1594,7 +1592,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
 			btrfs_dev_stat_inc_and_print(page_bad->dev,
 				BTRFS_DEV_STAT_WRITE_ERRS);
 			btrfs_dev_replace_stats_inc(
-				&sblock_bad->sctx->dev_root->fs_info->
+				&sblock_bad->sctx->fs_info->
 				dev_replace.num_write_errors);
 			bio_put(bio);
 			return -EIO;
@@ -1622,7 +1620,7 @@ static void scrub_write_block_to_dev_replace(struct scrub_block *sblock)
 		ret = scrub_write_page_to_dev_replace(sblock, page_num);
 		if (ret)
 			btrfs_dev_replace_stats_inc(
-				&sblock->sctx->dev_root->fs_info->dev_replace.
+				&sblock->sctx->fs_info->dev_replace.
 				num_write_errors);
 	}
 }
@@ -1737,7 +1735,7 @@ static void scrub_wr_submit(struct scrub_ctx *sctx)
 static void scrub_wr_bio_end_io(struct bio *bio)
 {
 	struct scrub_bio *sbio = bio->bi_private;
-	struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sbio->dev->fs_info;
 
 	sbio->err = bio->bi_error;
 	sbio->bio = bio;
@@ -1756,7 +1754,7 @@ static void scrub_wr_bio_end_io_worker(struct btrfs_work *work)
 	WARN_ON(sbio->page_count > SCRUB_PAGES_PER_WR_BIO);
 	if (sbio->err) {
 		struct btrfs_dev_replace *dev_replace =
-			&sbio->sctx->dev_root->fs_info->dev_replace;
+			&sbio->sctx->fs_info->dev_replace;
 
 		for (i = 0; i < sbio->page_count; i++) {
 			struct scrub_page *spage = sbio->pagev[i];
@@ -1856,7 +1854,7 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 {
 	struct scrub_ctx *sctx = sblock->sctx;
 	struct btrfs_header *h;
-	struct btrfs_root *root = sctx->dev_root;
+	struct btrfs_root *root = sctx->fs_info->dev_root;
 	struct btrfs_fs_info *fs_info = root->fs_info;
 	u8 calculated_csum[BTRFS_CSUM_SIZE];
 	u8 on_disk_csum[BTRFS_CSUM_SIZE];
@@ -2122,7 +2120,7 @@ again:
 static void scrub_missing_raid56_end_io(struct bio *bio)
 {
 	struct scrub_block *sblock = bio->bi_private;
-	struct btrfs_fs_info *fs_info = sblock->sctx->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sblock->sctx->fs_info;
 
 	if (bio->bi_error)
 		sblock->no_io_error_seen = 0;
@@ -2149,14 +2147,14 @@ static void scrub_missing_raid56_worker(struct btrfs_work *work)
 		spin_lock(&sctx->stat_lock);
 		sctx->stat.read_errors++;
 		spin_unlock(&sctx->stat_lock);
-		btrfs_err_rl_in_rcu(sctx->dev_root->fs_info,
+		btrfs_err_rl_in_rcu(sctx->fs_info,
 			"IO error rebuilding logical %llu for dev %s",
 			logical, rcu_str_deref(dev->name));
 	} else if (sblock->header_error || sblock->checksum_error) {
 		spin_lock(&sctx->stat_lock);
 		sctx->stat.uncorrectable_errors++;
 		spin_unlock(&sctx->stat_lock);
-		btrfs_err_rl_in_rcu(sctx->dev_root->fs_info,
+		btrfs_err_rl_in_rcu(sctx->fs_info,
 			"failed to rebuild valid logical %llu for dev %s",
 			logical, rcu_str_deref(dev->name));
 	} else {
@@ -2178,7 +2176,8 @@ static void scrub_missing_raid56_worker(struct btrfs_work *work)
 static void scrub_missing_raid56_pages(struct scrub_block *sblock)
 {
 	struct scrub_ctx *sctx = sblock->sctx;
-	struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sctx->fs_info;
+	struct btrfs_root *dev_root = fs_info->dev_root;
 	u64 length = sblock->page_count * PAGE_SIZE;
 	u64 logical = sblock->pagev[0]->logical;
 	struct btrfs_bio *bbio = NULL;
@@ -2211,7 +2210,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock)
 	bio->bi_private = sblock;
 	bio->bi_end_io = scrub_missing_raid56_end_io;
 
-	rbio = raid56_alloc_missing_rbio(sctx->dev_root, bio, bbio, length);
+	rbio = raid56_alloc_missing_rbio(dev_root, bio, bbio, length);
 	if (!rbio)
 		goto rbio_out;
 
@@ -2330,7 +2329,7 @@ leave_nomem:
 static void scrub_bio_end_io(struct bio *bio)
 {
 	struct scrub_bio *sbio = bio->bi_private;
-	struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sbio->dev->fs_info;
 
 	sbio->err = bio->bi_error;
 	sbio->bio = bio;
@@ -2387,7 +2386,7 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity,
 {
 	u32 offset;
 	int nsectors;
-	int sectorsize = sparity->sctx->dev_root->sectorsize;
+	int sectorsize = sparity->sctx->fs_info->dev_root->sectorsize;
 
 	if (len >= sparity->stripe_len) {
 		bitmap_set(bitmap, 0, sparity->nsectors);
@@ -2755,13 +2754,14 @@ static void scrub_parity_bio_endio(struct bio *bio)
 
 	btrfs_init_work(&sparity->work, btrfs_scrubparity_helper,
 			scrub_parity_bio_endio_worker, NULL, NULL);
-	btrfs_queue_work(sparity->sctx->dev_root->fs_info->scrub_parity_workers,
+	btrfs_queue_work(sparity->sctx->fs_info->scrub_parity_workers,
 			 &sparity->work);
 }
 
 static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
 {
 	struct scrub_ctx *sctx = sparity->sctx;
+	struct btrfs_root *dev_root = sctx->fs_info->dev_root;
 	struct bio *bio;
 	struct btrfs_raid_bio *rbio;
 	struct scrub_page *spage;
@@ -2774,8 +2774,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
 		goto out;
 
 	length = sparity->logic_end - sparity->logic_start;
-	ret = btrfs_map_sblock(sctx->dev_root->fs_info, WRITE,
-			       sparity->logic_start,
+	ret = btrfs_map_sblock(sctx->fs_info, WRITE, sparity->logic_start,
 			       &length, &bbio, 0, 1);
 	if (ret || !bbio || !bbio->raid_map)
 		goto bbio_out;
@@ -2788,7 +2787,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
 	bio->bi_private = sparity;
 	bio->bi_end_io = scrub_parity_bio_endio;
 
-	rbio = raid56_parity_alloc_scrub_rbio(sctx->dev_root, bio, bbio,
+	rbio = raid56_parity_alloc_scrub_rbio(dev_root, bio, bbio,
 					      length, sparity->scrub_dev,
 					      sparity->dbitmap,
 					      sparity->nsectors);
@@ -2840,7 +2839,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
 						  u64 logic_start,
 						  u64 logic_end)
 {
-	struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sctx->fs_info;
 	struct btrfs_root *root = fs_info->extent_root;
 	struct btrfs_root *csum_root = fs_info->csum_root;
 	struct btrfs_extent_item *extent;
@@ -3063,7 +3062,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
 					   int is_dev_replace)
 {
 	struct btrfs_path *path, *ppath;
-	struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sctx->fs_info;
 	struct btrfs_root *root = fs_info->extent_root;
 	struct btrfs_root *csum_root = fs_info->csum_root;
 	struct btrfs_extent_item *extent;
@@ -3438,8 +3437,8 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
 					  struct btrfs_block_group_cache *cache,
 					  int is_dev_replace)
 {
-	struct btrfs_mapping_tree *map_tree =
-		&sctx->dev_root->fs_info->mapping_tree;
+	struct btrfs_fs_info *fs_info = sctx->fs_info;
+	struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree;
 	struct map_lookup *map;
 	struct extent_map *em;
 	int i;
@@ -3492,7 +3491,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 {
 	struct btrfs_dev_extent *dev_extent = NULL;
 	struct btrfs_path *path;
-	struct btrfs_root *root = sctx->dev_root;
+	struct btrfs_root *root = sctx->fs_info->dev_root;
 	struct btrfs_fs_info *fs_info = root->fs_info;
 	u64 length;
 	u64 chunk_offset;
@@ -3741,7 +3740,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
 	u64	bytenr;
 	u64	gen;
 	int	ret;
-	struct btrfs_root *root = sctx->dev_root;
+	struct btrfs_root *root = sctx->fs_info->dev_root;
 
 	if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state))
 		return -EIO;
@@ -4118,7 +4117,7 @@ static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
 			    int mirror_num, u64 physical_for_dev_replace)
 {
 	struct scrub_copy_nocow_ctx *nocow_ctx;
-	struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = sctx->fs_info;
 
 	nocow_ctx = kzalloc(sizeof(*nocow_ctx), GFP_NOFS);
 	if (!nocow_ctx) {
@@ -4177,7 +4176,7 @@ static void copy_nocow_pages_worker(struct btrfs_work *work)
 	struct btrfs_root *root;
 	int not_written = 0;
 
-	fs_info = sctx->dev_root->fs_info;
+	fs_info = sctx->fs_info;
 	root = fs_info->extent_root;
 
 	path = btrfs_alloc_path();
@@ -4292,7 +4291,7 @@ out_unlock:
 static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root,
 				      struct scrub_copy_nocow_ctx *nocow_ctx)
 {
-	struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = nocow_ctx->sctx->fs_info;
 	struct btrfs_key key;
 	struct inode *inode;
 	struct page *page;
@@ -4422,7 +4421,7 @@ static int write_page_nocow(struct scrub_ctx *sctx,
 	if (!dev)
 		return -EIO;
 	if (!dev->bdev) {
-		btrfs_warn_rl(dev->dev_root->fs_info,
+		btrfs_warn_rl(dev->fs_info,
 			"scrub write_page_nocow(bdev == NULL) is unexpected");
 		return -EIO;
 	}
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 9a155d2..b6e2498 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -368,7 +368,7 @@ static noinline void run_scheduled_bios(struct btrfs_device *device)
 	blk_start_plug(&plug);
 
 	bdi = blk_get_backing_dev_info(device->bdev);
-	fs_info = device->dev_root->fs_info;
+	fs_info = device->fs_info;
 	limit = btrfs_async_submit_limit(fs_info);
 	limit = limit * 2 / 3;
 
@@ -1122,7 +1122,7 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start,
 				   u64 end, u64 *length)
 {
 	struct btrfs_key key;
-	struct btrfs_root *root = device->dev_root;
+	struct btrfs_root *root = device->fs_info->dev_root;
 	struct btrfs_dev_extent *dev_extent;
 	struct btrfs_path *path;
 	u64 extent_end;
@@ -1205,7 +1205,7 @@ static int contains_pending_extent(struct btrfs_transaction *transaction,
 				   struct btrfs_device *device,
 				   u64 *start, u64 len)
 {
-	struct btrfs_fs_info *fs_info = device->dev_root->fs_info;
+	struct btrfs_fs_info *fs_info = device->fs_info;
 	struct extent_map *em;
 	struct list_head *search_list = &fs_info->pinned_chunks;
 	int ret = 0;
@@ -1281,8 +1281,8 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction,
 			       struct btrfs_device *device, u64 num_bytes,
 			       u64 search_start, u64 *start, u64 *len)
 {
+	struct btrfs_root *root = device->fs_info->dev_root;
 	struct btrfs_key key;
-	struct btrfs_root *root = device->dev_root;
 	struct btrfs_dev_extent *dev_extent;
 	struct btrfs_path *path;
 	u64 hole_size;
@@ -1451,9 +1451,9 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
 			  struct btrfs_device *device,
 			  u64 start, u64 *dev_extent_len)
 {
+	struct btrfs_root *root = device->fs_info->dev_root;
 	int ret;
 	struct btrfs_path *path;
-	struct btrfs_root *root = device->dev_root;
 	struct btrfs_key key;
 	struct btrfs_key found_key;
 	struct extent_buffer *leaf = NULL;
@@ -1512,7 +1512,7 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
 {
 	int ret;
 	struct btrfs_path *path;
-	struct btrfs_root *root = device->dev_root;
+	struct btrfs_root *root = device->fs_info->dev_root;
 	struct btrfs_dev_extent *extent;
 	struct extent_buffer *leaf;
 	struct btrfs_key key;
@@ -2339,7 +2339,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
 	device->total_bytes = i_size_read(bdev->bd_inode);
 	device->disk_total_bytes = device->total_bytes;
 	device->commit_total_bytes = device->total_bytes;
-	device->dev_root = root->fs_info->dev_root;
+	device->fs_info = fs_info;
 	device->bdev = bdev;
 	device->in_fs_metadata = 1;
 	device->is_tgtdev_for_dev_replace = 0;
@@ -2548,7 +2548,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path,
 	ASSERT(list_empty(&srcdev->resized_list));
 	device->commit_total_bytes = srcdev->commit_total_bytes;
 	device->commit_bytes_used = device->bytes_used;
-	device->dev_root = fs_info->dev_root;
+	device->fs_info = fs_info;
 	device->bdev = bdev;
 	device->in_fs_metadata = 1;
 	device->is_tgtdev_for_dev_replace = 1;
@@ -2576,7 +2576,7 @@ void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info,
 	tgtdev->io_width = fs_info->dev_root->sectorsize;
 	tgtdev->io_align = fs_info->dev_root->sectorsize;
 	tgtdev->sector_size = fs_info->dev_root->sectorsize;
-	tgtdev->dev_root = fs_info->dev_root;
+	tgtdev->fs_info = fs_info;
 	tgtdev->in_fs_metadata = 1;
 }
 
@@ -2590,7 +2590,7 @@ static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
 	struct extent_buffer *leaf;
 	struct btrfs_key key;
 
-	root = device->dev_root->fs_info->chunk_root;
+	root = device->fs_info->chunk_root;
 
 	path = btrfs_alloc_path();
 	if (!path)
@@ -2631,8 +2631,7 @@ out:
 int btrfs_grow_device(struct btrfs_trans_handle *trans,
 		      struct btrfs_device *device, u64 new_size)
 {
-	struct btrfs_super_block *super_copy =
-		device->dev_root->fs_info->super_copy;
+	struct btrfs_super_block *super_copy = device->fs_info->super_copy;
 	struct btrfs_fs_devices *fs_devices;
 	u64 old_total;
 	u64 diff;
@@ -2640,28 +2639,28 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
 	if (!device->writeable)
 		return -EACCES;
 
-	lock_chunks(device->dev_root);
+	lock_chunks(device->fs_info->dev_root);
 	old_total = btrfs_super_total_bytes(super_copy);
 	diff = new_size - device->total_bytes;
 
 	if (new_size <= device->total_bytes ||
 	    device->is_tgtdev_for_dev_replace) {
-		unlock_chunks(device->dev_root);
+		unlock_chunks(device->fs_info->dev_root);
 		return -EINVAL;
 	}
 
-	fs_devices = device->dev_root->fs_info->fs_devices;
+	fs_devices = device->fs_info->fs_devices;
 
 	btrfs_set_super_total_bytes(super_copy, old_total + diff);
 	device->fs_devices->total_rw_bytes += diff;
 
 	btrfs_device_set_total_bytes(device, new_size);
 	btrfs_device_set_disk_total_bytes(device, new_size);
-	btrfs_clear_space_info_full(device->dev_root->fs_info);
+	btrfs_clear_space_info_full(device->fs_info);
 	if (list_empty(&device->resized_list))
 		list_add_tail(&device->resized_list,
 			      &fs_devices->resized_devices);
-	unlock_chunks(device->dev_root);
+	unlock_chunks(device->fs_info->dev_root);
 
 	return btrfs_update_device(trans, device);
 }
@@ -4288,7 +4287,7 @@ int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info)
 int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
 {
 	struct btrfs_trans_handle *trans;
-	struct btrfs_root *root = device->dev_root;
+	struct btrfs_root *root = device->fs_info->dev_root;
 	struct btrfs_dev_extent *dev_extent = NULL;
 	struct btrfs_path *path;
 	u64 length;
@@ -6804,7 +6803,7 @@ void btrfs_init_devices_late(struct btrfs_fs_info *fs_info)
 	while (fs_devices) {
 		mutex_lock(&fs_devices->device_list_mutex);
 		list_for_each_entry(device, &fs_devices->devices, dev_list)
-			device->dev_root = fs_info->dev_root;
+			device->fs_info = fs_info;
 		mutex_unlock(&fs_devices->device_list_mutex);
 
 		fs_devices = fs_devices->seed;
@@ -6980,7 +6979,7 @@ static void btrfs_dev_stat_print_on_error(struct btrfs_device *dev)
 {
 	if (!dev->dev_stats_valid)
 		return;
-	btrfs_err_rl_in_rcu(dev->dev_root->fs_info,
+	btrfs_err_rl_in_rcu(dev->fs_info,
 		"bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u",
 			   rcu_str_deref(dev->name),
 			   btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS),
@@ -7000,7 +6999,7 @@ static void btrfs_dev_stat_print_on_load(struct btrfs_device *dev)
 	if (i == BTRFS_DEV_STAT_VALUES_MAX)
 		return; /* all values == 0, suppress message */
 
-	btrfs_info_in_rcu(dev->dev_root->fs_info,
+	btrfs_info_in_rcu(dev->fs_info,
 		"bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u",
 	       rcu_str_deref(dev->name),
 	       btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS),
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 6c765c0..a0ac26e 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -51,8 +51,7 @@ struct btrfs_device {
 	struct list_head dev_list;
 	struct list_head dev_alloc_list;
 	struct btrfs_fs_devices *fs_devices;
-
-	struct btrfs_root *dev_root;
+	struct btrfs_fs_info *fs_info;
 
 	struct rcu_string *name;
 
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 22/31] btrfs: root->fs_info cleanup, io_ctl_init
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (20 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 21/31] btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 24/31] btrfs: root->fs_info cleanup, btrfs_calc_{trans,trunc}_metadata_size jeffm
                   ` (9 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

The io_ctl->root member was only being used to access root->fs_info.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h            |  2 +-
 fs/btrfs/free-space-cache.c | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 784f003..4660ce4 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -513,7 +513,7 @@ struct btrfs_io_ctl {
 	void *cur, *orig;
 	struct page *page;
 	struct page **pages;
-	struct btrfs_root *root;
+	struct btrfs_fs_info *fs_info;
 	struct inode *inode;
 	unsigned long size;
 	int index;
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 5cbfa64..b3face3 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -305,7 +305,7 @@ static int readahead_cache(struct inode *inode)
 }
 
 static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,
-		       struct btrfs_root *root, int write)
+		       int write)
 {
 	int num_pages;
 	int check_crcs = 0;
@@ -327,7 +327,7 @@ static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,
 		return -ENOMEM;
 
 	io_ctl->num_pages = num_pages;
-	io_ctl->root = root;
+	io_ctl->fs_info = btrfs_sb(inode->i_sb);
 	io_ctl->check_crcs = check_crcs;
 	io_ctl->inode = inode;
 
@@ -450,7 +450,7 @@ static int io_ctl_check_generation(struct btrfs_io_ctl *io_ctl, u64 generation)
 
 	gen = io_ctl->cur;
 	if (le64_to_cpu(*gen) != generation) {
-		btrfs_err_rl(io_ctl->root->fs_info,
+		btrfs_err_rl(io_ctl->fs_info,
 			"space cache generation (%llu) does not match inode (%llu)",
 				*gen, generation);
 		io_ctl_unmap_page(io_ctl);
@@ -506,7 +506,7 @@ static int io_ctl_check_crc(struct btrfs_io_ctl *io_ctl, int index)
 			      PAGE_SIZE - offset);
 	btrfs_csum_final(crc, (char *)&crc);
 	if (val != crc) {
-		btrfs_err_rl(io_ctl->root->fs_info,
+		btrfs_err_rl(io_ctl->fs_info,
 			"csum mismatch on free space cache");
 		io_ctl_unmap_page(io_ctl);
 		return -EIO;
@@ -725,7 +725,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
 	if (!num_entries)
 		return 0;
 
-	ret = io_ctl_init(&io_ctl, inode, root, 0);
+	ret = io_ctl_init(&io_ctl, inode, 0);
 	if (ret)
 		return ret;
 
@@ -1230,7 +1230,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
 		return -EIO;
 
 	WARN_ON(io_ctl->pages);
-	ret = io_ctl_init(io_ctl, inode, root, 1);
+	ret = io_ctl_init(io_ctl, inode, 1);
 	if (ret)
 		return ret;
 
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 24/31] btrfs: root->fs_info cleanup, btrfs_calc_{trans,trunc}_metadata_size
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (21 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 22/31] btrfs: root->fs_info cleanup, io_ctl_init jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 25/31] btrfs: root->fs_info cleanup, lock/unlock_chunks jeffm
                   ` (8 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h            |  8 ++++----
 fs/btrfs/delayed-inode.c    |  4 ++--
 fs/btrfs/extent-tree.c      | 29 ++++++++++++++++-------------
 fs/btrfs/file.c             |  4 ++--
 fs/btrfs/free-space-cache.c |  4 ++--
 fs/btrfs/inode-map.c        |  3 ++-
 fs/btrfs/inode.c            |  4 ++--
 fs/btrfs/props.c            |  2 +-
 fs/btrfs/transaction.c      |  5 +++--
 9 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index b5b3148..d62ff0b 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2507,20 +2507,20 @@ static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
 
 u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes);
 
-static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
+static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_fs_info *fs_info,
 						 unsigned num_items)
 {
-	return root->fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
+	return fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
 }
 
 /*
  * Doing a truncate won't result in new nodes or leaves, just what we need for
  * COW.
  */
-static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_root *root,
+static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_fs_info *fs_info,
 						 unsigned num_items)
 {
-	return root->fs_info->nodesize * BTRFS_MAX_LEVEL * num_items;
+	return fs_info->nodesize * BTRFS_MAX_LEVEL * num_items;
 }
 
 int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 316ca24..65cd759 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -552,7 +552,7 @@ static int btrfs_delayed_item_reserve_metadata(struct btrfs_trans_handle *trans,
 	src_rsv = trans->block_rsv;
 	dst_rsv = &root->fs_info->delayed_block_rsv;
 
-	num_bytes = btrfs_calc_trans_metadata_size(root, 1);
+	num_bytes = btrfs_calc_trans_metadata_size(root->fs_info, 1);
 	ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes);
 	if (!ret) {
 		trace_btrfs_space_reservation(root->fs_info, "delayed_item",
@@ -595,7 +595,7 @@ static int btrfs_delayed_inode_reserve_metadata(
 	src_rsv = trans->block_rsv;
 	dst_rsv = &root->fs_info->delayed_block_rsv;
 
-	num_bytes = btrfs_calc_trans_metadata_size(root, 1);
+	num_bytes = btrfs_calc_trans_metadata_size(root->fs_info, 1);
 
 	/*
 	 * btrfs_dirty_inode will update the inode under btrfs_join_transaction
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 5d180ce..088182c 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2788,13 +2788,13 @@ int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
 	u64 num_bytes, num_dirty_bgs_bytes;
 	int ret = 0;
 
-	num_bytes = btrfs_calc_trans_metadata_size(root, 1);
+	num_bytes = btrfs_calc_trans_metadata_size(root->fs_info, 1);
 	num_heads = heads_to_leaves(root, num_heads);
 	if (num_heads > 1)
 		num_bytes += (num_heads - 1) * root->fs_info->nodesize;
 	num_bytes <<= 1;
 	num_bytes += btrfs_csum_bytes_to_leaves(root, csum_bytes) * root->fs_info->nodesize;
-	num_dirty_bgs_bytes = btrfs_calc_trans_metadata_size(root,
+	num_dirty_bgs_bytes = btrfs_calc_trans_metadata_size(root->fs_info,
 							     num_dirty_bgs);
 	global_rsv = &root->fs_info->global_block_rsv;
 
@@ -4416,8 +4416,8 @@ void check_system_chunk(struct btrfs_trans_handle *trans,
 	num_devs = get_profile_num_devs(root, type);
 
 	/* num_devs device items to update and 1 chunk item to add or remove */
-	thresh = btrfs_calc_trunc_metadata_size(root, num_devs) +
-		btrfs_calc_trans_metadata_size(root, 1);
+	thresh = btrfs_calc_trunc_metadata_size(root->fs_info, num_devs) +
+		btrfs_calc_trans_metadata_size(root->fs_info, 1);
 
 	if (left < thresh && btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
 		btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
@@ -4655,7 +4655,7 @@ static inline int calc_reclaim_items_nr(struct btrfs_root *root, u64 to_reclaim)
 	u64 bytes;
 	int nr;
 
-	bytes = btrfs_calc_trans_metadata_size(root, 1);
+	bytes = btrfs_calc_trans_metadata_size(root->fs_info, 1);
 	nr = (int)div64_u64(to_reclaim, bytes);
 	if (!nr)
 		nr = 1;
@@ -5555,7 +5555,7 @@ int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans,
 	 * added it, so this takes the reservation so we can release it later
 	 * when we are truly done with the orphan item.
 	 */
-	u64 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
+	u64 num_bytes = btrfs_calc_trans_metadata_size(root->fs_info, 1);
 	trace_btrfs_space_reservation(root->fs_info, "orphan",
 				      btrfs_ino(inode), num_bytes, 1);
 	return block_rsv_migrate_bytes(src_rsv, dst_rsv, num_bytes);
@@ -5564,7 +5564,7 @@ int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans,
 void btrfs_orphan_release_metadata(struct inode *inode)
 {
 	struct btrfs_root *root = BTRFS_I(inode)->root;
-	u64 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
+	u64 num_bytes = btrfs_calc_trans_metadata_size(root->fs_info, 1);
 	trace_btrfs_space_reservation(root->fs_info, "orphan",
 				      btrfs_ino(inode), num_bytes, 0);
 	btrfs_block_rsv_release(root, root->orphan_block_rsv, num_bytes);
@@ -5606,7 +5606,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
 
 	*qgroup_reserved = num_bytes;
 
-	num_bytes = btrfs_calc_trans_metadata_size(root, items);
+	num_bytes = btrfs_calc_trans_metadata_size(root->fs_info, items);
 	rsv->space_info = __find_space_info(root->fs_info,
 					    BTRFS_BLOCK_GROUP_METADATA);
 	ret = btrfs_block_rsv_add(root, rsv, num_bytes,
@@ -5710,10 +5710,11 @@ static u64 calc_csum_metadata_size(struct inode *inode, u64 num_bytes,
 		return 0;
 
 	if (reserve)
-		return btrfs_calc_trans_metadata_size(root,
+		return btrfs_calc_trans_metadata_size(root->fs_info,
 						      num_csums - old_csums);
 
-	return btrfs_calc_trans_metadata_size(root, old_csums - num_csums);
+	return btrfs_calc_trans_metadata_size(root->fs_info,
+					      old_csums - num_csums);
 }
 
 int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
@@ -5771,7 +5772,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
 		extra_reserve = 1;
 	}
 
-	to_reserve = btrfs_calc_trans_metadata_size(root, nr_extents);
+	to_reserve = btrfs_calc_trans_metadata_size(root->fs_info, nr_extents);
 	to_reserve += calc_csum_metadata_size(inode, num_bytes, 1);
 	csum_bytes = BTRFS_I(inode)->csum_bytes;
 	spin_unlock(&BTRFS_I(inode)->lock);
@@ -5861,7 +5862,8 @@ out_fail:
 	}
 	spin_unlock(&BTRFS_I(inode)->lock);
 	if (dropped)
-		to_free += btrfs_calc_trans_metadata_size(root, dropped);
+		to_free += btrfs_calc_trans_metadata_size(root->fs_info,
+							  dropped);
 
 	if (to_free) {
 		btrfs_block_rsv_release(root, block_rsv, to_free);
@@ -5896,7 +5898,8 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes)
 		to_free = calc_csum_metadata_size(inode, num_bytes, 0);
 	spin_unlock(&BTRFS_I(inode)->lock);
 	if (dropped > 0)
-		to_free += btrfs_calc_trans_metadata_size(root, dropped);
+		to_free += btrfs_calc_trans_metadata_size(root->fs_info,
+							  dropped);
 
 	if (btrfs_is_testing(root->fs_info))
 		return;
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 73114ac..cae6a45 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2323,7 +2323,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
 	u64 tail_len;
 	u64 orig_start = offset;
 	u64 cur_offset;
-	u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
+	u64 min_size = btrfs_calc_trunc_metadata_size(root->fs_info, 1);
 	u64 drop_end;
 	int ret = 0;
 	int err = 0;
@@ -2470,7 +2470,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
 		ret = -ENOMEM;
 		goto out_free;
 	}
-	rsv->size = btrfs_calc_trunc_metadata_size(root, 1);
+	rsv->size = btrfs_calc_trunc_metadata_size(root->fs_info, 1);
 	rsv->failfast = 1;
 
 	/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 7d99e29..02803e9 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -212,8 +212,8 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_root *root,
 	int ret;
 
 	/* 1 for slack space, 1 for updating the inode */
-	needed_bytes = btrfs_calc_trunc_metadata_size(root, 1) +
-		btrfs_calc_trans_metadata_size(root, 1);
+	needed_bytes = btrfs_calc_trunc_metadata_size(root->fs_info, 1) +
+		btrfs_calc_trans_metadata_size(root->fs_info, 1);
 
 	spin_lock(&rsv->lock);
 	if (rsv->reserved < needed_bytes)
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index aa6faba..a24a0ca 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -430,7 +430,8 @@ int btrfs_save_ino_cache(struct btrfs_root *root,
 	 * 1 item for free space object
 	 * 3 items for pre-allocation
 	 */
-	trans->bytes_reserved = btrfs_calc_trans_metadata_size(root, 10);
+	trans->bytes_reserved = btrfs_calc_trans_metadata_size(root->fs_info,
+							       10);
 	ret = btrfs_block_rsv_add(root, trans->block_rsv,
 				  trans->bytes_reserved,
 				  BTRFS_RESERVE_NO_FLUSH);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index bdc9f99..f1e2acc 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5158,7 +5158,7 @@ void btrfs_evict_inode(struct inode *inode)
 	struct btrfs_root *root = BTRFS_I(inode)->root;
 	struct btrfs_block_rsv *rsv, *global_rsv;
 	int steal_from_global = 0;
-	u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
+	u64 min_size = btrfs_calc_trunc_metadata_size(root->fs_info, 1);
 	int ret;
 
 	trace_btrfs_inode_evict(inode);
@@ -9057,7 +9057,7 @@ static int btrfs_truncate(struct inode *inode)
 	int err = 0;
 	struct btrfs_trans_handle *trans;
 	u64 mask = root->fs_info->sectorsize - 1;
-	u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
+	u64 min_size = btrfs_calc_trunc_metadata_size(root->fs_info, 1);
 
 	ret = btrfs_wait_ordered_range(inode, inode->i_size & (~mask),
 				       (u64)-1);
diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
index cf0b444..f4a5876 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -320,7 +320,7 @@ static int inherit_props(struct btrfs_trans_handle *trans,
 		if (!value)
 			continue;
 
-		num_bytes = btrfs_calc_trans_metadata_size(root, 1);
+		num_bytes = btrfs_calc_trans_metadata_size(root->fs_info, 1);
 		ret = btrfs_block_rsv_add(root, trans->block_rsv,
 					  num_bytes, BTRFS_RESERVE_NO_FLUSH);
 		if (ret)
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 93b463a..a1cbc22 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -502,7 +502,8 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
 		if (ret)
 			return ERR_PTR(ret);
 
-		num_bytes = btrfs_calc_trans_metadata_size(root, num_items);
+		num_bytes = btrfs_calc_trans_metadata_size(root->fs_info,
+							   num_items);
 		/*
 		 * Do the reservation for the relocation root creation
 		 */
@@ -627,7 +628,7 @@ struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv(
 	if (IS_ERR(trans))
 		return trans;
 
-	num_bytes = btrfs_calc_trans_metadata_size(root, num_items);
+	num_bytes = btrfs_calc_trans_metadata_size(root->fs_info, num_items);
 	ret = btrfs_cond_migrate_bytes(root->fs_info,
 				       &root->fs_info->trans_block_rsv,
 				       num_bytes,
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 25/31] btrfs: root->fs_info cleanup, lock/unlock_chunks
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (22 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 24/31] btrfs: root->fs_info cleanup, btrfs_calc_{trans,trunc}_metadata_size jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 26/31] btrfs: root->fs_info cleanup, update_block_group{,flags} jeffm
                   ` (7 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/disk-io.c          |  4 +--
 fs/btrfs/extent-tree.c      |  8 +++---
 fs/btrfs/free-space-cache.c |  4 +--
 fs/btrfs/volumes.c          | 70 ++++++++++++++++++++++-----------------------
 fs/btrfs/volumes.h          |  8 +++---
 5 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index b7891c4..18b41d7 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3949,7 +3949,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)
 	__btrfs_free_block_rsv(root->orphan_block_rsv);
 	root->orphan_block_rsv = NULL;
 
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 	while (!list_empty(&fs_info->pinned_chunks)) {
 		struct extent_map *em;
 
@@ -3958,7 +3958,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)
 		list_del_init(&em->list);
 		free_extent_map(em);
 	}
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 }
 
 int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 088182c..14f4d05 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -9418,9 +9418,9 @@ again:
 out:
 	if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) {
 		alloc_flags = update_block_group_flags(root, cache->flags);
-		lock_chunks(root->fs_info->chunk_root);
+		lock_chunks(root->fs_info);
 		check_system_chunk(trans, root, alloc_flags);
-		unlock_chunks(root->fs_info->chunk_root);
+		unlock_chunks(root->fs_info);
 	}
 	mutex_unlock(&root->fs_info->ro_block_group_mutex);
 
@@ -10433,7 +10433,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
 
 	memcpy(&key, &block_group->key, sizeof(key));
 
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 	if (!list_empty(&em->list)) {
 		/* We're in the transaction->pending_chunks list. */
 		free_extent_map(em);
@@ -10501,7 +10501,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
 		free_extent_map(em);
 	}
 
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 
 	ret = remove_block_group_free_space(trans, root->fs_info, block_group);
 	if (ret)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 02803e9..b194c09 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -3327,7 +3327,7 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group)
 	spin_unlock(&block_group->lock);
 
 	if (cleanup) {
-		lock_chunks(block_group->fs_info->chunk_root);
+		lock_chunks(block_group->fs_info);
 		em_tree = &block_group->fs_info->mapping_tree.map_tree;
 		write_lock(&em_tree->lock);
 		em = lookup_extent_mapping(em_tree, block_group->key.objectid,
@@ -3339,7 +3339,7 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group)
 		 */
 		remove_extent_mapping(em_tree, em);
 		write_unlock(&em_tree->lock);
-		unlock_chunks(block_group->fs_info->chunk_root);
+		unlock_chunks(block_group->fs_info);
 
 		/* once for us and once for the tree */
 		free_extent_map(em);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 26e8687..e90246d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1833,10 +1833,10 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 	}
 
 	if (device->writeable) {
-		lock_chunks(root);
+		lock_chunks(root->fs_info);
 		list_del_init(&device->dev_alloc_list);
 		device->fs_devices->rw_devices--;
-		unlock_chunks(root);
+		unlock_chunks(root->fs_info);
 		dev_name = kstrdup(device->name->str, GFP_KERNEL);
 		if (!dev_name) {
 			ret = -ENOMEM;
@@ -1938,11 +1938,11 @@ out:
 
 error_undo:
 	if (device->writeable) {
-		lock_chunks(root);
+		lock_chunks(root->fs_info);
 		list_add(&device->dev_alloc_list,
 			 &root->fs_info->fs_devices->alloc_list);
 		device->fs_devices->rw_devices++;
-		unlock_chunks(root);
+		unlock_chunks(root->fs_info);
 	}
 	goto out;
 }
@@ -2164,9 +2164,9 @@ static int btrfs_prepare_sprout(struct btrfs_root *root)
 	list_for_each_entry(device, &seed_devices->devices, dev_list)
 		device->fs_devices = seed_devices;
 
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 	list_splice_init(&fs_devices->alloc_list, &seed_devices->alloc_list);
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 
 	fs_devices->seeding = 0;
 	fs_devices->num_devices = 0;
@@ -2356,7 +2356,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
 	device->fs_devices = root->fs_info->fs_devices;
 
 	mutex_lock(&root->fs_info->fs_devices->device_list_mutex);
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 	list_add_rcu(&device->dev_list, &root->fs_info->fs_devices->devices);
 	list_add(&device->dev_alloc_list,
 		 &root->fs_info->fs_devices->alloc_list);
@@ -2390,13 +2390,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
 	 */
 	btrfs_clear_space_info_full(root->fs_info);
 
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 	mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
 
 	if (seeding_dev) {
-		lock_chunks(root);
+		lock_chunks(root->fs_info);
 		ret = init_first_rw_device(trans, root, device);
-		unlock_chunks(root);
+		unlock_chunks(root->fs_info);
 		if (ret) {
 			btrfs_abort_transaction(trans, ret);
 			goto error_trans;
@@ -2641,13 +2641,13 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
 	if (!device->writeable)
 		return -EACCES;
 
-	lock_chunks(device->fs_info->dev_root);
+	lock_chunks(device->fs_info);
 	old_total = btrfs_super_total_bytes(super_copy);
 	diff = new_size - device->total_bytes;
 
 	if (new_size <= device->total_bytes ||
 	    device->is_tgtdev_for_dev_replace) {
-		unlock_chunks(device->fs_info->dev_root);
+		unlock_chunks(device->fs_info);
 		return -EINVAL;
 	}
 
@@ -2662,7 +2662,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
 	if (list_empty(&device->resized_list))
 		list_add_tail(&device->resized_list,
 			      &fs_devices->resized_devices);
-	unlock_chunks(device->fs_info->dev_root);
+	unlock_chunks(device->fs_info);
 
 	return btrfs_update_device(trans, device);
 }
@@ -2718,7 +2718,7 @@ static int btrfs_del_sys_chunk(struct btrfs_fs_info *fs_info,
 	u32 cur;
 	struct btrfs_key key;
 
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 	array_size = btrfs_super_sys_array_size(super_copy);
 
 	ptr = super_copy->sys_chunk_array;
@@ -2748,7 +2748,7 @@ static int btrfs_del_sys_chunk(struct btrfs_fs_info *fs_info,
 			cur += len;
 		}
 	}
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 	return ret;
 }
 
@@ -2785,9 +2785,9 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 		return -EINVAL;
 	}
 	map = em->map_lookup;
-	lock_chunks(root->fs_info->chunk_root);
+	lock_chunks(fs_info);
 	check_system_chunk(trans, extent_root, map->type);
-	unlock_chunks(root->fs_info->chunk_root);
+	unlock_chunks(fs_info);
 
 	/*
 	 * Take the device list mutex to prevent races with the final phase of
@@ -2807,14 +2807,14 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
 		}
 
 		if (device->bytes_used > 0) {
-			lock_chunks(root);
+			lock_chunks(root->fs_info);
 			btrfs_device_set_bytes_used(device,
 					device->bytes_used - dev_extent_len);
 			spin_lock(&root->fs_info->free_chunk_lock);
 			root->fs_info->free_chunk_space += dev_extent_len;
 			spin_unlock(&root->fs_info->free_chunk_lock);
 			btrfs_clear_space_info_full(root->fs_info);
-			unlock_chunks(root);
+			unlock_chunks(root->fs_info);
 		}
 
 		if (map->stripes[i].dev) {
@@ -4315,7 +4315,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
 
 	path->reada = READA_FORWARD;
 
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 
 	btrfs_device_set_total_bytes(device, new_size);
 	if (device->writeable) {
@@ -4324,7 +4324,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
 		root->fs_info->free_chunk_space -= diff;
 		spin_unlock(&root->fs_info->free_chunk_lock);
 	}
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 
 again:
 	key.objectid = device->devid;
@@ -4396,7 +4396,7 @@ again:
 		goto done;
 	}
 
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 
 	/*
 	 * We checked in the above loop all device extents that were already in
@@ -4416,7 +4416,7 @@ again:
 
 		if (contains_pending_extent(trans->transaction, device,
 					    &start, len)) {
-			unlock_chunks(root);
+			unlock_chunks(root->fs_info);
 			checked_pending_chunks = true;
 			failed = 0;
 			retried = false;
@@ -4434,7 +4434,7 @@ again:
 
 	WARN_ON(diff > old_total);
 	btrfs_set_super_total_bytes(super_copy, old_total - diff);
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 
 	/* Now btrfs_update_device() will change the on-disk size. */
 	ret = btrfs_update_device(trans, device);
@@ -4442,14 +4442,14 @@ again:
 done:
 	btrfs_free_path(path);
 	if (ret) {
-		lock_chunks(root);
+		lock_chunks(root->fs_info);
 		btrfs_device_set_total_bytes(device, old_size);
 		if (device->writeable)
 			device->fs_devices->total_rw_bytes += diff;
 		spin_lock(&root->fs_info->free_chunk_lock);
 		root->fs_info->free_chunk_space += diff;
 		spin_unlock(&root->fs_info->free_chunk_lock);
-		unlock_chunks(root);
+		unlock_chunks(root->fs_info);
 	}
 	return ret;
 }
@@ -4463,11 +4463,11 @@ static int btrfs_add_system_chunk(struct btrfs_root *root,
 	u32 array_size;
 	u8 *ptr;
 
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 	array_size = btrfs_super_sys_array_size(super_copy);
 	if (array_size + item_size + sizeof(disk_key)
 			> BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) {
-		unlock_chunks(root);
+		unlock_chunks(root->fs_info);
 		return -EFBIG;
 	}
 
@@ -4478,7 +4478,7 @@ static int btrfs_add_system_chunk(struct btrfs_root *root,
 	memcpy(ptr, chunk, item_size);
 	item_size += sizeof(disk_key);
 	btrfs_set_super_sys_array_size(super_copy, array_size + item_size);
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 
 	return 0;
 }
@@ -6724,7 +6724,7 @@ int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
 		return -ENOMEM;
 
 	mutex_lock(&uuid_mutex);
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 
 	/*
 	 * Read all device items, and then all the chunk items. All
@@ -6791,7 +6791,7 @@ int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
 	}
 	ret = 0;
 error:
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 	mutex_unlock(&uuid_mutex);
 
 	btrfs_free_path(path);
@@ -7090,13 +7090,13 @@ void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info)
 		return;
 
 	mutex_lock(&fs_devices->device_list_mutex);
-	lock_chunks(fs_info->dev_root);
+	lock_chunks(fs_info);
 	list_for_each_entry_safe(curr, next, &fs_devices->resized_devices,
 				 resized_list) {
 		list_del_init(&curr->resized_list);
 		curr->commit_total_bytes = curr->disk_total_bytes;
 	}
-	unlock_chunks(fs_info->dev_root);
+	unlock_chunks(fs_info);
 	mutex_unlock(&fs_devices->device_list_mutex);
 }
 
@@ -7113,7 +7113,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_root *root,
 		return;
 
 	/* In order to kick the device replace finish process */
-	lock_chunks(root);
+	lock_chunks(root->fs_info);
 	list_for_each_entry(em, &transaction->pending_chunks, list) {
 		map = em->map_lookup;
 
@@ -7122,7 +7122,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_root *root,
 			dev->commit_bytes_used = dev->bytes_used;
 		}
 	}
-	unlock_chunks(root);
+	unlock_chunks(root->fs_info);
 }
 
 void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info)
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index a0ac26e..52fad80 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -511,14 +511,14 @@ void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info);
 void btrfs_update_commit_device_bytes_used(struct btrfs_root *root,
 					struct btrfs_transaction *transaction);
 
-static inline void lock_chunks(struct btrfs_root *root)
+static inline void lock_chunks(struct btrfs_fs_info *fs_info)
 {
-	mutex_lock(&root->fs_info->chunk_mutex);
+	mutex_lock(&fs_info->chunk_mutex);
 }
 
-static inline void unlock_chunks(struct btrfs_root *root)
+static inline void unlock_chunks(struct btrfs_fs_info *fs_info)
 {
-	mutex_unlock(&root->fs_info->chunk_mutex);
+	mutex_unlock(&fs_info->chunk_mutex);
 }
 
 struct list_head *btrfs_get_fs_uuids(void);
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 26/31] btrfs: root->fs_info cleanup, update_block_group{,flags}
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (23 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 25/31] btrfs: root->fs_info cleanup, lock/unlock_chunks jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 28/31] btrfs: root->fs_info cleanup, access fs_info->delayed_root directly jeffm
                   ` (6 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/extent-tree.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 14f4d05..bc56e04 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -76,7 +76,7 @@ enum {
 };
 
 static int update_block_group(struct btrfs_trans_handle *trans,
-			      struct btrfs_root *root, u64 bytenr,
+			      struct btrfs_fs_info *fs_info, u64 bytenr,
 			      u64 num_bytes, int alloc);
 static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 				struct btrfs_root *root,
@@ -5971,11 +5971,10 @@ void btrfs_delalloc_release_space(struct inode *inode, u64 start, u64 len)
 }
 
 static int update_block_group(struct btrfs_trans_handle *trans,
-			      struct btrfs_root *root, u64 bytenr,
+			      struct btrfs_fs_info *info, u64 bytenr,
 			      u64 num_bytes, int alloc)
 {
 	struct btrfs_block_group_cache *cache = NULL;
-	struct btrfs_fs_info *info = root->fs_info;
 	u64 total = num_bytes;
 	u64 old_val;
 	u64 byte_in_group;
@@ -6016,7 +6015,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
 		spin_lock(&cache->space_info->lock);
 		spin_lock(&cache->lock);
 
-		if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
+		if (btrfs_test_opt(info, SPACE_CACHE) &&
 		    cache->disk_cache_state < BTRFS_DC_CLEAR)
 			cache->disk_cache_state = BTRFS_DC_CLEAR;
 
@@ -6848,7 +6847,8 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
 			goto out;
 		}
 
-		ret = update_block_group(trans, root, bytenr, num_bytes, 0);
+		ret = update_block_group(trans, root->fs_info, bytenr,
+					 num_bytes, 0);
 		if (ret) {
 			btrfs_abort_transaction(trans, ret);
 			goto out;
@@ -7866,7 +7866,7 @@ static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
 	if (ret)
 		return ret;
 
-	ret = update_block_group(trans, root, ins->objectid, ins->offset, 1);
+	ret = update_block_group(trans, fs_info, ins->objectid, ins->offset, 1);
 	if (ret) { /* -ENOENT, logic error */
 		btrfs_err(fs_info, "update block group failed for %llu %llu",
 			ins->objectid, ins->offset);
@@ -7952,9 +7952,8 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
 	if (ret)
 		return ret;
 
-	ret = update_block_group(trans, root, ins->objectid,
-				 root->fs_info->nodesize,
-				 1);
+	ret = update_block_group(trans, fs_info, ins->objectid,
+				 fs_info->nodesize, 1);
 	if (ret) { /* -ENOENT, logic error */
 		btrfs_err(fs_info, "update block group failed for %llu %llu",
 			ins->objectid, ins->offset);
@@ -9262,7 +9261,7 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
-static u64 update_block_group_flags(struct btrfs_root *root, u64 flags)
+static u64 update_block_group_flags(struct btrfs_fs_info *fs_info, u64 flags)
 {
 	u64 num_devices;
 	u64 stripped;
@@ -9271,11 +9270,11 @@ static u64 update_block_group_flags(struct btrfs_root *root, u64 flags)
 	 * if restripe for this chunk_type is on pick target profile and
 	 * return, otherwise do the usual balance
 	 */
-	stripped = get_restripe_target(root->fs_info, flags);
+	stripped = get_restripe_target(fs_info, flags);
 	if (stripped)
 		return extended_to_chunk(stripped);
 
-	num_devices = root->fs_info->fs_devices->rw_devices;
+	num_devices = fs_info->fs_devices->rw_devices;
 
 	stripped = BTRFS_BLOCK_GROUP_RAID0 |
 		BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6 |
@@ -9391,7 +9390,7 @@ again:
 	 * if we are changing raid levels, try to allocate a corresponding
 	 * block group with the new raid level.
 	 */
-	alloc_flags = update_block_group_flags(root, cache->flags);
+	alloc_flags = update_block_group_flags(root->fs_info, cache->flags);
 	if (alloc_flags != cache->flags) {
 		ret = do_chunk_alloc(trans, root, alloc_flags,
 				     CHUNK_ALLOC_FORCE);
@@ -9417,7 +9416,8 @@ again:
 	ret = inc_block_group_ro(cache, 0);
 out:
 	if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) {
-		alloc_flags = update_block_group_flags(root, cache->flags);
+		alloc_flags = update_block_group_flags(root->fs_info,
+						       cache->flags);
 		lock_chunks(root->fs_info);
 		check_system_chunk(trans, root, alloc_flags);
 		unlock_chunks(root->fs_info);
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 28/31] btrfs: root->fs_info cleanup, access fs_info->delayed_root directly
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (24 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 26/31] btrfs: root->fs_info cleanup, update_block_group{,flags} jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 30/31] btrfs: root->fs_info cleanup, btrfs_commit_transaction already has root jeffm
                   ` (5 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

This results in btrfs_assert_delayed_root_empty and
btrfs_destroy_delayed_inode taking an fs_info instead of a root.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/delayed-inode.c | 23 ++++++-----------------
 fs/btrfs/delayed-inode.h |  4 ++--
 fs/btrfs/disk-io.c       |  8 ++++----
 fs/btrfs/transaction.c   |  2 +-
 4 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 370f398..733d7bc 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -72,12 +72,6 @@ static inline int btrfs_is_continuous_delayed_item(
 	return 0;
 }
 
-static inline struct btrfs_delayed_root *btrfs_get_delayed_root(
-							struct btrfs_root *root)
-{
-	return root->fs_info->delayed_root;
-}
-
 static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode)
 {
 	struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
@@ -1184,7 +1178,7 @@ static int __btrfs_run_delayed_items(struct btrfs_trans_handle *trans,
 	block_rsv = trans->block_rsv;
 	trans->block_rsv = &fs_info->delayed_block_rsv;
 
-	delayed_root = btrfs_get_delayed_root(root);
+	delayed_root = fs_info->delayed_root;
 
 	curr_node = btrfs_first_delayed_node(delayed_root);
 	while (curr_node && (!count || (count && nr--))) {
@@ -1411,11 +1405,9 @@ static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root,
 	return 0;
 }
 
-void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
+void btrfs_assert_delayed_root_empty(struct btrfs_fs_info *fs_info)
 {
-	struct btrfs_delayed_root *delayed_root;
-	delayed_root = btrfs_get_delayed_root(root);
-	WARN_ON(btrfs_first_delayed_node(delayed_root));
+	WARN_ON(btrfs_first_delayed_node(fs_info->delayed_root));
 }
 
 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
@@ -1436,7 +1428,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
 	struct btrfs_delayed_root *delayed_root;
 	struct btrfs_fs_info *fs_info = root->fs_info;
 
-	delayed_root = btrfs_get_delayed_root(root);
+	delayed_root = fs_info->delayed_root;
 
 	if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
 		return;
@@ -1990,14 +1982,11 @@ void btrfs_kill_all_delayed_nodes(struct btrfs_root *root)
 	}
 }
 
-void btrfs_destroy_delayed_inodes(struct btrfs_root *root)
+void btrfs_destroy_delayed_inodes(struct btrfs_fs_info *fs_info)
 {
-	struct btrfs_delayed_root *delayed_root;
 	struct btrfs_delayed_node *curr_node, *prev_node;
 
-	delayed_root = btrfs_get_delayed_root(root);
-
-	curr_node = btrfs_first_delayed_node(delayed_root);
+	curr_node = btrfs_first_delayed_node(fs_info->delayed_root);
 	while (curr_node) {
 		__btrfs_kill_delayed_node(curr_node);
 
diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
index 0167853..67b2153 100644
--- a/fs/btrfs/delayed-inode.h
+++ b/fs/btrfs/delayed-inode.h
@@ -134,7 +134,7 @@ int btrfs_delayed_delete_inode_ref(struct inode *inode);
 void btrfs_kill_all_delayed_nodes(struct btrfs_root *root);
 
 /* Used for clean the transaction */
-void btrfs_destroy_delayed_inodes(struct btrfs_root *root);
+void btrfs_destroy_delayed_inodes(struct btrfs_fs_info *fs_info);
 
 /* Used for readdir() */
 void btrfs_get_delayed_items(struct inode *inode, struct list_head *ins_list,
@@ -151,6 +151,6 @@ int __init btrfs_delayed_inode_init(void);
 void btrfs_delayed_inode_exit(void);
 
 /* for debugging */
-void btrfs_assert_delayed_root_empty(struct btrfs_root *root);
+void btrfs_assert_delayed_root_empty(struct btrfs_fs_info *fs_info);
 
 #endif
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 867a69d..a428e4e3 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4466,8 +4466,8 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
 	cur_trans->state = TRANS_STATE_UNBLOCKED;
 	wake_up(&fs_info->transaction_wait);
 
-	btrfs_destroy_delayed_inodes(root);
-	btrfs_assert_delayed_root_empty(root);
+	btrfs_destroy_delayed_inodes(fs_info);
+	btrfs_assert_delayed_root_empty(fs_info);
 
 	btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages,
 				     EXTENT_DIRTY);
@@ -4528,8 +4528,8 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root)
 	}
 	spin_unlock(&fs_info->trans_lock);
 	btrfs_destroy_all_ordered_extents(fs_info);
-	btrfs_destroy_delayed_inodes(root);
-	btrfs_assert_delayed_root_empty(root);
+	btrfs_destroy_delayed_inodes(fs_info);
+	btrfs_assert_delayed_root_empty(fs_info);
 	btrfs_destroy_pinned_extent(root, fs_info->pinned_extents);
 	btrfs_destroy_all_delalloc_inodes(fs_info);
 	mutex_unlock(&fs_info->transaction_kthread_mutex);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index ede1bea..a976373 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -2140,7 +2140,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
 	 * make sure none of the code above managed to slip in a
 	 * delayed item
 	 */
-	btrfs_assert_delayed_root_empty(root);
+	btrfs_assert_delayed_root_empty(fs_info);
 
 	WARN_ON(cur_trans != trans->transaction);
 
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 30/31] btrfs: root->fs_info cleanup, btrfs_commit_transaction already has root
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (25 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 28/31] btrfs: root->fs_info cleanup, access fs_info->delayed_root directly jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-24 22:15 ` [PATCH 31/31] btrfs: root->fs_info cleanup, btrfs_end_transaction{,_throttle} use trans->fs_info instead of parameter jeffm
                   ` (4 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

btrfs_commit_transaction is always called using the root that was used
to create the transaction handle.  Passing it separately is unnecessary.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/dev-replace.c     | 10 +++++-----
 fs/btrfs/disk-io.c         |  6 +++---
 fs/btrfs/extent-tree.c     |  4 ++--
 fs/btrfs/file.c            |  2 +-
 fs/btrfs/free-space-tree.c |  4 ++--
 fs/btrfs/inode.c           |  4 ++--
 fs/btrfs/ioctl.c           | 23 +++++++++++------------
 fs/btrfs/qgroup.c          |  4 ++--
 fs/btrfs/relocation.c      | 10 +++++-----
 fs/btrfs/scrub.c           |  3 +--
 fs/btrfs/send.c            |  2 +-
 fs/btrfs/super.c           |  4 ++--
 fs/btrfs/transaction.c     | 10 +++++-----
 fs/btrfs/transaction.h     |  3 +--
 fs/btrfs/tree-log.c        |  2 +-
 fs/btrfs/volumes.c         | 14 +++++++-------
 16 files changed, 51 insertions(+), 54 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 3eb0017..57dee36 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -333,7 +333,7 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, char *tgtdev_name,
 	 */
 	trans = btrfs_attach_transaction(root);
 	if (!IS_ERR(trans)) {
-		ret = btrfs_commit_transaction(trans, root);
+		ret = btrfs_commit_transaction(trans);
 		if (ret)
 			return ret;
 	} else if (PTR_ERR(trans) != -ENOENT) {
@@ -395,7 +395,7 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, char *tgtdev_name,
 		goto leave;
 	}
 
-	ret = btrfs_commit_transaction(trans, root);
+	ret = btrfs_commit_transaction(trans);
 	WARN_ON(ret);
 
 	/* the disk copy procedure reuses the scrub code */
@@ -511,7 +511,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 		mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
 		return PTR_ERR(trans);
 	}
-	ret = btrfs_commit_transaction(trans, root);
+	ret = btrfs_commit_transaction(trans);
 	WARN_ON(ret);
 
 	mutex_lock(&uuid_mutex);
@@ -601,7 +601,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 	/* write back the superblocks */
 	trans = btrfs_start_transaction(root, 0);
 	if (!IS_ERR(trans))
-		btrfs_commit_transaction(trans, root);
+		btrfs_commit_transaction(trans);
 
 	mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
 
@@ -716,7 +716,7 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 		mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
 		return PTR_ERR(trans);
 	}
-	ret = btrfs_commit_transaction(trans, root);
+	ret = btrfs_commit_transaction(trans);
 	WARN_ON(ret);
 	if (tgt_device)
 		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index f60be47..153e03e 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1874,7 +1874,7 @@ sleep:
 	} else {
 		int ret;
 
-		ret = btrfs_commit_transaction(trans, root);
+		ret = btrfs_commit_transaction(trans);
 		if (ret)
 			btrfs_err(fs_info,
 				  "cleaner open transaction commit returned %d",
@@ -1926,7 +1926,7 @@ static int transaction_kthread(void *arg)
 			goto sleep;
 		}
 		if (transid == trans->transid) {
-			btrfs_commit_transaction(trans, root);
+			btrfs_commit_transaction(trans);
 		} else {
 			btrfs_end_transaction(trans, root);
 		}
@@ -3848,7 +3848,7 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info)
 	trans = btrfs_join_transaction(root);
 	if (IS_ERR(trans))
 		return PTR_ERR(trans);
-	return btrfs_commit_transaction(trans, root);
+	return btrfs_commit_transaction(trans);
 }
 
 void close_ctree(struct btrfs_fs_info *fs_info)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 778ef17..31478eb 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4204,7 +4204,7 @@ commit_trans:
 			    test_bit(BTRFS_TRANS_HAVE_FREE_BGS,
 				     &trans->transaction->flags) ||
 			    need_commit > 0) {
-				ret = btrfs_commit_transaction(trans, root);
+				ret = btrfs_commit_transaction(trans);
 				if (ret)
 					return ret;
 				/*
@@ -4785,7 +4785,7 @@ commit:
 	if (IS_ERR(trans))
 		return -ENOSPC;
 
-	return btrfs_commit_transaction(trans, root);
+	return btrfs_commit_transaction(trans);
 }
 
 enum flush_state {
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 51f77a2..5fa030f 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2129,7 +2129,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 				goto out;
 			}
 		}
-		ret = btrfs_commit_transaction(trans, root);
+		ret = btrfs_commit_transaction(trans);
 	} else {
 		ret = btrfs_end_transaction(trans, root);
 	}
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index 58daa0e..671865b 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -1187,7 +1187,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
 	btrfs_set_fs_compat_ro(fs_info, FREE_SPACE_TREE);
 	fs_info->creating_free_space_tree = 0;
 
-	ret = btrfs_commit_transaction(trans, tree_root);
+	ret = btrfs_commit_transaction(trans);
 	if (ret)
 		return ret;
 
@@ -1275,7 +1275,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
 	free_extent_buffer(free_space_root->commit_root);
 	kfree(free_space_root);
 
-	ret = btrfs_commit_transaction(trans, tree_root);
+	ret = btrfs_commit_transaction(trans);
 	if (ret)
 		return ret;
 
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 37ef685..4600e93 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5296,7 +5296,7 @@ void btrfs_evict_inode(struct inode *inode)
 		 * again.
 		 */
 		if (ret) {
-			ret = btrfs_commit_transaction(trans, root);
+			ret = btrfs_commit_transaction(trans);
 			if (ret) {
 				btrfs_orphan_del(NULL, inode);
 				btrfs_free_block_rsv(fs_info, rsv);
@@ -5972,7 +5972,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
 			trans = btrfs_join_transaction(root);
 		if (IS_ERR(trans))
 			return PTR_ERR(trans);
-		ret = btrfs_commit_transaction(trans, root);
+		ret = btrfs_commit_transaction(trans);
 	}
 	return ret;
 }
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 50fc151..04e8061 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -623,9 +623,9 @@ fail:
 		*async_transid = trans->transid;
 		err = btrfs_commit_transaction_async(trans, root, 1);
 		if (err)
-			err = btrfs_commit_transaction(trans, root);
+			err = btrfs_commit_transaction(trans);
 	} else {
-		err = btrfs_commit_transaction(trans, root);
+		err = btrfs_commit_transaction(trans);
 	}
 	if (err && !ret)
 		ret = err;
@@ -732,12 +732,11 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
 	if (async_transid) {
 		*async_transid = trans->transid;
 		ret = btrfs_commit_transaction_async(trans,
-				     fs_info->extent_root, 1);
+						     fs_info->extent_root, 1);
 		if (ret)
-			ret = btrfs_commit_transaction(trans, root);
+			ret = btrfs_commit_transaction(trans);
 	} else {
-		ret = btrfs_commit_transaction(trans,
-					       fs_info->extent_root);
+		ret = btrfs_commit_transaction(trans);
 	}
 	if (ret)
 		goto fail;
@@ -1619,7 +1618,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
 			goto out_free;
 		}
 		ret = btrfs_grow_device(trans, device, new_size);
-		btrfs_commit_transaction(trans, root);
+		btrfs_commit_transaction(trans);
 	} else if (new_size < old_size) {
 		ret = btrfs_shrink_device(device, new_size);
 	} /* equal, nothing need to do */
@@ -1868,7 +1867,7 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
 	ret = btrfs_update_root(trans, fs_info->tree_root,
 				&root->root_key, &root->root_item);
 
-	btrfs_commit_transaction(trans, root);
+	btrfs_commit_transaction(trans);
 out_reset:
 	if (ret)
 		btrfs_set_root_flags(&root->root_item, root_flags);
@@ -4875,7 +4874,7 @@ static long btrfs_ioctl_quota_ctl(struct file *file, void __user *arg)
 		break;
 	}
 
-	err = btrfs_commit_transaction(trans, fs_info->tree_root);
+	err = btrfs_commit_transaction(trans);
 	if (err && !ret)
 		ret = err;
 out:
@@ -5189,7 +5188,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,
 			goto out;
 		}
 	}
-	ret = btrfs_commit_transaction(trans, root);
+	ret = btrfs_commit_transaction(trans);
 	if (ret < 0) {
 		btrfs_abort_transaction(trans, ret);
 		goto out;
@@ -5343,7 +5342,7 @@ static int btrfs_ioctl_set_fslabel(struct file *file, void __user *arg)
 	spin_lock(&fs_info->super_lock);
 	strcpy(super_block->label, label);
 	spin_unlock(&fs_info->super_lock);
-	ret = btrfs_commit_transaction(trans, root);
+	ret = btrfs_commit_transaction(trans);
 
 out_unlock:
 	mnt_drop_write_file(file);
@@ -5515,7 +5514,7 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg)
 	btrfs_set_super_incompat_flags(super_block, newflags);
 	spin_unlock(&fs_info->super_lock);
 
-	ret = btrfs_commit_transaction(trans, root);
+	ret = btrfs_commit_transaction(trans);
 out_drop_write:
 	mnt_drop_write_file(file);
 
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 6d45fb4..b00c2ea 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2319,7 +2319,7 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
 			err = qgroup_rescan_leaf(fs_info, path, trans);
 		}
 		if (err > 0)
-			btrfs_commit_transaction(trans, fs_info->fs_root);
+			btrfs_commit_transaction(trans);
 		else
 			btrfs_end_transaction(trans, fs_info->fs_root);
 	}
@@ -2472,7 +2472,7 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info)
 		fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
 		return PTR_ERR(trans);
 	}
-	ret = btrfs_commit_transaction(trans, fs_info->fs_root);
+	ret = btrfs_commit_transaction(trans);
 	if (ret) {
 		fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
 		return ret;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index a2ca2f0..d64a805 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2342,7 +2342,7 @@ again:
 	list_splice(&reloc_roots, &rc->reloc_roots);
 
 	if (!err)
-		btrfs_commit_transaction(trans, rc->extent_root);
+		btrfs_commit_transaction(trans);
 	else
 		btrfs_end_transaction(trans, rc->extent_root);
 	return err;
@@ -3917,7 +3917,7 @@ int prepare_to_relocate(struct reloc_control *rc)
 		 */
 		return PTR_ERR(trans);
 	}
-	btrfs_commit_transaction(trans, rc->extent_root);
+	btrfs_commit_transaction(trans);
 	return 0;
 }
 
@@ -4111,7 +4111,7 @@ restart:
 	if (IS_ERR(trans))
 		err = PTR_ERR(trans);
 	else
-		btrfs_commit_transaction(trans, rc->extent_root);
+		btrfs_commit_transaction(trans);
 out_free:
 	btrfs_free_block_rsv(fs_info, rc->block_rsv);
 	btrfs_free_path(path);
@@ -4465,7 +4465,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
 		fs_root->reloc_root = reloc_root;
 	}
 
-	err = btrfs_commit_transaction(trans, rc->extent_root);
+	err = btrfs_commit_transaction(trans);
 	if (err)
 		goto out_free;
 
@@ -4477,7 +4477,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
 	if (IS_ERR(trans))
 		err = PTR_ERR(trans);
 	else
-		err = btrfs_commit_transaction(trans, rc->extent_root);
+		err = btrfs_commit_transaction(trans);
 out_free:
 	kfree(rc);
 out:
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 5b0fcc9..c98b91b 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3612,8 +3612,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 				if (IS_ERR(trans))
 					ret = PTR_ERR(trans);
 				else
-					ret = btrfs_commit_transaction(trans,
-								       root);
+					ret = btrfs_commit_transaction(trans);
 				if (ret) {
 					scrub_pause_off(fs_info);
 					btrfs_put_block_group(cache);
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 5f4f853..cd0a052 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -5911,7 +5911,7 @@ commit_trans:
 		goto again;
 	}
 
-	return btrfs_commit_transaction(trans, sctx->send_root);
+	return btrfs_commit_transaction(trans);
 }
 
 static void btrfs_root_dec_send_in_progress(struct btrfs_root* root)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 3a160e1..d407826 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1188,7 +1188,7 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
 		if (IS_ERR(trans))
 			return PTR_ERR(trans);
 	}
-	return btrfs_commit_transaction(trans, root);
+	return btrfs_commit_transaction(trans);
 }
 
 static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
@@ -2228,7 +2228,7 @@ static int btrfs_freeze(struct super_block *sb)
 			return 0;
 		return PTR_ERR(trans);
 	}
-	return btrfs_commit_transaction(trans, root);
+	return btrfs_commit_transaction(trans);
 }
 
 static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 57d3187..a546c08 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -580,7 +580,7 @@ again:
 	if (cur_trans->state >= TRANS_STATE_BLOCKED &&
 	    may_wait_transaction(fs_info, type)) {
 		current->journal_info = h;
-		btrfs_commit_transaction(h, root);
+		btrfs_commit_transaction(h);
 		goto again;
 	}
 
@@ -877,7 +877,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
 
 	if (lock && ACCESS_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) {
 		if (throttle)
-			return btrfs_commit_transaction(trans, root);
+			return btrfs_commit_transaction(trans);
 		else
 			wake_up_process(info->transaction_kthread);
 	}
@@ -1798,7 +1798,7 @@ static void do_async_commit(struct work_struct *work)
 
 	current->journal_info = ac->newtrans;
 
-	btrfs_commit_transaction(ac->newtrans, ac->root);
+	btrfs_commit_transaction(ac->newtrans);
 	kfree(ac);
 }
 
@@ -1924,9 +1924,9 @@ btrfs_wait_pending_ordered(struct btrfs_transaction *cur_trans)
 		   atomic_read(&cur_trans->pending_ordered) == 0);
 }
 
-int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
-			     struct btrfs_root *root)
+int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 {
+	struct btrfs_root *root = trans->root;
 	struct btrfs_fs_info *fs_info = root->fs_info;
 	struct btrfs_transaction *cur_trans = trans->transaction;
 	struct btrfs_transaction *prev_trans = NULL;
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index 8bcf529..7d3b358 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -206,8 +206,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid);
 void btrfs_add_dead_root(struct btrfs_root *root);
 int btrfs_defrag_root(struct btrfs_root *root);
 int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root);
-int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
-			     struct btrfs_root *root);
+int btrfs_commit_transaction(struct btrfs_trans_handle *trans);
 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
 				   struct btrfs_root *root,
 				   int wait_for_unblock);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 945f02c..e714eb5 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -5614,7 +5614,7 @@ again:
 	btrfs_free_path(path);
 
 	/* step 4: commit the transaction, which also unpins the blocks */
-	ret = btrfs_commit_transaction(trans, fs_info->tree_root);
+	ret = btrfs_commit_transaction(trans);
 	if (ret)
 		return ret;
 
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index fadb37f..5953948 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1717,7 +1717,7 @@ static int btrfs_rm_dev_item(struct btrfs_fs_info *fs_info,
 		goto out;
 out:
 	btrfs_free_path(path);
-	btrfs_commit_transaction(trans, root);
+	btrfs_commit_transaction(trans);
 	return ret;
 }
 
@@ -2428,7 +2428,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
 
 	fs_info->num_tolerated_disk_barrier_failures =
 		btrfs_calc_num_tolerated_disk_barrier_failures(fs_info);
-	ret = btrfs_commit_transaction(trans, root);
+	ret = btrfs_commit_transaction(trans);
 
 	if (seeding_dev) {
 		mutex_unlock(&uuid_mutex);
@@ -2449,7 +2449,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
 				return 0;
 			return PTR_ERR(trans);
 		}
-		ret = btrfs_commit_transaction(trans, root);
+		ret = btrfs_commit_transaction(trans);
 	}
 
 	/* Update ctime/mtime for libblkid */
@@ -3020,7 +3020,7 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
 	btrfs_mark_buffer_dirty(leaf);
 out:
 	btrfs_free_path(path);
-	err = btrfs_commit_transaction(trans, root);
+	err = btrfs_commit_transaction(trans);
 	if (err && !ret)
 		ret = err;
 	return ret;
@@ -3059,7 +3059,7 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
 	ret = btrfs_del_item(trans, root, path);
 out:
 	btrfs_free_path(path);
-	err = btrfs_commit_transaction(trans, root);
+	err = btrfs_commit_transaction(trans);
 	if (err && !ret)
 		ret = err;
 	return ret;
@@ -4239,7 +4239,7 @@ int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info)
 
 	fs_info->uuid_root = uuid_root;
 
-	ret = btrfs_commit_transaction(trans, tree_root);
+	ret = btrfs_commit_transaction(trans);
 	if (ret)
 		return ret;
 
@@ -4411,7 +4411,7 @@ again:
 			checked_pending_chunks = true;
 			failed = 0;
 			retried = false;
-			ret = btrfs_commit_transaction(trans, root);
+			ret = btrfs_commit_transaction(trans);
 			if (ret)
 				goto done;
 			goto again;
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 31/31] btrfs: root->fs_info cleanup, btrfs_end_transaction{,_throttle} use trans->fs_info instead of parameter
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (26 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 30/31] btrfs: root->fs_info cleanup, btrfs_commit_transaction already has root jeffm
@ 2016-06-24 22:15 ` jeffm
  2016-06-26 13:50 ` [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers Jeff Mahoney
                   ` (3 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: jeffm @ 2016-06-24 22:15 UTC (permalink / raw)
  To: linux-btrfs

From: Jeff Mahoney <jeffm@suse.com>

Without btrfs_commit_transaction accepting a root parameter,
__btrfs_end_transaction doesn't consume one anymore.

In theory, we still accept it to compare that the root we used to start
the transaction is the same one we used to end it.  In practice, the
check doesn't exist.  There was one case where we were passing different
roots but that was fixed in an earlier patch.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/backref.c         |  2 +-
 fs/btrfs/delayed-inode.c   |  4 +--
 fs/btrfs/disk-io.c         |  2 +-
 fs/btrfs/extent-tree.c     | 25 ++++++++---------
 fs/btrfs/file.c            | 18 ++++++------
 fs/btrfs/free-space-tree.c |  4 +--
 fs/btrfs/inode.c           | 68 +++++++++++++++++++++++-----------------------
 fs/btrfs/ioctl.c           | 37 ++++++++++++-------------
 fs/btrfs/qgroup.c          |  4 +--
 fs/btrfs/relocation.c      | 20 +++++++-------
 fs/btrfs/root-tree.c       |  2 +-
 fs/btrfs/scrub.c           |  6 ++--
 fs/btrfs/send.c            |  2 +-
 fs/btrfs/transaction.c     | 30 ++++++++++----------
 fs/btrfs/transaction.h     |  6 ++--
 fs/btrfs/tree-log.c        |  2 +-
 fs/btrfs/uuid-tree.c       |  2 +-
 fs/btrfs/volumes.c         | 16 +++++------
 fs/btrfs/xattr.c           |  2 +-
 19 files changed, 123 insertions(+), 129 deletions(-)

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 1d2c742..5c9505a0 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -1706,7 +1706,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
 out:
 	if (!search_commit_root) {
 		btrfs_put_tree_mod_seq(fs_info, &tree_mod_seq_elem);
-		btrfs_end_transaction(trans, fs_info->extent_root);
+		btrfs_end_transaction(trans);
 	} else {
 		up_read(&fs_info->commit_root_sem);
 	}
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index ca56a8d..9535b5d 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1301,7 +1301,7 @@ int btrfs_commit_inode_delayed_inode(struct inode *inode)
 	btrfs_free_path(path);
 	trans->block_rsv = block_rsv;
 trans_out:
-	btrfs_end_transaction(trans, delayed_node->root);
+	btrfs_end_transaction(trans);
 	btrfs_btree_balance_dirty(fs_info);
 out:
 	btrfs_release_delayed_node(delayed_node);
@@ -1366,7 +1366,7 @@ again:
 	__btrfs_commit_inode_delayed_items(trans, path, delayed_node);
 
 	trans->block_rsv = block_rsv;
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	btrfs_btree_balance_dirty_nodelay(root->fs_info);
 
 release_path:
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 153e03e..59e5f1e 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1928,7 +1928,7 @@ static int transaction_kthread(void *arg)
 		if (transid == trans->transid) {
 			btrfs_commit_transaction(trans);
 		} else {
-			btrfs_end_transaction(trans, root);
+			btrfs_end_transaction(trans);
 		}
 sleep:
 		wake_up_process(fs_info->cleaner_kthread);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 31478eb..304e46d 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2849,7 +2849,7 @@ static void delayed_ref_async_start(struct btrfs_work *work)
 	if (ret)
 		async->error = ret;
 
-	ret = btrfs_end_transaction(trans, async->root);
+	ret = btrfs_end_transaction(trans);
 	if (ret && !async->error)
 		async->error = ret;
 done:
@@ -4159,7 +4159,7 @@ alloc:
 
 			ret = do_chunk_alloc(trans, fs_info, alloc_target,
 					     CHUNK_ALLOC_NO_FORCE);
-			btrfs_end_transaction(trans, root);
+			btrfs_end_transaction(trans);
 			if (ret < 0) {
 				if (ret != -ENOSPC)
 					return ret;
@@ -4216,7 +4216,7 @@ commit_trans:
 				mutex_unlock(&fs_info->cleaner_delayed_iput_mutex);
 				goto again;
 			} else {
-				btrfs_end_transaction(trans, root);
+				btrfs_end_transaction(trans);
 			}
 		}
 
@@ -4820,7 +4820,7 @@ static int flush_space(struct btrfs_root *root,
 			break;
 		}
 		ret = btrfs_run_delayed_items_nr(trans, fs_info, nr);
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		break;
 	case FLUSH_DELALLOC:
 	case FLUSH_DELALLOC_WAIT:
@@ -4836,7 +4836,7 @@ static int flush_space(struct btrfs_root *root,
 		ret = do_chunk_alloc(trans, fs_info,
 				     btrfs_get_alloc_profile(root, 0),
 				     CHUNK_ALLOC_NO_FORCE);
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		if (ret == -ENOSPC)
 			ret = 0;
 		break;
@@ -7629,7 +7629,7 @@ loop:
 			else
 				ret = 0;
 			if (!exist)
-				btrfs_end_transaction(trans, root);
+				btrfs_end_transaction(trans);
 			if (ret)
 				goto out;
 		}
@@ -9118,7 +9118,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 				goto out_end_trans;
 			}
 
-			btrfs_end_transaction_throttle(trans, tree_root);
+			btrfs_end_transaction_throttle(trans);
 			if (!for_reloc && btrfs_need_cleaner_sleep(fs_info)) {
 				pr_debug("BTRFS: drop snapshot early exit\n");
 				err = -EAGAIN;
@@ -9171,7 +9171,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	}
 	root_dropped = true;
 out_end_trans:
-	btrfs_end_transaction_throttle(trans, tree_root);
+	btrfs_end_transaction_throttle(trans);
 out_free:
 	kfree(wc);
 	btrfs_free_path(path);
@@ -9380,7 +9380,7 @@ again:
 		u64 transid = trans->transid;
 
 		mutex_unlock(&fs_info->ro_block_group_mutex);
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 
 		ret = btrfs_wait_for_commit(fs_info, transid);
 		if (ret)
@@ -9425,7 +9425,7 @@ out:
 	}
 	mutex_unlock(&fs_info->ro_block_group_mutex);
 
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	return ret;
 }
 
@@ -9644,7 +9644,7 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr)
 			   "no space to allocate a new chunk for block group %llu",
 			   block_group->key.objectid);
 	mutex_unlock(&fs_info->chunk_mutex);
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 out:
 	btrfs_put_block_group(block_group);
 	return ret;
@@ -10566,7 +10566,6 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_block_group_cache *block_group;
 	struct btrfs_space_info *space_info;
-	struct btrfs_root *root = fs_info->extent_root;
 	struct btrfs_trans_handle *trans;
 	int ret = 0;
 
@@ -10717,7 +10716,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
 			btrfs_get_block_group(block_group);
 		}
 end_trans:
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 next:
 		mutex_unlock(&fs_info->delete_unused_bgs_mutex);
 		btrfs_put_block_group(block_group);
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 5fa030f..34d54d9 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2109,7 +2109,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 	 * which are indicated by ctx.io_err.
 	 */
 	if (ctx.io_err) {
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		ret = ctx.io_err;
 		goto out;
 	}
@@ -2118,20 +2118,20 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 		if (!ret) {
 			ret = btrfs_sync_log(trans, root, &ctx);
 			if (!ret) {
-				ret = btrfs_end_transaction(trans, root);
+				ret = btrfs_end_transaction(trans);
 				goto out;
 			}
 		}
 		if (!full_sync) {
 			ret = btrfs_wait_ordered_range(inode, start, len);
 			if (ret) {
-				btrfs_end_transaction(trans, root);
+				btrfs_end_transaction(trans);
 				goto out;
 			}
 		}
 		ret = btrfs_commit_transaction(trans);
 	} else {
-		ret = btrfs_end_transaction(trans, root);
+		ret = btrfs_end_transaction(trans);
 	}
 out:
 	return ret > 0 ? -EIO : ret;
@@ -2524,7 +2524,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
 			break;
 		}
 
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		btrfs_btree_balance_dirty(fs_info);
 
 		trans = btrfs_start_transaction(root, rsv_count);
@@ -2590,7 +2590,7 @@ out_trans:
 	trans->block_rsv = &fs_info->trans_block_rsv;
 	ret = btrfs_update_inode(trans, root, inode);
 	updated_inode = true;
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	btrfs_btree_balance_dirty(fs_info);
 out_free:
 	btrfs_free_path(path);
@@ -2612,7 +2612,7 @@ out_only_mutex:
 			err = PTR_ERR(trans);
 		} else {
 			err = btrfs_update_inode(trans, root, inode);
-			ret = btrfs_end_transaction(trans, root);
+			ret = btrfs_end_transaction(trans);
 		}
 	}
 	inode_unlock(inode);
@@ -2843,9 +2843,9 @@ static long btrfs_fallocate(struct file *file, int mode,
 			btrfs_ordered_update_i_size(inode, actual_end, NULL);
 			ret = btrfs_update_inode(trans, root, inode);
 			if (ret)
-				btrfs_end_transaction(trans, root);
+				btrfs_end_transaction(trans);
 			else
-				ret = btrfs_end_transaction(trans, root);
+				ret = btrfs_end_transaction(trans);
 		}
 	}
 out_unlock:
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index 671865b..73918e9 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -1196,7 +1196,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
 abort:
 	fs_info->creating_free_space_tree = 0;
 	btrfs_abort_transaction(trans, ret);
-	btrfs_end_transaction(trans, tree_root);
+	btrfs_end_transaction(trans);
 	return ret;
 }
 
@@ -1283,7 +1283,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
 
 abort:
 	btrfs_abort_transaction(trans, ret);
-	btrfs_end_transaction(trans, tree_root);
+	btrfs_end_transaction(trans);
 	return ret;
 }
 
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 4600e93..c45570e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -325,7 +325,7 @@ out:
 	 */
 	btrfs_qgroup_free_data(inode, 0, PAGE_SIZE);
 	btrfs_free_path(path);
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	return ret;
 }
 
@@ -1516,7 +1516,7 @@ out_check:
 	}
 
 error:
-	err = btrfs_end_transaction(trans, root);
+	err = btrfs_end_transaction(trans);
 	if (!ret)
 		ret = err;
 
@@ -2640,7 +2640,7 @@ again:
 out_free_path:
 	btrfs_release_path(path);
 	path->leave_spinning = 0;
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 out_unlock:
 	unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, lock_end,
 			     &cached, GFP_NOFS);
@@ -2986,7 +2986,7 @@ out:
 	if (root != fs_info->tree_root)
 		btrfs_delalloc_release_metadata(inode, ordered_extent->len);
 	if (trans)
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 
 	if (ret || truncated) {
 		u64 start, end;
@@ -3494,7 +3494,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
 				    found_key.objectid);
 			ret = btrfs_del_orphan_item(trans, root,
 						    found_key.objectid);
-			btrfs_end_transaction(trans, root);
+			btrfs_end_transaction(trans);
 			if (ret)
 				goto out;
 			continue;
@@ -3524,7 +3524,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
 				goto out;
 			}
 			ret = btrfs_orphan_add(trans, inode);
-			btrfs_end_transaction(trans, root);
+			btrfs_end_transaction(trans);
 			if (ret) {
 				iput(inode);
 				goto out;
@@ -3555,7 +3555,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
 	    test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state)) {
 		trans = btrfs_join_transaction(root);
 		if (!IS_ERR(trans))
-			btrfs_end_transaction(trans, root);
+			btrfs_end_transaction(trans);
 	}
 
 	if (nr_unlink)
@@ -4125,7 +4125,7 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
 	}
 
 out:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	btrfs_btree_balance_dirty(root->fs_info);
 	return ret;
 }
@@ -4245,7 +4245,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
 	if (!err)
 		btrfs_i_size_write(inode, 0);
 out:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	btrfs_btree_balance_dirty(root->fs_info);
 
 	return err;
@@ -4806,7 +4806,7 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode,
 	ret = btrfs_drop_extents(trans, root, inode, offset, offset + len, 1);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		return ret;
 	}
 
@@ -4816,7 +4816,7 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode,
 		btrfs_abort_transaction(trans, ret);
 	else
 		btrfs_update_inode(trans, root, inode);
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	return ret;
 }
 
@@ -4980,7 +4980,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
 		pagecache_isize_extended(inode, oldsize, newsize);
 		ret = btrfs_update_inode(trans, root, inode);
 		btrfs_end_write_no_snapshoting(root);
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 	} else {
 
 		/*
@@ -5011,7 +5011,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
 		 * will be consistent.
 		 */
 		ret = btrfs_orphan_add(trans, inode);
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		if (ret)
 			return ret;
 
@@ -5042,7 +5042,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
 			err = btrfs_orphan_del(trans, inode);
 			if (err)
 				btrfs_abort_transaction(trans, err);
-			btrfs_end_transaction(trans, root);
+			btrfs_end_transaction(trans);
 		}
 	}
 
@@ -5314,7 +5314,7 @@ void btrfs_evict_inode(struct inode *inode)
 			break;
 
 		trans->block_rsv = &fs_info->trans_block_rsv;
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		trans = NULL;
 		btrfs_btree_balance_dirty(fs_info);
 	}
@@ -5337,7 +5337,7 @@ void btrfs_evict_inode(struct inode *inode)
 	      root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID))
 		btrfs_return_ino(root, btrfs_ino(inode));
 
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	btrfs_btree_balance_dirty(fs_info);
 no_delete:
 	btrfs_remove_delayed_node(inode);
@@ -6000,14 +6000,14 @@ static int btrfs_dirty_inode(struct inode *inode)
 	ret = btrfs_update_inode(trans, root, inode);
 	if (ret && ret == -ENOSPC) {
 		/* whoops, lets try again with the full transaction */
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		trans = btrfs_start_transaction(root, 1);
 		if (IS_ERR(trans))
 			return PTR_ERR(trans);
 
 		ret = btrfs_update_inode(trans, root, inode);
 	}
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	if (BTRFS_I(inode)->delayed_node)
 		btrfs_balance_delayed_items(fs_info);
 
@@ -6445,7 +6445,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
 	}
 
 out_unlock:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	btrfs_balance_delayed_items(fs_info);
 	btrfs_btree_balance_dirty(fs_info);
 	if (drop_inode) {
@@ -6521,7 +6521,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
 	d_instantiate(dentry, inode);
 
 out_unlock:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	if (err && drop_inode_on_err) {
 		inode_dec_link_count(inode);
 		iput(inode);
@@ -6603,7 +6603,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
 	btrfs_balance_delayed_items(fs_info);
 fail:
 	if (trans)
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 	if (drop_inode) {
 		inode_dec_link_count(inode);
 		iput(inode);
@@ -6672,7 +6672,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 	drop_on_err = 0;
 
 out_fail:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	if (drop_on_err) {
 		inode_dec_link_count(inode);
 		iput(inode);
@@ -7060,7 +7060,7 @@ out:
 
 	btrfs_free_path(path);
 	if (trans) {
-		ret = btrfs_end_transaction(trans, root);
+		ret = btrfs_end_transaction(trans);
 		if (!err)
 			err = ret;
 	}
@@ -7384,7 +7384,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
 
 	ret = btrfs_cross_ref_exist(trans, root, btrfs_ino(inode),
 				    key.offset - backref_offset, disk_bytenr);
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	if (ret) {
 		ret = 0;
 		goto out;
@@ -9180,7 +9180,7 @@ static int btrfs_truncate(struct inode *inode)
 			break;
 		}
 
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		btrfs_btree_balance_dirty(fs_info);
 
 		trans = btrfs_start_transaction(root, 2);
@@ -9209,7 +9209,7 @@ static int btrfs_truncate(struct inode *inode)
 		if (ret && !err)
 			err = ret;
 
-		ret = btrfs_end_transaction(trans, root);
+		ret = btrfs_end_transaction(trans);
 		btrfs_btree_balance_dirty(fs_info);
 	}
 
@@ -9678,7 +9678,7 @@ out_fail:
 			dest_log_pinned = false;
 		}
 	}
-	ret = btrfs_end_transaction(trans, root);
+	ret = btrfs_end_transaction(trans);
 out_notrans:
 	if (new_ino == BTRFS_FIRST_FREE_OBJECTID)
 		up_read(&fs_info->subvol_sem);
@@ -9948,7 +9948,7 @@ out_fail:
 		btrfs_end_log_trans(root);
 		log_pinned = false;
 	}
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 out_notrans:
 	if (old_ino == BTRFS_FIRST_FREE_OBJECTID)
 		up_read(&fs_info->subvol_sem);
@@ -10281,7 +10281,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
 	d_instantiate(dentry, inode);
 
 out_unlock:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	if (drop_inode) {
 		inode_dec_link_count(inode);
 		iput(inode);
@@ -10336,7 +10336,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
 					   *alloc_hint, &ins, 1, 0);
 		if (ret) {
 			if (own_trans)
-				btrfs_end_transaction(trans, root);
+				btrfs_end_transaction(trans);
 			break;
 		}
 		btrfs_dec_block_group_reservations(fs_info, ins.objectid);
@@ -10352,7 +10352,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
 						   ins.offset, 0);
 			btrfs_abort_transaction(trans, ret);
 			if (own_trans)
-				btrfs_end_transaction(trans, root);
+				btrfs_end_transaction(trans);
 			break;
 		}
 
@@ -10412,12 +10412,12 @@ next:
 		if (ret) {
 			btrfs_abort_transaction(trans, ret);
 			if (own_trans)
-				btrfs_end_transaction(trans, root);
+				btrfs_end_transaction(trans);
 			break;
 		}
 
 		if (own_trans)
-			btrfs_end_transaction(trans, root);
+			btrfs_end_transaction(trans);
 	}
 	return ret;
 }
@@ -10519,7 +10519,7 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
 	mark_inode_dirty(inode);
 
 out:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	if (ret)
 		iput(inode);
 	btrfs_balance_delayed_items(fs_info);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 04e8061..3d402dd 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -353,7 +353,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 	inode->i_ctime = current_fs_time(inode->i_sb);
 	ret = btrfs_update_inode(trans, root, inode);
 
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
  out_drop:
 	if (ret) {
 		ip->flags = ip_oldflags;
@@ -2542,7 +2542,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 out_end_trans:
 	trans->block_rsv = NULL;
 	trans->bytes_reserved = 0;
-	ret = btrfs_end_transaction(trans, root);
+	ret = btrfs_end_transaction(trans);
 	if (ret && !err)
 		err = ret;
 	inode->i_flags |= S_DEAD;
@@ -3302,10 +3302,10 @@ static int clone_finish_inode_update(struct btrfs_trans_handle *trans,
 	ret = btrfs_update_inode(trans, root, inode);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		goto out;
 	}
-	ret = btrfs_end_transaction(trans, root);
+	ret = btrfs_end_transaction(trans);
 out:
 	return ret;
 }
@@ -3706,7 +3706,7 @@ process_slot:
 					if (ret != -EOPNOTSUPP)
 						btrfs_abort_transaction(trans,
 									ret);
-					btrfs_end_transaction(trans, root);
+					btrfs_end_transaction(trans);
 					goto out;
 				}
 
@@ -3714,7 +3714,7 @@ process_slot:
 							      &new_key, size);
 				if (ret) {
 					btrfs_abort_transaction(trans, ret);
-					btrfs_end_transaction(trans, root);
+					btrfs_end_transaction(trans);
 					goto out;
 				}
 
@@ -3747,8 +3747,7 @@ process_slot:
 					if (ret) {
 						btrfs_abort_transaction(trans,
 									ret);
-						btrfs_end_transaction(trans,
-								      root);
+						btrfs_end_transaction(trans);
 						goto out;
 
 					}
@@ -3767,7 +3766,7 @@ process_slot:
 
 				if (comp && (skip || trim)) {
 					ret = -EINVAL;
-					btrfs_end_transaction(trans, root);
+					btrfs_end_transaction(trans);
 					goto out;
 				}
 				size -= skip + trim;
@@ -3783,7 +3782,7 @@ process_slot:
 					if (ret != -EOPNOTSUPP)
 						btrfs_abort_transaction(trans,
 									ret);
-					btrfs_end_transaction(trans, root);
+					btrfs_end_transaction(trans);
 					goto out;
 				}
 				leaf = path->nodes[0];
@@ -3838,7 +3837,7 @@ process_slot:
 		if (ret) {
 			if (ret != -EOPNOTSUPP)
 				btrfs_abort_transaction(trans, ret);
-			btrfs_end_transaction(trans, root);
+			btrfs_end_transaction(trans);
 			goto out;
 		}
 		clone_update_extent_map(inode, trans, NULL, last_dest_end,
@@ -4100,7 +4099,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
 				   dir_id, "default", 7, 1);
 	if (IS_ERR_OR_NULL(di)) {
 		btrfs_free_path(path);
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		btrfs_err(fs_info,
 			  "Umm, you don't have the default dir item, this isn't going to work");
 		ret = -ENOENT;
@@ -4113,7 +4112,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
 	btrfs_free_path(path);
 
 	btrfs_set_fs_incompat(fs_info, DEFAULT_SUBVOL);
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 out:
 	mnt_drop_write_file(file);
 	return ret;
@@ -4293,7 +4292,7 @@ long btrfs_ioctl_trans_end(struct file *file)
 		return -EINVAL;
 	file->private_data = NULL;
 
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 
 	atomic_dec(&root->fs_info->open_ioctl_trans);
 
@@ -4320,7 +4319,7 @@ static noinline long btrfs_ioctl_start_sync(struct btrfs_root *root,
 	transid = trans->transid;
 	ret = btrfs_commit_transaction_async(trans, root, 0);
 	if (ret) {
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		return ret;
 	}
 out:
@@ -4928,7 +4927,7 @@ static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)
 	if (err < 0)
 		btrfs_handle_fs_error(fs_info, err,
 				      "failed to update qgroup status and info");
-	err = btrfs_end_transaction(trans, root);
+	err = btrfs_end_transaction(trans);
 	if (err && !ret)
 		ret = err;
 
@@ -4980,7 +4979,7 @@ static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg)
 		ret = btrfs_remove_qgroup(trans, fs_info, sa->qgroupid);
 	}
 
-	err = btrfs_end_transaction(trans, root);
+	err = btrfs_end_transaction(trans);
 	if (err && !ret)
 		ret = err;
 
@@ -5030,7 +5029,7 @@ static long btrfs_ioctl_qgroup_limit(struct file *file, void __user *arg)
 	/* FIXME: check if the IDs really exist */
 	ret = btrfs_limit_qgroup(trans, fs_info, qgroupid, &sa->lim);
 
-	err = btrfs_end_transaction(trans, root);
+	err = btrfs_end_transaction(trans);
 	if (err && !ret)
 		ret = err;
 
@@ -5176,7 +5175,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,
 	ret = btrfs_update_root(trans, fs_info->tree_root,
 				&root->root_key, &root->root_item);
 	if (ret < 0) {
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		goto out;
 	}
 	if (received_uuid_changed && !btrfs_is_empty_uuid(sa->uuid)) {
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index b00c2ea..c9a1ce4 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2321,7 +2321,7 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
 		if (err > 0)
 			btrfs_commit_transaction(trans);
 		else
-			btrfs_end_transaction(trans, fs_info->fs_root);
+			btrfs_end_transaction(trans);
 	}
 
 out:
@@ -2356,7 +2356,7 @@ out:
 		err = ret;
 		btrfs_err(fs_info, "fail to update qgroup status: %d\n", err);
 	}
-	btrfs_end_transaction(trans, fs_info->quota_root);
+	btrfs_end_transaction(trans);
 
 	if (btrfs_fs_closing(fs_info)) {
 		btrfs_info(fs_info, "qgroup scan paused");
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index d64a805..930d09c 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2234,7 +2234,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
 			       path->slots[level]);
 		root_item->drop_level = level;
 
-		btrfs_end_transaction_throttle(trans, root);
+		btrfs_end_transaction_throttle(trans);
 		trans = NULL;
 
 		btrfs_btree_balance_dirty(fs_info);
@@ -2265,7 +2265,7 @@ out:
 	}
 
 	if (trans)
-		btrfs_end_transaction_throttle(trans, root);
+		btrfs_end_transaction_throttle(trans);
 
 	btrfs_btree_balance_dirty(fs_info);
 
@@ -2310,7 +2310,7 @@ again:
 
 	if (!err) {
 		if (num_bytes != rc->merging_rsv_size) {
-			btrfs_end_transaction(trans, rc->extent_root);
+			btrfs_end_transaction(trans);
 			btrfs_block_rsv_release(fs_info, rc->block_rsv,
 						num_bytes);
 			goto again;
@@ -2344,7 +2344,7 @@ again:
 	if (!err)
 		btrfs_commit_transaction(trans);
 	else
-		btrfs_end_transaction(trans, rc->extent_root);
+		btrfs_end_transaction(trans);
 	return err;
 }
 
@@ -3492,7 +3492,7 @@ truncate:
 
 	ret = btrfs_truncate_free_space_cache(root, trans, block_group, inode);
 
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	btrfs_btree_balance_dirty(fs_info);
 out:
 	iput(inode);
@@ -3964,7 +3964,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
 		}
 restart:
 		if (update_backref_cache(trans, &rc->backref_cache)) {
-			btrfs_end_transaction(trans, rc->extent_root);
+			btrfs_end_transaction(trans);
 			continue;
 		}
 
@@ -4052,7 +4052,7 @@ restart:
 			}
 		}
 
-		btrfs_end_transaction_throttle(trans, rc->extent_root);
+		btrfs_end_transaction_throttle(trans);
 		btrfs_btree_balance_dirty(fs_info);
 		trans = NULL;
 
@@ -4081,7 +4081,7 @@ restart:
 	clear_extent_bits(&rc->processed_blocks, 0, (u64)-1, EXTENT_DIRTY);
 
 	if (trans) {
-		btrfs_end_transaction_throttle(trans, rc->extent_root);
+		btrfs_end_transaction_throttle(trans);
 		btrfs_btree_balance_dirty(fs_info);
 	}
 
@@ -4187,7 +4187,7 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info,
 
 	err = btrfs_orphan_add(trans, inode);
 out:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	btrfs_btree_balance_dirty(fs_info);
 	if (err) {
 		if (inode)
@@ -4334,7 +4334,7 @@ static noinline_for_stack int mark_garbage_root(struct btrfs_root *root)
 	ret = btrfs_update_root(trans, fs_info->tree_root,
 				&root->root_key, &root->root_item);
 
-	err = btrfs_end_transaction(trans, fs_info->tree_root);
+	err = btrfs_end_transaction(trans);
 	if (err)
 		return err;
 	return ret;
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 0ed6b97..53e81cb1 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -293,7 +293,7 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
 			}
 			err = btrfs_del_orphan_item(trans, tree_root,
 						    root_key.objectid);
-			btrfs_end_transaction(trans, tree_root);
+			btrfs_end_transaction(trans);
 			if (err) {
 				btrfs_handle_fs_error(fs_info, err,
 					    "Failed to delete root orphan "
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index c98b91b..fb4d09d 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -838,7 +838,7 @@ static void scrub_fixup_nodatasum(struct btrfs_work *work)
 
 out:
 	if (trans && !IS_ERR(trans))
-		btrfs_end_transaction(trans, fixup->root);
+		btrfs_end_transaction(trans);
 	if (uncorrectable) {
 		spin_lock(&sctx->stat_lock);
 		++sctx->stat.uncorrectable_errors;
@@ -4197,7 +4197,7 @@ static void copy_nocow_pages_worker(struct btrfs_work *work)
 		goto out;
 	}
 
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	trans = NULL;
 	while (!list_empty(&nocow_ctx->inodes)) {
 		struct scrub_nocow_inode *entry;
@@ -4225,7 +4225,7 @@ out:
 		kfree(entry);
 	}
 	if (trans && !IS_ERR(trans))
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 	if (not_written)
 		btrfs_dev_replace_stats_inc(&fs_info->dev_replace.
 					    num_uncorrectable_read_errors);
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index cd0a052..eaf85db 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -5898,7 +5898,7 @@ again:
 			goto commit_trans;
 
 	if (trans)
-		return btrfs_end_transaction(trans, sctx->send_root);
+		return btrfs_end_transaction(trans);
 
 	return 0;
 
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index a546c08..091cb0d 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -640,7 +640,7 @@ struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv(
 	ret = btrfs_cond_migrate_bytes(fs_info, &fs_info->trans_block_rsv,
 				       num_bytes, min_factor);
 	if (ret) {
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		return ERR_PTR(ret);
 	}
 
@@ -822,10 +822,10 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
 }
 
 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
-			  struct btrfs_root *root, int throttle)
+				   int throttle)
 {
 	struct btrfs_transaction *cur_trans = trans->transaction;
-	struct btrfs_fs_info *info = root->fs_info;
+	struct btrfs_fs_info *info = trans->fs_info;
 	unsigned long cur = trans->delayed_ref_updates;
 	int lock = (trans->type != TRANS_JOIN_NOLOCK);
 	int err = 0;
@@ -919,16 +919,14 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
 	return err;
 }
 
-int btrfs_end_transaction(struct btrfs_trans_handle *trans,
-			  struct btrfs_root *root)
+int btrfs_end_transaction(struct btrfs_trans_handle *trans)
 {
-	return __btrfs_end_transaction(trans, root, 0);
+	return __btrfs_end_transaction(trans, 0);
 }
 
-int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans,
-				   struct btrfs_root *root)
+int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans)
 {
-	return __btrfs_end_transaction(trans, root, 1);
+	return __btrfs_end_transaction(trans, 1);
 }
 
 /*
@@ -1305,7 +1303,7 @@ int btrfs_defrag_root(struct btrfs_root *root)
 
 		ret = btrfs_defrag_leaves(trans, root);
 
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		btrfs_btree_balance_dirty(info);
 		cond_resched();
 
@@ -1827,7 +1825,7 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
 	cur_trans = trans->transaction;
 	atomic_inc(&cur_trans->use_count);
 
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 
 	/*
 	 * Tell lockdep we've released the freeze rwsem, since the
@@ -1936,7 +1934,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	/* Stop the commit early if ->aborted is set */
 	if (unlikely(ACCESS_ONCE(cur_trans->aborted))) {
 		ret = cur_trans->aborted;
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		return ret;
 	}
 
@@ -1945,7 +1943,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	 */
 	ret = btrfs_run_delayed_refs(trans, root, 0);
 	if (ret) {
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		return ret;
 	}
 
@@ -1966,7 +1964,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 
 	ret = btrfs_run_delayed_refs(trans, root, 0);
 	if (ret) {
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		return ret;
 	}
 
@@ -1996,7 +1994,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 			ret = btrfs_start_dirty_block_groups(trans, root);
 	}
 	if (ret) {
-		btrfs_end_transaction(trans, root);
+		btrfs_end_transaction(trans);
 		return ret;
 	}
 
@@ -2004,7 +2002,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	if (cur_trans->state >= TRANS_STATE_COMMIT_START) {
 		spin_unlock(&fs_info->trans_lock);
 		atomic_inc(&cur_trans->use_count);
-		ret = btrfs_end_transaction(trans, root);
+		ret = btrfs_end_transaction(trans);
 
 		wait_for_commit(cur_trans);
 
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index 7d3b358..f502514 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -184,8 +184,7 @@ static inline void btrfs_clear_skip_qgroup(struct btrfs_trans_handle *trans)
 	delayed_refs->qgroup_to_skip = 0;
 }
 
-int btrfs_end_transaction(struct btrfs_trans_handle *trans,
-			  struct btrfs_root *root);
+int btrfs_end_transaction(struct btrfs_trans_handle *trans);
 struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
 						   unsigned int num_items);
 struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv(
@@ -210,8 +209,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans);
 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
 				   struct btrfs_root *root,
 				   int wait_for_unblock);
-int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans,
-				   struct btrfs_root *root);
+int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans);
 int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
 				 struct btrfs_root *root);
 void btrfs_throttle(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index e714eb5..ccdff9c 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -5626,7 +5626,7 @@ again:
 	return 0;
 error:
 	if (wc.trans)
-		btrfs_end_transaction(wc.trans, fs_info->tree_root);
+		btrfs_end_transaction(wc.trans);
 	btrfs_free_path(path);
 	return ret;
 }
diff --git a/fs/btrfs/uuid-tree.c b/fs/btrfs/uuid-tree.c
index 24b4cfb..3476e91 100644
--- a/fs/btrfs/uuid-tree.c
+++ b/fs/btrfs/uuid-tree.c
@@ -251,7 +251,7 @@ static int btrfs_uuid_iter_rem(struct btrfs_root *uuid_root, u8 *uuid, u8 type,
 	}
 
 	ret = btrfs_uuid_tree_rem(trans, uuid_root->fs_info, uuid, type, subid);
-	btrfs_end_transaction(trans, uuid_root);
+	btrfs_end_transaction(trans);
 
 out:
 	return ret;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 5953948..b760933 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2457,7 +2457,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
 	return ret;
 
 error_trans:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	rcu_string_free(device->name);
 	btrfs_sysfs_rm_device_link(fs_info->fs_devices, device);
 	kfree(device);
@@ -2894,7 +2894,7 @@ static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
 	 * chunk tree entries
 	 */
 	ret = btrfs_remove_chunk(trans, fs_info, chunk_offset);
-	btrfs_end_transaction(trans, fs_info->extent_root);
+	btrfs_end_transaction(trans);
 	return ret;
 }
 
@@ -3456,7 +3456,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
 		ret = btrfs_grow_device(trans, device, old_size);
 		BUG_ON(ret);
 
-		btrfs_end_transaction(trans, dev_root);
+		btrfs_end_transaction(trans);
 	}
 
 	/* step two, relocate all the chunks */
@@ -3586,7 +3586,7 @@ again:
 
 			ret = btrfs_force_chunk_alloc(trans, fs_info,
 						      BTRFS_BLOCK_GROUP_DATA);
-			btrfs_end_transaction(trans, chunk_root);
+			btrfs_end_transaction(trans);
 			if (ret < 0) {
 				mutex_unlock(&fs_info->delete_unused_bgs_mutex);
 				goto error;
@@ -4114,7 +4114,7 @@ update_tree:
 
 skip:
 		if (trans) {
-			ret = btrfs_end_transaction(trans, fs_info->uuid_root);
+			ret = btrfs_end_transaction(trans);
 			trans = NULL;
 			if (ret)
 				break;
@@ -4139,7 +4139,7 @@ skip:
 out:
 	btrfs_free_path(path);
 	if (trans && !IS_ERR(trans))
-		btrfs_end_transaction(trans, fs_info->uuid_root);
+		btrfs_end_transaction(trans);
 	if (ret)
 		btrfs_warn(fs_info, "btrfs_uuid_scan_kthread failed %d", ret);
 	else
@@ -4233,7 +4233,7 @@ int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info)
 	if (IS_ERR(uuid_root)) {
 		ret = PTR_ERR(uuid_root);
 		btrfs_abort_transaction(trans, ret);
-		btrfs_end_transaction(trans, tree_root);
+		btrfs_end_transaction(trans);
 		return ret;
 	}
 
@@ -4429,7 +4429,7 @@ again:
 
 	/* Now btrfs_update_device() will change the on-disk size. */
 	ret = btrfs_update_device(trans, device);
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 done:
 	btrfs_free_path(path);
 	if (ret) {
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
index 8ee6e19..7a8ddfe 100644
--- a/fs/btrfs/xattr.c
+++ b/fs/btrfs/xattr.c
@@ -259,7 +259,7 @@ int __btrfs_setxattr(struct btrfs_trans_handle *trans,
 	ret = btrfs_update_inode(trans, root, inode);
 	BUG_ON(ret);
 out:
-	btrfs_end_transaction(trans, root);
+	btrfs_end_transaction(trans);
 	return ret;
 }
 
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (27 preceding siblings ...)
  2016-06-24 22:15 ` [PATCH 31/31] btrfs: root->fs_info cleanup, btrfs_end_transaction{,_throttle} use trans->fs_info instead of parameter jeffm
@ 2016-06-26 13:50 ` Jeff Mahoney
  2016-06-27  1:34 ` Qu Wenruo
                   ` (2 subsequent siblings)
  31 siblings, 0 replies; 44+ messages in thread
From: Jeff Mahoney @ 2016-06-26 13:50 UTC (permalink / raw)
  To: linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 8198 bytes --]

On 6/24/16 6:14 PM, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
> 
> One of the common complaints I've heard from new and experienced
> developers alike about the btrfs code is the ubiquity of
> struct btrfs_root.  There is one for every tree on disk and it's not
> always obvious which root is needed in a particular call path.  It can
> be frustrating to spend time figuring out which root is required only
> to discover that it's not actually used for anything other than
> getting the fs-global struct btrfs_fs_info.
> 
> The patchset contains several sections.
> 
> 1) The fsid trace event patchset I posted earlier; I can rebase without this
>    but I'd prefer not to.
> 
> 2) Converting btrfs_test_opt and friends to use an fs_info.
> 
> 3) Converting tests to use an fs_info pointer whenever a root is used.
> 
> 4) Moving sectorsize and nodesize to fs_info and cleaning up the
>    macros used to access them.
> 
> 5) General cleanups and small fixes to make the later patches easier to
>    review.
> 
> 6) Adding an "fs_info" convenience variable to every functiont that
>    references root->fs_info more than once.  As new references appear
>    in functions, more of these are added later.
> 
> 7) Call functions that always overwrite their root parameter with
>    an fs_info instead.
> 
> 8) Call functions that are always called using the same root with
>    an fs_info instead, retreiving the root internally.
> 
> 9) Convert every function that accepts a root argument but only uses it
>    to retreive an fs_info to accept an fs_info instead.  This is a
>    recursive process as the changes percolate up.
> 
> 10) Separately convert btrfs_commit_transaction and btrfs_end_transaction
>     to use trans->root instead of a root parameter.  Both are always called
>     with the same root that was passed to btrfs_{start,join}_transaction.
> 
> This series of patches in email format is the "squashed" version of
> the full development series.  That series is available at:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/jeffm/linux-btrfs.git
> 
> There are two branches of interest:
> - btrfs-testing/root-fsinfo-cleanup-squashed contains this series
> - btrfs-testing/root-fsinfo-cleanup contains the full series

Hrm.  It looks like vger didn't allow a few of the patches through,
presumably due to size.  Using the git repo is probably the only way to
go, then.

-Jeff

> The btrfs-testing/root-fsinfo-cleanup branch is easier to review if using
> git as each change is discrete.  As a whole, the patchset is invasive but
> should change execution minimally.  It passes and fails the same xfstests
> that the unpatched kernel does across multiple runs.
> 
> Thanks,
> 
> -Jeff
> 
> ---
> 
> Jeff Mahoney (31):
>   btrfs: plumb fs_info into btrfs_work
>   btrfs: prefix fsid to all trace events
>   btrfs: btrfs_test_opt and friends should take a btrfs_fs_info
>   btrfs: tests, move initialization into tests/
>   btrfs: tests, require fs_info for root
>   btrfs: tests, use BTRFS_FS_STATE_DUMMY_FS_INFO instead of dummy root
>   btrfs: simpilify btrfs_subvol_inherit_props
>   btrfs: copy_to_sk drop unused root parameter
>   btrfs: cleanup, remove prototype for btrfs_find_root_ref
>   btrfs: introduce BTRFS_MAX_ITEM_SIZE
>   btrfs: convert nodesize macros to static inlines
>   btrfs: btrfs_relocate_chunk pass extent_root to btrfs_end_transaction
>   btrfs: add btrfs_trans_handle->fs_info pointer
>   btrfs: btrfs_abort_transaction, drop root parameter
>   btrfs: call functions that overwrite their root parameter with fs_info
>   btrfs: call functions that always use the same root with fs_info
>     instead
>   btrfs: btrfs_init_new_device should use fs_info->dev_root
>   btrfs: alloc_reserved_file_extent trace point should use extent_root
>   btrfs: struct btrfsic_state->root should be an fs_info
>   btrfs: struct reada_control.root -> reada_control.fs_info
>   btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere
>   btrfs: root->fs_info cleanup, io_ctl_init
>   btrfs: pull node/sector/stripe sizes out of root and into fs_info
>   btrfs: root->fs_info cleanup, btrfs_calc_{trans,trunc}_metadata_size
>   btrfs: root->fs_info cleanup, lock/unlock_chunks
>   btrfs: root->fs_info cleanup, update_block_group{,flags}
>   btrfs: root->fs_info cleanup, add fs_info convenience variables
>   btrfs: root->fs_info cleanup, access fs_info->delayed_root directly
>   btrfs: take an fs_info parameter directly when the root is not used
>     otherwise
>   btrfs: root->fs_info cleanup, btrfs_commit_transaction already has
>     root
>   btrfs: root->fs_info cleanup, btrfs_end_transaction{,_throttle} use
>     trans->fs_info instead of parameter
> 
>  fs/btrfs/async-thread.c                |   31 +-
>  fs/btrfs/async-thread.h                |    6 +-
>  fs/btrfs/backref.c                     |   12 +-
>  fs/btrfs/check-integrity.c             |   41 +-
>  fs/btrfs/check-integrity.h             |    5 +-
>  fs/btrfs/compression.c                 |   54 +-
>  fs/btrfs/ctree.c                       |  483 ++++++------
>  fs/btrfs/ctree.h                       |  281 +++----
>  fs/btrfs/delayed-inode.c               |  147 ++--
>  fs/btrfs/delayed-inode.h               |   19 +-
>  fs/btrfs/delayed-ref.c                 |    9 +-
>  fs/btrfs/dev-replace.c                 |   68 +-
>  fs/btrfs/dev-replace.h                 |    4 +-
>  fs/btrfs/dir-item.c                    |   44 +-
>  fs/btrfs/disk-io.c                     |  593 ++++++++-------
>  fs/btrfs/disk-io.h                     |   27 +-
>  fs/btrfs/export.c                      |   10 +-
>  fs/btrfs/extent-tree.c                 | 1297 ++++++++++++++++----------------
>  fs/btrfs/extent_io.c                   |   41 +-
>  fs/btrfs/extent_io.h                   |    4 +-
>  fs/btrfs/file-item.c                   |  164 ++--
>  fs/btrfs/file.c                        |  220 +++---
>  fs/btrfs/free-space-cache.c            |  116 +--
>  fs/btrfs/free-space-cache.h            |    6 +-
>  fs/btrfs/free-space-tree.c             |   60 +-
>  fs/btrfs/inode-item.c                  |   11 +-
>  fs/btrfs/inode-map.c                   |   48 +-
>  fs/btrfs/inode.c                       |  834 ++++++++++----------
>  fs/btrfs/ioctl.c                       |  613 ++++++++-------
>  fs/btrfs/ordered-data.c                |   38 +-
>  fs/btrfs/ordered-data.h                |    4 +-
>  fs/btrfs/print-tree.c                  |   21 +-
>  fs/btrfs/print-tree.h                  |    4 +-
>  fs/btrfs/props.c                       |   11 +-
>  fs/btrfs/qgroup.c                      |   60 +-
>  fs/btrfs/qgroup.h                      |    9 +-
>  fs/btrfs/raid56.c                      |   60 +-
>  fs/btrfs/raid56.h                      |    8 +-
>  fs/btrfs/reada.c                       |   36 +-
>  fs/btrfs/relocation.c                  |  261 ++++---
>  fs/btrfs/root-tree.c                   |   36 +-
>  fs/btrfs/scrub.c                       |  177 +++--
>  fs/btrfs/send.c                        |   45 +-
>  fs/btrfs/super.c                       |  308 ++++----
>  fs/btrfs/tests/btrfs-tests.c           |   72 +-
>  fs/btrfs/tests/btrfs-tests.h           |   38 +-
>  fs/btrfs/tests/extent-buffer-tests.c   |   23 +-
>  fs/btrfs/tests/free-space-tests.c      |   14 +-
>  fs/btrfs/tests/free-space-tree-tests.c |   18 +-
>  fs/btrfs/tests/inode-tests.c           |   46 +-
>  fs/btrfs/tests/qgroup-tests.c          |   23 +-
>  fs/btrfs/transaction.c                 |  531 ++++++-------
>  fs/btrfs/transaction.h                 |   16 +-
>  fs/btrfs/tree-log.c                    |  193 ++---
>  fs/btrfs/uuid-tree.c                   |   20 +-
>  fs/btrfs/volumes.c                     |  813 ++++++++++----------
>  fs/btrfs/volumes.h                     |   42 +-
>  fs/btrfs/xattr.c                       |   21 +-
>  include/trace/events/btrfs.h           |  296 ++++----
>  59 files changed, 4383 insertions(+), 4109 deletions(-)
> 


-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 881 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (28 preceding siblings ...)
  2016-06-26 13:50 ` [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers Jeff Mahoney
@ 2016-06-27  1:34 ` Qu Wenruo
  2016-07-07 14:07 ` David Sterba
  2016-07-08  1:48 ` Jeff Mahoney
  31 siblings, 0 replies; 44+ messages in thread
From: Qu Wenruo @ 2016-06-27  1:34 UTC (permalink / raw)
  To: jeffm, linux-btrfs



At 06/25/2016 06:14 AM, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
>
> One of the common complaints I've heard from new and experienced
> developers alike about the btrfs code is the ubiquity of
> struct btrfs_root.  There is one for every tree on disk and it's not
> always obvious which root is needed in a particular call path.  It can
> be frustrating to spend time figuring out which root is required only
> to discover that it's not actually used for anything other than
> getting the fs-global struct btrfs_fs_info.

Can't agree any more.

btrfs_root should only be used for case involving searching one fs tree.

For non-fs trees, like extent/chunk/root and other trees, we should get 
it from fs_info, other than passing a btrfs_root.

So for this, I totally agree on the modification.

>
> The patchset contains several sections.
>
> 1) The fsid trace event patchset I posted earlier; I can rebase without this
>    but I'd prefer not to.

IMHO the fsid output in ftrace is too long, making the ftrace harder to 
read.

And even more, for some developer, like me, is doing testing with only 
one btrfs fs.
In that case, the ftrace fsid output is completely redundant.

So it would be quite nice to limit the fsid to first 8 hex bytes.

(And the first time I tested David's for next branch, the ftrace output 
makes it quite hard to read, had to stripe them out to read out needed data)

>
> 2) Converting btrfs_test_opt and friends to use an fs_info.
>
> 3) Converting tests to use an fs_info pointer whenever a root is used.
>
> 4) Moving sectorsize and nodesize to fs_info and cleaning up the
>    macros used to access them.

Yeah! nodesize inside btrfs_root is never sane.
I still remember the days I need to get nodesize either from 
fs_info->sb_copy or fs_info->root_tree.

I'll check each patch more carefully then, but the direction is quite good.
Good job!

Thanks,
Qu

>
> 5) General cleanups and small fixes to make the later patches easier to
>    review.
>
> 6) Adding an "fs_info" convenience variable to every functiont that
>    references root->fs_info more than once.  As new references appear
>    in functions, more of these are added later.
>
> 7) Call functions that always overwrite their root parameter with
>    an fs_info instead.
>
> 8) Call functions that are always called using the same root with
>    an fs_info instead, retreiving the root internally.
>
> 9) Convert every function that accepts a root argument but only uses it
>    to retreive an fs_info to accept an fs_info instead.  This is a
>    recursive process as the changes percolate up.
>
> 10) Separately convert btrfs_commit_transaction and btrfs_end_transaction
>     to use trans->root instead of a root parameter.  Both are always called
>     with the same root that was passed to btrfs_{start,join}_transaction.
>
> This series of patches in email format is the "squashed" version of
> the full development series.  That series is available at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/jeffm/linux-btrfs.git
>
> There are two branches of interest:
> - btrfs-testing/root-fsinfo-cleanup-squashed contains this series
> - btrfs-testing/root-fsinfo-cleanup contains the full series
>
> The btrfs-testing/root-fsinfo-cleanup branch is easier to review if using
> git as each change is discrete.  As a whole, the patchset is invasive but
> should change execution minimally.  It passes and fails the same xfstests
> that the unpatched kernel does across multiple runs.
>
> Thanks,
>
> -Jeff
>
> ---
>
> Jeff Mahoney (31):
>   btrfs: plumb fs_info into btrfs_work
>   btrfs: prefix fsid to all trace events
>   btrfs: btrfs_test_opt and friends should take a btrfs_fs_info
>   btrfs: tests, move initialization into tests/
>   btrfs: tests, require fs_info for root
>   btrfs: tests, use BTRFS_FS_STATE_DUMMY_FS_INFO instead of dummy root
>   btrfs: simpilify btrfs_subvol_inherit_props
>   btrfs: copy_to_sk drop unused root parameter
>   btrfs: cleanup, remove prototype for btrfs_find_root_ref
>   btrfs: introduce BTRFS_MAX_ITEM_SIZE
>   btrfs: convert nodesize macros to static inlines
>   btrfs: btrfs_relocate_chunk pass extent_root to btrfs_end_transaction
>   btrfs: add btrfs_trans_handle->fs_info pointer
>   btrfs: btrfs_abort_transaction, drop root parameter
>   btrfs: call functions that overwrite their root parameter with fs_info
>   btrfs: call functions that always use the same root with fs_info
>     instead
>   btrfs: btrfs_init_new_device should use fs_info->dev_root
>   btrfs: alloc_reserved_file_extent trace point should use extent_root
>   btrfs: struct btrfsic_state->root should be an fs_info
>   btrfs: struct reada_control.root -> reada_control.fs_info
>   btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere
>   btrfs: root->fs_info cleanup, io_ctl_init
>   btrfs: pull node/sector/stripe sizes out of root and into fs_info
>   btrfs: root->fs_info cleanup, btrfs_calc_{trans,trunc}_metadata_size
>   btrfs: root->fs_info cleanup, lock/unlock_chunks
>   btrfs: root->fs_info cleanup, update_block_group{,flags}
>   btrfs: root->fs_info cleanup, add fs_info convenience variables
>   btrfs: root->fs_info cleanup, access fs_info->delayed_root directly
>   btrfs: take an fs_info parameter directly when the root is not used
>     otherwise
>   btrfs: root->fs_info cleanup, btrfs_commit_transaction already has
>     root
>   btrfs: root->fs_info cleanup, btrfs_end_transaction{,_throttle} use
>     trans->fs_info instead of parameter
>
>  fs/btrfs/async-thread.c                |   31 +-
>  fs/btrfs/async-thread.h                |    6 +-
>  fs/btrfs/backref.c                     |   12 +-
>  fs/btrfs/check-integrity.c             |   41 +-
>  fs/btrfs/check-integrity.h             |    5 +-
>  fs/btrfs/compression.c                 |   54 +-
>  fs/btrfs/ctree.c                       |  483 ++++++------
>  fs/btrfs/ctree.h                       |  281 +++----
>  fs/btrfs/delayed-inode.c               |  147 ++--
>  fs/btrfs/delayed-inode.h               |   19 +-
>  fs/btrfs/delayed-ref.c                 |    9 +-
>  fs/btrfs/dev-replace.c                 |   68 +-
>  fs/btrfs/dev-replace.h                 |    4 +-
>  fs/btrfs/dir-item.c                    |   44 +-
>  fs/btrfs/disk-io.c                     |  593 ++++++++-------
>  fs/btrfs/disk-io.h                     |   27 +-
>  fs/btrfs/export.c                      |   10 +-
>  fs/btrfs/extent-tree.c                 | 1297 ++++++++++++++++----------------
>  fs/btrfs/extent_io.c                   |   41 +-
>  fs/btrfs/extent_io.h                   |    4 +-
>  fs/btrfs/file-item.c                   |  164 ++--
>  fs/btrfs/file.c                        |  220 +++---
>  fs/btrfs/free-space-cache.c            |  116 +--
>  fs/btrfs/free-space-cache.h            |    6 +-
>  fs/btrfs/free-space-tree.c             |   60 +-
>  fs/btrfs/inode-item.c                  |   11 +-
>  fs/btrfs/inode-map.c                   |   48 +-
>  fs/btrfs/inode.c                       |  834 ++++++++++----------
>  fs/btrfs/ioctl.c                       |  613 ++++++++-------
>  fs/btrfs/ordered-data.c                |   38 +-
>  fs/btrfs/ordered-data.h                |    4 +-
>  fs/btrfs/print-tree.c                  |   21 +-
>  fs/btrfs/print-tree.h                  |    4 +-
>  fs/btrfs/props.c                       |   11 +-
>  fs/btrfs/qgroup.c                      |   60 +-
>  fs/btrfs/qgroup.h                      |    9 +-
>  fs/btrfs/raid56.c                      |   60 +-
>  fs/btrfs/raid56.h                      |    8 +-
>  fs/btrfs/reada.c                       |   36 +-
>  fs/btrfs/relocation.c                  |  261 ++++---
>  fs/btrfs/root-tree.c                   |   36 +-
>  fs/btrfs/scrub.c                       |  177 +++--
>  fs/btrfs/send.c                        |   45 +-
>  fs/btrfs/super.c                       |  308 ++++----
>  fs/btrfs/tests/btrfs-tests.c           |   72 +-
>  fs/btrfs/tests/btrfs-tests.h           |   38 +-
>  fs/btrfs/tests/extent-buffer-tests.c   |   23 +-
>  fs/btrfs/tests/free-space-tests.c      |   14 +-
>  fs/btrfs/tests/free-space-tree-tests.c |   18 +-
>  fs/btrfs/tests/inode-tests.c           |   46 +-
>  fs/btrfs/tests/qgroup-tests.c          |   23 +-
>  fs/btrfs/transaction.c                 |  531 ++++++-------
>  fs/btrfs/transaction.h                 |   16 +-
>  fs/btrfs/tree-log.c                    |  193 ++---
>  fs/btrfs/uuid-tree.c                   |   20 +-
>  fs/btrfs/volumes.c                     |  813 ++++++++++----------
>  fs/btrfs/volumes.h                     |   42 +-
>  fs/btrfs/xattr.c                       |   21 +-
>  include/trace/events/btrfs.h           |  296 ++++----
>  59 files changed, 4383 insertions(+), 4109 deletions(-)
>



^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 02/31] btrfs: prefix fsid to all trace events
  2016-06-24 22:14 ` [PATCH 02/31] btrfs: prefix fsid to all trace events jeffm
@ 2016-06-27  1:50   ` Qu Wenruo
  0 siblings, 0 replies; 44+ messages in thread
From: Qu Wenruo @ 2016-06-27  1:50 UTC (permalink / raw)
  To: jeffm, linux-btrfs



At 06/25/2016 06:14 AM, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
>
> When using trace events to debug a problem, it's impossible to determine
> which file system generated a particular event.  This patch adds a
> macro to prefix standard information to the head of a trace event.
>
> The extent_state alloc/free events are all that's left without an
> fs_info available.
>
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
> ---
>  fs/btrfs/delayed-ref.c       |   9 +-
>  fs/btrfs/extent-tree.c       |  10 +-
>  fs/btrfs/qgroup.c            |  19 +--
>  fs/btrfs/qgroup.h            |   9 +-
>  fs/btrfs/super.c             |   2 +-
>  include/trace/events/btrfs.h | 282 ++++++++++++++++++++++++-------------------
>  6 files changed, 182 insertions(+), 149 deletions(-)
>
> diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
> index 430b368..e7b1ec0 100644
> --- a/fs/btrfs/delayed-ref.c
> +++ b/fs/btrfs/delayed-ref.c
> @@ -606,7 +606,8 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
>  		qrecord->num_bytes = num_bytes;
>  		qrecord->old_roots = NULL;
>
> -		qexisting = btrfs_qgroup_insert_dirty_extent(delayed_refs,
> +		qexisting = btrfs_qgroup_insert_dirty_extent(fs_info,
> +							     delayed_refs,
>  							     qrecord);
>  		if (qexisting)
>  			kfree(qrecord);
> @@ -615,7 +616,7 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
>  	spin_lock_init(&head_ref->lock);
>  	mutex_init(&head_ref->mutex);
>
> -	trace_add_delayed_ref_head(ref, head_ref, action);
> +	trace_add_delayed_ref_head(fs_info, ref, head_ref, action);
>
>  	existing = htree_insert(&delayed_refs->href_root,
>  				&head_ref->href_node);
> @@ -682,7 +683,7 @@ add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
>  		ref->type = BTRFS_TREE_BLOCK_REF_KEY;
>  	full_ref->level = level;
>
> -	trace_add_delayed_tree_ref(ref, full_ref, action);
> +	trace_add_delayed_tree_ref(fs_info, ref, full_ref, action);
>
>  	ret = add_delayed_ref_tail_merge(trans, delayed_refs, head_ref, ref);
>
> @@ -739,7 +740,7 @@ add_delayed_data_ref(struct btrfs_fs_info *fs_info,
>  	full_ref->objectid = owner;
>  	full_ref->offset = offset;
>
> -	trace_add_delayed_data_ref(ref, full_ref, action);
> +	trace_add_delayed_data_ref(fs_info, ref, full_ref, action);
>
>  	ret = add_delayed_ref_tail_merge(trans, delayed_refs, head_ref, ref);
>
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 29e5d00..39308a8 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -2194,7 +2194,7 @@ static int run_delayed_data_ref(struct btrfs_trans_handle *trans,
>  	ins.type = BTRFS_EXTENT_ITEM_KEY;
>
>  	ref = btrfs_delayed_node_to_data_ref(node);
> -	trace_run_delayed_data_ref(node, ref, node->action);
> +	trace_run_delayed_data_ref(root->fs_info, node, ref, node->action);
>
>  	if (node->type == BTRFS_SHARED_DATA_REF_KEY)
>  		parent = ref->parent;
> @@ -2349,7 +2349,7 @@ static int run_delayed_tree_ref(struct btrfs_trans_handle *trans,
>  						 SKINNY_METADATA);
>
>  	ref = btrfs_delayed_node_to_tree_ref(node);
> -	trace_run_delayed_tree_ref(node, ref, node->action);
> +	trace_run_delayed_tree_ref(root->fs_info, node, ref, node->action);
>
>  	if (node->type == BTRFS_SHARED_BLOCK_REF_KEY)
>  		parent = ref->parent;
> @@ -2413,7 +2413,8 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
>  		 */
>  		BUG_ON(extent_op);
>  		head = btrfs_delayed_node_to_head(node);
> -		trace_run_delayed_ref_head(node, head, node->action);
> +		trace_run_delayed_ref_head(root->fs_info, node, head,
> +					   node->action);
>
>  		if (insert_reserved) {
>  			btrfs_pin_extent(root, node->bytenr,
> @@ -8317,7 +8318,8 @@ static int record_one_subtree_extent(struct btrfs_trans_handle *trans,
>
>  	delayed_refs = &trans->transaction->delayed_refs;
>  	spin_lock(&delayed_refs->lock);
> -	if (btrfs_qgroup_insert_dirty_extent(delayed_refs, qrecord))
> +	if (btrfs_qgroup_insert_dirty_extent(trans->root->fs_info,
> +					     delayed_refs, qrecord))
>  		kfree(qrecord);
>  	spin_unlock(&delayed_refs->lock);
>
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 9d4c05b..13e28d8 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -1453,9 +1453,10 @@ int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
>  	return ret;
>  }
>
> -struct btrfs_qgroup_extent_record
> -*btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs,
> -				  struct btrfs_qgroup_extent_record *record)
> +struct btrfs_qgroup_extent_record *
> +btrfs_qgroup_insert_dirty_extent(struct btrfs_fs_info *fs_info,
> +				 struct btrfs_delayed_ref_root *delayed_refs,
> +				 struct btrfs_qgroup_extent_record *record)
>  {
>  	struct rb_node **p = &delayed_refs->dirty_extent_root.rb_node;
>  	struct rb_node *parent_node = NULL;
> @@ -1463,7 +1464,7 @@ struct btrfs_qgroup_extent_record
>  	u64 bytenr = record->bytenr;
>
>  	assert_spin_locked(&delayed_refs->lock);
> -	trace_btrfs_qgroup_insert_dirty_extent(record);
> +	trace_btrfs_qgroup_insert_dirty_extent(fs_info, record);
>
>  	while (*p) {
>  		parent_node = *p;
> @@ -1595,8 +1596,8 @@ static int qgroup_update_counters(struct btrfs_fs_info *fs_info,
>  		cur_old_count = btrfs_qgroup_get_old_refcnt(qg, seq);
>  		cur_new_count = btrfs_qgroup_get_new_refcnt(qg, seq);
>
> -		trace_qgroup_update_counters(qg->qgroupid, cur_old_count,
> -					     cur_new_count);
> +		trace_qgroup_update_counters(fs_info, qg->qgroupid,
> +					     cur_old_count, cur_new_count);
>
>  		/* Rfer update part */
>  		if (cur_old_count == 0 && cur_new_count > 0) {
> @@ -1687,8 +1688,8 @@ btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
>  		goto out_free;
>  	BUG_ON(!fs_info->quota_root);
>
> -	trace_btrfs_qgroup_account_extent(bytenr, num_bytes, nr_old_roots,
> -					  nr_new_roots);
> +	trace_btrfs_qgroup_account_extent(fs_info, bytenr, num_bytes,
> +					  nr_old_roots, nr_new_roots);
>
>  	qgroups = ulist_alloc(GFP_NOFS);
>  	if (!qgroups) {
> @@ -1759,7 +1760,7 @@ int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans,
>  		record = rb_entry(node, struct btrfs_qgroup_extent_record,
>  				  node);
>
> -		trace_btrfs_qgroup_account_extents(record);
> +		trace_btrfs_qgroup_account_extents(fs_info, record);
>
>  		if (!ret) {
>  			/*
> diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h
> index ecb2c14..710887c 100644
> --- a/fs/btrfs/qgroup.h
> +++ b/fs/btrfs/qgroup.h
> @@ -63,9 +63,10 @@ void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info);
>  struct btrfs_delayed_extent_op;
>  int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
>  					 struct btrfs_fs_info *fs_info);
> -struct btrfs_qgroup_extent_record
> -*btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs,
> -				  struct btrfs_qgroup_extent_record *record);
> +struct btrfs_qgroup_extent_record *
> +btrfs_qgroup_insert_dirty_extent(struct btrfs_fs_info *fs_info,
> +				 struct btrfs_delayed_ref_root *delayed_refs,
> +				 struct btrfs_qgroup_extent_record *record);
>  int
>  btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
>  			    struct btrfs_fs_info *fs_info,
> @@ -88,7 +89,7 @@ static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info,
>  						 u64 ref_root, u64 num_bytes)
>  {
>  	btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes);
> -	trace_btrfs_qgroup_free_delayed_ref(ref_root, num_bytes);
> +	trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes);
>  }
>  void assert_qgroups_uptodate(struct btrfs_trans_handle *trans);
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 60e7179..ee56b0e 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -1149,7 +1149,7 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
>  	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
>  	struct btrfs_root *root = fs_info->tree_root;
>
> -	trace_btrfs_sync_fs(wait);
> +	trace_btrfs_sync_fs(fs_info, wait);
>
>  	if (!wait) {
>  		filemap_flush(fs_info->btree_inode->i_mapping);
> diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
> index e90e82a..eba0c65 100644
> --- a/include/trace/events/btrfs.h
> +++ b/include/trace/events/btrfs.h
> @@ -66,6 +66,21 @@ struct btrfs_qgroup_extent_record;
>  	{ BTRFS_BLOCK_GROUP_RAID6,	"RAID6"}
>
>  #define BTRFS_UUID_SIZE 16
> +#define TP_STRUCT__entry_fsid __array(u8, fsid, BTRFS_UUID_SIZE)
> +
> +#define TP_fast_assign_fsid(fs_info)					\
> +	memcpy(__entry->fsid, fs_info->fsid, BTRFS_UUID_SIZE)
> +
> +#define TP_STRUCT__entry_btrfs(args...)					\
> +	TP_STRUCT__entry(						\
> +		TP_STRUCT__entry_fsid					\
> +		args)
> +#define TP_fast_assign_btrfs(fs_info, args...)				\
> +	TP_fast_assign(							\
> +		TP_fast_assign_fsid(fs_info);				\
> +		args)
> +#define TP_printk_btrfs(fmt, args...) \
> +	TP_printk("%pU: " fmt, __entry->fsid, args)

Although it would be much better if we can shorten the uuid length, but 
that would need to modify printk parameter to support non-standard uuid 
size.

Or we need to manual output chars as hex.

Either way, I'm not sure if it's worthy just to shorten the uuid length.

Otherwise it looks good for me.

Thanks,
Qu

>
>  TRACE_EVENT(btrfs_transaction_commit,
>
> @@ -73,17 +88,17 @@ TRACE_EVENT(btrfs_transaction_commit,
>
>  	TP_ARGS(root),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  generation		)
>  		__field(	u64,  root_objectid		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(root->fs_info,
>  		__entry->generation	= root->fs_info->generation;
>  		__entry->root_objectid	= root->root_key.objectid;
>  	),
>
> -	TP_printk("root = %llu(%s), gen = %llu",
> +	TP_printk_btrfs("root = %llu(%s), gen = %llu",
>  		  show_root_type(__entry->root_objectid),
>  		  (unsigned long long)__entry->generation)
>  );
> @@ -94,7 +109,7 @@ DECLARE_EVENT_CLASS(btrfs__inode,
>
>  	TP_ARGS(inode),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	ino_t,  ino			)
>  		__field(	blkcnt_t,  blocks		)
>  		__field(	u64,  disk_i_size		)
> @@ -104,7 +119,7 @@ DECLARE_EVENT_CLASS(btrfs__inode,
>  		__field(	u64,  root_objectid		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
>  		__entry->ino	= inode->i_ino;
>  		__entry->blocks	= inode->i_blocks;
>  		__entry->disk_i_size  = BTRFS_I(inode)->disk_i_size;
> @@ -115,7 +130,7 @@ DECLARE_EVENT_CLASS(btrfs__inode,
>  				BTRFS_I(inode)->root->root_key.objectid;
>  	),
>
> -	TP_printk("root = %llu(%s), gen = %llu, ino = %lu, blocks = %llu, "
> +	TP_printk_btrfs("root = %llu(%s), gen = %llu, ino = %lu, blocks = %llu, "
>  		  "disk_i_size = %llu, last_trans = %llu, logged_trans = %llu",
>  		  show_root_type(__entry->root_objectid),
>  		  (unsigned long long)__entry->generation,
> @@ -175,7 +190,7 @@ TRACE_EVENT_CONDITION(btrfs_get_extent,
>
>  	TP_CONDITION(map),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  root_objectid	)
>  		__field(	u64,  start		)
>  		__field(	u64,  len		)
> @@ -187,7 +202,7 @@ TRACE_EVENT_CONDITION(btrfs_get_extent,
>  		__field(	unsigned int,  compress_type	)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(root->fs_info,
>  		__entry->root_objectid	= root->root_key.objectid;
>  		__entry->start 		= map->start;
>  		__entry->len		= map->len;
> @@ -199,7 +214,7 @@ TRACE_EVENT_CONDITION(btrfs_get_extent,
>  		__entry->compress_type	= map->compress_type;
>  	),
>
> -	TP_printk("root = %llu(%s), start = %llu, len = %llu, "
> +	TP_printk_btrfs("root = %llu(%s), start = %llu, len = %llu, "
>  		  "orig_start = %llu, block_start = %llu(%s), "
>  		  "block_len = %llu, flags = %s, refs = %u, "
>  		  "compress_type = %u",
> @@ -233,7 +248,7 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent,
>
>  	TP_ARGS(inode, ordered),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	ino_t,  ino		)
>  		__field(	u64,  file_offset	)
>  		__field(	u64,  start		)
> @@ -246,7 +261,7 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent,
>  		__field(	u64,  root_objectid	)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
>  		__entry->ino 		= inode->i_ino;
>  		__entry->file_offset	= ordered->file_offset;
>  		__entry->start		= ordered->start;
> @@ -260,7 +275,7 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent,
>  				BTRFS_I(inode)->root->root_key.objectid;
>  	),
>
> -	TP_printk("root = %llu(%s), ino = %llu, file_offset = %llu, "
> +	TP_printk_btrfs("root = %llu(%s), ino = %llu, file_offset = %llu, "
>  		  "start = %llu, len = %llu, disk_len = %llu, "
>  		  "bytes_left = %llu, flags = %s, compress_type = %d, "
>  		  "refs = %d",
> @@ -310,7 +325,7 @@ DECLARE_EVENT_CLASS(btrfs__writepage,
>
>  	TP_ARGS(page, inode, wbc),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	ino_t,  ino			)
>  		__field(	pgoff_t,  index			)
>  		__field(	long,   nr_to_write		)
> @@ -324,7 +339,7 @@ DECLARE_EVENT_CLASS(btrfs__writepage,
>  		__field(	u64,    root_objectid		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
>  		__entry->ino		= inode->i_ino;
>  		__entry->index		= page->index;
>  		__entry->nr_to_write	= wbc->nr_to_write;
> @@ -339,7 +354,7 @@ DECLARE_EVENT_CLASS(btrfs__writepage,
>  				 BTRFS_I(inode)->root->root_key.objectid;
>  	),
>
> -	TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, "
> +	TP_printk_btrfs("root = %llu(%s), ino = %lu, page_index = %lu, "
>  		  "nr_to_write = %ld, pages_skipped = %ld, range_start = %llu, "
>  		  "range_end = %llu, for_kupdate = %d, "
>  		  "for_reclaim = %d, range_cyclic = %d, writeback_index = %lu",
> @@ -366,7 +381,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook,
>
>  	TP_ARGS(page, start, end, uptodate),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	ino_t,	 ino		)
>  		__field(	pgoff_t, index		)
>  		__field(	u64,	 start		)
> @@ -375,7 +390,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook,
>  		__field(	u64,    root_objectid	)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_sb(page->mapping->host->i_sb),
>  		__entry->ino	= page->mapping->host->i_ino;
>  		__entry->index	= page->index;
>  		__entry->start	= start;
> @@ -385,7 +400,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook,
>  			 BTRFS_I(page->mapping->host)->root->root_key.objectid;
>  	),
>
> -	TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, start = %llu, "
> +	TP_printk_btrfs("root = %llu(%s), ino = %lu, page_index = %lu, start = %llu, "
>  		  "end = %llu, uptodate = %d",
>  		  show_root_type(__entry->root_objectid),
>  		  (unsigned long)__entry->ino, (unsigned long)__entry->index,
> @@ -399,7 +414,7 @@ TRACE_EVENT(btrfs_sync_file,
>
>  	TP_ARGS(file, datasync),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	ino_t,  ino		)
>  		__field(	ino_t,  parent		)
>  		__field(	int,    datasync	)
> @@ -410,6 +425,7 @@ TRACE_EVENT(btrfs_sync_file,
>  		struct dentry *dentry = file->f_path.dentry;
>  		struct inode *inode = d_inode(dentry);
>
> +		TP_fast_assign_fsid(btrfs_sb(file->f_path.dentry->d_sb));
>  		__entry->ino		= inode->i_ino;
>  		__entry->parent		= d_inode(dentry->d_parent)->i_ino;
>  		__entry->datasync	= datasync;
> @@ -417,7 +433,7 @@ TRACE_EVENT(btrfs_sync_file,
>  				 BTRFS_I(inode)->root->root_key.objectid;
>  	),
>
> -	TP_printk("root = %llu(%s), ino = %ld, parent = %ld, datasync = %d",
> +	TP_printk_btrfs("root = %llu(%s), ino = %ld, parent = %ld, datasync = %d",
>  		  show_root_type(__entry->root_objectid),
>  		  (unsigned long)__entry->ino, (unsigned long)__entry->parent,
>  		  __entry->datasync)
> @@ -425,19 +441,19 @@ TRACE_EVENT(btrfs_sync_file,
>
>  TRACE_EVENT(btrfs_sync_fs,
>
> -	TP_PROTO(int wait),
> +	TP_PROTO(struct btrfs_fs_info *fs_info, int wait),
>
> -	TP_ARGS(wait),
> +	TP_ARGS(fs_info, wait),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	int,  wait		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(fs_info,
>  		__entry->wait	= wait;
>  	),
>
> -	TP_printk("wait = %d", __entry->wait)
> +	TP_printk_btrfs("wait = %d", __entry->wait)
>  );
>
>  #define show_ref_action(action)						\
> @@ -450,13 +466,14 @@ TRACE_EVENT(btrfs_sync_fs,
>
>  DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
>
> -	TP_PROTO(struct btrfs_delayed_ref_node *ref,
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_delayed_ref_node *ref,
>  		 struct btrfs_delayed_tree_ref *full_ref,
>  		 int action),
>
> -	TP_ARGS(ref, full_ref, action),
> +	TP_ARGS(fs_info, ref, full_ref, action),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  bytenr		)
>  		__field(	u64,  num_bytes		)
>  		__field(	int,  action		)
> @@ -467,7 +484,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
>  		__field(	u64,  seq		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(fs_info,
>  		__entry->bytenr		= ref->bytenr;
>  		__entry->num_bytes	= ref->num_bytes;
>  		__entry->action		= action;
> @@ -478,7 +495,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
>  		__entry->seq		= ref->seq;
>  	),
>
> -	TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, "
> +	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, action = %s, "
>  		  "parent = %llu(%s), ref_root = %llu(%s), level = %d, "
>  		  "type = %s, seq = %llu",
>  		  (unsigned long long)__entry->bytenr,
> @@ -492,31 +509,34 @@ DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref,
>
>  DEFINE_EVENT(btrfs_delayed_tree_ref,  add_delayed_tree_ref,
>
> -	TP_PROTO(struct btrfs_delayed_ref_node *ref,
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_delayed_ref_node *ref,
>  		 struct btrfs_delayed_tree_ref *full_ref,
>  		 int action),
>
> -	TP_ARGS(ref, full_ref, action)
> +	TP_ARGS(fs_info, ref, full_ref, action)
>  );
>
>  DEFINE_EVENT(btrfs_delayed_tree_ref,  run_delayed_tree_ref,
>
> -	TP_PROTO(struct btrfs_delayed_ref_node *ref,
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_delayed_ref_node *ref,
>  		 struct btrfs_delayed_tree_ref *full_ref,
>  		 int action),
>
> -	TP_ARGS(ref, full_ref, action)
> +	TP_ARGS(fs_info, ref, full_ref, action)
>  );
>
>  DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
>
> -	TP_PROTO(struct btrfs_delayed_ref_node *ref,
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_delayed_ref_node *ref,
>  		 struct btrfs_delayed_data_ref *full_ref,
>  		 int action),
>
> -	TP_ARGS(ref, full_ref, action),
> +	TP_ARGS(fs_info, ref, full_ref, action),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  bytenr		)
>  		__field(	u64,  num_bytes		)
>  		__field(	int,  action		)
> @@ -528,7 +548,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
>  		__field(	u64,  seq		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(fs_info,
>  		__entry->bytenr		= ref->bytenr;
>  		__entry->num_bytes	= ref->num_bytes;
>  		__entry->action		= action;
> @@ -540,7 +560,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
>  		__entry->seq		= ref->seq;
>  	),
>
> -	TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, "
> +	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, action = %s, "
>  		  "parent = %llu(%s), ref_root = %llu(%s), owner = %llu, "
>  		  "offset = %llu, type = %s, seq = %llu",
>  		  (unsigned long long)__entry->bytenr,
> @@ -556,45 +576,48 @@ DECLARE_EVENT_CLASS(btrfs_delayed_data_ref,
>
>  DEFINE_EVENT(btrfs_delayed_data_ref,  add_delayed_data_ref,
>
> -	TP_PROTO(struct btrfs_delayed_ref_node *ref,
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_delayed_ref_node *ref,
>  		 struct btrfs_delayed_data_ref *full_ref,
>  		 int action),
>
> -	TP_ARGS(ref, full_ref, action)
> +	TP_ARGS(fs_info, ref, full_ref, action)
>  );
>
>  DEFINE_EVENT(btrfs_delayed_data_ref,  run_delayed_data_ref,
>
> -	TP_PROTO(struct btrfs_delayed_ref_node *ref,
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_delayed_ref_node *ref,
>  		 struct btrfs_delayed_data_ref *full_ref,
>  		 int action),
>
> -	TP_ARGS(ref, full_ref, action)
> +	TP_ARGS(fs_info, ref, full_ref, action)
>  );
>
>  DECLARE_EVENT_CLASS(btrfs_delayed_ref_head,
>
> -	TP_PROTO(struct btrfs_delayed_ref_node *ref,
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_delayed_ref_node *ref,
>  		 struct btrfs_delayed_ref_head *head_ref,
>  		 int action),
>
> -	TP_ARGS(ref, head_ref, action),
> +	TP_ARGS(fs_info, ref, head_ref, action),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  bytenr		)
>  		__field(	u64,  num_bytes		)
>  		__field(	int,  action		)
>  		__field(	int,  is_data		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(fs_info,
>  		__entry->bytenr		= ref->bytenr;
>  		__entry->num_bytes	= ref->num_bytes;
>  		__entry->action		= action;
>  		__entry->is_data	= head_ref->is_data;
>  	),
>
> -	TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, is_data = %d",
> +	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, action = %s, is_data = %d",
>  		  (unsigned long long)__entry->bytenr,
>  		  (unsigned long long)__entry->num_bytes,
>  		  show_ref_action(__entry->action),
> @@ -603,20 +626,22 @@ DECLARE_EVENT_CLASS(btrfs_delayed_ref_head,
>
>  DEFINE_EVENT(btrfs_delayed_ref_head,  add_delayed_ref_head,
>
> -	TP_PROTO(struct btrfs_delayed_ref_node *ref,
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_delayed_ref_node *ref,
>  		 struct btrfs_delayed_ref_head *head_ref,
>  		 int action),
>
> -	TP_ARGS(ref, head_ref, action)
> +	TP_ARGS(fs_info, ref, head_ref, action)
>  );
>
>  DEFINE_EVENT(btrfs_delayed_ref_head,  run_delayed_ref_head,
>
> -	TP_PROTO(struct btrfs_delayed_ref_node *ref,
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_delayed_ref_node *ref,
>  		 struct btrfs_delayed_ref_head *head_ref,
>  		 int action),
>
> -	TP_ARGS(ref, head_ref, action)
> +	TP_ARGS(fs_info, ref, head_ref, action)
>  );
>
>  #define show_chunk_type(type)					\
> @@ -638,7 +663,7 @@ DECLARE_EVENT_CLASS(btrfs__chunk,
>
>  	TP_ARGS(root, map, offset, size),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	int,  num_stripes		)
>  		__field(	u64,  type			)
>  		__field(	int,  sub_stripes		)
> @@ -647,7 +672,7 @@ DECLARE_EVENT_CLASS(btrfs__chunk,
>  		__field(	u64,  root_objectid		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(root->fs_info,
>  		__entry->num_stripes	= map->num_stripes;
>  		__entry->type		= map->type;
>  		__entry->sub_stripes	= map->sub_stripes;
> @@ -656,7 +681,7 @@ DECLARE_EVENT_CLASS(btrfs__chunk,
>  		__entry->root_objectid	= root->root_key.objectid;
>  	),
>
> -	TP_printk("root = %llu(%s), offset = %llu, size = %llu, "
> +	TP_printk_btrfs("root = %llu(%s), offset = %llu, size = %llu, "
>  		  "num_stripes = %d, sub_stripes = %d, type = %s",
>  		  show_root_type(__entry->root_objectid),
>  		  (unsigned long long)__entry->offset,
> @@ -688,7 +713,7 @@ TRACE_EVENT(btrfs_cow_block,
>
>  	TP_ARGS(root, buf, cow),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  root_objectid		)
>  		__field(	u64,  buf_start			)
>  		__field(	int,  refs			)
> @@ -697,7 +722,7 @@ TRACE_EVENT(btrfs_cow_block,
>  		__field(	int,  cow_level			)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(root->fs_info,
>  		__entry->root_objectid	= root->root_key.objectid;
>  		__entry->buf_start	= buf->start;
>  		__entry->refs		= atomic_read(&buf->refs);
> @@ -706,7 +731,7 @@ TRACE_EVENT(btrfs_cow_block,
>  		__entry->cow_level	= btrfs_header_level(cow);
>  	),
>
> -	TP_printk("root = %llu(%s), refs = %d, orig_buf = %llu "
> +	TP_printk_btrfs("root = %llu(%s), refs = %d, orig_buf = %llu "
>  		  "(orig_level = %d), cow_buf = %llu (cow_level = %d)",
>  		  show_root_type(__entry->root_objectid),
>  		  __entry->refs,
> @@ -723,25 +748,23 @@ TRACE_EVENT(btrfs_space_reservation,
>
>  	TP_ARGS(fs_info, type, val, bytes, reserve),
>
> -	TP_STRUCT__entry(
> -		__array(	u8,	fsid,	BTRFS_UUID_SIZE	)
> +	TP_STRUCT__entry_btrfs(
>  		__string(	type,	type			)
>  		__field(	u64,	val			)
>  		__field(	u64,	bytes			)
>  		__field(	int,	reserve			)
>  	),
>
> -	TP_fast_assign(
> -		memcpy(__entry->fsid, fs_info->fsid, BTRFS_UUID_SIZE);
> +	TP_fast_assign_btrfs(fs_info,
>  		__assign_str(type, type);
>  		__entry->val		= val;
>  		__entry->bytes		= bytes;
>  		__entry->reserve	= reserve;
>  	),
>
> -	TP_printk("%pU: %s: %Lu %s %Lu", __entry->fsid, __get_str(type),
> -		  __entry->val, __entry->reserve ? "reserve" : "release",
> -		  __entry->bytes)
> +	TP_printk_btrfs("%s: %Lu %s %Lu", __get_str(type), __entry->val,
> +			__entry->reserve ? "reserve" : "release",
> +			__entry->bytes)
>  );
>
>  DECLARE_EVENT_CLASS(btrfs__reserved_extent,
> @@ -750,19 +773,19 @@ DECLARE_EVENT_CLASS(btrfs__reserved_extent,
>
>  	TP_ARGS(root, start, len),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  root_objectid		)
>  		__field(	u64,  start			)
>  		__field(	u64,  len			)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(root->fs_info,
>  		__entry->root_objectid	= root->root_key.objectid;
>  		__entry->start		= start;
>  		__entry->len		= len;
>  	),
>
> -	TP_printk("root = %llu(%s), start = %llu, len = %llu",
> +	TP_printk_btrfs("root = %llu(%s), start = %llu, len = %llu",
>  		  show_root_type(__entry->root_objectid),
>  		  (unsigned long long)__entry->start,
>  		  (unsigned long long)__entry->len)
> @@ -789,21 +812,21 @@ TRACE_EVENT(find_free_extent,
>
>  	TP_ARGS(root, num_bytes, empty_size, data),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,	root_objectid		)
>  		__field(	u64,	num_bytes		)
>  		__field(	u64,	empty_size		)
>  		__field(	u64,	data			)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(root->fs_info,
>  		__entry->root_objectid	= root->root_key.objectid;
>  		__entry->num_bytes	= num_bytes;
>  		__entry->empty_size	= empty_size;
>  		__entry->data		= data;
>  	),
>
> -	TP_printk("root = %Lu(%s), len = %Lu, empty_size = %Lu, "
> +	TP_printk_btrfs("root = %Lu(%s), len = %Lu, empty_size = %Lu, "
>  		  "flags = %Lu(%s)", show_root_type(__entry->root_objectid),
>  		  __entry->num_bytes, __entry->empty_size, __entry->data,
>  		  __print_flags((unsigned long)__entry->data, "|",
> @@ -818,7 +841,7 @@ DECLARE_EVENT_CLASS(btrfs__reserve_extent,
>
>  	TP_ARGS(root, block_group, start, len),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,	root_objectid		)
>  		__field(	u64,	bg_objectid		)
>  		__field(	u64,	flags			)
> @@ -826,7 +849,7 @@ DECLARE_EVENT_CLASS(btrfs__reserve_extent,
>  		__field(	u64,	len			)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(root->fs_info,
>  		__entry->root_objectid	= root->root_key.objectid;
>  		__entry->bg_objectid	= block_group->key.objectid;
>  		__entry->flags		= block_group->flags;
> @@ -834,7 +857,7 @@ DECLARE_EVENT_CLASS(btrfs__reserve_extent,
>  		__entry->len		= len;
>  	),
>
> -	TP_printk("root = %Lu(%s), block_group = %Lu, flags = %Lu(%s), "
> +	TP_printk_btrfs("root = %Lu(%s), block_group = %Lu, flags = %Lu(%s), "
>  		  "start = %Lu, len = %Lu",
>  		  show_root_type(__entry->root_objectid), __entry->bg_objectid,
>  		  __entry->flags, __print_flags((unsigned long)__entry->flags,
> @@ -867,7 +890,7 @@ TRACE_EVENT(btrfs_find_cluster,
>
>  	TP_ARGS(block_group, start, bytes, empty_size, min_bytes),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,	bg_objectid		)
>  		__field(	u64,	flags			)
>  		__field(	u64,	start			)
> @@ -876,7 +899,7 @@ TRACE_EVENT(btrfs_find_cluster,
>  		__field(	u64,	min_bytes		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(block_group->fs_info,
>  		__entry->bg_objectid	= block_group->key.objectid;
>  		__entry->flags		= block_group->flags;
>  		__entry->start		= start;
> @@ -885,7 +908,7 @@ TRACE_EVENT(btrfs_find_cluster,
>  		__entry->min_bytes	= min_bytes;
>  	),
>
> -	TP_printk("block_group = %Lu, flags = %Lu(%s), start = %Lu, len = %Lu,"
> +	TP_printk_btrfs("block_group = %Lu, flags = %Lu(%s), start = %Lu, len = %Lu,"
>  		  " empty_size = %Lu, min_bytes = %Lu", __entry->bg_objectid,
>  		  __entry->flags,
>  		  __print_flags((unsigned long)__entry->flags, "|",
> @@ -899,15 +922,15 @@ TRACE_EVENT(btrfs_failed_cluster_setup,
>
>  	TP_ARGS(block_group),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,	bg_objectid		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(block_group->fs_info,
>  		__entry->bg_objectid	= block_group->key.objectid;
>  	),
>
> -	TP_printk("block_group = %Lu", __entry->bg_objectid)
> +	TP_printk_btrfs("block_group = %Lu", __entry->bg_objectid)
>  );
>
>  TRACE_EVENT(btrfs_setup_cluster,
> @@ -917,7 +940,7 @@ TRACE_EVENT(btrfs_setup_cluster,
>
>  	TP_ARGS(block_group, cluster, size, bitmap),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,	bg_objectid		)
>  		__field(	u64,	flags			)
>  		__field(	u64,	start			)
> @@ -926,7 +949,7 @@ TRACE_EVENT(btrfs_setup_cluster,
>  		__field(	int,	bitmap			)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(block_group->fs_info,
>  		__entry->bg_objectid	= block_group->key.objectid;
>  		__entry->flags		= block_group->flags;
>  		__entry->start		= cluster->window_start;
> @@ -935,7 +958,7 @@ TRACE_EVENT(btrfs_setup_cluster,
>  		__entry->bitmap		= bitmap;
>  	),
>
> -	TP_printk("block_group = %Lu, flags = %Lu(%s), window_start = %Lu, "
> +	TP_printk_btrfs("block_group = %Lu, flags = %Lu(%s), window_start = %Lu, "
>  		  "size = %Lu, max_size = %Lu, bitmap = %d",
>  		  __entry->bg_objectid,
>  		  __entry->flags,
> @@ -993,7 +1016,7 @@ DECLARE_EVENT_CLASS(btrfs__work,
>
>  	TP_ARGS(work),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	void *,	work			)
>  		__field(	void *, wq			)
>  		__field(	void *,	func			)
> @@ -1002,7 +1025,7 @@ DECLARE_EVENT_CLASS(btrfs__work,
>  		__field(	void *,	normal_work		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_work_owner(work),
>  		__entry->work		= work;
>  		__entry->wq		= work->wq;
>  		__entry->func		= work->func;
> @@ -1011,7 +1034,7 @@ DECLARE_EVENT_CLASS(btrfs__work,
>  		__entry->normal_work	= &work->normal_work;
>  	),
>
> -	TP_printk("work=%p (normal_work=%p), wq=%p, func=%pf, ordered_func=%p,"
> +	TP_printk_btrfs("work=%p (normal_work=%p), wq=%p, func=%pf, ordered_func=%p,"
>  		  " ordered_free=%p",
>  		  __entry->work, __entry->normal_work, __entry->wq,
>  		   __entry->func, __entry->ordered_func, __entry->ordered_free)
> @@ -1024,15 +1047,15 @@ DECLARE_EVENT_CLASS(btrfs__work__done,
>
>  	TP_ARGS(work),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	void *,	work			)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_work_owner(work),
>  		__entry->work		= work;
>  	),
>
> -	TP_printk("work->%p", __entry->work)
> +	TP_printk_btrfs("work->%p", __entry->work)
>  );
>
>  DEFINE_EVENT(btrfs__work, btrfs_work_queued,
> @@ -1069,19 +1092,19 @@ DECLARE_EVENT_CLASS(btrfs__workqueue,
>
>  	TP_ARGS(wq, name, high),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	void *,	wq			)
>  		__string(	name,	name			)
>  		__field(	int ,	high			)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
>  		__entry->wq		= wq;
>  		__assign_str(name, name);
>  		__entry->high		= high;
>  	),
>
> -	TP_printk("name=%s%s, wq=%p", __get_str(name),
> +	TP_printk_btrfs("name=%s%s, wq=%p", __get_str(name),
>  		  __print_flags(__entry->high, "",
>  				{(WQ_HIGHPRI),	"-high"}),
>  		  __entry->wq)
> @@ -1100,15 +1123,15 @@ DECLARE_EVENT_CLASS(btrfs__workqueue_done,
>
>  	TP_ARGS(wq),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	void *,	wq			)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_workqueue_owner(wq),
>  		__entry->wq		= wq;
>  	),
>
> -	TP_printk("wq=%p", __entry->wq)
> +	TP_printk_btrfs("wq=%p", __entry->wq)
>  );
>
>  DEFINE_EVENT(btrfs__workqueue_done, btrfs_workqueue_destroy,
> @@ -1124,19 +1147,19 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_data_map,
>
>  	TP_ARGS(inode, free_reserved),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,		rootid		)
>  		__field(	unsigned long,	ino		)
>  		__field(	u64,		free_reserved	)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
>  		__entry->rootid		=	BTRFS_I(inode)->root->objectid;
>  		__entry->ino		=	inode->i_ino;
>  		__entry->free_reserved	=	free_reserved;
>  	),
>
> -	TP_printk("rootid=%llu, ino=%lu, free_reserved=%llu",
> +	TP_printk_btrfs("rootid=%llu, ino=%lu, free_reserved=%llu",
>  		  __entry->rootid, __entry->ino, __entry->free_reserved)
>  );
>
> @@ -1165,7 +1188,7 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data,
>
>  	TP_ARGS(inode, start, len, reserved, op),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,		rootid		)
>  		__field(	unsigned long,	ino		)
>  		__field(	u64,		start		)
> @@ -1174,7 +1197,7 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data,
>  		__field(	int,		op		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(btrfs_sb(inode->i_sb),
>  		__entry->rootid		= BTRFS_I(inode)->root->objectid;
>  		__entry->ino		= inode->i_ino;
>  		__entry->start		= start;
> @@ -1183,7 +1206,7 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data,
>  		__entry->op		= op;
>  	),
>
> -	TP_printk("root=%llu, ino=%lu, start=%llu, len=%llu, reserved=%llu, op=%s",
> +	TP_printk_btrfs("root=%llu, ino=%lu, start=%llu, len=%llu, reserved=%llu, op=%s",
>  		  __entry->rootid, __entry->ino, __entry->start, __entry->len,
>  		  __entry->reserved,
>  		  __print_flags((unsigned long)__entry->op, "",
> @@ -1207,86 +1230,90 @@ DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_release_data,
>
>  DECLARE_EVENT_CLASS(btrfs__qgroup_delayed_ref,
>
> -	TP_PROTO(u64 ref_root, u64 reserved),
> +	TP_PROTO(struct btrfs_fs_info *fs_info, u64 ref_root, u64 reserved),
>
> -	TP_ARGS(ref_root, reserved),
> +	TP_ARGS(fs_info, ref_root, reserved),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,		ref_root	)
>  		__field(	u64,		reserved	)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(fs_info,
>  		__entry->ref_root	= ref_root;
>  		__entry->reserved	= reserved;
>  	),
>
> -	TP_printk("root=%llu, reserved=%llu, op=free",
> +	TP_printk_btrfs("root=%llu, reserved=%llu, op=free",
>  		  __entry->ref_root, __entry->reserved)
>  );
>
>  DEFINE_EVENT(btrfs__qgroup_delayed_ref, btrfs_qgroup_free_delayed_ref,
>
> -	TP_PROTO(u64 ref_root, u64 reserved),
> +	TP_PROTO(struct btrfs_fs_info *fs_info, u64 ref_root, u64 reserved),
>
> -	TP_ARGS(ref_root, reserved)
> +	TP_ARGS(fs_info, ref_root, reserved)
>  );
>
>  DECLARE_EVENT_CLASS(btrfs_qgroup_extent,
> -	TP_PROTO(struct btrfs_qgroup_extent_record *rec),
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_qgroup_extent_record *rec),
>
> -	TP_ARGS(rec),
> +	TP_ARGS(fs_info, rec),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  bytenr		)
>  		__field(	u64,  num_bytes		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(fs_info,
>  		__entry->bytenr		= rec->bytenr,
>  		__entry->num_bytes	= rec->num_bytes;
>  	),
>
> -	TP_printk("bytenr = %llu, num_bytes = %llu",
> +	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu",
>  		  (unsigned long long)__entry->bytenr,
>  		  (unsigned long long)__entry->num_bytes)
>  );
>
>  DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents,
>
> -	TP_PROTO(struct btrfs_qgroup_extent_record *rec),
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_qgroup_extent_record *rec),
>
> -	TP_ARGS(rec)
> +	TP_ARGS(fs_info, rec)
>  );
>
>  DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_insert_dirty_extent,
>
> -	TP_PROTO(struct btrfs_qgroup_extent_record *rec),
> +	TP_PROTO(struct btrfs_fs_info *fs_info,
> +		 struct btrfs_qgroup_extent_record *rec),
>
> -	TP_ARGS(rec)
> +	TP_ARGS(fs_info, rec)
>  );
>
>  TRACE_EVENT(btrfs_qgroup_account_extent,
>
> -	TP_PROTO(u64 bytenr, u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots),
> +	TP_PROTO(struct btrfs_fs_info *fs_info, u64 bytenr,
> +		 u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots),
>
> -	TP_ARGS(bytenr, num_bytes, nr_old_roots, nr_new_roots),
> +	TP_ARGS(fs_info, bytenr, num_bytes, nr_old_roots, nr_new_roots),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  bytenr			)
>  		__field(	u64,  num_bytes			)
>  		__field(	u64,  nr_old_roots		)
>  		__field(	u64,  nr_new_roots		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(fs_info,
>  		__entry->bytenr		= bytenr;
>  		__entry->num_bytes	= num_bytes;
>  		__entry->nr_old_roots	= nr_old_roots;
>  		__entry->nr_new_roots	= nr_new_roots;
>  	),
>
> -	TP_printk("bytenr = %llu, num_bytes = %llu, nr_old_roots = %llu, "
> +	TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, nr_old_roots = %llu, "
>  		  "nr_new_roots = %llu",
>  		  __entry->bytenr,
>  		  __entry->num_bytes,
> @@ -1296,23 +1323,24 @@ TRACE_EVENT(btrfs_qgroup_account_extent,
>
>  TRACE_EVENT(qgroup_update_counters,
>
> -	TP_PROTO(u64 qgid, u64 cur_old_count, u64 cur_new_count),
> +	TP_PROTO(struct btrfs_fs_info *fs_info, u64 qgid,
> +		 u64 cur_old_count, u64 cur_new_count),
>
> -	TP_ARGS(qgid, cur_old_count, cur_new_count),
> +	TP_ARGS(fs_info, qgid, cur_old_count, cur_new_count),
>
> -	TP_STRUCT__entry(
> +	TP_STRUCT__entry_btrfs(
>  		__field(	u64,  qgid			)
>  		__field(	u64,  cur_old_count		)
>  		__field(	u64,  cur_new_count		)
>  	),
>
> -	TP_fast_assign(
> +	TP_fast_assign_btrfs(fs_info,
>  		__entry->qgid		= qgid;
>  		__entry->cur_old_count	= cur_old_count;
>  		__entry->cur_new_count	= cur_new_count;
>  	),
>
> -	TP_printk("qgid = %llu, cur_old_count = %llu, cur_new_count = %llu",
> +	TP_printk_btrfs("qgid = %llu, cur_old_count = %llu, cur_new_count = %llu",
>  		  __entry->qgid,
>  		  __entry->cur_old_count,
>  		  __entry->cur_new_count)
>



^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info
  2016-06-24 22:14 ` [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info jeffm
@ 2016-06-27  2:14   ` Qu Wenruo
  2016-06-27  2:21     ` Jeff Mahoney
  0 siblings, 1 reply; 44+ messages in thread
From: Qu Wenruo @ 2016-06-27  2:14 UTC (permalink / raw)
  To: jeffm, linux-btrfs



At 06/25/2016 06:14 AM, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
>
> btrfs_test_opt and friends only use the root pointer to access
> the fs_info.  Let's pass the fs_info directly in preparation to
> eliminate similar patterns all over btrfs.
>
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
> ---
>  fs/btrfs/ctree.h            |  22 ++++----
>  fs/btrfs/delayed-inode.c    |   2 +-
>  fs/btrfs/dev-replace.c      |   4 +-
>  fs/btrfs/disk-io.c          |  22 ++++----
>  fs/btrfs/extent-tree.c      |  32 +++++------
>  fs/btrfs/file.c             |   2 +-
>  fs/btrfs/free-space-cache.c |   6 +-
>  fs/btrfs/inode-map.c        |  12 ++--
>  fs/btrfs/inode.c            |  12 ++--
>  fs/btrfs/ioctl.c            |   2 +-
>  fs/btrfs/super.c            | 132 +++++++++++++++++++++++---------------------
>  fs/btrfs/transaction.c      |   6 +-
>  fs/btrfs/tree-log.c         |   4 +-
>  fs/btrfs/volumes.c          |  11 ++--
>  14 files changed, 137 insertions(+), 132 deletions(-)
>
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 101c3cf..100d2ea 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -1297,21 +1297,21 @@ struct btrfs_root {
>  #define btrfs_clear_opt(o, opt)		((o) &= ~BTRFS_MOUNT_##opt)
>  #define btrfs_set_opt(o, opt)		((o) |= BTRFS_MOUNT_##opt)
>  #define btrfs_raw_test_opt(o, opt)	((o) & BTRFS_MOUNT_##opt)
> -#define btrfs_test_opt(root, opt)	((root)->fs_info->mount_opt & \
> +#define btrfs_test_opt(fs_info, opt)	((fs_info)->mount_opt & \
>  					 BTRFS_MOUNT_##opt)
>
> -#define btrfs_set_and_info(root, opt, fmt, args...)			\
> +#define btrfs_set_and_info(fs_info, opt, fmt, args...)			\
>  {									\
> -	if (!btrfs_test_opt(root, opt))					\
> -		btrfs_info(root->fs_info, fmt, ##args);			\
> -	btrfs_set_opt(root->fs_info->mount_opt, opt);			\
> +	if (!btrfs_test_opt(fs_info, opt))				\
> +		btrfs_info(fs_info, fmt, ##args);			\
> +	btrfs_set_opt(fs_info->mount_opt, opt);				\
>  }
>
> -#define btrfs_clear_and_info(root, opt, fmt, args...)			\
> +#define btrfs_clear_and_info(fs_info, opt, fmt, args...)		\
>  {									\
> -	if (btrfs_test_opt(root, opt))					\
> -		btrfs_info(root->fs_info, fmt, ##args);			\
> -	btrfs_clear_opt(root->fs_info->mount_opt, opt);			\
> +	if (btrfs_test_opt(fs_info, opt))				\
> +		btrfs_info(fs_info, fmt, ##args);			\
> +	btrfs_clear_opt(fs_info->mount_opt, opt);			\
>  }
>
>  #ifdef CONFIG_BTRFS_DEBUG
> @@ -1319,9 +1319,9 @@ static inline int
>  btrfs_should_fragment_free_space(struct btrfs_root *root,
>  				 struct btrfs_block_group_cache *block_group)
>  {
> -	return (btrfs_test_opt(root, FRAGMENT_METADATA) &&
> +	return (btrfs_test_opt(root->fs_info, FRAGMENT_METADATA) &&
>  		block_group->flags & BTRFS_BLOCK_GROUP_METADATA) ||
> -	       (btrfs_test_opt(root, FRAGMENT_DATA) &&
> +	       (btrfs_test_opt(root->fs_info, FRAGMENT_DATA) &&
>  		block_group->flags &  BTRFS_BLOCK_GROUP_DATA);
>  }
>  #endif
> diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
> index 61561c2..ed67717 100644
> --- a/fs/btrfs/delayed-inode.c
> +++ b/fs/btrfs/delayed-inode.c
> @@ -653,7 +653,7 @@ static int btrfs_delayed_inode_reserve_metadata(
>  		if (!ret)
>  			goto out;
>
> -		if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
> +		if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>  			btrfs_debug(root->fs_info,
>  				    "block rsv migrate returned %d", ret);
>  			WARN_ON(1);
> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
> index 63ef9cd..e9bbff3 100644
> --- a/fs/btrfs/dev-replace.c
> +++ b/fs/btrfs/dev-replace.c
> @@ -142,7 +142,7 @@ no_valid_dev_replace_entry_found:
>  		 * missing
>  		 */
>  		if (!dev_replace->srcdev &&
> -		    !btrfs_test_opt(dev_root, DEGRADED)) {
> +		    !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
Just fs_info, as following btrfs_warn() is using fs_info.

>  			ret = -EIO;
>  			btrfs_warn(fs_info,
>  			   "cannot mount because device replace operation is ongoing and");
> @@ -151,7 +151,7 @@ no_valid_dev_replace_entry_found:
>  			   src_devid);
>  		}
>  		if (!dev_replace->tgtdev &&
> -		    !btrfs_test_opt(dev_root, DEGRADED)) {
> +		    !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {

Same here.

>  			ret = -EIO;
>  			btrfs_warn(fs_info,
>  			   "cannot mount because device replace operation is ongoing and");
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 685c81a..8f27127 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -3025,8 +3025,8 @@ retry_root_backup:
>  	if (IS_ERR(fs_info->transaction_kthread))
>  		goto fail_cleaner;
>
> -	if (!btrfs_test_opt(tree_root, SSD) &&
> -	    !btrfs_test_opt(tree_root, NOSSD) &&
> +	if (!btrfs_test_opt(tree_root->fs_info, SSD) &&
> +	    !btrfs_test_opt(tree_root->fs_info, NOSSD) &&

Same fs_info here.

>  	    !fs_info->fs_devices->rotating) {
>  		btrfs_info(fs_info, "detected SSD devices, enabling SSD mode");
>  		btrfs_set_opt(fs_info->mount_opt, SSD);
> @@ -3039,9 +3039,9 @@ retry_root_backup:
>  	btrfs_apply_pending_changes(fs_info);
>
>  #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
> -	if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) {
> +	if (btrfs_test_opt(tree_root->fs_info, CHECK_INTEGRITY)) {
>  		ret = btrfsic_mount(tree_root, fs_devices,
> -				    btrfs_test_opt(tree_root,
> +				    btrfs_test_opt(tree_root->fs_info,

Same here.

>  					CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
>  				    1 : 0,
>  				    fs_info->check_integrity_print_mask);
> @@ -3057,7 +3057,7 @@ retry_root_backup:
>
>  	/* do not make disk changes in broken FS or nologreplay is given */
>  	if (btrfs_super_log_root(disk_super) != 0 &&
> -	    !btrfs_test_opt(tree_root, NOLOGREPLAY)) {
> +	    !btrfs_test_opt(tree_root->fs_info, NOLOGREPLAY)) {
Same here.
>  		ret = btrfs_replay_log(fs_info, fs_devices);
>  		if (ret) {
>  			err = ret;
> @@ -3098,7 +3098,7 @@ retry_root_backup:
>  	if (sb->s_flags & MS_RDONLY)
>  		return 0;
>
> -	if (btrfs_test_opt(tree_root, FREE_SPACE_TREE) &&
> +	if (btrfs_test_opt(tree_root->fs_info, FREE_SPACE_TREE) &&
Same here.
>  	    !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
>  		btrfs_info(fs_info, "creating free space tree");
>  		ret = btrfs_create_free_space_tree(fs_info);
> @@ -3135,7 +3135,7 @@ retry_root_backup:
>
>  	btrfs_qgroup_rescan_resume(fs_info);
>
> -	if (btrfs_test_opt(tree_root, CLEAR_CACHE) &&
> +	if (btrfs_test_opt(tree_root->fs_info, CLEAR_CACHE) &&

Same here.

>  	    btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
>  		btrfs_info(fs_info, "clearing free space tree");
>  		ret = btrfs_clear_free_space_tree(fs_info);
> @@ -3156,7 +3156,7 @@ retry_root_backup:
>  			close_ctree(tree_root);
>  			return ret;
>  		}
> -	} else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) ||
> +	} else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) ||
Same here
>  		   fs_info->generation !=
>  				btrfs_super_uuid_tree_generation(disk_super)) {
>  		btrfs_info(fs_info, "checking UUID tree");
> @@ -3233,7 +3233,7 @@ fail:
>  	return err;
>
>  recovery_tree_root:
> -	if (!btrfs_test_opt(tree_root, USEBACKUPROOT))
> +	if (!btrfs_test_opt(tree_root->fs_info, USEBACKUPROOT))
Same here, any fs_info user inside open_ctree() can directly use fs_info.
>  		goto fail_tree_roots;
>
>  	free_root_pointers(fs_info, 0);
> @@ -3648,7 +3648,7 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors)
>  	int total_errors = 0;
>  	u64 flags;
>
> -	do_barriers = !btrfs_test_opt(root, NOBARRIER);
> +	do_barriers = !btrfs_test_opt(root->fs_info, NOBARRIER);
>  	backup_super_roots(root->fs_info);
>
>  	sb = root->fs_info->super_for_commit;
> @@ -3932,7 +3932,7 @@ void close_ctree(struct btrfs_root *root)
>  	iput(fs_info->btree_inode);
>
>  #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
> -	if (btrfs_test_opt(root, CHECK_INTEGRITY))
> +	if (btrfs_test_opt(root->fs_info, CHECK_INTEGRITY))
Same here.

Get fs_info at the beginning of close_ctree().

>  		btrfsic_unmount(root, fs_info->fs_devices);
>  #endif
>
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 39308a8..efb5459 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -3427,7 +3427,7 @@ again:
>
>  	spin_lock(&block_group->lock);
>  	if (block_group->cached != BTRFS_CACHE_FINISHED ||
> -	    !btrfs_test_opt(root, SPACE_CACHE)) {
> +	    !btrfs_test_opt(root->fs_info, SPACE_CACHE)) {

>  		/*
>  		 * don't bother trying to write stuff out _if_
>  		 * a) we're not cached,
> @@ -3504,7 +3504,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
>  	struct btrfs_path *path;
>
>  	if (list_empty(&cur_trans->dirty_bgs) ||
> -	    !btrfs_test_opt(root, SPACE_CACHE))
> +	    !btrfs_test_opt(root->fs_info, SPACE_CACHE))
>  		return 0;
>
>  	path = btrfs_alloc_path();
> @@ -4417,7 +4417,7 @@ void check_system_chunk(struct btrfs_trans_handle *trans,
>  	thresh = btrfs_calc_trunc_metadata_size(root, num_devs) +
>  		btrfs_calc_trans_metadata_size(root, 1);
>
> -	if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) {
> +	if (left < thresh && btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>  		btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
>  			left, thresh, type);
>  		dump_space_info(info, 0, 0);
> @@ -6009,7 +6009,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
>  		spin_lock(&cache->space_info->lock);
>  		spin_lock(&cache->lock);
>
> -		if (btrfs_test_opt(root, SPACE_CACHE) &&
> +		if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&

Same here.
Fs_info is extracted at the beginning of update_block_group().

>  		    cache->disk_cache_state < BTRFS_DC_CLEAR)
>  			cache->disk_cache_state = BTRFS_DC_CLEAR;
>
> @@ -6388,7 +6388,7 @@ fetch_cluster_info(struct btrfs_root *root, struct btrfs_space_info *space_info,
>  		   u64 *empty_cluster)
>  {
>  	struct btrfs_free_cluster *ret = NULL;
> -	bool ssd = btrfs_test_opt(root, SSD);
> +	bool ssd = btrfs_test_opt(root->fs_info, SSD);
>
>  	*empty_cluster = 0;
>  	if (btrfs_mixed_space_info(space_info))
> @@ -6518,7 +6518,7 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
>  			break;
>  		}
>
> -		if (btrfs_test_opt(root, DISCARD))
> +		if (btrfs_test_opt(root->fs_info, DISCARD))

Same here.

>  			ret = btrfs_discard_extent(root, start,
>  						   end + 1 - start, NULL);
>
> @@ -7737,7 +7737,7 @@ again:
>  			if (num_bytes == min_alloc_size)
>  				final_tried = true;
>  			goto again;
> -		} else if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
> +		} else if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>  			struct btrfs_space_info *sinfo;
>
>  			sinfo = __find_space_info(root->fs_info, flags);
> @@ -7768,7 +7768,7 @@ static int __btrfs_free_reserved_extent(struct btrfs_root *root,
>  	if (pin)
>  		pin_down_extent(root, cache, start, len, 1);
>  	else {
> -		if (btrfs_test_opt(root, DISCARD))
> +		if (btrfs_test_opt(root->fs_info, DISCARD))
>  			ret = btrfs_discard_extent(root, start, len, NULL);
>  		btrfs_add_free_space(cache, start, len);
>  		btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc);
> @@ -8078,7 +8078,7 @@ again:
>  		goto again;
>  	}
>
> -	if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
> +	if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>  		static DEFINE_RATELIMIT_STATE(_rs,
>  				DEFAULT_RATELIMIT_INTERVAL * 10,
>  				/*DEFAULT_RATELIMIT_BURST*/ 1);
> @@ -9510,7 +9510,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
>  	int full = 0;
>  	int ret = 0;
>
> -	debug = btrfs_test_opt(root, ENOSPC_DEBUG);
> +	debug = btrfs_test_opt(root->fs_info, ENOSPC_DEBUG);
>
>  	block_group = btrfs_lookup_block_group(root->fs_info, bytenr);
>
> @@ -9782,7 +9782,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
>  		space_info = list_entry(info->space_info.next,
>  					struct btrfs_space_info,
>  					list);
> -		if (btrfs_test_opt(info->tree_root, ENOSPC_DEBUG)) {
> +		if (btrfs_test_opt(info, ENOSPC_DEBUG)) {
>  			if (WARN_ON(space_info->bytes_pinned > 0 ||
>  			    space_info->bytes_reserved > 0 ||
>  			    space_info->bytes_may_use > 0)) {
> @@ -9906,10 +9906,10 @@ int btrfs_read_block_groups(struct btrfs_root *root)
>  	path->reada = READA_FORWARD;
>
>  	cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
> -	if (btrfs_test_opt(root, SPACE_CACHE) &&
> +	if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
Same here.
btrfs_read_block_groups() has fs_info extracted as info.

>  	    btrfs_super_generation(root->fs_info->super_copy) != cache_gen)
>  		need_clear = 1;
> -	if (btrfs_test_opt(root, CLEAR_CACHE))
> +	if (btrfs_test_opt(root->fs_info, CLEAR_CACHE))
Same here
>  		need_clear = 1;
>
>  	while (1) {
> @@ -9940,7 +9940,7 @@ int btrfs_read_block_groups(struct btrfs_root *root)
>  			 * b) Setting 'dirty flag' makes sure that we flush
>  			 *    the new space cache info onto disk.
>  			 */
> -			if (btrfs_test_opt(root, SPACE_CACHE))
> +			if (btrfs_test_opt(root->fs_info, SPACE_CACHE))
Same here
>  				cache->disk_cache_state = BTRFS_DC_CLEAR;
>  		}
>
> @@ -10406,7 +10406,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
>  	spin_lock(&block_group->space_info->lock);
>  	list_del_init(&block_group->ro_list);
>
> -	if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
> +	if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>  		WARN_ON(block_group->space_info->total_bytes
>  			< block_group->key.offset);
>  		WARN_ON(block_group->space_info->bytes_readonly
> @@ -10674,7 +10674,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
>  		spin_unlock(&space_info->lock);
>
>  		/* DISCARD can flip during remount */
> -		trimming = btrfs_test_opt(root, DISCARD);
> +		trimming = btrfs_test_opt(root->fs_info, DISCARD);
>
>  		/* Implicit trim during transaction commit. */
>  		if (trimming)
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index e0c9bd3..ffd9001 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -132,7 +132,7 @@ static int __btrfs_add_inode_defrag(struct inode *inode,
>
>  static inline int __need_auto_defrag(struct btrfs_root *root)
>  {
> -	if (!btrfs_test_opt(root, AUTO_DEFRAG))
> +	if (!btrfs_test_opt(root->fs_info, AUTO_DEFRAG))
>  		return 0;
>
>  	if (btrfs_fs_closing(root->fs_info))
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 69d270f..cee2049 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -3026,7 +3026,7 @@ int btrfs_find_space_cluster(struct btrfs_root *root,
>  	 * For metadata, allow allocates with smaller extents.  For
>  	 * data, keep it dense.
>  	 */
> -	if (btrfs_test_opt(root, SSD_SPREAD)) {
> +	if (btrfs_test_opt(root->fs_info, SSD_SPREAD)) {
>  		cont1_bytes = min_bytes = bytes + empty_size;
>  	} else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) {
>  		cont1_bytes = bytes;
> @@ -3470,7 +3470,7 @@ int load_free_ino_cache(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
>  	int ret = 0;
>  	u64 root_gen = btrfs_root_generation(&root->root_item);
>
> -	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
> +	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
>  		return 0;
>
>  	/*
> @@ -3514,7 +3514,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
>  	struct btrfs_io_ctl io_ctl;
>  	bool release_metadata = true;
>
> -	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
> +	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
>  		return 0;
>
>  	memset(&io_ctl, 0, sizeof(io_ctl));
> diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
> index 70107f7..e3ad8c1 100644
> --- a/fs/btrfs/inode-map.c
> +++ b/fs/btrfs/inode-map.c
> @@ -38,7 +38,7 @@ static int caching_kthread(void *data)
>  	int slot;
>  	int ret;
>
> -	if (!btrfs_test_opt(root, INODE_MAP_CACHE))
> +	if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
Caching_kthread() has fs_info extracted.
So same here.

Although such modification won't do anything real to the generated 
binary, but never a bad idea to make code a little clearer.

Thanks,
Qu



^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 04/31] btrfs: tests, move initialization into tests/
  2016-06-24 22:14 ` [PATCH 04/31] btrfs: tests, move initialization into tests/ jeffm
@ 2016-06-27  2:17   ` Qu Wenruo
  2016-06-27  2:28     ` Jeff Mahoney
  0 siblings, 1 reply; 44+ messages in thread
From: Qu Wenruo @ 2016-06-27  2:17 UTC (permalink / raw)
  To: jeffm, linux-btrfs



At 06/25/2016 06:14 AM, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
>
> We have all these stubs that only exist because they're called from
> btrfs_run_sanity_tests, which is a static inside super.c.  Let's just
> move it all into tests/btrfs-tests.c and only have one stub.
>
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
> ---
>  fs/btrfs/super.c             | 43 ----------------------------------------
>  fs/btrfs/tests/btrfs-tests.c | 47 ++++++++++++++++++++++++++++++++++++++++++--
>  fs/btrfs/tests/btrfs-tests.h | 35 +++------------------------------
>  3 files changed, 48 insertions(+), 77 deletions(-)
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index a7b9a15..d8e48bb 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -2323,49 +2323,6 @@ static void btrfs_print_mod_info(void)
>  			btrfs_crc32c_impl());
>  }
>
> -static int btrfs_run_sanity_tests(void)
> -{
> -	int ret, i;
> -	u32 sectorsize, nodesize;
> -	u32 test_sectorsize[] = {
> -		PAGE_SIZE,
> -	};
> -	ret = btrfs_init_test_fs();
> -	if (ret)
> -		return ret;
> -	for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) {
> -		sectorsize = test_sectorsize[i];
> -		for (nodesize = sectorsize;
> -		     nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE;
> -		     nodesize <<= 1) {
> -			pr_info("BTRFS: selftest: sectorsize: %u  nodesize: %u\n",
> -				sectorsize, nodesize);
> -			ret = btrfs_test_free_space_cache(sectorsize, nodesize);
> -			if (ret)
> -				goto out;
> -			ret = btrfs_test_extent_buffer_operations(sectorsize,
> -				nodesize);
> -			if (ret)
> -				goto out;
> -			ret = btrfs_test_extent_io(sectorsize, nodesize);
> -			if (ret)
> -				goto out;
> -			ret = btrfs_test_inodes(sectorsize, nodesize);
> -			if (ret)
> -				goto out;
> -			ret = btrfs_test_qgroups(sectorsize, nodesize);
> -			if (ret)
> -				goto out;
> -			ret = btrfs_test_free_space_tree(sectorsize, nodesize);
> -			if (ret)
> -				goto out;
> -		}
> -	}
> -out:
> -	btrfs_destroy_test_fs();
> -	return ret;
> -}
> -
>  static int __init init_btrfs_fs(void)
>  {
>  	int err;
> diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
> index 10eb249..d90c951 100644
> --- a/fs/btrfs/tests/btrfs-tests.c
> +++ b/fs/btrfs/tests/btrfs-tests.c
> @@ -54,7 +54,7 @@ struct inode *btrfs_new_test_inode(void)
>  	return new_inode(test_mnt->mnt_sb);
>  }
>
> -int btrfs_init_test_fs(void)
> +static int btrfs_init_test_fs(void)
>  {
>  	int ret;
>
> @@ -73,7 +73,7 @@ int btrfs_init_test_fs(void)
>  	return 0;
>  }
>
> -void btrfs_destroy_test_fs(void)
> +static void btrfs_destroy_test_fs(void)
>  {
>  	kern_unmount(test_mnt);
>  	unregister_filesystem(&test_type);
> @@ -220,3 +220,46 @@ void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans)
>  	INIT_LIST_HEAD(&trans->qgroup_ref_list);
>  	trans->type = __TRANS_DUMMY;
>  }
> +
> +int btrfs_run_sanity_tests(void)
> +{
> +	int ret, i;
> +	u32 sectorsize, nodesize;
> +	u32 test_sectorsize[] = {
> +		PAGE_SIZE,
> +	};
> +	ret = btrfs_init_test_fs();
> +	if (ret)
> +		return ret;
> +	for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) {
> +		sectorsize = test_sectorsize[i];
> +		for (nodesize = sectorsize;
> +		     nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE;
> +		     nodesize <<= 1) {
> +			pr_info("BTRFS: selftest: sectorsize: %u  nodesize: %u\n",
> +				sectorsize, nodesize);
> +			ret = btrfs_test_free_space_cache(sectorsize, nodesize);
> +			if (ret)
> +				goto out;
> +			ret = btrfs_test_extent_buffer_operations(sectorsize,
> +				nodesize);
> +			if (ret)
> +				goto out;
> +			ret = btrfs_test_extent_io(sectorsize, nodesize);
> +			if (ret)
> +				goto out;
> +			ret = btrfs_test_inodes(sectorsize, nodesize);
> +			if (ret)
> +				goto out;
> +			ret = btrfs_test_qgroups(sectorsize, nodesize);
> +			if (ret)
> +				goto out;
> +			ret = btrfs_test_free_space_tree(sectorsize, nodesize);
> +			if (ret)
> +				goto out;
> +		}
> +	}
> +out:
> +	btrfs_destroy_test_fs();
> +	return ret;
> +}
> diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h
> index 66fb6b70..e7d364f 100644
> --- a/fs/btrfs/tests/btrfs-tests.h
> +++ b/fs/btrfs/tests/btrfs-tests.h
> @@ -20,20 +20,19 @@
>  #define __BTRFS_TESTS
>
>  #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
> +int btrfs_run_sanity_tests(void);
>
>  #define test_msg(fmt, ...) pr_info("BTRFS: selftest: " fmt, ##__VA_ARGS__)
>
>  struct btrfs_root;
>  struct btrfs_trans_handle;
>
> -int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize);
>  int btrfs_test_extent_buffer_operations(u32 sectorsize, u32 nodesize);
> +int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize);

Anything special for the line move?
Otherwise it looks good for me.

Thanks,
Qu
>  int btrfs_test_extent_io(u32 sectorsize, u32 nodesize);
>  int btrfs_test_inodes(u32 sectorsize, u32 nodesize);
>  int btrfs_test_qgroups(u32 sectorsize, u32 nodesize);
>  int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
> -int btrfs_init_test_fs(void);
> -void btrfs_destroy_test_fs(void);
>  struct inode *btrfs_new_test_inode(void);
>  struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void);
>  void btrfs_free_dummy_root(struct btrfs_root *root);
> @@ -42,35 +41,7 @@ btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize);
>  void btrfs_free_dummy_block_group(struct btrfs_block_group_cache *cache);
>  void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans);
>  #else
> -static inline int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
> -{
> -	return 0;
> -}
> -static inline int btrfs_test_extent_buffer_operations(u32 sectorsize,
> -	u32 nodesize)
> -{
> -	return 0;
> -}
> -static inline int btrfs_init_test_fs(void)
> -{
> -	return 0;
> -}
> -static inline void btrfs_destroy_test_fs(void)
> -{
> -}
> -static inline int btrfs_test_extent_io(u32 sectorsize, u32 nodesize)
> -{
> -	return 0;
> -}
> -static inline int btrfs_test_inodes(u32 sectorsize, u32 nodesize)
> -{
> -	return 0;
> -}
> -static inline int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
> -{
> -	return 0;
> -}
> -static inline int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize)
> +static inline int btrfs_run_sanity_tests(void)
>  {
>  	return 0;
>  }
>



^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info
  2016-06-27  2:14   ` Qu Wenruo
@ 2016-06-27  2:21     ` Jeff Mahoney
  2016-06-27  2:24       ` Qu Wenruo
  0 siblings, 1 reply; 44+ messages in thread
From: Jeff Mahoney @ 2016-06-27  2:21 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 19205 bytes --]

On 6/26/16 10:14 PM, Qu Wenruo wrote:
> 
> 
> At 06/25/2016 06:14 AM, jeffm@suse.com wrote:
>> From: Jeff Mahoney <jeffm@suse.com>
>>
>> btrfs_test_opt and friends only use the root pointer to access
>> the fs_info.  Let's pass the fs_info directly in preparation to
>> eliminate similar patterns all over btrfs.
>>
>> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
>> ---
>>  fs/btrfs/ctree.h            |  22 ++++----
>>  fs/btrfs/delayed-inode.c    |   2 +-
>>  fs/btrfs/dev-replace.c      |   4 +-
>>  fs/btrfs/disk-io.c          |  22 ++++----
>>  fs/btrfs/extent-tree.c      |  32 +++++------
>>  fs/btrfs/file.c             |   2 +-
>>  fs/btrfs/free-space-cache.c |   6 +-
>>  fs/btrfs/inode-map.c        |  12 ++--
>>  fs/btrfs/inode.c            |  12 ++--
>>  fs/btrfs/ioctl.c            |   2 +-
>>  fs/btrfs/super.c            | 132
>> +++++++++++++++++++++++---------------------
>>  fs/btrfs/transaction.c      |   6 +-
>>  fs/btrfs/tree-log.c         |   4 +-
>>  fs/btrfs/volumes.c          |  11 ++--
>>  14 files changed, 137 insertions(+), 132 deletions(-)
>>
>> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
>> index 101c3cf..100d2ea 100644
>> --- a/fs/btrfs/ctree.h
>> +++ b/fs/btrfs/ctree.h
>> @@ -1297,21 +1297,21 @@ struct btrfs_root {
>>  #define btrfs_clear_opt(o, opt)        ((o) &= ~BTRFS_MOUNT_##opt)
>>  #define btrfs_set_opt(o, opt)        ((o) |= BTRFS_MOUNT_##opt)
>>  #define btrfs_raw_test_opt(o, opt)    ((o) & BTRFS_MOUNT_##opt)
>> -#define btrfs_test_opt(root, opt)    ((root)->fs_info->mount_opt & \
>> +#define btrfs_test_opt(fs_info, opt)    ((fs_info)->mount_opt & \
>>                       BTRFS_MOUNT_##opt)
>>
>> -#define btrfs_set_and_info(root, opt, fmt, args...)            \
>> +#define btrfs_set_and_info(fs_info, opt, fmt, args...)            \
>>  {                                    \
>> -    if (!btrfs_test_opt(root, opt))                    \
>> -        btrfs_info(root->fs_info, fmt, ##args);            \
>> -    btrfs_set_opt(root->fs_info->mount_opt, opt);            \
>> +    if (!btrfs_test_opt(fs_info, opt))                \
>> +        btrfs_info(fs_info, fmt, ##args);            \
>> +    btrfs_set_opt(fs_info->mount_opt, opt);                \
>>  }
>>
>> -#define btrfs_clear_and_info(root, opt, fmt, args...)            \
>> +#define btrfs_clear_and_info(fs_info, opt, fmt, args...)        \
>>  {                                    \
>> -    if (btrfs_test_opt(root, opt))                    \
>> -        btrfs_info(root->fs_info, fmt, ##args);            \
>> -    btrfs_clear_opt(root->fs_info->mount_opt, opt);            \
>> +    if (btrfs_test_opt(fs_info, opt))                \
>> +        btrfs_info(fs_info, fmt, ##args);            \
>> +    btrfs_clear_opt(fs_info->mount_opt, opt);            \
>>  }
>>
>>  #ifdef CONFIG_BTRFS_DEBUG
>> @@ -1319,9 +1319,9 @@ static inline int
>>  btrfs_should_fragment_free_space(struct btrfs_root *root,
>>                   struct btrfs_block_group_cache *block_group)
>>  {
>> -    return (btrfs_test_opt(root, FRAGMENT_METADATA) &&
>> +    return (btrfs_test_opt(root->fs_info, FRAGMENT_METADATA) &&
>>          block_group->flags & BTRFS_BLOCK_GROUP_METADATA) ||
>> -           (btrfs_test_opt(root, FRAGMENT_DATA) &&
>> +           (btrfs_test_opt(root->fs_info, FRAGMENT_DATA) &&
>>          block_group->flags &  BTRFS_BLOCK_GROUP_DATA);
>>  }
>>  #endif
>> diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
>> index 61561c2..ed67717 100644
>> --- a/fs/btrfs/delayed-inode.c
>> +++ b/fs/btrfs/delayed-inode.c
>> @@ -653,7 +653,7 @@ static int btrfs_delayed_inode_reserve_metadata(
>>          if (!ret)
>>              goto out;
>>
>> -        if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
>> +        if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>              btrfs_debug(root->fs_info,
>>                      "block rsv migrate returned %d", ret);
>>              WARN_ON(1);
>> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
>> index 63ef9cd..e9bbff3 100644
>> --- a/fs/btrfs/dev-replace.c
>> +++ b/fs/btrfs/dev-replace.c
>> @@ -142,7 +142,7 @@ no_valid_dev_replace_entry_found:
>>           * missing
>>           */
>>          if (!dev_replace->srcdev &&
>> -            !btrfs_test_opt(dev_root, DEGRADED)) {
>> +            !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
> Just fs_info, as following btrfs_warn() is using fs_info.
> 
>>              ret = -EIO;
>>              btrfs_warn(fs_info,
>>                 "cannot mount because device replace operation is
>> ongoing and");
>> @@ -151,7 +151,7 @@ no_valid_dev_replace_entry_found:
>>                 src_devid);
>>          }
>>          if (!dev_replace->tgtdev &&
>> -            !btrfs_test_opt(dev_root, DEGRADED)) {
>> +            !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
> 
> Same here.
> 
>>              ret = -EIO;
>>              btrfs_warn(fs_info,
>>                 "cannot mount because device replace operation is
>> ongoing and");
>> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
>> index 685c81a..8f27127 100644
>> --- a/fs/btrfs/disk-io.c
>> +++ b/fs/btrfs/disk-io.c
>> @@ -3025,8 +3025,8 @@ retry_root_backup:
>>      if (IS_ERR(fs_info->transaction_kthread))
>>          goto fail_cleaner;
>>
>> -    if (!btrfs_test_opt(tree_root, SSD) &&
>> -        !btrfs_test_opt(tree_root, NOSSD) &&
>> +    if (!btrfs_test_opt(tree_root->fs_info, SSD) &&
>> +        !btrfs_test_opt(tree_root->fs_info, NOSSD) &&
> 
> Same fs_info here.
> 
>>          !fs_info->fs_devices->rotating) {
>>          btrfs_info(fs_info, "detected SSD devices, enabling SSD mode");
>>          btrfs_set_opt(fs_info->mount_opt, SSD);
>> @@ -3039,9 +3039,9 @@ retry_root_backup:
>>      btrfs_apply_pending_changes(fs_info);
>>
>>  #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
>> -    if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) {
>> +    if (btrfs_test_opt(tree_root->fs_info, CHECK_INTEGRITY)) {
>>          ret = btrfsic_mount(tree_root, fs_devices,
>> -                    btrfs_test_opt(tree_root,
>> +                    btrfs_test_opt(tree_root->fs_info,
> 
> Same here.
> 
>>                      CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
>>                      1 : 0,
>>                      fs_info->check_integrity_print_mask);
>> @@ -3057,7 +3057,7 @@ retry_root_backup:
>>
>>      /* do not make disk changes in broken FS or nologreplay is given */
>>      if (btrfs_super_log_root(disk_super) != 0 &&
>> -        !btrfs_test_opt(tree_root, NOLOGREPLAY)) {
>> +        !btrfs_test_opt(tree_root->fs_info, NOLOGREPLAY)) {
> Same here.
>>          ret = btrfs_replay_log(fs_info, fs_devices);
>>          if (ret) {
>>              err = ret;
>> @@ -3098,7 +3098,7 @@ retry_root_backup:
>>      if (sb->s_flags & MS_RDONLY)
>>          return 0;
>>
>> -    if (btrfs_test_opt(tree_root, FREE_SPACE_TREE) &&
>> +    if (btrfs_test_opt(tree_root->fs_info, FREE_SPACE_TREE) &&
> Same here.
>>          !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
>>          btrfs_info(fs_info, "creating free space tree");
>>          ret = btrfs_create_free_space_tree(fs_info);
>> @@ -3135,7 +3135,7 @@ retry_root_backup:
>>
>>      btrfs_qgroup_rescan_resume(fs_info);
>>
>> -    if (btrfs_test_opt(tree_root, CLEAR_CACHE) &&
>> +    if (btrfs_test_opt(tree_root->fs_info, CLEAR_CACHE) &&
> 
> Same here.
> 
>>          btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
>>          btrfs_info(fs_info, "clearing free space tree");
>>          ret = btrfs_clear_free_space_tree(fs_info);
>> @@ -3156,7 +3156,7 @@ retry_root_backup:
>>              close_ctree(tree_root);
>>              return ret;
>>          }
>> -    } else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) ||
>> +    } else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) ||
> Same here
>>             fs_info->generation !=
>>                  btrfs_super_uuid_tree_generation(disk_super)) {
>>          btrfs_info(fs_info, "checking UUID tree");
>> @@ -3233,7 +3233,7 @@ fail:
>>      return err;
>>
>>  recovery_tree_root:
>> -    if (!btrfs_test_opt(tree_root, USEBACKUPROOT))
>> +    if (!btrfs_test_opt(tree_root->fs_info, USEBACKUPROOT))
> Same here, any fs_info user inside open_ctree() can directly use fs_info.
>>          goto fail_tree_roots;
>>
>>      free_root_pointers(fs_info, 0);
>> @@ -3648,7 +3648,7 @@ static int write_all_supers(struct btrfs_root
>> *root, int max_mirrors)
>>      int total_errors = 0;
>>      u64 flags;
>>
>> -    do_barriers = !btrfs_test_opt(root, NOBARRIER);
>> +    do_barriers = !btrfs_test_opt(root->fs_info, NOBARRIER);
>>      backup_super_roots(root->fs_info);
>>
>>      sb = root->fs_info->super_for_commit;
>> @@ -3932,7 +3932,7 @@ void close_ctree(struct btrfs_root *root)
>>      iput(fs_info->btree_inode);
>>
>>  #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
>> -    if (btrfs_test_opt(root, CHECK_INTEGRITY))
>> +    if (btrfs_test_opt(root->fs_info, CHECK_INTEGRITY))
> Same here.
> 
> Get fs_info at the beginning of close_ctree().
> 
>>          btrfsic_unmount(root, fs_info->fs_devices);
>>  #endif
>>
>> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
>> index 39308a8..efb5459 100644
>> --- a/fs/btrfs/extent-tree.c
>> +++ b/fs/btrfs/extent-tree.c
>> @@ -3427,7 +3427,7 @@ again:
>>
>>      spin_lock(&block_group->lock);
>>      if (block_group->cached != BTRFS_CACHE_FINISHED ||
>> -        !btrfs_test_opt(root, SPACE_CACHE)) {
>> +        !btrfs_test_opt(root->fs_info, SPACE_CACHE)) {
> 
>>          /*
>>           * don't bother trying to write stuff out _if_
>>           * a) we're not cached,
>> @@ -3504,7 +3504,7 @@ int btrfs_setup_space_cache(struct
>> btrfs_trans_handle *trans,
>>      struct btrfs_path *path;
>>
>>      if (list_empty(&cur_trans->dirty_bgs) ||
>> -        !btrfs_test_opt(root, SPACE_CACHE))
>> +        !btrfs_test_opt(root->fs_info, SPACE_CACHE))
>>          return 0;
>>
>>      path = btrfs_alloc_path();
>> @@ -4417,7 +4417,7 @@ void check_system_chunk(struct
>> btrfs_trans_handle *trans,
>>      thresh = btrfs_calc_trunc_metadata_size(root, num_devs) +
>>          btrfs_calc_trans_metadata_size(root, 1);
>>
>> -    if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) {
>> +    if (left < thresh && btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>          btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
>>              left, thresh, type);
>>          dump_space_info(info, 0, 0);
>> @@ -6009,7 +6009,7 @@ static int update_block_group(struct
>> btrfs_trans_handle *trans,
>>          spin_lock(&cache->space_info->lock);
>>          spin_lock(&cache->lock);
>>
>> -        if (btrfs_test_opt(root, SPACE_CACHE) &&
>> +        if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
> 
> Same here.
> Fs_info is extracted at the beginning of update_block_group().
> 
>>              cache->disk_cache_state < BTRFS_DC_CLEAR)
>>              cache->disk_cache_state = BTRFS_DC_CLEAR;
>>
>> @@ -6388,7 +6388,7 @@ fetch_cluster_info(struct btrfs_root *root,
>> struct btrfs_space_info *space_info,
>>             u64 *empty_cluster)
>>  {
>>      struct btrfs_free_cluster *ret = NULL;
>> -    bool ssd = btrfs_test_opt(root, SSD);
>> +    bool ssd = btrfs_test_opt(root->fs_info, SSD);
>>
>>      *empty_cluster = 0;
>>      if (btrfs_mixed_space_info(space_info))
>> @@ -6518,7 +6518,7 @@ int btrfs_finish_extent_commit(struct
>> btrfs_trans_handle *trans,
>>              break;
>>          }
>>
>> -        if (btrfs_test_opt(root, DISCARD))
>> +        if (btrfs_test_opt(root->fs_info, DISCARD))
> 
> Same here.
> 
>>              ret = btrfs_discard_extent(root, start,
>>                             end + 1 - start, NULL);
>>
>> @@ -7737,7 +7737,7 @@ again:
>>              if (num_bytes == min_alloc_size)
>>                  final_tried = true;
>>              goto again;
>> -        } else if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
>> +        } else if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>              struct btrfs_space_info *sinfo;
>>
>>              sinfo = __find_space_info(root->fs_info, flags);
>> @@ -7768,7 +7768,7 @@ static int __btrfs_free_reserved_extent(struct
>> btrfs_root *root,
>>      if (pin)
>>          pin_down_extent(root, cache, start, len, 1);
>>      else {
>> -        if (btrfs_test_opt(root, DISCARD))
>> +        if (btrfs_test_opt(root->fs_info, DISCARD))
>>              ret = btrfs_discard_extent(root, start, len, NULL);
>>          btrfs_add_free_space(cache, start, len);
>>          btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc);
>> @@ -8078,7 +8078,7 @@ again:
>>          goto again;
>>      }
>>
>> -    if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
>> +    if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>          static DEFINE_RATELIMIT_STATE(_rs,
>>                  DEFAULT_RATELIMIT_INTERVAL * 10,
>>                  /*DEFAULT_RATELIMIT_BURST*/ 1);
>> @@ -9510,7 +9510,7 @@ int btrfs_can_relocate(struct btrfs_root *root,
>> u64 bytenr)
>>      int full = 0;
>>      int ret = 0;
>>
>> -    debug = btrfs_test_opt(root, ENOSPC_DEBUG);
>> +    debug = btrfs_test_opt(root->fs_info, ENOSPC_DEBUG);
>>
>>      block_group = btrfs_lookup_block_group(root->fs_info, bytenr);
>>
>> @@ -9782,7 +9782,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info
>> *info)
>>          space_info = list_entry(info->space_info.next,
>>                      struct btrfs_space_info,
>>                      list);
>> -        if (btrfs_test_opt(info->tree_root, ENOSPC_DEBUG)) {
>> +        if (btrfs_test_opt(info, ENOSPC_DEBUG)) {
>>              if (WARN_ON(space_info->bytes_pinned > 0 ||
>>                  space_info->bytes_reserved > 0 ||
>>                  space_info->bytes_may_use > 0)) {
>> @@ -9906,10 +9906,10 @@ int btrfs_read_block_groups(struct btrfs_root
>> *root)
>>      path->reada = READA_FORWARD;
>>
>>      cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
>> -    if (btrfs_test_opt(root, SPACE_CACHE) &&
>> +    if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
> Same here.
> btrfs_read_block_groups() has fs_info extracted as info.
> 
>>          btrfs_super_generation(root->fs_info->super_copy) != cache_gen)
>>          need_clear = 1;
>> -    if (btrfs_test_opt(root, CLEAR_CACHE))
>> +    if (btrfs_test_opt(root->fs_info, CLEAR_CACHE))
> Same here
>>          need_clear = 1;
>>
>>      while (1) {
>> @@ -9940,7 +9940,7 @@ int btrfs_read_block_groups(struct btrfs_root
>> *root)
>>               * b) Setting 'dirty flag' makes sure that we flush
>>               *    the new space cache info onto disk.
>>               */
>> -            if (btrfs_test_opt(root, SPACE_CACHE))
>> +            if (btrfs_test_opt(root->fs_info, SPACE_CACHE))
> Same here
>>                  cache->disk_cache_state = BTRFS_DC_CLEAR;
>>          }
>>
>> @@ -10406,7 +10406,7 @@ int btrfs_remove_block_group(struct
>> btrfs_trans_handle *trans,
>>      spin_lock(&block_group->space_info->lock);
>>      list_del_init(&block_group->ro_list);
>>
>> -    if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
>> +    if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>          WARN_ON(block_group->space_info->total_bytes
>>              < block_group->key.offset);
>>          WARN_ON(block_group->space_info->bytes_readonly
>> @@ -10674,7 +10674,7 @@ void btrfs_delete_unused_bgs(struct
>> btrfs_fs_info *fs_info)
>>          spin_unlock(&space_info->lock);
>>
>>          /* DISCARD can flip during remount */
>> -        trimming = btrfs_test_opt(root, DISCARD);
>> +        trimming = btrfs_test_opt(root->fs_info, DISCARD);
>>
>>          /* Implicit trim during transaction commit. */
>>          if (trimming)
>> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
>> index e0c9bd3..ffd9001 100644
>> --- a/fs/btrfs/file.c
>> +++ b/fs/btrfs/file.c
>> @@ -132,7 +132,7 @@ static int __btrfs_add_inode_defrag(struct inode
>> *inode,
>>
>>  static inline int __need_auto_defrag(struct btrfs_root *root)
>>  {
>> -    if (!btrfs_test_opt(root, AUTO_DEFRAG))
>> +    if (!btrfs_test_opt(root->fs_info, AUTO_DEFRAG))
>>          return 0;
>>
>>      if (btrfs_fs_closing(root->fs_info))
>> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
>> index 69d270f..cee2049 100644
>> --- a/fs/btrfs/free-space-cache.c
>> +++ b/fs/btrfs/free-space-cache.c
>> @@ -3026,7 +3026,7 @@ int btrfs_find_space_cluster(struct btrfs_root
>> *root,
>>       * For metadata, allow allocates with smaller extents.  For
>>       * data, keep it dense.
>>       */
>> -    if (btrfs_test_opt(root, SSD_SPREAD)) {
>> +    if (btrfs_test_opt(root->fs_info, SSD_SPREAD)) {
>>          cont1_bytes = min_bytes = bytes + empty_size;
>>      } else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) {
>>          cont1_bytes = bytes;
>> @@ -3470,7 +3470,7 @@ int load_free_ino_cache(struct btrfs_fs_info
>> *fs_info, struct btrfs_root *root)
>>      int ret = 0;
>>      u64 root_gen = btrfs_root_generation(&root->root_item);
>>
>> -    if (!btrfs_test_opt(root, INODE_MAP_CACHE))
>> +    if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
>>          return 0;
>>
>>      /*
>> @@ -3514,7 +3514,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root
>> *root,
>>      struct btrfs_io_ctl io_ctl;
>>      bool release_metadata = true;
>>
>> -    if (!btrfs_test_opt(root, INODE_MAP_CACHE))
>> +    if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
>>          return 0;
>>
>>      memset(&io_ctl, 0, sizeof(io_ctl));
>> diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
>> index 70107f7..e3ad8c1 100644
>> --- a/fs/btrfs/inode-map.c
>> +++ b/fs/btrfs/inode-map.c
>> @@ -38,7 +38,7 @@ static int caching_kthread(void *data)
>>      int slot;
>>      int ret;
>>
>> -    if (!btrfs_test_opt(root, INODE_MAP_CACHE))
>> +    if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
> Caching_kthread() has fs_info extracted.
> So same here.
> 
> Although such modification won't do anything real to the generated
> binary, but never a bad idea to make code a little clearer.

Thanks, but this is intentional to keep the patches obvious.  Patch 27
adds and/or uses a local fs_info in every function that uses
root->fs_info more than once.  Unfortunately, the list seems to have
dropped it.

https://git.kernel.org/cgit/linux/kernel/git/jeffm/linux-btrfs.git/commit/?h=btrfs-testing/root-fsinfo-cleanup-squashed&id=b7bccd6c7a2ac810eca8109adcdb3647a776e7de

It also dropped the patch that converts everything taking a root but not
using it for anything other than an fs_info to fs_info.

https://git.kernel.org/cgit/linux/kernel/git/jeffm/linux-btrfs.git/commit/?h=btrfs-testing/root-fsinfo-cleanup-squashed&id=9cd5ae906bbb22962091aaaaa7ff4e85b03ee26d

-Jeff

-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 827 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info
  2016-06-27  2:21     ` Jeff Mahoney
@ 2016-06-27  2:24       ` Qu Wenruo
  0 siblings, 0 replies; 44+ messages in thread
From: Qu Wenruo @ 2016-06-27  2:24 UTC (permalink / raw)
  To: Jeff Mahoney, linux-btrfs



At 06/27/2016 10:21 AM, Jeff Mahoney wrote:
> On 6/26/16 10:14 PM, Qu Wenruo wrote:
>>
>>
>> At 06/25/2016 06:14 AM, jeffm@suse.com wrote:
>>> From: Jeff Mahoney <jeffm@suse.com>
>>>
>>> btrfs_test_opt and friends only use the root pointer to access
>>> the fs_info.  Let's pass the fs_info directly in preparation to
>>> eliminate similar patterns all over btrfs.
>>>
>>> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
>>> ---
>>>  fs/btrfs/ctree.h            |  22 ++++----
>>>  fs/btrfs/delayed-inode.c    |   2 +-
>>>  fs/btrfs/dev-replace.c      |   4 +-
>>>  fs/btrfs/disk-io.c          |  22 ++++----
>>>  fs/btrfs/extent-tree.c      |  32 +++++------
>>>  fs/btrfs/file.c             |   2 +-
>>>  fs/btrfs/free-space-cache.c |   6 +-
>>>  fs/btrfs/inode-map.c        |  12 ++--
>>>  fs/btrfs/inode.c            |  12 ++--
>>>  fs/btrfs/ioctl.c            |   2 +-
>>>  fs/btrfs/super.c            | 132
>>> +++++++++++++++++++++++---------------------
>>>  fs/btrfs/transaction.c      |   6 +-
>>>  fs/btrfs/tree-log.c         |   4 +-
>>>  fs/btrfs/volumes.c          |  11 ++--
>>>  14 files changed, 137 insertions(+), 132 deletions(-)
>>>
>>> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
>>> index 101c3cf..100d2ea 100644
>>> --- a/fs/btrfs/ctree.h
>>> +++ b/fs/btrfs/ctree.h
>>> @@ -1297,21 +1297,21 @@ struct btrfs_root {
>>>  #define btrfs_clear_opt(o, opt)        ((o) &= ~BTRFS_MOUNT_##opt)
>>>  #define btrfs_set_opt(o, opt)        ((o) |= BTRFS_MOUNT_##opt)
>>>  #define btrfs_raw_test_opt(o, opt)    ((o) & BTRFS_MOUNT_##opt)
>>> -#define btrfs_test_opt(root, opt)    ((root)->fs_info->mount_opt & \
>>> +#define btrfs_test_opt(fs_info, opt)    ((fs_info)->mount_opt & \
>>>                       BTRFS_MOUNT_##opt)
>>>
>>> -#define btrfs_set_and_info(root, opt, fmt, args...)            \
>>> +#define btrfs_set_and_info(fs_info, opt, fmt, args...)            \
>>>  {                                    \
>>> -    if (!btrfs_test_opt(root, opt))                    \
>>> -        btrfs_info(root->fs_info, fmt, ##args);            \
>>> -    btrfs_set_opt(root->fs_info->mount_opt, opt);            \
>>> +    if (!btrfs_test_opt(fs_info, opt))                \
>>> +        btrfs_info(fs_info, fmt, ##args);            \
>>> +    btrfs_set_opt(fs_info->mount_opt, opt);                \
>>>  }
>>>
>>> -#define btrfs_clear_and_info(root, opt, fmt, args...)            \
>>> +#define btrfs_clear_and_info(fs_info, opt, fmt, args...)        \
>>>  {                                    \
>>> -    if (btrfs_test_opt(root, opt))                    \
>>> -        btrfs_info(root->fs_info, fmt, ##args);            \
>>> -    btrfs_clear_opt(root->fs_info->mount_opt, opt);            \
>>> +    if (btrfs_test_opt(fs_info, opt))                \
>>> +        btrfs_info(fs_info, fmt, ##args);            \
>>> +    btrfs_clear_opt(fs_info->mount_opt, opt);            \
>>>  }
>>>
>>>  #ifdef CONFIG_BTRFS_DEBUG
>>> @@ -1319,9 +1319,9 @@ static inline int
>>>  btrfs_should_fragment_free_space(struct btrfs_root *root,
>>>                   struct btrfs_block_group_cache *block_group)
>>>  {
>>> -    return (btrfs_test_opt(root, FRAGMENT_METADATA) &&
>>> +    return (btrfs_test_opt(root->fs_info, FRAGMENT_METADATA) &&
>>>          block_group->flags & BTRFS_BLOCK_GROUP_METADATA) ||
>>> -           (btrfs_test_opt(root, FRAGMENT_DATA) &&
>>> +           (btrfs_test_opt(root->fs_info, FRAGMENT_DATA) &&
>>>          block_group->flags &  BTRFS_BLOCK_GROUP_DATA);
>>>  }
>>>  #endif
>>> diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
>>> index 61561c2..ed67717 100644
>>> --- a/fs/btrfs/delayed-inode.c
>>> +++ b/fs/btrfs/delayed-inode.c
>>> @@ -653,7 +653,7 @@ static int btrfs_delayed_inode_reserve_metadata(
>>>          if (!ret)
>>>              goto out;
>>>
>>> -        if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
>>> +        if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>>              btrfs_debug(root->fs_info,
>>>                      "block rsv migrate returned %d", ret);
>>>              WARN_ON(1);
>>> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
>>> index 63ef9cd..e9bbff3 100644
>>> --- a/fs/btrfs/dev-replace.c
>>> +++ b/fs/btrfs/dev-replace.c
>>> @@ -142,7 +142,7 @@ no_valid_dev_replace_entry_found:
>>>           * missing
>>>           */
>>>          if (!dev_replace->srcdev &&
>>> -            !btrfs_test_opt(dev_root, DEGRADED)) {
>>> +            !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
>> Just fs_info, as following btrfs_warn() is using fs_info.
>>
>>>              ret = -EIO;
>>>              btrfs_warn(fs_info,
>>>                 "cannot mount because device replace operation is
>>> ongoing and");
>>> @@ -151,7 +151,7 @@ no_valid_dev_replace_entry_found:
>>>                 src_devid);
>>>          }
>>>          if (!dev_replace->tgtdev &&
>>> -            !btrfs_test_opt(dev_root, DEGRADED)) {
>>> +            !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
>>
>> Same here.
>>
>>>              ret = -EIO;
>>>              btrfs_warn(fs_info,
>>>                 "cannot mount because device replace operation is
>>> ongoing and");
>>> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
>>> index 685c81a..8f27127 100644
>>> --- a/fs/btrfs/disk-io.c
>>> +++ b/fs/btrfs/disk-io.c
>>> @@ -3025,8 +3025,8 @@ retry_root_backup:
>>>      if (IS_ERR(fs_info->transaction_kthread))
>>>          goto fail_cleaner;
>>>
>>> -    if (!btrfs_test_opt(tree_root, SSD) &&
>>> -        !btrfs_test_opt(tree_root, NOSSD) &&
>>> +    if (!btrfs_test_opt(tree_root->fs_info, SSD) &&
>>> +        !btrfs_test_opt(tree_root->fs_info, NOSSD) &&
>>
>> Same fs_info here.
>>
>>>          !fs_info->fs_devices->rotating) {
>>>          btrfs_info(fs_info, "detected SSD devices, enabling SSD mode");
>>>          btrfs_set_opt(fs_info->mount_opt, SSD);
>>> @@ -3039,9 +3039,9 @@ retry_root_backup:
>>>      btrfs_apply_pending_changes(fs_info);
>>>
>>>  #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
>>> -    if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) {
>>> +    if (btrfs_test_opt(tree_root->fs_info, CHECK_INTEGRITY)) {
>>>          ret = btrfsic_mount(tree_root, fs_devices,
>>> -                    btrfs_test_opt(tree_root,
>>> +                    btrfs_test_opt(tree_root->fs_info,
>>
>> Same here.
>>
>>>                      CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
>>>                      1 : 0,
>>>                      fs_info->check_integrity_print_mask);
>>> @@ -3057,7 +3057,7 @@ retry_root_backup:
>>>
>>>      /* do not make disk changes in broken FS or nologreplay is given */
>>>      if (btrfs_super_log_root(disk_super) != 0 &&
>>> -        !btrfs_test_opt(tree_root, NOLOGREPLAY)) {
>>> +        !btrfs_test_opt(tree_root->fs_info, NOLOGREPLAY)) {
>> Same here.
>>>          ret = btrfs_replay_log(fs_info, fs_devices);
>>>          if (ret) {
>>>              err = ret;
>>> @@ -3098,7 +3098,7 @@ retry_root_backup:
>>>      if (sb->s_flags & MS_RDONLY)
>>>          return 0;
>>>
>>> -    if (btrfs_test_opt(tree_root, FREE_SPACE_TREE) &&
>>> +    if (btrfs_test_opt(tree_root->fs_info, FREE_SPACE_TREE) &&
>> Same here.
>>>          !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
>>>          btrfs_info(fs_info, "creating free space tree");
>>>          ret = btrfs_create_free_space_tree(fs_info);
>>> @@ -3135,7 +3135,7 @@ retry_root_backup:
>>>
>>>      btrfs_qgroup_rescan_resume(fs_info);
>>>
>>> -    if (btrfs_test_opt(tree_root, CLEAR_CACHE) &&
>>> +    if (btrfs_test_opt(tree_root->fs_info, CLEAR_CACHE) &&
>>
>> Same here.
>>
>>>          btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
>>>          btrfs_info(fs_info, "clearing free space tree");
>>>          ret = btrfs_clear_free_space_tree(fs_info);
>>> @@ -3156,7 +3156,7 @@ retry_root_backup:
>>>              close_ctree(tree_root);
>>>              return ret;
>>>          }
>>> -    } else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) ||
>>> +    } else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) ||
>> Same here
>>>             fs_info->generation !=
>>>                  btrfs_super_uuid_tree_generation(disk_super)) {
>>>          btrfs_info(fs_info, "checking UUID tree");
>>> @@ -3233,7 +3233,7 @@ fail:
>>>      return err;
>>>
>>>  recovery_tree_root:
>>> -    if (!btrfs_test_opt(tree_root, USEBACKUPROOT))
>>> +    if (!btrfs_test_opt(tree_root->fs_info, USEBACKUPROOT))
>> Same here, any fs_info user inside open_ctree() can directly use fs_info.
>>>          goto fail_tree_roots;
>>>
>>>      free_root_pointers(fs_info, 0);
>>> @@ -3648,7 +3648,7 @@ static int write_all_supers(struct btrfs_root
>>> *root, int max_mirrors)
>>>      int total_errors = 0;
>>>      u64 flags;
>>>
>>> -    do_barriers = !btrfs_test_opt(root, NOBARRIER);
>>> +    do_barriers = !btrfs_test_opt(root->fs_info, NOBARRIER);
>>>      backup_super_roots(root->fs_info);
>>>
>>>      sb = root->fs_info->super_for_commit;
>>> @@ -3932,7 +3932,7 @@ void close_ctree(struct btrfs_root *root)
>>>      iput(fs_info->btree_inode);
>>>
>>>  #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
>>> -    if (btrfs_test_opt(root, CHECK_INTEGRITY))
>>> +    if (btrfs_test_opt(root->fs_info, CHECK_INTEGRITY))
>> Same here.
>>
>> Get fs_info at the beginning of close_ctree().
>>
>>>          btrfsic_unmount(root, fs_info->fs_devices);
>>>  #endif
>>>
>>> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
>>> index 39308a8..efb5459 100644
>>> --- a/fs/btrfs/extent-tree.c
>>> +++ b/fs/btrfs/extent-tree.c
>>> @@ -3427,7 +3427,7 @@ again:
>>>
>>>      spin_lock(&block_group->lock);
>>>      if (block_group->cached != BTRFS_CACHE_FINISHED ||
>>> -        !btrfs_test_opt(root, SPACE_CACHE)) {
>>> +        !btrfs_test_opt(root->fs_info, SPACE_CACHE)) {
>>
>>>          /*
>>>           * don't bother trying to write stuff out _if_
>>>           * a) we're not cached,
>>> @@ -3504,7 +3504,7 @@ int btrfs_setup_space_cache(struct
>>> btrfs_trans_handle *trans,
>>>      struct btrfs_path *path;
>>>
>>>      if (list_empty(&cur_trans->dirty_bgs) ||
>>> -        !btrfs_test_opt(root, SPACE_CACHE))
>>> +        !btrfs_test_opt(root->fs_info, SPACE_CACHE))
>>>          return 0;
>>>
>>>      path = btrfs_alloc_path();
>>> @@ -4417,7 +4417,7 @@ void check_system_chunk(struct
>>> btrfs_trans_handle *trans,
>>>      thresh = btrfs_calc_trunc_metadata_size(root, num_devs) +
>>>          btrfs_calc_trans_metadata_size(root, 1);
>>>
>>> -    if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) {
>>> +    if (left < thresh && btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>>          btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
>>>              left, thresh, type);
>>>          dump_space_info(info, 0, 0);
>>> @@ -6009,7 +6009,7 @@ static int update_block_group(struct
>>> btrfs_trans_handle *trans,
>>>          spin_lock(&cache->space_info->lock);
>>>          spin_lock(&cache->lock);
>>>
>>> -        if (btrfs_test_opt(root, SPACE_CACHE) &&
>>> +        if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
>>
>> Same here.
>> Fs_info is extracted at the beginning of update_block_group().
>>
>>>              cache->disk_cache_state < BTRFS_DC_CLEAR)
>>>              cache->disk_cache_state = BTRFS_DC_CLEAR;
>>>
>>> @@ -6388,7 +6388,7 @@ fetch_cluster_info(struct btrfs_root *root,
>>> struct btrfs_space_info *space_info,
>>>             u64 *empty_cluster)
>>>  {
>>>      struct btrfs_free_cluster *ret = NULL;
>>> -    bool ssd = btrfs_test_opt(root, SSD);
>>> +    bool ssd = btrfs_test_opt(root->fs_info, SSD);
>>>
>>>      *empty_cluster = 0;
>>>      if (btrfs_mixed_space_info(space_info))
>>> @@ -6518,7 +6518,7 @@ int btrfs_finish_extent_commit(struct
>>> btrfs_trans_handle *trans,
>>>              break;
>>>          }
>>>
>>> -        if (btrfs_test_opt(root, DISCARD))
>>> +        if (btrfs_test_opt(root->fs_info, DISCARD))
>>
>> Same here.
>>
>>>              ret = btrfs_discard_extent(root, start,
>>>                             end + 1 - start, NULL);
>>>
>>> @@ -7737,7 +7737,7 @@ again:
>>>              if (num_bytes == min_alloc_size)
>>>                  final_tried = true;
>>>              goto again;
>>> -        } else if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
>>> +        } else if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>>              struct btrfs_space_info *sinfo;
>>>
>>>              sinfo = __find_space_info(root->fs_info, flags);
>>> @@ -7768,7 +7768,7 @@ static int __btrfs_free_reserved_extent(struct
>>> btrfs_root *root,
>>>      if (pin)
>>>          pin_down_extent(root, cache, start, len, 1);
>>>      else {
>>> -        if (btrfs_test_opt(root, DISCARD))
>>> +        if (btrfs_test_opt(root->fs_info, DISCARD))
>>>              ret = btrfs_discard_extent(root, start, len, NULL);
>>>          btrfs_add_free_space(cache, start, len);
>>>          btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc);
>>> @@ -8078,7 +8078,7 @@ again:
>>>          goto again;
>>>      }
>>>
>>> -    if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
>>> +    if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>>          static DEFINE_RATELIMIT_STATE(_rs,
>>>                  DEFAULT_RATELIMIT_INTERVAL * 10,
>>>                  /*DEFAULT_RATELIMIT_BURST*/ 1);
>>> @@ -9510,7 +9510,7 @@ int btrfs_can_relocate(struct btrfs_root *root,
>>> u64 bytenr)
>>>      int full = 0;
>>>      int ret = 0;
>>>
>>> -    debug = btrfs_test_opt(root, ENOSPC_DEBUG);
>>> +    debug = btrfs_test_opt(root->fs_info, ENOSPC_DEBUG);
>>>
>>>      block_group = btrfs_lookup_block_group(root->fs_info, bytenr);
>>>
>>> @@ -9782,7 +9782,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info
>>> *info)
>>>          space_info = list_entry(info->space_info.next,
>>>                      struct btrfs_space_info,
>>>                      list);
>>> -        if (btrfs_test_opt(info->tree_root, ENOSPC_DEBUG)) {
>>> +        if (btrfs_test_opt(info, ENOSPC_DEBUG)) {
>>>              if (WARN_ON(space_info->bytes_pinned > 0 ||
>>>                  space_info->bytes_reserved > 0 ||
>>>                  space_info->bytes_may_use > 0)) {
>>> @@ -9906,10 +9906,10 @@ int btrfs_read_block_groups(struct btrfs_root
>>> *root)
>>>      path->reada = READA_FORWARD;
>>>
>>>      cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
>>> -    if (btrfs_test_opt(root, SPACE_CACHE) &&
>>> +    if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
>> Same here.
>> btrfs_read_block_groups() has fs_info extracted as info.
>>
>>>          btrfs_super_generation(root->fs_info->super_copy) != cache_gen)
>>>          need_clear = 1;
>>> -    if (btrfs_test_opt(root, CLEAR_CACHE))
>>> +    if (btrfs_test_opt(root->fs_info, CLEAR_CACHE))
>> Same here
>>>          need_clear = 1;
>>>
>>>      while (1) {
>>> @@ -9940,7 +9940,7 @@ int btrfs_read_block_groups(struct btrfs_root
>>> *root)
>>>               * b) Setting 'dirty flag' makes sure that we flush
>>>               *    the new space cache info onto disk.
>>>               */
>>> -            if (btrfs_test_opt(root, SPACE_CACHE))
>>> +            if (btrfs_test_opt(root->fs_info, SPACE_CACHE))
>> Same here
>>>                  cache->disk_cache_state = BTRFS_DC_CLEAR;
>>>          }
>>>
>>> @@ -10406,7 +10406,7 @@ int btrfs_remove_block_group(struct
>>> btrfs_trans_handle *trans,
>>>      spin_lock(&block_group->space_info->lock);
>>>      list_del_init(&block_group->ro_list);
>>>
>>> -    if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
>>> +    if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
>>>          WARN_ON(block_group->space_info->total_bytes
>>>              < block_group->key.offset);
>>>          WARN_ON(block_group->space_info->bytes_readonly
>>> @@ -10674,7 +10674,7 @@ void btrfs_delete_unused_bgs(struct
>>> btrfs_fs_info *fs_info)
>>>          spin_unlock(&space_info->lock);
>>>
>>>          /* DISCARD can flip during remount */
>>> -        trimming = btrfs_test_opt(root, DISCARD);
>>> +        trimming = btrfs_test_opt(root->fs_info, DISCARD);
>>>
>>>          /* Implicit trim during transaction commit. */
>>>          if (trimming)
>>> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
>>> index e0c9bd3..ffd9001 100644
>>> --- a/fs/btrfs/file.c
>>> +++ b/fs/btrfs/file.c
>>> @@ -132,7 +132,7 @@ static int __btrfs_add_inode_defrag(struct inode
>>> *inode,
>>>
>>>  static inline int __need_auto_defrag(struct btrfs_root *root)
>>>  {
>>> -    if (!btrfs_test_opt(root, AUTO_DEFRAG))
>>> +    if (!btrfs_test_opt(root->fs_info, AUTO_DEFRAG))
>>>          return 0;
>>>
>>>      if (btrfs_fs_closing(root->fs_info))
>>> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
>>> index 69d270f..cee2049 100644
>>> --- a/fs/btrfs/free-space-cache.c
>>> +++ b/fs/btrfs/free-space-cache.c
>>> @@ -3026,7 +3026,7 @@ int btrfs_find_space_cluster(struct btrfs_root
>>> *root,
>>>       * For metadata, allow allocates with smaller extents.  For
>>>       * data, keep it dense.
>>>       */
>>> -    if (btrfs_test_opt(root, SSD_SPREAD)) {
>>> +    if (btrfs_test_opt(root->fs_info, SSD_SPREAD)) {
>>>          cont1_bytes = min_bytes = bytes + empty_size;
>>>      } else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) {
>>>          cont1_bytes = bytes;
>>> @@ -3470,7 +3470,7 @@ int load_free_ino_cache(struct btrfs_fs_info
>>> *fs_info, struct btrfs_root *root)
>>>      int ret = 0;
>>>      u64 root_gen = btrfs_root_generation(&root->root_item);
>>>
>>> -    if (!btrfs_test_opt(root, INODE_MAP_CACHE))
>>> +    if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
>>>          return 0;
>>>
>>>      /*
>>> @@ -3514,7 +3514,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root
>>> *root,
>>>      struct btrfs_io_ctl io_ctl;
>>>      bool release_metadata = true;
>>>
>>> -    if (!btrfs_test_opt(root, INODE_MAP_CACHE))
>>> +    if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
>>>          return 0;
>>>
>>>      memset(&io_ctl, 0, sizeof(io_ctl));
>>> diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
>>> index 70107f7..e3ad8c1 100644
>>> --- a/fs/btrfs/inode-map.c
>>> +++ b/fs/btrfs/inode-map.c
>>> @@ -38,7 +38,7 @@ static int caching_kthread(void *data)
>>>      int slot;
>>>      int ret;
>>>
>>> -    if (!btrfs_test_opt(root, INODE_MAP_CACHE))
>>> +    if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
>> Caching_kthread() has fs_info extracted.
>> So same here.
>>
>> Although such modification won't do anything real to the generated
>> binary, but never a bad idea to make code a little clearer.
>
> Thanks, but this is intentional to keep the patches obvious.  Patch 27
> adds and/or uses a local fs_info in every function that uses
> root->fs_info more than once.  Unfortunately, the list seems to have
> dropped it.
>
> https://git.kernel.org/cgit/linux/kernel/git/jeffm/linux-btrfs.git/commit/?h=btrfs-testing/root-fsinfo-cleanup-squashed&id=b7bccd6c7a2ac810eca8109adcdb3647a776e7de
>
> It also dropped the patch that converts everything taking a root but not
> using it for anything other than an fs_info to fs_info.
>
> https://git.kernel.org/cgit/linux/kernel/git/jeffm/linux-btrfs.git/commit/?h=btrfs-testing/root-fsinfo-cleanup-squashed&id=9cd5ae906bbb22962091aaaaa7ff4e85b03ee26d
>
> -Jeff
>
Oh, I'm sorry for that.

I'm just going through the patchset one by one.
Didn't realize that later patchset will change it.

I'd better go through the whole patchset to comment.

Thanks,
Qu



^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 04/31] btrfs: tests, move initialization into tests/
  2016-06-27  2:17   ` Qu Wenruo
@ 2016-06-27  2:28     ` Jeff Mahoney
  0 siblings, 0 replies; 44+ messages in thread
From: Jeff Mahoney @ 2016-06-27  2:28 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 5803 bytes --]

On 6/26/16 10:17 PM, Qu Wenruo wrote:
> 
> 
> At 06/25/2016 06:14 AM, jeffm@suse.com wrote:
>> From: Jeff Mahoney <jeffm@suse.com>
>>
>> We have all these stubs that only exist because they're called from
>> btrfs_run_sanity_tests, which is a static inside super.c.  Let's just
>> move it all into tests/btrfs-tests.c and only have one stub.
>>
>> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
>> ---
>>  fs/btrfs/super.c             | 43
>> ----------------------------------------
>>  fs/btrfs/tests/btrfs-tests.c | 47
>> ++++++++++++++++++++++++++++++++++++++++++--
>>  fs/btrfs/tests/btrfs-tests.h | 35 +++------------------------------
>>  3 files changed, 48 insertions(+), 77 deletions(-)
>>
>> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
>> index a7b9a15..d8e48bb 100644
>> --- a/fs/btrfs/super.c
>> +++ b/fs/btrfs/super.c
>> @@ -2323,49 +2323,6 @@ static void btrfs_print_mod_info(void)
>>              btrfs_crc32c_impl());
>>  }
>>
>> -static int btrfs_run_sanity_tests(void)
>> -{
>> -    int ret, i;
>> -    u32 sectorsize, nodesize;
>> -    u32 test_sectorsize[] = {
>> -        PAGE_SIZE,
>> -    };
>> -    ret = btrfs_init_test_fs();
>> -    if (ret)
>> -        return ret;
>> -    for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) {
>> -        sectorsize = test_sectorsize[i];
>> -        for (nodesize = sectorsize;
>> -             nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE;
>> -             nodesize <<= 1) {
>> -            pr_info("BTRFS: selftest: sectorsize: %u  nodesize: %u\n",
>> -                sectorsize, nodesize);
>> -            ret = btrfs_test_free_space_cache(sectorsize, nodesize);
>> -            if (ret)
>> -                goto out;
>> -            ret = btrfs_test_extent_buffer_operations(sectorsize,
>> -                nodesize);
>> -            if (ret)
>> -                goto out;
>> -            ret = btrfs_test_extent_io(sectorsize, nodesize);
>> -            if (ret)
>> -                goto out;
>> -            ret = btrfs_test_inodes(sectorsize, nodesize);
>> -            if (ret)
>> -                goto out;
>> -            ret = btrfs_test_qgroups(sectorsize, nodesize);
>> -            if (ret)
>> -                goto out;
>> -            ret = btrfs_test_free_space_tree(sectorsize, nodesize);
>> -            if (ret)
>> -                goto out;
>> -        }
>> -    }
>> -out:
>> -    btrfs_destroy_test_fs();
>> -    return ret;
>> -}
>> -
>>  static int __init init_btrfs_fs(void)
>>  {
>>      int err;
>> diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
>> index 10eb249..d90c951 100644
>> --- a/fs/btrfs/tests/btrfs-tests.c
>> +++ b/fs/btrfs/tests/btrfs-tests.c
>> @@ -54,7 +54,7 @@ struct inode *btrfs_new_test_inode(void)
>>      return new_inode(test_mnt->mnt_sb);
>>  }
>>
>> -int btrfs_init_test_fs(void)
>> +static int btrfs_init_test_fs(void)
>>  {
>>      int ret;
>>
>> @@ -73,7 +73,7 @@ int btrfs_init_test_fs(void)
>>      return 0;
>>  }
>>
>> -void btrfs_destroy_test_fs(void)
>> +static void btrfs_destroy_test_fs(void)
>>  {
>>      kern_unmount(test_mnt);
>>      unregister_filesystem(&test_type);
>> @@ -220,3 +220,46 @@ void btrfs_init_dummy_trans(struct
>> btrfs_trans_handle *trans)
>>      INIT_LIST_HEAD(&trans->qgroup_ref_list);
>>      trans->type = __TRANS_DUMMY;
>>  }
>> +
>> +int btrfs_run_sanity_tests(void)
>> +{
>> +    int ret, i;
>> +    u32 sectorsize, nodesize;
>> +    u32 test_sectorsize[] = {
>> +        PAGE_SIZE,
>> +    };
>> +    ret = btrfs_init_test_fs();
>> +    if (ret)
>> +        return ret;
>> +    for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) {
>> +        sectorsize = test_sectorsize[i];
>> +        for (nodesize = sectorsize;
>> +             nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE;
>> +             nodesize <<= 1) {
>> +            pr_info("BTRFS: selftest: sectorsize: %u  nodesize: %u\n",
>> +                sectorsize, nodesize);
>> +            ret = btrfs_test_free_space_cache(sectorsize, nodesize);
>> +            if (ret)
>> +                goto out;
>> +            ret = btrfs_test_extent_buffer_operations(sectorsize,
>> +                nodesize);
>> +            if (ret)
>> +                goto out;
>> +            ret = btrfs_test_extent_io(sectorsize, nodesize);
>> +            if (ret)
>> +                goto out;
>> +            ret = btrfs_test_inodes(sectorsize, nodesize);
>> +            if (ret)
>> +                goto out;
>> +            ret = btrfs_test_qgroups(sectorsize, nodesize);
>> +            if (ret)
>> +                goto out;
>> +            ret = btrfs_test_free_space_tree(sectorsize, nodesize);
>> +            if (ret)
>> +                goto out;
>> +        }
>> +    }
>> +out:
>> +    btrfs_destroy_test_fs();
>> +    return ret;
>> +}
>> diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h
>> index 66fb6b70..e7d364f 100644
>> --- a/fs/btrfs/tests/btrfs-tests.h
>> +++ b/fs/btrfs/tests/btrfs-tests.h
>> @@ -20,20 +20,19 @@
>>  #define __BTRFS_TESTS
>>
>>  #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
>> +int btrfs_run_sanity_tests(void);
>>
>>  #define test_msg(fmt, ...) pr_info("BTRFS: selftest: " fmt,
>> ##__VA_ARGS__)
>>
>>  struct btrfs_root;
>>  struct btrfs_trans_handle;
>>
>> -int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize);
>>  int btrfs_test_extent_buffer_operations(u32 sectorsize, u32 nodesize);
>> +int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize);
> 
> Anything special for the line move?
> Otherwise it looks good for me.

No.  It's probably leftover from an earlier revision.  It's not necessary.

-Jeff

-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 827 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (29 preceding siblings ...)
  2016-06-27  1:34 ` Qu Wenruo
@ 2016-07-07 14:07 ` David Sterba
  2016-07-08  1:48 ` Jeff Mahoney
  31 siblings, 0 replies; 44+ messages in thread
From: David Sterba @ 2016-07-07 14:07 UTC (permalink / raw)
  To: jeffm; +Cc: linux-btrfs

On Fri, Jun 24, 2016 at 06:14:53PM -0400, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
> 
> One of the common complaints I've heard from new and experienced
> developers alike about the btrfs code is the ubiquity of
> struct btrfs_root.  There is one for every tree on disk and it's not
> always obvious which root is needed in a particular call path.  It can
> be frustrating to spend time figuring out which root is required only
> to discover that it's not actually used for anything other than
> getting the fs-global struct btrfs_fs_info.
> 
> The patchset contains several sections.
[...]

The whole series looks very good. The patches are well split and
reviewable. I'll take the squashed series, but due to the merge
conflicts I'll  merge it last on top of other patches that have been
sent before.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 05/31] btrfs: tests, require fs_info for root
  2016-06-24 22:14 ` [PATCH 05/31] btrfs: tests, require fs_info for root jeffm
@ 2016-07-08  1:32   ` Jeff Mahoney
  2016-07-08 11:20     ` David Sterba
  0 siblings, 1 reply; 44+ messages in thread
From: Jeff Mahoney @ 2016-07-08  1:32 UTC (permalink / raw)
  To: linux-btrfs, David Sterba


[-- Attachment #1.1: Type: text/plain, Size: 2537 bytes --]

On 6/24/16 6:14 PM, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
> 
> This allows the upcoming patchset to push nodesize and sectorsize into
> fs_info.
> 
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
> ---
>  fs/btrfs/ctree.h                       |  1 +
>  fs/btrfs/disk-io.c                     | 15 +++++++----
>  fs/btrfs/disk-io.h                     |  3 ++-
>  fs/btrfs/tests/btrfs-tests.c           | 20 ++++++++++++---
>  fs/btrfs/tests/btrfs-tests.h           |  1 +
>  fs/btrfs/tests/extent-buffer-tests.c   | 23 +++++++++++------
>  fs/btrfs/tests/free-space-tests.c      | 14 +++++++----
>  fs/btrfs/tests/free-space-tree-tests.c | 18 +++++++------
>  fs/btrfs/tests/inode-tests.c           | 46 ++++++++++++++++++----------------
>  fs/btrfs/tests/qgroup-tests.c          | 23 +++++++++--------
>  10 files changed, 103 insertions(+), 61 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 100d2ea..4781057 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -117,6 +117,7 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
>  #define BTRFS_FS_STATE_REMOUNTING	1
>  #define BTRFS_FS_STATE_TRANS_ABORTED	2
>  #define BTRFS_FS_STATE_DEV_REPLACING	3
> +#define BTRFS_FS_STATE_DUMMY_FS_INFO	4
>  
>  #define BTRFS_BACKREF_REV_MAX		256
>  #define BTRFS_BACKREF_REV_SHIFT		56
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 8f27127..418163d 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -1233,6 +1233,7 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
>  			 struct btrfs_root *root, struct btrfs_fs_info *fs_info,
>  			 u64 objectid)
>  {
> +	bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
>  	root->node = NULL;
>  	root->commit_root = NULL;
>  	root->sectorsize = sectorsize;
> @@ -1287,14 +1288,14 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
>  	root->log_transid = 0;
>  	root->log_transid_committed = -1;
>  	root->last_log_commit = 0;
> -	if (fs_info)
> +	if (dummy)

This should be:
if (!dummy)

>  		extent_io_tree_init(&root->dirty_log_pages,
>  				     fs_info->btree_inode->i_mapping);
>  
>  	memset(&root->root_key, 0, sizeof(root->root_key));
>  	memset(&root->root_item, 0, sizeof(root->root_item));
>  	memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
> -	if (fs_info)
> +	if (dummy)

So should this.

-Jeff

-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 881 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers
  2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
                   ` (30 preceding siblings ...)
  2016-07-07 14:07 ` David Sterba
@ 2016-07-08  1:48 ` Jeff Mahoney
  2016-07-08  2:19   ` Jeff Mahoney
  31 siblings, 1 reply; 44+ messages in thread
From: Jeff Mahoney @ 2016-07-08  1:48 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba


[-- Attachment #1.1: Type: text/plain, Size: 1284 bytes --]

On 6/24/16 6:14 PM, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
> 
> One of the common complaints I've heard from new and experienced
> developers alike about the btrfs code is the ubiquity of
> struct btrfs_root.  There is one for every tree on disk and it's not
> always obvious which root is needed in a particular call path.  It can
> be frustrating to spend time figuring out which root is required only
> to discover that it's not actually used for anything other than
> getting the fs-global struct btrfs_fs_info.
> 
> The patchset contains several sections.
> 
> 1) The fsid trace event patchset I posted earlier; I can rebase without this
>    but I'd prefer not to.
> 
> 2) Converting btrfs_test_opt and friends to use an fs_info.
> 
> 3) Converting tests to use an fs_info pointer whenever a root is used.
> 
> 4) Moving sectorsize and nodesize to fs_info and cleaning up the
>    macros used to access them.

This change was a little overzealous in free-space-cache.c, which hit
block_group->sectorsize as well as root->sectorsize by accident.  While
the change is fine for general btrfs usage, it breaks the sanity tests
since dummy block groups now depend on a dummy fs_info as well.

-Jeff

-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 881 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers
  2016-07-08  1:48 ` Jeff Mahoney
@ 2016-07-08  2:19   ` Jeff Mahoney
  2016-07-08 12:50     ` David Sterba
  0 siblings, 1 reply; 44+ messages in thread
From: Jeff Mahoney @ 2016-07-08  2:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba


[-- Attachment #1.1: Type: text/plain, Size: 1538 bytes --]

On 7/7/16 9:48 PM, Jeff Mahoney wrote:
> On 6/24/16 6:14 PM, jeffm@suse.com wrote:
>> From: Jeff Mahoney <jeffm@suse.com>
>>
>> One of the common complaints I've heard from new and experienced
>> developers alike about the btrfs code is the ubiquity of
>> struct btrfs_root.  There is one for every tree on disk and it's not
>> always obvious which root is needed in a particular call path.  It can
>> be frustrating to spend time figuring out which root is required only
>> to discover that it's not actually used for anything other than
>> getting the fs-global struct btrfs_fs_info.
>>
>> The patchset contains several sections.
>>
>> 1) The fsid trace event patchset I posted earlier; I can rebase without this
>>    but I'd prefer not to.
>>
>> 2) Converting btrfs_test_opt and friends to use an fs_info.
>>
>> 3) Converting tests to use an fs_info pointer whenever a root is used.
>>
>> 4) Moving sectorsize and nodesize to fs_info and cleaning up the
>>    macros used to access them.
> 
> This change was a little overzealous in free-space-cache.c, which hit
> block_group->sectorsize as well as root->sectorsize by accident.  While
> the change is fine for general btrfs usage, it breaks the sanity tests
> since dummy block groups now depend on a dummy fs_info as well.

There's also another error in btrfs_alloc_dummy_fs_info that doesn't
initialize sectorsize.

Clearly my test config got CONFIG_BTRFS_FS_RUN_SANITY_TESTS disabled at
some point. :(

-Jeff

-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 881 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 05/31] btrfs: tests, require fs_info for root
  2016-07-08  1:32   ` Jeff Mahoney
@ 2016-07-08 11:20     ` David Sterba
  0 siblings, 0 replies; 44+ messages in thread
From: David Sterba @ 2016-07-08 11:20 UTC (permalink / raw)
  To: Jeff Mahoney; +Cc: linux-btrfs, David Sterba

On Thu, Jul 07, 2016 at 09:32:37PM -0400, Jeff Mahoney wrote:
> On 6/24/16 6:14 PM, jeffm@suse.com wrote:
> > From: Jeff Mahoney <jeffm@suse.com>
> > 
> > This allows the upcoming patchset to push nodesize and sectorsize into
> > fs_info.
> > 
> > Signed-off-by: Jeff Mahoney <jeffm@suse.com>
> > ---
> >  fs/btrfs/ctree.h                       |  1 +
> >  fs/btrfs/disk-io.c                     | 15 +++++++----
> >  fs/btrfs/disk-io.h                     |  3 ++-
> >  fs/btrfs/tests/btrfs-tests.c           | 20 ++++++++++++---
> >  fs/btrfs/tests/btrfs-tests.h           |  1 +
> >  fs/btrfs/tests/extent-buffer-tests.c   | 23 +++++++++++------
> >  fs/btrfs/tests/free-space-tests.c      | 14 +++++++----
> >  fs/btrfs/tests/free-space-tree-tests.c | 18 +++++++------
> >  fs/btrfs/tests/inode-tests.c           | 46 ++++++++++++++++++----------------
> >  fs/btrfs/tests/qgroup-tests.c          | 23 +++++++++--------
> >  10 files changed, 103 insertions(+), 61 deletions(-)
> > 
> > diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> > index 100d2ea..4781057 100644
> > --- a/fs/btrfs/ctree.h
> > +++ b/fs/btrfs/ctree.h
> > @@ -117,6 +117,7 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
> >  #define BTRFS_FS_STATE_REMOUNTING	1
> >  #define BTRFS_FS_STATE_TRANS_ABORTED	2
> >  #define BTRFS_FS_STATE_DEV_REPLACING	3
> > +#define BTRFS_FS_STATE_DUMMY_FS_INFO	4
> >  
> >  #define BTRFS_BACKREF_REV_MAX		256
> >  #define BTRFS_BACKREF_REV_SHIFT		56
> > diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> > index 8f27127..418163d 100644
> > --- a/fs/btrfs/disk-io.c
> > +++ b/fs/btrfs/disk-io.c
> > @@ -1233,6 +1233,7 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
> >  			 struct btrfs_root *root, struct btrfs_fs_info *fs_info,
> >  			 u64 objectid)
> >  {
> > +	bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
> >  	root->node = NULL;
> >  	root->commit_root = NULL;
> >  	root->sectorsize = sectorsize;
> > @@ -1287,14 +1288,14 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
> >  	root->log_transid = 0;
> >  	root->log_transid_committed = -1;
> >  	root->last_log_commit = 0;
> > -	if (fs_info)
> > +	if (dummy)
> 
> This should be:
> if (!dummy)
> 
> >  		extent_io_tree_init(&root->dirty_log_pages,
> >  				     fs_info->btree_inode->i_mapping);
> >  
> >  	memset(&root->root_key, 0, sizeof(root->root_key));
> >  	memset(&root->root_item, 0, sizeof(root->root_item));
> >  	memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
> > -	if (fs_info)
> > +	if (dummy)
> 
> So should this.

Updated in the patch.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers
  2016-07-08  2:19   ` Jeff Mahoney
@ 2016-07-08 12:50     ` David Sterba
  0 siblings, 0 replies; 44+ messages in thread
From: David Sterba @ 2016-07-08 12:50 UTC (permalink / raw)
  To: Jeff Mahoney; +Cc: linux-btrfs, David Sterba

On Thu, Jul 07, 2016 at 10:19:37PM -0400, Jeff Mahoney wrote:
> On 7/7/16 9:48 PM, Jeff Mahoney wrote:
> > On 6/24/16 6:14 PM, jeffm@suse.com wrote:
> >> From: Jeff Mahoney <jeffm@suse.com>
> >>
> >> One of the common complaints I've heard from new and experienced
> >> developers alike about the btrfs code is the ubiquity of
> >> struct btrfs_root.  There is one for every tree on disk and it's not
> >> always obvious which root is needed in a particular call path.  It can
> >> be frustrating to spend time figuring out which root is required only
> >> to discover that it's not actually used for anything other than
> >> getting the fs-global struct btrfs_fs_info.
> >>
> >> The patchset contains several sections.
> >>
> >> 1) The fsid trace event patchset I posted earlier; I can rebase without this
> >>    but I'd prefer not to.
> >>
> >> 2) Converting btrfs_test_opt and friends to use an fs_info.
> >>
> >> 3) Converting tests to use an fs_info pointer whenever a root is used.
> >>
> >> 4) Moving sectorsize and nodesize to fs_info and cleaning up the
> >>    macros used to access them.
> > 
> > This change was a little overzealous in free-space-cache.c, which hit
> > block_group->sectorsize as well as root->sectorsize by accident.  While
> > the change is fine for general btrfs usage, it breaks the sanity tests
> > since dummy block groups now depend on a dummy fs_info as well.
> 
> There's also another error in btrfs_alloc_dummy_fs_info that doesn't
> initialize sectorsize.
> 
> Clearly my test config got CONFIG_BTRFS_FS_RUN_SANITY_TESTS disabled at
> some point. :(

I've tried to fix that but the tests still failed so for sake of getting
for-next out, I've verified that commits up to

"btrfs: btrfs_abort_transaction, drop root parameter"

do boot so please send updates only to the following patches. My fixup
attempts are in the branch for-4.8-fixups-buggy.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 15/31] btrfs: call functions that overwrite their root parameter with fs_info
  2016-06-24 22:15 ` [PATCH 15/31] btrfs: call functions that overwrite their root parameter with fs_info jeffm
@ 2016-09-06 17:40   ` David Sterba
  0 siblings, 0 replies; 44+ messages in thread
From: David Sterba @ 2016-09-06 17:40 UTC (permalink / raw)
  To: jeffm; +Cc: linux-btrfs

Hi,

On Fri, Jun 24, 2016 at 06:15:08PM -0400, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
> 
> There are 11 functions that accept a root parameter and immediately
> overwrite it.  We can pass those an fs_info pointer instead.
> 
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>

including this patch, the rest of the series hasn't been merged in the
last cycle.

The first batch of 4.9 patches is done, please refresh the series on top
of that. Branch misc-4.9 in
http://repo.or.cz/linux-2.6/btrfs-unstable.git or
https://github.com/kdave/btrfs-devel . Thanks.

^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2016-09-06 17:42 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-24 22:14 [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers jeffm
2016-06-24 22:14 ` [PATCH 01/31] btrfs: plumb fs_info into btrfs_work jeffm
2016-06-24 22:14 ` [PATCH 02/31] btrfs: prefix fsid to all trace events jeffm
2016-06-27  1:50   ` Qu Wenruo
2016-06-24 22:14 ` [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info jeffm
2016-06-27  2:14   ` Qu Wenruo
2016-06-27  2:21     ` Jeff Mahoney
2016-06-27  2:24       ` Qu Wenruo
2016-06-24 22:14 ` [PATCH 04/31] btrfs: tests, move initialization into tests/ jeffm
2016-06-27  2:17   ` Qu Wenruo
2016-06-27  2:28     ` Jeff Mahoney
2016-06-24 22:14 ` [PATCH 05/31] btrfs: tests, require fs_info for root jeffm
2016-07-08  1:32   ` Jeff Mahoney
2016-07-08 11:20     ` David Sterba
2016-06-24 22:14 ` [PATCH 06/31] btrfs: tests, use BTRFS_FS_STATE_DUMMY_FS_INFO instead of dummy root jeffm
2016-06-24 22:15 ` [PATCH 07/31] btrfs: simpilify btrfs_subvol_inherit_props jeffm
2016-06-24 22:15 ` [PATCH 08/31] btrfs: copy_to_sk drop unused root parameter jeffm
2016-06-24 22:15 ` [PATCH 09/31] btrfs: cleanup, remove prototype for btrfs_find_root_ref jeffm
2016-06-24 22:15 ` [PATCH 10/31] btrfs: introduce BTRFS_MAX_ITEM_SIZE jeffm
2016-06-24 22:15 ` [PATCH 11/31] btrfs: convert nodesize macros to static inlines jeffm
2016-06-24 22:15 ` [PATCH 12/31] btrfs: btrfs_relocate_chunk pass extent_root to btrfs_end_transaction jeffm
2016-06-24 22:15 ` [PATCH 13/31] btrfs: add btrfs_trans_handle->fs_info pointer jeffm
2016-06-24 22:15 ` [PATCH 14/31] btrfs: btrfs_abort_transaction, drop root parameter jeffm
2016-06-24 22:15 ` [PATCH 15/31] btrfs: call functions that overwrite their root parameter with fs_info jeffm
2016-09-06 17:40   ` David Sterba
2016-06-24 22:15 ` [PATCH 16/31] btrfs: call functions that always use the same root with fs_info instead jeffm
2016-06-24 22:15 ` [PATCH 17/31] btrfs: btrfs_init_new_device should use fs_info->dev_root jeffm
2016-06-24 22:15 ` [PATCH 18/31] btrfs: alloc_reserved_file_extent trace point should use extent_root jeffm
2016-06-24 22:15 ` [PATCH 19/31] btrfs: struct btrfsic_state->root should be an fs_info jeffm
2016-06-24 22:15 ` [PATCH 20/31] btrfs: struct reada_control.root -> reada_control.fs_info jeffm
2016-06-24 22:15 ` [PATCH 21/31] btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere jeffm
2016-06-24 22:15 ` [PATCH 22/31] btrfs: root->fs_info cleanup, io_ctl_init jeffm
2016-06-24 22:15 ` [PATCH 24/31] btrfs: root->fs_info cleanup, btrfs_calc_{trans,trunc}_metadata_size jeffm
2016-06-24 22:15 ` [PATCH 25/31] btrfs: root->fs_info cleanup, lock/unlock_chunks jeffm
2016-06-24 22:15 ` [PATCH 26/31] btrfs: root->fs_info cleanup, update_block_group{,flags} jeffm
2016-06-24 22:15 ` [PATCH 28/31] btrfs: root->fs_info cleanup, access fs_info->delayed_root directly jeffm
2016-06-24 22:15 ` [PATCH 30/31] btrfs: root->fs_info cleanup, btrfs_commit_transaction already has root jeffm
2016-06-24 22:15 ` [PATCH 31/31] btrfs: root->fs_info cleanup, btrfs_end_transaction{,_throttle} use trans->fs_info instead of parameter jeffm
2016-06-26 13:50 ` [PATCH 00/31] btrfs: simplify use of struct btrfs_root pointers Jeff Mahoney
2016-06-27  1:34 ` Qu Wenruo
2016-07-07 14:07 ` David Sterba
2016-07-08  1:48 ` Jeff Mahoney
2016-07-08  2:19   ` Jeff Mahoney
2016-07-08 12:50     ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.