Skip to contentSkip to conversation

btrfs: simplify use of struct btrfs_root pointers

PATCH In review [email protected] 3 participants 44 messages Jun 24, 2016 – Sep 6, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover btrfs: simplify use of struct btrfs_root pointers

From: Jeff Mahoney <[email protected]>

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(-)
Signature · 1 line
2.7.1
#1 lore raw

PATCH 1/31 btrfs: plumb fs_info into btrfs_work

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/async-thread.c +25 -6
index 5fb60ea..e0f071f 100644
@@ -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);
fs/btrfs/async-thread.h +5 -1
index ad4d064..8e52484 100644
@@ -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
fs/btrfs/disk-io.c +28 -19

86 lines not on this page · raw message

fs/btrfs/scrub.c +5 -5
index 70427ef..86270c6 100644
@@ -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;
Signature · 1 line
2.7.1
#2 lore raw

PATCH 2/31 btrfs: prefix fsid to all trace events

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/delayed-ref.c +5 -4
index 430b368..e7b1ec0 100644
@@ -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);
 
fs/btrfs/extent-tree.c +6 -4
index 29e5d00..39308a8 100644
@@ -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);
 
fs/btrfs/qgroup.c +10 -9
index 9d4c05b..13e28d8 100644
@@ -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) {
 			/*
fs/btrfs/qgroup.h +5 -4
index ecb2c14..710887c 100644
@@ -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);
 
fs/btrfs/super.c +1 -1
index 60e7179..ee56b0e 100644
@@ -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);
include/trace/events/btrfs.h +155 -127

863 lines not on this page · raw message

Signature · 1 line
2.7.1
#3 lore raw

Re: [PATCH 02/31] btrfs: prefix fsid to all trace events

Quoted 213 lines · At 06/25/2016 06:14 AM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/delayed-ref.c +5 -4
index 430b368..e7b1ec0 100644
@@ -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);
 
fs/btrfs/extent-tree.c +6 -4
index 29e5d00..39308a8 100644
@@ -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);
 
fs/btrfs/qgroup.c +10 -9
index 9d4c05b..13e28d8 100644
@@ -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) {
 			/*
fs/btrfs/qgroup.h +5 -4
index ecb2c14..710887c 100644
@@ -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);
 
fs/btrfs/super.c +1 -1
index 60e7179..ee56b0e 100644
@@ -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);
include/trace/events/btrfs.h +5 -0
index e90e82a..eba0c65 100644
@@ -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)
+

include/trace/events/btrfs.h struct btrfs_qgroup_extent_record; · line 83

Quoted 10 lines
include/trace/events/btrfs.h +10 -0
+#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

Quoted 905 lines
include/trace/events/btrfs.h +140 -127
 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)
#4 lore raw

PATCH 3/31 btrfs: btrfs_test_opt and friends should take a btrfs_fs_info

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/ctree.h +11 -11
index 101c3cf..100d2ea 100644
@@ -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
fs/btrfs/delayed-inode.c +1 -1
index 61561c2..ed67717 100644
@@ -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);
fs/btrfs/dev-replace.c +2 -2
index 63ef9cd..e9bbff3 100644
@@ -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");
fs/btrfs/disk-io.c +11 -11
index 685c81a..8f27127 100644
@@ -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
 
fs/btrfs/extent-tree.c +16 -16
index 39308a8..efb5459 100644
@@ -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)
fs/btrfs/file.c +1 -1
index e0c9bd3..ffd9001 100644
@@ -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))
fs/btrfs/free-space-cache.c +3 -3
index 69d270f..cee2049 100644
@@ -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));
fs/btrfs/inode-map.c +6 -6
index 70107f7..e3ad8c1 100644
@@ -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();
fs/btrfs/inode.c +6 -6
index d2be95c..141a233 100644
@@ -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;
 	}
fs/btrfs/ioctl.c +1 -1
index 0517356..ffb1628 100644
@@ -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;
 
 		/*
fs/btrfs/super.c +68 -64

323 lines not on this page · raw message

fs/btrfs/transaction.c +3 -3
index 7658457..db26eff 100644
@@ -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);
 }
 
fs/btrfs/tree-log.c +2 -2
index c05f69a..5893018 100644
@@ -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;
 	}
fs/btrfs/volumes.c +6 -5
index 2f631b5..ca98cac 100644
@@ -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) {
Signature · 1 line
2.7.1
#5 lore raw

Re: [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info

Quoted 89 lines · At 06/25/2016 06:14 AM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/ctree.h +11 -11
index 101c3cf..100d2ea 100644
@@ -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
fs/btrfs/delayed-inode.c +1 -1
index 61561c2..ed67717 100644
@@ -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);
fs/btrfs/dev-replace.c +0 -0
index 63ef9cd..e9bbff3 100644

fs/btrfs/dev-replace.c no_valid_dev_replace_entry_found: · line 145

Quoted 5 lines
fs/btrfs/dev-replace.c +1 -1
@@ -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.

fs/btrfs/dev-replace.c no_valid_dev_replace_entry_found: · line 154

Quoted 9 lines
fs/btrfs/dev-replace.c +1 -1
 			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.

Quoted 8 lines
fs/btrfs/dev-replace.c +0 -0
 			ret = -EIO;
 			btrfs_warn(fs_info,
 			   "cannot mount because device replace operation is ongoing and");
fs/btrfs/disk-io.c +0 -0
index 685c81a..8f27127 100644

fs/btrfs/disk-io.c retry_root_backup: · line 3029

Quoted 7 lines
fs/btrfs/disk-io.c +2 -2
@@ -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/btrfs/disk-io.c retry_root_backup: · line 3044

Quoted 12 lines
fs/btrfs/disk-io.c +2 -2
 	    !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.

fs/btrfs/disk-io.c retry_root_backup: · line 3060

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
 					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.

fs/btrfs/disk-io.c retry_root_backup: · line 3101

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
 		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.

fs/btrfs/disk-io.c retry_root_backup: · line 3138

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
 	    !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.

fs/btrfs/disk-io.c retry_root_backup: · line 3159

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
 	    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/btrfs/disk-io.c fail: · line 3236

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
 		   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.

Quoted 13 lines
fs/btrfs/disk-io.c +1 -1
 		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;

fs/btrfs/disk-io.c void close_ctree(struct btrfs_root *root) · line 3935

Quoted 5 lines
fs/btrfs/disk-io.c +1 -1
@@ -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().

Quoted 36 lines
fs/btrfs/disk-io.c +0 -0
 		btrfsic_unmount(root, fs_info->fs_devices);
 #endif
 
fs/btrfs/extent-tree.c +1 -1
index 39308a8..efb5459 100644
@@ -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_
fs/btrfs/extent-tree.c +2 -2
 		 * 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);

fs/btrfs/extent-tree.c static int update_block_group(struct btrfs_trans_handle *trans, · line 6012

Quoted 5 lines
fs/btrfs/extent-tree.c +1 -1
@@ -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().

Quoted 13 lines
fs/btrfs/extent-tree.c +1 -1
 		    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))

fs/btrfs/extent-tree.c int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, · line 6521

Quoted 5 lines
fs/btrfs/extent-tree.c +1 -1
@@ -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.

Quoted 49 lines
fs/btrfs/extent-tree.c +5 -5
 			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)) {

fs/btrfs/extent-tree.c int btrfs_read_block_groups(struct btrfs_root *root) · line 9909

Quoted 5 lines
fs/btrfs/extent-tree.c +1 -1
@@ -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.

fs/btrfs/extent-tree.c int btrfs_read_block_groups(struct btrfs_root *root) · line 9912

Quoted 4 lines
fs/btrfs/extent-tree.c +1 -1
 	    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

fs/btrfs/extent-tree.c int btrfs_read_block_groups(struct btrfs_root *root) · line 9943

Quoted 9 lines
fs/btrfs/extent-tree.c +1 -1
 		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

Quoted 70 lines
fs/btrfs/extent-tree.c +2 -2
 				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)
fs/btrfs/file.c +1 -1
index e0c9bd3..ffd9001 100644
@@ -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))
fs/btrfs/free-space-cache.c +3 -3
index 69d270f..cee2049 100644
@@ -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));
fs/btrfs/inode-map.c +0 -0
index 70107f7..e3ad8c1 100644

fs/btrfs/inode-map.c static int caching_kthread(void *data) · line 41

Quoted 5 lines
fs/btrfs/inode-map.c +1 -1
@@ -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

#6 lore raw

Re: [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info

Quoted 449 lines · Qu Wenruo
Quoted 90 lines · At 06/25/2016 06:14 AM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/ctree.h +11 -11
index 101c3cf..100d2ea 100644
@@ -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
fs/btrfs/delayed-inode.c +1 -1
index 61561c2..ed67717 100644
@@ -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);
fs/btrfs/dev-replace.c +0 -0
index 63ef9cd..e9bbff3 100644

fs/btrfs/dev-replace.c no_valid_dev_replace_entry_found: · line 145

Quoted 5 lines
fs/btrfs/dev-replace.c +1 -1
@@ -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.

fs/btrfs/dev-replace.c no_valid_dev_replace_entry_found: · line 154

Quoted 10 lines
fs/btrfs/dev-replace.c +0 -0
             ret = -EIO;
             btrfs_warn(fs_info,
                "cannot mount because device replace operation is

ongoing and");

fs/btrfs/dev-replace.c +1 -1
@@ -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.

Quoted 9 lines
fs/btrfs/dev-replace.c +0 -0
             ret = -EIO;
             btrfs_warn(fs_info,
                "cannot mount because device replace operation is

ongoing and");

fs/btrfs/disk-io.c +0 -0
index 685c81a..8f27127 100644

fs/btrfs/disk-io.c retry_root_backup: · line 3029

Quoted 7 lines
fs/btrfs/disk-io.c +2 -2
@@ -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/btrfs/disk-io.c retry_root_backup: · line 3044

Quoted 12 lines
fs/btrfs/disk-io.c +2 -2
         !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.

fs/btrfs/disk-io.c retry_root_backup: · line 3060

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
                     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.

fs/btrfs/disk-io.c retry_root_backup: · line 3101

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
         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.

fs/btrfs/disk-io.c retry_root_backup: · line 3138

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
         !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.

fs/btrfs/disk-io.c retry_root_backup: · line 3159

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
         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/btrfs/disk-io.c fail: · line 3236

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
            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.

Quoted 14 lines
fs/btrfs/disk-io.c +1 -1
         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;

fs/btrfs/disk-io.c void close_ctree(struct btrfs_root *root) · line 3935

Quoted 5 lines
fs/btrfs/disk-io.c +1 -1
@@ -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().

Quoted 38 lines
fs/btrfs/disk-io.c +0 -0
         btrfsic_unmount(root, fs_info->fs_devices);
 #endif
 
fs/btrfs/extent-tree.c +1 -1
index 39308a8..efb5459 100644
@@ -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,

fs/btrfs/extent-tree.c +1 -1
@@ -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();
fs/btrfs/extent-tree.c +1 -1
@@ -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);

fs/btrfs/extent-tree.c static int update_block_group(struct · line 6013

Quoted 6 lines
fs/btrfs/extent-tree.c +1 -1
@@ -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().

Quoted 14 lines
fs/btrfs/extent-tree.c +1 -1
             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))

fs/btrfs/extent-tree.c int btrfs_finish_extent_commit(struct · line 6522

Quoted 6 lines
fs/btrfs/extent-tree.c +1 -1
@@ -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.

Quoted 52 lines
fs/btrfs/extent-tree.c +2 -2
             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);
fs/btrfs/extent-tree.c +3 -3
@@ -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)) {

fs/btrfs/extent-tree.c int btrfs_read_block_groups(struct btrfs_root · line 9910

Quoted 6 lines
fs/btrfs/extent-tree.c +1 -1
@@ -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.

fs/btrfs/extent-tree.c int btrfs_read_block_groups(struct btrfs_root *root) · line 9912

Quoted 4 lines
fs/btrfs/extent-tree.c +1 -1
         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

fs/btrfs/extent-tree.c int btrfs_read_block_groups(struct btrfs_root · line 9944

Quoted 10 lines
fs/btrfs/extent-tree.c +0 -0
         need_clear = 1;
 
     while (1) {
fs/btrfs/extent-tree.c +1 -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

Quoted 79 lines
fs/btrfs/extent-tree.c +1 -1
                 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
fs/btrfs/extent-tree.c +1 -1
@@ -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)

fs/btrfs/file.c +1 -1
index e0c9bd3..ffd9001 100644
@@ -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))
fs/btrfs/free-space-cache.c +1 -1
index 69d270f..cee2049 100644
@@ -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;
fs/btrfs/free-space-cache.c +1 -1
@@ -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;
 
     /*
fs/btrfs/free-space-cache.c +1 -1
@@ -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));
fs/btrfs/inode-map.c +0 -0
index 70107f7..e3ad8c1 100644
@@ -38,7 +38,7 @@ static int caching_kthread(void *data)
     int slot;
     int ret;
 
Quoted 7 lines

fs/btrfs/inode-map.c static int caching_kthread(void *data) · line 41

Quoted 2 lines
fs/btrfs/inode-map.c +1 -1
-    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

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#7 lore raw

Re: [PATCH 03/31] btrfs: btrfs_test_opt and friends should take a btrfs_fs_info

Quoted 463 lines · Jeff Mahoney
Quoted 449 lines · Qu Wenruo
Quoted 90 lines · At 06/25/2016 06:14 AM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/ctree.h +11 -11
index 101c3cf..100d2ea 100644
@@ -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
fs/btrfs/delayed-inode.c +1 -1
index 61561c2..ed67717 100644
@@ -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);
fs/btrfs/dev-replace.c +0 -0
index 63ef9cd..e9bbff3 100644

fs/btrfs/dev-replace.c no_valid_dev_replace_entry_found: · line 145

Quoted 5 lines
fs/btrfs/dev-replace.c +1 -1
@@ -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.

fs/btrfs/dev-replace.c no_valid_dev_replace_entry_found: · line 154

Quoted 10 lines
fs/btrfs/dev-replace.c +0 -0
             ret = -EIO;
             btrfs_warn(fs_info,
                "cannot mount because device replace operation is

ongoing and");

fs/btrfs/dev-replace.c +1 -1
@@ -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.

Quoted 9 lines
fs/btrfs/dev-replace.c +0 -0
             ret = -EIO;
             btrfs_warn(fs_info,
                "cannot mount because device replace operation is

ongoing and");

fs/btrfs/disk-io.c +0 -0
index 685c81a..8f27127 100644

fs/btrfs/disk-io.c retry_root_backup: · line 3029

Quoted 7 lines
fs/btrfs/disk-io.c +2 -2
@@ -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/btrfs/disk-io.c retry_root_backup: · line 3044

Quoted 12 lines
fs/btrfs/disk-io.c +2 -2
         !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.

fs/btrfs/disk-io.c retry_root_backup: · line 3060

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
                     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.

fs/btrfs/disk-io.c retry_root_backup: · line 3101

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
         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.

fs/btrfs/disk-io.c retry_root_backup: · line 3138

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
         !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.

fs/btrfs/disk-io.c retry_root_backup: · line 3159

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
         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/btrfs/disk-io.c fail: · line 3236

Quoted 9 lines
fs/btrfs/disk-io.c +1 -1
            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.

Quoted 14 lines
fs/btrfs/disk-io.c +1 -1
         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;

fs/btrfs/disk-io.c void close_ctree(struct btrfs_root *root) · line 3935

Quoted 5 lines
fs/btrfs/disk-io.c +1 -1
@@ -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().

Quoted 38 lines
fs/btrfs/disk-io.c +0 -0
         btrfsic_unmount(root, fs_info->fs_devices);
 #endif
 
fs/btrfs/extent-tree.c +1 -1
index 39308a8..efb5459 100644
@@ -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,

fs/btrfs/extent-tree.c +1 -1
@@ -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();
fs/btrfs/extent-tree.c +1 -1
@@ -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);

fs/btrfs/extent-tree.c static int update_block_group(struct · line 6013

Quoted 6 lines
fs/btrfs/extent-tree.c +1 -1
@@ -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().

Quoted 14 lines
fs/btrfs/extent-tree.c +1 -1
             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))

fs/btrfs/extent-tree.c int btrfs_finish_extent_commit(struct · line 6522

Quoted 6 lines
fs/btrfs/extent-tree.c +1 -1
@@ -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.

Quoted 52 lines
fs/btrfs/extent-tree.c +2 -2
             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);
fs/btrfs/extent-tree.c +3 -3
@@ -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)) {

fs/btrfs/extent-tree.c int btrfs_read_block_groups(struct btrfs_root · line 9910

Quoted 6 lines
fs/btrfs/extent-tree.c +1 -1
@@ -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.

fs/btrfs/extent-tree.c int btrfs_read_block_groups(struct btrfs_root *root) · line 9912

Quoted 4 lines
fs/btrfs/extent-tree.c +1 -1
         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

fs/btrfs/extent-tree.c int btrfs_read_block_groups(struct btrfs_root · line 9944

Quoted 10 lines
fs/btrfs/extent-tree.c +0 -0
         need_clear = 1;
 
     while (1) {
fs/btrfs/extent-tree.c +1 -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

Quoted 79 lines
fs/btrfs/extent-tree.c +1 -1
                 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
fs/btrfs/extent-tree.c +1 -1
@@ -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)

fs/btrfs/file.c +1 -1
index e0c9bd3..ffd9001 100644
@@ -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))
fs/btrfs/free-space-cache.c +1 -1
index 69d270f..cee2049 100644
@@ -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;
fs/btrfs/free-space-cache.c +1 -1
@@ -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;
 
     /*
fs/btrfs/free-space-cache.c +1 -1
@@ -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));
fs/btrfs/inode-map.c +0 -0
index 70107f7..e3ad8c1 100644
@@ -38,7 +38,7 @@ static int caching_kthread(void *data)
     int slot;
     int ret;
 
Quoted 7 lines

fs/btrfs/inode-map.c static int caching_kthread(void *data) · line 41

Quoted 2 lines
fs/btrfs/inode-map.c +1 -1
-    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.

Quoted 9 lines

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

#8 lore raw

PATCH 4/31 btrfs: tests, move initialization into tests/

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/super.c +0 -43
index a7b9a15..d8e48bb 100644
@@ -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;
fs/btrfs/tests/btrfs-tests.c +45 -2

62 lines not on this page · raw message

fs/btrfs/tests/btrfs-tests.h +3 -32
index 66fb6b70..e7d364f 100644
@@ -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;
 }
Signature · 1 line
2.7.1
#9 lore raw

Re: [PATCH 04/31] btrfs: tests, move initialization into tests/

Quoted 144 lines · At 06/25/2016 06:14 AM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/super.c +0 -43
index a7b9a15..d8e48bb 100644
@@ -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;
fs/btrfs/tests/btrfs-tests.c +45 -2
index 10eb249..d90c951 100644
@@ -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;
+}
fs/btrfs/tests/btrfs-tests.h +0 -0
index 66fb6b70..e7d364f 100644
@@ -20,20 +20,19 @@
 #define __BTRFS_TESTS
 
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS

fs/btrfs/tests/btrfs-tests.h line 31

Quoted 10 lines
fs/btrfs/tests/btrfs-tests.h +2 -1
+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

Quoted 47 lines
fs/btrfs/tests/btrfs-tests.h +1 -31
 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;
 }
#10 lore raw

Re: [PATCH 04/31] btrfs: tests, move initialization into tests/

Quoted 158 lines · Qu Wenruo
Quoted 155 lines · At 06/25/2016 06:14 AM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/super.c +0 -43
index a7b9a15..d8e48bb 100644
@@ -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;
fs/btrfs/tests/btrfs-tests.c +45 -2
index 10eb249..d90c951 100644
@@ -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;
+}
fs/btrfs/tests/btrfs-tests.h +1 -0
index 66fb6b70..e7d364f 100644
@@ -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;
 
Quoted 6 lines

fs/btrfs/tests/btrfs-tests.h line 31

Quoted 3 lines
fs/btrfs/tests/btrfs-tests.h +1 -1
-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

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#11 lore raw

PATCH 5/31 btrfs: tests, require fs_info for root

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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

---
 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(-)
fs/btrfs/ctree.h +1 -0
index 100d2ea..4781057 100644
@@ -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
fs/btrfs/disk-io.c +10 -5
index 8f27127..418163d 100644
@@ -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;
fs/btrfs/disk-io.h +2 -1
index acba821..c9d42c9 100644
@@ -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
 
 /*
fs/btrfs/tests/btrfs-tests.c +17 -3
index d90c951..c3783c3 100644
@@ -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);
 }
 
fs/btrfs/tests/btrfs-tests.h +1 -0
index e7d364f..b17ffbe 100644
@@ -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);
fs/btrfs/tests/extent-buffer-tests.c +16 -7
index 4f8cbd1..1995691 100644
@@ -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;
 }
 
fs/btrfs/tests/free-space-tests.c +9 -5
index 3956bb2..3221c8d 100644
@@ -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;
 }
fs/btrfs/tests/free-space-tree-tests.c +10 -8
index aac5070..7508d3b 100644
@@ -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;
 }
 
fs/btrfs/tests/inode-tests.c +24 -22

107 lines not on this page · raw message

fs/btrfs/tests/qgroup-tests.c +13 -10
index 57a12c0..4407fef 100644
@@ -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;
 }
Signature · 1 line
2.7.1
#12 lore raw

Re: [PATCH 05/31] btrfs: tests, require fs_info for root

Quoted 44 lines · On 6/24/16 6:14 PM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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

---
 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(-)
fs/btrfs/ctree.h +1 -0
index 100d2ea..4781057 100644
@@ -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
fs/btrfs/disk-io.c +1 -0
index 8f27127..418163d 100644
@@ -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;

fs/btrfs/disk-io.c static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize, · line 1291

Quoted 5 lines
fs/btrfs/disk-io.c +1 -1
@@ -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)

fs/btrfs/disk-io.c static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize, · line 1298

Quoted 8 lines
fs/btrfs/disk-io.c +1 -1
 		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

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#13 lore raw

Re: [PATCH 05/31] btrfs: tests, require fs_info for root

Quoted 57 lines · Jeff Mahoney
Quoted 44 lines · On 6/24/16 6:14 PM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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

---
 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(-)
fs/btrfs/ctree.h +1 -0
index 100d2ea..4781057 100644
@@ -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
fs/btrfs/disk-io.c +1 -0
index 8f27127..418163d 100644
@@ -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;

fs/btrfs/disk-io.c static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize, · line 1291

Quoted 5 lines
fs/btrfs/disk-io.c +1 -1
@@ -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)

Quoted 3 lines
fs/btrfs/disk-io.c +0 -0
 		extent_io_tree_init(&root->dirty_log_pages,
 				     fs_info->btree_inode->i_mapping);
 
Quoted 7 lines

fs/btrfs/disk-io.c static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize, · line 1298

Quoted 5 lines
fs/btrfs/disk-io.c +1 -1
 	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.

#14 lore raw

PATCH 6/31 btrfs: tests, use BTRFS_FS_STATE_DUMMY_FS_INFO instead of dummy root

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/backref.c +1 -1
index 8bb3509..8637069 100644
@@ -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;
fs/btrfs/ctree.c +1 -1
index 6276add..2bf3d58 100644
@@ -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 */
fs/btrfs/ctree.h +8 -9
index 4781057..0b107d1 100644
@@ -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
fs/btrfs/disk-io.c +1 -2
index 418163d..e1b36e1 100644
@@ -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;
fs/btrfs/extent-tree.c +4 -4
index efb5459..ee8cd29 100644
@@ -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))
fs/btrfs/inode.c +2 -2
index 141a233..1acba51 100644
@@ -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
fs/btrfs/qgroup.c +2 -2
index 13e28d8..3a83631 100644
@@ -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;
Signature · 1 line
2.7.1
#15 lore raw

