public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: damenly.su@gmail.com
To: linux-btrfs@vger.kernel.org
Cc: Su Yue <Damenly_Su@gmx.com>
Subject: [PATCH 06/11] btrfs-progs: handle split-brain scenario for scanned changed/unchanged device with INCOMPAT_METADATA_UUID
Date: Thu, 12 Dec 2019 19:01:59 +0800	[thread overview]
Message-ID: <20191212110204.11128-7-Damenly_Su@gmx.com> (raw)
In-Reply-To: <20191212110204.11128-1-Damenly_Su@gmx.com>

From: Su Yue <Damenly_Su@gmx.com>

For the unchanged/changed device, just need to fs_devices in changing
state, or devices with same status:

a) The scanned device succeeded to sync into disk. The fs_devices
can be with INCOMPAT_METADATA_UUID. So their fsid and metadata_uuid
differs, and metadata_uuid is same as its metada_uuid.

b) The scanned device succeeded to sync into disk. The fs_devices
can be without INCOMPAT_METADATA_UUID. So their fsid and metadata_uuid
be same, and fsid is same as its metadata_uuid.

c) The scanned device failed to be into changing state. There
are some devices whose fsids and metadata_uuids are same as the
device's.

d) The above cases all are missed, only unchanged devices are same
as the device.

Case c and d can be merged into one that both fsid and metadata
requirements are meet.

Signed-off-by: Su Yue <Damenly_Su@gmx.com>
---
 volumes.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/volumes.c b/volumes.c
index 0fd41186c54a..d094f85999d4 100644
--- a/volumes.c
+++ b/volumes.c
@@ -275,6 +275,50 @@ static struct btrfs_fs_devices *find_fsid_changed(
 	return find_fsid(disk_super->fsid, disk_super->metadata_uuid);
 }
 
+static struct btrfs_fs_devices *find_fsid_changing_metadata_uuid(
+					struct btrfs_super_block *disk_super)
+{
+	struct btrfs_fs_devices *fs_devices;
+
+	/*
+	 * Handle scanned device having completed its fsid change but
+	 * belonging to a fs_devices that was created by first scanning
+	 * a device which didn't have its fsid/metadata_uuid changed
+	 * at all and the CHANGING_FSID_V2 flag set.
+	 */
+	list_for_each_entry(fs_devices, &fs_uuids, list) {
+		if (fs_devices->fsid_change &&
+		    memcmp(disk_super->metadata_uuid, fs_devices->fsid,
+			   BTRFS_FSID_SIZE) == 0 &&
+		    memcmp(fs_devices->fsid, fs_devices->metadata_uuid,
+			   BTRFS_FSID_SIZE) == 0) {
+			return fs_devices;
+		}
+	}
+	/*
+	 * Handle scanned device having completed its fsid change but
+	 * belonging to a fs_devices that was created by a device that
+	 * has an outdated pair of fsid/metadata_uuid and
+	 * CHANGING_FSID_V2 flag set.
+	 */
+	list_for_each_entry(fs_devices, &fs_uuids, list) {
+		if (fs_devices->fsid_change &&
+		    memcmp(fs_devices->metadata_uuid,
+			   fs_devices->fsid, BTRFS_FSID_SIZE) != 0 &&
+		    memcmp(disk_super->metadata_uuid,
+			   fs_devices->metadata_uuid, BTRFS_FSID_SIZE) == 0) {
+			return fs_devices;
+		}
+	}
+
+	/*
+	 * The scanned device is unchanged. Try to find devices which are
+	 * successful in changing stage. Or old devices failed to be
+	 * changeing liked current device.
+	 */
+	return find_fsid(disk_super->fsid, disk_super->metadata_uuid);
+}
+
 static int device_list_add(const char *path,
 			   struct btrfs_super_block *disk_super,
 			   u64 devid, struct btrfs_fs_devices **fs_devices_ret)
@@ -292,6 +336,8 @@ static int device_list_add(const char *path,
 			fs_devices = find_fsid_inprogress(disk_super);
 		else
 			fs_devices = find_fsid_changed(disk_super);
+	} else if (metadata_uuid) {
+		fs_devices = find_fsid_changing_metadata_uuid(disk_super);
 	}
 
 	if (metadata_uuid && !fs_devices)
-- 
2.21.0 (Apple Git-122.2)


  parent reply	other threads:[~2019-12-12 11:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-12 11:01 [PATCH 00/11] btrfs-progs: metadata_uuid feature fixes and portation damenly.su
2019-12-12 11:01 ` [PATCH 01/11] btrfs-progs: misc-tests/034: reload btrfs module before running failure_recovery damenly.su
2020-01-31  8:01   ` Nikolay Borisov
2019-12-12 11:01 ` [PATCH 02/11] btrfs-progs: misc-tests/034: mount the second device if first device mount failed damenly.su
2020-01-31  8:03   ` Nikolay Borisov
2020-01-31 10:01     ` Su Yue
2020-01-31 12:47       ` Nikolay Borisov
2020-02-04  4:40         ` Su Yue
2019-12-12 11:01 ` [PATCH 03/11] btrfs-progs: metadata_uuid: add new member btrfs_fs_devices::fsid_change damenly.su
2019-12-12 11:01 ` [PATCH 04/11] btrfs-progs: handle split-brain scenario for scanned changing device without INCOMPAT_METADATA_UUID damenly.su
2019-12-12 11:01 ` [PATCH 05/11] btrfs-progs: handle split-brain scenario for scanned changing device with INCOMPAT_METADATA_UUID damenly.su
2019-12-12 11:01 ` damenly.su [this message]
2019-12-12 11:02 ` [PATCH 07/11] btrfs-progs: handle split-brain scenario for scanned changed/unchanged device without INCOMPAT_METADATA_UUID damenly.su
2019-12-12 11:02 ` [PATCH 08/11] btrfs-progs: metadata_uuid: remove old logic to find fs_devices damenly.su
2019-12-12 11:02 ` [PATCH 09/11] btrfs-progs: metadata_uuid: rewrite fs_devices fsid and metadata_uuid if it's changing damenly.su
2019-12-12 11:02 ` [PATCH 10/11] btrfs-progs: metadata_uuid: clear FSID_CHANGING_V2 while open_ctree() damenly.su
2019-12-12 11:02 ` [PATCH 11/11] btrfs-progs: misc-tests/034: add new test images and modify the script damenly.su
2020-01-31  8:00   ` Nikolay Borisov
2020-01-31  8:05 ` [PATCH 00/11] btrfs-progs: metadata_uuid feature fixes and portation Nikolay Borisov
2020-01-31 10:04   ` Su Yue
2020-03-04 14:14     ` David Sterba
2020-03-05  1:18       ` Su Yue
2020-03-05 14:16         ` David Sterba

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=20191212110204.11128-7-Damenly_Su@gmx.com \
    --to=damenly.su@gmail.com \
    --cc=Damenly_Su@gmx.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