Skip to content

Commit

Permalink
qapi: Change Netdev into a flat union
Browse files Browse the repository at this point in the history
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union.  The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.

While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place.  Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two.  Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.

Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
  • Loading branch information
ebblake authored and Markus Armbruster committed Jul 19, 2016
1 parent faecd40 commit f394b2e
Show file tree
Hide file tree
Showing 48 changed files with 230 additions and 172 deletions.
2 changes: 1 addition & 1 deletion hw/arm/musicpal.c
Expand Up @@ -378,7 +378,7 @@ static void eth_cleanup(NetClientState *nc)
}

static NetClientInfo net_mv88w8618_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = eth_receive,
.cleanup = eth_cleanup,
Expand Down
2 changes: 1 addition & 1 deletion hw/core/qdev-properties-system.c
Expand Up @@ -247,7 +247,7 @@ static void set_netdev(Object *obj, Visitor *v, const char *name,
}

queues = qemu_find_net_clients_except(str, peers,
NET_CLIENT_OPTIONS_KIND_NIC,
NET_CLIENT_DRIVER_NIC,
MAX_QUEUE_NUM);
if (queues == 0) {
err = -ENOENT;
Expand Down
2 changes: 1 addition & 1 deletion hw/net/allwinner_emac.c
Expand Up @@ -424,7 +424,7 @@ static const MemoryRegionOps aw_emac_mem_ops = {
};

static NetClientInfo net_aw_emac_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = aw_emac_can_receive,
.receive = aw_emac_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/cadence_gem.c
Expand Up @@ -1207,7 +1207,7 @@ static void gem_set_link(NetClientState *nc)
}

static NetClientInfo net_gem_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = gem_can_receive,
.receive = gem_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/dp8393x.c
Expand Up @@ -812,7 +812,7 @@ static void dp8393x_reset(DeviceState *dev)
}

static NetClientInfo net_dp83932_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = dp8393x_can_receive,
.receive = dp8393x_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/e1000.c
Expand Up @@ -1563,7 +1563,7 @@ pci_e1000_uninit(PCIDevice *dev)
}

static NetClientInfo net_e1000_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = e1000_can_receive,
.receive = e1000_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/e1000e.c
Expand Up @@ -225,7 +225,7 @@ e1000e_set_link_status(NetClientState *nc)
}

static NetClientInfo net_e1000e_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = e1000e_nc_can_receive,
.receive = e1000e_nc_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/eepro100.c
Expand Up @@ -1848,7 +1848,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev)
}

static NetClientInfo net_eepro100_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = nic_receive,
};
Expand Down
2 changes: 1 addition & 1 deletion hw/net/etraxfs_eth.c
Expand Up @@ -578,7 +578,7 @@ static const MemoryRegionOps eth_ops = {
};

static NetClientInfo net_etraxfs_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = eth_receive,
.link_status_changed = eth_set_link,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/fsl_etsec/etsec.c
Expand Up @@ -371,7 +371,7 @@ static void etsec_set_link_status(NetClientState *nc)
}

static NetClientInfo net_etsec_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = etsec_receive,
.link_status_changed = etsec_set_link_status,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/imx_fec.c
Expand Up @@ -1147,7 +1147,7 @@ static void imx_eth_cleanup(NetClientState *nc)
}

static NetClientInfo imx_eth_net_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = imx_eth_can_receive,
.receive = imx_eth_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/lan9118.c
Expand Up @@ -1313,7 +1313,7 @@ static const MemoryRegionOps lan9118_16bit_mem_ops = {
};

static NetClientInfo net_lan9118_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = lan9118_receive,
.link_status_changed = lan9118_set_link,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/lance.c
Expand Up @@ -93,7 +93,7 @@ static const MemoryRegionOps lance_mem_ops = {
};

static NetClientInfo net_lance_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = pcnet_receive,
.link_status_changed = pcnet_set_link_status,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/mcf_fec.c
Expand Up @@ -507,7 +507,7 @@ static const MemoryRegionOps mcf_fec_ops = {
};

static NetClientInfo net_mcf_fec_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = mcf_fec_receive,
};
Expand Down
2 changes: 1 addition & 1 deletion hw/net/milkymist-minimac2.c
Expand Up @@ -447,7 +447,7 @@ static void milkymist_minimac2_reset(DeviceState *d)
}

