diff options
| author | Serapheim Dimitropoulos <serapheim@delphix.com> | 2017-01-17 17:04:34 -0800 |
|---|---|---|
| committer | Matthew Ahrens <mahrens@delphix.com> | 2017-01-18 14:47:18 -0800 |
| commit | 7c13517fff71be473e47531ef4330160c042bedc (patch) | |
| tree | c8279f8fc882d8f592316f9f36be5272ef1d403b /usr/src/lib/libzfs_core | |
| parent | 95e79c0b22e3ef2a1ac6412a4ab12cd99922fc12 (diff) | |
| download | illumos-joyent-7c13517fff71be473e47531ef4330160c042bedc.tar.gz | |
7745 print error if lzc_* is called before libzfs_core_init
Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Dan McDonald <danmcd@omniti.com>
Diffstat (limited to 'usr/src/lib/libzfs_core')
| -rw-r--r-- | usr/src/lib/libzfs_core/Makefile.com | 3 | ||||
| -rw-r--r-- | usr/src/lib/libzfs_core/common/libzfs_core.c | 16 |
2 files changed, 15 insertions, 4 deletions
diff --git a/usr/src/lib/libzfs_core/Makefile.com b/usr/src/lib/libzfs_core/Makefile.com index 1a48353cef..cd756d5be3 100644 --- a/usr/src/lib/libzfs_core/Makefile.com +++ b/usr/src/lib/libzfs_core/Makefile.com @@ -20,7 +20,7 @@ # # # Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. -# Copyright (c) 2012 by Delphix. All rights reserved. +# Copyright (c) 2012, 2016 by Delphix. All rights reserved. # LIBRARY= libzfs_core.a @@ -51,6 +51,7 @@ C99MODE= -xc99=%all C99LMODE= -Xc99=%all LDLIBS += -lc -lnvpair CPPFLAGS += $(INCS) -D_LARGEFILE64_SOURCE=1 -D_REENTRANT +$(NOT_RELEASE_BUILD)CPPFLAGS += -DDEBUG SRCS= $(OBJS_COMMON:%.o=$(SRCDIR)/%.c) \ $(OBJS_SHARED:%.o=$(SRC)/common/zfs/%.c) diff --git a/usr/src/lib/libzfs_core/common/libzfs_core.c b/usr/src/lib/libzfs_core/common/libzfs_core.c index 7e7891798d..9868d70ffb 100644 --- a/usr/src/lib/libzfs_core/common/libzfs_core.c +++ b/usr/src/lib/libzfs_core/common/libzfs_core.c @@ -85,7 +85,7 @@ #include <sys/stat.h> #include <sys/zfs_ioctl.h> -static int g_fd; +static int g_fd = -1; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; static int g_refcount; @@ -110,9 +110,14 @@ libzfs_core_fini(void) { (void) pthread_mutex_lock(&g_lock); ASSERT3S(g_refcount, >, 0); - g_refcount--; - if (g_refcount == 0) + + if (g_refcount > 0) + g_refcount--; + + if (g_refcount == 0 && g_fd != -1) { (void) close(g_fd); + g_fd = -1; + } (void) pthread_mutex_unlock(&g_lock); } @@ -126,6 +131,7 @@ lzc_ioctl(zfs_ioc_t ioc, const char *name, size_t size; ASSERT3S(g_refcount, >, 0); + VERIFY3S(g_fd, !=, -1); (void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name)); @@ -328,6 +334,9 @@ lzc_exists(const char *dataset) */ zfs_cmd_t zc = { 0 }; + ASSERT3S(g_refcount, >, 0); + VERIFY3S(g_fd, !=, -1); + (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); return (ioctl(g_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0); } @@ -573,6 +582,7 @@ recv_impl(const char *snapname, nvlist_t *props, const char *origin, int error; ASSERT3S(g_refcount, >, 0); + VERIFY3S(g_fd, !=, -1); /* zc_name is name of containing filesystem */ (void) strlcpy(zc.zc_name, snapname, sizeof (zc.zc_name)); |
