diff mbox series

[13/26] btrfs-progs: change how we check supported csum type

Message ID adac7e6d30d7b3fe266651bddd6542f161f7eeb1.1682799405.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: sync ctree.c into btrfs-progs | expand

Commit Message

Josef Bacik April 29, 2023, 8:19 p.m. UTC
In the kernel we have a basic btrfs_supported_super_csum() helper in
disk-io.c to validate the csum type.  Update progs to do the same thing
that the kernel does and then drop the btrfs_super_num_csums() helper as
it doesn't exist upstream and is no longer used.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 kernel-shared/ctree.c   |  5 -----
 kernel-shared/ctree.h   |  1 -
 kernel-shared/disk-io.c | 15 ++++++++++++++-
 3 files changed, 14 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c
index 97164cb8..0bd24646 100644
--- a/kernel-shared/ctree.c
+++ b/kernel-shared/ctree.c
@@ -65,11 +65,6 @@  const char *btrfs_super_csum_name(u16 csum_type)
 	return btrfs_csums[csum_type].name;
 }
 
-size_t btrfs_super_num_csums(void)
-{
-	return ARRAY_SIZE(btrfs_csums);
-}
-
 u16 btrfs_csum_type_size(u16 csum_type)
 {
 	return btrfs_csums[csum_type].size;
diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index b3e73e35..cab8f71b 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -1064,7 +1064,6 @@  void btrfs_set_item_key_unsafe(struct btrfs_root *root,
 u16 btrfs_super_csum_size(const struct btrfs_super_block *s);
 const char *btrfs_super_csum_name(u16 csum_type);
 u16 btrfs_csum_type_size(u16 csum_type);
-size_t btrfs_super_num_csums(void);
 
 /* root-item.c */
 int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index 3e0c3534..b7a98c4c 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1713,6 +1713,19 @@  struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
 	return info->fs_root;
 }
 
+static bool btrfs_supported_super_csum(u16 csum_type)
+{
+	switch (csum_type) {
+	case BTRFS_CSUM_TYPE_CRC32:
+	case BTRFS_CSUM_TYPE_XXHASH:
+	case BTRFS_CSUM_TYPE_SHA256:
+	case BTRFS_CSUM_TYPE_BLAKE2:
+		return true;
+	default:
+		return false;
+	}
+}
+
 /*
  * Check if the super is valid:
  * - nodesize/sectorsize - minimum, maximum, alignment
@@ -1737,7 +1750,7 @@  int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
 	}
 
 	csum_type = btrfs_super_csum_type(sb);
-	if (csum_type >= btrfs_super_num_csums()) {
+	if (!btrfs_supported_super_csum(csum_type)) {
 		error("unsupported checksum algorithm %u", csum_type);
 		return -EIO;
 	}