summaryrefslogtreecommitdiff
path: root/blockdev.c
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2010-07-13 19:49:16 -0300
committerMarcelo Tosatti <mtosatti@redhat.com>2010-07-13 19:49:16 -0300
commit6b440ef2a97e45f6839413f7609fa16090c5d5ff (patch)
tree3563a2aab82ed0fa011a5353acd01b617c8d3947 /blockdev.c
parentdd09bf100b244a4af389eb5e427e1986836366e5 (diff)
parentd17b5288d91c935cc8795fa0620721da0a3865e1 (diff)
Merge commit 'd17b5288d91c935cc8795fa0620721da0a3865e1' into upstream-merge
* commit 'd17b5288d91c935cc8795fa0620721da0a3865e1': (54 commits) Remove uses of ram.last_offset (aka last_ram_offset) make rtc alatm work scsi: Fix SCSI bus reset Fix io-thread build breakage of a88790a14f Include sys/mman.h before qemu-options.h cris: Avoid debug clobbering for both I & D MMU state. cris: Dont clobber the MMU state across calls to cpu_get_phys_page_debug. cris: Break out rand LFSR update into a separate func. block: Handle multiwrite errors only when all requests have completed block: Fix early failure in multiwrite qemu-img: avoid calling exit(1) to release resources properly pc: Fix CMOS info for drives defined with -device ide: Make PIIX and ISA IDE init functions return the qdev block: Fix virtual media change for if=none block: Clean up bdrv_snapshots() savevm: Survive hot-unplug of snapshot device blkdebug: Initialize state as 1 blkdebug: Free QemuOpts after having read the config blkdebug: Fix set_state_opts definition qemu-option: New qemu_opts_reset() ... Conflicts: exec.c Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/blockdev.c b/blockdev.c
index 965a089e8..31b392ce5 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -19,6 +19,29 @@ DriveInfo *extboot_drive = NULL;
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;
@@ -54,18 +77,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;
@@ -80,16 +91,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)
@@ -534,7 +545,7 @@ static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
BlockDriverState *bs;
- int force = qdict_get_int(qdict, "force");
+ int force = qdict_get_try_bool(qdict, "force", 0);
const char *filename = qdict_get_str(qdict, "device");
bs = bdrv_find(filename);