Skip to content

Commit

Permalink
7745 print error if lzc_* is called before libzfs_core_init
Browse files Browse the repository at this point in the history
Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Dan McDonald <danmcd@omniti.com>
  • Loading branch information
sdimitro authored and ahrens committed Jan 18, 2017
1 parent 95e79c0 commit 7c13517
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions usr/src/lib/libzfs/Makefile.com
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion usr/src/lib/libzfs/common/libzfs_pool.c
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions usr/src/lib/libzfs/common/libzfs_sendrecv.c
Expand Up @@ -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:
{
Expand Down
3 changes: 2 additions & 1 deletion usr/src/lib/libzfs_core/Makefile.com
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions usr/src/lib/libzfs_core/common/libzfs_core.c
Expand Up @@ -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;

Expand All @@ -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);
}

Expand All @@ -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));

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 7c13517

Please sign in to comment.