aboutsummaryrefslogtreecommitdiff
path: root/cddl
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2007-04-08 03:02:08 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2007-04-08 03:02:08 +0000
commit902cbe0df80e1aaa701853252414773dad2886dd (patch)
tree0a9afa399a3e77a94e2d26f11dfde2e6a57ea585 /cddl
parent264de85e73e17c4ed707d1ee71572b5d442869d8 (diff)
downloadsrc-902cbe0df80e1aaa701853252414773dad2886dd.tar.gz
src-902cbe0df80e1aaa701853252414773dad2886dd.zip
If we cannot open /dev/zfs try to load zfs.ko automatically and reopen.
Notes
Notes: svn path=/head/; revision=168484
Diffstat (limited to 'cddl')
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c
index 279835b4f197..b9d8b97c0450 100644
--- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c
+++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c
@@ -490,6 +490,21 @@ libzfs_print_on_error(libzfs_handle_t *hdl, boolean_t printerr)
hdl->libzfs_printerr = printerr;
}
+static int
+libzfs_load(void)
+{
+ int error;
+
+ if (modfind("zfs") < 0) {
+ /* Not present in kernel, try loading it. */
+ if (kldload("zfs") < 0 || modfind("zfs") < 0) {
+ if (errno != EEXIST)
+ return (error);
+ }
+ }
+ return (0);
+}
+
libzfs_handle_t *
libzfs_init(void)
{
@@ -500,8 +515,12 @@ libzfs_init(void)
}
if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)) < 0) {
- free(hdl);
- return (NULL);
+ if (libzfs_load() == 0)
+ hdl->libzfs_fd = open(ZFS_DEV, O_RDWR);
+ if (hdl->libzfs_fd < 0) {
+ free(hdl);
+ return (NULL);
+ }
}
if ((hdl->libzfs_mnttab = fopen(MNTTAB, "r")) == NULL) {