[Ocfs2-tools-devel] [PATCH 4/9] ocfs2_controld: Connect to dlm_controld.

Joel Becker joel.becker at oracle.com
Wed Aug 13 17:15:34 PDT 2008


Our first step in introducing the dlmcontrol API is to connect and
disconnect from dlm_controld at start and exit.

Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
 ocfs2_controld/Makefile         |    6 ++-
 ocfs2_controld/dlmcontrol.c     |   90 +++++++++++++++++++++++++++++++++++++++
 ocfs2_controld/main.c           |   12 ++++-
 ocfs2_controld/ocfs2_controld.h |    4 ++
 4 files changed, 108 insertions(+), 4 deletions(-)
 create mode 100644 ocfs2_controld/dlmcontrol.c

diff --git a/ocfs2_controld/Makefile b/ocfs2_controld/Makefile
index 3a948a4..5db2cb9 100644
--- a/ocfs2_controld/Makefile
+++ b/ocfs2_controld/Makefile
@@ -17,6 +17,7 @@ LIBO2CB_DEPS = $(TOPDIR)/libo2cb/libo2cb.a
 LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
 LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
 OPENAIS_LIBS = $(CPG_LDFLAGS) -lcpg -lSaCkpt
+DLMCONTROL_LIBS = -ldlmcontrol
 
 ifdef OCFS2_DEBUG
 OPTS += -ggdb
@@ -32,7 +33,7 @@ DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES \
 
 UNINST_HFILES = ocfs2_controld.h
 
-DAEMON_CFILES = main.c cpg.c mount.c ckpt.c
+DAEMON_CFILES = main.c cpg.c mount.c ckpt.c dlmcontrol.c
 
 CMAN_CFILES = cman.c
 CMAN_DAEMON_CFILES = $(DAEMON_CFILES) $(CMAN_CFILES)
@@ -50,7 +51,8 @@ DIST_FILES =				\
 	$(addsuffix .in,$(MANS))
 
 ocfs2_controld.cman: $(CMAN_DAEMON_OBJS) $(LIBO2CB_DEPS)
-	$(LINK) $(LIBO2CB_LIBS) $(COM_ERR_LIBS) $(OPENAIS_LIBS) -lcman
+	$(LINK) $(LIBO2CB_LIBS) $(COM_ERR_LIBS) $(OPENAIS_LIBS) \
+		$(DLMCONTROL_LIBS) -lcman
 
 test_client: $(TEST_OBJS) $(LIBO2CB_DEPS) $(LIBOCFS2_DEPS)
 	$(LINK) $(LIBOCFS2_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
diff --git a/ocfs2_controld/dlmcontrol.c b/ocfs2_controld/dlmcontrol.c
new file mode 100644
index 0000000..f7e3047
--- /dev/null
+++ b/ocfs2_controld/dlmcontrol.c
@@ -0,0 +1,90 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2008 Oracle.  All rights reserved.
+ *
+ *  This copyrighted material is made available to anyone wishing to use,
+ *  modify, copy, or redistribute it subject to the terms and conditions
+ *  of the GNU General Public License v.2.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <unistd.h>
+#include <time.h>
+#include <syslog.h>
+#include <libdlm.h>
+#include <libdlmcontrol.h>
+
+#include "ocfs2_controld.h"
+
+static int dlmcontrol_ci;
+static int dlmcontrol_fd = -1;
+
+static void dead_dlmcontrol(int ci)
+{
+	if (ci != dlmcontrol_ci) {
+		log_error("Unknown connection %d", ci);
+		return;
+	}
+
+	log_error("dlmcontrol connection died");
+	shutdown_daemon();
+	connection_dead(ci);
+}
+
+static void process_dlmcontrol(int ci)
+{
+	if (ci != dlmcontrol_ci) {
+		log_error("Unknown connection %d", ci);
+		return;
+	}
+
+	log_debug("message from dlmcontrol\n");
+}
+
+int setup_dlmcontrol(void)
+{
+	int rc;
+
+	rc = dlmc_fs_connect();
+	if (rc < 0) {
+		rc = -errno;
+		log_error("Unable to connect to dlm_controld: %s",
+			  strerror(-rc));
+		goto out;
+	}
+	dlmcontrol_fd = rc;
+
+	dlmcontrol_ci = connection_add(dlmcontrol_fd, process_dlmcontrol,
+				       dead_dlmcontrol);
+
+	if (dlmcontrol_ci < 0) {
+		rc = dlmcontrol_ci;
+		log_error("Unable to add dlmcontrol client: %s",
+			  strerror(-dlmcontrol_ci));
+		dlmc_fs_disconnect(dlmcontrol_fd);
+		goto out;
+	}
+
+	rc = 0;
+
+out:
+	return rc;
+}
+
+void exit_dlmcontrol(void)
+{
+	if (dlmcontrol_fd < 0)
+		return;
+
+	log_debug("Closing dlm_controld connection");
+	dlmc_fs_disconnect(dlmcontrol_fd);
+}
+
diff --git a/ocfs2_controld/main.c b/ocfs2_controld/main.c
index c16771e..ac2dbb5 100644
--- a/ocfs2_controld/main.c
+++ b/ocfs2_controld/main.c
@@ -245,7 +245,7 @@ out:
 	return rc;
 }
 
-int do_read(int fd, void *buf, size_t count)
+static int do_read(int fd, void *buf, size_t count)
 {
 	int rv, off = 0;
 
@@ -262,7 +262,7 @@ int do_read(int fd, void *buf, size_t count)
 	return 0;
 }
 
-int do_write(int fd, void *buf, size_t count)
+static int do_write(int fd, void *buf, size_t count)
 {
 	int rv, off = 0;
 
@@ -873,6 +873,13 @@ static void cpg_joined(int first)
 	log_debug("fs protocol is %d.%d",
 		  fs_running_proto.pv_major, fs_running_proto.pv_minor);
 
+	log_debug("Connecting to dlm_controld");
+	rv = setup_dlmcontrol();
+	if (rv) {
+		shutdown_daemon();
+		return;
+	}
+
 	log_debug("Opening control device");
 	err = o2cb_control_open(our_nodeid, &fs_running_proto);
 	if (err) {
@@ -951,6 +958,7 @@ stop:
 	bail_on_mounts();
 
 	o2cb_control_close();
+	exit_dlmcontrol();
 	exit_cpg();
 	drop_node_checkpoint();
 	exit_ckpt();
diff --git a/ocfs2_controld/ocfs2_controld.h b/ocfs2_controld/ocfs2_controld.h
index c0f69de..61c4689 100644
--- a/ocfs2_controld/ocfs2_controld.h
+++ b/ocfs2_controld/ocfs2_controld.h
@@ -97,6 +97,10 @@ int group_join(const char *name,
 	       void *user_data);
 int group_leave(struct cgroup *cg);
 
+/* dlmcontrol.c */
+int setup_dlmcontrol(void);
+void exit_dlmcontrol(void);
+
 /* mount.c */
 void init_mounts(void);
 int have_mounts(void);
-- 
1.5.6.3




More information about the Ocfs2-tools-devel mailing list