From patchwork Mon Apr 2 03:30:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Jinxiang X-Patchwork-Id: 10319445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0A54F60388 for ; Mon, 2 Apr 2018 03:38:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1B4427F9F for ; Mon, 2 Apr 2018 03:38:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D65C128112; Mon, 2 Apr 2018 03:38:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 803C127F9F for ; Mon, 2 Apr 2018 03:38:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754104AbeDBDiw (ORCPT ); Sun, 1 Apr 2018 23:38:52 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:45452 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754092AbeDBDiw (ORCPT ); Sun, 1 Apr 2018 23:38:52 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38384844" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 Apr 2018 11:38:49 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 6644648AE782 for ; Mon, 2 Apr 2018 11:38:48 +0800 (CST) Received: from ubuntu.g08.fujitsu.local (10.167.226.132) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 2 Apr 2018 11:38:50 +0800 From: Gu Jinxiang To: Subject: [PATCH] btrfs-progs: Let function find_device to be consistent with kernel Date: Mon, 2 Apr 2018 11:30:12 +0800 Message-ID: <1522639812-28309-1-git-send-email-gujx@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.132] X-yoursite-MailScanner-ID: 6644648AE782.A55F6 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: gujx@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make find_device to be consistent with kernel according 35c70103a528 ("btrfs: refactor find_device helper") And, modify the compare condition from both devid and uuid to devid or devid and uuid according 8f18cf13396c ("Btrfs: Make the resizer work based on shrinking and growing devices") Signed-off-by: Gu Jinxiang --- volumes.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/volumes.c b/volumes.c index edad367b..1320b55b 100644 --- a/volumes.c +++ b/volumes.c @@ -54,14 +54,22 @@ static inline int nr_data_stripes(struct map_lookup *map) static LIST_HEAD(fs_uuids); -static struct btrfs_device *__find_device(struct list_head *head, u64 devid, - u8 *uuid) +/* + * Find a device specified by @devid or @uuid in the list of @fs_devices, or + * return NULL. + * + * If devid and uuid are both specified, the match must be exact, otherwise + * only devid is used. + */ +static struct btrfs_device *find_device(struct btrfs_fs_devices *fs_devices, + u64 devid, u8 *uuid) { + struct list_head *head = &fs_devices->devices; struct btrfs_device *dev; list_for_each_entry(dev, head, dev_list) { if (dev->devid == devid && - !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE)) { + (!uuid || !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE))) { return dev; } } @@ -100,7 +108,7 @@ static int device_list_add(const char *path, fs_devices->lowest_devid = (u64)-1; device = NULL; } else { - device = __find_device(&fs_devices->devices, devid, + device = find_device(fs_devices, devid, disk_super->dev_item.uuid); } if (!device) { @@ -1616,8 +1624,7 @@ struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid, if (!fsid || (!memcmp(cur_devices->fsid, fsid, BTRFS_UUID_SIZE) || fs_info->ignore_fsid_mismatch)) { - device = __find_device(&cur_devices->devices, - devid, uuid); + device = find_device(cur_devices, devid, uuid); if (device) return device; }