qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging

# gpg: Signature made Mon 05 Mar 2018 03:06:59 GMT
# gpg: using RSA key EF04965B398D6211
# gpg: Good signature from "Jason Wang (Jason Wang on RedHat) <jasowang@redhat.com>"
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg: It is not certain that the signature belongs to the owner.
# Primary key fingerprint: 215D 46F4 8246 689E C77F 3562 EF04 965B 398D 6211

* remotes/jasowang/tags/net-pull-request:
tap: setting error appropriately when calling net_init_tap_one()
hw/net: Remove unnecessary header includes
net: Add a new convenience option "--nic" to configure default/on-board NICs
net: Remove the deprecated 'host_net_add' and 'host_net_remove' HMP commands
net: Remove the deprecated way of dumping network packets
net: Make net_client_init() static
net: Only show vhost-user in the help text if CONFIG_POSIX is defined
net: List available netdevs with "-netdev help"
net: Move error reporting from net_init_client/netdev to the calling site

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

+190 -391
-30
hmp-commands.hx
··· 1291 1291 ETEXI 1292 1292 1293 1293 { 1294 - .name = "host_net_add", 1295 - .args_type = "device:s,opts:s?", 1296 - .params = "tap|user|socket|vde|netmap|bridge|vhost-user|dump [options]", 1297 - .help = "add host VLAN client (deprecated, use netdev_add instead)", 1298 - .cmd = hmp_host_net_add, 1299 - .command_completion = host_net_add_completion, 1300 - }, 1301 - 1302 - STEXI 1303 - @item host_net_add 1304 - @findex host_net_add 1305 - Add host VLAN client. Deprecated, please use @code{netdev_add} instead. 1306 - ETEXI 1307 - 1308 - { 1309 - .name = "host_net_remove", 1310 - .args_type = "vlan_id:i,device:s", 1311 - .params = "vlan_id name", 1312 - .help = "remove host VLAN client (deprecated, use netdev_del instead)", 1313 - .cmd = hmp_host_net_remove, 1314 - .command_completion = host_net_remove_completion, 1315 - }, 1316 - 1317 - STEXI 1318 - @item host_net_remove 1319 - @findex host_net_remove 1320 - Remove host VLAN client. Deprecated, please use @code{netdev_del} instead. 1321 - ETEXI 1322 - 1323 - { 1324 1294 .name = "netdev_add", 1325 1295 .args_type = "netdev:O", 1326 1296 .params = "[user|tap|socket|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]",
-3
hmp.h
··· 132 132 const char *str); 133 133 void migrate_set_parameter_completion(ReadLineState *rs, int nb_args, 134 134 const char *str); 135 - void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str); 136 - void host_net_remove_completion(ReadLineState *rs, int nb_args, 137 - const char *str); 138 135 void delvm_completion(ReadLineState *rs, int nb_args, const char *str); 139 136 void loadvm_completion(ReadLineState *rs, int nb_args, const char *str); 140 137 void hmp_rocker(Monitor *mon, const QDict *qdict);
-1
hw/net/e1000.c
··· 30 30 #include "hw/pci/pci.h" 31 31 #include "net/net.h" 32 32 #include "net/checksum.h" 33 - #include "hw/loader.h" 34 33 #include "sysemu/sysemu.h" 35 34 #include "sysemu/dma.h" 36 35 #include "qemu/iov.h"
-3
hw/net/lance.c
··· 36 36 */ 37 37 38 38 #include "qemu/osdep.h" 39 - #include "hw/sysbus.h" 40 - #include "net/net.h" 41 39 #include "qemu/timer.h" 42 - #include "qemu/sockets.h" 43 40 #include "hw/sparc/sparc32_dma.h" 44 41 #include "hw/net/lance.h" 45 42 #include "trace.h"
-2
hw/net/ne2000.c
··· 23 23 */ 24 24 #include "qemu/osdep.h" 25 25 #include "hw/pci/pci.h" 26 - #include "net/net.h" 27 26 #include "net/eth.h" 28 27 #include "ne2000.h" 29 - #include "hw/loader.h" 30 28 #include "sysemu/sysemu.h" 31 29 32 30 /* debug NE2000 card */
-1
hw/net/pcnet-pci.c
··· 30 30 #include "qemu/osdep.h" 31 31 #include "hw/pci/pci.h" 32 32 #include "net/net.h" 33 - #include "hw/loader.h" 34 33 #include "qemu/timer.h" 35 34 #include "sysemu/dma.h" 36 35 #include "sysemu/sysemu.h"
-1
hw/net/pcnet.c
··· 40 40 #include "net/net.h" 41 41 #include "net/eth.h" 42 42 #include "qemu/timer.h" 43 - #include "qemu/sockets.h" 44 43 #include "sysemu/sysemu.h" 45 44 #include "trace.h" 46 45
-2
hw/net/rtl8139.c
··· 58 58 #include "qemu/timer.h" 59 59 #include "net/net.h" 60 60 #include "net/eth.h" 61 - #include "hw/loader.h" 62 61 #include "sysemu/sysemu.h" 63 - #include "qemu/iov.h" 64 62 65 63 /* debug RTL8139 card */ 66 64 //#define DEBUG_RTL8139 1
-1
hw/net/xgmac.c
··· 28 28 #include "hw/sysbus.h" 29 29 #include "qemu/log.h" 30 30 #include "net/net.h" 31 - #include "net/checksum.h" 32 31 33 32 #ifdef DEBUG_XGMAC 34 33 #define DEBUGF_BRK(message, args...) do { \
+1 -3
include/net/net.h
··· 204 204 extern const char *legacy_tftp_prefix; 205 205 extern const char *legacy_bootp_filename; 206 206 207 - int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp); 208 207 int net_client_parse(QemuOptsList *opts_list, const char *str); 209 - int net_init_clients(void); 208 + int net_init_clients(Error **errp); 210 209 void net_check_clients(void); 211 210 void net_cleanup(void); 212 211 void hmp_host_net_add(Monitor *mon, const QDict *qdict); ··· 228 227 #define POLYNOMIAL_LE 0xedb88320 229 228 uint32_t net_crc32(const uint8_t *p, int len); 230 229 uint32_t net_crc32_le(const uint8_t *p, int len); 231 - unsigned compute_mcast_idx(const uint8_t *ep); 232 230 233 231 #define vmstate_offset_macaddr(_state, _field) \ 234 232 vmstate_offset_array(_state, _field.a, uint8_t, \
+3
include/net/vhost_net.h
··· 4 4 #include "net/net.h" 5 5 #include "hw/virtio/vhost-backend.h" 6 6 7 + #define VHOST_NET_INIT_FAILED \ 8 + "vhost-net requested but could not be initialized" 9 + 7 10 struct vhost_net; 8 11 typedef struct vhost_net VHostNetState; 9 12
+1
include/sysemu/sysemu.h
··· 198 198 extern QemuOptsList qemu_chardev_opts; 199 199 extern QemuOptsList qemu_device_opts; 200 200 extern QemuOptsList qemu_netdev_opts; 201 + extern QemuOptsList qemu_nic_opts; 201 202 extern QemuOptsList qemu_net_opts; 202 203 extern QemuOptsList qemu_global_opts; 203 204 extern QemuOptsList qemu_mon_opts;
-61
monitor.c
··· 3581 3581 } 3582 3582 } 3583 3583 3584 - void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str) 3585 - { 3586 - int i; 3587 - size_t len; 3588 - if (nb_args != 2) { 3589 - return; 3590 - } 3591 - len = strlen(str); 3592 - readline_set_completion_index(rs, len); 3593 - for (i = 0; host_net_devices[i]; i++) { 3594 - if (!strncmp(host_net_devices[i], str, len)) { 3595 - readline_add_completion(rs, host_net_devices[i]); 3596 - } 3597 - } 3598 - } 3599 - 3600 - void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str) 3601 - { 3602 - NetClientState *ncs[MAX_QUEUE_NUM]; 3603 - int count, i, len; 3604 - 3605 - len = strlen(str); 3606 - readline_set_completion_index(rs, len); 3607 - if (nb_args == 2) { 3608 - count = qemu_find_net_clients_except(NULL, ncs, 3609 - NET_CLIENT_DRIVER_NONE, 3610 - MAX_QUEUE_NUM); 3611 - for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) { 3612 - int id; 3613 - char name[16]; 3614 - 3615 - if (net_hub_id_for_client(ncs[i], &id)) { 3616 - continue; 3617 - } 3618 - snprintf(name, sizeof(name), "%d", id); 3619 - if (!strncmp(str, name, len)) { 3620 - readline_add_completion(rs, name); 3621 - } 3622 - } 3623 - return; 3624 - } else if (nb_args == 3) { 3625 - count = qemu_find_net_clients_except(NULL, ncs, 3626 - NET_CLIENT_DRIVER_NIC, 3627 - MAX_QUEUE_NUM); 3628 - for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) { 3629 - int id; 3630 - const char *name; 3631 - 3632 - if (ncs[i]->info->type == NET_CLIENT_DRIVER_HUBPORT || 3633 - net_hub_id_for_client(ncs[i], &id)) { 3634 - continue; 3635 - } 3636 - name = ncs[i]->name; 3637 - if (!strncmp(str, name, len)) { 3638 - readline_add_completion(rs, name); 3639 - } 3640 - } 3641 - return; 3642 - } 3643 - } 3644 - 3645 3584 static void vm_completion(ReadLineState *rs, const char *str) 3646 3585 { 3647 3586 size_t len;
+2 -100
net/dump.c
··· 109 109 110 110 fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0644); 111 111 if (fd < 0) { 112 - error_setg_errno(errp, errno, "-net dump: can't open %s", filename); 112 + error_setg_errno(errp, errno, "net dump: can't open %s", filename); 113 113 return -1; 114 114 } 115 115 ··· 122 122 hdr.linktype = 1; 123 123 124 124 if (write(fd, &hdr, sizeof(hdr)) < sizeof(hdr)) { 125 - error_setg_errno(errp, errno, "-net dump write error"); 125 + error_setg_errno(errp, errno, "net dump write error"); 126 126 close(fd); 127 127 return -1; 128 128 } ··· 135 135 136 136 return 0; 137 137 } 138 - 139 - /* Dumping via VLAN netclient */ 140 - 141 - struct DumpNetClient { 142 - NetClientState nc; 143 - DumpState ds; 144 - }; 145 - typedef struct DumpNetClient DumpNetClient; 146 - 147 - static ssize_t dumpclient_receive(NetClientState *nc, const uint8_t *buf, 148 - size_t size) 149 - { 150 - DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc); 151 - struct iovec iov = { 152 - .iov_base = (void *)buf, 153 - .iov_len = size 154 - }; 155 - 156 - return dump_receive_iov(&dc->ds, &iov, 1); 157 - } 158 - 159 - static ssize_t dumpclient_receive_iov(NetClientState *nc, 160 - const struct iovec *iov, int cnt) 161 - { 162 - DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc); 163 - 164 - return dump_receive_iov(&dc->ds, iov, cnt); 165 - } 166 - 167 - static void dumpclient_cleanup(NetClientState *nc) 168 - { 169 - DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc); 170 - 171 - dump_cleanup(&dc->ds); 172 - } 173 - 174 - static NetClientInfo net_dump_info = { 175 - .type = NET_CLIENT_DRIVER_DUMP, 176 - .size = sizeof(DumpNetClient), 177 - .receive = dumpclient_receive, 178 - .receive_iov = dumpclient_receive_iov, 179 - .cleanup = dumpclient_cleanup, 180 - }; 181 - 182 - int net_init_dump(const Netdev *netdev, const char *name, 183 - NetClientState *peer, Error **errp) 184 - { 185 - int len, rc; 186 - const char *file; 187 - char def_file[128]; 188 - const NetdevDumpOptions *dump; 189 - NetClientState *nc; 190 - DumpNetClient *dnc; 191 - 192 - assert(netdev->type == NET_CLIENT_DRIVER_DUMP); 193 - dump = &netdev->u.dump; 194 - 195 - assert(peer); 196 - 197 - error_report("'-net dump' is deprecated. " 198 - "Please use '-object filter-dump' instead."); 199 - 200 - if (dump->has_file) { 201 - file = dump->file; 202 - } else { 203 - int id; 204 - int ret; 205 - 206 - ret = net_hub_id_for_client(peer, &id); 207 - assert(ret == 0); /* peer must be on a hub */ 208 - 209 - snprintf(def_file, sizeof(def_file), "qemu-vlan%d.pcap", id); 210 - file = def_file; 211 - } 212 - 213 - if (dump->has_len) { 214 - if (dump->len > INT_MAX) { 215 - error_setg(errp, "invalid length: %"PRIu64, dump->len); 216 - return -1; 217 - } 218 - len = dump->len; 219 - } else { 220 - len = 65536; 221 - } 222 - 223 - nc = qemu_new_net_client(&net_dump_info, peer, "dump", name); 224 - snprintf(nc->info_str, sizeof(nc->info_str), 225 - "dump to %s (len=%d)", file, len); 226 - 227 - dnc = DO_UPCAST(DumpNetClient, nc, nc); 228 - rc = net_dump_state_init(&dnc->ds, file, len, errp); 229 - if (rc) { 230 - qemu_del_net_client(nc); 231 - } 232 - return rc; 233 - } 234 - 235 - /* Dumping via filter */ 236 138 237 139 #define TYPE_FILTER_DUMP "filter-dump" 238 140
+116 -123
net/net.c
··· 60 60 static VMChangeStateEntry *net_change_state_entry; 61 61 static QTAILQ_HEAD(, NetClientState) net_clients; 62 62 63 - const char *host_net_devices[] = { 64 - "tap", 65 - "socket", 66 - "dump", 67 - #ifdef CONFIG_NET_BRIDGE 68 - "bridge", 69 - #endif 70 - #ifdef CONFIG_NETMAP 71 - "netmap", 72 - #endif 73 - #ifdef CONFIG_SLIRP 74 - "user", 75 - #endif 76 - #ifdef CONFIG_VDE 77 - "vde", 78 - #endif 79 - "vhost-user", 80 - NULL, 81 - }; 82 - 83 63 /***********************************************************/ 84 64 /* network device redirectors */ 85 65 ··· 967 947 #ifdef CONFIG_NETMAP 968 948 [NET_CLIENT_DRIVER_NETMAP] = net_init_netmap, 969 949 #endif 970 - [NET_CLIENT_DRIVER_DUMP] = net_init_dump, 971 950 #ifdef CONFIG_NET_BRIDGE 972 951 [NET_CLIENT_DRIVER_BRIDGE] = net_init_bridge, 973 952 #endif ··· 993 972 netdev = object; 994 973 name = netdev->id; 995 974 996 - if (netdev->type == NET_CLIENT_DRIVER_DUMP || 997 - netdev->type == NET_CLIENT_DRIVER_NIC || 975 + if (netdev->type == NET_CLIENT_DRIVER_NIC || 998 976 !net_client_init_fun[netdev->type]) { 999 977 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", 1000 978 "a netdev backend type"); ··· 1036 1014 legacy.type = NET_CLIENT_DRIVER_VDE; 1037 1015 legacy.u.vde = opts->u.vde; 1038 1016 break; 1039 - case NET_LEGACY_OPTIONS_TYPE_DUMP: 1040 - legacy.type = NET_CLIENT_DRIVER_DUMP; 1041 - legacy.u.dump = opts->u.dump; 1042 - break; 1043 1017 case NET_LEGACY_OPTIONS_TYPE_BRIDGE: 1044 1018 legacy.type = NET_CLIENT_DRIVER_BRIDGE; 1045 1019 legacy.u.bridge = opts->u.bridge; ··· 1086 1060 return 0; 1087 1061 } 1088 1062 1063 + static void show_netdevs(void) 1064 + { 1065 + int idx; 1066 + const char *available_netdevs[] = { 1067 + "socket", 1068 + "hubport", 1069 + "tap", 1070 + #ifdef CONFIG_SLIRP 1071 + "user", 1072 + #endif 1073 + #ifdef CONFIG_L2TPV3 1074 + "l2tpv3", 1075 + #endif 1076 + #ifdef CONFIG_VDE 1077 + "vde", 1078 + #endif 1079 + #ifdef CONFIG_NET_BRIDGE 1080 + "bridge", 1081 + #endif 1082 + #ifdef CONFIG_NETMAP 1083 + "netmap", 1084 + #endif 1085 + #ifdef CONFIG_POSIX 1086 + "vhost-user", 1087 + #endif 1088 + }; 1089 1089 1090 - int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) 1090 + printf("Available netdev backend types:\n"); 1091 + for (idx = 0; idx < ARRAY_SIZE(available_netdevs); idx++) { 1092 + puts(available_netdevs[idx]); 1093 + } 1094 + } 1095 + 1096 + static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) 1091 1097 { 1092 1098 void *object = NULL; 1093 1099 Error *err = NULL; 1094 1100 int ret = -1; 1095 1101 Visitor *v = opts_visitor_new(opts); 1096 1102 1097 - { 1103 + if (is_netdev && is_help_option(qemu_opt_get(opts, "type"))) { 1104 + show_netdevs(); 1105 + exit(0); 1106 + } else { 1098 1107 /* Parse convenience option format ip6-net=fec0::0[/64] */ 1099 1108 const char *ip6_net = qemu_opt_get(opts, "ipv6-net"); 1100 1109 ··· 1146 1155 return ret; 1147 1156 } 1148 1157 1149 - 1150 - static int net_host_check_device(const char *device) 1151 - { 1152 - int i; 1153 - for (i = 0; host_net_devices[i]; i++) { 1154 - if (!strncmp(host_net_devices[i], device, 1155 - strlen(host_net_devices[i]))) { 1156 - return 1; 1157 - } 1158 - } 1159 - 1160 - return 0; 1161 - } 1162 - 1163 - void hmp_host_net_add(Monitor *mon, const QDict *qdict) 1164 - { 1165 - const char *device = qdict_get_str(qdict, "device"); 1166 - const char *opts_str = qdict_get_try_str(qdict, "opts"); 1167 - Error *local_err = NULL; 1168 - QemuOpts *opts; 1169 - static bool warned; 1170 - 1171 - if (!warned && !qtest_enabled()) { 1172 - error_report("host_net_add is deprecated, use netdev_add instead"); 1173 - warned = true; 1174 - } 1175 - 1176 - if (!net_host_check_device(device)) { 1177 - monitor_printf(mon, "invalid host network device %s\n", device); 1178 - return; 1179 - } 1180 - 1181 - opts = qemu_opts_parse_noisily(qemu_find_opts("net"), 1182 - opts_str ? opts_str : "", false); 1183 - if (!opts) { 1184 - return; 1185 - } 1186 - 1187 - qemu_opt_set(opts, "type", device, &error_abort); 1188 - 1189 - net_client_init(opts, false, &local_err); 1190 - if (local_err) { 1191 - error_report_err(local_err); 1192 - monitor_printf(mon, "adding host network device %s failed\n", device); 1193 - } 1194 - } 1195 - 1196 - void hmp_host_net_remove(Monitor *mon, const QDict *qdict) 1197 - { 1198 - NetClientState *nc; 1199 - int vlan_id = qdict_get_int(qdict, "vlan_id"); 1200 - const char *device = qdict_get_str(qdict, "device"); 1201 - static bool warned; 1202 - 1203 - if (!warned && !qtest_enabled()) { 1204 - error_report("host_net_remove is deprecated, use netdev_del instead"); 1205 - warned = true; 1206 - } 1207 - 1208 - nc = net_hub_find_client_by_name(vlan_id, device); 1209 - if (!nc) { 1210 - error_report("Host network device '%s' on hub '%d' not found", 1211 - device, vlan_id); 1212 - return; 1213 - } 1214 - if (nc->info->type == NET_CLIENT_DRIVER_NIC) { 1215 - error_report("invalid host network device '%s'", device); 1216 - return; 1217 - } 1218 - 1219 - qemu_del_net_client(nc->peer); 1220 - qemu_del_net_client(nc); 1221 - qemu_opts_del(qemu_opts_find(qemu_find_opts("net"), device)); 1222 - } 1223 - 1224 1158 void netdev_add(QemuOpts *opts, Error **errp) 1225 1159 { 1226 1160 net_client_init(opts, true, errp); ··· 1520 1454 1521 1455 static int net_init_client(void *dummy, QemuOpts *opts, Error **errp) 1522 1456 { 1523 - Error *local_err = NULL; 1457 + return net_client_init(opts, false, errp); 1458 + } 1459 + 1460 + static int net_init_netdev(void *dummy, QemuOpts *opts, Error **errp) 1461 + { 1462 + return net_client_init(opts, true, errp); 1463 + } 1464 + 1465 + /* For the convenience "--nic" parameter */ 1466 + static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp) 1467 + { 1468 + char *mac, *nd_id; 1469 + int idx, ret; 1470 + NICInfo *ni; 1471 + const char *type; 1524 1472 1525 - net_client_init(opts, false, &local_err); 1526 - if (local_err) { 1527 - error_report_err(local_err); 1473 + type = qemu_opt_get(opts, "type"); 1474 + if (type && g_str_equal(type, "none")) { 1475 + return 0; /* Nothing to do, default_net is cleared in vl.c */ 1476 + } 1477 + 1478 + idx = nic_get_free_idx(); 1479 + if (idx == -1 || nb_nics >= MAX_NICS) { 1480 + error_setg(errp, "no more on-board/default NIC slots available"); 1528 1481 return -1; 1529 1482 } 1530 1483 1531 - return 0; 1532 - } 1484 + if (!type) { 1485 + qemu_opt_set(opts, "type", "user", &error_abort); 1486 + } 1533 1487 1534 - static int net_init_netdev(void *dummy, QemuOpts *opts, Error **errp) 1535 - { 1536 - Error *local_err = NULL; 1537 - int ret; 1488 + ni = &nd_table[idx]; 1489 + memset(ni, 0, sizeof(*ni)); 1490 + ni->model = qemu_opt_get_del(opts, "model"); 1491 + 1492 + /* Create an ID if the user did not specify one */ 1493 + nd_id = g_strdup(qemu_opts_id(opts)); 1494 + if (!nd_id) { 1495 + nd_id = g_strdup_printf("__org.qemu.nic%i\n", idx); 1496 + qemu_opts_set_id(opts, nd_id); 1497 + } 1498 + 1499 + /* Handle MAC address */ 1500 + mac = qemu_opt_get_del(opts, "mac"); 1501 + if (mac) { 1502 + ret = net_parse_macaddr(ni->macaddr.a, mac); 1503 + g_free(mac); 1504 + if (ret) { 1505 + error_setg(errp, "invalid syntax for ethernet address"); 1506 + return -1; 1507 + } 1508 + if (is_multicast_ether_addr(ni->macaddr.a)) { 1509 + error_setg(errp, "NIC cannot have multicast MAC address"); 1510 + return -1; 1511 + } 1512 + } 1513 + qemu_macaddr_default_if_unset(&ni->macaddr); 1538 1514 1539 - ret = net_client_init(opts, true, &local_err); 1540 - if (local_err) { 1541 - error_report_err(local_err); 1542 - return -1; 1515 + ret = net_client_init(opts, true, errp); 1516 + if (ret == 0) { 1517 + ni->netdev = qemu_find_netdev(nd_id); 1518 + ni->used = true; 1519 + nb_nics++; 1543 1520 } 1544 1521 1522 + g_free(nd_id); 1545 1523 return ret; 1546 1524 } 1547 1525 1548 - int net_init_clients(void) 1526 + int net_init_clients(Error **errp) 1549 1527 { 1550 - QemuOptsList *net = qemu_find_opts("net"); 1551 - 1552 1528 net_change_state_entry = 1553 1529 qemu_add_vm_change_state_handler(net_vm_change_state_handler, NULL); 1554 1530 1555 1531 QTAILQ_INIT(&net_clients); 1556 1532 1557 1533 if (qemu_opts_foreach(qemu_find_opts("netdev"), 1558 - net_init_netdev, NULL, NULL)) { 1534 + net_init_netdev, NULL, errp)) { 1559 1535 return -1; 1560 1536 } 1561 1537 1562 - if (qemu_opts_foreach(net, net_init_client, NULL, NULL)) { 1538 + if (qemu_opts_foreach(qemu_find_opts("nic"), net_param_nic, NULL, errp)) { 1539 + return -1; 1540 + } 1541 + 1542 + if (qemu_opts_foreach(qemu_find_opts("net"), net_init_client, NULL, errp)) { 1563 1543 return -1; 1564 1544 } 1565 1545 ··· 1625 1605 .name = "netdev", 1626 1606 .implied_opt_name = "type", 1627 1607 .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head), 1608 + .desc = { 1609 + /* 1610 + * no elements => accept any params 1611 + * validation will happen later 1612 + */ 1613 + { /* end of list */ } 1614 + }, 1615 + }; 1616 + 1617 + QemuOptsList qemu_nic_opts = { 1618 + .name = "nic", 1619 + .implied_opt_name = "type", 1620 + .head = QTAILQ_HEAD_INITIALIZER(qemu_nic_opts.head), 1628 1621 .desc = { 1629 1622 /* 1630 1623 * no elements => accept any params
+17 -5
net/tap.c
··· 686 686 if (vhostfdname) { 687 687 vhostfd = monitor_fd_param(cur_mon, vhostfdname, &err); 688 688 if (vhostfd == -1) { 689 - error_propagate(errp, err); 689 + if (tap->has_vhostforce && tap->vhostforce) { 690 + error_propagate(errp, err); 691 + } else { 692 + warn_report_err(err); 693 + } 690 694 return; 691 695 } 692 696 } else { 693 697 vhostfd = open("/dev/vhost-net", O_RDWR); 694 698 if (vhostfd < 0) { 695 - error_setg_errno(errp, errno, 696 - "tap: open vhost char device failed"); 699 + if (tap->has_vhostforce && tap->vhostforce) { 700 + error_setg_errno(errp, errno, 701 + "tap: open vhost char device failed"); 702 + } else { 703 + warn_report("tap: open vhost char device failed: %s", 704 + strerror(errno)); 705 + } 697 706 return; 698 707 } 699 708 fcntl(vhostfd, F_SETFL, O_NONBLOCK); ··· 702 711 703 712 s->vhost_net = vhost_net_init(&options); 704 713 if (!s->vhost_net) { 705 - error_setg(errp, 706 - "vhost-net requested but could not be initialized"); 714 + if (tap->has_vhostforce && tap->vhostforce) { 715 + error_setg(errp, VHOST_NET_INIT_FAILED); 716 + } else { 717 + warn_report(VHOST_NET_INIT_FAILED); 718 + } 707 719 return; 708 720 } 709 721 } else if (vhostfdname) {
+6 -23
qapi/net.json
··· 39 39 # 40 40 # Add a network backend. 41 41 # 42 - # @type: the type of network backend. Current valid values are 'user', 'tap', 43 - # 'vde', 'socket', 'dump' and 'bridge' 42 + # @type: the type of network backend. Possible values are listed in 43 + # NetClientDriver (excluding 'none' and 'nic') 44 44 # 45 45 # @id: the name of the new network backend 46 46 # ··· 372 372 '*mode': 'uint16' } } 373 373 374 374 ## 375 - # @NetdevDumpOptions: 376 - # 377 - # Dump VLAN network traffic to a file. 378 - # 379 - # @len: per-packet size limit (64k default). Understands [TGMKkb] 380 - # suffixes. 381 - # 382 - # @file: dump file path (default is qemu-vlan0.pcap) 383 - # 384 - # Since: 1.2 385 - ## 386 - { 'struct': 'NetdevDumpOptions', 387 - 'data': { 388 - '*len': 'size', 389 - '*file': 'str' } } 390 - 391 - ## 392 375 # @NetdevBridgeOptions: 393 376 # 394 377 # Connect a host TAP network interface to a host bridge device. ··· 466 449 # Available netdev drivers. 467 450 # 468 451 # Since: 2.7 452 + # 453 + # 'dump' - removed with 2.12 469 454 ## 470 455 { 'enum': 'NetClientDriver', 471 - 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', 'dump', 456 + 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', 472 457 'bridge', 'hubport', 'netmap', 'vhost-user' ] } 473 458 474 459 ## ··· 495 480 'l2tpv3': 'NetdevL2TPv3Options', 496 481 'socket': 'NetdevSocketOptions', 497 482 'vde': 'NetdevVdeOptions', 498 - 'dump': 'NetdevDumpOptions', 499 483 'bridge': 'NetdevBridgeOptions', 500 484 'hubport': 'NetdevHubPortOptions', 501 485 'netmap': 'NetdevNetmapOptions', ··· 530 514 ## 531 515 { 'enum': 'NetLegacyOptionsType', 532 516 'data': ['none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', 533 - 'dump', 'bridge', 'netmap', 'vhost-user'] } 517 + 'bridge', 'netmap', 'vhost-user'] } 534 518 535 519 ## 536 520 # @NetLegacyOptions: ··· 550 534 'l2tpv3': 'NetdevL2TPv3Options', 551 535 'socket': 'NetdevSocketOptions', 552 536 'vde': 'NetdevVdeOptions', 553 - 'dump': 'NetdevDumpOptions', 554 537 'bridge': 'NetdevBridgeOptions', 555 538 'netmap': 'NetdevNetmapOptions', 556 539 'vhost-user': 'NetdevVhostUserOptions' } }
-16
qemu-doc.texi
··· 2707 2707 The drive addr argument is replaced by the the addr argument 2708 2708 that can be specified with the ``-device'' parameter. 2709 2709 2710 - @subsection -net dump (since 2.10.0) 2711 - 2712 - The ``--net dump'' argument is now replaced with the 2713 - ``-object filter-dump'' argument which works in combination 2714 - with the modern ``-netdev`` backends instead. 2715 - 2716 2710 @subsection -usbdevice (since 2.10.0) 2717 2711 2718 2712 The ``-usbdevice DEV'' argument is now a synonym for setting ··· 2765 2759 @subsection query-cpus (since 2.12.0) 2766 2760 2767 2761 The ``query-cpus'' command is replaced by the ``query-cpus-fast'' command. 2768 - 2769 - @section System emulator human monitor commands 2770 - 2771 - @subsection host_net_add (since 2.10.0) 2772 - 2773 - The ``host_net_add'' command is replaced by the ``netdev_add'' command. 2774 - 2775 - @subsection host_net_remove (since 2.10.0) 2776 - 2777 - The ``host_net_remove'' command is replaced by the ``netdev_del'' command. 2778 2762 2779 2763 @section System emulator devices 2780 2764
+35 -13
qemu-options.hx
··· 1998 1998 " VALE port (created on the fly) called 'name' ('nmname' is name of the \n" 1999 1999 " netmap device, defaults to '/dev/netmap')\n" 2000 2000 #endif 2001 + #ifdef CONFIG_POSIX 2001 2002 "-netdev vhost-user,id=str,chardev=dev[,vhostforce=on|off]\n" 2002 2003 " configure a vhost-user network, backed by a chardev 'dev'\n" 2004 + #endif 2003 2005 "-netdev hubport,id=str,hubid=n[,netdev=nd]\n" 2004 2006 " configure a hub port on QEMU VLAN 'n'\n", QEMU_ARCH_ALL) 2007 + DEF("nic", HAS_ARG, QEMU_OPTION_nic, 2008 + "--nic [tap|bridge|" 2009 + #ifdef CONFIG_SLIRP 2010 + "user|" 2011 + #endif 2012 + #ifdef __linux__ 2013 + "l2tpv3|" 2014 + #endif 2015 + #ifdef CONFIG_VDE 2016 + "vde|" 2017 + #endif 2018 + #ifdef CONFIG_NETMAP 2019 + "netmap|" 2020 + #endif 2021 + #ifdef CONFIG_POSIX 2022 + "vhost-user|" 2023 + #endif 2024 + "socket][,option][,...][mac=macaddr]\n" 2025 + " initialize an on-board / default host NIC (using MAC address\n" 2026 + " macaddr) and connect it to the given host network backend\n" 2027 + "--nic none use it alone to have zero network devices (the default is to\n" 2028 + " provided a 'user' network connection)\n", 2029 + QEMU_ARCH_ALL) 2005 2030 DEF("net", HAS_ARG, QEMU_OPTION_net, 2006 2031 "-net nic[,vlan=n][,netdev=nd][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n" 2007 2032 " configure or create an on-board (or machine default) NIC and\n" 2008 2033 " connect it either to VLAN 'n' or the netdev 'nd' (for pluggable\n" 2009 2034 " NICs please use '-device devtype,netdev=nd' instead)\n" 2010 - "-net dump[,vlan=n][,file=f][,len=n]\n" 2011 - " dump traffic on vlan 'n' to file 'f' (max n bytes per packet)\n" 2012 - "-net none use it alone to have zero network devices. If no -net option\n" 2013 - " is provided, the default is '-net nic -net user'\n" 2014 2035 "-net [" 2015 2036 #ifdef CONFIG_SLIRP 2016 2037 "user|" ··· 2456 2477 -device virtio-net-pci,netdev=net0 2457 2478 @end example 2458 2479 2459 - @item -net dump[,vlan=@var{n}][,file=@var{file}][,len=@var{len}] 2460 - Dump network traffic on VLAN @var{n} to file @var{file} (@file{qemu-vlan0.pcap} by default). 2461 - At most @var{len} bytes (64k by default) per packet are stored. The file format is 2462 - libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. 2463 - Note: For devices created with '-netdev', use '-object filter-dump,...' instead. 2480 + @item --nic [tap|bridge|user|l2tpv3|vde|netmap|vhost-user|socket][,...][,mac=macaddr] 2481 + 2482 + This option is a shortcut for setting both, the on-board (default) guest NIC 2483 + hardware and the host network backend in one go. The host backend options are 2484 + the same as with the corresponding @option{--netdev} option. The guest NIC 2485 + hardware MAC address can be set with @option{mac=@var{macaddr}}. 2464 2486 2465 - @item -net none 2466 - Indicate that no network devices should be configured. It is used to 2467 - override the default configuration (@option{-net nic -net user}) which 2468 - is activated if no @option{-net} options are provided. 2487 + @item --nic none 2488 + Indicate that no network devices should be configured. It is used to override 2489 + the default configuration (default NIC with @option{--net user} backend) which 2490 + is activated if no other networking options are provided. 2469 2491 ETEXI 2470 2492 2471 2493 STEXI
-2
tests/test-hmp.c
··· 37 37 "dump-guest-memory /dev/null 0 4096", 38 38 "dump-guest-memory /dev/null", 39 39 "gdbserver", 40 - "host_net_add user id=net0", 41 40 "hostfwd_add tcp::43210-:43210", 42 41 "hostfwd_remove tcp::43210-:43210", 43 - "host_net_remove 0 net0", 44 42 "i /w 0", 45 43 "log all", 46 44 "log none",
+9 -1
vl.c
··· 3093 3093 qemu_add_opts(&qemu_chardev_opts); 3094 3094 qemu_add_opts(&qemu_device_opts); 3095 3095 qemu_add_opts(&qemu_netdev_opts); 3096 + qemu_add_opts(&qemu_nic_opts); 3096 3097 qemu_add_opts(&qemu_net_opts); 3097 3098 qemu_add_opts(&qemu_rtc_opts); 3098 3099 qemu_add_opts(&qemu_global_opts); ··· 3310 3311 case QEMU_OPTION_netdev: 3311 3312 default_net = 0; 3312 3313 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { 3314 + exit(1); 3315 + } 3316 + break; 3317 + case QEMU_OPTION_nic: 3318 + default_net = 0; 3319 + if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) { 3313 3320 exit(1); 3314 3321 } 3315 3322 break; ··· 4491 4498 4492 4499 colo_info_init(); 4493 4500 4494 - if (net_init_clients() < 0) { 4501 + if (net_init_clients(&err) < 0) { 4502 + error_report_err(err); 4495 4503 exit(1); 4496 4504 } 4497 4505