From patchwork Mon Oct 7 09:45:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11177077 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DE2A17E6 for ; Mon, 7 Oct 2019 09:45:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1BD2421655 for ; Mon, 7 Oct 2019 09:45:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="qI4IgdFT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727511AbfJGJpZ (ORCPT ); Mon, 7 Oct 2019 05:45:25 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:33520 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbfJGJpY (ORCPT ); Mon, 7 Oct 2019 05:45:24 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979dI28065891 for ; Mon, 7 Oct 2019 09:45:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=V9tib0wsL/GdEx7feZAGzq0ied+zxMxr68qEnb04CXw=; b=qI4IgdFTZV0w3iuaps7CkJzPZUUBazsgjcI05UbGGX69wfW43RS+j6bSKF+VromQg8SK 2HQuPaw4MTjoLgT+LMgLkBmVk4nhoXz42/btxeWSvvPYW6aZR/fEhbUsdVfU6aq7IUSI 9rWyU2zkcTHclfPiGmkOd3rTB7HW1WjZp6io6FBJ6923u8t4h3F8RmzBgUBuK/1DpfIO lXeNI1g+8eXYdWY4ngyyMF5Wk74+p7a5XroWhN5J4vYR7sigbG5iujfMictdLAnhX65I AAzGC0kCIhKMjI2ZVgJjOk12fX8DSxOxNVpEEzzvHSn0qxrUt8w/lqx3tTpeuNUudNA5 MA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2vejku5qa4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:45:23 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979cQ40077608 for ; Mon, 7 Oct 2019 09:45:22 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2vg1ytjug9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:45:22 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x979jLSJ003933 for ; Mon, 7 Oct 2019 09:45:21 GMT Received: from localhost.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Oct 2019 02:45:20 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/5] btrfs: drop useless goto in open_fs_devices Date: Mon, 7 Oct 2019 17:45:11 +0800 Message-Id: <20191007094515.925-2-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191007094515.925-1-anand.jain@oracle.com> References: <20191007094515.925-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There is no need of goto out in open_fs_devices() as there is nothing special done at %out:. So refactor it. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov --- fs/btrfs/volumes.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index bba74e3bd9d8..c223a8147bfd 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1123,7 +1123,6 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices, { struct btrfs_device *device; struct btrfs_device *latest_dev = NULL; - int ret = 0; flags |= FMODE_EXCL; @@ -1136,15 +1135,14 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices, device->generation > latest_dev->generation) latest_dev = device; } - if (fs_devices->open_devices == 0) { - ret = -EINVAL; - goto out; - } + if (fs_devices->open_devices == 0) + return -EINVAL; + fs_devices->opened = 1; fs_devices->latest_bdev = latest_dev->bdev; fs_devices->total_rw_bytes = 0; -out: - return ret; + + return 0; } static int devid_cmp(void *priv, struct list_head *a, struct list_head *b) From patchwork Mon Oct 7 09:45:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11177079 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D3BF76 for ; Mon, 7 Oct 2019 09:45:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6AE4D2166E for ; Mon, 7 Oct 2019 09:45:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="B7tfUCma" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727515AbfJGJpZ (ORCPT ); Mon, 7 Oct 2019 05:45:25 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59960 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbfJGJpZ (ORCPT ); Mon, 7 Oct 2019 05:45:25 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979dCA3022967 for ; Mon, 7 Oct 2019 09:45:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=6dmS48pG6irNMwD9fS+3IUEJAha5ZP72X+7lROcEt0o=; b=B7tfUCmakbzwWaP23T5ahoHi4rG/HRYFLM9vHMfCOSc7sdv2kaOt34vDo0JnzKNSUhJ1 XIB6tPM02vxAHRxJqIoP1wEUp5cOp/Kp/+7K8QLsIGwjmJgvZQlVMFGW43ieuJzcMeUa zMtxvo8xvWAK9UzFDZsIXQkyJtoWT9q4mOP044DJDgRgEdTurOH+W8ShK48pvPASZ/am g1jWRcQVIW95oGm/Ly8lrKHhgWHJNkU0SAq7xQ4tu+ohYSgcDzbCESoGgyD9GvsGbd2L ISdMk5/su6bqv9O9a6XJkuirWC7G0iENlDZsi8aQOu8B3JhMiGUR52AGRZy9ID3mZcSB AQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2vek4q5ncx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:45:24 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979cTWj094102 for ; Mon, 7 Oct 2019 09:45:23 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2vf4ph7a13-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:45:23 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x979jMpD003948 for ; Mon, 7 Oct 2019 09:45:22 GMT Received: from localhost.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Oct 2019 02:45:22 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/5] btrfs: include non-missing as a qualifier for the latest_bdev Date: Mon, 7 Oct 2019 17:45:12 +0800 Message-Id: <20191007094515.925-3-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191007094515.925-1-anand.jain@oracle.com> References: <20191007094515.925-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_free_extra_devids() reorgs fs_devices::latest_bdev to point to the bdev with greatest device::generation number. For a typical-missing device the generation number is zero so fs_devices::latest_bdev will never point to it. But if the missing device is due to alienating [1], then device::generation is not-zero and if it is >= to rest of device::generation in the list, then fs_devices::latest_bdev ends up pointing to the missing device and reports the error like this [2] [1] mkfs.btrfs -fq /dev/sdd && mount /dev/sdd /btrfs mkfs.btrfs -fq -draid1 -mraid1 /dev/sdb /dev/sdc sleep 3 # avoid racing with udev's useless scans if needed btrfs dev add -f /dev/sdb /btrfs mount -o degraded /dev/sdc /btrfs1 [2] mount: wrong fs type, bad option, bad superblock on /dev/sdc, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so. kernel: BTRFS warning (device sdc): devid 1 uuid 072a0192-675b-4d5a-8640-a5cf2b2c704d is missing kernel: BTRFS error (device sdc): failed to read devices kernel: BTRFS error (device sdc): open_ctree failed Fix the root of the issue, by checking if the the device is not missing before it can be a contender for the fs_devices::latest_bdev title. Signed-off-by: Anand Jain --- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c223a8147bfd..0cc8d40b8bb9 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -974,6 +974,8 @@ void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step) &device->dev_state)) { if (!test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state) && + !test_bit(BTRFS_DEV_STATE_MISSING, + &device->dev_state) && (!latest_dev || device->generation > latest_dev->generation)) { latest_dev = device; From patchwork Mon Oct 7 09:45:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11177081 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CF181709 for ; Mon, 7 Oct 2019 09:45:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 193FF2166E for ; Mon, 7 Oct 2019 09:45:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="sQW3xn9i" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727524AbfJGJp1 (ORCPT ); Mon, 7 Oct 2019 05:45:27 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:37044 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbfJGJp0 (ORCPT ); Mon, 7 Oct 2019 05:45:26 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979cvxK055175 for ; Mon, 7 Oct 2019 09:45:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=DohWxkfCt4g3rEVlPbAEZngxr7crwRtuveTVz1roRIg=; b=sQW3xn9iopjqExYDT3B/t4/cwW1l/iUu4TxfpOWAOmtQ/UAI6ultlll+YxfcBExdGfqK HnnNdnxjsjaqM4bBlWelTUPW+3qegsZHL003Zqw5ddk/B+k3n5KTSvPc4Mmq/50J19jT 0G8Q2GniIGDo8i2sDc1PhAcSZr+1j7uBDaJaCDEJ6NKo676czH40JxUpuKHVZex39dYS WtyARf6zLi3P7b7kO3YZ9BtIorcE7J3i7rz8wH5o3gUzqcRJRZDWmt797N2CjDLs6DT7 LtgmBcO2yHqmgRThk0M4NkCIF2cOgQMinbJz+pXeMvZdqx+7mc1/ntX6I5FR2OMjMBp/ RA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2vektr5gej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:45:26 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979cQSo077636 for ; Mon, 7 Oct 2019 09:45:25 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2vg1ytjujm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:45:25 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x979jOTg003988 for ; Mon, 7 Oct 2019 09:45:24 GMT Received: from localhost.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Oct 2019 02:45:23 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v3 3/5] btrfs: remove identified alien btrfs device in open_fs_devices Date: Mon, 7 Oct 2019 17:45:13 +0800 Message-Id: <20191007094515.925-4-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191007094515.925-1-anand.jain@oracle.com> References: <20191007094515.925-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In open_fs_devices() we identify alien device but we don't reset its the device::name. So progs device list does not show the device missing as shown in the script below. mkfs.btrfs -fq /dev/sdd && mount /dev/sdd /btrfs mkfs.btrfs -fq -draid1 -mraid1 /dev/sdc /dev/sdb sleep 3 # avoid racing with udev's useless scans if needed btrfs dev add -f /dev/sdb /btrfs mount -o degraded /dev/sdc /btrfs1 No missing device: btrfs fi show -m /btrfs1 Label: none uuid: 3eb7cd50-4594-458f-9d68-c243cc49954d Total devices 2 FS bytes used 128.00KiB devid 1 size 12.00GiB used 1.26GiB path /dev/sdc devid 2 size 12.00GiB used 1.26GiB path /dev/sdb Signed-off-by: Anand Jain --- v3: Fix nit, rearrange code to remove continue. v2: Move free alien part to its parent function btrfs_open_one_device. Thanks Nikolay. fs/btrfs/volumes.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 0cc8d40b8bb9..81097c80ac4a 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -591,13 +591,18 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, if (ret) return ret; + ret = -EINVAL; disk_super = (struct btrfs_super_block *)bh->b_data; devid = btrfs_stack_device_id(&disk_super->dev_item); - if (devid != device->devid) + if (devid != device->devid) { + ret = -EUCLEAN; goto error_brelse; + } - if (memcmp(device->uuid, disk_super->dev_item.uuid, BTRFS_UUID_SIZE)) + if (memcmp(device->uuid, disk_super->dev_item.uuid, BTRFS_UUID_SIZE)) { + ret = -EUCLEAN; goto error_brelse; + } device->generation = btrfs_super_generation(disk_super); @@ -640,7 +645,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, brelse(bh); blkdev_put(bdev, flags); - return -EINVAL; + return ret; } /* @@ -1123,18 +1128,25 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices) static int open_fs_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder) { + int ret; struct btrfs_device *device; + struct btrfs_device *tmp_device; struct btrfs_device *latest_dev = NULL; flags |= FMODE_EXCL; - list_for_each_entry(device, &fs_devices->devices, dev_list) { + list_for_each_entry_safe(device, tmp_device, &fs_devices->devices, + dev_list) { /* Just open everything we can; ignore failures here */ - if (btrfs_open_one_device(fs_devices, device, flags, holder)) - continue; - - if (!latest_dev || - device->generation > latest_dev->generation) + ret = btrfs_open_one_device(fs_devices, device, flags, holder); + if (ret == -EUCLEAN) { + /* Its an alien device, remove it from the list */ + fs_devices->num_devices--; + list_del(&device->dev_list); + btrfs_free_device(device); + } + if (ret == 0 && (!latest_dev || + device->generation > latest_dev->generation)) latest_dev = device; } if (fs_devices->open_devices == 0) From patchwork Mon Oct 7 09:45:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11177085 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BEDE976 for ; Mon, 7 Oct 2019 09:47:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 958292166E for ; Mon, 7 Oct 2019 09:47:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jS7cGjpO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727324AbfJGJr2 (ORCPT ); Mon, 7 Oct 2019 05:47:28 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:38842 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727290AbfJGJr2 (ORCPT ); Mon, 7 Oct 2019 05:47:28 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979cvXx055196 for ; Mon, 7 Oct 2019 09:47:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=uxLnuaTusD6GVlodIfEgcw/hzj4a8hTmmrWsih825Rw=; b=jS7cGjpObdIVj0Kc3NnkX6oMy0T4u7C1aTu7LFinunYsHoEHMKh9xbwKcG8DQVTSwkZk OSyfX2cNc39nPY9DoK7tRLV+v1d6paSbjOOmK27PRDXhJ2bCi1waW2IWFPM+ZsfBtlog wONzbFNvhetVT5tKuR+9qG8dMDgyIyB8PyC9jyHF4xsGkMVzpqjYrwg6Zn95dMPm3AyS MSJqXW8RjHRKMWE+omodeIyrs7kVuxlEDI6FNttY+N8FDFghptonbjtbksAaAyIxkaxW 69LLW0il+DLBoHESgMfP5Mm6eySy/JEDfoxDfnCMPkKCBIcqG/Avnf5fKYBV0YDf69KJ Mg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2vektr5gnh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:47:26 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979cddZ099237 for ; Mon, 7 Oct 2019 09:45:26 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2vg203btbg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:45:26 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x979jPcv022320 for ; Mon, 7 Oct 2019 09:45:25 GMT Received: from localhost.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Oct 2019 02:45:25 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/5] btrfs: remove identified alien device in open_fs_devices Date: Mon, 7 Oct 2019 17:45:14 +0800 Message-Id: <20191007094515.925-5-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191007094515.925-1-anand.jain@oracle.com> References: <20191007094515.925-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Following test case explains it all, even though the degraded mount is successful the btrfs-progs fails to report the missing device. mkfs.btrfs -fq -draid1 -mraid1 /dev/sdc /dev/sdd && \ wipefs -a /dev/sdd && mount -o degraded /dev/sdc /btrfs && \ btrfs fi show -m /btrfs Label: none uuid: 2b3b8d92-572b-4d37-b4ee-046d3a538495 Total devices 2 FS bytes used 128.00KiB devid 1 size 1.09TiB used 2.01GiB path /dev/sdc devid 2 size 1.09TiB used 2.01GiB path /dev/sdd This is because btrfs-progs does it fundamentally wrong way that it deduces the missing device status in the user land instead of refuting from the kernel. At the same time in the kernel when we know that there is device with non-btrfs magic, then remove that device from the list so that btrfs-progs or someother userland utility won't be confused. Signed-off-by: Anand Jain --- fs/btrfs/disk-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 326d5281ad93..e05856432456 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3417,7 +3417,7 @@ int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num, if (btrfs_super_bytenr(super) != bytenr || btrfs_super_magic(super) != BTRFS_MAGIC) { brelse(bh); - return -EINVAL; + return -EUCLEAN; } *bh_ret = bh; From patchwork Mon Oct 7 09:45:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11177083 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F1DD61709 for ; Mon, 7 Oct 2019 09:45:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D0F2F2166E for ; Mon, 7 Oct 2019 09:45:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="CWDIzH5Q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727533AbfJGJpa (ORCPT ); Mon, 7 Oct 2019 05:45:30 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:60046 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbfJGJp3 (ORCPT ); Mon, 7 Oct 2019 05:45:29 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979cwHl022705 for ; Mon, 7 Oct 2019 09:45:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=S5KxWtjDjZ7DtCoK3FT7D7HXXLW/68gaDJQL+SHzvFM=; b=CWDIzH5QqwPsD+iDWKgRGygiGkKNrgFNEvfVPLMd5Eu7DKPVdRSxlziCrQWxdbTzbvuM DEQELuKAkXuAALfFJqBsSioVretSb0J3Dm8BExO8JpFs2rBdh5IWgqUoXbv4oLgI1Yay M6kRLYeE2h51ndMkKBYcNOTyssDX+b0L3Don0f7mFFk1jsJokhMnjG32qEUVDnOBMQVc ZJOTIqa32Z8u4oFqpkiWL+QSolz7E9epFCbe+Flm8PJTcZx4QxFhFEUpEPWtjxS0TlXQ 1s/t8L1CUr5r0eNlTu+CjMr4mNDDESOZ9bcINd6JiqKbT28eU+zANPI1f0tg6cjBu2Qo 2g== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2vek4q5nd3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:45:28 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x979cT0N094041 for ; Mon, 7 Oct 2019 09:45:28 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2vf4ph7a4g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Oct 2019 09:45:28 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x979jRd0004004 for ; Mon, 7 Oct 2019 09:45:27 GMT Received: from localhost.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Oct 2019 02:45:26 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 5/5] btrfs: free alien device due to device add Date: Mon, 7 Oct 2019 17:45:15 +0800 Message-Id: <20191007094515.925-6-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191007094515.925-1-anand.jain@oracle.com> References: <20191007094515.925-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9402 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910070097 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When the old device has new fsid through btrfs device add -f our fs_devices list has an alien device in one of the fs_devices. By having an alien device in fs_devices, we have two issues so far 1. missing device is not shows as missing in the userland Which is due to cracks in the function btrfs_open_one_device() and hardened by patch btrfs: delete identified alien device in open_fs_devices 2. mount of a degraded fs_devices fails Which is due to cracks in the function btrfs_free_extra_devids() and hardened by patch btrfs: include non-missing as a qualifier for the latest_bdev Now the reason for both of this issue is that there is an alien (does not contain the intended fsid) device in the fs_devices. We know a device can be scanned/added through btrfs-control::BTRFS_IOC_SCAN_DEV|BTRFS_IOC_DEVICES_READY or by ioctl::BTRFS_IOC_ADD_DEV And device coming through btrfs-control is checked against the all other devices in btrfs kernel but not coming through BTRFS_IOC_ADD_DEV. This patch checks if the device add is alienating any other scanned device and deletes it. In fact, this patch fixes both the issues 1 and 2 (above) by eliminating the source of the issue, but still they have their own patch as well because its the right way to harden the functions and fill the cracks. Signed-off-by: Anand Jain --- fs/btrfs/volumes.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 81097c80ac4a..4c7e37cd2166 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2534,6 +2534,19 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path /* Update ctime/mtime for libblkid */ update_dev_time(device_path); + + /* + * Now that we have written a new sb into this device, check all other + * fs_devices list if it alienates any scanned device. + */ + mutex_lock(&uuid_mutex); + /* + * Ignore the return as we are successfull in the core task - to added + * the device + */ + btrfs_free_stale_devices(device_path, NULL); + mutex_unlock(&uuid_mutex); + return ret; error_sysfs: