Skip to content

Commit

Permalink
qapi rocker: Elide redundant has_FOO in generated C
Browse files Browse the repository at this point in the history
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>
Message-Id: <20221104160712.3005652-23-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
  • Loading branch information
Markus Armbruster committed Dec 14, 2022
1 parent d01c004 commit 05e0748
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
13 changes: 2 additions & 11 deletions hw/net/rocker/rocker_of_dpa.c
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
22 changes: 11 additions & 11 deletions monitor/hmp-cmds.c
Expand Up @@ -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);
}
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -2137,15 +2137,15 @@ 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");
}
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");
}
Expand Down
1 change: 0 additions & 1 deletion scripts/qapi/schema.py
Expand Up @@ -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',
Expand Down

0 comments on commit 05e0748

Please sign in to comment.