diff options
author | Markus Armbruster <armbru@redhat.com> | 2010-06-25 08:09:10 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2010-07-02 13:18:01 +0200 |
commit | 14bafc540774baf316e9ce2474e97d5df6cb8e6c (patch) | |
tree | ceb120945adedcbcdaf0bd18bb5558289fe92be6 /blockdev.c | |
parent | e4700e595ea0b24d5291dbd68deba26d7a955703 (diff) |
blockdev: Clean up automatic drive deletion
We automatically delete blockdev host parts on unplug of the guest
device. Too much magic, but we can't change that now.
The delete happens early in the guest device teardown, before the
connection to the host part is severed. Thus, the guest part's
pointer to the host part dangles for a brief time. No actual harm
comes from this, but we'll catch such dangling pointers a few commits
down the road. Clean up the dangling pointers by delaying the
automatic deletion until the guest part's pointer is gone.
Device usb-storage deliberately makes two qdev properties refer to the
same drive, because it automatically creates a second device. Again,
too much magic we can't change now. Multiple references worked okay
before, but now free_drive() dies for the second one. Zap the extra
reference.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r-- | blockdev.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/blockdev.c b/blockdev.c index ba4f66f976..48481120c2 100644 --- a/blockdev.c +++ b/blockdev.c @@ -17,6 +17,29 @@ static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives); +/* + * We automatically delete the drive when a device using it gets + * unplugged. Questionable feature, but we can't just drop it. + * Device models call blockdev_mark_auto_del() to schedule the + * automatic deletion, and generic qdev code calls blockdev_auto_del() + * when deletion is actually safe. + */ +void blockdev_mark_auto_del(BlockDriverState *bs) +{ + DriveInfo *dinfo = drive_get_by_blockdev(bs); + + dinfo->auto_del = 1; +} + +void blockdev_auto_del(BlockDriverState *bs) +{ + DriveInfo *dinfo = drive_get_by_blockdev(bs); + + if (dinfo->auto_del) { + drive_uninit(dinfo); + } +} + QemuOpts *drive_add(const char *file, const char *fmt, ...) { va_list ap; |