Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / lib / locking / external_locking.c
blobe0fe5deeec4819ef9de7e7b37a2cc61c1b0bdad2
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "lib.h"
19 #include "locking_types.h"
20 #include "defaults.h"
21 #include "sharedlib.h"
22 #include "toolcontext.h"
24 static void *_locking_lib = NULL;
25 static void (*_reset_fn) (void) = NULL;
26 static void (*_end_fn) (void) = NULL;
27 static int (*_lock_fn) (struct cmd_context * cmd, const char *resource,
28 uint32_t flags) = NULL;
29 static int (*_init_fn) (int type, struct config_tree * cft,
30 uint32_t *flags) = NULL;
31 static int (*_lock_query_fn) (const char *resource, int *mode) = NULL;
33 static int _lock_resource(struct cmd_context *cmd, const char *resource,
34 uint32_t flags)
36 if (_lock_fn)
37 return _lock_fn(cmd, resource, flags);
38 else
39 return 0;
42 static void _fin_external_locking(void)
44 if (_end_fn)
45 _end_fn();
47 dlclose(_locking_lib);
49 _locking_lib = NULL;
50 _init_fn = NULL;
51 _end_fn = NULL;
52 _lock_fn = NULL;
53 _reset_fn = NULL;
56 static void _reset_external_locking(void)
58 if (_reset_fn)
59 _reset_fn();
62 int init_external_locking(struct locking_type *locking, struct cmd_context *cmd)
64 const char *libname;
66 if (_locking_lib) {
67 log_error("External locking already initialised");
68 return 1;
71 locking->lock_resource = _lock_resource;
72 locking->fin_locking = _fin_external_locking;
73 locking->reset_locking = _reset_external_locking;
74 locking->flags = 0;
76 libname = find_config_tree_str(cmd, "global/locking_library",
77 DEFAULT_LOCKING_LIB);
79 if (!(_locking_lib = load_shared_library(cmd, libname, "locking", 1)))
80 return_0;
82 /* Get the functions we need */
83 if (!(_init_fn = dlsym(_locking_lib, "locking_init")) ||
84 !(_lock_fn = dlsym(_locking_lib, "lock_resource")) ||
85 !(_reset_fn = dlsym(_locking_lib, "reset_locking")) ||
86 !(_end_fn = dlsym(_locking_lib, "locking_end"))) {
87 log_error("Shared library %s does not contain locking "
88 "functions", libname);
89 dlclose(_locking_lib);
90 _locking_lib = NULL;
91 return 0;
94 if (!(_lock_query_fn = dlsym(_locking_lib, "query_resource")))
95 log_warn("WARNING: %s: _query_resource() missing: "
96 "Using inferior activation method.", libname);
98 log_verbose("Loaded external locking library %s", libname);
99 return _init_fn(2, cmd->cft, &locking->flags);