From patchwork Tue Aug 27 09:37:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11116481 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C072413B1 for ; Tue, 27 Aug 2019 09:37:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9DB6F2173E for ; Tue, 27 Aug 2019 09:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729898AbfH0Jhy (ORCPT ); Tue, 27 Aug 2019 05:37:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:34028 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729596AbfH0Jhx (ORCPT ); Tue, 27 Aug 2019 05:37:53 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B33A9AFDD for ; Tue, 27 Aug 2019 09:37:52 +0000 (UTC) From: Johannes Thumshirn To: David Sterba Cc: Linux BTRFS Mailinglist , Johannes Thumshirn Subject: [PATCH v4 4/4] btrfs: sysfs: export supported checksums Date: Tue, 27 Aug 2019 11:37:50 +0200 Message-Id: <20190827093750.15310-5-jthumshirn@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190827093750.15310-1-jthumshirn@suse.de> References: <20190827093750.15310-1-jthumshirn@suse.de> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: David Sterba Export supported checksum algorithms via sysfs. Signed-off-by: David Sterba Signed-off-by: Johannes Thumshirn Reviewed-by: Nikolay Borisov --- Changes to v2: - Prevent possible overflow of sysfs attribute Changes to v1: - Removed btrfs_checksums_store() function (Nik) - Renamed sysfs file to supported_checksums --- fs/btrfs/sysfs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index f6d3c80f2e28..cae9c99253c7 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -246,6 +246,24 @@ static umode_t btrfs_feature_visible(struct kobject *kobj, return mode; } +static ssize_t btrfs_supported_checksums_show(struct kobject *kobj, + struct kobj_attribute *a, + char *buf) +{ + ssize_t ret = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(btrfs_csums); i++) { + ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s%s", + (i == 0 ? "" : ", "), + btrfs_csums[i].name); + + } + + ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); + return ret; +} + BTRFS_FEAT_ATTR_INCOMPAT(mixed_backref, MIXED_BACKREF); BTRFS_FEAT_ATTR_INCOMPAT(default_subvol, DEFAULT_SUBVOL); BTRFS_FEAT_ATTR_INCOMPAT(mixed_groups, MIXED_GROUPS); @@ -259,6 +277,14 @@ BTRFS_FEAT_ATTR_INCOMPAT(no_holes, NO_HOLES); BTRFS_FEAT_ATTR_INCOMPAT(metadata_uuid, METADATA_UUID); BTRFS_FEAT_ATTR_COMPAT_RO(free_space_tree, FREE_SPACE_TREE); +static struct btrfs_feature_attr btrfs_attr_features_checksums_name = { + .kobj_attr = __INIT_KOBJ_ATTR(supported_checksums, S_IRUGO, + btrfs_supported_checksums_show, + NULL), + .feature_set = FEAT_INCOMPAT, + .feature_bit = 0, +}; + static struct attribute *btrfs_supported_feature_attrs[] = { BTRFS_FEAT_ATTR_PTR(mixed_backref), BTRFS_FEAT_ATTR_PTR(default_subvol), @@ -272,6 +298,9 @@ static struct attribute *btrfs_supported_feature_attrs[] = { BTRFS_FEAT_ATTR_PTR(no_holes), BTRFS_FEAT_ATTR_PTR(metadata_uuid), BTRFS_FEAT_ATTR_PTR(free_space_tree), + + &btrfs_attr_features_checksums_name.kobj_attr.attr, + NULL };