On Tue, Feb 19, 2013 at 08:27:44PM +0800, Osier Yang wrote: > The disk def could be free'ed by qemuDomainChangeEjectableMedia, > which can thus cause crash if we reference the disk pointer. On > the other hand, we have to remove the added shared disk entry from > the table on error codepath. > --- > src/qemu/qemu_driver.c | 25 +++++++++++-------------- > 1 files changed, 11 insertions(+), 14 deletions(-) > > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c > index 27d3daf..5a3550d 100644 > --- a/src/qemu/qemu_driver.c > +++ b/src/qemu/qemu_driver.c > @@ -5710,6 +5710,12 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, > goto end; > } > > + if (qemuAddSharedDisk(driver, disk, vm->def->name) < 0) > + goto end; > + > + if (qemuSetUnprivSGIO(disk) < 0) > + goto end; > + > if (qemuDomainDetermineDiskChain(driver, disk, false) < 0) > goto end; > > @@ -5723,6 +5729,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, > if (qemuSetupDiskCgroup(vm, cgroup, disk) < 0) > goto end; > } > + > switch (disk->device) { > case VIR_DOMAIN_DISK_DEVICE_CDROM: > case VIR_DOMAIN_DISK_DEVICE_FLOPPY: > @@ -5761,16 +5768,9 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, > NULLSTR(disk->src)); > } > > - if (ret == 0) { > - if (qemuAddSharedDisk(driver, disk, vm->def->name) < 0) > - VIR_WARN("Failed to add disk '%s' to shared disk table", > - disk->src); > - > - if (qemuSetUnprivSGIO(disk) < 0) > - VIR_WARN("Failed to set unpriv_sgio of disk '%s'", disk->src); > - } > - > end: > + if (ret != 0) > + ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)); > if (cgroup) > virCgroupFree(&cgroup); > return ret; > @@ -5885,11 +5885,8 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, > break; > } > > - if (ret == 0) { > - if (qemuRemoveSharedDisk(driver, disk, vm->def->name) < 0) > - VIR_WARN("Failed to remove disk '%s' from shared disk table", > - disk->src); > - } > + if (ret == 0) > + ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)) ACK 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 :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list