From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920528; cv=none; d=zoho.com; s=zohoarc; b=e5b8LD1pSrZMyCk7z0d0GEtLg7yK2BUPWZnaXJnX2x98SvmJQzk4YtaSZVENcpbfvF+BpeL0YQTg9lxVErJdyz87hCldTIn0GNsrit6U4XgWlEBvPAIWTnFkdJsiCD+Z5CB4ZXYMZW94HgNsn7yNLFnWCbEPCWDTOWa7Pa+lPxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920528; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DLJveUk/5+so2mFcEtyabzzrYOLY4y2ZHCF2VE4IX9Q=; b=RfmDPp4VWzkgEJNSmWl1OLql85h8bXaz7HdZnTxR5RvU3NJXh5Z5byq8Sn/++MYiNm8mKsqPXURkb2IDaqBI+hAx1bmnBEoAz36yknt6ZhLLqxF/7HGxHw/AzMlYx6ESlGVXAnK2uE0XxSN/QmEbcn5ccJGk7P4rXqovAbX5nFk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 15719205282841016.7951926437335; Thu, 24 Oct 2019 05:35:28 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-12-WJWlhMBPOCiwkZ2k--YIrw-1; Thu, 24 Oct 2019 08:35:24 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E787F801E72; Thu, 24 Oct 2019 12:35:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B75C15DC1E; Thu, 24 Oct 2019 12:35:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 640984E9F5; Thu, 24 Oct 2019 12:35:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ4Zb004437 for ; Thu, 24 Oct 2019 08:35:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 49B1052E7; Thu, 24 Oct 2019 12:35:04 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8941752F6; Thu, 24 Oct 2019 12:35:01 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F232911384A8; Thu, 24 Oct 2019 14:34:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920527; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DLJveUk/5+so2mFcEtyabzzrYOLY4y2ZHCF2VE4IX9Q=; b=bM6mVPapolfunUf9ZHyI6uCp7JSO0XAsLSUXHzfxYUT5qkJGS9YsYoptaAbmzUkGe7M2rM N1IxLn4zzsLAQdCf9EWpqJDTXj1EbSJjm4aKNCxc215g0RThtx0EIARIQrFdXd4xfxeT+K cW6KMIzWJF4fKQivq8XTui8XmrMgjHw= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:40 +0200 Message-Id: <20191024123458.13505-2-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 01/19] tests/test-qmp-cmds: Factor out qmp_dispatch() test helpers X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: WJWlhMBPOCiwkZ2k--YIrw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Checking the value of qmp_dispatch() is repetitive. Factor out helpers do_qmp_dispatch() and do_qmp_dispatch_error(). Without this, the next commit would make things even more repetitive. Signed-off-by: Markus Armbruster --- tests/test-qmp-cmds.c | 72 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 27b0afe55a..e738bead86 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -144,34 +144,55 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_q= emu_x_EnumList *a, } =20 =20 +static QObject *do_qmp_dispatch(QDict *req, bool allow_oob) +{ + QDict *resp; + QObject *ret; + + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); + g_assert(resp && !qdict_haskey(resp, "error")); + ret =3D qdict_get(resp, "return"); + g_assert(ret); + + qobject_ref(ret); + qobject_unref(resp); + return ret; +} + +static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass c= ls) +{ + QDict *resp; + + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); + g_assert(resp && qdict_haskey(resp, "error")); + + qobject_unref(resp); +} + /* test commands with no input and no return value */ static void test_dispatch_cmd(void) { QDict *req =3D qdict_new(); - QDict *resp; + QObject *ret; =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp !=3D NULL); - assert(!qdict_haskey(resp, "error")); + ret =3D do_qmp_dispatch(req, false); =20 - qobject_unref(resp); + qobject_unref(ret); qobject_unref(req); } =20 static void test_dispatch_cmd_oob(void) { QDict *req =3D qdict_new(); - QDict *resp; + QObject *ret; =20 qdict_put_str(req, "exec-oob", "test-flags-command"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), true); - assert(resp !=3D NULL); - assert(!qdict_haskey(resp, "error")); + ret =3D do_qmp_dispatch(req, true); =20 - qobject_unref(resp); + qobject_unref(ret); qobject_unref(req); } =20 @@ -180,15 +201,11 @@ static void test_dispatch_cmd_failure(void) { QDict *req =3D qdict_new(); QDict *args =3D qdict_new(); - QDict *resp; =20 qdict_put_str(req, "execute", "user_def_cmd2"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp !=3D NULL); - assert(qdict_haskey(resp, "error")); + do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); =20 - qobject_unref(resp); qobject_unref(req); =20 /* check that with extra arguments it throws an error */ @@ -198,11 +215,8 @@ static void test_dispatch_cmd_failure(void) =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp !=3D NULL); - assert(qdict_haskey(resp, "error")); + do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); =20 - qobject_unref(resp); qobject_unref(req); } =20 @@ -217,20 +231,6 @@ static void test_dispatch_cmd_success_response(void) qobject_unref(req); } =20 -static QObject *test_qmp_dispatch(QDict *req) -{ - QDict *resp; - QObject *ret; - - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp && !qdict_haskey(resp, "error")); - ret =3D qdict_get(resp, "return"); - assert(ret); - qobject_ref(ret); - qobject_unref(resp); - return ret; -} - /* test commands that involve both input parameters and return values */ static void test_dispatch_cmd_io(void) { @@ -253,7 +253,7 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args); qdict_put_str(req, "execute", "user_def_cmd2"); =20 - ret =3D qobject_to(QDict, test_qmp_dispatch(req)); + ret =3D qobject_to(QDict, do_qmp_dispatch(req, false)); =20 assert(!strcmp(qdict_get_str(ret, "string0"), "blah1")); ret_dict =3D qdict_get_qdict(ret, "dict1"); @@ -274,12 +274,10 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args3); qdict_put_str(req, "execute", "guest-get-time"); =20 - ret3 =3D qobject_to(QNum, test_qmp_dispatch(req)); + ret3 =3D qobject_to(QNum, do_qmp_dispatch(req, false)); g_assert(qnum_get_try_int(ret3, &val)); g_assert_cmpint(val, =3D=3D, 66); qobject_unref(ret3); - - qobject_unref(req); } =20 /* test generated dealloc functions for generated types */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920565; cv=none; d=zoho.com; s=zohoarc; b=j7NuWIPmwlrhrkQNrVDxJ/fpnjhST4sJ2ROLBHpPFOWhQdbUUcMFUnHOMq2gr/L2eo80JE13GCzAhx39cjsS594fWM3e2QI5nK4dNkyRYSueEUhGIJmql3Kh0LcnZ/kiSiNnv1PiLX86YlD6fk6PCCwNHgthcgZuTa2m13ejCB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920565; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dU2XoTJ4m/a8b3lR5vsCkZOIiDIoj5s6Dt+7GmcMY/w=; b=hzCm7vrdva3HoB8LYLP5px8IFRbFlpej4jrjdq8gENRv+Z8kv59usW3oSM/E27PL+SPMWyT4wxg1hir3O9r1dNLKjodw7rpUGuZ2s3eNHKSuLTVfxcsOW+MIhYdCMPIDygTZlieFj8dnp8NRAlect/bMGnXNZeNNFDz7S35xd2Q= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571920565145952.0445648813512; Thu, 24 Oct 2019 05:36:05 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-136-FhvxDVNaO2qSHVafk0WK8A-1; Thu, 24 Oct 2019 08:35:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 705D05FC; Thu, 24 Oct 2019 12:35:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F1D56012E; Thu, 24 Oct 2019 12:35:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E4DC51803B4E; Thu, 24 Oct 2019 12:35:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ4x2004442 for ; Thu, 24 Oct 2019 08:35:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id E89C05DC1E; Thu, 24 Oct 2019 12:35:04 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8B28B5D9CA; Thu, 24 Oct 2019 12:35:00 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 00DB31133034; Thu, 24 Oct 2019 14:34:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920563; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dU2XoTJ4m/a8b3lR5vsCkZOIiDIoj5s6Dt+7GmcMY/w=; b=WCkZiEYyqD1f5Arxj0U9AGppthS4JUjs8CgZjncX/fpo/iqK15oqXOMXrBpi9t++pnXgAE yWVI3mA5ulgjOkcBpFZLAG8sdhUKRQblxHVkQC60HcZfOE6q3z6hFYXAduD2VnKViKtHYm KpK4hWYxjeSONm2biIMMe5oTnLyyqt8= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:41 +0200 Message-Id: <20191024123458.13505-3-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 02/19] tests/test-qmp-cmds: Check responses more thoroughly X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: FhvxDVNaO2qSHVafk0WK8A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster --- tests/test-qmp-cmds.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index e738bead86..667e03cb1b 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -150,9 +150,10 @@ static QObject *do_qmp_dispatch(QDict *req, bool allow= _oob) QObject *ret; =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); - g_assert(resp && !qdict_haskey(resp, "error")); + g_assert(resp); ret =3D qdict_get(resp, "return"); g_assert(ret); + g_assert(qdict_size(resp) =3D=3D 1); =20 qobject_ref(ret); qobject_unref(resp); @@ -162,9 +163,17 @@ static QObject *do_qmp_dispatch(QDict *req, bool allow= _oob) static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass c= ls) { QDict *resp; + QDict *error; =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); - g_assert(resp && qdict_haskey(resp, "error")); + g_assert(resp); + error =3D qdict_get_qdict(resp, "error"); + g_assert(error); + g_assert_cmpstr(qdict_get_try_str(error, "class"), + =3D=3D, QapiErrorClass_str(cls)); + g_assert(qdict_get_try_str(error, "desc")); + g_assert(qdict_size(error) =3D=3D 2); + g_assert(qdict_size(resp) =3D=3D 1); =20 qobject_unref(resp); } @@ -173,11 +182,12 @@ static void do_qmp_dispatch_error(QDict *req, bool al= low_oob, ErrorClass cls) static void test_dispatch_cmd(void) { QDict *req =3D qdict_new(); - QObject *ret; + QDict *ret; =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - ret =3D do_qmp_dispatch(req, false); + ret =3D qobject_to(QDict, do_qmp_dispatch(req, false)); + assert(ret && qdict_size(ret) =3D=3D 0); =20 qobject_unref(ret); qobject_unref(req); @@ -186,11 +196,12 @@ static void test_dispatch_cmd(void) static void test_dispatch_cmd_oob(void) { QDict *req =3D qdict_new(); - QObject *ret; + QDict *ret; =20 qdict_put_str(req, "exec-oob", "test-flags-command"); =20 - ret =3D do_qmp_dispatch(req, true); + ret =3D qobject_to(QDict, do_qmp_dispatch(req, true)); + assert(ret && qdict_size(ret) =3D=3D 0); =20 qobject_unref(ret); qobject_unref(req); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920517; cv=none; d=zoho.com; s=zohoarc; b=nhUU55ByMaBixUtf90rOMJ5Ood3nIcL1y32WnPj9qhEdneqNDg3+1aBNxbVFjzur3qH8Pe5fnehNYTjjlv5CdgaSxUHIre846OODcE1lRyIXlZ0qUd9WxFLYPGZdKt9WWlhqXx1aVNjTQRvN26UYUb8jKwaV96+LIrr9KXh8zO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920517; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7zqnbAE5N7BdnLdZXmqhSc52WToIyp0Xrdfz+3woMlA=; b=N7C2yfAF1Eg+FTUrZAUCJD3xsGGzD8fZnvbkHr8R4pkg4i5lqdFAqdYEXML/9wvK/PEDLDuj60EO0w0ZxZZhlbK2+Ah4vP2Am4AA1XxSMxr8nFVITGIH3Aw35bxXSf6oBCxeTu3vucJLHkYuOQhbH6JIq5RlSFIrN79udWqlVHk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571920517064723.2642827185102; Thu, 24 Oct 2019 05:35:17 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-254-QZLICSKbPNWYLQxD5T_Lhw-1; Thu, 24 Oct 2019 08:35:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CB86107AD31; Thu, 24 Oct 2019 12:35:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C146660167; Thu, 24 Oct 2019 12:35:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 35AFB18005A0; Thu, 24 Oct 2019 12:35:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ37R004415 for ; Thu, 24 Oct 2019 08:35:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4B61E1C93D; Thu, 24 Oct 2019 12:35:03 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8EB6A19D70; Thu, 24 Oct 2019 12:35:00 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 045121132D6D; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920516; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7zqnbAE5N7BdnLdZXmqhSc52WToIyp0Xrdfz+3woMlA=; b=BYXruw6dfLwgEG8k7A/jaoobIx8iPqdTDRcRCZv5hkLBf48zJLOEFMAdPzrMk2gmemkoBs XRMnbrLXkDqxqZ/GLS03vzrU/ncGllTtoUOgmg9bwNKemrZc5BTKUMInb6XlZHFtiDxFQu imynBTxi4nM5bImPwzFEkQkkPucvlSY= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:42 +0200 Message-Id: <20191024123458.13505-4-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 03/19] tests/test-qmp-cmds: Simplify test data setup X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: QZLICSKbPNWYLQxD5T_Lhw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Building requests with qdict_put() & friends is tedious to write and hard to read. Parse them from string literals with qdict_from_vjsonf_nofail() instead. Signed-off-by: Markus Armbruster --- tests/test-qmp-cmds.c | 93 ++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 55 deletions(-) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 667e03cb1b..3798ba1b16 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -1,5 +1,6 @@ #include "qemu/osdep.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" #include "qapi/error.h" @@ -144,11 +145,16 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_q= emu_x_EnumList *a, } =20 =20 -static QObject *do_qmp_dispatch(QDict *req, bool allow_oob) +static QObject *do_qmp_dispatch(bool allow_oob, const char *template, ...) { - QDict *resp; + va_list ap; + QDict *req, *resp; QObject *ret; =20 + va_start(ap, template); + req =3D qdict_from_vjsonf_nofail(template, ap); + va_end(ap); + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); g_assert(resp); ret =3D qdict_get(resp, "return"); @@ -157,14 +163,21 @@ static QObject *do_qmp_dispatch(QDict *req, bool allo= w_oob) =20 qobject_ref(ret); qobject_unref(resp); + qobject_unref(req); return ret; } =20 -static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass c= ls) +static void do_qmp_dispatch_error(bool allow_oob, ErrorClass cls, + const char *template, ...) { - QDict *resp; + va_list ap; + QDict *req, *resp; QDict *error; =20 + va_start(ap, template); + req =3D qdict_from_vjsonf_nofail(template, ap); + va_end(ap); + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); g_assert(resp); error =3D qdict_get_qdict(resp, "error"); @@ -176,59 +189,43 @@ static void do_qmp_dispatch_error(QDict *req, bool al= low_oob, ErrorClass cls) g_assert(qdict_size(resp) =3D=3D 1); =20 qobject_unref(resp); + qobject_unref(req); } =20 /* test commands with no input and no return value */ static void test_dispatch_cmd(void) { - QDict *req =3D qdict_new(); QDict *ret; =20 - qdict_put_str(req, "execute", "user_def_cmd"); - - ret =3D qobject_to(QDict, do_qmp_dispatch(req, false)); + ret =3D qobject_to(QDict, + do_qmp_dispatch(false, + "{ 'execute': 'user_def_cmd' }")); assert(ret && qdict_size(ret) =3D=3D 0); - qobject_unref(ret); - qobject_unref(req); } =20 static void test_dispatch_cmd_oob(void) { - QDict *req =3D qdict_new(); QDict *ret; =20 - qdict_put_str(req, "exec-oob", "test-flags-command"); - - ret =3D qobject_to(QDict, do_qmp_dispatch(req, true)); + ret =3D qobject_to(QDict, + do_qmp_dispatch(true, + "{ 'exec-oob': 'test-flags-command' }= ")); assert(ret && qdict_size(ret) =3D=3D 0); - qobject_unref(ret); - qobject_unref(req); } =20 /* test commands that return an error due to invalid parameters */ static void test_dispatch_cmd_failure(void) { - QDict *req =3D qdict_new(); - QDict *args =3D qdict_new(); - - qdict_put_str(req, "execute", "user_def_cmd2"); - - do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); - - qobject_unref(req); - - /* check that with extra arguments it throws an error */ - req =3D qdict_new(); - qdict_put_int(args, "a", 66); - qdict_put(req, "arguments", args); - - qdict_put_str(req, "execute", "user_def_cmd"); - - do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); - - qobject_unref(req); + /* missing arguments */ + do_qmp_dispatch_error(false, ERROR_CLASS_GENERIC_ERROR, + "{ 'execute': 'user_def_cmd2' }"); + + /* extra arguments */ + do_qmp_dispatch_error(false, ERROR_CLASS_GENERIC_ERROR, + "{ 'execute': 'user_def_cmd'," + " 'arguments': { 'a': 66 } }"); } =20 static void test_dispatch_cmd_success_response(void) @@ -245,26 +242,15 @@ static void test_dispatch_cmd_success_response(void) /* test commands that involve both input parameters and return values */ static void test_dispatch_cmd_io(void) { - QDict *req =3D qdict_new(); - QDict *args =3D qdict_new(); - QDict *args3 =3D qdict_new(); - QDict *ud1a =3D qdict_new(); - QDict *ud1b =3D qdict_new(); QDict *ret, *ret_dict, *ret_dict_dict, *ret_dict_dict_userdef; QDict *ret_dict_dict2, *ret_dict_dict2_userdef; QNum *ret3; int64_t val; =20 - qdict_put_int(ud1a, "integer", 42); - qdict_put_str(ud1a, "string", "hello"); - qdict_put_int(ud1b, "integer", 422); - qdict_put_str(ud1b, "string", "hello2"); - qdict_put(args, "ud1a", ud1a); - qdict_put(args, "ud1b", ud1b); - qdict_put(req, "arguments", args); - qdict_put_str(req, "execute", "user_def_cmd2"); - - ret =3D qobject_to(QDict, do_qmp_dispatch(req, false)); + ret =3D qobject_to(QDict, do_qmp_dispatch(false, + "{ 'execute': 'user_def_cmd2', 'arguments': {" + " 'ud1a': { 'integer': 42, 'string': 'hello' }," + " 'ud1b': { 'integer': 422, 'string': 'hello2' } } }")); =20 assert(!strcmp(qdict_get_str(ret, "string0"), "blah1")); ret_dict =3D qdict_get_qdict(ret, "dict1"); @@ -281,11 +267,8 @@ static void test_dispatch_cmd_io(void) assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4")); qobject_unref(ret); =20 - qdict_put_int(args3, "a", 66); - qdict_put(req, "arguments", args3); - qdict_put_str(req, "execute", "guest-get-time"); - - ret3 =3D qobject_to(QNum, do_qmp_dispatch(req, false)); + ret3 =3D qobject_to(QNum, do_qmp_dispatch(false, + "{ 'execute': 'guest-get-time', 'arguments': { 'a': 66 } }")); g_assert(qnum_get_try_int(ret3, &val)); g_assert_cmpint(val, =3D=3D, 66); qobject_unref(ret3); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920516; cv=none; d=zoho.com; s=zohoarc; b=c8o+iYj8fgLoKJ9YqXPBh/SiCKgmfyGXgnUIdZMUIjaPFDCGDAAvMUE0XeLrBkflQwb5+iTawcAUJ22165S8ZRJDm8F6zO0NXchz/lIZVMJ4NDlPD6wPKFLDhnmBArLkrhQKBCFV4X9GOtyUV78ImFBm2yJ8ocpU/fYT3WNKats= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920516; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DspOsyKL4USxqqd8/YpMwH4nnbIzknsvsMSb3mb0gwU=; b=K1EYIjFq1Jtc8AUCH+kX0raDx2Q5wgg4iBt7x10f5ytEHUW5G5Stv8cd2KAKcfzTQPMsGUosaNr/6McKfS7OEtWOLpHvOrreGIX/dzm1j9FaOiamSfQEj+0y1fHXbrprWJhW7co/CcuPibC7nh8NMoLOK2L7K+2oq0V4NrKQBf0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571920516341686.2638669467049; Thu, 24 Oct 2019 05:35:16 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-112-e6Nt8fBZMC6DCKrZObgeiQ-1; Thu, 24 Oct 2019 08:35:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B6E11800D6B; Thu, 24 Oct 2019 12:35:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDE1E60161; Thu, 24 Oct 2019 12:35:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 663D81808878; Thu, 24 Oct 2019 12:35:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ3ar004414 for ; Thu, 24 Oct 2019 08:35:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4AF735792; Thu, 24 Oct 2019 12:35:03 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F7CB4523; Thu, 24 Oct 2019 12:35:00 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 078BA1132A05; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920515; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DspOsyKL4USxqqd8/YpMwH4nnbIzknsvsMSb3mb0gwU=; b=eG1PjgRSCBL2kDrh+FN2k85w+ePkTjWCqOLuLRAg9yq5b3YoSX3jTdjvy77JbPBxIXstuJ e9HZtKxca7e1k2yYyQpFPc7rTjauuU44uTzfZe7zazqDrfE6vLzQrcBtkahN0BUFfufpi0 Yv71xrmsQjoN1mpEtmNZML6zJXSqe5g= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:43 +0200 Message-Id: <20191024123458.13505-5-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 04/19] tests/test-qmp-event: Simplify test data setup X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: e6Nt8fBZMC6DCKrZObgeiQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Building expected data with qdict_put() & friends is tedious to write and hard to read. Parse them from string literals with qdict_from_jsonf_nofail() instead. While there, use initializers instead of assignments for initializing aggregate event arguments. Signed-off-by: Markus Armbruster --- tests/test-qmp-event.c | 93 ++++++++++++------------------------------ 1 file changed, 27 insertions(+), 66 deletions(-) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index eee7e08ab6..430001e622 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -17,6 +17,7 @@ #include "qapi/error.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" #include "qapi/qmp-event.h" @@ -124,17 +125,13 @@ static void event_prepare(TestEventData *data, /* Global variable test_event_data was used to pass the expectation, so test cases can't be executed at same time. */ g_mutex_lock(&test_event_lock); - - data->expect =3D qdict_new(); test_event_data =3D data; } =20 static void event_teardown(TestEventData *data, const void *unused) { - qobject_unref(data->expect); test_event_data =3D NULL; - g_mutex_unlock(&test_event_lock); } =20 @@ -152,90 +149,54 @@ static void event_test_add(const char *testpath, static void test_event_a(TestEventData *data, const void *unused) { - QDict *d; - d =3D data->expect; - qdict_put_str(d, "event", "EVENT_A"); + data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'EVENT_A' }"); qapi_event_send_event_a(); + qobject_unref(data->expect); } =20 static void test_event_b(TestEventData *data, const void *unused) { - QDict *d; - d =3D data->expect; - qdict_put_str(d, "event", "EVENT_B"); + data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'EVENT_B' }"); qapi_event_send_event_b(); + qobject_unref(data->expect); } =20 static void test_event_c(TestEventData *data, const void *unused) { - QDict *d, *d_data, *d_b; - - UserDefOne b; - b.integer =3D 2; - b.string =3D g_strdup("test1"); - b.has_enum1 =3D false; - - d_b =3D qdict_new(); - qdict_put_int(d_b, "integer", 2); - qdict_put_str(d_b, "string", "test1"); - - d_data =3D qdict_new(); - qdict_put_int(d_data, "a", 1); - qdict_put(d_data, "b", d_b); - qdict_put_str(d_data, "c", "test2"); - - d =3D data->expect; - qdict_put_str(d, "event", "EVENT_C"); - qdict_put(d, "data", d_data); + UserDefOne b =3D { .integer =3D 2, .string =3D (char *)"test1" }; =20 + data->expect =3D qdict_from_jsonf_nofail( + "{ 'event': 'EVENT_C', 'data': {" + " 'a': 1, 'b': { 'integer': 2, 'string': 'test1' }, 'c': 'test2' }= }"); qapi_event_send_event_c(true, 1, true, &b, "test2"); - - g_free(b.string); + qobject_unref(data->expect); } =20 /* Complex type */ static void test_event_d(TestEventData *data, const void *unused) { - UserDefOne struct1; - EventStructOne a; - QDict *d, *d_data, *d_a, *d_struct1; - - struct1.integer =3D 2; - struct1.string =3D g_strdup("test1"); - struct1.has_enum1 =3D true; - struct1.enum1 =3D ENUM_ONE_VALUE1; - - a.struct1 =3D &struct1; - a.string =3D g_strdup("test2"); - a.has_enum2 =3D true; - a.enum2 =3D ENUM_ONE_VALUE2; - - d_struct1 =3D qdict_new(); - qdict_put_int(d_struct1, "integer", 2); - qdict_put_str(d_struct1, "string", "test1"); - qdict_put_str(d_struct1, "enum1", "value1"); - - d_a =3D qdict_new(); - qdict_put(d_a, "struct1", d_struct1); - qdict_put_str(d_a, "string", "test2"); - qdict_put_str(d_a, "enum2", "value2"); - - d_data =3D qdict_new(); - qdict_put(d_data, "a", d_a); - qdict_put_str(d_data, "b", "test3"); - qdict_put_str(d_data, "enum3", "value3"); - - d =3D data->expect; - qdict_put_str(d, "event", "EVENT_D"); - qdict_put(d, "data", d_data); + UserDefOne struct1 =3D { + .integer =3D 2, .string =3D (char *)"test1", + .has_enum1 =3D true, .enum1 =3D ENUM_ONE_VALUE1, + }; + EventStructOne a =3D { + .struct1 =3D &struct1, + .string =3D (char *)"test2", + .has_enum2 =3D true, + .enum2 =3D ENUM_ONE_VALUE2, + }; =20 + data->expect =3D qdict_from_jsonf_nofail( + "{ 'event': 'EVENT_D', 'data': {" + " 'a': {" + " 'struct1': { 'integer': 2, 'string': 'test1', 'enum1': 'value1'= }," + " 'string': 'test2', 'enum2': 'value2' }," + " 'b': 'test3', 'enum3': 'value3' } }"); qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE= 3); - - g_free(struct1.string); - g_free(a.string); + qobject_unref(data->expect); } =20 int main(int argc, char **argv) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920575; cv=none; d=zoho.com; s=zohoarc; b=Wh3gGgU7449eJLIwY5QmpfBS2zxV2+4/E/6Bfa0kzQ6O90GVKg3PfX/TLkpIyYa8iuVnCJ2zkmlJa6eYgCUi9mpWQ216ILWa13niNpPTJm5eodK492HJtrp+WsCAh1P2YxOveXMKfh7gxPbP7Ip6Qcv15Gx1brAsRnDljKrbMZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920575; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qttYAVcbzkdYQDZAi6glGKbPwGV0HBaTENnCmVlB8UU=; b=X7yTaM3sqZr2wjzeh8XQmvp9ZOwEEqTrBB05sXwyLlMqaMBiJZV6Cs0v5JU4CmCQ6UUtbSu0/885pQreqGLtV9ya2HJNkPXBmHOdBrFNRDqzusSu2MYb+qgaTm0kOkmzgaMbR9fcRCVJGh0i8rLSUWhr5mRU+FmThPDu1PJAryc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571920575743612.2341381344278; Thu, 24 Oct 2019 05:36:15 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-314-UUp4RtXWMz2ixZWIk5VSzQ-1; Thu, 24 Oct 2019 08:35:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B4A11801E78; Thu, 24 Oct 2019 12:35:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 835CD601AF; Thu, 24 Oct 2019 12:35:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 29B99180B761; Thu, 24 Oct 2019 12:35:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZBBl004547 for ; Thu, 24 Oct 2019 08:35:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 69B8C5D70E; Thu, 24 Oct 2019 12:35:11 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A45485D712; Thu, 24 Oct 2019 12:35:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0A9451132A0B; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920574; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qttYAVcbzkdYQDZAi6glGKbPwGV0HBaTENnCmVlB8UU=; b=RYc1j6dd7c04EXzMP0nlfzaJaJfwQG3NI723e/n1CuUeBIqf25woapgQZjjRlK/vStGPc8 SjOdfFrqhyopU7iJDnbP5qDDXs26zE71Lw6yzABy6pCuWX/yScMZFfOP18T7iJ2Vw+jjlD nShYf/5HzV0H81o0iHr4ECMal4+pjVQ= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:44 +0200 Message-Id: <20191024123458.13505-6-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 05/19] tests/test-qmp-event: Use qobject_is_equal() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: UUp4RtXWMz2ixZWIk5VSzQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Locally defined helper qdict_cmp_simple() implements just enough of a comparison to serve here. Replace it by qobject_is_equal(), which implements all of it. Signed-off-by: Markus Armbruster --- tests/test-qmp-event.c | 66 +----------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 430001e622..d64066139c 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -28,73 +28,9 @@ typedef struct TestEventData { QDict *expect; } TestEventData; =20 -typedef struct QDictCmpData { - QDict *expect; - bool result; -} QDictCmpData; - TestEventData *test_event_data; static GMutex test_event_lock; =20 -/* Only compares bool, int, string */ -static -void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque) - -{ - QObject *obj2; - QDictCmpData d_new, *d =3D opaque; - int64_t val1, val2; - - if (!d->result) { - return; - } - - obj2 =3D qdict_get(d->expect, key); - if (!obj2) { - d->result =3D false; - return; - } - - if (qobject_type(obj1) !=3D qobject_type(obj2)) { - d->result =3D false; - return; - } - - switch (qobject_type(obj1)) { - case QTYPE_QBOOL: - d->result =3D (qbool_get_bool(qobject_to(QBool, obj1)) =3D=3D - qbool_get_bool(qobject_to(QBool, obj2))); - return; - case QTYPE_QNUM: - g_assert(qnum_get_try_int(qobject_to(QNum, obj1), &val1)); - g_assert(qnum_get_try_int(qobject_to(QNum, obj2), &val2)); - d->result =3D val1 =3D=3D val2; - return; - case QTYPE_QSTRING: - d->result =3D g_strcmp0(qstring_get_str(qobject_to(QString, obj1)), - qstring_get_str(qobject_to(QString, obj2))) = =3D=3D 0; - return; - case QTYPE_QDICT: - d_new.expect =3D qobject_to(QDict, obj2); - d_new.result =3D true; - qdict_iter(qobject_to(QDict, obj1), qdict_cmp_do_simple, &d_new); - d->result =3D d_new.result; - return; - default: - abort(); - } -} - -static bool qdict_cmp_simple(QDict *a, QDict *b) -{ - QDictCmpData d; - - d.expect =3D b; - d.result =3D true; - qdict_iter(a, qdict_cmp_do_simple, &d); - return d.result; -} - void test_qapi_event_emit(test_QAPIEvent event, QDict *d) { QDict *t; @@ -115,7 +51,7 @@ void test_qapi_event_emit(test_QAPIEvent event, QDict *d) =20 qdict_del(d, "timestamp"); =20 - g_assert(qdict_cmp_simple(d, test_event_data->expect)); + g_assert(qobject_is_equal(QOBJECT(d), QOBJECT(test_event_data->expect)= )); =20 } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920537; cv=none; d=zoho.com; s=zohoarc; b=CeFLeJTKS/jEk3x1au1mOkrUX0jQPdo3AC7X8pan6OXqp74z3fBhWKMyJM/8EVCBXoZUdym1zq1PkWgLrXTmZt7+mVwULhE5wBGrDasqGj5ngH6BJ4ezu+q88j/FF5obKudnHExYa3gAHHvD2tdoDNaNSaSVcnFWCM1shwEHaHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920537; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bXjbKhR/mSNYfKWITs3+za+ifJ7QMAFLPekueGtoBRE=; b=eGb0c70miS9sxQBNWdGqxJm4L89Bz48sRvqyFgpCmzgOvPDIB8OQs0nz4rP3J95X8jaPHOTrSSCkkzja/9Bp1NY6EGiIiwrbm7cM+9FEGqzrGKFvHwjmJhdSV5/dUf2LKIxI+RJnP8vdEgVwwycEt/0l0Lf1D0RSX+qXcrH957Y= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571920537604148.45269349998136; Thu, 24 Oct 2019 05:35:37 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306-3TSvgXz-OImt9vqqpglsvQ-1; Thu, 24 Oct 2019 08:35:33 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 204FE107AD3F; Thu, 24 Oct 2019 12:35:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC22410098FB; Thu, 24 Oct 2019 12:35:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AA527180BA9B; Thu, 24 Oct 2019 12:35:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZC37004561 for ; Thu, 24 Oct 2019 08:35:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9854D6012E; Thu, 24 Oct 2019 12:35:12 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5FF660126; Thu, 24 Oct 2019 12:35:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0DAE111329CF; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920534; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bXjbKhR/mSNYfKWITs3+za+ifJ7QMAFLPekueGtoBRE=; b=getvwmXPJpUPiud0fSsx8HN2WgSN0n5HRna15qAyT0iKkMrDkH3ciH0d/CSV4JltCBwTA9 GluGB84pioRWlHpo5+7I5gDeCWK8iTb7vaAInl1r13b1qFVslZ0F3WmeY349KukL46AFxo 7tXCYj1iWvZioXO5zy68VhKm3iM8Olo= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:45 +0200 Message-Id: <20191024123458.13505-7-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 06/19] tests/test-qmp-event: Check event is actually emitted X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 3TSvgXz-OImt9vqqpglsvQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster --- tests/test-qmp-event.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index d64066139c..7dd0053190 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -26,6 +26,7 @@ =20 typedef struct TestEventData { QDict *expect; + bool emitted; } TestEventData; =20 TestEventData *test_event_data; @@ -52,7 +53,7 @@ void test_qapi_event_emit(test_QAPIEvent event, QDict *d) qdict_del(d, "timestamp"); =20 g_assert(qobject_is_equal(QOBJECT(d), QOBJECT(test_event_data->expect)= )); - + test_event_data->emitted =3D true; } =20 static void event_prepare(TestEventData *data, @@ -87,6 +88,7 @@ static void test_event_a(TestEventData *data, { data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'EVENT_A' }"); qapi_event_send_event_a(); + g_assert(data->emitted); qobject_unref(data->expect); } =20 @@ -95,6 +97,7 @@ static void test_event_b(TestEventData *data, { data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'EVENT_B' }"); qapi_event_send_event_b(); + g_assert(data->emitted); qobject_unref(data->expect); } =20 @@ -107,6 +110,7 @@ static void test_event_c(TestEventData *data, "{ 'event': 'EVENT_C', 'data': {" " 'a': 1, 'b': { 'integer': 2, 'string': 'test1' }, 'c': 'test2' }= }"); qapi_event_send_event_c(true, 1, true, &b, "test2"); + g_assert(data->emitted); qobject_unref(data->expect); } =20 @@ -132,6 +136,7 @@ static void test_event_d(TestEventData *data, " 'string': 'test2', 'enum2': 'value2' }," " 'b': 'test3', 'enum3': 'value3' } }"); qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE= 3); + g_assert(data->emitted); qobject_unref(data->expect); } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920584; cv=none; d=zoho.com; s=zohoarc; b=AbP8cPOwmbVzOrhfoQq8stqqcKFBkuODHfr3uerlZXB2/K4ijYl8W/1Qfcc47nuqQxJPxz6tSBvpEHe4HCZM8cNRJ8JbbwXpHCmS5XrZdEEdLKQnI/KG32PzLVzhphGmBDD0z407H7j/eaVeyDbOknTzamw7k/pmDHyjxLjvDXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920584; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GR1wMhhJ6CIlkZ+/6SMpsjbayaS4u/9QKeLwa/TmwJY=; b=oK+T9Oe1wqNVeXSAhYIcLcH/b//4lx7vNWFY7msFvll89imcfvWS8rPA34z2BwBOIPl0E/WBP6X/h6CnfnnqbznCXfzWkQytW3FhtJNrodNmyO+haBrtmTdMRHaRi0HpDFNJZhUmnDypK6Sb8JlKy0Fzk2qNED407O31cs4w7qU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 157192058492429.584460840040265; Thu, 24 Oct 2019 05:36:24 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-10-xGHKcjpcNv-doHt9UzEMAQ-1; Thu, 24 Oct 2019 08:35:39 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F174F801E74; Thu, 24 Oct 2019 12:35:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5DBD52F6; Thu, 24 Oct 2019 12:35:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 75A764EEBA; Thu, 24 Oct 2019 12:35:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZA10004540 for ; Thu, 24 Oct 2019 08:35:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id E9B965C223; Thu, 24 Oct 2019 12:35:10 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A87125C222; Thu, 24 Oct 2019 12:35:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 114AA1132986; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920583; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GR1wMhhJ6CIlkZ+/6SMpsjbayaS4u/9QKeLwa/TmwJY=; b=PbvoMwEXg6cJnAPZPv12DwjyzAAb1cu3v7fzvscgwMQB/vJkN2XfLWGPxW+PXBiDSsT5vI fR6Vgb1+DLf1MCtZ8AoMiZDFlT4YT+lrUE29lW+OsDiroSdlR4lD8iJM1EyjXhiYl4B+0A AXN55Vc2bXUUbKJlY6BnxWICnvwTaVU= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:46 +0200 Message-Id: <20191024123458.13505-8-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 07/19] qapi: Add feature flags to remaining definitions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: xGHKcjpcNv-doHt9UzEMAQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In v4.1.0, we added feature flags just to struct types (commit 6a8c0b5102^..f3ed93d545), to satisfy an immediate need (commit c9d4070991 "file-posix: Add dynamic-auto-read-only QAPI feature"). We just added them to commands (commit 23394b4c39 "qapi: Add feature flags to commands") to satisfy another immediate need (commit d76744e65e "qapi: Allow introspecting fix for savevm's cooperation with blockdev"). Add them to the remaining definitions: enumeration types, union types, alternate types, and events. Signed-off-by: Markus Armbruster --- docs/devel/qapi-code-gen.txt | 15 ++-- tests/qapi-schema/doc-good.texi | 32 ++++++++- qapi/introspect.json | 28 +++++--- tests/test-qmp-cmds.c | 6 +- scripts/qapi/doc.py | 6 +- scripts/qapi/events.py | 2 +- scripts/qapi/expr.py | 11 ++- scripts/qapi/introspect.py | 31 ++++---- scripts/qapi/schema.py | 96 ++++++++++++++----------- scripts/qapi/types.py | 4 +- scripts/qapi/visit.py | 4 +- tests/qapi-schema/alternate-base.err | 2 +- tests/qapi-schema/doc-good.json | 18 ++++- tests/qapi-schema/doc-good.out | 20 +++++- tests/qapi-schema/qapi-schema-test.json | 29 ++++++-- tests/qapi-schema/qapi-schema-test.out | 27 +++++-- tests/qapi-schema/test-qapi.py | 9 ++- 17 files changed, 226 insertions(+), 114 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 45c93a43cc..eaeedc7bd3 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -172,7 +172,8 @@ Syntax: ENUM =3D { 'enum': STRING, 'data': [ ENUM-VALUE, ... ], '*prefix': STRING, - '*if': COND } + '*if': COND, + '*features': FEATURES } ENUM-VALUE =3D STRING | { 'name': STRING, '*if': COND } =20 @@ -279,12 +280,14 @@ below for more on this. Syntax: UNION =3D { 'union': STRING, 'data': BRANCHES, - '*if': COND } + '*if': COND, + '*features': FEATURES } | { 'union': STRING, 'data': BRANCHES, 'base': ( MEMBERS | STRING ), 'discriminator': STRING, - '*if': COND } + '*if': COND, + '*features': FEATURES } BRANCHES =3D { BRANCH, ... } BRANCH =3D STRING : TYPE-REF | STRING : { 'type': TYPE-REF, '*if': COND } @@ -397,7 +400,8 @@ the schema" below for more on this. Syntax: ALTERNATE =3D { 'alternate': STRING, 'data': ALTERNATIVES, - '*if': COND } + '*if': COND, + '*features': FEATURES } ALTERNATIVES =3D { ALTERNATIVE, ... } ALTERNATIVE =3D STRING : TYPE-REF | STRING : { 'type': STRING, '*if': COND } @@ -595,7 +599,8 @@ Syntax: 'data': STRING, 'boxed': true, ) - '*if': COND } + '*if': COND, + '*features': FEATURES } =20 Member 'event' names the event. This is the event name used in the Client JSON Protocol. diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.t= exi index d4b15dabf0..5ef7fea436 100644 --- a/tests/qapi-schema/doc-good.texi +++ b/tests/qapi-schema/doc-good.texi @@ -84,11 +84,17 @@ Examples: @table @asis @item @code{one} The @emph{one} @{and only@} +@code{two} is undocumented @*@b{If:} @code{defined(IFONE)} @item @code{two} Not documented @end table -@code{two} is undocumented + +@b{Features:} +@table @asis +@item @code{enum-feat} +Also @emph{one} @{and only@} +@end table =20 @b{If:} @code{defined(IFCOND)} @end deftp @@ -151,6 +157,12 @@ a feature @item The members of @code{Variant2} when @code{base1} is @t{"two"} (@b{If= :} @code{IFTWO}) @end table =20 +@b{Features:} +@table @asis +@item @code{union-feat1} +a feature +@end table + @end deftp =20 =20 @@ -167,6 +179,12 @@ One of @t{"one"}, @t{"two"} @item @code{data: Variant2} when @code{type} is @t{"two"} (@b{If:} @code{I= FTWO}) @end table =20 +@b{Features:} +@table @asis +@item @code{union-feat2} +a feature +@end table + @end deftp =20 =20 @@ -184,6 +202,12 @@ an integer Not documented @end table =20 +@b{Features:} +@table @asis +@item @code{alt-feat} +a feature +@end table + @end deftp =20 =20 @@ -283,5 +307,11 @@ another feature =20 @b{Arguments:} the members of @code{Object} =20 +@b{Features:} +@table @asis +@item @code{feat3} +a feature +@end table + @end deftypefn =20 diff --git a/qapi/introspect.json b/qapi/introspect.json index 031a954fa9..7322ab3f59 100644 --- a/qapi/introspect.json +++ b/qapi/introspect.json @@ -105,6 +105,17 @@ 'command': 'SchemaInfoCommand', 'event': 'SchemaInfoEvent' } } =20 +## +# @SchemaInfoFeatures: +# +# @features: names of features associated with the entity, in no particular +# order. +# +# Since: 4.2 +## +{ 'struct': 'SchemaInfoFeatures', + 'data': { '*features': [ 'str' ] } } + ## # @SchemaInfoBuiltin: # @@ -142,6 +153,7 @@ # Since: 2.5 ## { 'struct': 'SchemaInfoEnum', + 'base': 'SchemaInfoFeatures', 'data': { 'values': ['str'] } } =20 ## @@ -174,18 +186,15 @@ # and may even differ from the order of the values of the # enum type of the @tag. # -# @features: names of features associated with the type, in no particular -# order. (since: 4.1) -# # Values of this type are JSON object on the wire. # # Since: 2.5 ## { 'struct': 'SchemaInfoObject', + 'base': 'SchemaInfoFeatures', 'data': { 'members': [ 'SchemaInfoObjectMember' ], '*tag': 'str', - '*variants': [ 'SchemaInfoObjectVariant' ], - '*features': [ 'str' ] } } + '*variants': [ 'SchemaInfoObjectVariant' ] } } =20 ## # @SchemaInfoObjectMember: @@ -239,6 +248,7 @@ # Since: 2.5 ## { 'struct': 'SchemaInfoAlternate', + 'base': 'SchemaInfoFeatures', 'data': { 'members': [ 'SchemaInfoAlternateMember' ] } } =20 ## @@ -266,17 +276,14 @@ # @allow-oob: whether the command allows out-of-band execution, # defaults to false (Since: 2.12) # -# @features: names of features associated with the command, in no particul= ar -# order. (since 4.2) -# # TODO: @success-response (currently irrelevant, because it's QGA, not QMP) # # Since: 2.5 ## { 'struct': 'SchemaInfoCommand', + 'base': 'SchemaInfoFeatures', 'data': { 'arg-type': 'str', 'ret-type': 'str', - '*allow-oob': 'bool', - '*features': [ 'str' ] } } + '*allow-oob': 'bool' } } =20 ## # @SchemaInfoEvent: @@ -289,4 +296,5 @@ # Since: 2.5 ## { 'struct': 'SchemaInfoEvent', + 'base': 'SchemaInfoFeatures', 'data': { 'arg-type': 'str' } } diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 3798ba1b16..cf4fa1a091 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -44,7 +44,7 @@ void qmp_user_def_cmd1(UserDefOne * ud1, Error **errp) { } =20 -void qmp_test_features(FeatureStruct0 *fs0, FeatureStruct1 *fs1, +void qmp_test_features0(FeatureStruct0 *fs0, FeatureStruct1 *fs1, FeatureStruct2 *fs2, FeatureStruct3 *fs3, FeatureStruct4 *fs4, CondFeatureStruct1 *cfs1, CondFeatureStruct2 *cfs2, CondFeatureStruct3 *cfs3, @@ -52,10 +52,6 @@ void qmp_test_features(FeatureStruct0 *fs0, FeatureStruc= t1 *fs1, { } =20 -void qmp_test_command_features0(Error **errp) -{ -} - void qmp_test_command_features1(Error **errp) { } diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index 6f1c17f71f..53a1f8e952 100644 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -244,7 +244,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): def write(self, output_dir): self._gen.write(output_dir) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): doc =3D self.cur_doc self._gen.add(texi_type('Enum', doc, ifcond, texi_members(doc, 'Values', @@ -258,7 +258,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): self._gen.add(texi_type('Object', doc, ifcond, texi_members(doc, 'Members', base, variant= s))) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): doc =3D self.cur_doc self._gen.add(texi_type('Alternate', doc, ifcond, texi_members(doc, 'Members'))) @@ -271,7 +271,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): texi_arguments(doc, arg_type if boxed else None)= )) =20 - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): doc =3D self.cur_doc self._gen.add(texi_msg('Event', doc, ifcond, texi_arguments(doc, diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 10fc509fa9..f64e61076e 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -189,7 +189,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); event_emit=3Dself._event_emit_name, event_enum=3Dself._event_enum_name)) =20 - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) self._genc.add(gen_event_send(name, arg_type, boxed, diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index d7a289eded..92b2407315 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -220,7 +220,6 @@ def check_struct(expr, info): =20 check_type(members, info, "'data'", allow_dict=3Dname) check_type(expr.get('base'), info, "'base'") - check_features(expr.get('features'), info) =20 =20 def check_union(expr, info): @@ -268,7 +267,6 @@ def check_command(expr, info): raise QAPISemError(info, "'boxed': true requires 'data'") check_type(args, info, "'data'", allow_dict=3Dnot boxed) check_type(rets, info, "'returns'", allow_array=3DTrue) - check_features(expr.get('features'), info) =20 =20 def check_event(expr, info): @@ -320,18 +318,18 @@ def check_exprs(exprs): =20 if meta =3D=3D 'enum': check_keys(expr, info, meta, - ['enum', 'data'], ['if', 'prefix']) + ['enum', 'data'], ['if', 'features', 'prefix']) check_enum(expr, info) elif meta =3D=3D 'union': check_keys(expr, info, meta, ['union', 'data'], - ['base', 'discriminator', 'if']) + ['base', 'discriminator', 'if', 'features']) normalize_members(expr.get('base')) normalize_members(expr['data']) check_union(expr, info) elif meta =3D=3D 'alternate': check_keys(expr, info, meta, - ['alternate', 'data'], ['if']) + ['alternate', 'data'], ['if', 'features']) normalize_members(expr['data']) check_alternate(expr, info) elif meta =3D=3D 'struct': @@ -349,13 +347,14 @@ def check_exprs(exprs): check_command(expr, info) elif meta =3D=3D 'event': check_keys(expr, info, meta, - ['event'], ['data', 'boxed', 'if']) + ['event'], ['data', 'boxed', 'if', 'features']) normalize_members(expr.get('data')) check_event(expr, info) else: assert False, 'unexpected meta type' =20 check_if(expr, info, meta) + check_features(expr.get('features'), info) check_flags(expr, info) =20 return exprs diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index b3a463dd8b..ba493977cf 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -146,7 +146,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) =20 - def _gen_qlit(self, name, mtype, obj, ifcond): + def _gen_qlit(self, name, mtype, obj, ifcond, features): extra =3D {} if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: @@ -156,6 +156,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype + if features: + obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in featu= res] if ifcond: extra['if'] =3D ifcond if extra: @@ -180,18 +182,18 @@ const QLitObject %(c_name)s =3D %(c_string)s; {'if': variant.ifcond}) =20 def visit_builtin_type(self, name, info, json_type): - self._gen_qlit(name, 'builtin', {'json-type': json_type}, []) + self._gen_qlit(name, 'builtin', {'json-type': json_type}, [], None) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): self._gen_qlit(name, 'enum', {'values': [(m.name, {'if': m.ifcond}) for m in members]}, - ifcond) + ifcond, features) =20 def visit_array_type(self, name, info, ifcond, element_type): element =3D self._use_type(element_type) self._gen_qlit('[' + element + ']', 'array', {'element-type': elem= ent}, - ifcond) + ifcond, None) =20 def visit_object_type_flat(self, name, info, ifcond, members, variants, features): @@ -199,16 +201,15 @@ const QLitObject %(c_name)s =3D %(c_string)s; if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) - if features: - obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in featu= res] =20 - self._gen_qlit(name, 'object', obj, ifcond) + self._gen_qlit(name, 'object', obj, ifcond, features) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): self._gen_qlit(name, 'alternate', {'members': [ ({'type': self._use_type(m.type)}, {'if': m.ifc= ond}) - for m in variants.variants]}, ifcond) + for m in variants.variants]}, + ifcond, features) =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, @@ -219,16 +220,12 @@ const QLitObject %(c_name)s =3D %(c_string)s; 'ret-type': self._use_type(ret_type)} if allow_oob: obj['allow-oob'] =3D allow_oob + self._gen_qlit(name, 'command', obj, ifcond, features) =20 - if features: - obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in featu= res] - - self._gen_qlit(name, 'command', obj, ifcond) - - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): arg_type =3D arg_type or self._schema.the_empty_object_type self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type= )}, - ifcond) + ifcond, features) =20 =20 def gen_introspect(schema, output_dir, prefix, opt_unmask): diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index cf0045f34e..f13f442896 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -109,7 +109,7 @@ class QAPISchemaVisitor(object): def visit_builtin_type(self, name, info, json_type): pass =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): pass =20 def visit_array_type(self, name, info, ifcond, element_type): @@ -123,7 +123,7 @@ class QAPISchemaVisitor(object): features): pass =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): pass =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, @@ -131,7 +131,7 @@ class QAPISchemaVisitor(object): features): pass =20 - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): pass =20 =20 @@ -220,8 +220,8 @@ class QAPISchemaBuiltinType(QAPISchemaType): class QAPISchemaEnumType(QAPISchemaType): meta =3D 'enum' =20 - def __init__(self, name, info, doc, ifcond, members, prefix): - QAPISchemaType.__init__(self, name, info, doc, ifcond) + def __init__(self, name, info, doc, ifcond, features, members, prefix): + QAPISchemaType.__init__(self, name, info, doc, ifcond, features) for m in members: assert isinstance(m, QAPISchemaEnumMember) m.set_defined_in(name) @@ -256,15 +256,16 @@ class QAPISchemaEnumType(QAPISchemaType): =20 def visit(self, visitor): QAPISchemaType.visit(self, visitor) - visitor.visit_enum_type(self.name, self.info, self.ifcond, - self.members, self.prefix) + visitor.visit_enum_type( + self.name, self.info, self.ifcond, self.features, + self.members, self.prefix) =20 =20 class QAPISchemaArrayType(QAPISchemaType): meta =3D 'array' =20 def __init__(self, name, info, element_type): - QAPISchemaType.__init__(self, name, info, None, None) + QAPISchemaType.__init__(self, name, info, None) assert isinstance(element_type, str) self._element_type_name =3D element_type self.element_type =3D None @@ -312,8 +313,8 @@ class QAPISchemaArrayType(QAPISchemaType): =20 =20 class QAPISchemaObjectType(QAPISchemaType): - def __init__(self, name, info, doc, ifcond, - base, local_members, variants, features): + def __init__(self, name, info, doc, ifcond, features, + base, local_members, variants): # struct has local_members, optional base, and no variants # flat union has base, variants, and no local_members # simple union has local_members, variants, and no base @@ -609,8 +610,8 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeM= ember): class QAPISchemaAlternateType(QAPISchemaType): meta =3D 'alternate' =20 - def __init__(self, name, info, doc, ifcond, variants): - QAPISchemaType.__init__(self, name, info, doc, ifcond) + def __init__(self, name, info, doc, ifcond, features, variants): + QAPISchemaType.__init__(self, name, info, doc, ifcond, features) assert isinstance(variants, QAPISchemaObjectTypeVariants) assert variants.tag_member variants.set_defined_in(name) @@ -669,16 +670,16 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 def visit(self, visitor): QAPISchemaType.visit(self, visitor) - visitor.visit_alternate_type(self.name, self.info, self.ifcond, - self.variants) + visitor.visit_alternate_type( + self.name, self.info, self.ifcond, self.features, self.variant= s) =20 =20 class QAPISchemaCommand(QAPISchemaEntity): meta =3D 'command' =20 - def __init__(self, name, info, doc, ifcond, arg_type, ret_type, - gen, success_response, boxed, allow_oob, allow_preconfig, - features): + def __init__(self, name, info, doc, ifcond, features, + arg_type, ret_type, + gen, success_response, boxed, allow_oob, allow_preconfig): QAPISchemaEntity.__init__(self, name, info, doc, ifcond, features) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) @@ -739,8 +740,8 @@ class QAPISchemaCommand(QAPISchemaEntity): class QAPISchemaEvent(QAPISchemaEntity): meta =3D 'event' =20 - def __init__(self, name, info, doc, ifcond, arg_type, boxed): - QAPISchemaEntity.__init__(self, name, info, doc, ifcond) + def __init__(self, name, info, doc, ifcond, features, arg_type, boxed): + QAPISchemaEntity.__init__(self, name, info, doc, ifcond, features) assert not arg_type or isinstance(arg_type, str) self._arg_type_name =3D arg_type self.arg_type =3D None @@ -770,8 +771,9 @@ class QAPISchemaEvent(QAPISchemaEntity): =20 def visit(self, visitor): QAPISchemaEntity.visit(self, visitor) - visitor.visit_event(self.name, self.info, self.ifcond, - self.arg_type, self.boxed) + visitor.visit_event( + self.name, self.info, self.ifcond, self.features, + self.arg_type, self.boxed) =20 =20 class QAPISchema(object): @@ -860,7 +862,7 @@ class QAPISchema(object): ('null', 'null', 'QNull' + pointer_suffix)]: self._def_builtin_type(*t) self.the_empty_object_type =3D QAPISchemaObjectType( - 'q_empty', None, None, None, None, [], None, []) + 'q_empty', None, None, None, None, None, [], None) self._def_entity(self.the_empty_object_type) =20 qtypes =3D ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', @@ -868,10 +870,11 @@ class QAPISchema(object): qtype_values =3D self._make_enum_members( [{'name': n} for n in qtypes], None) =20 - self._def_entity(QAPISchemaEnumType('QType', None, None, None, + self._def_entity(QAPISchemaEnumType('QType', None, None, None, Non= e, qtype_values, 'QTYPE')) =20 - def _make_features(self, features, info): + def _make_features(self, expr, info): + features =3D expr.get('features', []) return [QAPISchemaFeature(f['name'], info, f.get('if')) for f in features] =20 @@ -883,7 +886,8 @@ class QAPISchema(object): # See also QAPISchemaObjectTypeMember.describe() name =3D name + 'Kind' # reserved by check_defn_name_str() self._def_entity(QAPISchemaEnumType( - name, info, None, ifcond, self._make_enum_members(values, info= ), + name, info, None, ifcond, None, + self._make_enum_members(values, info), None)) return name =20 @@ -911,8 +915,8 @@ class QAPISchema(object): # TODO kill simple unions or implement the disjunction assert (ifcond or []) =3D=3D typ._ifcond # pylint: disable=3Dp= rotected-access else: - self._def_entity(QAPISchemaObjectType(name, info, None, ifcond, - None, members, None, [])) + self._def_entity(QAPISchemaObjectType( + name, info, None, ifcond, None, None, members, None)) return name =20 def _def_enum_type(self, expr, info, doc): @@ -920,8 +924,9 @@ class QAPISchema(object): data =3D expr['data'] prefix =3D expr.get('prefix') ifcond =3D expr.get('if') + features =3D self._make_features(expr, info) self._def_entity(QAPISchemaEnumType( - name, info, doc, ifcond, + name, info, doc, ifcond, features, self._make_enum_members(data, info), prefix)) =20 def _make_member(self, name, typ, ifcond, info): @@ -943,12 +948,11 @@ class QAPISchema(object): base =3D expr.get('base') data =3D expr['data'] ifcond =3D expr.get('if') - features =3D expr.get('features', []) + features =3D self._make_features(expr, info) self._def_entity(QAPISchemaObjectType( - name, info, doc, ifcond, base, + name, info, doc, ifcond, features, base, self._make_members(data, info), - None, - self._make_features(features, info))) + None)) =20 def _make_variant(self, case, typ, ifcond, info): return QAPISchemaObjectTypeVariant(case, info, typ, ifcond) @@ -967,6 +971,7 @@ class QAPISchema(object): data =3D expr['data'] base =3D expr.get('base') ifcond =3D expr.get('if') + features =3D self._make_features(expr, info) tag_name =3D expr.get('discriminator') tag_member =3D None if isinstance(base, dict): @@ -987,21 +992,22 @@ class QAPISchema(object): tag_member =3D QAPISchemaObjectTypeMember('type', info, typ, F= alse) members =3D [tag_member] self._def_entity( - QAPISchemaObjectType(name, info, doc, ifcond, base, members, + QAPISchemaObjectType(name, info, doc, ifcond, features, + base, members, QAPISchemaObjectTypeVariants( - tag_name, info, tag_member, variants), - [])) + tag_name, info, tag_member, variants)= )) =20 def _def_alternate_type(self, expr, info, doc): name =3D expr['alternate'] data =3D expr['data'] ifcond =3D expr.get('if') + features =3D self._make_features(expr, info) variants =3D [self._make_variant(key, value['type'], value.get('if= '), info) for (key, value) in data.items()] tag_member =3D QAPISchemaObjectTypeMember('type', info, 'QType', F= alse) self._def_entity( - QAPISchemaAlternateType(name, info, doc, ifcond, + QAPISchemaAlternateType(name, info, doc, ifcond, features, QAPISchemaObjectTypeVariants( None, info, tag_member, variants))) =20 @@ -1015,27 +1021,31 @@ class QAPISchema(object): allow_oob =3D expr.get('allow-oob', False) allow_preconfig =3D expr.get('allow-preconfig', False) ifcond =3D expr.get('if') - features =3D expr.get('features', []) + features =3D self._make_features(expr, info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, ifcond, 'arg', self._make_members(data, info)) + name, info, ifcond, + 'arg', self._make_members(data, info)) if isinstance(rets, list): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) - self._def_entity(QAPISchemaCommand(name, info, doc, ifcond, data, = rets, + self._def_entity(QAPISchemaCommand(name, info, doc, ifcond, featur= es, + data, rets, gen, success_response, - boxed, allow_oob, allow_preconf= ig, - self._make_features(features, i= nfo))) + boxed, allow_oob, allow_preconf= ig)) =20 def _def_event(self, expr, info, doc): name =3D expr['event'] data =3D expr.get('data') boxed =3D expr.get('boxed', False) ifcond =3D expr.get('if') + features =3D self._make_features(expr, info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, ifcond, 'arg', self._make_members(data, info)) - self._def_entity(QAPISchemaEvent(name, info, doc, ifcond, data, bo= xed)) + name, info, ifcond, + 'arg', self._make_members(data, info)) + self._def_entity(QAPISchemaEvent(name, info, doc, ifcond, features, + data, boxed)) =20 def _def_exprs(self, exprs): for expr_elem in exprs: diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index d8751daa04..2a108b6911 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -277,7 +277,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): self._genh.add(gen_type_cleanup_decl(name)) self._genc.add(gen_type_cleanup(name)) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): with ifcontext(ifcond, self._genh, self._genc): self._genh.preamble_add(gen_enum(name, members, prefix)) self._genc.add(gen_enum_lookup(name, members, prefix)) @@ -305,7 +305,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): with ifcontext(ifcond, self._genh): self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.add(gen_object(name, ifcond, None, diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index c72f2bc5c0..b21e1340a2 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -316,7 +316,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): ''', types=3Dtypes)) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name, scalar=3DTrue)) self._genc.add(gen_visit_enum(name)) @@ -342,7 +342,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_object(name, base, members, varia= nts)) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_alternate(name, variants)) diff --git a/tests/qapi-schema/alternate-base.err b/tests/qapi-schema/alter= nate-base.err index 31ebe56bbf..970a08ab26 100644 --- a/tests/qapi-schema/alternate-base.err +++ b/tests/qapi-schema/alternate-base.err @@ -1,3 +1,3 @@ alternate-base.json: In alternate 'Alt': alternate-base.json:4: alternate has unknown key 'base' -Valid keys are 'alternate', 'data', 'if'. +Valid keys are 'alternate', 'data', 'features', 'if'. diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index d992e713d9..01c930c474 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -52,11 +52,14 @@ ## # @Enum: # @one: The _one_ {and only} -# # @two is undocumented +# +# Features: +# @enum-feat: Also _one_ {and only} ## { 'enum': 'Enum', 'data': [ { 'name': 'one', 'if': 'defined(IFONE)' }, 'two' ], + 'features': [ 'enum-feat' ], 'if': 'defined(IFCOND)' } =20 ## @@ -86,24 +89,34 @@ =20 ## # @Object: +# Features: +# @union-feat1: a feature ## { 'union': 'Object', + 'features': [ 'union-feat1' ], 'base': 'Base', 'discriminator': 'base1', 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' = } } } =20 ## # @SugaredUnion: +# Features: +# @union-feat2: a feature ## { 'union': 'SugaredUnion', + 'features': [ 'union-feat2' ], 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' = } } } =20 ## # @Alternate: # @i: an integer # @b is undocumented +# +# Features: +# @alt-feat: a feature ## { 'alternate': 'Alternate', + 'features': [ 'alt-feat' ], 'data': { 'i': 'int', 'b': 'bool' } } =20 ## @@ -160,6 +173,9 @@ =20 ## # @EVT-BOXED: +# Features: +# @feat3: a feature ## { 'event': 'EVT-BOXED', 'boxed': true, + 'features': [ 'feat3' ], 'data': 'Object' } diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 4c9406a464..f5d9dc969c 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -15,6 +15,7 @@ enum Enum if ['defined(IFONE)'] member two if ['defined(IFCOND)'] + feature enum-feat object Base member base1: Enum optional=3DFalse object Variant1 @@ -28,6 +29,7 @@ object Object case one: Variant1 case two: Variant2 if ['IFTWO'] + feature union-feat1 object q_obj_Variant1-wrapper member data: Variant1 optional=3DFalse object q_obj_Variant2-wrapper @@ -42,10 +44,12 @@ object SugaredUnion case one: q_obj_Variant1-wrapper case two: q_obj_Variant2-wrapper if ['IFTWO'] + feature union-feat2 alternate Alternate tag type case i: int case b: bool + feature alt-feat object q_obj_cmd-arg member arg1: int optional=3DFalse member arg2: str optional=3DTrue @@ -60,6 +64,7 @@ command cmd-boxed Object -> None feature cmd-feat2 event EVT-BOXED Object boxed=3DTrue + feature feat3 doc freeform body=3D =3D Section @@ -110,10 +115,11 @@ doc symbol=3DEnum =20 arg=3Done The _one_ {and only} - arg=3Dtwo - - section=3DNone @two is undocumented + arg=3Dtwo + + feature=3Denum-feat +Also _one_ {and only} doc symbol=3DBase body=3D =20 @@ -134,11 +140,15 @@ doc symbol=3DVariant2 doc symbol=3DObject body=3D =20 + feature=3Dunion-feat1 +a feature doc symbol=3DSugaredUnion body=3D =20 arg=3Dtype =20 + feature=3Dunion-feat2 +a feature doc symbol=3DAlternate body=3D =20 @@ -147,6 +157,8 @@ an integer @b is undocumented arg=3Db =20 + feature=3Dalt-feat +a feature doc freeform body=3D =3D=3D Another subsection @@ -197,3 +209,5 @@ another feature doc symbol=3DEVT-BOXED body=3D =20 + feature=3Dfeat3 +a feature diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 9abf175fe0..fa4f3a15da 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -252,7 +252,7 @@ 'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } }, 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } =20 -# test 'features' for structs +# test 'features' =20 { 'struct': 'FeatureStruct0', 'data': { 'foo': 'int' }, @@ -281,7 +281,22 @@ 'data': { 'foo': 'int' }, 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] }= ] } -{ 'command': 'test-features', + +{ 'enum': 'FeatureEnum1', + 'data': [ 'eins', 'zwei', 'drei' ], + 'features': [ 'feature1' ] } + +{ 'union': 'FeatureUnion1', + 'base': { 'tag': 'FeatureEnum1' }, + 'discriminator': 'tag', + 'data': { 'eins': 'FeatureStruct1' }, + 'features': [ 'feature1' ] } + +{ 'alternate': 'FeatureAlternate1', + 'data': { 'eins': 'FeatureStruct1' }, + 'features': [ 'feature1' ] } + +{ 'command': 'test-features0', 'data': { 'fs0': 'FeatureStruct0', 'fs1': 'FeatureStruct1', 'fs2': 'FeatureStruct2', @@ -289,12 +304,9 @@ 'fs4': 'FeatureStruct4', 'cfs1': 'CondFeatureStruct1', 'cfs2': 'CondFeatureStruct2', - 'cfs3': 'CondFeatureStruct3' } } - -# test 'features' for command - -{ 'command': 'test-command-features0', + 'cfs3': 'CondFeatureStruct3' }, 'features': [] } + { 'command': 'test-command-features1', 'features': [ 'feature1' ] } { 'command': 'test-command-features3', @@ -308,3 +320,6 @@ { 'command': 'test-command-cond-features3', 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] }= ] } + +{ 'event': 'TEST-EVENT-FEATURES1', + 'features': [ 'feature1' ] } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 3660e75a48..1ece836d9b 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -401,7 +401,25 @@ object CondFeatureStruct3 member foo: int optional=3DFalse feature feature1 if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] -object q_obj_test-features-arg +enum FeatureEnum1 + member eins + member zwei + member drei + feature feature1 +object q_obj_FeatureUnion1-base + member tag: FeatureEnum1 optional=3DFalse +object FeatureUnion1 + base q_obj_FeatureUnion1-base + tag tag + case eins: FeatureStruct1 + case zwei: q_empty + case drei: q_empty + feature feature1 +alternate FeatureAlternate1 + tag type + case eins: FeatureStruct1 + feature feature1 +object q_obj_test-features0-arg member fs0: FeatureStruct0 optional=3DFalse member fs1: FeatureStruct1 optional=3DFalse member fs2: FeatureStruct2 optional=3DFalse @@ -410,9 +428,7 @@ object q_obj_test-features-arg member cfs1: CondFeatureStruct1 optional=3DFalse member cfs2: CondFeatureStruct2 optional=3DFalse member cfs3: CondFeatureStruct3 optional=3DFalse -command test-features q_obj_test-features-arg -> None - gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse -command test-command-features0 None -> None +command test-features0 q_obj_test-features0-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse command test-command-features1 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse @@ -435,3 +451,6 @@ command test-command-cond-features3 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] +event TEST-EVENT-FEATURES1 None + boxed=3DFalse + feature feature1 diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index bad14edb47..078fc63f97 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -35,7 +35,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): def visit_include(self, name, info): print('include %s' % name) =20 - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): print('enum %s' % name) if prefix: print(' prefix %s' % prefix) @@ -43,6 +43,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print(' member %s' % m.name) self._print_if(m.ifcond, indent=3D8) self._print_if(ifcond) + self._print_features(features) =20 def visit_array_type(self, name, info, ifcond, element_type): if not info: @@ -63,10 +64,11 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(ifcond) self._print_features(features) =20 - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): print('alternate %s' % name) self._print_variants(variants) self._print_if(ifcond) + self._print_features(features) =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, @@ -79,10 +81,11 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(ifcond) self._print_features(features) =20 - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): print('event %s %s' % (name, arg_type and arg_type.name)) print(' boxed=3D%s' % boxed) self._print_if(ifcond) + self._print_features(features) =20 @staticmethod def _print_variants(variants): --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920551; cv=none; d=zoho.com; s=zohoarc; b=RwuCm1tUVZ97E+gsoew1Fo+AM+HKBN8mmReF9eYo96rEC5is9+ILKnQ45aLbPcKYJr/Fs+2J2GD4CVo/2V0XPem+YQR6ows1YzoOknTuIULm1lCovfCV/iZ9e1TOm+eSG6k+YjhIdOSvfBNBU+OGcflmCWVaRmBr2t/UTLWx72g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920551; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3XCZw6xCxG1OPfGhEhzxmQj8qMqqg2BNsKwwCQ6EpGg=; b=FklCf8nT59Za4xg3Jg/gcDpuA/LOeu6d9mMCyex85swL9DEHOnp8m5yuQyn4f+CXw1UbkjErLkjcpk/SziVCJqBmAsINleOcP3XoLe6ASfHcKf1mQMEjF7lgZpvyfwB0MgENzolzpVBcaVYvs3FuMdKm0uZrtInbEyGwvAbXINk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571920551181133.6235777140423; Thu, 24 Oct 2019 05:35:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-56-aercBQSWPn25ApFpRNnxNQ-1; Thu, 24 Oct 2019 08:35:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7E97100551D; Thu, 24 Oct 2019 12:35:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F8E95C29A; Thu, 24 Oct 2019 12:35:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 40B7F3FB42; Thu, 24 Oct 2019 12:35:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZBko004552 for ; Thu, 24 Oct 2019 08:35:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id C898C60C57; Thu, 24 Oct 2019 12:35:11 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0F1C60BE0; Thu, 24 Oct 2019 12:35:07 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 149921132989; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920550; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3XCZw6xCxG1OPfGhEhzxmQj8qMqqg2BNsKwwCQ6EpGg=; b=aOaUiyUoi2wGPaI08NO6svv+2JfZi3R+E+tjlvdvJM/l+mBoqCjtKzVfoW8cWyTIfqdR6A 4QSajssuRzG22bYx3qd2Tg8A/JniqwFDTvWNRkDOhu4UM+wEnfvIG6kdm0g56N1G3lBuKo iOWL3RDnXOSnr27IkQKg6Ak9HOY930o= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:47 +0200 Message-Id: <20191024123458.13505-9-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 08/19] qapi: Consistently put @features parameter right after @ifcond X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: aercBQSWPn25ApFpRNnxNQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster --- scripts/qapi/commands.py | 6 +++--- scripts/qapi/doc.py | 10 +++++----- scripts/qapi/introspect.py | 10 +++++----- scripts/qapi/schema.py | 36 ++++++++++++++++------------------ scripts/qapi/types.py | 4 ++-- scripts/qapi/visit.py | 4 ++-- tests/qapi-schema/test-qapi.py | 10 +++++----- 7 files changed, 39 insertions(+), 41 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index ab98e504f3..11e9a6c095 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -276,9 +276,9 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); c_prefix=3Dc_name(self._prefix, protect=3DFalse))) genc.add(gen_registry(self._regy.get_content(), self._prefix)) =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): if not gen: return # FIXME: If T is a user-defined type, the user is responsible diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index 53a1f8e952..55c4892a1e 100644 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -250,8 +250,8 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): texi_members(doc, 'Values', member_func=3Dtexi_enum_value= ))) =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): doc =3D self.cur_doc if base and base.is_implicit(): base =3D None @@ -263,9 +263,9 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): self._gen.add(texi_type('Alternate', doc, ifcond, texi_members(doc, 'Members'))) =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): doc =3D self.cur_doc self._gen.add(texi_msg('Command', doc, ifcond, texi_arguments(doc, diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index ba493977cf..f71b984d3b 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -195,8 +195,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; self._gen_qlit('[' + element + ']', 'array', {'element-type': elem= ent}, ifcond, None) =20 - def visit_object_type_flat(self, name, info, ifcond, members, variants, - features): + def visit_object_type_flat(self, name, info, ifcond, features, + members, variants): obj =3D {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, @@ -211,9 +211,9 @@ const QLitObject %(c_name)s =3D %(c_string)s; for m in variants.variants]}, ifcond, features) =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type obj =3D {'arg-type': self._use_type(arg_type), diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index f13f442896..639140fceb 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -115,20 +115,20 @@ class QAPISchemaVisitor(object): def visit_array_type(self, name, info, ifcond, element_type): pass =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): pass =20 - def visit_object_type_flat(self, name, info, ifcond, members, variants, - features): + def visit_object_type_flat(self, name, info, features, ifcond, + members, variants): pass =20 def visit_alternate_type(self, name, info, ifcond, features, variants): pass =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): pass =20 def visit_event(self, name, info, ifcond, features, arg_type, boxed): @@ -422,12 +422,12 @@ class QAPISchemaObjectType(QAPISchemaType): =20 def visit(self, visitor): QAPISchemaType.visit(self, visitor) - visitor.visit_object_type(self.name, self.info, self.ifcond, - self.base, self.local_members, self.vari= ants, - self.features) - visitor.visit_object_type_flat(self.name, self.info, self.ifcond, - self.members, self.variants, - self.features) + visitor.visit_object_type( + self.name, self.info, self.ifcond, self.features, + self.base, self.local_members, self.variants) + visitor.visit_object_type_flat( + self.name, self.info, self.ifcond, self.features, + self.members, self.variants) =20 =20 class QAPISchemaMember(object): @@ -729,12 +729,10 @@ class QAPISchemaCommand(QAPISchemaEntity): =20 def visit(self, visitor): QAPISchemaEntity.visit(self, visitor) - visitor.visit_command(self.name, self.info, self.ifcond, - self.arg_type, self.ret_type, - self.gen, self.success_response, - self.boxed, self.allow_oob, - self.allow_preconfig, - self.features) + visitor.visit_command( + self.name, self.info, self.ifcond, self.features, + self.arg_type, self.ret_type, self.gen, self.success_response, + self.boxed, self.allow_oob, self.allow_preconfig) =20 =20 class QAPISchemaEvent(QAPISchemaEntity): diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 2a108b6911..9dc07f6308 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -288,8 +288,8 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): self._genh.add(gen_array(name, element_type)) self._gen_type_cleanup(name) =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index b21e1340a2..4db94e5e80 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -326,8 +326,8 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_list(name, element_type)) =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 078fc63f97..9ee8993f8d 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -51,8 +51,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print('array %s %s' % (name, element_type.name)) self._print_if(ifcond) =20 - def visit_object_type(self, name, info, ifcond, base, members, variant= s, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): print('object %s' % name) if base: print(' base %s' % base.name) @@ -70,9 +70,9 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(ifcond) self._print_features(features) =20 - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): print('command %s %s -> %s' % (name, arg_type and arg_type.name, ret_type and ret_type.name)) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920537; cv=none; d=zoho.com; s=zohoarc; b=Bb0E9kIupDrZAxPG6nYfk6jYTG6iBQAsXqbmEcJfbNo0fHMOXykwjP+IYaaoUR+IWQzhrECca/JrBPkkL8LXuvsa9H+ewJpc1M7ufVRNpWHvLwMebLlTV6bguAqX393lVMMqBoOfnLh8zn6o0HOdfGO8wFijsHPHjYV7rRqQy7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920537; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ePt4UTMiHmd5bEMvqYM6uYZ83LNMYmlWnISSO6AB1vY=; b=k6r7W0ovqjrFvKqAa9SBaspg9VjdCWjnxl2TmUpV6YEzbUT5FqDQ4Q2P/teRlNJPRlHMfxPizJcNI/3A5gP24SFEkBkQr49Bg2umsyqHGQnL4ns+67k1Nw5hPQHH/f2bPt5z4K6SGSYUBEObSX0AV41zgh+pP/zkJswKwn/2N1Q= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 157192053769594.4106370845816; Thu, 24 Oct 2019 05:35:37 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-I9sgBvRNN8iRCFOEhaAFlw-1; Thu, 24 Oct 2019 08:35:34 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD181100552F; Thu, 24 Oct 2019 12:35:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 80CA85D9CA; Thu, 24 Oct 2019 12:35:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3585E4EE6E; Thu, 24 Oct 2019 12:35:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ6YB004458 for ; Thu, 24 Oct 2019 08:35:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8B78052F6; Thu, 24 Oct 2019 12:35:06 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A22E252E7; Thu, 24 Oct 2019 12:35:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 18049113292F; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920536; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ePt4UTMiHmd5bEMvqYM6uYZ83LNMYmlWnISSO6AB1vY=; b=VJupQ6VznedYms/6V4Z95AIOkZHTWrq2BdiJ0ygXBFV5D6wRiKPfwuR+BGlC/+fDbs/JiI pWxEnQ6cINRJOy01gLIA3c6U27OLsL6fzU5VsfxUnqat78axrKPmeEpXZoAFLJnKlSVwBu xMSrD0Fhf6884+h9PQGeZOcT6GHPi0E= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:48 +0200 Message-Id: <20191024123458.13505-10-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 09/19] qapi: Inline do_qmp_dispatch() into qmp_dispatch() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: I9sgBvRNN8iRCFOEhaAFlw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Both functions check @request is a QDict, and both have code for QCO_NO_SUCCESS_RESP. This wasn't the case back when they were created. It's a sign of muddled responsibilities. Inline. The next commits will clean up some more. Signed-off-by: Markus Armbruster --- qapi/qmp-dispatch.c | 90 +++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index bc264b3c9b..a69d5b5a96 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -75,19 +75,42 @@ static QDict *qmp_dispatch_check_obj(const QObject *req= uest, bool allow_oob, return dict; } =20 -static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request, - bool allow_oob, Error **errp) +QDict *qmp_error_response(Error *err) { - Error *local_err =3D NULL; + QDict *rsp; + + rsp =3D qdict_from_jsonf_nofail("{ 'error': { 'class': %s, 'desc': %s = } }", + QapiErrorClass_str(error_get_class(err)), + error_get_pretty(err)); + error_free(err); + return rsp; +} + +/* + * Does @qdict look like a command to be run out-of-band? + */ +bool qmp_is_oob(const QDict *dict) +{ + return qdict_haskey(dict, "exec-oob") + && !qdict_haskey(dict, "execute"); +} + +QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, + bool allow_oob) +{ + Error *err =3D NULL; bool oob; const char *command; - QDict *args, *dict; + QDict *args; QmpCommand *cmd; + QDict *dict =3D qobject_to(QDict, request); + QObject *id =3D dict ? qdict_get(dict, "id") : NULL; QObject *ret =3D NULL; + QDict *rsp; =20 - dict =3D qmp_dispatch_check_obj(request, allow_oob, errp); + dict =3D qmp_dispatch_check_obj(request, allow_oob, &err); if (!dict) { - return NULL; + goto out; } =20 command =3D qdict_get_try_str(dict, "execute"); @@ -99,27 +122,27 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, } cmd =3D qmp_find_command(cmds, command); if (cmd =3D=3D NULL) { - error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, + error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has not been found", command); - return NULL; + goto out; } if (!cmd->enabled) { - error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, + error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has been disabled for this instance", command); - return NULL; + goto out; } if (oob && !(cmd->options & QCO_ALLOW_OOB)) { - error_setg(errp, "The command %s does not support OOB", + error_setg(&err, "The command %s does not support OOB", command); - return NULL; + goto out; } =20 if (runstate_check(RUN_STATE_PRECONFIG) && !(cmd->options & QCO_ALLOW_PRECONFIG)) { - error_setg(errp, "The command '%s' isn't permitted in '%s' state", + error_setg(&err, "The command '%s' isn't permitted in '%s' state", cmd->name, RunState_str(RUN_STATE_PRECONFIG)); - return NULL; + goto out; } =20 if (!qdict_haskey(dict, "arguments")) { @@ -129,9 +152,9 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, Q= Object *request, qobject_ref(args); } =20 - cmd->fn(args, &ret, &local_err); - if (local_err) { - error_propagate(errp, local_err); + cmd->fn(args, &ret, &err);=20 + if (err) { + ; } else if (cmd->options & QCO_NO_SUCCESS_RESP) { g_assert(!ret); } else if (!ret) { @@ -141,38 +164,7 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, =20 qobject_unref(args); =20 - return ret; -} - -QDict *qmp_error_response(Error *err) -{ - QDict *rsp; - - rsp =3D qdict_from_jsonf_nofail("{ 'error': { 'class': %s, 'desc': %s = } }", - QapiErrorClass_str(error_get_class(err)), - error_get_pretty(err)); - error_free(err); - return rsp; -} - -/* - * Does @qdict look like a command to be run out-of-band? - */ -bool qmp_is_oob(const QDict *dict) -{ - return qdict_haskey(dict, "exec-oob") - && !qdict_haskey(dict, "execute"); -} - -QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, - bool allow_oob) -{ - Error *err =3D NULL; - QDict *dict =3D qobject_to(QDict, request); - QObject *ret, *id =3D dict ? qdict_get(dict, "id") : NULL; - QDict *rsp; - - ret =3D do_qmp_dispatch(cmds, request, allow_oob, &err); +out: if (err) { rsp =3D qmp_error_response(err); } else if (ret) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920636; cv=none; d=zoho.com; s=zohoarc; b=VS8CCnqQ2GkfxoenMQworJQMTdp/F14d+a6jJlFEFYTxE1JzLMPkaRlQOoqNSulTxmE2LAULbpSCBNAdqfKziLknUh6ql6A6XCLXpwN44kcR2mtPjB0MRUCJLPqEKbDFPhmfxXfLLEx4KbCKLLjsd+xy2r991t56uiXcmRq0EDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920636; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DFQaK5/n1kPltuUs42oncHhJsQAMmaOUvm0QyimHp9g=; b=C5GTUH6OrVbrmPJ5C97Naw/pH8AcUp9DipsSf1NYxFpR8jGuv3wWvkoZN6RPBOOXBPRQgzFTCpuzdFHH+dboRCdrv1om2HdKPILKIAkHvDwSfzIzd1ieENq2MKxOYQcWhEsQXmlj74WS2uCiIyLDalyH20rVUshJmDpFZNSZS0U= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571920636302152.63763199561345; Thu, 24 Oct 2019 05:37:16 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-360-k5hzfv6oMKGmI8o7NvURgw-1; Thu, 24 Oct 2019 08:35:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0BE99800D69; Thu, 24 Oct 2019 12:35:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA7026062B; Thu, 24 Oct 2019 12:35:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7B7704EE7E; Thu, 24 Oct 2019 12:35:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZAlH004517 for ; Thu, 24 Oct 2019 08:35:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0F0511001B33; Thu, 24 Oct 2019 12:35:10 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9CBD10027A1; Thu, 24 Oct 2019 12:35:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1B371113294C; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920635; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DFQaK5/n1kPltuUs42oncHhJsQAMmaOUvm0QyimHp9g=; b=MWsu7xrxh3I2FjasGrzzcSJOQFUW/i/Zy9O78s/EK5YIRBiedsHkPS7PwME0SPfpZSEfxg Hg/j/KzchlfVzY6Q5zUDx/U3XBdcPaWA9Isr/q7kpVDtVfqXfbgu1vX0Dxy0wf3p4FFUqy HMWwlqWppgo4KtRokr2yVx5fFt7MVqQ= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:49 +0200 Message-Id: <20191024123458.13505-11-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 10/19] qapi: Simplify how qmp_dispatch() deals with QCO_NO_SUCCESS_RESP X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: k5hzfv6oMKGmI8o7NvURgw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster --- qapi/qmp-dispatch.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index a69d5b5a96..d1643fe37a 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -151,31 +151,31 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *re= quest, args =3D qdict_get_qdict(dict, "arguments"); qobject_ref(args); } - cmd->fn(args, &ret, &err);=20 + qobject_unref(args); if (err) { - ; - } else if (cmd->options & QCO_NO_SUCCESS_RESP) { + goto out; + } + + if (cmd->options & QCO_NO_SUCCESS_RESP) { g_assert(!ret); + return NULL; } else if (!ret) { /* TODO turn into assertion */ ret =3D QOBJECT(qdict_new()); } =20 - qobject_unref(args); - out: + assert(!err !=3D !ret); + if (err) { rsp =3D qmp_error_response(err); - } else if (ret) { + } else { rsp =3D qdict_new(); qdict_put_obj(rsp, "return", ret); - } else { - /* Can only happen for commands with QCO_NO_SUCCESS_RESP */ - rsp =3D NULL; } =20 - if (rsp && id) { + if (id) { qdict_put_obj(rsp, "id", qobject_ref(id)); } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920629; cv=none; d=zoho.com; s=zohoarc; b=LQ6fr6zQONNPYEqI65Op6D+cIPchcKeh/MhjW0JeZze9NHO17q6Q7/YhXrxo6iaT1Ia7PgSZ/avn2dv0o2eO+tdsqqzdHVahiPeFwmnoFXipy212uBW3Jx0CI4wZY9egVnzsw3CqmbKRvaD8EWJsLR7SHwvxUCdm9x3TGXUfkUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920629; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QfWhCwcuiYkNb11FtX/FzN/pr1AfKjeQ1vIewiT9ZaQ=; b=fJkBZRjq597GMg2+eGUiyrYTdyK3XZENszvpeU9mWfZhBK9qZfbJV5lHomjbyFm8ST1HzmBXM4b15PUhKREOUTvOmwSQ8PfiXZtra4bElOw5pNiRheXmbOC1y3dzdkMP6NSYoL+UjWO3yh8rm1jjqUvYGHBpHWmT/KgOD1lvAqI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571920629801152.39761451492518; Thu, 24 Oct 2019 05:37:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-90ZxMfb9NKS9UkWOjmCRZA-1; Thu, 24 Oct 2019 08:35:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B25D35FD; Thu, 24 Oct 2019 12:35:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 85B0C6062E; Thu, 24 Oct 2019 12:35:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3C04C180BAA8; Thu, 24 Oct 2019 12:35:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ9nR004505 for ; Thu, 24 Oct 2019 08:35:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC2DB6012D; Thu, 24 Oct 2019 12:35:09 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9AA3F600CC; Thu, 24 Oct 2019 12:35:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1E60B113294D; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920628; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QfWhCwcuiYkNb11FtX/FzN/pr1AfKjeQ1vIewiT9ZaQ=; b=iJipu6xCkFDINQfxPKKjwhhhoTEwx9AH/iTBieVq54DFs4orjo4d7an9fuKvnU+u0PyOmy gGCDodiaN2Ds4jTfmnwG+X1NeuyGyhdimGekO/aBVPEkwmZ92kKdLDzaMvFtQJQuKHdxVy f4Bq3WvGEr8SzyLwEauoBgOgGu75VCo= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:50 +0200 Message-Id: <20191024123458.13505-12-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 11/19] qapi: Simplify how qmp_dispatch() gets the request ID X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 90ZxMfb9NKS9UkWOjmCRZA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We convert the request object to a QDict twice: first in qmp_dispatch() to get the request ID, and then again in qmp_dispatch_check_obj(), which converts to QDict, then checks and returns it. We can't get the request ID from the latter, because it's null when the qdict flunks the checks. Move getting the request ID into qmp_dispatch_check_obj(). Signed-off-by: Markus Armbruster --- qapi/qmp-dispatch.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index d1643fe37a..0cbb663097 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -20,7 +20,7 @@ #include "qapi/qmp/qbool.h" =20 static QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oo= b, - Error **errp) + QObject **id, Error **errp) { const char *exec_key =3D NULL; const QDictEntry *ent; @@ -30,10 +30,13 @@ static QDict *qmp_dispatch_check_obj(const QObject *req= uest, bool allow_oob, =20 dict =3D qobject_to(QDict, request); if (!dict) { + *id =3D NULL; error_setg(errp, "QMP input must be a JSON object"); return NULL; } =20 + *id =3D qdict_get(dict, "id"); + for (ent =3D qdict_first(dict); ent; ent =3D qdict_next(dict, ent)) { arg_name =3D qdict_entry_key(ent); @@ -103,12 +106,12 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *re= quest, const char *command; QDict *args; QmpCommand *cmd; - QDict *dict =3D qobject_to(QDict, request); - QObject *id =3D dict ? qdict_get(dict, "id") : NULL; + QDict *dict; + QObject *id; QObject *ret =3D NULL; QDict *rsp; =20 - dict =3D qmp_dispatch_check_obj(request, allow_oob, &err); + dict =3D qmp_dispatch_check_obj(request, allow_oob, &id, &err); if (!dict) { goto out; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920521; cv=none; d=zoho.com; s=zohoarc; b=hSM9z1Faa3ex/9S8XXcQdSSA+1gRvuiW3XpZzchdLejAnuvjonKbPUuXwY1EDpK6qOOhDFtLmhUKN9VU66y88xfhsXCauDm9yL0SxYTY7iXPJDwmI5Bj1jEViU6Vl1JrKsKvRRzCiUbu6w4bLM70TfHhzKypqQWxSKhSuvpQijc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920521; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=15drxuzcOQCQFkvaoMBF/3VHDuJh5Wh8c6TDtfsVpEo=; b=lEampxBG5R8B5rjcV8OKYU7KupcOjYzcEGqWZzxw7Fa1BOil2zVTTGDrFW3O5cCLjn5Vp80hHu8wInqbWjn+G4gR6y9d58PwSG4HefTWEELhqRsO9+NlHL3uPR7gv1l892ZLYM/yVMY5ARda15ISJw7Ibb04R/hdekkQe9zMlxM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571920521118875.0409909493793; Thu, 24 Oct 2019 05:35:21 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-86-DsgJlHJLNrm1tfjymFXBZA-1; Thu, 24 Oct 2019 08:35:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B947E107AD35; Thu, 24 Oct 2019 12:35:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 90F70600CC; Thu, 24 Oct 2019 12:35:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 35F964E58A; Thu, 24 Oct 2019 12:35:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ8Vs004490 for ; Thu, 24 Oct 2019 08:35:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id CDF3852F7; Thu, 24 Oct 2019 12:35:08 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B47D52E7; Thu, 24 Oct 2019 12:35:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2177F11328A8; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920519; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=15drxuzcOQCQFkvaoMBF/3VHDuJh5Wh8c6TDtfsVpEo=; b=VzCE+iElBZLf8ldw2gSwRYvmK84rhPicaYrPkkkLUwo7dPARnkFFa6dzPon7yg33JEDzV4 vjMhaqazUZt6G62g2zdneg5hG5bx+gLy4qpp1wl9MkWtpIUewcQcB7txw+L52KYcx4O2NR aom3lmy004TAwIY/jDV/aWpIEYIk+/o= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:51 +0200 Message-Id: <20191024123458.13505-13-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 12/19] qapi: Replace qmp_dispatch()'s TODO comment by an explanation X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: DsgJlHJLNrm1tfjymFXBZA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster --- qapi/qmp-dispatch.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 0cbb663097..55bc224c61 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -164,7 +164,11 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *req= uest, g_assert(!ret); return NULL; } else if (!ret) { - /* TODO turn into assertion */ + /*=20 + * When the command's schema has no 'returns', cmd->fn() + * leaves @ret null. The QMP spec calls for an the empty + * object then; supply it. + */ ret =3D QOBJECT(qdict_new()); } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920547; cv=none; d=zoho.com; s=zohoarc; b=QyZZ9JPcLzC4ySkDhHtyVt3iAbT+jIhkRsfUrNgrcb3AcCFxr1/wc/GnW1uNT0LFuw1D4E8HmHtPe+CE1scH4EpoBiu/RJKNsrWmPJWNZ9XemOE055sFT5qg7wxL6uYUgDgopgFuyu8oTTUQi+KobJSz8p7rgC5GvUDs5ZVlopU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920547; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xfMfvbdn8k1S1tj704koX9NvTw301yIHdOpAoLcYvb4=; b=CkQHqfMN7wvqpOp2z43T0Q/ZXHBsxGPTgmKFd/whCDZEUtk9hH0Y+LSksytBQ0PbtpqpWf1dd7cAZ+InBqebTVIyAyQwc6u1dglJtkrkMasLzWxbMlvfBbQGgKtX4v55WMxF999sy59R4VwAEPfkv4P9kdwUMnb9HQld3kNmtzo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571920547241974.5026168343609; Thu, 24 Oct 2019 05:35:47 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-154-KhDL4HirMBSb9Oobs9M1Hg-1; Thu, 24 Oct 2019 08:35:44 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70432107AD36; Thu, 24 Oct 2019 12:35:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BE2F60467; Thu, 24 Oct 2019 12:35:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E45B2180BAA5; Thu, 24 Oct 2019 12:35:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ8aZ004485 for ; Thu, 24 Oct 2019 08:35:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F4D55D9CA; Thu, 24 Oct 2019 12:35:08 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 467A25DC1E; Thu, 24 Oct 2019 12:35:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 24B0B11328AA; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920546; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xfMfvbdn8k1S1tj704koX9NvTw301yIHdOpAoLcYvb4=; b=POnIyxjN7ArWsJdLo27TOLM+3AaixITsrLAKxhlHIh5yVR++ZxpNvL0okPFPg84clRwJA4 zRXbT+MJaWggBUl3XrNSjle/TLwQZWaBQn6BQYr0x1YHIM1RVylOXFW9RgMahqRMhL54M4 7l3MPnuUmkn4F76E/7FrYNzGHMxcEL4= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:52 +0200 Message-Id: <20191024123458.13505-14-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 13/19] qapi: New special feature flag "deprecated" X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: KhDL4HirMBSb9Oobs9M1Hg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Unlike regular feature flags, the new special feature flag "deprecated" is recognized by the QAPI generator. For now, it's only permitted with commands and events. It will be put to use shortly. Signed-off-by: Markus Armbruster --- docs/devel/qapi-code-gen.txt | 6 ++++++ scripts/qapi/schema.py | 6 ++++++ tests/Makefile.include | 1 + tests/qapi-schema/features-deprecated-type.err | 2 ++ tests/qapi-schema/features-deprecated-type.json | 3 +++ tests/qapi-schema/features-deprecated-type.out | 0 tests/qapi-schema/qapi-schema-test.json | 4 ++-- tests/qapi-schema/qapi-schema-test.out | 4 ++-- 8 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/qapi-schema/features-deprecated-type.err create mode 100644 tests/qapi-schema/features-deprecated-type.json create mode 100644 tests/qapi-schema/features-deprecated-type.out diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index eaeedc7bd3..e6ef93544e 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -665,6 +665,12 @@ Example: 'features': [ 'allow-negative-numbers' ] } =20 =20 +=3D=3D=3D=3D Special features =3D=3D=3D=3D + +Feature "deprecated" makes a command or event as deprecated. It is +not supported elsewhere so far. + + =3D=3D=3D Naming rules and reserved names =3D=3D=3D =20 All names must begin with a letter, and contain only ASCII letters, diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 639140fceb..840d119c6d 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -179,6 +179,12 @@ class QAPISchemaType(QAPISchemaEntity): return None return self.name =20 + def check(self, schema): + QAPISchemaEntity.check(self, schema) + if 'deprecated' in [f.name for f in self.features]: + raise QAPISemError( + self.info, "feature 'deprecated' is not supported for type= s") + def describe(self): assert self.meta return "%s type '%s'" % (self.meta, self.name) diff --git a/tests/Makefile.include b/tests/Makefile.include index ea35cd54cc..9da831b882 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -388,6 +388,7 @@ qapi-schema +=3D event-case.json qapi-schema +=3D event-member-invalid-dict.json qapi-schema +=3D event-nest-struct.json qapi-schema +=3D features-bad-type.json +qapi-schema +=3D features-deprecated-type.json qapi-schema +=3D features-duplicate-name.json qapi-schema +=3D features-if-invalid.json qapi-schema +=3D features-missing-name.json diff --git a/tests/qapi-schema/features-deprecated-type.err b/tests/qapi-sc= hema/features-deprecated-type.err new file mode 100644 index 0000000000..af4ffe20aa --- /dev/null +++ b/tests/qapi-schema/features-deprecated-type.err @@ -0,0 +1,2 @@ +features-deprecated-type.json: In struct 'S': +features-deprecated-type.json:2: feature 'deprecated' is not supported for= types diff --git a/tests/qapi-schema/features-deprecated-type.json b/tests/qapi-s= chema/features-deprecated-type.json new file mode 100644 index 0000000000..4b5bf5b86e --- /dev/null +++ b/tests/qapi-schema/features-deprecated-type.json @@ -0,0 +1,3 @@ +# Feature 'deprecated' is not supported for types +{ 'struct': 'S', 'data': {}, + 'features': [ 'deprecated' ] } diff --git a/tests/qapi-schema/features-deprecated-type.out b/tests/qapi-sc= hema/features-deprecated-type.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index fa4f3a15da..6862d8ba2c 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -308,7 +308,7 @@ 'features': [] } =20 { 'command': 'test-command-features1', - 'features': [ 'feature1' ] } + 'features': [ 'deprecated' ] } { 'command': 'test-command-features3', 'features': [ 'feature1', 'feature2' ] } =20 @@ -322,4 +322,4 @@ 'defined(TEST_IF_COND_2)'] }= ] } =20 { 'event': 'TEST-EVENT-FEATURES1', - 'features': [ 'feature1' ] } + 'features': [ 'deprecated' ] } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 1ece836d9b..494d4c25c4 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -432,7 +432,7 @@ command test-features0 q_obj_test-features0-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse command test-command-features1 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - feature feature1 + feature deprecated command test-command-features3 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 @@ -453,4 +453,4 @@ command test-command-cond-features3 None -> None if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] event TEST-EVENT-FEATURES1 None boxed=3DFalse - feature feature1 + feature deprecated --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920554; cv=none; d=zoho.com; s=zohoarc; b=YccXomZaStQq+E1lvIzVp0OevP6/ZMyMvKpvYk+hZbxRvhB8n39WdNioQozd7OynxenUEsvskzBXrdWW1lUe0qWD6EYhU6gaHRF93IAtwc7xhoPhEadtDlVPbeEvcAzFe2FPszq9tGbIh8xQ5UPtDoU+wSZkn861fxCkDsJGLjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920554; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=S69TMsW+44ZNoHHBTdNOkRsG725L6D61PrR4OwX1RDo=; b=mifolpuQ4e3cVxKjOXuJzyUAAYmtKsFgrHoTWuc4Q4yqoy1fBnrvojtO01JI8S7T6YsFClAYVUV2lhRn8wwArw5qqC2iECJp7V8R1N7j3fmvKURKw68/0OqLkiz0YxOBS7hg8FaRF/KhYEIuOJylX7ra6pvcioZHp93WiHITFeo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 157192055399914.163148469096427; Thu, 24 Oct 2019 05:35:53 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-170-rDPnuhcbPry653iVyv1Orw-1; Thu, 24 Oct 2019 08:35:51 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B40E801E5C; Thu, 24 Oct 2019 12:35:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53B5B36F9; Thu, 24 Oct 2019 12:35:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 12533180BACE; Thu, 24 Oct 2019 12:35:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZA7r004530 for ; Thu, 24 Oct 2019 08:35:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 905945B681; Thu, 24 Oct 2019 12:35:10 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4AF245D713; Thu, 24 Oct 2019 12:35:07 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 27E981130341; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920552; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=S69TMsW+44ZNoHHBTdNOkRsG725L6D61PrR4OwX1RDo=; b=K5ufTFtm/9f+ToosVidV0UFqQD15sSp1/qfldrwIiTNW9rDP42zt5MWxc8itOnNfhKJdZ8 ELs/i7NB+6pfW39xJX+AoO7Dnr4jH4hY5/yNLHMFjT9ELgMBVfxrWiqbNTuInhXsDXhkwZ 9EosbQwUDxSmPwfCoGAYfA8faPMG28M= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:53 +0200 Message-Id: <20191024123458.13505-15-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 14/19] qemu-options: New -compat to set policy for "funny" interfaces X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: rDPnuhcbPry653iVyv1Orw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" "Funny" interface policy is separate for input and output. Input policy can be "accept" (accept silently; default), "reject" (reject the request with an error), or "crash" (abort() the process). Output policy can be "accept" (pass on unchanged), or "hide" (filter out the deprecated parts). Policies other than "accept" are implemented later in this series. For now, the "funny" interfaces are just QMP commands and events with feature "deprecated". We'll want to extend this to arguments, returns, and the command line. Extending it to experimental interfaces may make sense. FIXME Documentation and help need some work Signed-off-by: Markus Armbruster --- qapi/common.json | 48 ++++++++++++++++++++++++++++++++++++ include/qapi/compat-policy.h | 20 +++++++++++++++ qapi/qmp-dispatch.c | 3 +++ vl.c | 17 +++++++++++++ qemu-options.hx | 18 ++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 include/qapi/compat-policy.h diff --git a/qapi/common.json b/qapi/common.json index 7b9cbcd97b..9fc3e6400c 100644 --- a/qapi/common.json +++ b/qapi/common.json @@ -144,3 +144,51 @@ ## { 'enum': 'PCIELinkWidth', 'data': [ '1', '2', '4', '8', '12', '16', '32' ] } + +## +# @CompatPolicyInput: +# +# Policy for handling "funny" input. +# +# @accept: Accept silently +# TODO @reject: Reject with an error +# TODO @crash: abort() the process +# +# FIXME Guidance on intended use. +# +# Since: 4.2 +## +{ 'enum': 'CompatPolicyInput', + 'data': [ 'accept' ] } + +## +# @CompatPolicyOutput: +# +# Policy for handling "funny" output. +# +# @accept: Pass on unchanged +# TODO @hide: Filter out +# +# FIXME Guidance on intended use. +# +# Since: 4.2 +## +{ 'enum': 'CompatPolicyOutput', + 'data': [ 'accept' ] } + +## +# @CompatPolicy: +# +# Policy for handling "funny" management interfaces. +# +# Limitation: covers only QMP commands and events. Argument support +# is not yet implemented. CLI is not yet implemented. +# +# @deprecated-input: how to handle deprecated input (default 'accept') +# @deprecated-output: how to handle deprecated output (default 'accept') +## +{ 'struct': 'CompatPolicy', + 'data': { '*deprecated-input': 'CompatPolicyInput', + '*deprecated-output': 'CompatPolicyOutput' } } + +# FIXME CompatPolicy & friends don't belong here diff --git a/include/qapi/compat-policy.h b/include/qapi/compat-policy.h new file mode 100644 index 0000000000..c491d74aac --- /dev/null +++ b/include/qapi/compat-policy.h @@ -0,0 +1,20 @@ +/* + * Policy for handling "funny" management interfaces + * + * Copyright (C) 2019 Red Hat, Inc. + * + * Authors: + * Markus Armbruster , + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef QAPI_COMPAT_POLICY_H +#define QAPI_COMPAT_POLICY_H + +#include "qapi/qapi-types-common.h" + +extern CompatPolicy qapi_compat_policy; + +#endif diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 55bc224c61..8fe59cf54d 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -12,6 +12,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" @@ -19,6 +20,8 @@ #include "sysemu/runstate.h" #include "qapi/qmp/qbool.h" =20 +CompatPolicy qapi_compat_policy; + static QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oo= b, QObject **id, Error **errp) { diff --git a/vl.c b/vl.c index 4489cfb2bb..300f2a01de 100644 --- a/vl.c +++ b/vl.c @@ -26,6 +26,7 @@ #include "qemu-common.h" #include "qemu/units.h" #include "hw/qdev-properties.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qemu-version.h" #include "qemu/cutils.h" @@ -3783,6 +3784,22 @@ int main(int argc, char **argv, char **envp) qemu_opt_get_bool(opts, "mem-lock", false); enable_cpu_pm =3D qemu_opt_get_bool(opts, "cpu-pm", false); break; + case QEMU_OPTION_compat: + { + CompatPolicy *opts; + Visitor *v; + + v =3D qobject_input_visitor_new_str(optarg, NULL, + &error_fatal); + + visit_type_CompatPolicy(v, NULL, &opts, &error_fatal); + QAPI_CLONE_MEMBERS(CompatPolicy, &qapi_compat_policy, + opts); + + qapi_free_CompatPolicy(opts); + visit_free(v); + break; + } case QEMU_OPTION_msg: opts =3D qemu_opts_parse_noisily(qemu_find_opts("msg"), op= targ, false); diff --git a/qemu-options.hx b/qemu-options.hx index 996b6fba74..c43f768a15 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3319,6 +3319,24 @@ STEXI @table @option ETEXI =20 +DEF("compat", HAS_ARG, QEMU_OPTION_compat, + "-compat [deprecated-input=3Daccept][,deprecated-output=3Daccept]\n" + " Policy for handling deprecated management interfaces\= n", + QEMU_ARCH_ALL) +STEXI +@item -compat [deprecated-input=3D@var{input-policy}][,deprecated-output= =3D@var{output-policy}] +@findex -compat + +Set policy for handling deprecated management interfaces: +@table @option +@item deprecated-input=3Daccept (default) +Accept deprecated commands +@item deprecated-output=3Daccept (default) +Emit deprecated events +@end table +FIXME Guidance on intended use +ETEXI + DEF("fw_cfg", HAS_ARG, QEMU_OPTION_fwcfg, "-fw_cfg [name=3D],file=3D\n" " add named fw_cfg entry with contents from file\n" --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920539; cv=none; d=zoho.com; s=zohoarc; b=KNRWVdNOGCs5MoMlT9t/2Z1VVsQsYVTOmQ07fNXEOGUkIO5OpQriMsW/eQt0Py8fYEQcYQZsaVVUH0e+QcLRVaXpEvsZGIrXFQT3B37PUN37xm3adJXdZkog4U9ewABo37bp8de8Ym2/tDKCjrIGwqXO2hFv0lYvXqfuP5Js/Vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920539; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bU8WnGDi9GHTIjg49i9PK+WmgV8NVpEn+0MHwSUtMZw=; b=mo10xMfiwxFNX/KepZfgAhy8GlOfsH4/22LXe/gGQXs9OHbL6zI/vh87UKfEVC6W+LywsWHHfYW7osry6zSYSL8ZEeZMf7sX45v/bjoOFXgIKM+cLM4CntRolwEaeIiHY+OratrdPHKoha7J8hfW7P/gizlrwDcnbX0QQNbYUY4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571920539333744.4034778488013; Thu, 24 Oct 2019 05:35:39 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-248-_X45MBguOgCQ79tup7Vegw-1; Thu, 24 Oct 2019 08:35:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B97FC1005530; Thu, 24 Oct 2019 12:35:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 845B6601AF; Thu, 24 Oct 2019 12:35:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 338684EE75; Thu, 24 Oct 2019 12:35:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ8FD004473 for ; Thu, 24 Oct 2019 08:35:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 415265D9CA; Thu, 24 Oct 2019 12:35:08 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DD4A5413A; Thu, 24 Oct 2019 12:35:07 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2B2FB1130344; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920538; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bU8WnGDi9GHTIjg49i9PK+WmgV8NVpEn+0MHwSUtMZw=; b=AazE6Hj9NWssgQFCde+ePtcZXpD8GstOc3bZak+tAaTYlyGthKThOeO0srKC2CjPk/+ePL FpU8sQZtZCKLbY4GdHdko1eY/ERa9xzE8bOIwXZhBN3nDxhvta32EG/gbX8NPhYPLPtilH IsCZ95PqwrtVvSad7o0h2uaVpiPUuSM= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:54 +0200 Message-Id: <20191024123458.13505-16-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 15/19] qapi: Mark deprecated QMP commands with feature 'deprecated' X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: _X45MBguOgCQ79tup7Vegw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add feature 'deprecated' to the deprecated QMP commands, so their deprecation becomes visible in output of query-qmp-schema. Looks like this: {"name": "query-cpus", "ret-type": "[164]", "meta-type": "command", "arg-type": "0", ---> "features": ["deprecated"]} The deprecated commands are change, cpu-add, migrate-set-cache-size, migrate_set_downtime, migrate_set_speed, query-cpus, query-events, query-migrate-cache-size. Management applications can use -compat deprecated-input=3D... to set policy for these commands. So far, the only available policy is "accept", which doesn't change behavior. The next few commits will provide more interesting policies. Command deprecation becomes visible in introspection. Management applications could conceivably use this for static checking. Signed-off-by: Markus Armbruster --- qapi/machine.json | 24 ++++++++++++++---------- qapi/migration.json | 36 ++++++++++++++++++++++++------------ qapi/misc.json | 25 +++++++++++++++---------- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/qapi/machine.json b/qapi/machine.json index ca26779f1a..3913ef2138 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -189,6 +189,11 @@ # It is recommended to use @query-cpus-fast instead of this command to # avoid the vCPU interruption. # +# Features: +# @deprecated: This interface is deprecated (since 2.12.0), and it is +# strongly recommended that you avoid using it. Use +# @query-cpus-fast to obtain information about virtual CPUs. +# # Returns: a list of @CpuInfo for each virtual CPU # # Since: 0.14.0 @@ -218,12 +223,9 @@ # ] # } # -# Notes: This interface is deprecated (since 2.12.0), and it is strongly -# recommended that you avoid using it. Use @query-cpus-fast to -# obtain information about virtual CPUs. -# ## -{ 'command': 'query-cpus', 'returns': ['CpuInfo'] } +{ 'command': 'query-cpus', 'returns': ['CpuInfo'], + 'features': [ 'deprecated' ] } =20 ## # @CpuInfoFast: @@ -309,21 +311,23 @@ # # @id: ID of CPU to be created, valid values [0..max_cpus) # +# Features: +# @deprecated: This command is deprecated. The `device_add` command +# should be used instead. See the `query-hotpluggable-cpus` +# command for details. +# # Returns: Nothing on success # # Since: 1.5 # -# Note: This command is deprecated. The `device_add` command should be -# used instead. See the `query-hotpluggable-cpus` command for -# details. -# # Example: # # -> { "execute": "cpu-add", "arguments": { "id": 2 } } # <- { "return": {} } # ## -{ 'command': 'cpu-add', 'data': {'id': 'int'} } +{ 'command': 'cpu-add', 'data': {'id': 'int'}, + 'features': [ 'deprecated' ] } =20 ## # @MachineInfo: diff --git a/qapi/migration.json b/qapi/migration.json index 82feb5bd39..a110948bfe 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1119,9 +1119,11 @@ # # @value: maximum downtime in seconds # -# Returns: nothing on success +# Features: +# @deprecated: This command is deprecated in favor of +# 'migrate-set-parameters'. # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# Returns: nothing on success # # Since: 0.14.0 # @@ -1131,7 +1133,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate_set_downtime', 'data': {'value': 'number'} } +{ 'command': 'migrate_set_downtime', 'data': {'value': 'number'}, + 'features': [ 'deprecated' ] } =20 ## # @migrate_set_speed: @@ -1140,9 +1143,11 @@ # # @value: maximum speed in bytes per second. # -# Returns: nothing on success +# Features: +# @deprecated: This command is deprecated in favor of +# 'migrate-set-parameters'. # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# Returns: nothing on success # # Since: 0.14.0 # @@ -1152,7 +1157,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate_set_speed', 'data': {'value': 'int'} } +{ 'command': 'migrate_set_speed', 'data': {'value': 'int'}, + 'features': [ 'deprecated' ] } =20 ## # @migrate-set-cache-size: @@ -1161,13 +1167,15 @@ # # @value: cache size in bytes # +# Features: +# @deprecated: This command is deprecated in favor of +# 'migrate-set-parameters'. +# # The size will be rounded down to the nearest power of 2. # The cache size can be modified before and during ongoing migration # # Returns: nothing on success # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' -# # Since: 1.2 # # Example: @@ -1177,17 +1185,20 @@ # <- { "return": {} } # ## -{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'} } +{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'}, + 'features': [ 'deprecated' ] } =20 ## # @query-migrate-cache-size: # # Query migration XBZRLE cache size # +# Features: +# @deprecated: This command is deprecated in favor of +# 'query-migrate-parameters'. +# # Returns: XBZRLE cache size in bytes # -# Notes: This command is deprecated in favor of 'query-migrate-parameters' -# # Since: 1.2 # # Example: @@ -1196,7 +1207,8 @@ # <- { "return": 67108864 } # ## -{ 'command': 'query-migrate-cache-size', 'returns': 'int' } +{ 'command': 'query-migrate-cache-size', 'returns': 'int', + 'features': [ 'deprecated' ] } =20 ## # @migrate: diff --git a/qapi/misc.json b/qapi/misc.json index 33b94e3589..abd2e5dc6e 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -316,13 +316,15 @@ # # Return information on QMP events. # +# Features: +# @deprecated: This command is deprecated, because its output doesn't +# reflect compile-time configuration. Use query-qmp-schema +# instead. +# # Returns: A list of @EventInfo. # # Since: 1.2.0 # -# Note: This command is deprecated, because its output doesn't reflect -# compile-time configuration. Use query-qmp-schema instead. -# # Example: # # -> { "execute": "query-events" } @@ -340,7 +342,8 @@ # Note: This example has been shortened as the real response is too long. # ## -{ 'command': 'query-events', 'returns': ['EventInfo'] } +{ 'command': 'query-events', 'returns': ['EventInfo'], + 'features': [ 'deprecated' ] } =20 ## # @IOThreadInfo: @@ -1074,14 +1077,15 @@ # If @device is 'vnc' and @target is 'password', this is the new = VNC # password to set. See change-vnc-password for additional notes. # +# Features: +# @deprecated: This command is deprecated, and it is strongly +# recommended that you avoid using it. For changing block +# devices, use blockdev-change-medium; for changing VNC +# parameters, use change-vnc-password. +# # Returns: Nothing on success. # If @device is not a valid block device, DeviceNotFound # -# Notes: This interface is deprecated, and it is strongly recommended tha= t you -# avoid using it. For changing block devices, use -# blockdev-change-medium; for changing VNC parameters, use -# change-vnc-password. -# # Since: 0.14.0 # # Example: @@ -1102,7 +1106,8 @@ # ## { 'command': 'change', - 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + 'data': {'device': 'str', 'target': 'str', '*arg': 'str'}, + 'features': [ 'deprecated' ] } =20 ## # @xen-set-global-dirty-log: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920544; cv=none; d=zoho.com; s=zohoarc; b=Hbh+K2ewTSwv6zX+ZtglMPOsq7FVOKT8sKWXjk4uWWb4lHWAXIH24AELm02vueKwatrwpQ8v/t1hqGIXWbsuY4X7FYRfxsOiyoxaN+UkEzcqL+yh7q91VW7VKZ7Say4Cg+1coCzz78Jko6D5oih/HGvsvelMGvT/4WW+T6PSXJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920544; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=U5CRcnECN8l/dSTlxE80LdDBAZ8iKas1FgSkuv0RBIU=; b=Ihn4UUvsPbLyIMij8IZ3bEJ+wHtTu+O+6XTN/mzqcqT/MpqWvadXjq1lrD96W3NLRWs4kCrSBrqAUTcdu+N+ZeNXZPY4ELvxxKgoviDywhIiETylf7C8psVwe3J+QCoVNvffru4RDbYmi8CCc3jwtbDU5NHSUN18F8m7DQFkeWw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571920544138609.2724627194394; Thu, 24 Oct 2019 05:35:44 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-76-07tL4oOeO9iHCkvrxc7-Iw-1; Thu, 24 Oct 2019 08:35:39 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFF88100552D; Thu, 24 Oct 2019 12:35:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 838FC10027C5; Thu, 24 Oct 2019 12:35:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 363974EEBD; Thu, 24 Oct 2019 12:35:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ8tr004474 for ; Thu, 24 Oct 2019 08:35:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 467BE52F6; Thu, 24 Oct 2019 12:35:08 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E0FAE52E7; Thu, 24 Oct 2019 12:35:07 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2E5A71130346; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920543; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=U5CRcnECN8l/dSTlxE80LdDBAZ8iKas1FgSkuv0RBIU=; b=DqWmb891rkgYSx/+ek4o6FL3YhiMYcTrypNs8H5jzejquVQ1j7IE4cyfnAzNlWDUywzEaE trLTqcuekAdJaTNlrrrBlASywFqJTcwPAdIzygNlNSiZYTbS2+4IofEXB58pzd9pyGi/G7 ayKYI04qBiLsIgRnigTL3HVW1t+rEpc= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:55 +0200 Message-Id: <20191024123458.13505-17-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 16/19] qapi: Implement -compat deprecated-input=reject for commands X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 07tL4oOeO9iHCkvrxc7-Iw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This policy makes deprecated commands fail like this: ---> {"execute": "query-cpus"} <--- {"error": {"class": "CommandNotFound", "desc": "Deprecated command= query-cpus disabled by policy"}} When the command is removed, the error will change to <--- {"error": {"class": "CommandNotFound", "desc": "The command query-= cpus has not been found"}} The policy thus permits "testing the future". Signed-off-by: Markus Armbruster --- qapi/common.json | 4 ++-- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-dispatch.c | 13 +++++++++++++ tests/test-qmp-cmds.c | 23 +++++++++++++++++++++++ qemu-options.hx | 4 +++- scripts/qapi/commands.py | 10 +++++++--- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/qapi/common.json b/qapi/common.json index 9fc3e6400c..3e9d12c90f 100644 --- a/qapi/common.json +++ b/qapi/common.json @@ -151,7 +151,7 @@ # Policy for handling "funny" input. # # @accept: Accept silently -# TODO @reject: Reject with an error +# @reject: Reject with an error # TODO @crash: abort() the process # # FIXME Guidance on intended use. @@ -159,7 +159,7 @@ # Since: 4.2 ## { 'enum': 'CompatPolicyInput', - 'data': [ 'accept' ] } + 'data': [ 'accept', 'reject' ] } =20 ## # @CompatPolicyOutput: diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 9aa426a398..ef256f2bb7 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -24,6 +24,7 @@ typedef enum QmpCommandOptions QCO_NO_SUCCESS_RESP =3D (1U << 0), QCO_ALLOW_OOB =3D (1U << 1), QCO_ALLOW_PRECONFIG =3D (1U << 2), + QCO_DEPRECATED =3D (1U << 3), } QmpCommandOptions; =20 typedef struct QmpCommand diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 8fe59cf54d..b079db85d2 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -132,6 +132,19 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *req= uest, "The command %s has not been found", command); goto out; } + if (cmd->options & QCO_DEPRECATED) { + switch (qapi_compat_policy.deprecated_input) { + case COMPAT_POLICY_INPUT_ACCEPT: + break; + case COMPAT_POLICY_INPUT_REJECT: + error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, + "Deprecated command %s disabled by policy", + command); + goto out; + default: + abort(); + } + } if (!cmd->enabled) { error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has been disabled for this instance", diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index cf4fa1a091..005ea24a27 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -1,4 +1,5 @@ #include "qemu/osdep.h" +#include "qapi/compat-policy.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qnum.h" @@ -235,6 +236,26 @@ static void test_dispatch_cmd_success_response(void) qobject_unref(req); } =20 +static void test_dispatch_cmd_deprecated(void) +{ + const char *cmd =3D "{ 'execute': 'test-command-features1' }"; + QDict *ret; + + /* accept */ + ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + assert(ret && qdict_size(ret) =3D=3D 0); + qobject_unref(ret); + + qapi_compat_policy.has_deprecated_input =3D true; + qapi_compat_policy.deprecated_input =3D COMPAT_POLICY_INPUT_ACCEPT; + ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + assert(ret && qdict_size(ret) =3D=3D 0); + qobject_unref(ret); + + qapi_compat_policy.deprecated_input =3D COMPAT_POLICY_INPUT_REJECT; + do_qmp_dispatch_error(false, ERROR_CLASS_COMMAND_NOT_FOUND, cmd); +} + /* test commands that involve both input parameters and return values */ static void test_dispatch_cmd_io(void) { @@ -344,6 +365,8 @@ int main(int argc, char **argv) g_test_add_func("/qmp/dispatch_cmd_io", test_dispatch_cmd_io); g_test_add_func("/qmp/dispatch_cmd_success_response", test_dispatch_cmd_success_response); + g_test_add_func("/qmp/dispatch_cmd_deprecated", + test_dispatch_cmd_deprecated); g_test_add_func("/qmp/dealloc_types", test_dealloc_types); g_test_add_func("/qmp/dealloc_partial", test_dealloc_partial); =20 diff --git a/qemu-options.hx b/qemu-options.hx index c43f768a15..f107a57c81 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3320,7 +3320,7 @@ STEXI ETEXI =20 DEF("compat", HAS_ARG, QEMU_OPTION_compat, - "-compat [deprecated-input=3Daccept][,deprecated-output=3Daccept]\n" + "-compat [deprecated-input=3Daccept|reject][,deprecated-output=3Daccep= t]\n" " Policy for handling deprecated management interfaces\= n", QEMU_ARCH_ALL) STEXI @@ -3331,6 +3331,8 @@ Set policy for handling deprecated management interfa= ces: @table @option @item deprecated-input=3Daccept (default) Accept deprecated commands +@item deprecated-input=3Dreject +Reject deprecated commands @item deprecated-output=3Daccept (default) Emit deprecated events @end table diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 11e9a6c095..df2a132915 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -194,9 +194,13 @@ out: return ret =20 =20 -def gen_register_command(name, success_response, allow_oob, allow_preconfi= g): +def gen_register_command(name, features, + success_response, allow_oob, allow_preconfig): options =3D [] =20 + if 'deprecated' in [f.name for f in features]: + options +=3D ['QCO_DEPRECATED'] + if not success_response: options +=3D ['QCO_NO_SUCCESS_RESP'] if allow_oob: @@ -295,8 +299,8 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); self._genh.add(gen_command_decl(name, arg_type, boxed, ret_typ= e)) self._genh.add(gen_marshal_decl(name)) self._genc.add(gen_marshal(name, arg_type, boxed, ret_type)) - self._regy.add(gen_register_command(name, success_response, - allow_oob, allow_preconfig= )) + self._regy.add(gen_register_command( + name, features, success_response, allow_oob, allow_preconf= ig)) =20 =20 def gen_commands(schema, output_dir, prefix): --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920527; cv=none; d=zoho.com; s=zohoarc; b=a8wyB9idQefY3rWCkdN4KJrgpWfrxTyqnhfxqhHU+BalAnPhLxynXSobGXsNg8SsyJf+5GZUI4hIq89HnJnDfjD4er6fRhnje2WA3BZqmko/x1ZmH3DtbKVz5odGzvQCoC7OmClmZISoFbVjacFO/wineJrcZ2mtwhhP6vw4UKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920527; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BygR34LySj0l7ppg21rNNPWEo8jhNWcQwBrvYuZcl2U=; b=hnRAm5pztoeMAraeYq2xLTzKeJqcS+oGq0ADdG48Ji3XY8ugbrILRCSzuLtMiAg/gxcICMxdFSjF8ivaVO/16fsFkzrdT20m8dYJzO3eYKBToz5pZpWsRUQAgZieqPPPxmjakwZla39+KI/lZWTDWvVi4Wiz4WaHFoB1291VlSI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571920527700439.4668539353031; Thu, 24 Oct 2019 05:35:27 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-102-nUnRK-0nMHCUfXSsbGNUAA-1; Thu, 24 Oct 2019 08:35:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 08164476; Thu, 24 Oct 2019 12:35:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB06E5D712; Thu, 24 Oct 2019 12:35:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6F5361803B4C; Thu, 24 Oct 2019 12:35:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ9L2004500 for ; Thu, 24 Oct 2019 08:35:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id C63165DC1E; Thu, 24 Oct 2019 12:35:09 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 944645D9CA; Thu, 24 Oct 2019 12:35:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 317951130348; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920526; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BygR34LySj0l7ppg21rNNPWEo8jhNWcQwBrvYuZcl2U=; b=fuxa3ZM6QZ0iLN7GkLhJMmkdS4dks+j+Zo3zwB6yq6M9GNMfV1V2JDAreKya1QskgqWQos XcrvGNRCteyDlthc9uD4rKnyw6go0ENpTkiymQbCnqNkgs3HHQjZ2u5WA5oqLA4RFnNrw6 /wWoAFqaE3mCEbG8yelbBsFMaOJmYHI= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:56 +0200 Message-Id: <20191024123458.13505-18-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 17/19] qapi: Implement -compat deprecated-input=crash for commands X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: nUnRK-0nMHCUfXSsbGNUAA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This policy calls abort() when a deprecated command is received. Crashing should reliably[*] fail existing integration tests with very little additional work (just pass the option). [*] Bugs in tests can conceivably mask even crashes, but that seems unlikely. Signed-off-by: Markus Armbruster --- qapi/common.json | 4 ++-- qapi/qmp-dispatch.c | 1 + qemu-options.hx | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/qapi/common.json b/qapi/common.json index 3e9d12c90f..06e54642bb 100644 --- a/qapi/common.json +++ b/qapi/common.json @@ -152,14 +152,14 @@ # # @accept: Accept silently # @reject: Reject with an error -# TODO @crash: abort() the process +# @crash: abort() the process # # FIXME Guidance on intended use. # # Since: 4.2 ## { 'enum': 'CompatPolicyInput', - 'data': [ 'accept', 'reject' ] } + 'data': [ 'accept', 'reject', 'crash' ] } =20 ## # @CompatPolicyOutput: diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index b079db85d2..6436417844 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -141,6 +141,7 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *requ= est, "Deprecated command %s disabled by policy", command); goto out; + case COMPAT_POLICY_INPUT_CRASH: default: abort(); } diff --git a/qemu-options.hx b/qemu-options.hx index f107a57c81..3a740ea7b1 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3320,7 +3320,7 @@ STEXI ETEXI =20 DEF("compat", HAS_ARG, QEMU_OPTION_compat, - "-compat [deprecated-input=3Daccept|reject][,deprecated-output=3Daccep= t]\n" + "-compat [deprecated-input=3Daccept|reject|crash][,deprecated-output= =3Daccept]\n" " Policy for handling deprecated management interfaces\= n", QEMU_ARCH_ALL) STEXI @@ -3333,6 +3333,8 @@ Set policy for handling deprecated management interfa= ces: Accept deprecated commands @item deprecated-input=3Dreject Reject deprecated commands +@item deprecated-input=3Dcrash +Crash on deprecated command @item deprecated-output=3Daccept (default) Emit deprecated events @end table --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920531; cv=none; d=zoho.com; s=zohoarc; b=KgF2t0yZVKqePWyMmCf6Na16XeeV7ePHcbBolvm0TJli0rbmd+hGfuBdJfeJTsqA4A0FRTilU1UYdvS86DqHROm6Y59DUUsHXim3uwhZ55un88QXnuoZ7vsn8GTCnHiSpQu5nzURIV5zUOUXybhV1XhN+hweKcqFu3DIIDi8v0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920531; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oRYK1wNoUbOrUpLJ6I71pEg0Uq7IZmeodd1g8M9qKjU=; b=YbSxYqejnsL+HtuHmvtdrtPxQuUK0JGcLk5YcN74CxTlBx0xscu06FJ3B5b/AVlOKSLCFiDgFMjsH2LFS9sULatM2nVjEG5EqP5gmdYCVorSgwygCSEJsisJ2BAX24eUQYFX/45FiSsnkuzpAezIoKlJNRh32bN2VDp0vX2nDbM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571920531965928.1670560522145; Thu, 24 Oct 2019 05:35:31 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-2hgFcbWpNGeEbK_eRm0VtQ-1; Thu, 24 Oct 2019 08:35:29 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9386D800D64; Thu, 24 Oct 2019 12:35:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 643B54523; Thu, 24 Oct 2019 12:35:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 134054EE6A; Thu, 24 Oct 2019 12:35:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZAfe004507 for ; Thu, 24 Oct 2019 08:35:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 009076012D; Thu, 24 Oct 2019 12:35:10 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A3BF60161; Thu, 24 Oct 2019 12:35:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 34A8F113034A; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920530; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=oRYK1wNoUbOrUpLJ6I71pEg0Uq7IZmeodd1g8M9qKjU=; b=BTKERl62Fhr2PUWV3ZcYN4MHlBbpJTn7izCUqqhXqEX/snB1ng3xvg4XZJlzy3EAc6o6jB r5Nn9R8oEjD0dzghUMhGYAu1wrQEXESi0Ilt0qoT/qYcUiLULJCKLdatR3mJnXYUEDICM2 N3XeXBqxDd9n5DKfERmeObJd2vOx6ik= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:57 +0200 Message-Id: <20191024123458.13505-19-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 18/19] qapi: Include a warning in the response to a deprecated command X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 2hgFcbWpNGeEbK_eRm0VtQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Looks like this ---> {"execute": "query-cpus"} <--- {"return": [...], "warnings": [{"class": "CommandNotFound", "desc"= : "command is deprecated"}]} Management applications may want to log such warnings. This commit is not for merging as is, because * docs/interop/qmp-spec.txt needs an update for the new success response member "warnings". * I'd like to see a prospective user before I extend the QMP protocol. If you have specific plans to put them to use, let me know. * The same warning should be included in a deprecated event. * Emitting the same warning over and over again might be annoying or slow. Perhaps warning just once would be better. Signed-off-by: Markus Armbruster --- qapi/qmp-dispatch.c | 8 ++++++++ tests/test-qmp-cmds.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qemu-options.hx | 2 +- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 6436417844..9c17a59f31 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -197,6 +197,14 @@ out: } else { rsp =3D qdict_new(); qdict_put_obj(rsp, "return", ret); + if (cmd->options & QCO_DEPRECATED) { + qdict_put_obj( + rsp, "warnings", + qobject_from_jsonf_nofail( + "[ { 'class': %s, 'desc': %s } ]", + QapiErrorClass_str(ERROR_CLASS_COMMAND_NOT_FOUND), + "command is deprecated")); + } } =20 if (id) { diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 005ea24a27..38d2e5b4a7 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -2,6 +2,7 @@ #include "qapi/compat-policy.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" +#include "qapi/qmp/qlist.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" #include "qapi/error.h" @@ -164,6 +165,40 @@ static QObject *do_qmp_dispatch(bool allow_oob, const = char *template, ...) return ret; } =20 +static QObject *do_qmp_dispatch_warning(bool allow_oob, ErrorClass cls, + const char *template, ...) +{ + va_list ap; + QDict *req, *resp; + QObject *ret; + QList *warnings; + QDict *warning; + + va_start(ap, template); + req =3D qdict_from_vjsonf_nofail(template, ap); + va_end(ap); + + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); + g_assert(resp); + ret =3D qdict_get(resp, "return"); + g_assert(ret); + warnings =3D qdict_get_qlist(resp, "warnings"); + g_assert(warnings); + warning =3D qobject_to(QDict, qlist_peek(warnings)); + g_assert(warning); + g_assert_cmpstr(qdict_get_try_str(warning, "class"), + =3D=3D, QapiErrorClass_str(cls)); + g_assert(qdict_get_try_str(warning, "desc")); + g_assert(qdict_size(warning) =3D=3D 2); + g_assert(qlist_size(warnings) =3D=3D 1); + g_assert(qdict_size(resp) =3D=3D 2); + + qobject_ref(ret); + qobject_unref(resp); + qobject_unref(req); + return ret; +} + static void do_qmp_dispatch_error(bool allow_oob, ErrorClass cls, const char *template, ...) { @@ -242,13 +277,17 @@ static void test_dispatch_cmd_deprecated(void) QDict *ret; =20 /* accept */ - ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + ret =3D qobject_to(QDict, do_qmp_dispatch_warning( + false, ERROR_CLASS_COMMAND_NOT_FOUND, + "{ 'execute': 'test-command-features1' }")); assert(ret && qdict_size(ret) =3D=3D 0); qobject_unref(ret); =20 qapi_compat_policy.has_deprecated_input =3D true; qapi_compat_policy.deprecated_input =3D COMPAT_POLICY_INPUT_ACCEPT; - ret =3D qobject_to(QDict, do_qmp_dispatch(false, cmd)); + ret =3D qobject_to(QDict, do_qmp_dispatch_warning( + false, ERROR_CLASS_COMMAND_NOT_FOUND, + "{ 'execute': 'test-command-features1' }")); assert(ret && qdict_size(ret) =3D=3D 0); qobject_unref(ret); =20 diff --git a/qemu-options.hx b/qemu-options.hx index 3a740ea7b1..645629457a 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3330,7 +3330,7 @@ STEXI Set policy for handling deprecated management interfaces: @table @option @item deprecated-input=3Daccept (default) -Accept deprecated commands +Accept deprecated commands with a warning @item deprecated-input=3Dreject Reject deprecated commands @item deprecated-input=3Dcrash --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:31:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920569; cv=none; d=zoho.com; s=zohoarc; b=kcJ3SCz9P6XeZa5Cy5+wpK7K6S0iykY9Y5Z/4aZKJzqW26IN4mXQ/m7gD4SGJLxyiEqJwdV03HDNeRiKzDvbJlojXqDGq9eDpTGZRURxWtLvYdA/DB3M+WD+OrhOL2ZZIbHll6bgoRHNFHIJb/0XOymvwRWNiEr37Xivp+KEwVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920569; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aasGP68poqHNgPWiovdNiTbbIbH25VqckB+BhIQNShU=; b=olPmXJf9rIuY4KW9npX4gRRA5MY+KDzN0lu5+FXj8tsSkPuQMaNcRO9on+/Nig0y4rOYjK6i6WD5n5Iliyrd4iWq6kCRpLv/bpEM+zqfI77tseDC4FoHx+o4z2ttFfrbPSHQYcBO/voV8D6n8vHB0rau8CNlk7GLuy6bDFqquMA= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571920569618465.4757438963545; Thu, 24 Oct 2019 05:36:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-CZxDSGIcOB-NvKBS013AOg-1; Thu, 24 Oct 2019 08:35:33 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BD4A71800E0D; Thu, 24 Oct 2019 12:35:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 90F8210027AD; Thu, 24 Oct 2019 12:35:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 45C7D180BA9E; Thu, 24 Oct 2019 12:35:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZAsZ004511 for ; Thu, 24 Oct 2019 08:35:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 021D660167; Thu, 24 Oct 2019 12:35:10 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9CC7760166; Thu, 24 Oct 2019 12:35:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 37D1D112FB55; Thu, 24 Oct 2019 14:34:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920568; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=aasGP68poqHNgPWiovdNiTbbIbH25VqckB+BhIQNShU=; b=UgTPn/RczXs01wruiPbYR4EKw2ovDWX0ajekYGE1jcXUHvqzrFpv+HtZYKtqsrqYqfMH5W +e1sLxtNjylNsc4mR/+YKYwyKUy+KL6VMM+Dw1Njiy1tcW8fbTluk0z19hf/czkwgWFey9 JaEPoU+onagoq46ig7cPTfvTF/d/ir4= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:58 +0200 Message-Id: <20191024123458.13505-20-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 19/19] qapi: Implement -compat deprecated-output=hide for events X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: CZxDSGIcOB-NvKBS013AOg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This policy suppresses deprecated events, and thus permits "testing the future". No QMP event is deprecated right now. Signed-off-by: Markus Armbruster --- qapi/common.json | 4 ++-- tests/test-qmp-event.c | 17 +++++++++++++++++ qemu-options.hx | 4 +++- scripts/qapi/events.py | 14 ++++++++++++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/qapi/common.json b/qapi/common.json index 06e54642bb..4e3da4beee 100644 --- a/qapi/common.json +++ b/qapi/common.json @@ -167,14 +167,14 @@ # Policy for handling "funny" output. # # @accept: Pass on unchanged -# TODO @hide: Filter out +# @hide: Filter out # # FIXME Guidance on intended use. # # Since: 4.2 ## { 'enum': 'CompatPolicyOutput', - 'data': [ 'accept' ] } + 'data': [ 'accept', 'hide' ] } =20 ## # @CompatPolicy: diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 7dd0053190..303c8d6382 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" =20 #include "qemu-common.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" @@ -140,6 +141,21 @@ static void test_event_d(TestEventData *data, qobject_unref(data->expect); } =20 +static void test_event_deprecated(TestEventData *data, const void *unused) +{ + data->expect =3D qdict_from_jsonf_nofail("{ 'event': 'TEST-EVENT-FEATU= RES1' }"); + + qapi_event_send_test_event_features1(); + g_assert(data->emitted); + + qapi_compat_policy.deprecated_output =3D COMPAT_POLICY_OUTPUT_HIDE; + data->emitted =3D false; + qapi_event_send_test_event_features1(); + g_assert(!data->emitted); + + qobject_unref(data->expect); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -148,6 +164,7 @@ int main(int argc, char **argv) event_test_add("/event/event_b", test_event_b); event_test_add("/event/event_c", test_event_c); event_test_add("/event/event_d", test_event_d); + event_test_add("/event/deprecated", test_event_deprecated); g_test_run(); =20 return 0; diff --git a/qemu-options.hx b/qemu-options.hx index 645629457a..c0128813c6 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3320,7 +3320,7 @@ STEXI ETEXI =20 DEF("compat", HAS_ARG, QEMU_OPTION_compat, - "-compat [deprecated-input=3Daccept|reject|crash][,deprecated-output= =3Daccept]\n" + "-compat [deprecated-input=3Daccept|reject|crash][,deprecated-output= =3Daccept|hide]\n" " Policy for handling deprecated management interfaces\= n", QEMU_ARCH_ALL) STEXI @@ -3337,6 +3337,8 @@ Reject deprecated commands Crash on deprecated command @item deprecated-output=3Daccept (default) Emit deprecated events +@item deprecated-output=3Dhide +Suppress deprecated events @end table FIXME Guidance on intended use ETEXI diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index f64e61076e..5778fa1a0d 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -61,7 +61,8 @@ def gen_param_var(typ): return ret =20 =20 -def gen_event_send(name, arg_type, boxed, event_enum_name, event_emit): +def gen_event_send(name, arg_type, features, boxed, + event_enum_name, event_emit): # FIXME: Our declaration of local variables (and of 'errp' in the # parameter list) can collide with exploded members of the event's # data type passed in as parameters. If this collision ever hits in @@ -86,6 +87,14 @@ def gen_event_send(name, arg_type, boxed, event_enum_nam= e, event_emit): if not boxed: ret +=3D gen_param_var(arg_type) =20 + if 'deprecated' in [f.name for f in features]: + ret +=3D mcgen(''' + + if (qapi_compat_policy.deprecated_output =3D=3D COMPAT_POLICY_OUTPUT_H= IDE) { + return; + } +''') + ret +=3D mcgen(''' =20 qmp =3D qmp_event_build_dict("%(name)s"); @@ -154,6 +163,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): #include "%(prefix)sqapi-emit-events.h" #include "%(events)s.h" #include "%(visit)s.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "qapi/qobject-output-visitor.h" @@ -192,7 +202,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); def visit_event(self, name, info, ifcond, features, arg_type, boxed): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) - self._genc.add(gen_event_send(name, arg_type, boxed, + self._genc.add(gen_event_send(name, arg_type, features, boxed, self._event_enum_name, self._event_emit_name)) # Note: we generate the enum member regardless of @ifcond, to --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list