forked from pool/ocfs2-tools
4633b6be45
update to be compatible with corosync 2.3.x OBS-URL: https://build.opensuse.org/request/show/185215 OBS-URL: https://build.opensuse.org/package/show/network:ha-clustering:Factory/ocfs2-tools?expand=0&rev=60
316 lines
9.0 KiB
Diff
316 lines
9.0 KiB
Diff
From 1a7b9a35228cd5ef9d6ad96ec35f6fc812ee821c Mon Sep 17 00:00:00 2001
|
|
From: Goldwyn Rodrigues <rgoldwyn@suse.com>
|
|
Date: Tue, 23 Jul 2013 12:09:28 -0500
|
|
Subject: [PATCH 2/5] Add corosync cfg to get configuration information
|
|
|
|
---
|
|
ocfs2_controld/Makefile | 2 +-
|
|
ocfs2_controld/cpg.c | 1 -
|
|
ocfs2_controld/main.c | 58 ++-------------------
|
|
ocfs2_controld/member.c | 111 ++++++++++++++++++++++++++++++++++++++++
|
|
ocfs2_controld/ocfs2_controld.h | 20 ++------
|
|
5 files changed, 119 insertions(+), 73 deletions(-)
|
|
create mode 100644 ocfs2_controld/member.c
|
|
|
|
Index: ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/Makefile
|
|
===================================================================
|
|
--- ocfs2-tools-1.8.2+git.1361836695.ff84eb5.orig/ocfs2_controld/Makefile 2013-07-31 08:25:43.559675366 -0500
|
|
+++ ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/Makefile 2013-07-31 08:26:05.733331692 -0500
|
|
@@ -49,7 +49,7 @@ CMAN_CFILES = cman.c
|
|
CMAN_DAEMON_CFILES = $(DAEMON_CFILES) $(CMAN_CFILES)
|
|
CMAN_DAEMON_OBJS = $(subst .c,.o,$(CMAN_DAEMON_CFILES))
|
|
|
|
-COROSYNC_CFILES =
|
|
+COROSYNC_CFILES = member.c
|
|
COROSYNC_DAEMON_CFILES = $(DAEMON_CFILES) $(COROSYNC_CFILES)
|
|
COROSYNC_DAEMON_OBJS = $(subst .c,.o,$(COROSYNC_DAEMON_CFILES))
|
|
|
|
Index: ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/cpg.c
|
|
===================================================================
|
|
--- ocfs2-tools-1.8.2+git.1361836695.ff84eb5.orig/ocfs2_controld/cpg.c 2013-07-31 08:25:34.868418089 -0500
|
|
+++ ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/cpg.c 2013-07-31 08:25:43.559675366 -0500
|
|
@@ -339,7 +339,6 @@ static void handle_daemon_left(struct cp
|
|
if (1) {
|
|
log_error("kill node %d - ocfs2_controld PROCDOWN",
|
|
addr->nodeid);
|
|
- kill_stack_node(addr->nodeid);
|
|
}
|
|
|
|
/* FALL THROUGH */
|
|
Index: ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/main.c
|
|
===================================================================
|
|
--- ocfs2-tools-1.8.2+git.1361836695.ff84eb5.orig/ocfs2_controld/main.c 2013-07-31 08:25:34.837417171 -0500
|
|
+++ ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/main.c 2013-07-31 08:25:43.560675395 -0500
|
|
@@ -114,10 +114,8 @@ static struct ocfs2_protocol_version dae
|
|
.pv_major = CONTROLD_PROTOCOL_MAJOR,
|
|
.pv_minor = CONTROLD_PROTOCOL_MINOR,
|
|
};
|
|
-static struct ocfs2_protocol_version fs_max_proto;
|
|
struct ocfs2_protocol_version daemon_running_proto;
|
|
struct ocfs2_protocol_version fs_running_proto;
|
|
-struct ckpt_handle *node_handle;
|
|
|
|
void shutdown_daemon(void)
|
|
{
|
|
@@ -254,11 +252,6 @@ static int do_mount(int ci, int fd, cons
|
|
goto fail;
|
|
}
|
|
|
|
- if (!validate_cluster(cluster)) {
|
|
- error_msg = "Invalid cluster name";
|
|
- goto fail;
|
|
- }
|
|
-
|
|
return start_mount(ci, fd, uuid, device, service);
|
|
|
|
fail:
|
|
@@ -456,11 +449,6 @@ static int send_filesystems(int ci, int
|
|
goto fail;
|
|
}
|
|
|
|
- if (!validate_cluster(cluster)) {
|
|
- error_msg = "Invalid cluster name";
|
|
- goto fail;
|
|
- }
|
|
-
|
|
return send_mountgroups(ci, fd);
|
|
|
|
fail:
|
|
@@ -471,15 +459,6 @@ static int send_clustername(int ci, int
|
|
{
|
|
int rc = 0, rctmp;
|
|
char error_msg[100]; /* Arbitrary size smaller than a message */
|
|
- const char *cluster;
|
|
-
|
|
- rc = get_clustername(&cluster);
|
|
- if (rc) {
|
|
- snprintf(error_msg, sizeof(error_msg),
|
|
- "Unable to query cluster name: %s",
|
|
- strerror(-rc));
|
|
- goto out_status;
|
|
- }
|
|
|
|
/* Cman only supports one cluster */
|
|
rc = send_message(fd, CM_ITEMCOUNT, 1);
|
|
@@ -490,7 +469,7 @@ static int send_clustername(int ci, int
|
|
goto out_status;
|
|
}
|
|
|
|
- rc = send_message(fd, CM_ITEM, cluster);
|
|
+ rc = send_message(fd, CM_ITEM, cluster_name);
|
|
if (rc) {
|
|
snprintf(error_msg, sizeof(error_msg),
|
|
"Unable to send ITEM: %s",
|
|
@@ -630,27 +609,6 @@ static int setup_listener(void)
|
|
return 0;
|
|
}
|
|
|
|
-static int proto_version_to_checkpoint(struct ocfs2_protocol_version *proto,
|
|
- char **checkpoint_data)
|
|
-{
|
|
- size_t len;
|
|
- char *buf;
|
|
-
|
|
- len = snprintf(NULL, 0, "%02x %02x", proto->pv_major,
|
|
- proto->pv_minor);
|
|
- buf = malloc(sizeof(char) * (len + 1));
|
|
- if (!buf) {
|
|
- log_error("Unable to allocate memory for checkpoint data");
|
|
- return -ENOMEM;
|
|
- }
|
|
-
|
|
- snprintf(buf, len + 1, "%02x %02x", proto->pv_major,
|
|
- proto->pv_minor);
|
|
- *checkpoint_data = buf;
|
|
-
|
|
- return 0;
|
|
-}
|
|
-
|
|
static void cpg_joined(int first)
|
|
{
|
|
int rv;
|
|
@@ -759,7 +717,7 @@ static int loop(void)
|
|
if (rv < 0)
|
|
goto out;
|
|
|
|
- rv = install_node_checkpoint();
|
|
+ rv = setup_cluster_cfg();
|
|
if (rv < 0)
|
|
goto out;
|
|
|
|
@@ -1032,17 +990,6 @@ int main(int argc, char **argv)
|
|
return 1;
|
|
}
|
|
|
|
- err = o2cb_get_stack_name(&stack);
|
|
- if (err) {
|
|
- com_err(prog_name, err, "while determining the current cluster stack");
|
|
- return 1;
|
|
- }
|
|
- if (strcmp(stack, stackname)) {
|
|
- log_error("%s: This daemon supports the \"%s\" stack, but the \"%s\" stack is in use",
|
|
- prog_name, stackname, stack);
|
|
- return 1;
|
|
- }
|
|
-
|
|
if (!daemon_debug_opt)
|
|
daemonize();
|
|
|
|
Index: ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/member.c
|
|
===================================================================
|
|
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
+++ ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/member.c 2013-07-31 08:25:43.560675395 -0500
|
|
@@ -0,0 +1,111 @@
|
|
+#include <stdio.h>
|
|
+#include <stdlib.h>
|
|
+#include <string.h>
|
|
+#include <syslog.h>
|
|
+
|
|
+#include "ocfs2_controld.h"
|
|
+#include <corosync/corotypes.h>
|
|
+#include <corosync/cfg.h>
|
|
+#include <corosync/cmap.h>
|
|
+
|
|
+
|
|
+char cluster_name[65];
|
|
+int our_nodeid;
|
|
+
|
|
+static corosync_cfg_handle_t ch;
|
|
+
|
|
+static int detect_cluster_name(void)
|
|
+{
|
|
+ cmap_handle_t handle;
|
|
+ char *str = NULL;
|
|
+ int rv, err = -1;
|
|
+
|
|
+ rv = cmap_initialize(&handle);
|
|
+ if (rv != CS_OK) {
|
|
+ log_error("cmap_initialize error %d", rv);
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ rv = cmap_get_string(handle, "totem.cluster_name", &str);
|
|
+ if (rv != CS_OK) {
|
|
+ log_error("cmap_get_string totem.cluster_name error %d", rv);
|
|
+ goto out;
|
|
+ } else
|
|
+ err = 0;
|
|
+
|
|
+ log_debug("cmap totem.cluster_name = '%s'", str);
|
|
+
|
|
+ strncpy(cluster_name, str, 64);
|
|
+out:
|
|
+ if (str)
|
|
+ free(str);
|
|
+ cmap_finalize(handle);
|
|
+ return err;
|
|
+}
|
|
+
|
|
+static void shutdown_callback(corosync_cfg_handle_t h,
|
|
+ corosync_cfg_shutdown_flags_t flags)
|
|
+{
|
|
+ if (flags & COROSYNC_CFG_SHUTDOWN_FLAG_REQUEST) {
|
|
+ log_debug("shutdown request yes");
|
|
+ corosync_cfg_replyto_shutdown(ch, COROSYNC_CFG_SHUTDOWN_FLAG_YES);
|
|
+ }
|
|
+}
|
|
+
|
|
+static corosync_cfg_callbacks_t cfg_callbacks =
|
|
+{
|
|
+ .corosync_cfg_shutdown_callback = shutdown_callback,
|
|
+};
|
|
+
|
|
+int setup_cluster_cfg(void)
|
|
+{
|
|
+ cs_error_t err;
|
|
+ unsigned int nodeid;
|
|
+ int fd;
|
|
+ int retry = 1;
|
|
+
|
|
+try_again:
|
|
+ err = corosync_cfg_initialize(&ch, &cfg_callbacks);
|
|
+ if (err != CS_OK) {
|
|
+ if ((err == CS_ERR_TRY_AGAIN) && (retry <= 10)) {
|
|
+ log_error("corosync has not completed initialization.. retry %d", retry);
|
|
+ sleep(1);
|
|
+ retry++;
|
|
+ goto try_again;
|
|
+ }
|
|
+ log_error("corosync cfg init error %d", err);
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ err = corosync_cfg_fd_get(ch, &fd);
|
|
+ if (err != CS_OK) {
|
|
+ log_error("corosync cfg fd_get error %d", err);
|
|
+ corosync_cfg_finalize(ch);
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ err = corosync_cfg_local_get(ch, &nodeid);
|
|
+ if (err != CS_OK) {
|
|
+ log_error("corosync cfg local_get error %d", err);
|
|
+ corosync_cfg_finalize(ch);
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ our_nodeid = nodeid;
|
|
+ log_debug("our_nodeid %d", our_nodeid);
|
|
+
|
|
+ if (our_nodeid < 0) {
|
|
+ log_error("negative nodeid, set corosync totem.clear_node_high_bit");
|
|
+ corosync_cfg_finalize(ch);
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ return fd;
|
|
+}
|
|
+
|
|
+void close_cluster_cfg(void)
|
|
+{
|
|
+ corosync_cfg_finalize(ch);
|
|
+}
|
|
+
|
|
+
|
|
Index: ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/ocfs2_controld.h
|
|
===================================================================
|
|
--- ocfs2-tools-1.8.2+git.1361836695.ff84eb5.orig/ocfs2_controld/ocfs2_controld.h 2013-07-31 08:25:34.869418118 -0500
|
|
+++ ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/ocfs2_controld.h 2013-07-31 08:25:43.560675395 -0500
|
|
@@ -39,6 +39,7 @@ extern int dump_point;
|
|
extern int dump_wrap;
|
|
extern int our_nodeid;
|
|
extern const char *stackname;
|
|
+extern char cluster_name[65];
|
|
|
|
extern void daemon_dump_save(void);
|
|
|
|
@@ -70,25 +71,12 @@ int connection_add(int fd, void (*work)(
|
|
void connection_dead(int ci);
|
|
void shutdown_daemon(void);
|
|
|
|
-/* ckpt.c */
|
|
-int setup_ckpt(void);
|
|
-void exit_ckpt(void);
|
|
-int ckpt_open_global(int write);
|
|
-void ckpt_close_global(void);
|
|
-int ckpt_open_node(int nodeid, struct ckpt_handle **handle);
|
|
-int ckpt_open_this_node(struct ckpt_handle **handle);
|
|
-void ckpt_close(struct ckpt_handle *handle);
|
|
-int ckpt_global_store(const char *section, const char *data, size_t data_len);
|
|
-int ckpt_global_get(const char *section, char **data, size_t *data_len);
|
|
-int ckpt_section_store(struct ckpt_handle *handle, const char *section,
|
|
- const char *data, size_t data_len);
|
|
-int ckpt_section_get(struct ckpt_handle *handle, const char *section,
|
|
- char **data, size_t *data_len);
|
|
-
|
|
+/* member.c */
|
|
+int setup_cluster_cfg(void);
|
|
+void close_cluster_cfg(void);
|
|
/* stack-specific interfaces (cman.c) */
|
|
int setup_stack(void);
|
|
char *nodeid2name(int nodeid);
|
|
-int validate_cluster(const char *cluster);
|
|
int get_clustername(const char **cluster);
|
|
int kill_stack_node(int nodeid);
|
|
void exit_stack(void);
|