[libvirt] [PATCH] storage: add check for invalid volume name
by Jincheng Miao
If volume name is a path, storageVolCreateXML appends that name to
the specified pool path, that will taint other pools. Adding the
volume check is better for sanity.
Signed-off-by: Jincheng Miao <jmiao(a)redhat.com>
---
src/storage/storage_driver.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 2cb8347..c3b807f 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -49,6 +49,7 @@
#include "configmake.h"
#include "virstring.h"
#include "viraccessapicheck.h"
+#include "dirname.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -1864,6 +1865,14 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
goto cleanup;
}
+ /* Make sure the volume name is not a path */
+ if (last_component(newvol->name) != newvol->name) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("storage volume name '%s' is a path"),
+ newvol->name);
+ goto cleanup;
+ }
+
/* Is there ever a valid case for this? */
if (newvol->target.capacity < origvol->target.capacity)
newvol->target.capacity = origvol->target.capacity;
--
1.8.3.1
10 years, 8 months
[libvirt] [PATCH v4] Introduce --without-pm-utils to get rid of pm-is-supported dependency
by Cédric Bosdonnat
This uses the dbus api of systemd to check the power management
capabilities of the node.
---
Diff with v3:
* Added unit tests vir virSystemdCan* helpers
* Make the default for with-pm-utils depending on dbus and systemd detection
* Changed the implementation of the helpers to return true for
'yes' and 'challenge' responses, we shouldn't get a 'no' given libvirtd runs
as privileged user... but who knows.
configure.ac | 24 +++++++++++
libvirt.spec.in | 9 +++++
src/libvirt_private.syms | 3 ++
src/util/virnodesuspend.c | 75 ++++++++++++++++++++++++++--------
src/util/virsystemd.c | 59 +++++++++++++++++++++++++++
src/util/virsystemd.h | 6 +++
tests/virsystemdmock.c | 22 ++++++++++
tests/virsystemdtest.c | 100 +++++++++++++++++++++++++++++++++++++++++++++-
8 files changed, 281 insertions(+), 17 deletions(-)
diff --git a/configure.ac b/configure.ac
index 73efffa..34e5ec2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -563,6 +563,10 @@ AC_ARG_WITH([chrdev-lock-files],
[location for UUCP style lock files for character devices
(use auto for default paths on some platforms) @<:@default=auto@:>@])])
m4_divert_text([DEFAULTS], [with_chrdev_lock_files=auto])
+AC_ARG_WITH([pm-utils],
+ [AS_HELP_STRING([--with-pm-utils],
+ [use pm-utils for power management @<:@default=yes@:>@])])
+m4_divert_text([DEFAULTS], [with_pm_utils=check])
dnl
dnl in case someone want to build static binaries
@@ -1621,6 +1625,25 @@ fi
AM_CONDITIONAL([WITH_PHYP],[test "$with_phyp" = "yes"])
+dnl
+dnl Should we build with pm-utils support?
+dnl
+set -x
+if test "$with_pm_utils" = "check"; then
+ with_pm_utils=yes
+ if test "$with_dbus" = "yes"; then
+ if test "$init_systemd" = "yes"; then
+ with_pm_utils=no
+ fi
+ fi
+fi
+
+if test "$with_pm_utils" = "yes"; then
+ AC_DEFINE_UNQUOTED([WITH_PM_UTILS], 1, [whether to use pm-utils])
+fi
+AM_CONDITIONAL([WITH_PM_UTILS], [test "$with_pm_utils" = "yes"])
+set +x
+
dnl virsh libraries
VIRSH_LIBS="$VIRSH_LIBS $READLINE_LIBS"
AC_SUBST([VIRSH_LIBS])
@@ -2845,6 +2868,7 @@ AC_MSG_NOTICE([ rbd: $LIBRBD_LIBS])
else
AC_MSG_NOTICE([ rbd: no])
fi
+AC_MSG_NOTICE([pm-utils: $with_pm_utils])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([Test suite])
diff --git a/libvirt.spec.in b/libvirt.spec.in
index eab9b23..5c20955 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -132,6 +132,7 @@
%define with_libssh2 0%{!?_without_libssh2:0}
%define with_wireshark 0%{!?_without_wireshark:0}
%define with_systemd_daemon 0%{!?_without_systemd_daemon:0}
+%define with_pm_utils 1
# Non-server/HV driver defaults which are always enabled
%define with_sasl 0%{!?_without_sasl:1}
@@ -182,6 +183,7 @@
%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7
%define with_systemd 1
%define with_systemd_daemon 1
+ %define with_pm_utils 0
%endif
# Fedora 18 / RHEL-7 are first where firewalld support is enabled
@@ -1138,8 +1140,10 @@ Requires: nc
Requires: gettext
# Needed by virt-pki-validate script.
Requires: gnutls-utils
+%if %{with_pm_utils}
# Needed for probing the power management features of the host.
Requires: pm-utils
+%{endif}
%if %{with_sasl}
Requires: cyrus-sasl
# Not technically required, but makes 'out-of-box' config
@@ -1395,6 +1399,10 @@ driver
%define _without_systemd_daemon --without-systemd-daemon
%endif
+%if ! %{with_pm_utils}
+ %define _without_pm_utils --without-pm-utils
+%endif
+
%define when %(date +"%%F-%%T")
%define where %(hostname)
%define who %{?packager}%{!?packager:Unknown}
@@ -1471,6 +1479,7 @@ rm -f po/stamp-po
%{?_with_firewalld} \
%{?_without_wireshark} \
%{?_without_systemd_daemon} \
+ %{?_without_pm_utils} \
%{with_packager} \
%{with_packager_version} \
--with-qemu-user=%{qemu_user} \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 38fbf63..ce51bdf 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1879,6 +1879,9 @@ virSysinfoSetup;
# util/virsystemd.h
+virSystemdCanHibernate;
+virSystemdCanHybridSleep;
+virSystemdCanSuspend;
virSystemdCreateMachine;
virSystemdMakeMachineName;
virSystemdMakeScopeName;
diff --git a/src/util/virnodesuspend.c b/src/util/virnodesuspend.c
index 8088931..b1eddff 100644
--- a/src/util/virnodesuspend.c
+++ b/src/util/virnodesuspend.c
@@ -22,6 +22,7 @@
#include <config.h>
#include "virnodesuspend.h"
+# include "virsystemd.h"
#include "vircommand.h"
#include "virthread.h"
#include "datatypes.h"
@@ -245,23 +246,9 @@ int nodeSuspendForDuration(unsigned int target,
return ret;
}
-
-/**
- * virNodeSuspendSupportsTarget:
- * @target: The power management target to check whether it is supported
- * by the host. Values could be:
- * VIR_NODE_SUSPEND_TARGET_MEM
- * VIR_NODE_SUSPEND_TARGET_DISK
- * VIR_NODE_SUSPEND_TARGET_HYBRID
- * @supported: set to true if supported, false otherwise
- *
- * Run the script 'pm-is-supported' (from the pm-utils package)
- * to find out if @target is supported by the host.
- *
- * Returns 0 if the query was successful, -1 on failure.
- */
+#ifdef WITH_PM_UTILS
static int
-virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
+virNodeSuspendSupportsTargetPMUtils(unsigned int target, bool *supported)
{
virCommandPtr cmd;
int status;
@@ -300,6 +287,62 @@ virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
virCommandFree(cmd);
return ret;
}
+#endif
+
+static int
+virNodeSuspendSupportsTargetSystemd(unsigned int target, bool *supported)
+{
+ int ret = -1;
+
+ if (virNodeSuspendInitialize() < 0)
+ return -1;
+
+ *supported = false;
+
+ switch (target) {
+ case VIR_NODE_SUSPEND_TARGET_MEM:
+ ret = virSystemdCanSuspend(supported);
+ break;
+ case VIR_NODE_SUSPEND_TARGET_DISK:
+ ret = virSystemdCanHibernate(supported);
+ break;
+ case VIR_NODE_SUSPEND_TARGET_HYBRID:
+ ret = virSystemdCanHybridSleep(supported);
+ break;
+ default:
+ return ret;
+ }
+
+ return ret;
+}
+
+/**
+ * virNodeSuspendSupportsTarget:
+ * @target: The power management target to check whether it is supported
+ * by the host. Values could be:
+ * VIR_NODE_SUSPEND_TARGET_MEM
+ * VIR_NODE_SUSPEND_TARGET_DISK
+ * VIR_NODE_SUSPEND_TARGET_HYBRID
+ * @supported: set to true if supported, false otherwise
+ *
+ * Run the script 'pm-is-supported' (from the pm-utils package)
+ * to find out if @target is supported by the host.
+ *
+ * Returns 0 if the query was successful, -1 on failure.
+ */
+static int
+virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
+{
+ int ret;
+
+ ret = virNodeSuspendSupportsTargetSystemd(target, supported);
+#ifdef WITH_PM_UTILS
+ if (ret < 0)
+ ret = virNodeSuspendSupportsTargetPMUtils(target, supported);
+#endif
+
+ return ret;
+}
/**
* virNodeSuspendGetTargetMask:
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 93b3f9c..e9ca564 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -325,3 +325,62 @@ virSystemdNotifyStartup(void)
sd_notify(0, "READY=1");
#endif
}
+
+static int
+virSystemdPMSupportTarget(const char *methodName, bool *result)
+{
+ int ret;
+ DBusConnection *conn;
+ DBusMessage *message = NULL;
+ char *response;
+
+ ret = virDBusIsServiceEnabled("org.freedesktop.login1");
+ if (ret < 0)
+ return ret;
+
+ if ((ret = virDBusIsServiceRegistered("org.freedesktop.login1")) < 0)
+ return ret;
+
+ if (!(conn = virDBusGetSystemBus()))
+ return -1;
+
+ ret = -1;
+
+ if (virDBusCallMethod(conn,
+ &message,
+ NULL,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ methodName,
+ NULL) < 0)
+ return ret;
+
+ if ((ret = virDBusMessageRead(message, "s", &response)) < 0)
+ goto cleanup;
+
+ *result = STREQ("yes", response) || STREQ("challenge", response);
+
+ ret = 0;
+
+ cleanup:
+ dbus_message_unref(message);
+ VIR_FREE(response);
+
+ return ret;
+}
+
+int virSystemdCanSuspend(bool *result)
+{
+ return virSystemdPMSupportTarget("CanSuspend", result);
+}
+
+int virSystemdCanHibernate(bool *result)
+{
+ return virSystemdPMSupportTarget("CanHibernate", result);
+}
+
+int virSystemdCanHybridSleep(bool *result)
+{
+ return virSystemdPMSupportTarget("CanHybridSleep", result);
+}
diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h
index 7fed456..491c9b7 100644
--- a/src/util/virsystemd.h
+++ b/src/util/virsystemd.h
@@ -48,4 +48,10 @@ int virSystemdTerminateMachine(const char *name,
void virSystemdNotifyStartup(void);
+int virSystemdCanSuspend(bool *result);
+
+int virSystemdCanHibernate(bool *result);
+
+int virSystemdCanHybridSleep(bool *result);
+
#endif /* __VIR_SYSTEMD_H__ */
diff --git a/tests/virsystemdmock.c b/tests/virsystemdmock.c
index 23167db..cc385ec 100644
--- a/tests/virsystemdmock.c
+++ b/tests/virsystemdmock.c
@@ -76,10 +76,21 @@ DBusMessage *dbus_connection_send_with_reply_and_block(DBusConnection *connectio
} else {
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
}
+ } else if (STREQ(service, "org.freedesktop.login1")) {
+ char *supported = getenv("RESULT_SUPPORT");
+ DBusMessageIter iter;
+ reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (!dbus_message_iter_append_basic(&iter,
+ DBUS_TYPE_STRING,
+ &supported))
+ goto error;
} else if (STREQ(service, "org.freedesktop.DBus") &&
STREQ(member, "ListActivatableNames")) {
const char *svc1 = "org.foo.bar.wizz";
const char *svc2 = "org.freedesktop.machine1";
+ const char *svc3 = "org.freedesktop.login1";
DBusMessageIter iter, sub;
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
dbus_message_iter_init_append(reply, &iter);
@@ -95,11 +106,17 @@ DBusMessage *dbus_connection_send_with_reply_and_block(DBusConnection *connectio
DBUS_TYPE_STRING,
&svc2))
goto error;
+ if (!getenv("FAIL_NO_SERVICE") &&
+ !dbus_message_iter_append_basic(&sub,
+ DBUS_TYPE_STRING,
+ &svc3))
+ goto error;
dbus_message_iter_close_container(&iter, &sub);
} else if (STREQ(service, "org.freedesktop.DBus") &&
STREQ(member, "ListNames")) {
const char *svc1 = "org.foo.bar.wizz";
const char *svc2 = "org.freedesktop.systemd1";
+ const char *svc3 = "org.freedesktop.login1";
DBusMessageIter iter, sub;
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
dbus_message_iter_init_append(reply, &iter);
@@ -115,6 +132,11 @@ DBusMessage *dbus_connection_send_with_reply_and_block(DBusConnection *connectio
DBUS_TYPE_STRING,
&svc2))
goto error;
+ if ((!getenv("FAIL_NO_SERVICE") && !getenv("FAIL_NOT_REGISTERED")) &&
+ !dbus_message_iter_append_basic(&sub,
+ DBUS_TYPE_STRING,
+ &svc3))
+ goto error;
dbus_message_iter_close_container(&iter, &sub);
} else {
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
index 4fc5137..a9583e7 100644
--- a/tests/virsystemdtest.c
+++ b/tests/virsystemdtest.c
@@ -205,7 +205,6 @@ static int testCreateBadSystemd(const void *opaque ATTRIBUTE_UNUSED)
return 0;
}
-
struct testScopeData {
const char *name;
const char *partition;
@@ -237,6 +236,86 @@ testScopeName(const void *opaque)
return ret;
}
+typedef int (*virSystemdCanHelper)(bool * result);
+struct testPMSupportData {
+ virSystemdCanHelper tested;
+};
+
+static int testPMSupportHelper(const void *opaque)
+{
+ int rv;
+ bool result;
+ size_t i;
+ const char *results[4] = {"yes", "no", "na", "challenge"};
+ int expected[4] = {1, 0, 0, 1};
+ const struct testPMSupportData *data = opaque;
+
+ for (i = 0; i < 4; i++) {
+ setenv("RESULT_SUPPORT", results[i], 1);
+ if ((rv = data->tested(&result)) < 0) {
+ fprintf(stderr, "%s", "Unexpected canSuspend error\n");
+ return -1;
+ }
+
+ if (result != expected[i]) {
+ fprintf(stderr, "Unexpected result for answer '%s'\n", results[i]);
+ goto error;
+ }
+ unsetenv("RESULT_SUPPORT");
+ }
+
+ return 0;
+error:
+ unsetenv("RESULT_SUPPORT");
+ return -1;
+}
+
+static int testPMSupportHelperNoSystemd(const void *opaque)
+{
+ int rv;
+ bool result;
+ const struct testPMSupportData *data = opaque;
+
+ setenv("FAIL_NO_SERVICE", "1", 1);
+
+ if ((rv = data->tested(&result)) == 0) {
+ unsetenv("FAIL_NO_SERVICE");
+ fprintf(stderr, "%s", "Unexpected canSuspend success\n");
+ return -1;
+ }
+ unsetenv("FAIL_NO_SERVICE");
+
+ if (rv != -2) {
+ fprintf(stderr, "%s", "Unexpected canSuspend error\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int testPMSupportSystemdNotRunning(const void *opaque)
+{
+ int rv;
+ bool result;
+ const struct testPMSupportData *data = opaque;
+
+ setenv("FAIL_NOT_REGISTERED", "1", 1);
+
+ if ((rv = data->tested(&result)) == 0) {
+ unsetenv("FAIL_NOT_REGISTERED");
+ fprintf(stderr, "%s", "Unexpected canSuspend success\n");
+ return -1;
+ }
+ unsetenv("FAIL_NOT_REGISTERED");
+
+ if (rv != -2) {
+ fprintf(stderr, "%s", "Unexpected canSuspend error\n");
+ return -1;
+ }
+
+ return 0;
+}
+
static int
mymain(void)
{
@@ -275,6 +354,25 @@ mymain(void)
TEST_SCOPE("demo", "/machine/eng-dept/testing!stuff",
"machine-eng\\x2ddept-testing\\x21stuff-lxc\\x2ddemo.scope");
+# define TESTS_PM_SUPPORT_HELPER(name, function) \
+ do { \
+ struct testPMSupportData data = { \
+ function \
+ }; \
+ if (virtTestRun("Test " name " ", testPMSupportHelper, &data) < 0) \
+ ret = -1; \
+ if (virtTestRun("Test " name " no systemd ", \
+ testPMSupportHelperNoSystemd, &data) < 0) \
+ ret = -1; \
+ if (virtTestRun("Test systemd " name " not running ", \
+ testPMSupportSystemdNotRunning, &data) < 0) \
+ ret = -1; \
+ } while (0)
+
+ TESTS_PM_SUPPORT_HELPER("canSuspend", &virSystemdCanSuspend);
+ TESTS_PM_SUPPORT_HELPER("canHibernate", &virSystemdCanHibernate);
+ TESTS_PM_SUPPORT_HELPER("canHybridSleep", &virSystemdCanHybridSleep);
+
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--
1.8.4.5
10 years, 8 months
[libvirt] [PATCH v2 1/1] Enable QEMU_CAPS_PCI_MULTIBUS capability for QEMU2.0 forward on PPC64.
by Li Zhang
From: Li Zhang <zhlcindy(a)linux.vnet.ibm.com>
For QEMU2.0 forward version on PPC64, it supports PCI multibus.
Currently, libvirt still disables it which causes an error
"Bus 'pci' not found".
Signed-off-by: Li Zhang <zhlcindy(a)linux.vnet.ibm.com>
---
src/qemu/qemu_capabilities.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 381b3ec..812bbe0 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2813,13 +2813,16 @@ virQEMUCapsInitHelp(virQEMUCapsPtr qemuCaps, uid_t runUid, gid_t runGid)
false) < 0)
goto cleanup;
- /* Currently only x86_64 and i686 support PCI-multibus. */
- if (qemuCaps->arch == VIR_ARCH_X86_64 ||
- qemuCaps->arch == VIR_ARCH_I686) {
+ /* Currently only x86_64, i686 and PPC64 support PCI-multibus. */
+ if ((qemuCaps->arch == VIR_ARCH_PPC64 &&
+ qemuCaps->version >= 2000000) ||
+ ARCH_IS_X86(qemuCaps->arch)) {
virQEMUCapsSet(qemuCaps, QEMU_CAPS_PCI_MULTIBUS);
- } else {
- /* -no-acpi is not supported on other archs
- * even if qemu reports it in -help */
+ }
+
+ /* -no-acpi is not supported on non-X86 archs
+ * even if qemu reports it in -help */
+ if (!ARCH_IS_X86(qemuCaps->arch)) {
virQEMUCapsClear(qemuCaps, QEMU_CAPS_NO_ACPI);
}
@@ -2940,11 +2943,14 @@ virQEMUCapsInitArchQMPBasic(virQEMUCapsPtr qemuCaps,
}
/*
- * Currently only x86_64 and i686 support PCI-multibus,
- * -no-acpi and -no-kvm-pit-reinjection.
+ * Currently only x86_64, i686 and PPC64 support PCI-multibus,
+ * Moreover, the first two arches support -no-acpi and
+ * -no-kvm-pit-reinjection.
*/
- if (qemuCaps->arch == VIR_ARCH_X86_64 ||
- qemuCaps->arch == VIR_ARCH_I686) {
+ if (qemuCaps->arch == VIR_ARCH_PPC64 &&
+ qemuCaps->version >= 2000000) {
+ virQEMUCapsSet(qemuCaps, QEMU_CAPS_PCI_MULTIBUS);
+ } else if (ARCH_IS_X86(qemuCaps->arch)) {
virQEMUCapsSet(qemuCaps, QEMU_CAPS_PCI_MULTIBUS);
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_ACPI);
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_KVM_PIT);
--
1.8.2.1
10 years, 8 months
[libvirt] [PATCH 0/5] progress towards removing virStorageFileMetadata
by Eric Blake
I'm almost to the point where virStorageSource can track everything
that virStorageFileMetadata was used for, so that we can use one
struct instead of two. But while working on this today, I noticed
that virStorageFileChainLookup() does not have any unit tests, so
I'll be writing those before removing the two remaining redundant
fields.
Eric Blake (5):
conf: provide details on network backing store
conf: expose probe for non-local storage
conf: delete useless backingStoreIsFile field
conf: return backing information separately from metadata
conf: delete useless backingStoreFormat field
src/conf/domain_conf.c | 2 +-
src/libvirt_private.syms | 1 +
src/storage/storage_backend_fs.c | 34 ++++----
src/storage/storage_backend_gluster.c | 14 ++--
src/util/virstoragefile.c | 146 +++++++++++++++++++++-------------
src/util/virstoragefile.h | 9 ++-
tests/virstoragetest.c | 49 ++++--------
7 files changed, 135 insertions(+), 120 deletions(-)
--
1.9.0
10 years, 8 months
[libvirt] [PATCH] conf: make virstoragetest debug easier
by Eric Blake
I'm tired of alternating between test failures due to bugs in
my refactoring work, vs. test failures due to leftovers in
the file system from the previous test. This patch has no
impact when the testsuite is successful, but doeesn't hurt either.
* tests/virstoragetest.c (testPrepImages): Clean up from prior
failed test.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
Pushing under the trivial rule.
tests/virstoragetest.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 13b5032..029561c 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -102,6 +102,9 @@ testPrepImages(void)
if (!qemuimg)
goto skip;
+ /* Clean up from any earlier failed tests */
+ virFileDeleteTree(datadir);
+
/* See if qemu-img supports '-o compat=xxx'. If so, we force the
* use of both v2 and v3 files; if not, it is v2 only but the test
* still works. */
--
1.9.0
10 years, 8 months
[libvirt] [PATCH 00/13] Add multiple trace backend function and add new ftrace backend for libvirt
by yangzy.fnst@cn.fujitsu.com
From: Xinghai Yu <yuxinghai(a)cn.fujitsu.com>
This patch set will let libvirt to support multiple trace backend function
and add a new 'ftrace' backend at the same time.
Then, libvirt would have 2 trace backend: dtrace, ftrace.They can be used
alone or together.
Patchs 1,2,3,4,5 are used for supporting multiple trace backend function.
Patch 6 are used for adding ftrace as a new trace backend for libvirt.
Patchs 7,8,9,10,11,12,13 add ftrace initial code in programs who use it.
Thanks very much for Stefan Hajnoczi for I have used his scripts in patch
4 which commited in qemu.
Thanks very much for Eiichi Tsukata for I have used his ftrace codes in
patch 6 which commited in qemu.
Backgroud:
The existing trace mechanism in libvirt is dtrace. Although the dtrace
can work, it's not work well enough. Every time we want get information
from the trace point we must write a systemtap script and run it
together with libvirt.
That's really unpractical on some occasion, especially on production
server since the systemtap script can't be executed automatically.
And some problems may be not easy to reproduce, then it will cost a
lot of time to get the trace information again.
So I think it is essential to add supporting for record the trace
information automatically in libvirt to satisfy the user's requirement.
That's why I implemented multiple trace backend function and ftrace
support in libvirt.
Xinghai Yu (13):
configure.ac: Define new macro 'WITH_TRACE_PROBES' to indicate trace
function are available
Makefile.am: Add new multiple trace backend supporting framework
src: Use new tracepoint declaration files to replace the old dtrace
declaration files to support multiple trace function
src: Add scripts 'tracetool' to supporting the translation from
tracepoint files to multiple trace backend supporting files
daemon,src: Use new tracepoint function calls to replace old PROBE
macro calls to support multiple trace function
configure.ac, Makefile.am, src: Add new ftrace backend
src/libvirt.c: Init ftrace backend in libvirt library so that programs
containing it can use ftrace
src/qemu/qemu_driver.c: Init ftrace backend in qemu driver so that
qemu driver can support ftrace
src/locking/lock_daemon.c: Init ftrace backend in program 'virtlockd'
src/util/iohelper.c: Init ftrace backend in program 'libvirt_iohelper'
src/storage/parthelper.c: Init ftrace backend in program
'libvirt_parthelper'
src/lxc/lxc_controller.c: Init ftrace backend in program 'libvirt_lxc'
src/security/virt-aa-helper.c: Init ftrace backend in program
'virt-aa-helper'
config-post.h | 2 +-
configure.ac | 24 ++++
daemon/Makefile.am | 13 +-
daemon/remote.c | 77 +++++------
src/Makefile.am | 179 +++++++++++++++++++------
src/ftrace.c | 91 +++++++++++++
src/ftrace.h | 14 ++
src/internal.h | 69 +----------
src/libvirt.c | 9 ++
src/libvirt_probes.d | 82 ------------
src/libvirt_qemu_probes.d | 22 ----
src/libvirt_qemu_trace_events | 15 +++
src/libvirt_trace_events | 70 ++++++++++
src/locking/lock_daemon.c | 9 ++
src/lxc/lxc_controller.c | 9 ++
src/qemu/qemu_driver.c | 10 ++
src/qemu/qemu_monitor.c | 42 +++---
src/qemu/qemu_monitor_json.c | 12 +-
src/qemu/qemu_monitor_text.c | 8 +-
src/rpc/virkeepalive.c | 42 +++---
src/rpc/virnetclient.c | 43 +++---
src/rpc/virnetserverclient.c | 31 ++---
src/rpc/virnetsocket.c | 22 ++--
src/rpc/virnettlscontext.c | 42 +++---
src/security/virt-aa-helper.c | 9 ++
src/storage/parthelper.c | 9 ++
src/tracetool.py | 103 +++++++++++++++
src/tracetool/__init__.py | 268 ++++++++++++++++++++++++++++++++++++++
src/tracetool/backend/__init__.py | 120 +++++++++++++++++
src/tracetool/backend/trace.py | 112 ++++++++++++++++
src/tracetool/format/__init__.py | 103 +++++++++++++++
src/tracetool/format/c.py | 22 ++++
src/tracetool/format/d.py | 20 +++
src/tracetool/format/h.py | 22 ++++
src/util/iohelper.c | 9 ++
src/util/vireventpoll.c | 66 +++++-----
src/util/virobject.c | 16 ++-
tests/Makefile.am | 13 +-
tools/virsh.c | 3 +
39 files changed, 1429 insertions(+), 401 deletions(-)
create mode 100644 src/ftrace.c
create mode 100644 src/ftrace.h
delete mode 100644 src/libvirt_probes.d
delete mode 100644 src/libvirt_qemu_probes.d
create mode 100644 src/libvirt_qemu_trace_events
create mode 100644 src/libvirt_trace_events
create mode 100644 src/tracetool.py
create mode 100644 src/tracetool/__init__.py
create mode 100644 src/tracetool/backend/__init__.py
create mode 100644 src/tracetool/backend/trace.py
create mode 100644 src/tracetool/format/__init__.py
create mode 100644 src/tracetool/format/c.py
create mode 100644 src/tracetool/format/d.py
create mode 100644 src/tracetool/format/h.py
--
1.8.3.1
10 years, 8 months
[libvirt] [PATCH] Add support for timestamping QEMU logs
by Ján Tomko
QEMU commit 5e2ac51 added a boolean '-msg timestamp=[on|off]'
option, which can enable timestamps on errors:
$ qemu-system-x86_64 -msg timestamp=on zghhdorf
2014-04-09T13:25:46.779484Z qemu-system-x86_64: -msg timestamp=on: could
not open disk image zghhdorf: Could not open 'zghhdorf': No such file or
directory
Enable this timestamp if the QEMU binary supports it.
Add a 'log_timestamp' option to qemu.conf for disabling this behavior.
---
src/qemu/libvirtd_qemu.aug | 3 +++
src/qemu/qemu.conf | 8 ++++++++
src/qemu/qemu_capabilities.c | 5 +++++
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 4 ++++
src/qemu/qemu_conf.c | 4 ++++
src/qemu/qemu_conf.h | 2 ++
src/qemu/test_libvirtd_qemu.aug.in | 1 +
tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 1 +
tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 +
tests/qemuxml2argvtest.c | 1 +
11 files changed, 31 insertions(+)
diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index a9ff421..e985d22 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -85,6 +85,8 @@ module Libvirtd_qemu =
| int_entry "migration_port_min"
| int_entry "migration_port_max"
+ let log_entry = bool_entry "log_timestamp"
+
(* Each entry in the config is one of the following ... *)
let entry = vnc_entry
| spice_entry
@@ -96,6 +98,7 @@ module Libvirtd_qemu =
| device_entry
| rpc_entry
| network_entry
+ | log_entry
let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
let empty = [ label "#empty" . eol ]
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index f0e802f..42f812d 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -465,3 +465,11 @@
#
#migration_port_min = 49152
#migration_port_max = 49215
+
+
+
+# Timestamp QEMU's log messages (if QEMU supports it)
+#
+# Defaults to 1.
+#
+#log_timestamp = 0
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 381b3ec..71bf5f2 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -254,6 +254,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
"spiceport",
"usb-kbd", /* 165 */
+ "msg-timestamp",
);
@@ -1143,6 +1144,9 @@ virQEMUCapsComputeCmdFlags(const char *help,
if (strstr(help, "-machine"))
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_OPT);
+ if (strstr(help, "-msg timestamp"))
+ virQEMUCapsSet(qemuCaps, QEMU_CAPS_MSG_TIMESTAMP);
+
/* USB option is supported v1.3.0 onwards */
if (qemuCaps->version >= 1003000)
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_USB_OPT);
@@ -2329,6 +2333,7 @@ static struct virQEMUCapsCommandLineProps virQEMUCapsCommandLine[] = {
{ "boot-opts", "strict", QEMU_CAPS_BOOT_STRICT },
{ "boot-opts", "reboot-timeout", QEMU_CAPS_REBOOT_TIMEOUT },
{ "spice", "disable-agent-file-xfer", QEMU_CAPS_SPICE_FILE_XFER_DISABLE },
+ { "msg", "timestamp", QEMU_CAPS_MSG_TIMESTAMP },
};
static int
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index df8c978..f1ea05b 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -204,6 +204,7 @@ enum virQEMUCapsFlags {
QEMU_CAPS_SPICE_FILE_XFER_DISABLE = 163, /* -spice disable-agent-file-xfer */
QEMU_CAPS_CHARDEV_SPICEPORT = 164, /* -chardev spiceport */
QEMU_CAPS_DEVICE_USB_KBD = 165, /* -device usb-kbd */
+ QEMU_CAPS_MSG_TIMESTAMP = 166, /* -msg timestamp */
QEMU_CAPS_LAST, /* this must always be the last item */
};
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 379c094..286070a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9735,6 +9735,10 @@ qemuBuildCommandLine(virConnectPtr conn,
virCommandSetMaxMemLock(cmd, memKB * 1024);
}
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MSG_TIMESTAMP) &&
+ cfg->logTimestamp)
+ virCommandAddArgList(cmd, "-msg", "timestamp=on", NULL);
+
virObjectUnref(cfg);
return cmd;
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 198ee2f..e487f5e 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -255,6 +255,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
cfg->keepAliveCount = 5;
cfg->seccompSandbox = -1;
+ cfg->logTimestamp = true;
+
return cfg;
error:
@@ -576,6 +578,8 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
GET_VALUE_STR("migration_address", cfg->migrationAddress);
+ GET_VALUE_BOOL("log_timestamp", cfg->logTimestamp);
+
ret = 0;
cleanup:
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a36ea63..5d2983a 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -167,6 +167,8 @@ struct _virQEMUDriverConfig {
char *migrationAddress;
int migrationPortMin;
int migrationPortMax;
+
+ bool logTimestamp;
};
/* Main driver state */
diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in
index b2328d3..30a4257 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -72,3 +72,4 @@ module Test_libvirtd_qemu =
{ "migration_address" = "127.0.0.1" }
{ "migration_port_min" = "49152" }
{ "migration_port_max" = "49215" }
+{ "log_timestamp" = "0" }
diff --git a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps
index 597f873..55ad973 100644
--- a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps
@@ -142,4 +142,5 @@
<flag name='spice-file-xfer-disable'/>
<flag name='spiceport'/>
<flag name='usb-kbd'/>
+ <flag name='msg-timestamp'/>
</qemuCaps>
diff --git a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps
index 0c1dd87..37b1a9a 100644
--- a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps
+++ b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps
@@ -140,4 +140,5 @@
<flag name='spice-file-xfer-disable'/>
<flag name='spiceport'/>
<flag name='usb-kbd'/>
+ <flag name='msg-timestamp'/>
</qemuCaps>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 13ed4f6..3e81998 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -582,6 +582,7 @@ mymain(void)
unsetenv("SDL_AUDIODRIVER");
DO_TEST("minimal", QEMU_CAPS_NAME);
+ DO_TEST("minimal-msg-timestamp", QEMU_CAPS_NAME, QEMU_CAPS_MSG_TIMESTAMP);
DO_TEST("minimal-s390", QEMU_CAPS_NAME);
DO_TEST("machine-aliases1", NONE);
DO_TEST("machine-aliases2", QEMU_CAPS_KVM);
--
1.8.3.2
10 years, 8 months
[libvirt] [PATCH] Fix build on mingw32
by Ján Tomko
My commit 897808e added a parameter to virCgroupGetPercpuStats,
but didn't change the stub for systems where cgroups are not supported.
---
Pushed as a build-breaker fix.
src/util/vircgroup.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 74e0907..c7ebf8d 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -4469,7 +4469,8 @@ virCgroupGetPercpuStats(virCgroupPtr group ATTRIBUTE_UNUSED,
virTypedParameterPtr params ATTRIBUTE_UNUSED,
unsigned int nparams ATTRIBUTE_UNUSED,
int start_cpu ATTRIBUTE_UNUSED,
- unsigned int ncpus ATTRIBUTE_UNUSED)
+ unsigned int ncpus ATTRIBUTE_UNUSED,
+ unsigned int nvcpupids ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Control groups not supported on this platform"));
--
1.8.3.2
10 years, 8 months
[libvirt] [PATCH 0/6] qemuDomainGetPercpuStats cleanups
by Ján Tomko
This series removes qemuDomainGetPercpuStats in favor of
virCgroupGetPercpuStats, fixes incorrect startcpu
boundaries check and cleans the code up.
Ján Tomko (6):
Don't require domain obj in qemuDomainGetPercpuStats
Fix return value of virCgroupGetPercpuStats
Extend virCgroupGetPercpuStats to fill in vcputime too
Rename id, max_id to need_cpus, total_cpus
Check maximum startcpu value correctly
Clean up virCgroupGetPercpuStats
src/lxc/lxc_driver.c | 2 +-
src/qemu/qemu_driver.c | 163 +------------------------------------------------
src/util/vircgroup.c | 115 ++++++++++++++++++++++++++++------
src/util/vircgroup.h | 3 +-
tests/vircgrouptest.c | 2 +-
5 files changed, 103 insertions(+), 182 deletions(-)
--
1.8.3.2
10 years, 8 months
[libvirt] [PATCH] virsh: Fix comment of vshCmdInfo
by liyang
From: Li Yang <liyang.fnst(a)cn.fujitsu.com>
The original comment of vshCmdInfo:
"name" - command name
Actually it's 'help' and the short description
of command, not the command name.
Signed-off-by: Li Yang <liyang.fnst(a)cn.fujitsu.com>
---
tools/virsh.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/virsh.h b/tools/virsh.h
index 3e0251b..1ffc003 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -154,7 +154,7 @@ typedef char **(*vshCompleter)(unsigned int flags);
* vshCmdInfo -- name/value pair for information about command
*
* Commands should have at least the following names:
- * "name" - command name
+ * "help" - short description of command
* "desc" - description of command, or empty string
*/
struct _vshCmdInfo {
--
1.7.1
10 years, 8 months