From patchwork Wed Jun 7 16:36:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 772550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wjZBm6qmTz9s7m for ; Thu, 8 Jun 2017 02:44:00 +1000 (AEST) Received: from localhost ([::1]:45148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIe3q-00045v-JF for incoming@patchwork.ozlabs.org; Wed, 07 Jun 2017 12:43:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdyO-0007WW-He for qemu-devel@nongnu.org; Wed, 07 Jun 2017 12:38:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIdyN-0007Vq-A0 for qemu-devel@nongnu.org; Wed, 07 Jun 2017 12:38:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25258) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIdyN-0007VS-1m for qemu-devel@nongnu.org; Wed, 07 Jun 2017 12:38:19 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15AC95BECB for ; Wed, 7 Jun 2017 16:38:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 15AC95BECB Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 15AC95BECB Received: from localhost (ovpn-112-40.ams2.redhat.com [10.36.112.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11B4E179C4; Wed, 7 Jun 2017 16:38:13 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 20:36:03 +0400 Message-Id: <20170607163635.17635-12-marcandre.lureau@redhat.com> In-Reply-To: <20170607163635.17635-1-marcandre.lureau@redhat.com> References: <20170607163635.17635-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 07 Jun 2017 16:38:18 +0000 (UTC) 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 v3 11/43] qapi: update the qobject visitor to use QNUM_U64 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Switch to use QNum/uint where appropriate to remove i64 limitation. The input visitor will cast i64 input to u64 for compatibility reasons (existing json QMP client already use negative i64 for large u64, and expect an implicit cast in qemu). Note: before the patch, uint64_t values above INT64_MAX are sent over json QMP as negative values, e.g. UINT64_MAX is sent as -1. After the patch, they are sent unmodified. Clearly a bug fix, but we have to consider compatibility issues anyway. libvirt should cope fine, because its parsing of unsigned integers accepts negative values modulo 2^64. There's hope that other clients will, too. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- hw/i386/acpi-build.c | 2 +- qapi/qobject-input-visitor.c | 21 ++++++++++++++++----- qapi/qobject-output-visitor.c | 3 +-- tests/test-qobject-input-visitor.c | 7 ++----- tests/test-qobject-output-visitor.c | 20 ++++++++++++++++---- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index d7d2b65fe4..3eb43677f0 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2614,7 +2614,7 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) if (!o) { return false; } - mcfg->mcfg_base = qnum_get_int(qobject_to_qnum(o)); + mcfg->mcfg_base = qnum_get_uint(qobject_to_qnum(o)); qobject_decref(o); o = object_property_get_qobject(pci_host, PCIE_HOST_MCFG_SIZE, NULL); diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 539b3b825d..35aff78f2b 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -417,7 +417,6 @@ 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_qnum mishandles values over INT64_MAX */ QObjectInputVisitor *qiv = to_qiv(v); QObject *qobj = qobject_input_get_object(qiv, name, true, errp); QNum *qnum; @@ -427,11 +426,23 @@ static void qobject_input_type_uint64(Visitor *v, const char *name, return; } qnum = qobject_to_qnum(qobj); - if (!qnum || !qnum_get_try_int(qnum, &val)) { - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, - full_name(qiv, name), "integer"); + if (!qnum) { + goto err; + } + + if (qnum_get_try_uint(qnum, obj)) { + return; } - *obj = val; + + /* Need to accept negative values for backward compatibility */ + if (qnum_get_try_int(qnum, &val)) { + *obj = val; + return; + } + +err: + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + full_name(qiv, name), "uint64"); } 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 2ca5093b22..70be84ccb5 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 = to_qov(v); - qobject_output_add(qov, name, qnum_from_int(*obj)); + qobject_output_add(qov, name, qnum_from_uint(*obj)); } static void qobject_output_type_bool(Visitor *v, const char *name, bool *obj, diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c index 40a135db89..3bcdb9a045 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -123,7 +123,6 @@ static void test_visitor_in_int(TestInputVisitorData *data, static void test_visitor_in_uint(TestInputVisitorData *data, const void *unused) { - Error *err = NULL; uint64_t res = 0; int64_t i64; double dbl; @@ -147,12 +146,10 @@ static void test_visitor_in_uint(TestInputVisitorData *data, visit_type_uint64(v, NULL, &res, &error_abort); g_assert_cmpuint(res, ==, (uint64_t)-value); - /* BUG: value between INT64_MAX+1 and UINT64_MAX rejected */ - v = visitor_input_test_init(data, "18446744073709551574"); - visit_type_uint64(v, NULL, &res, &err); - error_free_or_abort(&err); + visit_type_uint64(v, NULL, &res, &error_abort); + g_assert_cmpuint(res, ==, 18446744073709551574U); visit_type_number(v, NULL, &dbl, &error_abort); } diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c index a16c8f663f..d23c8eb352 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -602,14 +602,26 @@ static void check_native_list(QObject *qobj, qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data"))); 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 = 0; i < 32; i++) { + QObject *tmp; + QNum *qvalue; + + tmp = qlist_peek(qlist); + g_assert(tmp); + qvalue = qobject_to_qnum(tmp); + g_assert_cmpuint(qnum_get_uint(qvalue), ==, 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 QNums * when we convert to QObjects, so we can check them all in