From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4Whm-0007R6-VU for qemu-devel@nongnu.org; Mon, 15 Jun 2015 11:53:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4Whj-000635-Jo for qemu-devel@nongnu.org; Mon, 15 Jun 2015 11:53:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39135) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4Whj-00061c-Cj for qemu-devel@nongnu.org; Mon, 15 Jun 2015 11:53:43 -0400 Message-ID: <557EF500.3090409@redhat.com> Date: Mon, 15 Jun 2015 09:53:36 -0600 From: Eric Blake MIME-Version: 1.0 References: <1434117956-4929-1-git-send-email-dslutz@verizon.com> <1434117956-4929-7-git-send-email-dslutz@verizon.com> In-Reply-To: <1434117956-4929-7-git-send-email-dslutz@verizon.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="fXksRuwPGKeGoWs52gDQL3CiGfr86DLhX" Subject: Re: [Qemu-devel] [PATCH v7 6/9] vmport_rpc: Add QMP access to vmport_rpc object. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Don Slutz , qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Markus Armbruster , Luiz Capitulino , Don Slutz , Anthony Liguori , Paolo Bonzini , =?UTF-8?B?QW5kcmVhcyBGw6RyYmVy?= , Richard Henderson This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --fXksRuwPGKeGoWs52gDQL3CiGfr86DLhX Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/12/2015 08:05 AM, Don Slutz wrote: > This adds one new inject command: >=20 > inject-vmport-action >=20 > And three guest info commands: >=20 > vmport-guestinfo-set > vmport-guestinfo-get > query-vmport-guestinfo >=20 > More details in qmp-commands.hx >=20 > Signed-off-by: Don Slutz > CC: Don Slutz > --- > +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) > =20 > +static int get_qmp_guestinfo(VMPortRpcState *s, > + unsigned int a_key_len, const char *a_inf= o_key, > + unsigned int *a_value_len, void ** a_valu= e_data) No space after **. > +void qmp_inject_vmport_action(enum VmportAction action, Error **errp) > +{ > + int rc; > + > + switch (action) { > + case VMPORT_ACTION_REBOOT: > + rc =3D foreach_dynamic_vmport_rpc_device(vmport_rpc_find_send,= > + "OS_Reboot"); > + break; > + case VMPORT_ACTION_HALT: > + rc =3D foreach_dynamic_vmport_rpc_device(vmport_rpc_find_send,= > + "OS_Halt"); > + break; > + case VMPORT_ACTION_MAX: > + assert(action !=3D 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.")) =3D=3D 0) { > + key_value.key_data =3D (void *)(key + strlen("guestinfo.")); Cast here... > + key_value.key_len =3D strlen(key) - strlen("guestinfo."); > + } else { > + key_value.key_data =3D (void *)key; =2E..and here... > + key_value.key_len =3D strlen(key); > + } > + if (has_format && (format =3D=3D DATA_FORMAT_BASE64)) { > + gsize write_count; > + > + key_value.value_data =3D g_base64_decode(value, &write_count);= > + key_value.value_len =3D write_count; > + } else { > + key_value.value_data =3D (void *)value; =2E..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 =3D strlen(value); > + } > + > + rc =3D foreach_dynamic_vmport_rpc_device(find_set, (void *)&key_va= lue); 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.")) =3D=3D 0) { > + key_value.key_data =3D (void *)(key + strlen("guestinfo.")); > + key_value.key_len =3D strlen(key) - strlen("guestinfo."); > + } else { > + key_value.key_data =3D (void *)key; More casts that might be prevented with correct const in the callback struct. > + key_value.key_len =3D strlen(key); > + } > + > + rc =3D foreach_dynamic_vmport_rpc_device(find_get, (void *)&key_va= lue); Another spurious cast. > + if (rc) { > + convert_local_rc(errp, rc); > + return NULL; > + } > + > + ret_value =3D 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 =3D=3D DATA_FORMAT_BASE64)) { > + ret_value->value =3D 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. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --fXksRuwPGKeGoWs52gDQL3CiGfr86DLhX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVfvUAAAoJEKeha0olJ0NqKLUH/2IZ5XdHl9VaGLyHQC5HFS8x WDz/5Ftbn4IZYrvjbW2sXJ2BaE8tf2iPe/xanjDIQj57Vxd7Qt+QwK6xEgcBfN+S EpDjY0ooPW7OJ8IzG92XeqF4dtVl29I+klWH38l80f7mEvWUkjcIzGZYI/VfB7gu OtMJ3jVRjorgFwB+k7pG1KTe0DI8txZuSs7tejkPc8YwpsD0mf6VjIi3zy5ARv09 ecXdLdDZX30hl10bvIhWqrrP0ZzulXzOA91/e1RXlMLgpSrrVMo4jewmvzKWyoRf JAsenVoXyhAy8g4MPZyJNI0tYgxD07OaI9ic8uui1EBmt2oMHQsom8Yflw/Rckk= =4PtT -----END PGP SIGNATURE----- --fXksRuwPGKeGoWs52gDQL3CiGfr86DLhX--