summaryrefslogtreecommitdiff
path: root/usr/src/lib/fm
diff options
context:
space:
mode:
authorKeith M Wesolowski <wesolows@foobazco.org>2013-08-08 21:53:18 +0000
committerKeith M Wesolowski <wesolows@foobazco.org>2013-08-08 21:53:18 +0000
commitb059ddba3e870cb075b1b4470a4510e018fe98a1 (patch)
tree70f8baa9a846488d2d83ef50221f963fcfbd411e /usr/src/lib/fm
parent3bc2a09f9d0806b878b63183b1a46b81bbd33612 (diff)
parenta86e931db9089f6b514c9b98b206d0eb2c1a2a34 (diff)
downloadillumos-joyent-b059ddba3e870cb075b1b4470a4510e018fe98a1.tar.gz
[illumos-gate merge]
commit a86e931db9089f6b514c9b98b206d0eb2c1a2a34 3912 crti needs to make sure _init and _fini are 16-byte stack aligned commit 2954adb080121c02025bb94537c313e6f51c9fd7 3931 vrrpadm should work with a vnic as its link 3932 vrrpadm dies when its configuration file doesn't exist commit da4badc008f69df74f592b0831d92baa6dfcee76 4013 backout 6910752/6968206: needs more work commit 2227b8ad8ebd0984a34b696ce07145248700852b 3944 libtopo zfs module will clobber libzfs handle when an instance of the module unloads
Diffstat (limited to 'usr/src/lib/fm')
-rw-r--r--usr/src/lib/fm/topo/libtopo/common/zfs.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/usr/src/lib/fm/topo/libtopo/common/zfs.c b/usr/src/lib/fm/topo/libtopo/common/zfs.c
index 573115efe3..e7989ea6e3 100644
--- a/usr/src/lib/fm/topo/libtopo/common/zfs.c
+++ b/usr/src/lib/fm/topo/libtopo/common/zfs.c
@@ -22,6 +22,7 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
#include <stdio.h>
@@ -41,6 +42,7 @@
#include <topo_subr.h>
#include <libzfs.h>
#include <zfs.h>
+#include <pthread.h>
static int zfs_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
topo_instance_t, void *, void *);
@@ -59,7 +61,9 @@ static const topo_modops_t zfs_ops =
static const topo_modinfo_t zfs_info =
{ ZFS, FM_FMRI_SCHEME_ZFS, ZFS_VERSION, &zfs_ops };
-static libzfs_handle_t *g_zfs;
+static libzfs_handle_t *g_zfs = NULL;
+static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
+static int g_refcount = 0;
int
zfs_init(topo_mod_t *mod, topo_version_t version)
@@ -80,8 +84,18 @@ zfs_init(topo_mod_t *mod, topo_version_t version)
"%s\n", topo_mod_errmsg(mod));
return (-1); /* mod errno already set */
}
- if (!g_zfs)
- g_zfs = libzfs_init();
+
+ (void) pthread_mutex_lock(&g_lock);
+ if (g_refcount == 0) {
+ if ((g_zfs = libzfs_init()) == NULL) {
+ (void) pthread_mutex_unlock(&g_lock);
+ topo_mod_dprintf(mod, "libzfs_init() failed");
+ topo_mod_unregister(mod);
+ return (topo_mod_seterrno(mod, EMOD_UNKNOWN));
+ }
+ }
+ g_refcount++;
+ (void) pthread_mutex_unlock(&g_lock);
return (0);
}
@@ -89,10 +103,13 @@ zfs_init(topo_mod_t *mod, topo_version_t version)
void
zfs_fini(topo_mod_t *mod)
{
- if (g_zfs) {
+ (void) pthread_mutex_lock(&g_lock);
+ g_refcount--;
+ if (g_refcount == 0) {
libzfs_fini(g_zfs);
g_zfs = NULL;
}
+ (void) pthread_mutex_unlock(&g_lock);
topo_mod_unregister(mod);
}
@@ -155,7 +172,7 @@ fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen)
cb.cb_guid = pool_guid;
cb.cb_pool = NULL;
- if (g_zfs != NULL && zpool_iter(g_zfs, find_pool, &cb) == 1) {
+ if (zpool_iter(g_zfs, find_pool, &cb) == 1) {
name = zpool_get_name(cb.cb_pool);
} else {
(void) snprintf(guidbuf, sizeof (guidbuf), "%llx", pool_guid);