From patchwork Fri Sep 4 09:25:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11756359 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 481E8138E for ; Fri, 4 Sep 2020 09:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 239B3206B8 for ; Fri, 4 Sep 2020 09:26:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="kWOr3sbC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729615AbgIDJ0H (ORCPT ); Fri, 4 Sep 2020 05:26:07 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57036 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725812AbgIDJ0G (ORCPT ); Fri, 4 Sep 2020 05:26:06 -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 0849NugN167342; Fri, 4 Sep 2020 09:26:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=doPiPA8AIGvoROPXXlP8n+cE2DM9W3QlfpRyEtZyCtE=; b=kWOr3sbCcdiYaZer+D1tNZ+Hf0gQygokEtuHGLiQA1B7N0Saxr4LppDBEItLqSBVk7zj QQswJSg5NsIanJoG4AnN/ophjaXrQQ1lIfK7itdonlGk4VON3HCdw3sYEst5s9hlaiaQ BHwGx7bPHK5XYPlpgHJ48IFJNzc1rONWHJSTzeIGpX6y7Bu++F4VuUOpZ7cOOTBLs5Qt UWAR0F1YdDEwuIEr1go6HoCONOri+E2nH9ZXibFNr/7m1Z4+i62KPGGnUmEhY90uG742 MYuiiju85aZWqVVuOkbPYmOzH5mV3N0EqlAY0pTpRL3NBEOMTKqaG8+BNuT75s3AsIlV +Q== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 339dmnc0dw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 04 Sep 2020 09:26:03 +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 0849PAVB192598; Fri, 4 Sep 2020 09:26:03 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 33bhs440sg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Sep 2020 09:26:03 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0849Q18d022043; Fri, 4 Sep 2020 09:26:01 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 04 Sep 2020 02:26:01 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: josef@toxicpanda.com Subject: [PATCH v3 04/15] btrfs: refactor btrfs_sysfs_add_devices_dir Date: Fri, 4 Sep 2020 17:25:53 +0800 Message-Id: <352f52343e26e26afd1355a6720762d729bfc088.1599193971.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=9733 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=1 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009040087 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9733 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-2009040087 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 --- v3: Fix conflict due to the patch [1] [1] btrfs: sysfs: init devices outside of the chunk_mutex 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 34899b59fcbc..713246af9137 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 df3a31fcc4d7..f858c4d9a6ae 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2606,7 +2606,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path mutex_unlock(&fs_info->chunk_mutex); /* Add sysfs device entry */ - btrfs_sysfs_add_devices_dir(fs_devices, device); + btrfs_sysfs_add_device(device); mutex_unlock(&fs_devices->device_list_mutex); From patchwork Fri Sep 4 09:24:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11756361 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 5C26F138C for ; Fri, 4 Sep 2020 09:26:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F0B520791 for ; Fri, 4 Sep 2020 09:26:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="UY8XXGrt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729753AbgIDJ0b (ORCPT ); Fri, 4 Sep 2020 05:26:31 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:44930 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729751AbgIDJ0b (ORCPT ); Fri, 4 Sep 2020 05:26:31 -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 0849OI2W183042 for ; Fri, 4 Sep 2020 09:26:29 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=zlJVWBlGeRJenRhj/w/JM3Ax8N3qVibwFhDK+cGgDa8=; b=UY8XXGrtjMdTnlYv3ScGRF4N38apRYFmM0WsoFnF0oECMq+dlVl7cC4mKrcfu2z366xu KgQQZqey7y6GPrOPj7ueW/JV6ulNeSoEcFHYoYLNEUumfm9A6VqQEMjCGlwwjoRWOKpT YUVVtE1SaqCmWsW790jQlqWb0Ri/jp0iswaOsveNnifsEVqKIui78R8keufbd51/zDgq 9WD1UwlxVBc9P1e2hD4tf72txAOFNDD2A9Gag2bFvCD2UZLYA6gW5GjaQovHlZ6VqzGK fnRFC5KvaXBREzcmr2TfTt/IgWskOn5nW4bwF38559rbynPZIxg5KIThXWCSTz3NMsEk qQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 337eymng8j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 04 Sep 2020 09:26:29 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08499nvf139986 for ; Fri, 4 Sep 2020 09:24:29 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 33b7v289mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 04 Sep 2020 09:24:28 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0849ORtQ031849 for ; Fri, 4 Sep 2020 09:24:28 GMT Received: from localhost.localdomain (/39.109.231.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 04 Sep 2020 02:24:27 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v3 07/15] btrfs: handle fail path for btrfs_sysfs_add_fs_devices Date: Fri, 4 Sep 2020 17:24:20 +0800 Message-Id: <1bc0c094ab839218f3d6f02727f6536dbb7713b0.1599201200.git.anand.jain@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <32779bc42ae40eea707cc585624724ac91cd967e.1599091832.git.anand.jain@oracle.com> References: <32779bc42ae40eea707cc585624724ac91cd967e.1599091832.git.anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9733 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=1 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009040086 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9733 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-2009040087 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 --- v3: fix the goto fail fs/btrfs/sysfs.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 56eca63360ad..be5b773225e8 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, @@ -1325,18 +1327,22 @@ 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)