[libvirt] [PATCH] locking: remove redundant codes
by ajia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
* src/locking/lock_driver_sanlock.c: remove redundant codes in error_unlink
label from virLockManagerSanlockSetupLockspace, in fact, the codes make
sure 'path' is non-null before getting to error_unlink label, so 'if (path)'
is redundant, removing it in here and will also silence coverity.
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
src/locking/lock_driver_sanlock.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index 2d72510..c4dce4f 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -250,8 +250,7 @@ static int virLockManagerSanlockSetupLockspace(void)
return 0;
error_unlink:
- if (path)
- unlink(path);
+ unlink(path);
error:
VIR_FORCE_CLOSE(fd);
VIR_FREE(path);
--
1.7.1
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_process.c: Taking if (qemuDomainObjEndJob(driver, obj) == 0)
true branch then 'obj' is NULL, virDomainObjIsActive(obj) and
virDomainObjUnref(obj) will dereference NULL pointer.
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
src/qemu/qemu_process.c | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index bd49b21..9fdf846 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2661,22 +2661,24 @@ error:
if (qemuDomainObjEndJob(driver, obj) == 0)
obj = NULL;
- if (!virDomainObjIsActive(obj)) {
- if (virDomainObjUnref(obj) > 0)
- virDomainObjUnlock(obj);
- qemuDriverUnlock(driver);
- return;
- }
+ if (obj) {
+ if (!virDomainObjIsActive(obj)) {
+ if (virDomainObjUnref(obj) > 0)
+ virDomainObjUnlock(obj);
+ qemuDriverUnlock(driver);
+ return;
+ }
- if (virDomainObjUnref(obj) > 0) {
- /* We can't get the monitor back, so must kill the VM
- * to remove danger of it ending up running twice if
- * user tries to start it again later */
- qemuProcessStop(driver, obj, 0, VIR_DOMAIN_SHUTOFF_FAILED);
- if (!obj->persistent)
- virDomainRemoveInactive(&driver->domains, obj);
- else
- virDomainObjUnlock(obj);
+ if (virDomainObjUnref(obj) > 0) {
+ /* We can't get the monitor back, so must kill the VM
+ * to remove danger of it ending up running twice if
+ * user tries to start it again later */
+ qemuProcessStop(driver, obj, 0, VIR_DOMAIN_SHUTOFF_FAILED);
+ if (!obj->persistent)
+ virDomainRemoveInactive(&driver->domains, obj);
+ else
+ virDomainObjUnlock(obj);
+ }
}
qemuDriverUnlock(driver);
--
1.7.1
13 years, 2 months
[libvirt] [PATCH] virsh: More friendly err if no pool is specified for looking up a vol
by Osier Yang
There are 3 ways to lookup a volume, only virStorageVolLookupByName
needs pool object. So if no --pool is specified, it will tries to
get the volume via virStorageVolLookupByPath/virStorageVolLookupByKey.
But if all 3 ways fails, and no --pool is specified, a friendly
error might help the user get right way quickly.
---
tools/virsh.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 371346a..4b9e662 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -14714,8 +14714,13 @@ vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
vol = virStorageVolLookupByPath(ctl->conn, n);
}
- if (!vol)
- vshError(ctl, _("failed to get vol '%s'"), n);
+ if (!vol) {
+ if (pool)
+ vshError(ctl, _("failed to get vol '%s'"), n);
+ else
+ vshError(ctl, _("failed to get vol '%s', specifying --pool "
+ "might help"), n);
+ }
if (pool)
virStoragePoolFree(pool);
--
1.7.6
13 years, 2 months
[libvirt] [PATCH] storage: Wait udev events are handled before removing lvm vol
by Osier Yang
Related #BZ: https://bugzilla.redhat.com/show_bug.cgi?id=702260.
There are two problems described in the BZ:
1) "Can't remove open logical volume".
2) "Unable to deactivate logical volume "foo""
This patch just intends to fix 2), as 1) is expected if the vol
is still used by something, and you never known if "lvchange -an"
will fail or not either (sometime, it will succeed, sometimes not).
We'd better not look for trouble, :-)
For 2), that's caused by race between lvremove and udev event handling,
the only workable way now is to wait the events handling are finished,
though it might introduce latencies, as "udevadmin settle" exits
after *all* events are handled, it's the only way we can fix
the racing in libvirt layer.
See https://bugzilla.redhat.com/show_bug.cgi?id=570359 for more
details.
---
src/storage/storage_backend_logical.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 4f42047..23d80cb 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -686,6 +686,8 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virCheckFlags(0, -1);
+ virFileWaitForDevices();
+
if (virRun(cmdargv, NULL) < 0)
return -1;
--
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_process.c: Taking if (qemuDomainObjEndJob(driver, obj) == 0)
true branch then 'obj' is NULL, virDomainObjIsActive(obj) and
virDomainObjUnref(obj) will dereference NULL pointer.
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
src/qemu/qemu_process.c | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index bd49b21..9fdf846 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2661,22 +2661,24 @@ error:
if (qemuDomainObjEndJob(driver, obj) == 0)
obj = NULL;
- if (!virDomainObjIsActive(obj)) {
- if (virDomainObjUnref(obj) > 0)
- virDomainObjUnlock(obj);
- qemuDriverUnlock(driver);
- return;
- }
+ if (obj) {
+ if (!virDomainObjIsActive(obj)) {
+ if (virDomainObjUnref(obj) > 0)
+ virDomainObjUnlock(obj);
+ qemuDriverUnlock(driver);
+ return;
+ }
- if (virDomainObjUnref(obj) > 0) {
- /* We can't get the monitor back, so must kill the VM
- * to remove danger of it ending up running twice if
- * user tries to start it again later */
- qemuProcessStop(driver, obj, 0, VIR_DOMAIN_SHUTOFF_FAILED);
- if (!obj->persistent)
- virDomainRemoveInactive(&driver->domains, obj);
- else
- virDomainObjUnlock(obj);
+ if (virDomainObjUnref(obj) > 0) {
+ /* We can't get the monitor back, so must kill the VM
+ * to remove danger of it ending up running twice if
+ * user tries to start it again later */
+ qemuProcessStop(driver, obj, 0, VIR_DOMAIN_SHUTOFF_FAILED);
+ if (!obj->persistent)
+ virDomainRemoveInactive(&driver->domains, obj);
+ else
+ virDomainObjUnlock(obj);
+ }
}
qemuDriverUnlock(driver);
--
1.7.1
13 years, 2 months
[libvirt] virsh qemu-monitor-command broken with 0.9.5
by Jason Krieg
Hi,
the virsh qemu-monitor-command is not working with libvirt 0.9.5
with git commit 85d2810823a31634b12145d6c196930b40425370
*opts_seen moved into the != VSH_OT_ARGV if statement
so now opts_seen is only set if not VSH_OT_ARGV
see attached fix
Regards Jason
13 years, 2 months
[libvirt] [PATCH] qemu: Avoid loop of fake reboots
by Jiri Denemark
Once virDomainReboot is called for a domain, guest OS initiated shutdown
would always result in reboot instead of shutdown. Only
virDomainShutdown would actually shutd such domain down. That's because
we forgot to reset fakeReboot flag once we asked the domain to reboot.
---
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 3baaa19..bd49b21 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -445,6 +445,7 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
priv->gotShutdown = true;
if (priv->fakeReboot) {
+ priv->fakeReboot = false;
virDomainObjRef(vm);
virThread th;
if (virThreadCreate(&th,
--
1.7.6.1
13 years, 2 months
[libvirt] [PATCH v2] qemu: Fix shutdown regression with buggy qemu
by Jiri Denemark
The commit that prevents disk corruption on domain shutdown
(96fc4784177ecb70357518fa863442455e45ad0e) causes regression with QEMU
0.14.* and 0.15.* because of a regression bug in QEMU that was fixed
only recently in QEMU git. The affected versions of QEMU do not quit on
SIGTERM if started with -no-shutdown, which we use to implement fake
reboot. Since -no-shutdown tells QEMU not to quit automatically on guest
shutdown, domains started using the affected QEMU cannot be shutdown
properly and stay in a paused state.
This patch disables fake reboot feature on such QEMU by not using
-no-shutdown, which makes shutdown work as expected. However,
virDomainReboot will not work in this case and it will report "Requested
operation is not valid: Reboot is not supported with this QEMU binary".
---
src/qemu/qemu_capabilities.c | 8 ++++++++
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 2 +-
src/qemu/qemu_driver.c | 6 ++++++
4 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 36f47a9..850d46e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -136,6 +136,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST,
"pci-ohci",
"usb-redir",
"usb-hub",
+ "no-shutdown",
);
struct qemu_feature_flags {
@@ -1008,6 +1009,13 @@ qemuCapsComputeCmdFlags(const char *help,
qemuCapsSet(flags, QEMU_CAPS_VHOST_NET);
}
+ /* Do not use -no-shutdown if qemu doesn't support it or SIGTERM handling
+ * is most likely buggy when used with -no-shutdown (which applies for qemu
+ * 0.14.* and 0.15.*)
+ */
+ if (strstr(help, "-no-shutdown") && (version < 14000 || version > 15999))
+ qemuCapsSet(flags, QEMU_CAPS_NO_SHUTDOWN);
+
/*
* Handling of -incoming arg with varying features
* -incoming tcp (kvm >= 79, qemu >= 0.10.0)
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 96b7a3b..74d3ab2 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -110,6 +110,7 @@ enum qemuCapsFlags {
QEMU_CAPS_PCI_OHCI = 71, /* -device pci-ohci */
QEMU_CAPS_USB_REDIR = 72, /* -device usb-redir */
QEMU_CAPS_USB_HUB = 73, /* -device usb-hub */
+ QEMU_CAPS_NO_SHUTDOWN = 74, /* usable -no-shutdown */
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 ee4b52b..0adc56a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3574,7 +3574,7 @@ qemuBuildCommandLine(virConnectPtr conn,
* when QEMU stops. If we use no-shutdown, then we can
* watch for this event and do a soft/warm reboot.
*/
- if (monitor_json)
+ if (monitor_json && qemuCapsGet(qemuCaps, QEMU_CAPS_NO_SHUTDOWN))
virCommandAddArg(cmd, "-no-shutdown");
if (!(def->features & (1 << VIR_DOMAIN_FEATURE_ACPI)))
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f4ee4c3..67c43ab 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1557,6 +1557,12 @@ static int qemuDomainReboot(virDomainPtr dom, unsigned int flags) {
priv = vm->privateData;
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_MONITOR_JSON)) {
+ if (!qemuCapsGet(priv->qemuCaps, QEMU_CAPS_NO_SHUTDOWN)) {
+ qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("Reboot is not supported with this QEMU binary"));
+ goto cleanup;
+ }
+
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup;
--
1.7.6.1
13 years, 2 months
[libvirt] [PATCH] Fix synchronous reading of stream data
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
commit 984840a2c292402926ad100aeea33f8859ff31a9 removed the
notification of waiting calls when VIR_NET_CONTINUE messages
arrive. This was to fix the case of a virStreamAbort() call
being prematurely notified of completion.
The problem is that sometimes there are dummy calls from a
virStreamRecv() call waiting that *do* need to be notified.
These dummy calls should have a status VIR_NET_CONTINUE. So
re-add the notification upon VIR_NET_CONTINUE, but only if
the waiter also has a status of VIR_NET_CONTINUE.
* src/rpc/virnetclient.c: Notify waiting call if stream data
arrives
* src/rpc/virnetclientstream.c: Mark dummy stream read packet
with status VIR_NET_CONTINUE
---
src/rpc/virnetclient.c | 10 ++++++++++
src/rpc/virnetclientstream.c | 1 +
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 055361d..b2c528a 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -627,6 +627,15 @@ static int virNetClientCallDispatchStream(virNetClientPtr client)
case VIR_NET_CONTINUE: {
if (virNetClientStreamQueuePacket(st, &client->msg) < 0)
return -1;
+
+ if (thecall && thecall->expectReply) {
+ if (thecall->msg->header.status == VIR_NET_CONTINUE) {
+ VIR_DEBUG("Got a synchronous confirm");
+ thecall->mode = VIR_NET_CLIENT_MODE_COMPLETE;
+ } else {
+ VIR_DEBUG("Not completing call with status %d", thecall->msg->header.status);
+ }
+ }
return 0;
}
@@ -1189,6 +1198,7 @@ int virNetClientSend(virNetClientPtr client,
int ret = -1;
if (expectReply &&
+ (msg->bufferLength != 0) &&
(msg->header.status == VIR_NET_CONTINUE)) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Attempt to send an asynchronous message with a synchronous reply"));
diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c
index 2cc84d4..4cd0295 100644
--- a/src/rpc/virnetclientstream.c
+++ b/src/rpc/virnetclientstream.c
@@ -400,6 +400,7 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
msg->header.type = VIR_NET_STREAM;
msg->header.serial = st->serial;
msg->header.proc = st->proc;
+ msg->header.status = VIR_NET_CONTINUE;
VIR_DEBUG("Dummy packet to wait for stream data");
virMutexUnlock(&st->lock);
--
1.7.6.2
13 years, 2 months
[libvirt] [test-API][PATCH v2] Add test case update_devflag.py for update device flag
by Nan Zhang
---
repos/domain/update_devflag.py | 163 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 163 insertions(+), 0 deletions(-)
create mode 100644 repos/domain/update_devflag.py
diff --git a/repos/domain/update_devflag.py b/repos/domain/update_devflag.py
new file mode 100644
index 0000000..287f2a5
--- /dev/null
+++ b/repos/domain/update_devflag.py
@@ -0,0 +1,163 @@
+#!/usr/bin/evn python
+"""Update virtual device to guest from an XML file
+"""
+
+__author__ = 'Nan Zhang: nzhang(a)redhat.com'
+__date__ = 'Fri Sep 2, 2011'
+__version__ = '0.1.0'
+__credits__ = 'Copyright (C) 2011 Red Hat, Inc.'
+__all__ = ['usage', 'update_devflag']
+
+import os
+import re
+import sys
+import commands
+from xml.dom import minidom
+
+def append_path(path):
+ """Append root path of package"""
+ if path in sys.path:
+ pass
+ else:
+ sys.path.append(path)
+
+pwd = os.getcwd()
+result = re.search('(.*)libvirt-test-API', pwd)
+append_path(result.group(0))
+
+from lib import connectAPI
+from lib import domainAPI
+from utils.Python import utils
+from utils.Python import xmlbuilder
+from exception import LibvirtAPI
+
+def usage():
+ print '''usage: mandatory arguments:
+ guestname
+ devtype
+ '''
+
+def check_params(params):
+ """Verify inputing parameter dictionary"""
+ logger = params['logger']
+ keys = ['guestname', 'devtype']
+ for key in keys:
+ if key not in params:
+ logger.error("%s is required" %key)
+ usage()
+ return 1
+ return 0
+
+def create_image(params, img_name, img_size):
+ """Create an image file"""
+ logger = params['logger']
+ stat, ret = commands.getstatusoutput("dd if=/dev/zero of=%s bs=1 \
+ count=1 seek=%s" % (img_name, img_size))
+ if stat == 0:
+ logger.debug("create image result:\n%s" % ret)
+ return True
+ else:
+ return False
+
+def check_updated_device(params, guestname, domobj, srcfile):
+ """Check if the device is updated"""
+ logger = params['logger']
+ xmlobj = domobj.get_xml_desc(guestname)
+ domxml = minidom.parseString(xmlobj)
+
+ for diskTag in domxml.getElementsByTagName("source"):
+ if diskTag.parentNode.getAttribute("device") == 'cdrom':
+ upfile = diskTag.getAttribute("file")
+ elif diskTag.parentNode.getAttribute('device') == 'floppy':
+ upfile = diskTag.getAttribute("file")
+
+ if upfile == srcfile:
+ return False, upfile
+ else:
+ return True, upfile
+
+def update_devflag(params):
+ """Update virtual device to a domain from xml"""
+
+ # Initiate and check parameters
+ params_check_result = check_params(params)
+ if params_check_result:
+ return 1
+ logger = params['logger']
+ guestname = params['guestname']
+ devtype = params['devtype']
+ if devtype == 'cdrom':
+ xmlargs = {}
+ xmlargs['guestname'] = guestname
+ xmlargs['guesttype'] = 'kvm'
+ xmlargs['hdmodel'] = 'ide'
+ xmlargs['bootcd'] = '/var/lib/libvirt/boot/cdrom.img'
+ srcfile = xmlargs['bootcd']
+ create_image(params, srcfile, '100M')
+ elif devtype == 'floppy':
+ xmlargs = {}
+ xmlargs['guestname'] = guestname
+ xmlargs['floppysource'] = '/var/lib/libvirt/boot/floppy.img'
+ srcfile = xmlargs['floppysource']
+ create_image(params, srcfile, '2M')
+ else:
+ srcfile = None
+ logger.error("Wrong device type was specified.")
+ return 1
+
+ if not params.has_key('flag'):
+ flag = domainAPI.VIR_DOMAIN_AFFECT_CONFIG
+
+ # Connect to local hypervisor connection URI
+ util = utils.Utils()
+ uri = util.get_uri('127.0.0.1')
+ conn = connectAPI.ConnectAPI()
+ virconn = conn.open(uri)
+
+ caps = conn.get_caps()
+ logger.debug(caps)
+
+ # Generate device XML for updating
+ domobj = domainAPI.DomainAPI(virconn)
+ newxmlobj = xmlbuilder.XmlBuilder()
+
+ if devtype == 'cdrom':
+ newdevxml = newxmlobj.build_cdrom(xmlargs)
+ elif devtype == 'floppy':
+ newdevxml = newxmlobj.build_floppy(xmlargs)
+
+ logger.debug("block device xml desc:\n%s" %newdevxml)
+
+ try:
+ try:
+ domobj.update_device_flag(guestname, newdevxml, flag)
+ res, upfile = check_updated_device(params, guestname, \
+ domobj, srcfile)
+ if res:
+ logger.info("success to update '%s' device: %s\n" % \
+ (devtype, upfile))
+ else:
+ logger.error("fail to update '%s' device: %s\n" % \
+ (devtype, upfile))
+ except LibvirtAPI, e:
+ logger.error("API error message: %s, error code is %s" %
+ (e.response()['message'], e.response()['code']))
+ conn.close()
+ logger.info("closed hypervisor connection")
+ return 1
+ finally:
+ conn.close()
+ logger.info("closed hypervisor connection")
+
+ return 0
+
+def update_devflag_clean(params):
+ """Clean testing environment"""
+ logger = params['logger']
+
+ if params['devtype'] == 'cdrom':
+ os.unlink('/var/lib/libvirt/boot/cdrom.img')
+ elif params['devtype'] == 'floppy':
+ os.unlink('/var/lib/libvirt/boot/floppy.img')
+ else:
+ logger.debug("image file was not found.")
--
1.7.4.4
13 years, 2 months