diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2010-07-06 08:31:43 -0500 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2010-07-06 08:31:43 -0500 |
commit | 734003e6153b3552b9406ef598a1e67aac4a899e (patch) | |
tree | 9e4b225de8915dfecaec15356f085f9cb36057f7 /blockdev.c | |
parent | 02d0ba1420803562109185f47be6f7430bfdefae (diff) | |
parent | de189a1b4a471d37a2909e97646654fc9751b52f (diff) |
Merge remote branch 'kwolf/for-anthony' into staging
Diffstat (limited to 'blockdev.c')
-rw-r--r-- | blockdev.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/blockdev.c b/blockdev.c index 4dcfad89c5..be88098d53 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; @@ -52,18 +75,6 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit) return NULL; } -DriveInfo *drive_get_by_id(const char *id) -{ - DriveInfo *dinfo; - - QTAILQ_FOREACH(dinfo, &drives, next) { - if (strcmp(id, dinfo->id)) - continue; - return dinfo; - } - return NULL; -} - int drive_get_max_bus(BlockInterfaceType type) { int max_bus; @@ -78,16 +89,16 @@ int drive_get_max_bus(BlockInterfaceType type) return max_bus; } -const char *drive_get_serial(BlockDriverState *bdrv) +DriveInfo *drive_get_by_blockdev(BlockDriverState *bs) { DriveInfo *dinfo; QTAILQ_FOREACH(dinfo, &drives, next) { - if (dinfo->bdrv == bdrv) - return dinfo->serial; + if (dinfo->bdrv == bs) { + return dinfo; + } } - - return "\0"; + return NULL; } static void bdrv_format_print(void *opaque, const char *name) |