diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 17:01:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 17:01:24 +0000 |
commit | 6dd3dfb79125cd02d02efbce435a6c82e5af92ef (patch) | |
tree | 45084fc83278586f6bbafcb935f92d53f71a6b03 /tools | |
parent | Initial commit. (diff) | |
download | corosync-6dd3dfb79125cd02d02efbce435a6c82e5af92ef.tar.xz corosync-6dd3dfb79125cd02d02efbce435a6c82e5af92ef.zip |
Adding upstream version 3.1.8.upstream/3.1.8upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 93 | ||||
-rw-r--r-- | tools/Makefile.in | 899 | ||||
-rw-r--r-- | tools/corosync-blackbox.sh | 34 | ||||
-rw-r--r-- | tools/corosync-cfgtool.c | 614 | ||||
-rw-r--r-- | tools/corosync-cmapctl.c | 996 | ||||
-rw-r--r-- | tools/corosync-cpgtool.c | 276 | ||||
-rw-r--r-- | tools/corosync-keygen.c | 191 | ||||
-rw-r--r-- | tools/corosync-notifyd.c | 1420 | ||||
-rw-r--r-- | tools/corosync-notifyd.sysconfig.example | 10 | ||||
-rw-r--r-- | tools/corosync-quorumtool.c | 1023 | ||||
-rw-r--r-- | tools/corosync-xmlproc.sh | 57 | ||||
-rw-r--r-- | tools/util.c | 35 | ||||
-rw-r--r-- | tools/util.h | 15 |
13 files changed, 5663 insertions, 0 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..6279dd4 --- /dev/null +++ b/tools/Makefile.am @@ -0,0 +1,93 @@ +# Copyright (c) 2009 Red Hat, Inc. +# +# Authors: Andrew Beekhof +# Steven Dake (sdake@redhat.com) +# +# This software licensed under BSD license, the text of which follows: +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# - Neither the name of the MontaVista Software, Inc. nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +MAINTAINERCLEANFILES = Makefile.in + +sbin_PROGRAMS = corosync-cfgtool \ + corosync-keygen \ + corosync-cpgtool corosync-quorumtool \ + corosync-notifyd corosync-cmapctl + +bin_SCRIPTS = corosync-blackbox + +if INSTALL_XMLCONF +bin_SCRIPTS += corosync-xmlproc +endif + +noinst_HEADERS = util.h + +AM_CFLAGS = $(knet_CFLAGS) + +EXTRA_DIST = corosync-xmlproc.sh \ + corosync-notifyd.sysconfig.example \ + corosync-blackbox.sh + +corosync_cfgtool_SOURCES = corosync-cfgtool.c util.c + +corosync_quorumtool_SOURCES = corosync-quorumtool.c util.c + +corosync-xmlproc: corosync-xmlproc.sh + $(SED) -e 's#@''DATADIR@#${datadir}#g' \ + -e 's#@''BASHPATH@#${BASHPATH}#g' \ + $< > $@ + +corosync-blackbox: corosync-blackbox.sh + $(SED) -e 's#@''LOCALSTATEDIR@#${localstatedir}#g' $< > $@ + +corosync_cmapctl_LDADD = $(LIBQB_LIBS) $(top_builddir)/common_lib/libcorosync_common.la $(top_builddir)/lib/libcmap.la + +corosync_cfgtool_LDADD = $(LIBQB_LIBS) $(top_builddir)/common_lib/libcorosync_common.la \ + $(top_builddir)/lib/libcfg.la $(top_builddir)/lib/libcmap.la + +corosync_cpgtool_LDADD = $(LIBQB_LIBS) $(top_builddir)/lib/libcfg.la \ + $(top_builddir)/lib/libcpg.la \ + $(top_builddir)/common_lib/libcorosync_common.la + +corosync_quorumtool_LDADD = $(LIBQB_LIBS) \ + $(top_builddir)/lib/libcmap.la \ + $(top_builddir)/lib/libcfg.la \ + $(top_builddir)/lib/libquorum.la \ + $(top_builddir)/lib/libvotequorum.la \ + $(top_builddir)/common_lib/libcorosync_common.la + +corosync_notifyd_CFLAGS = $(DBUS_CFLAGS) $(libsystemd_CFLAGS) +corosync_notifyd_LDADD = $(LIBQB_LIBS) $(DBUS_LIBS) $(SNMP_LIBS) \ + $(libsystemd_LIBS) \ + $(top_builddir)/lib/libcmap.la \ + $(top_builddir)/lib/libcfg.la \ + $(top_builddir)/lib/libquorum.la \ + $(top_builddir)/common_lib/libcorosync_common.la + +lint: + -splint $(LINT_FLAGS) $(DBUS_CFLAGS) $(CPPFLAGS) $(CFLAGS) *.c + +clean-local: + rm -f corosync-xmlproc corosync-blackbox diff --git a/tools/Makefile.in b/tools/Makefile.in new file mode 100644 index 0000000..2e9398c --- /dev/null +++ b/tools/Makefile.in @@ -0,0 +1,899 @@ +# Makefile.in generated by automake 1.13.4 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2013 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# Copyright (c) 2009 Red Hat, Inc. +# +# Authors: Andrew Beekhof +# Steven Dake (sdake@redhat.com) +# +# This software licensed under BSD license, the text of which follows: +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# - Neither the name of the MontaVista Software, Inc. nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + + + +VPATH = @srcdir@ +am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +sbin_PROGRAMS = corosync-cfgtool$(EXEEXT) corosync-keygen$(EXEEXT) \ + corosync-cpgtool$(EXEEXT) corosync-quorumtool$(EXEEXT) \ + corosync-notifyd$(EXEEXT) corosync-cmapctl$(EXEEXT) +@INSTALL_XMLCONF_TRUE@am__append_1 = corosync-xmlproc +subdir = tools +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ + $(top_srcdir)/depcomp $(noinst_HEADERS) +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/lib/libcfg.verso $(top_srcdir)/lib/libcpg.verso \ + $(top_srcdir)/lib/libquorum.verso \ + $(top_srcdir)/lib/libsam.verso \ + $(top_srcdir)/lib/libvotequorum.verso \ + $(top_srcdir)/lib/libcmap.verso $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/include/corosync/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(bindir)" +PROGRAMS = $(sbin_PROGRAMS) +am_corosync_cfgtool_OBJECTS = corosync-cfgtool.$(OBJEXT) \ + util.$(OBJEXT) +corosync_cfgtool_OBJECTS = $(am_corosync_cfgtool_OBJECTS) +am__DEPENDENCIES_1 = +corosync_cfgtool_DEPENDENCIES = $(am__DEPENDENCIES_1) \ + $(top_builddir)/common_lib/libcorosync_common.la \ + $(top_builddir)/lib/libcfg.la $(top_builddir)/lib/libcmap.la +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +corosync_cmapctl_SOURCES = corosync-cmapctl.c +corosync_cmapctl_OBJECTS = corosync-cmapctl.$(OBJEXT) +corosync_cmapctl_DEPENDENCIES = $(am__DEPENDENCIES_1) \ + $(top_builddir)/common_lib/libcorosync_common.la \ + $(top_builddir)/lib/libcmap.la +corosync_cpgtool_SOURCES = corosync-cpgtool.c +corosync_cpgtool_OBJECTS = corosync-cpgtool.$(OBJEXT) +corosync_cpgtool_DEPENDENCIES = $(am__DEPENDENCIES_1) \ + $(top_builddir)/lib/libcfg.la $(top_builddir)/lib/libcpg.la \ + $(top_builddir)/common_lib/libcorosync_common.la +corosync_keygen_SOURCES = corosync-keygen.c +corosync_keygen_OBJECTS = corosync-keygen.$(OBJEXT) +corosync_keygen_LDADD = $(LDADD) +corosync_notifyd_SOURCES = corosync-notifyd.c +corosync_notifyd_OBJECTS = \ + corosync_notifyd-corosync-notifyd.$(OBJEXT) +corosync_notifyd_DEPENDENCIES = $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(top_builddir)/lib/libcmap.la \ + $(top_builddir)/lib/libcfg.la $(top_builddir)/lib/libquorum.la \ + $(top_builddir)/common_lib/libcorosync_common.la +corosync_notifyd_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(corosync_notifyd_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ + -o $@ +am_corosync_quorumtool_OBJECTS = corosync-quorumtool.$(OBJEXT) \ + util.$(OBJEXT) +corosync_quorumtool_OBJECTS = $(am_corosync_quorumtool_OBJECTS) +corosync_quorumtool_DEPENDENCIES = $(am__DEPENDENCIES_1) \ + $(top_builddir)/lib/libcmap.la $(top_builddir)/lib/libcfg.la \ + $(top_builddir)/lib/libquorum.la \ + $(top_builddir)/lib/libvotequorum.la \ + $(top_builddir)/common_lib/libcorosync_common.la +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +SCRIPTS = $(bin_SCRIPTS) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/corosync +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(corosync_cfgtool_SOURCES) corosync-cmapctl.c \ + corosync-cpgtool.c corosync-keygen.c corosync-notifyd.c \ + $(corosync_quorumtool_SOURCES) +DIST_SOURCES = $(corosync_cfgtool_SOURCES) corosync-cmapctl.c \ + corosync-cpgtool.c corosync-keygen.c corosync-notifyd.c \ + $(corosync_quorumtool_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALLOCA = @ALLOCA@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUGTOOL = @AUGTOOL@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BASHPATH = @BASHPATH@ +BINDGEN = @BINDGEN@ +CARGO = @CARGO@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFG_SONAME = @CFG_SONAME@ +CFLAGS = @CFLAGS@ +CLIPPY = @CLIPPY@ +CMAP_SONAME = @CMAP_SONAME@ +COROSYSCONFDIR = @COROSYSCONFDIR@ +CPG_SONAME = @CPG_SONAME@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_LIBS = @DBUS_LIBS@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DOT = @DOT@ +DOXYGEN = @DOXYGEN@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +GROFF = @GROFF@ +INITCONFIGDIR = @INITCONFIGDIR@ +INITDDIR = @INITDDIR@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBQB_CFLAGS = @LIBQB_CFLAGS@ +LIBQB_LIBS = @LIBQB_LIBS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LINT_FLAGS = @LINT_FLAGS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LOGDIR = @LOGDIR@ +LOGROTATEDIR = @LOGROTATEDIR@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +QUORUM_SONAME = @QUORUM_SONAME@ +RANLIB = @RANLIB@ +RUSTC = @RUSTC@ +RUSTDOC = @RUSTDOC@ +RUSTFMT = @RUSTFMT@ +RUST_FLAGS = @RUST_FLAGS@ +RUST_TARGET_DIR = @RUST_TARGET_DIR@ +SAM_SONAME = @SAM_SONAME@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SNMPCONFIG = @SNMPCONFIG@ +SNMP_LIBS = @SNMP_LIBS@ +SOMAJOR = @SOMAJOR@ +SOMICRO = @SOMICRO@ +SOMINOR = @SOMINOR@ +SONAME = @SONAME@ +STRIP = @STRIP@ +SYSTEMDDIR = @SYSTEMDDIR@ +VERSCRIPT_LDFLAGS = @VERSCRIPT_LDFLAGS@ +VERSION = @VERSION@ +VOTEQUORUM_SONAME = @VOTEQUORUM_SONAME@ +WITH_LIST = @WITH_LIST@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +corosyncrustver = @corosyncrustver@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +knet_CFLAGS = @knet_CFLAGS@ +knet_LIBS = @knet_LIBS@ +libdir = @libdir@ +libexecdir = @libexecdir@ +libsystemd_CFLAGS = @libsystemd_CFLAGS@ +libsystemd_LIBS = @libsystemd_LIBS@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +nozzle_CFLAGS = @nozzle_CFLAGS@ +nozzle_LIBS = @nozzle_LIBS@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +statgrab_CFLAGS = @statgrab_CFLAGS@ +statgrab_LIBS = @statgrab_LIBS@ +statgrabge090_CFLAGS = @statgrabge090_CFLAGS@ +statgrabge090_LIBS = @statgrabge090_LIBS@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +MAINTAINERCLEANFILES = Makefile.in +bin_SCRIPTS = corosync-blackbox $(am__append_1) +noinst_HEADERS = util.h +AM_CFLAGS = $(knet_CFLAGS) +EXTRA_DIST = corosync-xmlproc.sh \ + corosync-notifyd.sysconfig.example \ + corosync-blackbox.sh + +corosync_cfgtool_SOURCES = corosync-cfgtool.c util.c +corosync_quorumtool_SOURCES = corosync-quorumtool.c util.c +corosync_cmapctl_LDADD = $(LIBQB_LIBS) $(top_builddir)/common_lib/libcorosync_common.la $(top_builddir)/lib/libcmap.la +corosync_cfgtool_LDADD = $(LIBQB_LIBS) $(top_builddir)/common_lib/libcorosync_common.la \ + $(top_builddir)/lib/libcfg.la $(top_builddir)/lib/libcmap.la + +corosync_cpgtool_LDADD = $(LIBQB_LIBS) $(top_builddir)/lib/libcfg.la \ + $(top_builddir)/lib/libcpg.la \ + $(top_builddir)/common_lib/libcorosync_common.la + +corosync_quorumtool_LDADD = $(LIBQB_LIBS) \ + $(top_builddir)/lib/libcmap.la \ + $(top_builddir)/lib/libcfg.la \ + $(top_builddir)/lib/libquorum.la \ + $(top_builddir)/lib/libvotequorum.la \ + $(top_builddir)/common_lib/libcorosync_common.la + +corosync_notifyd_CFLAGS = $(DBUS_CFLAGS) $(libsystemd_CFLAGS) +corosync_notifyd_LDADD = $(LIBQB_LIBS) $(DBUS_LIBS) $(SNMP_LIBS) \ + $(libsystemd_LIBS) \ + $(top_builddir)/lib/libcmap.la \ + $(top_builddir)/lib/libcfg.la \ + $(top_builddir)/lib/libquorum.la \ + $(top_builddir)/common_lib/libcorosync_common.la + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign tools/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign tools/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-sbinPROGRAMS: $(sbin_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p \ + || test -f $$p1 \ + ; then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' \ + -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-sbinPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' \ + `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(sbindir)" && rm -f $$files + +clean-sbinPROGRAMS: + @list='$(sbin_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +corosync-cfgtool$(EXEEXT): $(corosync_cfgtool_OBJECTS) $(corosync_cfgtool_DEPENDENCIES) $(EXTRA_corosync_cfgtool_DEPENDENCIES) + @rm -f corosync-cfgtool$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(corosync_cfgtool_OBJECTS) $(corosync_cfgtool_LDADD) $(LIBS) + +corosync-cmapctl$(EXEEXT): $(corosync_cmapctl_OBJECTS) $(corosync_cmapctl_DEPENDENCIES) $(EXTRA_corosync_cmapctl_DEPENDENCIES) + @rm -f corosync-cmapctl$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(corosync_cmapctl_OBJECTS) $(corosync_cmapctl_LDADD) $(LIBS) + +corosync-cpgtool$(EXEEXT): $(corosync_cpgtool_OBJECTS) $(corosync_cpgtool_DEPENDENCIES) $(EXTRA_corosync_cpgtool_DEPENDENCIES) + @rm -f corosync-cpgtool$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(corosync_cpgtool_OBJECTS) $(corosync_cpgtool_LDADD) $(LIBS) + +corosync-keygen$(EXEEXT): $(corosync_keygen_OBJECTS) $(corosync_keygen_DEPENDENCIES) $(EXTRA_corosync_keygen_DEPENDENCIES) + @rm -f corosync-keygen$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(corosync_keygen_OBJECTS) $(corosync_keygen_LDADD) $(LIBS) + +corosync-notifyd$(EXEEXT): $(corosync_notifyd_OBJECTS) $(corosync_notifyd_DEPENDENCIES) $(EXTRA_corosync_notifyd_DEPENDENCIES) + @rm -f corosync-notifyd$(EXEEXT) + $(AM_V_CCLD)$(corosync_notifyd_LINK) $(corosync_notifyd_OBJECTS) $(corosync_notifyd_LDADD) $(LIBS) + +corosync-quorumtool$(EXEEXT): $(corosync_quorumtool_OBJECTS) $(corosync_quorumtool_DEPENDENCIES) $(EXTRA_corosync_quorumtool_DEPENDENCIES) + @rm -f corosync-quorumtool$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(corosync_quorumtool_OBJECTS) $(corosync_quorumtool_LDADD) $(LIBS) +install-binSCRIPTS: $(bin_SCRIPTS) + @$(NORMAL_INSTALL) + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n' \ + -e 'h;s|.*|.|' \ + -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) { files[d] = files[d] " " $$1; \ + if (++n[d] == $(am__install_max)) { \ + print "f", d, files[d]; n[d] = 0; files[d] = "" } } \ + else { print "f", d "/" $$4, $$1 } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || exit 0; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 's,.*/,,;$(transform)'`; \ + dir='$(DESTDIR)$(bindir)'; $(am__uninstall_files_from_dir) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/corosync-cfgtool.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/corosync-cmapctl.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/corosync-cpgtool.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/corosync-keygen.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/corosync-quorumtool.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/corosync_notifyd-corosync-notifyd.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +corosync_notifyd-corosync-notifyd.o: corosync-notifyd.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(corosync_notifyd_CFLAGS) $(CFLAGS) -MT corosync_notifyd-corosync-notifyd.o -MD -MP -MF $(DEPDIR)/corosync_notifyd-corosync-notifyd.Tpo -c -o corosync_notifyd-corosync-notifyd.o `test -f 'corosync-notifyd.c' || echo '$(srcdir)/'`corosync-notifyd.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/corosync_notifyd-corosync-notifyd.Tpo $(DEPDIR)/corosync_notifyd-corosync-notifyd.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='corosync-notifyd.c' object='corosync_notifyd-corosync-notifyd.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(corosync_notifyd_CFLAGS) $(CFLAGS) -c -o corosync_notifyd-corosync-notifyd.o `test -f 'corosync-notifyd.c' || echo '$(srcdir)/'`corosync-notifyd.c + +corosync_notifyd-corosync-notifyd.obj: corosync-notifyd.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(corosync_notifyd_CFLAGS) $(CFLAGS) -MT corosync_notifyd-corosync-notifyd.obj -MD -MP -MF $(DEPDIR)/corosync_notifyd-corosync-notifyd.Tpo -c -o corosync_notifyd-corosync-notifyd.obj `if test -f 'corosync-notifyd.c'; then $(CYGPATH_W) 'corosync-notifyd.c'; else $(CYGPATH_W) '$(srcdir)/corosync-notifyd.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/corosync_notifyd-corosync-notifyd.Tpo $(DEPDIR)/corosync_notifyd-corosync-notifyd.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='corosync-notifyd.c' object='corosync_notifyd-corosync-notifyd.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(corosync_notifyd_CFLAGS) $(CFLAGS) -c -o corosync_notifyd-corosync-notifyd.obj `if test -f 'corosync-notifyd.c'; then $(CYGPATH_W) 'corosync-notifyd.c'; else $(CYGPATH_W) '$(srcdir)/corosync-notifyd.c'; fi` + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) $(SCRIPTS) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-am + +clean-am: clean-generic clean-libtool clean-local clean-sbinPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binSCRIPTS install-sbinPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binSCRIPTS uninstall-sbinPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-local clean-sbinPROGRAMS cscopelist-am \ + ctags ctags-am distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-binSCRIPTS \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-sbinPROGRAMS \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-binSCRIPTS uninstall-sbinPROGRAMS + + +corosync-xmlproc: corosync-xmlproc.sh + $(SED) -e 's#@''DATADIR@#${datadir}#g' \ + -e 's#@''BASHPATH@#${BASHPATH}#g' \ + $< > $@ + +corosync-blackbox: corosync-blackbox.sh + $(SED) -e 's#@''LOCALSTATEDIR@#${localstatedir}#g' $< > $@ + +lint: + -splint $(LINT_FLAGS) $(DBUS_CFLAGS) $(CPPFLAGS) $(CFLAGS) *.c + +clean-local: + rm -f corosync-xmlproc corosync-blackbox + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/tools/corosync-blackbox.sh b/tools/corosync-blackbox.sh new file mode 100644 index 0000000..1ca831f --- /dev/null +++ b/tools/corosync-blackbox.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Copyright (c) 2010 Red Hat, Inc. +# +# Authors: Angus Salkeld <asalkeld@redhat.com +# +# This software licensed under BSD license, the text of which follows: +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# - Neither the name of the MontaVista Software, Inc. nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +corosync-cmapctl -s runtime.blackbox.dump_state str "$(date +%s)" +corosync-cmapctl -s runtime.blackbox.dump_flight_data str "$(date +%s)" +qb-blackbox "@LOCALSTATEDIR@/lib/corosync/fdata" diff --git a/tools/corosync-cfgtool.c b/tools/corosync-cfgtool.c new file mode 100644 index 0000000..d04d5be --- /dev/null +++ b/tools/corosync-cfgtool.c @@ -0,0 +1,614 @@ +/* + * Copyright (c) 2006-2020 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Steven Dake <sdake@redhat.com> + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the MontaVista Software, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <unistd.h> +#include <string.h> +#include <pthread.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/select.h> +#include <sys/un.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <limits.h> +#include <getopt.h> + +#include <corosync/corotypes.h> +#include <corosync/totem/totem.h> +#include <corosync/cfg.h> +#include <corosync/cmap.h> +#include "util.h" + +#define cs_repeat(result, max, code) \ + do { \ + int counter = 0; \ + do { \ + result = code; \ + if (result == CS_ERR_TRY_AGAIN) { \ + sleep(1); \ + counter++; \ + } else { \ + break; \ + } \ + } while (counter < max); \ + } while (0) + +enum user_action { + ACTION_NOOP=0, + ACTION_LINKSTATUS_GET, + ACTION_NODESTATUS_GET, + ACTION_RELOAD_CONFIG, + ACTION_REOPEN_LOG_FILES, + ACTION_SHUTDOW, + ACTION_SHOWADDR, + ACTION_KILL_NODE, +}; + +static int node_compare(const void *aptr, const void *bptr) +{ + uint32_t a,b; + + a = *(uint32_t *)aptr; + b = *(uint32_t *)bptr; + + return a > b; +} + +static int +nodestatusget_do (enum user_action action, int brief) +{ + cs_error_t result; + corosync_cfg_handle_t handle; + cmap_handle_t cmap_handle; + char iter_key[CMAP_KEYNAME_MAXLEN]; + cmap_iter_handle_t iter; + unsigned int local_nodeid; + unsigned int local_nodeid_index=0; + unsigned int other_nodeid_index=0; + unsigned int nodeid; + int nodeid_match_guard; + cmap_value_types_t type; + size_t value_len; + char *str; + char *transport_str = NULL; + uint32_t nodeid_list[KNET_MAX_HOST]; + const char *link_transport[KNET_MAX_LINK]; + int s = 0; + int rc = EXIT_SUCCESS; + int transport_number = TOTEM_TRANSPORT_KNET; + int i,j; + struct corosync_cfg_node_status_v1 node_status; + + result = corosync_cfg_initialize (&handle, NULL); + if (result != CS_OK) { + fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result); + exit (EXIT_FAILURE); + } + + result = cmap_initialize (&cmap_handle); + if (result != CS_OK) { + fprintf (stderr, "Could not initialize corosync cmap API error %d\n", result); + exit (EXIT_FAILURE); + } + + result = cmap_get_string(cmap_handle, "totem.transport", &str); + if (result == CS_OK) { + if (strcmp (str, "udpu") == 0) { + transport_number = TOTEM_TRANSPORT_UDPU; + } + if (strcmp (str, "udp") == 0) { + transport_number = TOTEM_TRANSPORT_UDP; + } + transport_str = str; + } + if (!transport_str) { + transport_str = strdup("knet"); /* It's the default */ + } + + result = corosync_cfg_local_get(handle, &local_nodeid); + if (result != CS_OK) { + fprintf (stderr, "Could not get the local node id, the error is: %d\n", result); + free(transport_str); + cmap_finalize(cmap_handle); + corosync_cfg_finalize(handle); + return EXIT_FAILURE; + } + + /* Get a list of nodes. We do it this way rather than using votequorum as cfgtool + * needs to be independent of quorum type + */ + result = cmap_iter_init(cmap_handle, "nodelist.node.", &iter); + if (result != CS_OK) { + fprintf (stderr, "Could not get nodelist from cmap. error %d\n", result); + free(transport_str); + cmap_finalize(cmap_handle); + corosync_cfg_finalize(handle); + exit (EXIT_FAILURE); + } + + while ((cmap_iter_next(cmap_handle, iter, iter_key, &value_len, &type)) == CS_OK) { + nodeid_match_guard = 0; + if (sscanf(iter_key, "nodelist.node.%*u.nodeid%n", &nodeid_match_guard) != 0) { + continue; + } + /* check for exact match */ + if (nodeid_match_guard != strlen(iter_key)) { + continue; + } + if (cmap_get_uint32(cmap_handle, iter_key, &nodeid) == CS_OK) { + nodeid_list[s++] = nodeid; + } + } + + if (s == 0) { + fprintf(stderr, "No nodes found in nodelist\n"); + exit (EXIT_FAILURE); + } + + /* It's nice to have these in nodeid order */ + qsort(nodeid_list, s, sizeof(uint32_t), node_compare); + + /* + * Find local and other nodeid index in nodeid_list + */ + for (i = 0; i < s; i++) { + if (nodeid_list[i] == local_nodeid) { + local_nodeid_index = i; + } else { + /* Bit of an odd one this. but local node only uses one link (of course, to itself) + so if we want to know which links are active across the cluster we need to look + at another node (any other) node's link list */ + other_nodeid_index = i; + } + } + + /* Get the transport of each link - but set reasonable defaults */ + if (transport_number == TOTEM_TRANSPORT_KNET) { + for (i = 0; i<KNET_MAX_LINK; i++) { + link_transport[i] = "udp"; + } + } else { + for (i = 0; i<KNET_MAX_LINK; i++) { + link_transport[i] = ""; /* No point in displaying "udp" again */ + } + } + result = cmap_iter_init(cmap_handle, "totem.interface.", &iter); + if (result == CS_OK) { /* it's fine for this to fail, we just use the defaults */ + while ((cmap_iter_next(cmap_handle, iter, iter_key, &value_len, &type)) == CS_OK) { + unsigned int link_number; + char *knet_transport; + char knet_transport_str[CMAP_KEYNAME_MAXLEN]; + + /* transport is (sensibly) indexed by link number */ + if (sscanf(iter_key, "totem.interface.%u.knet_transport", &link_number) != 1) { + continue; + } + snprintf(knet_transport_str, sizeof(knet_transport_str), + "totem.interface.%u.knet_transport", link_number); + if (cmap_get_string(cmap_handle, knet_transport_str, &knet_transport) == CS_OK) { + link_transport[link_number] = knet_transport; + } + } + + cmap_iter_finalize(cmap_handle, iter); + } + + cmap_finalize(cmap_handle); + + printf ("Local node ID " CS_PRI_NODE_ID ", transport %s\n", local_nodeid, transport_str); + + /* If node status requested then do print node-based info */ + if (action == ACTION_NODESTATUS_GET) { + for (i=0; i<s; i++) { + result = corosync_cfg_node_status_get(handle, nodeid_list[i], CFG_NODE_STATUS_V1, &node_status); + if (result == CS_OK) { + /* Only display node info if it is reachable (and not us) */ + if (node_status.reachable && node_status.nodeid != local_nodeid) { + printf("nodeid: " CS_PRI_NODE_ID "", node_status.nodeid); + printf(" reachable"); + if (node_status.remote) { + printf(" remote"); + } + if (node_status.external) { + printf(" external"); + } +#ifdef HAVE_KNET_ONWIRE_VER + if (transport_number == TOTEM_TRANSPORT_KNET) { + printf(" onwire (min/max/cur): %d, %d, %d", + node_status.onwire_min, + node_status.onwire_max, + node_status.onwire_ver); + } +#endif + printf("\n"); + for (j=0; j<CFG_MAX_LINKS; j++) { + if (node_status.link_status[j].enabled) { + printf(" LINK: %d %s", j, link_transport[j]); + printf(" (%s%s%s)", + node_status.link_status[j].src_ipaddr, + transport_number==TOTEM_TRANSPORT_KNET?"->":"", + node_status.link_status[j].dst_ipaddr); + if (node_status.link_status[j].enabled) { + printf(" enabled"); + } + if (node_status.link_status[j].connected) { + printf(" connected"); + } + if (node_status.link_status[j].dynconnected) { + printf(" dynconnected"); + } + printf(" mtu: %d\n", node_status.link_status[j].mtu); + } + } + printf("\n"); + } + } + } + } + /* Print in link order */ + else { + struct corosync_cfg_node_status_v1 node_info[s]; + memset(node_info, 0, sizeof(node_info)); + + for (i=0; i<s; i++) { + result = corosync_cfg_node_status_get(handle, nodeid_list[i], CFG_NODE_STATUS_V1, &node_info[i]); + if (result != CS_OK) { + fprintf (stderr, "Could not get the node status for nodeid %d, the error is: %d\n", nodeid_list[i], result); + } + } + + for (i=0; i<CFG_MAX_LINKS; i++) { + if (node_info[other_nodeid_index].link_status[i].enabled) { + printf("LINK ID %d %s\n", i, link_transport[i]); + printf("\taddr\t= %s\n", node_info[other_nodeid_index].link_status[i].src_ipaddr); + if (brief) { + printf("\tstatus\t= "); + for (j=0; j<s; j++) { + char status = (node_info[j].link_status[i].enabled | + (node_info[j].link_status[i].connected << 1)) + '0'; + if (j == local_nodeid_index) { + status = 'n'; + } + printf("%c", status); + } + printf("\n"); + } else { + printf("\tstatus:\n"); + for (j=0; j<s; j++) { + printf("\t\tnodeid: " CS_PRI_NODE_ID_PADDED ":\t", node_info[j].nodeid); + if (j == local_nodeid_index) { + printf("localhost"); + } else { + if (node_info[j].link_status[i].connected) { + printf("connected"); + } else { + printf("disconnected"); + } + } + printf("\n"); + } + } + } + } + } + free(transport_str); + corosync_cfg_finalize(handle); + return rc; +} + +static int reload_config_do (void) +{ + cs_error_t result; + corosync_cfg_handle_t handle; + int rc; + + rc = EXIT_SUCCESS; + + printf ("Reloading corosync.conf...\n"); + result = corosync_cfg_initialize (&handle, NULL); + if (result != CS_OK) { + fprintf (stderr, "Could not initialize corosync configuration API error %s\n", cs_strerror(result)); + exit (EXIT_FAILURE); + } + + result = corosync_cfg_reload_config (handle); + if (result != CS_OK) { + fprintf (stderr, "Could not reload configuration. Error %s\n", cs_strerror(result)); + rc = (int)result; + } + else { + printf ("Done\n"); + } + + (void)corosync_cfg_finalize (handle); + + return (rc); +} + +static int reopen_log_files_do (void) +{ + cs_error_t result; + corosync_cfg_handle_t handle; + int rc; + + rc = EXIT_SUCCESS; + + result = corosync_cfg_initialize (&handle, NULL); + if (result != CS_OK) { + fprintf (stderr, "Could not initialize corosync configuration API error %s\n", cs_strerror(result)); + exit (EXIT_FAILURE); + } + + result = corosync_cfg_reopen_log_files (handle); + if (result != CS_OK) { + fprintf (stderr, "Could not reopen corosync logging files. Error %s\n", cs_strerror(result)); + rc = (int)result; + } + + (void)corosync_cfg_finalize (handle); + + return (rc); +} + +static void shutdown_do(int force) +{ + cs_error_t result; + corosync_cfg_handle_t handle; + corosync_cfg_callbacks_t callbacks; + int flag; + + callbacks.corosync_cfg_shutdown_callback = NULL; + if (force) { + flag = COROSYNC_CFG_SHUTDOWN_FLAG_REGARDLESS; + } else { + flag = COROSYNC_CFG_SHUTDOWN_FLAG_REQUEST; + } + + result = corosync_cfg_initialize (&handle, &callbacks); + if (result != CS_OK) { + fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result); + exit (EXIT_FAILURE); + } + + printf ("Shutting down corosync\n"); + cs_repeat(result, 30, corosync_cfg_try_shutdown (handle, flag)); + if (result != CS_OK) { + fprintf (stderr, "Could not shutdown (error = %d)\n", result); + } + + (void)corosync_cfg_finalize (handle); +} + +static int showaddrs_do(unsigned int nodeid) +{ + cs_error_t result; + corosync_cfg_handle_t handle; + int numaddrs; + int i; + int rc = EXIT_SUCCESS; + corosync_cfg_node_address_t addrs[INTERFACE_MAX]; + + + result = corosync_cfg_initialize (&handle, NULL); + if (result != CS_OK) { + fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result); + exit (EXIT_FAILURE); + } + + if (corosync_cfg_get_node_addrs(handle, nodeid, INTERFACE_MAX, &numaddrs, addrs) == CS_OK) { + for (i=0; i<numaddrs; i++) { + char buf[INET6_ADDRSTRLEN]; + struct sockaddr_storage *ss = (struct sockaddr_storage *)addrs[i].address; + struct sockaddr_in *sin = (struct sockaddr_in *)addrs[i].address; + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addrs[i].address; + void *saddr; + + if (!ss->ss_family) { + continue; + } + if (ss->ss_family == AF_INET6) { + saddr = &sin6->sin6_addr; + } else { + saddr = &sin->sin_addr; + } + + inet_ntop(ss->ss_family, saddr, buf, sizeof(buf)); + if (i != 0) { + printf(" "); + } + printf("%s", buf); + } + printf("\n"); + } else { + fprintf (stderr, "Could not get node address for nodeid %d\n", nodeid); + rc = EXIT_FAILURE; + } + + + (void)corosync_cfg_finalize (handle); + return rc; +} + + +static void killnode_do(unsigned int nodeid) +{ + cs_error_t result; + corosync_cfg_handle_t handle; + + printf ("Killing node " CS_PRI_NODE_ID "\n", nodeid); + result = corosync_cfg_initialize (&handle, NULL); + if (result != CS_OK) { + fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result); + exit (EXIT_FAILURE); + } + result = corosync_cfg_kill_node (handle, nodeid, "Killed by corosync-cfgtool"); + if (result != CS_OK) { + fprintf (stderr, "Could not kill node (error = %s)\n", cs_strerror(result)); + exit(EXIT_FAILURE); + } + (void)corosync_cfg_finalize (handle); +} + + +static void usage_do (void) +{ + printf ("corosync-cfgtool [[-i <interface ip>] [-b] -s] [-R] [-L] [-k nodeid] [-a nodeid] [-h] [-H]\n\n"); + printf ("A tool for displaying and configuring active parameters within corosync.\n"); + printf ("options:\n"); + printf ("\t-i\tFinds only information about the specified interface IP address or link id when used with -s..\n"); + printf ("\t-s\tDisplays the status of the current links on this node.\n"); + printf ("\t-n\tDisplays the status of the connected nodes and their links.\n"); + printf ("\t-b\tDisplays the brief status of the current links on this node when used with -s.\n"); + printf ("\t-R\tTell all instances of corosync in this cluster to reload corosync.conf.\n"); + printf ("\t-L\tTell corosync to reopen all logging files.\n"); + printf ("\t-k\tKill a node identified by node id.\n"); + printf ("\t-a\tDisplay the IP address(es) of a node\n"); + printf ("\t-h\tPrint basic usage.\n"); + printf ("\t-H\tShutdown corosync cleanly on this node.\n"); + printf ("\t\t--force will shut down corosync regardless of daemon vetos\n"); +} + +int main (int argc, char *argv[]) { + int opt; + unsigned int nodeid = 0; + char interface_name[128] = ""; + int rc = EXIT_SUCCESS; + enum user_action action = ACTION_NOOP; + int brief = 0; + long long int l; + int option_index = 0; + int force_shutdown = 0; + const char *options = "i:snbrRLk:a:hH"; + struct option long_options[] = { + {"if", required_argument, 0, 'i'}, + {"status", no_argument, 0, 's'}, + {"nodes", no_argument, 0, 'n'}, + {"brief", no_argument, 0, 'b'}, + {"reload", no_argument, 0, 'R'}, + {"reopen", no_argument, 0, 'L'}, + {"kill", required_argument, 0, 'k'}, + {"address", required_argument, 0, 'a'}, + {"shutdown", no_argument, 0, 'H'}, + {"force", no_argument, 0, 0}, + {0, 0, 0, 0} + }; + + while ( (opt = getopt_long(argc, argv, options, long_options, &option_index)) != -1 ) { + switch (opt) { + case 0: // options with no short equivalent - just --force ATM + if (strcmp(long_options[option_index].name, "force") == 0) { + force_shutdown = 1; + } + break; + case 'i': + strncpy(interface_name, optarg, sizeof(interface_name)); + interface_name[sizeof(interface_name) - 1] = '\0'; + break; + case 's': + action = ACTION_LINKSTATUS_GET; + break; + case 'n': + action = ACTION_NODESTATUS_GET; + break; + case 'b': + brief = 1; + break; + case 'R': + action = ACTION_RELOAD_CONFIG; + break; + case 'L': + action = ACTION_REOPEN_LOG_FILES; + break; + case 'k': + if (util_strtonum(optarg, 1, UINT_MAX, &l) == -1) { + fprintf(stderr, "The nodeid was not valid, try a positive number\n"); + exit(EXIT_FAILURE); + } + nodeid = l; + action = ACTION_KILL_NODE; + break; + case 'H': + action = ACTION_SHUTDOW; + break; + case 'a': + if (util_strtonum(optarg, 1, UINT_MAX, &l) == -1) { + fprintf(stderr, "The nodeid was not valid, try a positive number\n"); + exit(EXIT_FAILURE); + } + nodeid = l; + action = ACTION_SHOWADDR; + break; + case '?': + return (EXIT_FAILURE); + break; + case 'h': + default: + break; + } + } + switch(action) { + case ACTION_LINKSTATUS_GET: + rc = nodestatusget_do(action, brief); + break; + case ACTION_NODESTATUS_GET: + rc = nodestatusget_do(action, brief); + break; + case ACTION_RELOAD_CONFIG: + rc = reload_config_do(); + break; + case ACTION_REOPEN_LOG_FILES: + rc = reopen_log_files_do(); + break; + case ACTION_KILL_NODE: + killnode_do(nodeid); + break; + case ACTION_SHUTDOW: + shutdown_do(force_shutdown); + break; + case ACTION_SHOWADDR: + rc = showaddrs_do(nodeid); + break; + case ACTION_NOOP: + default: + usage_do(); + break; + } + + return (rc); +} diff --git a/tools/corosync-cmapctl.c b/tools/corosync-cmapctl.c new file mode 100644 index 0000000..6c79c9a --- /dev/null +++ b/tools/corosync-cmapctl.c @@ -0,0 +1,996 @@ +/* + * Copyright (c) 2011-2012 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Jan Friesse (jfriesse@redhat.com) + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the Red Hat, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <config.h> + +#include <ctype.h> +#include <stdio.h> +#include <poll.h> + +#include <corosync/corotypes.h> +#include <corosync/cmap.h> +#include "../lib/util.h" + +#ifndef INFTIM +#define INFTIM -1 +#endif + +#define MAX_TRY_AGAIN 10 + +enum user_action { + ACTION_GET, + ACTION_SET, + ACTION_DELETE, + ACTION_DELETE_PREFIX, + ACTION_PRINT_PREFIX, + ACTION_TRACK, + ACTION_LOAD, + ACTION_CLEARSTATS, +}; + +struct name_to_type_item { + const char *name; + cmap_value_types_t type; +}; + +struct name_to_type_item name_to_type[] = { + {"i8", CMAP_VALUETYPE_INT8}, + {"u8", CMAP_VALUETYPE_UINT8}, + {"i16", CMAP_VALUETYPE_INT16}, + {"u16", CMAP_VALUETYPE_UINT16}, + {"i32", CMAP_VALUETYPE_INT32}, + {"u32", CMAP_VALUETYPE_UINT32}, + {"i64", CMAP_VALUETYPE_INT64}, + {"u64", CMAP_VALUETYPE_UINT64}, + {"flt", CMAP_VALUETYPE_FLOAT}, + {"dbl", CMAP_VALUETYPE_DOUBLE}, + {"str", CMAP_VALUETYPE_STRING}, + {"bin", CMAP_VALUETYPE_BINARY}}; + +int show_binary = 0; +int quiet = 0; + +static int convert_name_to_type(const char *name) +{ + int i; + + for (i = 0; i < sizeof(name_to_type) / sizeof(*name_to_type); i++) { + if (strcmp(name, name_to_type[i].name) == 0) { + return (name_to_type[i].type); + } + } + + return (-1); +} + +static int print_help(void) +{ + printf("\n"); + printf("usage: corosync-cmapctl [-b] [-DdghsqTCt] [-p filename] [-m map] [params...]\n"); + printf("\n"); + printf(" -b show binary values\n"); + printf("\n"); + printf(" -m select map to use\n"); + printf(" The default map is 'icmap' which contains configuration information and some runtime variables used by corosync. \n"); + printf(" A 'stats' map is also available which displays network statistics - in great detail when knet is used as the transport.\n"); + printf("Set key:\n"); + printf(" corosync-cmapctl -s key_name type value\n"); + printf("\n"); + printf(" where type is one of ([i|u][8|16|32|64] | flt | dbl | str | bin)\n"); + printf(" for bin, value is file name (or - for stdin)\n"); + printf("\n"); + printf(" map can be either 'icmap' (the default) which contains corosync\n"); + printf(" configuration information, or 'stats' which contains statistics\n"); + printf(" about the networking and IPC traffic in some detail.\n"); + printf("\n"); + printf("Clear stats:\n"); + printf(" corosync-cmapctl -C [knet|ipc|totem|schedmiss|all]\n"); + printf(" The 'stats' map is implied\n"); + printf("\n"); + printf("Load settings from a file:\n"); + printf(" corosync-cmapctl -p filename\n"); + printf("\n"); + printf(" the format of the file is:\n"); + printf(" [^[^]]<key_name>[ <type> <value>]\n"); + printf(" Keys prefixed with single caret ('^') are deleted (see -d).\n"); + printf(" Keys (actually prefixes) prefixed with double caret ('^^') are deleted by prefix (see -D).\n"); + printf(" <type> and <value> are optional (not checked) in above cases.\n"); + printf(" Other keys are set (see -s) so both <type> and <value> are required.\n"); + printf("\n"); + printf("Delete key:\n"); + printf(" corosync-cmapctl -d key_name...\n"); + printf("\n"); + printf("Delete multiple keys with prefix:\n"); + printf(" corosync-cmapctl -D key_prefix...\n"); + printf("\n"); + printf("Get key:\n"); + printf(" corosync-cmapctl [-b] -g key_name...\n"); + printf("\n"); + printf("Quiet mode:\n"); + printf(" corosync-cmapctl [-b] -q -g key_name...\n"); + printf("\n"); + printf("Display all keys:\n"); + printf(" corosync-cmapctl [-b]\n"); + printf("\n"); + printf("Display keys with prefix key_name:\n"); + printf(" corosync-cmapctl [-b] key_name...\n"); + printf("\n"); + printf("Track changes on keys with key_name:\n"); + printf(" corosync-cmapctl [-b] -t key_name\n"); + printf("\n"); + printf("Track changes on keys with key prefix:\n"); + printf(" corosync-cmapctl [-b] -T key_prefix\n"); + printf("\n"); + + return (0); +} + +static void print_binary_key (char *value, size_t value_len) +{ + size_t i; + char c; + + for (i = 0; i < value_len; i++) { + c = value[i]; + if (c >= ' ' && c < 0x7f && c != '\\') { + fputc (c, stdout); + } else { + if (c == '\\') { + printf ("\\\\"); + } else { + printf ("\\x%02X", c); + } + } + } +} + +static void print_key(cmap_handle_t handle, + const char *key_name, + size_t value_len, + const void *value, + cmap_value_types_t type) +{ + char *str; + char *bin_value = NULL; + cs_error_t err; + int8_t i8; + uint8_t u8; + int16_t i16; + uint16_t u16; + int32_t i32; + uint32_t u32; + int64_t i64; + uint64_t u64; + float flt; + double dbl; + int end_loop; + int no_retries; + size_t bin_value_len; + + end_loop = 0; + no_retries = 0; + + err = CS_OK; + + while (!end_loop) { + switch (type) { + case CMAP_VALUETYPE_INT8: + if (value == NULL) { + err = cmap_get_int8(handle, key_name, &i8); + } else { + i8 = *((int8_t *)value); + } + break; + case CMAP_VALUETYPE_INT16: + if (value == NULL) { + err = cmap_get_int16(handle, key_name, &i16); + } else { + i16 = *((int16_t *)value); + } + break; + case CMAP_VALUETYPE_INT32: + if (value == NULL) { + err = cmap_get_int32(handle, key_name, &i32); + } else { + i32 = *((int32_t *)value); + } + break; + case CMAP_VALUETYPE_INT64: + if (value == NULL) { + err = cmap_get_int64(handle, key_name, &i64); + } else { + i64 = *((int64_t *)value); + } + break; + case CMAP_VALUETYPE_UINT8: + if (value == NULL) { + err = cmap_get_uint8(handle, key_name, &u8); + } else { + u8 = *((uint8_t *)value); + } + break; + case CMAP_VALUETYPE_UINT16: + if (value == NULL) { + err = cmap_get_uint16(handle, key_name, &u16); + } else { + u16 = *((uint16_t *)value); + } + break; + case CMAP_VALUETYPE_UINT32: + if (value == NULL) { + err = cmap_get_uint32(handle, key_name, &u32); + } else { + u32 = *((uint32_t *)value); + } + break; + case CMAP_VALUETYPE_UINT64: + if (value == NULL) { + err = cmap_get_uint64(handle, key_name, &u64); + } else { + u64 = *((uint64_t *)value); + } + break; + case CMAP_VALUETYPE_FLOAT: + if (value == NULL) { + err = cmap_get_float(handle, key_name, &flt); + } else { + flt = *((float *)value); + } + break; + case CMAP_VALUETYPE_DOUBLE: + if (value == NULL) { + err = cmap_get_double(handle, key_name, &dbl); + } else { + dbl = *((double *)value); + } + break; + case CMAP_VALUETYPE_STRING: + if (value == NULL) { + err = cmap_get_string(handle, key_name, &str); + } else { + str = (char *)value; + } + break; + case CMAP_VALUETYPE_BINARY: + if (show_binary) { + if (value == NULL) { + bin_value = malloc(value_len); + if (bin_value == NULL) { + fprintf(stderr, "Can't alloc memory\n"); + exit(EXIT_FAILURE); + } + bin_value_len = value_len; + err = cmap_get(handle, key_name, bin_value, &bin_value_len, NULL); + } else { + bin_value = (char *)value; + } + } + break; + } + + if (err == CS_OK) { + end_loop = 1; + } else if (err == CS_ERR_TRY_AGAIN) { + sleep(1); + no_retries++; + + if (no_retries > MAX_TRY_AGAIN) { + end_loop = 1; + } + } else { + end_loop = 1; + } + }; + + if (err != CS_OK) { + fprintf(stderr, "Can't get value of %s. Error %s\n", key_name, cs_strerror(err)); + + /* + * bin_value was newly allocated + */ + if (bin_value != NULL && value == NULL) { + free(bin_value); + } + return ; + } + + if (!quiet) + printf("%s (", key_name); + + switch (type) { + case CMAP_VALUETYPE_INT8: + if (!quiet) + printf("%s) = %"PRId8, "i8", i8); + else + printf("%"PRId8, i8); + break; + case CMAP_VALUETYPE_UINT8: + if (!quiet) + printf("%s) = %"PRIu8, "u8", u8); + else + printf("%"PRIu8, u8); + break; + case CMAP_VALUETYPE_INT16: + if (!quiet) + printf("%s) = %"PRId16, "i16", i16); + else + printf("%"PRId16, i16); + break; + case CMAP_VALUETYPE_UINT16: + if (!quiet) + printf("%s) = %"PRIu16, "u16", u16); + else + printf("%"PRIu16, u16); + break; + case CMAP_VALUETYPE_INT32: + if (!quiet) + printf("%s) = %"PRId32, "i32", i32); + else + printf("%"PRId32, i32); + break; + case CMAP_VALUETYPE_UINT32: + if (!quiet) + printf("%s) = %"PRIu32, "u32", u32); + else + printf("%"PRIu32, u32); + break; + case CMAP_VALUETYPE_INT64: + if (!quiet) + printf("%s) = %"PRId64, "i64", i64); + else + printf("%"PRId64, i64); + break; + case CMAP_VALUETYPE_UINT64: + if (!quiet) + printf("%s) = %"PRIu64, "u64", u64); + else + printf("%"PRIu64, u64); + break; + case CMAP_VALUETYPE_FLOAT: + if (!quiet) + printf("%s) = %f", "flt", flt); + else + printf("%f", flt); + break; + case CMAP_VALUETYPE_DOUBLE: + if (!quiet) + printf("%s) = %lf", "dbl", dbl); + else + printf("%lf", dbl); + break; + case CMAP_VALUETYPE_STRING: + if (!quiet) + printf("%s) = %s", "str", str); + else + printf("%s", str); + if (value == NULL) { + free(str); + } + break; + case CMAP_VALUETYPE_BINARY: + printf("%s)", "bin"); + if (show_binary) { + printf(" = "); + if (bin_value) { + print_binary_key(bin_value, value_len); + if (value == NULL) { + free(bin_value); + } + } else { + printf("*empty*"); + } + } + break; + } + + printf("\n"); +} + +static int print_iter(cmap_handle_t handle, const char *prefix) +{ + cmap_iter_handle_t iter_handle; + char key_name[CMAP_KEYNAME_MAXLEN + 1]; + size_t value_len; + cmap_value_types_t type; + cs_error_t err; + int no_result = 1; + + err = cmap_iter_init(handle, prefix, &iter_handle); + if (err != CS_OK) { + fprintf (stderr, "Failed to initialize iteration. Error %s\n", cs_strerror(err)); + exit (EXIT_FAILURE); + } + + while ((err = cmap_iter_next(handle, iter_handle, key_name, &value_len, &type)) == CS_OK) { + no_result = 0; + print_key(handle, key_name, value_len, NULL, type); + } + + cmap_iter_finalize(handle, iter_handle); + return no_result; +} + +static void delete_with_prefix(cmap_handle_t handle, const char *prefix) +{ + cmap_iter_handle_t iter_handle; + char key_name[CMAP_KEYNAME_MAXLEN + 1]; + size_t value_len; + cmap_value_types_t type; + cs_error_t err; + cs_error_t err2; + + err = cmap_iter_init(handle, prefix, &iter_handle); + if (err != CS_OK) { + fprintf (stderr, "Failed to initialize iteration. Error %s\n", cs_strerror(err)); + exit (EXIT_FAILURE); + } + + while ((err = cmap_iter_next(handle, iter_handle, key_name, &value_len, &type)) == CS_OK) { + err2 = cmap_delete(handle, key_name); + if (err2 != CS_OK) { + fprintf(stderr, "Can't delete key %s. Error %s\n", key_name, cs_strerror(err2)); + } + } + cmap_iter_finalize(handle, iter_handle); +} + +static void cmap_notify_fn( + cmap_handle_t cmap_handle, + cmap_track_handle_t cmap_track_handle, + int32_t event, + const char *key_name, + struct cmap_notify_value new_val, + struct cmap_notify_value old_val, + void *user_data) +{ + switch (event) { + case CMAP_TRACK_ADD: + printf("create> "); + print_key(cmap_handle, key_name, new_val.len, new_val.data, new_val.type); + break; + case CMAP_TRACK_DELETE: + printf("delete> "); + print_key(cmap_handle, key_name, old_val.len, old_val.data, old_val.type); + break; + case CMAP_TRACK_MODIFY: + printf("modify> "); + print_key(cmap_handle, key_name, new_val.len, new_val.data, new_val.type); + break; + default: + printf("unknown change> "); + break; + } + +} + +static void add_track(cmap_handle_t handle, const char *key_name, int prefix) +{ + cmap_track_handle_t track_handle; + int32_t track_type; + cs_error_t err; + + track_type = CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_MODIFY; + if (prefix) { + track_type |= CMAP_TRACK_PREFIX; + } + + err = cmap_track_add(handle, key_name, track_type, cmap_notify_fn, NULL, &track_handle); + if (err != CS_OK) { + fprintf(stderr, "Failed to add tracking function. Error %s\n", cs_strerror(err)); + exit (EXIT_FAILURE); + } +} + +static void track_changes(cmap_handle_t handle) +{ + struct pollfd pfd[2]; + int cmap_fd; + cs_error_t err; + int poll_res; + char inbuf[3]; + int quit = CS_FALSE; + + err = cmap_fd_get(handle, &cmap_fd); + if (err != CS_OK) { + fprintf(stderr, "Failed to get file handle. Error %s\n", cs_strerror(err)); + exit (EXIT_FAILURE); + } + + pfd[0].fd = cmap_fd; + pfd[1].fd = STDIN_FILENO; + pfd[0].events = pfd[1].events = POLLIN; + + printf("Type \"q\" to finish\n"); + do { + pfd[0].revents = pfd[1].revents = 0; + poll_res = poll(pfd, 2, INFTIM); + if (poll_res == -1) { + perror("poll"); + } + + if (pfd[1].revents & POLLIN) { + if (fgets(inbuf, sizeof(inbuf), stdin) == NULL) { + quit = CS_TRUE; + } else if (strncmp(inbuf, "q", 1) == 0) { + quit = CS_TRUE; + } + } + + if (pfd[0].revents & POLLIN) { + err = cmap_dispatch(handle, CS_DISPATCH_ALL); + if (err != CS_OK) { + fprintf(stderr, "Dispatch error %s\n", cs_strerror(err)); + quit = CS_TRUE; + } + } + } while (poll_res > 0 && !quit); +} + +static cs_error_t set_key_bin(cmap_handle_t handle, const char *key_name, const char *fname) +{ + FILE *f; + char *val; + char buf[4096]; + size_t size; + size_t readed; + size_t pos; + cs_error_t err; + + if (strcmp(fname, "-") == 0) { + f = stdin; + } else { + f = fopen(fname, "rb"); + if (f == NULL) { + perror("Can't open input file"); + exit(EXIT_FAILURE); + } + } + + val = NULL; + size = 0; + pos = 0; + + while ((readed = fread(buf, 1, sizeof(buf), f)) != 0) { + size += readed; + if ((val = realloc(val, size)) == NULL) { + fprintf(stderr, "Can't alloc memory\n"); + exit (EXIT_FAILURE); + } + memcpy(val + pos, buf, readed); + pos += readed; + } + + if (f != stdin) { + fclose(f); + } + + err = cmap_set(handle, key_name, val, size, CMAP_VALUETYPE_BINARY); + free(val); + + return (err); +} + +static void set_key(cmap_handle_t handle, const char *key_name, const char *key_type_s, const char *key_value_s) +{ + int64_t i64; + uint64_t u64; + double dbl; + float flt; + cs_error_t err = CS_OK; + int scanf_res = 0; + + cmap_value_types_t type; + + if (convert_name_to_type(key_type_s) == -1) { + fprintf(stderr, "Unknown type %s\n", key_type_s); + exit (EXIT_FAILURE); + } + + type = convert_name_to_type(key_type_s); + + switch (type) { + case CMAP_VALUETYPE_INT8: + case CMAP_VALUETYPE_INT16: + case CMAP_VALUETYPE_INT32: + case CMAP_VALUETYPE_INT64: + scanf_res = sscanf(key_value_s, "%"PRId64, &i64); + break; + case CMAP_VALUETYPE_UINT8: + case CMAP_VALUETYPE_UINT16: + case CMAP_VALUETYPE_UINT32: + case CMAP_VALUETYPE_UINT64: + scanf_res = sscanf(key_value_s, "%"PRIu64, &u64); + break; + case CMAP_VALUETYPE_FLOAT: + scanf_res = sscanf(key_value_s, "%f", &flt); + break; + case CMAP_VALUETYPE_DOUBLE: + scanf_res = sscanf(key_value_s, "%lf", &dbl); + break; + case CMAP_VALUETYPE_STRING: + case CMAP_VALUETYPE_BINARY: + /* + * Do nothing + */ + scanf_res = 1; + break; + } + + if (scanf_res != 1) { + fprintf(stderr, "%s is not valid %s type value\n", key_value_s, key_type_s); + exit(EXIT_FAILURE); + } + /* + * We have parsed value, so insert value + */ + + switch (type) { + case CMAP_VALUETYPE_INT8: + if (i64 > INT8_MAX || i64 < INT8_MIN) { + fprintf(stderr, "%s is not valid i8 integer\n", key_value_s); + exit(EXIT_FAILURE); + } + err = cmap_set_int8(handle, key_name, i64); + break; + case CMAP_VALUETYPE_INT16: + if (i64 > INT16_MAX || i64 < INT16_MIN) { + fprintf(stderr, "%s is not valid i16 integer\n", key_value_s); + exit(EXIT_FAILURE); + } + err = cmap_set_int16(handle, key_name, i64); + break; + case CMAP_VALUETYPE_INT32: + if (i64 > INT32_MAX || i64 < INT32_MIN) { + fprintf(stderr, "%s is not valid i32 integer\n", key_value_s); + exit(EXIT_FAILURE); + } + err = cmap_set_int32(handle, key_name, i64); + break; + case CMAP_VALUETYPE_INT64: + err = cmap_set_int64(handle, key_name, i64); + break; + + case CMAP_VALUETYPE_UINT8: + if (u64 > UINT8_MAX) { + fprintf(stderr, "%s is not valid u8 integer\n", key_value_s); + exit(EXIT_FAILURE); + } + err = cmap_set_uint8(handle, key_name, u64); + break; + case CMAP_VALUETYPE_UINT16: + if (u64 > UINT16_MAX) { + fprintf(stderr, "%s is not valid u16 integer\n", key_value_s); + exit(EXIT_FAILURE); + } + err = cmap_set_uint16(handle, key_name, u64); + break; + case CMAP_VALUETYPE_UINT32: + if (u64 > UINT32_MAX) { + fprintf(stderr, "%s is not valid u32 integer\n", key_value_s); + exit(EXIT_FAILURE); + } + err = cmap_set_uint32(handle, key_name, u64); + break; + case CMAP_VALUETYPE_UINT64: + err = cmap_set_uint64(handle, key_name, u64); + break; + case CMAP_VALUETYPE_FLOAT: + err = cmap_set_float(handle, key_name, flt); + break; + case CMAP_VALUETYPE_DOUBLE: + err = cmap_set_double(handle, key_name, dbl); + break; + case CMAP_VALUETYPE_STRING: + err = cmap_set_string(handle, key_name, key_value_s); + break; + case CMAP_VALUETYPE_BINARY: + err = set_key_bin(handle, key_name, key_value_s); + break; + } + + if (err != CS_OK) { + fprintf (stderr, "Failed to set key %s. Error %s\n", key_name, cs_strerror(err)); + exit (EXIT_FAILURE); + } +} + + +static void read_in_config_file(cmap_handle_t handle, char * filename) +{ + int ignore; + int c; + FILE* fh; + char buf[1024]; + char * line; + char *key_name; + char *key_type_s; + char *key_value_s; + + fh = fopen(filename, "r"); + if (fh == NULL) { + perror ("Couldn't open file."); + return; + } + + while (fgets (buf, 1024, fh) != NULL) { + /* find the first real character, if it is + * a '#' then ignore this line. + * else process. + * if no real characters then also ignore. + */ + ignore = 1; + for (c = 0; c < 1024; c++) { + if (isblank (buf[c])) { + continue; + } + + if (buf[c] == '#' || buf[c] == '\n') { + ignore = 1; + break; + } + ignore = 0; + line = &buf[c]; + break; + } + if (ignore == 1) { + continue; + } + + /* + * should be: + * [^[^]]<key>[ <type> <value>] + */ + key_name = strtok(line, " \n"); + if (key_name && *key_name == '^') { + key_name++; + if (*key_name == '^') { + key_name++; + delete_with_prefix(handle, key_name); + } else { + cs_error_t err; + + err = cmap_delete(handle, key_name); + if (err != CS_OK) { + fprintf(stderr, "Can't delete key %s. Error %s\n", key_name, cs_strerror(err)); + } + } + } else { + key_type_s = strtok(NULL, " \n"); + key_value_s = strtok(NULL, " \n"); + if (key_type_s == NULL || key_value_s == NULL) { + fprintf(stderr, "Both type and value for key %s are required\n", key_name); + exit (EXIT_FAILURE); + } + set_key(handle, key_name, key_type_s, key_value_s); + } + } + + fclose (fh); +} + +static void clear_stats(cmap_handle_t handle, char *clear_opt) +{ + char key_name[CMAP_KEYNAME_MAXLEN + 1]; + + sprintf(key_name, "stats.clear.%s", clear_opt); + cmap_set_uint32(handle, key_name, 1); +} + +int main(int argc, char *argv[]) +{ + enum user_action action; + int c; + cs_error_t err; + cmap_handle_t handle; + int i; + size_t value_len; + cmap_value_types_t type; + cmap_map_t map = CMAP_MAP_DEFAULT; + int track_prefix; + int map_set = 0; + int no_retries; + char * clear_opt = NULL; + char * settings_file = NULL; + int count_of_no_result = 0; + + action = ACTION_PRINT_PREFIX; + track_prefix = 1; + + while ((c = getopt(argc, argv, "m:hqgsdDtTbp:C:")) != -1) { + switch (c) { + case 'h': + return print_help(); + break; + case 'b': + show_binary++; + break; + case 'q': + quiet = 1; + break; + case 'g': + action = ACTION_GET; + break; + case 's': + action = ACTION_SET; + break; + case 'd': + action = ACTION_DELETE; + break; + case 'D': + action = ACTION_DELETE_PREFIX; + break; + case 'p': + settings_file = optarg; + action = ACTION_LOAD; + break; + case 'C': + if (strcmp(optarg, "knet") == 0 || + strcmp(optarg, "totem") == 0 || + strcmp(optarg, "ipc") == 0 || + strcmp(optarg, "schedmiss") == 0 || + strcmp(optarg, "all") == 0) { + action = ACTION_CLEARSTATS; + clear_opt = optarg; + + /* Force the map to be STATS */ + map = CMAP_MAP_STATS; + } + else { + fprintf(stderr, "argument to -C should be 'knet', 'totem', 'ipc', 'schedmiss' or 'all'\n"); + return (EXIT_FAILURE); + } + break; + case 't': + action = ACTION_TRACK; + track_prefix = 0; + break; + case 'T': + action = ACTION_TRACK; + break; + case 'm': + if (strcmp(optarg, "icmap") == 0 || + strcmp(optarg, "default") == 0) { + map = CMAP_MAP_ICMAP; + map_set = 1; + } + if (strcmp(optarg, "stats") == 0) { + map = CMAP_MAP_STATS; + map_set = 1; + } + if (!map_set) { + fprintf(stderr, "invalid map name, must be 'default', 'icmap' or 'stats'\n"); + return (EXIT_FAILURE); + } + break; + case '?': + return (EXIT_FAILURE); + break; + default: + action = ACTION_PRINT_PREFIX; + break; + } + } + + argc -= optind; + argv += optind; + + if (argc == 0 && + action != ACTION_LOAD && + action != ACTION_CLEARSTATS && + action != ACTION_PRINT_PREFIX) { + fprintf(stderr, "Expected key after options\n"); + return (EXIT_FAILURE); + } + + no_retries = 0; + + while ((err = cmap_initialize_map(&handle, map)) == CS_ERR_TRY_AGAIN && no_retries++ < MAX_TRY_AGAIN) { + sleep(1); + } + + if (err != CS_OK) { + fprintf (stderr, "Failed to initialize the cmap API. Error %s\n", cs_strerror(err)); + exit (EXIT_FAILURE); + } + + switch (action) { + case ACTION_PRINT_PREFIX: + if (argc == 0) { + count_of_no_result = print_iter(handle, NULL); + } else { + for (i = 0; i < argc; i++) { + count_of_no_result += print_iter(handle, argv[i]); + } + } + + if (count_of_no_result > 0 && count_of_no_result >= argc) { + return (EXIT_FAILURE); + } + break; + case ACTION_GET: + for (i = 0; i < argc; i++) { + err = cmap_get(handle, argv[i], NULL, &value_len, &type); + if (err == CS_OK) { + print_key(handle, argv[i], value_len, NULL, type); + } else { + fprintf(stderr, "Can't get key %s. Error %s\n", argv[i], cs_strerror(err)); + return (EXIT_FAILURE); + } + } + break; + case ACTION_DELETE: + for (i = 0; i < argc; i++) { + err = cmap_delete(handle, argv[i]); + if (err != CS_OK) { + fprintf(stderr, "Can't delete key %s. Error %s\n", argv[i], cs_strerror(err)); + return (EXIT_FAILURE); + } + } + break; + case ACTION_DELETE_PREFIX: + for (i = 0; i < argc; i++) { + delete_with_prefix(handle, argv[i]); + } + break; + case ACTION_LOAD: + read_in_config_file(handle, settings_file); + break; + case ACTION_TRACK: + for (i = 0; i < argc; i++) { + add_track(handle, argv[i], track_prefix); + } + track_changes(handle); + break; + case ACTION_SET: + if (argc < 3) { + fprintf(stderr, "At least 3 parameters are expected for set\n"); + return (EXIT_FAILURE); + } + + set_key(handle, argv[0], argv[1], argv[2]); + break; + case ACTION_CLEARSTATS: + clear_stats(handle, clear_opt); + break; + + } + + err = cmap_finalize(handle); + if (err != CS_OK) { + fprintf (stderr, "Failed to finalize the cmap API. Error %s\n", cs_strerror(err)); + exit (EXIT_FAILURE); + } + + return (0); +} diff --git a/tools/corosync-cpgtool.c b/tools/corosync-cpgtool.c new file mode 100644 index 0000000..b52a35b --- /dev/null +++ b/tools/corosync-cpgtool.c @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2009-2011 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Jan Friesse <jfriesse@redhat.com> + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the MontaVista Software, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <unistd.h> +#include <string.h> +#include <pthread.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/select.h> +#include <sys/un.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <libgen.h> + +#include <corosync/corotypes.h> +#include <corosync/totem/totem.h> +#include <corosync/cfg.h> +#include <corosync/cpg.h> + +static corosync_cfg_handle_t cfg_handle; +static cpg_handle_t cpg_handle; + +typedef enum { + OPER_NAMES_ONLY = 1, + OPER_FULL_OUTPUT = 2, +} operation_t; + +static void fprint_addrs(FILE *f, unsigned int nodeid) +{ + int numaddrs; + int i; + corosync_cfg_node_address_t addrs[INTERFACE_MAX]; + + if (corosync_cfg_get_node_addrs(cfg_handle, nodeid, INTERFACE_MAX, &numaddrs, addrs) == CS_OK) { + for (i=0; i<numaddrs; i++) { + char buf[INET6_ADDRSTRLEN]; + struct sockaddr_storage *ss = (struct sockaddr_storage *)addrs[i].address; + struct sockaddr_in *sin = (struct sockaddr_in *)addrs[i].address; + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addrs[i].address; + void *saddr; + + if (!ss->ss_family) { + continue; + } + + if (ss->ss_family == AF_INET6) { + saddr = &sin6->sin6_addr; + } else { + saddr = &sin->sin_addr; + } + + inet_ntop(ss->ss_family, saddr, buf, sizeof(buf)); + if (i != 0) { + fprintf(f, " "); + } + fprintf(f, "%s", buf); + } + } +} + +static void fprint_group (FILE *f, int escape, const struct cpg_name *group) { + int i; + char c; + + for (i = 0; i < group->length; i++) { + c = group->value[i]; + + if (!escape || (c >= ' ' && c < 0x7f && c != '\\')) { + fputc (c, f); + } else { + if (c == '\\') + fprintf (f, "\\\\"); + else + fprintf (f, "\\x%02X", c); + } + } +} + +static int display_groups (char delimiter, int escape) +{ + cs_error_t res; + cpg_iteration_handle_t iter_handle; + struct cpg_iteration_description_t description; + + res = cpg_iteration_initialize (cpg_handle, CPG_ITERATION_NAME_ONLY, NULL, &iter_handle); + if (res != CS_OK) { + fprintf (stderr, "Cannot initialize cpg iterator error %d\n", res); + + return 0; + } + + while ((res = cpg_iteration_next (iter_handle, &description)) == CS_OK) { + fprint_group (stdout, escape, &description.group); + fputc ((delimiter ? delimiter : '\n'), stdout); + } + + if (delimiter) + putc ('\n', stdout); + + cpg_iteration_finalize (iter_handle); + + return 1; +} + +static inline int group_name_compare ( + const struct cpg_name *g1, + const struct cpg_name *g2) +{ + return (g1->length == g2->length? + memcmp (g1->value, g2->value, g1->length): + g1->length - g2->length); +} + +static int display_groups_with_members (char delimiter, int escape) { + cs_error_t res; + cpg_iteration_handle_t iter_handle; + struct cpg_iteration_description_t description; + struct cpg_name old_group; + + res = cpg_iteration_initialize (cpg_handle, CPG_ITERATION_ALL, NULL, &iter_handle); + if (res != CS_OK) { + fprintf (stderr, "Cannot initialize cpg iterator error %d\n", res); + + return 0; + } + + memset (&old_group, 0, sizeof (struct cpg_name)); + + if (delimiter) { + fprintf (stdout, "GRP_NAME%cPID%cNODEID\n", delimiter, delimiter); + } else { + fprintf (stdout, "Group Name\t%10s\t%10s\n", "PID", "Node ID"); + } + + while ((res = cpg_iteration_next (iter_handle, &description)) == CS_OK) { + if (!delimiter && group_name_compare (&old_group, &description.group) != 0) { + fprint_group (stdout, escape, &description.group); + fprintf (stdout, "\n"); + + memcpy (&old_group, &description.group, sizeof (struct cpg_name)); + } + + if (!delimiter) { + fprintf (stdout, "\t\t%10u\t%10u (", description.pid, description.nodeid); + fprint_addrs (stdout, description.nodeid); + fprintf (stdout, ")\n"); + } else { + fprint_group (stdout, escape, &description.group); + fprintf (stdout, "%c%u%c%u\n", delimiter, description.pid, delimiter, description.nodeid); + } + } + + if (res != CS_ERR_NO_SECTIONS) { + fprintf (stderr, "cpg iteration error %d\n", res); + + return 0; + } + + cpg_iteration_finalize (iter_handle); + + return 1; +} + +static void usage_do (const char *prog_name) +{ + printf ("%s [-d delimiter] [-e] [-n] [-h]\n\n", prog_name); + printf ("A tool for displaying cpg groups and members.\n"); + printf ("options:\n"); + printf ("\t-d\tDelimiter between fields.\n"); + printf ("\t-e\tDon't escape unprintable characters in group name.\n"); + printf ("\t-n\tDisplay only all existing group names.\n"); + printf ("\t-h\tDisplay this help.\n"); +} + + +int main (int argc, char *argv[]) { + const char *options = "hd:ne"; + int opt; + const char *prog_name = basename(argv[0]); + char delimiter = 0; + int escape = 1; + operation_t operation = OPER_FULL_OUTPUT; + int result; + + while ( (opt = getopt(argc, argv, options)) != -1 ) { + switch (opt) { + case 'd': + if (strlen (optarg) > 0) { + delimiter = optarg[0]; + } + break; + + case 'n': + operation = OPER_NAMES_ONLY; + break; + + case 'e': + escape = 0; + break; + + case 'h': + usage_do (prog_name); + return (EXIT_SUCCESS); + break; + + case '?': + case ':': + return (EXIT_FAILURE); + break; + } + } + + result = cpg_initialize (&cpg_handle, NULL); + + if (result != CS_OK) { + fprintf (stderr, "Could not initialize corosync cpg API error %d\n", result); + return (EXIT_FAILURE); + } + + result = corosync_cfg_initialize (&cfg_handle, NULL); + if (result != CS_OK) { + fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result); + return (EXIT_FAILURE); + } + + switch (operation) { + case OPER_NAMES_ONLY: + result = display_groups (delimiter, escape); + break; + + case OPER_FULL_OUTPUT: + result = display_groups_with_members (delimiter, escape); + break; + } + + cpg_finalize (cpg_handle); + corosync_cfg_finalize (cfg_handle); + + return (result ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/tools/corosync-keygen.c b/tools/corosync-keygen.c new file mode 100644 index 0000000..243661a --- /dev/null +++ b/tools/corosync-keygen.c @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2004 MontaVista Software, Inc. + * Copyright (c) 2005-2019 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Steven Dake (sdake@redhat.com) + * Jan Friesse (jfriesse@redhat.com) + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the MontaVista Software, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <config.h> + +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <getopt.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include <netinet/in.h> + +#include <corosync/totem/totem.h> + +#define DEFAULT_KEYFILE COROSYSCONFDIR "/authkey" + +#define DEFAULT_KEYFILE_LEN 256 + +#define DEFAULT_RANDOM_DEV "/dev/urandom" + +static const char usage[] = + "Usage: corosync-keygen [-k <keyfile>] [-s size] [-m <randomfile>] [-l] [-h]\n" + " -k / --key-file=<filename> - Write to the specified keyfile\n" + " instead of the default " DEFAULT_KEYFILE ".\n" + " -r / --random-file - Random number source file. Default is \n" + " /dev/urandom. As an example /dev/random may be requested\n" + " (that may require user input for entropy).\n" + " -l / --less-secure - Not used, option is kept only\n" + " for compatibility.\n" + " -s / --size - Length of key.\n" + " -h / --help - Print basic usage.\n"; + + +int main (int argc, char *argv[]) +{ + int authkey_fd; + int random_fd; + char *keyfile = NULL; + unsigned char key[TOTEM_PRIVATE_KEY_LEN_MAX]; + ssize_t res; + ssize_t bytes_read; + size_t key_len = DEFAULT_KEYFILE_LEN; + const char *random_dev = DEFAULT_RANDOM_DEV; + long long int tmpll; + char *ep; + int c; + int option_index; + static struct option long_options[] = { + { "key-file", required_argument, NULL, 'k' }, + { "less-secure", no_argument, NULL, 'l' }, + { "random-file", required_argument, NULL, 'r' }, + { "size", required_argument, NULL, 's' }, + { "help", no_argument, NULL, 'h' }, + { 0, 0, NULL, 0 }, + }; + + while ((c = getopt_long (argc, argv, "k:r:s:lh", + long_options, &option_index)) != -1) { + switch (c) { + case 'k': + keyfile = optarg; + break; + case 'l': + /* + * Only kept for compatibility + */ + break; + case 'r': + random_dev = optarg; + break; + case 's': + tmpll = strtoll(optarg, &ep, 10); + if (tmpll < TOTEM_PRIVATE_KEY_LEN_MIN || + tmpll > TOTEM_PRIVATE_KEY_LEN_MAX || + errno != 0 || *ep != '\0') { + errx (1, "Unsupported key size (supported <%u,%u>)\n", + TOTEM_PRIVATE_KEY_LEN_MIN, + TOTEM_PRIVATE_KEY_LEN_MAX); + } + + key_len = (size_t)tmpll; + break; + case 'h': + printf ("%s\n", usage); + exit(0); + break; + default: + printf ("Error parsing command line options.\n"); + exit (1); + } + } + + printf ("Corosync Cluster Engine Authentication key generator.\n"); + + if (!keyfile) { + keyfile = (char *)DEFAULT_KEYFILE; + } + + printf ("Gathering %lu bits for key from %s.\n", (unsigned long)(key_len * 8), random_dev); + random_fd = open (random_dev, O_RDONLY); + + if (random_fd == -1) { + err (1, "Failed to open random source"); + } + + if (strcmp(random_dev, "/dev/random") == 0) { + printf ("Press keys on your keyboard to generate entropy.\n"); + } + /* + * Read random data + */ + bytes_read = 0; + +retry_read: + res = read (random_fd, &key[bytes_read], key_len - bytes_read); + if (res == -1) { + err (1, "Could not read /dev/random"); + } + bytes_read += res; + if (bytes_read != key_len) { + printf ("Press keys on your keyboard to generate entropy (%d bits still needed).\n", + (int)((key_len - bytes_read) * 8)); + goto retry_read; + } + close (random_fd); + + /* + * Open key + */ + authkey_fd = open (keyfile, O_CREAT|O_WRONLY|O_TRUNC, 0600); + if (authkey_fd == -1) { + err (2, "Could not create %s", keyfile); + } + if (fchmod (authkey_fd, 0400)) { + err (3, "Failed to set key file permissions to 0400"); + } + + printf ("Writing corosync key to %s.\n", keyfile); + + /* + * Write key + */ + res = write (authkey_fd, key, key_len); + if (res != key_len) { + err (4, "Could not write %s", keyfile); + } + + if (close (authkey_fd)) { + err (5, "Could not close %s", keyfile); + } + + return (0); +} diff --git a/tools/corosync-notifyd.c b/tools/corosync-notifyd.c new file mode 100644 index 0000000..93414f6 --- /dev/null +++ b/tools/corosync-notifyd.c @@ -0,0 +1,1420 @@ +/* + * Copyright (c) 2011-2017 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Angus Salkeld <asalkeld@redhat.com> + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the MontaVista Software, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <config.h> + +#include <sys/select.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/types.h> +#include <netdb.h> +#include <arpa/inet.h> + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <unistd.h> +#include <string.h> +#include <ctype.h> +#include <poll.h> +#include <signal.h> + +#include <qb/qbdefs.h> +#include <qb/qbloop.h> +#include <qb/qbmap.h> +#include <qb/qblog.h> + +#include <corosync/corotypes.h> +#include <corosync/cfg.h> +#include <corosync/quorum.h> +#include <corosync/cmap.h> + +#ifdef HAVE_LIBSYSTEMD +#include <systemd/sd-daemon.h> +#endif + +/* + * generic declarations + */ +enum { + CS_NTF_LOG, + CS_NTF_STDOUT, + CS_NTF_SNMP, + CS_NTF_DBUS, + CS_NTF_FG, + CS_NTF_NODNS, + CS_NTF_MAX, +}; +static int conf[CS_NTF_MAX]; + +static int exit_code = 0; + +static int32_t _cs_is_quorate = 0; + +typedef void (*node_membership_fn_t)(char *nodename, uint32_t nodeid, char *state, char* ip); +typedef void (*node_quorum_fn_t)(char *nodename, uint32_t nodeid, const char *state); +typedef void (*application_connection_fn_t)(char *nodename, uint32_t nodeid, char *app_name, const char *state); +typedef void (*link_faulty_fn_t)(char *nodename, uint32_t local_nodeid, uint32_t nodeid, uint32_t iface_no, const char *state); + +struct notify_callbacks { + node_membership_fn_t node_membership_fn; + node_quorum_fn_t node_quorum_fn; + application_connection_fn_t application_connection_fn; + link_faulty_fn_t link_faulty_fn; +}; + +struct track_item { + char key_name[CMAP_KEYNAME_MAXLEN + 1]; + cmap_track_handle_t track_handle; +}; + +#define MAX_NOTIFIERS 5 +static int num_notifiers = 0; +static struct notify_callbacks notifiers[MAX_NOTIFIERS]; +/* + * Global variable with local nodeid + */ +static uint32_t g_local_nodeid = 0; +static char local_nodename[CS_MAX_NAME_LENGTH]; +static qb_loop_t *main_loop; +static quorum_handle_t quorum_handle; +static qb_map_t *tracker_map; + +static void _cs_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip); +static void _cs_node_quorum_event(const char *state); +static void _cs_application_connection_event(char *app_name, const char *state); +static void _cs_link_faulty_event(uint32_t nodeid, uint32_t iface_no, const char *state); + +#ifdef HAVE_DBUS +#include <dbus/dbus.h> +/* + * dbus + */ +#define DBUS_CS_NAME "org.corosync" +#define DBUS_CS_IFACE "org.corosync" +#define DBUS_CS_PATH "/org/corosync" + +static DBusConnection *db = NULL; +static char _err[512]; +static int err_set = 0; +static void _cs_dbus_init(void); +#endif /* HAVE_DBUS */ + +#ifdef ENABLE_SNMP +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/snmpv3_api.h> +#include <net-snmp/agent/agent_trap.h> +#include <net-snmp/library/mib.h> +#include <net-snmp/library/snmp_api.h> +#include <net-snmp/library/snmp_client.h> +#include <net-snmp/library/snmp_debug.h> + +enum snmp_node_status { + SNMP_NODE_STATUS_UNKNOWN = 0, + SNMP_NODE_STATUS_JOINED = 1, + SNMP_NODE_STATUS_LEFT = 2 +}; + +#define SNMP_OID_COROSYNC "1.3.6.1.4.1.35488" +#define SNMP_OID_OBJECT_ROOT SNMP_OID_COROSYNC ".1" +#define SNMP_OID_OBJECT_NODE_NAME SNMP_OID_OBJECT_ROOT ".1" +#define SNMP_OID_OBJECT_NODE_ID SNMP_OID_OBJECT_ROOT ".2" +#define SNMP_OID_OBJECT_NODE_STATUS SNMP_OID_OBJECT_ROOT ".3" +#define SNMP_OID_OBJECT_NODE_ADDR SNMP_OID_OBJECT_ROOT ".4" +#define SNMP_OID_OBJECT_LOCAL_NODE_ID SNMP_OID_OBJECT_ROOT ".5" + +#define SNMP_OID_OBJECT_RINGSEQ SNMP_OID_OBJECT_ROOT ".20" +#define SNMP_OID_OBJECT_QUORUM SNMP_OID_OBJECT_ROOT ".21" + +#define SNMP_OID_OBJECT_APP_NAME SNMP_OID_OBJECT_ROOT ".40" +#define SNMP_OID_OBJECT_APP_STATUS SNMP_OID_OBJECT_ROOT ".41" + +#define SNMP_OID_OBJECT_LINK_IFACE_NO SNMP_OID_OBJECT_ROOT ".60" +#define SNMP_OID_OBJECT_LINK_STATUS SNMP_OID_OBJECT_ROOT ".61" + +#define SNMP_OID_TRAPS_ROOT SNMP_OID_COROSYNC ".0" +#define SNMP_OID_TRAPS_NODE SNMP_OID_TRAPS_ROOT ".1" +#define SNMP_OID_TRAPS_QUORUM SNMP_OID_TRAPS_ROOT ".2" +#define SNMP_OID_TRAPS_APP SNMP_OID_TRAPS_ROOT ".3" +#define SNMP_OID_TRAPS_LINK SNMP_OID_TRAPS_ROOT ".4" + +#define CS_TIMESTAMP_STR_LEN 20 +static const char *local_host = "localhost"; +#endif /* ENABLE_SNMP */ +static char snmp_manager_buf[CS_MAX_NAME_LENGTH]; +static char *snmp_manager = NULL; +static char snmp_community_buf[CS_MAX_NAME_LENGTH]; +static char *snmp_community = NULL; + +#define CMAP_MAX_RETRIES 10 + +/* + * cmap + */ +static cmap_handle_t cmap_handle; +static cmap_handle_t stats_handle; +static cmap_track_handle_t cmap_track_handle_runtime_members_key_changed; +static cmap_track_handle_t cmap_track_handle_stats_ipcs_key_changed; +static cmap_track_handle_t cmap_track_handle_stats_knet_key_changed; + +static int32_t _cs_ip_to_hostname(char* ip, char* name_out) +{ + struct sockaddr_in sa; + int rc; + + if (strchr(ip, ':') == NULL) { + sa.sin_family = AF_INET; + } else { + sa.sin_family = AF_INET6; + } + + rc = inet_pton(sa.sin_family, ip, &sa.sin_addr); + if (rc == 0) { + return -EINVAL; + } + + rc = getnameinfo((struct sockaddr*)&sa, sizeof(sa), + name_out, CS_MAX_NAME_LENGTH, NULL, 0, 0); + if (rc != 0) { + qb_log(LOG_ERR, "error looking up %s : %s", ip, gai_strerror(rc)); + return -EINVAL; + } + return 0; +} + +static void _cs_cmap_members_key_changed ( + cmap_handle_t cmap_handle_c, + cmap_track_handle_t cmap_track_handle, + int32_t event, + const char *key_name, + struct cmap_notify_value new_value, + struct cmap_notify_value old_value, + void *user_data) +{ + char nodename[CS_MAX_NAME_LENGTH]; + char* open_bracket = NULL; + char* close_bracket = NULL; + int res; + uint32_t nodeid; + char *ip_str; + char tmp_key[CMAP_KEYNAME_MAXLEN]; + cs_error_t err; + int no_retries; + + if (event != CMAP_TRACK_ADD && event != CMAP_TRACK_MODIFY) { + return ; + } + + if (NULL == key_name) { + qb_log(LOG_ERR, "key_name: nil"); + return ; + } + + res = sscanf(key_name, "runtime.members.%u.%s", &nodeid, tmp_key); + if (res != 2) + return ; + + if (strcmp(tmp_key, "status") != 0) { + return ; + } + + res = snprintf(tmp_key, CMAP_KEYNAME_MAXLEN, "runtime.members.%u.ip", nodeid); + if (res <= 0 || res >= CMAP_KEYNAME_MAXLEN) { + qb_log(LOG_ERR, "temp_key: failed, res: %d, nodeid: " CS_PRI_NODE_ID, res, nodeid); + return ; + } + no_retries = 0; + while ((err = cmap_get_string(cmap_handle, tmp_key, &ip_str)) == CS_ERR_TRY_AGAIN && + no_retries++ < CMAP_MAX_RETRIES) { + sleep(1); + } + + if (err != CS_OK) { + return ; + } + /* + * We want the ip out of: "r(0) ip(192.168.100.92)" + */ + open_bracket = strrchr(ip_str, '('); + if (NULL == open_bracket) { + qb_log(LOG_ERR, "ip_str: %s", ip_str); + free(ip_str); + return ; + } + open_bracket++; + close_bracket = strchr(open_bracket, ')'); + if (NULL == close_bracket) { + qb_log(LOG_ERR, "open_bracket: %s", open_bracket); + free(ip_str); + return ; + } + *close_bracket = '\0'; + if(conf[CS_NTF_NODNS]) { + strncpy(nodename, open_bracket, CS_MAX_NAME_LENGTH-1); + } else { + res = _cs_ip_to_hostname(open_bracket, nodename); + if (res) { + strncpy(nodename, open_bracket, CS_MAX_NAME_LENGTH-1); + } + } + _cs_node_membership_event(nodename, nodeid, (char *)new_value.data, open_bracket); + free(ip_str); +} + +static void _cs_cmap_connections_key_changed ( + cmap_handle_t cmap_handle_c, + cmap_track_handle_t cmap_track_handle, + int32_t event, + const char *key_name, + struct cmap_notify_value new_value, + struct cmap_notify_value old_value, + void *user_data) +{ + char obj_name[CS_MAX_NAME_LENGTH]; + char conn_str[CMAP_KEYNAME_MAXLEN]; + char tmp_key[CMAP_KEYNAME_MAXLEN]; + int service, pid; + int res; + + res = sscanf(key_name, "stats.ipcs.service%d.%d.%[^.].%s", &service,&pid, conn_str, tmp_key); + if (res != 4) { + return ; + } + + if (strcmp(tmp_key, "procname") != 0) { + return ; + } + + if (snprintf(obj_name, CS_MAX_NAME_LENGTH, "%s.%d.%s", conn_str, pid, + (char*)new_value.data) >= CS_MAX_NAME_LENGTH) { + /* + * This should never happen + */ + qb_log(LOG_ERR, "Can't snprintf obj_name"); + return ; + } + + if (event == CMAP_TRACK_ADD) { + _cs_application_connection_event(obj_name, "connected"); + } + + if (event == CMAP_TRACK_DELETE) { + _cs_application_connection_event(obj_name, "disconnected"); + } +} + +static void _cs_cmap_link_faulty_key_changed ( + cmap_handle_t cmap_handle_c, + cmap_track_handle_t cmap_track_handle, + int32_t event, + const char *key_name, + struct cmap_notify_value new_value, + struct cmap_notify_value old_value, + void *user_data) +{ + uint32_t iface_no; + uint32_t nodeid; + int res; + int no_retries; + uint8_t connected; + cs_error_t err; + + res = sscanf(key_name, "stats.knet.node%u.link%u.connected", &nodeid, &iface_no); + if (res != 2) { + return ; + } + + no_retries = 0; + while ((err = cmap_get_uint8(stats_handle, key_name, &connected)) == CS_ERR_TRY_AGAIN && + no_retries++ < CMAP_MAX_RETRIES) { + sleep(1); + } + + if (err != CS_OK) { + return ; + } + + if (connected) { + _cs_link_faulty_event(nodeid, iface_no, "operational"); + } else { + _cs_link_faulty_event(nodeid, iface_no, "disconnected"); + } +} + +static void _cs_cmap_link_added_removed ( + cmap_handle_t cmap_handle_c, + cmap_track_handle_t track_handle, + int32_t event, + const char *key_name, + struct cmap_notify_value new_value, + struct cmap_notify_value old_value, + void *user_data) +{ + struct track_item *track_item; + cs_error_t err; + + /* Add/remove a tracker for a new/removed knet link */ + if (strstr(key_name, ".connected")) { + if (event == CMAP_TRACK_ADD) { + assert(strlen(key_name) < sizeof(track_item->key_name)); + + track_item = malloc(sizeof(struct track_item)); + if (!track_item) { + qb_log(LOG_WARNING, "Can't alloc track_item for new/removed knet link"); + return; + } + err = cmap_track_add(stats_handle, key_name, CMAP_TRACK_MODIFY, + _cs_cmap_link_faulty_key_changed, NULL, &track_handle); + if (err != CS_OK) { + qb_log(LOG_WARNING, "Can't add tracker for new/removed knet link"); + + free(track_item); + return ; + } + + strcpy(track_item->key_name, key_name); + + track_item->track_handle = track_handle; + qb_map_put(tracker_map, track_item->key_name, track_item); + } else { + track_item = qb_map_get(tracker_map, key_name); + if (track_item) { + cmap_track_delete(stats_handle, track_item->track_handle); + qb_map_rm(tracker_map, track_item->key_name); + free(track_item); + } + } + } +} + + +static int +_cs_cmap_dispatch(int fd, int revents, void *data) +{ + cs_error_t err; + + err = cmap_dispatch(*(cmap_handle_t *)data, CS_DISPATCH_ONE); + + if (err != CS_OK && err != CS_ERR_TRY_AGAIN && err != CS_ERR_TIMEOUT && + err != CS_ERR_QUEUE_FULL) { + qb_log(LOG_ERR, "Could not dispatch cmap events. Error %u", err); + qb_loop_stop(main_loop); + + exit_code = 1; + + return -1; + } + + return 0; +} + +static void _cs_quorum_notification(quorum_handle_t handle, + uint32_t quorate, uint64_t ring_seq, + uint32_t view_list_entries, uint32_t *view_list) +{ + if (_cs_is_quorate == quorate) { + return; + } + _cs_is_quorate = quorate; + + if (quorate) { + _cs_node_quorum_event("quorate"); + } else { + _cs_node_quorum_event("not quorate"); + } +} + +static int +_cs_quorum_dispatch(int fd, int revents, void *data) +{ + cs_error_t err; + + err = quorum_dispatch(quorum_handle, CS_DISPATCH_ONE); + if (err != CS_OK && err != CS_ERR_TRY_AGAIN && err != CS_ERR_TIMEOUT && + err != CS_ERR_QUEUE_FULL) { + qb_log(LOG_ERR, "Could not dispatch quorum events. Error %u", err); + qb_loop_stop(main_loop); + + exit_code = 1; + + return -1; + } + return 0; +} + +static void +_cs_quorum_init(void) +{ + cs_error_t rc; + uint32_t quorum_type; + int fd; + + quorum_callbacks_t quorum_callbacks = { + .quorum_notify_fn = _cs_quorum_notification, + }; + + rc = quorum_initialize (&quorum_handle, &quorum_callbacks, + &quorum_type); + if (rc != CS_OK) { + qb_log(LOG_ERR, "Could not connect to corosync(quorum)"); + return; + } + quorum_fd_get(quorum_handle, &fd); + qb_loop_poll_add(main_loop, QB_LOOP_MED, fd, POLLIN|POLLNVAL, NULL, + _cs_quorum_dispatch); + rc = quorum_trackstart(quorum_handle, CS_TRACK_CHANGES); + if (rc != CS_OK) { + qb_log(LOG_ERR, "Could not start tracking"); + return; + } +} + +static void +_cs_quorum_finalize(void) +{ + quorum_finalize (quorum_handle); +} + + +#ifdef HAVE_DBUS +/* + * dbus notifications + */ +static void +_cs_dbus_auto_flush(void) +{ + dbus_connection_ref(db); + while (dbus_connection_get_dispatch_status(db) == DBUS_DISPATCH_DATA_REMAINS) { + dbus_connection_dispatch(db); + } + + while (dbus_connection_has_messages_to_send(db)) { + dbus_connection_flush(db); + } + + dbus_connection_unref(db); +} + +static void +_cs_dbus_release(void) +{ + DBusError err; + + if (!db) + return; + + dbus_error_init(&err); + dbus_bus_release_name(db, DBUS_CS_NAME, &err); + dbus_error_free(&err); + dbus_connection_unref(db); + db = NULL; +} + +static void +_cs_dbus_node_quorum_event(char *nodename, uint32_t nodeid, const char *state) +{ + DBusMessage *msg = NULL; + + if (err_set) { + qb_log(LOG_ERR, "%s", _err); + err_set = 0; + } + + if (!db) { + goto out_free; + } + + if (dbus_connection_get_is_connected(db) != TRUE) { + err_set = 1; + snprintf(_err, sizeof(_err), "DBus connection lost"); + _cs_dbus_release(); + goto out_unlock; + } + + _cs_dbus_auto_flush(); + + if (!(msg = dbus_message_new_signal(DBUS_CS_PATH, + DBUS_CS_IFACE, + "QuorumStateChange"))) { + qb_log(LOG_ERR, "error creating dbus signal"); + goto out_unlock; + } + + if (!dbus_message_append_args(msg, + DBUS_TYPE_STRING, &nodename, + DBUS_TYPE_UINT32, &nodeid, + DBUS_TYPE_STRING, &state, + DBUS_TYPE_INVALID)) { + qb_log(LOG_ERR, "error adding args to quorum signal"); + goto out_unlock; + } + + dbus_connection_send(db, msg, NULL); + +out_unlock: + if (msg) { + dbus_message_unref(msg); + } +out_free: + return; +} + +static void +_cs_dbus_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip) +{ + DBusMessage *msg = NULL; + + if (err_set) { + qb_log(LOG_ERR, "%s", _err); + err_set = 0; + } + + if (!db) { + goto out_free; + } + + if (dbus_connection_get_is_connected(db) != TRUE) { + err_set = 1; + snprintf(_err, sizeof(_err), "DBus connection lost"); + _cs_dbus_release(); + goto out_unlock; + } + + _cs_dbus_auto_flush(); + + if (!(msg = dbus_message_new_signal(DBUS_CS_PATH, + DBUS_CS_IFACE, + "NodeStateChange"))) { + qb_log(LOG_ERR, "error creating NodeStateChange signal"); + goto out_unlock; + } + + if (!dbus_message_append_args(msg, + DBUS_TYPE_STRING, &nodename, + DBUS_TYPE_UINT32, &nodeid, + DBUS_TYPE_STRING, &ip, + DBUS_TYPE_STRING, &state, + DBUS_TYPE_INVALID)) { + qb_log(LOG_ERR, "error adding args to NodeStateChange signal"); + goto out_unlock; + } + + dbus_connection_send(db, msg, NULL); + +out_unlock: + if (msg) { + dbus_message_unref(msg); + } +out_free: + return; +} + +static void +_cs_dbus_application_connection_event(char *nodename, uint32_t nodeid, char *app_name, const char *state) +{ + DBusMessage *msg = NULL; + + if (err_set) { + qb_log(LOG_ERR, "%s", _err); + err_set = 0; + } + + if (!db) { + goto out_free; + } + + if (dbus_connection_get_is_connected(db) != TRUE) { + err_set = 1; + snprintf(_err, sizeof(_err), "DBus connection lost"); + _cs_dbus_release(); + goto out_unlock; + } + + _cs_dbus_auto_flush(); + + if (!(msg = dbus_message_new_signal(DBUS_CS_PATH, + DBUS_CS_IFACE, + "ConnectionStateChange"))) { + qb_log(LOG_ERR, "error creating ConnectionStateChange signal"); + goto out_unlock; + } + + if (!dbus_message_append_args(msg, + DBUS_TYPE_STRING, &nodename, + DBUS_TYPE_UINT32, &nodeid, + DBUS_TYPE_STRING, &app_name, + DBUS_TYPE_STRING, &state, + DBUS_TYPE_INVALID)) { + qb_log(LOG_ERR, "error adding args to ConnectionStateChange signal"); + goto out_unlock; + } + + dbus_connection_send(db, msg, NULL); + +out_unlock: + if (msg) { + dbus_message_unref(msg); + } +out_free: + return; +} + +static void +_cs_dbus_link_faulty_event(char *nodename, uint32_t local_nodeid, uint32_t nodeid, uint32_t iface_no, const char *state) +{ + DBusMessage *msg = NULL; + + if (err_set) { + qb_log(LOG_ERR, "%s", _err); + err_set = 0; + } + + if (!db) { + goto out_free; + } + + if (dbus_connection_get_is_connected(db) != TRUE) { + err_set = 1; + snprintf(_err, sizeof(_err), "DBus connection lost"); + _cs_dbus_release(); + goto out_unlock; + } + + _cs_dbus_auto_flush(); + + if (!(msg = dbus_message_new_signal(DBUS_CS_PATH, + DBUS_CS_IFACE, + "QuorumStateChange"))) { + qb_log(LOG_ERR, "error creating dbus signal"); + goto out_unlock; + } + + if (!dbus_message_append_args(msg, + DBUS_TYPE_STRING, &nodename, + DBUS_TYPE_UINT32, &local_nodeid, + DBUS_TYPE_UINT32, &nodeid, + DBUS_TYPE_UINT32, &iface_no, + DBUS_TYPE_STRING, &state, + DBUS_TYPE_INVALID)) { + qb_log(LOG_ERR, "error adding args to link signal"); + goto out_unlock; + } + + dbus_connection_send(db, msg, NULL); + +out_unlock: + if (msg) { + dbus_message_unref(msg); + } +out_free: + return; +} + +static void +_cs_dbus_init(void) +{ + DBusConnection *dbc = NULL; + DBusError err; + + dbus_error_init(&err); + + dbc = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + if (!dbc) { + snprintf(_err, sizeof(_err), + "dbus_bus_get: %s", err.message); + err_set = 1; + dbus_error_free(&err); + return; + } + + dbus_connection_set_exit_on_disconnect(dbc, FALSE); + + db = dbc; + + notifiers[num_notifiers].node_membership_fn = + _cs_dbus_node_membership_event; + notifiers[num_notifiers].node_quorum_fn = + _cs_dbus_node_quorum_event; + notifiers[num_notifiers].application_connection_fn = + _cs_dbus_application_connection_event; + notifiers[num_notifiers].link_faulty_fn = + _cs_dbus_link_faulty_event; + + num_notifiers++; +} + +#endif /* HAVE_DBUS */ + +#ifdef ENABLE_SNMP +static netsnmp_session *_cs_snmp_session_init (const char *target) +{ + static netsnmp_session *session = NULL; +#ifndef NETSNMPV54 + char default_port[128]; + snprintf (default_port, sizeof (default_port), "%s:162", target); +#endif + if (session) { + return (session); + } + + if (target == NULL) { + return NULL; + } + + session = malloc (sizeof (netsnmp_session)); + snmp_sess_init (session); + session->version = SNMP_VERSION_2c; + session->callback = NULL; + session->callback_magic = NULL; + + if (snmp_community) { + session->community = (u_char *)snmp_community; + session->community_len = strlen(snmp_community_buf); + } + + session = snmp_add(session, +#ifdef NETSNMPV54 + netsnmp_transport_open_client ("snmptrap", target), +#else + netsnmp_tdomain_transport (default_port, 0, "udp"), +#endif + NULL, NULL); + + if (session == NULL) { + qb_log(LOG_ERR, 0, "Could not create snmp transport"); + } + return (session); +} + +static void _cs_snmp_add_field ( + netsnmp_pdu *trap_pdu, + u_char asn_type, + const char *prefix, + void *value, + size_t value_size) +{ + oid _oid[MAX_OID_LEN]; + size_t _oid_len = MAX_OID_LEN; + if (snmp_parse_oid(prefix, _oid, &_oid_len)) { + snmp_pdu_add_variable (trap_pdu, _oid, _oid_len, asn_type, (u_char *) value, value_size); + } +} + +static netsnmp_pdu *_cs_snmp_trap_pdu_init (const char *trap_oid) +{ + static oid snmptrap_oid[] = { 1,3,6,1,6,3,1,1,4,1,0 }; + static oid sysuptime_oid[] = { 1,3,6,1,2,1,1,3,0 }; + char csysuptime[CS_TIMESTAMP_STR_LEN]; + time_t now; + struct tm *now_tm; + netsnmp_pdu *trap_pdu; + + now = time (NULL); + if (now == ((time_t)-1)) { + qb_log(LOG_NOTICE, "Failed to get timestamp."); + return (NULL); + } + + /* format uptime */ + now_tm = localtime(&now); + if (now_tm == NULL || strftime (csysuptime, sizeof(csysuptime), "%s", now_tm) == 0) { + qb_log(LOG_NOTICE, "Failed to format timestamp."); + return (NULL); + } + + trap_pdu = snmp_pdu_create (SNMP_MSG_TRAP2); + if (!trap_pdu) { + qb_log(LOG_NOTICE, "Failed to create SNMP notification."); + return (NULL); + } + + /* send uptime */ + snmp_add_var (trap_pdu, sysuptime_oid, sizeof (sysuptime_oid) / sizeof (oid), 't', csysuptime); + snmp_add_var (trap_pdu, snmptrap_oid, sizeof (snmptrap_oid) / sizeof (oid), 'o', trap_oid); + + return (trap_pdu); +} + +static void +_cs_snmp_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip) +{ + int ret; + netsnmp_pdu *trap_pdu; + netsnmp_session *session = _cs_snmp_session_init (snmp_manager); + + if (session == NULL) { + qb_log(LOG_NOTICE, "Failed to init SNMP session."); + return ; + } + + trap_pdu = _cs_snmp_trap_pdu_init(SNMP_OID_TRAPS_NODE); + if (trap_pdu == NULL) { + return ; + } + + /* Add extries to the trap */ + _cs_snmp_add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename)); + _cs_snmp_add_field (trap_pdu, ASN_UNSIGNED, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid)); + _cs_snmp_add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_ADDR, (void*)ip, strlen (ip)); + _cs_snmp_add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_STATUS, (void*)state, strlen (state)); + + /* Send and cleanup */ + ret = snmp_send (session, trap_pdu); + if (ret == 0) { + /* error */ + qb_log(LOG_ERR, "Could not send SNMP trap"); + snmp_free_pdu (trap_pdu); + } +} + +static void +_cs_snmp_node_quorum_event(char *nodename, uint32_t nodeid, + const char *state) +{ + int ret; + netsnmp_pdu *trap_pdu; + netsnmp_session *session = _cs_snmp_session_init (snmp_manager); + + if (session == NULL) { + qb_log(LOG_NOTICE, "Failed to init SNMP session."); + return ; + } + + trap_pdu = _cs_snmp_trap_pdu_init(SNMP_OID_TRAPS_QUORUM); + if (trap_pdu == NULL) { + return ; + } + + /* Add extries to the trap */ + _cs_snmp_add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename)); + _cs_snmp_add_field (trap_pdu, ASN_UNSIGNED, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid)); + _cs_snmp_add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_QUORUM, (void*)state, strlen (state)); + + /* Send and cleanup */ + ret = snmp_send (session, trap_pdu); + if (ret == 0) { + /* error */ + qb_log(LOG_ERR, "Could not send SNMP trap"); + snmp_free_pdu (trap_pdu); + } +} + +static void +_cs_snmp_link_faulty_event(char *nodename, uint32_t local_nodeid, uint32_t nodeid, + uint32_t iface_no, const char *state) +{ + int ret; + netsnmp_pdu *trap_pdu; + netsnmp_session *session = _cs_snmp_session_init (snmp_manager); + + if (session == NULL) { + qb_log(LOG_NOTICE, "Failed to init SNMP session."); + return ; + } + + trap_pdu = _cs_snmp_trap_pdu_init(SNMP_OID_TRAPS_LINK); + if (trap_pdu == NULL) { + return ; + } + + /* Add extries to the trap */ + _cs_snmp_add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename)); + _cs_snmp_add_field (trap_pdu, ASN_UNSIGNED, SNMP_OID_OBJECT_LOCAL_NODE_ID, (void*)&local_nodeid, sizeof (local_nodeid)); + _cs_snmp_add_field (trap_pdu, ASN_UNSIGNED, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid)); + _cs_snmp_add_field (trap_pdu, ASN_INTEGER, SNMP_OID_OBJECT_LINK_IFACE_NO, (void*)&iface_no, sizeof (iface_no)); + _cs_snmp_add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_LINK_STATUS, (void*)state, strlen (state)); + + /* Send and cleanup */ + ret = snmp_send (session, trap_pdu); + if (ret == 0) { + /* error */ + qb_log(LOG_ERR, "Could not send SNMP trap"); + snmp_free_pdu (trap_pdu); + } +} + +static void +_cs_snmp_init(void) +{ + if (snmp_manager == NULL) { + snmp_manager = (char*)local_host; + } + + notifiers[num_notifiers].node_membership_fn = + _cs_snmp_node_membership_event; + notifiers[num_notifiers].node_quorum_fn = + _cs_snmp_node_quorum_event; + notifiers[num_notifiers].application_connection_fn = NULL; + notifiers[num_notifiers].link_faulty_fn = + _cs_snmp_link_faulty_event; + num_notifiers++; +} + +#endif /* ENABLE_SNMP */ + +static void +_cs_syslog_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip) +{ + qb_log(LOG_NOTICE, "%s[" CS_PRI_NODE_ID "] ip:%s %s", nodename, nodeid, ip, state); +} + +static void +_cs_syslog_node_quorum_event(char *nodename, uint32_t nodeid, const char *state) +{ + if (strcmp(state, "quorate") == 0) { + qb_log(LOG_NOTICE, "%s[" CS_PRI_NODE_ID "] is now %s", nodename, nodeid, state); + } else { + qb_log(LOG_NOTICE, "%s[" CS_PRI_NODE_ID "] has lost quorum", nodename, nodeid); + } +} + +static void +_cs_syslog_application_connection_event(char *nodename, uint32_t nodeid, char* app_name, const char *state) +{ + if (strcmp(state, "connected") == 0) { + qb_log(LOG_NOTICE, "%s[" CS_PRI_NODE_ID "] %s is now %s to corosync", nodename, nodeid, app_name, state); + } else { + qb_log(LOG_NOTICE, "%s[" CS_PRI_NODE_ID "] %s is now %s from corosync", nodename, nodeid, app_name, state); + } +} + +static void +_cs_syslog_link_faulty_event(char *nodename, uint32_t our_nodeid, uint32_t nodeid, uint32_t iface_no, const char *state) +{ + qb_log(LOG_NOTICE, "%s[" CS_PRI_NODE_ID "] link %u to node " CS_PRI_NODE_ID " is now %s", nodename, our_nodeid, iface_no, nodeid, state); +} + +static void +_cs_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip) +{ + int i; + + for (i = 0; i < num_notifiers; i++) { + if (notifiers[i].node_membership_fn) { + notifiers[i].node_membership_fn(nodename, nodeid, state, ip); + } + } +} + +static void +_cs_local_node_info_get(char **nodename, uint32_t *nodeid) +{ + cs_error_t rc; + corosync_cfg_handle_t cfg_handle; + + if (g_local_nodeid == 0) { + rc = corosync_cfg_initialize(&cfg_handle, NULL); + if (rc != CS_OK) { + syslog (LOG_ERR, "Failed to initialize the cfg API. Error %d\n", rc); + exit (EXIT_FAILURE); + } + + rc = corosync_cfg_local_get (cfg_handle, &g_local_nodeid); + corosync_cfg_finalize(cfg_handle); + if (rc != CS_OK) { + g_local_nodeid = 0; + strncpy(local_nodename, "localhost", sizeof (local_nodename)); + local_nodename[sizeof (local_nodename) - 1] = '\0'; + } else { + gethostname(local_nodename, CS_MAX_NAME_LENGTH); + } + } + *nodeid = g_local_nodeid; + *nodename = local_nodename; +} + +static void +_cs_node_quorum_event(const char *state) +{ + int i; + char *nodename; + uint32_t nodeid; + + _cs_local_node_info_get(&nodename, &nodeid); + + for (i = 0; i < num_notifiers; i++) { + if (notifiers[i].node_quorum_fn) { + notifiers[i].node_quorum_fn(nodename, nodeid, state); + } + } +} + +static void +_cs_application_connection_event(char *app_name, const char *state) +{ + int i; + char *nodename; + uint32_t nodeid; + + _cs_local_node_info_get(&nodename, &nodeid); + + for (i = 0; i < num_notifiers; i++) { + if (notifiers[i].application_connection_fn) { + notifiers[i].application_connection_fn(nodename, nodeid, app_name, state); + } + } +} + +static void +_cs_link_faulty_event(uint32_t nodeid, uint32_t iface_no, const char *state) +{ + int i; + char *nodename; + uint32_t our_nodeid; + + _cs_local_node_info_get(&nodename, &our_nodeid); + + for (i = 0; i < num_notifiers; i++) { + if (notifiers[i].link_faulty_fn) { + notifiers[i].link_faulty_fn(nodename, our_nodeid, nodeid, iface_no, state); + } + } +} + +static int32_t +sig_exit_handler(int32_t num, void *data) +{ + qb_loop_stop(main_loop); + return 0; +} + +static void track_link_updown_events(void) +{ + cmap_iter_handle_t iter_handle; + cmap_track_handle_t track_handle; + + char key_name[CMAP_KEYNAME_MAXLEN + 1]; + size_t value_len; + cmap_value_types_t type; + cs_error_t err; + struct track_item *track_item; + + err = cmap_iter_init(stats_handle, "stats.knet.", &iter_handle); + if (err != CS_OK) { + fprintf (stderr, "Failed to initialize knet stats iterator. Error %s\n", cs_strerror(err)); + exit (EXIT_FAILURE); + } + + while ((err = cmap_iter_next(stats_handle, iter_handle, key_name, &value_len, &type)) == CS_OK) { + if (strstr(key_name, ".connected")) { + + track_item = malloc(sizeof(struct track_item)); + if (!track_item) { + return; + } + + if ((err = cmap_track_add(stats_handle, key_name, CMAP_TRACK_MODIFY, _cs_cmap_link_faulty_key_changed, NULL, &track_handle)) != CS_OK) { + fprintf (stderr, "Failed to add tracker for %s. Error %s\n", key_name, cs_strerror(err)); + exit (EXIT_FAILURE); + } + strcpy(track_item->key_name, key_name); + track_item->track_handle = track_handle; + qb_map_put(tracker_map, track_item->key_name, track_item); + } + } + cmap_iter_finalize(stats_handle, iter_handle); +} + +static void +_cs_cmap_init(void) +{ + cs_error_t rc = CS_OK; + int cmap_fd = 0; + int stats_fd = 0; + + tracker_map = qb_trie_create(); + if (!tracker_map) { + qb_log(LOG_ERR, "Failed to initialize the track map. Error %d", rc); + exit (EXIT_FAILURE); + } + + rc = cmap_initialize_map (&cmap_handle, CMAP_MAP_ICMAP); + if (rc != CS_OK) { + qb_log(LOG_ERR, "Failed to initialize the cmap API. Error %d", rc); + exit (EXIT_FAILURE); + } + cmap_fd_get(cmap_handle, &cmap_fd); + + qb_loop_poll_add(main_loop, QB_LOOP_MED, cmap_fd, POLLIN|POLLNVAL, (void*)&cmap_handle, + _cs_cmap_dispatch); + + + rc = cmap_initialize_map (&stats_handle, CMAP_MAP_STATS); + if (rc != CS_OK) { + qb_log(LOG_ERR, "Failed to initialize the cmap stats API. Error %d", rc); + exit (EXIT_FAILURE); + } + cmap_fd_get(stats_handle, &stats_fd); + + qb_loop_poll_add(main_loop, QB_LOOP_MED, stats_fd, POLLIN|POLLNVAL, (void*)&stats_handle, + _cs_cmap_dispatch); + + + rc = cmap_track_add(cmap_handle, "runtime.members.", + CMAP_TRACK_ADD | CMAP_TRACK_MODIFY | CMAP_TRACK_PREFIX, + _cs_cmap_members_key_changed, + NULL, + &cmap_track_handle_runtime_members_key_changed); + if (rc != CS_OK) { + qb_log(LOG_ERR, + "Failed to track the members key. Error %d", rc); + exit (EXIT_FAILURE); + } + + rc = cmap_track_add(stats_handle, "stats.ipcs.", + CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_PREFIX, + _cs_cmap_connections_key_changed, + NULL, + &cmap_track_handle_stats_ipcs_key_changed); + if (rc != CS_OK) { + qb_log(LOG_ERR, + "Failed to track the connections key. Error %d", rc); + exit (EXIT_FAILURE); + } + + rc = cmap_track_add(stats_handle, "stats.knet.", + CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_PREFIX, + _cs_cmap_link_added_removed, + NULL, + &cmap_track_handle_stats_knet_key_changed); + if (rc != CS_OK) { + qb_log(LOG_ERR, + "Failed to track the knet link status key. Error %d", rc); + exit (EXIT_FAILURE); + } + track_link_updown_events(); +} + +static void +_cs_cmap_finalize(void) +{ + struct qb_map_iter *map_iter; + struct track_item *track_item; + + map_iter = qb_map_iter_create(tracker_map); + while (qb_map_iter_next(map_iter, (void **)&track_item) != NULL) { + cmap_track_delete(stats_handle, track_item->track_handle); + free(track_item); + } + qb_map_iter_free(map_iter); + + cmap_track_delete(cmap_handle, cmap_track_handle_runtime_members_key_changed); + cmap_track_delete(stats_handle, cmap_track_handle_stats_ipcs_key_changed); + cmap_track_delete(stats_handle, cmap_track_handle_stats_knet_key_changed); + cmap_finalize (cmap_handle); + cmap_finalize (stats_handle); +} + +static void +_cs_check_config(void) +{ + if (conf[CS_NTF_LOG] == QB_FALSE && + conf[CS_NTF_STDOUT] == QB_FALSE && + conf[CS_NTF_SNMP] == QB_FALSE && + conf[CS_NTF_DBUS] == QB_FALSE) { + qb_log(LOG_ERR, "no event type enabled, see corosync-notifyd -h, exiting."); + exit(EXIT_FAILURE); + } + +#ifndef ENABLE_SNMP + if (conf[CS_NTF_SNMP]) { + qb_log(LOG_ERR, "Not compiled with SNMP support enabled, exiting."); + exit(EXIT_FAILURE); + } +#endif +#ifndef HAVE_DBUS + if (conf[CS_NTF_DBUS]) { + qb_log(LOG_ERR, "Not compiled with DBus support enabled, exiting."); + exit(EXIT_FAILURE); + } +#endif + + if (conf[CS_NTF_STDOUT] && !conf[CS_NTF_FG]) { + qb_log(LOG_ERR, "configured to print to stdout and run in the background, exiting"); + exit(EXIT_FAILURE); + } + if (conf[CS_NTF_SNMP] && conf[CS_NTF_DBUS]) { + qb_log(LOG_ERR, "configured to send snmp traps and dbus signals - are you sure?."); + } +} + +static void +_cs_usage(void) +{ + fprintf(stderr, "usage:\n"\ + " -c : SNMP Community name.\n"\ + " -f : Start application in foreground.\n"\ + " -l : Log all events.\n"\ + " -o : Print events to stdout (turns on -l).\n"\ + " -s : Send SNMP traps on all events.\n"\ + " -m : Set the SNMP Manager IP address (defaults to localhost).\n"\ + " -n : No reverse DNS lookup on cmap member change events.\n"\ + " -d : Send DBUS signals on all events.\n"\ + " -h : Print this help.\n\n"); +} + +int +main(int argc, char *argv[]) +{ + int ch; + + conf[CS_NTF_FG] = QB_FALSE; + conf[CS_NTF_LOG] = QB_FALSE; + conf[CS_NTF_STDOUT] = QB_FALSE; + conf[CS_NTF_SNMP] = QB_FALSE; + conf[CS_NTF_DBUS] = QB_FALSE; + + while ((ch = getopt (argc, argv, "c:floshdnm:")) != EOF) { + switch (ch) { + case 'c': + strncpy(snmp_community_buf, optarg, sizeof (snmp_community_buf)); + snmp_community_buf[sizeof (snmp_community_buf) - 1] = '\0'; + snmp_community = snmp_community_buf; + break; + case 'f': + conf[CS_NTF_FG] = QB_TRUE; + break; + case 'l': + conf[CS_NTF_LOG] = QB_TRUE; + break; + case 'm': + conf[CS_NTF_SNMP] = QB_TRUE; + strncpy(snmp_manager_buf, optarg, sizeof (snmp_manager_buf)); + snmp_manager_buf[sizeof (snmp_manager_buf) - 1] = '\0'; + snmp_manager = snmp_manager_buf; + break; + case 'n': + conf[CS_NTF_NODNS] = QB_TRUE; + break; + case 'o': + conf[CS_NTF_LOG] = QB_TRUE; + conf[CS_NTF_STDOUT] = QB_TRUE; + break; + case 's': + conf[CS_NTF_SNMP] = QB_TRUE; + break; + case 'd': + conf[CS_NTF_DBUS] = QB_TRUE; + break; + case 'h': + default: + _cs_usage(); + return EXIT_FAILURE; + } + } + + qb_log_init("notifyd", LOG_DAEMON, LOG_INFO); + + if (conf[CS_NTF_STDOUT]) { + qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD, + QB_LOG_FILTER_FILE, "*", LOG_DEBUG); + qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, conf[CS_NTF_STDOUT]); + } + _cs_check_config(); + + if (!conf[CS_NTF_FG]) { + if (daemon(0, 0) < 0) + { + perror("daemon() failed"); + return EXIT_FAILURE; + } + } + + num_notifiers = 0; + if (conf[CS_NTF_LOG]) { + notifiers[num_notifiers].node_membership_fn = + _cs_syslog_node_membership_event; + notifiers[num_notifiers].node_quorum_fn = + _cs_syslog_node_quorum_event; + notifiers[num_notifiers].application_connection_fn = + _cs_syslog_application_connection_event; + notifiers[num_notifiers].link_faulty_fn = + _cs_syslog_link_faulty_event; + num_notifiers++; + } + + main_loop = qb_loop_create(); + + _cs_cmap_init(); + _cs_quorum_init(); + +#ifdef HAVE_DBUS + if (conf[CS_NTF_DBUS]) { + _cs_dbus_init(); + } +#endif /* HAVE_DBUS */ + +#ifdef ENABLE_SNMP + if (conf[CS_NTF_SNMP]) { + _cs_snmp_init(); + } +#endif /* ENABLE_SNMP */ + + qb_loop_signal_add(main_loop, + QB_LOOP_HIGH, + SIGINT, + NULL, + sig_exit_handler, + NULL); + qb_loop_signal_add(main_loop, + QB_LOOP_HIGH, + SIGQUIT, + NULL, + sig_exit_handler, + NULL); + qb_loop_signal_add(main_loop, + QB_LOOP_HIGH, + SIGTERM, + NULL, + sig_exit_handler, + NULL); + +#ifdef HAVE_LIBSYSTEMD + sd_notify (0, "READY=1"); +#endif + + qb_loop_run(main_loop); + +#ifdef HAVE_DBUS + if (conf[CS_NTF_DBUS]) { + _cs_dbus_release(); + } +#endif /* HAVE_DBUS */ + + _cs_quorum_finalize(); + _cs_cmap_finalize(); + + return (exit_code); +} + diff --git a/tools/corosync-notifyd.sysconfig.example b/tools/corosync-notifyd.sysconfig.example new file mode 100644 index 0000000..908bc8c --- /dev/null +++ b/tools/corosync-notifyd.sysconfig.example @@ -0,0 +1,10 @@ +# +# See "man corosync-notifyd" for detailed descriptions of +# the options below. +# +# OPTIONS="-d -s -l -m <snmp manager address>" +# + +# Send DBUS signals on all events (for SNMP traps, use -s) +OPTIONS="-d" + diff --git a/tools/corosync-quorumtool.c b/tools/corosync-quorumtool.c new file mode 100644 index 0000000..199bd20 --- /dev/null +++ b/tools/corosync-quorumtool.c @@ -0,0 +1,1023 @@ +/* + * Copyright (c) 2009-2020 Red Hat, Inc. + * + * All rights reserved. + * + * Authors: Christine Caulfield <ccaulfie@redhat.com> + * Fabio M. Di Nitto (fdinitto@redhat.com) + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the Red Hat Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#include <limits.h> + +#include <corosync/totem/totem.h> +#include <corosync/cfg.h> +#include <corosync/cmap.h> +#include <corosync/quorum.h> +#include <corosync/votequorum.h> +#include "util.h" + +typedef enum { + NODEID_FORMAT_DECIMAL, + NODEID_FORMAT_HEX +} nodeid_format_t; + +typedef enum { + ADDRESS_FORMAT_NAME, + ADDRESS_FORMAT_IP +} name_format_t; + +typedef enum { + CMD_SHOWNODES, + CMD_SHOWSTATUS, + CMD_SETVOTES, + CMD_SETEXPECTED, + CMD_MONITOR, + CMD_UNREGISTER_QDEVICE +} command_t; + +typedef enum { + SORT_ADDR, + SORT_NODEID, + SORT_NODENAME +} sorttype_t; + +#define EXIT_NOT_QUORATE 2 + +/* + * global vars + */ + +/* + * cmap bits + */ +static cmap_handle_t cmap_handle; + +/* + * quorum bits + */ +static void quorum_notification_fn( + quorum_handle_t handle, + uint32_t quorate, + uint64_t ring_id, + uint32_t view_list_entries, + uint32_t *view_list); + +static quorum_handle_t q_handle; +static uint32_t q_type; +static quorum_callbacks_t q_callbacks = { + .quorum_notify_fn = quorum_notification_fn +}; + +/* + * quorum call back vars + */ + +/* Containing struct to keep votequorum & normal quorum bits together */ +typedef struct { + struct votequorum_info *vq_info; /* Might be NULL if votequorum not present */ + char *name; /* Might be IP address or NULL */ + int node_id; /* Always present */ +} view_list_entry_t; + +static view_list_entry_t *g_view_list; +static uint32_t g_quorate; +static uint64_t g_ring_id; +static uint32_t g_ring_id_rep_node; +static uint32_t g_view_list_entries; +static uint32_t g_called; +static uint32_t g_vq_called; +static uint32_t g_show_all_addrs = 0; + +/* + * votequorum bits + */ +static void votequorum_notification_fn( + votequorum_handle_t handle, + uint64_t context, + votequorum_ring_id_t ring_id, + uint32_t node_list_entries, + uint32_t node_list[]); +static votequorum_handle_t v_handle; +static votequorum_callbacks_t v_callbacks = { + .votequorum_quorum_notify_fn = NULL, + .votequorum_expectedvotes_notify_fn = NULL, + .votequorum_nodelist_notify_fn = votequorum_notification_fn, +}; +static uint32_t our_nodeid = 0; + +/* + * cfg bits + */ +static corosync_cfg_handle_t c_handle; +static corosync_cfg_callbacks_t c_callbacks = { + .corosync_cfg_shutdown_callback = NULL +}; + +/* + * global + */ +static int machine_parsable = 0; + +static void show_usage(const char *name) +{ + printf("usage: \n"); + printf("%s <options>\n", name); + printf("\n"); + printf(" options:\n"); + printf("\n"); + printf(" -s show quorum status\n"); + printf(" -m constantly monitor quorum status\n"); + printf(" -l list nodes\n"); + printf(" -a show all names or addresses for each node\n"); + printf(" -p when used with -s or -l, generates machine parsable output\n"); + printf(" -v <votes> change the number of votes for a node (*)\n"); + printf(" -n <nodeid> optional nodeid of node for -v\n"); + printf(" -e <expected> change expected votes for the cluster (*)\n"); + printf(" -H show nodeids in hexadecimal rather than decimal\n"); + printf(" -i show node IP addresses instead of the resolved name\n"); + printf(" -o <a|n|i> order by [a] IP address (default), [n] name, [i] nodeid\n"); + printf(" -f forcefully unregister a quorum device *DANGEROUS* (*)\n"); + printf(" -h show this help text\n"); + printf(" -V show version and exit\n"); + printf("\n"); + printf(" (*) Starred items only work if votequorum is the quorum provider for corosync\n"); + printf("\n"); +} + +static int get_quorum_type(char *quorum_type, size_t quorum_type_len) +{ + int err; + char *str = NULL; + + if ((!quorum_type) || (quorum_type_len <= 0)) { + return -1; + } + + if (q_type == QUORUM_FREE) { + return -1; + } + + if ((err = cmap_get_string(cmap_handle, "quorum.provider", &str)) != CS_OK) { + goto out; + } + + if (!str) { + return -1; + } + + strncpy(quorum_type, str, quorum_type_len - 1); + free(str); + + return 0; +out: + return err; +} + +/* + * Returns 1 if 'votequorum' is active. The called then knows that + * votequorum calls should work and can provide extra information + */ +static int using_votequorum(void) +{ + char quorumtype[256]; + int using_voteq; + + memset(quorumtype, 0, sizeof(quorumtype)); + + if (get_quorum_type(quorumtype, sizeof(quorumtype))) { + return -1; + } + + if (strcmp(quorumtype, "corosync_votequorum") == 0) { + using_voteq = 1; + } else { + using_voteq = 0; + } + + return using_voteq; +} + +static int set_votes(uint32_t nodeid, int votes) +{ + int err; + + if ((err=votequorum_setvotes(v_handle, nodeid, votes)) != CS_OK) { + fprintf(stderr, "Unable to set votes %d for nodeid: " CS_PRI_NODE_ID ": %s\n", + votes, nodeid, cs_strerror(err)); + } + + return (err == CS_OK ? EXIT_SUCCESS : EXIT_FAILURE); +} + +static int set_expected(int expected_votes) +{ + int err; + + if ((err=votequorum_setexpected(v_handle, expected_votes)) != CS_OK) { + fprintf(stderr, "Unable to set expected votes: %s\n", cs_strerror(err)); + } + + return (err == CS_OK ? EXIT_SUCCESS : EXIT_FAILURE); +} + +/* + * node name by nodelist + */ + +static const char *node_name_by_nodelist(uint32_t nodeid) +{ + cmap_iter_handle_t iter; + char key_name[CMAP_KEYNAME_MAXLEN + 1]; + char tmp_key[CMAP_KEYNAME_MAXLEN + 1]; + static char ret_buf[_POSIX_HOST_NAME_MAX]; + char *str = NULL; + uint32_t node_pos, cur_nodeid; + int res = 0; + + if (cmap_iter_init(cmap_handle, "nodelist.node.", &iter) != CS_OK) { + return ""; + } + + memset(ret_buf, 0, sizeof(ret_buf)); + + while ((cmap_iter_next(cmap_handle, iter, key_name, NULL, NULL)) == CS_OK) { + + res = sscanf(key_name, "nodelist.node.%u.%s", &node_pos, tmp_key); + if (res != 2) { + continue; + } + + if (strcmp(tmp_key, "nodeid") != 0) { + continue; + } + + snprintf(tmp_key, CMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos); + if (cmap_get_uint32(cmap_handle, tmp_key, &cur_nodeid) != CS_OK) { + continue; + } + if (cur_nodeid != nodeid) { + continue; + } + snprintf(tmp_key, CMAP_KEYNAME_MAXLEN, "nodelist.node.%u.name", node_pos); + if (cmap_get_string(cmap_handle, tmp_key, &str) != CS_OK) { + continue; + } + if (!str) { + continue; + } + strncpy(ret_buf, str, sizeof(ret_buf) - 1); + free(str); + break; + } + cmap_iter_finalize(cmap_handle, iter); + + return ret_buf; +} + +/* + * This resolves the first address assigned to a node + * and returns the name or IP address. Use cfgtool if you need more information. + */ +static const char *node_name(uint32_t nodeid, name_format_t name_format) +{ + int err; + int numaddrs; + corosync_cfg_node_address_t addrs[INTERFACE_MAX]; + static char buf[(INET6_ADDRSTRLEN + 1) * KNET_MAX_LINK]; + const char *nodelist_name = NULL; + socklen_t addrlen; + struct sockaddr_storage *ss; + int start_addr = 0; + int i; + int bufptr = 0; + + buf[0] = '\0'; + + /* If a name is required, always look for the nodelist node0_addr name first */ + if (name_format == ADDRESS_FORMAT_NAME) { + nodelist_name = node_name_by_nodelist(nodeid); + } + if ((nodelist_name) && + (strlen(nodelist_name) > 0)) { + start_addr = 1; + assert(strlen(nodelist_name) < sizeof(buf)); + strcpy(buf, nodelist_name); + bufptr = strlen(buf); + } + + err = corosync_cfg_get_node_addrs(c_handle, nodeid, INTERFACE_MAX, &numaddrs, addrs); + if (err != CS_OK) { + fprintf(stderr, "Unable to get node address for nodeid " CS_PRI_NODE_ID ": %s\n", nodeid, cs_strerror(err)); + return ""; + } + + /* Don't show all addressess */ + if (!g_show_all_addrs) { + numaddrs = 1; + } + + for (i=start_addr; i<numaddrs; i++) { + + ss = (struct sockaddr_storage *)addrs[i].address; + + if (!ss->ss_family) { + continue; + } + + if (ss->ss_family == AF_INET6) { + addrlen = sizeof(struct sockaddr_in6); + } else { + addrlen = sizeof(struct sockaddr_in); + } + + if (i) { + buf[bufptr++] = ','; + buf[bufptr++] = ' '; + } + + if (!getnameinfo( + (struct sockaddr *)addrs[i].address, addrlen, + buf+bufptr, sizeof(buf)-bufptr, + NULL, 0, + (name_format == ADDRESS_FORMAT_IP)?NI_NUMERICHOST:0)) { + bufptr += strlen(buf+bufptr); + } + } + + return buf; +} + + +static void votequorum_notification_fn( + votequorum_handle_t handle, + uint64_t context, + votequorum_ring_id_t ring_id, + uint32_t node_list_entries, + uint32_t node_list[]) +{ + g_ring_id_rep_node = ring_id.nodeid; + g_vq_called = 1; +} + +static void quorum_notification_fn( + quorum_handle_t handle, + uint32_t quorate, + uint64_t ring_id, + uint32_t view_list_entries, + uint32_t *view_list) +{ + int i; + + g_called = 1; + g_quorate = quorate; + g_ring_id = ring_id; + g_view_list_entries = view_list_entries; + if (g_view_list) { + free(g_view_list); + } + g_view_list = malloc(sizeof(view_list_entry_t) * view_list_entries); + if (g_view_list) { + for (i=0; i< view_list_entries; i++) { + g_view_list[i].node_id = view_list[i]; + g_view_list[i].name = NULL; + g_view_list[i].vq_info = NULL; + } + } +} + +static void print_string_padded(const char *buf) +{ + int len, delta; + + len = strlen(buf); + delta = 10 - len; + while (delta > 0) { + printf(" "); + delta--; + } + printf("%s ", buf); +} + +static void print_uint32_padded(uint32_t value) +{ + char buf[12]; + + snprintf(buf, sizeof(buf) - 1, "%u", value); + print_string_padded(buf); +} + +/* for qsort */ +static int compare_nodeids(const void *one, const void *two) +{ + const view_list_entry_t *info1 = one; + const view_list_entry_t *info2 = two; + + if (info1->node_id == info2->node_id) { + return 0; + } + if (info1->node_id > info2->node_id) { + return 1; + } + return -1; +} + +static int compare_nodenames(const void *one, const void *two) +{ + const view_list_entry_t *info1 = one; + const view_list_entry_t *info2 = two; + + return strcmp(info1->name, info2->name); +} + +static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type) +{ + int i, display_qdevice = 0; + unsigned int our_flags = 0; + struct votequorum_info info[g_view_list_entries]; + /* + * cache node info because we need to parse them twice + */ + if (v_handle) { + for (i=0; i < g_view_list_entries; i++) { + if (votequorum_getinfo(v_handle, g_view_list[i].node_id, &info[i]) != CS_OK) { + printf("Unable to get node " CS_PRI_NODE_ID " info\n", g_view_list[i].node_id); + } + g_view_list[i].vq_info = &info[i]; + if (info[i].flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED) { + display_qdevice = 1; + } + } + } + + /* + * Get node names + */ + for (i=0; i < g_view_list_entries; i++) { + g_view_list[i].name = strdup(node_name(g_view_list[i].node_id, name_format)); + } + + printf("\nMembership information\n"); + printf("----------------------\n"); + + print_string_padded("Nodeid"); + if (v_handle) { + print_string_padded("Votes"); + if ((display_qdevice) || (machine_parsable)) { + print_string_padded("Qdevice"); + } + } + printf("Name\n"); + + /* corosync sends them already sorted by address */ + if (sort_type == SORT_NODEID) { + qsort(g_view_list, g_view_list_entries, sizeof(view_list_entry_t), compare_nodeids); + } + if (sort_type == SORT_NODENAME) { + qsort(g_view_list, g_view_list_entries, sizeof(view_list_entry_t), compare_nodenames); + } + for (i=0; i < g_view_list_entries; i++) { + if (nodeid_format == NODEID_FORMAT_DECIMAL) { + print_uint32_padded(g_view_list[i].node_id); + } else { + printf("0x%08x ", g_view_list[i].node_id); + } + if (v_handle) { + int votes = -1; + + votes = info[i].node_votes; + print_uint32_padded(votes); + + if ((display_qdevice) || (machine_parsable)) { + if (info[i].flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED) { + char buf[10]; + + snprintf(buf, sizeof(buf), + "%s,%s,%s", + info[i].flags & VOTEQUORUM_INFO_QDEVICE_ALIVE?"A":"NA", + info[i].flags & VOTEQUORUM_INFO_QDEVICE_CAST_VOTE?"V":"NV", + info[i].flags & VOTEQUORUM_INFO_QDEVICE_MASTER_WINS?"MW":"NMW"); + print_string_padded(buf); + } else { + print_string_padded("NR"); + } + } + } + printf("%s", g_view_list[i].name); + if (g_view_list[i].node_id == our_nodeid) { + printf(" (local)"); + if (v_handle) { + our_flags = info[i].flags; + } + } + printf("\n"); + } + + if (g_view_list_entries) { + for (i=0; i < g_view_list_entries; i++) { + free(g_view_list[i].name); + } + free(g_view_list); + g_view_list = NULL; + } + + if (display_qdevice) { + if (nodeid_format == NODEID_FORMAT_DECIMAL) { + print_uint32_padded(VOTEQUORUM_QDEVICE_NODEID); + } else { + printf("0x%08x ", VOTEQUORUM_QDEVICE_NODEID); + } + /* If the quorum device is inactive on this node then show votes as 0 + so that the display is not confusing */ + if (our_flags & VOTEQUORUM_INFO_QDEVICE_CAST_VOTE) { + print_uint32_padded(info[0].qdevice_votes); + } + else { + print_uint32_padded(0); + } + printf(" %s", info[0].qdevice_name); + if (our_flags & VOTEQUORUM_INFO_QDEVICE_CAST_VOTE) { + printf("\n"); + } + else { + printf(" (votes %d)\n", info[0].qdevice_votes); + } + } + +} + +static int display_quorum_data(int is_quorate, + nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type, + int loop) +{ + struct votequorum_info info; + int err; + char quorumtype[256]; + time_t t; + + memset(quorumtype, 0, sizeof(quorumtype)); + + printf("Quorum information\n"); + printf("------------------\n"); + time(&t); + printf("Date: %s", ctime((const time_t *)&t)); + + if (get_quorum_type(quorumtype, sizeof(quorumtype))) { + strncpy(quorumtype, "Not configured", sizeof(quorumtype) - 1); + } + printf("Quorum provider: %s\n", quorumtype); + printf("Nodes: %d\n", g_view_list_entries); + if (nodeid_format == NODEID_FORMAT_DECIMAL) { + printf("Node ID: " CS_PRI_NODE_ID "\n", our_nodeid); + } else { + printf("Node ID: 0x%08x\n", our_nodeid); + } + + if (v_handle) { + printf("Ring ID: " CS_PRI_RING_ID "\n", g_ring_id_rep_node, g_ring_id); + } + else { + printf("Ring ID: " CS_PRI_RING_ID_SEQ "\n", g_ring_id); + } + printf("Quorate: %s\n", is_quorate?"Yes":"No"); + + if (!v_handle) { + return CS_OK; + } + + err=votequorum_getinfo(v_handle, our_nodeid, &info); + if ((err == CS_OK) || (err == CS_ERR_NOT_EXIST)) { + printf("\nVotequorum information\n"); + printf("----------------------\n"); + printf("Expected votes: %d\n", info.node_expected_votes); + printf("Highest expected: %d\n", info.highest_expected); + printf("Total votes: %d\n", info.total_votes); + printf("Quorum: %d %s\n", info.quorum, info.flags & VOTEQUORUM_INFO_QUORATE?" ":"Activity blocked"); + printf("Flags: "); + if (info.flags & VOTEQUORUM_INFO_TWONODE) printf("2Node "); + if (info.flags & VOTEQUORUM_INFO_QUORATE) printf("Quorate "); + if (info.flags & VOTEQUORUM_INFO_WAIT_FOR_ALL) printf("WaitForAll "); + if (info.flags & VOTEQUORUM_INFO_LAST_MAN_STANDING) printf("LastManStanding "); + if (info.flags & VOTEQUORUM_INFO_AUTO_TIE_BREAKER) printf("AutoTieBreaker "); + if (info.flags & VOTEQUORUM_INFO_ALLOW_DOWNSCALE) printf("AllowDownscale "); + if (info.flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED) printf("Qdevice "); + printf("\n"); + } else { + fprintf(stderr, "Unable to get node info: %s\n", cs_strerror(err)); + } + + display_nodes_data(nodeid_format, name_format, sort_type); + + return err; +} + +/* + * return EXIT_SUCCESS if quorate + * EXIT_NOT_QUORATE if not quorate + * EXIT_FAILURE on error + */ +static int show_status(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type) +{ + int is_quorate; + int err; + + err=quorum_getquorate(q_handle, &is_quorate); + if (err != CS_OK) { + fprintf(stderr, "Unable to get cluster quorate status: %s\n", cs_strerror(err)); + goto quorum_err; + } + + err=quorum_trackstart(q_handle, CS_TRACK_CURRENT); + if (err != CS_OK) { + fprintf(stderr, "Unable to start quorum status tracking: %s\n", cs_strerror(err)); + goto quorum_err; + } + + g_called = 0; + while (g_called == 0 && err == CS_OK) { + err = quorum_dispatch(q_handle, CS_DISPATCH_ONE); + if (err != CS_OK) { + fprintf(stderr, "Unable to dispatch quorum status: %s\n", cs_strerror(err)); + } + } + + if (quorum_trackstop(q_handle) != CS_OK) { + fprintf(stderr, "Unable to stop quorum status tracking: %s\n", cs_strerror(err)); + } + + if (using_votequorum()) { + + if ( (err=votequorum_trackstart(v_handle, 0LL, CS_TRACK_CURRENT)) != CS_OK) { + fprintf(stderr, "Unable to start votequorum status tracking: %s\n", cs_strerror(err)); + goto quorum_err; + } + + g_vq_called = 0; + while (g_vq_called == 0 && err == CS_OK) { + err = votequorum_dispatch(v_handle, CS_DISPATCH_ONE); + if (err != CS_OK) { + fprintf(stderr, "Unable to dispatch votequorum status: %s\n", cs_strerror(err)); + } + } + } + +quorum_err: + if (err != CS_OK) { + return EXIT_FAILURE; + } + + err = display_quorum_data(is_quorate, nodeid_format, name_format, sort_type, 0); + if (err != CS_OK) { + return EXIT_FAILURE; + } + + return (is_quorate ? EXIT_SUCCESS : EXIT_NOT_QUORATE); +} + +static int monitor_status(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type) { + int err; + int loop = 0; + + if (q_type == QUORUM_FREE) { + printf("\nQuorum is not configured - cannot monitor\n"); + return show_status(nodeid_format, name_format, sort_type); + } + + err=quorum_trackstart(q_handle, CS_TRACK_CHANGES); + if (err != CS_OK) { + fprintf(stderr, "Unable to start quorum status tracking: %s\n", cs_strerror(err)); + goto quorum_err; + } + + if (using_votequorum()) { + if ( (err=votequorum_trackstart(v_handle, 0LL, CS_TRACK_CHANGES)) != CS_OK) { + fprintf(stderr, "Unable to start votequorum status tracking: %s\n", cs_strerror(err)); + goto quorum_err; + } + } + + + while (1) { + err = quorum_dispatch(q_handle, CS_DISPATCH_ONE); + if (err != CS_OK) { + fprintf(stderr, "Unable to dispatch quorum status: %s\n", cs_strerror(err)); + goto quorum_err; + } + if (using_votequorum()) { + g_vq_called = 0; + while (!g_vq_called) { + err = votequorum_dispatch(v_handle, CS_DISPATCH_ONE); + if (err != CS_OK) { + fprintf(stderr, "Unable to dispatch votequorum status: %s\n", cs_strerror(err)); + goto quorum_err; + } + } + } + + err = display_quorum_data(g_quorate, nodeid_format, name_format, sort_type, loop); + printf("\n"); + loop = 1; + if (err != CS_OK) { + fprintf(stderr, "Unable to display quorum data: %s\n", cs_strerror(err)); + goto quorum_err; + } + } + +quorum_err: + return EXIT_FAILURE; +} + +static int show_nodes(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type) +{ + int err; + int result = EXIT_FAILURE; + + err = quorum_trackstart(q_handle, CS_TRACK_CURRENT); + if (err != CS_OK) { + fprintf(stderr, "Unable to start quorum status tracking: %s\n", cs_strerror(err)); + goto err_exit; + } + + g_called = 0; + while (g_called == 0) { + err = quorum_dispatch(q_handle, CS_DISPATCH_ONE); + if (err != CS_OK) { + fprintf(stderr, "Unable to dispatch quorum status: %s\n", cs_strerror(err)); + goto err_exit; + } + } + + display_nodes_data(nodeid_format, name_format, sort_type); + + result = EXIT_SUCCESS; +err_exit: + return result; +} + +static int unregister_qdevice(void) +{ + int err; + struct votequorum_info info; + int result; + + result = EXIT_FAILURE; + + err = votequorum_getinfo(v_handle, our_nodeid, &info); + if (err != CS_OK) { + fprintf(stderr, "Unable to get quorum device info: %s\n", cs_strerror(err)); + goto err_exit; + } + + if (!(info.flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED)) { + result = EXIT_SUCCESS; + goto err_exit; + } + + err = votequorum_qdevice_unregister(v_handle, info.qdevice_name); + if (err != CS_OK) { + fprintf(stderr, "Unable to unregister quorum device: %s\n", cs_strerror(err)); + goto err_exit; + } + + result = EXIT_SUCCESS; +err_exit: + return result; +} + +/* + * return -1 on error + * 0 if OK + */ + +static int init_all(void) { + cmap_handle = 0; + q_handle = 0; + v_handle = 0; + c_handle = 0; + + if (cmap_initialize(&cmap_handle) != CS_OK) { + fprintf(stderr, "Cannot initialize CMAP service\n"); + cmap_handle = 0; + goto out; + } + + if (quorum_initialize(&q_handle, &q_callbacks, &q_type) != CS_OK) { + fprintf(stderr, "Cannot initialize QUORUM service\n"); + q_handle = 0; + goto out; + } + + if (corosync_cfg_initialize(&c_handle, &c_callbacks) != CS_OK) { + fprintf(stderr, "Cannot initialise CFG service\n"); + c_handle = 0; + goto out; + } + + if (using_votequorum() <= 0) { + return 0; + } + + if (votequorum_initialize(&v_handle, &v_callbacks) != CS_OK) { + fprintf(stderr, "Cannot initialise VOTEQUORUM service\n"); + v_handle = 0; + goto out; + } + + if (cmap_get_uint32(cmap_handle, "runtime.votequorum.this_node_id", &our_nodeid) != CS_OK) { + fprintf(stderr, "Unable to retrieve this_node_id\n"); + goto out; + } + + return 0; +out: + return -1; +} + +static void close_all(void) { + if (cmap_handle) { + cmap_finalize(cmap_handle); + } + if (q_handle) { + quorum_finalize(q_handle); + } + if (c_handle) { + corosync_cfg_finalize(c_handle); + } + if (v_handle) { + votequorum_finalize(v_handle); + } +} + +int main (int argc, char *argv[]) { + const char *options = "VHaslpmfe:v:hin:o:"; + int opt; + int votes = 0; + int ret = 0; + uint32_t nodeid = 0; + uint32_t nodeid_set = 0; + nodeid_format_t nodeid_format = NODEID_FORMAT_DECIMAL; + name_format_t address_format = ADDRESS_FORMAT_NAME; + command_t command_opt = CMD_SHOWSTATUS; + sorttype_t sort_opt = SORT_ADDR; + long long int l; + + while ( (opt = getopt(argc, argv, options)) != -1 ) { + switch (opt) { + case 'f': + command_opt = CMD_UNREGISTER_QDEVICE; + break; + case 's': + command_opt = CMD_SHOWSTATUS; + break; + case 'a': + g_show_all_addrs = 1; + break; + case 'm': + command_opt = CMD_MONITOR; + break; + case 'i': + address_format = ADDRESS_FORMAT_IP; + break; + case 'H': + nodeid_format = NODEID_FORMAT_HEX; + break; + case 'l': + command_opt = CMD_SHOWNODES; + break; + case 'p': + machine_parsable = 1; + break; + case 'e': + if (util_strtonum(optarg, 1, INT_MAX, &l) == -1) { + fprintf(stderr, "New expected votes value was not valid, try a positive number\n"); + exit(EXIT_FAILURE); + } + votes = l; + command_opt = CMD_SETEXPECTED; + break; + case 'n': + if (util_strtonum(optarg, 1, UINT_MAX, &l) == -1) { + fprintf(stderr, "The nodeid was not valid, try a positive number\n"); + exit(EXIT_FAILURE); + } + nodeid = l; + nodeid_set = 1; + break; + case 'v': + if (util_strtonum(optarg, 0, INT_MAX, &l) == -1) { + fprintf(stderr, "New votes value was not valid, try a positive number or zero\n"); + exit(EXIT_FAILURE); + } + votes = l; + command_opt = CMD_SETVOTES; + break; + case 'o': + if (strcmp(optarg, "a") == 0) { + sort_opt = SORT_ADDR; + } else if (strcmp(optarg, "i") == 0) { + sort_opt = SORT_NODEID; + } else if (strcmp(optarg, "n") == 0) { + sort_opt = SORT_NODENAME; + } else { + fprintf(stderr, "Invalid ordering option. valid orders are a(address), i(node ID) or n(name)\n"); + exit(EXIT_FAILURE); + } + break; + case 'V': + printf("corosync-quorumtool version: %s\n", VERSION); + exit(EXIT_SUCCESS); + break; + case 'h': + show_usage(argv[0]); + exit(EXIT_SUCCESS); + break; + case ':': + case '?': + default: + show_usage(argv[0]); + exit(EXIT_FAILURE); + break; + } + } + + if (init_all()) { + close_all(); + exit(EXIT_FAILURE); + } + + switch (command_opt) { + case CMD_SHOWNODES: + ret = show_nodes(nodeid_format, address_format, sort_opt); + break; + case CMD_SHOWSTATUS: + ret = show_status(nodeid_format, address_format, sort_opt); + break; + case CMD_SETVOTES: + if (using_votequorum() > 0) { + if (!nodeid_set) { + nodeid = our_nodeid; + } + ret = set_votes(nodeid, votes); + } else { + fprintf(stderr, "You cannot change node votes, corosync is not using votequorum\n"); + ret = EXIT_FAILURE; + } + break; + case CMD_SETEXPECTED: + if (using_votequorum() > 0) { + ret = set_expected(votes); + } else { + fprintf(stderr, "You cannot change expected votes, corosync is not using votequorum\n"); + ret = EXIT_FAILURE; + } + break; + case CMD_MONITOR: + ret = monitor_status(nodeid_format, address_format, sort_opt); + break; + case CMD_UNREGISTER_QDEVICE: + if (using_votequorum() > 0) { + ret = unregister_qdevice(); + } else { + fprintf(stderr, "You cannot unregister quorum device, corosync is not using votequorum\n"); + ret = EXIT_FAILURE; + } + break; + } + + close_all(); + + return (ret); +} diff --git a/tools/corosync-xmlproc.sh b/tools/corosync-xmlproc.sh new file mode 100644 index 0000000..c098958 --- /dev/null +++ b/tools/corosync-xmlproc.sh @@ -0,0 +1,57 @@ +#!@BASHPATH@ + +# Copyright (c) 2011 Red Hat, Inc. +# +# All rights reserved. +# +# Author: Jan Friesse (jfriesse@redhat.com) +# +# This software licensed under BSD license, the text of which follows: +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# - Neither the name of the Red Hat, Inc. nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +XSLT_PROC=xsltproc + +usage() { + echo "$0 input_config [output]" + echo " where input_config is valid XML configuration file" + + exit 1 +} + +[ "$1" == "" ] && usage + +$XSLT_PROC -V >/dev/null 2>&1 +if [ "$?" != 0 ];then + echo "Can't find xslt processor $XSLT_PROC" + exit 2 +fi + +# TODO: +# Validation should occur before actual processing + +[ "$2" != "" ] && out_param="-o $2" + +$XSLT_PROC --stringparam inputfile "$1" $out_param @DATADIR@/corosync/xml2conf.xsl "$1" diff --git a/tools/util.c b/tools/util.c new file mode 100644 index 0000000..f2ef5fd --- /dev/null +++ b/tools/util.c @@ -0,0 +1,35 @@ +#include <stdlib.h> +#include <errno.h> + +#include "util.h" + +/* + * Safer wrapper of strtoll. Return 0 on success, otherwise -1. + * Idea from corosync-qdevice project + */ +int +util_strtonum(const char *str, long long int min_val, long long int max_val, + long long int *res) +{ + long long int tmp_ll; + char *ep; + + if (min_val > max_val) { + return (-1); + } + + errno = 0; + + tmp_ll = strtoll(str, &ep, 10); + if (ep == str || *ep != '\0' || errno != 0) { + return (-1); + } + + if (tmp_ll < min_val || tmp_ll > max_val) { + return (-1); + } + + *res = tmp_ll; + + return (0); +} diff --git a/tools/util.h b/tools/util.h new file mode 100644 index 0000000..619cf67 --- /dev/null +++ b/tools/util.h @@ -0,0 +1,15 @@ +#ifndef COROSYNC_TOOLS_UTIL_H_DEFINED +#define COROSYNC_TOOLS_UTIL_H_DEFINED + +#ifdef __cplusplus +extern "C" { +#endif + +extern int util_strtonum(const char *str, long long int min_val, + long long int max_val, long long int *res); + +#ifdef __cplusplus +} +#endif + +#endif /* COROSYNC_TOOLS_UTIL_H_DEFINED */ |