PATCH 7/31 btrfs: simpilify btrfs_subvol_inherit_props

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 fs/btrfs/props.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/props.c +3 -3
index 3699212..cf0b444 100644
@@ -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);
Signature · 1 line
2.7.1
#16 lore raw

PATCH 8/31 btrfs: copy_to_sk drop unused root parameter

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

The root parameter for copy_to_sk is not used at all.

---
 fs/btrfs/ioctl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/ioctl.c +2 -3
index ffb1628..81413e6 100644
@@ -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)
Signature · 1 line
2.7.1
#17 lore raw

PATCH 9/31 btrfs: cleanup, remove prototype for btrfs_find_root_ref

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

The function isn't implemented anywhere.

---
 fs/btrfs/ctree.h | 3 ---
 1 file changed, 3 deletions(-)
fs/btrfs/ctree.h +0 -3
index 0b107d1..bff6ce6 100644
@@ -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,
Signature · 1 line
2.7.1
#18 lore raw

PATCH 10/31 btrfs: introduce BTRFS_MAX_ITEM_SIZE

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/ctree.h +4 -4
index bff6ce6..1d3c4b5 100644
@@ -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))
 
 
fs/btrfs/extent-tree.c +1 -1
index ee8cd29..e4af375 100644
@@ -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);
fs/btrfs/file-item.c +2 -3
index 62a81ee..fc6390e 100644
@@ -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))
fs/btrfs/volumes.c +1 -2
index ca98cac..49c9851 100644
@@ -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)
 
