From: Eric Blake <eblake@redhat.com>
To: Don Slutz <dslutz@verizon.com>, qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Luiz Capitulino" <lcapitulino@redhat.com>,
"Don Slutz" <don.slutz@gmail.com>,
"Anthony Liguori" <aliguori@amazon.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>,
"Richard Henderson" <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH v7 6/9] vmport_rpc: Add QMP access to vmport_rpc object.
Date: Mon, 15 Jun 2015 09:53:36 -0600 [thread overview]
Message-ID: <557EF500.3090409@redhat.com> (raw)
In-Reply-To: <1434117956-4929-7-git-send-email-dslutz@verizon.com>
[-- Attachment #1: Type: text/plain, Size: 4809 bytes --]
On 06/12/2015 08:05 AM, Don Slutz wrote:
> This adds one new inject command:
>
> inject-vmport-action
>
> And three guest info commands:
>
> vmport-guestinfo-set
> vmport-guestinfo-get
> query-vmport-guestinfo
>
> More details in qmp-commands.hx
>
> Signed-off-by: Don Slutz <dslutz@verizon.com>
> CC: Don Slutz <don.slutz@gmail.com>
> ---
> +typedef int FindVMPortRpcDeviceFunc(VMPortRpcState *s, const void *arg);
> +
> +/*
> + * The input and output argument that find_VMPortRpc_device() uses
> + * to do it's work.
s/it's/its/ (the only time "it's" is correct is if "it is" would also be
correct)
>
> +static int get_qmp_guestinfo(VMPortRpcState *s,
> + unsigned int a_key_len, const char *a_info_key,
> + unsigned int *a_value_len, void ** a_value_data)
No space after **.
> +void qmp_inject_vmport_action(enum VmportAction action, Error **errp)
> +{
> + int rc;
> +
> + switch (action) {
> + case VMPORT_ACTION_REBOOT:
> + rc = foreach_dynamic_vmport_rpc_device(vmport_rpc_find_send,
> + "OS_Reboot");
> + break;
> + case VMPORT_ACTION_HALT:
> + rc = foreach_dynamic_vmport_rpc_device(vmport_rpc_find_send,
> + "OS_Halt");
> + break;
> + case VMPORT_ACTION_MAX:
> + assert(action != VMPORT_ACTION_MAX);
> + abort(); /* Should be impossible to get here. */
> + break;
Don't know if any static checkers will complain about the break being
dead code.
> +
> +void qmp_vmport_guestinfo_set(const char *key, const char *value,
> + bool has_format, enum DataFormat format,
> + Error **errp)
> +{
> + int rc;
> + keyValue key_value;
> +
> + if (strncmp(key, "guestinfo.", strlen("guestinfo.")) == 0) {
> + key_value.key_data = (void *)(key + strlen("guestinfo."));
Cast here...
> + key_value.key_len = strlen(key) - strlen("guestinfo.");
> + } else {
> + key_value.key_data = (void *)key;
...and here...
> + key_value.key_len = strlen(key);
> + }
> + if (has_format && (format == DATA_FORMAT_BASE64)) {
> + gsize write_count;
> +
> + key_value.value_data = g_base64_decode(value, &write_count);
> + key_value.value_len = write_count;
> + } else {
> + key_value.value_data = (void *)value;
...and here is only needed to get rid of const. Would it help if struct
keyValue declared 'const char *key_data' instead of 'void *key_data'?
> + key_value.value_len = strlen(value);
> + }
> +
> + rc = foreach_dynamic_vmport_rpc_device(find_set, (void *)&key_value);
This cast is spurious (it does not get rid of const, and any non-const
pointer in C can already be passed to void* without a cast).
> +VmportGuestInfoValue *qmp_vmport_guestinfo_get(const char *key,
> + bool has_format,
> + enum DataFormat format,
> + Error **errp)
> +{
> + int rc;
> + keyValue key_value;
> + VmportGuestInfoValue *ret_value;
> +
> + if (strncmp(key, "guestinfo.", strlen("guestinfo.")) == 0) {
> + key_value.key_data = (void *)(key + strlen("guestinfo."));
> + key_value.key_len = strlen(key) - strlen("guestinfo.");
> + } else {
> + key_value.key_data = (void *)key;
More casts that might be prevented with correct const in the callback
struct.
> + key_value.key_len = strlen(key);
> + }
> +
> + rc = foreach_dynamic_vmport_rpc_device(find_get, (void *)&key_value);
Another spurious cast.
> + if (rc) {
> + convert_local_rc(errp, rc);
> + return NULL;
> + }
> +
> + ret_value = g_malloc(sizeof(VmportGuestInfoKey));
Do you want g_malloc0, or even the additional type-safety (and less
typing) of g_new0(VmportGuestInfoKey, 1)? Otherwise, if you later add
fields, but forget to initialize them, you'll have random garbage.
> + if (has_format && (format == DATA_FORMAT_BASE64)) {
> + ret_value->value = g_base64_encode(key_value.value_data,
> + key_value.value_len);
> + } else {
> + /*
> + * FIXME should check for complete, valid UTF-8 characters.
> + * Invalid sequences should be replaced by a suitable
> + * replacement character.
Or cause an error to be raised.
Looking better, though.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2015-06-15 15:53 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-12 14:05 [Qemu-devel] [PATCH v7 0/9] Add limited support of VMware's hyper-call rpc Don Slutz
2015-06-12 14:05 ` [Qemu-devel] [BUGFIX][PATCH v7 1/9] vmport: The io memory region needs to be at least a size of 4 Don Slutz
2015-06-12 22:38 ` Eric Blake
2015-06-15 13:53 ` Don Slutz
2015-06-15 15:09 ` Eric Blake
2015-06-15 16:15 ` Don Slutz
2015-06-12 14:05 ` [Qemu-devel] [PATCH v7 2/9] vmport: Switch to trace Don Slutz
2015-06-12 14:05 ` [Qemu-devel] [BUGFIX][PATCH v7 3/9] vmport: Fix vmport_cmd_ram_size Don Slutz
2015-06-12 14:05 ` [Qemu-devel] [PATCH v7 4/9] vmport_rpc: Add the object vmport_rpc Don Slutz
2015-06-12 14:05 ` [Qemu-devel] [PATCH v7 5/9] vmport_rpc: Add limited support of VMware's hyper-call rpc Don Slutz
2015-06-12 14:05 ` [Qemu-devel] [PATCH v7 6/9] vmport_rpc: Add QMP access to vmport_rpc object Don Slutz
2015-06-15 15:53 ` Eric Blake [this message]
2015-06-17 16:42 ` Don Slutz
2015-06-12 14:05 ` [Qemu-devel] [PATCH v7 7/9] vmport_rpc: Add migration Don Slutz
2015-06-12 14:05 ` [Qemu-devel] [PATCH v7 8/9] vmport: Add VMware all ring hack Don Slutz
2015-06-12 14:05 ` [Qemu-devel] [PATCH v7 9/9] MAINTAINERS: add VMware port Don Slutz
2015-06-17 13:44 ` [Qemu-devel] [PATCH v7 0/9] Add limited support of VMware's hyper-call rpc Paolo Bonzini
2015-06-17 22:26 ` Don Slutz
2015-06-18 7:58 ` Michael S. Tsirkin
2015-06-18 8:33 ` Paolo Bonzini
2015-06-18 9:40 ` Michael S. Tsirkin
2015-06-18 8:33 ` Paolo Bonzini
2015-06-17 14:11 ` Michael S. Tsirkin
2015-06-17 14:13 ` Paolo Bonzini
2015-06-17 14:18 ` Michael S. Tsirkin
2015-06-17 14:27 ` Paolo Bonzini
2015-06-17 14:29 ` Michael S. Tsirkin
2015-06-17 16:17 ` Paolo Bonzini
2015-06-17 16:29 ` Michael S. Tsirkin
2015-06-17 16:48 ` Paolo Bonzini
2015-06-17 18:43 ` Michael S. Tsirkin
2015-06-17 19:15 ` Paolo Bonzini
2015-06-17 19:22 ` Michael S. Tsirkin
2015-06-17 19:24 ` Paolo Bonzini
2015-06-17 19:29 ` Michael S. Tsirkin
2015-06-17 17:03 ` Don Slutz
2015-06-17 17:14 ` Paolo Bonzini
2015-06-17 17:25 ` Paolo Bonzini
2015-06-17 17:34 ` Don Slutz
2015-06-17 18:58 ` Michael S. Tsirkin
2015-06-18 18:40 ` Don Slutz
2015-06-17 18:45 ` Michael S. Tsirkin
2015-06-17 18:45 ` Michael S. Tsirkin
2015-06-18 7:03 ` Gerd Hoffmann
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=557EF500.3090409@redhat.com \
--to=eblake@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=don.slutz@gmail.com \
--cc=dslutz@verizon.com \
--cc=lcapitulino@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).