From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:35518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjZZp-0003lS-33 for qemu-devel@nongnu.org; Wed, 20 Jul 2011 12:24:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QjZZi-0008RR-Rt for qemu-devel@nongnu.org; Wed, 20 Jul 2011 12:24:48 -0400 Received: from oxygen.pond.sub.org ([78.46.104.156]:55563) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjZZe-0008Ok-7U for qemu-devel@nongnu.org; Wed, 20 Jul 2011 12:24:38 -0400 From: Markus Armbruster Date: Wed, 20 Jul 2011 18:23:57 +0200 Message-Id: <1311179069-27882-24-git-send-email-armbru@redhat.com> In-Reply-To: <1311179069-27882-1-git-send-email-armbru@redhat.com> References: <1311179069-27882-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH 23/55] block: Show whether the guest ejected the medium in info block List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, quintela@redhat.com, dbaryshkov@gmail.com, stefano.stabellini@eu.citrix.com, lcapitulino@redhat.com, amit.shah@redhat.com Need to ask the device, so this requires new BlockDevOps member is_medium_ejected(). Signed-off-by: Markus Armbruster --- block.c | 18 ++++++++++++++++-- block.h | 6 ++++++ hw/ide/core.c | 6 ++++++ hw/scsi-disk.c | 10 ++++++++++ qmp-commands.hx | 1 + 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index ba24bf1..6759066 100644 --- a/block.c +++ b/block.c @@ -761,6 +761,14 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs) } } +bool bdrv_dev_is_medium_ejected(BlockDriverState *bs) +{ + if (bs->dev_ops && bs->dev_ops->is_medium_ejected) { + return bs->dev_ops->is_medium_ejected(bs->dev_opaque); + } + return false; +} + static void bdrv_dev_resize_cb(BlockDriverState *bs) { if (bs->dev_ops && bs->dev_ops->resize_cb) { @@ -1712,7 +1720,9 @@ static void bdrv_print_dict(QObject *obj, void *opaque) if (qdict_get_bool(bs_dict, "removable")) { monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked")); } - + if (qdict_get_try_bool(bs_dict, "ejected", false)) { + monitor_printf(mon, " ejected"); + } if (qdict_haskey(bs_dict, "inserted")) { QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted")); @@ -1747,15 +1757,19 @@ void bdrv_info(Monitor *mon, QObject **ret_data) QTAILQ_FOREACH(bs, &bdrv_states, list) { QObject *bs_obj; + QDict *bs_dict; bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', " "'removable': %i, 'locked': %i }", bs->device_name, bs->removable, bs->locked); + bs_dict = qobject_to_qdict(bs_obj); + if (bdrv_dev_is_medium_ejected(bs)) { + qdict_put(bs_dict, "ejected", qbool_from_int(1)); + } if (bs->drv) { QObject *obj; - QDict *bs_dict = qobject_to_qdict(bs_obj); obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, " "'encrypted': %i }", diff --git a/block.h b/block.h index 89f75e3..65a0115 100644 --- a/block.h +++ b/block.h @@ -36,6 +36,11 @@ typedef struct BlockDevOps { */ void (*change_media_cb)(void *opaque); /* + * Is medium ejected from the device? + * Device models calling bdrv_eject() should implement this. + */ + bool (*is_medium_ejected)(void *opaque); + /* * Runs when the size changed (e.g. monitor command block_resize) */ void (*resize_cb)(void *opaque); @@ -92,6 +97,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev); void *bdrv_get_attached_dev(BlockDriverState *bs); void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, void *opaque); +bool bdrv_dev_is_medium_ejected(BlockDriverState *bs); int bdrv_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors); int bdrv_write(BlockDriverState *bs, int64_t sector_num, diff --git a/hw/ide/core.c b/hw/ide/core.c index c8cfd67..b07a4d7 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1769,8 +1769,14 @@ void ide_bus_reset(IDEBus *bus) bus->dma->ops->reset(bus->dma); } +static bool ide_cd_medium_ejected(void *opaque) +{ + return ((IDEState *)opaque)->tray_open; +} + static const BlockDevOps ide_cd_block_ops = { .change_media_cb = ide_cd_change_cb, + .is_medium_ejected = ide_cd_medium_ejected, }; int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 207a868..ff52d87 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1261,6 +1261,15 @@ static void scsi_destroy(SCSIDevice *dev) blockdev_mark_auto_del(s->qdev.conf.bs); } +static bool scsi_cd_is_medium_ejected(void *opaque) +{ + return ((SCSIDiskState *)opaque)->tray_open; +} + +static const BlockDevOps scsi_cd_block_ops = { + .is_medium_ejected = scsi_cd_is_medium_ejected, +}; + static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); @@ -1294,6 +1303,7 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind) } if (kind == SCSI_CD) { + bdrv_set_dev_ops(s->bs, &scsi_cd_block_ops, s); s->qdev.blocksize = 2048; } else { s->qdev.blocksize = s->qdev.conf.logical_block_size; diff --git a/qmp-commands.hx b/qmp-commands.hx index 92c5c3a..cc5d30f 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1070,6 +1070,7 @@ Each json-object contain the following: - Possible values: "unknown" - "removable": true if the device is removable, false otherwise (json-bool) - "locked": true if the device is locked, false otherwise (json-bool) +- "ejected": present and true if the device ejected its media (json-bool) - "inserted": only present if the device is inserted, it is a json-object containing the following: - "file": device file name (json-string) -- 1.7.2.3