2 * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include "locking_types.h"
19 #include "sharedlib.h"
20 #include "toolcontext.h"
22 static void *_locking_lib = NULL;
23 static void (*_reset_fn) (void) = NULL;
24 static void (*_end_fn) (void) = NULL;
25 static int (*_lock_fn) (struct cmd_context * cmd, const char *resource,
26 uint32_t flags) = NULL;
27 static int (*_init_fn) (int type, struct config_tree * cft,
28 uint32_t *flags) = NULL;
29 static int (*_lock_query_fn) (const char *resource, int *mode) = NULL;
31 static int _lock_resource(struct cmd_context *cmd, const char *resource,
35 return _lock_fn(cmd, resource, flags);
40 static void _fin_external_locking(void)
45 dlclose(_locking_lib);
54 static void _reset_external_locking(void)
60 int init_external_locking(struct locking_type *locking, struct cmd_context *cmd)
65 log_error("External locking already initialised");
69 locking->lock_resource = _lock_resource;
70 locking->fin_locking = _fin_external_locking;
71 locking->reset_locking = _reset_external_locking;
74 libname = find_config_tree_str(cmd, "global/locking_library",
77 if (!(_locking_lib = load_shared_library(cmd, libname, "locking", 1)))
80 /* Get the functions we need */
81 if (!(_init_fn = dlsym(_locking_lib, "locking_init")) ||
82 !(_lock_fn = dlsym(_locking_lib, "lock_resource")) ||
83 !(_reset_fn = dlsym(_locking_lib, "reset_locking")) ||
84 !(_end_fn = dlsym(_locking_lib, "locking_end"))) {
85 log_error("Shared library %s does not contain locking "
86 "functions", libname);
87 dlclose(_locking_lib);
92 if (!(_lock_query_fn = dlsym(_locking_lib, "query_resource")))
93 log_warn("WARNING: %s: _query_resource() missing: "
94 "Using inferior activation method.", libname);
96 log_verbose("Loaded external locking library %s", libname);
97 return _init_fn(2, cmd->cft, &locking->flags);