aboutsummaryrefslogtreecommitdiffstats
path: root/cmds-filesystem.c
diff options
context:
space:
mode:
authorYauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>2016-04-14 15:21:11 -0700
committerDavid Sterba <dsterba@suse.com>2016-05-02 14:42:04 +0200
commiteba0d8925c6811d35eca95cd9f83b15fff6f690d (patch)
tree485ab787d59260667c6fe5a31393df1e893f5dbd /cmds-filesystem.c
parente8ac13098d64f542f26aea74c583b5446e0db06d (diff)
downloadbtrfs-progs-eba0d8925c6811d35eca95cd9f83b15fff6f690d.tar.gz
btrfs-progs-eba0d8925c6811d35eca95cd9f83b15fff6f690d.tar.xz
btrfs-progs-eba0d8925c6811d35eca95cd9f83b15fff6f690d.zip
btrfs-progs: Check if the FSID was seen by comparing full UUID
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> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-filesystem.c')
-rw-r--r--cmds-filesystem.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 38749ba..e27cb26 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)