From patchwork Wed May 16 08:09:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 10402965 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DA65D60155 for ; Wed, 16 May 2018 08:07:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD872287B9 for ; Wed, 16 May 2018 08:07:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C213B287F5; Wed, 16 May 2018 08:07:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27A03287B9 for ; Wed, 16 May 2018 08:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752513AbeEPIHd (ORCPT ); Wed, 16 May 2018 04:07:33 -0400 Received: from mgwym02.jp.fujitsu.com ([211.128.242.41]:19085 "EHLO mgwym02.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752234AbeEPIGy (ORCPT ); Wed, 16 May 2018 04:06:54 -0400 Received: from yt-mxoi2.gw.nic.fujitsu.com (unknown [192.168.229.69]) by mgwym02.jp.fujitsu.com with smtp id 72b3_2f82_cb625aae_55d6_4228_8b5c_435cb79c6ceb; Wed, 16 May 2018 17:06:48 +0900 Received: from g01jpfmpwkw02.exch.g01.fujitsu.local (g01jpfmpwkw02.exch.g01.fujitsu.local [10.0.193.56]) by yt-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id 21E54AC0095 for ; Wed, 16 May 2018 17:06:48 +0900 (JST) Received: from G01JPEXCHKW18.g01.fujitsu.local (G01JPEXCHKW18.g01.fujitsu.local [10.0.194.57]) by g01jpfmpwkw02.exch.g01.fujitsu.local (Postfix) with ESMTP id 47C913287DE for ; Wed, 16 May 2018 17:06:47 +0900 (JST) Received: from luna3.soft.fujitsu.com (10.124.196.199) by G01JPEXCHKW18.g01.fujitsu.local (10.0.194.57) with Microsoft SMTP Server id 14.3.352.0; Wed, 16 May 2018 17:06:46 +0900 From: Tomohiro Misono To: Subject: [PATCH v2 2/2] btrfs: sysfs: Add entry which shows rmdir(2) can work for subvolume Date: Wed, 16 May 2018 17:09:27 +0900 Message-ID: <2eb3880232f74bb884a269264058e6d5f5337ffc.1526457206.git.misono.tomohiro@jp.fujitsu.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: References: MIME-Version: 1.0 X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Deletion of a subvolume by rmdir(2) has become allowed by the 'commit cd2decf640b1 ("btrfs: Allow rmdir(2) to delete an empty subvolume")'. It is a kind of new feature and this commits add a sysfs entry /sys/fs/btrfs/static_features/rmdir_subvol to indicate the availability of feature so that a user program (e.g. xfstests) can detect it. Note that new sysfs directory "static_features" is created since a entry in /sys/fs/btrfs/features depends on feature bits of superblock (in other words, they may be different between each fs) and is not suitable to hold the features which only depend on kernel version. New attribute_group "btrfs_static_feature_attr_group" is created for this purpose. Signed-off-by: Tomohiro Misono --- fs/btrfs/sysfs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 217d401fe8ae..35b3ac567899 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -210,12 +210,32 @@ static struct attribute *btrfs_supported_feature_attrs[] = { NULL }; +/* Features which depend on feature bits and may differ between each fs */ static const struct attribute_group btrfs_feature_attr_group = { .name = "features", .is_visible = btrfs_feature_visible, .attrs = btrfs_supported_feature_attrs, }; +static ssize_t rmdir_subvol_show(struct kobject *kobj, + struct kobj_attribute *ka, char *buf) +{ + /* No meaning for the value */ + return snprintf(buf, PAGE_SIZE, "0\n"); +} +BTRFS_ATTR(static_feature, rmdir_subvol, rmdir_subvol_show); + +static struct attribute *btrfs_supported_static_feature_attrs[] = { + BTRFS_ATTR_PTR(static_feature, rmdir_subvol), + NULL +}; + +/* Features which only depend on kernel version */ +static const struct attribute_group btrfs_static_feature_attr_group = { + .name = "static_features", + .attrs = btrfs_supported_static_feature_attrs, +}; + static ssize_t btrfs_show_u64(u64 *value_ptr, spinlock_t *lock, char *buf) { u64 val; @@ -901,8 +921,15 @@ int __init btrfs_init_sysfs(void) ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); if (ret) goto out2; + ret = sysfs_create_group(&btrfs_kset->kobj, + &btrfs_static_feature_attr_group); + if (ret) + goto out3; return 0; + +out3: + sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); out2: debugfs_remove_recursive(btrfs_debugfs_root_dentry); out1: @@ -914,6 +941,8 @@ int __init btrfs_init_sysfs(void) void __cold btrfs_exit_sysfs(void) { sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); + sysfs_remove_group(&btrfs_kset->kobj, + &btrfs_static_feature_attr_group); kset_unregister(btrfs_kset); debugfs_remove_recursive(btrfs_debugfs_root_dentry); }