public inbox for cluster-cvs@sourceware.org help / color / mirror / Atom feed
From: Christine Caulfield <chrissie@fedoraproject.org> To: cluster-cvs-relay@redhat.com Subject: cluster: master - config: Add cman-mkconf Date: Thu, 05 Feb 2009 15:34:00 -0000 [thread overview] Message-ID: <20090205153207.07FECC024D@lists.fedorahosted.org> (raw) Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=71fd5650faa08a94aed6f2824b231e1d05b4b883 Commit: 71fd5650faa08a94aed6f2824b231e1d05b4b883 Parent: c469ea22e6170760ca74a77f61bd2f6b13e90e92 Author: Christine Caulfield <christine@christine-ubuntu.(none)> AuthorDate: Thu Feb 5 15:30:28 2009 +0000 Committer: Christine Caulfield <christine@christine-ubuntu.(none)> CommitterDate: Thu Feb 5 15:30:28 2009 +0000 config: Add cman-mkconf cman-mkconf is a little program to generate very basic cluster.conf file from a running system. Signed-off-by: Christine Caulfield <christine@christine-ubuntu.(none)> --- config/tools/Makefile | 2 +- config/tools/mkconf/Makefile | 27 ++++++ config/tools/mkconf/mkconf.c | 211 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+), 1 deletions(-) diff --git a/config/tools/Makefile b/config/tools/Makefile index 04cc742..8feab10 100644 --- a/config/tools/Makefile +++ b/config/tools/Makefile @@ -1,4 +1,4 @@ include ../../make/defines.mk include $(OBJDIR)/make/passthrough.mk -SUBDIRS=ccs_tool ldap man +SUBDIRS=ccs_tool ldap mkconf man diff --git a/config/tools/mkconf/Makefile b/config/tools/mkconf/Makefile new file mode 100644 index 0000000..4741c31 --- /dev/null +++ b/config/tools/mkconf/Makefile @@ -0,0 +1,27 @@ +TARGET= cman-mkconf + +SBINDIRT=$(TARGET) + +all: ${TARGET} + +include ../../../make/defines.mk +include $(OBJDIR)/make/cobj.mk +include $(OBJDIR)/make/clean.mk +include $(OBJDIR)/make/install.mk +include $(OBJDIR)/make/uninstall.mk + +OBJS= mkconf.o + +CFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE +CFLAGS += -I${corosyncincdir} +CFLAGS += -I${incdir} + +LDFLAGS += -L${corosynclibdir} -lconfdb -lquorum -lcfg -lccs +LDFLAGS += -L${libdir} + +${TARGET}: ${OBJS} + $(CC) -o $@ $^ $(LDFLAGS) + +clean: generalclean + +-include $(OBJS:.o=.d) diff --git a/config/tools/mkconf/mkconf.c b/config/tools/mkconf/mkconf.c new file mode 100644 index 0000000..a4cc71b --- /dev/null +++ b/config/tools/mkconf/mkconf.c @@ -0,0 +1,211 @@ +#include <sys/types.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <netdb.h> +#include <errno.h> + +#include <corosync/corotypes.h> +#include <corosync/quorum.h> +#include <corosync/confdb.h> +#include <corosync/cfg.h> +#include <ccs.h> + +struct node_info { + uint32_t nodeid; + char name[256]; +}; + +static uint32_t node_list_size; +static struct node_info *node_list; + + +static char *node_name(corosync_cfg_node_address_t *addr) +{ + static char name[256]; + + if (getnameinfo((struct sockaddr *)addr->address, addr->address_length, name, sizeof(name), + NULL, 0, NI_NAMEREQD)) + return NULL; + else + return name; +} + +static void quorum_notification_callback( + quorum_handle_t handle, + uint32_t quorate, + uint64_t ring_seq, + uint32_t view_list_entries, + uint32_t *view_list) +{ + int i; + + node_list = malloc(sizeof(struct node_info) * view_list_entries); + if (node_list) { + for (i=0; i<view_list_entries; i++) { + node_list[i].nodeid = view_list[i]; + } + node_list_size = view_list_entries; + } +} + + +static int refresh_node_list(void) +{ + int error; + int i; + quorum_handle_t quorum_handle; + corosync_cfg_handle_t cfg_handle; + quorum_callbacks_t quorum_callbacks = {.quorum_notify_fn = quorum_notification_callback}; + int max_addrs = 4; + corosync_cfg_node_address_t addrs[max_addrs]; + int num_addrs; + char *name = NULL; + + if (quorum_initialize(&quorum_handle, &quorum_callbacks) != CS_OK) { + errno = ENOMEM; + return -1; + } + if (corosync_cfg_initialize(&cfg_handle, NULL) != CS_OK) { + quorum_finalize(quorum_handle); + errno = ENOMEM; + return -1; + } + + quorum_trackstart(quorum_handle, CS_TRACK_CURRENT); + + error = quorum_dispatch(quorum_handle, CS_DISPATCH_ONE); + if (error != CS_OK) + return -1; + + quorum_finalize(quorum_handle); + + for (i=0; i < node_list_size; i++) { + + + error = corosync_cfg_get_node_addrs(cfg_handle, node_list[i].nodeid, max_addrs, &num_addrs, addrs); + if (error == CS_OK) { + name = node_name(&addrs[0]); + } + if (name) { + sprintf(node_list[i].name, "%s", name); + } + else { + sprintf(node_list[i].name, "Node-%x", node_list[i].nodeid); + } + + } + corosync_cfg_finalize(cfg_handle); + return 0; +} + +static void usage(char *prog) +{ + printf("Usage:\n\n"); + printf(" %s [options]\n", prog); + printf("\n"); + + printf(" -N Generate sequential nodeids\n"); + printf(" -n <name> Use this cluster name\n"); + printf(" -i Use IP Addresses rather than resolved node names\n"); + printf(" -f <name> Fence agent name (default: 'default')\n"); + printf(" -F <name> Fence agent parameter name (default: 'ipaddr'\n"); + printf(" -v <num> Config version number (default: 0)\n"); + + printf("\n"); + + printf("NOTE: It is stringly recommended that the existing cluster is shut down\n"); + printf(" completely before restarting any nodes using the generated file\n"); + + printf("\n"); +} + +int main(int argc, char *argv[]) +{ + unsigned int ccs_handle; + char *value; + int optchar; + int nodeid = 0; + int i; + + int seq_nodeids=0; + int use_ip_addrs=0; + int config_version = 0; + char *cluster_name = NULL; + char *fence_type = "default"; + char *fence_param = "ipaddr"; + + /* Parse options... */ + do { + optchar = getopt(argc, argv, "?hNn:if:F:v:"); + switch (optchar) { + case 'N': + seq_nodeids=1; + break; + case 'n': + cluster_name = strdup(optarg); + break; + case 'i': + use_ip_addrs=1; + break; + case 'f': + fence_type = strdup(optarg); + break; + case 'F': + fence_param = strdup(optarg); + break; + case 'v': + config_version = atoi(optarg); + break; + case '?': + case 'h': + usage(argv[0]); + exit(0); + case EOF: + break; + + } + } while (optchar != EOF); + + + /* Get the list of nodes and names */ + if (refresh_node_list()){ + fprintf(stderr, "Unable to get node information from corosync\n"); + return 1; + } + + ccs_handle = ccs_connect(); + + if (!cluster_name) { + if (!ccs_get(ccs_handle, "/cluster/@name", &value)) { + cluster_name = strdup(value); + free(value); + } + } + + /* TODO more ccs keys as a filled in by NOCONFIG ... */ + + /* Print config file header */ + printf("<?xml version=\"1.0\" ?>\n"); + printf("<cluster name=\"%s\" config_version=\"0\">\n", cluster_name); + printf(" <clusternodes>\n"); + for (i=0; i<node_list_size; i++) { + printf(" <clusternode name=\"%s\" nodeid=\"%u\">\n", node_list[i].name, + seq_nodeids?++nodeid:node_list[i].nodeid); + printf(" <fence>\n"); + printf(" <method name=\"single\">\n"); + printf(" <device name=\"%s\" %s=\"%s\"/>\n", fence_type, fence_param,node_list[i].name); + printf(" </method>\n"); + printf(" </fence>\n"); + printf(" </clusternode>\n"); + printf("\n"); + } + printf(" </clusternodes>\n"); + + printf("</cluster>\n"); + + ccs_disconnect(ccs_handle); + return 0; +}
reply other threads:[~2009-02-05 15:34 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20090205153207.07FECC024D@lists.fedorahosted.org \ --to=chrissie@fedoraproject.org \ --cc=cluster-cvs-relay@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).