[libvirt] [PATCH 2/2] Add new error code VIR_ERROR_AUTH_CANCELLED
by Cole Robinson
And hook it up for policykit auth. This allows virt-manager to detect
that the user clicked the policykit 'cancel' button and not throw
an 'authentication failed' error message at the user.
---
daemon/remote.c | 13 +++++++++++--
include/libvirt/virterror.h | 1 +
src/util/virterror.c | 6 ++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 1ada146..2e813d6 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -2471,6 +2471,8 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED,
const char *action;
int status = -1;
char *ident = NULL;
+ int authdismissed = 0;
+ char *pkoutput = NULL;
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
virCommandPtr cmd = NULL;
@@ -2481,6 +2483,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED,
"org.libvirt.unix.manage";
cmd = virCommandNewArgList(PKCHECK_PATH, "--action-id", action, NULL);
+ virCommandSetOutputBuffer(cmd, &pkoutput);
VIR_DEBUG("Start PolicyKit auth %d", virNetServerClientGetFD(client));
if (virNetServerClientGetAuth(client) != VIR_NET_SERVER_SERVICE_AUTH_POLKIT) {
@@ -2509,6 +2512,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED,
if (virCommandRun(cmd, &status) < 0)
goto authfail;
+ authdismissed = (pkoutput && strstr(pkoutput, "dismissed=true"));
if (status != 0) {
char *tmp = virCommandTranslateStatus(status);
VIR_ERROR(_("Policy kit denied action %s from pid %lld, uid %d: %s"),
@@ -2534,8 +2538,13 @@ error:
virCommandFree(cmd);
VIR_FREE(ident);
virResetLastError();
- virNetError(VIR_ERR_AUTH_FAILED, "%s",
- _("authentication failed"));
+ if (authdismissed) {
+ virNetError(VIR_ERR_AUTH_CANCELLED, "%s",
+ _("authentication cancelled by user"));
+ } else {
+ virNetError(VIR_ERR_AUTH_FAILED, "%s",
+ _("authentication failed"));
+ }
virNetMessageSaveError(rerr);
virMutexUnlock(&priv->lock);
return -1;
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index e896d67..9844cbe 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -243,6 +243,7 @@ typedef enum {
risky domain snapshot revert */
VIR_ERR_OPERATION_ABORTED = 78, /* operation on a domain was
canceled/aborted by user */
+ VIR_ERR_AUTH_CANCELLED = 79, /* authentication cancelled */
} virErrorNumber;
/**
diff --git a/src/util/virterror.c b/src/util/virterror.c
index 85eec8d..31ddd9d 100644
--- a/src/util/virterror.c
+++ b/src/util/virterror.c
@@ -1022,6 +1022,12 @@ virErrorMsg(virErrorNumber error, const char *info)
else
errmsg = _("authentication failed: %s");
break;
+ case VIR_ERR_AUTH_CANCELLED:
+ if (info == NULL)
+ errmsg = _("authentication cancelled");
+ else
+ errmsg = _("authentication cancelled: %s");
+ break;
case VIR_ERR_NO_STORAGE_POOL:
if (info == NULL)
errmsg = _("Storage pool not found");
--
1.7.7.5
12 years, 9 months
[libvirt] [PATCH] build: fix missing include
by Eric Blake
Fix a build failure:
virt-host-validate.c: In function 'main':
virt-host-validate.c:82:5: error: implicit declaration of function 'setlocale' [-Werror=implicit-function-declaration]
virt-host-validate.c:82:5: error: nested extern declaration of 'setlocale' [-Werror=nested-externs]
virt-host-validate.c:82:20: error: 'LC_ALL' undeclared (first use in this function)
* tools/virt-host-validate.c: Add <locale.h>.
---
Pushing under the build-breaker rule.
tools/virt-host-validate.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/tools/virt-host-validate.c b/tools/virt-host-validate.c
index 3893ba3..cdf8302 100644
--- a/tools/virt-host-validate.c
+++ b/tools/virt-host-validate.c
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <gettext.h>
#include <getopt.h>
+#include <locale.h>
#include "internal.h"
#include "configmake.h"
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCH] xml: fix struct typos
by Eric Blake
Noticed this while reviewing Dan's patches.
* src/util/xml.c (virXMLRewritFileData): Rename to
virXMLRewriteFileData.
---
Pushing under the trivial rule.
src/util/xml.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/util/xml.c b/src/util/xml.c
index 2909e85..b0d90de 100644
--- a/src/util/xml.c
+++ b/src/util/xml.c
@@ -1,7 +1,7 @@
/*
* xml.c: XML based interfaces for the libvir library
*
- * Copyright (C) 2005, 2007-2011 Red Hat, Inc.
+ * Copyright (C) 2005, 2007-2012 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
@@ -801,7 +801,7 @@ error:
}
-struct virXMLRewritFileData {
+struct virXMLRewriteFileData {
const char *warnName;
const char *warnCommand;
const char *xml;
@@ -810,7 +810,7 @@ struct virXMLRewritFileData {
static int
virXMLRewriteFile(int fd, void *opaque)
{
- struct virXMLRewritFileData *data = opaque;
+ struct virXMLRewriteFileData *data = opaque;
if (data->warnName && data->warnCommand) {
if (virEmitXMLWarning(fd, data->warnName, data->warnCommand) < 0)
@@ -829,7 +829,7 @@ virXMLSaveFile(const char *path,
const char *warnCommand,
const char *xml)
{
- struct virXMLRewritFileData data = { warnName, warnCommand, xml };
+ struct virXMLRewriteFileData data = { warnName, warnCommand, xml };
return virFileRewrite(path, S_IRUSR | S_IWUSR, virXMLRewriteFile, &data);
}
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCH v2] Add a virt-host-validate command to sanity check HV config
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
To assist people in verifying that their host is operating in an
optimal manner, provide a 'virt-host-validate' command. For each
type of hypervisor, it will check any pre-requisites, or other
good recommendations and report what's working & what is not.
eg
# virt-host-validate
QEMU: Checking for device /dev/kvm : FAIL (Check that the 'kvm-intel' or 'kvm-amd' modules are loaded & the BIOS has enabled virtualization)
QEMU: Checking for device /dev/vhost : WARN (Load the 'vhost_net' module to improve performance of virtio networking)
QEMU: Checking for device /dev/net/tun : PASS
LXC: Checking for Linux >= 2.6.26 : PASS
This warns people if they have vmx/svm, but don't have /dev/kvm. It
also warns about missing /dev/vhost net.
In version 2:
- Add to RPM specs
- Add man page
- Use getopt to parse --help, --version & --quiet options
- Don't use VT100 escape codes unless on a tty
- Disable QEMU / LXC checks if not compiled into libvirt
---
tools/Makefile.am | 33 ++++++-
tools/virt-host-validate-common.c | 214 +++++++++++++++++++++++++++++++++++++
tools/virt-host-validate-common.h | 57 ++++++++++
tools/virt-host-validate-lxc.c | 37 +++++++
tools/virt-host-validate-lxc.h | 27 +++++
tools/virt-host-validate-qemu.c | 52 +++++++++
tools/virt-host-validate-qemu.h | 27 +++++
tools/virt-host-validate.c | 213 ++++++++++++++++++++++++++++++++++++
8 files changed, 658 insertions(+), 2 deletions(-)
create mode 100644 tools/virt-host-validate-common.c
create mode 100644 tools/virt-host-validate-common.h
create mode 100644 tools/virt-host-validate-lxc.c
create mode 100644 tools/virt-host-validate-lxc.h
create mode 100644 tools/virt-host-validate-qemu.c
create mode 100644 tools/virt-host-validate-qemu.h
create mode 100644 tools/virt-host-validate.c
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 6705546..6596a51 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -30,14 +30,18 @@ EXTRA_DIST = \
DISTCLEANFILES =
bin_SCRIPTS = virt-xml-validate virt-pki-validate
-bin_PROGRAMS = virsh
+bin_PROGRAMS = virsh virt-host-validate
if HAVE_SANLOCK
sbin_SCRIPTS = virt-sanlock-cleanup
DISTCLEANFILES += virt-sanlock-cleanup
endif
-dist_man1_MANS = virt-xml-validate.1 virt-pki-validate.1 virsh.1
+dist_man1_MANS = \
+ virt-host-validate.1 \
+ virt-pki-validate.1 \
+ virt-xml-validate.1 \
+ virsh.1
if HAVE_SANLOCK
dist_man8_MANS = virt-sanlock-cleanup.8
endif
@@ -56,6 +60,9 @@ virt-pki-validate: virt-pki-validate.in Makefile
virt-pki-validate.1: virt-pki-validate.in
$(AM_V_GEN)$(POD2MAN) $< $(srcdir)/$@
+virt-host-validate.1: virt-host-validate.c
+ $(AM_V_GEN)$(POD2MAN) $< $(srcdir)/$@
+
virt-sanlock-cleanup: virt-sanlock-cleanup.in Makefile
$(AM_V_GEN)sed -e 's,[@]SYSCONFDIR@,$(sysconfdir),' \
-e 's,[@]LOCALSTATEDIR@,$(localstatedir),' < $< > $@ \
@@ -64,6 +71,28 @@ virt-sanlock-cleanup: virt-sanlock-cleanup.in Makefile
virt-sanlock-cleanup.8: virt-sanlock-cleanup.in
$(AM_V_GEN)$(POD2MAN) $< $(srcdir)/$@
+virt_host_validate_SOURCES = \
+ virt-host-validate.c \
+ virt-host-validate-common.c virt-host-validate-common.h \
+ virt-host-validate-qemu.c virt-host-validate-qemu.h \
+ virt-host-validate-lxc.c virt-host-validate-lxc.h \
+ $(NULL)
+
+virt_host_validate_LDFLAGS = \
+ $(WARN_LDFLAGS) \
+ $(COVERAGE_LDFLAGS) \
+ $(NULL)
+
+virt_host_validate_LDADD = \
+ ../src/libvirt.la \
+ ../gnulib/lib/libgnu.la \
+ $(NULL)
+
+virt_host_validate_CFLAGS = \
+ $(WARN_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
+ $(NULL)
+
virsh_SOURCES = \
console.c console.h \
virsh.c
diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c
new file mode 100644
index 0000000..e8cff85
--- /dev/null
+++ b/tools/virt-host-validate-common.c
@@ -0,0 +1,214 @@
+/*
+ * virt-host-validate-common.c: Sanity check helper APis
+ *
+ * Copyright (C) 2012 Red Hat, 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
+ *
+ */
+
+#include <config.h>
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/utsname.h>
+
+#include "util.h"
+#include "memory.h"
+#include "virfile.h"
+#include "virt-host-validate-common.h"
+
+static bool quiet;
+
+void virHostMsgSetQuiet(bool quietFlag)
+{
+ quiet = quietFlag;
+}
+
+void virHostMsgCheck(const char *prefix,
+ const char *format,
+ ...)
+{
+ va_list args;
+ char *msg;
+
+ if (quiet)
+ return;
+
+ va_start(args, format);
+ if (virVasprintf(&msg, format, args) < 0) {
+ perror("malloc");
+ abort();
+ }
+ va_end(args);
+
+ fprintf(stdout, _("%6s: Checking %-60s: "), prefix, msg);
+ VIR_FREE(msg);
+}
+
+static bool virHostMsgWantEscape(void)
+{
+ static bool detectTty = true;
+ static bool wantEscape = false;
+ if (detectTty) {
+ if (isatty(STDOUT_FILENO))
+ wantEscape = true;
+ detectTty = false;
+ }
+ return wantEscape;
+}
+
+void virHostMsgPass(void)
+{
+ if (quiet)
+ return;
+
+ if (virHostMsgWantEscape())
+ fprintf(stdout, "\033[32m%s\033[0m\n", _("PASS"));
+ else
+ fprintf(stdout, "%s\n", _("PASS"));
+}
+
+
+static const char * failMessages[] = {
+ N_("FAIL"),
+ N_("WARN"),
+ N_("NOTE"),
+};
+
+verify(ARRAY_CARDINALITY(failMessages) == VIR_HOST_VALIDATE_LAST);
+
+static const char *failEscapeCodes[] = {
+ "\033[31m",
+ "\033[33m",
+ "\033[34m",
+};
+
+verify(ARRAY_CARDINALITY(failEscapeCodes) == VIR_HOST_VALIDATE_LAST);
+
+void virHostMsgFail(virHostValidateLevel level,
+ const char *hint)
+{
+ if (virHostMsgWantEscape())
+ fprintf(stdout, "%s%s\033[0m (%s)\n",
+ failEscapeCodes[level], _(failMessages[level]), hint);
+ else
+ fprintf(stdout, "%s (%s)\n",
+ _(failMessages[level]), hint);
+}
+
+
+int virHostValidateDevice(const char *hvname,
+ const char *devname,
+ virHostValidateLevel level,
+ const char *hint)
+{
+ virHostMsgCheck(hvname, "for device %s", devname);
+
+ if (access(devname, R_OK|W_OK) < 0) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ virHostMsgPass();
+ return 0;
+}
+
+
+int virHostValidateHasCPUFlag(const char *name)
+{
+ FILE *fp = fopen("/proc/cpuinfo", "r");
+ int ret = 0;
+
+ if (!fp)
+ return 0;
+
+ do {
+ char line[1024];
+
+ if (!fgets(line, sizeof(line), fp))
+ break;
+
+ if (strstr(line, name)) {
+ ret = 1;
+ break;
+ }
+ } while (1);
+
+ VIR_FORCE_FCLOSE(fp);
+
+ return ret;
+}
+
+
+int virHostValidateLinuxKernel(const char *hvname,
+ int version,
+ virHostValidateLevel level,
+ const char *hint)
+{
+ struct utsname uts;
+ int major, minor, micro;
+ unsigned long thisversion;
+
+ uname(&uts);
+
+ virHostMsgCheck(hvname, _("for Linux >= %d.%d.%d"),
+ ((version >> 16) & 0xff),
+ ((version >> 8) & 0xff),
+ (version & 0xff));
+
+ if (STRNEQ(uts.sysname, "Linux")) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ if (virParseVersionString(uts.release, &thisversion, true) < 0) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ micro = (thisversion & 0xff);
+ minor = ((thisversion >> 8) & 0xff);
+ major = ((thisversion >> 16) & 0xff);
+
+ if (major > ((version >> 16) & 0xff)) {
+ virHostMsgPass();
+ return 0;
+ } else if (major < ((version >> 16) & 0xff)) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ if (minor > ((version >> 8) & 0xff)) {
+ virHostMsgPass();
+ return 0;
+ } else if (minor < ((version >> 8) & 0xff)) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ if (micro > (version & 0xff)) {
+ virHostMsgPass();
+ return 0;
+ } else if (micro < (version & 0xff)) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ virHostMsgPass();
+ return 0;
+}
diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-common.h
new file mode 100644
index 0000000..99b09b6
--- /dev/null
+++ b/tools/virt-host-validate-common.h
@@ -0,0 +1,57 @@
+/*
+ * virt-host-validate-common.h: Sanity check helper APis
+ *
+ * Copyright (C) 2012 Red Hat, 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
+ *
+ */
+
+#ifndef __VIRT_HOST_VALIDATE_COMMON_H__
+#define __VIRT_HOST_VALIDATE_COMMON_H__
+
+#include "internal.h"
+
+typedef enum {
+ VIR_HOST_VALIDATE_FAIL,
+ VIR_HOST_VALIDATE_WARN,
+ VIR_HOST_VALIDATE_NOTE,
+
+ VIR_HOST_VALIDATE_LAST,
+} virHostValidateLevel;
+
+extern void virHostMsgSetQuiet(bool quietFlag);
+
+extern void virHostMsgCheck(const char *prefix,
+ const char *format,
+ ...) ATTRIBUTE_FMT_PRINTF(2, 3);
+
+extern void virHostMsgPass(void);
+extern void virHostMsgFail(virHostValidateLevel level,
+ const char *hint);
+
+extern int virHostValidateDevice(const char *hvname,
+ const char *devname,
+ virHostValidateLevel level,
+ const char *hint);
+
+extern int virHostValidateHasCPUFlag(const char *name);
+
+extern int virHostValidateLinuxKernel(const char *hvname,
+ int version,
+ virHostValidateLevel level,
+ const char *hint);
+
+#endif /* __VIRT_HOST_VALIDATE_COMMON_H__ */
diff --git a/tools/virt-host-validate-lxc.c b/tools/virt-host-validate-lxc.c
new file mode 100644
index 0000000..9d69b67
--- /dev/null
+++ b/tools/virt-host-validate-lxc.c
@@ -0,0 +1,37 @@
+/*
+ * virt-host-validate-lxc.c: Sanity check a LXC hypervisor host
+ *
+ * Copyright (C) 2012 Red Hat, 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
+ *
+ */
+
+#include <config.h>
+
+#include "virt-host-validate-lxc.h"
+#include "virt-host-validate-common.h"
+
+int virHostValidateLXC(void)
+{
+ int ret = 0;
+
+ if (virHostValidateLinuxKernel("LXC", (2 << 16) | (6 << 8) | 26,
+ VIR_HOST_VALIDATE_FAIL,
+ _("Upgrade to a kernel supporting namespaces")) < 0)
+ ret = -1;
+
+ return ret;
+}
diff --git a/tools/virt-host-validate-lxc.h b/tools/virt-host-validate-lxc.h
new file mode 100644
index 0000000..ef824be
--- /dev/null
+++ b/tools/virt-host-validate-lxc.h
@@ -0,0 +1,27 @@
+/*
+ * virt-host-validate-lxc.h: Sanity check a LXC hypervisor host
+ *
+ * Copyright (C) 2012 Red Hat, 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
+ *
+ */
+
+#ifndef __VIRT_HOST_VALIDATE_LXC_H__
+#define __VIRT_HOST_VALIDATE_LXC_H__
+
+extern int virHostValidateLXC(void);
+
+#endif /* __VIRT_HOST_VALIDATE_LXC_H__ */
diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qemu.c
new file mode 100644
index 0000000..d3a82cc
--- /dev/null
+++ b/tools/virt-host-validate-qemu.c
@@ -0,0 +1,52 @@
+/*
+ * virt-host-validate-qemu.c: Sanity check a QEMU hypervisor host
+ *
+ * Copyright (C) 2012 Red Hat, 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
+ *
+ */
+
+#include <config.h>
+
+#include "virt-host-validate-qemu.h"
+#include "virt-host-validate-common.h"
+
+int virHostValidateQEMU(void)
+{
+ int ret = 0;
+
+ if (virHostValidateHasCPUFlag("svm") ||
+ virHostValidateHasCPUFlag("vmx")) {
+ if (virHostValidateDevice("QEMU", "/dev/kvm",
+ VIR_HOST_VALIDATE_FAIL,
+ _("Check that the 'kvm-intel' or 'kvm-amd' modules are "
+ "loaded & the BIOS has enabled virtualization")) < 0)
+ ret = -1;
+ }
+
+ if (virHostValidateDevice("QEMU", "/dev/vhost-net",
+ VIR_HOST_VALIDATE_WARN,
+ _("Load the 'vhost_net' module to improve performance "
+ "of virtio networking")) < 0)
+ ret = -1;
+
+ if (virHostValidateDevice("QEMU", "/dev/net/tun",
+ VIR_HOST_VALIDATE_FAIL,
+ _("Load the 'tun' module to enable networking for QEMU guests")) < 0)
+ ret = -1;
+
+ return ret;
+}
diff --git a/tools/virt-host-validate-qemu.h b/tools/virt-host-validate-qemu.h
new file mode 100644
index 0000000..3e79d51
--- /dev/null
+++ b/tools/virt-host-validate-qemu.h
@@ -0,0 +1,27 @@
+/*
+ * virt-host-validate-qemu.h: Sanity check a QEMU hypervisor host
+ *
+ * Copyright (C) 2012 Red Hat, 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
+ *
+ */
+
+#ifndef __VIRT_HOST_VALIDATE_QEMU_H__
+#define __VIRT_HOST_VALIDATE_QEMU_H__
+
+extern int virHostValidateQEMU(void);
+
+#endif /* __VIRT_HOST_VALIDATE_QEMU_H__ */
diff --git a/tools/virt-host-validate.c b/tools/virt-host-validate.c
new file mode 100644
index 0000000..06fee58
--- /dev/null
+++ b/tools/virt-host-validate.c
@@ -0,0 +1,213 @@
+/*
+ * virt-host-check.c: Sanity check a hypervisor host
+ *
+ * Copyright (C) 2012 Red Hat, 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
+ *
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <gettext.h>
+#include <getopt.h>
+
+#include "internal.h"
+#include "configmake.h"
+
+#include "virt-host-validate-common.h"
+#if WITH_QEMU
+#include "virt-host-validate-qemu.h"
+#endif
+#if WITH_LXC
+#include "virt-host-validate-lxc.h"
+#endif
+
+static void
+show_help(FILE *out, const char *argv0)
+{
+ fprintf(out,
+ _("\n"
+ "syntax: %s [OPTIONS] [HVTYPE]\n"
+ "\n"
+ " Hypervisor types:\n"
+ "\n"
+ " - qemu\n"
+ " - lxc\n"
+ "\n"
+ " Options:\n"
+ " -h, --help Display command line help\n"
+ " -v, --version Display command version\n"
+ " -q, --quiet Don't display progress information\n"
+ "\n"),
+ argv0);
+}
+
+static void
+show_version(FILE *out, const char *argv0)
+{
+ fprintf(out, "version: %s %s\n", argv0, VERSION);
+}
+
+static const struct option argOptions[] = {
+ { "help", 0, NULL, 'h', },
+ { "version", 0, NULL, 'v', },
+ { "quiet", 0, NULL, 'q', },
+ { NULL, 0, NULL, '\0', }
+};
+
+int
+main(int argc, char **argv)
+{
+ const char *hvname = NULL;
+ int c;
+ int ret = EXIT_SUCCESS;
+ bool quiet = false;
+
+ if (!setlocale(LC_ALL, "")) {
+ perror("setlocale");
+ /* failure to setup locale is not fatal */
+ }
+ if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
+ perror("bindtextdomain");
+ return EXIT_FAILURE;
+ }
+ if (!textdomain(PACKAGE)) {
+ perror("textdomain");
+ return EXIT_FAILURE;
+ }
+
+ while ((c = getopt_long(argc, argv, "hvq", argOptions, NULL)) != -1) {
+ switch (c) {
+ case 'v':
+ show_version(stdout, argv[0]);
+ return EXIT_SUCCESS;
+
+ case 'h':
+ show_help(stdout, argv[0]);
+ return EXIT_SUCCESS;
+
+ case 'q':
+ quiet = true;
+ break;
+
+ case '?':
+ default:
+ show_help(stderr, argv[0]);
+ return EXIT_FAILURE;
+ }
+ }
+
+ if ((argc-optind) > 2) {
+ fprintf(stderr, _("%s: too many command line arguments\n"), argv[0]);
+ show_help(stderr, argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (argc > 1)
+ hvname = argv[optind];
+
+ virHostMsgSetQuiet(quiet);
+
+#if WITH_QEMU
+ if ((!hvname || STREQ(hvname, "qemu")) &&
+ virHostValidateQEMU() < 0)
+ ret = EXIT_FAILURE;
+#endif
+
+#if WITH_LXC
+ if ((!hvname || STREQ(hvname, "lxc")) &&
+ virHostValidateLXC() < 0)
+ ret = EXIT_FAILURE;
+#endif
+
+ return ret;
+}
+
+/*
+
+=pod
+
+=head1 NAME
+
+ virt-host-validate - validate host virtualization setup
+
+=head1 SYNOPSIS
+
+ virt-host-validate [OPTIONS...] [HV-TYPE]
+
+=head1 DESCRIPTION
+
+This tool validates that the host is configured in a suitable
+way to run libvirt hypervisor drivers. If invoked without any
+arguments it will check support for all hypervisor drivers it
+is aware of. Optionally it can be given a particular hypervisor
+type ('qemu' or 'lxc') to restrict the checks to those relevant
+for that virtualization technology
+
+=head1 OPTIONS
+
+=over 4
+
+=item C<-v>, C<--version>
+
+Display the command version
+
+=item C<-h>, C<--help>
+
+Display the command line help
+
+=item C<-q>, C<--quiet>
+
+Don't display details of individual checks being performed.
+Only display output if a check does not pass.
+
+=back
+
+=head1 EXIT STATUS
+
+Upon successful validation, an exit status of 0 will be set. Upon
+failure a non-zero status will be set.
+
+=head1 AUTHOR
+
+Daniel P. Berrange
+
+=head1 BUGS
+
+Report any bugs discovered to the libvirt community via the
+mailing list C<http://libvirt.org/contact.html> or bug tracker C<http://libvirt.org/bugs.html>.
+Alternatively report bugs to your software distributor / vendor.
+
+=head1 COPYRIGHT
+
+Copyright (C) 2012 by Red Hat, Inc.
+
+=head1 LICENSE
+
+virt-host-validate is distributed under the terms of the GNU GPL v2+.
+This is free software; see the source for copying conditions. There
+is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
+PURPOSE
+
+=head1 SEE ALSO
+
+C<virsh(1)>, C<virt-pki-validate>, C<virt-xml-validate>
+
+=cut
+
+*/
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCH v3 0/2] nwfilter: Compare filters for equality when updating
by Stefan Berger
When a filter is updated, compare it and the original one for equality
so that unnecessary instantiations of rules can be avoided.
v3:
- introducing a function to instantiate all running VMs' filters; call
it upon nwfilter driver reload
- reworked function comparing filters; determining whether two filters
are equal now by comparing their XML representations
v2:
- added a test case for testing virHashEqual
Regards,
Stefan
12 years, 9 months
[libvirt] [PATCH v2 0/7] qemu: support disabling/enabling kvmclock with <timer> elements
by Paolo Bonzini
QEMU supports a bunch of CPUID features that are tied to the kvm CPUID
nodes rather than the processor's. They are "kvmclock", "kvm_nopiodelay",
"kvm_mmu", "kvm_asyncpf". These are not known to libvirt and their
CPUID leaf might move if (for example) the Hyper-V extensions are enabled.
Hence their handling would anyway require some special-casing.
However, among these the most useful is kvmclock; an additional
"property" of this feature is that a <timer> element is a better model
than a CPUID feature.
This is what this series does.
Actually, while working on this I noticed that it is quite difficult
to have round-trip testcases involving -cpu, that can be used with
both qemuargv2xmltest and qemuxml2argvtest. This is what the first
five four patches do. The first patch is unrelated. The second patch
updates the CPU feature map with default CPUs, and is a prerequisite
for patch 3. That one makes the -cpu parsing code detect the "lm"
CPU feature, so that the guest arch is correctly set to either
i686 or x86_64.
The fifth patch is also mostly needed for testing. It notices the
default models qemu32/qemu64 and does not generate <cpu> elements;
this happens with "-cpu qemu32,-kvmclock" for example. Then, the
last two patches actually add the new feature.
Paolo Bonzini (7):
qemu: parse -enable-kvm
x86: add kvm32 and kvm64, update qemu64
qemu: detect arch correctly for KVM
qemu: get arch name from <cpu> element
qemu: do not create useless <cpu> element
conf: add kvmclock timer
qemu: parse and create -cpu ...,-kvmclock
v1->v2: completely redone first patch (which became patches 1-5 :)
docs/formatdomain.html.in | 4 +-
docs/schemas/domaincommon.rng | 3 +-
src/conf/domain_conf.c | 3 +-
src/conf/domain_conf.h | 1 +
src/cpu/cpu_map.xml | 31 +++++
src/qemu/qemu_command.c | 129 ++++++++++++++++++--
tests/qemuargv2xmltest.c | 4 +
.../qemuxml2argv-cpu-host-kvmclock.args | 4 +
.../qemuxml2argv-cpu-host-kvmclock.xml | 23 ++++
.../qemuxml2argv-cpu-kvmclock.args | 4 +
.../qemuxml2argvdata/qemuxml2argv-cpu-kvmclock.xml | 24 ++++
tests/qemuxml2argvdata/qemuxml2argv-kvmclock.args | 4 +
tests/qemuxml2argvdata/qemuxml2argv-kvmclock.xml | 21 +++
tests/qemuxml2argvtest.c | 3 +
tests/qemuxml2xmltest.c | 3 +
15 files changed, 244 insertions(+), 17 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-kvmclock.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-kvmclock.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-kvmclock.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-kvmclock.xml
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCH] qemu: support qmp on RHEL/CentOS qemu
by Eric Blake
I'm getting tired of remembering to backport RHEL-specific
patches when building upstream libvirt on RHEL 6.x or CentOS.
All the affected versions of RHEL qemu-kvm have backported
enough patches to a) make JSON useful, and b) modify the
-help text to mention libvirt as the preferred interface;
which means this string in the help output is a reliable
indicator that we can outsmart a strict version check,
even when upstream qemu 0.12 lacked the needed features.
* src/qemu/qemu_capabilities.c (qemuCapsComputeCmdFlags):
Recognize particular help string present when enough features were
backported to be worth using JSON.
* tests/qemuhelptest.c (mymain): Update tests accordingly.
---
src/qemu/qemu_capabilities.c | 17 +++++++++++++----
tests/qemuhelptest.c | 6 ++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 54757fc..c4bad6f 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1104,7 +1104,8 @@ qemuCapsComputeCmdFlags(const char *help,
if (strstr(help, "-netdev")) {
/* Disable -netdev on 0.12 since although it exists,
* the corresponding netdev_add/remove monitor commands
- * do not, and we need them to be able todo hotplug */
+ * do not, and we need them to be able to do hotplug.
+ * But see below about RHEL build. */
if (version >= 13000)
qemuCapsSet(flags, QEMU_CAPS_NETDEV);
}
@@ -1169,12 +1170,20 @@ qemuCapsComputeCmdFlags(const char *help,
/* While JSON mode was available in 0.12.0, it was too
* incomplete to contemplate using. The 0.13.0 release
* is good enough to use, even though it lacks one or
- * two features. The benefits of JSON mode now outweigh
- * the downside.
+ * two features. This is also true of versions of qemu
+ * built for RHEL, labeled 0.12.1, but with extra text
+ * in the help output that mentions that features were
+ * backported for libvirt. The benefits of JSON mode now
+ * outweigh the downside.
*/
#if HAVE_YAJL
- if (version >= 13000)
+ if (version >= 13000) {
qemuCapsSet(flags, QEMU_CAPS_MONITOR_JSON);
+ } else if (version >= 12000 &&
+ strstr(help, "libvirt")) {
+ qemuCapsSet(flags, QEMU_CAPS_MONITOR_JSON);
+ qemuCapsSet(flags, QEMU_CAPS_NETDEV);
+ }
#endif
if (version >= 13000)
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index 8802271..5ad55bc 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -354,9 +354,11 @@ mymain(void)
QEMU_CAPS_MIGRATE_QEMU_UNIX,
QEMU_CAPS_CHARDEV,
QEMU_CAPS_ENABLE_KVM,
+ QEMU_CAPS_MONITOR_JSON,
QEMU_CAPS_BALLOON,
QEMU_CAPS_DEVICE,
QEMU_CAPS_SMP_TOPOLOGY,
+ QEMU_CAPS_NETDEV,
QEMU_CAPS_RTC,
QEMU_CAPS_VHOST_NET,
QEMU_CAPS_NO_KVM_PIT,
@@ -503,9 +505,11 @@ mymain(void)
QEMU_CAPS_MIGRATE_QEMU_UNIX,
QEMU_CAPS_CHARDEV,
QEMU_CAPS_ENABLE_KVM,
+ QEMU_CAPS_MONITOR_JSON,
QEMU_CAPS_BALLOON,
QEMU_CAPS_DEVICE,
QEMU_CAPS_SMP_TOPOLOGY,
+ QEMU_CAPS_NETDEV,
QEMU_CAPS_RTC,
QEMU_CAPS_VHOST_NET,
QEMU_CAPS_NO_KVM_PIT,
@@ -559,8 +563,10 @@ mymain(void)
QEMU_CAPS_CHARDEV,
QEMU_CAPS_ENABLE_KVM,
QEMU_CAPS_BALLOON,
+ QEMU_CAPS_MONITOR_JSON,
QEMU_CAPS_DEVICE,
QEMU_CAPS_SMP_TOPOLOGY,
+ QEMU_CAPS_NETDEV,
QEMU_CAPS_RTC,
QEMU_CAPS_VHOST_NET,
QEMU_CAPS_NO_KVM_PIT,
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCH] qemu: require qmp on new enough qemu
by Eric Blake
The qemu developers have made it clear that modern qemu will no
longer guarantee human monitor command stability; furthermore,
some features, such as async events, are only supported via qmp.
If we are compiled without support for handling JSON, we cannot
expect to sanely interact with modern qemu.
However, things must continue to build on RHEL 5, where qemu
is stuck at 0.10, and where yajl is not available.
Another benefit of this patch: future additions of new monitor
commands need only focus on qemu_monitor_json.c, instead of
also wasting time with qemu_monitor_text.c.
* src/qemu/qemu_capabilities.c (qemuCapsComputeCmdFlags): Report
error if yajl is missing but qemu requires qmp.
(qemuCapsParseHelpStr): Propagate error.
(qemuCapsExtractVersionInfo): Update caller.
* tests/qemuhelptest.c (testHelpStrParsing): Likewise.
---
Tested on Fedora 16, RHEL 6.2, and RHEL 5.8.
src/qemu/qemu_capabilities.c | 33 ++++++++++++++++++++++++++++-----
src/qemu/qemu_capabilities.h | 3 ++-
tests/qemuhelptest.c | 2 +-
3 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index c4bad6f..13a9cb0 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -982,12 +982,13 @@ virCapsPtr qemuCapsInit(virCapsPtr old_caps)
}
-static void
+static int
qemuCapsComputeCmdFlags(const char *help,
unsigned int version,
unsigned int is_kvm,
unsigned int kvm_version,
- virBitmapPtr flags)
+ virBitmapPtr flags,
+ bool check_yajl ATTRIBUTE_UNUSED)
{
const char *p;
const char *fsdev;
@@ -1184,6 +1185,23 @@ qemuCapsComputeCmdFlags(const char *help,
qemuCapsSet(flags, QEMU_CAPS_MONITOR_JSON);
qemuCapsSet(flags, QEMU_CAPS_NETDEV);
}
+#else
+ /* Starting with qemu 0.15 and newer, upstream qemu no longer
+ * promised to keep the human interface stable, but request that
+ * we use QMP (the JSON interface) for everything. If the user
+ * forgot to include YAJL libraries when building their own
+ * libvirt but is targetting a newer qemu, we are better off
+ * telling them to recompile (the spec file includes the
+ * dependency, so distros won't hit this). */
+ if (version >= 15000 ||
+ (version >= 12000 && strstr(help, "libvirt"))) {
+ if (check_yajl) {
+ qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("this qemu binary requires compilation with yajl"));
+ return -1;
+ }
+ qemuCapsSet(flags, QEMU_CAPS_NETDEV);
+ }
#endif
if (version >= 13000)
@@ -1204,6 +1222,7 @@ qemuCapsComputeCmdFlags(const char *help,
if (version >= 11000)
qemuCapsSet(flags, QEMU_CAPS_CPU_HOST);
+ return 0;
}
/* We parse the output of 'qemu -help' to get the QEMU
@@ -1235,7 +1254,8 @@ int qemuCapsParseHelpStr(const char *qemu,
virBitmapPtr flags,
unsigned int *version,
unsigned int *is_kvm,
- unsigned int *kvm_version)
+ unsigned int *kvm_version,
+ bool check_yajl)
{
unsigned major, minor, micro;
const char *p = help;
@@ -1291,7 +1311,9 @@ int qemuCapsParseHelpStr(const char *qemu,
*version = (major * 1000 * 1000) + (minor * 1000) + micro;
- qemuCapsComputeCmdFlags(help, *version, *is_kvm, *kvm_version, flags);
+ if (qemuCapsComputeCmdFlags(help, *version, *is_kvm, *kvm_version,
+ flags, check_yajl) < 0)
+ goto cleanup;
strflags = virBitmapString(flags);
VIR_DEBUG("Version %u.%u.%u, cooked version %u, flags %s",
@@ -1314,6 +1336,7 @@ fail:
_("cannot parse %s version number in '%s'"),
qemu, p ? p : help);
+cleanup:
VIR_FREE(p);
return -1;
@@ -1455,7 +1478,7 @@ int qemuCapsExtractVersionInfo(const char *qemu, const char *arch,
if (!(flags = qemuCapsNew()) ||
qemuCapsParseHelpStr(qemu, help, flags,
- &version, &is_kvm, &kvm_version) == -1)
+ &version, &is_kvm, &kvm_version, true) == -1)
goto cleanup;
/* Currently only x86_64 and i686 support PCI-multibus. */
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 8b009f9..18d6bc8 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -162,7 +162,8 @@ int qemuCapsParseHelpStr(const char *qemu,
virBitmapPtr qemuCaps,
unsigned int *version,
unsigned int *is_kvm,
- unsigned int *kvm_version);
+ unsigned int *kvm_version,
+ bool check_yajl);
int qemuCapsParseDeviceStr(const char *str,
virBitmapPtr qemuCaps);
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index 5ad55bc..370cd0d 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -53,7 +53,7 @@ static int testHelpStrParsing(const void *data)
goto cleanup;
if (qemuCapsParseHelpStr("QEMU", help, flags,
- &version, &is_kvm, &kvm_version) == -1)
+ &version, &is_kvm, &kvm_version, false) == -1)
goto cleanup;
# ifndef HAVE_YAJL
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCH RFC] Add a virt-host-validate command to sanity check HV config
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
To assist people in verifying that their host is operating in an
optimal manner, provide a 'virt-host-validate' command. For each
type of hypervisor, it will check any pre-requisites, or other
good recommendations and report what's working & what is not.
eg
# virt-host-validate
QEMU: Checking for device /dev/kvm : FAIL (Check that the 'kvm-intel' or 'kvm-amd' modules are loaded & the BIOS has enabled virtualization)
QEMU: Checking for device /dev/vhost : WARN (Load the 'vhost_net' module to improve performance of virtio networking)
QEMU: Checking for device /dev/net/tun : PASS
LXC: Checking for Linux >= 2.6.26 : PASS
This warns people if they have vmx/svm, but don't have /dev/kvm. It
also warns about missing /dev/vhost net.
---
tools/Makefile.am | 25 ++++++-
tools/virt-host-validate-common.c | 166 +++++++++++++++++++++++++++++++++++++
tools/virt-host-validate-common.h | 53 ++++++++++++
tools/virt-host-validate-lxc.c | 37 ++++++++
tools/virt-host-validate-lxc.h | 27 ++++++
tools/virt-host-validate-qemu.c | 50 +++++++++++
tools/virt-host-validate-qemu.h | 27 ++++++
tools/virt-host-validate.c | 77 +++++++++++++++++
8 files changed, 461 insertions(+), 1 deletions(-)
create mode 100644 tools/virt-host-validate-common.c
create mode 100644 tools/virt-host-validate-common.h
create mode 100644 tools/virt-host-validate-lxc.c
create mode 100644 tools/virt-host-validate-lxc.h
create mode 100644 tools/virt-host-validate-qemu.c
create mode 100644 tools/virt-host-validate-qemu.h
create mode 100644 tools/virt-host-validate.c
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 6705546..2b14319 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -30,7 +30,7 @@ EXTRA_DIST = \
DISTCLEANFILES =
bin_SCRIPTS = virt-xml-validate virt-pki-validate
-bin_PROGRAMS = virsh
+bin_PROGRAMS = virsh virt-host-validate
if HAVE_SANLOCK
sbin_SCRIPTS = virt-sanlock-cleanup
@@ -64,6 +64,29 @@ virt-sanlock-cleanup: virt-sanlock-cleanup.in Makefile
virt-sanlock-cleanup.8: virt-sanlock-cleanup.in
$(AM_V_GEN)$(POD2MAN) $< $(srcdir)/$@
+virt_host_validate_SOURCES = \
+ virt-host-validate.c \
+ virt-host-validate-common.c virt-host-validate-common.h \
+ virt-host-validate-qemu.c virt-host-validate-qemu.h \
+ virt-host-validate-lxc.c virt-host-validate-lxc.h \
+ $(NULL)
+
+virt_host_validate_LDFLAGS = \
+ $(WARN_LDFLAGS) \
+ $(COVERAGE_LDFLAGS) \
+ $(NULL)
+
+virt_host_validate_LDADD = \
+ $(WARN_CFLAGS) \
+ ../src/libvirt.la \
+ ../gnulib/lib/libgnu.la \
+ $(NULL)
+
+virt_host_validate_CFLAGS = \
+ $(WARN_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
+ $(NULL)
+
virsh_SOURCES = \
console.c console.h \
virsh.c
diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c
new file mode 100644
index 0000000..7ada218
--- /dev/null
+++ b/tools/virt-host-validate-common.c
@@ -0,0 +1,166 @@
+/*
+ * virt-host-validate-common.c: Sanity check helper APis
+ *
+ * Copyright (C) 2011 Red Hat, 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
+ *
+ */
+
+#include <config.h>
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/utsname.h>
+
+#include "util.h"
+#include "memory.h"
+#include "virt-host-validate-common.h"
+
+void virHostMsgCheck(const char *prefix,
+ const char *format,
+ ...)
+{
+ va_list args;
+ char *msg;
+
+ va_start(args, format);
+ if (virVasprintf(&msg, format, args) < 0) {
+ perror("malloc");
+ abort();
+ }
+ va_end(args);
+
+ fprintf(stdout, "%6s: Checking %-60s: ", prefix, msg);
+ VIR_FREE(msg);
+}
+
+void virHostMsgPass(void)
+{
+ fprintf(stdout, "\033[32mPASS\033[0m\n");
+}
+
+void virHostMsgFail(virHostValidateLevel level,
+ const char *hint)
+{
+ if (level == VIR_HOST_VALIDATE_FAIL)
+ fprintf(stdout, "\033[31mFAIL\033[0m (%s)\n", hint);
+ else if (level == VIR_HOST_VALIDATE_WARN)
+ fprintf(stdout, "\033[33mWARN\033[0m (%s)\n", hint);
+ else if (level == VIR_HOST_VALIDATE_NOTE)
+ fprintf(stdout, "\033[34mNOTE\033[0m (%s)\n", hint);
+}
+
+
+int virHostValidateDevice(const char *hvname,
+ const char *devname,
+ virHostValidateLevel level,
+ const char *hint)
+{
+ virHostMsgCheck(hvname, "for device %s", devname);
+
+ if (access(devname, R_OK|W_OK) < 0) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ virHostMsgPass();
+ return 0;
+}
+
+
+int virHostValidateHasCPUFlag(const char *name)
+{
+ FILE *fp = fopen("/proc/cpuinfo", "r");
+ int ret = 0;
+
+ if (!fp)
+ return 0;
+
+ do {
+ char line[1024];
+
+ if (!fgets(line, sizeof(line), fp))
+ break;
+
+ if (strstr(line, name)) {
+ ret = 1;
+ break;
+ }
+ } while (1);
+
+ fclose(fp);
+
+ return ret;
+}
+
+
+int virHostValidateLinuxKernel(const char *hvname,
+ int version,
+ virHostValidateLevel level,
+ const char *hint)
+{
+ struct utsname uts;
+ int major, minor, micro;
+
+ uname(&uts);
+
+ virHostMsgCheck(hvname, "for Linux >= %d.%d.%d",
+ ((version >> 16) & 0xff),
+ ((version >> 8) & 0xff),
+ (version & 0xff));
+
+ if (STRNEQ(uts.sysname, "Linux")) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ if (sscanf(uts.release, "%d.%d.%d", &major, &minor, µ) != 3) {
+ micro = 0;
+ if (sscanf(uts.release, "%d.%d", &major, &minor) != 2) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+ }
+
+ if (major > ((version >> 16) & 0xff)) {
+ virHostMsgPass();
+ return 0;
+ } else if (major < ((version >> 16) & 0xff)) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ if (minor > ((version >> 8) & 0xff)) {
+ virHostMsgPass();
+ return 0;
+ } else if (minor < ((version >> 8) & 0xff)) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ if (micro > (version & 0xff)) {
+ virHostMsgPass();
+ return 0;
+ } else if (micro < (version & 0xff)) {
+ virHostMsgFail(level, hint);
+ return -1;
+ }
+
+ virHostMsgPass();
+ return 0;
+}
diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-common.h
new file mode 100644
index 0000000..6a4d1ac
--- /dev/null
+++ b/tools/virt-host-validate-common.h
@@ -0,0 +1,53 @@
+/*
+ * virt-host-validate-common.h: Sanity check helper APis
+ *
+ * Copyright (C) 2011 Red Hat, 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
+ *
+ */
+
+#ifndef __VIRT_HOST_VALIDATE_COMMON_H__
+#define __VIRT_HOST_VALIDATE_COMMON_H__
+
+#include "internal.h"
+
+typedef enum {
+ VIR_HOST_VALIDATE_FAIL,
+ VIR_HOST_VALIDATE_WARN,
+ VIR_HOST_VALIDATE_NOTE,
+} virHostValidateLevel;
+
+extern void virHostMsgCheck(const char *prefix,
+ const char *format,
+ ...) ATTRIBUTE_FMT_PRINTF(2, 3);
+
+extern void virHostMsgPass(void);
+extern void virHostMsgFail(virHostValidateLevel level,
+ const char *hint);
+
+extern int virHostValidateDevice(const char *hvname,
+ const char *devname,
+ virHostValidateLevel level,
+ const char *hint);
+
+extern int virHostValidateHasCPUFlag(const char *name);
+
+extern int virHostValidateLinuxKernel(const char *hvname,
+ int version,
+ virHostValidateLevel level,
+ const char *hint);
+
+#endif /* __VIRT_HOST_VALIDATE_COMMON_H__ */
diff --git a/tools/virt-host-validate-lxc.c b/tools/virt-host-validate-lxc.c
new file mode 100644
index 0000000..f41cf78
--- /dev/null
+++ b/tools/virt-host-validate-lxc.c
@@ -0,0 +1,37 @@
+/*
+ * virt-host-validate-lxc.c: Sanity check a LXC hypervisor host
+ *
+ * Copyright (C) 2011 Red Hat, 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
+ *
+ */
+
+#include <config.h>
+
+#include "virt-host-validate-lxc.h"
+#include "virt-host-validate-common.h"
+
+int virHostValidateLXC(void)
+{
+ int ret = 0;
+
+ if (virHostValidateLinuxKernel("LXC", (2 << 16) | (6 << 8) | 26,
+ VIR_HOST_VALIDATE_FAIL,
+ "Upgrade to a kernel supporting namespaces") < 0)
+ ret = -1;
+
+ return ret;
+}
diff --git a/tools/virt-host-validate-lxc.h b/tools/virt-host-validate-lxc.h
new file mode 100644
index 0000000..3cae39f
--- /dev/null
+++ b/tools/virt-host-validate-lxc.h
@@ -0,0 +1,27 @@
+/*
+ * virt-host-validate-lxc.h: Sanity check a LXC hypervisor host
+ *
+ * Copyright (C) 2011 Red Hat, 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
+ *
+ */
+
+#ifndef __VIRT_HOST_VALIDATE_LXC_H__
+#define __VIRT_HOST_VALIDATE_LXC_H__
+
+extern int virHostValidateLXC(void);
+
+#endif /* __VIRT_HOST_VALIDATE_LXC_H__ */
diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qemu.c
new file mode 100644
index 0000000..b0e4fe5
--- /dev/null
+++ b/tools/virt-host-validate-qemu.c
@@ -0,0 +1,50 @@
+/*
+ * virt-host-validate-qemu.c: Sanity check a QEMU hypervisor host
+ *
+ * Copyright (C) 2011 Red Hat, 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
+ *
+ */
+
+#include <config.h>
+
+#include "virt-host-validate-qemu.h"
+#include "virt-host-validate-common.h"
+
+int virHostValidateQEMU(void)
+{
+ int ret = 0;
+
+ if (virHostValidateHasCPUFlag("svm") ||
+ virHostValidateHasCPUFlag("vmx")) {
+ if (virHostValidateDevice("QEMU", "/dev/kvm",
+ VIR_HOST_VALIDATE_FAIL,
+ "Check that the 'kvm-intel' or 'kvm-amd' modules are loaded & the BIOS has enabled virtualization") < 0)
+ ret = -1;
+ }
+
+ if (virHostValidateDevice("QEMU", "/dev/vhost",
+ VIR_HOST_VALIDATE_WARN,
+ "Load the 'vhost_net' module to improve performance of virtio networking") < 0)
+ ret = -1;
+
+ if (virHostValidateDevice("QEMU", "/dev/net/tun",
+ VIR_HOST_VALIDATE_FAIL,
+ "Load the 'tun' module to enable networking for QEMU guests") < 0)
+ ret = -1;
+
+ return ret;
+}
diff --git a/tools/virt-host-validate-qemu.h b/tools/virt-host-validate-qemu.h
new file mode 100644
index 0000000..e1dbcbe
--- /dev/null
+++ b/tools/virt-host-validate-qemu.h
@@ -0,0 +1,27 @@
+/*
+ * virt-host-validate-qemu.h: Sanity check a QEMU hypervisor host
+ *
+ * Copyright (C) 2011 Red Hat, 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
+ *
+ */
+
+#ifndef __VIRT_HOST_VALIDATE_QEMU_H__
+#define __VIRT_HOST_VALIDATE_QEMU_H__
+
+extern int virHostValidateQEMU(void);
+
+#endif /* __VIRT_HOST_VALIDATE_QEMU_H__ */
diff --git a/tools/virt-host-validate.c b/tools/virt-host-validate.c
new file mode 100644
index 0000000..b94aa8f
--- /dev/null
+++ b/tools/virt-host-validate.c
@@ -0,0 +1,77 @@
+/*
+ * virt-host-check.c: Sanity check a hypervisor host
+ *
+ * Copyright (C) 2011 Red Hat, 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
+ *
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <gettext.h>
+
+#include "internal.h"
+#include "configmake.h"
+
+#include "virt-host-validate-qemu.h"
+#include "virt-host-validate-lxc.h"
+
+static void
+show_help(FILE *out, const char *argv0)
+{
+ fprintf(out, "syntax: %s [OPTIONS] [HVTYPE]\n", argv0);
+}
+
+int
+main(int argc, char **argv)
+{
+ const char *hvname = NULL;
+ int ret = EXIT_SUCCESS;
+
+ if (!setlocale(LC_ALL, "")) {
+ perror("setlocale");
+ /* failure to setup locale is not fatal */
+ }
+ if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
+ perror("bindtextdomain");
+ return EXIT_FAILURE;
+ }
+ if (!textdomain(PACKAGE)) {
+ perror("textdomain");
+ return EXIT_FAILURE;
+ }
+
+ if (argc > 2) {
+ fprintf(stderr, "too many command line arguments\n");
+ show_help(stderr, argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (argc > 1)
+ hvname = argv[1];
+
+ if ((!hvname || STREQ(hvname, "qemu")) &&
+ virHostValidateQEMU() < 0)
+ ret = EXIT_FAILURE;
+
+ if ((!hvname || STREQ(hvname, "lxc")) &&
+ virHostValidateLXC() < 0)
+ ret = EXIT_FAILURE;
+
+ return ret;
+}
--
1.7.7.5
12 years, 9 months