Skip to content

Commit 71830d8

Browse files
huthjasowang
authored andcommitted
net: Drop the NetLegacy structure, always use Netdev instead
Now that the "name" parameter is gone, there is hardly any difference between NetLegacy and Netdev anymore, so we can drop NetLegacy and always use Netdev to simplify the code quite a bit. The only two differences that were really left between Netdev and NetLegacy: 1) NetLegacy does not allow a "hubport" type. We can continue to block this with a simple check in net_client_init1() for this type. 2) The "id" parameter was optional in NetLegacy (and an internal id was chosen via assign_name() during initialization), but it is mandatory for Netdev. To avoid that the visitor code bails out here, we have to add an internal id to the QemuOpts already earlier now. Signed-off-by: Thomas Huth <[email protected]> Reviewed-by: Eric Blake <[email protected]> Signed-off-by: Jason Wang <[email protected]>
1 parent 9d903f3 commit 71830d8

File tree

2 files changed

+13
-110
lines changed

2 files changed

+13
-110
lines changed

net/net.c

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -965,72 +965,23 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
965965
};
966966

967967

968-
static int net_client_init1(const void *object, bool is_netdev, Error **errp)
968+
static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
969969
{
970-
Netdev legacy = {0};
971-
const Netdev *netdev;
972970
NetClientState *peer = NULL;
973971

974972
if (is_netdev) {
975-
netdev = object;
976-
977973
if (netdev->type == NET_CLIENT_DRIVER_NIC ||
978974
!net_client_init_fun[netdev->type]) {
979975
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
980976
"a netdev backend type");
981977
return -1;
982978
}
983979
} else {
984-
const NetLegacy *net = object;
985-
const NetLegacyOptions *opts = net->opts;
986-
legacy.id = net->id;
987-
netdev = &legacy;
988-
989-
/* Map the old options to the new flat type */
990-
switch (opts->type) {
991-
case NET_LEGACY_OPTIONS_TYPE_NONE:
980+
if (netdev->type == NET_CLIENT_DRIVER_NONE) {
992981
return 0; /* nothing to do */
993-
case NET_LEGACY_OPTIONS_TYPE_NIC:
994-
legacy.type = NET_CLIENT_DRIVER_NIC;
995-
legacy.u.nic = opts->u.nic;
996-
break;
997-
case NET_LEGACY_OPTIONS_TYPE_USER:
998-
legacy.type = NET_CLIENT_DRIVER_USER;
999-
legacy.u.user = opts->u.user;
1000-
break;
1001-
case NET_LEGACY_OPTIONS_TYPE_TAP:
1002-
legacy.type = NET_CLIENT_DRIVER_TAP;
1003-
legacy.u.tap = opts->u.tap;
1004-
break;
1005-
case NET_LEGACY_OPTIONS_TYPE_L2TPV3:
1006-
legacy.type = NET_CLIENT_DRIVER_L2TPV3;
1007-
legacy.u.l2tpv3 = opts->u.l2tpv3;
1008-
break;
1009-
case NET_LEGACY_OPTIONS_TYPE_SOCKET:
1010-
legacy.type = NET_CLIENT_DRIVER_SOCKET;
1011-
legacy.u.socket = opts->u.socket;
1012-
break;
1013-
case NET_LEGACY_OPTIONS_TYPE_VDE:
1014-
legacy.type = NET_CLIENT_DRIVER_VDE;
1015-
legacy.u.vde = opts->u.vde;
1016-
break;
1017-
case NET_LEGACY_OPTIONS_TYPE_BRIDGE:
1018-
legacy.type = NET_CLIENT_DRIVER_BRIDGE;
1019-
legacy.u.bridge = opts->u.bridge;
1020-
break;
1021-
case NET_LEGACY_OPTIONS_TYPE_NETMAP:
1022-
legacy.type = NET_CLIENT_DRIVER_NETMAP;
1023-
legacy.u.netmap = opts->u.netmap;
1024-
break;
1025-
case NET_LEGACY_OPTIONS_TYPE_VHOST_USER:
1026-
legacy.type = NET_CLIENT_DRIVER_VHOST_USER;
1027-
legacy.u.vhost_user = opts->u.vhost_user;
1028-
break;
1029-
default:
1030-
abort();
1031982
}
1032-
1033-
if (!net_client_init_fun[netdev->type]) {
983+
if (netdev->type == NET_CLIENT_DRIVER_HUBPORT ||
984+
!net_client_init_fun[netdev->type]) {
1034985
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
1035986
"a net backend type (maybe it is not compiled "
1036987
"into this binary)");
@@ -1039,7 +990,7 @@ static int net_client_init1(const void *object, bool is_netdev, Error **errp)
1039990

1040991
/* Do not add to a hub if it's a nic with a netdev= parameter. */
1041992
if (netdev->type != NET_CLIENT_DRIVER_NIC ||
1042-
!opts->u.nic.has_netdev) {
993+
!netdev->u.nic.has_netdev) {
1043994
peer = net_hub_add_port(0, NULL, NULL);
1044995
}
1045996
}
@@ -1100,7 +1051,7 @@ static void show_netdevs(void)
11001051
static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
11011052
{
11021053
gchar **substrings = NULL;
1103-
void *object = NULL;
1054+
Netdev *object = NULL;
11041055
Error *err = NULL;
11051056
int ret = -1;
11061057
Visitor *v = opts_visitor_new(opts);
@@ -1143,21 +1094,19 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
11431094
}
11441095
}
11451096

1146-
if (is_netdev) {
1147-
visit_type_Netdev(v, NULL, (Netdev **)&object, &err);
1148-
} else {
1149-
visit_type_NetLegacy(v, NULL, (NetLegacy **)&object, &err);
1097+
/* Create an ID for -net if the user did not specify one */
1098+
if (!is_netdev && !qemu_opts_id(opts)) {
1099+
static int idx;
1100+
qemu_opts_set_id(opts, g_strdup_printf("__org.qemu.net%i", idx++));
11501101
}
11511102

1103+
visit_type_Netdev(v, NULL, &object, &err);
1104+
11521105
if (!err) {
11531106
ret = net_client_init1(object, is_netdev, &err);
11541107
}
11551108

1156-
if (is_netdev) {
1157-
qapi_free_Netdev(object);
1158-
} else {
1159-
qapi_free_NetLegacy(object);
1160-
}
1109+
qapi_free_Netdev(object);
11611110

11621111
out:
11631112
error_propagate(errp, err);

qapi/net.json

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -467,52 +467,6 @@
467467
'netmap': 'NetdevNetmapOptions',
468468
'vhost-user': 'NetdevVhostUserOptions' } }
469469

