* [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring
@ 2014-08-01 23:12 Eric Sandeen
2014-08-01 23:12 ` [PATCH 01/12] btrfs: remove unused fs_info arg from btrfs_close_extra_devices() Eric Sandeen
` (11 more replies)
0 siblings, 12 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
This is mostly to refactor open_ctree(); at the end of the series
it's "only" around 600 lines instead of 900.
The first 2 patches are just little cleanups I saw while doing this;
the 3rd actually is something of a bugfix.
The rest are refactoring - this is a bit of an RFC still; some
seem like clear groups of code to move out of the way, others
are a bit more gratuitous. Perhaps after these 300 lines are
moved out of the way, folks who are familiar with the code
can spot other reasonable groupings or functionality which could
also be factored out.
There are still large swaths of random initializations; I though
about "btrfs_initialize_locks_and_stuff()" but decided against it.
:)
Anyway, it builds & passes default xfstests "-g auto" runs, so it
can't be all bad. Let me know what you think. Different function
names might be better, better symmetry with close_ctree() might be good,
but it's a start.
Thanks,
-Eric
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 01/12] btrfs: remove unused fs_info arg from btrfs_close_extra_devices()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 02/12] btrfs: consistently use fs_info in close_ctree() Eric Sandeen
` (10 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
The commit:
8dabb74 Btrfs: change core code of btrfs to support the
device replace operations
added the fs_info argument, but never used it -
just remove it again.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 4 ++--
fs/btrfs/volumes.c | 3 +--
fs/btrfs/volumes.h | 3 +--
3 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 08e65e9..f6d7afd 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2672,7 +2672,7 @@ int open_ctree(struct super_block *sb,
* keep the device that is marked to be the target device for the
* dev_replace procedure
*/
- btrfs_close_extra_devices(fs_info, fs_devices, 0);
+ btrfs_close_extra_devices(fs_devices, 0);
if (!fs_devices->latest_bdev) {
printk(KERN_CRIT "BTRFS: failed to read devices on %s\n",
@@ -2778,7 +2778,7 @@ retry_root_backup:
goto fail_block_groups;
}
- btrfs_close_extra_devices(fs_info, fs_devices, 1);
+ btrfs_close_extra_devices(fs_devices, 1);
ret = btrfs_sysfs_add_one(fs_info);
if (ret) {
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 6cb82f6..b5aa0c9 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -574,8 +574,7 @@ error:
return ERR_PTR(-ENOMEM);
}
-void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info,
- struct btrfs_fs_devices *fs_devices, int step)
+void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step)
{
struct btrfs_device *device, *next;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 2aaa00c..2026741 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -307,8 +307,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
struct btrfs_fs_devices **fs_devices_ret);
int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
-void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info,
- struct btrfs_fs_devices *fs_devices, int step);
+void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step);
int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
char *device_path,
struct btrfs_device **device);
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 02/12] btrfs: consistently use fs_info in close_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
2014-08-01 23:12 ` [PATCH 01/12] btrfs: remove unused fs_info arg from btrfs_close_extra_devices() Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 03/12] btrfs: handle errors from reading the quota tree root Eric Sandeen
` (9 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
close_ctree() has a local fs_info var for convienience;
use it consistently.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index f6d7afd..e6746be 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3651,7 +3651,7 @@ int close_ctree(struct btrfs_root *root)
if (!(fs_info->sb->s_flags & MS_RDONLY)) {
ret = btrfs_commit_super(root);
if (ret)
- btrfs_err(root->fs_info, "commit super ret %d", ret);
+ btrfs_err(fs_info, "commit super ret %d", ret);
}
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
@@ -3663,10 +3663,10 @@ int close_ctree(struct btrfs_root *root)
fs_info->closing = 2;
smp_mb();
- btrfs_free_qgroup_config(root->fs_info);
+ btrfs_free_qgroup_config(fs_info);
if (percpu_counter_sum(&fs_info->delalloc_bytes)) {
- btrfs_info(root->fs_info, "at unmount delalloc count %lld",
+ btrfs_info(fs_info, "at unmount delalloc count %lld",
percpu_counter_sum(&fs_info->delalloc_bytes));
}
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 03/12] btrfs: handle errors from reading the quota tree root
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
2014-08-01 23:12 ` [PATCH 01/12] btrfs: remove unused fs_info arg from btrfs_close_extra_devices() Eric Sandeen
2014-08-01 23:12 ` [PATCH 02/12] btrfs: consistently use fs_info in close_ctree() Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-04 18:35 ` Zach Brown
2014-08-01 23:12 ` [PATCH 04/12] btrfs: factor btrfs_scrub_init() out of open_ctree() Eric Sandeen
` (8 subsequent siblings)
11 siblings, 1 reply; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Reading the quota tree root may fail with ENOENT
if there is no quota, which is fine, but the code was
ignoring every other error as well, which is not fine.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index e6746be..28d35a8 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2733,7 +2733,12 @@ retry_root_backup:
location.objectid = BTRFS_QUOTA_TREE_OBJECTID;
quota_root = btrfs_read_tree_root(tree_root, &location);
- if (!IS_ERR(quota_root)) {
+ if (IS_ERR(quota_root)) {
+ ret = PTR_ERR(quota_root);
+ /* It's fine to not have quotas */
+ if (ret != -ENOENT)
+ goto recovery_tree_root;
+ } else {
set_bit(BTRFS_ROOT_TRACK_DIRTY, "a_root->state);
fs_info->quota_enabled = 1;
fs_info->pending_quota_state = 1;
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 04/12] btrfs: factor btrfs_scrub_init() out of open_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
` (2 preceding siblings ...)
2014-08-01 23:12 ` [PATCH 03/12] btrfs: handle errors from reading the quota tree root Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 05/12] btrfs: factor btrfs_balance_init() " Eric Sandeen
` (7 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 28d35a8..b95635f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2134,6 +2134,17 @@ void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info)
}
}
+static void btrfs_scrub_init(struct btrfs_fs_info *fs_info)
+{
+ mutex_init(&fs_info->scrub_lock);
+ atomic_set(&fs_info->scrubs_running, 0);
+ atomic_set(&fs_info->scrub_pause_req, 0);
+ atomic_set(&fs_info->scrubs_paused, 0);
+ atomic_set(&fs_info->scrub_cancel_req, 0);
+ init_waitqueue_head(&fs_info->scrub_pause_wait);
+ fs_info->scrub_workers_refcnt = 0;
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2281,14 +2292,8 @@ int open_ctree(struct super_block *sb,
}
btrfs_init_delayed_root(fs_info->delayed_root);
- mutex_init(&fs_info->scrub_lock);
- atomic_set(&fs_info->scrubs_running, 0);
- atomic_set(&fs_info->scrub_pause_req, 0);
- atomic_set(&fs_info->scrubs_paused, 0);
- atomic_set(&fs_info->scrub_cancel_req, 0);
+ btrfs_scrub_init(fs_info);
init_waitqueue_head(&fs_info->replace_wait);
- init_waitqueue_head(&fs_info->scrub_pause_wait);
- fs_info->scrub_workers_refcnt = 0;
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
fs_info->check_integrity_print_mask = 0;
#endif
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 05/12] btrfs: factor btrfs_balance_init() out of open_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
` (3 preceding siblings ...)
2014-08-01 23:12 ` [PATCH 04/12] btrfs: factor btrfs_scrub_init() out of open_ctree() Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 06/12] btrfs: factor btrfs_btree_inode_init() " Eric Sandeen
` (6 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 20 ++++++++++++--------
1 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index b95635f..8c7113b 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2145,6 +2145,17 @@ static void btrfs_scrub_init(struct btrfs_fs_info *fs_info)
fs_info->scrub_workers_refcnt = 0;
}
+static void btrfs_balance_init(struct btrfs_fs_info *fs_info)
+{
+ spin_lock_init(&fs_info->balance_lock);
+ mutex_init(&fs_info->balance_mutex);
+ atomic_set(&fs_info->balance_running, 0);
+ atomic_set(&fs_info->balance_pause_req, 0);
+ atomic_set(&fs_info->balance_cancel_req, 0);
+ fs_info->balance_ctl = NULL;
+ init_waitqueue_head(&fs_info->balance_wait_q);
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2297,14 +2308,7 @@ int open_ctree(struct super_block *sb,
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
fs_info->check_integrity_print_mask = 0;
#endif
-
- spin_lock_init(&fs_info->balance_lock);
- mutex_init(&fs_info->balance_mutex);
- atomic_set(&fs_info->balance_running, 0);
- atomic_set(&fs_info->balance_pause_req, 0);
- atomic_set(&fs_info->balance_cancel_req, 0);
- fs_info->balance_ctl = NULL;
- init_waitqueue_head(&fs_info->balance_wait_q);
+ btrfs_balance_init(fs_info);
btrfs_init_async_reclaim_work(&fs_info->async_reclaim_work);
sb->s_blocksize = 4096;
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 06/12] btrfs: factor btrfs_btree_inode_init() out of open_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
` (4 preceding siblings ...)
2014-08-01 23:12 ` [PATCH 05/12] btrfs: factor btrfs_balance_init() " Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 07/12] btrfs: factor btrfs_dev_replace_locks_init() " Eric Sandeen
` (5 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 56 ++++++++++++++++++++++++++++-----------------------
1 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8c7113b..6636386 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2156,6 +2156,36 @@ static void btrfs_balance_init(struct btrfs_fs_info *fs_info)
init_waitqueue_head(&fs_info->balance_wait_q);
}
+static void btrfs_btree_inode_init(struct btrfs_fs_info *fs_info,
+ struct btrfs_root *tree_root)
+{
+ fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
+ set_nlink(fs_info->btree_inode, 1);
+ /*
+ * we set the i_size on the btree inode to the max possible int.
+ * the real end of the address space is determined by all of
+ * the devices in the system
+ */
+ fs_info->btree_inode->i_size = OFFSET_MAX;
+ fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
+ fs_info->btree_inode->i_mapping->backing_dev_info = &fs_info->bdi;
+
+ RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node);
+ extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
+ fs_info->btree_inode->i_mapping);
+ BTRFS_I(fs_info->btree_inode)->io_tree.track_uptodate = 0;
+ extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree);
+
+ BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
+
+ BTRFS_I(fs_info->btree_inode)->root = tree_root;
+ memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
+ sizeof(struct btrfs_key));
+ set_bit(BTRFS_INODE_DUMMY,
+ &BTRFS_I(fs_info->btree_inode)->runtime_flags);
+ btrfs_insert_inode_hash(fs_info->btree_inode);
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2315,31 +2345,7 @@ int open_ctree(struct super_block *sb,
sb->s_blocksize_bits = blksize_bits(4096);
sb->s_bdi = &fs_info->bdi;
- fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
- set_nlink(fs_info->btree_inode, 1);
- /*
- * we set the i_size on the btree inode to the max possible int.
- * the real end of the address space is determined by all of
- * the devices in the system
- */
- fs_info->btree_inode->i_size = OFFSET_MAX;
- fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
- fs_info->btree_inode->i_mapping->backing_dev_info = &fs_info->bdi;
-
- RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node);
- extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
- fs_info->btree_inode->i_mapping);
- BTRFS_I(fs_info->btree_inode)->io_tree.track_uptodate = 0;
- extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree);
-
- BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
-
- BTRFS_I(fs_info->btree_inode)->root = tree_root;
- memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
- sizeof(struct btrfs_key));
- set_bit(BTRFS_INODE_DUMMY,
- &BTRFS_I(fs_info->btree_inode)->runtime_flags);
- btrfs_insert_inode_hash(fs_info->btree_inode);
+ btrfs_btree_inode_init(fs_info, tree_root);
spin_lock_init(&fs_info->block_group_cache_lock);
fs_info->block_group_cache_tree = RB_ROOT;
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 07/12] btrfs: factor btrfs_dev_replace_locks_init() out of open_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
` (5 preceding siblings ...)
2014-08-01 23:12 ` [PATCH 06/12] btrfs: factor btrfs_btree_inode_init() " Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 08/12] btrfs: factor btrfs_qgroup_init() " Eric Sandeen
` (4 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 6636386..a5fa84f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2186,6 +2186,15 @@ static void btrfs_btree_inode_init(struct btrfs_fs_info *fs_info,
btrfs_insert_inode_hash(fs_info->btree_inode);
}
+static void btrfs_dev_replace_locks_init(struct btrfs_fs_info *fs_info)
+{
+ fs_info->dev_replace.lock_owner = 0;
+ atomic_set(&fs_info->dev_replace.nesting_level, 0);
+ mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount);
+ mutex_init(&fs_info->dev_replace.lock_management_lock);
+ mutex_init(&fs_info->dev_replace.lock);
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2370,11 +2379,8 @@ int open_ctree(struct super_block *sb,
init_rwsem(&fs_info->cleanup_work_sem);
init_rwsem(&fs_info->subvol_sem);
sema_init(&fs_info->uuid_tree_rescan_sem, 1);
- fs_info->dev_replace.lock_owner = 0;
- atomic_set(&fs_info->dev_replace.nesting_level, 0);
- mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount);
- mutex_init(&fs_info->dev_replace.lock_management_lock);
- mutex_init(&fs_info->dev_replace.lock);
+
+ btrfs_dev_replace_locks_init(fs_info);
spin_lock_init(&fs_info->qgroup_lock);
mutex_init(&fs_info->qgroup_ioctl_lock);
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 08/12] btrfs: factor btrfs_qgroup_init() out of open_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
` (6 preceding siblings ...)
2014-08-01 23:12 ` [PATCH 07/12] btrfs: factor btrfs_dev_replace_locks_init() " Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 09/12] btrfs: factor btrfs_setup_super() " Eric Sandeen
` (3 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index a5fa84f..47fcacf 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2195,6 +2195,20 @@ static void btrfs_dev_replace_locks_init(struct btrfs_fs_info *fs_info)
mutex_init(&fs_info->dev_replace.lock);
}
+static void btrfs_qgroup_init(struct btrfs_fs_info *fs_info)
+{
+ spin_lock_init(&fs_info->qgroup_lock);
+ mutex_init(&fs_info->qgroup_ioctl_lock);
+ fs_info->qgroup_tree = RB_ROOT;
+ fs_info->qgroup_op_tree = RB_ROOT;
+ INIT_LIST_HEAD(&fs_info->dirty_qgroups);
+ fs_info->qgroup_seq = 1;
+ fs_info->quota_enabled = 0;
+ fs_info->pending_quota_state = 0;
+ fs_info->qgroup_ulist = NULL;
+ mutex_init(&fs_info->qgroup_rescan_lock);
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2381,17 +2395,7 @@ int open_ctree(struct super_block *sb,
sema_init(&fs_info->uuid_tree_rescan_sem, 1);
btrfs_dev_replace_locks_init(fs_info);
-
- spin_lock_init(&fs_info->qgroup_lock);
- mutex_init(&fs_info->qgroup_ioctl_lock);
- fs_info->qgroup_tree = RB_ROOT;
- fs_info->qgroup_op_tree = RB_ROOT;
- INIT_LIST_HEAD(&fs_info->dirty_qgroups);
- fs_info->qgroup_seq = 1;
- fs_info->quota_enabled = 0;
- fs_info->pending_quota_state = 0;
- fs_info->qgroup_ulist = NULL;
- mutex_init(&fs_info->qgroup_rescan_lock);
+ btrfs_qgroup_init(fs_info);
btrfs_init_free_cluster(&fs_info->meta_alloc_cluster);
btrfs_init_free_cluster(&fs_info->data_alloc_cluster);
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 09/12] btrfs: factor btrfs_setup_super() out of open_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
` (7 preceding siblings ...)
2014-08-01 23:12 ` [PATCH 08/12] btrfs: factor btrfs_qgroup_init() " Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 10/12] btrfs: factor btrfs_alloc_workqueues() " Eric Sandeen
` (2 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Move all the superblock flag & geometry testing & fiddling
into its own function.
This does coalesce some far-flung tests, but it ... looks
ok to me.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 207 ++++++++++++++++++++++++++++------------------------
1 files changed, 112 insertions(+), 95 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 47fcacf..31e9791 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2209,6 +2209,104 @@ static void btrfs_qgroup_init(struct btrfs_fs_info *fs_info)
mutex_init(&fs_info->qgroup_rescan_lock);
}
+/*
+ * Test geometry and feature flags at mount time
+ */
+static int btrfs_setup_super(struct super_block *sb,
+ struct btrfs_fs_info *fs_info)
+{
+ struct btrfs_super_block *disk_super = fs_info->super_copy;
+ u32 nodesize = btrfs_super_nodesize(disk_super);
+ u32 leafsize = btrfs_super_leafsize(disk_super);
+ u32 sectorsize = btrfs_super_sectorsize(disk_super);
+ u64 features;
+
+
+ /* First sanity check magic & sizes */
+ if (btrfs_super_magic(disk_super) != BTRFS_MAGIC) {
+ printk(KERN_INFO "BTRFS: valid FS not found on %s\n", sb->s_id);
+ return -EINVAL;
+ }
+
+ if (leafsize != nodesize) {
+ printk(KERN_ERR "BTRFS: couldn't mount because metadata "
+ "blocksizes don't match. node %d leaf %d\n",
+ nodesize, leafsize);
+ return -EINVAL;
+ }
+
+ if (leafsize > BTRFS_MAX_METADATA_BLOCKSIZE) {
+ printk(KERN_ERR "BTRFS: couldn't mount because metadata "
+ "blocksize (%d) was too large\n", leafsize);
+ return -EINVAL;
+ }
+
+ if (sectorsize != PAGE_SIZE) {
+ printk(KERN_WARNING "BTRFS: Incompatible sector size(%lu) "
+ "found on %s\n", (unsigned long)sectorsize, sb->s_id);
+ return -EINVAL;
+ }
+
+ /* check FS state, whether FS is broken. */
+ if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_ERROR)
+ set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state);
+
+ features = btrfs_super_incompat_flags(disk_super);
+ if (features & ~BTRFS_FEATURE_INCOMPAT_SUPP) {
+ printk(KERN_ERR "BTRFS: couldn't mount because of "
+ "unsupported optional features (%Lx).\n",
+ features & ~BTRFS_FEATURE_INCOMPAT_SUPP);
+ return -EINVAL;
+ }
+
+ features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF;
+ /* Original LZO commit didn't set incompat flag when mounted :( */
+ if (fs_info->compress_type == BTRFS_COMPRESS_LZO)
+ features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
+
+ if (features & BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
+ printk(KERN_ERR "BTRFS: has skinny extents\n");
+
+ /*
+ * flag our filesystem as having big metadata blocks if
+ * they are bigger than the page size
+ */
+ if (leafsize > PAGE_CACHE_SIZE) {
+ if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA))
+ printk(KERN_INFO "BTRFS: flagging fs with big metadata feature\n");
+ features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA;
+ }
+
+ /*
+ * mixed block groups end up with duplicate but slightly offset
+ * extent buffers for the same range. It leads to corruptions
+ */
+ if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) &&
+ (sectorsize != leafsize)) {
+ printk(KERN_WARNING "BTRFS: unequal leaf/node/sector sizes "
+ "are not allowed for mixed block groups on %s\n",
+ sb->s_id);
+ return -EINVAL;
+ }
+
+ /*
+ * Needn't use the lock because there is no other task which will
+ * update the flag.
+ */
+ btrfs_set_super_incompat_flags(disk_super, features);
+
+ features = btrfs_super_compat_ro_flags(disk_super) &
+ ~BTRFS_FEATURE_COMPAT_RO_SUPP;
+ if (!(sb->s_flags & MS_RDONLY) && features) {
+ printk(KERN_ERR "BTRFS: couldn't mount RDWR because of "
+ "unsupported option features (%Lx).\n",
+ features);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2219,7 +2317,6 @@ int open_ctree(struct super_block *sb,
u32 blocksize;
u32 stripesize;
u64 generation;
- u64 features;
struct btrfs_key location;
struct buffer_head *bh;
struct btrfs_super_block *disk_super;
@@ -2458,10 +2555,6 @@ int open_ctree(struct super_block *sb,
if (!btrfs_super_root(disk_super))
goto fail_alloc;
- /* check FS state, whether FS is broken. */
- if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_ERROR)
- set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state);
-
/*
* run through our array of backup supers and setup
* our ring pointer to the oldest one
@@ -2469,6 +2562,12 @@ int open_ctree(struct super_block *sb,
generation = btrfs_super_generation(disk_super);
find_oldest_super_backup(fs_info, generation);
+ ret = btrfs_setup_super(sb, fs_info);
+ if (ret) {
+ err = ret;
+ goto fail_alloc;
+ }
+
/*
* In the long term, we'll store the compression type in the super
* block, and it'll be used for per file compression control.
@@ -2481,86 +2580,6 @@ int open_ctree(struct super_block *sb,
goto fail_alloc;
}
- features = btrfs_super_incompat_flags(disk_super) &
- ~BTRFS_FEATURE_INCOMPAT_SUPP;
- if (features) {
- printk(KERN_ERR "BTRFS: couldn't mount because of "
- "unsupported optional features (%Lx).\n",
- features);
- err = -EINVAL;
- goto fail_alloc;
- }
-
- if (btrfs_super_leafsize(disk_super) !=
- btrfs_super_nodesize(disk_super)) {
- printk(KERN_ERR "BTRFS: couldn't mount because metadata "
- "blocksizes don't match. node %d leaf %d\n",
- btrfs_super_nodesize(disk_super),
- btrfs_super_leafsize(disk_super));
- err = -EINVAL;
- goto fail_alloc;
- }
- if (btrfs_super_leafsize(disk_super) > BTRFS_MAX_METADATA_BLOCKSIZE) {
- printk(KERN_ERR "BTRFS: couldn't mount because metadata "
- "blocksize (%d) was too large\n",
- btrfs_super_leafsize(disk_super));
- err = -EINVAL;
- goto fail_alloc;
- }
-
- features = btrfs_super_incompat_flags(disk_super);
- features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF;
- if (tree_root->fs_info->compress_type == BTRFS_COMPRESS_LZO)
- features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
-
- if (features & BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
- printk(KERN_ERR "BTRFS: has skinny extents\n");
-
- /*
- * flag our filesystem as having big metadata blocks if
- * they are bigger than the page size
- */
- if (btrfs_super_leafsize(disk_super) > PAGE_CACHE_SIZE) {
- if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA))
- printk(KERN_INFO "BTRFS: flagging fs with big metadata feature\n");
- features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA;
- }
-
- nodesize = btrfs_super_nodesize(disk_super);
- leafsize = btrfs_super_leafsize(disk_super);
- sectorsize = btrfs_super_sectorsize(disk_super);
- stripesize = btrfs_super_stripesize(disk_super);
- fs_info->dirty_metadata_batch = leafsize * (1 + ilog2(nr_cpu_ids));
- fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids));
-
- /*
- * mixed block groups end up with duplicate but slightly offset
- * extent buffers for the same range. It leads to corruptions
- */
- if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) &&
- (sectorsize != leafsize)) {
- printk(KERN_WARNING "BTRFS: unequal leaf/node/sector sizes "
- "are not allowed for mixed block groups on %s\n",
- sb->s_id);
- goto fail_alloc;
- }
-
- /*
- * Needn't use the lock because there is no other task which will
- * update the flag.
- */
- btrfs_set_super_incompat_flags(disk_super, features);
-
- features = btrfs_super_compat_ro_flags(disk_super) &
- ~BTRFS_FEATURE_COMPAT_RO_SUPP;
- if (!(sb->s_flags & MS_RDONLY) && features) {
- printk(KERN_ERR "BTRFS: couldn't mount RDWR because of "
- "unsupported option features (%Lx).\n",
- features);
- err = -EINVAL;
- goto fail_alloc;
- }
-
max_active = fs_info->thread_pool_size;
fs_info->workers =
@@ -2636,6 +2655,14 @@ int open_ctree(struct super_block *sb,
fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages,
4 * 1024 * 1024 / PAGE_CACHE_SIZE);
+ nodesize = btrfs_super_nodesize(disk_super);
+ leafsize = btrfs_super_leafsize(disk_super);
+ sectorsize = btrfs_super_sectorsize(disk_super);
+ stripesize = btrfs_super_stripesize(disk_super);
+
+ fs_info->dirty_metadata_batch = leafsize * (1 + ilog2(nr_cpu_ids));
+ fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids));
+
tree_root->nodesize = nodesize;
tree_root->leafsize = leafsize;
tree_root->sectorsize = sectorsize;
@@ -2644,16 +2671,6 @@ int open_ctree(struct super_block *sb,
sb->s_blocksize = sectorsize;
sb->s_blocksize_bits = blksize_bits(sectorsize);
- if (btrfs_super_magic(disk_super) != BTRFS_MAGIC) {
- printk(KERN_INFO "BTRFS: valid FS not found on %s\n", sb->s_id);
- goto fail_sb_buffer;
- }
-
- if (sectorsize != PAGE_SIZE) {
- printk(KERN_WARNING "BTRFS: Incompatible sector size(%lu) "
- "found on %s\n", (unsigned long)sectorsize, sb->s_id);
- goto fail_sb_buffer;
- }
mutex_lock(&fs_info->chunk_mutex);
ret = btrfs_read_sys_array(tree_root);
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 10/12] btrfs: factor btrfs_alloc_workqueues() out of open_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
` (8 preceding siblings ...)
2014-08-01 23:12 ` [PATCH 09/12] btrfs: factor btrfs_setup_super() " Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 11/12] btrfs: factor btrfs_read_roots() " Eric Sandeen
2014-08-01 23:12 ` [PATCH 12/12] btrfs: factor btrfs_replay_log() " Eric Sandeen
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 144 ++++++++++++++++++++++++++++------------------------
1 files changed, 77 insertions(+), 67 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 31e9791..0465d43 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2307,6 +2307,80 @@ static int btrfs_setup_super(struct super_block *sb,
return 0;
}
+static int btrfs_alloc_workqueues(struct btrfs_fs_info *fs_info,
+ struct btrfs_fs_devices *fs_devices)
+{
+ int max_active = fs_info->thread_pool_size;
+ int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND;
+
+ fs_info->workers =
+ btrfs_alloc_workqueue("worker", flags | WQ_HIGHPRI,
+ max_active, 16);
+ fs_info->delalloc_workers =
+ btrfs_alloc_workqueue("delalloc", flags, max_active, 2);
+
+ fs_info->flush_workers =
+ btrfs_alloc_workqueue("flush_delalloc", flags, max_active, 0);
+
+ fs_info->caching_workers =
+ btrfs_alloc_workqueue("cache", flags, max_active, 0);
+
+ /*
+ * a higher idle thresh on the submit workers makes it much more
+ * likely that bios will be send down in a sane order to the
+ * devices
+ */
+ fs_info->submit_workers =
+ btrfs_alloc_workqueue("submit", flags,
+ min_t(u64, fs_devices->num_devices,
+ max_active), 64);
+ fs_info->fixup_workers =
+ btrfs_alloc_workqueue("fixup", flags, 1, 0);
+ /*
+ * endios are largely parallel and should have a very
+ * low idle thresh
+ */
+ fs_info->endio_workers =
+ btrfs_alloc_workqueue("endio", flags, max_active, 4);
+ fs_info->endio_meta_workers =
+ btrfs_alloc_workqueue("endio-meta", flags, max_active, 4);
+ fs_info->endio_meta_write_workers =
+ btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2);
+ fs_info->endio_raid56_workers =
+ btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4);
+ fs_info->rmw_workers =
+ btrfs_alloc_workqueue("rmw", flags, max_active, 2);
+ fs_info->endio_write_workers =
+ btrfs_alloc_workqueue("endio-write", flags, max_active, 2);
+ fs_info->endio_freespace_worker =
+ btrfs_alloc_workqueue("freespace-write", flags, max_active, 0);
+ fs_info->delayed_workers =
+ btrfs_alloc_workqueue("delayed-meta", flags, max_active, 0);
+ fs_info->readahead_workers =
+ btrfs_alloc_workqueue("readahead", flags, max_active, 2);
+ fs_info->qgroup_rescan_workers =
+ btrfs_alloc_workqueue("qgroup-rescan", flags, 1, 0);
+ fs_info->extent_workers =
+ btrfs_alloc_workqueue("extent-refs", flags,
+ min_t(u64, fs_devices->num_devices,
+ max_active), 8);
+
+ if (!(fs_info->workers && fs_info->delalloc_workers &&
+ fs_info->submit_workers && fs_info->flush_workers &&
+ fs_info->endio_workers && fs_info->endio_meta_workers &&
+ fs_info->endio_meta_write_workers &&
+ fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
+ fs_info->endio_freespace_worker && fs_info->rmw_workers &&
+ fs_info->caching_workers && fs_info->readahead_workers &&
+ fs_info->fixup_workers && fs_info->delayed_workers &&
+ fs_info->fixup_workers && fs_info->extent_workers &&
+ fs_info->qgroup_rescan_workers)) {
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2334,7 +2408,6 @@ int open_ctree(struct super_block *sb,
int num_backups_tried = 0;
int backup_index = 0;
int max_active;
- int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND;
bool create_uuid_tree;
bool check_uuid_tree;
@@ -2582,72 +2655,9 @@ int open_ctree(struct super_block *sb,
max_active = fs_info->thread_pool_size;
- fs_info->workers =
- btrfs_alloc_workqueue("worker", flags | WQ_HIGHPRI,
- max_active, 16);
-
- fs_info->delalloc_workers =
- btrfs_alloc_workqueue("delalloc", flags, max_active, 2);
-
- fs_info->flush_workers =
- btrfs_alloc_workqueue("flush_delalloc", flags, max_active, 0);
-
- fs_info->caching_workers =
- btrfs_alloc_workqueue("cache", flags, max_active, 0);
-
- /*
- * a higher idle thresh on the submit workers makes it much more
- * likely that bios will be send down in a sane order to the
- * devices
- */
- fs_info->submit_workers =
- btrfs_alloc_workqueue("submit", flags,
- min_t(u64, fs_devices->num_devices,
- max_active), 64);
-
- fs_info->fixup_workers =
- btrfs_alloc_workqueue("fixup", flags, 1, 0);
-
- /*
- * endios are largely parallel and should have a very
- * low idle thresh
- */
- fs_info->endio_workers =
- btrfs_alloc_workqueue("endio", flags, max_active, 4);
- fs_info->endio_meta_workers =
- btrfs_alloc_workqueue("endio-meta", flags, max_active, 4);
- fs_info->endio_meta_write_workers =
- btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2);
- fs_info->endio_raid56_workers =
- btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4);
- fs_info->rmw_workers =
- btrfs_alloc_workqueue("rmw", flags, max_active, 2);
- fs_info->endio_write_workers =
- btrfs_alloc_workqueue("endio-write", flags, max_active, 2);
- fs_info->endio_freespace_worker =
- btrfs_alloc_workqueue("freespace-write", flags, max_active, 0);
- fs_info->delayed_workers =
- btrfs_alloc_workqueue("delayed-meta", flags, max_active, 0);
- fs_info->readahead_workers =
- btrfs_alloc_workqueue("readahead", flags, max_active, 2);
- fs_info->qgroup_rescan_workers =
- btrfs_alloc_workqueue("qgroup-rescan", flags, 1, 0);
- fs_info->extent_workers =
- btrfs_alloc_workqueue("extent-refs", flags,
- min_t(u64, fs_devices->num_devices,
- max_active), 8);
-
- if (!(fs_info->workers && fs_info->delalloc_workers &&
- fs_info->submit_workers && fs_info->flush_workers &&
- fs_info->endio_workers && fs_info->endio_meta_workers &&
- fs_info->endio_meta_write_workers &&
- fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
- fs_info->endio_freespace_worker && fs_info->rmw_workers &&
- fs_info->caching_workers && fs_info->readahead_workers &&
- fs_info->fixup_workers && fs_info->delayed_workers &&
- fs_info->fixup_workers && fs_info->extent_workers &&
- fs_info->qgroup_rescan_workers)) {
- err = -ENOMEM;
+ ret = btrfs_alloc_workqueues(fs_info, fs_devices);
+ if (ret) {
+ err = ret;
goto fail_sb_buffer;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 11/12] btrfs: factor btrfs_read_roots() out of open_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
` (9 preceding siblings ...)
2014-08-01 23:12 ` [PATCH 10/12] btrfs: factor btrfs_alloc_workqueues() " Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 12/12] btrfs: factor btrfs_replay_log() " Eric Sandeen
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Also, remove the two local variables create_uuid_tree
and check_uuid_tree; we can use the existence of
the uuid root and/or the RESCAN_UUID_TREE flag to
determine what action to take.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 141 ++++++++++++++++++++++++++--------------------------
1 files changed, 71 insertions(+), 70 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 0465d43..a50beca 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2381,6 +2381,70 @@ static int btrfs_alloc_workqueues(struct btrfs_fs_info *fs_info,
return 0;
}
+static int btrfs_read_roots(struct btrfs_fs_info *fs_info,
+ struct btrfs_root *tree_root)
+{
+ struct btrfs_root *extent_root;
+ struct btrfs_root *dev_root;
+ struct btrfs_root *csum_root;
+ struct btrfs_root *quota_root;
+ struct btrfs_root *uuid_root;
+ struct btrfs_key location;
+ int ret;
+
+ location.objectid = BTRFS_EXTENT_TREE_OBJECTID;
+ location.type = BTRFS_ROOT_ITEM_KEY;
+ location.offset = 0;
+
+ extent_root = btrfs_read_tree_root(tree_root, &location);
+ if (IS_ERR(extent_root))
+ return PTR_ERR(extent_root);
+ set_bit(BTRFS_ROOT_TRACK_DIRTY, &extent_root->state);
+ fs_info->extent_root = extent_root;
+
+ location.objectid = BTRFS_DEV_TREE_OBJECTID;
+ dev_root = btrfs_read_tree_root(tree_root, &location);
+ if (IS_ERR(dev_root))
+ return PTR_ERR(dev_root);
+ set_bit(BTRFS_ROOT_TRACK_DIRTY, &dev_root->state);
+ fs_info->dev_root = dev_root;
+ btrfs_init_devices_late(fs_info);
+
+ location.objectid = BTRFS_CSUM_TREE_OBJECTID;
+ csum_root = btrfs_read_tree_root(tree_root, &location);
+ if (IS_ERR(csum_root))
+ return PTR_ERR(csum_root);
+ set_bit(BTRFS_ROOT_TRACK_DIRTY, &csum_root->state);
+ fs_info->csum_root = csum_root;
+
+ location.objectid = BTRFS_QUOTA_TREE_OBJECTID;
+ quota_root = btrfs_read_tree_root(tree_root, &location);
+ if (IS_ERR(quota_root)) {
+ ret = PTR_ERR(quota_root);
+ /* It's fine to not have quotas */
+ if (ret != -ENOENT)
+ return ret;
+ } else {
+ set_bit(BTRFS_ROOT_TRACK_DIRTY, "a_root->state);
+ fs_info->quota_enabled = 1;
+ fs_info->pending_quota_state = 1;
+ fs_info->quota_root = quota_root;
+ }
+
+ location.objectid = BTRFS_UUID_TREE_OBJECTID;
+ uuid_root = btrfs_read_tree_root(tree_root, &location);
+ if (IS_ERR(uuid_root)) {
+ ret = PTR_ERR(uuid_root);
+ if (ret != -ENOENT)
+ return ret;
+ } else {
+ set_bit(BTRFS_ROOT_TRACK_DIRTY, &uuid_root->state);
+ fs_info->uuid_root = uuid_root;
+ }
+
+ return 0;
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2396,20 +2460,13 @@ int open_ctree(struct super_block *sb,
struct btrfs_super_block *disk_super;
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
struct btrfs_root *tree_root;
- struct btrfs_root *extent_root;
- struct btrfs_root *csum_root;
struct btrfs_root *chunk_root;
- struct btrfs_root *dev_root;
- struct btrfs_root *quota_root;
- struct btrfs_root *uuid_root;
struct btrfs_root *log_tree_root;
int ret;
int err = -EINVAL;
int num_backups_tried = 0;
int backup_index = 0;
int max_active;
- bool create_uuid_tree;
- bool check_uuid_tree;
tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info);
chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info);
@@ -2752,66 +2809,9 @@ retry_root_backup:
tree_root->commit_root = btrfs_root_node(tree_root);
btrfs_set_root_refs(&tree_root->root_item, 1);
- location.objectid = BTRFS_EXTENT_TREE_OBJECTID;
- location.type = BTRFS_ROOT_ITEM_KEY;
- location.offset = 0;
-
- extent_root = btrfs_read_tree_root(tree_root, &location);
- if (IS_ERR(extent_root)) {
- ret = PTR_ERR(extent_root);
- goto recovery_tree_root;
- }
- set_bit(BTRFS_ROOT_TRACK_DIRTY, &extent_root->state);
- fs_info->extent_root = extent_root;
-
- location.objectid = BTRFS_DEV_TREE_OBJECTID;
- dev_root = btrfs_read_tree_root(tree_root, &location);
- if (IS_ERR(dev_root)) {
- ret = PTR_ERR(dev_root);
- goto recovery_tree_root;
- }
- set_bit(BTRFS_ROOT_TRACK_DIRTY, &dev_root->state);
- fs_info->dev_root = dev_root;
- btrfs_init_devices_late(fs_info);
-
- location.objectid = BTRFS_CSUM_TREE_OBJECTID;
- csum_root = btrfs_read_tree_root(tree_root, &location);
- if (IS_ERR(csum_root)) {
- ret = PTR_ERR(csum_root);
+ ret = btrfs_read_roots(fs_info, tree_root);
+ if (ret)
goto recovery_tree_root;
- }
- set_bit(BTRFS_ROOT_TRACK_DIRTY, &csum_root->state);
- fs_info->csum_root = csum_root;
-
- location.objectid = BTRFS_QUOTA_TREE_OBJECTID;
- quota_root = btrfs_read_tree_root(tree_root, &location);
- if (IS_ERR(quota_root)) {
- ret = PTR_ERR(quota_root);
- /* It's fine to not have quotas */
- if (ret != -ENOENT)
- goto recovery_tree_root;
- } else {
- set_bit(BTRFS_ROOT_TRACK_DIRTY, "a_root->state);
- fs_info->quota_enabled = 1;
- fs_info->pending_quota_state = 1;
- fs_info->quota_root = quota_root;
- }
-
- location.objectid = BTRFS_UUID_TREE_OBJECTID;
- uuid_root = btrfs_read_tree_root(tree_root, &location);
- if (IS_ERR(uuid_root)) {
- ret = PTR_ERR(uuid_root);
- if (ret != -ENOENT)
- goto recovery_tree_root;
- create_uuid_tree = true;
- check_uuid_tree = false;
- } else {
- set_bit(BTRFS_ROOT_TRACK_DIRTY, &uuid_root->state);
- fs_info->uuid_root = uuid_root;
- create_uuid_tree = false;
- check_uuid_tree =
- generation != btrfs_super_uuid_tree_generation(disk_super);
- }
fs_info->generation = generation;
fs_info->last_trans_committed = generation;
@@ -2849,7 +2849,7 @@ retry_root_backup:
goto fail_sysfs;
}
- ret = btrfs_read_block_groups(extent_root);
+ ret = btrfs_read_block_groups(fs_info->extent_root);
if (ret) {
printk(KERN_ERR "BTRFS: Failed to read block groups: %d\n", ret);
goto fail_sysfs;
@@ -3011,7 +3011,7 @@ retry_root_backup:
btrfs_qgroup_rescan_resume(fs_info);
- if (create_uuid_tree) {
+ if (!fs_info->uuid_root) {
pr_info("BTRFS: creating UUID tree\n");
ret = btrfs_create_uuid_tree(fs_info);
if (ret) {
@@ -3020,8 +3020,9 @@ retry_root_backup:
close_ctree(tree_root);
return ret;
}
- } else if (check_uuid_tree ||
- btrfs_test_opt(tree_root, RESCAN_UUID_TREE)) {
+ } else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) ||
+ fs_info->generation !=
+ btrfs_super_uuid_tree_generation(disk_super)) {
pr_info("BTRFS: checking UUID tree\n");
ret = btrfs_check_uuid_tree(fs_info);
if (ret) {
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 12/12] btrfs: factor btrfs_replay_log() out of open_ctree()
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
` (10 preceding siblings ...)
2014-08-01 23:12 ` [PATCH 11/12] btrfs: factor btrfs_read_roots() " Eric Sandeen
@ 2014-08-01 23:12 ` Eric Sandeen
11 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-01 23:12 UTC (permalink / raw)
To: linux-btrfs
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/btrfs/disk-io.c | 100 +++++++++++++++++++++++++++++-----------------------
1 files changed, 56 insertions(+), 44 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index a50beca..ffb2f21 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2445,6 +2445,60 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info,
return 0;
}
+static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
+ struct btrfs_fs_devices *fs_devices)
+{
+ int ret;
+ u32 blocksize;
+ struct btrfs_root *tree_root = fs_info->tree_root;
+ struct btrfs_root *log_tree_root;
+ struct btrfs_super_block *disk_super = fs_info->super_copy;
+ u64 bytenr = btrfs_super_log_root(disk_super);
+
+ if (fs_devices->rw_devices == 0) {
+ printk(KERN_WARNING "BTRFS: log replay required "
+ "on RO media\n");
+ return -EIO;
+ }
+ blocksize = btrfs_level_size(tree_root,
+ btrfs_super_log_root_level(disk_super));
+
+ log_tree_root = btrfs_alloc_root(fs_info);
+ if (!log_tree_root)
+ return -ENOMEM;
+
+ __setup_root(tree_root->nodesize, tree_root->leafsize,
+ tree_root->sectorsize, tree_root->stripesize,
+ log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
+
+ log_tree_root->node = read_tree_block(tree_root, bytenr,
+ blocksize,
+ fs_info->generation + 1);
+ if (!log_tree_root->node ||
+ !extent_buffer_uptodate(log_tree_root->node)) {
+ printk(KERN_ERR "BTRFS: failed to read log tree\n");
+ free_extent_buffer(log_tree_root->node);
+ kfree(log_tree_root);
+ return -EIO;
+ }
+ /* returns with log_tree_root freed on success */
+ ret = btrfs_recover_log_trees(log_tree_root);
+ if (ret) {
+ btrfs_error(tree_root->fs_info, ret,
+ "Failed to recover log tree");
+ free_extent_buffer(log_tree_root->node);
+ kfree(log_tree_root);
+ return ret;
+ }
+
+ if (fs_info->sb->s_flags & MS_RDONLY) {
+ ret = btrfs_commit_super(tree_root);
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options)
@@ -2461,7 +2515,6 @@ int open_ctree(struct super_block *sb,
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
struct btrfs_root *tree_root;
struct btrfs_root *chunk_root;
- struct btrfs_root *log_tree_root;
int ret;
int err = -EINVAL;
int num_backups_tried = 0;
@@ -2905,52 +2958,11 @@ retry_root_backup:
/* do not make disk changes in broken FS */
if (btrfs_super_log_root(disk_super) != 0) {
- u64 bytenr = btrfs_super_log_root(disk_super);
-
- if (fs_devices->rw_devices == 0) {
- printk(KERN_WARNING "BTRFS: log replay required "
- "on RO media\n");
- err = -EIO;
- goto fail_qgroup;
- }
- blocksize =
- btrfs_level_size(tree_root,
- btrfs_super_log_root_level(disk_super));
-
- log_tree_root = btrfs_alloc_root(fs_info);
- if (!log_tree_root) {
- err = -ENOMEM;
- goto fail_qgroup;
- }
-
- __setup_root(nodesize, leafsize, sectorsize, stripesize,
- log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
-
- log_tree_root->node = read_tree_block(tree_root, bytenr,
- blocksize,
- generation + 1);
- if (!log_tree_root->node ||
- !extent_buffer_uptodate(log_tree_root->node)) {
- printk(KERN_ERR "BTRFS: failed to read log tree\n");
- free_extent_buffer(log_tree_root->node);
- kfree(log_tree_root);
- goto fail_qgroup;
- }
- /* returns with log_tree_root freed on success */
- ret = btrfs_recover_log_trees(log_tree_root);
+ ret = btrfs_replay_log(fs_info, fs_devices);
if (ret) {
- btrfs_error(tree_root->fs_info, ret,
- "Failed to recover log tree");
- free_extent_buffer(log_tree_root->node);
- kfree(log_tree_root);
+ err = ret;
goto fail_qgroup;
}
-
- if (sb->s_flags & MS_RDONLY) {
- ret = btrfs_commit_super(tree_root);
- if (ret)
- goto fail_qgroup;
- }
}
ret = btrfs_find_orphan_roots(tree_root);
--
1.7.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH 03/12] btrfs: handle errors from reading the quota tree root
2014-08-01 23:12 ` [PATCH 03/12] btrfs: handle errors from reading the quota tree root Eric Sandeen
@ 2014-08-04 18:35 ` Zach Brown
2014-08-04 18:42 ` Eric Sandeen
0 siblings, 1 reply; 17+ messages in thread
From: Zach Brown @ 2014-08-04 18:35 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-btrfs
On Fri, Aug 01, 2014 at 06:12:37PM -0500, Eric Sandeen wrote:
> Reading the quota tree root may fail with ENOENT
> if there is no quota, which is fine, but the code was
> ignoring every other error as well, which is not fine.
Kinda makes you want to write a test that would have caught this.
Kinda.
Also, if you're still keen to iterate on this series, it looks like this
pattern is copied and pasted a few times in open_ctree(). With
temporary root pointers for each block, for some reason. A little
helper function could take a bite out of open_ctree().
- z
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 03/12] btrfs: handle errors from reading the quota tree root
2014-08-04 18:35 ` Zach Brown
@ 2014-08-04 18:42 ` Eric Sandeen
2014-08-04 18:51 ` Zach Brown
0 siblings, 1 reply; 17+ messages in thread
From: Eric Sandeen @ 2014-08-04 18:42 UTC (permalink / raw)
To: Zach Brown; +Cc: linux-btrfs
On 8/4/14, 1:35 PM, Zach Brown wrote:
> On Fri, Aug 01, 2014 at 06:12:37PM -0500, Eric Sandeen wrote:
>> Reading the quota tree root may fail with ENOENT
>> if there is no quota, which is fine, but the code was
>> ignoring every other error as well, which is not fine.
>
> Kinda makes you want to write a test that would have caught this.
>
> Kinda.
/me looks at ground, shuffles feet ...
> Also, if you're still keen to iterate on this series, it looks like this
> pattern is copied and pasted a few times in open_ctree(). With
> temporary root pointers for each block, for some reason. A little
> helper function could take a bite out of open_ctree().
Hm, the uuid tree is roughly similar, but not exactly. I think those
are the only 2 "optional" roots (uuid because it'll get regenerated).
I'm guessing the temporary root pointer is so we don't ever assign a
PTR_ERR to the root in fs_info?
-Eric
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 03/12] btrfs: handle errors from reading the quota tree root
2014-08-04 18:42 ` Eric Sandeen
@ 2014-08-04 18:51 ` Zach Brown
2014-08-04 18:53 ` Eric Sandeen
0 siblings, 1 reply; 17+ messages in thread
From: Zach Brown @ 2014-08-04 18:51 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-btrfs
On Mon, Aug 04, 2014 at 01:42:23PM -0500, Eric Sandeen wrote:
> On 8/4/14, 1:35 PM, Zach Brown wrote:
> > On Fri, Aug 01, 2014 at 06:12:37PM -0500, Eric Sandeen wrote:
> >> Reading the quota tree root may fail with ENOENT
> >> if there is no quota, which is fine, but the code was
> >> ignoring every other error as well, which is not fine.
> >
> > Kinda makes you want to write a test that would have caught this.
> >
> > Kinda.
>
> /me looks at ground, shuffles feet ...
>
> > Also, if you're still keen to iterate on this series, it looks like this
> > pattern is copied and pasted a few times in open_ctree(). With
> > temporary root pointers for each block, for some reason. A little
> > helper function could take a bite out of open_ctree().
>
> Hm, the uuid tree is roughly similar, but not exactly. I think those
> are the only 2 "optional" roots (uuid because it'll get regenerated).
>
> I'm guessing the temporary root pointer is so we don't ever assign a
> PTR_ERR to the root in fs_info?
It took me a while to see what you meant.
Yeah, using a temporary root makes sense. Using a different one for
each block makes less sense.
a = f(A);
if (a)
goto out;
info->a = a;
b = f(B);
if (b)
goto out;
info->b = b;
vs.
r = f(A);
if (r)
goto out;
info->a = r;
r = f(B);
if (r)
goto out;
info->b = r;
- z
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 03/12] btrfs: handle errors from reading the quota tree root
2014-08-04 18:51 ` Zach Brown
@ 2014-08-04 18:53 ` Eric Sandeen
0 siblings, 0 replies; 17+ messages in thread
From: Eric Sandeen @ 2014-08-04 18:53 UTC (permalink / raw)
To: Zach Brown; +Cc: linux-btrfs
On 8/4/14, 1:51 PM, Zach Brown wrote:
> On Mon, Aug 04, 2014 at 01:42:23PM -0500, Eric Sandeen wrote:
>> On 8/4/14, 1:35 PM, Zach Brown wrote:
>>> On Fri, Aug 01, 2014 at 06:12:37PM -0500, Eric Sandeen wrote:
>>>> Reading the quota tree root may fail with ENOENT
>>>> if there is no quota, which is fine, but the code was
>>>> ignoring every other error as well, which is not fine.
>>>
>>> Kinda makes you want to write a test that would have caught this.
>>>
>>> Kinda.
>>
>> /me looks at ground, shuffles feet ...
>>
>>> Also, if you're still keen to iterate on this series, it looks like this
>>> pattern is copied and pasted a few times in open_ctree(). With
>>> temporary root pointers for each block, for some reason. A little
>>> helper function could take a bite out of open_ctree().
>>
>> Hm, the uuid tree is roughly similar, but not exactly. I think those
>> are the only 2 "optional" roots (uuid because it'll get regenerated).
>>
>> I'm guessing the temporary root pointer is so we don't ever assign a
>> PTR_ERR to the root in fs_info?
>
> It took me a while to see what you meant.
>
> Yeah, using a temporary root makes sense. Using a different one for
> each block makes less sense.
>
<snip>
> - z
>
Yeah, fair enough, I thought about that after I hit send ;)
I could send a V2 of patch 11/12 to do that w/o needing to redo
the series too much. :) I'll see if there are any other comments.
Thanks!
-Eric
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2014-08-04 18:53 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-01 23:12 [PATCH 00/12] disk-io.c / open_ctree cleanup & refactoring Eric Sandeen
2014-08-01 23:12 ` [PATCH 01/12] btrfs: remove unused fs_info arg from btrfs_close_extra_devices() Eric Sandeen
2014-08-01 23:12 ` [PATCH 02/12] btrfs: consistently use fs_info in close_ctree() Eric Sandeen
2014-08-01 23:12 ` [PATCH 03/12] btrfs: handle errors from reading the quota tree root Eric Sandeen
2014-08-04 18:35 ` Zach Brown
2014-08-04 18:42 ` Eric Sandeen
2014-08-04 18:51 ` Zach Brown
2014-08-04 18:53 ` Eric Sandeen
2014-08-01 23:12 ` [PATCH 04/12] btrfs: factor btrfs_scrub_init() out of open_ctree() Eric Sandeen
2014-08-01 23:12 ` [PATCH 05/12] btrfs: factor btrfs_balance_init() " Eric Sandeen
2014-08-01 23:12 ` [PATCH 06/12] btrfs: factor btrfs_btree_inode_init() " Eric Sandeen
2014-08-01 23:12 ` [PATCH 07/12] btrfs: factor btrfs_dev_replace_locks_init() " Eric Sandeen
2014-08-01 23:12 ` [PATCH 08/12] btrfs: factor btrfs_qgroup_init() " Eric Sandeen
2014-08-01 23:12 ` [PATCH 09/12] btrfs: factor btrfs_setup_super() " Eric Sandeen
2014-08-01 23:12 ` [PATCH 10/12] btrfs: factor btrfs_alloc_workqueues() " Eric Sandeen
2014-08-01 23:12 ` [PATCH 11/12] btrfs: factor btrfs_read_roots() " Eric Sandeen
2014-08-01 23:12 ` [PATCH 12/12] btrfs: factor btrfs_replay_log() " Eric Sandeen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).