From owner-svn-src-head@freebsd.org Thu Jul 9 13:19:01 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7094936AD6F; Thu, 9 Jul 2020 13:19:01 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B2cFd2Nv7z42NS; Thu, 9 Jul 2020 13:19:01 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 309C2119AB; Thu, 9 Jul 2020 13:19:01 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 069DJ154056652; Thu, 9 Jul 2020 13:19:01 GMT (envelope-from tsoome@FreeBSD.org) Received: (from tsoome@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 069DJ1fv056651; Thu, 9 Jul 2020 13:19:01 GMT (envelope-from tsoome@FreeBSD.org) Message-Id: <202007091319.069DJ1fv056651@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tsoome set sender to tsoome@FreeBSD.org using -f From: Toomas Soome Date: Thu, 9 Jul 2020 13:19:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363042 - head/stand/libsa/zfs X-SVN-Group: head X-SVN-Commit-Author: tsoome X-SVN-Commit-Paths: head/stand/libsa/zfs X-SVN-Commit-Revision: 363042 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jul 2020 13:19:01 -0000 Author: tsoome Date: Thu Jul 9 13:19:00 2020 New Revision: 363042 URL: https://svnweb.freebsd.org/changeset/base/363042 Log: loader: setting vdev size based on label asize is not working Because we need to read asize from vdev_tree. We also need to consider different vdev type difference. Reviewed by: allanjude Sponsored by: Netflix, Klara Inc. Differential Revision: https://reviews.freebsd.org/D25586 Modified: head/stand/libsa/zfs/zfsimpl.c Modified: head/stand/libsa/zfs/zfsimpl.c ============================================================================== --- head/stand/libsa/zfs/zfsimpl.c Thu Jul 9 11:06:29 2020 (r363041) +++ head/stand/libsa/zfs/zfsimpl.c Thu Jul 9 13:19:00 2020 (r363042) @@ -1586,6 +1586,57 @@ vdev_label_read(vdev_t *vd, int l, void *buf, uint64_t return (vdev_read_phys(vd, &bp, buf, off, size)); } +static uint64_t +vdev_get_label_asize(nvlist_t *nvl) +{ + nvlist_t *vdevs; + uint64_t asize; + const char *type; + int len; + + asize = 0; + /* Get vdev tree */ + if (nvlist_find(nvl, ZPOOL_CONFIG_VDEV_TREE, DATA_TYPE_NVLIST, + NULL, &vdevs, NULL) != 0) + return (asize); + + /* + * Get vdev type. We will calculate asize for raidz, mirror and disk. + * For raidz, the asize is raw size of all children. + */ + if (nvlist_find(vdevs, ZPOOL_CONFIG_TYPE, DATA_TYPE_STRING, + NULL, &type, &len) != 0) + goto done; + + if (memcmp(type, VDEV_TYPE_MIRROR, len) != 0 && + memcmp(type, VDEV_TYPE_DISK, len) != 0 && + memcmp(type, VDEV_TYPE_RAIDZ, len) != 0) + goto done; + + if (nvlist_find(vdevs, ZPOOL_CONFIG_ASIZE, DATA_TYPE_UINT64, + NULL, &asize, NULL) != 0) + goto done; + + if (memcmp(type, VDEV_TYPE_RAIDZ, len) == 0) { + nvlist_t *kids; + int nkids; + + if (nvlist_find(vdevs, ZPOOL_CONFIG_CHILDREN, + DATA_TYPE_NVLIST_ARRAY, &nkids, &kids, NULL) != 0) { + asize = 0; + goto done; + } + + asize /= nkids; + nvlist_destroy(kids); + } + + asize += VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE; +done: + nvlist_destroy(vdevs); + return (asize); +} + static nvlist_t * vdev_label_read_config(vdev_t *vd, uint64_t txg) { @@ -1631,10 +1682,9 @@ vdev_label_read_config(vdev_t *vd, uint64_t txg) * Use asize from pool config. We need this * because we can get bad value from BIOS. */ - if (nvlist_find(nvl, ZPOOL_CONFIG_ASIZE, - DATA_TYPE_UINT64, NULL, &asize, NULL) == 0) { - vd->v_psize = asize + - VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE; + asize = vdev_get_label_asize(nvl); + if (asize != 0) { + vd->v_psize = asize; } } nvlist_destroy(tmp);