All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 24/35] block: Show whether the virtual tray is open in info block
Date: Mon, 12 Sep 2011 16:19:23 +0200	[thread overview]
Message-ID: <1315837174-15327-25-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1315837174-15327-1-git-send-email-kwolf@redhat.com>

From: Markus Armbruster <armbru@redhat.com>

Need to ask the device, so this requires new BlockDevOps member
is_tray_open().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c         |   18 ++++++++++++++++--
 block.h         |    6 ++++++
 hw/ide/core.c   |    6 ++++++
 hw/scsi-disk.c  |    6 ++++++
 qmp-commands.hx |    2 ++
 5 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index d8193a3..febfd67 100644
--- a/block.c
+++ b/block.c
@@ -819,6 +819,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_tray_open(BlockDriverState *bs)
+{
+    if (bs->dev_ops && bs->dev_ops->is_tray_open) {
+        return bs->dev_ops->is_tray_open(bs->dev_opaque);
+    }
+    return false;
+}
+
 static void bdrv_dev_resize_cb(BlockDriverState *bs)
 {
     if (bs->dev_ops && bs->dev_ops->resize_cb) {
@@ -1853,8 +1861,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"));
+        monitor_printf(mon, " tray-open=%d",
+                       qdict_get_bool(bs_dict, "tray-open"));
     }
-
     if (qdict_haskey(bs_dict, "inserted")) {
         QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
 
@@ -1889,16 +1898,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, "tray-open",
+                      qbool_from_int(bdrv_dev_is_tray_open(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 e4b5530..9f6d02c 100644
--- a/block.h
+++ b/block.h
@@ -38,6 +38,11 @@ typedef struct BlockDevOps {
      */
     void (*change_media_cb)(void *opaque);
     /*
+     * Is the virtual tray open?
+     * Device models implement this only when the device has a tray.
+     */
+    bool (*is_tray_open)(void *opaque);
+    /*
      * Is the virtual medium locked into the device?
      * Device models 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_tray_open(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 716addc..8f719ee 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1795,6 +1795,11 @@ void ide_bus_reset(IDEBus *bus)
     bus->dma->ops->reset(bus->dma);
 }
 
+static bool ide_cd_is_tray_open(void *opaque)
+{
+    return ((IDEState *)opaque)->tray_open;
+}
+
 static bool ide_cd_is_medium_locked(void *opaque)
 {
     return ((IDEState *)opaque)->tray_locked;
@@ -1802,6 +1807,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_tray_open = ide_cd_is_tray_open,
     .is_medium_locked = ide_cd_is_medium_locked,
 };
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 0f0cddc..f48ca8b 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1176,6 +1176,11 @@ static void scsi_cd_change_media_cb(void *opaque)
 {
 }
 
+static bool scsi_cd_is_tray_open(void *opaque)
+{
+    return ((SCSIDiskState *)opaque)->tray_open;
+}
+
 static bool scsi_cd_is_medium_locked(void *opaque)
 {
     return ((SCSIDiskState *)opaque)->tray_locked;
@@ -1183,6 +1188,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_tray_open = scsi_cd_is_tray_open,
     .is_medium_locked = scsi_cd_is_medium_locked,
 };
 
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 27cc66e..d1c2c59 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)
+- "tray-open": only present if removable, true if the device has a tray,
+               and it is open (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.6

  parent reply	other threads:[~2011-09-12 14:17 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-12 14:18 [Qemu-devel] [PULL 00/35] Block patches Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 01/35] qcow2: removed unused depends_on field Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 02/35] ide: Fix ATA command READ to set ATAPI signature for CD-ROM Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 03/35] ide: Use a table to declare which drive kinds accept each command Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 04/35] ide: Reject ATA commands specific to drive kinds Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 05/35] ide/atapi: Clean up misleading name in cmd_start_stop_unit() Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 06/35] ide/atapi: Track tray open/close state Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 07/35] scsi-disk: Factor out scsi_disk_emulate_start_stop() Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 08/35] scsi-disk: Track tray open/close state Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 09/35] block: Revert entanglement of bdrv_is_inserted() with tray status Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 10/35] block: Drop tray status tracking, no longer used Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 11/35] ide/atapi: Track tray locked state Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 12/35] scsi-disk: " Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 13/35] block: Leave enforcing tray lock to device models Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 14/35] block: Drop medium lock tracking, ask device models instead Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 15/35] block: Rename bdrv_set_locked() to bdrv_lock_medium() Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 16/35] rbd: allow client id to be specified in config string Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 17/35] rbd: clean up, fix style Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 18/35] rbd: fix leak in qemu_rbd_open failure paths Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 19/35] ide/atapi: Don't fail eject when tray is already open Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 20/35] scsi-disk: Fix START_STOP to fail when it can't eject Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 21/35] ide/atapi: Preserve tray state on migration Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 22/35] block: Clean up remaining users of "removable" Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 23/35] block: Drop BlockDriverState member removable Kevin Wolf
2011-09-12 14:19 ` Kevin Wolf [this message]
2011-09-12 14:19 ` [Qemu-devel] [PATCH 25/35] block: Move BlockConf & friends from block_int.h to block.h Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 26/35] hw: Trim superfluous #include "block_int.h" Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 27/35] block: New bdrv_set_buffer_alignment() Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 28/35] block: Reset buffer alignment on detach Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 29/35] nbd: Clean up use of block_int.h Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 30/35] block: New change_media_cb() parameter load Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 31/35] ide/atapi scsi-disk: Make monitor eject -f, then change work Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 32/35] qcow2: initialize metadata before inserting in cluster_allocs Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 33/35] ahci: Remove unused struct member Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 34/35] qcow2: align cluster_data to block to improve performance using O_DIRECT Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 35/35] qcow2: fix range check Kevin Wolf
2011-09-15 19:09 ` [Qemu-devel] [PULL 00/35] Block patches Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1315837174-15327-25-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.