Signature · 1 line
2.7.1
#19 lore raw

PATCH 11/31 btrfs: convert nodesize macros to static inlines

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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

---
 fs/btrfs/ctree.h | 48 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 15 deletions(-)
fs/btrfs/ctree.h +33 -15
index 1d3c4b5..95fe439 100644
@@ -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.
  *
Signature · 1 line
2.7.1
#20 lore raw

PATCH 12/31 btrfs: btrfs_relocate_chunk pass extent_root to btrfs_end_transaction

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 fs/btrfs/volumes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/volumes.c +1 -1
index 49c9851..e0332c9 100644
@@ -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;
 }
 
Signature · 1 line
2.7.1
#21 lore raw

PATCH 13/31 btrfs: add btrfs_trans_handle->fs_info pointer

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/extent-tree.c +3 -3
index e4af375..2081ed4 100644
@@ -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);
fs/btrfs/qgroup.c +1 -1
index 3a83631..93ee1c1 100644
@@ -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",
fs/btrfs/transaction.c +1 -0
index db26eff..db0eb1f 100644
@@ -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;
fs/btrfs/transaction.h +1 -0
index c5abee4..efb1226 100644
@@ -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;
Signature · 1 line
2.7.1
#22 lore raw

PATCH 14/31 btrfs: btrfs_abort_transaction, drop root parameter

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

