Make cmap_* also has same policy as dlm_*
Let libcmap lib and related funs also only need one-time setup during mdadm running period. Signed-off-by: Guoqing Jiang <gqjiang@suse.com> Signed-off-by: NeilBrown <neilb@suse.com>
This commit is contained in:
parent
d15a1f72bd
commit
e80357f825
5
mdadm.c
5
mdadm.c
|
@ -1317,6 +1317,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
rv = 0;
|
||||
|
||||
set_hooks(); /* set hooks from libs */
|
||||
|
||||
if (c.homecluster == NULL && (c.nodes > 0)) {
|
||||
c.homecluster = conf_get_homecluster();
|
||||
if (c.homecluster == NULL)
|
||||
|
@ -1346,8 +1349,6 @@ int main(int argc, char *argv[])
|
|||
/* --scan implied --brief unless -vv */
|
||||
c.brief = 1;
|
||||
|
||||
set_dlm_hooks(); /* get dlm funcs from libdlm_lt.so.3 */
|
||||
|
||||
switch(mode) {
|
||||
case MANAGE:
|
||||
/* readonly, add/remove, readwrite, runstop */
|
||||
|
|
20
mdadm.h
20
mdadm.h
|
@ -52,6 +52,13 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
|
|||
#define srandom srand
|
||||
#endif
|
||||
|
||||
#ifdef NO_COROSYNC
|
||||
#define CS_OK 1
|
||||
typedef uint64_t cmap_handle_t;
|
||||
#else
|
||||
#include <corosync/cmap.h>
|
||||
#endif
|
||||
|
||||
#ifndef NO_DLM
|
||||
#include <libdlm.h>
|
||||
#include <errno.h>
|
||||
|
@ -1444,6 +1451,19 @@ extern char *fd2devnm(int fd);
|
|||
|
||||
extern int in_initrd(void);
|
||||
|
||||
struct cmap_hooks {
|
||||
void *cmap_handle; /* corosync lib related */
|
||||
|
||||
int (*initialize)(cmap_handle_t *handle);
|
||||
int (*get_string)(cmap_handle_t handle,
|
||||
const char *string,
|
||||
char **name);
|
||||
int (*finalize)(cmap_handle_t handle);
|
||||
};
|
||||
|
||||
extern void set_cmap_hooks(void);
|
||||
extern void set_hooks(void);
|
||||
|
||||
struct dlm_hooks {
|
||||
void *dlm_handle; /* dlm lib related */
|
||||
|
||||
|
|
69
util.c
69
util.c
|
@ -36,13 +36,6 @@
|
|||
#include <dirent.h>
|
||||
#include <signal.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stdint.h>
|
||||
#ifdef NO_COROSYNC
|
||||
typedef uint64_t cmap_handle_t;
|
||||
#define CS_OK 1
|
||||
#else
|
||||
#include <corosync/cmap.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
|
@ -2121,41 +2114,42 @@ void reopen_mddev(int mdfd)
|
|||
if (fd >= 0 && fd != mdfd)
|
||||
dup2(fd, mdfd);
|
||||
}
|
||||
|
||||
static struct cmap_hooks *cmap_hooks = NULL;
|
||||
static int is_cmap_hooks_ready = 0;
|
||||
|
||||
#ifndef MDASSEMBLE
|
||||
void set_cmap_hooks(void)
|
||||
{
|
||||
cmap_hooks = xmalloc(sizeof(struct cmap_hooks));
|
||||
cmap_hooks->cmap_handle = dlopen("libcmap.so.4", RTLD_NOW | RTLD_LOCAL);
|
||||
if (!cmap_hooks->cmap_handle)
|
||||
return;
|
||||
|
||||
cmap_hooks->initialize = dlsym(cmap_hooks->cmap_handle, "cmap_initialize");
|
||||
cmap_hooks->get_string = dlsym(cmap_hooks->cmap_handle, "cmap_get_string");
|
||||
cmap_hooks->finalize = dlsym(cmap_hooks->cmap_handle, "cmap_finalize");
|
||||
|
||||
if (!cmap_hooks->initialize || !cmap_hooks->get_string ||
|
||||
!cmap_hooks->finalize)
|
||||
dlclose(cmap_hooks->cmap_handle);
|
||||
else
|
||||
is_cmap_hooks_ready = 1;
|
||||
}
|
||||
|
||||
int get_cluster_name(char **cluster_name)
|
||||
{
|
||||
void *lib_handle = NULL;
|
||||
int rv = -1;
|
||||
cmap_handle_t handle;
|
||||
|
||||
cmap_handle_t handle;
|
||||
static int (*initialize)(cmap_handle_t *handle);
|
||||
static int (*get_string)(cmap_handle_t handle,
|
||||
const char *string,
|
||||
char **name);
|
||||
static int (*finalize)(cmap_handle_t handle);
|
||||
if (!is_cmap_hooks_ready)
|
||||
return rv;
|
||||
|
||||
|
||||
lib_handle = dlopen("libcmap.so.4", RTLD_NOW | RTLD_LOCAL);
|
||||
if (!lib_handle)
|
||||
return rv;
|
||||
|
||||
initialize = dlsym(lib_handle, "cmap_initialize");
|
||||
if (!initialize)
|
||||
goto out;
|
||||
|
||||
get_string = dlsym(lib_handle, "cmap_get_string");
|
||||
if (!get_string)
|
||||
goto out;
|
||||
|
||||
finalize = dlsym(lib_handle, "cmap_finalize");
|
||||
if (!finalize)
|
||||
goto out;
|
||||
|
||||
rv = initialize(&handle);
|
||||
rv = cmap_hooks->initialize(&handle);
|
||||
if (rv != CS_OK)
|
||||
goto out;
|
||||
|
||||
rv = get_string(handle, "totem.cluster_name", cluster_name);
|
||||
rv = cmap_hooks->get_string(handle, "totem.cluster_name", cluster_name);
|
||||
if (rv != CS_OK) {
|
||||
free(*cluster_name);
|
||||
rv = -1;
|
||||
|
@ -2164,9 +2158,8 @@ int get_cluster_name(char **cluster_name)
|
|||
|
||||
rv = 0;
|
||||
name_err:
|
||||
finalize(handle);
|
||||
cmap_hooks->finalize(handle);
|
||||
out:
|
||||
dlclose(lib_handle);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -2191,4 +2184,10 @@ void set_dlm_hooks(void)
|
|||
else
|
||||
is_dlm_hooks_ready = 1;
|
||||
}
|
||||
|
||||
void set_hooks(void)
|
||||
{
|
||||
set_dlm_hooks();
|
||||
set_cmap_hooks();
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue