From 0eaf487c54cf0529dccee4d7ed6d43fed7725849 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 16 Oct 2018 12:37:13 +0100 Subject: [PATCH] Include all upstream patches since 0.5. Enable systemd init scripts (RHBZ#1592400). --- ...plemental-groups-correctly-when-drop.patch | 6 +- ...n-error-indication-up-through-get_me.patch | 4 +- 0003-Make-Xen-Libraries-really-optional.patch | 4 +- 0004-Add-contact-info-to-README.patch | 34 ++ ...nd-location-of-the-vhostmd.conf-file.patch | 41 +++ ...-typo-in-vhostmd.init-virutalization.patch | 25 ++ 0007-Modernize-build-files.patch | 61 ++++ 0008-Add-systemd-service-file.patch | 128 +++++++ 0009-Remove-xenctrl-support.patch | 311 ++++++++++++++++++ 0010-Remove-support-for-libxenstat.patch | 222 +++++++++++++ 0011-Fix-compilation-with-xenstore.patch | 58 ++++ 0012-Fix-typo-in-systemd-service-file.patch | 24 ++ 0013-Fix-help-option.patch | 70 ++++ 0014-Add-SIGPIPE-handler-and-reconnect.patch | 110 +++++++ 0015-fix-deallocation-in-vu_vm_free.patch | 40 +++ ...igure-fix-logic-in-init-script-check.patch | 39 +++ ...f-Improve-example-configuration-file.patch | 175 ++++++++++ vhostmd.spec | 82 ++--- 18 files changed, 1387 insertions(+), 47 deletions(-) create mode 100644 0004-Add-contact-info-to-README.patch create mode 100644 0005-Fix-name-and-location-of-the-vhostmd.conf-file.patch create mode 100644 0006-fix-typo-in-vhostmd.init-virutalization.patch create mode 100644 0007-Modernize-build-files.patch create mode 100644 0008-Add-systemd-service-file.patch create mode 100644 0009-Remove-xenctrl-support.patch create mode 100644 0010-Remove-support-for-libxenstat.patch create mode 100644 0011-Fix-compilation-with-xenstore.patch create mode 100644 0012-Fix-typo-in-systemd-service-file.patch create mode 100644 0013-Fix-help-option.patch create mode 100644 0014-Add-SIGPIPE-handler-and-reconnect.patch create mode 100644 0015-fix-deallocation-in-vu_vm_free.patch create mode 100644 0016-configure-fix-logic-in-init-script-check.patch create mode 100644 0017-conf-Improve-example-configuration-file.patch diff --git a/0001-Security-Set-supplemental-groups-correctly-when-drop.patch b/0001-Security-Set-supplemental-groups-correctly-when-drop.patch index 9b68102..25ec0c0 100644 --- a/0001-Security-Set-supplemental-groups-correctly-when-drop.patch +++ b/0001-Security-Set-supplemental-groups-correctly-when-drop.patch @@ -1,8 +1,8 @@ From 8684995d87e08fadd44e1814e810c770a1f60273 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 5 Mar 2012 14:48:08 +0000 -Subject: [PATCH 1/3] Security: Set supplemental groups correctly when dropping - privileges. +Subject: [PATCH 01/17] Security: Set supplemental groups correctly when + dropping privileges. https://bugzilla.redhat.com/show_bug.cgi?id=741289 @@ -36,5 +36,5 @@ index 21763af..90ba76d 100644 vu_log (VHOSTMD_ERR, "setuid: %d: %m", pw->pw_uid); goto out; -- -1.8.3.1 +2.19.0.rc0 diff --git a/0002-libmetrics-Return-error-indication-up-through-get_me.patch b/0002-libmetrics-Return-error-indication-up-through-get_me.patch index bd9e5eb..e5844b1 100644 --- a/0002-libmetrics-Return-error-indication-up-through-get_me.patch +++ b/0002-libmetrics-Return-error-indication-up-through-get_me.patch @@ -1,7 +1,7 @@ From efba4feaef25ea7efc9e35cfa6e92b69784aa88f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 10 May 2012 10:14:50 +0100 -Subject: [PATCH 2/3] libmetrics: Return error indication up through +Subject: [PATCH 02/17] libmetrics: Return error indication up through get_metric. If private function 'get_mdef' returns an error, then the error is not @@ -25,5 +25,5 @@ index d049458..6d5c26f 100644 *mdef = NULL; -- -1.8.3.1 +2.19.0.rc0 diff --git a/0003-Make-Xen-Libraries-really-optional.patch b/0003-Make-Xen-Libraries-really-optional.patch index 0a97add..ba06222 100644 --- a/0003-Make-Xen-Libraries-really-optional.patch +++ b/0003-Make-Xen-Libraries-really-optional.patch @@ -1,7 +1,7 @@ From 8fd4d847277bb9a7e53f8bb3f3f935004d8e5cc4 Mon Sep 17 00:00:00 2001 From: Eduardo Otubo Date: Thu, 2 Aug 2012 19:42:00 -0300 -Subject: [PATCH 3/3] Make Xen Libraries really optional +Subject: [PATCH 03/17] Make Xen Libraries really optional The default behavior in the configure script was to make with_xenstore set to 'true', which caused the compilation to break in my case because @@ -47,5 +47,5 @@ index ee9c446..fb4309b 100644 AC_OUTPUT(vhostmd/Makefile -- -1.8.3.1 +2.19.0.rc0 diff --git a/0004-Add-contact-info-to-README.patch b/0004-Add-contact-info-to-README.patch new file mode 100644 index 0000000..de38803 --- /dev/null +++ b/0004-Add-contact-info-to-README.patch @@ -0,0 +1,34 @@ +From 7a2936ec4e6bd5a47ef8ac4f4b889c70b8a78e9b Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Wed, 9 Mar 2016 18:40:56 -0700 +Subject: [PATCH 04/17] Add contact info to README + +Extended README with contact info (virt-tools-list) for +comments, suggestions, and patches. +--- + README | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/README b/README +index 2755e4f..788ffe4 100644 +--- a/README ++++ b/README +@@ -15,6 +15,15 @@ surfaced read-only to virtual machines using tools provided by the host's + virtualization platform. + + ++Contact ++------- ++ ++All comments / suggestions / patches should be directed to the ++virt-tools-list mailing list: ++ ++ http://www.redhat.com/mailman/listinfo/virt-tools-list ++ ++ + Usage + ----- + +-- +2.19.0.rc0 + diff --git a/0005-Fix-name-and-location-of-the-vhostmd.conf-file.patch b/0005-Fix-name-and-location-of-the-vhostmd.conf-file.patch new file mode 100644 index 0000000..bb4999e --- /dev/null +++ b/0005-Fix-name-and-location-of-the-vhostmd.conf-file.patch @@ -0,0 +1,41 @@ +From 972ac212abcf0eacd7039b3a5987bd9ae2083607 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Wed, 22 Feb 2017 11:39:59 +0000 +Subject: [PATCH 05/17] Fix name and location of the vhostmd.conf file. + +Thanks: Xianghua Chen +Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1359593 +--- + README | 2 +- + docs/man/vhostmd.8 | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/README b/README +index 788ffe4..cb23226 100644 +--- a/README ++++ b/README +@@ -32,7 +32,7 @@ vhostmd [options] + Options: + -v | --verbose Verbose messages + -d | --no-daemonize Process will not daemonize +- -f | --config Configuration file (/etc/vhostmd.xml default) ++ -f | --config Configuration file (/etc/vhostmd/vhostmd.conf default) + -p | --pid-file PID file (/var/run/vhostmd.pid default) + + +diff --git a/docs/man/vhostmd.8 b/docs/man/vhostmd.8 +index dfcb301..2c73adc 100644 +--- a/docs/man/vhostmd.8 ++++ b/docs/man/vhostmd.8 +@@ -32,7 +32,7 @@ Drop root privileges and run as the named non-root user. + Specify an alternate path for vhostmd to record its process-id in. Normally /var/run/vhostmd.pid + .TP + .B \-f, --config +-Specify a different configuration file. Normally /etc/vhostmd.xml ++Specify a different configuration file. Normally /etc/vhostmd/vhostmd.conf + .SH CONFIG FILE + At startup, vhostmd reads + .I /etc/vhostmd/vhostmd.conf, +-- +2.19.0.rc0 + diff --git a/0006-fix-typo-in-vhostmd.init-virutalization.patch b/0006-fix-typo-in-vhostmd.init-virutalization.patch new file mode 100644 index 0000000..cdba1dc --- /dev/null +++ b/0006-fix-typo-in-vhostmd.init-virutalization.patch @@ -0,0 +1,25 @@ +From 3e4df5dd16c59a804373564602aa045b0599aa82 Mon Sep 17 00:00:00 2001 +From: Johannes Kastl +Date: Sun, 6 May 2018 16:23:05 +0200 +Subject: [PATCH 06/17] fix typo in vhostmd.init: virutalization + +--- + vhostmd.init | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/vhostmd.init b/vhostmd.init +index 71f9ab8..23d7874 100644 +--- a/vhostmd.init ++++ b/vhostmd.init +@@ -11,7 +11,7 @@ + # Required-Stop: $remote_fs $null + # Should-Stop: $null + # Default-Stop: 0 1 2 4 6 +-# Short-Description: daemon for collecting virutalization host metrics ++# Short-Description: daemon for collecting virtualization host metrics + # Description: This is a daemon for collecting virtualization host + # metrics and writing them to a file-backed disk. + ### END INIT INFO +-- +2.19.0.rc0 + diff --git a/0007-Modernize-build-files.patch b/0007-Modernize-build-files.patch new file mode 100644 index 0000000..408f0f6 --- /dev/null +++ b/0007-Modernize-build-files.patch @@ -0,0 +1,61 @@ +From 498bace866c16842d677a00b1df8ab62e0724d55 Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Thu, 27 Apr 2017 09:36:28 -0600 +Subject: [PATCH 07/17] Modernize build files + +Some of the constructs used in the configure script and Makefiles +are a bit outdated, e.g. use of '$(mkinstalldirs)' instead of +'$(MKDIR_P)'. Change these old constructs to their modern counterparts. + +Signed-off-by: Jim Fehlig +--- + Makefile.am | 15 +++++++-------- + configure.ac | 2 +- + 2 files changed, 8 insertions(+), 9 deletions(-) + +diff --git a/Makefile.am b/Makefile.am +index e11963a..8234d98 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -8,11 +8,10 @@ EXTRA_DIST = $(doc_DATA) vhostmd.init vhostmd.spec autogen.sh + AUTOMAKE_OPTIONS=dist-bzip2 + + install-data-local: +- $(mkinstalldirs) $(DESTDIR)/etc/vhostmd +- $(mkinstalldirs) $(DESTDIR)/etc/init.d +- $(mkinstalldirs) $(DESTDIR)/usr/sbin +- -@INSTALL@ -m 0644 $(srcdir)/vhostmd.xml $(DESTDIR)/etc/vhostmd/vhostmd.conf +- -@INSTALL@ -m 0644 $(srcdir)/vhostmd.dtd $(DESTDIR)/etc/vhostmd +- -@INSTALL@ -m 0644 $(srcdir)/metric.dtd $(DESTDIR)/etc/vhostmd +- -@INSTALL@ -m 0755 $(srcdir)/vhostmd.init $(DESTDIR)/etc/init.d/vhostmd +- ++ $(MKDIR_P) $(DESTDIR)/etc/vhostmd ++ $(MKDIR_P) $(DESTDIR)/etc/init.d ++ $(MKDIR_P) $(DESTDIR)/usr/sbin ++ $(INSTALL_DATA) $(srcdir)/vhostmd.xml $(DESTDIR)/etc/vhostmd/vhostmd.conf ++ $(INSTALL_DATA) $(srcdir)/vhostmd.dtd $(DESTDIR)/etc/vhostmd ++ $(INSTALL_DATA) $(srcdir)/metric.dtd $(DESTDIR)/etc/vhostmd ++ $(INSTALL_SCRIPT) $(srcdir)/vhostmd.init $(DESTDIR)/etc/init.d/vhostmd +diff --git a/configure.ac b/configure.ac +index fb4309b..27c8488 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -4,6 +4,7 @@ AC_CONFIG_SRCDIR(vhostmd/vhostmd.c) + AC_CONFIG_HEADERS([config.h]) + + AC_GNU_SOURCE ++AM_INIT_AUTOMAKE + + AC_PROG_LIBTOOL + +@@ -21,7 +22,6 @@ AC_SUBST(topdir) + + AC_CONFIG_FILES([Makefile]) + +-AM_INIT_AUTOMAKE + + # Checks for programs. + AM_PROG_CC_C_O +-- +2.19.0.rc0 + diff --git a/0008-Add-systemd-service-file.patch b/0008-Add-systemd-service-file.patch new file mode 100644 index 0000000..b92eadc --- /dev/null +++ b/0008-Add-systemd-service-file.patch @@ -0,0 +1,128 @@ +From d12766463a9de3b8490e6a552db83bf7d4853896 Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Thu, 27 Apr 2017 09:52:02 -0600 +Subject: [PATCH 08/17] Add systemd service file + +vhostmd is long overdue for a systemd service file. Add one, and +while at it support specifying the type of init system in the +configure script. + +Signed-off-by: Jim Fehlig +--- + Makefile.am | 36 +++++++++++++++++++++++++++++++++--- + configure.ac | 24 +++++++++++++++++++++++- + vhostmd.service | 14 ++++++++++++++ + 3 files changed, 70 insertions(+), 4 deletions(-) + create mode 100644 vhostmd.service + +diff --git a/Makefile.am b/Makefile.am +index 8234d98..4f8af15 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -7,11 +7,41 @@ EXTRA_DIST = $(doc_DATA) vhostmd.init vhostmd.spec autogen.sh + + AUTOMAKE_OPTIONS=dist-bzip2 + +-install-data-local: ++install-data-local: install-init-systemv install-init-systemd + $(MKDIR_P) $(DESTDIR)/etc/vhostmd +- $(MKDIR_P) $(DESTDIR)/etc/init.d +- $(MKDIR_P) $(DESTDIR)/usr/sbin + $(INSTALL_DATA) $(srcdir)/vhostmd.xml $(DESTDIR)/etc/vhostmd/vhostmd.conf + $(INSTALL_DATA) $(srcdir)/vhostmd.dtd $(DESTDIR)/etc/vhostmd + $(INSTALL_DATA) $(srcdir)/metric.dtd $(DESTDIR)/etc/vhostmd ++ ++uninstall-local: uninstall-init-systemv uninstall-init-systemd ++ rm -f $(DESTDIR)/etc/vhostmd/vhostmd.conf ++ rm -f $(DESTDIR)/etc/vhostmd/vhostmd.dtd ++ rm -f $(DESTDIR)/etc/vhostmd/metric.dtd ++ rmdir $(DESTDIR)/etc/vhostmd || : ++ ++if INIT_SCRIPT_SYSTEMV ++install-init-systemv: $(srcdir)/vhostmd.init ++ $(MKDIR_P) $(DESTDIR)$(sysconfdir)/init.d + $(INSTALL_SCRIPT) $(srcdir)/vhostmd.init $(DESTDIR)/etc/init.d/vhostmd ++ ++uninstall-init-systemv: ++ rm -f $(DESTDIR)$(sysconfdir)/init.d/vhostmd ++ rmdir $(DESTDIR)$(sysconfdir)/init.d || : ++else ! INIT_SCRIPT_SYSTEMV ++install-init-systemv: ++uninstall-init-systemv: ++endif ! INIT_SCRIPT_SYSTEMV ++ ++if INIT_SCRIPT_SYSTEMD ++SYSTEMD_UNIT_DIR = $(prefix)/lib/systemd/system ++install-init-systemd: $(srcdir)/vhostmd.service ++ $(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNIT_DIR) ++ $(INSTALL_DATA) $(srcdir)/vhostmd.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/vhostmd.service ++ ++uninstall-init-systemd: ++ rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/vhostmd.service ++ rmdir $(DESTDIR)$(SYSTEMD_UNIT_DIR) || : ++else ! INIT_SCRIPT_SYSTEMD ++install-init-systemd: ++uninstall-init-systemd: ++endif ! INIT_SCRIPT_SYSTEMD +diff --git a/configure.ac b/configure.ac +index 27c8488..b0a07c7 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1,4 +1,4 @@ +-AC_INIT(Virtual Host Metrics Daemon, 0.5, jfehlig@novell.com, vhostmd) ++AC_INIT(Virtual Host Metrics Daemon, 0.5, jfehlig@suse.com, vhostmd) + + AC_CONFIG_SRCDIR(vhostmd/vhostmd.c) + AC_CONFIG_HEADERS([config.h]) +@@ -82,6 +82,28 @@ AC_ARG_WITH([xenstore], + esac],[AC_CHECK_HEADER(xs.h, with_xenstore=true)]) + AM_CONDITIONAL(WITH_XENSTORE, test x$with_xenstore = xtrue) + ++# Configure argument to support type of init system ++AC_ARG_WITH([init_script], ++ [AS_HELP_STRING([--with-init-script], ++ [Type of init script to install: systemv, systemd, check @<:@default=check@:>@])], ++ [], ++ [with_init_script=check]) ++init_systemv=no ++init_systemd=no ++if test "$with_init_script" = check && type systemctl >/dev/null 2>&1; then ++ init_systemd=yes ++else ++ init_systemv=yes ++fi ++case "${with_init_script}" in ++ systemv) init_systemv=yes;; ++ systemd) init_systemd=yes;; ++ check) ;; ++ *) AC_MSG_ERROR([Unknown initscript type $with_init_script]);; ++esac ++AM_CONDITIONAL([INIT_SCRIPT_SYSTEMV], test "$init_systemv" = "yes") ++AM_CONDITIONAL([INIT_SCRIPT_SYSTEMD], test "$init_systemd" = "yes") ++ + AC_OUTPUT(vhostmd/Makefile + include/Makefile + libmetrics/Makefile +diff --git a/vhostmd.service b/vhostmd.service +new file mode 100644 +index 0000000..9d50523 +--- /dev/null ++++ b/vhostmd.service +@@ -0,0 +1,14 @@ ++[Unit] ++Description=Daemon for collecting virutalization host metrics ++After=libvirtd.service ++Documentation=man:vhostmd(8) ++ ++[Service] ++Type=forking ++ExecStart=/usr/sbin/vhostmd ++ExecReload=/bin/kill -HUP $MAINPID ++KillMode=process ++Restart=on-failure ++ ++[Install] ++WantedBy=multi-user.target +-- +2.19.0.rc0 + diff --git a/0009-Remove-xenctrl-support.patch b/0009-Remove-xenctrl-support.patch new file mode 100644 index 0000000..0bf32a4 --- /dev/null +++ b/0009-Remove-xenctrl-support.patch @@ -0,0 +1,311 @@ +From 3dd984f7299d1364d6e7a902776e1fcfd83d6370 Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Wed, 6 Jun 2018 14:40:33 -0600 +Subject: [PATCH 09/17] Remove xenctrl support + +The xenctrl interface has changed over the years, causing +the associated code in vhostmd to no longer compile. Instead +of trying to get this low-level xen interface working again, +simply remove it from vhostmd. libvirt or custom "actions" +should be used to gather metrics. + +Signed-off-by: Jim Fehlig +--- + configure.ac | 21 +----- + include/util.h | 2 - + vhostmd/Makefile.am | 17 +---- + vhostmd/metric.c | 5 -- + vhostmd/vhostmd.c | 4 -- + vhostmd/xenctrl-util.c | 148 ----------------------------------------- + 6 files changed, 4 insertions(+), 193 deletions(-) + delete mode 100644 vhostmd/xenctrl-util.c + +diff --git a/configure.ac b/configure.ac +index b0a07c7..2e88bfd 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -51,26 +51,7 @@ AC_ARG_ENABLE([libxenstat], + esac],[AC_CHECK_HEADER(xenstat.h, libxenstat=true, libxenstat=false)]) + AM_CONDITIONAL(LIBXENSTAT, test x$libxenstat = xtrue) + +-# Configure argument to support using xenctrl library for vm enumeration +-AC_ARG_ENABLE([xenctrl], +-[ --enable-xenctrl use xenctrl specific vm enumeration instead of libvirt], +- [case "${enableval}" in +- yes) xenctrl=true +- CFLAGS="$CFLAGS -DXENCTRL" +- ;; +- no) xenctrl=false ;; +- *) AC_MSG_ERROR(bad value ${enableval} for --enable-xenctrl) ;; +- esac],[AC_CHECK_HEADER(xenctrl.h, xenctrl=true, xenctrl=false,)]) +-AM_CONDITIONAL(XENCTRL, test x$xenctrl = xtrue) +- +-libvirt=false +-AM_CONDITIONAL(LIBVIRT, test x$libvirt = xtrue) +-# Default to libvirt for vm enumeration if no other enabled +-if test "x$xenctrl" = "xfalse"; then +- libvirt=true +- PKG_CHECK_MODULES([LIBVIRT], [libvirt]) +- AM_CONDITIONAL(LIBVIRT, test x$libvirt = xtrue) +-fi ++PKG_CHECK_MODULES([LIBVIRT], [libvirt]) + + # Configure argument to support using xenstore + AC_ARG_WITH([xenstore], +diff --git a/include/util.h b/include/util.h +index 6045665..3a21e09 100644 +--- a/include/util.h ++++ b/include/util.h +@@ -53,12 +53,10 @@ typedef struct _vu_vm + } vu_vm; + + +-#ifndef XENCTRL + /* The libvirt URI to connect to (-c argument on the command line). If + * not set, this will be NULL. + */ + extern const char *libvirt_uri; +-#endif + + /* + * Init logging interface. If running as daemon messages +diff --git a/vhostmd/Makefile.am b/vhostmd/Makefile.am +index 3801882..659a0ce 100644 +--- a/vhostmd/Makefile.am ++++ b/vhostmd/Makefile.am +@@ -3,26 +3,15 @@ INCLUDES = \ + -I../include + + sbin_PROGRAMS = vhostmd +-vhostmd_SOURCES = vhostmd.c util.c metric.c +-vhostmd_CFLAGS = $(LIBXML_CFLAGS) +-vhostmd_LDADD = -lm $(LIBXML_LIBS) ++vhostmd_SOURCES = vhostmd.c util.c metric.c virt-util.c ++vhostmd_CFLAGS = $(LIBXML_CFLAGS) $(LIBVIRT_CFLAGS) ++vhostmd_LDADD = -lm $(LIBXML_LIBS) $(LIBVIRT_LIBS) + + if WITH_XENSTORE + vhostmd_SOURCES += xenstore-update.c + vhostmd_LDADD += -lxenstore + endif + +-if XENCTRL +-vhostmd_SOURCES += xenctrl-util.c +-vhostmd_LDADD += -lxenctrl -lxenstore +-endif +- +-if LIBVIRT +-vhostmd_SOURCES += virt-util.c +-vhostmd_LDADD += $(LIBVIRT_LIBS) +-vhostmd_CFLAGS += $(LIBVIRT_CFLAGS) +-endif +- + if LIBXENSTAT + vhostmd_SOURCES += xen-metrics.c + vhostmd_LDADD += ../xenstat/libxenstat/src/libxenstat.a +diff --git a/vhostmd/metric.c b/vhostmd/metric.c +index 3fdf4f6..84b1678 100644 +--- a/vhostmd/metric.c ++++ b/vhostmd/metric.c +@@ -71,10 +71,6 @@ static int metric_action_subst(metric *m, char **action) + return -1; + } + +-#ifdef XENCTRL +- temp = replace (temp, "CONNECT", ""); +- if (temp == NULL) return -1; +-#else /* LIBVIRT used instead */ + if (libvirt_uri) { + temp = replace (temp, "CONNECT", "--connect '%s'", libvirt_uri); + if (temp == NULL) return -1; +@@ -82,7 +78,6 @@ static int metric_action_subst(metric *m, char **action) + temp = replace (temp, "CONNECT", ""); + if (temp == NULL) return -1; + } +-#endif + + if (m->ctx == METRIC_CONTEXT_VM) { + temp = replace (temp, "NAME", "%s", m->vm->name); +diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c +index 90ba76d..e2e91f6 100644 +--- a/vhostmd/vhostmd.c ++++ b/vhostmd/vhostmd.c +@@ -979,9 +979,7 @@ int main(int argc, char *argv[]) + { "config", required_argument, NULL, 'f'}, + { "pid-file", required_argument, NULL, 'p'}, + { "user", required_argument, NULL, 'u'}, +-#ifndef XENCTRL + { "connect", required_argument, NULL, 'c'}, +-#endif + { "help", no_argument, NULL, '?' }, + {0, 0, 0, 0} + }; +@@ -1014,11 +1012,9 @@ int main(int argc, char *argv[]) + case 'u': + user = optarg; + break; +-#ifndef XENCTRL + case 'c': + libvirt_uri = optarg; + break; +-#endif + case '?': + usage(argv[0]); + return 2; +diff --git a/vhostmd/xenctrl-util.c b/vhostmd/xenctrl-util.c +deleted file mode 100644 +index 7c78ca4..0000000 +--- a/vhostmd/xenctrl-util.c ++++ /dev/null +@@ -1,148 +0,0 @@ +-/* +- * Copyright (C) 2009 Novell, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * This library is distributed in the hope that it will be useful, +- * but WITHOUT ANY WARRANTY; without even the implied warranty of +- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, write to the Free Software +- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +- * +- * Author: Pat Campbell +- * +- * Preliminary, this could be done better +- */ +- +-#include +- +-#include +-#include +-#include +-#include +- +-#include "util.h" +- +-#define MAX_DOMS 1024 +-static int xc_handle = -1; +-static xc_dominfo_t info[MAX_DOMS]; +- +-int vu_num_vms(void) +-{ +- uint32_t first_dom = 0; +- int max_doms = MAX_DOMS, nr_doms = 0; +- +- if (xc_handle == -1) +- xc_handle = xc_interface_open(); +- +- if (xc_handle == -1) +- return -1; +- +- nr_doms = xc_domain_getinfo(xc_handle, first_dom, max_doms, info); +- +- return(nr_doms); +-} +- +-int vu_get_vms(int *ids, int max_ids) +-{ +- uint32_t first_dom = 0; +- int max_doms = MAX_DOMS, nr_doms = 0, i; +- +- if (xc_handle == -1) +- xc_handle = xc_interface_open(); +- +- if (xc_handle == -1) +- return -1; +- +- nr_doms = xc_domain_getinfo(xc_handle, first_dom, max_doms, info); +- if (nr_doms < 0) { +- goto out; +- } +- +- if (max_ids < nr_doms) +- nr_doms = max_ids; +- for (i = 0; i < nr_doms; i++) +- ids[i] = (int)info[i].domid; +- +-out: +- return nr_doms; +-} +- +-vu_vm *vu_get_vm(int id) +-{ +- vu_vm *vm = NULL; +- char *path = NULL, *buf = NULL; +- char *name = NULL; +- char *uuid = NULL; +- struct xs_handle *xsh = NULL; +- unsigned len; +- char *cp; +- +- vm = calloc(1, sizeof(vu_vm)); +- if (vm == NULL) +- return NULL; +- +- vm->id = id; +- +- xsh = xs_daemon_open(); +- if (xsh == NULL) +- goto error; +- +- path = xs_get_domain_path(xsh, id); +- if (path == NULL) { +- goto error; +- } +- +- asprintf(&buf, "%s/vm", path); +- uuid = xs_read(xsh, XBT_NULL, buf, &len); +- if (uuid == NULL) { +- goto error; +- } +- cp = strrchr(uuid, '/'); +- memmove(uuid, cp+1, strlen(cp)); +- vm->uuid = strdup(uuid); +- free(buf); +- +- asprintf(&buf, "%s/name", path); +- name = xs_read(xsh, XBT_NULL, buf, &len); +- if (name) +- vm->name = strdup(name); +- +- goto out; +- +-error: +- if (vm) free(vm); +- vm = NULL; +- +-out: +- if (buf) free(buf); +- if (path) free(path); +- if (name) free(name); +- if (uuid) free(uuid); +- if (xsh) xs_daemon_close(xsh); +- +- return vm; +-} +- +-void vu_vm_free(vu_vm *vm) +-{ +- if (vm) { +- free(vm->name); +- free(vm->uuid); +- free(vm); +- } +-} +- +-void vu_vm_connect_close() +-{ +- if (xc_handle != -1) +- xc_interface_close(xc_handle); +- xc_handle = -1; +-} +- +-- +2.19.0.rc0 + diff --git a/0010-Remove-support-for-libxenstat.patch b/0010-Remove-support-for-libxenstat.patch new file mode 100644 index 0000000..db52f25 --- /dev/null +++ b/0010-Remove-support-for-libxenstat.patch @@ -0,0 +1,222 @@ +From 1586cf7722d8ca45e4e4fff67be1ae0567e6d4b8 Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Wed, 6 Jun 2018 14:52:29 -0600 +Subject: [PATCH 10/17] Remove support for libxenstat + +Old, crufty code that no longer compiles and should be +removed from the sources. libvirt or custom "actions" +should be used to gather metrics. + +Signed-off-by: Jim Fehlig +--- + configure.ac | 12 ----- + include/metric.h | 4 -- + vhostmd/Makefile.am | 5 -- + vhostmd/vhostmd.c | 6 --- + vhostmd/xen-metrics.c | 123 ------------------------------------------ + 5 files changed, 150 deletions(-) + delete mode 100644 vhostmd/xen-metrics.c + +diff --git a/configure.ac b/configure.ac +index 2e88bfd..830c47f 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -39,18 +39,6 @@ AC_ARG_ENABLE([debug], + CFLAGS="$CFLAGS $DEBUG_CFLAGS" + ]) + +-# Add a configure argument to support using xen library, libxenstat +-AC_ARG_ENABLE([libxenstat], +-[ --enable-libxenstat enable libxenstat usage], +- [case "${enableval}" in +- yes) libxenstat=true +- CFLAGS="$CFLAGS -DLIBXENSTAT" +- ;; +- no) libxenstat=false ;; +- *) AC_MSG_ERROR(bad value ${enableval} for --enable-libxenstat) ;; +- esac],[AC_CHECK_HEADER(xenstat.h, libxenstat=true, libxenstat=false)]) +-AM_CONDITIONAL(LIBXENSTAT, test x$libxenstat = xtrue) +- + PKG_CHECK_MODULES([LIBVIRT], [libvirt]) + + # Configure argument to support using xenstore +diff --git a/include/metric.h b/include/metric.h +index 6c8432e..cc82366 100644 +--- a/include/metric.h ++++ b/include/metric.h +@@ -71,10 +71,6 @@ int metric_value_get(metric *def); + + int metric_xml(metric *m, vu_buffer *buf); + +-#ifdef LIBXENSTAT +-int xen_metrics(metric **user_metrics); +-#endif +- + #ifdef WITH_XENSTORE + int metrics_xenstore_update(char *buffer, int *ids, int num_vms); + #endif +diff --git a/vhostmd/Makefile.am b/vhostmd/Makefile.am +index 659a0ce..3585970 100644 +--- a/vhostmd/Makefile.am ++++ b/vhostmd/Makefile.am +@@ -12,11 +12,6 @@ vhostmd_SOURCES += xenstore-update.c + vhostmd_LDADD += -lxenstore + endif + +-if LIBXENSTAT +-vhostmd_SOURCES += xen-metrics.c +-vhostmd_LDADD += ../xenstat/libxenstat/src/libxenstat.a +-endif +- + valgrind: + $(MAKE) CHECKER='valgrind --quiet --leak-check=full --suppressions=$(srcdir)/.valgrind.supp' tests + +diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c +index e2e91f6..7f04705 100644 +--- a/vhostmd/vhostmd.c ++++ b/vhostmd/vhostmd.c +@@ -1077,12 +1077,6 @@ int main(int argc, char *argv[]) + goto out; + } + +-#ifdef LIBXENSTAT +- if (xen_metrics(&metrics)) { +- vu_log(VHOSTMD_ERR, "Unable to load xen specific metrics, ignoring"); +- } +-#endif +- + if ((mdisk_fd = metrics_disk_create()) < 0) { + vu_log(VHOSTMD_ERR, "Failed to create metrics disk %s", mdisk_path); + goto out; +diff --git a/vhostmd/xen-metrics.c b/vhostmd/xen-metrics.c +deleted file mode 100644 +index 94f7dea..0000000 +--- a/vhostmd/xen-metrics.c ++++ /dev/null +@@ -1,123 +0,0 @@ +-/* +- * Copyright (C) 2008 Novell, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * This library is distributed in the hope that it will be useful, +- * but WITHOUT ANY WARRANTY; without even the implied warranty of +- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, write to the Free Software +- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +- * +- * Author: Pat Campbell +- */ +- +-#include +- +-#include +-#include +-#include +-#include +-#include +- +-#include "util.h" +-#include "metric.h" +- +-#include "xenstat.h" +- +-static xenstat_handle *xhandle = NULL; +-static xenstat_node *cur_node = NULL; +- +-int node_tot_mem(void *vp) { +- metric *m = vp; +- +- cur_node = xenstat_get_node(xhandle, XENSTAT_ALL); +- if (cur_node == NULL) { +- vu_log(VHOSTMD_WARN, "Failed to retrieve statistics from libxenstat\n"); +- return -1; +- } +- m->value.r32 = xenstat_node_tot_mem(cur_node); +- xenstat_free_node(cur_node); +- return 0; +-} +- +-int func_str_test(void *vp) { +- metric *m = vp; +- int len = 0; +- char value[] = "func_str_test"; +- +- if (m->value.str) { +- len = strlen(m->value.str); +- m->value.str[0] = '\0'; +- if (strlen(value) > len) +- m->value.str = realloc(m->value.str, strlen(value) + 1); +- } +- else +- m->value.str = calloc(1, strlen(value) + 1); +- if (m->value.str == NULL) +- goto out; +- sprintf(m->value.str, "%s", value); +-out: +- return 0; +-} +- +- +-metric m[] = { +- { "test", +- NULL, +- M_STRING, +- METRIC_CONTEXT_HOST, +- func_str_test, +- 0, +- NULL +- }, +- { "node_tot_mem", +- NULL, +- M_REAL32, +- METRIC_CONTEXT_HOST, +- node_tot_mem, +- 0, +- NULL +- }, +- { "pages paged out", +- "vmstat -s |grep \"pages paged out\" | awk '{print $1}'", +- M_UINT32, +- METRIC_CONTEXT_HOST, +- NULL, +- 0, +- NULL +- } +-}; +- +- +-int xen_metrics(metric **user_metrics) { +- int i; +- metric *mdef; +- metric *metrics = *user_metrics; +- +- xhandle = xenstat_init(); +- if (xhandle == NULL) { +- vu_log(VHOSTMD_WARN, "Failed to initialize xenstat library\n"); +- return -1; +- } +- +- for (i = 0; i < sizeof(m)/sizeof(metric); i++) { +- mdef = calloc(sizeof(metric), 1); +- if (mdef) { +- memcpy(mdef,&m[i], sizeof(metric)); +- mdef->next = metrics; +- metrics = mdef; +- } +- else { +- vu_log(VHOSTMD_WARN, "Unable to allocate metric node, ignoring ..."); +- } +- } +- *user_metrics = metrics; +- return 0; +-} +-- +2.19.0.rc0 + diff --git a/0011-Fix-compilation-with-xenstore.patch b/0011-Fix-compilation-with-xenstore.patch new file mode 100644 index 0000000..7b80f99 --- /dev/null +++ b/0011-Fix-compilation-with-xenstore.patch @@ -0,0 +1,58 @@ +From 66967ef343c40d91918384540f9868b43c90c433 Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Wed, 6 Jun 2018 14:58:00 -0600 +Subject: [PATCH 11/17] Fix compilation with xenstore + +The xenstore transport is worth keeping, so update it to +work with "modern" Xen. By modern I mean something like 4.4 +or newer. + +Signed-off-by: Jim Fehlig +--- + configure.ac | 2 +- + libmetrics/libmetrics.c | 2 +- + vhostmd/xenstore-update.c | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 830c47f..c6b660e 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -48,7 +48,7 @@ AC_ARG_WITH([xenstore], + yes) with_xenstore=true;; + no) with_xenstore=false;; + *) AC_MSG_ERROR(bad value ${withval} for --with-xenstore) ;; +- esac],[AC_CHECK_HEADER(xs.h, with_xenstore=true)]) ++ esac],[AC_CHECK_HEADER(xenstore.h, with_xenstore=true)]) + AM_CONDITIONAL(WITH_XENSTORE, test x$with_xenstore = xtrue) + + # Configure argument to support type of init system +diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c +index 6d5c26f..81f4d1a 100644 +--- a/libmetrics/libmetrics.c ++++ b/libmetrics/libmetrics.c +@@ -31,7 +31,7 @@ + #include + #include + #ifdef WITH_XENSTORE +-#include ++#include + #endif + + #include "libmetrics.h" +diff --git a/vhostmd/xenstore-update.c b/vhostmd/xenstore-update.c +index f157f60..20fbde1 100644 +--- a/vhostmd/xenstore-update.c ++++ b/vhostmd/xenstore-update.c +@@ -28,7 +28,7 @@ + #include + #include + #include +-#include ++#include + + #include "util.h" + #include "metric.h" +-- +2.19.0.rc0 + diff --git a/0012-Fix-typo-in-systemd-service-file.patch b/0012-Fix-typo-in-systemd-service-file.patch new file mode 100644 index 0000000..02be16f --- /dev/null +++ b/0012-Fix-typo-in-systemd-service-file.patch @@ -0,0 +1,24 @@ +From b015f73b742db6285d8201e87387a7217e89dbfd Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Mon, 11 Jun 2018 15:25:58 -0600 +Subject: [PATCH 12/17] Fix typo in systemd service file + +Signed-off-by: Jim Fehlig +--- + vhostmd.service | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/vhostmd.service b/vhostmd.service +index 9d50523..576dabd 100644 +--- a/vhostmd.service ++++ b/vhostmd.service +@@ -1,5 +1,5 @@ + [Unit] +-Description=Daemon for collecting virutalization host metrics ++Description=Daemon for collecting virtualization host metrics + After=libvirtd.service + Documentation=man:vhostmd(8) + +-- +2.19.0.rc0 + diff --git a/0013-Fix-help-option.patch b/0013-Fix-help-option.patch new file mode 100644 index 0000000..4513273 --- /dev/null +++ b/0013-Fix-help-option.patch @@ -0,0 +1,70 @@ +From 302e49730f862a10b3b5b58905d803d27853f7d6 Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Wed, 20 Jun 2018 16:39:20 -0600 +Subject: [PATCH 13/17] Fix help option + +Fix the short option for help, add help to the help output, and +add help to the vhostmd man page. + +Signed-off-by: Jim Fehlig +--- + docs/man/vhostmd.8 | 3 +++ + vhostmd/vhostmd.c | 7 ++++--- + 2 files changed, 7 insertions(+), 3 deletions(-) + +diff --git a/docs/man/vhostmd.8 b/docs/man/vhostmd.8 +index 2c73adc..ed82432 100644 +--- a/docs/man/vhostmd.8 ++++ b/docs/man/vhostmd.8 +@@ -13,6 +13,9 @@ provides a "metrics communication channel" between a host and its hosted virtual + vhostmd will periodically write metrics to a disk. The metrics to write, how often, and where to write them are all adjustable via the /etc/vhostmd/vhostmd.conf configuration file. The disk can then be surfaced read-only to virtual machines using tools provided by the host's virtualization platform. + .SH OPTIONS + .TP ++.B \-h, --help ++Display help and exit ++.TP + .B \-v, --verbose + Verbose messages + .TP +diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c +index 7f04705..8576609 100644 +--- a/vhostmd/vhostmd.c ++++ b/vhostmd/vhostmd.c +@@ -950,6 +950,7 @@ static void usage(const char *argv0) + %s [options]\n\ + \n\ + Options:\n\ ++ -h | --help Display program help.\n\ + -v | --verbose Verbose messages.\n\ + -c | --connect Set the libvirt URI.\n\ + -d | --no-daemonize Process will not daemonize - useful for debugging.\n\ +@@ -980,7 +981,7 @@ int main(int argc, char *argv[]) + { "pid-file", required_argument, NULL, 'p'}, + { "user", required_argument, NULL, 'u'}, + { "connect", required_argument, NULL, 'c'}, +- { "help", no_argument, NULL, '?' }, ++ { "help", no_argument, NULL, 'h' }, + {0, 0, 0, 0} + }; + +@@ -988,7 +989,7 @@ int main(int argc, char *argv[]) + int optidx = 0; + int c; + +- c = getopt_long(argc, argv, "c:df:p:u:v", opts, &optidx); ++ c = getopt_long(argc, argv, "c:df:p:u:vh", opts, &optidx); + + if (c == -1) + break; +@@ -1015,7 +1016,7 @@ int main(int argc, char *argv[]) + case 'c': + libvirt_uri = optarg; + break; +- case '?': ++ case 'h': + usage(argv[0]); + return 2; + default: +-- +2.19.0.rc0 + diff --git a/0014-Add-SIGPIPE-handler-and-reconnect.patch b/0014-Add-SIGPIPE-handler-and-reconnect.patch new file mode 100644 index 0000000..f2c707a --- /dev/null +++ b/0014-Add-SIGPIPE-handler-and-reconnect.patch @@ -0,0 +1,110 @@ +From c7646e329ca61a038777f58042539611ac42b007 Mon Sep 17 00:00:00 2001 +From: Michael Trapp +Date: Thu, 21 Jun 2018 15:03:50 +0200 +Subject: [PATCH 14/17] Add SIGPIPE handler and reconnect + +vhostmd has no signal handler for SIGPIPE and a restart of libvirtd results in +a stopped vhostmd. The root cause seems to be a UDS socket between vhostmd and +libvirtd which is closed by a libvirtd restart. +In addition to the signal handler the connection to libvirtd has to be opened +again otherwise vhostmd can't read any data from libvirtd and doesn't update +the metrics. +--- + vhostmd/vhostmd.c | 2 ++ + vhostmd/virt-util.c | 43 ++++++++++++++++++++++++++++++++++++------- + 2 files changed, 38 insertions(+), 7 deletions(-) + +diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c +index 8576609..dc80345 100644 +--- a/vhostmd/vhostmd.c ++++ b/vhostmd/vhostmd.c +@@ -117,6 +117,7 @@ static void sig_handler(int sig, siginfo_t *siginfo ATTRIBUTE_UNUSED, + case SIGQUIT: + down = 1; + break; ++ case SIGPIPE: + default: + break; + } +@@ -1054,6 +1055,7 @@ int main(int argc, char *argv[]) + sigaction(SIGINT, &sig_action, NULL); + sigaction(SIGQUIT, &sig_action, NULL); + sigaction(SIGTERM, &sig_action, NULL); ++ sigaction(SIGPIPE, &sig_action, NULL); + + xmlInitParser(); + +diff --git a/vhostmd/virt-util.c b/vhostmd/virt-util.c +index 1c31305..587146f 100644 +--- a/vhostmd/virt-util.c ++++ b/vhostmd/virt-util.c +@@ -26,21 +26,48 @@ + + #include "util.h" + ++enum { ++ CLOSED = 0, ++ ESTABLISHED ++} connection = CLOSED; ++ + static virConnectPtr conn = NULL; + + const char *libvirt_uri = NULL; + ++void ++conn_close_cb(virConnectPtr c, ++ int reason ATTRIBUTE_UNUSED, ++ void *p ATTRIBUTE_UNUSED) ++{ ++ if (c == conn) ++ connection = CLOSED; ++} ++ + static int +-do_connect (void) ++do_connect(void) + { ++ if (connection == ESTABLISHED) ++ return 0; ++ ++ if (conn != NULL) ++ virConnectClose(conn); ++ ++ conn = virConnectOpenReadOnly(libvirt_uri); + if (conn == NULL) { +- conn = virConnectOpenReadOnly (libvirt_uri); +- if (conn == NULL) { +- vu_log (VHOSTMD_ERR, "Unable to open libvirt connection to %s", +- libvirt_uri ? libvirt_uri : "default hypervisor"); +- return -1; +- } ++ vu_log(VHOSTMD_ERR, "Unable to open libvirt connection to %s", ++ libvirt_uri ? libvirt_uri : "default hypervisor"); ++ return -1; + } ++ ++ if (virConnectRegisterCloseCallback(conn, conn_close_cb, NULL, NULL)) { ++ vu_log(VHOSTMD_ERR, "Unable to register callback 'virConnectCloseFunc'"); ++ virConnectClose(conn); ++ conn = NULL; ++ return -1; ++ } ++ ++ connection = ESTABLISHED; + return 0; + } + +@@ -107,8 +134,10 @@ void vu_vm_free(vu_vm *vm) + void vu_vm_connect_close() + { + if (conn) { ++ virConnectUnregisterCloseCallback(conn, conn_close_cb); + virConnectClose(conn); + conn = NULL; + } ++ connection = CLOSED; + } + +-- +2.19.0.rc0 + diff --git a/0015-fix-deallocation-in-vu_vm_free.patch b/0015-fix-deallocation-in-vu_vm_free.patch new file mode 100644 index 0000000..975882d --- /dev/null +++ b/0015-fix-deallocation-in-vu_vm_free.patch @@ -0,0 +1,40 @@ +From 03dc99825ad3d53cfcc7d8c2b8288b1549f261d6 Mon Sep 17 00:00:00 2001 +From: Michael Trapp +Date: Thu, 21 Jun 2018 15:19:26 +0200 +Subject: [PATCH 15/17] fix deallocation in vu_vm_free + +Callers of vu_vm_free may pass a partially constructed vu_vm +object. Check if members of the object have been allocated +before deallocating them. +--- + vhostmd/virt-util.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/vhostmd/virt-util.c b/vhostmd/virt-util.c +index 587146f..a94cccd 100644 +--- a/vhostmd/virt-util.c ++++ b/vhostmd/virt-util.c +@@ -118,15 +118,17 @@ vu_vm *vu_get_vm(int id) + + error: + virDomainFree(dom); +- free(vm); ++ vu_vm_free(vm); + return NULL; + } + + void vu_vm_free(vu_vm *vm) + { + if (vm) { +- free(vm->name); +- free(vm->uuid); ++ if (vm->name) ++ free(vm->name); ++ if (vm->uuid) ++ free(vm->uuid); + free(vm); + } + } +-- +2.19.0.rc0 + diff --git a/0016-configure-fix-logic-in-init-script-check.patch b/0016-configure-fix-logic-in-init-script-check.patch new file mode 100644 index 0000000..0d4f324 --- /dev/null +++ b/0016-configure-fix-logic-in-init-script-check.patch @@ -0,0 +1,39 @@ +From 6439d22cea451e54b58bb9d6e8072cc6c58694be Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Mon, 11 Jun 2018 20:35:50 -0600 +Subject: [PATCH 16/17] configure: fix logic in init script check + +The logic introduced in commit d1276646to check for init script type is +a bit flawed. If the init script type is specified, init_systemv is +always set to 'yes', even when '--with-init-script=systemd'. Split the +logic to only check for init script type when '--with-init-script=check'. + +Signed-off-by: Jim Fehlig +--- + configure.ac | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/configure.ac b/configure.ac +index c6b660e..9414440 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -59,10 +59,12 @@ AC_ARG_WITH([init_script], + [with_init_script=check]) + init_systemv=no + init_systemd=no +-if test "$with_init_script" = check && type systemctl >/dev/null 2>&1; then +- init_systemd=yes +-else +- init_systemv=yes ++if test "$with_init_script" = check; then ++ if type systemctl >/dev/null 2>&1; then ++ init_systemd=yes ++ else ++ init_systemv=yes ++ fi + fi + case "${with_init_script}" in + systemv) init_systemv=yes;; +-- +2.19.0.rc0 + diff --git a/0017-conf-Improve-example-configuration-file.patch b/0017-conf-Improve-example-configuration-file.patch new file mode 100644 index 0000000..7926fe6 --- /dev/null +++ b/0017-conf-Improve-example-configuration-file.patch @@ -0,0 +1,175 @@ +From d1a230d6d3ca4ded376f6522688d379bac347fbe Mon Sep 17 00:00:00 2001 +From: Jim Fehlig +Date: Wed, 20 Jun 2018 15:39:45 -0600 +Subject: [PATCH 17/17] conf: Improve example configuration file + +Although the upstream vhostmd config file serves primarily as an +example, it should at least work and not unconditionally call +commands that no longer exist. + +While at it, improve the comments describing the element. + +Signed-off-by: Jim Fehlig +--- + vhostmd.xml | 95 +++++++++++++++++++++++++++++++++++++++++++---------- + 1 file changed, 78 insertions(+), 17 deletions(-) + +diff --git a/vhostmd.xml b/vhostmd.xml +index 6f56b58..9b048df 100644 +--- a/vhostmd.xml ++++ b/vhostmd.xml +@@ -18,6 +18,12 @@ A metric's value is set to the output produced by executing its action. + the vm currently under inspection is substituted for NAME. Only useful + within the vm element. + ++NOTE - 'action' must be a valid shell builtin, script or external ++command found in the path specified by the global element. ++When chaining commands, '&', '<' and '>' are reserved characters, ++therefore '&', '<' and '>' must be used instead. For example, ++the logical && operator must be replaced with "&&". ++ + --> + + +@@ -28,52 +34,75 @@ within the vm element. + 256 + + 5 +- /usr/bin:/usr/sbin:/usr/share/vhostmd/scripts ++ /usr/sbin:/sbin:/usr/bin:/bin:/usr/share/vhostmd/scripts + vbd + + + + + HostName +- virsh CONNECT hostname | tr -d '[:space:]' ++ ++ virsh CONNECT hostname | tr -d '[:space:]' ++ + + + VirtualizationVendor +- /bin/rpm -q --info xen | grep Vendor: | \ +- awk '{print substr($0, index($0,$5)) }' ++ ++ [ -f /proc/xen/privcmd ] && RPM="xen" || RPM="libvirt"; \ ++ rpm -q --queryformat "%{VENDOR}\n" $RPM | sort -u | sed -e 's/<.*//' -e 's/ *$//' ++ + + + VirtualizationProductInfo +- xm info | gawk '/^xen_(major|minor|extra)/ {print $3}' | \ +- tr -d . | tr '[:space:]' . ++ ++ [ -f /proc/xen/privcmd ] && xl info | \ ++ awk '/^xen_(major|minor|extra)/ {print $3}' | sed -e 'N;s/\n/./' -e 'N;s/\n//' || \ ++ rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" libvirt | sort -u ++ + + + TotalPhyCPUs +- xm info | gawk '/^nr_cpus/ {print $3}' ++ ++ virsh nodeinfo | awk '/^CPU\(s\)/ {print $2}' ++ + + + NumCPUs +- xm info | gawk '/^nr_cpus/ {print $3}' ++ ++ virsh nodeinfo | awk '/^CPU\(s\)/ {print $2}' ++ + + + TotalPhyMem +- xm info | gawk '/^total_memory/ {print $3}' ++ ++ echo $((`virsh nodeinfo | awk '/^Memory/ {print $3}'` / 1024)) ++ + + + UsedMem +- echo "$((`xentop -b -i 1 | gawk '/Domain-0/ {print $5}'` / 1024))" ++ ++ [ -f /proc/xen/privcmd ] && echo "$((`xentop -b -i 1 | awk '/Domain-0/ {print $5}'` / 1024))" || \ ++ free | egrep -i '^[[:space:]]*(.*buffers/cache:)' | awk '{ printf "%d\n", $3/1024; }' ++ + + + FreeMem +- xm info | gawk '/^max_free_memory/ {print $3}' ++ ++ [ -f /proc/xen/privcmd ] && xl info | awk '/^free_memory/ {print $3}' || \ ++ free | egrep -i '^[[:space:]]*(.*buffers/cache:)' | awk '{ printf "%d\n", $4/1024; }' ++ + + + PagedInMemory +- echo "$((`vmstat -s | gawk '/pages paged in/ {print $1}'` / 1024))" ++ ++ vmstat -s | awk '/pages paged in/ {printf "%d\n", $1 / 1024 * $(getconf PAGESIZE) / 1024;}' ++ + + + PagedOutMemory +- echo "$((`vmstat -s | gawk '/pages paged out/ {print $1}'` / 1024))" ++ ++ vmstat -s | awk '/pages paged out/ {printf "%d\n", $1 / 1024 * $(getconf PAGESIZE) / 1024;}' ++ + + + PageRates +@@ -83,13 +112,45 @@ within the vm element. + + + TotalCPUTime +- virsh CONNECT dominfo 0 | sed 's/: */:/' | \ +- gawk -F: '/CPU time/ {print $2;}' ++ ++ [ -f /proc/xen/privcmd ] && xl list | awk '/^Domain-0/ {print $6}' || \ ++ awk ' ++ function user_hz( hz) ++ { ++ cmd = "getconf CLK_TCK"; ++ cmd | getline; ++ hz = $1; ++ close(cmd); ++ ++ return hz; ++ } ++ ++ BEGIN { ++ USER_HZ = user_hz(); ++ TotalCPUTime = 0; ++ ++ while ( 0 < ( getline < "/proc/stat" ) ) ++ { ++ if ( "cpu" == $1 ) ++ { ++ TotalCPUTime = $2 + $3 + $4; ++ ++ break; ++ } ++ } ++ close("/proc/stat"); ++ ++ TotalCPUTime /= USER_HZ; ++ printf "%f\n", TotalCPUTime; ++ }' ++ + + + TotalCPUTime +- virsh CONNECT dominfo NAME | sed 's/: */:/' | \ +- gawk -F: '/CPU time/ {print $2;}' ++ ++ virsh CONNECT dominfo NAME | sed 's/: */:/' | \ ++ awk -F: '/CPU time/ {print $2;}' | sed 's/s//' ++ + + + +-- +2.19.0.rc0 + diff --git a/vhostmd.spec b/vhostmd.spec index 0e97ef2..cbcc927 100644 --- a/vhostmd.spec +++ b/vhostmd.spec @@ -17,9 +17,23 @@ Source3: vhostmd.conf # These commits have been added upstream since vhostmd 0.5 was # released. -Patch1: 0001-Security-Set-supplemental-groups-correctly-when-drop.patch -Patch2: 0002-libmetrics-Return-error-indication-up-through-get_me.patch -Patch3: 0003-Make-Xen-Libraries-really-optional.patch +Patch0001: 0001-Security-Set-supplemental-groups-correctly-when-drop.patch +Patch0002: 0002-libmetrics-Return-error-indication-up-through-get_me.patch +Patch0003: 0003-Make-Xen-Libraries-really-optional.patch +Patch0004: 0004-Add-contact-info-to-README.patch +Patch0005: 0005-Fix-name-and-location-of-the-vhostmd.conf-file.patch +Patch0006: 0006-fix-typo-in-vhostmd.init-virutalization.patch +Patch0007: 0007-Modernize-build-files.patch +Patch0008: 0008-Add-systemd-service-file.patch +Patch0009: 0009-Remove-xenctrl-support.patch +Patch0010: 0010-Remove-support-for-libxenstat.patch +Patch0011: 0011-Fix-compilation-with-xenstore.patch +Patch0012: 0012-Fix-typo-in-systemd-service-file.patch +Patch0013: 0013-Fix-help-option.patch +Patch0014: 0014-Add-SIGPIPE-handler-and-reconnect.patch +Patch0015: 0015-fix-deallocation-in-vu_vm_free.patch +Patch0016: 0016-configure-fix-logic-in-init-script-check.patch +Patch0017: 0017-conf-Improve-example-configuration-file.patch BuildRequires: gcc BuildRequires: chrpath @@ -27,17 +41,15 @@ BuildRequires: perl-generators BuildRequires: pkgconfig BuildRequires: libxml2-devel BuildRequires: libvirt-devel +BuildRequires: autoconf, automake, libtool +BuildRequires: git +%{?systemd_requires} +BuildRequires: systemd %if %{have_xen} BuildRequires: xen-devel %endif -Requires(post): chkconfig -Requires(preun): chkconfig -Requires(preun): initscripts -Requires(postun): initscripts -Requires(pre): shadow-utils - %description vhostmd provides a "metrics communication channel" between a host and @@ -65,18 +77,16 @@ Header and libraries necessary for metrics gathering development %prep -%setup -q - -%patch1 -p1 -%patch2 -p1 -%patch3 -p1 +%autosetup -S git %build +autoreconf -i %configure \ %if %{have_xen} == 0 --without-xenstore \ %endif + --with-init-script=systemd \ --enable-shared --disable-static make %{_smp_mflags} @@ -86,12 +96,6 @@ rm -rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/init.d -install -m 0755 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/init.d/%{name} - -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig -install -m 0644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/%{name} - #rm $RPM_BUILD_ROOT%{_libdir}/libmetrics.a rm $RPM_BUILD_ROOT%{_libdir}/libmetrics.la @@ -115,24 +119,6 @@ rm $RPM_BUILD_ROOT%{_datadir}/vhostmd/scripts/pagerate.pl %endif - -%post -/sbin/chkconfig --add vhostmd - - -%preun -if [ $1 = 0 ] ; then - /sbin/service vhostmd stop >/dev/null 2>&1 - /sbin/chkconfig --del vhostmd -fi - - -%postun -if [ "$1" -ge "1" ] ; then - /sbin/service vhostmd condrestart >/dev/null 2>&1 || : -fi - - %pre # UID:GID 112:112 reserved, see RHBZ#534109. getent group vhostmd >/dev/null || groupadd -g 112 -r vhostmd @@ -142,6 +128,18 @@ useradd -u 112 -r -g vhostmd -d %{_datadir}/vhostmd -s /sbin/nologin \ exit 0 +%post +%systemd_post vhostmd.service + + +%preun +%systemd_preun vhostmd.service + + +%postun +%systemd_postun_with_restart vhostmd.service + + %files %doc AUTHORS ChangeLog COPYING README %doc mdisk.xml metric.dtd vhostmd.dtd vhostmd.xml @@ -151,8 +149,8 @@ exit 0 %dir %{_sysconfdir}/vhostmd %config(noreplace) %{_sysconfdir}/vhostmd/vhostmd.conf %config %{_sysconfdir}/vhostmd/vhostmd.dtd -%{_sysconfdir}/init.d/%{name} -%config(noreplace) %{_sysconfdir}/sysconfig/%{name} + +%{_unitdir}/vhostmd.service %dir %{_datadir}/vhostmd %dir %{_datadir}/vhostmd/scripts @@ -179,6 +177,10 @@ exit 0 %changelog +* Tue Oct 16 2018 Richard W.M. Jones - 0.5-19 +- Include all upstream patches since 0.5. +- Enable systemd init scripts (RHBZ#1592400). + * Sat Jul 14 2018 Fedora Release Engineering - 0.5-18 - Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild