linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] btrfs-progs: btrfstune -m|M remove 2-stage commit
@ 2023-08-15 12:53 Anand Jain
  2023-08-16  2:17 ` Qu Wenruo
  2023-08-17 11:52 ` David Sterba
  0 siblings, 2 replies; 8+ messages in thread
From: Anand Jain @ 2023-08-15 12:53 UTC (permalink / raw)
  To: linux-btrfs

The btrfstune -m|M operation changes the fsid and preserves the original
fsid in the metadata_uuid.

Changing the fsid happens in two commits in the function
set_metadata_uuid()
- Stage 1 commits the superblock with the CHANGING_FSID_V2 flag.
- Stage 2 updates the fsid in fs_info->super_copy (local memory),
  resets the CHANGING_FSID_V2 flag (local memory),
  and then calls commit.

The two-stage operation with the CHANGING_FSID flag makes sense for
btrfstune -u|U, where the fsid is changed on each and every tree block,
involving many commits. The CHANGING_FSID flag helps to identify the
transient incomplete operation.

However, for btrfstune -m|M, we don't need the CHANGING_FSID_V2 flag, and
a single commit would have been sufficient. The original git commit that
added it, 493dfc9d1fc4 ("btrfs-progs: btrfstune: Add support for changing
the metadata uuid"), provides no reasoning or did I miss something?
(So marking this patch as RFC).

This patch removes the two-stage commit for btrfstune -m|M and instead
performs it in a single commit.

With this change, the CHANGING_FSID_V2 flag is unused. Nevertheless, for
legacy purposes, we will still reset the CHANGING_FSID_V2 flag during the
btrfstune -m|M commit. Furthermore, the patchset titled:

	[PATCH 00/16] btrfs-progs: recover from failed metadata_uuid

will help recover from the split brain situation due to two stage
method in the older btrfstune.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 tune/change-metadata-uuid.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/tune/change-metadata-uuid.c b/tune/change-metadata-uuid.c
index 371f34e679b4..ac8c2fd398c2 100644
--- a/tune/change-metadata-uuid.c
+++ b/tune/change-metadata-uuid.c
@@ -33,7 +33,6 @@ int set_metadata_uuid(struct btrfs_root *root, const char *new_fsid_string)
 	u64 incompat_flags;
 	bool fsid_changed;
 	u64 super_flags;
-	int ret;
 
 	disk_super = root->fs_info->super_copy;
 	super_flags = btrfs_super_flags(disk_super);
@@ -66,14 +65,6 @@ int set_metadata_uuid(struct btrfs_root *root, const char *new_fsid_string)
 
 	new_fsid = (memcmp(fsid, disk_super->fsid, BTRFS_FSID_SIZE) != 0);
 
-	/* Step 1 sets the in progress flag */
-	trans = btrfs_start_transaction(root, 1);
-	super_flags |= BTRFS_SUPER_FLAG_CHANGING_FSID_V2;
-	btrfs_set_super_flags(disk_super, super_flags);
-	ret = btrfs_commit_transaction(trans, root);
-	if (ret < 0)
-		return ret;
-
 	if (new_fsid && fsid_changed && memcmp(disk_super->metadata_uuid,
 					       fsid, BTRFS_FSID_SIZE) == 0) {
 		/*
@@ -106,8 +97,7 @@ int set_metadata_uuid(struct btrfs_root *root, const char *new_fsid_string)
 	trans = btrfs_start_transaction(root, 1);
 
 	/*
-	 * Step 2 is to write the metadata_uuid, set the incompat flag and
-	 * clear the in progress flag
+	 * For leagcy purpose reset the BTRFS_SUPER_FLAG_CHANGING_FSID_V2
 	 */
 	super_flags &= ~BTRFS_SUPER_FLAG_CHANGING_FSID_V2;
 	btrfs_set_super_flags(disk_super, super_flags);
-- 
2.39.3


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

end of thread, other threads:[~2023-09-20 23:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-15 12:53 [PATCH RFC] btrfs-progs: btrfstune -m|M remove 2-stage commit Anand Jain
2023-08-16  2:17 ` Qu Wenruo
2023-08-17 11:52 ` David Sterba
2023-08-18  9:21   ` Anand Jain
2023-08-18  9:27     ` Qu Wenruo
2023-08-19 11:14       ` Anand Jain
2023-09-18 22:38         ` David Sterba
2023-09-20 23:01           ` Anand Jain

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