__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.

---
 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(-)
fs/btrfs/ctree.c +6 -6
index 2bf3d58..904b924 100644
@@ -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,
fs/btrfs/ctree.h +4 -4
index 95fe439..679135d 100644
@@ -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)
 
fs/btrfs/delayed-inode.c +1 -1
index ed67717..316ca24 100644
@@ -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;
 		}
 
fs/btrfs/extent-tree.c +23 -24

177 lines not on this page · raw message

fs/btrfs/file-item.c +1 -1
index fc6390e..e4b8e77 100644
@@ -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;
 			}
 
fs/btrfs/file.c +4 -4
index ffd9001..cc928aa 100644
@@ -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;
 		}
 	}
fs/btrfs/free-space-cache.c +1 -1
index cee2049..d571bd2 100644
@@ -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;
 }
fs/btrfs/free-space-tree.c +8 -8
index 53dbeaf..87e7e3d 100644
@@ -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;
 }
 
fs/btrfs/inode-map.c +2 -2
index e3ad8c1..aa6faba 100644
@@ -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;
 		}
 	}
fs/btrfs/inode.c +37 -40

304 lines not on this page · raw message

fs/btrfs/ioctl.c +15 -18
index 81413e6..14ed1e9 100644
@@ -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;
 	}
 
fs/btrfs/relocation.c +2 -2
index 0477dca..9d07953 100644
@@ -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;
 		}
 	}
