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
19 #include "locking_types.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
,
37 return _lock_fn(cmd
, resource
, flags
);
42 static void _fin_external_locking(void)
47 dlclose(_locking_lib
);
56 static void _reset_external_locking(void)
62 int init_external_locking(struct locking_type
*locking
, struct cmd_context
*cmd
)
67 log_error("External locking already initialised");
71 locking
->lock_resource
= _lock_resource
;
72 locking
->fin_locking
= _fin_external_locking
;
73 locking
->reset_locking
= _reset_external_locking
;
76 libname
= find_config_tree_str(cmd
, "global/locking_library",
79 if (!(_locking_lib
= load_shared_library(cmd
, libname
, "locking", 1)))
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
);
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
);