Skip to contentSkip to conversation

zfs: recognize zpools formatted with features support as used in OpenZFS

PATCH In review WHR 1 participant 2 messages Apr 30, 2024

lore
Share & tools
lore

WHR

author
#0 lore raw

PATCH 1/1 zfs: recognize zpools formatted with features support as used in OpenZFS

Currently no features are implemented, only the zpool version 5000 that indicating the features support, is recognized. Since it is possible for OpenZFS to create a pool with features support enabled, but without enabling any actual feature, this change enables U-Boot to read such pools.

fs/zfs/zfs.c +12 -7
index 4896cc18ef..3575c23a42 100644
@@ -336,6 +336,12 @@ vdev_uberblock_compare(uberblock_t *ub1, uberblock_t *ub2)
 	return 0;
 }
 
+static inline int
+is_supported_spa_version(uint64_t version) {
+	return version == FEATURES_SUPPORTED_SPA_VERSION ||
+		(version > 0 && version <= SPA_VERSION);
+}
+
 /*
  * Three pieces of information are needed to verify an uberblock: the magic
  * number, the version number, and the checksum.
@@ -348,6 +354,7 @@ static int
 uberblock_verify(uberblock_t *uber, int offset, struct zfs_data *data)
 {
 	int err;
+	uint64_t spa_version;
 	zfs_endian_t endian = UNKNOWN_ENDIAN;
 	zio_cksum_t zc;
 
@@ -357,14 +364,12 @@ uberblock_verify(uberblock_t *uber, int offset, struct zfs_data *data)
 		return ZFS_ERR_BAD_FS;
 	}
 
-	if (zfs_to_cpu64(uber->ub_magic, LITTLE_ENDIAN) == UBERBLOCK_MAGIC
-		&& zfs_to_cpu64(uber->ub_version, LITTLE_ENDIAN) > 0
-		&& zfs_to_cpu64(uber->ub_version, LITTLE_ENDIAN) <= SPA_VERSION)
+	if (zfs_to_cpu64(uber->ub_magic, LITTLE_ENDIAN) == UBERBLOCK_MAGIC &&
+		is_supported_spa_version(zfs_to_cpu64(uber->ub_version, LITTLE_ENDIAN)))
 		endian = LITTLE_ENDIAN;
 
-	if (zfs_to_cpu64(uber->ub_magic, BIG_ENDIAN) == UBERBLOCK_MAGIC
-		&& zfs_to_cpu64(uber->ub_version, BIG_ENDIAN) > 0
-		&& zfs_to_cpu64(uber->ub_version, BIG_ENDIAN) <= SPA_VERSION)
+	if (zfs_to_cpu64(uber->ub_magic, BIG_ENDIAN) == UBERBLOCK_MAGIC &&
+		is_supported_spa_version(zfs_to_cpu64(uber->ub_version, BIG_ENDIAN)))
 		endian = BIG_ENDIAN;
 
 	if (endian == UNKNOWN_ENDIAN) {
@@ -1790,7 +1795,7 @@ check_pool_label(struct zfs_data *data)
 		return ZFS_ERR_BAD_FS;
 	}
 
-	if (version > SPA_VERSION) {
+	if (!is_supported_spa_version(version)) {
 		free(nvlist);
 		printf("SPA version too new %llu > %llu\n",
 			   (unsigned long long) version,
author
#1 lore raw
Quoted 10 lines

Currently no features are implemented, only the zpool version 5000 that indicating the features support, is recognized. Since it is possible for OpenZFS to create a pool with features support enabled, but without enabling any actual feature, this change enables U-Boot to read such pools.

This commit is missing changed file include/zfs/zfs.h, has been replaced by https://lists.denx.de/pipermail/u-boot/2024-April/552434.html, please drop.