diff mbox

btrfs-progs: Check if the FSID was seen by comparing full UUID

Message ID 1460672471-12433-1-git-send-email-yauhen.kharuzhy@zavadatar.com (mailing list archive)
State Accepted
Headers show

Commit Message

Yauhen Kharuzhy April 14, 2016, 10:21 p.m. UTC
is_seen_fsid() uses simple hash to check if FS was seen before at
walking on FS list in 'filesystem show' command: hash key is first byte
of the UUID. This function doesn't check full UUID then, so, if there
are two FS with same first byte in UUIDs exist, only one will be shown:

root@test:~# btrfs fi show
Label: 'System'  uuid: 688cb918-7bac-4c8e-9b11-8d047eb14cf4
        Total devices 2 FS bytes used 1.76GiB
        devid    1 size 3.46TiB used 4.01GiB path /dev/sda2
        devid    2 size 6.91TiB used 4.01GiB path /dev/sdb2

Global spare

root@test:~# grep btrfs /proc/mounts
/dev/sda2 / btrfs rw,relatime,space_cache,subvolid=256,subvol=/root 0 0
/dev/sdc /media/688cb918-7bac-4c8e-9b11-8d047eb14cf4 btrfs rw,relatime,space_cache,subvolid=5,subvol=/ 0 0

root@test:~# btrfs fi show --all-devices
Label: 'System'  uuid: 688cb918-7bac-4c8e-9b11-8d047eb14cf4
        Total devices 2 FS bytes used 1.76GiB
        devid    1 size 3.46TiB used 4.03GiB path /dev/sda2
        devid    2 size 6.91TiB used 4.01GiB path /dev/sdb2

Label: 'test'  uuid: 683b1a80-ca7f-4c4d-b87b-7155401a4d18
        Total devices 7 FS bytes used 2.06MiB
        devid    1 size 7.28TiB used 1.57GiB path /dev/sdc
        devid    2 size 7.28TiB used 1.57GiB path /dev/sdd
        devid    3 size 7.28TiB used 1.57GiB path /dev/sde
        devid    4 size 7.28TiB used 1.57GiB path /dev/sdf
        devid    5 size 7.28TiB used 1.57GiB path /dev/sdg
        devid    6 size 7.28TiB used 1.57GiB path /dev/sdh
        devid    7 size 7.28TiB used 1.57GiB path /dev/sdi

To resolve this collision, search for full FSID in the list of seen
filesystems.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
---
 cmds-filesystem.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

David Sterba April 15, 2016, 11:20 a.m. UTC | #1
On Thu, Apr 14, 2016 at 03:21:11PM -0700, Yauhen Kharuzhy wrote:
> is_seen_fsid() uses simple hash to check if FS was seen before at
> walking on FS list in 'filesystem show' command: hash key is first byte
> of the UUID. This function doesn't check full UUID then, so, if there
> are two FS with same first byte in UUIDs exist, only one will be shown:
> 
> root@test:~# btrfs fi show
> Label: 'System'  uuid: 688cb918-7bac-4c8e-9b11-8d047eb14cf4
>         Total devices 2 FS bytes used 1.76GiB
>         devid    1 size 3.46TiB used 4.01GiB path /dev/sda2
>         devid    2 size 6.91TiB used 4.01GiB path /dev/sdb2
> 
> Global spare
> 
> root@test:~# grep btrfs /proc/mounts
> /dev/sda2 / btrfs rw,relatime,space_cache,subvolid=256,subvol=/root 0 0
> /dev/sdc /media/688cb918-7bac-4c8e-9b11-8d047eb14cf4 btrfs rw,relatime,space_cache,subvolid=5,subvol=/ 0 0
> 
> root@test:~# btrfs fi show --all-devices
> Label: 'System'  uuid: 688cb918-7bac-4c8e-9b11-8d047eb14cf4
>         Total devices 2 FS bytes used 1.76GiB
>         devid    1 size 3.46TiB used 4.03GiB path /dev/sda2
>         devid    2 size 6.91TiB used 4.01GiB path /dev/sdb2
> 
> Label: 'test'  uuid: 683b1a80-ca7f-4c4d-b87b-7155401a4d18
>         Total devices 7 FS bytes used 2.06MiB
>         devid    1 size 7.28TiB used 1.57GiB path /dev/sdc
>         devid    2 size 7.28TiB used 1.57GiB path /dev/sdd
>         devid    3 size 7.28TiB used 1.57GiB path /dev/sde
>         devid    4 size 7.28TiB used 1.57GiB path /dev/sdf
>         devid    5 size 7.28TiB used 1.57GiB path /dev/sdg
>         devid    6 size 7.28TiB used 1.57GiB path /dev/sdh
>         devid    7 size 7.28TiB used 1.57GiB path /dev/sdi
> 
> To resolve this collision, search for full FSID in the list of seen
> filesystems.
> 
> Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index f8fc764..97b2645 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -58,7 +58,14 @@  static int is_seen_fsid(u8 *fsid)
 	int slot = hash % SEEN_FSID_HASH_SIZE;
 	struct seen_fsid *seen = seen_fsid_hash[slot];
 
-	return seen ? 1 : 0;
+	while (seen) {
+		if (memcmp(seen->fsid, fsid, BTRFS_FSID_SIZE) == 0)
+			return 1;
+
+		seen = seen->next;
+	}
+
+	return 0;
 }
 
 static int add_seen_fsid(u8 *fsid)