Patchwork [RFC,4/4] qmp: Introduce memchar_read QMP command

login
register
mail settings
Submitter Lei Li
Date Aug. 1, 2012, 9:48 a.m.
Message ID <1343814538-27591-5-git-send-email-lilei@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/174424/
State New
Headers show

Comments

Lei Li - Aug. 1, 2012, 9:48 a.m.
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
---
 qapi-schema.json |   20 ++++++++++++++++++++
 qemu-char.c      |   16 ++++++++++++++++
 qmp-commands.hx  |   28 ++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 0 deletions(-)
Eric Blake - Aug. 1, 2012, 3:51 p.m.
On 08/01/2012 03:48 AM, Lei Li wrote:
> Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
> ---
>  qapi-schema.json |   20 ++++++++++++++++++++
>  qemu-char.c      |   16 ++++++++++++++++
>  qmp-commands.hx  |   28 ++++++++++++++++++++++++++++
>  3 files changed, 64 insertions(+), 0 deletions(-)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 3c8530f..23edda9 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -226,6 +226,26 @@
>    'data': {'chardev': 'str', 'size': 'int', 'data': 'str'} }
>  
>  ##
> +# @memchar_read:

As in the previous patch, s/_/-/g

> +#
> +# Provide read interface for memchardev. Read from memchar
> +# char device and return the data.
> +#
> +# @chardev: the name of the  memchar char device.
> +#
> +# @size: the size to write in bytes.

s/write/read/

> +#
> +# Returns: The data read from memchar as string.
> +#          If @chardev is not a valid memchar device, DeviceNotFound
> +#          If an I/O error occurs while reading, IOError
> +#
> +# Since: 1.2
> +##
> +{ 'command': 'memchar_read',
> +  'data': {'chardev': 'str', 'size': 'int'},
> +  'returns': 'str' }

Again, is there going to be a binary encoding issue?

Patch

diff --git a/qapi-schema.json b/qapi-schema.json
index 3c8530f..23edda9 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -226,6 +226,26 @@ 
   'data': {'chardev': 'str', 'size': 'int', 'data': 'str'} }
 
 ##
+# @memchar_read:
+#
+# Provide read interface for memchardev. Read from memchar
+# char device and return the data.
+#
+# @chardev: the name of the  memchar char device.
+#
+# @size: the size to write in bytes.
+#
+# Returns: The data read from memchar as string.
+#          If @chardev is not a valid memchar device, DeviceNotFound
+#          If an I/O error occurs while reading, IOError
+#
+# Since: 1.2
+##
+{ 'command': 'memchar_read',
+  'data': {'chardev': 'str', 'size': 'int'},
+  'returns': 'str' }
+
+##
 # @CommandInfo:
 #
 # Information about a QMP command
diff --git a/qemu-char.c b/qemu-char.c
index 1012e65..545a792 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2655,6 +2655,22 @@  void qmp_memchar_write(const char *chardev, int64_t size,
     }
 }
 
+char *qmp_memchar_read(const char *chardev, int64_t size,
+                       Error **errp)
+{
+    CharDriverState *chr;
+    char *out_data;
+
+    chr = qemu_chr_find(chardev);
+    if(!chr) {
+        error_set(errp, QERR_DEVICE_NOT_FOUND, chardev);
+        return NULL;
+    }
+
+    mem_chr_read(chr, (uint8_t *)out_data, size);
+    return out_data;
+}
+
 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
 {
     char host[65], port[33], width[8], height[8];
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 182f1e6..163e547 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -470,6 +470,34 @@  Example:
 EQMP
 
     {
+        .name       = "memchar_read",
+        .args_type  = "id:s,size:i",
+        .mhandler.cmd_new = qmp_marshal_input_memchar_read,
+    },
+
+SQMP
+memchar_read
+-------------
+
+Provide read interface for memchardev. Read from memchar
+char device and return the data.
+
+Arguments:
+
+- "chardev": the name of the char device, must be unique (json-string)
+- "size": the memory size in bytes, init size of the memchar
+          by default (json-int)
+
+Example:
+
+-> { "execute": "memchar_read",
+                "arguments": { "chardev": foo,
+                               "size": 1000,
+<- { "return": "data string" }
+
+EQMP
+
+    {
         .name       = "xen-save-devices-state",
         .args_type  = "filename:F",
     .mhandler.cmd_new = qmp_marshal_input_xen_save_devices_state,