Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Jul 2023 00:41:42 GMT
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 2f700ca965a0 - main - libbe: bail out early if the zfs kmod isn't loaded
Message-ID:  <202307070041.3670fg7S003296@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kevans:

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

commit 2f700ca965a04c4a03b6f760da6a210b6ca4df4b
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2023-07-07 00:41:14 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2023-07-07 00:41:14 +0000

    libbe: bail out early if the zfs kmod isn't loaded
    
    As noted in the comment, we already know the rest of libbe_init() will
    fail because there's no pool imported.  Avoid the side effect by
    checking beforehand and bailing out early.
    
    With this, freebsd-update(8) should no longer trigger a load of the zfs
    kmod just because it runs `bectl check`.
    
    Reviewed by:    jwmaag_gmail.com, rew
    Differential Revision:  https://reviews.freebsd.org/D36188
---
 lib/libbe/be.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/libbe/be.c b/lib/libbe/be.c
index c4dec043fcb6..753fde746e31 100644
--- a/lib/libbe/be.c
+++ b/lib/libbe/be.c
@@ -29,6 +29,7 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
+#include <sys/module.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/ucred.h>
@@ -119,6 +120,16 @@ libbe_init(const char *root)
 	lbh = NULL;
 	poolname = pos = NULL;
 
+	/*
+	 * If the zfs kmod's not loaded then the later libzfs_init() will load
+	 * the module for us, but that's not desirable for a couple reasons.  If
+	 * the module's not loaded, there's no pool imported and we're going to
+	 * fail anyways.  We also don't really want libbe consumers to have that
+	 * kind of side-effect (module loading) in the general case.
+	 */
+	if (modfind("zfs") < 0)
+		goto err;
+
 	if ((lbh = calloc(1, sizeof(libbe_handle_t))) == NULL)
 		goto err;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202307070041.3670fg7S003296>