fs/btrfs/root-tree.c +5 -5
index f1c3086..7fd7e18 100644
@@ -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;
 	}
fs/btrfs/super.c +7 -5
index d8e48bb..4c031d7 100644
@@ -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,
fs/btrfs/transaction.c +15 -15
index db0eb1f..ad2b6d1 100644
@@ -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);
 
fs/btrfs/tree-log.c +7 -7
index 5893018..697d7f6 100644
@@ -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;
fs/btrfs/volumes.c +9 -9
index e0332c9..0f4f99a 100644
@@ -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;
 	}
Signature · 1 line
2.7.1
#23 lore raw

PATCH 15/31 btrfs: call functions that overwrite their root parameter with fs_info

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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

---
 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(-)
fs/btrfs/ctree.h +2 -2
index 679135d..cc2d8f5 100644
@@ -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,
fs/btrfs/disk-io.c +2 -2
index e1b36e1..42d4a31 100644
@@ -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;
fs/btrfs/extent-tree.c +9 -8
index 56d7b32..0b493c4 100644
@@ -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) {
fs/btrfs/file-item.c +2 -3
index e4b8e77..1160d96 100644
@@ -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;
fs/btrfs/free-space-cache.c +2 -3
index d571bd2..5cbfa64 100644
@@ -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);
fs/btrfs/free-space-cache.h +1 -1
index 3af651c..92e2d1a 100644
@@ -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);
fs/btrfs/transaction.c +4 -5
index ad2b6d1..b540de1 100644
@@ -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);
fs/btrfs/tree-log.c +3 -3
index 697d7f6..bdacbc3 100644
@@ -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,
fs/btrfs/volumes.c +25 -30

