qapi net: Elide redundant has_FOO in generated C

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/net.json.

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

Cc: Jason Wang <jasowang@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20221104160712.3005652-19-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
[Fixes for MacOS squashed in]
This commit is contained in:
Markus Armbruster 2022-11-04 17:07:00 +01:00
parent 9492718b7c
commit 7480874a69
14 changed files with 77 additions and 82 deletions

View file

@ -457,8 +457,7 @@ static void rxfilter_notify(NetClientState *nc)
if (nc->rxfilter_notify_enabled) {
char *path = object_get_canonical_path(OBJECT(n->qdev));
qapi_event_send_nic_rx_filter_changed(!!n->netclient_name,
n->netclient_name, path);
qapi_event_send_nic_rx_filter_changed(n->netclient_name, path);
g_free(path);
/* disable event notification to avoid events flooding */

View file

@ -1104,7 +1104,6 @@ void hmp_announce_self(Monitor *mon, const QDict *qdict)
params->interfaces = strList_from_comma_list(interfaces_str);
params->has_interfaces = params->interfaces != NULL;
params->id = g_strdup(id);
params->has_id = !!params->id;
qmp_announce_self(params, NULL);
qapi_free_AnnounceParameters(params);
}

View file

@ -46,7 +46,7 @@ void qemu_announce_timer_del(AnnounceTimer *timer, bool free_named)
}
qapi_free_strList(timer->params.interfaces);
timer->params.interfaces = NULL;
if (free_named && timer->params.has_id) {
if (free_named && timer->params.id) {
AnnounceTimer *list_timer;
/*
* Sanity check: There should only be one timer on the list with
@ -157,7 +157,7 @@ static void qemu_announce_self_iter(NICState *nic, void *opaque)
skip = false;
}
trace_qemu_announce_self_iter(timer->params.has_id ? timer->params.id : "_",
trace_qemu_announce_self_iter(timer->params.id ?: "_",
nic->ncs->name,
qemu_ether_ntoa(&nic->conf->macaddr), skip);
@ -199,9 +199,9 @@ void qemu_announce_self(AnnounceTimer *timer, AnnounceParameters *params)
void qmp_announce_self(AnnounceParameters *params, Error **errp)
{
AnnounceTimer *named_timer;
if (!params->has_id) {
if (!params->id) {
params->id = g_strdup("");
params->has_id = true;
}
named_timer = g_datalist_get_data(&named_timers, params->id);

View file

@ -274,7 +274,7 @@ int net_init_hubport(const Netdev *netdev, const char *name,
assert(!peer);
hubport = &netdev->u.hubport;
if (hubport->has_netdev) {
if (hubport->netdev) {
hubpeer = qemu_find_netdev(hubport->netdev);
if (!hubpeer) {
error_setg(errp, "netdev '%s' not found", hubport->netdev);

View file

@ -578,7 +578,7 @@ int net_init_l2tpv3(const Netdev *netdev,
if (l2tpv3->has_udp && l2tpv3->udp) {
s->udp = true;
if (!(l2tpv3->has_srcport && l2tpv3->has_dstport)) {
if (!(l2tpv3->srcport && l2tpv3->dstport)) {
error_setg(errp, "need both src and dst port for udp");
goto outerr;
} else {

View file

@ -964,7 +964,7 @@ static int net_init_nic(const Netdev *netdev, const char *name,
memset(nd, 0, sizeof(*nd));
if (nic->has_netdev) {
if (nic->netdev) {
nd->netdev = qemu_find_netdev(nic->netdev);
if (!nd->netdev) {
error_setg(errp, "netdev '%s' not found", nic->netdev);
@ -975,19 +975,19 @@ static int net_init_nic(const Netdev *netdev, const char *name,
nd->netdev = peer;
}
nd->name = g_strdup(name);
if (nic->has_model) {
if (nic->model) {
nd->model = g_strdup(nic->model);
}
if (nic->has_addr) {
if (nic->addr) {
nd->devaddr = g_strdup(nic->addr);
}
if (nic->has_macaddr &&
if (nic->macaddr &&
net_parse_macaddr(nd->macaddr.a, nic->macaddr) < 0) {
error_setg(errp, "invalid syntax for ethernet address");
return -1;
}
if (nic->has_macaddr &&
if (nic->macaddr &&
is_multicast_ether_addr(nd->macaddr.a)) {
error_setg(errp,
"NIC cannot have multicast MAC address (odd 1st byte)");
@ -1081,7 +1081,7 @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
/* Do not add to a hub if it's a nic with a netdev= parameter. */
if (netdev->type != NET_CLIENT_DRIVER_NIC ||
!netdev->u.nic.has_netdev) {
!netdev->u.nic.netdev) {
peer = net_hub_add_port(0, NULL, NULL);
}
}
@ -1295,8 +1295,7 @@ void print_net_client(Monitor *mon, NetClientState *nc)
}
}
RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
Error **errp)
RxFilterInfoList *qmp_query_rx_filter(const char *name, Error **errp)
{
NetClientState *nc;
RxFilterInfoList *filter_list = NULL, **tail = &filter_list;
@ -1304,13 +1303,13 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
QTAILQ_FOREACH(nc, &net_clients, next) {
RxFilterInfo *info;
if (has_name && strcmp(nc->name, name) != 0) {
if (name && strcmp(nc->name, name) != 0) {
continue;
}
/* only query rx-filter information of NIC */
if (nc->info->type != NET_CLIENT_DRIVER_NIC) {
if (has_name) {
if (name) {
error_setg(errp, "net client(%s) isn't a NIC", name);
assert(!filter_list);
return NULL;
@ -1327,19 +1326,19 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
if (nc->info->query_rx_filter) {
info = nc->info->query_rx_filter(nc);
QAPI_LIST_APPEND(tail, info);
} else if (has_name) {
} else if (name) {
error_setg(errp, "net client(%s) doesn't support"
" rx-filter querying", name);
assert(!filter_list);
return NULL;
}
if (has_name) {
if (name) {
break;
}
}
if (filter_list == NULL && has_name) {
if (filter_list == NULL && name) {
error_setg(errp, "invalid net client name: %s", name);
}

View file

@ -1153,8 +1153,8 @@ int net_init_slirp(const Netdev *netdev, const char *name,
ipv6 = 0;
}
vnet = user->has_net ? g_strdup(user->net) :
user->has_ip ? g_strdup_printf("%s/24", user->ip) :
vnet = user->net ? g_strdup(user->net) :
user->ip ? g_strdup_printf("%s/24", user->ip) :
NULL;
dnssearch = slirp_dnssearch(user->dnssearch);

View file

@ -705,19 +705,19 @@ int net_init_socket(const Netdev *netdev, const char *name,
assert(netdev->type == NET_CLIENT_DRIVER_SOCKET);
sock = &netdev->u.socket;
if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast +
sock->has_udp != 1) {
if (!!sock->fd + !!sock->listen + !!sock->connect + !!sock->mcast +
!!sock->udp != 1) {
error_setg(errp, "exactly one of listen=, connect=, mcast= or udp="
" is required");
return -1;
}
if (sock->has_localaddr && !sock->has_mcast && !sock->has_udp) {
if (sock->localaddr && !sock->mcast && !sock->udp) {
error_setg(errp, "localaddr= is only valid with mcast= or udp=");
return -1;
}
if (sock->has_fd) {
if (sock->fd) {
int fd, ret;
fd = monitor_fd_param(monitor_cur(), sock->fd, errp);
@ -737,7 +737,7 @@ int net_init_socket(const Netdev *netdev, const char *name,
return 0;
}
if (sock->has_listen) {
if (sock->listen) {
if (net_socket_listen_init(peer, "socket", name, sock->listen, errp)
< 0) {
return -1;
@ -745,7 +745,7 @@ int net_init_socket(const Netdev *netdev, const char *name,
return 0;
}
if (sock->has_connect) {
if (sock->connect) {
if (net_socket_connect_init(peer, "socket", name, sock->connect, errp)
< 0) {
return -1;
@ -753,7 +753,7 @@ int net_init_socket(const Netdev *netdev, const char *name,
return 0;
}
if (sock->has_mcast) {
if (sock->mcast) {
/* if sock->localaddr is missing, it has been initialized to "all bits
* zero" */
if (net_socket_mcast_init(peer, "socket", name, sock->mcast,
@ -763,8 +763,8 @@ int net_init_socket(const Netdev *netdev, const char *name,
return 0;
}
assert(sock->has_udp);
if (!sock->has_localaddr) {
assert(sock->udp);
if (!sock->localaddr) {
error_setg(errp, "localaddr= is mandatory with udp=");
return -1;
}

View file

@ -807,7 +807,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
assert(netdev->type == NET_CLIENT_DRIVER_TAP);
tap = &netdev->u.tap;
if (!tap->has_ifname) {
if (!tap->ifname) {
error_report("tap: no interface name");
return -1;
}

View file

@ -611,8 +611,8 @@ int net_init_bridge(const Netdev *netdev, const char *name,
assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE);
bridge = &netdev->u.bridge;
helper = bridge->has_helper ? bridge->helper : NULL;
br = bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTERFACE;
helper = bridge->helper;
br = bridge->br ?: DEFAULT_BRIDGE_INTERFACE;
fd = net_bridge_run_helper(helper, br, errp);
if (fd == -1) {
@ -688,9 +688,9 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
goto failed;
}
if (tap->has_fd || tap->has_fds) {
if (tap->fd || tap->fds) {
qemu_set_info_str(&s->nc, "fd=%d", fd);
} else if (tap->has_helper) {
} else if (tap->helper) {
qemu_set_info_str(&s->nc, "helper=%s", tap->helper);
} else {
qemu_set_info_str(&s->nc, "ifname=%s,script=%s,downscript=%s", ifname,
@ -812,21 +812,21 @@ int net_init_tap(const Netdev *netdev, const char *name,
assert(netdev->type == NET_CLIENT_DRIVER_TAP);
tap = &netdev->u.tap;
queues = tap->has_queues ? tap->queues : 1;
vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
script = tap->has_script ? tap->script : NULL;
downscript = tap->has_downscript ? tap->downscript : NULL;
vhostfdname = tap->vhostfd;
script = tap->script;
downscript = tap->downscript;
/* QEMU hubs do not support multiqueue tap, in this case peer is set.
* For -netdev, peer is always NULL. */
if (peer && (tap->has_queues || tap->has_fds || tap->has_vhostfds)) {
if (peer && (tap->has_queues || tap->fds || tap->vhostfds)) {
error_setg(errp, "Multiqueue tap cannot be used with hubs");
return -1;
}
if (tap->has_fd) {
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
tap->has_fds || tap->has_vhostfds) {
if (tap->fd) {
if (tap->ifname || tap->script || tap->downscript ||
tap->has_vnet_hdr || tap->helper || tap->has_queues ||
tap->fds || tap->vhostfds) {
error_setg(errp, "ifname=, script=, downscript=, vnet_hdr=, "
"helper=, queues=, fds=, and vhostfds= "
"are invalid with fd=");
@ -859,14 +859,14 @@ int net_init_tap(const Netdev *netdev, const char *name,
close(fd);
return -1;
}
} else if (tap->has_fds) {
} else if (tap->fds) {
char **fds;
char **vhost_fds;
int nfds = 0, nvhosts = 0;
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
tap->has_vhostfd) {
if (tap->ifname || tap->script || tap->downscript ||
tap->has_vnet_hdr || tap->helper || tap->has_queues ||
tap->vhostfd) {
error_setg(errp, "ifname=, script=, downscript=, vnet_hdr=, "
"helper=, queues=, and vhostfd= "
"are invalid with fds=");
@ -877,7 +877,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
vhost_fds = g_new0(char *, MAX_TAP_QUEUES);
nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
if (tap->has_vhostfds) {
if (tap->vhostfds) {
nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
if (nfds != nvhosts) {
error_setg(errp, "The number of fds passed does not match "
@ -916,7 +916,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
net_init_tap_one(tap, peer, "tap", name, ifname,
script, downscript,
tap->has_vhostfds ? vhost_fds[i] : NULL,
tap->vhostfds ? vhost_fds[i] : NULL,
vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
@ -935,17 +935,16 @@ free_fail:
g_free(fds);
g_free(vhost_fds);
return ret;
} else if (tap->has_helper) {
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) {
} else if (tap->helper) {
if (tap->ifname || tap->script || tap->downscript ||
tap->has_vnet_hdr || tap->has_queues || tap->vhostfds) {
error_setg(errp, "ifname=, script=, downscript=, vnet_hdr=, "
"queues=, and vhostfds= are invalid with helper=");
return -1;
}
fd = net_bridge_run_helper(tap->helper,
tap->has_br ?
tap->br : DEFAULT_BRIDGE_INTERFACE,
tap->br ?: DEFAULT_BRIDGE_INTERFACE,
errp);
if (fd == -1) {
return -1;
@ -972,7 +971,7 @@ free_fail:
} else {
g_autofree char *default_script = NULL;
g_autofree char *default_downscript = NULL;
if (tap->has_vhostfds) {
if (tap->vhostfds) {
error_setg(errp, "vhostfds= is invalid if fds= wasn't specified");
return -1;
}
@ -985,7 +984,7 @@ free_fail:
get_relocated_path(DEFAULT_NETWORK_DOWN_SCRIPT);
}
if (tap->has_ifname) {
if (tap->ifname) {
pstrcpy(ifname, sizeof ifname, tap->ifname);
} else {
ifname[0] = '\0';
@ -998,7 +997,7 @@ free_fail:
return -1;
}
if (queues > 1 && i == 0 && !tap->has_ifname) {
if (queues > 1 && i == 0 && !tap->ifname) {
if (tap_fd_get_ifname(fd, ifname)) {
error_setg(errp, "Fail to get ifname");
close(fd);

View file

@ -635,19 +635,19 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
opts = &netdev->u.vhost_vdpa;
if (!opts->has_vhostdev && !opts->has_vhostfd) {
if (!opts->vhostdev && !opts->vhostfd) {
error_setg(errp,
"vhost-vdpa: neither vhostdev= nor vhostfd= was specified");
return -1;
}
if (opts->has_vhostdev && opts->has_vhostfd) {
if (opts->vhostdev && opts->vhostfd) {
error_setg(errp,
"vhost-vdpa: vhostdev= and vhostfd= are mutually exclusive");
return -1;
}
if (opts->has_vhostdev) {
if (opts->vhostdev) {
vdpa_device_fd = qemu_open(opts->vhostdev, O_RDWR, errp);
if (vdpa_device_fd == -1) {
return -errno;

View file

@ -26,7 +26,7 @@ static bool validate_options(const Netdev *netdev, Error **errp)
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
QemuUUID net_uuid;
if (options->has_net_uuid &&
if (options->net_uuid &&
qemu_uuid_parse(options->net_uuid, &net_uuid) < 0) {
error_setg(errp, "Invalid UUID provided in 'net-uuid'");
return false;
@ -39,7 +39,7 @@ static bool validate_options(const Netdev *netdev, Error **errp)
return false;
}
if (options->has_net_uuid) {
if (options->net_uuid) {
error_setg(errp,
"vmnet-host.net-uuid feature is "
"unavailable: outdated vmnet.framework API");
@ -47,12 +47,12 @@ static bool validate_options(const Netdev *netdev, Error **errp)
}
#endif
if ((options->has_start_address ||
options->has_end_address ||
options->has_subnet_mask) &&
!(options->has_start_address &&
options->has_end_address &&
options->has_subnet_mask)) {
if ((options->start_address ||
options->end_address ||
options->subnet_mask) &&
!(options->start_address &&
options->end_address &&
options->subnet_mask)) {
error_setg(errp,
"'start-address', 'end-address', 'subnet-mask' "
"should be provided together");
@ -79,7 +79,7 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
options->isolated);
QemuUUID net_uuid;
if (options->has_net_uuid) {
if (options->net_uuid) {
qemu_uuid_parse(options->net_uuid, &net_uuid);
xpc_dictionary_set_uuid(if_desc,
vmnet_network_identifier_key,
@ -87,7 +87,7 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
}
#endif
if (options->has_start_address) {
if (options->start_address) {
xpc_dictionary_set_string(if_desc,
vmnet_start_address_key,
options->start_address);

View file

@ -31,12 +31,12 @@ static bool validate_options(const Netdev *netdev, Error **errp)
}
#endif
if ((options->has_start_address ||
options->has_end_address ||
options->has_subnet_mask) &&
!(options->has_start_address &&
options->has_end_address &&
options->has_subnet_mask)) {
if ((options->start_address ||
options->end_address ||
options->subnet_mask) &&
!(options->start_address &&
options->end_address &&
options->subnet_mask)) {
error_setg(errp,
"'start-address', 'end-address', 'subnet-mask' "
"should be provided together"
@ -58,13 +58,13 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
VMNET_SHARED_MODE
);
if (options->has_nat66_prefix) {
if (options->nat66_prefix) {
xpc_dictionary_set_string(if_desc,
vmnet_nat66_prefix_key,
options->nat66_prefix);
}
if (options->has_start_address) {
if (options->start_address) {
xpc_dictionary_set_string(if_desc,
vmnet_start_address_key,
options->start_address);

View file

@ -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/net.json',
'qapi/pci.json',
'qapi/qdev.json',
'qapi/qom.json',