From patchwork Tue Jun 3 03:36:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 4284951 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CD28F9F391 for ; Tue, 3 Jun 2014 03:36:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E236B200CF for ; Tue, 3 Jun 2014 03:36:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D38BC2021A for ; Tue, 3 Jun 2014 03:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753270AbaFCDgo (ORCPT ); Mon, 2 Jun 2014 23:36:44 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:24382 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753232AbaFCDgl (ORCPT ); Mon, 2 Jun 2014 23:36:41 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s533aZmu018971 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 Jun 2014 03:36:35 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s533aYNE006894 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 3 Jun 2014 03:36:35 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s533aYMC006889; Tue, 3 Jun 2014 03:36:34 GMT Received: from localhost.localdomain (/119.56.121.246) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 02 Jun 2014 20:36:34 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: jeffm@suse.com, dsterba@suse.cz, clm@fb.com Subject: [PATCH 6/6 RFC v2] btrfs: revamp /sys/fs/btrfs//devices Date: Tue, 3 Jun 2014 11:36:04 +0800 Message-Id: <1401766564-7381-7-git-send-email-Anand.Jain@oracle.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1401766564-7381-1-git-send-email-Anand.Jain@oracle.com> References: <1401096626-13210-1-git-send-email-anand.jain@oracle.com> <1401766564-7381-1-git-send-email-Anand.Jain@oracle.com> X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Anand Jain As of now with out this patch the sysfs interface under dir /sys/fs/btrfs//devices is just link to the block devs. Moving forward we would need the above btrfs sysfs path to contain more info about the btrfs devices. So this patch provides a framework for the same. And as of now a probe interface is added, which can be used to notify btrfs for any change in the device status. Signed-off-by: Anand Jain --- V2: On the 2nd thought I kept the device link, but under the device name. eg: /sys/fs/btrfs//devices//sdx-> link to blk device /sys/fs/btrfs//devices//probe and commit update accordingly fs/btrfs/sysfs.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++----- fs/btrfs/volumes.h | 2 ++ 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 9733cfc..92fb3bb 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -31,8 +31,11 @@ #include "transaction.h" #include "sysfs.h" #include "volumes.h" +#include "rcu-string.h" static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj); +int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info, + struct btrfs_device *one_device); static u64 get_features(struct btrfs_fs_info *fs_info, enum btrfs_feature_set set) @@ -490,8 +493,13 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info) kobject_del(fs_info->space_info_kobj); kobject_put(fs_info->space_info_kobj); } - kobject_del(fs_info->device_dir_kobj); - kobject_put(fs_info->device_dir_kobj); + + if (fs_info->device_dir_kobj) { + btrfs_kobj_rm_device(fs_info, NULL); + kobject_del(fs_info->device_dir_kobj); + kobject_put(fs_info->device_dir_kobj); + } + addrm_unknown_feature_attrs(fs_info, false); sysfs_remove_group(&fs_info->super_kobj, &btrfs_feature_attr_group); __btrfs_sysfs_remove_one(fs_info); @@ -577,21 +585,68 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info, { struct hd_struct *disk; struct kobject *disk_kobj; + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; + struct btrfs_device *dev; if (!fs_info->device_dir_kobj) return -EINVAL; if (one_device) { + if (!one_device->device_kobj.parent) + return -EINVAL; + disk = one_device->bdev->bd_part; disk_kobj = &part_to_dev(disk)->kobj; - sysfs_remove_link(fs_info->device_dir_kobj, + sysfs_remove_link(&one_device->device_kobj, disk_kobj->name); + kobject_del(&one_device->device_kobj); + kobject_put(&one_device->device_kobj); + return 0; } + list_for_each_entry(dev, &fs_devices->devices, dev_list) { + if (!dev->device_kobj.parent) + continue; + + disk = dev->bdev->bd_part; + disk_kobj = &part_to_dev(disk)->kobj; + + sysfs_remove_link(&dev->device_kobj, disk_kobj->name); + kobject_del(&dev->device_kobj); + kobject_put(&dev->device_kobj); + } return 0; } +#define to_btrfs_device(_kobj) container_of(_kobj, struct btrfs_device, device_kobj) + +static ssize_t device_kobj_probe_store(struct kobject *dev_kobj, + struct kobj_attribute *a, const char *buf, size_t len) +{ + /* Fixme: Call appropriate device check status handler */ + + return len; +} + +BTRFS_ATTR_RW(probe, 0200, NULL, device_kobj_probe_store); + +static struct attribute *device_kobj_attrs[] = { + BTRFS_ATTR_PTR(probe), + NULL, +}; + +static void device_kobj_release(struct kobject *dev_kobj) +{ + /* nothing to free as of now */ +} + +struct kobj_type device_ktype = { + .sysfs_ops = &kobj_sysfs_ops, + .release = device_kobj_release, + .default_attrs = device_kobj_attrs, +}; + int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info, struct btrfs_device *one_device) { @@ -610,19 +665,25 @@ int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info, struct hd_struct *disk; struct kobject *disk_kobj; - if (!dev->bdev) + if (!dev->bdev || dev->missing || dev->device_kobj.parent) continue; if (one_device && one_device != dev) continue; + error = kobject_init_and_add(&dev->device_kobj, &device_ktype, + fs_info->device_dir_kobj, "%s", + strrchr(rcu_str_deref(dev->name), '/') + 1); + if (error) + break; + disk = dev->bdev->bd_part; disk_kobj = &part_to_dev(disk)->kobj; - - error = sysfs_create_link(fs_info->device_dir_kobj, + error = sysfs_create_link(&dev->device_kobj, disk_kobj, disk_kobj->name); if (error) break; + } return error; diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 25f0505..d0c9c32 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -113,6 +113,8 @@ struct btrfs_device { int dev_stats_valid; int dev_stats_dirty; /* counters need to be written to disk */ atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX]; + + struct kobject device_kobj; }; struct btrfs_fs_devices {