191 lines not on this page · raw message

fs/btrfs/volumes.h +2 -2
index 0ac90f8..b0605cb 100644
@@ -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)
 {
Signature · 1 line
2.7.1
#24 lore raw

Re: [PATCH 15/31] btrfs: call functions that overwrite their root parameter with fs_info

Hi,

Quoted 6 lines · On Fri, Jun 24, 2016 at 06:15:08PM -0400, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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

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.

#25 lore raw

PATCH 16/31 btrfs: call functions that always use the same root with fs_info instead

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/ctree.h +8 -8
index cc2d8f5..7063c55 100644
@@ -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,
fs/btrfs/disk-io.c +23 -21

159 lines not on this page · raw message

fs/btrfs/disk-io.h +2 -2
index c9d42c9..25cb43c 100644
@@ -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,
fs/btrfs/extent-tree.c +11 -9
index 0b493c4..e6ad776 100644
@@ -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);
 
fs/btrfs/inode.c +3 -3
index 322ee50..4a9ebb7 100644
@@ -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);
 
fs/btrfs/ioctl.c +8 -10
index 14ed1e9..2ce7c18 100644
@@ -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) {
fs/btrfs/relocation.c +2 -2
index 9d07953..8ee2c2f 100644
@@ -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;
fs/btrfs/root-tree.c +6 -3
index 7fd7e18..a2a99da 100644
@@ -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;
fs/btrfs/super.c +7 -6
index 4c031d7..1cdb9a2 100644
@@ -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);
fs/btrfs/transaction.c +3 -3
index b540de1..4b18a20 100644
@@ -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);
fs/btrfs/uuid-tree.c +6 -4
index 7782829..27cfd7c 100644
@@ -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:
fs/btrfs/volumes.c +26 -20

159 lines not on this page · raw message

fs/btrfs/volumes.h +2 -2
index b0605cb..c5d310d 100644
@@ -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);
include/trace/events/btrfs.h +8 -8
index eba0c65..72ca3a8 100644
@@ -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,
Signature · 1 line
2.7.1
#26 lore raw

PATCH 17/31 btrfs: btrfs_init_new_device should use fs_info->dev_root

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 fs/btrfs/ioctl.c   | 2 +-
 fs/btrfs/volumes.c | 3 ++-
 fs/btrfs/volumes.h | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
