Commit f7cea56c authored by David Sterba's avatar David Sterba

btrfs: sysfs: export supported checksums

Export supported checksum algorithms via sysfs in the list of static
features:

  /sys/fs/btrfs/features/supported_checksums

Space spearated list of checksum algorithm names.
Co-developed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 3831bf00
...@@ -53,6 +53,11 @@ const char *btrfs_super_csum_name(u16 csum_type) ...@@ -53,6 +53,11 @@ const char *btrfs_super_csum_name(u16 csum_type)
return btrfs_csums[csum_type].name; return btrfs_csums[csum_type].name;
} }
size_t __const btrfs_get_num_csums(void)
{
return ARRAY_SIZE(btrfs_csums);
}
struct btrfs_path *btrfs_alloc_path(void) struct btrfs_path *btrfs_alloc_path(void)
{ {
return kmem_cache_zalloc(btrfs_path_cachep, GFP_NOFS); return kmem_cache_zalloc(btrfs_path_cachep, GFP_NOFS);
......
...@@ -2163,6 +2163,8 @@ BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, ...@@ -2163,6 +2163,8 @@ BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
int btrfs_super_csum_size(const struct btrfs_super_block *s); int btrfs_super_csum_size(const struct btrfs_super_block *s);
const char *btrfs_super_csum_name(u16 csum_type); const char *btrfs_super_csum_name(u16 csum_type);
size_t __const btrfs_get_num_csums(void);
/* /*
* The leaf data grows from end-to-front in the node. * The leaf data grows from end-to-front in the node.
......
...@@ -295,8 +295,30 @@ static ssize_t rmdir_subvol_show(struct kobject *kobj, ...@@ -295,8 +295,30 @@ static ssize_t rmdir_subvol_show(struct kobject *kobj,
} }
BTRFS_ATTR(static_feature, rmdir_subvol, rmdir_subvol_show); BTRFS_ATTR(static_feature, rmdir_subvol, rmdir_subvol_show);
static ssize_t supported_checksums_show(struct kobject *kobj,
struct kobj_attribute *a, char *buf)
{
ssize_t ret = 0;
int i;
for (i = 0; i < btrfs_get_num_csums(); i++) {
/*
* This "trick" only works as long as 'enum btrfs_csum_type' has
* no holes in it
*/
ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s%s",
(i == 0 ? "" : " "), btrfs_super_csum_name(i));
}
ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
return ret;
}
BTRFS_ATTR(static_feature, supported_checksums, supported_checksums_show);
static struct attribute *btrfs_supported_static_feature_attrs[] = { static struct attribute *btrfs_supported_static_feature_attrs[] = {
BTRFS_ATTR_PTR(static_feature, rmdir_subvol), BTRFS_ATTR_PTR(static_feature, rmdir_subvol),
BTRFS_ATTR_PTR(static_feature, supported_checksums),
NULL NULL
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment