On Fri, Feb 08, 2013 at 09:08:02PM +0800, Osier Yang wrote:
The disk def could be free'ed by qemuDomainChangeEjectableMedia
for cdrom or floppy disk. This moves the adding and setting before
the attaching takes place. And for cdrom floppy disk, if the
change is ejecting, removing the existed hash entry for it.
---
src/qemu/qemu_driver.c | 23 +++++++++++++----------
src/qemu/qemu_hotplug.c | 6 +++++-
src/qemu/qemu_hotplug.h | 3 ++-
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 03fe526..4aad42f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5789,6 +5789,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
{
virDomainDiskDefPtr disk = dev->data.disk;
virCgroupPtr cgroup = NULL;
+ int eject, added;
int ret = -1;
if (disk->driverName != NULL && !STREQ(disk->driverName,
"qemu")) {
@@ -5798,6 +5799,12 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
goto end;
}
+ if (qemuAddSharedDisk(driver->sharedDisks, disk, &added) < 0)
+ goto end;
+
+ if (qemuSetUnprivSGIO(disk) < 0)
+ goto end;
+
if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
goto end;
@@ -5814,7 +5821,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
switch (disk->device) {
case VIR_DOMAIN_DISK_DEVICE_CDROM:
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
- ret = qemuDomainChangeEjectableMedia(driver, vm, disk, false);
+ ret = qemuDomainChangeEjectableMedia(driver, vm, disk, false, &eject);
break;
case VIR_DOMAIN_DISK_DEVICE_DISK:
case VIR_DOMAIN_DISK_DEVICE_LUN:
@@ -5843,22 +5850,18 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
break;
}
+ if (ret == 0 && eject)
+ ignore_value(qemuRemoveSharedDisk(driver->sharedDisks, disk));
This doesn't make sense - you're removing the disk we just added.
You need to remove the *old* disk->src surely ? In addition it is
*not* valid to reference 'disk' at all at this point, since the
functions we just called may have free'd it.
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|