git: 3a616b10d8f7 - main - kboot: Better default boot device

From: Warner Losh <imp_at_FreeBSD.org>
Date: Thu, 02 Mar 2023 18:18:30 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=3a616b10d8f7bb0f1af7d6a971bdfbabdfecd896

commit 3a616b10d8f7bb0f1af7d6a971bdfbabdfecd896
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-03-02 17:55:06 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-03-02 18:12:09 +0000

    kboot: Better default boot device
    
    Provide a better message when we can't find a boot device.
    
    Sponsored by: Netflix
---
 stand/kboot/main.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/stand/kboot/main.c b/stand/kboot/main.c
index 1cc4c0531772..e01507323bad 100644
--- a/stand/kboot/main.c
+++ b/stand/kboot/main.c
@@ -232,23 +232,22 @@ main(int argc, const char **argv)
 	bootdev = getenv("bootdev");
 	if (bootdev == NULL)
 		bootdev = hostdisk_gen_probe();
-	if (bootdev == NULL)
-		bootdev="zfs:";
 	hostfs_root = getenv("hostfs_root");
 	if (hostfs_root == NULL)
 		hostfs_root = "/";
 #if defined(LOADER_ZFS_SUPPORT)
-	if (strcmp(bootdev, "zfs:") == 0) {
+	if (bootdev == NULL || strcmp(bootdev, "zfs:") == 0) {
 		/*
 		 * Pseudo device that says go find the right ZFS pool. This will be
 		 * the first pool that we find that passes the sanity checks (eg looks
 		 * like it might be vbootable) and sets currdev to the right thing based
 		 * on active BEs, etc
 		 */
-		hostdisk_zfs_find_default();
-	} else
+		if (hostdisk_zfs_find_default())
+			bootdev = getenv("currdev");
+	}
 #endif
-	{
+	if (bootdev != NULL) {
 		/*
 		 * Otherwise, honor what's on the command line. If we've been
 		 * given a specific ZFS partition, then we'll honor it w/o BE
@@ -256,6 +255,8 @@ main(int argc, const char **argv)
 		 * boot than the default one in the pool.
 		 */
 		set_currdev(bootdev);
+	} else {
+		panic("Bootdev is still NULL");
 	}
 
 	printf("Boot device: %s with hostfs_root %s\n", bootdev, hostfs_root);