From patchwork Mon Sep 16 18:19:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 2899201 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5022FBFF05 for ; Mon, 16 Sep 2013 18:22:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2EF642016A for ; Mon, 16 Sep 2013 18:22:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 028A720260 for ; Mon, 16 Sep 2013 18:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752080Ab3IPSWh (ORCPT ); Mon, 16 Sep 2013 14:22:37 -0400 Received: from cantor2.suse.de ([195.135.220.15]:51722 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751864Ab3IPSWR (ORCPT ); Mon, 16 Sep 2013 14:22:17 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AD7A9A52C6; Mon, 16 Sep 2013 20:22:16 +0200 (CEST) Message-Id: <20130916182018.291611624@suse.com> User-Agent: quilt/0.60-5.1.1 Date: Mon, 16 Sep 2013 14:19:14 -0400 From: Jeff Mahoney To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, clmason@fusionio.com Subject: [patch 4/9] btrfs: export supported featured to sysfs References: <20130916181910.799140428@suse.com> Content-Disposition: inline; filename=btrfs-export-supported-featured-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 adds the ability to publish supported features to sysfs under /sys/fs/btrfs/features. The files are module-wide and export which features the kernel supports. The content, for now, is just "0\n". Signed-off-by: Jeff Mahoney --- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/disk-io.c | 1 - fs/btrfs/sysfs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/sysfs.h | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) -- 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:46:30.875025162 -0400 +++ b/fs/btrfs/ctree.h 2013-09-16 13:48:53.252952421 -0400 @@ -32,6 +32,7 @@ #include #include #include +#include #include "extent_io.h" #include "extent_map.h" #include "async-thread.h" @@ -1511,8 +1512,7 @@ struct btrfs_fs_info { struct task_struct *cleaner_kthread; int thread_pool_size; - struct kobject super_kobj; - struct completion kobj_unregister; + struct kobj_completion super_kc; int do_barriers; int closing; int log_root_recovering; --- a/fs/btrfs/disk-io.c 2013-09-16 13:46:30.875025162 -0400 +++ b/fs/btrfs/disk-io.c 2013-09-16 13:46:32.970992936 -0400 @@ -2163,7 +2163,6 @@ int open_ctree(struct super_block *sb, mutex_init(&fs_info->reloc_mutex); seqlock_init(&fs_info->profiles_lock); - init_completion(&fs_info->kobj_unregister); INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); INIT_LIST_HEAD(&fs_info->space_info); INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); --- a/fs/btrfs/sysfs.c 2013-09-16 13:46:30.875025162 -0400 +++ b/fs/btrfs/sysfs.c 2013-09-16 13:48:53.252952421 -0400 @@ -22,24 +22,76 @@ #include #include #include +#include #include "ctree.h" #include "disk-io.h" #include "transaction.h" +BTRFS_FEAT_ATTR_INCOMPAT(mixed_backref, MIXED_BACKREF); +BTRFS_FEAT_ATTR_INCOMPAT(default_subvol, DEFAULT_SUBVOL); +BTRFS_FEAT_ATTR_INCOMPAT(mixed_groups, MIXED_GROUPS); +BTRFS_FEAT_ATTR_INCOMPAT(compress_lzo, COMPRESS_LZO); +BTRFS_FEAT_ATTR_INCOMPAT(compress_lzov2, COMPRESS_LZOv2); +BTRFS_FEAT_ATTR_INCOMPAT(big_metadata, BIG_METADATA); +BTRFS_FEAT_ATTR_INCOMPAT(extended_iref, EXTENDED_IREF); +BTRFS_FEAT_ATTR_INCOMPAT(raid56, RAID56); +BTRFS_FEAT_ATTR_INCOMPAT(skinny_metadata, SKINNY_METADATA); + +static struct attribute *btrfs_supp_feature_attrs[] = { + BTRFS_FEAT_ATTR_LIST(mixed_backref) + BTRFS_FEAT_ATTR_LIST(default_subvol) + BTRFS_FEAT_ATTR_LIST(mixed_groups) + BTRFS_FEAT_ATTR_LIST(compress_lzo) + BTRFS_FEAT_ATTR_LIST(compress_lzov2) + BTRFS_FEAT_ATTR_LIST(big_metadata) + BTRFS_FEAT_ATTR_LIST(extended_iref) + BTRFS_FEAT_ATTR_LIST(raid56) + BTRFS_FEAT_ATTR_LIST(skinny_metadata) + NULL +}; + +static ssize_t btrfs_supp_attr_show(struct kobject *kobj, struct attribute *a, + char *buf) +{ + return snprintf(buf, PAGE_SIZE, "0\n"); +} + +static const struct sysfs_ops btrfs_supp_attr_ops = { + .show = btrfs_supp_attr_show, +}; + +static struct kobj_type btrfs_supp_feat_ktype = { + .default_attrs = btrfs_supp_feature_attrs, + .sysfs_ops = &btrfs_supp_attr_ops, + .release = kobj_completion_release, +}; + /* /sys/fs/btrfs/ entry */ static struct kset *btrfs_kset; +static struct kobj_completion btrfs_features; int btrfs_init_sysfs(void) { + int ret; btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj); if (!btrfs_kset) return -ENOMEM; + + kobj_completion_init(&btrfs_features, &btrfs_supp_feat_ktype); + btrfs_features.kc_kobj.kset = btrfs_kset; + ret = kobject_add(&btrfs_features.kc_kobj, NULL, "features"); + if (ret) { + kset_unregister(btrfs_kset); + return ret; + } + return 0; } void btrfs_exit_sysfs(void) { + kobj_completion_del_and_wait(&btrfs_features); kset_unregister(btrfs_kset); } --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ b/fs/btrfs/sysfs.h 2013-09-16 13:49:01.064844933 -0400 @@ -0,0 +1,35 @@ +#ifndef _BTRFS_SYSFS_H_ +#define _BTRFS_SYSFS_H_ + +enum btrfs_feature_set { + FEAT_COMPAT, + FEAT_COMPAT_RO, + FEAT_INCOMPAT, + FEAT_MAX +}; + +struct btrfs_feature_attr { + struct attribute attr; /* global show, no store */ + enum btrfs_feature_set feature_set; + u64 feature_bit; +}; + +#define BTRFS_FEAT_ATTR(_name, _feature_set, _prefix, _feature_bit) \ +static struct btrfs_feature_attr btrfs_attr_##_name = { \ + .attr = { .name = __stringify(_name), .mode = S_IRUGO, }, \ + .feature_set = _feature_set, \ + .feature_bit = _prefix ##_## _feature_bit, \ +} +#define BTRFS_FEAT_ATTR_LIST(_name) (&btrfs_attr_##_name.attr), + +#define BTRFS_FEAT_ATTR_COMPAT(name, feature) \ + BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature) +#define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \ + BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT, feature) +#define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \ + BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature) + +/* convert from attribute */ +#define to_btrfs_feature_attr(a) \ + container_of(a, struct btrfs_feature_attr, attr) +#endif /* _BTRFS_SYSFS_H_ */