qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ian Main <imain@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, imain@redhat.com,
	stefanha@redhat.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v2] RFC: Add blockdev-del QMP command
Date: Wed, 12 Feb 2014 09:36:13 -0800	[thread overview]
Message-ID: <1392226573-14901-1-git-send-email-imain@redhat.com> (raw)

This is the sister command to blockdev-add.  In Fam's example he uses
the drive_del HMP command to clean up but it would be much nicer to
have a way to do this via QMP.

Signed-off-by: Ian Main <imain@redhat.com>
---

v2:
- s/blockdev-delete/blockdev-del
- Fixed example.

 blockdev.c       | 52 ++++++++++++++++++++++++++++++++++++++--------------
 qapi-schema.json | 11 +++++++++++
 qmp-commands.hx  | 30 ++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 14 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 7372721..96d0da1 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1733,21 +1733,9 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
     }
 }
 
-int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
+/* This is called by both do_drive_del() and qmp_blockdev_del */
+static int drive_del_core(BlockDriverState *bs)
 {
-    const char *id = qdict_get_str(qdict, "id");
-    BlockDriverState *bs;
-
-    bs = bdrv_find(id);
-    if (!bs) {
-        qerror_report(QERR_DEVICE_NOT_FOUND, id);
-        return -1;
-    }
-    if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, NULL)) {
-        qerror_report(QERR_DEVICE_IN_USE, id);
-        return -1;
-    }
-
     /* quiesce block driver; prevent further io */
     bdrv_drain_all();
     bdrv_flush(bs);
@@ -1771,6 +1759,25 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
     return 0;
 }
 
+int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    const char *id = qdict_get_str(qdict, "id");
+    BlockDriverState *bs;
+
+    bs = bdrv_find(id);
+    if (!bs) {
+        qerror_report(QERR_DEVICE_NOT_FOUND, id);
+        return -1;
+    }
+
+    if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, NULL)) {
+        qerror_report(QERR_DEVICE_IN_USE, id);
+        return -1;
+    }
+
+    return drive_del_core(bs);
+}
+
 void qmp_block_resize(bool has_device, const char *device,
                       bool has_node_name, const char *node_name,
                       int64_t size, Error **errp)
@@ -2386,6 +2393,23 @@ fail:
     qmp_output_visitor_cleanup(ov);
 }
 
+void qmp_blockdev_del(const char *device, Error **errp)
+{
+    BlockDriverState *bs;
+
+    bs = bdrv_find(device);
+    if (!bs) {
+        error_setg(errp, "Block device not found");
+        return;
+    }
+
+    if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, NULL)) {
+        return;
+    }
+
+    drive_del_core(bs);
+}
+
 static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs)
 {
     BlockJobInfoList **prev = opaque;
diff --git a/qapi-schema.json b/qapi-schema.json
index d22651c..01186cd 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4469,3 +4469,14 @@
 # Since: 1.7
 ##
 { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }
+
+##
+# @blockdev-del:
+#
+# Delete a block device.
+#
+# @device: Identifier for the block device to be deleted.
+#
+# Since: 2.0
+##
+{ 'command': 'blockdev-del', 'data': { 'device': 'str' } }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index c3ee46a..f08045d 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3442,6 +3442,36 @@ Example (2):
 EQMP
 
     {
+        .name       = "blockdev-del",
+        .args_type  = "device:s",
+        .mhandler.cmd_new = qmp_marshal_input_blockdev_del,
+    },
+
+SQMP
+blockdev-del
+------------
+
+Remove host block device.  The result is that guest generated IO is no
+longer submitted against the host device underlying the disk.  Once a
+drive has been deleted, the QEMU Block layer returns -EIO which results
+in IO errors in the guest for applications that are reading/writing to
+the device.  These errors are always reported to the guest, regardless
+of the drive's error actions (drive options rerror, werror).
+
+Arguments:
+
+- "device": Identifier of the block device (json-string)
+
+Example (1):
+
+-> { "execute": "blockdev-del",
+                "arguments": { "device": "target0" }
+   }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "query-named-block-nodes",
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_input_query_named_block_nodes,
-- 
1.8.3.1

             reply	other threads:[~2014-02-12 17:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-12 17:36 Ian Main [this message]
2014-02-12 18:07 ` [Qemu-devel] [PATCH v2] RFC: Add blockdev-del QMP command Eric Blake
2014-02-13  2:59 ` Fam Zheng
2014-02-13  8:59 ` Kevin Wolf
2014-02-14 19:17   ` Ian Main
2014-02-17 10:23     ` Kevin Wolf
2014-02-18  9:37   ` Markus Armbruster
2014-11-17 17:59 ` William Dauchy

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=1392226573-14901-1-git-send-email-imain@redhat.com \
    --to=imain@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).