From patchwork Mon Sep 16 18:19:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 2899151 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 3860D9F1E3 for ; Mon, 16 Sep 2013 18:22:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B03420170 for ; Mon, 16 Sep 2013 18:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA2E52016A for ; Mon, 16 Sep 2013 18:22:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752083Ab3IPSWW (ORCPT ); Mon, 16 Sep 2013 14:22:22 -0400 Received: from cantor2.suse.de ([195.135.220.15]:51727 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751986Ab3IPSWS (ORCPT ); Mon, 16 Sep 2013 14:22:18 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C00B3A5359; Mon, 16 Sep 2013 20:22:16 +0200 (CEST) Message-Id: <20130916182018.627191537@suse.com> User-Agent: quilt/0.60-5.1.1 Date: Mon, 16 Sep 2013 14:19:16 -0400 From: Jeff Mahoney To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, clmason@fusionio.com Subject: [patch 6/9] btrfs: publish per-super features to sysfs References: <20130916181910.799140428@suse.com> Content-Disposition: inline; filename=btrfs-publish-per-super-features-to-sysfs 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.6 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 This patch publishes information on which features are enabled in the file system on a per-super basis. At this point, it only publishes information on features supported by the file system implementation. Signed-off-by: Jeff Mahoney --- fs/btrfs/ctree.h | 1 fs/btrfs/sysfs.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/sysfs.h | 2 - 3 files changed, 75 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/fs/btrfs/ctree.h 2013-09-16 13:49:28.960465646 -0400 +++ b/fs/btrfs/ctree.h 2013-09-16 13:49:47.688214995 -0400 @@ -1513,6 +1513,7 @@ struct btrfs_fs_info { int thread_pool_size; struct kobj_completion super_kc; + struct kobj_completion features_kc; int do_barriers; int closing; int log_root_recovering; --- a/fs/btrfs/sysfs.c 2013-09-16 13:49:28.960465646 -0400 +++ b/fs/btrfs/sysfs.c 2013-09-16 13:49:47.688214995 -0400 @@ -68,6 +68,39 @@ static struct kobj_type btrfs_supp_feat_ .release = kobj_completion_release, }; +static u64 get_features(struct btrfs_fs_info *fs_info, + enum btrfs_feature_set set) +{ + struct btrfs_super_block *disk_super = fs_info->super_copy; + if (set == FEAT_COMPAT) + return btrfs_super_compat_flags(disk_super); + else if (set == FEAT_COMPAT_RO) + return btrfs_super_compat_ro_flags(disk_super); + else + return btrfs_super_incompat_flags(disk_super); +} + +#define feat_kobj_to_fs_info(kobj) \ + container_of(kobj, struct btrfs_fs_info, features_kc.kc_kobj) +static ssize_t btrfs_feat_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct btrfs_fs_info *fs_info = feat_kobj_to_fs_info(kobj); + struct btrfs_feature_attr *fa = to_btrfs_feature_attr(attr); + u64 features = get_features(fs_info, fa->feature_set); + + return snprintf(buf, PAGE_SIZE, "%u\n", !!(features & fa->feature_bit)); +} + +static const struct sysfs_ops btrfs_feat_attr_ops = { + .show = btrfs_feat_show, +}; + +static struct kobj_type btrfs_feat_ktype = { + .sysfs_ops = &btrfs_feat_attr_ops, + .release = kobj_completion_release, +}; + static struct attribute *btrfs_attrs[] = { NULL, }; @@ -105,6 +138,26 @@ static struct kobj_type btrfs_ktype = { .release = kobj_completion_release, }; +static int add_per_fs_features(struct btrfs_fs_info *fs_info) +{ + int i; + for (i = 0; btrfs_supp_feature_attrs[i]; i++) { + struct attribute *attr = btrfs_supp_feature_attrs[i]; + struct btrfs_feature_attr *fa = to_btrfs_feature_attr(attr); + u64 features = get_features(fs_info, fa->feature_set); + int error; + + if (!(features & fa->feature_bit)) + continue; + + error = sysfs_create_file(&fs_info->features_kc.kc_kobj, + &fa->attr); + if (error) + return error; + } + return 0; +} + /* /sys/fs/btrfs/ entry */ static struct kset *btrfs_kset; @@ -116,12 +169,32 @@ int btrfs_sysfs_add_one(struct btrfs_fs_ fs_info->super_kc.kc_kobj.kset = btrfs_kset; error = kobject_add(&fs_info->super_kc.kc_kobj, NULL, "%pU", fs_info->fsid); + if (error) + return error; + + kobj_completion_init(&fs_info->features_kc, &btrfs_feat_ktype); + error = kobject_add(&fs_info->features_kc.kc_kobj, + &fs_info->super_kc.kc_kobj, "features"); + if (error) + goto out_super; + + error = add_per_fs_features(fs_info); + if (error) + goto out_features; + + return 0; + +out_features: + kobj_completion_del_and_wait(&fs_info->features_kc); +out_super: + kobj_completion_del_and_wait(&fs_info->super_kc); return error; } void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info) { + kobj_completion_del_and_wait(&fs_info->features_kc); kobj_completion_del_and_wait(&fs_info->super_kc); } --- a/fs/btrfs/sysfs.h 2013-09-16 13:49:28.964465592 -0400 +++ b/fs/btrfs/sysfs.h 2013-09-16 13:49:47.688214995 -0400 @@ -28,7 +28,7 @@ static struct btrfs_attr btrfs_attr_##_n #define BTRFS_ATTR_LIST(_name) (&btrfs_attr_##_name.attr), struct btrfs_feature_attr { - struct attribute attr; /* global show, no store */ + struct attribute attr; /* per-fs/global show, no store */ enum btrfs_feature_set feature_set; u64 feature_bit; };