From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489238645994134.81483325637714; Sat, 11 Mar 2017 05:24:05 -0800 (PST) Received: from localhost ([::1]:43387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh08-0001kn-9w for importer@patchew.org; Sat, 11 Mar 2017 08:24:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzC-0001jt-5t for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzA-0002GB-TX for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53968) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzA-0002Er-LY; Sat, 11 Mar 2017 08:23:04 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD11985542; Sat, 11 Mar 2017 13:23:04 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDN254028074; Sat, 11 Mar 2017 08:23:03 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:36 +0400 Message-Id: <20170311132256.22951-2-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 11 Mar 2017 13:23:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/21] qapi: add info comment for generated types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This may help to find where the origin of the type was declared in the json (when greping isn't easy enough). Signed-off-by: Marc-Andr=C3=A9 Lureau Cc: qemu-trivial@nongnu.org --- scripts/qapi.py | 11 +++++++++-- scripts/qapi-event.py | 4 +++- scripts/qapi-types.py | 17 +++++++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 53a44779d0..9504ebd8c7 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1874,15 +1874,22 @@ const char *const %(c_name)s_lookup[] =3D { return ret =20 =20 -def gen_enum(name, values, prefix=3DNone): +def gen_info_comment(info): + if info: + return "/* %s:%d */" % (info['file'], info['line']) + else: + return "" + +def gen_enum(info, name, values, prefix=3DNone): # append automatically generated _MAX value enum_values =3D values + ['_MAX'] =20 ret =3D mcgen(''' =20 +%(info)s typedef enum %(c_name)s { ''', - c_name=3Dc_name(name)) + c_name=3Dc_name(name), info=3Dgen_info_comment(info)) =20 i =3D 0 for value in enum_values: diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index f4eb7f85b1..ca90d6a5df 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -152,6 +152,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self.decl =3D None self.defn =3D None self._event_names =3D None + self.info =3D None =20 def visit_begin(self, schema): self.decl =3D '' @@ -159,7 +160,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self._event_names =3D [] =20 def visit_end(self): - self.decl +=3D gen_enum(event_enum_name, self._event_names) + self.decl +=3D gen_enum(self.info, event_enum_name, self._event_na= mes) self.defn +=3D gen_enum_lookup(event_enum_name, self._event_names) self._event_names =3D None =20 @@ -167,6 +168,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self.decl +=3D gen_event_send_decl(name, arg_type, boxed) self.defn +=3D gen_event_send(name, arg_type, boxed) self._event_names.append(name) + self.info =3D info =20 =20 (input_file, output_dir, do_c, do_h, prefix, dummy) =3D parse_command_line= () diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index dabc42e047..896749bf61 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -19,12 +19,13 @@ from qapi import * objects_seen =3D set() =20 =20 -def gen_fwd_object_or_array(name): +def gen_fwd_object_or_array(info, name): return mcgen(''' =20 +%(info)s typedef struct %(c_name)s %(c_name)s; ''', - c_name=3Dc_name(name)) + c_name=3Dc_name(name), info=3Dgen_info_comment(info)) =20 =20 def gen_array(name, element_type): @@ -199,22 +200,22 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): # Special case for our lone builtin enum type # TODO use something cleaner than existence of info if not info: - self._btin +=3D gen_enum(name, values, prefix) + self._btin +=3D gen_enum(info, name, values, prefix) if do_builtins: self.defn +=3D gen_enum_lookup(name, values, prefix) else: - self._fwdecl +=3D gen_enum(name, values, prefix) + self._fwdecl +=3D gen_enum(info, name, values, prefix) self.defn +=3D gen_enum_lookup(name, values, prefix) =20 def visit_array_type(self, name, info, element_type): if isinstance(element_type, QAPISchemaBuiltinType): - self._btin +=3D gen_fwd_object_or_array(name) + self._btin +=3D gen_fwd_object_or_array(info, name) self._btin +=3D gen_array(name, element_type) self._btin +=3D gen_type_cleanup_decl(name) if do_builtins: self.defn +=3D gen_type_cleanup(name) else: - self._fwdecl +=3D gen_fwd_object_or_array(name) + self._fwdecl +=3D gen_fwd_object_or_array(info, name) self.decl +=3D gen_array(name, element_type) self._gen_type_cleanup(name) =20 @@ -222,7 +223,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return - self._fwdecl +=3D gen_fwd_object_or_array(name) + self._fwdecl +=3D gen_fwd_object_or_array(info, name) self.decl +=3D gen_object(name, base, members, variants) if base and not base.is_implicit(): self.decl +=3D gen_upcast(name, base) @@ -233,7 +234,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._gen_type_cleanup(name) =20 def visit_alternate_type(self, name, info, variants): - self._fwdecl +=3D gen_fwd_object_or_array(name) + self._fwdecl +=3D gen_fwd_object_or_array(info, name) self.decl +=3D gen_object(name, None, [variants.tag_member], varia= nts) self._gen_type_cleanup(name) =20 --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489238648324240.583629523176; Sat, 11 Mar 2017 05:24:08 -0800 (PST) Received: from localhost ([::1]:43388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh0B-0001ms-3O for importer@patchew.org; Sat, 11 Mar 2017 08:24:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzF-0001lE-V2 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzE-0002LX-Vr for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzE-0002L6-Nh for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:08 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD4DC3B712; Sat, 11 Mar 2017 13:23:08 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDN6fP017652; Sat, 11 Mar 2017 08:23:07 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:37 +0400 Message-Id: <20170311132256.22951-3-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 11 Mar 2017 13:23:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/21] pci-host: use more specific type names X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the actual unsigned integer type name (this should't break since property type aren't directly accessed from outside). Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/pci-host/piix.c | 8 ++++---- hw/pci-host/q35.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index f9218aa952..9aed6225bf 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -279,19 +279,19 @@ static void i440fx_pcihost_initfn(Object *obj) memory_region_init_io(&s->data_mem, obj, &pci_host_data_le_ops, s, "pci-conf-data", 4); =20 - object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "int", + object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "uint32", i440fx_pcihost_get_pci_hole_start, NULL, NULL, NULL, NULL); =20 - object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_END, "int", + object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_END, "uint32", i440fx_pcihost_get_pci_hole_end, NULL, NULL, NULL, NULL); =20 - object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_START, "int", + object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_START, "uint64", i440fx_pcihost_get_pci_hole64_start, NULL, NULL, NULL, NULL); =20 - object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_END, "int", + object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_END, "uint64", i440fx_pcihost_get_pci_hole64_end, NULL, NULL, NULL, NULL); } diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 344f77b10c..5438be8253 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -176,23 +176,23 @@ static void q35_host_initfn(Object *obj) qdev_prop_set_uint32(DEVICE(&s->mch), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(&s->mch), "multifunction", false); =20 - object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "int", + object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "uint32", q35_host_get_pci_hole_start, NULL, NULL, NULL, NULL); =20 - object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_END, "int", + object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_END, "uint32", q35_host_get_pci_hole_end, NULL, NULL, NULL, NULL); =20 - object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_START, "int", + object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_START, "uint64", q35_host_get_pci_hole64_start, NULL, NULL, NULL, NULL); =20 - object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_END, "int", + object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_END, "uint64", q35_host_get_pci_hole64_end, NULL, NULL, NULL, NULL); =20 - object_property_add(obj, PCIE_HOST_MCFG_SIZE, "int", + object_property_add(obj, PCIE_HOST_MCFG_SIZE, "uint32", q35_host_get_mmcfg_size, NULL, NULL, NULL, NULL); =20 --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489238785261155.48634583248884; Sat, 11 Mar 2017 05:26:25 -0800 (PST) Received: from localhost ([::1]:43402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh2N-0003kp-Up for importer@patchew.org; Sat, 11 Mar 2017 08:26:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzM-0001qq-MB for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzI-0002Mw-O8 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzI-0002MZ-Hu; Sat, 11 Mar 2017 08:23:12 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B977D61D08; Sat, 11 Mar 2017 13:23:12 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNAJh028115; Sat, 11 Mar 2017 08:23:11 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:38 +0400 Message-Id: <20170311132256.22951-4-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 11 Mar 2017 13:23:12 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 03/21] object: fix potential leak in getters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If the property is not of the requested type, the getters will leak a QObject. Signed-off-by: Marc-Andr=C3=A9 Lureau Cc: qemu-trivial@nongnu.org Reviewed-by: Eric Blake --- qom/object.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qom/object.c b/qom/object.c index eb4bc924ff..c7b8079df6 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1122,7 +1122,7 @@ char *object_property_get_str(Object *obj, const char= *name, retval =3D g_strdup(qstring_get_str(qstring)); } =20 - QDECREF(qstring); + qobject_decref(ret); return retval; } =20 @@ -1183,7 +1183,7 @@ bool object_property_get_bool(Object *obj, const char= *name, retval =3D qbool_get_bool(qbool); } =20 - QDECREF(qbool); + qobject_decref(ret); return retval; } =20 @@ -1214,7 +1214,7 @@ int64_t object_property_get_int(Object *obj, const ch= ar *name, retval =3D qint_get_int(qint); } =20 - QDECREF(qint); + qobject_decref(ret); return retval; } =20 --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489238797983779.8321470288782; Sat, 11 Mar 2017 05:26:37 -0800 (PST) Received: from localhost ([::1]:43403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh2a-0003ug-Bv for importer@patchew.org; Sat, 11 Mar 2017 08:26:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzO-0001sG-PX for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzN-0002PW-2f for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44800) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzM-0002PH-PO for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:16 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F00AB4E4CD; Sat, 11 Mar 2017 13:23:16 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNEea017670; Sat, 11 Mar 2017 08:23:15 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:39 +0400 Message-Id: <20170311132256.22951-5-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 11 Mar 2017 13:23:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/21] qobject: add quint type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The type is not used at all yet. Add some tests to exercice it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/introspect.json | 2 +- scripts/qapi.py | 28 ++++++++------- include/qapi/qmp/quint.h | 25 ++++++++++++++ include/qapi/qmp/types.h | 1 + block/qapi.c | 5 +++ qobject/qobject.c | 1 + qobject/quint.c | 58 ++++++++++++++++++++++++++++= +++ tests/check-qint.c | 59 ++++++++++++++++++++++++++++= ++++ qobject/Makefile.objs | 2 +- tests/qapi-schema/comments.out | 2 +- tests/qapi-schema/empty.out | 2 +- tests/qapi-schema/event-case.out | 2 +- tests/qapi-schema/ident-with-escape.out | 2 +- tests/qapi-schema/include-relpath.out | 2 +- tests/qapi-schema/include-repetition.out | 2 +- tests/qapi-schema/include-simple.out | 2 +- tests/qapi-schema/indented-expr.out | 2 +- tests/qapi-schema/qapi-schema-test.out | 2 +- 18 files changed, 175 insertions(+), 24 deletions(-) create mode 100644 include/qapi/qmp/quint.h create mode 100644 qobject/quint.c diff --git a/qapi/introspect.json b/qapi/introspect.json index f6adc439bb..512a961ab3 100644 --- a/qapi/introspect.json +++ b/qapi/introspect.json @@ -125,7 +125,7 @@ # Since: 2.5 ## { 'enum': 'JSONType', - 'data': [ 'string', 'number', 'int', 'boolean', 'null', + 'data': [ 'string', 'number', 'int', 'uint', 'boolean', 'null', 'object', 'array', 'value' ] } =20 ## diff --git a/scripts/qapi.py b/scripts/qapi.py index 9504ebd8c7..80ecc821cb 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -28,11 +28,11 @@ builtin_types =3D { 'int16': 'QTYPE_QINT', 'int32': 'QTYPE_QINT', 'int64': 'QTYPE_QINT', - 'uint8': 'QTYPE_QINT', - 'uint16': 'QTYPE_QINT', - 'uint32': 'QTYPE_QINT', - 'uint64': 'QTYPE_QINT', - 'size': 'QTYPE_QINT', + 'uint8': 'QTYPE_QUINT', + 'uint16': 'QTYPE_QUINT', + 'uint32': 'QTYPE_QUINT', + 'uint64': 'QTYPE_QUINT', + 'size': 'QTYPE_QUINT', 'any': None, # any QType possible, actually 'QType': 'QTYPE_QSTRING', } @@ -1093,6 +1093,7 @@ class QAPISchemaType(QAPISchemaEntity): 'string': 'QTYPE_QSTRING', 'number': 'QTYPE_QFLOAT', 'int': 'QTYPE_QINT', + 'uint': 'QTYPE_QUINT', 'boolean': 'QTYPE_QBOOL', 'object': 'QTYPE_QDICT' } @@ -1103,8 +1104,8 @@ class QAPISchemaBuiltinType(QAPISchemaType): def __init__(self, name, json_type, c_type): QAPISchemaType.__init__(self, name, None) assert not c_type or isinstance(c_type, str) - assert json_type in ('string', 'number', 'int', 'boolean', 'null', - 'value') + assert json_type in ('string', 'number', 'int', 'uint', + 'boolean', 'null', 'value') self._json_type_name =3D json_type self._c_type_name =3D c_type =20 @@ -1519,18 +1520,19 @@ class QAPISchema(object): ('int16', 'int', 'int16_t'), ('int32', 'int', 'int32_t'), ('int64', 'int', 'int64_t'), - ('uint8', 'int', 'uint8_t'), - ('uint16', 'int', 'uint16_t'), - ('uint32', 'int', 'uint32_t'), - ('uint64', 'int', 'uint64_t'), - ('size', 'int', 'uint64_t'), + ('uint8', 'uint', 'uint8_t'), + ('uint16', 'uint', 'uint16_t'), + ('uint32', 'uint', 'uint32_t'), + ('uint64', 'uint', 'uint64_t'), + ('size', 'uint', 'uint64_t'), ('bool', 'boolean', 'bool'), ('any', 'value', 'QObject' + pointer_suffix)]: self._def_builtin_type(*t) self.the_empty_object_type =3D QAPISchemaObjectType('q_empty', Non= e, None, [], None) self._def_entity(self.the_empty_object_type) - qtype_values =3D self._make_enum_members(['none', 'qnull', 'qint', + qtype_values =3D self._make_enum_members(['none', 'qnull', + 'qint', 'quint', 'qstring', 'qdict', 'qlist= ', 'qfloat', 'qbool']) self._def_entity(QAPISchemaEnumType('QType', None, qtype_values, diff --git a/include/qapi/qmp/quint.h b/include/qapi/qmp/quint.h new file mode 100644 index 0000000000..5b920ece5d --- /dev/null +++ b/include/qapi/qmp/quint.h @@ -0,0 +1,25 @@ +/* + * QUInt Module + * + * Copyright (C) 2017 Red Hat Inc. + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. + * See the COPYING.LIB file in the top-level directory. + */ + +#ifndef QUINT_H +#define QUINT_H + +#include "qapi/qmp/qobject.h" + +typedef struct QUInt { + QObject base; + uint64_t value; +} QUInt; + +QUInt *quint_from_uint(uint64_t value); +uint64_t quint_get_uint(const QUInt *qi); +QUInt *qobject_to_quint(const QObject *obj); +void quint_destroy_obj(QObject *obj); + +#endif /* QUINT_H */ diff --git a/include/qapi/qmp/types.h b/include/qapi/qmp/types.h index 27cfbd84e5..99a60f75d0 100644 --- a/include/qapi/qmp/types.h +++ b/include/qapi/qmp/types.h @@ -15,6 +15,7 @@ =20 #include "qapi/qmp/qobject.h" #include "qapi/qmp/qint.h" +#include "qapi/qmp/quint.h" #include "qapi/qmp/qfloat.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qstring.h" diff --git a/block/qapi.c b/block/qapi.c index a40922ea26..6261a49b4d 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -600,6 +600,11 @@ static void dump_qobject(fprintf_function func_fprintf= , void *f, func_fprintf(f, "%" PRId64, qint_get_int(value)); break; } + case QTYPE_QUINT: { + QUInt *value =3D qobject_to_quint(obj); + func_fprintf(f, "%" PRIu64, quint_get_uint(value)); + break; + } case QTYPE_QSTRING: { QString *value =3D qobject_to_qstring(obj); func_fprintf(f, "%s", qstring_get_str(value)); diff --git a/qobject/qobject.c b/qobject/qobject.c index fe4fa10989..9bdb5e5947 100644 --- a/qobject/qobject.c +++ b/qobject/qobject.c @@ -15,6 +15,7 @@ static void (*qdestroy[QTYPE__MAX])(QObject *) =3D { [QTYPE_NONE] =3D NULL, /* No such object exists */ [QTYPE_QNULL] =3D NULL, /* qnull_ is indestructible */ [QTYPE_QINT] =3D qint_destroy_obj, + [QTYPE_QUINT] =3D quint_destroy_obj, [QTYPE_QSTRING] =3D qstring_destroy_obj, [QTYPE_QDICT] =3D qdict_destroy_obj, [QTYPE_QLIST] =3D qlist_destroy_obj, diff --git a/qobject/quint.c b/qobject/quint.c new file mode 100644 index 0000000000..e3a7ac37c4 --- /dev/null +++ b/qobject/quint.c @@ -0,0 +1,58 @@ +/* + * QUInt Module + * + * Copyright (C) 2017 Red Hat Inc. + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. + * See the COPYING.LIB file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/qmp/quint.h" +#include "qapi/qmp/qobject.h" +#include "qemu-common.h" + +/** + * quint_from_uint(): Create a new QUInt from an uint64_t + * + * Return strong reference. + */ +QUInt *quint_from_uint(uint64_t value) +{ + QUInt *qi; + + qi =3D g_malloc(sizeof(*qi)); + qobject_init(QOBJECT(qi), QTYPE_QUINT); + qi->value =3D value; + + return qi; +} + +/** + * quint_get_int(): Get the stored integer + */ +uint64_t quint_get_uint(const QUInt *qi) +{ + return qi->value; +} + +/** + * qobject_to_quint(): Convert a QObject into a QUInt + */ +QUInt *qobject_to_quint(const QObject *obj) +{ + if (!obj || qobject_type(obj) !=3D QTYPE_QUINT) { + return NULL; + } + return container_of(obj, QUInt, base); +} + +/** + * quint_destroy_obj(): Free all memory allocated by a + * QUInt object + */ +void quint_destroy_obj(QObject *obj) +{ + assert(obj !=3D NULL); + g_free(qobject_to_quint(obj)); +} diff --git a/tests/check-qint.c b/tests/check-qint.c index b6e4555115..603aa1aa92 100644 --- a/tests/check-qint.c +++ b/tests/check-qint.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" =20 #include "qapi/qmp/qint.h" +#include "qapi/qmp/quint.h" #include "qemu-common.h" =20 /* @@ -73,6 +74,58 @@ static void qobject_to_qint_test(void) QDECREF(qi); } =20 +static void quint_from_uint_test(void) +{ + QUInt *qu; + const unsigned value =3D -42; + + qu =3D quint_from_uint(value); + g_assert(qu !=3D NULL); + g_assert(qu->value =3D=3D value); + g_assert(qu->base.refcnt =3D=3D 1); + g_assert(qobject_type(QOBJECT(qu)) =3D=3D QTYPE_QUINT); + + g_free(qu); +} + +static void quint_destroy_test(void) +{ + QUInt *qu =3D quint_from_uint(0); + QDECREF(qu); +} + +static void quint_from_uint64_test(void) +{ + QUInt *qu; + const uint64_t value =3D 0x1234567890abcdefLL; + + qu =3D quint_from_uint(value); + g_assert((uint64_t) qu->value =3D=3D value); + + QDECREF(qu); +} + +static void quint_get_uint_test(void) +{ + QUInt *qu; + const unsigned value =3D 123456; + + qu =3D quint_from_uint(value); + g_assert(quint_get_uint(qu) =3D=3D value); + + QDECREF(qu); +} + +static void qobject_to_quint_test(void) +{ + QUInt *qu; + + qu =3D quint_from_uint(0); + g_assert(qobject_to_quint(QOBJECT(qu)) =3D=3D qu); + + QDECREF(qu); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -83,5 +136,11 @@ int main(int argc, char **argv) g_test_add_func("/public/get_int", qint_get_int_test); g_test_add_func("/public/to_qint", qobject_to_qint_test); =20 + g_test_add_func("/public/from_uint", quint_from_uint_test); + g_test_add_func("/public/uint_destroy", quint_destroy_test); + g_test_add_func("/public/from_uint64", quint_from_uint64_test); + g_test_add_func("/public/get_uint", quint_get_uint_test); + g_test_add_func("/public/to_quint", qobject_to_quint_test); + return g_test_run(); } diff --git a/qobject/Makefile.objs b/qobject/Makefile.objs index bed55084bb..1f7b95552f 100644 --- a/qobject/Makefile.objs +++ b/qobject/Makefile.objs @@ -1,2 +1,2 @@ -util-obj-y =3D qnull.o qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o +util-obj-y =3D qnull.o qint.o quint.o qstring.o qdict.o qlist.o qfloat.o q= bool.o util-obj-y +=3D qjson.o qobject.o json-lexer.o json-streamer.o json-parser= .o diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out index a962fb2d2e..42ea87a1a1 100644 --- a/tests/qapi-schema/comments.out +++ b/tests/qapi-schema/comments.out @@ -1,4 +1,4 @@ -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat'= , 'qbool'] +enum QType ['none', 'qnull', 'qint', 'quint', 'qstring', 'qdict', 'qlist',= 'qfloat', 'qbool'] prefix QTYPE enum Status ['good', 'bad', 'ugly'] object q_empty diff --git a/tests/qapi-schema/empty.out b/tests/qapi-schema/empty.out index 8a5b034424..5dcccb1d55 100644 --- a/tests/qapi-schema/empty.out +++ b/tests/qapi-schema/empty.out @@ -1,3 +1,3 @@ -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat'= , 'qbool'] +enum QType ['none', 'qnull', 'qint', 'quint', 'qstring', 'qdict', 'qlist',= 'qfloat', 'qbool'] prefix QTYPE object q_empty diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-cas= e.out index 2865714ad5..3464bd30f6 100644 --- a/tests/qapi-schema/event-case.out +++ b/tests/qapi-schema/event-case.out @@ -1,4 +1,4 @@ -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat'= , 'qbool'] +enum QType ['none', 'qnull', 'qint', 'quint', 'qstring', 'qdict', 'qlist',= 'qfloat', 'qbool'] prefix QTYPE event oops None boxed=3DFalse diff --git a/tests/qapi-schema/ident-with-escape.out b/tests/qapi-schema/id= ent-with-escape.out index 69fc908e68..a81ef8cd34 100644 --- a/tests/qapi-schema/ident-with-escape.out +++ b/tests/qapi-schema/ident-with-escape.out @@ -1,4 +1,4 @@ -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat'= , 'qbool'] +enum QType ['none', 'qnull', 'qint', 'quint', 'qstring', 'qdict', 'qlist',= 'qfloat', 'qbool'] prefix QTYPE command fooA q_obj_fooA-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse diff --git a/tests/qapi-schema/include-relpath.out b/tests/qapi-schema/incl= ude-relpath.out index a962fb2d2e..42ea87a1a1 100644 --- a/tests/qapi-schema/include-relpath.out +++ b/tests/qapi-schema/include-relpath.out @@ -1,4 +1,4 @@ -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat'= , 'qbool'] +enum QType ['none', 'qnull', 'qint', 'quint', 'qstring', 'qdict', 'qlist',= 'qfloat', 'qbool'] prefix QTYPE enum Status ['good', 'bad', 'ugly'] object q_empty diff --git a/tests/qapi-schema/include-repetition.out b/tests/qapi-schema/i= nclude-repetition.out index a962fb2d2e..42ea87a1a1 100644 --- a/tests/qapi-schema/include-repetition.out +++ b/tests/qapi-schema/include-repetition.out @@ -1,4 +1,4 @@ -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat'= , 'qbool'] +enum QType ['none', 'qnull', 'qint', 'quint', 'qstring', 'qdict', 'qlist',= 'qfloat', 'qbool'] prefix QTYPE enum Status ['good', 'bad', 'ugly'] object q_empty diff --git a/tests/qapi-schema/include-simple.out b/tests/qapi-schema/inclu= de-simple.out index a962fb2d2e..42ea87a1a1 100644 --- a/tests/qapi-schema/include-simple.out +++ b/tests/qapi-schema/include-simple.out @@ -1,4 +1,4 @@ -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat'= , 'qbool'] +enum QType ['none', 'qnull', 'qint', 'quint', 'qstring', 'qdict', 'qlist',= 'qfloat', 'qbool'] prefix QTYPE enum Status ['good', 'bad', 'ugly'] object q_empty diff --git a/tests/qapi-schema/indented-expr.out b/tests/qapi-schema/indent= ed-expr.out index 285d052257..b158bcd6eb 100644 --- a/tests/qapi-schema/indented-expr.out +++ b/tests/qapi-schema/indented-expr.out @@ -1,4 +1,4 @@ -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat'= , 'qbool'] +enum QType ['none', 'qnull', 'qint', 'quint', 'qstring', 'qdict', 'qlist',= 'qfloat', 'qbool'] prefix QTYPE command eins None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index bc8d496ff4..690460658c 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -54,7 +54,7 @@ object NestedEnumsOne member enum4: EnumOne optional=3DTrue enum QEnumTwo ['value1', 'value2'] prefix QENUM_TWO -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat'= , 'qbool'] +enum QType ['none', 'qnull', 'qint', 'quint', 'qstring', 'qdict', 'qlist',= 'qfloat', 'qbool'] prefix QTYPE object TestStruct member integer: int optional=3DFalse --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489238991455983.330489950156; Sat, 11 Mar 2017 05:29:51 -0800 (PST) Received: from localhost ([::1]:43416 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh5g-0006i5-V4 for importer@patchew.org; Sat, 11 Mar 2017 08:29:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzS-0001v1-1i for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzQ-0002Rc-Ox for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzQ-0002RB-Gp for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:20 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4A554E4C6; Sat, 11 Mar 2017 13:23:20 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNIwC002021; Sat, 11 Mar 2017 08:23:19 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:40 +0400 Message-Id: <20170311132256.22951-6-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 11 Mar 2017 13:23:20 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/21] qapi: update the qobject visitor to use QUInt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-visit.py | 3 ++- qapi/qobject-input-visitor.c | 30 ++++++++++++++++++++++++------ qapi/qobject-output-visitor.c | 3 +-- tests/test-qobject-input-visitor.c | 15 +++++++++++++++ tests/test-qobject-output-visitor.c | 19 +++++++++++++++---- 5 files changed, 57 insertions(+), 13 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 330b9f321b..532f929e18 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -165,7 +165,8 @@ def gen_visit_alternate(name, variants): promote_int =3D 'true' ret =3D '' for var in variants.variants: - if var.type.alternate_qtype() =3D=3D 'QTYPE_QINT': + if var.type.alternate_qtype() =3D=3D 'QTYPE_QINT' \ + or var.type.alternate_qtype() =3D=3D 'QTYPE_QUINT': promote_int =3D 'false' =20 ret +=3D mcgen(''' diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 865e948ac0..41a825b06b 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -21,6 +21,7 @@ #include "qapi/qmp/qjson.h" #include "qapi/qmp/types.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qemu/cutils.h" #include "qemu/option.h" =20 @@ -349,7 +350,8 @@ static void qobject_input_start_alternate(Visitor *v, c= onst char *name, } *obj =3D g_malloc0(size); (*obj)->type =3D qobject_type(qobj); - if (promote_int && (*obj)->type =3D=3D QTYPE_QINT) { + if (promote_int && + ((*obj)->type =3D=3D QTYPE_QINT || (*obj)->type =3D=3D QTYPE_QUINT= )) { (*obj)->type =3D QTYPE_QFLOAT; } } @@ -395,22 +397,38 @@ static void qobject_input_type_int64_keyval(Visitor *= v, const char *name, static void qobject_input_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { - /* FIXME: qobject_to_qint mishandles values over INT64_MAX */ QObjectInputVisitor *qiv =3D to_qiv(v); QObject *qobj =3D qobject_input_get_object(qiv, name, true, errp); + QUInt *quint; QInt *qint; + int64_t val; =20 if (!qobj) { return; } + + quint =3D qobject_to_quint(qobj); + if (quint) { + *obj =3D quint_get_uint(quint); + return; + } + qint =3D qobject_to_qint(qobj); if (!qint) { - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, - full_name(qiv, name), "integer"); - return; + goto error; } =20 - *obj =3D qint_get_int(qint); + val =3D qint_get_int(qint); + if (val < 0) { + goto error; + } + + *obj =3D val; + return; + +error: + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, + full_name(qiv, name), "unsigned integer"); } =20 static void qobject_input_type_uint64_keyval(Visitor *v, const char *name, diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index 871127079d..7066b3b59b 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -150,9 +150,8 @@ static void qobject_output_type_int64(Visitor *v, const= char *name, static void qobject_output_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { - /* FIXME values larger than INT64_MAX become negative */ QObjectOutputVisitor *qov =3D to_qov(v); - qobject_output_add(qov, name, qint_from_int(*obj)); + qobject_output_add(qov, name, quint_from_uint(*obj)); } =20 static void qobject_output_type_bool(Visitor *v, const char *name, bool *o= bj, diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index 6eb48fee7b..011366a65b 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -170,6 +170,19 @@ static void test_visitor_in_int_str_fail(TestInputVisi= torData *data, error_free_or_abort(&err); } =20 +static void test_visitor_in_uint(TestInputVisitorData *data, + const void *unused) +{ + uint64_t res =3D 0; + uint64_t value =3D G_MAXUINT64; + Visitor *v; + + v =3D visitor_input_test_init(data, "%" PRIu64, value); + + visit_type_uint64(v, NULL, &res, &error_abort); + g_assert_cmpint(res, =3D=3D, value); +} + static void test_visitor_in_bool(TestInputVisitorData *data, const void *unused) { @@ -1233,6 +1246,8 @@ int main(int argc, char **argv) NULL, test_visitor_in_int_str_keyval); input_visitor_test_add("/visitor/input/int_str_fail", NULL, test_visitor_in_int_str_fail); + input_visitor_test_add("/visitor/input/uint", + NULL, test_visitor_in_uint); input_visitor_test_add("/visitor/input/bool", NULL, test_visitor_in_bool); input_visitor_test_add("/visitor/input/bool_keyval", diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 500b452d98..047c6b5c6c 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -597,14 +597,25 @@ static void check_native_list(QObject *qobj, qlist =3D qlist_copy(qobject_to_qlist(qdict_get(qdict, "data"))); =20 switch (kind) { - case USER_DEF_NATIVE_LIST_UNION_KIND_S8: - case USER_DEF_NATIVE_LIST_UNION_KIND_S16: - case USER_DEF_NATIVE_LIST_UNION_KIND_S32: - case USER_DEF_NATIVE_LIST_UNION_KIND_S64: case USER_DEF_NATIVE_LIST_UNION_KIND_U8: case USER_DEF_NATIVE_LIST_UNION_KIND_U16: case USER_DEF_NATIVE_LIST_UNION_KIND_U32: case USER_DEF_NATIVE_LIST_UNION_KIND_U64: + for (i =3D 0; i < 32; i++) { + QObject *tmp; + QUInt *qvalue; + tmp =3D qlist_peek(qlist); + g_assert(tmp); + qvalue =3D qobject_to_quint(tmp); + g_assert_cmpint(quint_get_uint(qvalue), =3D=3D, i); + qobject_decref(qlist_pop(qlist)); + } + break; + + case USER_DEF_NATIVE_LIST_UNION_KIND_S8: + case USER_DEF_NATIVE_LIST_UNION_KIND_S16: + case USER_DEF_NATIVE_LIST_UNION_KIND_S32: + case USER_DEF_NATIVE_LIST_UNION_KIND_S64: /* all integer elements in JSON arrays get stored into QInts when * we convert to QObjects, so we can check them all in the same * fashion, so simply fall through here --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489238781710471.4632703155712; Sat, 11 Mar 2017 05:26:21 -0800 (PST) Received: from localhost ([::1]:43401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh2K-0003hb-7m for importer@patchew.org; Sat, 11 Mar 2017 08:26:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58608) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzW-0001yB-4X for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzU-0002Sk-AP for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40364) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzU-0002ST-1p for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:24 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FBF78FCEA; Sat, 11 Mar 2017 13:23:24 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B3D22D655; Sat, 11 Mar 2017 13:23:22 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:41 +0400 Message-Id: <20170311132256.22951-7-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 11 Mar 2017 13:23:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/21] json: learn to parse uint64 numbers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If the parsed number doesn't fit in a int64, try with a uint64 before falling back to double. Switch strtoll() usage to qemu_strtoi64() helper while at it. Add a few tests for large numbers. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qobject/json-lexer.c | 4 ++++ qobject/json-parser.c | 19 +++++++++++++++++-- qobject/qjson.c | 8 ++++++++ tests/check-qjson.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c index af4a75e05b..a0beb0b106 100644 --- a/qobject/json-lexer.c +++ b/qobject/json-lexer.c @@ -227,15 +227,18 @@ static const uint8_t json_lexer[][256] =3D { /* escape */ [IN_ESCAPE_LL] =3D { ['d'] =3D JSON_ESCAPE, + ['u'] =3D JSON_ESCAPE, }, =20 [IN_ESCAPE_L] =3D { ['d'] =3D JSON_ESCAPE, + ['u'] =3D JSON_ESCAPE, ['l'] =3D IN_ESCAPE_LL, }, =20 [IN_ESCAPE_I64] =3D { ['d'] =3D JSON_ESCAPE, + ['u'] =3D JSON_ESCAPE, }, =20 [IN_ESCAPE_I6] =3D { @@ -247,6 +250,7 @@ static const uint8_t json_lexer[][256] =3D { }, =20 [IN_ESCAPE] =3D { + ['u'] =3D JSON_ESCAPE, ['d'] =3D JSON_ESCAPE, ['i'] =3D JSON_ESCAPE, ['p'] =3D JSON_ESCAPE, diff --git a/qobject/json-parser.c b/qobject/json-parser.c index c18e48ab94..b39cb4d8d6 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -12,6 +12,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "qemu-common.h" #include "qapi/qmp/types.h" @@ -472,6 +473,13 @@ static QObject *parse_escape(JSONParserContext *ctxt, = va_list *ap) } else if (!strcmp(token->str, "%lld") || !strcmp(token->str, "%I64d")) { return QOBJECT(qint_from_int(va_arg(*ap, long long))); + } else if (!strcmp(token->str, "%u")) { + return QOBJECT(quint_from_uint(va_arg(*ap, unsigned int))); + } else if (!strcmp(token->str, "%lu")) { + return QOBJECT(quint_from_uint(va_arg(*ap, unsigned long))); + } else if (!strcmp(token->str, "%llu") || + !strcmp(token->str, "%I64u")) { + return QOBJECT(quint_from_uint(va_arg(*ap, unsigned long long))); } else if (!strcmp(token->str, "%s")) { return QOBJECT(qstring_from_str(va_arg(*ap, const char *))); } else if (!strcmp(token->str, "%f")) { @@ -504,14 +512,21 @@ static QObject *parse_literal(JSONParserContext *ctxt) * strtoll() indicates these instances by setting errno to ERANGE */ int64_t value; + uint64_t uvalue; =20 - errno =3D 0; /* strtoll doesn't set errno on success */ - value =3D strtoll(token->str, NULL, 10); + qemu_strtoi64(token->str, NULL, 10, &value); if (errno !=3D ERANGE) { return QOBJECT(qint_from_int(value)); } + + qemu_strtou64(token->str, NULL, 10, &uvalue); + if (errno !=3D ERANGE) { + return QOBJECT(quint_from_uint(uvalue)); + } + /* fall through to JSON_FLOAT */ } + case JSON_FLOAT: /* FIXME dependent on locale; a pervasive issue in QEMU */ /* FIXME our lexer matches RFC 7159 in forbidding Inf or NaN, diff --git a/qobject/qjson.c b/qobject/qjson.c index b2f3bfec53..6356cff594 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -140,6 +140,14 @@ static void to_json(const QObject *obj, QString *str, = int pretty, int indent) qstring_append(str, buffer); break; } + case QTYPE_QUINT: { + QUInt *val =3D qobject_to_quint(obj); + char buffer[1024]; + + snprintf(buffer, sizeof(buffer), "%" PRIu64, quint_get_uint(val)); + qstring_append(str, buffer); + break; + } case QTYPE_QSTRING: { QString *val =3D qobject_to_qstring(obj); const char *ptr; diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 963dd46f07..fd44cd6207 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -904,6 +904,33 @@ static void simple_number(void) } } =20 +static void large_number(void) +{ + const char *maxu64 =3D "18446744073709551615"; /* 2^64-1 */ + const char *gtu64 =3D "18446744073709551616"; /* 2^64 */ + QUInt *quint; + QFloat *qfloat; + QString *str; + + quint =3D qobject_to_quint(qobject_from_json(maxu64, &error_abort)); + g_assert(quint); + g_assert_cmpint(quint_get_uint(quint), =3D=3D, 18446744073709551615U); + + str =3D qobject_to_json(QOBJECT(quint)); + g_assert_cmpstr(qstring_get_str(str), =3D=3D, maxu64); + QDECREF(str); + QDECREF(quint); + + qfloat =3D qobject_to_qfloat(qobject_from_json(gtu64, &error_abort)); + g_assert(qfloat); + g_assert_cmpfloat(qfloat_get_double(qfloat), =3D=3D, 18446744073709551= 616.0); + + str =3D qobject_to_json(QOBJECT(qfloat)); + g_assert_cmpstr(qstring_get_str(str), =3D=3D, gtu64); + QDECREF(str); + QDECREF(qfloat); +} + static void float_number(void) { int i; @@ -1468,6 +1495,7 @@ int main(int argc, char **argv) g_test_add_func("/literals/string/vararg", vararg_string); =20 g_test_add_func("/literals/number/simple", simple_number); + g_test_add_func("/literals/number/large", large_number); g_test_add_func("/literals/number/float", float_number); g_test_add_func("/literals/number/vararg", vararg_number); =20 --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489238913335441.5553605069563; Sat, 11 Mar 2017 05:28:33 -0800 (PST) Received: from localhost ([::1]:43410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh4S-0005bo-2k for importer@patchew.org; Sat, 11 Mar 2017 08:28:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzZ-00021I-95 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzY-0002UA-8S for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzX-0002To-W5 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:28 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27BE93B712; Sat, 11 Mar 2017 13:23:28 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNPsU028161; Sat, 11 Mar 2017 08:23:27 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:42 +0400 Message-Id: <20170311132256.22951-8-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 11 Mar 2017 13:23:28 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/21] object: add uint property setter/getter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qom/object.h | 23 +++++++++++++++++++++++ qom/object.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index cd0f412ce9..abaeb8cf4e 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1094,6 +1094,29 @@ int64_t object_property_get_int(Object *obj, const c= har *name, Error **errp); =20 /** + * object_property_set_uint: + * @value: the value to be written to the property + * @name: the name of the property + * @errp: returns an error if this function fails + * + * Writes an unsigned integer value to a property. + */ +void object_property_set_uint(Object *obj, uint64_t value, + const char *name, Error **errp); + +/** + * object_property_get_uint: + * @obj: the object + * @name: the name of the property + * @errp: returns an error if this function fails + * + * Returns: the value of the property, converted to an unsigned integer, o= r 0 + * an error occurs (including when the property value is not an integer). + */ +uint64_t object_property_get_uint(Object *obj, const char *name, + Error **errp); + +/** * object_property_get_enum: * @obj: the object * @name: the name of the property diff --git a/qom/object.c b/qom/object.c index c7b8079df6..ca9d4137b3 100644 --- a/qom/object.c +++ b/qom/object.c @@ -28,6 +28,7 @@ #include "qapi/qmp/qobject.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qint.h" +#include "qapi/qmp/quint.h" #include "qapi/qmp/qstring.h" =20 #define MAX_INTERFACES 32 @@ -1218,6 +1219,37 @@ int64_t object_property_get_int(Object *obj, const c= har *name, return retval; } =20 +void object_property_set_uint(Object *obj, uint64_t value, + const char *name, Error **errp) +{ + QUInt *quint =3D quint_from_uint(value); + object_property_set_qobject(obj, QOBJECT(quint), name, errp); + + QDECREF(quint); +} + +uint64_t object_property_get_uint(Object *obj, const char *name, + Error **errp) +{ + QObject *ret =3D object_property_get_qobject(obj, name, errp); + QUInt *quint; + uint64_t retval; + + if (!ret) { + return 0; + } + quint =3D qobject_to_quint(ret); + if (!quint) { + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "uint"); + retval =3D 0; + } else { + retval =3D quint_get_uint(quint); + } + + qobject_decref(ret); + return retval; +} + typedef struct EnumProperty { const char * const *strings; int (*get)(Object *, Error **); --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489238684083125.06928712791228; Sat, 11 Mar 2017 05:24:44 -0800 (PST) Received: from localhost ([::1]:43390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh0k-0002Az-L6 for importer@patchew.org; Sat, 11 Mar 2017 08:24:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzg-00027M-9x for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzc-0002WJ-AZ for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54066) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzc-0002Vv-1n for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:32 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3ED3985542; Sat, 11 Mar 2017 13:23:32 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFDFA2D655; Sat, 11 Mar 2017 13:23:30 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:43 +0400 Message-Id: <20170311132256.22951-9-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 11 Mar 2017 13:23:32 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/21] qdev: use int and uint properties X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" So the correct QObject type is used. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/hw/qdev-core.h | 5 +++- include/hw/qdev-properties.h | 59 ++++++++++++++++++++++++++--------------= ---- hw/block/fdc.c | 54 ++++++++++++++++++++-------------------- hw/core/qdev-properties.c | 8 +++--- hw/core/qdev.c | 8 +++--- hw/net/e1000e.c | 14 +++++------ 6 files changed, 82 insertions(+), 66 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index b44b476765..218f83b4a1 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -239,7 +239,10 @@ struct Property { ptrdiff_t offset; uint8_t bitnr; QType qtype; - int64_t defval; + union { + int64_t i; + uint64_t u; + } defval; int arrayoffset; PropertyInfo *arrayinfo; int arrayfieldsize; diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 7ac315331a..96584354a7 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -37,22 +37,33 @@ extern PropertyInfo qdev_prop_arraylen; .offset =3D offsetof(_state, _field) \ + type_check(_type, typeof_field(_state, _field)), \ } -#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) = { \ + +#define DEFINE_PROP_INT(_name, _state, _field, _defval, _prop, _type) { \ .name =3D (_name), \ .info =3D &(_prop), \ .offset =3D offsetof(_state, _field) \ + type_check(_type,typeof_field(_state, _field)), \ .qtype =3D QTYPE_QINT, \ - .defval =3D (_type)_defval, \ + .defval.i =3D (_type)_defval, \ } -#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \ - .name =3D (_name), \ - .info =3D &(qdev_prop_bit), \ - .bitnr =3D (_bit), \ - .offset =3D offsetof(_state, _field) \ - + type_check(uint32_t,typeof_field(_state, _field)), \ - .qtype =3D QTYPE_QBOOL, \ - .defval =3D (bool)_defval, \ + +#define DEFINE_PROP_UINT(_name, _state, _field, _defval, _prop, _type) { \ + .name =3D (_name), \ + .info =3D &(_prop), \ + .offset =3D offsetof(_state, _field) \ + + type_check(_type, typeof_field(_state, _field)), \ + .qtype =3D QTYPE_QUINT, \ + .defval.u =3D (_type)_defval, \ + } + +#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \ + .name =3D (_name), \ + .info =3D &(qdev_prop_bit), \ + .bitnr =3D (_bit), \ + .offset =3D offsetof(_state, _field) \ + + type_check(uint32_t, typeof_field(_state, _field)), \ + .qtype =3D QTYPE_QBOOL, \ + .defval.i =3D (bool)_defval, \ } #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \ .name =3D (_name), \ @@ -61,7 +72,7 @@ extern PropertyInfo qdev_prop_arraylen; .offset =3D offsetof(_state, _field) \ + type_check(uint64_t, typeof_field(_state, _field)), \ .qtype =3D QTYPE_QBOOL, \ - .defval =3D (bool)_defval, \ + .defval.i =3D (bool)_defval , \ } =20 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \ @@ -70,7 +81,7 @@ extern PropertyInfo qdev_prop_arraylen; .offset =3D offsetof(_state, _field) \ + type_check(bool, typeof_field(_state, _field)), \ .qtype =3D QTYPE_QBOOL, \ - .defval =3D (bool)_defval, \ + .defval.i =3D (bool)_defval, \ } =20 #define PROP_ARRAY_LEN_PREFIX "len-" @@ -112,19 +123,19 @@ extern PropertyInfo qdev_prop_arraylen; } =20 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) + DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) + DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) + DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) #define DEFINE_PROP_INT32(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t) + DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_int32, int32_t) #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) + DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) #define DEFINE_PROP_SIZE(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_size, uint64_t) + DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_size, uint64_t) #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t) + DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t) =20 /* * Please avoid pointer properties. If you must use them, you must @@ -158,17 +169,17 @@ extern PropertyInfo qdev_prop_arraylen; #define DEFINE_PROP_MACADDR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto) + DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto) #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ + DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ LostTickPolicy) #define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \ + DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \ BlockdevOnError) #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int) + DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int) #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t) + DEFINE_PROP_UINT(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t) #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddre= ss) =20 diff --git a/hw/block/fdc.c b/hw/block/fdc.c index a328693d15..df11abe91a 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -511,9 +511,9 @@ typedef struct FloppyDrive { static Property floppy_drive_properties[] =3D { DEFINE_PROP_UINT32("unit", FloppyDrive, unit, -1), DEFINE_BLOCK_PROPERTIES(FloppyDrive, conf), - DEFINE_PROP_DEFAULT("drive-type", FloppyDrive, type, - FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, - FloppyDriveType), + DEFINE_PROP_INT("drive-type", FloppyDrive, type, + FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, + FloppyDriveType), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -2805,15 +2805,15 @@ static Property isa_fdc_properties[] =3D { DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.qdev_for_drives[1].blk= ), DEFINE_PROP_BIT("check_media_rate", FDCtrlISABus, state.check_media_ra= te, 0, true), - DEFINE_PROP_DEFAULT("fdtypeA", FDCtrlISABus, state.qdev_for_drives[0].= type, - FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, - FloppyDriveType), - DEFINE_PROP_DEFAULT("fdtypeB", FDCtrlISABus, state.qdev_for_drives[1].= type, - FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, - FloppyDriveType), - DEFINE_PROP_DEFAULT("fallback", FDCtrlISABus, state.fallback, - FLOPPY_DRIVE_TYPE_288, qdev_prop_fdc_drive_type, - FloppyDriveType), + DEFINE_PROP_INT("fdtypeA", FDCtrlISABus, state.qdev_for_drives[0].type, + FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, + FloppyDriveType), + DEFINE_PROP_INT("fdtypeB", FDCtrlISABus, state.qdev_for_drives[1].type, + FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, + FloppyDriveType), + DEFINE_PROP_INT("fallback", FDCtrlISABus, state.fallback, + FLOPPY_DRIVE_TYPE_288, qdev_prop_fdc_drive_type, + FloppyDriveType), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -2862,15 +2862,15 @@ static const VMStateDescription vmstate_sysbus_fdc = =3D{ static Property sysbus_fdc_properties[] =3D { DEFINE_PROP_DRIVE("driveA", FDCtrlSysBus, state.qdev_for_drives[0].blk= ), DEFINE_PROP_DRIVE("driveB", FDCtrlSysBus, state.qdev_for_drives[1].blk= ), - DEFINE_PROP_DEFAULT("fdtypeA", FDCtrlSysBus, state.qdev_for_drives[0].= type, - FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, - FloppyDriveType), - DEFINE_PROP_DEFAULT("fdtypeB", FDCtrlSysBus, state.qdev_for_drives[1].= type, - FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, - FloppyDriveType), - DEFINE_PROP_DEFAULT("fallback", FDCtrlISABus, state.fallback, - FLOPPY_DRIVE_TYPE_144, qdev_prop_fdc_drive_type, - FloppyDriveType), + DEFINE_PROP_INT("fdtypeA", FDCtrlSysBus, state.qdev_for_drives[0].type, + FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, + FloppyDriveType), + DEFINE_PROP_INT("fdtypeB", FDCtrlSysBus, state.qdev_for_drives[1].type, + FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, + FloppyDriveType), + DEFINE_PROP_INT("fallback", FDCtrlISABus, state.fallback, + FLOPPY_DRIVE_TYPE_144, qdev_prop_fdc_drive_type, + FloppyDriveType), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -2891,12 +2891,12 @@ static const TypeInfo sysbus_fdc_info =3D { =20 static Property sun4m_fdc_properties[] =3D { DEFINE_PROP_DRIVE("drive", FDCtrlSysBus, state.qdev_for_drives[0].blk), - DEFINE_PROP_DEFAULT("fdtype", FDCtrlSysBus, state.qdev_for_drives[0].t= ype, - FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, - FloppyDriveType), - DEFINE_PROP_DEFAULT("fallback", FDCtrlISABus, state.fallback, - FLOPPY_DRIVE_TYPE_144, qdev_prop_fdc_drive_type, - FloppyDriveType), + DEFINE_PROP_INT("fdtype", FDCtrlSysBus, state.qdev_for_drives[0].type, + FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, + FloppyDriveType), + DEFINE_PROP_INT("fallback", FDCtrlISABus, state.fallback, + FLOPPY_DRIVE_TYPE_144, qdev_prop_fdc_drive_type, + FloppyDriveType), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 6ab4265eb4..fc2bf73369 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -982,17 +982,17 @@ void qdev_prop_set_bit(DeviceState *dev, const char *= name, bool value) =20 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value) { - object_property_set_int(OBJECT(dev), value, name, &error_abort); + object_property_set_uint(OBJECT(dev), value, name, &error_abort); } =20 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t val= ue) { - object_property_set_int(OBJECT(dev), value, name, &error_abort); + object_property_set_uint(OBJECT(dev), value, name, &error_abort); } =20 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t val= ue) { - object_property_set_int(OBJECT(dev), value, name, &error_abort); + object_property_set_uint(OBJECT(dev), value, name, &error_abort); } =20 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value) @@ -1002,7 +1002,7 @@ void qdev_prop_set_int32(DeviceState *dev, const char= *name, int32_t value) =20 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t val= ue) { - object_property_set_int(OBJECT(dev), value, name, &error_abort); + object_property_set_uint(OBJECT(dev), value, name, &error_abort); } =20 void qdev_prop_set_string(DeviceState *dev, const char *name, const char *= value) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 1e7fb33246..0c47d92a1f 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -833,12 +833,14 @@ void qdev_property_add_static(DeviceState *dev, Prope= rty *prop, } =20 if (prop->qtype =3D=3D QTYPE_QBOOL) { - object_property_set_bool(obj, prop->defval, prop->name, &error_abo= rt); + object_property_set_bool(obj, prop->defval.i, prop->name, &error_a= bort); } else if (prop->info->enum_table) { - object_property_set_str(obj, prop->info->enum_table[prop->defval], + object_property_set_str(obj, prop->info->enum_table[prop->defval.i= ], prop->name, &error_abort); } else if (prop->qtype =3D=3D QTYPE_QINT) { - object_property_set_int(obj, prop->defval, prop->name, &error_abor= t); + object_property_set_int(obj, prop->defval.i, prop->name, &error_ab= ort); + } else if (prop->qtype =3D=3D QTYPE_QUINT) { + object_property_set_uint(obj, prop->defval.u, prop->name, &error_a= bort); } } =20 diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c index b0f429b8e5..5b50f1853a 100644 --- a/hw/net/e1000e.c +++ b/hw/net/e1000e.c @@ -645,13 +645,13 @@ static PropertyInfo e1000e_prop_disable_vnet, =20 static Property e1000e_properties[] =3D { DEFINE_NIC_PROPERTIES(E1000EState, conf), - DEFINE_PROP_DEFAULT("disable_vnet_hdr", E1000EState, disable_vnet, fal= se, - e1000e_prop_disable_vnet, bool), - DEFINE_PROP_DEFAULT("subsys_ven", E1000EState, subsys_ven, - PCI_VENDOR_ID_INTEL, - e1000e_prop_subsys_ven, uint16_t), - DEFINE_PROP_DEFAULT("subsys", E1000EState, subsys, 0, - e1000e_prop_subsys, uint16_t), + DEFINE_PROP_INT("disable_vnet_hdr", E1000EState, disable_vnet, false, + e1000e_prop_disable_vnet, bool), + DEFINE_PROP_INT("subsys_ven", E1000EState, subsys_ven, + PCI_VENDOR_ID_INTEL, + e1000e_prop_subsys_ven, uint16_t), + DEFINE_PROP_INT("subsys", E1000EState, subsys, 0, + e1000e_prop_subsys, uint16_t), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239135731690.5262820233107; Sat, 11 Mar 2017 05:32:15 -0800 (PST) Received: from localhost ([::1]:43433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh82-0000HD-DE for importer@patchew.org; Sat, 11 Mar 2017 08:32:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzg-00027t-SV for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzf-0002Yj-Om for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33168) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzf-0002Y8-GB for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:35 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE420811A7; Sat, 11 Mar 2017 13:23:35 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id C996E2D655; Sat, 11 Mar 2017 13:23:34 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:44 +0400 Message-Id: <20170311132256.22951-10-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 11 Mar 2017 13:23:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/21] qdev: use appropriate type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/i386/acpi-build.c | 15 ++++++++------- hw/pci-host/gpex.c | 2 +- hw/pci-host/q35.c | 2 +- hw/pci-host/xilinx-pcie.c | 2 +- target/i386/cpu.c | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 2073108577..76bff18e3f 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -58,6 +58,7 @@ #include "hw/acpi/aml-build.h" =20 #include "qapi/qmp/qint.h" +#include "qapi/qmp/quint.h" #include "qom/qom-qobject.h" #include "hw/i386/amd_iommu.h" #include "hw/i386/intel_iommu.h" @@ -150,21 +151,21 @@ static void acpi_get_pm_info(AcpiPmInfo *pm) /* Fill in optional s3/s4 related properties */ o =3D object_property_get_qobject(obj, ACPI_PM_PROP_S3_DISABLED, NULL); if (o) { - pm->s3_disabled =3D qint_get_int(qobject_to_qint(o)); + pm->s3_disabled =3D quint_get_uint(qobject_to_quint(o)); } else { pm->s3_disabled =3D false; } qobject_decref(o); o =3D object_property_get_qobject(obj, ACPI_PM_PROP_S4_DISABLED, NULL); if (o) { - pm->s4_disabled =3D qint_get_int(qobject_to_qint(o)); + pm->s4_disabled =3D quint_get_uint(qobject_to_quint(o)); } else { pm->s4_disabled =3D false; } qobject_decref(o); o =3D object_property_get_qobject(obj, ACPI_PM_PROP_S4_VAL, NULL); if (o) { - pm->s4_val =3D qint_get_int(qobject_to_qint(o)); + pm->s4_val =3D quint_get_uint(qobject_to_quint(o)); } else { pm->s4_val =3D false; } @@ -500,7 +501,7 @@ static void build_append_pci_bus_devices(Aml *parent_sc= ope, PCIBus *bus, =20 bsel =3D object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL= , NULL); if (bsel) { - int64_t bsel_val =3D qint_get_int(qobject_to_qint(bsel)); + uint64_t bsel_val =3D quint_get_uint(qobject_to_quint(bsel)); =20 aml_append(parent_scope, aml_name_decl("BSEL", aml_int(bsel_val))); notify_method =3D aml_method("DVNT", 2, AML_NOTSERIALIZED); @@ -610,7 +611,7 @@ static void build_append_pci_bus_devices(Aml *parent_sc= ope, PCIBus *bus, =20 /* If bus supports hotplug select it and notify about local events */ if (bsel) { - int64_t bsel_val =3D qint_get_int(qobject_to_qint(bsel)); + uint64_t bsel_val =3D quint_get_uint(qobject_to_quint(bsel)); aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM"))); aml_append(method, aml_call2("DVNT", aml_name("PCIU"), aml_int(1) /* Device Check= */) @@ -2586,12 +2587,12 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) if (!o) { return false; } - mcfg->mcfg_base =3D qint_get_int(qobject_to_qint(o)); + mcfg->mcfg_base =3D quint_get_uint(qobject_to_quint(o)); qobject_decref(o); =20 o =3D object_property_get_qobject(pci_host, PCIE_HOST_MCFG_SIZE, NULL); assert(o); - mcfg->mcfg_size =3D qint_get_int(qobject_to_qint(o)); + mcfg->mcfg_size =3D quint_get_uint(qobject_to_quint(o)); qobject_decref(o); return true; } diff --git a/hw/pci-host/gpex.c b/hw/pci-host/gpex.c index 66055ee5cc..8d3a64008c 100644 --- a/hw/pci-host/gpex.c +++ b/hw/pci-host/gpex.c @@ -94,7 +94,7 @@ static void gpex_host_initfn(Object *obj) =20 object_initialize(root, sizeof(*root), TYPE_GPEX_ROOT_DEVICE); object_property_add_child(obj, "gpex_root", OBJECT(root), NULL); - qdev_prop_set_uint32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); + qdev_prop_set_int32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(root), "multifunction", false); } =20 diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 5438be8253..3cbe8cfcea 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -173,7 +173,7 @@ static void q35_host_initfn(Object *obj) =20 object_initialize(&s->mch, sizeof(s->mch), TYPE_MCH_PCI_DEVICE); object_property_add_child(OBJECT(s), "mch", OBJECT(&s->mch), NULL); - qdev_prop_set_uint32(DEVICE(&s->mch), "addr", PCI_DEVFN(0, 0)); + qdev_prop_set_int32(DEVICE(&s->mch), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(&s->mch), "multifunction", false); =20 object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "uint32", diff --git a/hw/pci-host/xilinx-pcie.c b/hw/pci-host/xilinx-pcie.c index 8b71e2d950..461ed41151 100644 --- a/hw/pci-host/xilinx-pcie.c +++ b/hw/pci-host/xilinx-pcie.c @@ -150,7 +150,7 @@ static void xilinx_pcie_host_init(Object *obj) =20 object_initialize(root, sizeof(*root), TYPE_XILINX_PCIE_ROOT); object_property_add_child(obj, "root", OBJECT(root), NULL); - qdev_prop_set_uint32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); + qdev_prop_set_int32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(root), "multifunction", false); } =20 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index fba92125ab..54f859bc8d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3176,7 +3176,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **= errp) OBJECT(cpu->apic_state), &error_abort); object_unref(OBJECT(cpu->apic_state)); =20 - qdev_prop_set_uint32(cpu->apic_state, "id", cpu->apic_id); + qdev_prop_set_int32(cpu->apic_state, "id", cpu->apic_id); /* TODO: convert to link<> */ apic =3D APIC_COMMON(cpu->apic_state); apic->cpu =3D cpu; --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239041889390.224091274486; Sat, 11 Mar 2017 05:30:41 -0800 (PST) Received: from localhost ([::1]:43419 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh6W-0007Q4-72 for importer@patchew.org; Sat, 11 Mar 2017 08:30:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzm-0002DJ-P5 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzk-0002cg-Gs for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45910) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzk-0002bh-7V for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:40 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 64012C056800; Sat, 11 Mar 2017 13:23:40 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNb9Z002096; Sat, 11 Mar 2017 08:23:38 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:45 +0400 Message-Id: <20170311132256.22951-11-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 11 Mar 2017 13:23:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/21] Use uint property getter/setter where appropriate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" All those property usages are associated with unsigned integers, so use appropriate getter/setter. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/hw/isa/isa.h | 2 +- hw/acpi/memory_hotplug.c | 10 ++++---- hw/acpi/nvdimm.c | 10 ++++---- hw/acpi/pcihp.c | 6 ++--- hw/arm/aspeed.c | 4 ++-- hw/arm/bcm2835_peripherals.c | 9 ++++---- hw/arm/raspi.c | 4 ++-- hw/core/platform-bus.c | 2 +- hw/i386/acpi-build.c | 55 ++++++++++++++++++++++------------------= ---- hw/i386/pc.c | 6 ++--- hw/intc/arm_gicv3_common.c | 2 +- hw/mem/pc-dimm.c | 5 ++-- hw/misc/auxbus.c | 2 +- hw/misc/pvpanic.c | 2 +- hw/ppc/pnv_core.c | 2 +- hw/ppc/spapr.c | 8 ++++--- numa.c | 6 ++--- target/i386/cpu.c | 4 ++-- ui/console.c | 4 ++-- xen-hvm.c | 6 ++--- 20 files changed, 77 insertions(+), 72 deletions(-) diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h index c2fdd70cdc..95593408ef 100644 --- a/include/hw/isa/isa.h +++ b/include/hw/isa/isa.h @@ -29,7 +29,7 @@ static inline uint16_t applesmc_port(void) Object *obj =3D object_resolve_path_type("", TYPE_APPLE_SMC, NULL); =20 if (obj) { - return object_property_get_int(obj, APPLESMC_PROP_IO_BASE, NULL); + return object_property_get_uint(obj, APPLESMC_PROP_IO_BASE, NULL); } return 0; } diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c index 210073d283..db3c89ceab 100644 --- a/hw/acpi/memory_hotplug.c +++ b/hw/acpi/memory_hotplug.c @@ -83,11 +83,12 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, = hwaddr addr, o =3D OBJECT(mdev->dimm); switch (addr) { case 0x0: /* Lo part of phys address where DIMM is mapped */ - val =3D o ? object_property_get_int(o, PC_DIMM_ADDR_PROP, NULL) : = 0; + val =3D o ? object_property_get_uint(o, PC_DIMM_ADDR_PROP, NULL) := 0; trace_mhp_acpi_read_addr_lo(mem_st->selector, val); break; case 0x4: /* Hi part of phys address where DIMM is mapped */ - val =3D o ? object_property_get_int(o, PC_DIMM_ADDR_PROP, NULL) >>= 32 : 0; + val =3D + o ? object_property_get_uint(o, PC_DIMM_ADDR_PROP, NULL) >> 32= : 0; trace_mhp_acpi_read_addr_hi(mem_st->selector, val); break; case 0x8: /* Lo part of DIMM size */ @@ -95,11 +96,12 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, = hwaddr addr, trace_mhp_acpi_read_size_lo(mem_st->selector, val); break; case 0xc: /* Hi part of DIMM size */ - val =3D o ? object_property_get_int(o, PC_DIMM_SIZE_PROP, NULL) >>= 32 : 0; + val =3D + o ? object_property_get_int(o, PC_DIMM_SIZE_PROP, NULL) >> 32 = : 0; trace_mhp_acpi_read_size_hi(mem_st->selector, val); break; case 0x10: /* node proximity for _PXM method */ - val =3D o ? object_property_get_int(o, PC_DIMM_NODE_PROP, NULL) : = 0; + val =3D o ? object_property_get_uint(o, PC_DIMM_NODE_PROP, NULL) := 0; trace_mhp_acpi_read_pxm(mem_st->selector, val); break; case 0x14: /* pack and return is_* fields */ diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 8e7d6ec034..e57027149d 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -236,14 +236,14 @@ static void nvdimm_build_structure_spa(GArray *structures, DeviceState *dev) { NvdimmNfitSpa *nfit_spa; - uint64_t addr =3D object_property_get_int(OBJECT(dev), PC_DIMM_ADDR_PR= OP, - NULL); + uint64_t addr =3D object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_P= ROP, + NULL); uint64_t size =3D object_property_get_int(OBJECT(dev), PC_DIMM_SIZE_PR= OP, NULL); - uint32_t node =3D object_property_get_int(OBJECT(dev), PC_DIMM_NODE_PR= OP, - NULL); + uint32_t node =3D object_property_get_uint(OBJECT(dev), PC_DIMM_NODE_P= ROP, + NULL); int slot =3D object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, - NULL); + NULL); =20 nfit_spa =3D acpi_data_push(structures, sizeof(*nfit_spa)); =20 diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 2b0f3e1bfb..d0e9c4770a 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -63,10 +63,10 @@ typedef struct AcpiPciHpFind { static int acpi_pcihp_get_bsel(PCIBus *bus) { Error *local_err =3D NULL; - int64_t bsel =3D object_property_get_int(OBJECT(bus), ACPI_PCIHP_PROP_= BSEL, - &local_err); + uint64_t bsel =3D object_property_get_uint(OBJECT(bus), ACPI_PCIHP_PRO= P_BSEL, + &local_err); =20 - if (local_err || bsel < 0 || bsel >=3D ACPI_PCIHP_MAX_HOTPLUG_BUS) { + if (local_err || bsel >=3D ACPI_PCIHP_MAX_HOTPLUG_BUS) { if (local_err) { error_free(local_err); } diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index 283c038814..4af422909f 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -187,8 +187,8 @@ static void aspeed_board_init(MachineState *machine, * Allocate RAM after the memory controller has checked the size * was valid. If not, a default value is used. */ - ram_size =3D object_property_get_int(OBJECT(&bmc->soc), "ram-size", - &error_abort); + ram_size =3D object_property_get_uint(OBJECT(&bmc->soc), "ram-size", + &error_abort); =20 memory_region_allocate_system_memory(&bmc->ram, NULL, "ram", ram_size); memory_region_add_subregion(get_system_memory(), sc->info->sdram_base, diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c index 369ef1e3bd..b168c6f83e 100644 --- a/hw/arm/bcm2835_peripherals.c +++ b/hw/arm/bcm2835_peripherals.c @@ -126,7 +126,7 @@ static void bcm2835_peripherals_realize(DeviceState *de= v, Error **errp) Object *obj; MemoryRegion *ram; Error *err =3D NULL; - uint32_t ram_size, vcram_size; + uint64_t ram_size, vcram_size; int n; =20 obj =3D object_property_get_link(OBJECT(dev), "ram", &err); @@ -208,15 +208,14 @@ static void bcm2835_peripherals_realize(DeviceState *= dev, Error **errp) INTERRUPT_ARM_MAILBOX)); =20 /* Framebuffer */ - vcram_size =3D (uint32_t)object_property_get_int(OBJECT(s), "vcram-siz= e", - &err); + vcram_size =3D object_property_get_uint(OBJECT(s), "vcram-size", &err); if (err) { error_propagate(errp, err); return; } =20 - object_property_set_int(OBJECT(&s->fb), ram_size - vcram_size, - "vcram-base", &err); + object_property_set_uint(OBJECT(&s->fb), ram_size - vcram_size, + "vcram-base", &err); if (err) { error_propagate(errp, err); return; diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 2b295f14c4..32cdc98c6d 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -153,8 +153,8 @@ static void raspi2_init(MachineState *machine) qdev_prop_set_drive(carddev, "drive", blk, &error_fatal); object_property_set_bool(OBJECT(carddev), true, "realized", &error_fat= al); =20 - vcram_size =3D object_property_get_int(OBJECT(&s->soc), "vcram-size", - &error_abort); + vcram_size =3D object_property_get_uint(OBJECT(&s->soc), "vcram-size", + &error_abort); setup_boot(machine, 2, machine->ram_size - vcram_size); } =20 diff --git a/hw/core/platform-bus.c b/hw/core/platform-bus.c index 329ac670c0..33d32fbf22 100644 --- a/hw/core/platform-bus.c +++ b/hw/core/platform-bus.c @@ -71,7 +71,7 @@ hwaddr platform_bus_get_mmio_addr(PlatformBusDevice *pbus= , SysBusDevice *sbdev, return -1; } =20 - return object_property_get_int(OBJECT(sbdev_mr), "addr", NULL); + return object_property_get_uint(OBJECT(sbdev_mr), "addr", NULL); } =20 static void platform_bus_count_irqs(SysBusDevice *sbdev, void *opaque) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 76bff18e3f..d46195b83d 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -138,9 +138,9 @@ static void acpi_get_pm_info(AcpiPmInfo *pm) obj =3D piix; pm->cpu_hp_io_base =3D PIIX4_CPU_HOTPLUG_IO_BASE; pm->pcihp_io_base =3D - object_property_get_int(obj, ACPI_PCIHP_IO_BASE_PROP, NULL); + object_property_get_uint(obj, ACPI_PCIHP_IO_BASE_PROP, NULL); pm->pcihp_io_len =3D - object_property_get_int(obj, ACPI_PCIHP_IO_LEN_PROP, NULL); + object_property_get_uint(obj, ACPI_PCIHP_IO_LEN_PROP, NULL); } if (lpc) { obj =3D lpc; @@ -172,20 +172,21 @@ static void acpi_get_pm_info(AcpiPmInfo *pm) qobject_decref(o); =20 /* Fill in mandatory properties */ - pm->sci_int =3D object_property_get_int(obj, ACPI_PM_PROP_SCI_INT, NUL= L); - - pm->acpi_enable_cmd =3D object_property_get_int(obj, - ACPI_PM_PROP_ACPI_ENABLE= _CMD, - NULL); - pm->acpi_disable_cmd =3D object_property_get_int(obj, - ACPI_PM_PROP_ACPI_DISABL= E_CMD, - NULL); - pm->io_base =3D object_property_get_int(obj, ACPI_PM_PROP_PM_IO_BASE, - NULL); - pm->gpe0_blk =3D object_property_get_int(obj, ACPI_PM_PROP_GPE0_BLK, + pm->sci_int =3D object_property_get_uint(obj, ACPI_PM_PROP_SCI_INT, NU= LL); + + pm->acpi_enable_cmd =3D object_property_get_uint(obj, + ACPI_PM_PROP_ACPI_ENABL= E_CMD, + NULL); + pm->acpi_disable_cmd =3D + object_property_get_uint(obj, + ACPI_PM_PROP_ACPI_DISABLE_CMD, + NULL); + pm->io_base =3D object_property_get_uint(obj, ACPI_PM_PROP_PM_IO_BASE, NULL); - pm->gpe0_blk_len =3D object_property_get_int(obj, ACPI_PM_PROP_GPE0_BL= K_LEN, - NULL); + pm->gpe0_blk =3D object_property_get_uint(obj, ACPI_PM_PROP_GPE0_BLK, + NULL); + pm->gpe0_blk_len =3D object_property_get_uint(obj, ACPI_PM_PROP_GPE0_B= LK_LEN, + NULL); pm->pcihp_bridge_en =3D object_property_get_bool(obj, "acpi-pci-hotplug-with-bridge-suppor= t", NULL); @@ -238,19 +239,19 @@ static void acpi_get_pci_holes(Range *hole, Range *ho= le64) g_assert(pci_host); =20 range_set_bounds1(hole, - object_property_get_int(pci_host, - PCI_HOST_PROP_PCI_HOLE_START, - NULL), - object_property_get_int(pci_host, - PCI_HOST_PROP_PCI_HOLE_END, - NULL)); + object_property_get_uint(pci_host, + PCI_HOST_PROP_PCI_HOLE_STAR= T, + NULL), + object_property_get_uint(pci_host, + PCI_HOST_PROP_PCI_HOLE_END, + NULL)); range_set_bounds1(hole64, - object_property_get_int(pci_host, - PCI_HOST_PROP_PCI_HOLE64_STA= RT, - NULL), - object_property_get_int(pci_host, - PCI_HOST_PROP_PCI_HOLE64_END, - NULL)); + object_property_get_uint(pci_host, + PCI_HOST_PROP_PCI_HOLE64_ST= ART, + NULL), + object_property_get_uint(pci_host, + PCI_HOST_PROP_PCI_HOLE64_EN= D, + NULL)); } =20 #define ACPI_PORT_SMI_CMD 0x00b2 /* TODO: this is APM_CNT_IOPORT= */ diff --git a/hw/i386/pc.c b/hw/i386/pc.c index d24388e05f..3b3c2dc43c 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -347,7 +347,7 @@ static int check_fdc(Object *obj, void *opaque) return 0; } =20 - iobase =3D object_property_get_int(obj, "iobase", &local_err); + iobase =3D object_property_get_uint(obj, "iobase", &local_err); if (local_err || iobase !=3D 0x3f0) { error_free(local_err); return 0; @@ -1100,7 +1100,7 @@ static void pc_new_cpu(const char *typename, int64_t = apic_id, Error **errp) =20 cpu =3D object_new(typename); =20 - object_property_set_int(cpu, apic_id, "apic-id", &local_err); + object_property_set_uint(cpu, apic_id, "apic-id", &local_err); object_property_set_bool(cpu, true, "realized", &local_err); =20 object_unref(cpu); @@ -1562,7 +1562,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *= gsi, * and earlier, use IRQ2 for compat. Otherwise, use IRQ16~23, * IRQ8 and IRQ2. */ - uint8_t compat =3D object_property_get_int(OBJECT(hpet), + uint8_t compat =3D object_property_get_uint(OBJECT(hpet), HPET_INTCAP, NULL); if (!compat) { qdev_prop_set_uint32(hpet, HPET_INTCAP, hpet_irqs); diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c index c6493d6c07..e2064cd8c5 100644 --- a/hw/intc/arm_gicv3_common.c +++ b/hw/intc/arm_gicv3_common.c @@ -267,7 +267,7 @@ static void arm_gicv3_common_realize(DeviceState *dev, = Error **errp) * VLPIS =3D=3D 0 (virtual LPIs not supported) * PLPIS =3D=3D 0 (physical LPIs not supported) */ - cpu_affid =3D object_property_get_int(OBJECT(cpu), "mp-affinity", = NULL); + cpu_affid =3D object_property_get_uint(OBJECT(cpu), "mp-affinity",= NULL); last =3D (i =3D=3D s->num_cpu - 1); =20 /* The CPU mp-affinity property is in MPIDR register format; squash diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 9e8dab0e89..f6def8c239 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -46,7 +46,8 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugS= tate *hpms, uint64_t existing_dimms_capacity =3D 0; uint64_t addr; =20 - addr =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &loc= al_err); + addr =3D object_property_get_uint(OBJECT(dimm), + PC_DIMM_ADDR_PROP, &local_err); if (local_err) { goto out; } @@ -73,7 +74,7 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugS= tate *hpms, goto out; } =20 - object_property_set_int(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_e= rr); + object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_= err); if (local_err) { goto out; } diff --git a/hw/misc/auxbus.c b/hw/misc/auxbus.c index e4a7ba41de..8a90ddda84 100644 --- a/hw/misc/auxbus.c +++ b/hw/misc/auxbus.c @@ -244,7 +244,7 @@ static void aux_slave_dev_print(Monitor *mon, DeviceSta= te *dev, int indent) =20 monitor_printf(mon, "%*smemory " TARGET_FMT_plx "/" TARGET_FMT_plx "\n= ", indent, "", - object_property_get_int(OBJECT(s->mmio), "addr", NULL), + object_property_get_uint(OBJECT(s->mmio), "addr", NULL), memory_region_size(s->mmio)); } =20 diff --git a/hw/misc/pvpanic.c b/hw/misc/pvpanic.c index 57da7f2199..2b1e9a6450 100644 --- a/hw/misc/pvpanic.c +++ b/hw/misc/pvpanic.c @@ -111,7 +111,7 @@ uint16_t pvpanic_port(void) if (!o) { return 0; } - return object_property_get_int(o, PVPANIC_IOPORT_PROP, NULL); + return object_property_get_uint(o, PVPANIC_IOPORT_PROP, NULL); } =20 static Property pvpanic_isa_properties[] =3D { diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c index d79d530b48..fe3758754b 100644 --- a/hw/ppc/pnv_core.c +++ b/hw/ppc/pnv_core.c @@ -50,7 +50,7 @@ static void powernv_cpu_init(PowerPCCPU *cpu, Error **err= p) int thread_index =3D 0; /* TODO: TCG supports only one thread */ ppc_spr_t *pir =3D &env->spr_cb[SPR_PIR]; =20 - core_pir =3D object_property_get_int(OBJECT(cpu), "core-pir", &error_a= bort); + core_pir =3D object_property_get_uint(OBJECT(cpu), "core-pir", &error_= abort); =20 /* * The PIR of a thread is the core PIR + the thread index. We will diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index c3bb991605..a7fdeab471 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2528,7 +2528,8 @@ static void spapr_memory_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, goto out; } =20 - addr =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &loc= al_err); + addr =3D object_property_get_uint(OBJECT(dimm), + PC_DIMM_ADDR_PROP, &local_err); if (local_err) { pc_dimm_memory_unplug(dev, &ms->hotplug_memory, mr); goto out; @@ -2616,7 +2617,8 @@ static void spapr_memory_unplug_request(HotplugHandle= r *hotplug_dev, uint64_t size =3D memory_region_size(mr); uint64_t addr; =20 - addr =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &loc= al_err); + addr =3D object_property_get_uint(OBJECT(dimm), + PC_DIMM_ADDR_PROP, &local_err); if (local_err) { goto out; } @@ -2818,7 +2820,7 @@ static void spapr_machine_device_plug(HotplugHandler = *hotplug_dev, error_setg(errp, "Memory hotplug not supported for this machin= e"); return; } - node =3D object_property_get_int(OBJECT(dev), PC_DIMM_NODE_PROP, e= rrp); + node =3D object_property_get_uint(OBJECT(dev), PC_DIMM_NODE_PROP, = errp); if (*errp) { return; } diff --git a/numa.c b/numa.c index e01cb547a2..d22f3acc8a 100644 --- a/numa.c +++ b/numa.c @@ -205,7 +205,7 @@ static void numa_node_parse(NumaNodeOptions *node, Qemu= Opts *opts, Error **errp) } =20 object_ref(o); - numa_info[nodenr].node_mem =3D object_property_get_int(o, "size", = NULL); + numa_info[nodenr].node_mem =3D object_property_get_uint(o, "size",= NULL); numa_info[nodenr].node_memdev =3D MEMORY_BACKEND(o); } numa_info[nodenr].present =3D true; @@ -527,8 +527,8 @@ static int query_memdev(Object *obj, void *opaque) m->value->id =3D object_property_get_str(obj, "id", NULL); m->value->has_id =3D !!m->value->id; =20 - m->value->size =3D object_property_get_int(obj, "size", - &error_abort); + m->value->size =3D object_property_get_uint(obj, "size", + &error_abort); m->value->merge =3D object_property_get_bool(obj, "merge", &error_abort); m->value->dump =3D object_property_get_bool(obj, "dump", diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 54f859bc8d..261b1002e9 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2309,8 +2309,8 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefin= ition *def, Error **errp) */ =20 /* CPU models only set _minimum_ values for level/xlevel: */ - object_property_set_int(OBJECT(cpu), def->level, "min-level", errp); - object_property_set_int(OBJECT(cpu), def->xlevel, "min-xlevel", errp); + object_property_set_uint(OBJECT(cpu), def->level, "min-level", errp); + object_property_set_uint(OBJECT(cpu), def->xlevel, "min-xlevel", errp); =20 object_property_set_int(OBJECT(cpu), def->family, "family", errp); object_property_set_int(OBJECT(cpu), def->model, "model", errp); diff --git a/ui/console.c b/ui/console.c index d1ff7504ec..c5233c8daf 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1866,8 +1866,8 @@ QemuConsole *qemu_console_lookup_by_device(DeviceStat= e *dev, uint32_t head) if (DEVICE(obj) !=3D dev) { continue; } - h =3D object_property_get_int(OBJECT(consoles[i]), - "head", &error_abort); + h =3D object_property_get_uint(OBJECT(consoles[i]), + "head", &error_abort); if (h !=3D head) { continue; } diff --git a/xen-hvm.c b/xen-hvm.c index 5043beb98f..16c3a259fa 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -183,9 +183,9 @@ static void xen_ram_init(PCMachineState *pcms, { MemoryRegion *sysmem =3D get_system_memory(); ram_addr_t block_len; - uint64_t user_lowmem =3D object_property_get_int(qdev_get_machine(), - PC_MACHINE_MAX_RAM_BELO= W_4G, - &error_abort); + uint64_t user_lowmem =3D object_property_get_uint(qdev_get_machine(), + PC_MACHINE_MAX_RAM_BEL= OW_4G, + &error_abort); =20 /* Handle the machine opt max-ram-below-4g. It is basically doing * min(xen limit, user limit). --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239048445987.2635131944496; Sat, 11 Mar 2017 05:30:48 -0800 (PST) Received: from localhost ([::1]:43420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh6c-0007Vv-RX for importer@patchew.org; Sat, 11 Mar 2017 08:30:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzq-0002H2-S9 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzp-0002eO-FM for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44912) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzp-0002e4-61 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:45 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 591064E4CF; Sat, 11 Mar 2017 13:23:45 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNgcB017830; Sat, 11 Mar 2017 08:23:44 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:46 +0400 Message-Id: <20170311132256.22951-12-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 11 Mar 2017 13:23:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/21] qdict: learn to lookup quint X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since a number may be parsed as an integer if it fits, learn to deal with this situtation and fallback on QInt if QUint failed. There is no need for exact type getters in qemu yet. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qapi/qmp/qdict.h | 2 ++ qobject/qdict.c | 37 ++++++++++++++++++++++++++++++++++++- tests/check-qdict.c | 31 +++++++++++++++++++++++++++++++ util/qemu-option.c | 6 ++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index fe9a4c5c60..dae3149603 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -61,6 +61,8 @@ QDict *qdict_get_qdict(const QDict *qdict, const char *ke= y); const char *qdict_get_str(const QDict *qdict, const char *key); int64_t qdict_get_try_int(const QDict *qdict, const char *key, int64_t def_value); +uint64_t qdict_get_try_uint(const QDict *qdict, const char *key, + Error **errp); bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_valu= e); const char *qdict_get_try_str(const QDict *qdict, const char *key); =20 diff --git a/qobject/qdict.c b/qobject/qdict.c index 291eef1a19..8d5c028181 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -12,6 +12,7 @@ =20 #include "qemu/osdep.h" #include "qapi/qmp/qint.h" +#include "qapi/qmp/quint.h" #include "qapi/qmp/qfloat.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qbool.h" @@ -181,7 +182,7 @@ size_t qdict_size(const QDict *qdict) * qdict_get_double(): Get an number mapped by 'key' * * This function assumes that 'key' exists and it stores a - * QFloat or QInt object. + * QFloat, QInt or QUInt object. * * Return number mapped by 'key'. */ @@ -195,6 +196,8 @@ double qdict_get_double(const QDict *qdict, const char = *key) return qfloat_get_double(qobject_to_qfloat(obj)); case QTYPE_QINT: return qint_get_int(qobject_to_qint(obj)); + case QTYPE_QUINT: + return quint_get_uint(qobject_to_quint(obj)); default: abort(); } @@ -272,6 +275,38 @@ int64_t qdict_get_try_int(const QDict *qdict, const ch= ar *key, } =20 /** + * qdict_get_try_uint(): Try to get unsigned mapped by 'key' + * + * Return integer mapped by 'key', if it is not present in + * the dictionary or with negative value, returns 0 and set error. + */ +uint64_t qdict_get_try_uint(const QDict *qdict, const char *key, + Error **errp) +{ + QUInt *quint =3D qobject_to_quint(qdict_get(qdict, key)); + QInt *qint; + int val; + + if (quint) { + return quint_get_uint(quint); + } + + qint =3D qobject_to_qint(qdict_get(qdict, key)); + if (!qint) { + error_setg(errp, "Missing key or type mismatch"); + return 0; + } + + val =3D qint_get_int(qint); + if (val < 0) { + error_setg(errp, "Invalid value, unsigned int expected"); + return 0; + } + + return val; +} + +/** * qdict_get_try_bool(): Try to get a bool mapped by 'key' * * Return bool mapped by 'key', if it is not present in the diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 81162ee572..80a8aef689 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" =20 #include "qapi/qmp/qint.h" +#include "qapi/qmp/quint.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" #include "qapi/error.h" @@ -121,6 +122,35 @@ static void qdict_get_try_int_test(void) QDECREF(tests_dict); } =20 +static void qdict_get_try_uint_test(void) +{ + uint64_t ret; + const int ivalue =3D 100; + const uint64_t uvalue =3D G_MAXUINT64; + const char *key =3D "uint"; + QDict *tests_dict =3D qdict_new(); + Error *err =3D NULL; + + qdict_put(tests_dict, key, qint_from_int(ivalue)); + /* try_uint will work with int types too */ + ret =3D qdict_get_try_uint(tests_dict, key, &err); + g_assert_cmpint(ret, =3D=3D, ivalue); + g_assert(!err); + + qdict_put(tests_dict, key, quint_from_uint(uvalue)); + ret =3D qdict_get_try_uint(tests_dict, key, &err); + g_assert_cmpint(ret, =3D=3D, uvalue); + g_assert(!err); + + qdict_put(tests_dict, key, qint_from_int(-1)); + /* try_uint will fail with negative values */ + ret =3D qdict_get_try_uint(tests_dict, key, &err); + g_assert(err); + error_free(err); + + QDECREF(tests_dict); +} + static void qdict_get_str_test(void) { const char *p; @@ -854,6 +884,7 @@ int main(int argc, char **argv) g_test_add_func("/public/get", qdict_get_test); g_test_add_func("/public/get_int", qdict_get_int_test); g_test_add_func("/public/get_try_int", qdict_get_try_int_test); + g_test_add_func("/public/get_try_uint", qdict_get_try_uint_test); g_test_add_func("/public/get_str", qdict_get_str_test); g_test_add_func("/public/get_try_str", qdict_get_try_str_test); g_test_add_func("/public/defaults", qdict_defaults_test); diff --git a/util/qemu-option.c b/util/qemu-option.c index 5ce1b5c246..7338b943e1 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -959,6 +959,12 @@ static void qemu_opts_from_qdict_1(const char *key, QO= bject *obj, void *opaque) assert(n < sizeof(buf)); value =3D buf; break; + case QTYPE_QUINT: + n =3D snprintf(buf, sizeof(buf), "%" PRIu64, + quint_get_uint(qobject_to_quint(obj))); + assert(n < sizeof(buf)); + value =3D buf; + break; case QTYPE_QFLOAT: n =3D snprintf(buf, sizeof(buf), "%.17g", qfloat_get_double(qobject_to_qfloat(obj))); --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239283667790.134755831472; Sat, 11 Mar 2017 05:34:43 -0800 (PST) Received: from localhost ([::1]:43441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmhAP-0002Fv-7v for importer@patchew.org; Sat, 11 Mar 2017 08:34:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmgzu-0002Jc-3F for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzt-0002fs-7g for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57666) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzs-0002fL-UY for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:49 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21F67C04B93D; Sat, 11 Mar 2017 13:23:49 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNkTD028262; Sat, 11 Mar 2017 08:23:48 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:47 +0400 Message-Id: <20170311132256.22951-13-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 11 Mar 2017 13:23:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/21] test-qga: drop everything until guest-sync X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In the following commits, qemu-ga will emit an event on connect that a real client should treat or ignore and test-qga can skip. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/test-qga.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/test-qga.c b/tests/test-qga.c index c780f0079a..e1f59b7370 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -13,6 +13,8 @@ typedef struct { GPid pid; } TestFixture; =20 +static void guest_sync_delimited(const TestFixture *fixture); + static int connect_qga(char *path) { int s, ret, len, i =3D 0; @@ -45,12 +47,13 @@ static void qga_watch(GPid pid, gint status, gpointer u= ser_data) g_main_loop_quit(fixture->loop); } =20 + static void fixture_setup(TestFixture *fixture, gconstpointer data) { const gchar *extra_arg =3D data; GError *error =3D NULL; - gchar *cwd, *path, *cmd, **argv =3D NULL; + char *cwd, *path, *cmd, **argv =3D NULL; =20 fixture->loop =3D g_main_loop_new(NULL, FALSE); =20 @@ -77,6 +80,8 @@ fixture_setup(TestFixture *fixture, gconstpointer data) fixture->fd =3D connect_qga(path); g_assert_cmpint(fixture->fd, !=3D, -1); =20 + guest_sync_delimited(fixture); + g_strfreev(argv); g_free(cmd); g_free(cwd); @@ -138,9 +143,8 @@ static void qmp_assertion_message_error(const char = *domain, } \ } while (0) =20 -static void test_qga_sync_delimited(gconstpointer fix) +static void guest_sync_delimited(const TestFixture *fixture) { - const TestFixture *fixture =3D fix; guint32 v, r =3D g_random_int(); unsigned char c; QDict *ret; @@ -148,12 +152,13 @@ static void test_qga_sync_delimited(gconstpointer fix) =20 cmd =3D g_strdup_printf("%c{'execute': 'guest-sync-delimited'," " 'arguments': {'id': %u } }", 0xff, r); + qmp_fd_send(fixture->fd, cmd); - g_free(cmd); =20 - v =3D read(fixture->fd, &c, 1); - g_assert_cmpint(v, =3D=3D, 1); - g_assert_cmpint(c, =3D=3D, 0xff); + do { + v =3D read(fixture->fd, &c, 1); + g_assert_cmpint(v, =3D=3D, 1); + } while (c !=3D 0xff); =20 ret =3D qmp_fd_receive(fixture->fd); g_assert_nonnull(ret); @@ -163,6 +168,14 @@ static void test_qga_sync_delimited(gconstpointer fix) g_assert_cmpint(r, =3D=3D, v); =20 QDECREF(ret); + g_free(cmd); +} + +static void test_qga_sync_delimited(gconstpointer fix) +{ + const TestFixture *fixture =3D fix; + + guest_sync_delimited(fixture); } =20 static void test_qga_sync(gconstpointer fix) --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489238819191615.6182838494113; Sat, 11 Mar 2017 05:26:59 -0800 (PST) Received: from localhost ([::1]:43404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh2w-0004ET-0I for importer@patchew.org; Sat, 11 Mar 2017 08:26:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh00-0002P7-Q6 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmgzw-0002hC-Oa for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmgzw-0002gz-IO for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:52 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF9D064A62; Sat, 11 Mar 2017 13:23:52 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNole028268; Sat, 11 Mar 2017 08:23:51 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:48 +0400 Message-Id: <20170311132256.22951-14-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 11 Mar 2017 13:23:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 13/21] qga: report error on keyfile dump error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Cc:qemu-trivial@nongnu.org --- qga/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qga/main.c b/qga/main.c index 92658bc0e2..beff041340 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1082,7 +1082,12 @@ static void config_dump(GAConfig *config) g_free(tmp); =20 tmp =3D g_key_file_to_data(keyfile, NULL, &error); - printf("%s", tmp); + if (tmp) { + printf("%s", tmp); + } else if (error) { + g_critical("Failed to dump keyfile: %s", error->message); + g_clear_error(&error); + } =20 g_free(tmp); g_key_file_free(keyfile); --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239410966709.830824657709; Sat, 11 Mar 2017 05:36:50 -0800 (PST) Received: from localhost ([::1]:43456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmhCS-0004D1-Ks for importer@patchew.org; Sat, 11 Mar 2017 08:36:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh01-0002Pu-P4 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmh00-0002iV-Is for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45954) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmh00-0002i1-Ac for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:23:56 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B3ADC054C5E; Sat, 11 Mar 2017 13:23:56 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNsAx021573; Sat, 11 Mar 2017 08:23:55 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:49 +0400 Message-Id: <20170311132256.22951-15-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 11 Mar 2017 13:23:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 14/21] qga: add and populate VMDumpInfo X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Get various addresses and informations that can be useful for qemu to generate dumps, and provide enough details for KASLR kernels to be exploitable by tools like crash. phys-base: the physical address where the kernel is loaded vmcoreinfo: can be used to read the guest vmcoreinfo ELF note _text: can be used to compute the kaslr offset (not needed when vmcoreinfo) Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/main.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 134 insertions(+) diff --git a/qga/main.c b/qga/main.c index beff041340..1c39895baa 100644 --- a/qga/main.c +++ b/qga/main.c @@ -65,6 +65,14 @@ typedef struct GAPersistentState { int64_t fd_counter; } GAPersistentState; =20 +typedef struct VMDumpInfo { + bool has_phys_base; + uint64_t phys_base; + bool has_text; + uint64_t text; + char *vmcoreinfo; +} VMDumpInfo; + struct GAState { JSONMessageParser parser; GMainLoop *main_loop; @@ -90,6 +98,7 @@ struct GAState { #endif gchar *pstate_filepath; GAPersistentState pstate; + VMDumpInfo vmdump; }; =20 struct GAState *ga_state; @@ -1357,6 +1366,128 @@ static int run_agent(GAState *s, GAConfig *config) return EXIT_SUCCESS; } =20 +#define __START_KERNEL_map 0xffffffff80000000UL + +static void update_vmdump_info(GAState *s) +{ +#ifndef _WIN32 + char *vmcoreinfo =3D NULL; + char *iomem =3D NULL; + char *kallsyms =3D NULL; + gsize len; + GError *err =3D NULL; +#ifdef __x86_64__ + guint64 kernel_code_start, text_start, phys_base; + char *tmp, *line, *eol; + + if (!g_file_get_contents("/proc/iomem", &iomem, &len, &err)) { + g_critical("Failed to read /proc/iomem: %s", err->message); + g_clear_error(&err); + goto end; + } + if (!iomem[len] =3D=3D '\0') { + g_critical("iomem is not null-terminated"); + goto end; + } + + for (line =3D iomem; line !=3D NULL; line =3D eol ? eol + 1 : NULL) { + eol =3D strstr(line, "\n"); + if (eol) { + *eol =3D '\0'; + } + tmp =3D strstr(line, " : Kernel code"); + if (!tmp || *(tmp + 14) !=3D '\0') { + continue; + } else { + break; + } + } + + if (line =3D=3D NULL) { + g_critical("failed to find kernel_code_start"); + goto end; + } else { + tmp =3D strstr(line, "-"); + if (!tmp) { + g_critical("no -"); + goto end; + } + *tmp =3D '\0'; + kernel_code_start =3D g_ascii_strtoull(g_strstrip(line), &tmp, 16); + if (*tmp !=3D '\0') { + g_critical("failed to parse hex value"); + goto end; + } + } + + if (!g_file_get_contents("/proc/kallsyms", &kallsyms, &len, &err)) { + g_critical("Failed to read /proc/kallsyms: %s", err->message); + g_clear_error(&err); + goto end; + } + if (!kallsyms[len] =3D=3D '\0') { + g_critical("iomem is not null-terminated"); + goto end; + } + + for (line =3D kallsyms; line !=3D NULL; line =3D eol ? eol + 1 : NULL)= { + eol =3D strstr(line, "\n"); + if (eol) { + *eol =3D '\0'; + } + tmp =3D strstr(line, " T _text"); + if (!tmp || *(tmp + 8) !=3D '\0') { + continue; + } else { + *tmp =3D '\0'; + break; + } + } + + if (line =3D=3D NULL) { + g_critical("failed to find _text"); + goto end; + } else { + text_start =3D g_ascii_strtoull(g_strstrip(line), &tmp, 16); + if (*tmp !=3D '\0') { + g_critical("failed to parse hex value"); + goto end; + } + } + + phys_base =3D kernel_code_start - (text_start - __START_KERNEL_map); + g_debug("_text: %lx, kernel_code_start: %lx", + text_start, kernel_code_start); + g_debug("-> phys_base: %lx", phys_base); + g_debug("vmcoreinfo: %s", vmcoreinfo); + + s->vmdump.has_phys_base =3D true; + s->vmdump.phys_base =3D phys_base; + s->vmdump.has_text =3D true; + s->vmdump.text =3D text_start; +#endif /* x86_64 */ + + if (!g_file_get_contents("/sys/kernel/vmcoreinfo", + &vmcoreinfo, &len, &err)) { + g_critical("Failed to read vmcoreinfo: %s", err->message); + g_clear_error(&err); + goto end; + } + if (!vmcoreinfo[len] =3D=3D '\0') { + g_critical("vmcoreinfo is not null-terminated"); + goto end; + } + + s->vmdump.vmcoreinfo =3D vmcoreinfo; + vmcoreinfo =3D NULL; + +end: + g_free(vmcoreinfo); + g_free(kallsyms); + g_free(iomem); +#endif +} + int main(int argc, char **argv) { int ret =3D EXIT_SUCCESS; @@ -1364,6 +1495,8 @@ int main(int argc, char **argv) GAConfig *config =3D g_new0(GAConfig, 1); int listen_fd; =20 + update_vmdump_info(s); + config->log_level =3D G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; =20 qga_qmp_init_marshal(&ga_commands); @@ -1460,6 +1593,7 @@ end: if (s->main_loop) { g_main_loop_unref(s->main_loop); } + g_free(s->vmdump.vmcoreinfo); g_free(s); =20 return ret; --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239486066342.22917485868777; Sat, 11 Mar 2017 05:38:06 -0800 (PST) Received: from localhost ([::1]:43464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmhDg-0005SK-VF for importer@patchew.org; Sat, 11 Mar 2017 08:38:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh04-0002TH-Ts for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmh04-0002jZ-6b for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44980) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmh04-0002jQ-0V for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:00 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 38B844E4C6; Sat, 11 Mar 2017 13:24:00 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDNvdQ028321; Sat, 11 Mar 2017 08:23:59 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:50 +0400 Message-Id: <20170311132256.22951-16-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 11 Mar 2017 13:24:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 15/21] qga: register event emit function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/qga/main.c b/qga/main.c index 1c39895baa..8e852bd556 100644 --- a/qga/main.c +++ b/qga/main.c @@ -39,6 +39,7 @@ #define CONFIG_FSFREEZE #endif #endif +#include "qapi/qmp-event.h" =20 #ifndef _WIN32 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0" @@ -1488,6 +1489,12 @@ end: #endif } =20 +static void +monitor_qapi_event_queue(qga_QAPIEvent event, QDict *qdict, Error **errp) +{ + send_response(ga_state, QOBJECT(qdict)); +} + int main(int argc, char **argv) { int ret =3D EXIT_SUCCESS; @@ -1496,6 +1503,7 @@ int main(int argc, char **argv) int listen_fd; =20 update_vmdump_info(s); + qmp_event_set_func_emit(monitor_qapi_event_queue); =20 config->log_level =3D G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; =20 --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239195787199.93250724951577; Sat, 11 Mar 2017 05:33:15 -0800 (PST) Received: from localhost ([::1]:43434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh90-00013T-E2 for importer@patchew.org; Sat, 11 Mar 2017 08:33:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58911) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh0B-0002aY-4O for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmh08-0002ks-Ao for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57716) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmh08-0002kf-2B for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:04 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A037C04B93D; Sat, 11 Mar 2017 13:24:04 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDO1qk028338; Sat, 11 Mar 2017 08:24:03 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:51 +0400 Message-Id: <20170311132256.22951-17-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 11 Mar 2017 13:24:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 16/21] qga: emit VMDUMP_INFO event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When client connects, emit the VMDUMP_INFO. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/guest-agent-core.h | 2 ++ qga/channel-posix.c | 11 +++++++++++ qga/main.c | 13 +++++++++++++ Makefile | 7 ++++++- qga/Makefile.objs | 1 + qga/qapi-schema.json | 15 +++++++++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/qga/guest-agent-core.h b/qga/guest-agent-core.h index 3e8a4acff2..1880b0f0ac 100644 --- a/qga/guest-agent-core.h +++ b/qga/guest-agent-core.h @@ -46,3 +46,5 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp= ); #ifndef _WIN32 void reopen_fd_to_null(int fd); #endif + +void ga_client_added(void); diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 3f34465159..5999df0684 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -3,6 +3,7 @@ #include "qapi/error.h" #include "qemu/sockets.h" #include "qga/channel.h" +#include "qga/guest-agent-core.h" =20 #ifdef CONFIG_SOLARIS #include @@ -98,6 +99,13 @@ static gboolean ga_channel_client_event(GIOChannel *chan= nel, return true; } =20 +static gboolean client_added_idle_cb(gpointer user_data) +{ + ga_client_added(); + + return false; +} + static int ga_channel_client_add(GAChannel *c, int fd) { GIOChannel *client_channel; @@ -115,6 +123,9 @@ static int ga_channel_client_add(GAChannel *c, int fd) g_io_add_watch(client_channel, G_IO_IN | G_IO_HUP, ga_channel_client_event, c); c->client_channel =3D client_channel; + + g_idle_add(client_added_idle_cb, NULL); + return 0; } =20 diff --git a/qga/main.c b/qga/main.c index 8e852bd556..d2a874e67a 100644 --- a/qga/main.c +++ b/qga/main.c @@ -40,6 +40,7 @@ #endif #endif #include "qapi/qmp-event.h" +#include "qga-qapi-event.h" =20 #ifndef _WIN32 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0" @@ -691,6 +692,18 @@ static gboolean channel_event_cb(GIOCondition conditio= n, gpointer data) return true; } =20 +void ga_client_added(void) +{ +#ifndef _WIN32 + GAState *s =3D ga_state; + + qapi_event_send_vmdump_info(s->vmdump.has_phys_base, s->vmdump.phys_ba= se, + s->vmdump.has_text, s->vmdump.text, + s->vmdump.vmcoreinfo !=3D NULL, + s->vmdump.vmcoreinfo, NULL); +#endif +} + static gboolean channel_init(GAState *s, const gchar *method, const gchar = *path, int listen_fd) { diff --git a/Makefile b/Makefile index 1c4c04f6f2..fc7e321041 100644 --- a/Makefile +++ b/Makefile @@ -404,6 +404,11 @@ $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/q= api-commands.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \ $(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \ "GEN","$@") +qga/qapi-generated/qga-qapi-event.c qga/qapi-generated/qga-qapi-event.h :\ +$(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qa= pi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \ + $(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \ + "GEN","$@") =20 qapi-modules =3D $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json= \ $(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.jso= n \ @@ -437,7 +442,7 @@ $(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py = $(qapi-py) $(gen-out-type) -o "." $<, \ "GEN","$@") =20 -QGALIB_GEN=3D$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-vi= sit.h qga-qmp-commands.h) +QGALIB_GEN=3D$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-vi= sit.h qga-qmp-commands.h qga-qapi-event.h) $(qga-obj-y) qemu-ga.o: $(QGALIB_GEN) =20 qemu-ga$(EXESUF): $(qga-obj-y) $(COMMON_LDADDS) diff --git a/qga/Makefile.objs b/qga/Makefile.objs index 1c5986c0bb..d22977f0e1 100644 --- a/qga/Makefile.objs +++ b/qga/Makefile.objs @@ -4,5 +4,6 @@ qga-obj-$(CONFIG_WIN32) +=3D commands-win32.o channel-win32= .o service-win32.o qga-obj-$(CONFIG_WIN32) +=3D vss-win32.o qga-obj-y +=3D qapi-generated/qga-qapi-types.o qapi-generated/qga-qapi-vis= it.o qga-obj-y +=3D qapi-generated/qga-qmp-marshal.o +qga-obj-y +=3D qapi-generated/qga-qapi-event.o =20 qga-vss-dll-obj-$(CONFIG_QGA_VSS) +=3D vss-win32/ diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index d421609dcb..2a95af3399 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -48,6 +48,21 @@ 'returns': 'int' } =20 ## +# @VMDUMP_INFO: +# +# Provides VM dump information details to qemu. +# +# @phys-base: base address +# +# @text: "_text" location +# +# @vmcoreinfo: the content of /sys/kernel/vmcoreinfo on Linux +# +## +{ 'event': 'VMDUMP_INFO', + 'data': { '*phys-base': 'uint64', '*text': 'uint64', '*vmcoreinfo': 'str= ' } } + +## # @guest-sync: # # Echo back a unique integer value --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239199096903.9682838052983; Sat, 11 Mar 2017 05:33:19 -0800 (PST) Received: from localhost ([::1]:43435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh93-00015W-NS for importer@patchew.org; Sat, 11 Mar 2017 08:33:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh0C-0002cD-Sc for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmh0B-0002lW-Kl for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40550) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmh0B-0002lI-CY for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:07 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93F3C2E2431; Sat, 11 Mar 2017 13:24:07 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9FA62D655; Sat, 11 Mar 2017 13:24:06 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:52 +0400 Message-Id: <20170311132256.22951-18-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 11 Mar 2017 13:24:07 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 17/21] virtio-channel: parse qga stream for VMDUMP_INFO event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" On virtio channel "org.qemu.guest_agent.0", parse the json stream until the VMDUMP_INFO is received and retrieve the dump details. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/sysemu/dump-info.h | 15 +++++++++++++ dump.c | 3 +++ hw/char/virtio-console.c | 53 ++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 71 insertions(+) create mode 100644 include/sysemu/dump-info.h diff --git a/include/sysemu/dump-info.h b/include/sysemu/dump-info.h new file mode 100644 index 0000000000..fb1ddff9af --- /dev/null +++ b/include/sysemu/dump-info.h @@ -0,0 +1,15 @@ +#ifndef DUMP_INFO_H +#define DUMP_INFO_H + +typedef struct DumpInfo { + bool received; + bool has_phys_base; + uint64_t phys_base; + bool has_text; + uint64_t text; + char *vmcoreinfo; +} DumpInfo; + +extern DumpInfo dump_info; + +#endif /* DUMP_INFO_H */ diff --git a/dump.c b/dump.c index f7b80d856b..68b406459e 100644 --- a/dump.c +++ b/dump.c @@ -20,6 +20,7 @@ #include "monitor/monitor.h" #include "sysemu/kvm.h" #include "sysemu/dump.h" +#include "sysemu/dump-info.h" #include "sysemu/sysemu.h" #include "sysemu/memory_mapping.h" #include "sysemu/cpus.h" @@ -38,6 +39,8 @@ #define ELF_MACHINE_UNAME "Unknown" #endif =20 +DumpInfo dump_info =3D { 0, }; + uint16_t cpu_to_dump16(DumpState *s, uint16_t val) { if (s->dump_info.d_endian =3D=3D ELFDATA2LSB) { diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c index 798d9b69fd..796b7c85aa 100644 --- a/hw/char/virtio-console.c +++ b/hw/char/virtio-console.c @@ -16,6 +16,9 @@ #include "trace.h" #include "hw/virtio/virtio-serial.h" #include "qapi-event.h" +#include "qapi/qmp/json-streamer.h" +#include "qapi/qmp/json-parser.h" +#include "sysemu/dump-info.h" =20 #define TYPE_VIRTIO_CONSOLE_SERIAL_PORT "virtserialport" #define VIRTIO_CONSOLE(obj) \ @@ -26,6 +29,7 @@ typedef struct VirtConsole { =20 CharBackend chr; guint watch; + JSONMessageParser parser; } VirtConsole; =20 /* @@ -49,6 +53,11 @@ static ssize_t flush_buf(VirtIOSerialPort *port, VirtConsole *vcon =3D VIRTIO_CONSOLE(port); ssize_t ret; =20 + if (vcon->parser.emit && + !dump_info.received) { + json_message_parser_feed(&vcon->parser, (const char *)buf, len); + } + if (!qemu_chr_fe_get_driver(&vcon->chr)) { /* If there's no backend, we can just say we consumed all data. */ return len; @@ -108,6 +117,11 @@ static void set_guest_connected(VirtIOSerialPort *port= , int guest_connected) DeviceState *dev =3D DEVICE(port); VirtIOSerialPortClass *k =3D VIRTIO_SERIAL_PORT_GET_CLASS(port); =20 + if (guest_connected && !port->guest_connected) { + g_free(dump_info.vmcoreinfo); + memset(&dump_info, 0, sizeof(dump_info)); + } + if (!k->is_console) { qemu_chr_fe_set_open(&vcon->chr, guest_connected); } @@ -163,6 +177,37 @@ static void chr_event(void *opaque, int event) } } =20 + +static void qga_message(JSONMessageParser *parser, GQueue *tokens) +{ + /* VirtConsole *vcon =3D container_of(parser, VirtConsole, parser); */ + QObject *obj; + QDict *msg, *data; + const char *event; + + obj =3D json_parser_parse(tokens, NULL); + msg =3D qobject_to_qdict(obj); + if (!msg) { + error_report("JSON parsing failed"); + return; + } + + event =3D qdict_get_try_str(msg, "event"); + data =3D qdict_get_qdict(msg, "data"); + if (event && g_str_equal(event, "VMDUMP_INFO") && data) { + dump_info.received =3D true; + if (qdict_haskey(data, "phys-base")) { + dump_info.has_phys_base =3D true; + dump_info.phys_base =3D qdict_get_try_uint(data, "phys-base", = 0); + } + if (qdict_haskey(data, "text")) { + dump_info.has_text =3D true; + dump_info.text =3D qdict_get_try_uint(data, "text", 0); + } + dump_info.vmcoreinfo =3D g_strdup(qdict_get_try_str(data, "vmcorei= nfo")); + } +} + static void virtconsole_realize(DeviceState *dev, Error **errp) { VirtIOSerialPort *port =3D VIRTIO_SERIAL_PORT(dev); @@ -195,6 +240,10 @@ static void virtconsole_realize(DeviceState *dev, Erro= r **errp) chr_event, vcon, NULL, false); } } + + if (port->name && g_str_equal(port->name, "org.qemu.guest_agent.0")) { + json_message_parser_init(&vcon->parser, qga_message); + } } =20 static void virtconsole_unrealize(DeviceState *dev, Error **errp) @@ -204,6 +253,10 @@ static void virtconsole_unrealize(DeviceState *dev, Er= ror **errp) if (vcon->watch) { g_source_remove(vcon->watch); } + + if (vcon->parser.emit) { + json_message_parser_destroy(&vcon->parser); + } } =20 static void virtconsole_class_init(ObjectClass *klass, void *data) --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148923934184713.897683201676955; Sat, 11 Mar 2017 05:35:41 -0800 (PST) Received: from localhost ([::1]:43442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmhBL-000333-0H for importer@patchew.org; Sat, 11 Mar 2017 08:35:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh0G-0002gG-Tj for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmh0F-0002lx-Ir for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46002) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmh0F-0002lp-9v for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:11 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74A87C057FAD; Sat, 11 Mar 2017 13:24:11 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75AEE2D655; Sat, 11 Mar 2017 13:24:10 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:53 +0400 Message-Id: <20170311132256.22951-19-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 11 Mar 2017 13:24:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 18/21] dump: use qga VMDUMP_INFO for ELF dump X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add vmcoreinfo ELF note. NUMBRE(phys_base) in vmcoreinfo has only been recently introduced in Linux 4.10 ("kexec: export the value of phys_base instead of symbol address"). To accomadate for older kernels, modify the vmcoreinfo to add the new fields and help newer crash that will use it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/sysemu/dump.h | 2 + dump.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 135 insertions(+) diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index ef931be469..ff0e9894b7 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -191,6 +191,8 @@ typedef struct DumpState { * this could be used to calculate * how much work we have * finished. */ + uint8_t *vmcoreinfo; + size_t vmcoreinfo_size; } DumpState; =20 uint16_t cpu_to_dump16(DumpState *s, uint16_t val); diff --git a/dump.c b/dump.c index 68b406459e..0ebfb5471a 100644 --- a/dump.c +++ b/dump.c @@ -27,6 +27,7 @@ #include "qapi/qmp/qerror.h" #include "qmp-commands.h" #include "qapi-event.h" +#include "qemu/error-report.h" =20 #include #ifdef CONFIG_LZO @@ -82,6 +83,8 @@ static int dump_cleanup(DumpState *s) if (s->resume) { vm_start(); } + g_free(s->vmcoreinfo); + s->vmcoreinfo =3D NULL; =20 return 0; } @@ -232,6 +235,19 @@ static inline int cpu_index(CPUState *cpu) return cpu->cpu_index + 1; } =20 +static void write_vmcoreinfo_note(WriteCoreDumpFunction f, DumpState *s, + Error **errp) +{ + int ret; + + if (s->vmcoreinfo) { + ret =3D f(s->vmcoreinfo, s->vmcoreinfo_size, s); + if (ret < 0) { + error_setg(errp, "dump: failed to write vmcoreinfo"); + } + } +} + static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s, Error **errp) { @@ -255,6 +271,8 @@ static void write_elf64_notes(WriteCoreDumpFunction f, = DumpState *s, return; } } + + write_vmcoreinfo_note(f, s, errp); } =20 static void write_elf32_note(DumpState *s, Error **errp) @@ -300,6 +318,8 @@ static void write_elf32_notes(WriteCoreDumpFunction f, = DumpState *s, return; } } + + write_vmcoreinfo_note(f, s, errp); } =20 static void write_elf_section(DumpState *s, int type, Error **errp) @@ -711,6 +731,50 @@ static int buf_write_note(const void *buf, size_t size= , void *opaque) return 0; } =20 +static void get_note_sizes(DumpState *s, const void *note, + uint64_t *note_head_size, + uint64_t *name_size, + uint64_t *desc_size) +{ + uint64_t note_head_sz; + uint64_t name_sz; + uint64_t desc_sz; + + if (s->dump_info.d_class =3D=3D ELFCLASS64) { + const Elf64_Nhdr *hdr =3D note; + note_head_sz =3D sizeof(Elf64_Nhdr); + name_sz =3D hdr->n_namesz; + desc_sz =3D hdr->n_descsz; + } else { + const Elf32_Nhdr *hdr =3D note; + note_head_sz =3D sizeof(Elf32_Nhdr); + name_sz =3D hdr->n_namesz; + desc_sz =3D hdr->n_descsz; + } + + if (note_head_size) { + *note_head_size =3D note_head_sz; + } + if (name_size) { + *name_size =3D name_sz; + } + if (desc_size) { + *desc_size =3D desc_sz; + } +} + +static void set_note_desc_size(DumpState *s, void *note, + uint64_t desc_size) +{ + if (s->dump_info.d_class =3D=3D ELFCLASS64) { + Elf64_Nhdr *hdr =3D note; + hdr->n_descsz =3D desc_size; + } else { + Elf32_Nhdr *hdr =3D note; + hdr->n_descsz =3D desc_size; + } +} + /* write common header, sub header and elf note to vmcore */ static void create_header32(DumpState *s, Error **errp) { @@ -1485,6 +1549,42 @@ static int64_t dump_calculate_size(DumpState *s) return total; } =20 +static void vmcoreinfo_add_phys_base(DumpState *s) +{ + uint64_t size, note_head_size, name_size; + char **lines, *physbase =3D NULL; + uint8_t *newvmci, *vmci; + size_t i; + + get_note_sizes(s, s->vmcoreinfo, ¬e_head_size, &name_size, &size); + note_head_size =3D ((note_head_size + 3) / 4) * 4; + name_size =3D ((name_size + 3) / 4) * 4; + vmci =3D s->vmcoreinfo + note_head_size + name_size; + *(vmci + size) =3D '\0'; + lines =3D g_strsplit((char *)vmci, "\n", -1); + for (i =3D 0; lines[i]; i++) { + if (g_str_has_prefix(lines[i], "NUMBER(phys_base)=3D")) { + goto end; + } + } + + physbase =3D g_strdup_printf("\nNUMBER(phys_base)=3D%ld", + s->dump_info.phys_base); + s->vmcoreinfo_size =3D + ((note_head_size + name_size + size + strlen(physbase) + 3) / 4) *= 4; + + newvmci =3D g_malloc(s->vmcoreinfo_size); + memcpy(newvmci, s->vmcoreinfo, note_head_size + name_size + size - 1); + memcpy(newvmci + note_head_size + name_size + size - 1, physbase, + strlen(physbase) + 1); + g_free(s->vmcoreinfo); + s->vmcoreinfo =3D newvmci; + set_note_desc_size(s, s->vmcoreinfo, size + strlen(physbase)); + +end: + g_strfreev(lines); +} + static void dump_init(DumpState *s, int fd, bool has_format, DumpGuestMemoryFormat format, bool paging, bool has_= filter, int64_t begin, int64_t length, Error **errp) @@ -1560,6 +1660,39 @@ static void dump_init(DumpState *s, int fd, bool has= _format, goto cleanup; } =20 + if (dump_info.has_phys_base) { + s->dump_info.phys_base =3D dump_info.phys_base; + } + if (dump_info.vmcoreinfo) { + uint64_t addr, size, note_head_size, name_size, desc_size; + int count =3D sscanf(dump_info.vmcoreinfo, "%" PRIx64 " %" PRIx64, + &addr, &size); + if (count !=3D 2) { + /* non fatal error */ + error_report("Failed to parse vmcoreinfo"); + } else { + assert(!s->vmcoreinfo); + s->vmcoreinfo =3D g_malloc(size); + cpu_physical_memory_read(addr, s->vmcoreinfo, size); + + get_note_sizes(s, s->vmcoreinfo, + ¬e_head_size, &name_size, &desc_size); + s->vmcoreinfo_size =3D ((note_head_size + 3) / 4 + + (name_size + 3) / 4 + + (desc_size + 3) / 4) * 4; + if (s->vmcoreinfo_size > size) { + error_report("Invalid vmcoreinfo header, size mismatch"); + g_free(s->vmcoreinfo); + s->vmcoreinfo =3D NULL; + } else { + if (dump_info.has_phys_base) { + vmcoreinfo_add_phys_base(s); + } + s->note_size +=3D s->vmcoreinfo_size; + } + } + } + /* get memory mapping */ if (paging) { qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, &er= r); --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239125807983.3169757893525; Sat, 11 Mar 2017 05:32:05 -0800 (PST) Received: from localhost ([::1]:43431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh7s-00009g-FM for importer@patchew.org; Sat, 11 Mar 2017 08:32:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh0K-0002jv-W3 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmh0J-0002mS-AT for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54256) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmh0J-0002mM-2B for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:15 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EB0685542; Sat, 11 Mar 2017 13:24:15 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42F442D655; Sat, 11 Mar 2017 13:24:13 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:54 +0400 Message-Id: <20170311132256.22951-20-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 11 Mar 2017 13:24:15 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 19/21] kdump: write vmcoreinfo in header X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- dump.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/dump.c b/dump.c index 0ebfb5471a..bf88cb362b 100644 --- a/dump.c +++ b/dump.c @@ -785,8 +785,9 @@ static void create_header32(DumpState *s, Error **errp) uint32_t sub_hdr_size; uint32_t bitmap_blocks; uint32_t status =3D 0; - uint64_t offset_note; + uint64_t offset_note, offset_vmcoreinfo, size_vmcoreinfo =3D 0; Error *local_err =3D NULL; + uint8_t *vmcoreinfo =3D NULL; =20 /* write common header, the version of kdump-compressed format is 6th = */ size =3D sizeof(DiskDumpHeader32); @@ -835,7 +836,18 @@ static void create_header32(DumpState *s, Error **errp) kh->phys_base =3D cpu_to_dump32(s, s->dump_info.phys_base); kh->dump_level =3D cpu_to_dump32(s, DUMP_LEVEL); =20 - offset_note =3D DISKDUMP_HEADER_BLOCKS * block_size + size; + offset_vmcoreinfo =3D DISKDUMP_HEADER_BLOCKS * block_size + size; + if (s->vmcoreinfo) { + uint64_t hsize, name_size; + + get_note_sizes(s, s->vmcoreinfo, &hsize, &name_size, &size_vmcorei= nfo); + vmcoreinfo =3D + s->vmcoreinfo + ((hsize + 3) / 4 + (name_size + 3) / 4) * 4; + kh->offset_vmcoreinfo =3D cpu_to_dump64(s, offset_vmcoreinfo); + kh->size_vmcoreinfo =3D cpu_to_dump32(s, size_vmcoreinfo); + } + + offset_note =3D offset_vmcoreinfo + size_vmcoreinfo; kh->offset_note =3D cpu_to_dump64(s, offset_note); kh->note_size =3D cpu_to_dump32(s, s->note_size); =20 @@ -845,6 +857,14 @@ static void create_header32(DumpState *s, Error **errp) goto out; } =20 + if (vmcoreinfo) { + if (write_buffer(s->fd, offset_vmcoreinfo, vmcoreinfo, + size_vmcoreinfo) < 0) { + error_setg(errp, "dump: failed to vmcoreinfo"); + goto out; + } + } + /* write note */ s->note_buf =3D g_malloc0(s->note_size); s->note_buf_offset =3D 0; @@ -885,8 +905,9 @@ static void create_header64(DumpState *s, Error **errp) uint32_t sub_hdr_size; uint32_t bitmap_blocks; uint32_t status =3D 0; - uint64_t offset_note; + uint64_t offset_note, offset_vmcoreinfo, size_vmcoreinfo =3D 0; Error *local_err =3D NULL; + uint8_t *vmcoreinfo =3D NULL; =20 /* write common header, the version of kdump-compressed format is 6th = */ size =3D sizeof(DiskDumpHeader64); @@ -935,7 +956,18 @@ static void create_header64(DumpState *s, Error **errp) kh->phys_base =3D cpu_to_dump64(s, s->dump_info.phys_base); kh->dump_level =3D cpu_to_dump32(s, DUMP_LEVEL); =20 - offset_note =3D DISKDUMP_HEADER_BLOCKS * block_size + size; + offset_vmcoreinfo =3D DISKDUMP_HEADER_BLOCKS * block_size + size; + if (s->vmcoreinfo) { + uint64_t hsize, name_size; + + get_note_sizes(s, s->vmcoreinfo, &hsize, &name_size, &size_vmcorei= nfo); + vmcoreinfo =3D + s->vmcoreinfo + ((hsize + 3) / 4 + (name_size + 3) / 4) * 4; + kh->offset_vmcoreinfo =3D cpu_to_dump64(s, offset_vmcoreinfo); + kh->size_vmcoreinfo =3D cpu_to_dump64(s, size_vmcoreinfo); + } + + offset_note =3D offset_vmcoreinfo + size_vmcoreinfo; kh->offset_note =3D cpu_to_dump64(s, offset_note); kh->note_size =3D cpu_to_dump64(s, s->note_size); =20 @@ -945,6 +977,14 @@ static void create_header64(DumpState *s, Error **errp) goto out; } =20 + if (vmcoreinfo) { + if (write_buffer(s->fd, offset_vmcoreinfo, vmcoreinfo, + size_vmcoreinfo) < 0) { + error_setg(errp, "dump: failed to vmcoreinfo"); + goto out; + } + } + /* write note */ s->note_buf =3D g_malloc0(s->note_size); s->note_buf_offset =3D 0; --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239276106852.2685240541368; Sat, 11 Mar 2017 05:34:36 -0800 (PST) Received: from localhost ([::1]:43438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmhAI-0002A0-QV for importer@patchew.org; Sat, 11 Mar 2017 08:34:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh0N-0002mm-UI for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmh0N-0002nx-1e for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40578) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmh0M-0002nt-Rw for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:18 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13F0E7E9E1; Sat, 11 Mar 2017 13:24:19 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2BDOGYN017988; Sat, 11 Mar 2017 08:24:18 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:55 +0400 Message-Id: <20170311132256.22951-21-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 11 Mar 2017 13:24:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 20/21] scripts/dump-guest-memory.py: fix int128_get64 on recent gcc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The Int128 is no longer a struct, reaching a python exception: Python Exception Attempt to extract a component of a va= lue that is not a (null).: Replace struct access with a cast to uint64 instead. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1427466 Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/dump-guest-memory.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py index 9956fc036c..f7c6635f15 100644 --- a/scripts/dump-guest-memory.py +++ b/scripts/dump-guest-memory.py @@ -314,8 +314,18 @@ def get_arch_phdr(endianness, elfclass): def int128_get64(val): """Returns low 64bit part of Int128 struct.""" =20 - assert val["hi"] =3D=3D 0 - return val["lo"] + try: + assert val["hi"] =3D=3D 0 + return val["lo"] + except gdb.error: + u64t =3D gdb.lookup_type('uint64_t').array(2) + u64 =3D val.cast(u64t) + if sys.byteorder =3D=3D 'little': + assert u64[1] =3D=3D 0 + return u64[0] + else: + assert u64[0] =3D=3D 0 + return u64[1] =20 =20 def qlist_foreach(head, field_str): --=20 2.12.0.191.gc5d8de91d From nobody Thu Nov 6 14:25:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489239404097128.79416224415206; Sat, 11 Mar 2017 05:36:44 -0800 (PST) Received: from localhost ([::1]:43454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmhCL-000482-I5 for importer@patchew.org; Sat, 11 Mar 2017 08:36:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmh0U-0002sk-V3 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmh0R-0002oV-0e for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47988) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmh0Q-0002oP-O7 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 08:24:22 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E56AF85363; Sat, 11 Mar 2017 13:24:22 +0000 (UTC) Received: from localhost (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C6BC2D655; Sat, 11 Mar 2017 13:24:21 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 17:22:56 +0400 Message-Id: <20170311132256.22951-22-marcandre.lureau@redhat.com> In-Reply-To: <20170311132256.22951-1-marcandre.lureau@redhat.com> References: <20170311132256.22951-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 11 Mar 2017 13:24:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 21/21] scripts/dump-guest-memory.py: add VMCOREINFO X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/dump-guest-memory.py | 52 ++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 52 insertions(+) diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py index f7c6635f15..0ce32b2a3f 100644 --- a/scripts/dump-guest-memory.py +++ b/scripts/dump-guest-memory.py @@ -120,6 +120,33 @@ class ELF(object): self.segments[0].p_filesz +=3D ctypes.sizeof(note) self.segments[0].p_memsz +=3D ctypes.sizeof(note) =20 + + def add_vmcoreinfo_note(self, vmcoreinfo, phys_base=3DNone): + """Adds a vmcoreinfo note to the ELF.""" + chead =3D type(get_arch_note(self.endianness, 0, 0)) + header =3D chead.from_buffer_copy(vmcoreinfo[0:ctypes.sizeof(chead= )]) + note =3D get_arch_note(self.endianness, + header.n_namesz - 1, header.n_descsz) + ctypes.memmove(ctypes.pointer(note), vmcoreinfo, ctypes.sizeof(not= e)) + header_size =3D ctypes.sizeof(note) - header.n_descsz + + if phys_base: + desc =3D bytearray(note.n_desc).decode().split() + if not next((v for v in desc if v.startswith('NUMBER(phys_base= )=3D')), + False): + desc.append('NUMBER(phys_base)=3D%ld' % phys_base) + desc =3D "\n".join(desc) + '\n' + descsz =3D (len(desc) + 3) // 4 * 4 + desc +=3D '\0' * (descsz - len(desc)) + note =3D get_arch_note(self.endianness, header.n_namesz - 1, d= escsz) + ctypes.memmove(ctypes.pointer(note), vmcoreinfo, header_size) + note.n_descsz =3D descsz + ctypes.memmove(note.n_desc, desc.encode(), descsz) + + self.notes.append(note) + self.segments[0].p_filesz +=3D ctypes.sizeof(note) + self.segments[0].p_memsz +=3D ctypes.sizeof(note) + def add_segment(self, p_type, p_paddr, p_size): """Adds a segment to the elf.""" =20 @@ -505,6 +532,30 @@ shape and this command should mostly work.""" cur +=3D chunk_size left -=3D chunk_size =20 + def get_vmcoreinfo(self): + qemu_core =3D gdb.inferiors()[0] + + try: + coreinfo =3D gdb.parse_and_eval("dump_info.vmcoreinfo") + except gdb.error: + return + + if coreinfo =3D=3D 0: + return + + phys_base =3D None + has_phys_base =3D gdb.parse_and_eval("dump_info.has_phys_base") + if has_phys_base: + phys_base =3D int(gdb.parse_and_eval("dump_info.phys_base")) + + addr, size =3D [int(val, 16) for val in coreinfo.string().split()] + for block in self.guest_phys_blocks: + if block["target_start"] <=3D addr < block["target_end"]: + haddr =3D block["host_addr"] + (addr - block["target_start= "]) + vmcoreinfo =3D qemu_core.read_memory(haddr, size) + self.elf.add_vmcoreinfo_note(vmcoreinfo.tobytes(), phys_ba= se) + return + def invoke(self, args, from_tty): """Handles command invocation from gdb.""" =20 @@ -518,6 +569,7 @@ shape and this command should mostly work.""" =20 self.elf =3D ELF(argv[1]) self.guest_phys_blocks =3D get_guest_phys_blocks() + self.get_vmcoreinfo() =20 with open(argv[0], "wb") as vmcore: self.dump_init(vmcore) --=20 2.12.0.191.gc5d8de91d