From f49e6a0dd32f1b891a9281584a6c2516afe3d200 Mon Sep 17 00:00:00 2001 From: Goldwyn Rodrigues Date: Sat, 27 Jul 2013 14:28:48 -0500 Subject: [PATCH 3/5] Remove daemon protocol versions and consolidate fs versions We don't need the daemon protocol version. If there is a need you can think of, please let me know. --- ocfs2_controld/main.c | 124 +++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 57 deletions(-) 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-08-06 09:55:48.527750439 -0500 +++ ocfs2-tools-1.8.2+git.1361836695.ff84eb5/ocfs2_controld/main.c 2013-08-06 09:55:48.544750962 -0500 @@ -47,12 +47,14 @@ #define LOCKFILE_NAME "/var/run/ocfs2_controld.pid" #define NALLOC 8 -#define CONTROLD_PROTOCOL_MAJOR 1 -#define CONTROLD_PROTOCOL_MINOR 0 -#define DAEMON_MAX_PROTOCOL_SECTION "daemon_max_protocol" -#define DAEMON_PROTOCOL_SECTION "daemon_protocol" -#define FS_MAX_PROTOCOL_SECTION "ocfs2_max_protocol" -#define FS_PROTOCOL_SECTION "ocfs2_protocol" +#define FS_PROTOCOL_MAJOR 1 +#define FS_PROTOCOL_MINOR 0 + +static struct ocfs2_protocol_version fs_max_proto = { + .pv_major = FS_PROTOCOL_MAJOR, + .pv_minor = FS_PROTOCOL_MINOR, +}; + struct client { int fd; @@ -80,41 +82,6 @@ char dump_buf[DUMP_SIZE]; int dump_point; int dump_wrap; -/* - * Protocol negotiation. - * - * This is the maximum protocol supported by the daemon for inter-daemon - * communication. The negotiated value daemon_running_proto is what the - * daemon uses at runtime. - * - * All daemons must support the initial protocol, which works as follows: - * Prior to starting CPG, daemons store two values in the local node - * checkpoint. The maximum daemon protocol is stored in the - * "daemon_max_protocol" section, and the ocfs2 maximum protocol is stored - * in the "ocfs2_max_protocol" section. The protocols are stored in the - * format: - * - * <2-char-hex-major><2-char-hex-minor> - * - * These sections MUST be created before CPG is started. Other sections - * MUST NOT be created at this time. - * - * Once CPG is started, the daemon reads the "daemon_protocol" and - * "ocfs2_protocol" sections from the daemon's global checkpoint. The - * values are stored as the running versions. All interaction takes place - * based on the running versions. At this point, the daemon may add - * other sections to the local node checkpoint that are part of the - * running protocol. - * - * If the daemon is the first node to join the group, it sets the - * "daemon_protocol" and "ocfs2_protocol" sections of the global checkpoint - * to the maximum values this daemon supports. - */ -static struct ocfs2_protocol_version daemon_max_proto = { - .pv_major = CONTROLD_PROTOCOL_MAJOR, - .pv_minor = CONTROLD_PROTOCOL_MINOR, -}; -struct ocfs2_protocol_version daemon_running_proto; struct ocfs2_protocol_version fs_running_proto; void shutdown_daemon(void) @@ -609,6 +576,51 @@ static int setup_listener(void) return 0; } +/* + * Compare the cluster's locking protocol version against our maximum. + * + * If the major numbers are different, they are incompatible. + * If the cluster's minor is greater than our maximum minor, they are + * incompatible. + */ +static int protocol_compatible(struct ocfs2_protocol_version *cluster, + struct ocfs2_protocol_version *our_max) +{ + if (cluster->pv_major != our_max->pv_major) + return 0; + + if (cluster->pv_minor > our_max->pv_minor) + return 0; + + return 1; +} + +static int check_protocol_version(void) +{ + int rc = 0; + + fs_running_proto.pv_major = 1; + fs_running_proto.pv_minor = 0; + + o2cb_get_max_locking_protocol(&fs_max_proto); + + if (!protocol_compatible(&fs_running_proto, + &fs_max_proto)) { + log_error("Our maximum fs protocol (%d.%d) is not " + "compatible with the cluster's protocol (%d.%d)", + fs_max_proto.pv_major, + fs_max_proto.pv_minor, + fs_running_proto.pv_major, + fs_running_proto.pv_minor); + rc = -EPROTONOSUPPORT; + } + + log_debug("fs protocol is %d.%d", + fs_running_proto.pv_major, fs_running_proto.pv_minor); + return rc; + +} + static void cpg_joined(int first) { int rv; @@ -617,34 +629,33 @@ static void cpg_joined(int first) log_debug("CPG is live, we are %s first daemon", first ? "the" : "not the"); - log_debug("Daemon protocol is %d.%d", - daemon_running_proto.pv_major, - daemon_running_proto.pv_minor); - log_debug("fs protocol is %d.%d", - fs_running_proto.pv_major, fs_running_proto.pv_minor); + rv = check_protocol_version(); + if (rv) + goto error; log_debug("Connecting to dlm_controld"); rv = setup_dlmcontrol(); - if (rv) { - shutdown_daemon(); - return; - } + if (rv) + goto error; log_debug("Opening control device"); err = o2cb_control_open(our_nodeid, &fs_running_proto); if (err) { log_error("Error opening control device: %s", error_message(err)); - shutdown_daemon(); - return; + goto error; } log_debug("Starting to listen for mounters"); rv = setup_listener(); - if (rv < 0) { - shutdown_daemon(); - return; - } + if (rv < 0) + goto error; + + return; +error: + shutdown_daemon(); + return; + } static int find_minors(void) @@ -975,7 +986,6 @@ int main(int argc, char **argv) { errcode_t err; prog_name = argv[0]; - const char *stack = NULL; decode_arguments(argc, argv);