fs/btrfs/ioctl.c +1 -1
index 2ce7c18..2fce760 100644
@@ -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);
fs/btrfs/volumes.c +2 -1
index ae18210..9a155d2 100644
@@ -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;
fs/btrfs/volumes.h +1 -1
index c5d310d..6c765c0 100644
@@ -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);
Signature · 1 line
2.7.1
#27 lore raw

PATCH 18/31 btrfs: alloc_reserved_file_extent trace point should use extent_root

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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

---
 fs/btrfs/extent-tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +2 -1
index e6ad776..49775d4 100644
@@ -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;
 }
 
Signature · 1 line
2.7.1
#28 lore raw

PATCH 19/31 btrfs: struct btrfsic_state->root should be an fs_info

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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

---
 fs/btrfs/check-integrity.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
fs/btrfs/check-integrity.c +10 -10
index 7706c8d..656e6fa 100644
@@ -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;
Signature · 1 line
2.7.1
#29 lore raw

PATCH 20/31 btrfs: struct reada_control.root -> reada_control.fs_info

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 fs/btrfs/ctree.h |  2 +-
 fs/btrfs/reada.c | 13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
fs/btrfs/ctree.h +1 -1
index 7063c55..784f003 100644
@@ -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;
fs/btrfs/reada.c +7 -6
index 8428db7..4965d59 100644
@@ -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))
Signature · 1 line
2.7.1
#30 lore raw

PATCH 21/31 btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

---
 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(-)
fs/btrfs/check-integrity.c +1 -1
index 656e6fa..1c8be44 100644
@@ -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,
fs/btrfs/disk-io.c +2 -2
index 5a71cb8..3503455 100644
@@ -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++;
fs/btrfs/extent-tree.c +1 -1
index 49775d4..17afd22 100644
@@ -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;
 
fs/btrfs/scrub.c +43 -44

315 lines not on this page · raw message

fs/btrfs/volumes.c +20 -21

157 lines not on this page · raw message

fs/btrfs/volumes.h +1 -2
index 6c765c0..a0ac26e 100644
@@ -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;
 
Signature · 1 line
2.7.1
#31 lore raw

PATCH 22/31 btrfs: root->fs_info cleanup, io_ctl_init

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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

---
 fs/btrfs/ctree.h            |  2 +-
 fs/btrfs/free-space-cache.c | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)
fs/btrfs/ctree.h +1 -1
index 784f003..4660ce4 100644
@@ -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;
fs/btrfs/free-space-cache.c +6 -6
index 5cbfa64..b3face3 100644
@@ -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;
 
Signature · 1 line
2.7.1
#32 lore raw

PATCH 24/31 btrfs: root->fs_info cleanup, btrfs_calc_{trans,trunc}_metadata_size

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

---
 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(-)