470-
##
471-
# @NetLegacy:
472-
#
473-
# Captures the configuration of a network device; legacy.
474-
#
475-
# @id: identifier for monitor commands
476-
#
477-
# @opts: device type specific properties (legacy)
478-
#
479-
# Since: 1.2
480-
##
481-
{ 'struct': 'NetLegacy',
482-
'data': {
483-
'*id': 'str',
484-
'opts': 'NetLegacyOptions' } }
485-
486-
##
487-
# @NetLegacyOptionsType:
488-
#
489-
# Since: 1.2
490-
##
491-
{ 'enum': 'NetLegacyOptionsType',
492-
'data': ['none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde',
493-
'bridge', 'netmap', 'vhost-user'] }
494-
495-
##
496-
# @NetLegacyOptions:
497-
#
498-
# Like Netdev, but for use only by the legacy command line options
499-
#
500-
# Since: 1.2
501-
##
502-
{ 'union': 'NetLegacyOptions',
503-
'base': { 'type': 'NetLegacyOptionsType' },
504-
'discriminator': 'type',
505-
'data': {
506-
'nic': 'NetLegacyNicOptions',
507-
'user': 'NetdevUserOptions',
508-
'tap': 'NetdevTapOptions',
509-
'l2tpv3': 'NetdevL2TPv3Options',
510-
'socket': 'NetdevSocketOptions',
511-
'vde': 'NetdevVdeOptions',
512-
'bridge': 'NetdevBridgeOptions',
513-
'netmap': 'NetdevNetmapOptions',
514-
'vhost-user': 'NetdevVhostUserOptions' } }
515-
516470
##
517471
# @NetFilterDirection:
518472
#

0 commit comments

Comments
 (0)