From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 02/16] btrfs-progs: tune can use local fs_info variable
Date: Mon, 14 Aug 2023 23:27:58 +0800 [thread overview]
Message-ID: <c604ca9902bc78c9a6db8c1f1d210653511faf44.1692018849.git.anand.jain@oracle.com> (raw)
In-Reply-To: <cover.1692018849.git.anand.jain@oracle.com>
Since the root pointer dereferences for the fs_info several times,
it is rational to save the fs_info.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
tune/main.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/tune/main.c b/tune/main.c
index c49c24298187..e3b199c10dad 100644
--- a/tune/main.c
+++ b/tune/main.c
@@ -133,6 +133,7 @@ static const struct cmd_struct tune_cmd = {
int BOX_MAIN(btrfstune)(int argc, char *argv[])
{
struct btrfs_root *root;
+ struct btrfs_fs_info *fs_info;
unsigned ctree_flags = OPEN_CTREE_WRITES;
int success = 0;
int total = 0;
@@ -296,6 +297,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
ret = 1;
goto free_out;
}
+ fs_info = root->fs_info;
/*
* As we increment the generation number here, it is unlikely that the
@@ -309,9 +311,9 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
* all the partner devices.
*/
if ((change_metadata_uuid || random_fsid || new_fsid_str) &&
- root->fs_info->fs_devices->missing_devices > 0) {
+ fs_info->fs_devices->missing_devices > 0) {
error("missing %lld device(s), failing the command",
- root->fs_info->fs_devices->missing_devices);
+ fs_info->fs_devices->missing_devices);
ret = 1;
goto out;
}
@@ -322,17 +324,17 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
ret = 1;
goto out;
}
- if (btrfs_fs_compat_ro(root->fs_info, BLOCK_GROUP_TREE)) {
+ if (btrfs_fs_compat_ro(fs_info, BLOCK_GROUP_TREE)) {
error("the filesystem already has block group tree feature");
ret = 1;
goto out;
}
- if (!btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE_VALID)) {
+ if (!btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID)) {
error("the filesystem doesn't have space cache v2, needs to be mounted with \"-o space_cache=v2\" first");
ret = 1;
goto out;
}
- ret = convert_to_bg_tree(root->fs_info);
+ ret = convert_to_bg_tree(fs_info);
if (ret < 0) {
error("failed to convert the filesystem to block group tree feature");
goto out;
@@ -340,12 +342,12 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
goto out;
}
if (to_fst) {
- if (btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE_VALID)) {
+ if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID)) {
error("filesystem already has free-space-tree feature");
ret = 1;
goto out;
}
- ret = convert_to_fst(root->fs_info);
+ ret = convert_to_fst(fs_info);
if (ret < 0)
error("failed to convert the filesystem to free-space-tree feature");
goto out;
@@ -356,12 +358,12 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
ret = 1;
goto out;
}
- if (!btrfs_fs_compat_ro(root->fs_info, BLOCK_GROUP_TREE)) {
+ if (!btrfs_fs_compat_ro(fs_info, BLOCK_GROUP_TREE)) {
error("filesystem doesn't have block-group-tree feature");
ret = 1;
goto out;
}
- ret = convert_to_extent_tree(root->fs_info);
+ ret = convert_to_extent_tree(fs_info);
if (ret < 0) {
error("failed to convert the filesystem from block group tree feature");
goto out;
@@ -369,7 +371,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
goto out;
}
if (seeding_flag) {
- if (btrfs_fs_incompat(root->fs_info, METADATA_UUID)) {
+ if (btrfs_fs_incompat(fs_info, METADATA_UUID)) {
error("SEED flag cannot be changed on a metadata-uuid changed fs");
ret = 1;
goto out;
@@ -402,7 +404,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
if (csum_type != -1) {
/* TODO: check conflicting flags */
pr_verbose(LOG_DEFAULT, "Proceed to switch checksums\n");
- ret = btrfs_change_csum_type(root->fs_info, csum_type);
+ ret = btrfs_change_csum_type(fs_info, csum_type);
}
if (change_metadata_uuid) {
@@ -424,8 +426,8 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
}
if (random_fsid || (new_fsid_str && !change_metadata_uuid)) {
- if (btrfs_fs_incompat(root->fs_info, METADATA_UUID) ||
- root->fs_info->fs_devices->active_metadata_uuid) {
+ if (btrfs_fs_incompat(fs_info, METADATA_UUID) ||
+ fs_info->fs_devices->active_metadata_uuid) {
error(
"Cannot rewrite fsid while METADATA_UUID flag is active. \n"
"Ensure fsid and metadata_uuid match before retrying.");
@@ -445,7 +447,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
goto out;
}
}
- ret = change_uuid(root->fs_info, new_fsid_str);
+ ret = change_uuid(fs_info, new_fsid_str);
if (!ret)
success++;
total++;
@@ -454,7 +456,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
if (success == total) {
ret = 0;
} else {
- root->fs_info->readonly = 1;
+ fs_info->readonly = 1;
ret = 1;
error("btrfstune failed");
}
--
2.39.3
next prev parent reply other threads:[~2023-08-14 15:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-14 15:27 [PATCH 00/16] btrfs-progs: recover from failed metadata_uuid Anand Jain
2023-08-14 15:27 ` [PATCH 01/16] btrfs-progs: track num_devices per fs_devices Anand Jain
2023-08-14 15:27 ` Anand Jain [this message]
2023-08-14 15:27 ` [PATCH 03/16] btrfs-progs: rename set_metadata_uuid arg to new_fsid_str Anand Jain
2023-08-14 15:28 ` [PATCH 04/16] btrfs-progs: rename set_metadata_uuid new_fsid to fsid Anand Jain
2023-08-14 15:28 ` [PATCH 05/16] btrfs-progs: rename set_metadata_uuid new_uuid to new_fsid Anand Jain
2023-08-14 15:28 ` [PATCH 06/16] btrfs-progs: rename set_metadata_uuid uuid_changed to fsid_changed Anand Jain
2023-08-14 15:28 ` [PATCH 07/16] btrfs-progs: pass fsid in check_unfinished_fsid_change arg2 Anand Jain
2023-08-14 15:28 ` [PATCH 08/16] btrfs-progs: pass metadata_uuid in check_unfinished_fsid_change arg3 Anand Jain
2023-08-14 15:28 ` [PATCH 09/16] btrfs-progs: fix return without flag reset commit in tune Anand Jain
2023-08-14 15:28 ` [PATCH 10/16] btrfs-progs: preparing the latest device's superblock for commit Anand Jain
2023-08-14 15:28 ` [PATCH 11/16] btrfs-progs: rename fs_devices::list to match the kernel Anand Jain
2023-08-14 15:28 ` [PATCH 12/16] btrfs-progs: rename fs_devices::latest_trans " Anand Jain
2023-08-14 15:28 ` [PATCH 13/16] btrfs-progs: tune use the latest bdev in fs_devices for super_copy Anand Jain
2023-08-14 15:28 ` [PATCH 14/16] btrfs-progs: add support to fix superblock with CHANGING_FSID_V2 flag Anand Jain
2023-08-14 15:28 ` [PATCH 15/16] btrfs-progs: recover from the failed btrfstune -m|M Anand Jain
2023-08-14 15:28 ` [PATCH 16/16] btrfs-progs: test btrfstune -m|M ability to fix previous failures Anand Jain
2023-08-23 20:10 ` David Sterba
2023-08-24 14:00 ` Anand Jain
2023-08-23 22:13 ` [PATCH 00/16] btrfs-progs: recover from failed metadata_uuid David Sterba
2023-08-23 22:24 ` David Sterba
2023-08-24 13:54 ` Anand Jain
2023-08-25 11:53 ` David Sterba
2023-08-25 14:57 ` Anand Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c604ca9902bc78c9a6db8c1f1d210653511faf44.1692018849.git.anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).