From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491421926904745.7605693411076; Wed, 5 Apr 2017 12:52:06 -0700 (PDT) Received: from localhost ([::1]:42187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqyL-0005oK-IN for importer@patchew.org; Wed, 05 Apr 2017 15:52:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvquH-0002YV-GJ for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvquG-0007wK-9F for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58094) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquG-0007vW-0F for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:52 -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 mx1.redhat.com (Postfix) with ESMTPS id D46517E9C2 for ; Wed, 5 Apr 2017 19:47:50 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C6525C54B; Wed, 5 Apr 2017 19:47:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D46517E9C2 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D46517E9C2 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:29 -0500 Message-Id: <20170405194741.18956-2-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 05 Apr 2017 19:47:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 01/13] pci: Use struct instead of QDict to pass back parameters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marcel Apfelbaum , armbru@redhat.com, "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's simpler to just use a C struct than it is to bundle things into a QDict in one function just to pull them back out in the caller. Plus, doing this gets rid of one more user of dynamic JSON through qobject_from_jsonf(), as well as a memory leak of the QDict. While cleaning the code, fix things to report all errors (the code was previously silently ignoring a failure of pcie_aer_inject_error(), at a distance). Signed-off-by: Eric Blake Reviewed-by: Marcel Apfelbaum Reviewed-by: Michael S. Tsirkin --- v3: more cleanups suggested by Markus, drop R-b --- hw/pci/pcie_aer.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index a8c1820..653af86 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -44,6 +44,13 @@ #define PCI_ERR_SRC_COR_OFFS 0 #define PCI_ERR_SRC_UNCOR_OFFS 2 +typedef struct PCIEErrorDetails { + const char *id; + const char *root_bus; + int bus; + int devfn; +} PCIEErrorDetails; + /* From 6.2.7 Error Listing and Rules. Table 6-2, 6-3 and 6-4 */ static uint32_t pcie_aer_uncor_default_severity(uint32_t status) { @@ -942,8 +949,14 @@ static int pcie_aer_parse_error_string(const char *err= or_name, return -EINVAL; } +/* + * Inject an error described by @qdict. + * On success, set @details to show where error was sent. + * Return negative errno if injection failed and a message was emitted. + */ static int do_pcie_aer_inject_error(Monitor *mon, - const QDict *qdict, QObject **ret_data) + const QDict *qdict, + PCIEErrorDetails *details) { const char *id =3D qdict_get_str(qdict, "id"); const char *error_name; @@ -1005,33 +1018,28 @@ static int do_pcie_aer_inject_error(Monitor *mon, err.prefix[3] =3D qdict_get_try_int(qdict, "prefix3", 0); ret =3D pcie_aer_inject_error(dev, &err); - *ret_data =3D qobject_from_jsonf("{'id': %s, " - "'root_bus': %s, 'bus': %d, 'devfn': %d= , " - "'ret': %d}", - id, pci_root_bus_path(dev), - pci_bus_num(dev->bus), dev->devfn, - ret); - assert(*ret_data); + if (ret < 0) { + monitor_printf(mon, "failed to inject error: %s\n", + strerror(-ret)); + return ret; + } + details->id =3D id; + details->root_bus =3D pci_root_bus_path(dev); + details->bus =3D pci_bus_num(dev->bus); + details->devfn =3D dev->devfn; return 0; } void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict) { - QObject *data; - int devfn; + PCIEErrorDetails data; if (do_pcie_aer_inject_error(mon, qdict, &data) < 0) { return; } - qdict =3D qobject_to_qdict(data); - assert(qdict); - - devfn =3D (int)qdict_get_int(qdict, "devfn"); monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n", - qdict_get_str(qdict, "id"), - qdict_get_str(qdict, "root_bus"), - (int) qdict_get_int(qdict, "bus"), - PCI_SLOT(devfn), PCI_FUNC(devfn)); + data.id, data.root_bus, data.bus, + PCI_SLOT(data.devfn), PCI_FUNC(data.devfn)); } --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491421792441130.79626034803005; Wed, 5 Apr 2017 12:49:52 -0700 (PDT) Received: from localhost ([::1]:42172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqwA-0003uM-QO for importer@patchew.org; Wed, 05 Apr 2017 15:49:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvquH-0002Yu-T6 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvquH-0007wr-15 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37128) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquG-0007wI-Qr for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:52 -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 mx1.redhat.com (Postfix) with ESMTPS id D3A01C04F4AA for ; Wed, 5 Apr 2017 19:47:51 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1806C1719D; Wed, 5 Apr 2017 19:47:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D3A01C04F4AA Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D3A01C04F4AA From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:30 -0500 Message-Id: <20170405194741.18956-3-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 05 Apr 2017 19:47:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 02/13] pci: Reduce scope of error injection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marcel Apfelbaum , armbru@redhat.com, "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No one outside of pcie_aer.h was using error injection; mark them static for internal use. Signed-off-by: Eric Blake Reviewed-by: Marcel Apfelbaum Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v3: new patch, suggested by Markus --- include/hw/pci/pcie_aer.h | 4 ---- hw/pci/pcie_aer.c | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/include/hw/pci/pcie_aer.h b/include/hw/pci/pcie_aer.h index 526802b..729a943 100644 --- a/include/hw/pci/pcie_aer.h +++ b/include/hw/pci/pcie_aer.h @@ -100,8 +100,4 @@ void pcie_aer_root_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len, uint32_t root_cmd_prev); -/* error injection */ -int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err); -void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg); - #endif /* QEMU_PCIE_AER_H */ diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index 653af86..828052b 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -376,7 +376,7 @@ static void pcie_aer_msg_root_port(PCIDevice *dev, cons= t PCIEAERMsg *msg) * * Walk up the bus tree from the device, propagate the error message. */ -void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg) +static void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg) { uint8_t type; @@ -631,7 +631,7 @@ static bool pcie_aer_inject_uncor_error(PCIEAERInject *= inj, bool is_fatal) * Figure 6-2: Flowchart Showing Sequence of Device Error Signaling and Lo= gging * Operations */ -int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err) +static int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err) { uint8_t *aer_cap =3D NULL; uint16_t devctl =3D 0; --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491421793788248.5365903272051; Wed, 5 Apr 2017 12:49:53 -0700 (PDT) Received: from localhost ([::1]:42173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqwC-0003w5-KE for importer@patchew.org; Wed, 05 Apr 2017 15:49:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvquI-0002Zg-WA for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvquI-0007xi-07 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54492) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquH-0007x6-Qh for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:53 -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 mx1.redhat.com (Postfix) with ESMTPS id C6AFA7AEA4; Wed, 5 Apr 2017 19:47:52 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1626A5C54B; Wed, 5 Apr 2017 19:47:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C6AFA7AEA4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C6AFA7AEA4 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:31 -0500 Message-Id: <20170405194741.18956-4-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 05 Apr 2017 19:47:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 03/13] s390x: Drop useless casts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Graf , armbru@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" An upcoming Coccinelle cleanup script wanted to reformat the casts present in this file - but on closer look, we don't need the casts at all because C automatically converts void* to any other pointer. Signed-off-by: Eric Blake Acked-by: Cornelia Huck Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/s390x/cpu_models.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 1434d15..ce461cc 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -376,12 +376,12 @@ static void cpu_model_from_info(S390CPUModel *model, = const CpuModelInfo *info, static void qdict_add_disabled_feat(const char *name, void *opaque) { - qdict_put((QDict *) opaque, name, qbool_from_bool(false)); + qdict_put(opaque, name, qbool_from_bool(false)); } static void qdict_add_enabled_feat(const char *name, void *opaque) { - qdict_put((QDict *) opaque, name, qbool_from_bool(true)); + qdict_put(opaque, name, qbool_from_bool(true)); } /* convert S390CPUDef into a static CpuModelInfo */ --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491421794593407.70565263455444; Wed, 5 Apr 2017 12:49:54 -0700 (PDT) Received: from localhost ([::1]:42174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqwD-0003ws-F9 for importer@patchew.org; Wed, 05 Apr 2017 15:49:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvquJ-0002aD-HD for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvquI-0007xx-Lu for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquI-0007xY-G6 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:54 -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 mx1.redhat.com (Postfix) with ESMTPS id 81CB73D961 for ; Wed, 5 Apr 2017 19:47:53 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09BD05C54B; Wed, 5 Apr 2017 19:47:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 81CB73D961 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 81CB73D961 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:32 -0500 Message-Id: <20170405194741.18956-5-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 05 Apr 2017 19:47:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 04/13] coccinelle: Add script to remove useless QObject casts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We have macros in place to make it less verbose to add a subtype of QObject to both QDict and QList. While we have made cleanups like this in the past (see commit fcfcd8ffc, for example), having it be automated by Coccinelle makes it easier to maintain. The script is separate from the cleanups, for ease of review and backporting. A later patch will then add further possible cleanups. Signed-off-by: Eric Blake --- MAINTAINERS | 1 + scripts/coccinelle/qobject.cocci | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 scripts/coccinelle/qobject.cocci diff --git a/MAINTAINERS b/MAINTAINERS index c60235e..430efb0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1395,6 +1395,7 @@ S: Supported F: qobject/ F: include/qapi/qmp/ X: include/qapi/qmp/dispatch.h +F: scripts/coccinelle/qobject.cocci F: tests/check-qdict.c F: tests/check-qfloat.c F: tests/check-qint.c diff --git a/scripts/coccinelle/qobject.cocci b/scripts/coccinelle/qobject.= cocci new file mode 100644 index 0000000..aa899e2 --- /dev/null +++ b/scripts/coccinelle/qobject.cocci @@ -0,0 +1,13 @@ +// Use QDict macros where they make sense +@@ +expression Obj, Key, E; +@@ +- qdict_put_obj(Obj, Key, QOBJECT(E)); ++ qdict_put(Obj, Key, E); + +// Use QList macros where they make sense +@@ +expression Obj, E; +@@ +- qlist_append_obj(Obj, QOBJECT(E)); ++ qlist_append(Obj, E); --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491421946936295.78953350863674; Wed, 5 Apr 2017 12:52:26 -0700 (PDT) Received: from localhost ([::1]:42189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqyf-0006Gb-Nw for importer@patchew.org; Wed, 05 Apr 2017 15:52:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvquV-0002iI-2c for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvquT-00084d-GH for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37224) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquM-0007zi-Ba; Wed, 05 Apr 2017 15:47:58 -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 mx1.redhat.com (Postfix) with ESMTPS id 3493CC07F675; Wed, 5 Apr 2017 19:47:57 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id C11C35C54B; Wed, 5 Apr 2017 19:47:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3493CC07F675 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3493CC07F675 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:33 -0500 Message-Id: <20170405194741.18956-6-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 05 Apr 2017 19:47:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 05/13] qobject: Drop useless QObject casts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , Michael Roth , "open list:Block layer core" , Stefan Weil , armbru@redhat.com, Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We have macros in place to make it less verbose to add a subtype of QObject to both QDict and QList. While we have made cleanups like this in the past (see commit fcfcd8ffc, for example), having it be automated by Coccinelle makes it easier to maintain. Patch created mechanically via: spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h --dir . --in-place then I verified that no manual touchups were required. Signed-off-by: Eric Blake --- block.c | 12 ++++-------- block/blkdebug.c | 4 ++-- block/blkverify.c | 7 +++---- block/file-posix.c | 6 +++--- block/file-win32.c | 4 ++-- block/quorum.c | 16 ++++++---------- tests/check-qdict.c | 20 ++++++++++---------- tests/test-qmp-commands.c | 24 ++++++++++++------------ 8 files changed, 42 insertions(+), 51 deletions(-) diff --git a/block.c b/block.c index 927ba89..1803334 100644 --- a/block.c +++ b/block.c @@ -4658,11 +4658,9 @@ void bdrv_refresh_filename(BlockDriverState *bs) * contain a representation of the filename, therefore the followi= ng * suffices without querying the (exact_)filename of this BDS. */ if (bs->file->bs->full_open_options) { - qdict_put_obj(opts, "driver", - QOBJECT(qstring_from_str(drv->format_name))); + qdict_put(opts, "driver", qstring_from_str(drv->format_name)); QINCREF(bs->file->bs->full_open_options); - qdict_put_obj(opts, "file", - QOBJECT(bs->file->bs->full_open_options)); + qdict_put(opts, "file", bs->file->bs->full_open_options); bs->full_open_options =3D opts; } else { @@ -4678,8 +4676,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) opts =3D qdict_new(); append_open_options(opts, bs); - qdict_put_obj(opts, "driver", - QOBJECT(qstring_from_str(drv->format_name))); + qdict_put(opts, "driver", qstring_from_str(drv->format_name)); if (bs->exact_filename[0]) { /* This may not work for all block protocol drivers (some may @@ -4689,8 +4686,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) * needs some special format of the options QDict, it needs to * implement the driver-specific bdrv_refresh_filename() funct= ion. */ - qdict_put_obj(opts, "filename", - QOBJECT(qstring_from_str(bs->exact_filename))); + qdict_put(opts, "filename", qstring_from_str(bs->exact_filenam= e)); } bs->full_open_options =3D opts; diff --git a/block/blkdebug.c b/block/blkdebug.c index 67e8024..c5d4772 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -695,10 +695,10 @@ static void blkdebug_refresh_filename(BlockDriverStat= e *bs, QDict *options) } opts =3D qdict_new(); - qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkdebug"))); + qdict_put(opts, "driver", qstring_from_str("blkdebug")); QINCREF(bs->file->bs->full_open_options); - qdict_put_obj(opts, "image", QOBJECT(bs->file->bs->full_open_options)); + qdict_put(opts, "image", bs->file->bs->full_open_options); for (e =3D qdict_first(options); e; e =3D qdict_next(options, e)) { if (strcmp(qdict_entry_key(e), "x-image")) { diff --git a/block/blkverify.c b/block/blkverify.c index 9a1e21c..79c8914 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -291,13 +291,12 @@ static void blkverify_refresh_filename(BlockDriverSta= te *bs, QDict *options) && s->test_file->bs->full_open_options) { QDict *opts =3D qdict_new(); - qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkverify"= ))); + qdict_put(opts, "driver", qstring_from_str("blkverify")); QINCREF(bs->file->bs->full_open_options); - qdict_put_obj(opts, "raw", QOBJECT(bs->file->bs->full_open_options= )); + qdict_put(opts, "raw", bs->file->bs->full_open_options); QINCREF(s->test_file->bs->full_open_options); - qdict_put_obj(opts, "test", - QOBJECT(s->test_file->bs->full_open_options)); + qdict_put(opts, "test", s->test_file->bs->full_open_options); bs->full_open_options =3D opts; } diff --git a/block/file-posix.c b/block/file-posix.c index 0c48968..5370ba0 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -377,7 +377,7 @@ static void raw_parse_filename(const char *filename, QD= ict *options, * function call can be ignored. */ strstart(filename, "file:", &filename); - qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename))= ); + qdict_put(options, "filename", qstring_from_str(filename)); } static QemuOptsList raw_runtime_opts =3D { @@ -2150,7 +2150,7 @@ static void hdev_parse_filename(const char *filename,= QDict *options, /* The prefix is optional, just as for "file". */ strstart(filename, "host_device:", &filename); - qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename))= ); + qdict_put(options, "filename", qstring_from_str(filename)); } static bool hdev_is_sg(BlockDriverState *bs) @@ -2449,7 +2449,7 @@ static void cdrom_parse_filename(const char *filename= , QDict *options, /* The prefix is optional, just as for "file". */ strstart(filename, "host_cdrom:", &filename); - qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename))= ); + qdict_put(options, "filename", qstring_from_str(filename)); } #endif diff --git a/block/file-win32.c b/block/file-win32.c index 800fabd..57c4a78 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -282,7 +282,7 @@ static void raw_parse_filename(const char *filename, QD= ict *options, * function call can be ignored. */ strstart(filename, "file:", &filename); - qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename))= ); + qdict_put(options, "filename", qstring_from_str(filename)); } static QemuOptsList raw_runtime_opts =3D { @@ -669,7 +669,7 @@ static void hdev_parse_filename(const char *filename, Q= Dict *options, /* The prefix is optional, just as for "file". */ strstart(filename, "host_device:", &filename); - qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename))= ); + qdict_put(options, "filename", qstring_from_str(filename)); } static int hdev_open(BlockDriverState *bs, QDict *options, int flags, diff --git a/block/quorum.c b/block/quorum.c index 40205fb..f7949e2 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1096,19 +1096,15 @@ static void quorum_refresh_filename(BlockDriverStat= e *bs, QDict *options) children =3D qlist_new(); for (i =3D 0; i < s->num_children; i++) { QINCREF(s->children[i]->bs->full_open_options); - qlist_append_obj(children, - QOBJECT(s->children[i]->bs->full_open_options)); + qlist_append(children, s->children[i]->bs->full_open_options); } opts =3D qdict_new(); - qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("quorum"))); - qdict_put_obj(opts, QUORUM_OPT_VOTE_THRESHOLD, - QOBJECT(qint_from_int(s->threshold))); - qdict_put_obj(opts, QUORUM_OPT_BLKVERIFY, - QOBJECT(qbool_from_bool(s->is_blkverify))); - qdict_put_obj(opts, QUORUM_OPT_REWRITE, - QOBJECT(qbool_from_bool(s->rewrite_corrupted))); - qdict_put_obj(opts, "children", QOBJECT(children)); + qdict_put(opts, "driver", qstring_from_str("quorum")); + qdict_put(opts, QUORUM_OPT_VOTE_THRESHOLD, qint_from_int(s->threshold)= ); + qdict_put(opts, QUORUM_OPT_BLKVERIFY, qbool_from_bool(s->is_blkverify)= ); + qdict_put(opts, QUORUM_OPT_REWRITE, qbool_from_bool(s->rewrite_corrupt= ed)); + qdict_put(opts, "children", children); bs->full_open_options =3D opts; } diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 81162ee..9cdc985 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -47,7 +47,7 @@ static void qdict_put_obj_test(void) qdict =3D qdict_new(); // key "" will have tdb hash 12345 - qdict_put_obj(qdict, "", QOBJECT(qint_from_int(num))); + qdict_put(qdict, "", qint_from_int(num)); g_assert(qdict_size(qdict) =3D=3D 1); ent =3D QLIST_FIRST(&qdict->table[12345 % QDICT_BUCKET_MAX]); @@ -66,8 +66,8 @@ static void qdict_destroy_simple_test(void) QDict *qdict; qdict =3D qdict_new(); - qdict_put_obj(qdict, "num", QOBJECT(qint_from_int(0))); - qdict_put_obj(qdict, "str", QOBJECT(qstring_from_str("foo"))); + qdict_put(qdict, "num", qint_from_int(0)); + qdict_put(qdict, "str", qstring_from_str("foo")); QDECREF(qdict); } @@ -297,16 +297,16 @@ static void qdict_flatten_test(void) qdict_put(dict1, "a", qint_from_int(0)); qdict_put(dict1, "b", qint_from_int(1)); - qlist_append_obj(list1, QOBJECT(qint_from_int(23))); - qlist_append_obj(list1, QOBJECT(qint_from_int(66))); - qlist_append_obj(list1, QOBJECT(dict1)); - qlist_append_obj(list2, QOBJECT(qint_from_int(42))); - qlist_append_obj(list2, QOBJECT(list1)); + qlist_append(list1, qint_from_int(23)); + qlist_append(list1, qint_from_int(66)); + qlist_append(list1, dict1); + qlist_append(list2, qint_from_int(42)); + qlist_append(list2, list1); qdict_put(dict2, "c", qint_from_int(2)); qdict_put(dict2, "d", qint_from_int(3)); - qdict_put_obj(dict3, "e", QOBJECT(list2)); - qdict_put_obj(dict3, "f", QOBJECT(dict2)); + qdict_put(dict3, "e", list2); + qdict_put(dict3, "f", dict2); qdict_put(dict3, "g", qint_from_int(4)); qdict_flatten(dict3); diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index 0f81a98..ac3fd03 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -94,7 +94,7 @@ static void test_dispatch_cmd(void) QDict *req =3D qdict_new(); QObject *resp; - qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd")= )); + qdict_put(req, "execute", qstring_from_str("user_def_cmd")); resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp !=3D NULL); @@ -111,7 +111,7 @@ static void test_dispatch_cmd_failure(void) QDict *args =3D qdict_new(); QObject *resp; - qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2"= ))); + qdict_put(req, "execute", qstring_from_str("user_def_cmd2")); resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp !=3D NULL); @@ -125,7 +125,7 @@ static void test_dispatch_cmd_failure(void) qdict_put(args, "a", qint_from_int(66)); qdict_put(req, "arguments", args); - qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd")= )); + qdict_put(req, "execute", qstring_from_str("user_def_cmd")); resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp !=3D NULL); @@ -164,14 +164,14 @@ static void test_dispatch_cmd_io(void) QDict *ret_dict_dict2, *ret_dict_dict2_userdef; QInt *ret3; - qdict_put_obj(ud1a, "integer", QOBJECT(qint_from_int(42))); - qdict_put_obj(ud1a, "string", QOBJECT(qstring_from_str("hello"))); - qdict_put_obj(ud1b, "integer", QOBJECT(qint_from_int(422))); - qdict_put_obj(ud1b, "string", QOBJECT(qstring_from_str("hello2"))); - qdict_put_obj(args, "ud1a", QOBJECT(ud1a)); - qdict_put_obj(args, "ud1b", QOBJECT(ud1b)); - qdict_put_obj(req, "arguments", QOBJECT(args)); - qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2"= ))); + qdict_put(ud1a, "integer", qint_from_int(42)); + qdict_put(ud1a, "string", qstring_from_str("hello")); + qdict_put(ud1b, "integer", qint_from_int(422)); + qdict_put(ud1b, "string", qstring_from_str("hello2")); + qdict_put(args, "ud1a", ud1a); + qdict_put(args, "ud1b", ud1b); + qdict_put(req, "arguments", args); + qdict_put(req, "execute", qstring_from_str("user_def_cmd2")); ret =3D qobject_to_qdict(test_qmp_dispatch(req)); @@ -244,7 +244,7 @@ static void test_dealloc_partial(void) Visitor *v; ud2_dict =3D qdict_new(); - qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text))= ); + qdict_put(ud2_dict, "string0", qstring_from_str(text)); v =3D qobject_input_visitor_new(QOBJECT(ud2_dict)); visit_type_UserDefTwo(v, NULL, &ud2, &err); --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491422064945150.06662580245188; Wed, 5 Apr 2017 12:54:24 -0700 (PDT) Received: from localhost ([::1]:42198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvr0Z-00083w-P9 for importer@patchew.org; Wed, 05 Apr 2017 15:54:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvquP-0002eT-OK for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvquN-000811-Au for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47342) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquN-00080T-2n for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:47:59 -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 mx1.redhat.com (Postfix) with ESMTPS id EFBA4F80C for ; Wed, 5 Apr 2017 19:47:57 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B960171CE; Wed, 5 Apr 2017 19:47:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EFBA4F80C Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EFBA4F80C From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:34 -0500 Message-Id: <20170405194741.18956-7-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 05 Apr 2017 19:47:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 06/13] qobject: Add helper macros for common scalar insertions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rather than making lots of callers wrap a scalar in a QInt, QString, or QBool, provide helper macros that do the wrapping automatically. Update the Coccinelle script to make mass conversions easy, although the conversion itself will be done as a separate patches to ease review and backport efforts. Signed-off-by: Eric Blake --- include/qapi/qmp/qdict.h | 8 ++++++++ include/qapi/qmp/qlist.h | 8 ++++++++ scripts/coccinelle/qobject.cocci | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index fe9a4c5..9d9f9a3 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -52,6 +52,14 @@ void qdict_destroy_obj(QObject *obj); #define qdict_put(qdict, key, obj) \ qdict_put_obj(qdict, key, QOBJECT(obj)) +/* Helpers for int, bool, and const char*. */ +#define qdict_put_int(qdict, key, value) \ + qdict_put(qdict, key, qint_from_int(value)) +#define qdict_put_bool(qdict, key, value) \ + qdict_put(qdict, key, qbool_from_bool(value)) +#define qdict_put_str(qdict, key, value) \ + qdict_put(qdict, key, qstring_from_str(value)) + /* High level helpers */ double qdict_get_double(const QDict *qdict, const char *key); int64_t qdict_get_int(const QDict *qdict, const char *key); diff --git a/include/qapi/qmp/qlist.h b/include/qapi/qmp/qlist.h index a84117e..659325a 100644 --- a/include/qapi/qmp/qlist.h +++ b/include/qapi/qmp/qlist.h @@ -29,6 +29,14 @@ typedef struct QList { #define qlist_append(qlist, obj) \ qlist_append_obj(qlist, QOBJECT(obj)) +/* Helpers for int, bool, and const char*. */ +#define qlist_append_int(qlist, value) \ + qlist_append(qlist, qint_from_int(value)) +#define qlist_append_bool(qlist, value) \ + qlist_append(qlist, qbool_from_bool(value)) +#define qlist_append_str(qlist, value) \ + qlist_append(qlist, qstring_from_str(value)) + #define QLIST_FOREACH_ENTRY(qlist, var) \ for ((var) =3D ((qlist)->head.tqh_first); \ (var); \ diff --git a/scripts/coccinelle/qobject.cocci b/scripts/coccinelle/qobject.= cocci index aa899e2..97703a4 100644 --- a/scripts/coccinelle/qobject.cocci +++ b/scripts/coccinelle/qobject.cocci @@ -2,12 +2,34 @@ @@ expression Obj, Key, E; @@ +( - qdict_put_obj(Obj, Key, QOBJECT(E)); + qdict_put(Obj, Key, E); +| +- qdict_put(Obj, Key, qint_from_int(E)); ++ qdict_put_int(Obj, Key, E); +| +- qdict_put(Obj, Key, qbool_from_bool(E)); ++ qdict_put_bool(Obj, Key, E); +| +- qdict_put(Obj, Key, qstring_from_str(E)); ++ qdict_put_str(Obj, Key, E); +) // Use QList macros where they make sense @@ expression Obj, E; @@ +( - qlist_append_obj(Obj, QOBJECT(E)); + qlist_append(Obj, E); +| +- qlist_append(Obj, qint_from_int(E)); ++ qlist_append_int(Obj, E); +| +- qlist_append(Obj, qbool_from_bool(E)); ++ qlist_append_bool(Obj, E); +| +- qlist_append(Obj, qstring_from_str(E)); ++ qlist_append_str(Obj, E); +) --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491421953663459.572903744708; Wed, 5 Apr 2017 12:52:33 -0700 (PDT) Received: from localhost ([::1]:42190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqyk-0006Jv-7p for importer@patchew.org; Wed, 05 Apr 2017 15:52:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqua-0002oM-VO for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvquY-00087F-Kf for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63947) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquS-00083c-8H; Wed, 05 Apr 2017 15:48:04 -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 mx1.redhat.com (Postfix) with ESMTPS id DE5D480475; Wed, 5 Apr 2017 19:48:02 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A825171CE; Wed, 5 Apr 2017 19:47:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DE5D480475 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DE5D480475 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:35 -0500 Message-Id: <20170405194741.18956-8-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 05 Apr 2017 19:48:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 07/13] block: Use simpler QDict/QList scalar insertion macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Josh Durgin , Fam Zheng , Ronnie Sahlberg , "open list:blkdebug" , "Richard W.M. Jones" , Stefan Weil , Jeff Cody , Peter Lieven , armbru@redhat.com, Max Reitz , Alberto Garcia , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We now have macros in place to make it less verbose to add a scalar to QDict and QList, so use them. Patch created mechanically via: spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h --dir block --in-place then touched up manually to fix a couple of '?:' back to original spacing. Signed-off-by: Eric Blake --- block/blkdebug.c | 6 +++--- block/blkverify.c | 6 +++--- block/curl.c | 2 +- block/file-posix.c | 8 ++++---- block/file-win32.c | 4 ++-- block/iscsi.c | 2 +- block/nbd.c | 41 ++++++++++++++++++++--------------------- block/nfs.c | 43 +++++++++++++++++-------------------------- block/null.c | 2 +- block/qcow2.c | 4 ++-- block/quorum.c | 8 ++++---- block/rbd.c | 16 ++++++++-------- block/ssh.c | 16 +++++++--------- block/vvfat.c | 10 +++++----- 14 files changed, 78 insertions(+), 90 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index c5d4772..f69e136 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -301,7 +301,7 @@ static void blkdebug_parse_filename(const char *filenam= e, QDict *options, if (!strstart(filename, "blkdebug:", &filename)) { /* There was no prefix; therefore, all options have to be already present in the QDict (except for the filename) */ - qdict_put(options, "x-image", qstring_from_str(filename)); + qdict_put_str(options, "x-image", filename); return; } @@ -320,7 +320,7 @@ static void blkdebug_parse_filename(const char *filenam= e, QDict *options, /* TODO Allow multi-level nesting and set file.filename here */ filename =3D c + 1; - qdict_put(options, "x-image", qstring_from_str(filename)); + qdict_put_str(options, "x-image", filename); } static QemuOptsList runtime_opts =3D { @@ -695,7 +695,7 @@ static void blkdebug_refresh_filename(BlockDriverState = *bs, QDict *options) } opts =3D qdict_new(); - qdict_put(opts, "driver", qstring_from_str("blkdebug")); + qdict_put_str(opts, "driver", "blkdebug"); QINCREF(bs->file->bs->full_open_options); qdict_put(opts, "image", bs->file->bs->full_open_options); diff --git a/block/blkverify.c b/block/blkverify.c index 79c8914..5c7d506 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -67,7 +67,7 @@ static void blkverify_parse_filename(const char *filename= , QDict *options, if (!strstart(filename, "blkverify:", &filename)) { /* There was no prefix; therefore, all options have to be already present in the QDict (except for the filename) */ - qdict_put(options, "x-image", qstring_from_str(filename)); + qdict_put_str(options, "x-image", filename); return; } @@ -84,7 +84,7 @@ static void blkverify_parse_filename(const char *filename= , QDict *options, /* TODO Allow multi-level nesting and set file.filename here */ filename =3D c + 1; - qdict_put(options, "x-image", qstring_from_str(filename)); + qdict_put_str(options, "x-image", filename); } static QemuOptsList runtime_opts =3D { @@ -291,7 +291,7 @@ static void blkverify_refresh_filename(BlockDriverState= *bs, QDict *options) && s->test_file->bs->full_open_options) { QDict *opts =3D qdict_new(); - qdict_put(opts, "driver", qstring_from_str("blkverify")); + qdict_put_str(opts, "driver", "blkverify"); QINCREF(bs->file->bs->full_open_options); qdict_put(opts, "raw", bs->file->bs->full_open_options); diff --git a/block/curl.c b/block/curl.c index 2708d57..aa6e8cc 100644 --- a/block/curl.c +++ b/block/curl.c @@ -548,7 +548,7 @@ static void curl_clean_state(CURLState *s) static void curl_parse_filename(const char *filename, QDict *options, Error **errp) { - qdict_put(options, CURL_BLOCK_OPT_URL, qstring_from_str(filename)); + qdict_put_str(options, CURL_BLOCK_OPT_URL, filename); } static void curl_detach_aio_context(BlockDriverState *bs) diff --git a/block/file-posix.c b/block/file-posix.c index 5370ba0..9431ad1 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -377,7 +377,7 @@ static void raw_parse_filename(const char *filename, QD= ict *options, * function call can be ignored. */ strstart(filename, "file:", &filename); - qdict_put(options, "filename", qstring_from_str(filename)); + qdict_put_str(options, "filename", filename); } static QemuOptsList raw_runtime_opts =3D { @@ -2150,7 +2150,7 @@ static void hdev_parse_filename(const char *filename,= QDict *options, /* The prefix is optional, just as for "file". */ strstart(filename, "host_device:", &filename); - qdict_put(options, "filename", qstring_from_str(filename)); + qdict_put_str(options, "filename", filename); } static bool hdev_is_sg(BlockDriverState *bs) @@ -2239,7 +2239,7 @@ static int hdev_open(BlockDriverState *bs, QDict *opt= ions, int flags, goto hdev_open_Mac_error; } - qdict_put(options, "filename", qstring_from_str(bsd_path)); + qdict_put_str(options, "filename", bsd_path); hdev_open_Mac_error: g_free(mediaType); @@ -2449,7 +2449,7 @@ static void cdrom_parse_filename(const char *filename= , QDict *options, /* The prefix is optional, just as for "file". */ strstart(filename, "host_cdrom:", &filename); - qdict_put(options, "filename", qstring_from_str(filename)); + qdict_put_str(options, "filename", filename); } #endif diff --git a/block/file-win32.c b/block/file-win32.c index 57c4a78..0d455d1 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -282,7 +282,7 @@ static void raw_parse_filename(const char *filename, QD= ict *options, * function call can be ignored. */ strstart(filename, "file:", &filename); - qdict_put(options, "filename", qstring_from_str(filename)); + qdict_put_str(options, "filename", filename); } static QemuOptsList raw_runtime_opts =3D { @@ -669,7 +669,7 @@ static void hdev_parse_filename(const char *filename, Q= Dict *options, /* The prefix is optional, just as for "file". */ strstart(filename, "host_device:", &filename); - qdict_put(options, "filename", qstring_from_str(filename)); + qdict_put_str(options, "filename", filename); } static int hdev_open(BlockDriverState *bs, QDict *options, int flags, diff --git a/block/iscsi.c b/block/iscsi.c index 716e74a..1534ab6 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2102,7 +2102,7 @@ static int iscsi_create(const char *filename, QemuOpt= s *opts, Error **errp) iscsilun =3D bs->opaque; bs_options =3D qdict_new(); - qdict_put(bs_options, "filename", qstring_from_str(filename)); + qdict_put_str(bs_options, "filename", filename); ret =3D iscsi_open(bs, bs_options, 0, NULL); QDECREF(bs_options); diff --git a/block/nbd.c b/block/nbd.c index 814ab26d..b3545f5 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -79,7 +79,7 @@ static int nbd_parse_uri(const char *filename, QDict *opt= ions) p =3D uri->path ? uri->path : "/"; p +=3D strspn(p, "/"); if (p[0]) { - qdict_put(options, "export", qstring_from_str(p)); + qdict_put_str(options, "export", p); } qp =3D query_params_parse(uri->query); @@ -94,9 +94,8 @@ static int nbd_parse_uri(const char *filename, QDict *opt= ions) ret =3D -EINVAL; goto out; } - qdict_put(options, "server.type", qstring_from_str("unix")); - qdict_put(options, "server.path", - qstring_from_str(qp->p[0].value)); + qdict_put_str(options, "server.type", "unix"); + qdict_put_str(options, "server.path", qp->p[0].value); } else { QString *host; char *port_str; @@ -115,11 +114,11 @@ static int nbd_parse_uri(const char *filename, QDict = *options) host =3D qstring_from_str(uri->server); } - qdict_put(options, "server.type", qstring_from_str("inet")); + qdict_put_str(options, "server.type", "inet"); qdict_put(options, "server.host", host); port_str =3D g_strdup_printf("%d", uri->port ?: NBD_DEFAULT_PORT); - qdict_put(options, "server.port", qstring_from_str(port_str)); + qdict_put_str(options, "server.port", port_str); g_free(port_str); } @@ -181,7 +180,7 @@ static void nbd_parse_filename(const char *filename, QD= ict *options, export_name[0] =3D 0; /* truncate 'file' */ export_name +=3D strlen(EN_OPTSTR); - qdict_put(options, "export", qstring_from_str(export_name)); + qdict_put_str(options, "export", export_name); } /* extract the host_spec - fail if it's not nbd:... */ @@ -196,8 +195,8 @@ static void nbd_parse_filename(const char *filename, QD= ict *options, /* are we a UNIX or TCP socket? */ if (strstart(host_spec, "unix:", &unixpath)) { - qdict_put(options, "server.type", qstring_from_str("unix")); - qdict_put(options, "server.path", qstring_from_str(unixpath)); + qdict_put_str(options, "server.type", "unix"); + qdict_put_str(options, "server.path", unixpath); } else { InetSocketAddress *addr =3D NULL; @@ -206,9 +205,9 @@ static void nbd_parse_filename(const char *filename, QD= ict *options, goto out; } - qdict_put(options, "server.type", qstring_from_str("inet")); - qdict_put(options, "server.host", qstring_from_str(addr->host)); - qdict_put(options, "server.port", qstring_from_str(addr->port)); + qdict_put_str(options, "server.type", "inet"); + qdict_put_str(options, "server.host", addr->host); + qdict_put_str(options, "server.port", addr->port); qapi_free_InetSocketAddress(addr); } @@ -247,13 +246,13 @@ static bool nbd_process_legacy_socket_options(QDict *= output_options, return false; } - qdict_put(output_options, "server.type", qstring_from_str("unix")); - qdict_put(output_options, "server.path", qstring_from_str(path)); + qdict_put_str(output_options, "server.type", "unix"); + qdict_put_str(output_options, "server.path", path); } else if (host) { - qdict_put(output_options, "server.type", qstring_from_str("inet")); - qdict_put(output_options, "server.host", qstring_from_str(host)); - qdict_put(output_options, "server.port", - qstring_from_str(port ?: stringify(NBD_DEFAULT_PORT))); + qdict_put_str(output_options, "server.type", "inet"); + qdict_put_str(output_options, "server.host", host); + qdict_put_str(output_options, "server.port", + port ?: stringify(NBD_DEFAULT_PORT)); } return true; @@ -528,7 +527,7 @@ static void nbd_refresh_filename(BlockDriverState *bs, = QDict *options) path =3D s->saddr->u.q_unix.path; } /* else can't represent as pseudo-filename */ - qdict_put(opts, "driver", qstring_from_str("nbd")); + qdict_put_str(opts, "driver", "nbd"); if (path && s->export) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), @@ -551,10 +550,10 @@ static void nbd_refresh_filename(BlockDriverState *bs= , QDict *options) qdict_put_obj(opts, "server", saddr_qdict); if (s->export) { - qdict_put(opts, "export", qstring_from_str(s->export)); + qdict_put_str(opts, "export", s->export); } if (s->tlscredsid) { - qdict_put(opts, "tls-creds", qstring_from_str(s->tlscredsid)); + qdict_put_str(opts, "tls-creds", s->tlscredsid); } qdict_flatten(opts); diff --git a/block/nfs.c b/block/nfs.c index 0816678..bfeebc1 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -104,9 +104,9 @@ static int nfs_parse_uri(const char *filename, QDict *o= ptions, Error **errp) goto out; } - qdict_put(options, "server.host", qstring_from_str(uri->server)); - qdict_put(options, "server.type", qstring_from_str("inet")); - qdict_put(options, "path", qstring_from_str(uri->path)); + qdict_put_str(options, "server.host", uri->server); + qdict_put_str(options, "server.type", "inet"); + qdict_put_str(options, "path", uri->path); for (i =3D 0; i < qp->n; i++) { unsigned long long val; @@ -121,23 +121,17 @@ static int nfs_parse_uri(const char *filename, QDict = *options, Error **errp) goto out; } if (!strcmp(qp->p[i].name, "uid")) { - qdict_put(options, "user", - qstring_from_str(qp->p[i].value)); + qdict_put_str(options, "user", qp->p[i].value); } else if (!strcmp(qp->p[i].name, "gid")) { - qdict_put(options, "group", - qstring_from_str(qp->p[i].value)); + qdict_put_str(options, "group", qp->p[i].value); } else if (!strcmp(qp->p[i].name, "tcp-syncnt")) { - qdict_put(options, "tcp-syn-count", - qstring_from_str(qp->p[i].value)); + qdict_put_str(options, "tcp-syn-count", qp->p[i].value); } else if (!strcmp(qp->p[i].name, "readahead")) { - qdict_put(options, "readahead-size", - qstring_from_str(qp->p[i].value)); + qdict_put_str(options, "readahead-size", qp->p[i].value); } else if (!strcmp(qp->p[i].name, "pagecache")) { - qdict_put(options, "page-cache-size", - qstring_from_str(qp->p[i].value)); + qdict_put_str(options, "page-cache-size", qp->p[i].value); } else if (!strcmp(qp->p[i].name, "debug")) { - qdict_put(options, "debug", - qstring_from_str(qp->p[i].value)); + qdict_put_str(options, "debug", qp->p[i].value); } else { error_setg(errp, "Unknown NFS parameter name: %s", qp->p[i].name); @@ -811,7 +805,7 @@ static void nfs_refresh_filename(BlockDriverState *bs, = QDict *options) QObject *server_qdict; Visitor *ov; - qdict_put(opts, "driver", qstring_from_str("nfs")); + qdict_put_str(opts, "driver", "nfs"); if (client->uid && !client->gid) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), @@ -834,28 +828,25 @@ static void nfs_refresh_filename(BlockDriverState *bs= , QDict *options) visit_type_NFSServer(ov, NULL, &client->server, &error_abort); visit_complete(ov, &server_qdict); qdict_put_obj(opts, "server", server_qdict); - qdict_put(opts, "path", qstring_from_str(client->path)); + qdict_put_str(opts, "path", client->path); if (client->uid) { - qdict_put(opts, "user", qint_from_int(client->uid)); + qdict_put_int(opts, "user", client->uid); } if (client->gid) { - qdict_put(opts, "group", qint_from_int(client->gid)); + qdict_put_int(opts, "group", client->gid); } if (client->tcp_syncnt) { - qdict_put(opts, "tcp-syn-cnt", - qint_from_int(client->tcp_syncnt)); + qdict_put_int(opts, "tcp-syn-cnt", client->tcp_syncnt); } if (client->readahead) { - qdict_put(opts, "readahead-size", - qint_from_int(client->readahead)); + qdict_put_int(opts, "readahead-size", client->readahead); } if (client->pagecache) { - qdict_put(opts, "page-cache-size", - qint_from_int(client->pagecache)); + qdict_put_int(opts, "page-cache-size", client->pagecache); } if (client->debug) { - qdict_put(opts, "debug", qint_from_int(client->debug)); + qdict_put_int(opts, "debug", client->debug); } visit_free(ov); diff --git a/block/null.c b/block/null.c index b300390..876f909 100644 --- a/block/null.c +++ b/block/null.c @@ -232,7 +232,7 @@ static void null_refresh_filename(BlockDriverState *bs,= QDict *opts) bs->drv->format_name); } - qdict_put(opts, "driver", qstring_from_str(bs->drv->format_name)); + qdict_put_str(opts, "driver", bs->drv->format_name); bs->full_open_options =3D opts; } diff --git a/block/qcow2.c b/block/qcow2.c index 6a92d2e..49c737f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2265,7 +2265,7 @@ static int qcow2_create2(const char *filename, int64_= t total_size, * table) */ options =3D qdict_new(); - qdict_put(options, "driver", qstring_from_str("qcow2")); + qdict_put_str(options, "driver", "qcow2"); blk =3D blk_new_open(filename, NULL, options, BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH, &local_err); @@ -2327,7 +2327,7 @@ static int qcow2_create2(const char *filename, int64_= t total_size, /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returni= ng */ options =3D qdict_new(); - qdict_put(options, "driver", qstring_from_str("qcow2")); + qdict_put_str(options, "driver", "qcow2"); blk =3D blk_new_open(filename, NULL, options, BDRV_O_RDWR | BDRV_O_NO_BACKING, &local_err); if (blk =3D=3D NULL) { diff --git a/block/quorum.c b/block/quorum.c index f7949e2..1b2a8c3 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1100,10 +1100,10 @@ static void quorum_refresh_filename(BlockDriverStat= e *bs, QDict *options) } opts =3D qdict_new(); - qdict_put(opts, "driver", qstring_from_str("quorum")); - qdict_put(opts, QUORUM_OPT_VOTE_THRESHOLD, qint_from_int(s->threshold)= ); - qdict_put(opts, QUORUM_OPT_BLKVERIFY, qbool_from_bool(s->is_blkverify)= ); - qdict_put(opts, QUORUM_OPT_REWRITE, qbool_from_bool(s->rewrite_corrupt= ed)); + qdict_put_str(opts, "driver", "quorum"); + qdict_put_int(opts, QUORUM_OPT_VOTE_THRESHOLD, s->threshold); + qdict_put_bool(opts, QUORUM_OPT_BLKVERIFY, s->is_blkverify); + qdict_put_bool(opts, QUORUM_OPT_REWRITE, s->rewrite_corrupted); qdict_put(opts, "children", children); bs->full_open_options =3D opts; diff --git a/block/rbd.c b/block/rbd.c index 1ceeeb5..2354ffc 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -154,20 +154,20 @@ static void qemu_rbd_parse_filename(const char *filen= ame, QDict *options, goto done; } qemu_rbd_unescape(found_str); - qdict_put(options, "pool", qstring_from_str(found_str)); + qdict_put_str(options, "pool", found_str); if (strchr(p, '@')) { found_str =3D qemu_rbd_next_tok(p, '@', &p); qemu_rbd_unescape(found_str); - qdict_put(options, "image", qstring_from_str(found_str)); + qdict_put_str(options, "image", found_str); found_str =3D qemu_rbd_next_tok(p, ':', &p); qemu_rbd_unescape(found_str); - qdict_put(options, "snapshot", qstring_from_str(found_str)); + qdict_put_str(options, "snapshot", found_str); } else { found_str =3D qemu_rbd_next_tok(p, ':', &p); qemu_rbd_unescape(found_str); - qdict_put(options, "image", qstring_from_str(found_str)); + qdict_put_str(options, "image", found_str); } if (!p) { goto done; @@ -189,9 +189,9 @@ static void qemu_rbd_parse_filename(const char *filenam= e, QDict *options, qemu_rbd_unescape(value); if (!strcmp(name, "conf")) { - qdict_put(options, "conf", qstring_from_str(value)); + qdict_put_str(options, "conf", value); } else if (!strcmp(name, "id")) { - qdict_put(options, "user" , qstring_from_str(value)); + qdict_put_str(options, "user", value); } else { /* * We pass these internally to qemu_rbd_set_keypairs(), so @@ -204,8 +204,8 @@ static void qemu_rbd_parse_filename(const char *filenam= e, QDict *options, if (!keypairs) { keypairs =3D qlist_new(); } - qlist_append(keypairs, qstring_from_str(name)); - qlist_append(keypairs, qstring_from_str(value)); + qlist_append_str(keypairs, name); + qlist_append_str(keypairs, value); } } diff --git a/block/ssh.c b/block/ssh.c index 471ba8a..34a2f79 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -227,24 +227,23 @@ static int parse_uri(const char *filename, QDict *opt= ions, Error **errp) } if(uri->user && strcmp(uri->user, "") !=3D 0) { - qdict_put(options, "user", qstring_from_str(uri->user)); + qdict_put_str(options, "user", uri->user); } - qdict_put(options, "server.host", qstring_from_str(uri->server)); + qdict_put_str(options, "server.host", uri->server); port_str =3D g_strdup_printf("%d", uri->port ?: 22); - qdict_put(options, "server.port", qstring_from_str(port_str)); + qdict_put_str(options, "server.port", port_str); g_free(port_str); - qdict_put(options, "path", qstring_from_str(uri->path)); + qdict_put_str(options, "path", uri->path); /* Pick out any query parameters that we understand, and ignore * the rest. */ for (i =3D 0; i < qp->n; ++i) { if (strcmp(qp->p[i].name, "host_key_check") =3D=3D 0) { - qdict_put(options, "host_key_check", - qstring_from_str(qp->p[i].value)); + qdict_put_str(options, "host_key_check", qp->p[i].value); } } @@ -574,9 +573,8 @@ static bool ssh_process_legacy_socket_options(QDict *ou= tput_opts, } if (host) { - qdict_put(output_opts, "server.host", qstring_from_str(host)); - qdict_put(output_opts, "server.port", - qstring_from_str(port ?: stringify(22))); + qdict_put_str(output_opts, "server.host", host); + qdict_put_str(output_opts, "server.port", port ?: stringify(22)); } return true; diff --git a/block/vvfat.c b/block/vvfat.c index af5153d..8b4e4eb 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1057,10 +1057,10 @@ static void vvfat_parse_filename(const char *filena= me, QDict *options, } /* Fill in the options QDict */ - qdict_put(options, "dir", qstring_from_str(filename)); - qdict_put(options, "fat-type", qint_from_int(fat_type)); - qdict_put(options, "floppy", qbool_from_bool(floppy)); - qdict_put(options, "rw", qbool_from_bool(rw)); + qdict_put_str(options, "dir", filename); + qdict_put_int(options, "fat-type", fat_type); + qdict_put_bool(options, "floppy", floppy); + qdict_put_bool(options, "rw", rw); } static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, @@ -3040,7 +3040,7 @@ static int enable_write_target(BlockDriverState *bs, = Error **errp) } options =3D qdict_new(); - qdict_put(options, "write-target.driver", qstring_from_str("qcow")); + qdict_put_str(options, "write-target.driver", "qcow"); s->qcow =3D bdrv_open_child(s->qcow_filename, options, "write-target",= bs, &child_vvfat_qcow, false, errp); QDECREF(options); --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491422194586985.9818492723017; Wed, 5 Apr 2017 12:56:34 -0700 (PDT) Received: from localhost ([::1]:42210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvr2f-0001Xb-8e for importer@patchew.org; Wed, 05 Apr 2017 15:56:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvquW-0002jU-1z for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvquT-00084Y-Dx for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquT-00084N-4Z for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:05 -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 mx1.redhat.com (Postfix) with ESMTPS id 01FBE7E9C8; Wed, 5 Apr 2017 19:48:04 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26FF74DA67; Wed, 5 Apr 2017 19:48:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 01FBE7E9C8 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 01FBE7E9C8 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:36 -0500 Message-Id: <20170405194741.18956-9-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 05 Apr 2017 19:48:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 08/13] tests: Use simpler QDict/QList scalar insertion macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com, Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We now have macros in place to make it less verbose to add a scalar to QDict and QList, so use them. Patch created mechanically via: spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h --dir tests --in-place then manually checked that no touch-ups were needed. Signed-off-by: Eric Blake --- tests/check-qdict.c | 134 ++++++++++++++++++--------------= ---- tests/check-qlist.c | 4 +- tests/device-introspect-test.c | 4 +- tests/test-qemu-opts.c | 4 +- tests/test-qmp-commands.c | 24 +++---- tests/test-qmp-event.c | 30 ++++---- tests/test-qobject-output-visitor.c | 6 +- 7 files changed, 103 insertions(+), 103 deletions(-) diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 9cdc985..3effca5 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -47,7 +47,7 @@ static void qdict_put_obj_test(void) qdict =3D qdict_new(); // key "" will have tdb hash 12345 - qdict_put(qdict, "", qint_from_int(num)); + qdict_put_int(qdict, "", num); g_assert(qdict_size(qdict) =3D=3D 1); ent =3D QLIST_FIRST(&qdict->table[12345 % QDICT_BUCKET_MAX]); @@ -66,8 +66,8 @@ static void qdict_destroy_simple_test(void) QDict *qdict; qdict =3D qdict_new(); - qdict_put(qdict, "num", qint_from_int(0)); - qdict_put(qdict, "str", qstring_from_str("foo")); + qdict_put_int(qdict, "num", 0); + qdict_put_str(qdict, "str", "foo"); QDECREF(qdict); } @@ -80,7 +80,7 @@ static void qdict_get_test(void) const char *key =3D "test"; QDict *tests_dict =3D qdict_new(); - qdict_put(tests_dict, key, qint_from_int(value)); + qdict_put_int(tests_dict, key, value); obj =3D qdict_get(tests_dict, key); g_assert(obj !=3D NULL); @@ -98,7 +98,7 @@ static void qdict_get_int_test(void) const char *key =3D "int"; QDict *tests_dict =3D qdict_new(); - qdict_put(tests_dict, key, qint_from_int(value)); + qdict_put_int(tests_dict, key, value); ret =3D qdict_get_int(tests_dict, key); g_assert(ret =3D=3D value); @@ -113,7 +113,7 @@ static void qdict_get_try_int_test(void) const char *key =3D "int"; QDict *tests_dict =3D qdict_new(); - qdict_put(tests_dict, key, qint_from_int(value)); + qdict_put_int(tests_dict, key, value); ret =3D qdict_get_try_int(tests_dict, key, 0); g_assert(ret =3D=3D value); @@ -128,7 +128,7 @@ static void qdict_get_str_test(void) const char *str =3D "string"; QDict *tests_dict =3D qdict_new(); - qdict_put(tests_dict, key, qstring_from_str(str)); + qdict_put_str(tests_dict, key, str); p =3D qdict_get_str(tests_dict, key); g_assert(p !=3D NULL); @@ -144,7 +144,7 @@ static void qdict_get_try_str_test(void) const char *str =3D "string"; QDict *tests_dict =3D qdict_new(); - qdict_put(tests_dict, key, qstring_from_str(str)); + qdict_put_str(tests_dict, key, str); p =3D qdict_get_try_str(tests_dict, key); g_assert(p !=3D NULL); @@ -188,7 +188,7 @@ static void qdict_haskey_test(void) const char *key =3D "test"; QDict *tests_dict =3D qdict_new(); - qdict_put(tests_dict, key, qint_from_int(0)); + qdict_put_int(tests_dict, key, 0); g_assert(qdict_haskey(tests_dict, key) =3D=3D 1); QDECREF(tests_dict); @@ -199,7 +199,7 @@ static void qdict_del_test(void) const char *key =3D "key test"; QDict *tests_dict =3D qdict_new(); - qdict_put(tests_dict, key, qstring_from_str("foo")); + qdict_put_str(tests_dict, key, "foo"); g_assert(qdict_size(tests_dict) =3D=3D 1); qdict_del(tests_dict, key); @@ -226,9 +226,9 @@ static void qdict_iterapi_test(void) g_assert(qdict_first(tests_dict) =3D=3D NULL); - qdict_put(tests_dict, "key1", qint_from_int(1)); - qdict_put(tests_dict, "key2", qint_from_int(2)); - qdict_put(tests_dict, "key3", qint_from_int(3)); + qdict_put_int(tests_dict, "key1", 1); + qdict_put_int(tests_dict, "key2", 2); + qdict_put_int(tests_dict, "key3", 3); count =3D 0; for (ent =3D qdict_first(tests_dict); ent; ent =3D qdict_next(tests_di= ct, ent)){ @@ -294,20 +294,20 @@ static void qdict_flatten_test(void) * } */ - qdict_put(dict1, "a", qint_from_int(0)); - qdict_put(dict1, "b", qint_from_int(1)); + qdict_put_int(dict1, "a", 0); + qdict_put_int(dict1, "b", 1); - qlist_append(list1, qint_from_int(23)); - qlist_append(list1, qint_from_int(66)); + qlist_append_int(list1, 23); + qlist_append_int(list1, 66); qlist_append(list1, dict1); - qlist_append(list2, qint_from_int(42)); + qlist_append_int(list2, 42); qlist_append(list2, list1); - qdict_put(dict2, "c", qint_from_int(2)); - qdict_put(dict2, "d", qint_from_int(3)); + qdict_put_int(dict2, "c", 2); + qdict_put_int(dict2, "d", 3); qdict_put(dict3, "e", list2); qdict_put(dict3, "f", dict2); - qdict_put(dict3, "g", qint_from_int(4)); + qdict_put_int(dict3, "g", 4); qdict_flatten(dict3); @@ -369,12 +369,12 @@ static void qdict_array_split_test(void) * This example is given in the comment of qdict_array_split(). */ - qdict_put(test_dict, "1.x", qint_from_int(0)); - qdict_put(test_dict, "4.y", qint_from_int(1)); - qdict_put(test_dict, "0.a", qint_from_int(42)); - qdict_put(test_dict, "o.o", qint_from_int(7)); - qdict_put(test_dict, "0.b", qint_from_int(23)); - qdict_put(test_dict, "2", qint_from_int(66)); + qdict_put_int(test_dict, "1.x", 0); + qdict_put_int(test_dict, "4.y", 1); + qdict_put_int(test_dict, "0.a", 42); + qdict_put_int(test_dict, "o.o", 7); + qdict_put_int(test_dict, "0.b", 23); + qdict_put_int(test_dict, "2", 66); qdict_array_split(test_dict, &test_list); @@ -441,9 +441,9 @@ static void qdict_array_split_test(void) test_dict =3D qdict_new(); - qdict_put(test_dict, "0", qint_from_int(42)); - qdict_put(test_dict, "1", qint_from_int(23)); - qdict_put(test_dict, "1.x", qint_from_int(84)); + qdict_put_int(test_dict, "0", 42); + qdict_put_int(test_dict, "1", 23); + qdict_put_int(test_dict, "1.x", 84); qdict_array_split(test_dict, &test_list); @@ -472,38 +472,38 @@ static void qdict_array_entries_test(void) g_assert_cmpint(qdict_array_entries(dict, "foo."), =3D=3D, 0); - qdict_put(dict, "bar", qint_from_int(0)); - qdict_put(dict, "baz.0", qint_from_int(0)); + qdict_put_int(dict, "bar", 0); + qdict_put_int(dict, "baz.0", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), =3D=3D, 0); - qdict_put(dict, "foo.1", qint_from_int(0)); + qdict_put_int(dict, "foo.1", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), =3D=3D, -EINVAL); - qdict_put(dict, "foo.0", qint_from_int(0)); + qdict_put_int(dict, "foo.0", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), =3D=3D, 2); - qdict_put(dict, "foo.bar", qint_from_int(0)); + qdict_put_int(dict, "foo.bar", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), =3D=3D, -EINVAL); qdict_del(dict, "foo.bar"); - qdict_put(dict, "foo.2.a", qint_from_int(0)); - qdict_put(dict, "foo.2.b", qint_from_int(0)); - qdict_put(dict, "foo.2.c", qint_from_int(0)); + qdict_put_int(dict, "foo.2.a", 0); + qdict_put_int(dict, "foo.2.b", 0); + qdict_put_int(dict, "foo.2.c", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), =3D=3D, 3); g_assert_cmpint(qdict_array_entries(dict, ""), =3D=3D, -EINVAL); QDECREF(dict); dict =3D qdict_new(); - qdict_put(dict, "1", qint_from_int(0)); + qdict_put_int(dict, "1", 0); g_assert_cmpint(qdict_array_entries(dict, ""), =3D=3D, -EINVAL); - qdict_put(dict, "0", qint_from_int(0)); + qdict_put_int(dict, "0", 0); g_assert_cmpint(qdict_array_entries(dict, ""), =3D=3D, 2); - qdict_put(dict, "bar", qint_from_int(0)); + qdict_put_int(dict, "bar", 0); g_assert_cmpint(qdict_array_entries(dict, ""), =3D=3D, -EINVAL); qdict_del(dict, "bar"); - qdict_put(dict, "2.a", qint_from_int(0)); - qdict_put(dict, "2.b", qint_from_int(0)); - qdict_put(dict, "2.c", qint_from_int(0)); + qdict_put_int(dict, "2.a", 0); + qdict_put_int(dict, "2.b", 0); + qdict_put_int(dict, "2.c", 0); g_assert_cmpint(qdict_array_entries(dict, ""), =3D=3D, 3); QDECREF(dict); @@ -529,7 +529,7 @@ static void qdict_join_test(void) /* First iteration: Test movement */ /* Second iteration: Test empty source and non-empty destination */ - qdict_put(dict2, "foo", qint_from_int(42)); + qdict_put_int(dict2, "foo", 42); for (i =3D 0; i < 2; i++) { qdict_join(dict1, dict2, overwrite); @@ -541,7 +541,7 @@ static void qdict_join_test(void) } /* Test non-empty source and destination without conflict */ - qdict_put(dict2, "bar", qint_from_int(23)); + qdict_put_int(dict2, "bar", 23); qdict_join(dict1, dict2, overwrite); @@ -552,7 +552,7 @@ static void qdict_join_test(void) g_assert(qdict_get_int(dict1, "bar") =3D=3D 23); /* Test conflict */ - qdict_put(dict2, "foo", qint_from_int(84)); + qdict_put_int(dict2, "foo", 84); qdict_join(dict1, dict2, overwrite); @@ -594,15 +594,15 @@ static void qdict_crumple_test_recursive(void) QList *rules; src =3D qdict_new(); - qdict_put(src, "vnc.listen.addr", qstring_from_str("127.0.0.1")); - qdict_put(src, "vnc.listen.port", qstring_from_str("5901")); - qdict_put(src, "vnc.acl.rules.0.match", qstring_from_str("fred")); - qdict_put(src, "vnc.acl.rules.0.policy", qstring_from_str("allow")); - qdict_put(src, "vnc.acl.rules.1.match", qstring_from_str("bob")); - qdict_put(src, "vnc.acl.rules.1.policy", qstring_from_str("deny")); - qdict_put(src, "vnc.acl.default", qstring_from_str("deny")); - qdict_put(src, "vnc.acl..name", qstring_from_str("acl0")); - qdict_put(src, "vnc.acl.rule..name", qstring_from_str("acl0")); + qdict_put_str(src, "vnc.listen.addr", "127.0.0.1"); + qdict_put_str(src, "vnc.listen.port", "5901"); + qdict_put_str(src, "vnc.acl.rules.0.match", "fred"); + qdict_put_str(src, "vnc.acl.rules.0.policy", "allow"); + qdict_put_str(src, "vnc.acl.rules.1.match", "bob"); + qdict_put_str(src, "vnc.acl.rules.1.policy", "deny"); + qdict_put_str(src, "vnc.acl.default", "deny"); + qdict_put_str(src, "vnc.acl..name", "acl0"); + qdict_put_str(src, "vnc.acl.rule..name", "acl0"); dst =3D qobject_to_qdict(qdict_crumple(src, &error_abort)); g_assert(dst); @@ -669,8 +669,8 @@ static void qdict_crumple_test_bad_inputs(void) src =3D qdict_new(); /* rule.0 can't be both a string and a dict */ - qdict_put(src, "rule.0", qstring_from_str("fred")); - qdict_put(src, "rule.0.policy", qstring_from_str("allow")); + qdict_put_str(src, "rule.0", "fred"); + qdict_put_str(src, "rule.0.policy", "allow"); g_assert(qdict_crumple(src, &error) =3D=3D NULL); g_assert(error !=3D NULL); @@ -680,8 +680,8 @@ static void qdict_crumple_test_bad_inputs(void) src =3D qdict_new(); /* rule can't be both a list and a dict */ - qdict_put(src, "rule.0", qstring_from_str("fred")); - qdict_put(src, "rule.a", qstring_from_str("allow")); + qdict_put_str(src, "rule.0", "fred"); + qdict_put_str(src, "rule.a", "allow"); g_assert(qdict_crumple(src, &error) =3D=3D NULL); g_assert(error !=3D NULL); @@ -692,7 +692,7 @@ static void qdict_crumple_test_bad_inputs(void) src =3D qdict_new(); /* The input should be flat, ie no dicts or lists */ qdict_put(src, "rule.a", qdict_new()); - qdict_put(src, "rule.b", qstring_from_str("allow")); + qdict_put_str(src, "rule.b", "allow"); g_assert(qdict_crumple(src, &error) =3D=3D NULL); g_assert(error !=3D NULL); @@ -702,8 +702,8 @@ static void qdict_crumple_test_bad_inputs(void) src =3D qdict_new(); /* List indexes must not have gaps */ - qdict_put(src, "rule.0", qstring_from_str("deny")); - qdict_put(src, "rule.3", qstring_from_str("allow")); + qdict_put_str(src, "rule.0", "deny"); + qdict_put_str(src, "rule.3", "allow"); g_assert(qdict_crumple(src, &error) =3D=3D NULL); g_assert(error !=3D NULL); @@ -713,8 +713,8 @@ static void qdict_crumple_test_bad_inputs(void) src =3D qdict_new(); /* List indexes must be in %zu format */ - qdict_put(src, "rule.0", qstring_from_str("deny")); - qdict_put(src, "rule.+1", qstring_from_str("allow")); + qdict_put_str(src, "rule.0", "deny"); + qdict_put_str(src, "rule.+1", "allow"); g_assert(qdict_crumple(src, &error) =3D=3D NULL); g_assert(error !=3D NULL); @@ -733,8 +733,8 @@ static void qdict_put_exists_test(void) const char *key =3D "exists"; QDict *tests_dict =3D qdict_new(); - qdict_put(tests_dict, key, qint_from_int(1)); - qdict_put(tests_dict, key, qint_from_int(2)); + qdict_put_int(tests_dict, key, 1); + qdict_put_int(tests_dict, key, 2); value =3D qdict_get_int(tests_dict, key); g_assert(value =3D=3D 2); diff --git a/tests/check-qlist.c b/tests/check-qlist.c index e16da5e..4983867 100644 --- a/tests/check-qlist.c +++ b/tests/check-qlist.c @@ -74,7 +74,7 @@ static void qlist_destroy_test(void) qlist =3D qlist_new(); for (i =3D 0; i < 42; i++) - qlist_append(qlist, qint_from_int(i)); + qlist_append_int(qlist, i); QDECREF(qlist); } @@ -103,7 +103,7 @@ static void qlist_iter_test(void) qlist =3D qlist_new(); for (i =3D 0; i < iter_max; i++) - qlist_append(qlist, qint_from_int(i)); + qlist_append_int(qlist, i); iter_called =3D 0; qlist_iter(qlist, iter_func, NULL); diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c index c5637cc..b1abb2a 100644 --- a/tests/device-introspect-test.c +++ b/tests/device-introspect-test.c @@ -32,9 +32,9 @@ static QList *qom_list_types(const char *implements, bool= abstract) QList *ret; QDict *args =3D qdict_new(); - qdict_put(args, "abstract", qbool_from_bool(abstract)); + qdict_put_bool(args, "abstract", abstract); if (implements) { - qdict_put(args, "implements", qstring_from_str(implements)); + qdict_put_str(args, "implements", implements); } resp =3D qmp("{'execute': 'qom-list-types'," " 'arguments': %p }", args); diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index 0ad74b4..cc1bb1a 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -299,7 +299,7 @@ static void test_qemu_opt_get_size(void) dict =3D qdict_new(); g_assert(dict !=3D NULL); - qdict_put(dict, "size1", qstring_from_str("10")); + qdict_put_str(dict, "size1", "10"); qemu_opts_absorb_qdict(opts, dict, &error_abort); g_assert(error_abort =3D=3D NULL); @@ -309,7 +309,7 @@ static void test_qemu_opt_get_size(void) g_assert(opt =3D=3D 10); /* reset value */ - qdict_put(dict, "size1", qstring_from_str("15")); + qdict_put_str(dict, "size1", "15"); qemu_opts_absorb_qdict(opts, dict, &error_abort); g_assert(error_abort =3D=3D NULL); diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index ac3fd03..acdded4 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -94,7 +94,7 @@ static void test_dispatch_cmd(void) QDict *req =3D qdict_new(); QObject *resp; - qdict_put(req, "execute", qstring_from_str("user_def_cmd")); + qdict_put_str(req, "execute", "user_def_cmd"); resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp !=3D NULL); @@ -111,7 +111,7 @@ static void test_dispatch_cmd_failure(void) QDict *args =3D qdict_new(); QObject *resp; - qdict_put(req, "execute", qstring_from_str("user_def_cmd2")); + qdict_put_str(req, "execute", "user_def_cmd2"); resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp !=3D NULL); @@ -122,10 +122,10 @@ static void test_dispatch_cmd_failure(void) /* check that with extra arguments it throws an error */ req =3D qdict_new(); - qdict_put(args, "a", qint_from_int(66)); + qdict_put_int(args, "a", 66); qdict_put(req, "arguments", args); - qdict_put(req, "execute", qstring_from_str("user_def_cmd")); + qdict_put_str(req, "execute", "user_def_cmd"); resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp !=3D NULL); @@ -164,14 +164,14 @@ static void test_dispatch_cmd_io(void) QDict *ret_dict_dict2, *ret_dict_dict2_userdef; QInt *ret3; - qdict_put(ud1a, "integer", qint_from_int(42)); - qdict_put(ud1a, "string", qstring_from_str("hello")); - qdict_put(ud1b, "integer", qint_from_int(422)); - qdict_put(ud1b, "string", qstring_from_str("hello2")); + 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(req, "execute", qstring_from_str("user_def_cmd2")); + qdict_put_str(req, "execute", "user_def_cmd2"); ret =3D qobject_to_qdict(test_qmp_dispatch(req)); @@ -190,9 +190,9 @@ static void test_dispatch_cmd_io(void) assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4")); QDECREF(ret); - qdict_put(args3, "a", qint_from_int(66)); + qdict_put_int(args3, "a", 66); qdict_put(req, "arguments", args3); - qdict_put(req, "execute", qstring_from_str("guest-get-time")); + qdict_put_str(req, "execute", "guest-get-time"); ret3 =3D qobject_to_qint(test_qmp_dispatch(req)); assert(qint_get_int(ret3) =3D=3D 66); @@ -244,7 +244,7 @@ static void test_dealloc_partial(void) Visitor *v; ud2_dict =3D qdict_new(); - qdict_put(ud2_dict, "string0", qstring_from_str(text)); + qdict_put_str(ud2_dict, "string0", text); v =3D qobject_input_visitor_new(QOBJECT(ud2_dict)); visit_type_UserDefTwo(v, NULL, &ud2, &err); diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 7bb621b..4c0f096 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -153,7 +153,7 @@ static void test_event_a(TestEventData *data, { QDict *d; d =3D data->expect; - qdict_put(d, "event", qstring_from_str("EVENT_A")); + qdict_put_str(d, "event", "EVENT_A"); qapi_event_send_event_a(&error_abort); } @@ -162,7 +162,7 @@ static void test_event_b(TestEventData *data, { QDict *d; d =3D data->expect; - qdict_put(d, "event", qstring_from_str("EVENT_B")); + qdict_put_str(d, "event", "EVENT_B"); qapi_event_send_event_b(&error_abort); } @@ -177,16 +177,16 @@ static void test_event_c(TestEventData *data, b.has_enum1 =3D false; d_b =3D qdict_new(); - qdict_put(d_b, "integer", qint_from_int(2)); - qdict_put(d_b, "string", qstring_from_str("test1")); + qdict_put_int(d_b, "integer", 2); + qdict_put_str(d_b, "string", "test1"); d_data =3D qdict_new(); - qdict_put(d_data, "a", qint_from_int(1)); + qdict_put_int(d_data, "a", 1); qdict_put(d_data, "b", d_b); - qdict_put(d_data, "c", qstring_from_str("test2")); + qdict_put_str(d_data, "c", "test2"); d =3D data->expect; - qdict_put(d, "event", qstring_from_str("EVENT_C")); + qdict_put_str(d, "event", "EVENT_C"); qdict_put(d, "data", d_data); qapi_event_send_event_c(true, 1, true, &b, "test2", &error_abort); @@ -213,22 +213,22 @@ static void test_event_d(TestEventData *data, a.enum2 =3D ENUM_ONE_VALUE2; d_struct1 =3D qdict_new(); - qdict_put(d_struct1, "integer", qint_from_int(2)); - qdict_put(d_struct1, "string", qstring_from_str("test1")); - qdict_put(d_struct1, "enum1", qstring_from_str("value1")); + 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(d_a, "string", qstring_from_str("test2")); - qdict_put(d_a, "enum2", qstring_from_str("value2")); + 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(d_data, "b", qstring_from_str("test3")); - qdict_put(d_data, "enum3", qstring_from_str("value3")); + qdict_put_str(d_data, "b", "test3"); + qdict_put_str(d_data, "enum3", "value3"); d =3D data->expect; - qdict_put(d, "event", qstring_from_str("EVENT_D")); + qdict_put_str(d, "event", "EVENT_D"); qdict_put(d, "data", d_data); qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE= 3, diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index c213fce..94b9518 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -343,9 +343,9 @@ static void test_visitor_out_any(TestOutputVisitorData = *data, visitor_reset(data); qdict =3D qdict_new(); - qdict_put(qdict, "integer", qint_from_int(-42)); - qdict_put(qdict, "boolean", qbool_from_bool(true)); - qdict_put(qdict, "string", qstring_from_str("foo")); + qdict_put_int(qdict, "integer", -42); + qdict_put_bool(qdict, "boolean", true); + qdict_put_str(qdict, "string", "foo"); qobj =3D QOBJECT(qdict); visit_type_any(data->ov, NULL, &qobj, &error_abort); qobject_decref(qobj); --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491422207127115.23077057744092; Wed, 5 Apr 2017 12:56:47 -0700 (PDT) Received: from localhost ([::1]:42216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvr2s-0001hg-0f for importer@patchew.org; Wed, 05 Apr 2017 15:56:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqug-0002xl-0t for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvqud-00089F-L8 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43954) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquX-00086X-TO; Wed, 05 Apr 2017 15:48:10 -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 mx1.redhat.com (Postfix) with ESMTPS id B63D76315A; Wed, 5 Apr 2017 19:48:08 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 465E35C895; Wed, 5 Apr 2017 19:48:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B63D76315A Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B63D76315A From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:37 -0500 Message-Id: <20170405194741.18956-10-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 05 Apr 2017 19:48:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 09/13] qobject: Use simpler QDict/QList scalar insertion macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alexander Graf , Stefano Stabellini , Michael Roth , "open list:Block layer core" , armbru@redhat.com, Max Reitz , Gerd Hoffmann , "open list:X86" , Anthony Perard , Paolo Bonzini , "Dr. David Alan Gilbert" , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We now have macros in place to make it less verbose to add a scalar to QDict and QList, so use them. To make this patch smaller to review, a couple of subdirectories were done in earlier patches. Patch created mechanically via: spatch --sp-file scripts/coccinelle/qobject.cocci \ --macro-file scripts/cocci-macro-file.h --dir . --in-place and needed only one touch-up in monitor.c to avoid a long line. Signed-off-by: Eric Blake --- block.c | 45 +++++++++++++++++++------------------------= -- blockdev.c | 30 +++++++++++++----------------- hw/block/xen_disk.c | 2 +- hw/usb/xen-usb.c | 12 ++++++------ monitor.c | 23 +++++++++++------------ qapi/qmp-event.c | 2 +- qemu-img.c | 6 +++--- qemu-io.c | 2 +- qemu-nbd.c | 2 +- qobject/qdict.c | 2 +- target/s390x/cpu_models.c | 4 ++-- util/qemu-option.c | 2 +- 12 files changed, 60 insertions(+), 72 deletions(-) diff --git a/block.c b/block.c index 1803334..9b87bf6 100644 --- a/block.c +++ b/block.c @@ -937,16 +937,14 @@ static void update_flags_from_options(int *flags, Qem= uOpts *opts) static void update_options_from_flags(QDict *options, int flags) { if (!qdict_haskey(options, BDRV_OPT_CACHE_DIRECT)) { - qdict_put(options, BDRV_OPT_CACHE_DIRECT, - qbool_from_bool(flags & BDRV_O_NOCACHE)); + qdict_put_bool(options, BDRV_OPT_CACHE_DIRECT, flags & BDRV_O_NOCA= CHE); } if (!qdict_haskey(options, BDRV_OPT_CACHE_NO_FLUSH)) { - qdict_put(options, BDRV_OPT_CACHE_NO_FLUSH, - qbool_from_bool(flags & BDRV_O_NO_FLUSH)); + qdict_put_bool(options, BDRV_OPT_CACHE_NO_FLUSH, + flags & BDRV_O_NO_FLUSH); } if (!qdict_haskey(options, BDRV_OPT_READ_ONLY)) { - qdict_put(options, BDRV_OPT_READ_ONLY, - qbool_from_bool(!(flags & BDRV_O_RDWR))); + qdict_put_bool(options, BDRV_OPT_READ_ONLY, !(flags & BDRV_O_RDWR)= ); } } @@ -1362,7 +1360,7 @@ static int bdrv_fill_options(QDict **options, const c= har *filename, /* Fetch the file name from the options QDict if necessary */ if (protocol && filename) { if (!qdict_haskey(*options, "filename")) { - qdict_put(*options, "filename", qstring_from_str(filename)); + qdict_put_str(*options, "filename", filename); parse_filename =3D true; } else { error_setg(errp, "Can't specify 'file' and 'filename' options = at " @@ -1383,7 +1381,7 @@ static int bdrv_fill_options(QDict **options, const c= har *filename, } drvname =3D drv->format_name; - qdict_put(*options, "driver", qstring_from_str(drvname)); + qdict_put_str(*options, "driver", drvname); } else { error_setg(errp, "Must specify either driver or file"); return -EINVAL; @@ -2034,7 +2032,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, } if (bs->backing_format[0] !=3D '\0' && !qdict_haskey(options, "driver"= )) { - qdict_put(options, "driver", qstring_from_str(bs->backing_format)); + qdict_put_str(options, "driver", bs->backing_format); } backing_hd =3D bdrv_open_inherit(*backing_filename ? backing_filename = : NULL, @@ -2189,12 +2187,9 @@ static BlockDriverState *bdrv_append_temp_snapshot(B= lockDriverState *bs, } /* Prepare options QDict for the temporary file */ - qdict_put(snapshot_options, "file.driver", - qstring_from_str("file")); - qdict_put(snapshot_options, "file.filename", - qstring_from_str(tmp_filename)); - qdict_put(snapshot_options, "driver", - qstring_from_str("qcow2")); + qdict_put_str(snapshot_options, "file.driver", "file"); + qdict_put_str(snapshot_options, "file.filename", tmp_filename); + qdict_put_str(snapshot_options, "driver", "qcow2"); bs_snapshot =3D bdrv_open(NULL, NULL, snapshot_options, flags, errp); snapshot_options =3D NULL; @@ -2369,8 +2364,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, goto fail; } - qdict_put(options, "file", - qstring_from_str(bdrv_get_node_name(file_bs))); + qdict_put_str(options, "file", bdrv_get_node_name(file_bs)); } } @@ -2392,8 +2386,8 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, * sure to update both bs->options (which has the full effective * options for bs) and options (which has file.* already removed). */ - qdict_put(bs->options, "driver", qstring_from_str(drv->format_name= )); - qdict_put(options, "driver", qstring_from_str(drv->format_name)); + qdict_put_str(bs->options, "driver", drv->format_name); + qdict_put_str(options, "driver", drv->format_name); } else if (!drv) { error_setg(errp, "Must specify either driver or file"); goto fail; @@ -2768,12 +2762,12 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_sta= te, BlockReopenQueue *queue, * that they are checked at the end of this function. */ value =3D qemu_opt_get(opts, "node-name"); if (value) { - qdict_put(reopen_state->options, "node-name", qstring_from_str(val= ue)); + qdict_put_str(reopen_state->options, "node-name", value); } value =3D qemu_opt_get(opts, "driver"); if (value) { - qdict_put(reopen_state->options, "driver", qstring_from_str(value)= ); + qdict_put_str(reopen_state->options, "driver", value); } /* if we are to stay read-only, do not allow permission change @@ -4260,8 +4254,7 @@ void bdrv_img_create(const char *filename, const char= *fmt, if (backing_fmt) { backing_options =3D qdict_new(); - qdict_put(backing_options, "driver", - qstring_from_str(backing_fmt)); + qdict_put_str(backing_options, "driver", backing_fmt); } bs =3D bdrv_open(full_backing, NULL, backing_options, back_fla= gs, @@ -4658,7 +4651,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) * contain a representation of the filename, therefore the followi= ng * suffices without querying the (exact_)filename of this BDS. */ if (bs->file->bs->full_open_options) { - qdict_put(opts, "driver", qstring_from_str(drv->format_name)); + qdict_put_str(opts, "driver", drv->format_name); QINCREF(bs->file->bs->full_open_options); qdict_put(opts, "file", bs->file->bs->full_open_options); @@ -4676,7 +4669,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) opts =3D qdict_new(); append_open_options(opts, bs); - qdict_put(opts, "driver", qstring_from_str(drv->format_name)); + qdict_put_str(opts, "driver", drv->format_name); if (bs->exact_filename[0]) { /* This may not work for all block protocol drivers (some may @@ -4686,7 +4679,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) * needs some special format of the options QDict, it needs to * implement the driver-specific bdrv_refresh_filename() funct= ion. */ - qdict_put(opts, "filename", qstring_from_str(bs->exact_filenam= e)); + qdict_put_str(opts, "filename", bs->exact_filename); } bs->full_open_options =3D opts; diff --git a/blockdev.c b/blockdev.c index 040c152..269a5e1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -527,7 +527,7 @@ static BlockBackend *blockdev_init(const char *file, QD= ict *bs_opts, error_setg(errp, "Cannot specify both 'driver' and 'format'"); goto early_err; } - qdict_put(bs_opts, "driver", qstring_from_str(buf)); + qdict_put_str(bs_opts, "driver", buf); } on_write_error =3D BLOCKDEV_ON_ERROR_ENOSPC; @@ -903,10 +903,8 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfac= eType block_default_type) copy_on_read =3D false; } - qdict_put(bs_opts, BDRV_OPT_READ_ONLY, - qstring_from_str(read_only ? "on" : "off")); - qdict_put(bs_opts, "copy-on-read", - qstring_from_str(copy_on_read ? "on" :"off")); + qdict_put_str(bs_opts, BDRV_OPT_READ_ONLY, read_only ? "on" : "off"); + qdict_put_str(bs_opts, "copy-on-read", copy_on_read ? "on" : "off"); /* Controller type */ value =3D qemu_opt_get(legacy_opts, "if"); @@ -1030,7 +1028,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfa= ceType block_default_type) new_id =3D g_strdup_printf("%s%s%i", if_name[type], mediastr, unit_id); } - qdict_put(bs_opts, "id", qstring_from_str(new_id)); + qdict_put_str(bs_opts, "id", new_id); g_free(new_id); } @@ -1067,7 +1065,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfa= ceType block_default_type) error_report("werror is not supported by this bus type"); goto fail; } - qdict_put(bs_opts, "werror", qstring_from_str(werror)); + qdict_put_str(bs_opts, "werror", werror); } rerror =3D qemu_opt_get(legacy_opts, "rerror"); @@ -1077,7 +1075,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfa= ceType block_default_type) error_report("rerror is not supported by this bus type"); goto fail; } - qdict_put(bs_opts, "rerror", qstring_from_str(rerror)); + qdict_put_str(bs_opts, "rerror", rerror); } /* Actual block device init: Functionality shared with blockdev-add */ @@ -1737,10 +1735,9 @@ static void external_snapshot_prepare(BlkActionState= *common, options =3D qdict_new(); if (s->has_snapshot_node_name) { - qdict_put(options, "node-name", - qstring_from_str(snapshot_node_name)); + qdict_put_str(options, "node-name", snapshot_node_name); } - qdict_put(options, "driver", qstring_from_str(format)); + qdict_put_str(options, "driver", format); flags |=3D BDRV_O_NO_BACKING; } @@ -2579,11 +2576,10 @@ void qmp_blockdev_change_medium(bool has_device, co= nst char *device, options =3D qdict_new(); detect_zeroes =3D blk_get_detect_zeroes_from_root_state(blk); - qdict_put(options, "detect-zeroes", - qstring_from_str(detect_zeroes ? "on" : "off")); + qdict_put_str(options, "detect-zeroes", detect_zeroes ? "on" : "off"); if (has_format) { - qdict_put(options, "driver", qstring_from_str(format)); + qdict_put_str(options, "driver", format); } medium_bs =3D bdrv_open(filename, NULL, options, bdrv_flags, errp); @@ -3251,7 +3247,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= BlockJobTxn *txn, if (backup->format) { options =3D qdict_new(); - qdict_put(options, "driver", qstring_from_str(backup->format)); + qdict_put_str(options, "driver", backup->format); } target_bs =3D bdrv_open(backup->target, NULL, options, flags, errp); @@ -3555,10 +3551,10 @@ void qmp_drive_mirror(DriveMirror *arg, Error **err= p) options =3D qdict_new(); if (arg->has_node_name) { - qdict_put(options, "node-name", qstring_from_str(arg->node_name)); + qdict_put_str(options, "node-name", arg->node_name); } if (format) { - qdict_put(options, "driver", qstring_from_str(format)); + qdict_put_str(options, "driver", format); } /* Mirroring takes care of copy-on-write using the source's backing diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 456a2d5..47b2ca1 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1082,7 +1082,7 @@ static int blk_connect(struct XenDevice *xendev) if (strcmp(blkdev->fileproto, "")) { options =3D qdict_new(); - qdict_put(options, "driver", qstring_from_str(blkdev->fileprot= o)); + qdict_put_str(options, "driver", blkdev->fileproto); } /* setup via xenbus -> create new block driver instance */ diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index 8e676e6..6659415 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -746,16 +746,16 @@ static void usbback_portid_add(struct usbback_info *u= sbif, unsigned port, portname++; qdict =3D qdict_new(); - qdict_put(qdict, "driver", qstring_from_str("usb-host")); + qdict_put_str(qdict, "driver", "usb-host"); tmp =3D g_strdup_printf("%s.0", usbif->xendev.qdev.id); - qdict_put(qdict, "bus", qstring_from_str(tmp)); + qdict_put_str(qdict, "bus", tmp); g_free(tmp); tmp =3D g_strdup_printf("%s-%u", usbif->xendev.qdev.id, port); - qdict_put(qdict, "id", qstring_from_str(tmp)); + qdict_put_str(qdict, "id", tmp); g_free(tmp); - qdict_put(qdict, "port", qint_from_int(port)); - qdict_put(qdict, "hostbus", qint_from_int(atoi(busid))); - qdict_put(qdict, "hostport", qstring_from_str(portname)); + qdict_put_int(qdict, "port", port); + qdict_put_int(qdict, "hostbus", atoi(busid)); + qdict_put_str(qdict, "hostport", portname); opts =3D qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_= err); if (local_err) { goto err; diff --git a/monitor.c b/monitor.c index be282ec..88f6fe9 100644 --- a/monitor.c +++ b/monitor.c @@ -2671,7 +2671,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, } goto fail; } - qdict_put(qdict, key, qstring_from_str(buf)); + qdict_put_str(qdict, key, buf); } break; case 'O': @@ -2773,9 +2773,9 @@ static QDict *monitor_parse_arguments(Monitor *mon, size =3D -1; } } - qdict_put(qdict, "count", qint_from_int(count)); - qdict_put(qdict, "format", qint_from_int(format)); - qdict_put(qdict, "size", qint_from_int(size)); + qdict_put_int(qdict, "count", count); + qdict_put_int(qdict, "format", format); + qdict_put_int(qdict, "size", size); } break; case 'i': @@ -2818,7 +2818,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, } val <<=3D 20; } - qdict_put(qdict, key, qint_from_int(val)); + qdict_put_int(qdict, key, val); } break; case 'o': @@ -2841,7 +2841,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, monitor_printf(mon, "invalid size\n"); goto fail; } - qdict_put(qdict, key, qint_from_int(val)); + qdict_put_int(qdict, key, val); p =3D end; } break; @@ -2897,7 +2897,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, monitor_printf(mon, "Expected 'on' or 'off'\n"); goto fail; } - qdict_put(qdict, key, qbool_from_bool(val)); + qdict_put_bool(qdict, key, val); } break; case '-': @@ -2928,7 +2928,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, } else { /* has option */ p++; - qdict_put(qdict, key, qbool_from_bool(true)); + qdict_put_bool(qdict, key, true); } } } @@ -2954,7 +2954,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, cmd->name); goto fail; } - qdict_put(qdict, key, qstring_from_str(p)); + qdict_put_str(qdict, key, p); p +=3D len; } break; @@ -3733,9 +3733,8 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) QapiErrorClass_lookup[ERROR_CLASS_COMMAND_NOT_FOUND]))= { /* Provide a more useful error message */ qdict_del(qdict, "desc"); - qdict_put(qdict, "desc", - qstring_from_str("Expecting capabilities negotiation" - " with 'qmp_capabilities'")); + qdict_put_str(qdict, "desc", "Expecting capabilities negotiati= on" + " with 'qmp_capabilities'"); } } diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c index 802ede4..ba3029c 100644 --- a/qapi/qmp-event.c +++ b/qapi/qmp-event.c @@ -51,7 +51,7 @@ static void timestamp_put(QDict *qdict) QDict *qmp_event_build_dict(const char *event_name) { QDict *dict =3D qdict_new(); - qdict_put(dict, "event", qstring_from_str(event_name)); + qdict_put_str(dict, "event", event_name); timestamp_put(dict); return dict; } diff --git a/qemu-img.c b/qemu-img.c index b220cf7..efb9833 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -313,7 +313,7 @@ static BlockBackend *img_open_file(const char *filename, if (fmt) { options =3D qdict_new(); - qdict_put(options, "driver", qstring_from_str(fmt)); + qdict_put_str(options, "driver", fmt); } blk =3D blk_new_open(filename, NULL, options, flags, &local_err); @@ -3158,7 +3158,7 @@ static int img_rebase(int argc, char **argv) if (bs->backing_format[0] !=3D '\0') { options =3D qdict_new(); - qdict_put(options, "driver", qstring_from_str(bs->backing_form= at)); + qdict_put_str(options, "driver", bs->backing_format); } bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name)); @@ -3175,7 +3175,7 @@ static int img_rebase(int argc, char **argv) if (out_baseimg[0]) { if (out_basefmt) { options =3D qdict_new(); - qdict_put(options, "driver", qstring_from_str(out_basefmt)= ); + qdict_put_str(options, "driver", out_basefmt); } else { options =3D NULL; } diff --git a/qemu-io.c b/qemu-io.c index 427cbae..ed0e2dc 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -601,7 +601,7 @@ int main(int argc, char **argv) } else { if (format) { opts =3D qdict_new(); - qdict_put(opts, "driver", qstring_from_str(format)); + qdict_put_str(opts, "driver", format); } if (openfile(argv[optind], flags, writethrough, opts)) { exit(1); diff --git a/qemu-nbd.c b/qemu-nbd.c index e080fb7..e4f00e2 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -959,7 +959,7 @@ int main(int argc, char **argv) } else { if (fmt) { options =3D qdict_new(); - qdict_put(options, "driver", qstring_from_str(fmt)); + qdict_put_str(options, "driver", fmt); } blk =3D blk_new_open(srcpath, NULL, options, flags, &local_err); } diff --git a/qobject/qdict.c b/qobject/qdict.c index 291eef1..88e2ecd 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -463,7 +463,7 @@ void qdict_set_default_str(QDict *dst, const char *key,= const char *val) return; } - qdict_put(dst, key, qstring_from_str(val)); + qdict_put_str(dst, key, val); } static void qdict_flatten_qdict(QDict *qdict, QDict *target, diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index ce461cc..8d27363 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -376,12 +376,12 @@ static void cpu_model_from_info(S390CPUModel *model, = const CpuModelInfo *info, static void qdict_add_disabled_feat(const char *name, void *opaque) { - qdict_put(opaque, name, qbool_from_bool(false)); + qdict_put_bool(opaque, name, false); } static void qdict_add_enabled_feat(const char *name, void *opaque) { - qdict_put(opaque, name, qbool_from_bool(true)); + qdict_put_bool(opaque, name, true); } /* convert S390CPUDef into a static CpuModelInfo */ diff --git a/util/qemu-option.c b/util/qemu-option.c index 5ce1b5c..a36cafa 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1060,7 +1060,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdic= t) qdict =3D qdict_new(); } if (opts->id) { - qdict_put(qdict, "id", qstring_from_str(opts->id)); + qdict_put_str(qdict, "id", opts->id); } QTAILQ_FOREACH(opt, &opts->head, next) { val =3D QOBJECT(qstring_from_str(opt->str)); --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14914220804941000.7272260985745; Wed, 5 Apr 2017 12:54:40 -0700 (PDT) Received: from localhost ([::1]:42200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvr0p-0008I4-Ev for importer@patchew.org; Wed, 05 Apr 2017 15:54:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvquc-0002r3-J4 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvqub-00088R-RA for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquY-00087B-Su; Wed, 05 Apr 2017 15:48:11 -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 mx1.redhat.com (Postfix) with ESMTPS id CDAB33D961; Wed, 5 Apr 2017 19:48:09 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF0501719D; Wed, 5 Apr 2017 19:48:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CDAB33D961 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CDAB33D961 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:38 -0500 Message-Id: <20170405194741.18956-11-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 05 Apr 2017 19:48:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 10/13] block: Simplify bdrv_append_temp_snapshot() logic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , armbru@redhat.com, "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Noticed while checking Coccinelle results. Naming a label 'out:' when it is only used on error paths is weird; meanwhile we know that snapshot_options is NULL on success and that QDECREF(NULL) is safe. So merge the two exit paths into one. Signed-off-by: Eric Blake --- block.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index 9b87bf6..a13625f 100644 --- a/block.c +++ b/block.c @@ -2209,13 +2209,10 @@ static BlockDriverState *bdrv_append_temp_snapshot(= BlockDriverState *bs, goto out; } +out: + QDECREF(snapshot_options); g_free(tmp_filename); return bs_snapshot; - -out: - QDECREF(snapshot_options); - g_free(tmp_filename); - return NULL; } /* --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149142194280697.47990960843902; Wed, 5 Apr 2017 12:52:22 -0700 (PDT) Received: from localhost ([::1]:42188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqyb-00067A-MI for importer@patchew.org; Wed, 05 Apr 2017 15:52:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvqua-0002oK-MJ for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvquZ-00087i-Rw for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39250) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquZ-00087M-LW for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:11 -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 mx1.redhat.com (Postfix) with ESMTPS id 9CA55C06584D for ; Wed, 5 Apr 2017 19:48:10 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 120075C54B; Wed, 5 Apr 2017 19:48:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9CA55C06584D Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9CA55C06584D From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:39 -0500 Message-Id: <20170405194741.18956-12-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 05 Apr 2017 19:48:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 11/13] QemuOpts: Simplify qemu_opts_to_qdict() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Noticed while investigating Coccinelle cleanups. There is no need for a temporary variable when we can use the new macro to do the same thing with less typing. Signed-off-by: Eric Blake --- util/qemu-option.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index a36cafa..5977bfc 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1054,7 +1054,6 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qd= ict, Error **errp) QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict) { QemuOpt *opt; - QObject *val; if (!qdict) { qdict =3D qdict_new(); @@ -1063,8 +1062,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdic= t) qdict_put_str(qdict, "id", opts->id); } QTAILQ_FOREACH(opt, &opts->head, next) { - val =3D QOBJECT(qstring_from_str(opt->str)); - qdict_put_obj(qdict, opt->name, val); + qdict_put_str(qdict, opt->name, opt->str); } return qdict; } --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491422095830807.8022377376867; Wed, 5 Apr 2017 12:54:55 -0700 (PDT) Received: from localhost ([::1]:42201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvr14-0008UF-2t for importer@patchew.org; Wed, 05 Apr 2017 15:54:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvquh-0002zf-Tb for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvque-0008A3-TA for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47550) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvquc-00088W-Fr; Wed, 05 Apr 2017 15:48:14 -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 mx1.redhat.com (Postfix) with ESMTPS id 7188696EF; Wed, 5 Apr 2017 19:48:13 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD8615C54B; Wed, 5 Apr 2017 19:48:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7188696EF Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7188696EF From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:40 -0500 Message-Id: <20170405194741.18956-13-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 05 Apr 2017 19:48:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 12/13] fdc-test: Avoid deprecated 'change' command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , armbru@redhat.com, "open list:Floppy" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use the preferred blockdev-change-medium command instead. Admittedly, use of 'device' is also deprecated over the newer use of 'id', but the test is exploiting that the name 'floppy0' is auto-created by the board, and I could not figure out where the command line lives that would need to be tweaked to provide a non-random 'id' to this device. Signed-off-by: Eric Blake Reviewed-by: John Snow --- v3: update commit message to point out that we are still using deprecated 'device' --- tests/fdc-test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/fdc-test.c b/tests/fdc-test.c index 738c6b4..f5ff68d 100644 --- a/tests/fdc-test.c +++ b/tests/fdc-test.c @@ -298,8 +298,9 @@ static void test_media_insert(void) /* Insert media in drive. DSKCHK should not be reset until a step pulse * is sent. */ - qmp_discard_response("{'execute':'change', 'arguments':{" - " 'device':'floppy0', 'target': %s, 'arg': 'raw' = }}", + qmp_discard_response("{'execute':'blockdev-change-medium', 'arguments'= :{" + " 'device':'floppy0', 'filename': %s, " + "'format': 'raw' }}", test_image); dir =3D inb(FLOPPY_BASE + reg_dir); --=20 2.9.3 From nobody Mon May 6 16:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491422147696242.80122471177037; Wed, 5 Apr 2017 12:55:47 -0700 (PDT) Received: from localhost ([::1]:42209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvr1u-0000uS-Dj for importer@patchew.org; Wed, 05 Apr 2017 15:55:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvque-0002tw-Km for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvqud-000896-FX for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44036) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvqud-00088c-6i for qemu-devel@nongnu.org; Wed, 05 Apr 2017 15:48:15 -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 mx1.redhat.com (Postfix) with ESMTPS id 323F664D9F for ; Wed, 5 Apr 2017 19:48:14 +0000 (UTC) Received: from red.redhat.com (ovpn-124-8.rdu2.redhat.com [10.10.124.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id A75C95C54B; Wed, 5 Apr 2017 19:48:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 323F664D9F Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 323F664D9F From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 14:47:41 -0500 Message-Id: <20170405194741.18956-14-eblake@redhat.com> In-Reply-To: <20170405194741.18956-1-eblake@redhat.com> References: <20170405194741.18956-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 05 Apr 2017 19:48:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 13/13] test-qga: Actually test 0xff sync bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit 62c39b3 introduced test-qga, and at face value, appears to be testing the 'guest-sync' behavior that is recommended for guests in sending 0xff to QGA to force the parser to reset. But this aspect of the test has never actually done anything: the qmp_fd() call chain converts its string argument into QObject, then converts that QObject back to the actual string that is sent over the wire - and the conversion process silently drops the 0xff byte from the string sent to QGA, thus never resetting the QGA parser. An upcoming patch will get rid of the wasteful round trip through QObject, at which point the string in test-qga will be directly sent over the wire. But fixing qmp_fd() to actually send 0xff over the wire is not all we have to do - the actual QMP parser loudly complains that 0xff is not valid JSON, and sends an error message _prior_ to actually parsing the 'guest-sync' or 'guest-sync-delimited' command. With 'guest-sync', we cannot easily tell if this error message is a result of our command - which is WHY we invented the 'guest-sync-delimited' command. So for the testsuite, fix things to only check 0xff behavior on 'guest-sync-delimited', and to loop until we've consumed all garbage prior to the requested delimiter, which matches the documented actions that a real QGA client is supposed to do. Ideally, we'd fix the QGA JSON parser to silently ignore 0xff rather than sending an error message back, at which point we could enhance this test for 'guest-sync' as well as for 'guest-sync-delimited'. But for the sake of this patch, our testing of 'guest-sync' is no worse than it was pre-patch, because we have never been sending 0xff over the wire in the first place. Signed-off-by: Eric Blake --- v3: use inline \xff byte rather than %c, add comment --- tests/libqtest.c | 8 ++++++++ tests/test-qga.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 99b1195..4b4407a 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -446,6 +446,14 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap) va_list ap_copy; QObject *qobj; + /* qobject_from_jsonv() silently eats leading 0xff as invalid + * JSON, but we want to test sending them over the wire to force + * resyncs */ + if (*fmt =3D=3D '\377') { + socket_send(fd, fmt, 1); + fmt++; + } + /* Going through qobject ensures we escape strings properly. * This seemingly unnecessary copy is required in case va_list * is an array type. diff --git a/tests/test-qga.c b/tests/test-qga.c index c780f00..438c2e7 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -146,14 +146,23 @@ static void test_qga_sync_delimited(gconstpointer fix) QDict *ret; gchar *cmd; - cmd =3D g_strdup_printf("%c{'execute': 'guest-sync-delimited'," - " 'arguments': {'id': %u } }", 0xff, r); + cmd =3D g_strdup_printf("\xff{'execute': 'guest-sync-delimited'," + " 'arguments': {'id': %u } }", r); qmp_fd_send(fixture->fd, cmd); g_free(cmd); - v =3D read(fixture->fd, &c, 1); - g_assert_cmpint(v, =3D=3D, 1); - g_assert_cmpint(c, =3D=3D, 0xff); + /* + * Read and ignore garbage until resynchronized. + * + * TODO: The server shouldn't emit so much garbage (among other + * things, it loudly complains about the client's \xff being + * invalid JSON, even though it is a documented part of the + * handshake. + */ + do { + v =3D read(fixture->fd, &c, 1); + g_assert_cmpint(v, =3D=3D, 1); + } while (c !=3D 0xff); ret =3D qmp_fd_receive(fixture->fd); g_assert_nonnull(ret); @@ -172,8 +181,19 @@ static void test_qga_sync(gconstpointer fix) QDict *ret; gchar *cmd; - cmd =3D g_strdup_printf("%c{'execute': 'guest-sync'," - " 'arguments': {'id': %u } }", 0xff, r); + /* + * TODO guest-sync is inherently limited: we cannot distinguish + * failure caused by reacting to garbage on the wire prior to this + * command, from failure of this actual command. Clients are + * supposed to be able to send a raw '\xff' byte to at least + * re-synchronize the server's parser prior to this command, but + * we are not in a position to test that here because (at least + * for now) it causes the server to issue an error message about + * invalid JSON. Testing of '\xff' handling is done in + * guest-sync-delimited instead. + */ + cmd =3D g_strdup_printf("{'execute': 'guest-sync'," + " 'arguments': {'id': %u } }", r); ret =3D qmp_fd(fixture->fd, cmd); g_free(cmd); --=20 2.9.3