qemu-e2k/stubs
Markus Armbruster 3ae59580a0 block: Keep DriveInfo alive until BlockDriverState dies
If the BDS's refcnt > 0, drive_del() destroys the DriveInfo, but not
the BDS.  This can happen in three places:

* Device model destruction during unplug: blockdev_auto_del()

* Xen IDE unplug: pci_piix3_xen_ide_unplug()

* drive_del command when no device model is attached: do_drive_del()

The other callers of drive_del are on error paths where refcnt == 1.

If the user somehow manages to plug in a device model using a BDS that
has gone through drive_del(), the legacy configuration passed in
DriveInfo doesn't reach the device model, and automatic deletion on
unplug doesn't work.  Worse, some device models such as scsi-disk
crash when DriveInfo doesn't exist.

This is theoretical; I didn't research an actual reproducer. The problem
was introduced when we replaced DriveInfo reference counting by BDS
reference counting in commit a94a3fa..fa510eb.

Fix by keeping DriveInfo alive until its BDS dies.

This affects qemu_drive_opts: now you can't reuse the same ID for new
drive options until the BDS dies.  Before, you could, but since the
code always attempts to create a BDS with the same ID next, the
enclosing operation "create a new drive" failed anyway.  Different
error path, same result.

Unfortunately, the fix involves use of blockdev.c stuff from block.c,
which is a layering violation.  Fortunately, my forthcoming
BlockBackend work will get rid of it again.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Benoît Canet <benoit.canet@nodalink.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2014-09-25 15:24:14 +02:00
..
arch-query-cpu-def.c qerror.h: Replace QERR_NOT_SUPPORTED with QERR_UNSUPPORTED 2014-04-25 09:19:59 -04:00
bdrv-commit-all.c libqemustub: add stubs to be able to use qemu-char.c 2014-06-19 18:44:18 +03:00
blockdev.c block: Keep DriveInfo alive until BlockDriverState dies 2014-09-25 15:24:14 +02:00
chr-baum-init.c libqemustub: add more stubs for qemu-char 2014-06-23 17:37:59 +03:00
chr-msmouse.c libqemustub: add stubs to be able to use qemu-char.c 2014-06-19 18:44:18 +03:00
chr-testdev.c backends: Introduce chr-testdev 2014-08-06 17:53:05 +02:00
clock-warp.c
cpu-get-clock.c
cpu-get-icount.c
cpus.c
dump.c dump: Make DumpState and endian conversion routines available for arch-specific dump code 2014-06-16 13:24:36 +02:00
fd-register.c
fdset-add-fd.c
fdset-find-fd.c
fdset-get-fd.c
fdset-remove-fd.c monitor: fix use after free 2014-08-18 14:39:10 -04:00
gdbstub.c stubs: Optimize dependencies for gdbstub.c 2014-03-02 17:13:31 +04:00
get-fd.c
get-next-serial.c libqemustub: add stubs to be able to use qemu-char.c 2014-06-19 18:44:18 +03:00
get-vm-name.c
iothread-lock.c
is-daemonized.c Add qtest for vhost-user 2014-06-19 18:44:18 +03:00
kvm.c
machine-init-done.c libqemustub: add stubs to be able to use qemu-char.c 2014-06-19 18:44:18 +03:00
Makefile.objs block: Keep DriveInfo alive until BlockDriverState dies 2014-09-25 15:24:14 +02:00
migr-blocker.c
mon-is-qmp.c
mon-printf.c
mon-set-error.c
monitor-init.c libqemustub: add stubs to be able to use qemu-char.c 2014-06-19 18:44:18 +03:00
notify-event.c libqemustub: add stubs to be able to use qemu-char.c 2014-06-19 18:44:18 +03:00
pci-drive-hot-add.c
qemu-chr-open-spice.c libqemustub: add more stubs for qemu-char 2014-06-23 17:37:59 +03:00
qmp_pc_dimm_device_list.c qmp: add query-memory-devices command 2014-06-19 18:44:22 +03:00
qtest.c main-loop: Suppress "I/O thread spun" warnings for qtest 2014-03-13 21:36:50 +01:00
reset.c
runstate-check.c blockdev: Refuse to open encrypted image unless paused 2014-03-14 16:24:42 +01:00
set-fd-handler.c
slirp.c
sysbus.c
uuid.c
vc-init.c console: move chardev declarations to sysemu/char.h 2014-06-23 10:56:20 +01:00
vm-stop.c block: asynchronously stop the VM on I/O errors 2014-06-23 16:36:13 +08:00
vmstate.c