static NetClientInfo net_milkymist_minimac2_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = minimac2_rx,
};
Expand Down
2 changes: 1 addition & 1 deletion hw/net/mipsnet.c
Expand Up @@ -224,7 +224,7 @@ static const VMStateDescription vmstate_mipsnet = {
};

static NetClientInfo net_mipsnet_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = mipsnet_receive,
};
Expand Down
2 changes: 1 addition & 1 deletion hw/net/ne2000-isa.c
Expand Up @@ -44,7 +44,7 @@ typedef struct ISANE2000State {
} ISANE2000State;

static NetClientInfo net_ne2000_isa_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = ne2000_receive,
};
Expand Down
2 changes: 1 addition & 1 deletion hw/net/ne2000.c
Expand Up @@ -712,7 +712,7 @@ void ne2000_setup_io(NE2000State *s, DeviceState *dev, unsigned size)
}

static NetClientInfo net_ne2000_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = ne2000_receive,
};
Expand Down
2 changes: 1 addition & 1 deletion hw/net/opencores_eth.c
Expand Up @@ -473,7 +473,7 @@ static ssize_t open_eth_receive(NetClientState *nc,
}

static NetClientInfo net_open_eth_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = open_eth_can_receive,
.receive = open_eth_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/pcnet-pci.c
Expand Up @@ -272,7 +272,7 @@ static void pci_pcnet_uninit(PCIDevice *dev)
}

static NetClientInfo net_pci_pcnet_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = pcnet_receive,
.link_status_changed = pcnet_set_link_status,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/rocker/rocker_fp.c
Expand Up @@ -167,7 +167,7 @@ static void fp_port_set_link_status(NetClientState *nc)
}

static NetClientInfo fp_port_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = fp_port_receive,
.receive_iov = fp_port_receive_iov,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/rtl8139.c
Expand Up @@ -3393,7 +3393,7 @@ static void rtl8139_set_link_status(NetClientState *nc)
}

static NetClientInfo net_rtl8139_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = rtl8139_can_receive,
.receive = rtl8139_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/smc91c111.c
Expand Up @@ -755,7 +755,7 @@ static const MemoryRegionOps smc91c111_mem_ops = {
};

static NetClientInfo net_smc91c111_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = smc91c111_can_receive_nc,
.receive = smc91c111_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/spapr_llan.c
Expand Up @@ -278,7 +278,7 @@ static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf,
}

static NetClientInfo net_spapr_vlan_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = spapr_vlan_can_receive,
.receive = spapr_vlan_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/stellaris_enet.c
Expand Up @@ -460,7 +460,7 @@ static void stellaris_enet_reset(stellaris_enet_state *s)
}

static NetClientInfo net_stellaris_enet_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = stellaris_enet_receive,
};
Expand Down
20 changes: 10 additions & 10 deletions hw/net/vhost_net.c
Expand Up @@ -88,10 +88,10 @@ static const int *vhost_net_get_feature_bits(struct vhost_net *net)
const int *feature_bits = 0;

