diff mbox

[RFC,V2,7/7] qmp: Add block-dedup-control.

Message ID 1360153946-9617-8-git-send-email-benoit@irqsave.net
State New
Headers show

Commit Message

Benoît Canet Feb. 6, 2013, 12:32 p.m. UTC
---
 blockdev.c       |   20 ++++++++++++++++++++
 qapi-schema.json |   19 +++++++++++++++++++
 qmp-commands.hx  |   25 +++++++++++++++++++++++++
 3 files changed, 64 insertions(+)

Comments

Eric Blake Feb. 7, 2013, 5:44 p.m. UTC | #1
On 02/06/2013 05:32 AM, Benoît Canet wrote:
> ---
>  blockdev.c       |   20 ++++++++++++++++++++
>  qapi-schema.json |   19 +++++++++++++++++++
>  qmp-commands.hx  |   25 +++++++++++++++++++++++++
>  3 files changed, 64 insertions(+)
> 

> +++ b/qapi-schema.json
> @@ -812,6 +812,25 @@
>  ##
>  { 'enum': 'DedupStatus', 'data': [ 'stopped', 'starting', 'started',
>                                     'stopping' ] }
> +##
> +# @block-dedup-control:
> +#
> +# This command pause the deduplication on a device that supports it.

s/pause/controls/, or copy your wording from the .hx file.

> +#
> +# @device:   the name of the device to control the deduplication for
> +# @enable:   true to start, false to stop
> +#
> +# Returns: nothing on success
> +#          If @device is not a valid block device, DeviceNotFound
> +#          GenericError if @device is not deduplicated

Most API in this file don't bother calling out GenericError; it is
implicit that pretty much any function is allowed to fail with a
GenericError and that the text of the error message would hopefully
explain why.

> +SQMP
> +block-dedup-control
> +------------
> +
> +Start or stop the deduplication on a device that support it.

s/support/supports/
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index 63e6f1e..44e9e58 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -897,6 +897,26 @@  void qmp_block_passwd(const char *device, const char *password, Error **errp)
     }
 }
 
+void qmp_block_dedup_control(const char *device, const bool enable,
+                             Error **errp)
+{
+    BlockDriverState *bs;
+    int err;
+
+    bs = bdrv_find(device);
+    if (!bs) {
+        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+        return;
+    }
+
+    err = bdrv_dedup_control(bs, enable);
+    if (err == -EINVAL) {
+        error_setg(errp, "Device '%s' doesn't support deduplication",
+            bdrv_get_device_name(bs));
+        return;
+    }
+}
+
 static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
                                     int bdrv_flags, BlockDriver *drv,
                                     const char *password, Error **errp)
diff --git a/qapi-schema.json b/qapi-schema.json
index ec61f6a..f861f00 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -812,6 +812,25 @@ 
 ##
 { 'enum': 'DedupStatus', 'data': [ 'stopped', 'starting', 'started',
                                    'stopping' ] }
+##
+# @block-dedup-control:
+#
+# This command pause the deduplication on a device that supports it.
+#
+# @device:   the name of the device to control the deduplication for
+# @enable:   true to start, false to stop
+#
+# Returns: nothing on success
+#          If @device is not a valid block device, DeviceNotFound
+#          GenericError if @device is not deduplicated
+#
+# Notes:  Not all block formats support deduplication one must use
+#         query-blockstats before and look at the optional deduplication field.
+#
+# Since: 1.5
+##
+{ 'command': 'block-dedup-control',
+  'data': {'device': 'str', 'enable': 'bool' } }
 
 ##
 # @BlockDeviceDedupInfo
diff --git a/qmp-commands.hx b/qmp-commands.hx
index bbb21f3..9c53e16 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1310,6 +1310,31 @@  Example:
 EQMP
 
     {
+        .name       = "block-dedup-control",
+        .args_type  = "device:B,enable:b",
+        .mhandler.cmd_new = qmp_marshal_input_block_dedup_control,
+    },
+
+SQMP
+block-dedup-control
+------------
+
+Start or stop the deduplication on a device that support it.
+
+Arguments:
+
+- "device": device name (json-string)
+- "enable": true to start, false to stop (json-bool)
+
+Example:
+
+-> { "execute": "block-dedup-control",
+     "arguments": { "device": "ide0-hd0", "enable": false } }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "block_set_io_throttle",
         .args_type  = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l",
         .mhandler.cmd_new = qmp_marshal_input_block_set_io_throttle,