qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: jsnow@redhat.com, eblake@redhat.com, michael.roth@amd.com,
	Jiri Pirko <jiri@resnulli.us>
Subject: [PATCH v3 22/30] qapi rocker: Elide redundant has_FOO in generated C
Date: Fri,  4 Nov 2022 17:07:04 +0100	[thread overview]
Message-ID: <20221104160712.3005652-23-armbru@redhat.com> (raw)
In-Reply-To: <20221104160712.3005652-1-armbru@redhat.com>

The has_FOO for pointer-valued FOO are redundant, except for arrays.
They are also a nuisance to work with.  Recent commit "qapi: Start to
elide redundant has_FOO in generated C" provided the means to elide
them step by step.  This is the step for qapi/rocker.json.

Said commit explains the transformation in more detail.  The invariant
violations mentioned there do not occur here.

Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/net/rocker/rocker_of_dpa.c | 13 ++-----------
 monitor/hmp-cmds.c            | 22 +++++++++++-----------
 scripts/qapi/schema.py        |  1 -
 3 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c
index b3b8c5bb6d..dfe4754469 100644
--- a/hw/net/rocker/rocker_of_dpa.c
+++ b/hw/net/rocker/rocker_of_dpa.c
@@ -2348,23 +2348,19 @@ static void of_dpa_flow_fill(void *cookie, void *value, void *user_data)
 
     if (memcmp(key->eth.src.a, zero_mac.a, ETH_ALEN) ||
         memcmp(mask->eth.src.a, zero_mac.a, ETH_ALEN)) {
-        nkey->has_eth_src = true;
         nkey->eth_src = qemu_mac_strdup_printf(key->eth.src.a);
     }
 
-    if (nkey->has_eth_src && memcmp(mask->eth.src.a, ff_mac.a, ETH_ALEN)) {
-        nmask->has_eth_src = true;
+    if (nkey->eth_src && memcmp(mask->eth.src.a, ff_mac.a, ETH_ALEN)) {
         nmask->eth_src = qemu_mac_strdup_printf(mask->eth.src.a);
     }
 
     if (memcmp(key->eth.dst.a, zero_mac.a, ETH_ALEN) ||
         memcmp(mask->eth.dst.a, zero_mac.a, ETH_ALEN)) {
-        nkey->has_eth_dst = true;
         nkey->eth_dst = qemu_mac_strdup_printf(key->eth.dst.a);
     }
 
-    if (nkey->has_eth_dst && memcmp(mask->eth.dst.a, ff_mac.a, ETH_ALEN)) {
-        nmask->has_eth_dst = true;
+    if (nkey->eth_dst && memcmp(mask->eth.dst.a, ff_mac.a, ETH_ALEN)) {
         nmask->eth_dst = qemu_mac_strdup_printf(mask->eth.dst.a);
     }
 
@@ -2400,7 +2396,6 @@ static void of_dpa_flow_fill(void *cookie, void *value, void *user_data)
             if (key->ipv4.addr.dst || mask->ipv4.addr.dst) {
                 char *dst = inet_ntoa(*(struct in_addr *)&key->ipv4.addr.dst);
                 int dst_len = of_dpa_mask2prefix(mask->ipv4.addr.dst);
-                nkey->has_ip_dst = true;
                 nkey->ip_dst = g_strdup_printf("%s/%d", dst, dst_len);
             }
             break;
@@ -2501,12 +2496,10 @@ static void of_dpa_group_fill(void *key, void *value, void *user_data)
             ngroup->set_vlan_id = ntohs(group->l2_rewrite.vlan_id);
         }
         if (memcmp(group->l2_rewrite.src_mac.a, zero_mac.a, ETH_ALEN)) {
-            ngroup->has_set_eth_src = true;
             ngroup->set_eth_src =
                 qemu_mac_strdup_printf(group->l2_rewrite.src_mac.a);
         }
         if (memcmp(group->l2_rewrite.dst_mac.a, zero_mac.a, ETH_ALEN)) {
-            ngroup->has_set_eth_dst = true;
             ngroup->set_eth_dst =
                 qemu_mac_strdup_printf(group->l2_rewrite.dst_mac.a);
         }
@@ -2532,12 +2525,10 @@ static void of_dpa_group_fill(void *key, void *value, void *user_data)
             ngroup->set_vlan_id = ntohs(group->l3_unicast.vlan_id);
         }
         if (memcmp(group->l3_unicast.src_mac.a, zero_mac.a, ETH_ALEN)) {
-            ngroup->has_set_eth_src = true;
             ngroup->set_eth_src =
                 qemu_mac_strdup_printf(group->l3_unicast.src_mac.a);
         }
         if (memcmp(group->l3_unicast.dst_mac.a, zero_mac.a, ETH_ALEN)) {
-            ngroup->has_set_eth_dst = true;
             ngroup->set_eth_dst =
                 qemu_mac_strdup_printf(group->l3_unicast.dst_mac.a);
         }
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index ae5ebe765a..a41f94a34a 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -2010,35 +2010,35 @@ void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
             }
         }
 
-        if (key->has_eth_src) {
+        if (key->eth_src) {
             if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
-                (mask->has_eth_src) &&
+                mask->eth_src &&
                 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
                 monitor_printf(mon, " src <any mcast/bcast>");
             } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
-                (mask->has_eth_src) &&
+                mask->eth_src &&
                 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
                 monitor_printf(mon, " src <any ucast>");
             } else {
                 monitor_printf(mon, " src %s", key->eth_src);
-                if (mask->has_eth_src) {
+                if (mask->eth_src) {
                     monitor_printf(mon, "(%s)", mask->eth_src);
                 }
             }
         }
 
