inuse_zpool.c revision 3e1bd7a2aaeb6188caef90679b98088cfef1edc6
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Attempt to dynamically link in the ZFS libzfs.so.1 so that we can
* see if there are any ZFS zpools on any of the slices.
*/
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <fcntl.h>
#include <thread.h>
#include <synch.h>
#include <dlfcn.h>
#include <link.h>
#include <ctype.h>
#include "libdiskmgt.h"
#include "disks_private.h"
/*
* Pointers to libzfs.so functions that we dynamically resolve.
*/
static int initialized = 0;
static void *init_zpool();
int
{
int found = 0;
int fd;
*errp = 0;
return (found);
}
(void) mutex_lock(&init_lock);
/*
* Dynamically load libzfs
*/
if (!initialized) {
if (!init_zpool()) {
(void) mutex_unlock(&init_lock);
return (found);
}
initialized = 1;
}
(void) mutex_unlock(&init_lock);
(void) rw_rdlock(&zpool_lock);
DM_USE_ZPOOL, errp);
found = 1;
}
}
(void) rw_unlock(&zpool_lock);
return (found);
}
/*
* Try to dynamically link the zfs functions we need.
*/
static void*
{
return (lh);
}
/*
* Instantiate the functions needed to get zpool configuration
* data
*/
"zpool_in_use")) == NULL) {
return (NULL);
}
return (lh);
}