From patchwork Thu Apr 14 22:21:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauhen Kharuzhy X-Patchwork-Id: 8843431 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BE6D79F3A0 for ; Thu, 14 Apr 2016 22:21:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C562F20295 for ; Thu, 14 Apr 2016 22:21:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE73720270 for ; Thu, 14 Apr 2016 22:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752441AbcDNWVU (ORCPT ); Thu, 14 Apr 2016 18:21:20 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:34108 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752416AbcDNWVT (ORCPT ); Thu, 14 Apr 2016 18:21:19 -0400 Received: by mail-pa0-f65.google.com with SMTP id hb4so7782228pac.1 for ; Thu, 14 Apr 2016 15:21:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=X91Xadt4YqWQ7JMLRBgr1NUDFDTZsO2fYrIQb9GkYjo=; b=JtUP4cl9OvqZCgTyRQ6cv0XAJ7BSt3DomW6QQTreXhASESI6Vpnq7SHKIpKa5uo7tO Sin3idurWiqINEAJUq7lypD4giQ2KuQcA/KEEzy9xeDfFpnZHaXe1PX81b3udtkrZkau JX8BzKOBK7m+l2tj0mp+/tC50I7kw6qjAtUTp2SG58mmp1JtxyA00jqyq7GlQCaQHe+W psS5KLzQiXivhC1e1/2UreEvnG/OjrENPcAqCjO7d2OQJT1kjxUN+1r4XKEYgXJhSZab 8/bgK3V64MxYFVTuBoPPlkV0NmEzu70nT0tJ5+azRsNNaGZ7f874n/5QeZA4bnDZOEW6 PGcA== X-Gm-Message-State: AOPr4FUQcEcKYIG2mI7WWThYCpMYj39QY6bfS7hyZKfowWBWrMQxViYjrbSmU9Qorok7SQ== X-Received: by 10.66.65.169 with SMTP id y9mr24712234pas.102.1460672479020; Thu, 14 Apr 2016 15:21:19 -0700 (PDT) Received: from jek-Latitude-E7440 (sjc00ib2.hgst.com. [199.255.44.5]) by smtp.gmail.com with ESMTPSA id y7sm60116592pfa.82.2016.04.14.15.21.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Apr 2016 15:21:18 -0700 (PDT) Received: from jek by jek-Latitude-E7440 with local (Exim 4.86) (envelope-from ) id 1aqpdV-0003FG-GK; Thu, 14 Apr 2016 15:21:17 -0700 From: Yauhen Kharuzhy To: linux-btrfs@vger.kernel.org Cc: Yauhen Kharuzhy Subject: [PATCH] btrfs-progs: Check if the FSID was seen by comparing full UUID Date: Thu, 14 Apr 2016 15:21:11 -0700 Message-Id: <1460672471-12433-1-git-send-email-yauhen.kharuzhy@zavadatar.com> X-Mailer: git-send-email 2.5.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- cmds-filesystem.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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)