[libvirt] [PATCH] qemu: add return value check
by ajia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
* src/qemu/qemu_command.c: missing return value check.
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
src/qemu/qemu_command.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 5f0de40..e8b1157 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1702,7 +1702,8 @@ qemuBuildDriveDevStr(virDomainDiskDefPtr disk,
virBufferAsprintf(&opt, ",event_idx=%s",
virDomainVirtioEventIdxTypeToString(disk->event_idx));
}
- qemuBuildDeviceAddressStr(&opt, &disk->info, qemuCaps);
+ if (qemuBuildDeviceAddressStr(&opt, &disk->info, qemuCaps) < 0)
+ goto error;
break;
case VIR_DOMAIN_DISK_BUS_USB:
virBufferAddLit(&opt, "usb-storage");
@@ -1781,7 +1782,9 @@ qemuBuildFSDevStr(virDomainFSDefPtr fs,
virBufferAsprintf(&opt, ",id=%s", fs->info.alias);
virBufferAsprintf(&opt, ",fsdev=%s%s", QEMU_FSDEV_HOST_PREFIX, fs->info.alias);
virBufferAsprintf(&opt, ",mount_tag=%s", fs->dst);
- qemuBuildDeviceAddressStr(&opt, &fs->info, qemuCaps);
+
+ if (qemuBuildDeviceAddressStr(&opt, &fs->info, qemuCaps) < 0)
+ goto error;
if (virBufferError(&opt)) {
virReportOOMError();
--
1.7.1
13 years, 2 months
[libvirt] [PATCH] snapshot: affect persistent xml after disk snapshot
by Eric Blake
For external snapshots to be useful on persistent domains, we must
alter the persistent definition alongside the running definition.
Thanks to the possibility of disk hotplug as well as of edits that
only affect the persistent xml, we can't assume that vm->def and
vm->newDef have the same disk at the same index, so we can only
update the persistent copy if the device destination matches up.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive)
(qemuDomainSnapshotCreateSingleDiskActive): Also affect newDef, if
present.
---
This is worth including in 0.9.5 - without it, the new feature of
disk snapshots on a persistent domain are lost the moment the domain
stops running, which is likely to cause data corruption for guests.
I'm still trying to reproduce another reported snapshot failure:
https://bugzilla.redhat.com/show_bug.cgi?id=738676
although I don't think this patch will help that issue.
src/qemu/qemu_driver.c | 38 ++++++++++++++++++++++++++++++++------
1 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 32f376ec..cbe28d8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9107,12 +9107,15 @@ static int
qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
virDomainObjPtr vm,
virDomainSnapshotDiskDefPtr snap,
- virDomainDiskDefPtr disk)
+ virDomainDiskDefPtr disk,
+ virDomainDiskDefPtr persistDisk)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
char *device = NULL;
char *source = NULL;
char *driverType = NULL;
+ char *persistSource = NULL;
+ char *persistDriverType = NULL;
int ret = -1;
int fd = -1;
char *origsrc = NULL;
@@ -9128,7 +9131,11 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0 ||
!(source = strdup(snap->file)) ||
(STRNEQ_NULLABLE(disk->driverType, "qcow2") &&
- !(driverType = strdup("qcow2")))) {
+ !(driverType = strdup("qcow2"))) ||
+ (persistDisk &&
+ (!(persistSource = strdup(source)) ||
+ (STRNEQ_NULLABLE(persistDisk->driverType, "qcow2") &&
+ !(persistDriverType = strdup("qcow2")))))) {
virReportOOMError();
goto cleanup;
}
@@ -9176,9 +9183,16 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
disk->driverType = driverType;
driverType = NULL;
}
-
- /* XXX Do we also need to update vm->newDef if there are pending
- * configuration changes awaiting the next boot? */
+ if (persistDisk) {
+ VIR_FREE(persistDisk->src);
+ persistDisk->src = persistSource;
+ persistSource = NULL;
+ if (persistDriverType) {
+ VIR_FREE(persistDisk->driverType);
+ persistDisk->driverType = persistDriverType;
+ persistDriverType = NULL;
+ }
+ }
cleanup:
if (origsrc) {
@@ -9190,6 +9204,8 @@ cleanup:
VIR_FREE(device);
VIR_FREE(source);
VIR_FREE(driverType);
+ VIR_FREE(persistSource);
+ VIR_FREE(persistDriverType);
return ret;
}
@@ -9235,12 +9251,22 @@ qemuDomainSnapshotCreateDiskActive(virConnectPtr conn,
* SNAPSHOT_EXTERNAL with a valid file name and qcow2 format. */
qemuDomainObjEnterMonitorWithDriver(driver, vm);
for (i = 0; i < snap->def->ndisks; i++) {
+ virDomainDiskDefPtr persistDisk = NULL;
+
if (snap->def->disks[i].snapshot == VIR_DOMAIN_DISK_SNAPSHOT_NO)
continue;
+ if (vm->newDef) {
+ int indx = virDomainDiskIndexByName(vm->newDef,
+ vm->def->disks[i]->dst,
+ false);
+ if (indx >= 0)
+ persistDisk = vm->newDef->disks[indx];
+ }
ret = qemuDomainSnapshotCreateSingleDiskActive(driver, vm,
&snap->def->disks[i],
- vm->def->disks[i]);
+ vm->def->disks[i],
+ persistDisk);
if (ret < 0)
break;
}
--
1.7.4.4
13 years, 2 months
[libvirt] [PATCH] snapshot: allow disk snapshots of qcow2 disks
by Eric Blake
For all types of disks other than qcow2, we were requesting that
SELinux labeling visit the new file as if it were qcow2, which
means labeling would try to find the backing files of an empty file.
And for a pre-existing qcow2 disk, we were passing NULL, which meant
that labelling tried to probe the file type (and if probing is
disabled, per the default qemu.conf, this made snapshots fail).
What we really want is to make SELinux labeling visit the new
file as raw; it will later be converted to qcow2 if qemu successfully
made the snapshot.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive): Force SELinux labeling
to avoid probe of new file.
---
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=738676
I wonder why we are passing disk types as strings, instead of encoding
them as an enum. Use of an enum would avoid my ugly hack of having to
cast away const of my temporary assignment of a string.
src/qemu/qemu_driver.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2a1e5ea..e2f428f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9151,7 +9151,7 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
origsrc = disk->src;
disk->src = source;
origdriver = disk->driverType;
- disk->driverType = driverType;
+ disk->driverType = (char *) "raw"; /* Don't want to probe backing files */
if (virDomainLockDiskAttach(driver->lockManager, vm, disk) < 0)
goto cleanup;
--
1.7.4.4
13 years, 2 months
[libvirt] [PATCH] spec: silence warnings when installing in F16
by Eric Blake
https://bugzilla.redhat.com/show_bug.cgi?id=738725 documents that
'yum install libvirt' in Fedora 16 is rather noisy. This fixes
the problems.
* libvirt.spec.in (%post client): Silence chkconfig warning about
SysV services.
(%post) [with_cgconfig]: Drop for Fedora 15 and newer, where
systemd does this automatically.
---
We should get this in before 0.9.5, but I'm just fuzzy enough with
spec files that I'd prefer an ACK instead of invoking the trivial rule.
libvirt.spec.in | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 19f91d7..25e521c 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -894,10 +894,14 @@ done
%endif
%if %{with_cgconfig}
+# Starting with Fedora 15, systemd automounts all cgroups, and cgconfig is
+# no longer a necessary service.
+%if 0%{?fedora} <= 14 || 0%{?rhel} <= 6
if [ "$1" -eq "1" ]; then
/sbin/chkconfig cgconfig on
fi
%endif
+%endif
/sbin/chkconfig --add libvirtd
if [ "$1" -ge "1" ]; then
@@ -926,7 +930,8 @@ fi
/sbin/chkconfig --add libvirt-guests
if [ $1 -ge 1 ]; then
level=$(/sbin/runlevel | /bin/cut -d ' ' -f 2)
- if /sbin/chkconfig --list libvirt-guests | /bin/grep -q $level:on ; then
+ if /sbin/chkconfig --list libvirt-guests 2>/dev/null \
+ | /bin/grep -q $level:on ; then
# this doesn't do anything but allowing for libvirt-guests to be
# stopped on the first shutdown
/sbin/service libvirt-guests start > /dev/null 2>&1 || true
--
1.7.4.4
13 years, 2 months
[libvirt] [PATCH 0/3] Fix Mac OS X build issues (and probably also BSD)
by Peter Krempa
While compiling libvirt on a Mac OS X machine, the build failed tue to several
reasons. This patchset fixes these issues and along with another patch
that removes shadowed declarations of "devname" from stdlib.h on BSD based
systems causes libvirt to compile cleanly.
These patches were tested on v0.9.5-rc2 as I don't have the complete
toolchain to do ./autogen.sh on a gitcheckout.
Problems found:
- fdatasync() is not supported on OS X.
- Conditionaly compiled structure was left out but function using it was not.
- OS X does not provide a 'mkfs' command, so the MKFS macro was not set.
- /usr/include/stdlib.h exports 'devname' wildly used through libvirt
Peter Krempa (3):
build: storage: fdatasync() is not supported in Mac OS X.
build: storage: Conditionaly compiled structure caused build fail on OSX
build: storage: Macro 'MKFS' is undefined on some platforms.
src/storage/storage_backend.c | 2 +-
src/storage/storage_backend_fs.c | 15 +++++++++++++++
src/storage/storage_backend_fs.h | 3 ++-
src/storage/storage_driver.c | 2 +-
4 files changed, 19 insertions(+), 3 deletions(-)
--
1.7.3.4
13 years, 2 months
[libvirt] [PATCH] Prevent crash from dlclose() of libvirt.so
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
When libvirt calls virInitialize it creates a thread local
for the virErrorPtr storage, and registers a callback to
cleanup memory when a thread exits. When libvirt is dlclose()d
or otherwise made non-resident, the callback function is
removed from memory, but the thread local may still exist
and if a thread later exists, it will invoke the callback
and SEGV. There may also be other thread locals with callbacks
pointing to libvirt code, so it is in general never safe to
unload libvirt.so from memory once initialized.
To allow dlclose() to succeed, but keep libvirt.so resident
in memory, link with '-z nodelete'. This issue was first
found with the libvirt CIM provider, but can potentially
hit many of the dynamic language bindings which all ultimately
involve dlopen() in some way, either on libvirt.so itself,
or on the glue code for the binding which in turns links
to libvirt
* configure.ac, src/Makefile.am: Ensure libvirt.so is linked
with -z nodelete
* tests/.gitignore, tests/Makefile.am, tests/shunloadhelper.c,
tests/shunloadtest.c: A test case to unload libvirt while
a thread is still running.
---
configure.ac | 9 +++
src/Makefile.am | 2 +-
tests/.gitignore | 3 +
tests/Makefile.am | 14 ++++-
tests/shunloadhelper.c | 51 ++++++++++++++++
tests/shunloadtest.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 228 insertions(+), 2 deletions(-)
create mode 100644 tests/shunloadhelper.c
create mode 100644 tests/shunloadtest.c
diff --git a/configure.ac b/configure.ac
index 3c08a19..148c1da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -96,9 +96,18 @@ AM_PROG_LIBTOOL
AM_PROG_CC_C_O
AM_PROG_LD
+AC_MSG_CHECKING([for how to mark DSO non-deletable at runtime])
+LIBVIRT_NODELETE=
+`$LD --help 2>&1 | grep -- "-z nodelete" >/dev/null` && \
+ LIBVIRT_NODELETE="-Wl,-z -Wl,nodelete"
+AC_MSG_RESULT([$LIBVIRT_NODELETE])
+AC_SUBST([LIBVIRT_NODELETE])
+
+AC_MSG_CHECKING([for how to set DSO symbol versions])
VERSION_SCRIPT_FLAGS=-Wl,--version-script=
`$LD --help 2>&1 | grep -- --version-script >/dev/null` || \
VERSION_SCRIPT_FLAGS="-Wl,-M -Wl,"
+AC_MSG_RESULT([$VERSION_SCRIPT_FLAGS])
LIBVIRT_COMPILE_WARNINGS([maximum])
diff --git a/src/Makefile.am b/src/Makefile.am
index 322c900..ae1b9e0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1228,7 +1228,7 @@ libvirt_qemu.def: $(srcdir)/libvirt_qemu.syms
libvirt_la_SOURCES =
libvirt_la_LDFLAGS = $(VERSION_SCRIPT_FLAGS)$(LIBVIRT_SYMBOL_FILE) \
-version-info $(LIBVIRT_VERSION_INFO) \
- $(AM_LDFLAGS) \
+ $(AM_LDFLAGS) $(LIBVIRT_NODELETE) \
$(CYGWIN_EXTRA_LDFLAGS) $(MINGW_EXTRA_LDFLAGS)
libvirt_la_BUILT_LIBADD += ../gnulib/lib/libgnu.la
libvirt_la_LIBADD += $(LIBXML_LIBS) \
diff --git a/tests/.gitignore b/tests/.gitignore
index 7159c37..37ca034 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,6 +1,7 @@
*.exe
.deps
.libs
+*.lo
ssh
commandhelper
commandhelper.log
@@ -41,3 +42,5 @@ xencapstest
xmconfigtest
xml2sexprtest
xml2vmxtest
+libshunload.la
+shunloadtest
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f4afcb9..cbbbc6f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -89,7 +89,9 @@ check_PROGRAMS = virshtest conftest sockettest \
nodeinfotest qparamtest virbuftest \
commandtest commandhelper seclabeltest \
hashtest virnetmessagetest virnetsockettest ssh \
- utiltest virnettlscontexttest
+ utiltest virnettlscontexttest shunloadtest
+
+check_LTLIBRARIES = libshunload.la
# This is a fake SSH we use from virnetsockettest
ssh_SOURCES = ssh.c
@@ -207,6 +209,7 @@ TESTS = virshtest \
virnetmessagetest \
virnetsockettest \
virnettlscontexttest \
+ shunloadtest \
utiltest \
$(test_scripts)
@@ -503,6 +506,15 @@ eventtest_SOURCES = \
eventtest_LDADD = -lrt $(LDADDS)
endif
+libshunload_la_SOURCES = shunloadhelper.c
+libshunload_la_LIBADD = ../src/libvirt.la
+libshunload_la_LDFLAGS = -module -avoid-version -rpath /evil/libtool/hack/to/force/shared/lib/creation
+
+shunloadtest_SOURCES = \
+ shunloadtest.c
+shunloadtest_LDADD = -lpthread
+shunloadtest_DEPENDENCIES = libshunload.la
+
if WITH_CIL
CILOPTFLAGS =
CILOPTINCS =
diff --git a/tests/shunloadhelper.c b/tests/shunloadhelper.c
new file mode 100644
index 0000000..6cbf5f4
--- /dev/null
+++ b/tests/shunloadhelper.c
@@ -0,0 +1,51 @@
+/*
+ * 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
+ *
+ */
+
+/*
+ * This is a helper for shunloadtest.c. This function is built into
+ * a shared library and linked with libvirto.so
+ *
+ * The function initializes libvirt and primes the thread local with
+ * an error which needs to be freed at thread exit
+ */
+
+#include "internal.h"
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include <stdlib.h>
+
+static void shunloadError(void *userData ATTRIBUTE_UNUSED,
+ virErrorPtr error ATTRIBUTE_UNUSED)
+{
+}
+
+void shunloadStart(void);
+
+void shunloadStart(void) {
+ virConnectPtr conn;
+
+ virSetErrorFunc(NULL, shunloadError);
+ virInitialize();
+
+ conn = virConnectOpen("test:///default");
+ virDomainDestroy(NULL);
+ if (conn)
+ virConnectClose(conn);
+}
diff --git a/tests/shunloadtest.c b/tests/shunloadtest.c
new file mode 100644
index 0000000..cbcbf45
--- /dev/null
+++ b/tests/shunloadtest.c
@@ -0,0 +1,151 @@
+/*
+ * 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
+ *
+ */
+
+/*
+ * When libvirt initializes, it creates a thread local for storing
+ * the last virErrorPtr instance. It also registers a cleanup
+ * callback for the thread local that will be invoked whenever
+ * a thread exits.
+ *
+ * If the libvirt.so library was dlopen()'d and is dlclose()'d
+ * while there is still a thread present, then when that thread
+ * later exits, the libvirt cleanup callback will be invoked.
+ * Unfortunately libvirt.so will no longer be in memory so the
+ * callback SEGVs (if you're lucky), or invokes unlreated
+ * code at the same address as the old callback (in you're
+ * unlucky).
+ *
+ * To fix the problem libvirt is linked '-z nodelete' which
+ * prevents the code being removed from memory at dlclose().
+ *
+ * This test case demonstrates this SEGV scenario. If this
+ * test does not SEGV, then the '-z nodelete' fix is working
+ */
+
+#ifdef linux
+
+#include <dlfcn.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include "internal.h"
+#include "ignore-value.h"
+#include "testutils.h"
+
+pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+bool running = false;
+bool quit = false;
+
+static void *threadMain(void *arg)
+{
+ void (*startup)(void) = arg;
+
+ startup();
+
+ pthread_mutex_lock(&lock);
+ running = true;
+ pthread_cond_signal(&cond);
+
+ while (!quit) {
+ pthread_cond_wait(&cond, &lock);
+ }
+ pthread_mutex_unlock(&lock);
+
+ return NULL;
+}
+
+static void sigHandler(int sig)
+{
+ ignore_value(write(STDERR_FILENO, "FAIL\n", 5));
+ signal(sig, SIG_DFL);
+ raise(sig);
+}
+
+/* We're not using the testutils.c main() wrapper because
+ * we don't want 'shunloadtest' itself to link against
+ * libvirt.so. We need to test dlopen()'ing of libvirt.so
+ */
+int main(int argc ATTRIBUTE_UNUSED, char **argv)
+{
+ void (*startup)(void);
+ pthread_t t;
+ void *lib;
+ char *theprogname;
+
+ theprogname = argv[0];
+ if (STRPREFIX(theprogname, "./"))
+ theprogname += 2;
+
+ fprintf(stderr, "TEST: %s\n", theprogname);
+ fprintf(stderr, " .%*s 1 ", 39, "");
+ signal(SIGSEGV, sigHandler);
+
+ if (!(lib = dlopen("./.libs/libshunload.so", RTLD_NOW))) {
+ fprintf(stderr, "Cannot load ./.libs/libshunload.so %s\n", dlerror());
+ return 1;
+ }
+ if (!(startup = dlsym(lib, "shunloadStart"))) {
+ fprintf(stderr, "Cannot find shunloadStart %s\n", dlerror());
+ return 1;
+ }
+
+ /*
+ * Create a thread which is going to initialize libvirt
+ * and raise an error
+ */
+ pthread_create(&t, NULL, threadMain, startup);
+
+ /* Wait for the thread to start and call libvirt */
+ pthread_mutex_lock(&lock);
+ while (!running) {
+ pthread_cond_wait(&cond, &lock);
+ }
+
+ /* Close the shared library (and thus make libvirt.so
+ * non-resident */
+ dlclose(lib);
+
+ /* Tell the thread to quit */
+ quit = true;
+ pthread_cond_signal(&cond);
+ pthread_mutex_unlock(&lock);
+
+ pthread_join(t, NULL);
+
+ /* If we got to hear the thread succesfully exited without
+ * causing a SEGV !
+ */
+
+ fprintf(stderr, "OK\n");
+
+ return 0;
+}
+
+#else
+
+int main(void)
+{
+ return EXIT_AM_SKIP;
+}
+
+#endif
--
1.7.6
13 years, 2 months
[libvirt] [PATCH] qemu: avoid dereferencing a NULL pointer
by ajia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
* src/qemu/qemu_migration.c: avoid dereferencing a pointer that might be
null "vmdef" when calling virDomainSaveConfig.
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
src/qemu/qemu_migration.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index d9f8d93..69ced88 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2510,7 +2510,8 @@ qemuMigrationFinish(struct qemud_driver *driver,
if (vm->persistent)
newVM = 0;
vm->persistent = 1;
- vmdef = virDomainObjGetPersistentDef(driver->caps, vm);
+ if (!(vmdef = virDomainObjGetPersistentDef(driver->caps, vm)))
+ goto endjob;
if (virDomainSaveConfig(driver->configDir, vmdef) < 0) {
/* Hmpf. Migration was successful, but making it persistent
* was not. If we report successful, then when this domain
--
1.7.1
13 years, 2 months
[libvirt] [PATCH 0/5] Improve Ceph Qemu+RBD support
by Sage Weil
The current support for qemu and Ceph RBD (rados block device) has two
main deficiencies: authentication doesn't work, and it relies on
environment variables (which don't work with latest upstream).
This patch set addresses both those problems, while trying to integrate as
cleanly as possible with the rest of libvirt.
The first few patches make some changes to libvirt itself: adding a CEPH
secret type (for Ceph/RBD authentication), adding authentication fields
to the XML schema, passing the virConnectPtr into the
Domain{Attach,Detach} methods (needed to access secrets while building
the qemu command), a helper that will escape arbitrary characters, and
finally a patch that replaces the current RBD qemu code.
Comments on this approach?
Thanks!
sage
Sage Weil (5):
secret: add Ceph secret type
storage: add authId, authDomain to virDomainDiskDef
qemu: pass virConnectPtr into Domain{Attach,Detach}*
buf: implement generic virBufferEscape
qemu/rbd: improve rbd device specification
include/libvirt/libvirt.h.in | 3 +
src/conf/domain_conf.c | 43 +++-
src/conf/domain_conf.h | 2 +
src/conf/secret_conf.c | 45 ++++-
src/conf/secret_conf.h | 1 +
src/libvirt_private.syms | 1 +
src/qemu/qemu_command.c | 273 +++++++++++---------
src/qemu/qemu_command.h | 3 +-
src/qemu/qemu_driver.c | 17 +-
src/qemu/qemu_hotplug.c | 15 +-
src/qemu/qemu_hotplug.h | 9 +-
src/secret/secret_driver.c | 8 +
src/util/buf.c | 33 ++-
src/util/buf.h | 1 +
.../qemuxml2argv-disk-drive-network-rbd.args | 6 +-
.../qemuxml2argv-disk-drive-network-rbd.xml | 1 +
16 files changed, 305 insertions(+), 156 deletions(-)
--
1.7.4.1
13 years, 2 months
[libvirt] [PATCH] qemu: Introduce shutdown reason for paused state
by Jiri Denemark
Qemu sends STOP event as part of the shutdown process. Detect such STOP
event and consider shutdown to be reason of emitting such event. That's
the best we can do until qemu provides us the reason directly in STOP
event. This allows us to report shutdown reason for paused state so that
apps can detect domains that failed to finish the shutdown process
(e.g., because qemu is buggy and doesn't exit on SIGTERM or it is
blocked in flushing disk buffers).
---
include/libvirt/libvirt.h.in | 1 +
src/conf/domain_conf.c | 5 +++--
src/libvirt_private.syms | 12 ++++++++++++
src/qemu/qemu_process.c | 14 +++++++++++---
tools/virsh.c | 2 ++
5 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index ea7b3fc..39155a6 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -124,6 +124,7 @@ typedef enum {
VIR_DOMAIN_PAUSED_IOERROR = 5, /* paused due to a disk I/O error */
VIR_DOMAIN_PAUSED_WATCHDOG = 6, /* paused due to a watchdog event */
VIR_DOMAIN_PAUSED_FROM_SNAPSHOT = 7, /* paused after restoring from snapshot */
+ VIR_DOMAIN_PAUSED_SHUTTING_DOWN = 8, /* paused during shutdown process */
} virDomainPausedReason;
typedef enum {
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ea6b581..ad2a730 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -487,7 +487,7 @@ VIR_ENUM_IMPL(virDomainRunningReason, VIR_DOMAIN_RUNNING_LAST,
VIR_ENUM_IMPL(virDomainBlockedReason, VIR_DOMAIN_BLOCKED_LAST,
"unknown")
-#define VIR_DOMAIN_PAUSED_LAST (VIR_DOMAIN_PAUSED_FROM_SNAPSHOT + 1)
+#define VIR_DOMAIN_PAUSED_LAST (VIR_DOMAIN_PAUSED_SHUTTING_DOWN + 1)
VIR_ENUM_IMPL(virDomainPausedReason, VIR_DOMAIN_PAUSED_LAST,
"unknown",
"user",
@@ -496,7 +496,8 @@ VIR_ENUM_IMPL(virDomainPausedReason, VIR_DOMAIN_PAUSED_LAST,
"dump",
"ioerror",
"watchdog",
- "from snapshot")
+ "from snapshot",
+ "shutdown")
#define VIR_DOMAIN_SHUTDOWN_LAST (VIR_DOMAIN_SHUTDOWN_USER + 1)
VIR_ENUM_IMPL(virDomainShutdownReason, VIR_DOMAIN_SHUTDOWN_LAST,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e45965e..8235ea1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -231,6 +231,8 @@ virDiskNameToBusDeviceIndex;
virDiskNameToIndex;
virDomainActualNetDefFree;
virDomainAssignDef;
+virDomainBlockedReasonTypeFromString;
+virDomainBlockedReasonTypeToString;
virDomainChrConsoleTargetTypeFromString;
virDomainChrConsoleTargetTypeToString;
virDomainChrDefForeach;
@@ -360,6 +362,8 @@ virDomainNetIndexByMac;
virDomainNetInsert;
virDomainNetRemoveByMac;
virDomainNetTypeToString;
+virDomainNostateReasonTypeFromString;
+virDomainNostateReasonTypeToString;
virDomainNumatuneMemModeTypeFromString;
virDomainNumatuneMemModeTypeToString;
virDomainObjAssignDef;
@@ -379,12 +383,20 @@ virDomainObjSetState;
virDomainObjTaint;
virDomainObjUnlock;
virDomainObjUnref;
+virDomainPausedReasonTypeFromString;
+virDomainPausedReasonTypeToString;
virDomainRedirdevBusTypeFromString;
virDomainRedirdevBusTypeToString;
virDomainRemoveInactive;
+virDomainRunningReasonTypeFromString;
+virDomainRunningReasonTypeToString;
virDomainSaveConfig;
virDomainSaveStatus;
virDomainSaveXML;
+virDomainShutdownReasonTypeFromString;
+virDomainShutdownReasonTypeToString;
+virDomainShutoffReasonTypeFromString;
+virDomainShutoffReasonTypeToString;
virDomainSmartcardDefForeach;
virDomainSmartcardDefFree;
virDomainSmartcardTypeFromString;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index dbd697d..4de7ab5 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -473,14 +473,22 @@ qemuProcessHandleStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
{
struct qemud_driver *driver = qemu_driver;
virDomainEventPtr event = NULL;
+ virDomainPausedReason reason = VIR_DOMAIN_PAUSED_UNKNOWN;
virDomainObjLock(vm);
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
qemuDomainObjPrivatePtr priv = vm->privateData;
- VIR_DEBUG("Transitioned guest %s to paused state due to unknown event",
- vm->def->name);
- virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_UNKNOWN);
+ if (priv->gotShutdown) {
+ VIR_DEBUG("Got STOP event after SHUTDOWN, assuming we are stopping"
+ " for shutdown");
+ reason = VIR_DOMAIN_PAUSED_SHUTTING_DOWN;
+ }
+
+ VIR_DEBUG("Transitioned guest %s to paused state, reason=%s",
+ vm->def->name, virDomainPausedReasonTypeToString(reason));
+
+ virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, reason);
event = virDomainEventNewFromObj(vm,
VIR_DOMAIN_EVENT_SUSPENDED,
VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
diff --git a/tools/virsh.c b/tools/virsh.c
index 3c6e65a..8d257bc 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -15137,6 +15137,8 @@ vshDomainStateReasonToString(int state, int reason)
return N_("watchdog");
case VIR_DOMAIN_PAUSED_FROM_SNAPSHOT:
return N_("from snapshot");
+ case VIR_DOMAIN_PAUSED_SHUTTING_DOWN:
+ return N_("shutting down");
case VIR_DOMAIN_PAUSED_UNKNOWN:
;
}
--
1.7.6.1
13 years, 2 months
[libvirt] [PATCH] qemu: Properly detect crash of a rebooted domain
by Jiri Denemark
When a domain is rebooted using libvirt API, we use fake reboot
consisting of shutting down and resetting the domain. Thus we see a
SHUTDOWN event and set gotShutdown flag. But we never reset it back and
if the domain crashes after it was rebooted this way, we consider it was
a normal shutdown and not a crash.
---
src/qemu/qemu_process.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ca4f21f..1332e04 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -405,6 +405,7 @@ qemuProcessFakeReboot(void *opaque)
"%s", _("resume operation failed"));
goto endjob;
}
+ priv->gotShutdown = false;
event = virDomainEventNewFromObj(vm,
VIR_DOMAIN_EVENT_RESUMED,
VIR_DOMAIN_EVENT_RESUMED_UNPAUSED);
--
1.7.6.1
13 years, 2 months