From 4fdb04d0a1ac0d298d2d6c1147c3dbd6bd85a450 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 14 Jan 2009 14:25:25 -0800 Subject: [PATCH] A little hackery to handle using zdb when the module stack isn't loaded. This is a hack and should be addressed upstream, zdb should not be attempting to initialize services it doesn't need --- lib/libzfs/libzfs_util.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 605c91a4ce..1a1025f3bf 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -567,8 +567,16 @@ libzfs_init(void) #endif if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { - free(hdl); - return (NULL); + /* XXX: Allow this failure on linux systems for now. It + * occurs when we attempt to open the /dev/zfs without the + * ZFS module stack loaded. This is normally a problem but + * tools such as zdb call this function and never use the + * ioctl() interface. Long term this should be cleaned up. + */ + if (errno != ENXIO) { + free(hdl); + return (NULL); + } } if ((hdl->libzfs_mnttab = fopen(MNTTAB, "r")) == NULL) { @@ -588,7 +596,8 @@ libzfs_init(void) void libzfs_fini(libzfs_handle_t *hdl) { - (void) close(hdl->libzfs_fd); + if (hdl->libzfs_fd != -1) + (void) close(hdl->libzfs_fd); if (hdl->libzfs_mnttab) (void) fclose(hdl->libzfs_mnttab); if (hdl->libzfs_sharetab)