1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/lib/locking/external_locking.c

95 lines
2.4 KiB
C
Raw Normal View History

/*
2004-03-30 23:35:44 +04:00
* Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2.
*
2004-03-30 23:35:44 +04:00
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
2002-11-18 17:01:16 +03:00
#include "lib.h"
#include "locking_types.h"
#include "defaults.h"
2002-11-18 17:01:16 +03:00
#include "sharedlib.h"
2002-11-18 17:01:16 +03:00
static void *_locking_lib = NULL;
2004-05-19 01:57:24 +04:00
static void (*_reset_fn) (void) = NULL;
2002-11-18 17:01:16 +03:00
static void (*_end_fn) (void) = NULL;
static int (*_lock_fn) (struct cmd_context * cmd, const char *resource,
int flags) = NULL;
2004-03-26 23:17:11 +03:00
static int (*_init_fn) (int type, struct config_tree * cft,
uint32_t *flags) = NULL;
2002-11-18 17:01:16 +03:00
static int _lock_resource(struct cmd_context *cmd, const char *resource,
int flags)
{
2002-11-18 17:01:16 +03:00
if (_lock_fn)
return _lock_fn(cmd, resource, flags);
else
return 0;
}
2002-11-18 17:01:16 +03:00
static void _fin_external_locking(void)
{
2002-11-18 17:01:16 +03:00
if (_end_fn)
_end_fn();
2002-11-18 17:01:16 +03:00
dlclose(_locking_lib);
2002-11-18 17:01:16 +03:00
_locking_lib = NULL;
_init_fn = NULL;
_end_fn = NULL;
_lock_fn = NULL;
2004-05-19 01:57:24 +04:00
_reset_fn = NULL;
}
static void _reset_external_locking(void)
{
if (_reset_fn)
_reset_fn();
}
int init_external_locking(struct locking_type *locking, struct config_tree *cft)
{
2002-11-18 17:01:16 +03:00
const char *libname;
2002-11-18 17:01:16 +03:00
if (_locking_lib) {
log_error("External locking already initialised");
return 1;
}
2002-11-18 17:01:16 +03:00
locking->lock_resource = _lock_resource;
locking->fin_locking = _fin_external_locking;
2004-05-19 01:57:24 +04:00
locking->reset_locking = _reset_external_locking;
2004-03-26 23:17:11 +03:00
locking->flags = 0;
libname = find_config_str(cft->root, "global/locking_library",
2002-11-18 17:01:16 +03:00
DEFAULT_LOCKING_LIB);
if (!(_locking_lib = load_shared_library(cft, libname, "locking"))) {
2002-11-18 17:01:16 +03:00
stack;
return 0;
}
/* Get the functions we need */
2004-03-26 23:17:11 +03:00
if (!(_init_fn = dlsym(_locking_lib, "locking_init")) ||
2002-11-18 17:01:16 +03:00
!(_lock_fn = dlsym(_locking_lib, "lock_resource")) ||
2004-05-19 01:57:24 +04:00
!(_reset_fn = dlsym(_locking_lib, "reset_locking")) ||
2004-03-26 23:17:11 +03:00
!(_end_fn = dlsym(_locking_lib, "locking_end"))) {
2002-11-18 17:01:16 +03:00
log_error("Shared library %s does not contain locking "
"functions", libname);
dlclose(_locking_lib);
_locking_lib = NULL;
return 0;
}
2002-11-18 17:01:16 +03:00
log_verbose("Loaded external locking library %s", libname);
2004-03-26 23:17:11 +03:00
return _init_fn(2, cft, &locking->flags);
}