From patchwork Thu Sep 3 00:57:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752123 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 2AFB8138A for ; Thu, 3 Sep 2020 00:58:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 139C0207D3 for ; Thu, 3 Sep 2020 00:58:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="iMxy/CwF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726979AbgICA6O (ORCPT ); Wed, 2 Sep 2020 20:58:14 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:38782 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726377AbgICA6M (ORCPT ); Wed, 2 Sep 2020 20:58:12 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830sAfA125306 for ; Thu, 3 Sep 2020 00:58:10 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-2020-01-29; bh=0QSkfpQDVXHlI3HV+SL9baFFNUfmaNcbEVhjAA71MZc=; b=iMxy/CwFAYadLD2JCyf6fYajgsN9/qzOpio/2tNbud8PojPy65MzqPXbJWzkt71deBl/ VROTG3/Q6+NlZ9gBqI8r6pckpFgV/sBJGoagbx/ZrW4yikD2vOhkqKgcqtajhq1ApU7q Aj2bU6g2kwKabX5Lmn3HmpO071nrbdKHJKZ/6eSpz0JiukcT2fcnCvMzq0NqBC0LiIWs ZeqeqqSZk0Y2onRKFrpqwYRzlsfJNtVRcR5S2BQgCE+QHpDt6zXd9ikrUEA9Ogq7WFY8 R79I86HVy5gD59YDIX8n3QmvwP4zavbBRbl+oqKr+0XHbIbR+oIw31WhhcoWbGa4pgb3 dQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 337eymdu2h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:10 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830t7IH179630 for ; Thu, 3 Sep 2020 00:58:09 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 3380sv1674-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:09 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830w9uf017142 for ; Thu, 3 Sep 2020 00:58:09 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:08 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 01/15] btrfs: add btrfs_sysfs_add_device helper Date: Thu, 3 Sep 2020 08:57:37 +0800 Message-Id: <5f8aa8a03a1712adba0023fc1efa18623571c588.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_sysfs_add_devices_dir() adds device link and devid kobject (sysfs entries) for a device or all the devices in the btrfs_fs_devices. In preparation to add these sysfs entries for the seed as well, add a btrfs_sysfs_add_device() helper function and avoid code duplication. Signed-off-by: Anand Jain --- fs/btrfs/sysfs.c | 79 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 190e59152be5..3381a91d7deb 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1271,44 +1271,71 @@ static struct kobj_type devid_ktype = { .release = btrfs_release_devid_kobj, }; -int btrfs_sysfs_add_devices_dir(struct btrfs_fs_devices *fs_devices, - struct btrfs_device *one_device) +static int btrfs_sysfs_add_device(struct btrfs_device *device) { - int error = 0; - struct btrfs_device *dev; + int ret; unsigned int nofs_flag; + struct kobject *devices_kobj; + struct kobject *devinfo_kobj; - nofs_flag = memalloc_nofs_save(); - list_for_each_entry(dev, &fs_devices->devices, dev_list) { + /* + * make sure we use the fs_info::fs_devices to fetch the kobjects + * even for the seed fs_devices + */ + devices_kobj = device->fs_devices->fs_info->fs_devices->devices_kobj; + devinfo_kobj = device->fs_devices->fs_info->fs_devices->devinfo_kobj; + ASSERT(devices_kobj); + ASSERT(devinfo_kobj); - if (one_device && one_device != dev) - continue; + nofs_flag = memalloc_nofs_save(); - if (dev->bdev) { - struct hd_struct *disk; - struct kobject *disk_kobj; + if (device->bdev) { + struct hd_struct *disk; + struct kobject *disk_kobj; - disk = dev->bdev->bd_part; - disk_kobj = &part_to_dev(disk)->kobj; + disk = device->bdev->bd_part; + disk_kobj = &part_to_dev(disk)->kobj; - error = sysfs_create_link(fs_devices->devices_kobj, - disk_kobj, disk_kobj->name); - if (error) - break; + ret = sysfs_create_link(devices_kobj, disk_kobj, + disk_kobj->name); + if (ret) { + btrfs_warn(device->fs_info, + "sysfs create device link failed %d devid %llu", + ret, device->devid); + goto out; } + } - init_completion(&dev->kobj_unregister); - error = kobject_init_and_add(&dev->devid_kobj, &devid_ktype, - fs_devices->devinfo_kobj, "%llu", - dev->devid); - if (error) { - kobject_put(&dev->devid_kobj); - break; - } + init_completion(&device->kobj_unregister); + ret = kobject_init_and_add(&device->devid_kobj, &devid_ktype, + devinfo_kobj, "%llu", device->devid); + if (ret) { + kobject_put(&device->devid_kobj); + btrfs_warn(device->fs_info, + "sysfs devinfo init failed %d devid %llu", + ret, device->devid); } + +out: memalloc_nofs_restore(nofs_flag); + return ret; +} - return error; +int btrfs_sysfs_add_devices_dir(struct btrfs_fs_devices *fs_devices, + struct btrfs_device *one_device) +{ + int ret; + + if (one_device) + return btrfs_sysfs_add_device(one_device); + + list_for_each_entry(one_device, &fs_devices->devices, dev_list) { + ret = btrfs_sysfs_add_device(one_device); + if (ret) + return ret; + } + + return 0; } void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action) From patchwork Thu Sep 3 00:57:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752127 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 C8B23722 for ; Thu, 3 Sep 2020 00:58:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1F13207D3 for ; Thu, 3 Sep 2020 00:58:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="EmFRXVfX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727794AbgICA6Q (ORCPT ); Wed, 2 Sep 2020 20:58:16 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:39120 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726312AbgICA6O (ORCPT ); Wed, 2 Sep 2020 20:58:14 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830t8LO048110 for ; Thu, 3 Sep 2020 00:58:12 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-2020-01-29; bh=xt41m4RaskU4H5aFX0gKv69SQNFhf4FOaUH5pI/6+fk=; b=EmFRXVfX1dGdM2Xsvl529PyNuUc+LdblYza1wiL94yUnMOftSiFhy+m/j7Oyidc4l9i1 OvgICdNXNVaWhiSyWVp3p8YsGKRGewTKTe0cTRP/JY2ww3XjE8nM5M+BQEvVh/T+29HU S98hIzrPmVot2Du44dXKGwwt/9nTaLX2jyePrPvVcv50pHtEvYsC+2F+fAej7WNIj6TA 4f+qRn3W9oSedjgm9tnCme+0GCdMbHjBNvdMrgzKcFCoX0jCJFDeobUpt4Dg+QrA0TGf k+W5adoCnRWJUavE8Si0ILSrfigGv0pxylIxMZ8eGVNRgygSbJfLT1u95Te2hBWGbgJJ sw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 337eer5xa4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:12 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830sfoh036822 for ; Thu, 3 Sep 2020 00:58:12 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 3380x8ans7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:11 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0830wAlA027447 for ; Thu, 3 Sep 2020 00:58:11 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:10 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 02/15] btrfs: add btrfs_sysfs_remove_device helper Date: Thu, 3 Sep 2020 08:57:38 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=1 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_sysfs_remove_devices_dir() removes device link and devid kobject (sysfs entries) for a device or all the devices in the btrfs_fs_devices. In preparation to remove these sysfs entries for the seed as well, add a btrfs_sysfs_remove_device() helper function and avoid code duplication. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov Reviewed-by: Josef Bacik --- fs/btrfs/sysfs.c | 54 ++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 3381a91d7deb..241ec0ad0379 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1149,46 +1149,42 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info, return 0; } -/* when one_device is NULL, it removes all device links */ - -int btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices, - struct btrfs_device *one_device) +static void btrfs_sysfs_remove_device(struct btrfs_device *device) { struct hd_struct *disk; struct kobject *disk_kobj; + struct kobject *devices_kobj; - if (!fs_devices->devices_kobj) - return -EINVAL; + /* + * Seed fs_devices devices_kobj aren't used, fetch kobject from the + * fs_info::fs_devices. + */ + devices_kobj = device->fs_info->fs_devices->devices_kobj; + ASSERT(devices_kobj); - if (one_device) { - if (one_device->bdev) { - disk = one_device->bdev->bd_part; - disk_kobj = &part_to_dev(disk)->kobj; - sysfs_remove_link(fs_devices->devices_kobj, - disk_kobj->name); - } + if (device->bdev) { + disk = device->bdev->bd_part; + disk_kobj = &part_to_dev(disk)->kobj; + sysfs_remove_link(devices_kobj, disk_kobj->name); + } - kobject_del(&one_device->devid_kobj); - kobject_put(&one_device->devid_kobj); + kobject_del(&device->devid_kobj); + kobject_put(&device->devid_kobj); - wait_for_completion(&one_device->kobj_unregister); + wait_for_completion(&device->kobj_unregister); +} +/* when 2nd argument device is NULL, it removes all devices link */ +int btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices, + struct btrfs_device *one_device) +{ + if (one_device) { + btrfs_sysfs_remove_device(one_device); return 0; } - list_for_each_entry(one_device, &fs_devices->devices, dev_list) { - - if (one_device->bdev) { - disk = one_device->bdev->bd_part; - disk_kobj = &part_to_dev(disk)->kobj; - sysfs_remove_link(fs_devices->devices_kobj, - disk_kobj->name); - } - kobject_del(&one_device->devid_kobj); - kobject_put(&one_device->devid_kobj); - - wait_for_completion(&one_device->kobj_unregister); - } + list_for_each_entry(one_device, &fs_devices->devices, dev_list) + btrfs_sysfs_remove_device(one_device); return 0; } From patchwork Thu Sep 3 00:57:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752125 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 31C25722 for ; Thu, 3 Sep 2020 00:58:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A81F207D3 for ; Thu, 3 Sep 2020 00:58:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="kjNDej2c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727025AbgICA6P (ORCPT ); Wed, 2 Sep 2020 20:58:15 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:38818 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726877AbgICA6O (ORCPT ); Wed, 2 Sep 2020 20:58:14 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830sgMe125431 for ; Thu, 3 Sep 2020 00:58:13 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-2020-01-29; bh=PYnPc8IiVLp1la8aIs82hI+M1GDbV0csbJYs01Xo3qQ=; b=kjNDej2c50OEjkDuY3AQQhSKJeJVhFOZUZUFM4HE2+S7q1v2tYnXqSS45sODub6gxWB6 BFoT51+Oal8ARWzJ+PddFTtGb/dNqFRVFT2A2+Uc1fVvcvzrp9xo3q8NASXyHqSpBFuk 7WbPy4hT+5WmCyjav6CWq0IzRsxWjJVgX/DMWj1RkY3C1Z5Yqw/MVUYl0fIVg9+S8imH cEJAWUXjlDlszAXfUOXoLBx5yHaDYPkWAWJZ3vNXTW1g1Z0r1eR27kFvjHCU8HB/NURR d5XFaHQgKe2RdwbUIWbnZfO+wZdFg0zD2zlzmbiX40b88ShW81+IqUAhH6i9zjWEnFgR UA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 337eymdu2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:13 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830tFnH105201 for ; Thu, 3 Sep 2020 00:58:12 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 3380kqwus8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:12 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830wC63020195 for ; Thu, 3 Sep 2020 00:58:12 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:12 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 03/15] btrfs: btrfs_sysfs_remove_devices_dir drop return value Date: Thu, 3 Sep 2020 08:57:39 +0800 Message-Id: <5ff561bc46063a3fc7eb12a51600fe754b12ad0d.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 adultscore=0 mlxscore=0 suspectscore=1 malwarescore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_sysfs_remove_devices_dir() return value is unused declare it as void. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov Reviewed-by: Josef Bacik --- fs/btrfs/sysfs.c | 8 +++----- fs/btrfs/sysfs.h | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 241ec0ad0379..7448caf12c53 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1175,18 +1175,16 @@ static void btrfs_sysfs_remove_device(struct btrfs_device *device) } /* when 2nd argument device is NULL, it removes all devices link */ -int btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices, - struct btrfs_device *one_device) +void btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices, + struct btrfs_device *one_device) { if (one_device) { btrfs_sysfs_remove_device(one_device); - return 0; + return; } list_for_each_entry(one_device, &fs_devices->devices, dev_list) btrfs_sysfs_remove_device(one_device); - - return 0; } static ssize_t btrfs_devinfo_in_fs_metadata_show(struct kobject *kobj, diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h index 4217823e255c..bc995b0c1889 100644 --- a/fs/btrfs/sysfs.h +++ b/fs/btrfs/sysfs.h @@ -16,8 +16,8 @@ char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags); const char *btrfs_feature_set_name(enum btrfs_feature_set set); int btrfs_sysfs_add_devices_dir(struct btrfs_fs_devices *fs_devices, struct btrfs_device *one_device); -int btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices, - struct btrfs_device *one_device); +void btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices, + struct btrfs_device *one_device); int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs); void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs); void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices); From patchwork Thu Sep 3 00:57:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752129 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 74A88138A for ; Thu, 3 Sep 2020 00:58:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AD3B2080C for ; Thu, 3 Sep 2020 00:58:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="rYgA0+TU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727865AbgICA6X (ORCPT ); Wed, 2 Sep 2020 20:58:23 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:38840 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727122AbgICA6Q (ORCPT ); Wed, 2 Sep 2020 20:58:16 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830tcQ8125996 for ; Thu, 3 Sep 2020 00:58:15 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-2020-01-29; bh=Mlu6T6Cyogj5gjacEyCUIPPg2SxNoJbFfakFFXxQSxw=; b=rYgA0+TUMKXc29XCQid3fkiMYOE+UDcPW3Sc3PmPB5PDDeivBohBnjfJ1uqR/zHdUipu wIBMFJu66eVe1IMf0+sy17RmSBaT2b9Gw6RuLvnGMGTQmghYxbLwECDPBX3tQZB3wyLQ 9mVKCuNfaktIvA6YLID6Ks2kKiL5bLzAXHmF5wYSdx9E0z0/DW15pVYkohuTNxBwe92b T/83Q+/JvA3hczU4kg9Mih7QAJ3KZZDbDfqPF1Bf3QZXRaW/ujtvw4TA9kFNfcvkPkvm uZuao0NcrT+2BiAEDRgJ2R/ZdwQRAa0bW28/23P2Opsr+p+caFpoE1AhP2hcUmNRzzYn Jw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 337eymdu2u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:15 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830tFe6105177 for ; Thu, 3 Sep 2020 00:58:15 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 3380kqwusp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:15 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830wE0H017156 for ; Thu, 3 Sep 2020 00:58:14 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:13 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 04/15] btrfs: refactor btrfs_sysfs_add_devices_dir Date: Thu, 3 Sep 2020 08:57:40 +0800 Message-Id: <7f81bf1c3e80e7b558d17c1caf049e0c431033ab.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 adultscore=0 mlxscore=0 suspectscore=1 malwarescore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When we add device we need to add a device to the sysfs, so instead of using the btrfs_sysfs_add_devices_dir() 2nd argument to specify whether to add a device or all of fs_devices, call the helper function directly btrfs_sysfs_add_device() and thus make it non static. Signed-off-by: Anand Jain --- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/sysfs.c | 15 ++++++--------- fs/btrfs/sysfs.h | 3 +-- fs/btrfs/volumes.c | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 580e60fe07d0..979b40754cb4 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -512,7 +512,7 @@ static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0); up_write(&dev_replace->rwsem); - ret = btrfs_sysfs_add_devices_dir(tgt_device->fs_devices, tgt_device); + ret = btrfs_sysfs_add_device(tgt_device); if (ret) btrfs_err(fs_info, "kobj add dev failed %d", ret); diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 7448caf12c53..69a58666f351 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1265,7 +1265,7 @@ static struct kobj_type devid_ktype = { .release = btrfs_release_devid_kobj, }; -static int btrfs_sysfs_add_device(struct btrfs_device *device) +int btrfs_sysfs_add_device(struct btrfs_device *device) { int ret; unsigned int nofs_flag; @@ -1315,16 +1315,13 @@ static int btrfs_sysfs_add_device(struct btrfs_device *device) return ret; } -int btrfs_sysfs_add_devices_dir(struct btrfs_fs_devices *fs_devices, - struct btrfs_device *one_device) +int btrfs_sysfs_add_fs_devices(struct btrfs_fs_devices *fs_devices) { int ret; + struct btrfs_device *device; - if (one_device) - return btrfs_sysfs_add_device(one_device); - - list_for_each_entry(one_device, &fs_devices->devices, dev_list) { - ret = btrfs_sysfs_add_device(one_device); + list_for_each_entry(device, &fs_devices->devices, dev_list) { + ret = btrfs_sysfs_add_device(device); if (ret) return ret; } @@ -1419,7 +1416,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info) struct btrfs_fs_devices *fs_devs = fs_info->fs_devices; struct kobject *fsid_kobj = &fs_devs->fsid_kobj; - error = btrfs_sysfs_add_devices_dir(fs_devs, NULL); + error = btrfs_sysfs_add_fs_devices(fs_devs); if (error) return error; diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h index bc995b0c1889..56c29257b5a7 100644 --- a/fs/btrfs/sysfs.h +++ b/fs/btrfs/sysfs.h @@ -14,8 +14,7 @@ enum btrfs_feature_set { char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags); const char *btrfs_feature_set_name(enum btrfs_feature_set set); -int btrfs_sysfs_add_devices_dir(struct btrfs_fs_devices *fs_devices, - struct btrfs_device *one_device); +int btrfs_sysfs_add_device(struct btrfs_device *device); void btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices, struct btrfs_device *one_device); int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3f8bd1af29eb..8952f7031f4b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2599,7 +2599,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path orig_super_num_devices + 1); /* add sysfs device entry */ - btrfs_sysfs_add_devices_dir(fs_devices, device); + btrfs_sysfs_add_device(device); /* * we've got more storage, clear any full flags on the space From patchwork Thu Sep 3 00:57:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752131 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 27DF4138A for ; Thu, 3 Sep 2020 00:58:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 03DDC2080C for ; Thu, 3 Sep 2020 00:58:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="BaWF/W/5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727895AbgICA6X (ORCPT ); Wed, 2 Sep 2020 20:58:23 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57006 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726312AbgICA6S (ORCPT ); Wed, 2 Sep 2020 20:58:18 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830rdQ3176239 for ; Thu, 3 Sep 2020 00:58:17 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-2020-01-29; bh=7Fd1sqhiACZFey/pa/5URTigjJdrXzE+CZl0NbIc/EI=; b=BaWF/W/5KC25A+iC+b2NSON4tpts+cIjT3oRQuR4IZnJdM2qGKI4ggbAenMqcRVTLyoI uNmYkr62GxAdGGmXZgnSyvtpZIuUvEePHKul+77neK7rwDM076HdX7HNrjZc7awUDfms WhHofWxSKDK2uPwsocf2ENauKgwGfUV72gyTzxaODewtk/IFuKmcHD/a5tNgiALFKKPR O28B2JcmbZBz90r4wBm+6qTU3G7TQc/04FaqqNLHvijvmnuEfejdGhKNl2Xjt03UAE1v axvwE4lUaX3UVeBMMDXqN+wMwXL0x5UOrvLR1DfKNdUZqYhT1ACu3qzKm6EL+ZVNtZKf gw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 339dmn4b1e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:16 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830t5aA179389 for ; Thu, 3 Sep 2020 00:58:16 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 3380sv16aq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:16 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830wFxN020205 for ; Thu, 3 Sep 2020 00:58:15 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:15 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 05/15] btrfs: refactor btrfs_sysfs_remove_devices_dir Date: Thu, 3 Sep 2020 08:57:41 +0800 Message-Id: <86f446238ee7f610090b79342ecf472453d9da4c.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=3 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Similar to btrfs_sysfs_add_devices_dir()'s refactor, refactor btrfs_sysfs_remove_devices_dir() so that we don't have to use the 2nd argument to indicate whether to free all devices or just one device. Make btrfs_sysfs_remove_device() global as device operations outside of sysfs.c now calls this instead of btrfs_sysfs_remove_devices_dir(). btrfs_sysfs_remove_devices_dir() is renamed to btrfs_sysfs_remove_fs_devices() to suite its new role. Now, no one outside of sysfs.c calls btrfs_sysfs_remove_fs_devices() so it is redeclared as static. And the same function had to be moved before its first caller. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov --- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/sysfs.c | 27 +++++++++++---------------- fs/btrfs/sysfs.h | 3 +-- fs/btrfs/volumes.c | 8 ++++---- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 979b40754cb4..a7b1ad4e5706 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -743,7 +743,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, mutex_unlock(&fs_info->fs_devices->device_list_mutex); /* replace the sysfs entry */ - btrfs_sysfs_remove_devices_dir(fs_info->fs_devices, src_device); + btrfs_sysfs_remove_device(src_device); btrfs_sysfs_update_devid(tgt_device); if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &src_device->dev_state)) btrfs_scratch_superblocks(fs_info, src_device->bdev, diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 69a58666f351..9853b9acd4bd 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -935,6 +935,14 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs) } } +void btrfs_sysfs_remove_fs_devices(struct btrfs_fs_devices *fs_devices) +{ + struct btrfs_device *device; + + list_for_each_entry(device, &fs_devices->devices, dev_list) + btrfs_sysfs_remove_device(device); +} + void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info) { struct kobject *fsid_kobj = &fs_info->fs_devices->fsid_kobj; @@ -962,7 +970,7 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info) addrm_unknown_feature_attrs(fs_info, false); sysfs_remove_group(fsid_kobj, &btrfs_feature_attr_group); sysfs_remove_files(fsid_kobj, btrfs_attrs); - btrfs_sysfs_remove_devices_dir(fs_info->fs_devices, NULL); + btrfs_sysfs_remove_fs_devices(fs_info->fs_devices); } static const char * const btrfs_feature_set_names[FEAT_MAX] = { @@ -1149,7 +1157,7 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info, return 0; } -static void btrfs_sysfs_remove_device(struct btrfs_device *device) +void btrfs_sysfs_remove_device(struct btrfs_device *device) { struct hd_struct *disk; struct kobject *disk_kobj; @@ -1174,19 +1182,6 @@ static void btrfs_sysfs_remove_device(struct btrfs_device *device) wait_for_completion(&device->kobj_unregister); } -/* when 2nd argument device is NULL, it removes all devices link */ -void btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices, - struct btrfs_device *one_device) -{ - if (one_device) { - btrfs_sysfs_remove_device(one_device); - return; - } - - list_for_each_entry(one_device, &fs_devices->devices, dev_list) - btrfs_sysfs_remove_device(one_device); -} - static ssize_t btrfs_devinfo_in_fs_metadata_show(struct kobject *kobj, struct kobj_attribute *a, char *buf) @@ -1422,7 +1417,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info) error = sysfs_create_files(fsid_kobj, btrfs_attrs); if (error) { - btrfs_sysfs_remove_devices_dir(fs_devs, NULL); + btrfs_sysfs_remove_fs_devices(fs_devs); return error; } diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h index 56c29257b5a7..bacef43f7267 100644 --- a/fs/btrfs/sysfs.h +++ b/fs/btrfs/sysfs.h @@ -15,8 +15,7 @@ enum btrfs_feature_set { char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags); const char *btrfs_feature_set_name(enum btrfs_feature_set set); int btrfs_sysfs_add_device(struct btrfs_device *device); -void btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices, - struct btrfs_device *one_device); +void btrfs_sysfs_remove_device(struct btrfs_device *device); int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs); void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs); void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 8952f7031f4b..9921b43ef839 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2040,7 +2040,7 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info, } int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path, - u64 devid) + u64 devid) { struct btrfs_device *device; struct btrfs_fs_devices *cur_devices; @@ -2144,7 +2144,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path, if (device->bdev) { cur_devices->open_devices--; /* remove sysfs entry */ - btrfs_sysfs_remove_devices_dir(fs_devices, device); + btrfs_sysfs_remove_device(device); } num_devices = btrfs_super_num_devices(fs_info->super_copy) - 1; @@ -2245,7 +2245,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev) mutex_lock(&fs_devices->device_list_mutex); - btrfs_sysfs_remove_devices_dir(fs_devices, tgtdev); + btrfs_sysfs_remove_device(tgtdev); if (tgtdev->bdev) fs_devices->open_devices--; @@ -2680,7 +2680,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path return ret; error_sysfs: - btrfs_sysfs_remove_devices_dir(fs_devices, device); + btrfs_sysfs_remove_device(device); mutex_lock(&fs_info->fs_devices->device_list_mutex); mutex_lock(&fs_info->chunk_mutex); list_del_rcu(&device->dev_list); From patchwork Thu Sep 3 00:57:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752147 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 DFD9F138A for ; Thu, 3 Sep 2020 00:58:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C76DB204EC for ; Thu, 3 Sep 2020 00:58:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="wVU0j4GT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727921AbgICA6Z (ORCPT ); Wed, 2 Sep 2020 20:58:25 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57030 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbgICA6U (ORCPT ); Wed, 2 Sep 2020 20:58:20 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830rcgW176210 for ; Thu, 3 Sep 2020 00:58:18 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-2020-01-29; bh=cNUY226Y6LnsBJdyW9ehkLDxsUdp44MJRKw77DRk+9A=; b=wVU0j4GTmlJh8tQ13fLn34UasEnUVJFmazvhfiTk7Y02Z4Vlk2uCSfmuva9qks2B4I9C Rhc8UfzOqj9F3TTe80AQ4v7C0+QKUvQindHOdKn6dlyPnglr6p+hSpXidungKgEdV/Ol 9PHX/Df3g4fuT/+2Xn9Kh1TxXY9PmDBrEOb2WeeK9h70g8E66zr1p9d6q/yUvhPrkC1v NczET0fqsWzfaThdNbewaYPhw1SABy1BFjhT/KmqCnuuV6SPeVWxl9+Z0hvy2PkQ01Jv DQmnnCoyJWSJv/V1HLrGE7x1Y33zGPTYttW7d4mCG+r+J63gjL35oO7IyBgbkdUQuyn/ pQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 339dmn4b1g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:18 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830sfVv036864 for ; Thu, 3 Sep 2020 00:58:17 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 3380x8anuv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:17 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0830wHCV020930 for ; Thu, 3 Sep 2020 00:58:17 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:17 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 06/15] btrfs: initialize sysfs devid and device link for seed device Date: Thu, 3 Sep 2020 08:57:42 +0800 Message-Id: <0b11ff81143ebfcaa1da26296ee12afcfe41dbb5.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=1 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=1 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The following test case leads to null kobject-being-freed error. mount seed /mnt add sprout to /mnt umount /mnt mount sprout to /mnt delete seed kobject: '(null)' (00000000dd2b87e4): is not initialized, yet kobject_put() is being called. WARNING: CPU: 1 PID: 15784 at lib/kobject.c:736 kobject_put+0x80/0x350 RIP: 0010:kobject_put+0x80/0x350 :: Call Trace: btrfs_sysfs_remove_devices_dir+0x6e/0x160 [btrfs] btrfs_rm_device.cold+0xa8/0x298 [btrfs] btrfs_ioctl+0x206c/0x22a0 [btrfs] ksys_ioctl+0xe2/0x140 __x64_sys_ioctl+0x1e/0x29 do_syscall_64+0x96/0x150 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f4047c6288b :: This is because, at the end of the seed device-delete, we try to remove the seed's devid sysfs entry. But for the seed devices under the sprout fs, we don't initialize the devid kobject yet. So this patch initializes the seed device devid kobject and the device link in the sysfs. This takes care of the Warning. Signed-off-by: Anand Jain --- fs/btrfs/sysfs.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 9853b9acd4bd..98ce955a0879 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -938,9 +938,15 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs) void btrfs_sysfs_remove_fs_devices(struct btrfs_fs_devices *fs_devices) { struct btrfs_device *device; + struct btrfs_fs_devices *seed; list_for_each_entry(device, &fs_devices->devices, dev_list) btrfs_sysfs_remove_device(device); + + list_for_each_entry(seed, &fs_devices->seed_list, seed_list) { + list_for_each_entry(device, &seed->devices, dev_list) + btrfs_sysfs_remove_device(device); + } } void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info) @@ -1314,6 +1320,7 @@ int btrfs_sysfs_add_fs_devices(struct btrfs_fs_devices *fs_devices) { int ret; struct btrfs_device *device; + struct btrfs_fs_devices *seed; list_for_each_entry(device, &fs_devices->devices, dev_list) { ret = btrfs_sysfs_add_device(device); @@ -1321,6 +1328,14 @@ int btrfs_sysfs_add_fs_devices(struct btrfs_fs_devices *fs_devices) return ret; } + list_for_each_entry(seed, &fs_devices->seed_list, seed_list) { + list_for_each_entry(device, &seed->devices, dev_list) { + ret = btrfs_sysfs_add_device(device); + if (ret) + return ret; + } + } + return 0; } From patchwork Thu Sep 3 00:57:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752133 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 7CC2F722 for ; Thu, 3 Sep 2020 00:58:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6552B207D3 for ; Thu, 3 Sep 2020 00:58:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="vIFvKxo3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727902AbgICA6Y (ORCPT ); Wed, 2 Sep 2020 20:58:24 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57050 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727818AbgICA6V (ORCPT ); Wed, 2 Sep 2020 20:58:21 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830swSh176869 for ; Thu, 3 Sep 2020 00:58:20 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-2020-01-29; bh=1DxNN5ByH8BK4fUsgKje1MSVlnbK7TsDgaBoY9hsDKE=; b=vIFvKxo3dn22HviV79zt/qMOTDsgAWPeRkBH+xI5uy2mM0fTbOrsocAUz3LfImMzJy0d sGtyHXhc1+kZDJbbxUXquRglJnMVp2aeLCBqSaoZkah4MDel0gvrR6TEZEjUg8Pmf36Y FcXcbtZPffLXKzK0omnoqIIX0mzhJeewMi4z3siJClTay9rTzADHkntWPxeasA6BWzWG N5r/oJKeAF37a0kV0tAGlILsz9aTikDVUPrH3FsLlYtOEHxHBCqR/r5NLzFX1hjoW2vs 7cxi8Uq4afqe8opaSTjIJO7sQ8e4SYFr8Sr2x5TdDXBP+LxbcvbxyHnHwKWytIpWymmY ZA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 339dmn4b1j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:20 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830tEVN105147 for ; Thu, 3 Sep 2020 00:58:19 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 3380kqwuuq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:19 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830wIuN020208 for ; Thu, 3 Sep 2020 00:58:18 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:18 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 07/15] btrfs: handle fail path for btrfs_sysfs_add_fs_devices Date: Thu, 3 Sep 2020 08:57:43 +0800 Message-Id: <32779bc42ae40eea707cc585624724ac91cd967e.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 adultscore=0 mlxscore=0 suspectscore=1 malwarescore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=1 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_sysfs_add_fs_devices() is called by btrfs_sysfs_add_mounted(). btrfs_sysfs_add_mounted() assumes that btrfs_sysfs_add_fs_devices() will either add sysfs entries for all the devices or none. So this patch keeps up to its caller expecatation and cleans up the created sysfs entries if it has to fail at some device in the list. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov --- fs/btrfs/sysfs.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 98ce955a0879..a5a73b21d4af 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1182,10 +1182,12 @@ void btrfs_sysfs_remove_device(struct btrfs_device *device) sysfs_remove_link(devices_kobj, disk_kobj->name); } - kobject_del(&device->devid_kobj); - kobject_put(&device->devid_kobj); + if (device->devid_kobj.state_initialized) { + kobject_del(&device->devid_kobj); + kobject_put(&device->devid_kobj); + wait_for_completion(&device->kobj_unregister); + } - wait_for_completion(&device->kobj_unregister); } static ssize_t btrfs_devinfo_in_fs_metadata_show(struct kobject *kobj, @@ -1324,19 +1326,21 @@ int btrfs_sysfs_add_fs_devices(struct btrfs_fs_devices *fs_devices) list_for_each_entry(device, &fs_devices->devices, dev_list) { ret = btrfs_sysfs_add_device(device); - if (ret) - return ret; + goto fail; } list_for_each_entry(seed, &fs_devices->seed_list, seed_list) { list_for_each_entry(device, &seed->devices, dev_list) { ret = btrfs_sysfs_add_device(device); - if (ret) - return ret; + goto fail; } } return 0; + +fail: + btrfs_sysfs_remove_fs_devices(fs_devices); + return ret; } void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action) From patchwork Thu Sep 3 00:57:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752135 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 CDB5B138A for ; Thu, 3 Sep 2020 00:58:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6685207D3 for ; Thu, 3 Sep 2020 00:58:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="RfO6Gxy3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbgICA61 (ORCPT ); Wed, 2 Sep 2020 20:58:27 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:38884 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727835AbgICA6Y (ORCPT ); Wed, 2 Sep 2020 20:58:24 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830tcQA125996 for ; Thu, 3 Sep 2020 00:58:21 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-2020-01-29; bh=8VIBReliT6fRFTOu0YrPSLqc/59E8HQdE5cDVDgUKHs=; b=RfO6Gxy30LGgEclvcEGtSm6jBJkpt/ZvDXrXQn51RT5iDqXxf2dMjOFy4KMGsg9pFwxl HMUsrutF2Y63ERFgI7ZdMfCxW2njRG02160iLdElZGh/4lv7qYzrt9uVlCRI6lYbQxAZ MCtSK2dB2BAWvdhgwVYukCJg/SxWnL5F2XSlEoY8eIy/2q2KDjHgUMbFukZU2ZEIwIO3 uFQtcmXP/GSP4/F5hLkGgjvBKSYcBjo8DUHfDzxyJ0X09HXAEDlkhVnBY546oeADnQ0A b8ctghqS0yMuosMmRsz94nfYYUUWwxxUyBHr4zzi4GEGHEw1pfXlQ3XMb041/NR7kkO5 yA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 337eymdu33-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:21 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830sfb7036876 for ; Thu, 3 Sep 2020 00:58:20 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 3380x8anvt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:20 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830wKXT020211 for ; Thu, 3 Sep 2020 00:58:20 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:19 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 08/15] btrfs: reada: use sprout device_list_mutex Date: Thu, 3 Sep 2020 08:57:44 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=1 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On an fs mounted using a sprout-device, the seed fs_devices are maintained in a linked list under fs_info->fs_devices. Each seed's fs_devices also have device_list_mutex initialized to protect against the potential race with delete threads. But the delete thread (at btrfs_rm_device()) is holding the fs_info::fs_devices::device_list_mutex mutex which is sprout's device_list_mutex instead of seed's device_list_mutex. Moreover, there aren't any significient benefits in using the seed::device_list_mutex instead of sprout::device_list_mutex. So this patch converts them of using the seed::device_list_mutex to sprout::device_list_mutex. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov --- fs/btrfs/reada.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c index e20972230823..9d4f5316a7e8 100644 --- a/fs/btrfs/reada.c +++ b/fs/btrfs/reada.c @@ -776,13 +776,11 @@ static int reada_start_for_fsdevs(struct btrfs_fs_devices *fs_devices) do { enqueued = 0; - mutex_lock(&fs_devices->device_list_mutex); list_for_each_entry(device, &fs_devices->devices, dev_list) { if (atomic_read(&device->reada_in_flight) < MAX_IN_FLIGHT) enqueued += reada_start_machine_dev(device); } - mutex_unlock(&fs_devices->device_list_mutex); total += enqueued; } while (enqueued && total < 10000); @@ -795,10 +793,13 @@ static void __reada_start_machine(struct btrfs_fs_info *fs_info) int i; u64 enqueued = 0; + mutex_lock(&fs_devices->device_list_mutex); + enqueued += reada_start_for_fsdevs(fs_devices); list_for_each_entry(seed_devs, &fs_devices->seed_list, seed_list) enqueued += reada_start_for_fsdevs(seed_devs); + mutex_unlock(&fs_devices->device_list_mutex); if (enqueued == 0) return; From patchwork Thu Sep 3 00:57:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752149 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 4D705138A for ; Thu, 3 Sep 2020 01:00:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 352B5206E7 for ; Thu, 3 Sep 2020 01:00:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jp2I9vdO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726853AbgICBA0 (ORCPT ); Wed, 2 Sep 2020 21:00:26 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:40018 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726654AbgICBAY (ORCPT ); Wed, 2 Sep 2020 21:00:24 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08310NrY141575 for ; Thu, 3 Sep 2020 01:00: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-2020-01-29; bh=+WVaYgRoxP0jt5qAyy/dn2WCTdvFIpE5A6qElxhGBCA=; b=jp2I9vdOFl+eOzf2YCZhqnpBZpUXxJgVDwMjwt2AD8+gfpkdOBfCjPytpYq53mJsOFZZ qYBeplkBdY+glssqexXlYxzbpyUrO+YkKY4iZ0PvnAah0vc4K7nRJg6n39SFilQkmiHR pxKLMKai9wZss/5OAIUW75IhU0zzNqqfqJEcaqE/H9vxDvGu9GeUFNCOhK5c698+z5SQ iTuvGFepBzb81pWTtMh8cO50m/chhbev9+qVu2EXJ+eF/SpdbI6CheY5SqwP+jIX3eks 5jZC6JM0RrKbR2LyP0hKYyHnKCbrbNleTX7aQRpQodr8yPvN7T2IXxbjAGgbtk98kvGU TA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 337eymdu70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 01:00:23 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830t6xM179484 for ; Thu, 3 Sep 2020 00:58:23 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 3380sv16d7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:22 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830wMmf020215 for ; Thu, 3 Sep 2020 00:58:22 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:21 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 09/15] btrfs: btrfs_init_devices_late: use sprout device_list_mutex Date: Thu, 3 Sep 2020 08:57:45 +0800 Message-Id: <21d594f31a8d674a12af309ca051b0eedf973b1e.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030005 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In a mounted sprout FS, all threads now are using the sprout::device_list_mutex, and this is the only piece of code using the seed::device_list_mutex. This patch converts to use the sprouts fs_info->fs_devices->device_list_mutex. The same reasoning holds true here, that device delete is holding the sprout::device_list_mutex. Signed-off-by: Anand Jain --- fs/btrfs/volumes.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9921b43ef839..7639a048c6cf 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -7184,16 +7184,14 @@ void btrfs_init_devices_late(struct btrfs_fs_info *fs_info) mutex_lock(&fs_devices->device_list_mutex); list_for_each_entry(device, &fs_devices->devices, dev_list) device->fs_info = fs_info; - mutex_unlock(&fs_devices->device_list_mutex); list_for_each_entry(seed_devs, &fs_devices->seed_list, seed_list) { - mutex_lock(&seed_devs->device_list_mutex); list_for_each_entry(device, &seed_devs->devices, dev_list) device->fs_info = fs_info; - mutex_unlock(&seed_devs->device_list_mutex); seed_devs->fs_info = fs_info; } + mutex_unlock(&fs_devices->device_list_mutex); } static u64 btrfs_dev_stats_value(const struct extent_buffer *eb, From patchwork Thu Sep 3 00:57:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752145 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 675F2138A for ; Thu, 3 Sep 2020 00:58:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F89B207D3 for ; Thu, 3 Sep 2020 00:58:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Kk5c8+Gm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728014AbgICA6c (ORCPT ); Wed, 2 Sep 2020 20:58:32 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:39232 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727932AbgICA60 (ORCPT ); Wed, 2 Sep 2020 20:58:26 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830u7T0048649 for ; Thu, 3 Sep 2020 00:58:25 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-2020-01-29; bh=Bx1/dRTyLHkIWOzbPa3Ysamw9/XsHqBDt3QfudzOZd8=; b=Kk5c8+GmIlO6RaOuSV8MTQ9BcmQBTkZRnG1zmGnG65vhJnrT9wNwCOoMQWWbpw7AtIfq PHQv1Zcy6DwfTA06B2D217tDhX09a5NDL3vnhC6n8UgGulD+7B7DgHNKcSYvbmnEGe/J 0iomUOOf7oKb2UNG5fKHbB3f+JvbDGcf7eiYjAjl9HCbRovrZX7xhb6P+qmGE2HBr6ut 4YFJIP3MSktln9YR/JGHMEMc/Hcg5nSwo3lGdZK2zW7bR5gF2okJG5oSL0juQ5iJl06M AU/TXfBVJXyzEdNDkoxsNT7F6p2EV9w1x3IRJmJiUo8KERbnD7vTyPh4u88KOqQK8TbU xQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 337eer5xaq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:25 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830tEqp105151 for ; Thu, 3 Sep 2020 00:58:24 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 3380kqwuw0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:24 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830wNha017171 for ; Thu, 3 Sep 2020 00:58:23 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:23 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 10/15] btrfs: open code list_head pointer in btrfs_init_dev_replace_tgtdev Date: Thu, 3 Sep 2020 08:57:46 +0800 Message-Id: <25473568cb1a09ef14821a554055d9dffb009d3f.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 adultscore=0 mlxscore=0 suspectscore=1 malwarescore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In the function btrfs_init_dev_replace_tgtdev(), the local variable struct list_head *devices is used only once, instead just open code the same. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov --- fs/btrfs/dev-replace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index a7b1ad4e5706..aea1c782c009 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -224,7 +224,6 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, { struct btrfs_device *device; struct block_device *bdev; - struct list_head *devices; struct rcu_string *name; u64 devid = BTRFS_DEV_REPLACE_DEVID; int ret = 0; @@ -244,8 +243,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, sync_blockdev(bdev); - devices = &fs_info->fs_devices->devices; - list_for_each_entry(device, devices, dev_list) { + list_for_each_entry(device, &fs_info->fs_devices->devices, dev_list) { if (device->bdev == bdev) { btrfs_err(fs_info, "target device is in the filesystem!"); From patchwork Thu Sep 3 00:57:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752137 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 AEA92722 for ; Thu, 3 Sep 2020 00:58:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 972B0207D3 for ; Thu, 3 Sep 2020 00:58:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="mpDkDTk+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727992AbgICA6b (ORCPT ); Wed, 2 Sep 2020 20:58:31 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:39236 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727951AbgICA61 (ORCPT ); Wed, 2 Sep 2020 20:58:27 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830tEUE048135 for ; Thu, 3 Sep 2020 00:58: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-2020-01-29; bh=VPB0h9o5bW+0d8HSJaqN6I2cDStj8lVXrh26oPtPXVE=; b=mpDkDTk+xXU2Orb2bFl/YxEzXOi+eI0upzUAxFODwplqrf0lbRuoxeDPRq9NthcZZ17b E7KbEgkfiRl+sFBvZvyK02fA/EhiKjWYmZT6h3sqCP2gNqAI/TvYVHqRKeEZqJcsUDpv xtl9PGOaIZJeqmf+EqwkbsqtmDnCcEHJZM0Pw3XI7Aj8nV/SzD4OhVYvItk3NQUhu+gA BSha4IJ4HfyK/7qGavgewAZIIWGZQct4D1jL5AOC6AsfCd+Mel2vsCQbhvIM4iUESe9B iWPbfmqYsVXpCW4giF3fEz0Y/dpfXiSJx208ZmYKHVAYRGUqElHVY45wLb8o1LpgAf0O 7g== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 337eer5xar-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:26 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830t56m179422 for ; Thu, 3 Sep 2020 00:58:26 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 3380sv16en-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:26 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830wP3O020220 for ; Thu, 3 Sep 2020 00:58:25 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:24 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 11/15] btrfs: cleanup btrfs_remove_chunk Date: Thu, 3 Sep 2020 08:57:47 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In the function btrfs_remove_chunk() remove the local variable %fs_devices, instead use the assigned pointer directly. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov --- fs/btrfs/volumes.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 7639a048c6cf..3e7a7d94a211 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2922,7 +2922,6 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset) struct map_lookup *map; u64 dev_extent_len = 0; int i, ret = 0; - struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; em = btrfs_get_chunk_map(fs_info, chunk_offset, 1); if (IS_ERR(em)) { @@ -2944,14 +2943,14 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset) * a device replace operation that replaces the device object associated * with map stripes (dev-replace.c:btrfs_dev_replace_finishing()). */ - mutex_lock(&fs_devices->device_list_mutex); + mutex_lock(&fs_info->fs_devices->device_list_mutex); for (i = 0; i < map->num_stripes; i++) { struct btrfs_device *device = map->stripes[i].dev; ret = btrfs_free_dev_extent(trans, device, map->stripes[i].physical, &dev_extent_len); if (ret) { - mutex_unlock(&fs_devices->device_list_mutex); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); btrfs_abort_transaction(trans, ret); goto out; } @@ -2967,12 +2966,12 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset) ret = btrfs_update_device(trans, device); if (ret) { - mutex_unlock(&fs_devices->device_list_mutex); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); btrfs_abort_transaction(trans, ret); goto out; } } - mutex_unlock(&fs_devices->device_list_mutex); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); ret = btrfs_free_chunk(trans, chunk_offset); if (ret) { From patchwork Thu Sep 3 00:57:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752151 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 843F8109B for ; Thu, 3 Sep 2020 01:00:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69CF6207D3 for ; Thu, 3 Sep 2020 01:00:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="bRlbMcWV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726994AbgICBAa (ORCPT ); Wed, 2 Sep 2020 21:00:30 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:40054 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726654AbgICBA3 (ORCPT ); Wed, 2 Sep 2020 21:00:29 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08310SOn141602 for ; Thu, 3 Sep 2020 01:00: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-2020-01-29; bh=lOVd1xg+WJTqWPeIJPYE4RY3UP9YAL44d8XEVvWhsuY=; b=bRlbMcWVrLuXKqzeTTu5IfUaZvFwSLarscRpOkJkDslEVEjYiXEdNva2W/aFVX2k4NVj 97cyen/YzxQ/2wG3Y+Sj49fUenvoSQVpkR49wOXoLRJgKk7LN2oMx4/9qfCr7y7PZxhK uX5O+bYG73pcYDkBsh5qUnhUWXYuDRsw11Wz9pnaHsM/jZ4vdAHBEWi0qWE6bZbQNVlh 0PwFuKW7PpteHT0IoNXIZe5LtKQS3tO//+IbksuxbzKlRn8MwB44lZl0Z50yW8wJtqnN qmXwYmK3YGNsrGjLDAJj2yMVFqaI7VGeBYXM3NnLJDOYu6p+95460DakdZ5DqoaKxj6G FA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 337eymdu72-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 01:00:28 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830t6mb179516 for ; Thu, 3 Sep 2020 00:58:27 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 3380sv16fm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:27 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0830wQap027559 for ; Thu, 3 Sep 2020 00:58:26 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:26 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 12/15] btrfs: cleanup btrfs_assign_next_active_device() Date: Thu, 3 Sep 2020 08:57:48 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030005 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Cleanup btrfs_assign_next_active_device(), drop %this_dev. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov --- fs/btrfs/volumes.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3e7a7d94a211..c8b0d9eb4468 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1961,16 +1961,13 @@ static struct btrfs_device * btrfs_find_next_active_device( * this_dev) which is active. */ void __cold btrfs_assign_next_active_device(struct btrfs_device *device, - struct btrfs_device *this_dev) + struct btrfs_device *next_device) { struct btrfs_fs_info *fs_info = device->fs_info; - struct btrfs_device *next_device; - if (this_dev) - next_device = this_dev; - else + if (!next_device) next_device = btrfs_find_next_active_device(fs_info->fs_devices, - device); + device); ASSERT(next_device); if (fs_info->sb->s_bdev && From patchwork Thu Sep 3 00:57:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752139 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 7A8EB138A for ; Thu, 3 Sep 2020 00:58:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64219207D3 for ; Thu, 3 Sep 2020 00:58:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="i0tXzmkY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728027AbgICA6d (ORCPT ); Wed, 2 Sep 2020 20:58:33 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:39272 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727986AbgICA6b (ORCPT ); Wed, 2 Sep 2020 20:58:31 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830su21048033 for ; Thu, 3 Sep 2020 00:58:30 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-2020-01-29; bh=ngkeAJIBSiQmuqukPm1sf9idiSNbBa5zZ7EEexb9BuY=; b=i0tXzmkYu/tFDhrWKZ3bJUDJzv2eZqta2c4ye6d5Vkmr4HSk2Mti591SiA+0zJQ/gQ8G M/dQXwnHVsV7NVagyg4fbY5ZHgjjeG3ifpoxVSuzg62TrxZRSunxlV5pZSO034oryoNW KUuYA+vacizQpTS5Z86giDmBxk39/H0b55Ne7EMZyV8+IKVLQ0gqq7azB2kyWfGTq/+p BYA7XEYup/17YQprPltFk+2g4eHjuQ0J+M/Kw1dP5/7hdCmNJiANstbmLFIL1gVo1sN2 9DFdoc0AgqKN/nTdGDd6sWgOG3uUpHxOT+WSthdLQ3glb02nGGy8Bwn4t9SY+BmzOYxN ww== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 337eer5xav-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:30 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830seKF036788 for ; Thu, 3 Sep 2020 00:58:29 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 3380x8anyw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:29 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0830wSHh027565 for ; Thu, 3 Sep 2020 00:58:28 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:27 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 13/15] btrfs: cleanup unnecessary goto in open_seed_device Date: Thu, 3 Sep 2020 08:57:49 +0800 Message-Id: <5a03a0bc3d94719c0587f6f62276bbc95838cc05.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=3 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org open_seed_devices() does goto to just return. So drop goto and just return instead. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov --- fs/btrfs/volumes.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c8b0d9eb4468..dc81646b13c0 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6741,19 +6741,17 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info, ret = open_fs_devices(fs_devices, FMODE_READ, fs_info->bdev_holder); if (ret) { free_fs_devices(fs_devices); - fs_devices = ERR_PTR(ret); - goto out; + return ERR_PTR(ret); } if (!fs_devices->seeding) { close_fs_devices(fs_devices); free_fs_devices(fs_devices); - fs_devices = ERR_PTR(-EINVAL); - goto out; + return ERR_PTR(-EINVAL); } list_add_tail(&fs_devices->seed_list, &fs_info->fs_devices->seed_list); -out: + return fs_devices; } From patchwork Thu Sep 3 00:57:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752141 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 318B0138A for ; Thu, 3 Sep 2020 00:58:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 19475204EC for ; Thu, 3 Sep 2020 00:58:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="FHSYMiL2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728043AbgICA6e (ORCPT ); Wed, 2 Sep 2020 20:58:34 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57150 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727991AbgICA6c (ORCPT ); Wed, 2 Sep 2020 20:58:32 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830rh0e176256 for ; Thu, 3 Sep 2020 00:58:30 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-2020-01-29; bh=Vc083YnFtu97ZqoePL72twNfwsR+MAZn8t1SUl/+4qU=; b=FHSYMiL2/ABdnbZgavmi1uogXLLiLlnEQqRhJ8rO3OUgoWHW/tVbym30roDKm6Dw4nb4 VdaMWroa1nJ9fzyzIP5KZenZPA0aO8oycgRMULGADOb+6XG/ge5LV6RwzKn9/5nuwlCb t/2+bnLDIxoba6eoBYc1DgJoqhOoQsuLHqwPN4UrPwKJp0mV9YLB6Oj+1hAuqdy4ES9s dyFI9kEsbs7g0UUdDWdgLHqrWIw8dQpdTuWs0+/fbmmmtU7PXN/VnIGbV4aXEOG5L20p POpnodAAV4Bol7YObQIVPAdwtFFQxhWfXpjNzkCF3ZmKWa2iYreE370Lbvqk/tjvMAid cg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 339dmn4b20-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:30 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830t5Qb179397 for ; Thu, 3 Sep 2020 00:58:30 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 3380sv16h1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:30 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0830wTqY017189 for ; Thu, 3 Sep 2020 00:58:29 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:29 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 14/15] btrfs: btrfs_dev_replace_update_device_in_mapping_tree drop file global declare Date: Thu, 3 Sep 2020 08:57:50 +0800 Message-Id: <30bd83fdbebb6d8f2f3eedf7b7861363af927145.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=3 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There isn't any convoluted child functions inside the btrfs_dev_replace_update_device_in_mapping_tree() function. With the function moved before where it is called, we can drop its file local declare. No functional changes. Signed-off-by: Anand Jain Reviewed-by: Nikolay Borisov --- fs/btrfs/dev-replace.c | 56 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index aea1c782c009..656d8ba642af 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -64,10 +64,6 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, int scrub_ret); -static void btrfs_dev_replace_update_device_in_mapping_tree( - struct btrfs_fs_info *fs_info, - struct btrfs_device *srcdev, - struct btrfs_device *tgtdev); static int btrfs_dev_replace_kthread(void *data); int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info) @@ -597,6 +593,32 @@ static void btrfs_rm_dev_replace_unblocked(struct btrfs_fs_info *fs_info) wake_up(&fs_info->dev_replace.replace_wait); } +static void btrfs_dev_replace_update_device_in_mapping_tree( + struct btrfs_fs_info *fs_info, + struct btrfs_device *srcdev, + struct btrfs_device *tgtdev) +{ + struct extent_map_tree *em_tree = &fs_info->mapping_tree; + struct extent_map *em; + struct map_lookup *map; + u64 start = 0; + int i; + + write_lock(&em_tree->lock); + do { + em = lookup_extent_mapping(em_tree, start, (u64)-1); + if (!em) + break; + map = em->map_lookup; + for (i = 0; i < map->num_stripes; i++) + if (srcdev == map->stripes[i].dev) + map->stripes[i].dev = tgtdev; + start = em->start + em->len; + free_extent_map(em); + } while (start); + write_unlock(&em_tree->lock); +} + static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, int scrub_ret) { @@ -759,32 +781,6 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, return 0; } -static void btrfs_dev_replace_update_device_in_mapping_tree( - struct btrfs_fs_info *fs_info, - struct btrfs_device *srcdev, - struct btrfs_device *tgtdev) -{ - struct extent_map_tree *em_tree = &fs_info->mapping_tree; - struct extent_map *em; - struct map_lookup *map; - u64 start = 0; - int i; - - write_lock(&em_tree->lock); - do { - em = lookup_extent_mapping(em_tree, start, (u64)-1); - if (!em) - break; - map = em->map_lookup; - for (i = 0; i < map->num_stripes; i++) - if (srcdev == map->stripes[i].dev) - map->stripes[i].dev = tgtdev; - start = em->start + em->len; - free_extent_map(em); - } while (start); - write_unlock(&em_tree->lock); -} - /* * Read progress of device replace status according to the state and last * stored position. The value format is the same as for From patchwork Thu Sep 3 00:57:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11752143 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 BE97B722 for ; Thu, 3 Sep 2020 00:58:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5749204EC for ; Thu, 3 Sep 2020 00:58:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="YC0EVOX6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727991AbgICA6f (ORCPT ); Wed, 2 Sep 2020 20:58:35 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:39296 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727996AbgICA6d (ORCPT ); Wed, 2 Sep 2020 20:58:33 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830tP2O048188 for ; Thu, 3 Sep 2020 00:58:32 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-2020-01-29; bh=d6xvwbbwFUIhyKqCryBUp8S2eSdVOnERyU3Mb8S9Vzo=; b=YC0EVOX6fpFeul85Cog7L+4cg9P2OXeqMcuzu30zxC5s8ZMyc4/XtfnFV4gus3EkzdGk WlR0CY+0Q2xW08IdMjc2ghMESTTt0cduAVlQdssRfv2gWr5tvQg4cAjows4VDMT/baCq AptvvB8ZiUTqZS8GDMtAoSl9A/8fUCyAZhZJ/XlM5oXuMMkmD1kBPqIE42ywITWPo9sk bDVXNennuTku3UjuXXkSZQjhb65JKcxas1PMkW8Sr4Qi3A5fFBXhqCCF3snpzIqMmFfl Uyd2mWM+XR9MX9U5wxf8hjY4nAGz99q3XA9agN3ACz4m1ZtiC+KTyE/74ZfVybHO5Nhc SA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 337eer5xay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 00:58:32 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0830tEVP105147 for ; Thu, 3 Sep 2020 00:58:31 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 3380kqwuyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 00:58:31 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0830wV1c020940 for ; Thu, 3 Sep 2020 00:58:31 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Sep 2020 17:58:30 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 15/15] btrfs: fix replace of seed device Date: Thu, 3 Sep 2020 08:57:51 +0800 Message-Id: <4e073022eeed10dd01f4af44c4264abf91fac02c.1599091832.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 adultscore=0 mlxscore=0 suspectscore=1 malwarescore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9732 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030004 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If you replace a seed device in a sprouted fs, it appears to have successfully replaced the seed device, but if you look closely, it didn't. Here is an example. mkfs.btrfs -fq /dev/sda btrfstune -S1 /dev/sda mount /dev/sda /btrfs btrfs dev add /dev/sdb /btrfs umount /btrfs; btrfs dev scan --forget mount -o device=/dev/sda /dev/sdb /btrfs btrfs rep start -f /dev/sda /dev/sdc /btrfs; echo $? 0 BTRFS info (device sdb): dev_replace from /dev/sda (devid 1) to /dev/sdc started BTRFS info (device sdb): dev_replace from /dev/sda (devid 1) to /dev/sdc finished btrfs fi show Label: none uuid: ab2c88b7-be81-4a7e-9849-c3666e7f9f4f Total devices 2 FS bytes used 256.00KiB devid 1 size 3.00GiB used 520.00MiB path /dev/sdc devid 2 size 3.00GiB used 896.00MiB path /dev/sdb Label: none uuid: 10bd3202-0415-43af-96a8-d5409f310a7e Total devices 1 FS bytes used 128.00KiB devid 1 size 3.00GiB used 536.00MiB path /dev/sda So as per the replace start command and kernel log replace was successful. Now let's try to clean mount. umount /btrfs; btrfs dev scan --forget mount -o device=/dev/sdc /dev/sdb /btrfs mount: /btrfs: wrong fs type, bad option, bad superblock on /dev/sdb, missing codepage or helper program, or other error. [ 636.157517] BTRFS error (device sdc): failed to read chunk tree: -2 [ 636.180177] BTRFS error (device sdc): open_ctree failed That's because per dev items it is still looking for the original seed device. btrfs in dump-tree -d /dev/sdb item 0 key (DEV_ITEMS DEV_ITEM 1) itemoff 16185 itemsize 98 devid 1 total_bytes 3221225472 bytes_used 545259520 io_align 4096 io_width 4096 sector_size 4096 type 0 generation 6 start_offset 0 dev_group 0 seek_speed 0 bandwidth 0 uuid 59368f50-9af2-4b17-91da-8a783cc418d4 <--- seed uuid fsid 10bd3202-0415-43af-96a8-d5409f310a7e <--- seed fsid item 1 key (DEV_ITEMS DEV_ITEM 2) itemoff 16087 itemsize 98 devid 2 total_bytes 3221225472 bytes_used 939524096 io_align 4096 io_width 4096 sector_size 4096 type 0 generation 0 start_offset 0 dev_group 0 seek_speed 0 bandwidth 0 uuid 56a0a6bc-4630-4998-8daf-3c3030c4256a <- sprout uuid fsid ab2c88b7-be81-4a7e-9849-c3666e7f9f4f <- sprout fsid But the replaced target has the following uuid+fsid in its superblock which doesn't match with the expected uuid+fsid in its devitem. btrfs in dump-super /dev/sdc | egrep '^generation|dev_item.uuid|dev_item.fsid|devid' generation 20 dev_item.uuid 59368f50-9af2-4b17-91da-8a783cc418d4 dev_item.fsid ab2c88b7-be81-4a7e-9849-c3666e7f9f4f [match] dev_item.devid 1 So if you provide the original seed device the mount shall be successful. Which so long happening in the test case btrfs/163. btrfs dev scan --forget mount -o device=/dev/sda /dev/sdb /btrfs Fix in this patch: Make it as you can't replace a seed device, you can only add a new device and then delete the seed device. If replace is attempted then returns -EINVAL. As in the below changes. Another possible fix: If we want to keep the ability to replace for seed-device, then we could update the fsid of the replace-target blocks. And after replacement, you have seed device but with sprout fsid. But then I don't know what is the point and if there is any such use case. Signed-off-by: Anand Jain --- fs/btrfs/dev-replace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 656d8ba642af..02b7b3edf9a3 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -225,7 +225,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, int ret = 0; *device_out = NULL; - if (fs_info->fs_devices->seeding) { + if (srcdev->fs_devices->seeding) { btrfs_err(fs_info, "the filesystem is a seed filesystem!"); return -EINVAL; }