-        if (key->has_eth_dst) {
+        if (key->eth_dst) {
             if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
-                (mask->has_eth_dst) &&
+                mask->eth_dst &&
                 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
                 monitor_printf(mon, " dst <any mcast/bcast>");
             } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
-                (mask->has_eth_dst) &&
+                mask->eth_dst &&
                 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
                 monitor_printf(mon, " dst <any ucast>");
             } else {
                 monitor_printf(mon, " dst %s", key->eth_dst);
-                if (mask->has_eth_dst) {
+                if (mask->eth_dst) {
                     monitor_printf(mon, "(%s)", mask->eth_dst);
                 }
             }
@@ -2058,7 +2058,7 @@ void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
             }
         }
 
-        if (key->has_ip_dst) {
+        if (key->ip_dst) {
             monitor_printf(mon, " dst %s", key->ip_dst);
         }
 
@@ -2137,7 +2137,7 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
                            group->set_vlan_id & VLAN_VID_MASK);
         }
 
-        if (group->has_set_eth_src) {
+        if (group->set_eth_src) {
             if (!set) {
                 set = true;
                 monitor_printf(mon, " set");
@@ -2145,7 +2145,7 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, " src %s", group->set_eth_src);
         }
 
-        if (group->has_set_eth_dst) {
+        if (group->set_eth_dst) {
             if (!set) {
                 monitor_printf(mon, " set");
             }
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 2b6644f1c3..1b3195bc87 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -759,7 +759,6 @@ def need_has(self):
         assert self.type
         # Temporary hack to support dropping the has_FOO in reviewable chunks
         opt_out = [
-            'qapi/rocker.json',
             'qapi/run-state.json',
             'qapi/stats.json',
             'qapi/tpm.json',
-- 
2.37.3



  parent reply	other threads:[~2022-11-04 16:13 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04 16:06 [PATCH v3 00/30] qapi: Elide redundant has_FOO in generated C Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 01/30] docs/devel/qapi-code-gen: Update example to match current code Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 02/30] qapi: Tidy up whitespace in generated code Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 03/30] docs/devel/qapi-code-gen: Extend example for next commit's change Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 04/30] qapi: Start to elide redundant has_FOO in generated C Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 05/30] qapi tests: Elide " Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 06/30] qapi acpi: " Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 07/30] qapi audio: " Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 08/30] blockdev: Clean up abuse of DriveBackup member format Markus Armbruster
2022-11-04 19:32   ` Eric Blake
2022-11-04 16:06 ` [PATCH v3 09/30] nbd/server: Clean up abuse of BlockExportOptionsNbd member @arg Markus Armbruster
2022-11-04 19:35   ` Eric Blake
2022-11-08 14:21   ` Vladimir Sementsov-Ogievskiy
2022-11-04 16:06 ` [PATCH v3 10/30] qapi block: Elide redundant has_FOO in generated C Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 11/30] qapi chardev: " Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 12/30] qapi crypto: " Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 13/30] qapi dump: " Markus Armbruster
2022-11-05 17:15   ` Philippe Mathieu-Daudé
2022-11-04 16:06 ` [PATCH v3 14/30] qapi job: " Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 15/30] qapi machine: " Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 16/30] qapi migration: " Markus Armbruster
2022-11-04 16:06 ` [PATCH v3 17/30] qapi misc: " Markus Armbruster
2022-11-04 16:07 ` [PATCH v3 18/30] qapi net: " Markus Armbruster
2022-11-05 17:03   ` Philippe Mathieu-Daudé
2022-11-04 16:07 ` [PATCH v3 19/30] qapi pci: " Markus Armbruster
2022-11-04 16:07 ` [PATCH v3 20/30] qapi qdev qom: " Markus Armbruster
2022-11-05 17:06   ` Philippe Mathieu-Daudé
2022-11-04 16:07 ` [PATCH v3 21/30] qapi replay: " Markus Armbruster
2022-11-04 16:07 ` Markus Armbruster [this message]
2022-11-05 17:08   ` [PATCH v3 22/30] qapi rocker: " Philippe Mathieu-Daudé
2022-11-04 16:07 ` [PATCH v3 23/30] qapi run-state: " Markus Armbruster
2022-11-04 16:07 ` [PATCH v3 24/30] qapi stats: " Markus Armbruster
2022-11-04 16:07 ` [PATCH v3 25/30] qapi tpm: " Markus Armbruster
2022-11-04 16:07 ` [PATCH v3 26/30] qapi transaction: " Markus Armbruster
2022-11-05 17:08   ` Philippe Mathieu-Daudé
2022-11-04 16:07 ` [PATCH v3 27/30] qapi ui: " Markus Armbruster
2022-11-04 16:07 ` [PATCH v3 28/30] qapi virtio: " Markus Armbruster
2022-11-04 16:07 ` [PATCH v3 29/30] qapi qga: " Markus Armbruster
2022-11-05 17:13   ` Philippe Mathieu-Daudé
2022-11-04 16:07 ` [PATCH v3 30/30] qapi: Drop temporary logic to support conversion step by step Markus Armbruster
2022-11-04 16:15 ` [PATCH v3 00/30] qapi: Elide redundant has_FOO in generated C Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221104160712.3005652-23-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=jsnow@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).