git: 85baf98bbb36 - stable/12 - loader: update zfsimpl.c from illumos review suggestions

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Fri, 08 Oct 2021 16:09:00 UTC
The branch stable/12 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=85baf98bbb3632b89a6f2a7ebdf419681021f2a1

commit 85baf98bbb3632b89a6f2a7ebdf419681021f2a1
Author:     Toomas Soome <tsoome@FreeBSD.org>
AuthorDate: 2020-01-06 19:35:22 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2021-10-08 08:09:39 +0000

    loader: update zfsimpl.c from illumos review suggestions
    
    Add extra comments and update error handling.
    
    (cherry picked from commit 653c3383c7287535e75a94563455b48f177bc803)
---
 stand/libsa/zfs/zfsimpl.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/stand/libsa/zfs/zfsimpl.c b/stand/libsa/zfs/zfsimpl.c
index 70e44d7f0e8b..6c46bfdaea9c 100644
--- a/stand/libsa/zfs/zfsimpl.c
+++ b/stand/libsa/zfs/zfsimpl.c
@@ -849,7 +849,8 @@ vdev_create(uint64_t guid, vdev_read_t *_read)
 		vdev->v_read = _read;
 
 		/*
-		 * root vdev has no read function.
+		 * root vdev has no read function, we use this fact to
+		 * skip setting up data we do not need for root vdev.
 		 * We only point root vdev from spa.
 		 */
 		if (_read != NULL) {
@@ -894,7 +895,7 @@ vdev_set_initial_state(vdev_t *vdev, const nvlist_t *nvlist)
 	else if (isnt_present != 0)
 		vdev->v_state = VDEV_STATE_CANT_OPEN;
 
-	vdev->v_islog = is_log == 1;
+	vdev->v_islog = is_log != 0;
 }
 
 static int
@@ -998,9 +999,8 @@ vdev_init(uint64_t guid, const nvlist_t *nvlist, vdev_t **vdevp)
 		if (memcmp(type, VDEV_TYPE_RAIDZ, len) == 0) {
 			if (vdev->v_nparity < 1 ||
 			    vdev->v_nparity > 3) {
-				printf("ZFS: can only boot from disk, "
-				    "mirror, raidz1, raidz2 and raidz3 "
-				    "vdevs\n");
+				printf("ZFS: invalid raidz parity: %d\n",
+				    vdev->v_nparity);
 				return (EIO);
 			}
 			(void) asprintf(&name, "%.*s%d-%" PRIu64, len, type,
@@ -1074,16 +1074,17 @@ vdev_insert(vdev_t *top_vdev, vdev_t *vdev)
 
 	if (previous == NULL) {
 		STAILQ_INSERT_HEAD(&top_vdev->v_children, vdev, v_childlink);
-		count = vdev_child_count(top_vdev);
-		if (top_vdev->v_nchildren < count)
-			top_vdev->v_nchildren = count;
+	} else if (previous->v_id == vdev->v_id) {
+		/*
+		 * This vdev was configured from label config,
+		 * do not insert duplicate.
+		 */
 		return;
+	} else {
+		STAILQ_INSERT_AFTER(&top_vdev->v_children, previous, vdev,
+		    v_childlink);
 	}
 
-	if (previous->v_id == vdev->v_id)
-		return;
-
-	STAILQ_INSERT_AFTER(&top_vdev->v_children, previous, vdev, v_childlink);
 	count = vdev_child_count(top_vdev);
 	if (top_vdev->v_nchildren < count)
 		top_vdev->v_nchildren = count;
@@ -1137,6 +1138,10 @@ vdev_from_nvlist(spa_t *spa, uint64_t top_guid, const nvlist_t *nvlist)
 			}
 		}
 	} else {
+		/*
+		 * When there are no children, nvlist_find() does return
+		 * error, reset it because leaf devices have no children.
+		 */
 		rc = 0;
 	}
 	nvlist_destroy(kids);
@@ -1284,7 +1289,7 @@ vdev_init_from_nvlist(spa_t *spa, const nvlist_t *nvlist)
 	 * MOS config has at least one child for root vdev.
 	 */
 	if (rc != 0)
-		return (EIO);
+		return (rc);
 
 	for (int i = 0; i < nkids; i++) {
 		uint64_t guid;
@@ -3207,7 +3212,10 @@ zfs_spa_init(spa_t *spa)
 	if (rc != 0)
 		return (rc);
 
-	/* Update vdevs from MOS config. */
+	/*
+	 * Update vdevs from MOS config. Note, we do skip encoding bytes
+	 * here. See also vdev_label_read_config().
+	 */
 	rc = vdev_init_from_nvlist(spa, nvlist);
 	nvlist_destroy(nvlist);
 	return (rc);