ocfs2-tools/0001-Use-cmap-for-getting-cluster-name.patch

161 lines
4.0 KiB
Diff

From 6423caf73ef9d0f22acf294e100523bc2af3acc9 Mon Sep 17 00:00:00 2001
From: Goldwyn Rodrigues <rgoldwyn@suse.com>
Date: Sat, 21 Dec 2013 18:41:04 -0600
Subject: [PATCH] Use cmap for getting cluster name
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
debugfs.ocfs2/Makefile | 2 +-
libo2cb/o2cb_abi.c | 79 +++++++++++++++++++++++++++-----------------------
o2cb.pc.in | 2 +-
o2cb_ctl/Makefile | 2 +-
4 files changed, 46 insertions(+), 39 deletions(-)
diff --git a/debugfs.ocfs2/Makefile b/debugfs.ocfs2/Makefile
index ca4c9a4..30dfa5f 100644
--- a/debugfs.ocfs2/Makefile
+++ b/debugfs.ocfs2/Makefile
@@ -32,7 +32,7 @@ HFILES = \
OBJS = $(subst .c,.o,$(CFILES))
LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
-LIBO2CB_LIBS = -L$(TOPDIR)/libo2cb -lo2cb
+LIBO2CB_LIBS = -L$(TOPDIR)/libo2cb -lo2cb $(DL_LIBS)
MANS = debugfs.ocfs2.8
diff --git a/libo2cb/o2cb_abi.c b/libo2cb/o2cb_abi.c
index ae03595..6c3ad73 100644
--- a/libo2cb/o2cb_abi.c
+++ b/libo2cb/o2cb_abi.c
@@ -35,6 +35,8 @@
#include <errno.h>
#include <limits.h>
#include <ctype.h>
+#include <dlfcn.h>
+#include <corosync/cmap.h>
#include <linux/types.h>
@@ -1966,52 +1968,57 @@ static errcode_t classic_list_clusters(char ***clusters)
static errcode_t user_list_clusters(char ***clusters)
{
- errcode_t err = O2CB_ET_SERVICE_UNAVAILABLE;
- int rc, fd = -1;
- char buf[OCFS2_CONTROLD_MAXLINE];
+ errcode_t ret = O2CB_ET_SERVICE_UNAVAILABLE;
+ void *lib_handle = NULL;
+ char **list;
+ int rv;
- rc = ocfs2_client_connect();
- if (rc < 0) {
- /* fprintf(stderr, "Unable to connect to ocfs2_controld: %s\n",
- strerror(-rc)); */
- switch (rc) {
- case -EACCES:
- case -EPERM:
- err = O2CB_ET_PERMISSION_DENIED;
- break;
+ 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);
- default:
- err = O2CB_ET_SERVICE_UNAVAILABLE;
- break;
- }
+
+ lib_handle = dlopen("libcmap.so.4", RTLD_NOW | RTLD_LOCAL);
+ if (!lib_handle)
+ return ret;
+
+ initialize = dlsym(lib_handle, "cmap_initialize");
+ if (!initialize)
goto out;
- }
- fd = rc;
- rc = send_message(fd, CM_LISTCLUSTERS);
- if (rc) {
- /* fprintf(stderr,
- "Unable to send LISTCLUSTERS message: %s\n",
- strerror(-rc)); */
- err = O2CB_ET_IO;
+ get_string = dlsym(lib_handle, "cmap_get_string");
+ if (!get_string)
goto out;
- }
- rc = receive_list(fd, buf, clusters);
- if (rc) {
- /* fprintf(stderr, "Error reading from daemon: %s\n",
- strerror(-rc)); */
- err = O2CB_ET_IO;
+ finalize = dlsym(lib_handle, "cmap_finalize");
+ if (!finalize)
goto out;
- }
- err = 0;
+ rv = initialize(&handle);
+ if (rv != CS_OK)
+ goto out;
-out:
- if (fd != -1)
- close(fd);
+ list = (char **)malloc(sizeof(char *) * 2);
+ if (!list)
+ goto out;
- return err;
+ rv = get_string(handle, "totem.cluster_name", &list[0]);
+ if (rv != CS_OK) {
+ free(list);
+ ret = O2CB_ET_INTERNAL_FAILURE;
+ goto out;
+ }
+
+ list[1] = NULL;
+ *clusters = list;
+ finalize(handle);
+ ret = 0;
+out:
+ dlclose(lib_handle);
+ return ret;
}
errcode_t o2cb_list_clusters(char ***clusters)
diff --git a/o2cb.pc.in b/o2cb.pc.in
index be94b8a..f13c560 100644
--- a/o2cb.pc.in
+++ b/o2cb.pc.in
@@ -7,5 +7,5 @@ Name: o2cb
Description: Library for accessing the ocfs2 cluster base (o2cb)
Version: @VERSION@
Requires: com_err
-Libs: -L${libdir} -lo2cb
+Libs: -L${libdir} -lo2cb -ldl
Cflags: -I${includedir}
diff --git a/o2cb_ctl/Makefile b/o2cb_ctl/Makefile
index 5efcab4..8589748 100644
--- a/o2cb_ctl/Makefile
+++ b/o2cb_ctl/Makefile
@@ -13,7 +13,7 @@ LIBTOOLS_INTERNAL_DEPS = $(TOPDIR)/libtools-internal/libtools-internal.a
LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
-LIBO2CB_LIBS = -L$(TOPDIR)/libo2cb -lo2cb
+LIBO2CB_LIBS = -L$(TOPDIR)/libo2cb -lo2cb $(DL_LIBS)
LIBO2CB_DEPS = $(TOPDIR)/libo2cb/libo2cb.a
LIBO2DLM_LIBS = -L$(TOPDIR)/libo2dlm -lo2dlm $(DL_LIBS)
--
1.8.4