[virt-tools-list] [vhostmd 1/3] Remove xenctrl support

Jim Fehlig jfehlig at suse.com
Wed Jun 6 21:22:29 UTC 2018


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 <jfehlig at suse.com>
---
 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(-)

diff --git a/configure.ac b/configure.ac
index fb4309b..65e463a 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 <plc at novell.com>
- *
- * Preliminary, this could be done better
- */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <xenctrl.h>
-#include <xs.h>
-
-#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.16.3




More information about the virt-tools-list mailing list