From patchwork Thu Dec 5 11:27:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11274663 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 DD1E2138D for ; Thu, 5 Dec 2019 11:29:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BAD552464E for ; Thu, 5 Dec 2019 11:29:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gQRrspNr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729295AbfLEL3R (ORCPT ); Thu, 5 Dec 2019 06:29:17 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:37566 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729167AbfLEL3Q (ORCPT ); Thu, 5 Dec 2019 06:29:16 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB5BSdEH074845 for ; Thu, 5 Dec 2019 11:29: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-2019-08-05; bh=V9vZwXX5fcKIr18s4hOMX8qBSjq90vItd86Wiazc0uY=; b=gQRrspNrVONq7Rz41bCF8neXBalpx1mjkCPdal9qWXASnmre3+SryuZuc8mQN3qmCnzw vDvomc2aAB0jGppN8Vss5u8Fi94F4GdWebtpz7M+ookXamxOxsbrmG+Oi47+ODdQcRli y4a/o+WolpIMjr/H6T9bSO8jsf5moriW998zvnv0yCGh1Pe/v9NY906icFLkvxd7Phw7 QXJaAfk85agoGTxCuMwZbQgKfR1dIhpv16GDhglVhx0NwrzG7JDMGpHv7DvkhkPWuUHO walxbBnp/aNCuIWFqX3wMwiZi/m4mqaOCiDeT363g06RtNLKFOeg3iLIMe65HsJ2Zntq 3g== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2wkgcqmf29-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Dec 2019 11:29:15 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB5BNVP2071796 for ; Thu, 5 Dec 2019 11:27:14 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2wpp73ygk4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Dec 2019 11:27:14 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xB5BRDtE007871 for ; Thu, 5 Dec 2019 11:27:13 GMT Received: from localhost.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Dec 2019 03:27:12 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid Date: Thu, 5 Dec 2019 19:27:03 +0800 Message-Id: <20191205112706.8125-2-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191205112706.8125-1-anand.jain@oracle.com> References: <20191205112706.8125-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9461 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=998 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912050094 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9461 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912050095 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have one simple function btrfs_sysfs_remove_fsid() to cleanup kobjects added by btrfs_sysfs_add_fsid() and calls kobject_put() and kobject_delete() only if the kobject is initialized or not null. So use this function while retreating in the function btrfs_sysfs_add_fsid(). One difference though, earlier we did not call kobject_del() during retreat in btrfs_sysfs_add_fsid() and I did experiment to figureout if that's an error or warning, however I didn't notice any such issues with or without kobject_del() not being called. So this patch is just for cleanup. Signed-off-by: Anand Jain --- fs/btrfs/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 16379f491ca1..4cda410f0e6b 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1076,7 +1076,7 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs) if (!fs_devs->devices_kobj) { btrfs_err(fs_devs->fs_info, "failed to init sysfs device interface"); - kobject_put(&fs_devs->fsid_kobj); + btrfs_sysfs_remove_fsid(fs_devs); return -ENOMEM; } From patchwork Thu Dec 5 11:27:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11274665 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 31396109A for ; Thu, 5 Dec 2019 11:29:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0CB0C20707 for ; Thu, 5 Dec 2019 11:29:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="r1SSWYWi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729306AbfLEL3S (ORCPT ); Thu, 5 Dec 2019 06:29:18 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:43378 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729260AbfLEL3R (ORCPT ); Thu, 5 Dec 2019 06:29:17 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB5BTCQk069664 for ; Thu, 5 Dec 2019 11:29:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=GnN/TWHCTabHIKgRFTwqlgZy/Z0reto2dzy9zYeRrH8=; b=r1SSWYWi6Q96rkoz/hok+QvuCgncNsO326kgXz0uaqcH+HL/tX6yPCMDoDEER0OAS45u a9YkvkhBluEf2hcnFx+yJWud3mHqIn1WPq7CjhZDaeKBl3T/stjm2pWmJzNrOrY+21qC oBlAQ/9dTi1xaLG43x/quqo333Slk+d35EVG1b0i2MyADoacZLqbx3FCBBjwBhQuu2wQ npTlsx1MnlxU86uqSZKRNcGqwqKQeeGmLFp57tx7I49oH/uHGv+OvlTkmwslPIgtWT5b OZUNjgSVILqJt7uZu1SR9TiOoRJm75faYdz27wt1GGiJOihq/ory3q3YxJL1uDjZR3r9 LA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2wkh2rmdag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Dec 2019 11:29:16 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB5BNVo1071754 for ; Thu, 5 Dec 2019 11:27:15 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2wpp73ygm0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Dec 2019 11:27:15 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xB5BRE4T007878 for ; Thu, 5 Dec 2019 11:27:14 GMT Received: from localhost.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Dec 2019 03:27:14 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/4] btrfs: sysfs, add UUID/devinfo kobject Date: Thu, 5 Dec 2019 19:27:04 +0800 Message-Id: <20191205112706.8125-3-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191205112706.8125-1-anand.jain@oracle.com> References: <20191205112706.8125-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9461 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912050094 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9461 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912050095 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Preparatory patch creates kobject /sys/fs/btrfs/UUID/devinfo to hold btrfs_fs_devices::dev_state attribute. This is being added in the mount context, that means we don't see UUID/devinfo before the mount (yet). Signed-off-by: Anand Jain --- fs/btrfs/sysfs.c | 15 +++++++++++++++ fs/btrfs/volumes.h | 1 + 2 files changed, 16 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 4cda410f0e6b..af169970e818 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -734,6 +734,12 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add) static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs) { + if (fs_devs->devinfo_kobj) { + kobject_del(fs_devs->devinfo_kobj); + kobject_put(fs_devs->devinfo_kobj); + fs_devs->devinfo_kobj = NULL; + } + if (fs_devs->devices_kobj) { kobject_del(fs_devs->devices_kobj); kobject_put(fs_devs->devices_kobj); @@ -1080,6 +1086,15 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs) return -ENOMEM; } + fs_devs->devinfo_kobj = kobject_create_and_add("devinfo", + &fs_devs->fsid_kobj); + if (!fs_devs->devinfo_kobj) { + btrfs_err(fs_devs->fs_info, + "failed to init sysfs devinfo kobject"); + btrfs_sysfs_remove_fsid(fs_devs); + return -ENOMEM; + } + return 0; } diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 3c56ef571b00..38f2e8437b68 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -256,6 +256,7 @@ struct btrfs_fs_devices { /* sysfs kobjects */ struct kobject fsid_kobj; struct kobject *devices_kobj; + struct kobject *devinfo_kobj; struct completion kobj_unregister; }; From patchwork Thu Dec 5 11:27:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11274659 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 D00AA14B7 for ; Thu, 5 Dec 2019 11:27:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2BE52464E for ; Thu, 5 Dec 2019 11:27:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="SNSyt+cb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729072AbfLEL1T (ORCPT ); Thu, 5 Dec 2019 06:27:19 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:35808 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728735AbfLEL1S (ORCPT ); Thu, 5 Dec 2019 06:27:18 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB5BJ5ox067856 for ; Thu, 5 Dec 2019 11:27: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-2019-08-05; bh=oO61Je4oaXusZAgH5fCk6zBXijQtaBB8na9k5bDTtiE=; b=SNSyt+cbGqaDx6apmv7JlzsiN4h6G++dg7UTZeJurZM2YMYewjlZBFDKI5Als5jOlK6H Q4XDkqX11GZDDTCHHha8i8PyLYit1Rx4/co/fFZdV79B/I8xfKL3gUgEQhUAB/tKQNcZ 09BxjhRvRVYuyZmn08mJkbvcdj6w6RN6pPIo8DSbBB/uz1xo2HiAZnWUR57ldRqrc8l/ k9flGbvcI/bSUMC55YStR/BMXaUHwuASBpocsyTFlxMEzi/MB8Z+/DaxTfAPw3dCSUX8 LOveIHz4wucdMhiVttKMhyT3j6LkJZXf+obLSm8LF3LQegmQM+ALj1UoL2xem2l2kLUn JA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2wkgcqmev0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Dec 2019 11:27:17 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB5BNoBm033437 for ; Thu, 5 Dec 2019 11:27:16 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2wptnx9qj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Dec 2019 11:27:16 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id xB5BRGNY006843 for ; Thu, 5 Dec 2019 11:27:16 GMT Received: from localhost.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Dec 2019 03:27:15 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 3/4] btrfs: sysfs, rename device_link add,remove functions Date: Thu, 5 Dec 2019 19:27:05 +0800 Message-Id: <20191205112706.8125-4-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191205112706.8125-1-anand.jain@oracle.com> References: <20191205112706.8125-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9461 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912050094 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9461 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912050094 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In preparation to add btrfs_device::dev_state attribute in /sys/fs/btrfs/UUID/devinfo Rename btrfs_sysfs_add_device_link() and btrfs_sysfs_rm_device_link() to btrfs_sysfs_add_devices_attr() and btrfs_sysfs_remove_devices_attr() as these functions is going to create dev_state attribute rather than just the link to the disk. No functional changes. Signed-off-by: Anand Jain --- v2: Update change log. Change ..UUID/devices to ..UUID/devinfo fs/btrfs/dev-replace.c | 4 ++-- fs/btrfs/sysfs.c | 12 ++++++------ fs/btrfs/sysfs.h | 4 ++-- fs/btrfs/volumes.c | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index f639dde2a679..9a29d6de9017 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -472,7 +472,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_device_link(tgt_device->fs_devices, tgt_device); + ret = btrfs_sysfs_add_devices_attr(tgt_device->fs_devices, tgt_device); if (ret) btrfs_err(fs_info, "kobj add dev failed %d", ret); @@ -706,7 +706,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_rm_device_link(fs_info->fs_devices, src_device); + btrfs_sysfs_remove_devices_attr(fs_info->fs_devices, src_device); btrfs_rm_dev_replace_free_srcdev(src_device); /* write back the superblocks */ diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index af169970e818..834f712ed60c 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -780,7 +780,7 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info) addrm_unknown_feature_attrs(fs_info, false); sysfs_remove_group(&fs_info->fs_devices->fsid_kobj, &btrfs_feature_attr_group); sysfs_remove_files(&fs_info->fs_devices->fsid_kobj, btrfs_attrs); - btrfs_sysfs_rm_device_link(fs_info->fs_devices, NULL); + btrfs_sysfs_remove_devices_attr(fs_info->fs_devices, NULL); } static const char * const btrfs_feature_set_names[FEAT_MAX] = { @@ -969,7 +969,7 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info, /* when one_device is NULL, it removes all device links */ -int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices, +int btrfs_sysfs_remove_devices_attr(struct btrfs_fs_devices *fs_devices, struct btrfs_device *one_device) { struct hd_struct *disk; @@ -1001,8 +1001,8 @@ int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices, return 0; } -int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices, - struct btrfs_device *one_device) +int btrfs_sysfs_add_devices_attr(struct btrfs_fs_devices *fs_devices, + struct btrfs_device *one_device) { int error = 0; struct btrfs_device *dev; @@ -1106,13 +1106,13 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info) btrfs_set_fs_info_ptr(fs_info); - error = btrfs_sysfs_add_device_link(fs_devs, NULL); + error = btrfs_sysfs_add_devices_attr(fs_devs, NULL); if (error) return error; error = sysfs_create_files(fsid_kobj, btrfs_attrs); if (error) { - btrfs_sysfs_rm_device_link(fs_devs, NULL); + btrfs_sysfs_remove_devices_attr(fs_devs, NULL); return error; } diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h index 3d27b39eaf94..9d97b3c8db4e 100644 --- a/fs/btrfs/sysfs.h +++ b/fs/btrfs/sysfs.h @@ -14,9 +14,9 @@ enum btrfs_feature_set { char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags); const char * const btrfs_feature_set_name(enum btrfs_feature_set set); -int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices, +int btrfs_sysfs_add_devices_attr(struct btrfs_fs_devices *fs_devices, struct btrfs_device *one_device); -int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices, +int btrfs_sysfs_remove_devices_attr(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); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c565650639ee..1d80ac164fe3 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2014,7 +2014,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_rm_device_link(fs_devices, device); + btrfs_sysfs_remove_devices_attr(fs_devices, device); } num_devices = btrfs_super_num_devices(fs_info->super_copy) - 1; @@ -2135,7 +2135,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev) WARN_ON(!tgtdev); mutex_lock(&fs_devices->device_list_mutex); - btrfs_sysfs_rm_device_link(fs_devices, tgtdev); + btrfs_sysfs_remove_devices_attr(fs_devices, tgtdev); if (tgtdev->bdev) fs_devices->open_devices--; @@ -2483,7 +2483,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_device_link(fs_devices, device); + btrfs_sysfs_add_devices_attr(fs_devices, device); /* * we've got more storage, clear any full flags on the space @@ -2551,7 +2551,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path return ret; error_sysfs: - btrfs_sysfs_rm_device_link(fs_devices, device); + btrfs_sysfs_remove_devices_attr(fs_devices, 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 Dec 5 11:27:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11274661 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 3C2181805 for ; Thu, 5 Dec 2019 11:27:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 109852464E for ; Thu, 5 Dec 2019 11:27:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ik3IsTsX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729096AbfLEL1V (ORCPT ); Thu, 5 Dec 2019 06:27:21 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:35828 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728735AbfLEL1V (ORCPT ); Thu, 5 Dec 2019 06:27:21 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB5BJ8Rf067956 for ; Thu, 5 Dec 2019 11:27:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=YAhVpkDxn+jVk8i1zrUbZEn4rso2BVIzfmiRP0W39sI=; b=ik3IsTsX9vZiWe/xyA7aUC8n22EkXSCif/eZKK9Lsm9uYR7SESGHQ4FjaeARFp+a/+8p j2SJGGj+FEeVmS3LkDly07MotjpBeSsjKw8daYfL5ClCam1TGlUro+ZaXTVuIQgQmQYe vCGKHZr8s+X9MAz0OVRUYIHjPio7upNUqlb4S/azS+UvKIsaG/oOBvYar2qcl1AA6W/q kZb8v9HgMB/awiCxxZmk+H1be16dMeiH5bXGsebl8n8DpuTQO1Khszcf8XPkSqrR0TaB 3shNasQ21Dp5Ou5KYKh0k/1MhLz9hcXBNEDC5Lm0xN2BIT2/qX/+0cDt5AW4v1FM36u7 CA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2wkgcqmev6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Dec 2019 11:27:19 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB5BNWhN071910 for ; Thu, 5 Dec 2019 11:27:18 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2wpp73ygnn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Dec 2019 11:27:18 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xB5BRHlT007886 for ; Thu, 5 Dec 2019 11:27:17 GMT Received: from localhost.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Dec 2019 03:27:17 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/4] btrfs: sysfs, add devid/dev_state kobject and attribute Date: Thu, 5 Dec 2019 19:27:06 +0800 Message-Id: <20191205112706.8125-5-anand.jain@oracle.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191205112706.8125-1-anand.jain@oracle.com> References: <20191205112706.8125-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9461 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912050094 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9461 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1912050094 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org A new sysfs RW attribute UUID/devinfo//dev_state is added here. The dev_state here reflects the state of the device from the kernel parameter btrfs_device::dev_state and this attribute is born after the device is mounted and goes along with the dynamic nature of the device add and delete. This attribute gets deleted at unmount. For example: pwd /sys/fs/btrfs/6e1961f1-5918-4ecc-a22f-948897b409f7/devinfo cat 1/dev_state IN_FS_METADATA MISSING cat 2/dev_state WRITABLE IN_FS_METADATA Signed-off-by: Anand Jain --- fs/btrfs/sysfs.c | 101 ++++++++++++++++++++++++++++++++++----------- fs/btrfs/volumes.h | 2 + 2 files changed, 80 insertions(+), 23 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 834f712ed60c..99c7269e0524 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -978,29 +978,76 @@ int btrfs_sysfs_remove_devices_attr(struct btrfs_fs_devices *fs_devices, if (!fs_devices->devices_kobj) return -EINVAL; - if (one_device && one_device->bdev) { - disk = one_device->bdev->bd_part; - disk_kobj = &part_to_dev(disk)->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); + } - sysfs_remove_link(fs_devices->devices_kobj, disk_kobj->name); - } + kobject_del(&one_device->devid_kobj); + kobject_put(&one_device->devid_kobj); - if (one_device) return 0; + } - list_for_each_entry(one_device, - &fs_devices->devices, dev_list) { - if (!one_device->bdev) - continue; - disk = one_device->bdev->bd_part; - disk_kobj = &part_to_dev(disk)->kobj; + list_for_each_entry(one_device, &fs_devices->devices, dev_list) { - sysfs_remove_link(fs_devices->devices_kobj, disk_kobj->name); + 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); } return 0; } +static void btrfs_dev_state_to_str(struct btrfs_device *device, char *dev_state_str, size_t n) +{ + int state; + const char *btrfs_dev_states[] = { "WRITEABLE", "IN_FS_METADATA", + "MISSING", "REPLACE_TGT", "FLUSHING" + }; + + n = n - strlen(dev_state_str) - 1; + + for (state = 0; state < ARRAY_SIZE(btrfs_dev_states); state++) { + if (test_bit(state, &device->dev_state)) { + if (strlen(dev_state_str)) + strncat(dev_state_str, " ", n); + strncat(dev_state_str, btrfs_dev_states[state], n); + } + } + strncat(dev_state_str, "\n", n); +} + +static ssize_t btrfs_sysfs_dev_state_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + struct btrfs_device *device = container_of(kobj, struct btrfs_device, + devid_kobj); + + btrfs_dev_state_to_str(device, buf, PAGE_SIZE); + return strlen(buf); +} + +BTRFS_ATTR(, dev_state, btrfs_sysfs_dev_state_show); + +static struct attribute *devinfo_attrs[] = { + BTRFS_ATTR_PTR(, dev_state), + NULL +}; + +ATTRIBUTE_GROUPS(devinfo); + +static struct kobj_type devinfo_ktype = { + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = devinfo_groups, +}; + int btrfs_sysfs_add_devices_attr(struct btrfs_fs_devices *fs_devices, struct btrfs_device *one_device) { @@ -1008,22 +1055,30 @@ int btrfs_sysfs_add_devices_attr(struct btrfs_fs_devices *fs_devices, struct btrfs_device *dev; list_for_each_entry(dev, &fs_devices->devices, dev_list) { - struct hd_struct *disk; - struct kobject *disk_kobj; - - if (!dev->bdev) - continue; if (one_device && one_device != dev) continue; - disk = dev->bdev->bd_part; - disk_kobj = &part_to_dev(disk)->kobj; + if (dev->bdev) { + struct hd_struct *disk; + struct kobject *disk_kobj; + + disk = dev->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) + error = sysfs_create_link(fs_devices->devices_kobj, + disk_kobj, disk_kobj->name); + if (error) + break; + } + + error = kobject_init_and_add(&dev->devid_kobj, &devinfo_ktype, + fs_devices->devinfo_kobj, "%llu", + dev->devid); + if (error) { + kobject_put(&dev->devid_kobj); break; + } } return error; diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 38f2e8437b68..68021d1ee216 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -138,6 +138,8 @@ struct btrfs_device { atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX]; struct extent_io_tree alloc_state; + + struct kobject devid_kobj; }; /*