fs/btrfs/ctree.h +4 -4
index b5b3148..d62ff0b 100644
@@ -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,
fs/btrfs/delayed-inode.c +2 -2
index 316ca24..65cd759 100644
@@ -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
fs/btrfs/extent-tree.c +16 -13
index 5d180ce..088182c 100644
@@ -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;
fs/btrfs/file.c +2 -2
index 73114ac..cae6a45 100644
@@ -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;
 
 	/*
fs/btrfs/free-space-cache.c +2 -2
index 7d99e29..02803e9 100644
@@ -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)
fs/btrfs/inode-map.c +2 -1
index aa6faba..a24a0ca 100644
@@ -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);
fs/btrfs/inode.c +2 -2
index bdc9f99..f1e2acc 100644
@@ -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);
fs/btrfs/props.c +1 -1
index cf0b444..f4a5876 100644
@@ -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)
fs/btrfs/transaction.c +3 -2
index 93b463a..a1cbc22 100644
@@ -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,
Signature · 1 line
2.7.1
#33 lore raw

PATCH 25/31 btrfs: root->fs_info cleanup, lock/unlock_chunks

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

---
 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(-)
fs/btrfs/disk-io.c +2 -2
index b7891c4..18b41d7 100644
@@ -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,
fs/btrfs/extent-tree.c +4 -4
index 088182c..14f4d05 100644
@@ -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)
fs/btrfs/free-space-cache.c +2 -2
index 02803e9..b194c09 100644
@@ -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);
fs/btrfs/volumes.c +35 -35

250 lines not on this page · raw message

fs/btrfs/volumes.h +4 -4
index a0ac26e..52fad80 100644
@@ -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);
Signature · 1 line
2.7.1
#34 lore raw

PATCH 26/31 btrfs: root->fs_info cleanup, update_block_group{,flags}

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

---
 fs/btrfs/extent-tree.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
fs/btrfs/extent-tree.c +14 -14
index 14f4d05..bc56e04 100644
@@ -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);
Signature · 1 line
2.7.1
#35 lore raw

PATCH 28/31 btrfs: root->fs_info cleanup, access fs_info->delayed_root directly

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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

---
 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(-)
fs/btrfs/delayed-inode.c +6 -17
index 370f398..733d7bc 100644
@@ -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);
 
fs/btrfs/delayed-inode.h +2 -2
index 0167853..67b2153 100644
@@ -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
fs/btrfs/disk-io.c +4 -4
index 867a69d..a428e4e3 100644
@@ -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);
fs/btrfs/transaction.c +1 -1
index ede1bea..a976373 100644
@@ -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);
 
Signature · 1 line
2.7.1
#36 lore raw

PATCH 30/31 btrfs: root->fs_info cleanup, btrfs_commit_transaction already has root

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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

---
 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(-)
fs/btrfs/dev-replace.c +5 -5
index 3eb0017..57dee36 100644
@@ -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);
fs/btrfs/disk-io.c +3 -3
index f60be47..153e03e 100644
@@ -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)
fs/btrfs/extent-tree.c +2 -2
index 778ef17..31478eb 100644
@@ -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 {
fs/btrfs/file.c +1 -1
index 51f77a2..5fa030f 100644
@@ -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);
 	}
fs/btrfs/free-space-tree.c +2 -2
index 58daa0e..671865b 100644
@@ -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;
 
fs/btrfs/inode.c +2 -2
index 37ef685..4600e93 100644
@@ -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;
 }
fs/btrfs/ioctl.c +11 -12
index 50fc151..04e8061 100644
@@ -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);
 
fs/btrfs/qgroup.c +2 -2
index 6d45fb4..b00c2ea 100644
@@ -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;
fs/btrfs/relocation.c +5 -5
index a2ca2f0..d64a805 100644
@@ -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:
fs/btrfs/scrub.c +1 -2
index 5b0fcc9..c98b91b 100644
@@ -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);
fs/btrfs/send.c +1 -1
index 5f4f853..cd0a052 100644
@@ -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)
fs/btrfs/super.c +2 -2
index 3a160e1..d407826 100644
@@ -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)
fs/btrfs/transaction.c +5 -5
index 57d3187..a546c08 100644
@@ -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;
fs/btrfs/transaction.h +1 -2
index 8bcf529..7d3b358 100644
@@ -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);
fs/btrfs/tree-log.c +1 -1
index 945f02c..e714eb5 100644
@@ -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;
 
fs/btrfs/volumes.c +7 -7
index fadb37f..5953948 100644
@@ -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;
Signature · 1 line
2.7.1
#37 lore raw

PATCH 31/31 btrfs: root->fs_info cleanup, btrfs_end_transaction{,_throttle} use trans->fs_info instead of parameter

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

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.

---
 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(-)
fs/btrfs/backref.c +1 -1
index 1d2c742..5c9505a0 100644
@@ -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);
 	}
fs/btrfs/delayed-inode.c +2 -2
index ca56a8d..9535b5d 100644
@@ -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:
fs/btrfs/disk-io.c +1 -1
index 153e03e..59e5f1e 100644
@@ -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);
fs/btrfs/extent-tree.c +12 -13
index 31478eb..304e46d 100644
@@ -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);
fs/btrfs/file.c +9 -9
index 5fa030f..34d54d9 100644
@@ -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:
fs/btrfs/free-space-tree.c +2 -2
index 671865b..73918e9 100644
@@ -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;
 }
 
fs/btrfs/inode.c +34 -34

270 lines not on this page · raw message

fs/btrfs/ioctl.c +18 -19
index 04e8061..3d402dd 100644
@@ -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)) {
fs/btrfs/qgroup.c +2 -2
index b00c2ea..c9a1ce4 100644
@@ -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");
fs/btrfs/relocation.c +10 -10
index d64a805..930d09c 100644
@@ -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;
fs/btrfs/root-tree.c +1 -1
index 0ed6b97..53e81cb1 100644
@@ -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 "
fs/btrfs/scrub.c +3 -3
index c98b91b..fb4d09d 100644
@@ -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);
fs/btrfs/send.c +1 -1
index cd0a052..eaf85db 100644
@@ -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;
 
fs/btrfs/transaction.c +14 -16
index a546c08..091cb0d 100644
@@ -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);
 
fs/btrfs/transaction.h +2 -4
index 7d3b358..f502514 100644
@@ -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);
fs/btrfs/tree-log.c +1 -1
index e714eb5..ccdff9c 100644
@@ -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;
 }
fs/btrfs/uuid-tree.c +1 -1
index 24b4cfb..3476e91 100644
@@ -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;
fs/btrfs/volumes.c +8 -8
index 5953948..b760933 100644
@@ -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) {
fs/btrfs/xattr.c +1 -1
index 8ee6e19..7a8ddfe 100644
@@ -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;
 }
 
Signature · 1 line
2.7.1
#38 lore raw
In reply to [email protected]
Quoted 43 lines · On 6/24/16 6:14 PM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

Quoted 8 lines

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

Quoted 109 lines

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(-)
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#39 lore raw
In reply to [email protected]
Quoted 9 lines · At 06/25/2016 06:14 AM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

Quoted 5 lines

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)

Quoted 7 lines

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

Quoted 140 lines

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(-)
#40 lore raw
In reply to [email protected]
Quoted 11 lines · On Fri, Jun 24, 2016 at 06:14:53PM -0400, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

#41 lore raw
In reply to [email protected]
Quoted 15 lines · On 6/24/16 6:14 PM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

Quoted 6 lines

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

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#42 lore raw
Quoted 20 lines · Jeff Mahoney
Quoted 19 lines · On 6/24/16 6:14 PM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

Quoted 7 lines
Quoted 2 lines

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

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#43 lore raw
Quoted 29 lines · Jeff Mahoney
Quoted 20 lines · Jeff Mahoney
Quoted 19 lines · On 6/24/16 6:14 PM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

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.

Quoted 7 lines
Quoted 2 lines

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.

Quoted 5 lines

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.