From b6d7a484804eaf39bf6074efd38ddcb78fd2a420 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 31 Jan 2012 21:21:53 +0000 Subject: [PATCH] Automatically detect whether corosync clvmd needs to use confdb or cmap. (fabio) --- WHATS_NEW | 1 + configure | 119 +++++++++++++++++++++++++++++++-- configure.in | 41 ++++++++++-- daemons/clvmd/Makefile.in | 6 +- daemons/clvmd/clvmd-corosync.c | 62 ++++++++++++++++- lib/misc/configure.h.in | 3 + 6 files changed, 216 insertions(+), 16 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index a458e29e6..422b6b0af 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.90 - =================================== + Automatically detect whether corosync clvmd needs to use confdb or cmap. Fix data% report for thin volume used as origin for non-thin snapshot. Version 2.02.89 - 26th January 2012 diff --git a/configure b/configure index 7c1cd439d..27b45d189 100755 --- a/configure +++ b/configure @@ -694,6 +694,8 @@ DLM_LIBS DLM_CFLAGS CPG_LIBS CPG_CFLAGS +CMAP_LIBS +CMAP_CFLAGS CONFDB_LIBS CONFDB_CFLAGS SALCK_LIBS @@ -873,6 +875,8 @@ SALCK_CFLAGS SALCK_LIBS CONFDB_CFLAGS CONFDB_LIBS +CMAP_CFLAGS +CMAP_LIBS CPG_CFLAGS CPG_LIBS DLM_CFLAGS @@ -1628,6 +1632,8 @@ Some influential environment variables: CONFDB_CFLAGS C compiler flags for CONFDB, overriding pkg-config CONFDB_LIBS linker flags for CONFDB, overriding pkg-config + CMAP_CFLAGS C compiler flags for CMAP, overriding pkg-config + CMAP_LIBS linker flags for CMAP, overriding pkg-config CPG_CFLAGS C compiler flags for CPG, overriding pkg-config CPG_LIBS linker flags for CPG, overriding pkg-config DLM_CFLAGS C compiler flags for DLM, overriding pkg-config @@ -7514,6 +7520,7 @@ $as_echo "yes" >&6; } HAVE_COROSYNC=yes fi CHECKCONFDB=yes + CHECKCMAP=yes fi if test x$BUILDCOROSYNC = xyes; then @@ -7759,11 +7766,110 @@ $as_echo "no pkg for confdb, using -lconfdb" >&6; } CONFDB_LIBS="-lconfdb" HAVE_CONFDB=yes fi +fi + + +if test x$CHECKCMAP = xyes; then + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CMAP" >&5 +$as_echo_n "checking for CMAP... " >&6; } + +if test -n "$CMAP_CFLAGS"; then + pkg_cv_CMAP_CFLAGS="$CMAP_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcmap\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libcmap") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_CMAP_CFLAGS=`$PKG_CONFIG --cflags "libcmap" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$CMAP_LIBS"; then + pkg_cv_CMAP_LIBS="$CMAP_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcmap\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libcmap") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_CMAP_LIBS=`$PKG_CONFIG --libs "libcmap" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } - if test x$BUILDCOROSYNC = xyes && \ - test x$HAVE_CONFDB != xyes && +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + CMAP_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libcmap" 2>&1` + else + CMAP_PKG_ERRORS=`$PKG_CONFIG --print-errors "libcmap" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$CMAP_PKG_ERRORS" >&5 + + HAVE_CMAP=no +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + HAVE_CMAP=no +else + CMAP_CFLAGS=$pkg_cv_CMAP_CFLAGS + CMAP_LIBS=$pkg_cv_CMAP_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + HAVE_CMAP=yes +fi + + for ac_header in corosync/cmap.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "corosync/cmap.h" "ac_cv_header_corosync_cmap_h" "$ac_includes_default" +if test "x$ac_cv_header_corosync_cmap_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_COROSYNC_CMAP_H 1 +_ACEOF + HAVE_CMAP_H=yes +else + HAVE_CMAP_H=no +fi + +done + + + if test x$HAVE_CMAP != xyes && \ + test x$HAVE_CMAP_H = xyes; then + check_lib_no_libs cmap cmap_initialize + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no pkg for cmap, using -lcmap" >&5 +$as_echo "no pkg for cmap, using -lcmap" >&6; } + CMAP_LIBS="-lcmap" + HAVE_CMAP=yes + fi +fi + +if test x$BUILDCOROSYNC = xyes; then + if test x$HAVE_CMAP != xyes && \ + test x$HAVE_CONFDB != xyes && \ test x$CLVMD != xall; then - as_fn_error $? "bailing out... confdb library is required" "$LINENO" 5 + as_fn_error $? "bailing out... cmap (corosync >= 2.0) or confdb (corosync < 2.0) library is required" "$LINENO" 5 fi fi @@ -7968,12 +8074,13 @@ $as_echo "Enabling clvmd cman cluster manager" >&6; } if test x$HAVE_COROSYNC = xyes && \ test x$HAVE_QUORUM = xyes && \ test x$HAVE_CPG = xyes && \ - test x$HAVE_DLM = xyes && \ - test x$HAVE_CONFDB = xyes; then + test x$HAVE_DLM = xyes; then + if test x$HAVE_CONFDB = xyes || test x$HAVE_CMAP = xyes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: Enabling clvmd corosync cluster manager" >&5 $as_echo "Enabling clvmd corosync cluster manager" >&6; } CLVMD="$CLVMD,corosync" CLVMD_CMANAGERS="$CLVMD_CMANAGERS corosync" + fi fi if test x$HAVE_COROSYNC = xyes && \ test x$HAVE_CPG = xyes && \ @@ -10227,6 +10334,8 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[()]' '{print $2}'` + + diff --git a/configure.in b/configure.in index 96b5f51ec..ab04ebbdd 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ ############################################################################### ## Copyright (C) 2000-2004 Sistina Software, Inc. All rights reserved. -## Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. +## Copyright (C) 2004-2012 Red Hat, Inc. All rights reserved. ## ## This copyrighted material is made available to anyone wishing to use, ## modify, copy, or redistribute it subject to the terms and conditions @@ -549,6 +549,7 @@ if test x$BUILDCOROSYNC = xyes || \ test x$BUILDOPENAIS = xyes; then PKG_CHECK_MODULES(COROSYNC, corosync, [HAVE_COROSYNC=yes], $bailout) CHECKCONFDB=yes + CHECKCMAP=yes fi dnl -- Look for corosync libraries if required. @@ -567,7 +568,7 @@ fi dnl -- Below are checks for libraries common to more than one build. dnl -- Check confdb library. -dnl -- mandatory for corosync build. +dnl -- mandatory for corosync < 2.0 build. dnl -- optional for openais/cman build. if test x$CHECKCONFDB = xyes; then @@ -586,11 +587,34 @@ if test x$CHECKCONFDB = xyes; then CONFDB_LIBS="-lconfdb" HAVE_CONFDB=yes fi +fi + +dnl -- Check cmap library +dnl -- mandatory for corosync >= 2.0 build. + +if test x$CHECKCMAP = xyes; then + PKG_CHECK_MODULES(CMAP, libcmap, + [HAVE_CMAP=yes], + [HAVE_CMAP=no]) - if test x$BUILDCOROSYNC = xyes && \ - test x$HAVE_CONFDB != xyes && + AC_CHECK_HEADERS(corosync/cmap.h, + [HAVE_CMAP_H=yes], + [HAVE_CMAP_H=no]) + + if test x$HAVE_CMAP != xyes && \ + test x$HAVE_CMAP_H = xyes; then + check_lib_no_libs cmap cmap_initialize + AC_MSG_RESULT([no pkg for cmap, using -lcmap]) + CMAP_LIBS="-lcmap" + HAVE_CMAP=yes + fi +fi + +if test x$BUILDCOROSYNC = xyes; then + if test x$HAVE_CMAP != xyes && \ + test x$HAVE_CONFDB != xyes && \ test x$CLVMD != xall; then - AC_MSG_ERROR([bailing out... confdb library is required]) + AC_MSG_ERROR([bailing out... cmap (corosync >= 2.0) or confdb (corosync < 2.0) library is required]) fi fi @@ -629,11 +653,12 @@ if test x$CLVMD = xall; then if test x$HAVE_COROSYNC = xyes && \ test x$HAVE_QUORUM = xyes && \ test x$HAVE_CPG = xyes && \ - test x$HAVE_DLM = xyes && \ - test x$HAVE_CONFDB = xyes; then + test x$HAVE_DLM = xyes; then + if test x$HAVE_CONFDB = xyes || test x$HAVE_CMAP = xyes; then AC_MSG_RESULT([Enabling clvmd corosync cluster manager]) CLVMD="$CLVMD,corosync" CLVMD_CMANAGERS="$CLVMD_CMANAGERS corosync" + fi fi if test x$HAVE_COROSYNC = xyes && \ test x$HAVE_CPG = xyes && \ @@ -1311,6 +1336,8 @@ AC_SUBST(CLVMD_CMANAGERS) AC_SUBST(CLVMD_PATH) AC_SUBST(CMAN_CFLAGS) AC_SUBST(CMAN_LIBS) +AC_SUBST(CMAP_CFLAGS) +AC_SUBST(CMAP_LIBS) AC_SUBST(CMDLIB) AC_SUBST(CONFDB_CFLAGS) AC_SUBST(CONFDB_LIBS) diff --git a/daemons/clvmd/Makefile.in b/daemons/clvmd/Makefile.in index dcdabab05..9ca11baf1 100644 --- a/daemons/clvmd/Makefile.in +++ b/daemons/clvmd/Makefile.in @@ -17,6 +17,8 @@ top_builddir = @top_builddir@ CMAN_LIBS = @CMAN_LIBS@ CMAN_CFLAGS = @CMAN_CFLAGS@ +CMAP_LIBS = @CMAP_LIBS@ +CMAP_CFLAGS = @CMAP_CFLAGS@ CONFDB_LIBS = @CONFDB_LIBS@ CONFDB_CFLAGS = @CONFDB_CFLAGS@ CPG_LIBS = @CPG_LIBS@ @@ -54,8 +56,8 @@ endif ifneq (,$(findstring corosync,, "@CLVMD@,")) SOURCES += clvmd-corosync.c - LMLIBS += $(CONFDB_LIBS) $(CPG_LIBS) $(DLM_LIBS) $(QUORUM_LIBS) - CFLAGS += $(CONFDB_CFLAGS) $(CPG_CFLAGS) $(DLM_CFLAGS) $(QUORUM_CFLAGS) + LMLIBS += $(CMAP_LIBS) $(CONFDB_LIBS) $(CPG_LIBS) $(DLM_LIBS) $(QUORUM_LIBS) + CFLAGS += $(CMAP_CFLAGS) $(CONFDB_CFLAGS) $(CPG_CFLAGS) $(DLM_CFLAGS) $(QUORUM_CFLAGS) DEFS += -DUSE_COROSYNC endif diff --git a/daemons/clvmd/clvmd-corosync.c b/daemons/clvmd/clvmd-corosync.c index e929681ce..d85ec1e61 100644 --- a/daemons/clvmd/clvmd-corosync.c +++ b/daemons/clvmd/clvmd-corosync.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Red Hat, Inc. All rights reserved. + * Copyright (C) 2009-2012 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * @@ -30,7 +30,15 @@ #include #include -#include + +#ifdef HAVE_COROSYNC_CONFDB_H +# include +#elif defined HAVE_COROSYNC_CMAP_H +# include +#else +# error "Either HAVE_COROSYNC_CONFDB_H or HAVE_COROSYNC_CMAP_H must be defined." +#endif + #include #include @@ -274,6 +282,10 @@ static int _init_cluster(void) { cs_error_t err; +#ifdef QUORUM_SET /* corosync/quorum.h */ + uint32_t quorum_type; +#endif + node_hash = dm_hash_create(100); err = cpg_initialize(&cpg_handle, @@ -285,8 +297,21 @@ static int _init_cluster(void) return cs_to_errno(err); } +#ifdef QUORUM_SET + err = quorum_initialize(&quorum_handle, + &quorum_callbacks, + &quorum_type); + + if (quorum_type != QUORUM_SET) { + syslog(LOG_ERR, "Corosync quorum service is not configured"); + DEBUGLOG("Corosync quorum service is not configured"); + return EINVAL; + } +#else err = quorum_initialize(&quorum_handle, &quorum_callbacks); +#endif + if (err != CS_OK) { syslog(LOG_ERR, "Cannot initialise Corosync quorum service: %d", err); @@ -551,6 +576,7 @@ static int _cluster_send_message(const void *buf, int msglen, const char *csid, return cs_to_errno(err); } +#ifdef HAVE_COROSYNC_CONFDB_H /* * We are not necessarily connected to a Red Hat Cluster system, * but if we are, this returns the cluster name from cluster.conf. @@ -597,6 +623,38 @@ out: return 0; } +#elif defined HAVE_COROSYNC_CMAP_H + +static int _get_cluster_name(char *buf, int buflen) +{ + cmap_handle_t cmap_handle = 0; + int result; + char *name = NULL; + + /* This is a default in case everything else fails */ + strncpy(buf, "Corosync", buflen); + + /* Look for a cluster name in cmap */ + result = cmap_initialize(&cmap_handle); + if (result != CS_OK) + return 0; + + result = cmap_get_string(cmap_handle, "totem.cluster_name", &name); + if (result != CS_OK) + goto out; + + memset(buf, 0, buflen); + strncpy(buf, name, buflen - 1); + +out: + if (name) + free(name); + cmap_finalize(cmap_handle); + return 0; +} + +#endif + static struct cluster_ops _cluster_corosync_ops = { .name = "corosync", .cluster_init_completed = NULL, diff --git a/lib/misc/configure.h.in b/lib/misc/configure.h.in index 707445ad8..1c86c1592 100644 --- a/lib/misc/configure.h.in +++ b/lib/misc/configure.h.in @@ -87,6 +87,9 @@ /* Define to 1 if your system has a working `chown' function. */ #undef HAVE_CHOWN +/* Define to 1 if you have the header file. */ +#undef HAVE_COROSYNC_CMAP_H + /* Define to 1 if you have the header file. */ #undef HAVE_COROSYNC_CONFDB_H -- 2.43.5