switch (net->nc->info->type) {
case NET_CLIENT_OPTIONS_KIND_TAP:
case NET_CLIENT_DRIVER_TAP:
feature_bits = kernel_feature_bits;
break;
case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
case NET_CLIENT_DRIVER_VHOST_USER:
feature_bits = user_feature_bits;
break;
default:
Expand Down Expand Up @@ -128,7 +128,7 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net)
static int vhost_net_get_fd(NetClientState *backend)
{
switch (backend->info->type) {
case NET_CLIENT_OPTIONS_KIND_TAP:
case NET_CLIENT_DRIVER_TAP:
return tap_get_fd(backend);
default:
fprintf(stderr, "vhost-net requires tap backend\n");
Expand Down Expand Up @@ -191,7 +191,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
}

/* Set sane init value. Override when guest acks. */
if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
features = vhost_user_get_acked_features(net->nc);
if (~net->dev.features & features) {
fprintf(stderr, "vhost lacks feature mask %" PRIu64
Expand Down Expand Up @@ -238,7 +238,7 @@ static int vhost_net_start_one(struct vhost_net *net,
net->nc->info->poll(net->nc, false);
}

if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {
if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
qemu_set_fd_handler(net->backend, NULL, NULL, NULL);
file.fd = net->backend;
for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
Expand All @@ -253,7 +253,7 @@ static int vhost_net_start_one(struct vhost_net *net,
return 0;
fail:
file.fd = -1;
if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {
if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
while (file.index-- > 0) {
const VhostOps *vhost_ops = net->dev.vhost_ops;
int r = vhost_ops->vhost_net_set_backend(&net->dev, &file);
Expand All @@ -275,7 +275,7 @@ static void vhost_net_stop_one(struct vhost_net *net,
{
struct vhost_vring_file file = { .fd = -1 };

if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {
if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
const VhostOps *vhost_ops = net->dev.vhost_ops;
int r = vhost_ops->vhost_net_set_backend(&net->dev, &file);
Expand Down Expand Up @@ -312,7 +312,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
* because vhost user doesn't interrupt masking/unmasking
* properly.
*/
if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
dev->use_guest_notifier_mask = false;
}
}
Expand Down Expand Up @@ -413,10 +413,10 @@ VHostNetState *get_vhost_net(NetClientState *nc)
}

switch (nc->info->type) {
case NET_CLIENT_OPTIONS_KIND_TAP:
case NET_CLIENT_DRIVER_TAP:
vhost_net = tap_get_vhost_net(nc);
break;
case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
case NET_CLIENT_DRIVER_VHOST_USER:
vhost_net = vhost_user_get_vhost_net(nc);
break;
default:
Expand Down
10 changes: 5 additions & 5 deletions hw/net/virtio-net.c
Expand Up @@ -468,11 +468,11 @@ static int peer_attach(VirtIONet *n, int index)
return 0;
}

if (nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
vhost_set_vring_enable(nc->peer, 1);
}

if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
if (nc->peer->info->type != NET_CLIENT_DRIVER_TAP) {
return 0;
}

Expand All @@ -487,11 +487,11 @@ static int peer_detach(VirtIONet *n, int index)
return 0;
}

if (nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
vhost_set_vring_enable(nc->peer, 0);
}

if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
if (nc->peer->info->type != NET_CLIENT_DRIVER_TAP) {
return 0;
}

Expand Down Expand Up @@ -1680,7 +1680,7 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
}

static NetClientInfo net_virtio_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = virtio_net_can_receive,
.receive = virtio_net_receive,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/vmxnet3.c
Expand Up @@ -2087,7 +2087,7 @@ static void vmxnet3_set_link_status(NetClientState *nc)
}

static NetClientInfo net_vmxnet3_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = vmxnet3_receive,
.link_status_changed = vmxnet3_set_link_status,
Expand Down
2 changes: 1 addition & 1 deletion hw/net/xen_nic.c
Expand Up @@ -269,7 +269,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size
/* ------------------------------------------------------------- */

static NetClientInfo net_xen_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = net_rx_packet,
};
Expand Down
2 changes: 1 addition & 1 deletion hw/net/xgmac.c
Expand Up @@ -371,7 +371,7 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size)
}

static NetClientInfo net_xgmac_enet_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = eth_rx,
};
Expand Down
2 changes: 1 addition & 1 deletion hw/net/xilinx_axienet.c
Expand Up @@ -935,7 +935,7 @@ xilinx_axienet_data_stream_push(StreamSlave *obj, uint8_t *buf, size_t size)
}

static NetClientInfo net_xilinx_enet_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = eth_rx,
};
Expand Down
2 changes: 1 addition & 1 deletion hw/net/xilinx_ethlite.c
Expand Up @@ -217,7 +217,7 @@ static void xilinx_ethlite_reset(DeviceState *dev)
}

static NetClientInfo net_xilinx_ethlite_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.can_receive = eth_can_rx,
.receive = eth_rx,
Expand Down
2 changes: 1 addition & 1 deletion hw/usb/dev-network.c
Expand Up @@ -1334,7 +1334,7 @@ static void usb_net_handle_destroy(USBDevice *dev)
}

static NetClientInfo net_usbnet_info = {
.type = NET_CLIENT_OPTIONS_KIND_NIC,
.type = NET_CLIENT_DRIVER_NIC,
.size = sizeof(NICState),
.receive = usbnet_receive,
.cleanup = usbnet_cleanup,
Expand Down

0 comments on commit f394b2e

Please sign in to comment.