Message ID | 1312376904-16115-38-git-send-email-armbru@redhat.com |
---|---|
State | New |
Headers | show |
On Wed, 3 Aug 2011 15:08:16 +0200 Markus Armbruster <armbru@redhat.com> wrote: > Need to ask the device, so this requires new BlockDevOps member > is_medium_ejected(). > > Signed-off-by: Markus Armbruster <armbru@redhat.com> Looks good to me. > --- > block.c | 17 +++++++++++++++-- > block.h | 6 ++++++ > hw/ide/core.c | 6 ++++++ > hw/scsi-disk.c | 6 ++++++ > qmp-commands.hx | 2 ++ > 5 files changed, 35 insertions(+), 2 deletions(-) > > diff --git a/block.c b/block.c > index b488b21..fed0c16 100644 > --- a/block.c > +++ b/block.c > @@ -792,6 +792,14 @@ bool bdrv_dev_has_removable_media(BlockDriverState *bs) > return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb); > } > > +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) { > @@ -1813,8 +1821,8 @@ 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")); > + monitor_printf(mon, " ejected=%d", qdict_get_bool(bs_dict, "ejected")); > } > - > if (qdict_haskey(bs_dict, "inserted")) { > QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted")); > > @@ -1849,16 +1857,21 @@ 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, > bdrv_dev_has_removable_media(bs), > bdrv_dev_is_medium_locked(bs)); > + bs_dict = qobject_to_qdict(bs_obj); > > + if (bdrv_dev_has_removable_media(bs)) { > + qdict_put(bs_dict, "ejected", > + qbool_from_int(bdrv_dev_is_medium_ejected(bs))); > + } > 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 6b11be5..fdb7680 100644 > --- a/block.h > +++ b/block.h > @@ -38,6 +38,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); > + /* > * Is the virtual medium locked into the device? > * Device models should implement this only when device has such a > * lock. > @@ -101,6 +106,7 @@ void *bdrv_get_attached_dev(BlockDriverState *bs); > void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, > void *opaque); > bool bdrv_dev_has_removable_media(BlockDriverState *bs); > +bool bdrv_dev_is_medium_ejected(BlockDriverState *bs); > bool bdrv_dev_is_medium_locked(BlockDriverState *bs); > int bdrv_read(BlockDriverState *bs, int64_t sector_num, > uint8_t *buf, int nb_sectors); > diff --git a/hw/ide/core.c b/hw/ide/core.c > index c82d8a1..47dd81c 100644 > --- a/hw/ide/core.c > +++ b/hw/ide/core.c > @@ -1769,6 +1769,11 @@ 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 bool ide_cd_is_medium_locked(void *opaque) > { > return ((IDEState *)opaque)->tray_locked; > @@ -1776,6 +1781,7 @@ static bool ide_cd_is_medium_locked(void *opaque) > > static const BlockDevOps ide_cd_block_ops = { > .change_media_cb = ide_cd_change_cb, > + .is_medium_ejected = ide_cd_medium_ejected, > .is_medium_locked = ide_cd_is_medium_locked, > }; > > diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c > index a7a70bd..3ebcee4 100644 > --- a/hw/scsi-disk.c > +++ b/hw/scsi-disk.c > @@ -1215,6 +1215,11 @@ static void scsi_cd_change_media_cb(void *opaque) > { > } > > +static bool scsi_cd_is_medium_ejected(void *opaque) > +{ > + return ((SCSIDiskState *)opaque)->tray_open; > +} > + > static bool scsi_cd_is_medium_locked(void *opaque) > { > return ((SCSIDiskState *)opaque)->tray_locked; > @@ -1222,6 +1227,7 @@ static bool scsi_cd_is_medium_locked(void *opaque) > > static const BlockDevOps scsi_cd_block_ops = { > .change_media_cb = scsi_cd_change_media_cb, > + .is_medium_ejected = scsi_cd_is_medium_ejected, > .is_medium_locked = scsi_cd_is_medium_locked, > }; > > diff --git a/qmp-commands.hx b/qmp-commands.hx > index 03f67da..b0447f1 100644 > --- a/qmp-commands.hx > +++ b/qmp-commands.hx > @@ -1131,6 +1131,8 @@ 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": only present if removable, 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)
Am 03.08.2011 15:08, schrieb Markus Armbruster: > Need to ask the device, so this requires new BlockDevOps member > is_medium_ejected(). > > Signed-off-by: Markus Armbruster <armbru@redhat.com> I find the name confusing. "medium is ejected" seems to mean "tray is open". It isn't obvious that "tray is closed, but no medium is inserted" is not "medium is ejected". Why not call it tray_open like in the devices? Kevin
Kevin Wolf <kwolf@redhat.com> writes: > Am 03.08.2011 15:08, schrieb Markus Armbruster: >> Need to ask the device, so this requires new BlockDevOps member >> is_medium_ejected(). >> >> Signed-off-by: Markus Armbruster <armbru@redhat.com> > > I find the name confusing. "medium is ejected" seems to mean "tray is > open". It isn't obvious that "tray is closed, but no medium is inserted" > is not "medium is ejected". > > Why not call it tray_open like in the devices? Not all all devices with removable media have trays. I'll rename it anyway. We'll figure out how to handle devices without trays when we add one.
Am 02.09.2011 17:29, schrieb Markus Armbruster: > Kevin Wolf <kwolf@redhat.com> writes: > >> Am 03.08.2011 15:08, schrieb Markus Armbruster: >>> Need to ask the device, so this requires new BlockDevOps member >>> is_medium_ejected(). >>> >>> Signed-off-by: Markus Armbruster <armbru@redhat.com> >> >> I find the name confusing. "medium is ejected" seems to mean "tray is >> open". It isn't obvious that "tray is closed, but no medium is inserted" >> is not "medium is ejected". >> >> Why not call it tray_open like in the devices? > > Not all all devices with removable media have trays. I'll rename it > anyway. We'll figure out how to handle devices without trays when we > add one. Then you need to clarify the intended semantics. For devices without a tray it's completely unclear to me what it means. The example for such a device that we have today is floppy. Kevin
diff --git a/block.c b/block.c index b488b21..fed0c16 100644 --- a/block.c +++ b/block.c @@ -792,6 +792,14 @@ bool bdrv_dev_has_removable_media(BlockDriverState *bs) return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb); } +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) { @@ -1813,8 +1821,8 @@ 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")); + monitor_printf(mon, " ejected=%d", qdict_get_bool(bs_dict, "ejected")); } - if (qdict_haskey(bs_dict, "inserted")) { QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted")); @@ -1849,16 +1857,21 @@ 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, bdrv_dev_has_removable_media(bs), bdrv_dev_is_medium_locked(bs)); + bs_dict = qobject_to_qdict(bs_obj); + if (bdrv_dev_has_removable_media(bs)) { + qdict_put(bs_dict, "ejected", + qbool_from_int(bdrv_dev_is_medium_ejected(bs))); + } 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 6b11be5..fdb7680 100644 --- a/block.h +++ b/block.h @@ -38,6 +38,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); + /* * Is the virtual medium locked into the device? * Device models should implement this only when device has such a * lock. @@ -101,6 +106,7 @@ void *bdrv_get_attached_dev(BlockDriverState *bs); void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, void *opaque); bool bdrv_dev_has_removable_media(BlockDriverState *bs); +bool bdrv_dev_is_medium_ejected(BlockDriverState *bs); bool bdrv_dev_is_medium_locked(BlockDriverState *bs); int bdrv_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors); diff --git a/hw/ide/core.c b/hw/ide/core.c index c82d8a1..47dd81c 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1769,6 +1769,11 @@ 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 bool ide_cd_is_medium_locked(void *opaque) { return ((IDEState *)opaque)->tray_locked; @@ -1776,6 +1781,7 @@ static bool ide_cd_is_medium_locked(void *opaque) static const BlockDevOps ide_cd_block_ops = { .change_media_cb = ide_cd_change_cb, + .is_medium_ejected = ide_cd_medium_ejected, .is_medium_locked = ide_cd_is_medium_locked, }; diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index a7a70bd..3ebcee4 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1215,6 +1215,11 @@ static void scsi_cd_change_media_cb(void *opaque) { } +static bool scsi_cd_is_medium_ejected(void *opaque) +{ + return ((SCSIDiskState *)opaque)->tray_open; +} + static bool scsi_cd_is_medium_locked(void *opaque) { return ((SCSIDiskState *)opaque)->tray_locked; @@ -1222,6 +1227,7 @@ static bool scsi_cd_is_medium_locked(void *opaque) static const BlockDevOps scsi_cd_block_ops = { .change_media_cb = scsi_cd_change_media_cb, + .is_medium_ejected = scsi_cd_is_medium_ejected, .is_medium_locked = scsi_cd_is_medium_locked, }; diff --git a/qmp-commands.hx b/qmp-commands.hx index 03f67da..b0447f1 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1131,6 +1131,8 @@ 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": only present if removable, 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)
Need to ask the device, so this requires new BlockDevOps member is_medium_ejected(). Signed-off-by: Markus Armbruster <armbru@redhat.com> --- block.c | 17 +++++++++++++++-- block.h | 6 ++++++ hw/ide/core.c | 6 ++++++ hw/scsi-disk.c | 6 ++++++ qmp-commands.hx | 2 ++ 5 files changed, 35 insertions(+), 2 deletions(-)