From patchwork Mon Sep 16 18:19:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 2899161 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 29030BFF05 for ; Mon, 16 Sep 2013 18:22:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 051392016A for ; Mon, 16 Sep 2013 18:22:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1BAF52025D for ; Mon, 16 Sep 2013 18:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752091Ab3IPSWW (ORCPT ); Mon, 16 Sep 2013 14:22:22 -0400 Received: from cantor2.suse.de ([195.135.220.15]:51728 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751982Ab3IPSWS (ORCPT ); Mon, 16 Sep 2013 14:22:18 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C47D7A535B; Mon, 16 Sep 2013 20:22:16 +0200 (CEST) Message-Id: <20130916182018.796022700@suse.com> User-Agent: quilt/0.60-5.1.1 Date: Mon, 16 Sep 2013 14:19:17 -0400 From: Jeff Mahoney To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, clmason@fusionio.com Subject: [patch 7/9] btrfs: add publishing of unknown features in sysfs References: <20130916181910.799140428@suse.com> Content-Disposition: inline; filename=btrfs-add-publishing-of-unknown-features-in-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 With the compat and compat-ro bits, it's possible for file systems to exist that have features that aren't supported by the kernel's file system implementation yet still be mountable. This patch publishes read-only info on those features using a prefix:number format, where the number is the bit number rather than the shifted value. e.g. "compat:12" Signed-off-by: Jeff Mahoney --- fs/btrfs/sysfs.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 4 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/sysfs.c 2013-09-10 15:58:32.209384497 -0400 +++ b/fs/btrfs/sysfs.c 2013-09-10 15:58:32.645377839 -0400 @@ -68,6 +68,58 @@ static struct kobj_type btrfs_supp_feat_ .release = kobj_completion_release, }; +const char * const btrfs_feature_set_names[FEAT_MAX] = { + [FEAT_COMPAT] = "compat", + [FEAT_COMPAT_RO] = "compat_ro", + [FEAT_INCOMPAT] = "incompat", +}; + +static char btrfs_feature_names[FEAT_MAX][64][13]; +static struct btrfs_feature_attr btrfs_feature_attrs[FEAT_MAX][64]; + +static void init_feature_set_attrs(enum btrfs_feature_set set) +{ + int i; + int len = strlen(btrfs_feature_set_names[set]) + 4; + + for (i = 0; i < 64; i++) { + char *name = btrfs_feature_names[set][i]; + struct btrfs_feature_attr *fa; + + snprintf(name, len, "%s:%u", btrfs_feature_set_names[set], i); + + fa = &btrfs_feature_attrs[set][i]; + fa->attr.name = name; + fa->attr.mode = S_IRUGO; + fa->feature_set = set; + fa->feature_bit = (1ULL << i); + } +} + +static void init_feature_attrs(void) +{ + int i; + + init_feature_set_attrs(FEAT_COMPAT); + init_feature_set_attrs(FEAT_COMPAT_RO); + init_feature_set_attrs(FEAT_INCOMPAT); + + /* Copy the names over for supported features */ + for (i = 0; btrfs_supp_feature_attrs[i]; i++) { + struct btrfs_feature_attr *fa; + struct attribute *attr; + int n; + + fa = to_btrfs_feature_attr(btrfs_supp_feature_attrs[i]); + n = ilog2(fa->feature_bit); + + attr = &btrfs_feature_attrs[fa->feature_set][n].attr; + attr->name = fa->attr.name; + + btrfs_feature_names[fa->feature_set][n][0] = '\0'; + } +} + static u64 get_features(struct btrfs_fs_info *fs_info, enum btrfs_feature_set set) { @@ -138,12 +190,12 @@ static struct kobj_type btrfs_ktype = { .release = kobj_completion_release, }; -static int add_per_fs_features(struct btrfs_fs_info *fs_info) +static int add_per_fs_feature_set(struct btrfs_fs_info *fs_info, + enum btrfs_feature_set set) { 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); + for (i = 0; i < ARRAY_SIZE(btrfs_feature_attrs[0]); i++) { + struct btrfs_feature_attr *fa = &btrfs_feature_attrs[set][i]; u64 features = get_features(fs_info, fa->feature_set); int error; @@ -158,6 +210,20 @@ static int add_per_fs_features(struct bt return 0; } +static int add_per_fs_features(struct btrfs_fs_info *fs_info) +{ + enum btrfs_feature_set set; + int error; + + for (set = FEAT_COMPAT; set < FEAT_MAX; set++) { + error = add_per_fs_feature_set(fs_info, set); + if (error) + return error; + } + + return 0; +} + /* /sys/fs/btrfs/ entry */ static struct kset *btrfs_kset; @@ -207,6 +273,7 @@ int btrfs_init_sysfs(void) if (!btrfs_kset) return -ENOMEM; + init_feature_attrs(); 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");