summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorSerapheim Dimitropoulos <serapheim@delphix.com>2017-01-17 17:04:34 -0800
committerMatthew Ahrens <mahrens@delphix.com>2017-01-18 14:47:18 -0800
commit7c13517fff71be473e47531ef4330160c042bedc (patch)
treec8279f8fc882d8f592316f9f36be5272ef1d403b /usr/src
parent95e79c0b22e3ef2a1ac6412a4ab12cd99922fc12 (diff)
downloadillumos-gate-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')
-rw-r--r--usr/src/lib/libzfs/Makefile.com1
-rw-r--r--usr/src/lib/libzfs/common/libzfs_pool.c2
-rw-r--r--usr/src/lib/libzfs/common/libzfs_sendrecv.c9
-rw-r--r--usr/src/lib/libzfs_core/Makefile.com3
-rw-r--r--usr/src/lib/libzfs_core/common/libzfs_core.c16
5 files changed, 26 insertions, 5 deletions
diff --git a/usr/src/lib/libzfs/Makefile.com b/usr/src/lib/libzfs/Makefile.com
index c80f481d6d..31619b01c1 100644
--- a/usr/src/lib/libzfs/Makefile.com
+++ b/usr/src/lib/libzfs/Makefile.com
@@ -72,6 +72,7 @@ C99LMODE= -Xc99=%all
LDLIBS += -lc -lm -ldevid -lgen -lnvpair -luutil -lavl -lefi \
-ladm -lidmap -ltsol -lmd -lumem -lzfs_core
CPPFLAGS += $(INCS) -D_LARGEFILE64_SOURCE=1 -D_REENTRANT
+$(NOT_RELEASE_BUILD)CPPFLAGS += -DDEBUG
# There's no lint library for zlib, so only include this when building
$(DYNLIB) := LDLIBS += -lz
diff --git a/usr/src/lib/libzfs/common/libzfs_pool.c b/usr/src/lib/libzfs/common/libzfs_pool.c
index 2c20ba8ffd..f9a05aeb39 100644
--- a/usr/src/lib/libzfs/common/libzfs_pool.c
+++ b/usr/src/lib/libzfs/common/libzfs_pool.c
@@ -818,7 +818,7 @@ zpool_prop_get_feature(zpool_handle_t *zhp, const char *propname, char *buf,
const char *feature = strchr(propname, '@') + 1;
supported = zpool_prop_feature(propname);
- ASSERT(supported || zfs_prop_unsupported(propname));
+ ASSERT(supported || zpool_prop_unsupported(propname));
/*
* Convert from feature name to feature guid. This conversion is
diff --git a/usr/src/lib/libzfs/common/libzfs_sendrecv.c b/usr/src/lib/libzfs/common/libzfs_sendrecv.c
index b8db4c9c8e..8d4f2fccd8 100644
--- a/usr/src/lib/libzfs/common/libzfs_sendrecv.c
+++ b/usr/src/lib/libzfs/common/libzfs_sendrecv.c
@@ -266,6 +266,15 @@ cksummer(void *arg)
ofp = fdopen(dda->inputfd, "r");
while (ssread(drr, sizeof (*drr), ofp) != 0) {
+ /*
+ * kernel filled in checksum, we are going to write same
+ * record, but need to regenerate checksum.
+ */
+ if (drr->drr_type != DRR_BEGIN) {
+ bzero(&drr->drr_u.drr_checksum.drr_checksum,
+ sizeof (drr->drr_u.drr_checksum.drr_checksum));
+ }
+
switch (drr->drr_type) {
case DRR_BEGIN:
{
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));