git: f168e96dfba2 - stable/13 - kboot: Add support for ZFS volumes

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:14:30 UTC
The branch stable/13 has been updated by imp:

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

commit f168e96dfba283958182ec7f64712be072147dad
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-01-13 21:20:40 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:47 +0000

    kboot: Add support for ZFS volumes
    
    Add the zfs device and filesystem to config and write the hook we need
    to probe zfs since there's not a generic mechanism in place to do that
    when ZFS is configured.
    
    Sponsored by:           Netflix
    Reviewed by:            kevans
    Differential Revision:  https://reviews.freebsd.org/D38008
    
    (cherry picked from commit f20ecce33a2a9a992fb267edf02edaa6eb9178b3)
---
 stand/kboot/conf.c |  9 +++++++++
 stand/kboot/main.c | 14 ++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/stand/kboot/conf.c b/stand/kboot/conf.c
index ba6031b52783..160cd0ad9554 100644
--- a/stand/kboot/conf.c
+++ b/stand/kboot/conf.c
@@ -33,6 +33,9 @@ __FBSDID("$FreeBSD$");
 #if defined(LOADER_NET_SUPPORT)
 #include "dev_net.h"
 #endif
+#ifdef LOADER_ZFS_SUPPORT
+#include "libzfs.h"
+#endif
 
 extern struct devsw hostdisk;
 extern struct devsw host_dev;
@@ -55,6 +58,9 @@ struct devsw *devsw[] = {
     &netdev,
 #endif
     &host_dev,
+#if defined(LOADER_ZFS_SUPPORT)
+    &zfs_dev,				/* Must be last */
+#endif
     NULL
 };
 
@@ -84,6 +90,9 @@ struct fs_ops *file_system[] = {
 #endif
 #if defined(LOADER_MSDOS_SUPPORT)
     &dosfs_fsops,
+#endif
+#if defined(LOADER_ZFS_SUPPORT)
+	&zfs_fsops,
 #endif
     &hostfs_fsops,
     NULL
diff --git a/stand/kboot/main.c b/stand/kboot/main.c
index 2e85121b7b12..d333737e164a 100644
--- a/stand/kboot/main.c
+++ b/stand/kboot/main.c
@@ -46,6 +46,7 @@ ssize_t kboot_readin(readin_handle_t fd, vm_offset_t dest, const size_t len);
 int kboot_autoload(void);
 uint64_t kboot_loadaddr(u_int type, void *data, uint64_t addr);
 static void kboot_kseg_get(int *nseg, void **ptr);
+static void kboot_zfs_probe(void);
 
 extern int command_fdt_internal(int argc, char *argv[]);
 
@@ -160,6 +161,7 @@ main(int argc, const char **argv)
 	archsw.arch_autoload = kboot_autoload;
 	archsw.arch_loadaddr = kboot_loadaddr;
 	archsw.arch_kexec_kseg_get = kboot_kseg_get;
+	archsw.arch_zfs_probe = kboot_zfs_probe;
 
 	/* Give us a sane world if we're running as init */
 	do_init();
@@ -380,6 +382,18 @@ kboot_kseg_get(int *nseg, void **ptr)
 	*ptr = &loaded_segments[0];
 }
 
+static void
+kboot_zfs_probe(void)
+{
+#if defined(LOADER_ZFS_SUPPORT)
+	/*
+	 * Open all the disks and partitions we can find to see if there are ZFS
+	 * pools on them.
+	 */
+	hostdisk_zfs_probe();
+#endif
+}
+
 /*
  * Since proper fdt command handling function is defined in fdt_loader_cmd.c,
  * and declaring it as extern is in contradiction with COMMAND_SET() macro