qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 3/3] QAPI: Introduce memchar-read QMP command


From: Luiz Capitulino
Subject: Re: [Qemu-devel] [PATCH 3/3] QAPI: Introduce memchar-read QMP command
Date: Fri, 25 Jan 2013 11:47:39 -0200

On Fri, 25 Jan 2013 00:03:21 +0800
Lei Li <address@hidden> wrote:

> +MemCharRead *qmp_memchar_read(const char *device, int64_t size,
> +                              bool has_format, enum DataFormat format,
> +                              Error **errp)
> +{
> +    CharDriverState *chr;
> +    guchar *read_data;
> +    MemCharRead *meminfo;
> +    size_t count;
> +
> +    chr = qemu_chr_find(device);
> +    if (!chr) {
> +        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
> +        return NULL;
> +    }
> +
> +    if (qemu_is_chr(chr, "memory")) {
> +        error_setg(errp,"%s is not memory char device", device);
> +        return NULL;
> +    }
> +
> +    if (size <= 0) {
> +        error_setg(errp, "size must be greater than zero");
> +        return NULL;
> +    }
> +
> +    meminfo = g_malloc0(sizeof(MemCharRead));
> +
> +    count = qemu_chr_cirmem_count(chr);
> +    if (count == 0) {
> +        return meminfo;

Although things work out, you can't return meminfo->data=NULL because
'data' isn't (and shouldn't be) optional. The right thing to do is to
return an empty string.

As I believe you'll agree with that change, and to avoid you a respin,
I'll make that change for you. Also:

> +    }
> +
> +    size = size > count ? count : size;
> +    read_data = g_malloc0(size + 1);
> +
> +    meminfo->count = cirmem_chr_read(chr, read_data, size);
> +
> +    if (has_format && (format == DATA_FORMAT_BASE64)) {
> +       if (read_data) {

This check is not needed (and you actually do the wrong thing is read_data=NULL.
But I'll just drop it for you.

> +           meminfo->data = g_base64_encode(read_data, 
> (size_t)meminfo->count);
> +       }
> +    } else {
> +        meminfo->data = (char *)read_data;
> +    }
> +
> +    return meminfo;
> +}
> +
>  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 8d10a67..17f83b3 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -499,6 +499,39 @@ Example:
>  EQMP
>  
>      {
> +        .name       = "memchar-read",
> +        .args_type  = "device:s,size:i,format:s?",
> +        .mhandler.cmd_new = qmp_marshal_input_memchar_read,
> +    },
> +
> +SQMP
> +memchar-read
> +-------------
> +
> +Provide read interface for CirMemCharDriver. Read from the char
> +device memory and return the data with size.
> +
> +Arguments:
> +
> +- "device": the name of the char device, must be unique (json-string)
> +- "size": the memory size wanted to read in bytes (refer to unencoded
> +          size of the raw data), would adjust to the init size of the
> +          memchar if the requested size is larger than it. (json-int)
> +- "format": the data format write to memchardev, default is
> +            utf8. (json-string, optional)
> +          - Possible values: "utf8", "base64"
> +
> +Example:
> +
> +-> { "execute": "memchar-read",
> +                "arguments": { "device": foo,
> +                               "size": 1000,
> +                               "format": "utf8" } }
> +<- { "return": { "data": "data string...", "count": 1000 } }
> +
> +EQMP
> +
> +    {
>          .name       = "xen-save-devices-state",
>          .args_type  = "filename:F",
>      .mhandler.cmd_new = qmp_marshal_input_xen_save_devices_state,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]