From patchwork Tue Apr 30 15:38:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WHR X-Patchwork-Id: 1929694 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VTPVc3k5Dz1ydT for ; Wed, 1 May 2024 01:38:32 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1ED5588A67; Tue, 30 Apr 2024 17:38:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=quarantine dis=none) header.from=rivoreo.one Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 7A8AF88A68; Tue, 30 Apr 2024 17:38:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: ** X-Spam-Status: No, score=2.9 required=5.0 tests=BAYES_00, RCVD_IN_PBL, RDNS_NONE, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from tianjin2.rivoreo.one (unknown [60.25.139.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1BF88884A2 for ; Tue, 30 Apr 2024 17:38:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=quarantine dis=none) header.from=rivoreo.one Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=whr@rivoreo.one Received: from [10.1.105.1] (localhost [127.0.0.1]) by tianjin2.rivoreo.one (Postfix) with ESMTP id C7C3A72144; Tue, 30 Apr 2024 23:38:14 +0800 (CST) Received: from 10.1.107.31 (SquirrelMail authenticated user whr) by _ with HTTP; Tue, 30 Apr 2024 23:38:14 +0800 Message-ID: <51ddf37de37df8afe45d683983b519f9.squirrel@_> Date: Tue, 30 Apr 2024 23:38:14 +0800 Subject: [PATCH] zfs: recognize zpools formatted with features support as used in OpenZFS From: "WHR" To: u-boot@lists.denx.de Cc: "Tom Rini" , mwleeds@mailtundra.com User-Agent: SquirrelMail/1.4.23 [SVN] MIME-Version: 1.0 X-Priority: 3 (Normal) Importance: Normal X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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. Signed-off-by: WHR diff --git a/fs/zfs/zfs.c b/fs/zfs/zfs.c index 4896cc18ef..3575c23a42 100644 --- a/fs/zfs/zfs.c +++ b/fs/zfs/zfs.c @@ -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,