aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2023-07-07 00:41:14 +0000
committerKyle Evans <kevans@FreeBSD.org>2023-11-03 04:50:46 +0000
commitee4bdd4b0db5b9d64e64490fc84a395344862aed (patch)
treea8082cf40588d64ecad719ff9855344a3764dca8
parentf383f4ad30a61fd0cd5104bb5c730aff139b993d (diff)
downloadsrc-ee4bdd4b0db5b9d64e64490fc84a395344862aed.tar.gz
src-ee4bdd4b0db5b9d64e64490fc84a395344862aed.zip
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 (cherry picked from commit 2f700ca965a04c4a03b6f760da6a210b6ca4df4b)
-rw-r--r--lib/libbe/be.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/libbe/be.c b/lib/libbe/be.c
index 6c7bf1b2ae45..e86ceccee74e 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>
@@ -115,6 +116,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;