1 | The following changes since commit 136c67e07869227b21b3f627316e03679ce7b738: | 1 | The following changes since commit 23895cbd82be95428e90168b12e925d0d3ca2f06: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/bkoppelmann/tags/pull-tricore-2018-03-02' into staging (2018-03-02 16:56:20 +0000) | 3 | Merge remote-tracking branch 'remotes/awilliam/tags/vfio-update-20201123.0' into staging (2020-11-23 18:51:13 +0000) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the git repository at: |
6 | 6 | ||
7 | https://github.com/jasowang/qemu.git tags/net-pull-request | 7 | https://github.com/jasowang/qemu.git tags/net-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 46d4d36d0bf2b24b205f2f604f0905db80264eef: | 9 | for you to fetch changes up to 9925990d01a92564af55f6f69d0f5f59b47609b1: |
10 | 10 | ||
11 | tap: setting error appropriately when calling net_init_tap_one() (2018-03-05 10:30:16 +0800) | 11 | net: Use correct default-path macro for downscript (2020-11-24 10:40:17 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | 14 | ||
15 | ---------------------------------------------------------------- | 15 | ---------------------------------------------------------------- |
16 | Jay Zhou (1): | 16 | Keqian Zhu (1): |
17 | tap: setting error appropriately when calling net_init_tap_one() | 17 | net: Use correct default-path macro for downscript |
18 | 18 | ||
19 | Thomas Huth (8): | 19 | Paolo Bonzini (1): |
20 | net: Move error reporting from net_init_client/netdev to the calling site | 20 | net: do not exit on "netdev_add help" monitor command |
21 | net: List available netdevs with "-netdev help" | ||
22 | net: Only show vhost-user in the help text if CONFIG_POSIX is defined | ||
23 | net: Make net_client_init() static | ||
24 | net: Remove the deprecated way of dumping network packets | ||
25 | net: Remove the deprecated 'host_net_add' and 'host_net_remove' HMP commands | ||
26 | net: Add a new convenience option "--nic" to configure default/on-board NICs | ||
27 | hw/net: Remove unnecessary header includes | ||
28 | 21 | ||
29 | hmp-commands.hx | 30 ------ | 22 | Prasad J Pandit (1): |
30 | hmp.h | 3 - | 23 | hw/net/e1000e: advance desc_offset in case of null descriptor |
31 | hw/net/e1000.c | 1 - | 24 | |
32 | hw/net/lance.c | 3 - | 25 | Yuri Benditovich (1): |
33 | hw/net/ne2000.c | 2 - | 26 | net: purge queued rx packets on queue deletion |
34 | hw/net/pcnet-pci.c | 1 - | 27 | |
35 | hw/net/pcnet.c | 1 - | 28 | yuanjungong (1): |
36 | hw/net/rtl8139.c | 2 - | 29 | tap: fix a memory leak |
37 | hw/net/xgmac.c | 1 - | 30 | |
38 | include/net/net.h | 4 +- | 31 | hw/net/e1000e_core.c | 8 +++--- |
39 | include/net/vhost_net.h | 3 + | 32 | include/net/net.h | 1 + |
40 | include/sysemu/sysemu.h | 1 + | 33 | monitor/hmp-cmds.c | 6 ++++ |
41 | monitor.c | 61 ------------ | 34 | net/net.c | 80 +++++++++++++++++++++++++++------------------------- |
42 | net/dump.c | 102 +-------------------- | 35 | net/tap.c | 5 +++- |
43 | net/net.c | 239 +++++++++++++++++++++++------------------------- | 36 | 5 files changed, 57 insertions(+), 43 deletions(-) |
44 | net/tap.c | 22 ++++- | ||
45 | qapi/net.json | 29 ++---- | ||
46 | qemu-doc.texi | 16 ---- | ||
47 | qemu-options.hx | 48 +++++++--- | ||
48 | tests/test-hmp.c | 2 - | ||
49 | vl.c | 10 +- | ||
50 | 21 files changed, 190 insertions(+), 391 deletions(-) | ||
51 | 37 | ||
52 | 38 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Prasad J Pandit <pjp@fedoraproject.org> |
---|---|---|---|
2 | 2 | ||
3 | Headers like "hw/loader.h" and "qemu/sockets.h" are not needed in | 3 | While receiving packets via e1000e_write_packet_to_guest() routine, |
4 | the hw/net/*.c files. And Some other headers are included via other | 4 | 'desc_offset' is advanced only when RX descriptor is processed. And |
5 | headers already, so we can drop them, too. | 5 | RX descriptor is not processed if it has NULL buffer address. |
6 | This may lead to an infinite loop condition. Increament 'desc_offset' | ||
7 | to process next descriptor in the ring to avoid infinite loop. | ||
6 | 8 | ||
7 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 9 | Reported-by: Cheol-woo Myung <330cjfdn@gmail.com> |
10 | Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org> | ||
8 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 11 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
9 | --- | 12 | --- |
10 | hw/net/e1000.c | 1 - | 13 | hw/net/e1000e_core.c | 8 ++++---- |
11 | hw/net/lance.c | 3 --- | 14 | 1 file changed, 4 insertions(+), 4 deletions(-) |
12 | hw/net/ne2000.c | 2 -- | ||
13 | hw/net/pcnet-pci.c | 1 - | ||
14 | hw/net/pcnet.c | 1 - | ||
15 | hw/net/rtl8139.c | 2 -- | ||
16 | hw/net/xgmac.c | 1 - | ||
17 | 7 files changed, 11 deletions(-) | ||
18 | 15 | ||
19 | diff --git a/hw/net/e1000.c b/hw/net/e1000.c | 16 | diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c |
20 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/net/e1000.c | 18 | --- a/hw/net/e1000e_core.c |
22 | +++ b/hw/net/e1000.c | 19 | +++ b/hw/net/e1000e_core.c |
23 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ e1000e_write_packet_to_guest(E1000ECore *core, struct NetRxPkt *pkt, |
24 | #include "hw/pci/pci.h" | 21 | (const char *) &fcs_pad, e1000x_fcs_len(core->mac)); |
25 | #include "net/net.h" | 22 | } |
26 | #include "net/checksum.h" | 23 | } |
27 | -#include "hw/loader.h" | 24 | - desc_offset += desc_size; |
28 | #include "sysemu/sysemu.h" | 25 | - if (desc_offset >= total_size) { |
29 | #include "sysemu/dma.h" | 26 | - is_last = true; |
30 | #include "qemu/iov.h" | 27 | - } |
31 | diff --git a/hw/net/lance.c b/hw/net/lance.c | 28 | } else { /* as per intel docs; skip descriptors with null buf addr */ |
32 | index XXXXXXX..XXXXXXX 100644 | 29 | trace_e1000e_rx_null_descriptor(); |
33 | --- a/hw/net/lance.c | 30 | } |
34 | +++ b/hw/net/lance.c | 31 | + desc_offset += desc_size; |
35 | @@ -XXX,XX +XXX,XX @@ | 32 | + if (desc_offset >= total_size) { |
36 | */ | 33 | + is_last = true; |
37 | 34 | + } | |
38 | #include "qemu/osdep.h" | 35 | |
39 | -#include "hw/sysbus.h" | 36 | e1000e_write_rx_descr(core, desc, is_last ? core->rx_pkt : NULL, |
40 | -#include "net/net.h" | 37 | rss_info, do_ps ? ps_hdr_len : 0, &bastate.written); |
41 | #include "qemu/timer.h" | ||
42 | -#include "qemu/sockets.h" | ||
43 | #include "hw/sparc/sparc32_dma.h" | ||
44 | #include "hw/net/lance.h" | ||
45 | #include "trace.h" | ||
46 | diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/hw/net/ne2000.c | ||
49 | +++ b/hw/net/ne2000.c | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | */ | ||
52 | #include "qemu/osdep.h" | ||
53 | #include "hw/pci/pci.h" | ||
54 | -#include "net/net.h" | ||
55 | #include "net/eth.h" | ||
56 | #include "ne2000.h" | ||
57 | -#include "hw/loader.h" | ||
58 | #include "sysemu/sysemu.h" | ||
59 | |||
60 | /* debug NE2000 card */ | ||
61 | diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/hw/net/pcnet-pci.c | ||
64 | +++ b/hw/net/pcnet-pci.c | ||
65 | @@ -XXX,XX +XXX,XX @@ | ||
66 | #include "qemu/osdep.h" | ||
67 | #include "hw/pci/pci.h" | ||
68 | #include "net/net.h" | ||
69 | -#include "hw/loader.h" | ||
70 | #include "qemu/timer.h" | ||
71 | #include "sysemu/dma.h" | ||
72 | #include "sysemu/sysemu.h" | ||
73 | diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/hw/net/pcnet.c | ||
76 | +++ b/hw/net/pcnet.c | ||
77 | @@ -XXX,XX +XXX,XX @@ | ||
78 | #include "net/net.h" | ||
79 | #include "net/eth.h" | ||
80 | #include "qemu/timer.h" | ||
81 | -#include "qemu/sockets.h" | ||
82 | #include "sysemu/sysemu.h" | ||
83 | #include "trace.h" | ||
84 | |||
85 | diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/hw/net/rtl8139.c | ||
88 | +++ b/hw/net/rtl8139.c | ||
89 | @@ -XXX,XX +XXX,XX @@ | ||
90 | #include "qemu/timer.h" | ||
91 | #include "net/net.h" | ||
92 | #include "net/eth.h" | ||
93 | -#include "hw/loader.h" | ||
94 | #include "sysemu/sysemu.h" | ||
95 | -#include "qemu/iov.h" | ||
96 | |||
97 | /* debug RTL8139 card */ | ||
98 | //#define DEBUG_RTL8139 1 | ||
99 | diff --git a/hw/net/xgmac.c b/hw/net/xgmac.c | ||
100 | index XXXXXXX..XXXXXXX 100644 | ||
101 | --- a/hw/net/xgmac.c | ||
102 | +++ b/hw/net/xgmac.c | ||
103 | @@ -XXX,XX +XXX,XX @@ | ||
104 | #include "hw/sysbus.h" | ||
105 | #include "qemu/log.h" | ||
106 | #include "net/net.h" | ||
107 | -#include "net/checksum.h" | ||
108 | |||
109 | #ifdef DEBUG_XGMAC | ||
110 | #define DEBUGF_BRK(message, args...) do { \ | ||
111 | -- | 38 | -- |
112 | 2.7.4 | 39 | 2.7.4 |
113 | 40 | ||
114 | 41 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Paolo Bonzini <pbonzini@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | It looks strange that net_init_client() and net_init_netdev() both | 3 | "netdev_add help" is causing QEMU to exit because the code that |
4 | take an "Error **errp" parameter, but then do the error reporting | 4 | invokes show_netdevs is shared between CLI and HMP processing. |
5 | with "error_report_err(local_err)" on their own. Let's move the | 5 | Move the check to the callers so that exit(0) remains only |
6 | error reporting to the calling site instead to simplify this code | 6 | in the CLI flow. |
7 | a little bit. | ||
8 | 7 | ||
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | 8 | "netdev_add help" is not fixed by this patch; that is left for |
10 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | 9 | later work. |
11 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 10 | |
11 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
12 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 12 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
13 | --- | 13 | --- |
14 | include/net/net.h | 2 +- | 14 | include/net/net.h | 1 + |
15 | net/net.c | 29 +++++------------------------ | 15 | monitor/hmp-cmds.c | 6 +++++ |
16 | vl.c | 3 ++- | 16 | net/net.c | 68 +++++++++++++++++++++++++++--------------------------- |
17 | 3 files changed, 8 insertions(+), 26 deletions(-) | 17 | 3 files changed, 41 insertions(+), 34 deletions(-) |
18 | 18 | ||
19 | diff --git a/include/net/net.h b/include/net/net.h | 19 | diff --git a/include/net/net.h b/include/net/net.h |
20 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/net/net.h | 21 | --- a/include/net/net.h |
22 | +++ b/include/net/net.h | 22 | +++ b/include/net/net.h |
23 | @@ -XXX,XX +XXX,XX @@ extern const char *legacy_bootp_filename; | 23 | @@ -XXX,XX +XXX,XX @@ extern const char *host_net_devices[]; |
24 | 24 | ||
25 | int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp); | 25 | /* from net.c */ |
26 | int net_client_parse(QemuOptsList *opts_list, const char *str); | 26 | int net_client_parse(QemuOptsList *opts_list, const char *str); |
27 | -int net_init_clients(void); | 27 | +void show_netdevs(void); |
28 | +int net_init_clients(Error **errp); | 28 | int net_init_clients(Error **errp); |
29 | void net_check_clients(void); | 29 | void net_check_clients(void); |
30 | void net_cleanup(void); | 30 | void net_cleanup(void); |
31 | void hmp_host_net_add(Monitor *mon, const QDict *qdict); | 31 | diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c |
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/monitor/hmp-cmds.c | ||
34 | +++ b/monitor/hmp-cmds.c | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | #include "qemu/option.h" | ||
37 | #include "qemu/timer.h" | ||
38 | #include "qemu/sockets.h" | ||
39 | +#include "qemu/help_option.h" | ||
40 | #include "monitor/monitor-internal.h" | ||
41 | #include "qapi/error.h" | ||
42 | #include "qapi/clone-visitor.h" | ||
43 | @@ -XXX,XX +XXX,XX @@ void hmp_netdev_add(Monitor *mon, const QDict *qdict) | ||
44 | { | ||
45 | Error *err = NULL; | ||
46 | QemuOpts *opts; | ||
47 | + const char *type = qdict_get_try_str(qdict, "type"); | ||
48 | |||
49 | + if (type && is_help_option(type)) { | ||
50 | + show_netdevs(); | ||
51 | + return; | ||
52 | + } | ||
53 | opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); | ||
54 | if (err) { | ||
55 | goto out; | ||
32 | diff --git a/net/net.c b/net/net.c | 56 | diff --git a/net/net.c b/net/net.c |
33 | index XXXXXXX..XXXXXXX 100644 | 57 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/net/net.c | 58 | --- a/net/net.c |
35 | +++ b/net/net.c | 59 | +++ b/net/net.c |
36 | @@ -XXX,XX +XXX,XX @@ void net_check_clients(void) | 60 | @@ -XXX,XX +XXX,XX @@ |
37 | 61 | #include "qemu/config-file.h" | |
38 | static int net_init_client(void *dummy, QemuOpts *opts, Error **errp) | 62 | #include "qemu/ctype.h" |
63 | #include "qemu/iov.h" | ||
64 | +#include "qemu/qemu-print.h" | ||
65 | #include "qemu/main-loop.h" | ||
66 | #include "qemu/option.h" | ||
67 | #include "qapi/error.h" | ||
68 | @@ -XXX,XX +XXX,XX @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp) | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | -static void show_netdevs(void) | ||
73 | +void show_netdevs(void) | ||
39 | { | 74 | { |
40 | - Error *local_err = NULL; | 75 | int idx; |
76 | const char *available_netdevs[] = { | ||
77 | @@ -XXX,XX +XXX,XX @@ static void show_netdevs(void) | ||
78 | #endif | ||
79 | }; | ||
80 | |||
81 | - printf("Available netdev backend types:\n"); | ||
82 | + qemu_printf("Available netdev backend types:\n"); | ||
83 | for (idx = 0; idx < ARRAY_SIZE(available_netdevs); idx++) { | ||
84 | - puts(available_netdevs[idx]); | ||
85 | + qemu_printf("%s\n", available_netdevs[idx]); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | @@ -XXX,XX +XXX,XX @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) | ||
90 | int ret = -1; | ||
91 | Visitor *v = opts_visitor_new(opts); | ||
92 | |||
93 | - const char *type = qemu_opt_get(opts, "type"); | ||
41 | - | 94 | - |
42 | - net_client_init(opts, false, &local_err); | 95 | - if (is_netdev && type && is_help_option(type)) { |
43 | - if (local_err) { | 96 | - show_netdevs(); |
44 | - error_report_err(local_err); | 97 | - exit(0); |
45 | - return -1; | 98 | - } else { |
46 | - } | 99 | - /* Parse convenience option format ip6-net=fec0::0[/64] */ |
100 | - const char *ip6_net = qemu_opt_get(opts, "ipv6-net"); | ||
101 | + /* Parse convenience option format ip6-net=fec0::0[/64] */ | ||
102 | + const char *ip6_net = qemu_opt_get(opts, "ipv6-net"); | ||
103 | |||
104 | - if (ip6_net) { | ||
105 | - char *prefix_addr; | ||
106 | - unsigned long prefix_len = 64; /* Default 64bit prefix length. */ | ||
107 | + if (ip6_net) { | ||
108 | + char *prefix_addr; | ||
109 | + unsigned long prefix_len = 64; /* Default 64bit prefix length. */ | ||
110 | |||
111 | - substrings = g_strsplit(ip6_net, "/", 2); | ||
112 | - if (!substrings || !substrings[0]) { | ||
113 | - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "ipv6-net", | ||
114 | - "a valid IPv6 prefix"); | ||
115 | - goto out; | ||
116 | - } | ||
117 | + substrings = g_strsplit(ip6_net, "/", 2); | ||
118 | + if (!substrings || !substrings[0]) { | ||
119 | + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "ipv6-net", | ||
120 | + "a valid IPv6 prefix"); | ||
121 | + goto out; | ||
122 | + } | ||
123 | |||
124 | - prefix_addr = substrings[0]; | ||
125 | + prefix_addr = substrings[0]; | ||
126 | |||
127 | - /* Handle user-specified prefix length. */ | ||
128 | - if (substrings[1] && | ||
129 | - qemu_strtoul(substrings[1], NULL, 10, &prefix_len)) | ||
130 | - { | ||
131 | - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, | ||
132 | - "ipv6-prefixlen", "a number"); | ||
133 | - goto out; | ||
134 | - } | ||
47 | - | 135 | - |
48 | - return 0; | 136 | - qemu_opt_set(opts, "ipv6-prefix", prefix_addr, &error_abort); |
49 | + return net_client_init(opts, false, errp); | 137 | - qemu_opt_set_number(opts, "ipv6-prefixlen", prefix_len, |
50 | } | 138 | - &error_abort); |
139 | - qemu_opt_unset(opts, "ipv6-net"); | ||
140 | + /* Handle user-specified prefix length. */ | ||
141 | + if (substrings[1] && | ||
142 | + qemu_strtoul(substrings[1], NULL, 10, &prefix_len)) | ||
143 | + { | ||
144 | + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, | ||
145 | + "ipv6-prefixlen", "a number"); | ||
146 | + goto out; | ||
147 | } | ||
148 | + | ||
149 | + qemu_opt_set(opts, "ipv6-prefix", prefix_addr, &error_abort); | ||
150 | + qemu_opt_set_number(opts, "ipv6-prefixlen", prefix_len, | ||
151 | + &error_abort); | ||
152 | + qemu_opt_unset(opts, "ipv6-net"); | ||
153 | } | ||
154 | |||
155 | /* Create an ID for -net if the user did not specify one */ | ||
156 | @@ -XXX,XX +XXX,XX @@ static int net_init_client(void *dummy, QemuOpts *opts, Error **errp) | ||
51 | 157 | ||
52 | static int net_init_netdev(void *dummy, QemuOpts *opts, Error **errp) | 158 | static int net_init_netdev(void *dummy, QemuOpts *opts, Error **errp) |
53 | { | 159 | { |
54 | - Error *local_err = NULL; | 160 | + const char *type = qemu_opt_get(opts, "type"); |
55 | - int ret; | 161 | + |
56 | - | 162 | + if (type && is_help_option(type)) { |
57 | - ret = net_client_init(opts, true, &local_err); | 163 | + show_netdevs(); |
58 | - if (local_err) { | 164 | + exit(0); |
59 | - error_report_err(local_err); | 165 | + } |
60 | - return -1; | 166 | return net_client_init(opts, true, errp); |
61 | - } | ||
62 | - | ||
63 | - return ret; | ||
64 | + return net_client_init(opts, true, errp); | ||
65 | } | 167 | } |
66 | |||
67 | -int net_init_clients(void) | ||
68 | +int net_init_clients(Error **errp) | ||
69 | { | ||
70 | - QemuOptsList *net = qemu_find_opts("net"); | ||
71 | - | ||
72 | net_change_state_entry = | ||
73 | qemu_add_vm_change_state_handler(net_vm_change_state_handler, NULL); | ||
74 | |||
75 | QTAILQ_INIT(&net_clients); | ||
76 | |||
77 | if (qemu_opts_foreach(qemu_find_opts("netdev"), | ||
78 | - net_init_netdev, NULL, NULL)) { | ||
79 | + net_init_netdev, NULL, errp)) { | ||
80 | return -1; | ||
81 | } | ||
82 | |||
83 | - if (qemu_opts_foreach(net, net_init_client, NULL, NULL)) { | ||
84 | + if (qemu_opts_foreach(qemu_find_opts("net"), net_init_client, NULL, errp)) { | ||
85 | return -1; | ||
86 | } | ||
87 | |||
88 | diff --git a/vl.c b/vl.c | ||
89 | index XXXXXXX..XXXXXXX 100644 | ||
90 | --- a/vl.c | ||
91 | +++ b/vl.c | ||
92 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
93 | |||
94 | colo_info_init(); | ||
95 | |||
96 | - if (net_init_clients() < 0) { | ||
97 | + if (net_init_clients(&err) < 0) { | ||
98 | + error_report_err(err); | ||
99 | exit(1); | ||
100 | } | ||
101 | 168 | ||
102 | -- | 169 | -- |
103 | 2.7.4 | 170 | 2.7.4 |
104 | 171 | ||
105 | 172 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Yuri Benditovich <yuri.benditovich@daynix.com> |
---|---|---|---|
2 | 2 | ||
3 | Other options like "-chardev" or "-device" feature a nice help text | 3 | https://bugzilla.redhat.com/show_bug.cgi?id=1829272 |
4 | with the available devices when being called with "help" or "?". | 4 | When deleting queue pair, purge pending RX packets if any. |
5 | Since it is quite useful, especially if you want to see which network | 5 | Example of problematic flow: |
6 | backends have been compiled into the QEMU binary, let's provide such | 6 | 1. Bring up q35 VM with tap (vhost off) and virtio-net or e1000e |
7 | a help text for "-netdev", too. | 7 | 2. Run ping flood to the VM NIC ( 1 ms interval) |
8 | 3. Hot unplug the NIC device (device_del) | ||
9 | During unplug process one or more packets come, the NIC | ||
10 | can't receive, tap disables read_poll | ||
11 | 4. Hot plug the device (device_add) with the same netdev | ||
12 | The tap stays with read_poll disabled and does not receive | ||
13 | any packets anymore (tap_send never triggered) | ||
8 | 14 | ||
9 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | 15 | Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com> |
10 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
11 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
12 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 16 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
13 | --- | 17 | --- |
14 | net/net.c | 37 ++++++++++++++++++++++++++++++++++++- | 18 | net/net.c | 12 ++++++++---- |
15 | 1 file changed, 36 insertions(+), 1 deletion(-) | 19 | 1 file changed, 8 insertions(+), 4 deletions(-) |
16 | 20 | ||
17 | diff --git a/net/net.c b/net/net.c | 21 | diff --git a/net/net.c b/net/net.c |
18 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/net/net.c | 23 | --- a/net/net.c |
20 | +++ b/net/net.c | 24 | +++ b/net/net.c |
21 | @@ -XXX,XX +XXX,XX @@ static int net_client_init1(const void *object, bool is_netdev, Error **errp) | 25 | @@ -XXX,XX +XXX,XX @@ void qemu_del_nic(NICState *nic) |
22 | return 0; | 26 | |
23 | } | 27 | qemu_macaddr_set_free(&nic->conf->macaddr); |
24 | 28 | ||
25 | +static void show_netdevs(void) | 29 | - /* If this is a peer NIC and peer has already been deleted, free it now. */ |
26 | +{ | 30 | - if (nic->peer_deleted) { |
27 | + int idx; | 31 | - for (i = 0; i < queues; i++) { |
28 | + const char *available_netdevs[] = { | 32 | - qemu_free_net_client(qemu_get_subqueue(nic, i)->peer); |
29 | + "socket", | 33 | + for (i = 0; i < queues; i++) { |
30 | + "hubport", | 34 | + NetClientState *nc = qemu_get_subqueue(nic, i); |
31 | + "tap", | 35 | + /* If this is a peer NIC and peer has already been deleted, free it now. */ |
32 | +#ifdef CONFIG_SLIRP | 36 | + if (nic->peer_deleted) { |
33 | + "user", | 37 | + qemu_free_net_client(nc->peer); |
34 | +#endif | 38 | + } else if (nc->peer) { |
35 | +#ifdef CONFIG_L2TPV3 | 39 | + /* if there are RX packets pending, complete them */ |
36 | + "l2tpv3", | 40 | + qemu_purge_queued_packets(nc->peer); |
37 | +#endif | 41 | } |
38 | +#ifdef CONFIG_VDE | 42 | } |
39 | + "vde", | ||
40 | +#endif | ||
41 | +#ifdef CONFIG_NET_BRIDGE | ||
42 | + "bridge", | ||
43 | +#endif | ||
44 | +#ifdef CONFIG_NETMAP | ||
45 | + "netmap", | ||
46 | +#endif | ||
47 | +#ifdef CONFIG_POSIX | ||
48 | + "vhost-user", | ||
49 | +#endif | ||
50 | + }; | ||
51 | + | ||
52 | + printf("Available netdev backend types:\n"); | ||
53 | + for (idx = 0; idx < ARRAY_SIZE(available_netdevs); idx++) { | ||
54 | + puts(available_netdevs[idx]); | ||
55 | + } | ||
56 | +} | ||
57 | |||
58 | int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) | ||
59 | { | ||
60 | @@ -XXX,XX +XXX,XX @@ int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) | ||
61 | int ret = -1; | ||
62 | Visitor *v = opts_visitor_new(opts); | ||
63 | |||
64 | - { | ||
65 | + if (is_netdev && is_help_option(qemu_opt_get(opts, "type"))) { | ||
66 | + show_netdevs(); | ||
67 | + exit(0); | ||
68 | + } else { | ||
69 | /* Parse convenience option format ip6-net=fec0::0[/64] */ | ||
70 | const char *ip6_net = qemu_opt_get(opts, "ipv6-net"); | ||
71 | 43 | ||
72 | -- | 44 | -- |
73 | 2.7.4 | 45 | 2.7.4 |
74 | 46 | ||
75 | 47 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: yuanjungong <ruc_gongyuanjun@163.com> |
---|---|---|---|
2 | 2 | ||
3 | According to net/Makefile.objs we only link in the vhost-user code | 3 | Close fd before returning. |
4 | if CONFIG_POSIX has been set. So the help screen should also only | ||
5 | show this information if CONFIG_POSIX has been defined. | ||
6 | 4 | ||
7 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | 5 | Buglink: https://bugs.launchpad.net/qemu/+bug/1904486 |
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 6 | |
7 | Signed-off-by: yuanjungong <ruc_gongyuanjun@163.com> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 9 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
10 | --- | 10 | --- |
11 | qemu-options.hx | 2 ++ | 11 | net/tap.c | 2 ++ |
12 | 1 file changed, 2 insertions(+) | 12 | 1 file changed, 2 insertions(+) |
13 | 13 | ||
14 | diff --git a/qemu-options.hx b/qemu-options.hx | 14 | diff --git a/net/tap.c b/net/tap.c |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/qemu-options.hx | 16 | --- a/net/tap.c |
17 | +++ b/qemu-options.hx | 17 | +++ b/net/tap.c |
18 | @@ -XXX,XX +XXX,XX @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, | 18 | @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, |
19 | " VALE port (created on the fly) called 'name' ('nmname' is name of the \n" | 19 | if (ret < 0) { |
20 | " netmap device, defaults to '/dev/netmap')\n" | 20 | error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d", |
21 | #endif | 21 | name, fd); |
22 | +#ifdef CONFIG_POSIX | 22 | + close(fd); |
23 | "-netdev vhost-user,id=str,chardev=dev[,vhostforce=on|off]\n" | 23 | return -1; |
24 | " configure a vhost-user network, backed by a chardev 'dev'\n" | 24 | } |
25 | +#endif | 25 | |
26 | "-netdev hubport,id=str,hubid=n[,netdev=nd]\n" | 26 | @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, |
27 | " configure a hub port on QEMU VLAN 'n'\n", QEMU_ARCH_ALL) | 27 | vhostfdname, vnet_hdr, fd, &err); |
28 | DEF("net", HAS_ARG, QEMU_OPTION_net, | 28 | if (err) { |
29 | error_propagate(errp, err); | ||
30 | + close(fd); | ||
31 | return -1; | ||
32 | } | ||
33 | } else if (tap->has_fds) { | ||
29 | -- | 34 | -- |
30 | 2.7.4 | 35 | 2.7.4 |
31 | 36 | ||
32 | 37 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
2 | 1 | ||
3 | The function is only used within net.c, so there's no need that | ||
4 | this is a global function. | ||
5 | |||
6 | While we're at it, also remove the unused prototype compute_mcast_idx() | ||
7 | (the function has been removed in commit d9caeb09b107e91122d10ba4a08a). | ||
8 | |||
9 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
10 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
11 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
12 | --- | ||
13 | include/net/net.h | 2 -- | ||
14 | net/net.c | 2 +- | ||
15 | 2 files changed, 1 insertion(+), 3 deletions(-) | ||
16 | |||
17 | diff --git a/include/net/net.h b/include/net/net.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/net/net.h | ||
20 | +++ b/include/net/net.h | ||
21 | @@ -XXX,XX +XXX,XX @@ extern const char *host_net_devices[]; | ||
22 | extern const char *legacy_tftp_prefix; | ||
23 | extern const char *legacy_bootp_filename; | ||
24 | |||
25 | -int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp); | ||
26 | int net_client_parse(QemuOptsList *opts_list, const char *str); | ||
27 | int net_init_clients(Error **errp); | ||
28 | void net_check_clients(void); | ||
29 | @@ -XXX,XX +XXX,XX @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); | ||
30 | #define POLYNOMIAL_LE 0xedb88320 | ||
31 | uint32_t net_crc32(const uint8_t *p, int len); | ||
32 | uint32_t net_crc32_le(const uint8_t *p, int len); | ||
33 | -unsigned compute_mcast_idx(const uint8_t *ep); | ||
34 | |||
35 | #define vmstate_offset_macaddr(_state, _field) \ | ||
36 | vmstate_offset_array(_state, _field.a, uint8_t, \ | ||
37 | diff --git a/net/net.c b/net/net.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/net/net.c | ||
40 | +++ b/net/net.c | ||
41 | @@ -XXX,XX +XXX,XX @@ static void show_netdevs(void) | ||
42 | } | ||
43 | } | ||
44 | |||
45 | -int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) | ||
46 | +static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) | ||
47 | { | ||
48 | void *object = NULL; | ||
49 | Error *err = NULL; | ||
50 | -- | ||
51 | 2.7.4 | ||
52 | |||
53 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
2 | 1 | ||
3 | "-net dump" has been marked as deprecated since QEMU v2.10, since it | ||
4 | only works with the deprecated 'vlan' parameter (or hubs). Network | ||
5 | dumping should be done with "-object filter-dump" nowadays instead. | ||
6 | Since nobody complained so far about the deprecation message, let's | ||
7 | finally get rid of "-net dump" now. | ||
8 | |||
9 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
10 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
11 | --- | ||
12 | net/dump.c | 102 ++------------------------------------------------------ | ||
13 | net/net.c | 9 +---- | ||
14 | qapi/net.json | 29 ++++------------ | ||
15 | qemu-doc.texi | 6 ---- | ||
16 | qemu-options.hx | 8 ----- | ||
17 | 5 files changed, 9 insertions(+), 145 deletions(-) | ||
18 | |||
19 | diff --git a/net/dump.c b/net/dump.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/net/dump.c | ||
22 | +++ b/net/dump.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static int net_dump_state_init(DumpState *s, const char *filename, | ||
24 | |||
25 | fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0644); | ||
26 | if (fd < 0) { | ||
27 | - error_setg_errno(errp, errno, "-net dump: can't open %s", filename); | ||
28 | + error_setg_errno(errp, errno, "net dump: can't open %s", filename); | ||
29 | return -1; | ||
30 | } | ||
31 | |||
32 | @@ -XXX,XX +XXX,XX @@ static int net_dump_state_init(DumpState *s, const char *filename, | ||
33 | hdr.linktype = 1; | ||
34 | |||
35 | if (write(fd, &hdr, sizeof(hdr)) < sizeof(hdr)) { | ||
36 | - error_setg_errno(errp, errno, "-net dump write error"); | ||
37 | + error_setg_errno(errp, errno, "net dump write error"); | ||
38 | close(fd); | ||
39 | return -1; | ||
40 | } | ||
41 | @@ -XXX,XX +XXX,XX @@ static int net_dump_state_init(DumpState *s, const char *filename, | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | -/* Dumping via VLAN netclient */ | ||
46 | - | ||
47 | -struct DumpNetClient { | ||
48 | - NetClientState nc; | ||
49 | - DumpState ds; | ||
50 | -}; | ||
51 | -typedef struct DumpNetClient DumpNetClient; | ||
52 | - | ||
53 | -static ssize_t dumpclient_receive(NetClientState *nc, const uint8_t *buf, | ||
54 | - size_t size) | ||
55 | -{ | ||
56 | - DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc); | ||
57 | - struct iovec iov = { | ||
58 | - .iov_base = (void *)buf, | ||
59 | - .iov_len = size | ||
60 | - }; | ||
61 | - | ||
62 | - return dump_receive_iov(&dc->ds, &iov, 1); | ||
63 | -} | ||
64 | - | ||
65 | -static ssize_t dumpclient_receive_iov(NetClientState *nc, | ||
66 | - const struct iovec *iov, int cnt) | ||
67 | -{ | ||
68 | - DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc); | ||
69 | - | ||
70 | - return dump_receive_iov(&dc->ds, iov, cnt); | ||
71 | -} | ||
72 | - | ||
73 | -static void dumpclient_cleanup(NetClientState *nc) | ||
74 | -{ | ||
75 | - DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc); | ||
76 | - | ||
77 | - dump_cleanup(&dc->ds); | ||
78 | -} | ||
79 | - | ||
80 | -static NetClientInfo net_dump_info = { | ||
81 | - .type = NET_CLIENT_DRIVER_DUMP, | ||
82 | - .size = sizeof(DumpNetClient), | ||
83 | - .receive = dumpclient_receive, | ||
84 | - .receive_iov = dumpclient_receive_iov, | ||
85 | - .cleanup = dumpclient_cleanup, | ||
86 | -}; | ||
87 | - | ||
88 | -int net_init_dump(const Netdev *netdev, const char *name, | ||
89 | - NetClientState *peer, Error **errp) | ||
90 | -{ | ||
91 | - int len, rc; | ||
92 | - const char *file; | ||
93 | - char def_file[128]; | ||
94 | - const NetdevDumpOptions *dump; | ||
95 | - NetClientState *nc; | ||
96 | - DumpNetClient *dnc; | ||
97 | - | ||
98 | - assert(netdev->type == NET_CLIENT_DRIVER_DUMP); | ||
99 | - dump = &netdev->u.dump; | ||
100 | - | ||
101 | - assert(peer); | ||
102 | - | ||
103 | - error_report("'-net dump' is deprecated. " | ||
104 | - "Please use '-object filter-dump' instead."); | ||
105 | - | ||
106 | - if (dump->has_file) { | ||
107 | - file = dump->file; | ||
108 | - } else { | ||
109 | - int id; | ||
110 | - int ret; | ||
111 | - | ||
112 | - ret = net_hub_id_for_client(peer, &id); | ||
113 | - assert(ret == 0); /* peer must be on a hub */ | ||
114 | - | ||
115 | - snprintf(def_file, sizeof(def_file), "qemu-vlan%d.pcap", id); | ||
116 | - file = def_file; | ||
117 | - } | ||
118 | - | ||
119 | - if (dump->has_len) { | ||
120 | - if (dump->len > INT_MAX) { | ||
121 | - error_setg(errp, "invalid length: %"PRIu64, dump->len); | ||
122 | - return -1; | ||
123 | - } | ||
124 | - len = dump->len; | ||
125 | - } else { | ||
126 | - len = 65536; | ||
127 | - } | ||
128 | - | ||
129 | - nc = qemu_new_net_client(&net_dump_info, peer, "dump", name); | ||
130 | - snprintf(nc->info_str, sizeof(nc->info_str), | ||
131 | - "dump to %s (len=%d)", file, len); | ||
132 | - | ||
133 | - dnc = DO_UPCAST(DumpNetClient, nc, nc); | ||
134 | - rc = net_dump_state_init(&dnc->ds, file, len, errp); | ||
135 | - if (rc) { | ||
136 | - qemu_del_net_client(nc); | ||
137 | - } | ||
138 | - return rc; | ||
139 | -} | ||
140 | - | ||
141 | -/* Dumping via filter */ | ||
142 | - | ||
143 | #define TYPE_FILTER_DUMP "filter-dump" | ||
144 | |||
145 | #define FILTER_DUMP(obj) \ | ||
146 | diff --git a/net/net.c b/net/net.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/net/net.c | ||
149 | +++ b/net/net.c | ||
150 | @@ -XXX,XX +XXX,XX @@ static QTAILQ_HEAD(, NetClientState) net_clients; | ||
151 | const char *host_net_devices[] = { | ||
152 | "tap", | ||
153 | "socket", | ||
154 | - "dump", | ||
155 | #ifdef CONFIG_NET_BRIDGE | ||
156 | "bridge", | ||
157 | #endif | ||
158 | @@ -XXX,XX +XXX,XX @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])( | ||
159 | #ifdef CONFIG_NETMAP | ||
160 | [NET_CLIENT_DRIVER_NETMAP] = net_init_netmap, | ||
161 | #endif | ||
162 | - [NET_CLIENT_DRIVER_DUMP] = net_init_dump, | ||
163 | #ifdef CONFIG_NET_BRIDGE | ||
164 | [NET_CLIENT_DRIVER_BRIDGE] = net_init_bridge, | ||
165 | #endif | ||
166 | @@ -XXX,XX +XXX,XX @@ static int net_client_init1(const void *object, bool is_netdev, Error **errp) | ||
167 | netdev = object; | ||
168 | name = netdev->id; | ||
169 | |||
170 | - if (netdev->type == NET_CLIENT_DRIVER_DUMP || | ||
171 | - netdev->type == NET_CLIENT_DRIVER_NIC || | ||
172 | + if (netdev->type == NET_CLIENT_DRIVER_NIC || | ||
173 | !net_client_init_fun[netdev->type]) { | ||
174 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", | ||
175 | "a netdev backend type"); | ||
176 | @@ -XXX,XX +XXX,XX @@ static int net_client_init1(const void *object, bool is_netdev, Error **errp) | ||
177 | legacy.type = NET_CLIENT_DRIVER_VDE; | ||
178 | legacy.u.vde = opts->u.vde; | ||
179 | break; | ||
180 | - case NET_LEGACY_OPTIONS_TYPE_DUMP: | ||
181 | - legacy.type = NET_CLIENT_DRIVER_DUMP; | ||
182 | - legacy.u.dump = opts->u.dump; | ||
183 | - break; | ||
184 | case NET_LEGACY_OPTIONS_TYPE_BRIDGE: | ||
185 | legacy.type = NET_CLIENT_DRIVER_BRIDGE; | ||
186 | legacy.u.bridge = opts->u.bridge; | ||
187 | diff --git a/qapi/net.json b/qapi/net.json | ||
188 | index XXXXXXX..XXXXXXX 100644 | ||
189 | --- a/qapi/net.json | ||
190 | +++ b/qapi/net.json | ||
191 | @@ -XXX,XX +XXX,XX @@ | ||
192 | # | ||
193 | # Add a network backend. | ||
194 | # | ||
195 | -# @type: the type of network backend. Current valid values are 'user', 'tap', | ||
196 | -# 'vde', 'socket', 'dump' and 'bridge' | ||
197 | +# @type: the type of network backend. Possible values are listed in | ||
198 | +# NetClientDriver (excluding 'none' and 'nic') | ||
199 | # | ||
200 | # @id: the name of the new network backend | ||
201 | # | ||
202 | @@ -XXX,XX +XXX,XX @@ | ||
203 | '*mode': 'uint16' } } | ||
204 | |||
205 | ## | ||
206 | -# @NetdevDumpOptions: | ||
207 | -# | ||
208 | -# Dump VLAN network traffic to a file. | ||
209 | -# | ||
210 | -# @len: per-packet size limit (64k default). Understands [TGMKkb] | ||
211 | -# suffixes. | ||
212 | -# | ||
213 | -# @file: dump file path (default is qemu-vlan0.pcap) | ||
214 | -# | ||
215 | -# Since: 1.2 | ||
216 | -## | ||
217 | -{ 'struct': 'NetdevDumpOptions', | ||
218 | - 'data': { | ||
219 | - '*len': 'size', | ||
220 | - '*file': 'str' } } | ||
221 | - | ||
222 | -## | ||
223 | # @NetdevBridgeOptions: | ||
224 | # | ||
225 | # Connect a host TAP network interface to a host bridge device. | ||
226 | @@ -XXX,XX +XXX,XX @@ | ||
227 | # Available netdev drivers. | ||
228 | # | ||
229 | # Since: 2.7 | ||
230 | +# | ||
231 | +# 'dump' - removed with 2.12 | ||
232 | ## | ||
233 | { 'enum': 'NetClientDriver', | ||
234 | - 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', 'dump', | ||
235 | + 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', | ||
236 | 'bridge', 'hubport', 'netmap', 'vhost-user' ] } | ||
237 | |||
238 | ## | ||
239 | @@ -XXX,XX +XXX,XX @@ | ||
240 | 'l2tpv3': 'NetdevL2TPv3Options', | ||
241 | 'socket': 'NetdevSocketOptions', | ||
242 | 'vde': 'NetdevVdeOptions', | ||
243 | - 'dump': 'NetdevDumpOptions', | ||
244 | 'bridge': 'NetdevBridgeOptions', | ||
245 | 'hubport': 'NetdevHubPortOptions', | ||
246 | 'netmap': 'NetdevNetmapOptions', | ||
247 | @@ -XXX,XX +XXX,XX @@ | ||
248 | ## | ||
249 | { 'enum': 'NetLegacyOptionsType', | ||
250 | 'data': ['none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', | ||
251 | - 'dump', 'bridge', 'netmap', 'vhost-user'] } | ||
252 | + 'bridge', 'netmap', 'vhost-user'] } | ||
253 | |||
254 | ## | ||
255 | # @NetLegacyOptions: | ||
256 | @@ -XXX,XX +XXX,XX @@ | ||
257 | 'l2tpv3': 'NetdevL2TPv3Options', | ||
258 | 'socket': 'NetdevSocketOptions', | ||
259 | 'vde': 'NetdevVdeOptions', | ||
260 | - 'dump': 'NetdevDumpOptions', | ||
261 | 'bridge': 'NetdevBridgeOptions', | ||
262 | 'netmap': 'NetdevNetmapOptions', | ||
263 | 'vhost-user': 'NetdevVhostUserOptions' } } | ||
264 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
265 | index XXXXXXX..XXXXXXX 100644 | ||
266 | --- a/qemu-doc.texi | ||
267 | +++ b/qemu-doc.texi | ||
268 | @@ -XXX,XX +XXX,XX @@ that can be specified with the ``-device'' parameter. | ||
269 | The drive addr argument is replaced by the the addr argument | ||
270 | that can be specified with the ``-device'' parameter. | ||
271 | |||
272 | -@subsection -net dump (since 2.10.0) | ||
273 | - | ||
274 | -The ``--net dump'' argument is now replaced with the | ||
275 | -``-object filter-dump'' argument which works in combination | ||
276 | -with the modern ``-netdev`` backends instead. | ||
277 | - | ||
278 | @subsection -usbdevice (since 2.10.0) | ||
279 | |||
280 | The ``-usbdevice DEV'' argument is now a synonym for setting | ||
281 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
282 | index XXXXXXX..XXXXXXX 100644 | ||
283 | --- a/qemu-options.hx | ||
284 | +++ b/qemu-options.hx | ||
285 | @@ -XXX,XX +XXX,XX @@ DEF("net", HAS_ARG, QEMU_OPTION_net, | ||
286 | " configure or create an on-board (or machine default) NIC and\n" | ||
287 | " connect it either to VLAN 'n' or the netdev 'nd' (for pluggable\n" | ||
288 | " NICs please use '-device devtype,netdev=nd' instead)\n" | ||
289 | - "-net dump[,vlan=n][,file=f][,len=n]\n" | ||
290 | - " dump traffic on vlan 'n' to file 'f' (max n bytes per packet)\n" | ||
291 | "-net none use it alone to have zero network devices. If no -net option\n" | ||
292 | " is provided, the default is '-net nic -net user'\n" | ||
293 | "-net [" | ||
294 | @@ -XXX,XX +XXX,XX @@ qemu -m 512 -object memory-backend-file,id=mem,size=512M,mem-path=/hugetlbfs,sha | ||
295 | -device virtio-net-pci,netdev=net0 | ||
296 | @end example | ||
297 | |||
298 | -@item -net dump[,vlan=@var{n}][,file=@var{file}][,len=@var{len}] | ||
299 | -Dump network traffic on VLAN @var{n} to file @var{file} (@file{qemu-vlan0.pcap} by default). | ||
300 | -At most @var{len} bytes (64k by default) per packet are stored. The file format is | ||
301 | -libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. | ||
302 | -Note: For devices created with '-netdev', use '-object filter-dump,...' instead. | ||
303 | - | ||
304 | @item -net none | ||
305 | Indicate that no network devices should be configured. It is used to | ||
306 | override the default configuration (@option{-net nic -net user}) which | ||
307 | -- | ||
308 | 2.7.4 | ||
309 | |||
310 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
2 | 1 | ||
3 | They are deprecated since QEMU v2.10, and so far nobody complained that | ||
4 | these commands are still necessary for any reason - and since you can use | ||
5 | 'netdev_add' and 'netdev_remove' instead, there also should not be any | ||
6 | real reason. Since they are also standing in the way for the upcoming | ||
7 | 'vlan' clean-up, it's now time to remove them. | ||
8 | |||
9 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
10 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
11 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
12 | --- | ||
13 | hmp-commands.hx | 30 ------------------ | ||
14 | hmp.h | 3 -- | ||
15 | monitor.c | 61 ------------------------------------ | ||
16 | net/net.c | 94 -------------------------------------------------------- | ||
17 | qemu-doc.texi | 10 ------ | ||
18 | tests/test-hmp.c | 2 -- | ||
19 | 6 files changed, 200 deletions(-) | ||
20 | |||
21 | diff --git a/hmp-commands.hx b/hmp-commands.hx | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/hmp-commands.hx | ||
24 | +++ b/hmp-commands.hx | ||
25 | @@ -XXX,XX +XXX,XX @@ Inject PCIe AER error | ||
26 | ETEXI | ||
27 | |||
28 | { | ||
29 | - .name = "host_net_add", | ||
30 | - .args_type = "device:s,opts:s?", | ||
31 | - .params = "tap|user|socket|vde|netmap|bridge|vhost-user|dump [options]", | ||
32 | - .help = "add host VLAN client (deprecated, use netdev_add instead)", | ||
33 | - .cmd = hmp_host_net_add, | ||
34 | - .command_completion = host_net_add_completion, | ||
35 | - }, | ||
36 | - | ||
37 | -STEXI | ||
38 | -@item host_net_add | ||
39 | -@findex host_net_add | ||
40 | -Add host VLAN client. Deprecated, please use @code{netdev_add} instead. | ||
41 | -ETEXI | ||
42 | - | ||
43 | - { | ||
44 | - .name = "host_net_remove", | ||
45 | - .args_type = "vlan_id:i,device:s", | ||
46 | - .params = "vlan_id name", | ||
47 | - .help = "remove host VLAN client (deprecated, use netdev_del instead)", | ||
48 | - .cmd = hmp_host_net_remove, | ||
49 | - .command_completion = host_net_remove_completion, | ||
50 | - }, | ||
51 | - | ||
52 | -STEXI | ||
53 | -@item host_net_remove | ||
54 | -@findex host_net_remove | ||
55 | -Remove host VLAN client. Deprecated, please use @code{netdev_del} instead. | ||
56 | -ETEXI | ||
57 | - | ||
58 | - { | ||
59 | .name = "netdev_add", | ||
60 | .args_type = "netdev:O", | ||
61 | .params = "[user|tap|socket|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]", | ||
62 | diff --git a/hmp.h b/hmp.h | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/hmp.h | ||
65 | +++ b/hmp.h | ||
66 | @@ -XXX,XX +XXX,XX @@ void migrate_set_capability_completion(ReadLineState *rs, int nb_args, | ||
67 | const char *str); | ||
68 | void migrate_set_parameter_completion(ReadLineState *rs, int nb_args, | ||
69 | const char *str); | ||
70 | -void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str); | ||
71 | -void host_net_remove_completion(ReadLineState *rs, int nb_args, | ||
72 | - const char *str); | ||
73 | void delvm_completion(ReadLineState *rs, int nb_args, const char *str); | ||
74 | void loadvm_completion(ReadLineState *rs, int nb_args, const char *str); | ||
75 | void hmp_rocker(Monitor *mon, const QDict *qdict); | ||
76 | diff --git a/monitor.c b/monitor.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/monitor.c | ||
79 | +++ b/monitor.c | ||
80 | @@ -XXX,XX +XXX,XX @@ void migrate_set_parameter_completion(ReadLineState *rs, int nb_args, | ||
81 | } | ||
82 | } | ||
83 | |||
84 | -void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str) | ||
85 | -{ | ||
86 | - int i; | ||
87 | - size_t len; | ||
88 | - if (nb_args != 2) { | ||
89 | - return; | ||
90 | - } | ||
91 | - len = strlen(str); | ||
92 | - readline_set_completion_index(rs, len); | ||
93 | - for (i = 0; host_net_devices[i]; i++) { | ||
94 | - if (!strncmp(host_net_devices[i], str, len)) { | ||
95 | - readline_add_completion(rs, host_net_devices[i]); | ||
96 | - } | ||
97 | - } | ||
98 | -} | ||
99 | - | ||
100 | -void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str) | ||
101 | -{ | ||
102 | - NetClientState *ncs[MAX_QUEUE_NUM]; | ||
103 | - int count, i, len; | ||
104 | - | ||
105 | - len = strlen(str); | ||
106 | - readline_set_completion_index(rs, len); | ||
107 | - if (nb_args == 2) { | ||
108 | - count = qemu_find_net_clients_except(NULL, ncs, | ||
109 | - NET_CLIENT_DRIVER_NONE, | ||
110 | - MAX_QUEUE_NUM); | ||
111 | - for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) { | ||
112 | - int id; | ||
113 | - char name[16]; | ||
114 | - | ||
115 | - if (net_hub_id_for_client(ncs[i], &id)) { | ||
116 | - continue; | ||
117 | - } | ||
118 | - snprintf(name, sizeof(name), "%d", id); | ||
119 | - if (!strncmp(str, name, len)) { | ||
120 | - readline_add_completion(rs, name); | ||
121 | - } | ||
122 | - } | ||
123 | - return; | ||
124 | - } else if (nb_args == 3) { | ||
125 | - count = qemu_find_net_clients_except(NULL, ncs, | ||
126 | - NET_CLIENT_DRIVER_NIC, | ||
127 | - MAX_QUEUE_NUM); | ||
128 | - for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) { | ||
129 | - int id; | ||
130 | - const char *name; | ||
131 | - | ||
132 | - if (ncs[i]->info->type == NET_CLIENT_DRIVER_HUBPORT || | ||
133 | - net_hub_id_for_client(ncs[i], &id)) { | ||
134 | - continue; | ||
135 | - } | ||
136 | - name = ncs[i]->name; | ||
137 | - if (!strncmp(str, name, len)) { | ||
138 | - readline_add_completion(rs, name); | ||
139 | - } | ||
140 | - } | ||
141 | - return; | ||
142 | - } | ||
143 | -} | ||
144 | - | ||
145 | static void vm_completion(ReadLineState *rs, const char *str) | ||
146 | { | ||
147 | size_t len; | ||
148 | diff --git a/net/net.c b/net/net.c | ||
149 | index XXXXXXX..XXXXXXX 100644 | ||
150 | --- a/net/net.c | ||
151 | +++ b/net/net.c | ||
152 | @@ -XXX,XX +XXX,XX @@ | ||
153 | static VMChangeStateEntry *net_change_state_entry; | ||
154 | static QTAILQ_HEAD(, NetClientState) net_clients; | ||
155 | |||
156 | -const char *host_net_devices[] = { | ||
157 | - "tap", | ||
158 | - "socket", | ||
159 | -#ifdef CONFIG_NET_BRIDGE | ||
160 | - "bridge", | ||
161 | -#endif | ||
162 | -#ifdef CONFIG_NETMAP | ||
163 | - "netmap", | ||
164 | -#endif | ||
165 | -#ifdef CONFIG_SLIRP | ||
166 | - "user", | ||
167 | -#endif | ||
168 | -#ifdef CONFIG_VDE | ||
169 | - "vde", | ||
170 | -#endif | ||
171 | - "vhost-user", | ||
172 | - NULL, | ||
173 | -}; | ||
174 | - | ||
175 | /***********************************************************/ | ||
176 | /* network device redirectors */ | ||
177 | |||
178 | @@ -XXX,XX +XXX,XX @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) | ||
179 | return ret; | ||
180 | } | ||
181 | |||
182 | - | ||
183 | -static int net_host_check_device(const char *device) | ||
184 | -{ | ||
185 | - int i; | ||
186 | - for (i = 0; host_net_devices[i]; i++) { | ||
187 | - if (!strncmp(host_net_devices[i], device, | ||
188 | - strlen(host_net_devices[i]))) { | ||
189 | - return 1; | ||
190 | - } | ||
191 | - } | ||
192 | - | ||
193 | - return 0; | ||
194 | -} | ||
195 | - | ||
196 | -void hmp_host_net_add(Monitor *mon, const QDict *qdict) | ||
197 | -{ | ||
198 | - const char *device = qdict_get_str(qdict, "device"); | ||
199 | - const char *opts_str = qdict_get_try_str(qdict, "opts"); | ||
200 | - Error *local_err = NULL; | ||
201 | - QemuOpts *opts; | ||
202 | - static bool warned; | ||
203 | - | ||
204 | - if (!warned && !qtest_enabled()) { | ||
205 | - error_report("host_net_add is deprecated, use netdev_add instead"); | ||
206 | - warned = true; | ||
207 | - } | ||
208 | - | ||
209 | - if (!net_host_check_device(device)) { | ||
210 | - monitor_printf(mon, "invalid host network device %s\n", device); | ||
211 | - return; | ||
212 | - } | ||
213 | - | ||
214 | - opts = qemu_opts_parse_noisily(qemu_find_opts("net"), | ||
215 | - opts_str ? opts_str : "", false); | ||
216 | - if (!opts) { | ||
217 | - return; | ||
218 | - } | ||
219 | - | ||
220 | - qemu_opt_set(opts, "type", device, &error_abort); | ||
221 | - | ||
222 | - net_client_init(opts, false, &local_err); | ||
223 | - if (local_err) { | ||
224 | - error_report_err(local_err); | ||
225 | - monitor_printf(mon, "adding host network device %s failed\n", device); | ||
226 | - } | ||
227 | -} | ||
228 | - | ||
229 | -void hmp_host_net_remove(Monitor *mon, const QDict *qdict) | ||
230 | -{ | ||
231 | - NetClientState *nc; | ||
232 | - int vlan_id = qdict_get_int(qdict, "vlan_id"); | ||
233 | - const char *device = qdict_get_str(qdict, "device"); | ||
234 | - static bool warned; | ||
235 | - | ||
236 | - if (!warned && !qtest_enabled()) { | ||
237 | - error_report("host_net_remove is deprecated, use netdev_del instead"); | ||
238 | - warned = true; | ||
239 | - } | ||
240 | - | ||
241 | - nc = net_hub_find_client_by_name(vlan_id, device); | ||
242 | - if (!nc) { | ||
243 | - error_report("Host network device '%s' on hub '%d' not found", | ||
244 | - device, vlan_id); | ||
245 | - return; | ||
246 | - } | ||
247 | - if (nc->info->type == NET_CLIENT_DRIVER_NIC) { | ||
248 | - error_report("invalid host network device '%s'", device); | ||
249 | - return; | ||
250 | - } | ||
251 | - | ||
252 | - qemu_del_net_client(nc->peer); | ||
253 | - qemu_del_net_client(nc); | ||
254 | - qemu_opts_del(qemu_opts_find(qemu_find_opts("net"), device)); | ||
255 | -} | ||
256 | - | ||
257 | void netdev_add(QemuOpts *opts, Error **errp) | ||
258 | { | ||
259 | net_client_init(opts, true, errp); | ||
260 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
261 | index XXXXXXX..XXXXXXX 100644 | ||
262 | --- a/qemu-doc.texi | ||
263 | +++ b/qemu-doc.texi | ||
264 | @@ -XXX,XX +XXX,XX @@ from qcow2 images. | ||
265 | |||
266 | The ``query-cpus'' command is replaced by the ``query-cpus-fast'' command. | ||
267 | |||
268 | -@section System emulator human monitor commands | ||
269 | - | ||
270 | -@subsection host_net_add (since 2.10.0) | ||
271 | - | ||
272 | -The ``host_net_add'' command is replaced by the ``netdev_add'' command. | ||
273 | - | ||
274 | -@subsection host_net_remove (since 2.10.0) | ||
275 | - | ||
276 | -The ``host_net_remove'' command is replaced by the ``netdev_del'' command. | ||
277 | - | ||
278 | @section System emulator devices | ||
279 | |||
280 | @subsection ivshmem (since 2.6.0) | ||
281 | diff --git a/tests/test-hmp.c b/tests/test-hmp.c | ||
282 | index XXXXXXX..XXXXXXX 100644 | ||
283 | --- a/tests/test-hmp.c | ||
284 | +++ b/tests/test-hmp.c | ||
285 | @@ -XXX,XX +XXX,XX @@ static const char *hmp_cmds[] = { | ||
286 | "dump-guest-memory /dev/null 0 4096", | ||
287 | "dump-guest-memory /dev/null", | ||
288 | "gdbserver", | ||
289 | - "host_net_add user id=net0", | ||
290 | "hostfwd_add tcp::43210-:43210", | ||
291 | "hostfwd_remove tcp::43210-:43210", | ||
292 | - "host_net_remove 0 net0", | ||
293 | "i /w 0", | ||
294 | "log all", | ||
295 | "log none", | ||
296 | -- | ||
297 | 2.7.4 | ||
298 | |||
299 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
2 | 1 | ||
3 | The legacy "-net" option can be quite confusing for the users since most | ||
4 | people do not expect to get a "vlan" hub between their emulated guest | ||
5 | hardware and the host backend. But so far, we are also not able to get | ||
6 | rid of "-net" completely, since it is the only way to configure on-board | ||
7 | NICs that can not be instantiated via "-device" yet. It's also a little | ||
8 | bit shorter to type "-net nic -net tap" instead of "-device xyz,netdev=n1 | ||
9 | -netdev tap,id=n1". | ||
10 | |||
11 | So what we need is a new convenience option that is shorter to type than | ||
12 | the full -device + -netdev stuff, and which can be used to configure the | ||
13 | on-board NICs that can not be handled via -device yet. Thus this patch now | ||
14 | provides such a new option "--nic": It adds an entry in the nd_table to | ||
15 | configure a on-board / default NIC, creates a host backend and connects | ||
16 | the two directly, without a confusing "vlan" hub inbetween. | ||
17 | |||
18 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
19 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
20 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
21 | --- | ||
22 | include/sysemu/sysemu.h | 1 + | ||
23 | net/net.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ | ||
24 | qemu-options.hx | 40 +++++++++++++++++++++---- | ||
25 | vl.c | 7 +++++ | ||
26 | 4 files changed, 120 insertions(+), 6 deletions(-) | ||
27 | |||
28 | diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/include/sysemu/sysemu.h | ||
31 | +++ b/include/sysemu/sysemu.h | ||
32 | @@ -XXX,XX +XXX,XX @@ extern QemuOptsList bdrv_runtime_opts; | ||
33 | extern QemuOptsList qemu_chardev_opts; | ||
34 | extern QemuOptsList qemu_device_opts; | ||
35 | extern QemuOptsList qemu_netdev_opts; | ||
36 | +extern QemuOptsList qemu_nic_opts; | ||
37 | extern QemuOptsList qemu_net_opts; | ||
38 | extern QemuOptsList qemu_global_opts; | ||
39 | extern QemuOptsList qemu_mon_opts; | ||
40 | diff --git a/net/net.c b/net/net.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/net/net.c | ||
43 | +++ b/net/net.c | ||
44 | @@ -XXX,XX +XXX,XX @@ static int net_init_netdev(void *dummy, QemuOpts *opts, Error **errp) | ||
45 | return net_client_init(opts, true, errp); | ||
46 | } | ||
47 | |||
48 | +/* For the convenience "--nic" parameter */ | ||
49 | +static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp) | ||
50 | +{ | ||
51 | + char *mac, *nd_id; | ||
52 | + int idx, ret; | ||
53 | + NICInfo *ni; | ||
54 | + const char *type; | ||
55 | + | ||
56 | + type = qemu_opt_get(opts, "type"); | ||
57 | + if (type && g_str_equal(type, "none")) { | ||
58 | + return 0; /* Nothing to do, default_net is cleared in vl.c */ | ||
59 | + } | ||
60 | + | ||
61 | + idx = nic_get_free_idx(); | ||
62 | + if (idx == -1 || nb_nics >= MAX_NICS) { | ||
63 | + error_setg(errp, "no more on-board/default NIC slots available"); | ||
64 | + return -1; | ||
65 | + } | ||
66 | + | ||
67 | + if (!type) { | ||
68 | + qemu_opt_set(opts, "type", "user", &error_abort); | ||
69 | + } | ||
70 | + | ||
71 | + ni = &nd_table[idx]; | ||
72 | + memset(ni, 0, sizeof(*ni)); | ||
73 | + ni->model = qemu_opt_get_del(opts, "model"); | ||
74 | + | ||
75 | + /* Create an ID if the user did not specify one */ | ||
76 | + nd_id = g_strdup(qemu_opts_id(opts)); | ||
77 | + if (!nd_id) { | ||
78 | + nd_id = g_strdup_printf("__org.qemu.nic%i\n", idx); | ||
79 | + qemu_opts_set_id(opts, nd_id); | ||
80 | + } | ||
81 | + | ||
82 | + /* Handle MAC address */ | ||
83 | + mac = qemu_opt_get_del(opts, "mac"); | ||
84 | + if (mac) { | ||
85 | + ret = net_parse_macaddr(ni->macaddr.a, mac); | ||
86 | + g_free(mac); | ||
87 | + if (ret) { | ||
88 | + error_setg(errp, "invalid syntax for ethernet address"); | ||
89 | + return -1; | ||
90 | + } | ||
91 | + if (is_multicast_ether_addr(ni->macaddr.a)) { | ||
92 | + error_setg(errp, "NIC cannot have multicast MAC address"); | ||
93 | + return -1; | ||
94 | + } | ||
95 | + } | ||
96 | + qemu_macaddr_default_if_unset(&ni->macaddr); | ||
97 | + | ||
98 | + ret = net_client_init(opts, true, errp); | ||
99 | + if (ret == 0) { | ||
100 | + ni->netdev = qemu_find_netdev(nd_id); | ||
101 | + ni->used = true; | ||
102 | + nb_nics++; | ||
103 | + } | ||
104 | + | ||
105 | + g_free(nd_id); | ||
106 | + return ret; | ||
107 | +} | ||
108 | + | ||
109 | int net_init_clients(Error **errp) | ||
110 | { | ||
111 | net_change_state_entry = | ||
112 | @@ -XXX,XX +XXX,XX @@ int net_init_clients(Error **errp) | ||
113 | return -1; | ||
114 | } | ||
115 | |||
116 | + if (qemu_opts_foreach(qemu_find_opts("nic"), net_param_nic, NULL, errp)) { | ||
117 | + return -1; | ||
118 | + } | ||
119 | + | ||
120 | if (qemu_opts_foreach(qemu_find_opts("net"), net_init_client, NULL, errp)) { | ||
121 | return -1; | ||
122 | } | ||
123 | @@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_netdev_opts = { | ||
124 | }, | ||
125 | }; | ||
126 | |||
127 | +QemuOptsList qemu_nic_opts = { | ||
128 | + .name = "nic", | ||
129 | + .implied_opt_name = "type", | ||
130 | + .head = QTAILQ_HEAD_INITIALIZER(qemu_nic_opts.head), | ||
131 | + .desc = { | ||
132 | + /* | ||
133 | + * no elements => accept any params | ||
134 | + * validation will happen later | ||
135 | + */ | ||
136 | + { /* end of list */ } | ||
137 | + }, | ||
138 | +}; | ||
139 | + | ||
140 | QemuOptsList qemu_net_opts = { | ||
141 | .name = "net", | ||
142 | .implied_opt_name = "type", | ||
143 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
144 | index XXXXXXX..XXXXXXX 100644 | ||
145 | --- a/qemu-options.hx | ||
146 | +++ b/qemu-options.hx | ||
147 | @@ -XXX,XX +XXX,XX @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, | ||
148 | #endif | ||
149 | "-netdev hubport,id=str,hubid=n[,netdev=nd]\n" | ||
150 | " configure a hub port on QEMU VLAN 'n'\n", QEMU_ARCH_ALL) | ||
151 | +DEF("nic", HAS_ARG, QEMU_OPTION_nic, | ||
152 | + "--nic [tap|bridge|" | ||
153 | +#ifdef CONFIG_SLIRP | ||
154 | + "user|" | ||
155 | +#endif | ||
156 | +#ifdef __linux__ | ||
157 | + "l2tpv3|" | ||
158 | +#endif | ||
159 | +#ifdef CONFIG_VDE | ||
160 | + "vde|" | ||
161 | +#endif | ||
162 | +#ifdef CONFIG_NETMAP | ||
163 | + "netmap|" | ||
164 | +#endif | ||
165 | +#ifdef CONFIG_POSIX | ||
166 | + "vhost-user|" | ||
167 | +#endif | ||
168 | + "socket][,option][,...][mac=macaddr]\n" | ||
169 | + " initialize an on-board / default host NIC (using MAC address\n" | ||
170 | + " macaddr) and connect it to the given host network backend\n" | ||
171 | + "--nic none use it alone to have zero network devices (the default is to\n" | ||
172 | + " provided a 'user' network connection)\n", | ||
173 | + QEMU_ARCH_ALL) | ||
174 | DEF("net", HAS_ARG, QEMU_OPTION_net, | ||
175 | "-net nic[,vlan=n][,netdev=nd][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n" | ||
176 | " configure or create an on-board (or machine default) NIC and\n" | ||
177 | " connect it either to VLAN 'n' or the netdev 'nd' (for pluggable\n" | ||
178 | " NICs please use '-device devtype,netdev=nd' instead)\n" | ||
179 | - "-net none use it alone to have zero network devices. If no -net option\n" | ||
180 | - " is provided, the default is '-net nic -net user'\n" | ||
181 | "-net [" | ||
182 | #ifdef CONFIG_SLIRP | ||
183 | "user|" | ||
184 | @@ -XXX,XX +XXX,XX @@ qemu -m 512 -object memory-backend-file,id=mem,size=512M,mem-path=/hugetlbfs,sha | ||
185 | -device virtio-net-pci,netdev=net0 | ||
186 | @end example | ||
187 | |||
188 | -@item -net none | ||
189 | -Indicate that no network devices should be configured. It is used to | ||
190 | -override the default configuration (@option{-net nic -net user}) which | ||
191 | -is activated if no @option{-net} options are provided. | ||
192 | +@item --nic [tap|bridge|user|l2tpv3|vde|netmap|vhost-user|socket][,...][,mac=macaddr] | ||
193 | + | ||
194 | +This option is a shortcut for setting both, the on-board (default) guest NIC | ||
195 | +hardware and the host network backend in one go. The host backend options are | ||
196 | +the same as with the corresponding @option{--netdev} option. The guest NIC | ||
197 | +hardware MAC address can be set with @option{mac=@var{macaddr}}. | ||
198 | + | ||
199 | +@item --nic none | ||
200 | +Indicate that no network devices should be configured. It is used to override | ||
201 | +the default configuration (default NIC with @option{--net user} backend) which | ||
202 | +is activated if no other networking options are provided. | ||
203 | ETEXI | ||
204 | |||
205 | STEXI | ||
206 | diff --git a/vl.c b/vl.c | ||
207 | index XXXXXXX..XXXXXXX 100644 | ||
208 | --- a/vl.c | ||
209 | +++ b/vl.c | ||
210 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
211 | qemu_add_opts(&qemu_chardev_opts); | ||
212 | qemu_add_opts(&qemu_device_opts); | ||
213 | qemu_add_opts(&qemu_netdev_opts); | ||
214 | + qemu_add_opts(&qemu_nic_opts); | ||
215 | qemu_add_opts(&qemu_net_opts); | ||
216 | qemu_add_opts(&qemu_rtc_opts); | ||
217 | qemu_add_opts(&qemu_global_opts); | ||
218 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
219 | exit(1); | ||
220 | } | ||
221 | break; | ||
222 | + case QEMU_OPTION_nic: | ||
223 | + default_net = 0; | ||
224 | + if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) { | ||
225 | + exit(1); | ||
226 | + } | ||
227 | + break; | ||
228 | case QEMU_OPTION_net: | ||
229 | default_net = 0; | ||
230 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { | ||
231 | -- | ||
232 | 2.7.4 | ||
233 | |||
234 | diff view generated by jsdifflib |
1 | From: Jay Zhou <jianjay.zhou@huawei.com> | 1 | From: Keqian Zhu <zhukeqian1@huawei.com> |
---|---|---|---|
2 | 2 | ||
3 | If netdev_add tap,id=net0,...,vhost=on failed in net_init_tap_one(), | 3 | Fixes: 63c4db4c2e6d (net: relocate paths to helpers and scripts) |
4 | the followed up device_add virtio-net-pci,netdev=net0 will fail | 4 | Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> |
5 | too, prints: | ||
6 | |||
7 | TUNSETOFFLOAD ioctl() failed: Bad file descriptor TUNSETOFFLOAD | ||
8 | ioctl() failed: Bad file descriptor | ||
9 | |||
10 | The reason is that the fd of tap is closed when error occured after | ||
11 | calling net_init_tap_one(). | ||
12 | |||
13 | The fd should be closed when calling net_init_tap_one failed: | ||
14 | - if tap_set_sndbuf() failed | ||
15 | - if tap_set_sndbuf() succeeded but vhost failed to open or | ||
16 | initialize with vhostforce flag on | ||
17 | - with wrong vhost command line parameter | ||
18 | The fd should not be closed just because vhost failed to open or | ||
19 | initialize but without vhostforce flag. So the followed up | ||
20 | device_add can fall back to userspace virtio successfully. | ||
21 | |||
22 | Suggested-by: Michael S. Tsirkin <mst@redhat.com> | ||
23 | Suggested-by: Igor Mammedov <imammedo@redhat.com> | ||
24 | Suggested-by: Jason Wang <jasowang@redhat.com> | ||
25 | Signed-off-by: Jay Zhou <jianjay.zhou@huawei.com> | ||
26 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 5 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
27 | --- | 6 | --- |
28 | include/net/vhost_net.h | 3 +++ | 7 | net/tap.c | 3 ++- |
29 | net/tap.c | 22 +++++++++++++++++----- | 8 | 1 file changed, 2 insertions(+), 1 deletion(-) |
30 | 2 files changed, 20 insertions(+), 5 deletions(-) | ||
31 | 9 | ||
32 | diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/include/net/vhost_net.h | ||
35 | +++ b/include/net/vhost_net.h | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | #include "net/net.h" | ||
38 | #include "hw/virtio/vhost-backend.h" | ||
39 | |||
40 | +#define VHOST_NET_INIT_FAILED \ | ||
41 | + "vhost-net requested but could not be initialized" | ||
42 | + | ||
43 | struct vhost_net; | ||
44 | typedef struct vhost_net VHostNetState; | ||
45 | |||
46 | diff --git a/net/tap.c b/net/tap.c | 10 | diff --git a/net/tap.c b/net/tap.c |
47 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/net/tap.c | 12 | --- a/net/tap.c |
49 | +++ b/net/tap.c | 13 | +++ b/net/tap.c |
50 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | 14 | @@ -XXX,XX +XXX,XX @@ free_fail: |
51 | if (vhostfdname) { | 15 | script = default_script = get_relocated_path(DEFAULT_NETWORK_SCRIPT); |
52 | vhostfd = monitor_fd_param(cur_mon, vhostfdname, &err); | ||
53 | if (vhostfd == -1) { | ||
54 | - error_propagate(errp, err); | ||
55 | + if (tap->has_vhostforce && tap->vhostforce) { | ||
56 | + error_propagate(errp, err); | ||
57 | + } else { | ||
58 | + warn_report_err(err); | ||
59 | + } | ||
60 | return; | ||
61 | } | ||
62 | } else { | ||
63 | vhostfd = open("/dev/vhost-net", O_RDWR); | ||
64 | if (vhostfd < 0) { | ||
65 | - error_setg_errno(errp, errno, | ||
66 | - "tap: open vhost char device failed"); | ||
67 | + if (tap->has_vhostforce && tap->vhostforce) { | ||
68 | + error_setg_errno(errp, errno, | ||
69 | + "tap: open vhost char device failed"); | ||
70 | + } else { | ||
71 | + warn_report("tap: open vhost char device failed: %s", | ||
72 | + strerror(errno)); | ||
73 | + } | ||
74 | return; | ||
75 | } | ||
76 | fcntl(vhostfd, F_SETFL, O_NONBLOCK); | ||
77 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
78 | |||
79 | s->vhost_net = vhost_net_init(&options); | ||
80 | if (!s->vhost_net) { | ||
81 | - error_setg(errp, | ||
82 | - "vhost-net requested but could not be initialized"); | ||
83 | + if (tap->has_vhostforce && tap->vhostforce) { | ||
84 | + error_setg(errp, VHOST_NET_INIT_FAILED); | ||
85 | + } else { | ||
86 | + warn_report(VHOST_NET_INIT_FAILED); | ||
87 | + } | ||
88 | return; | ||
89 | } | 16 | } |
90 | } else if (vhostfdname) { | 17 | if (!downscript) { |
18 | - downscript = default_downscript = get_relocated_path(DEFAULT_NETWORK_SCRIPT); | ||
19 | + downscript = default_downscript = | ||
20 | + get_relocated_path(DEFAULT_NETWORK_DOWN_SCRIPT); | ||
21 | } | ||
22 | |||
23 | if (tap->has_ifname) { | ||
91 | -- | 24 | -- |
92 | 2.7.4 | 25 | 2.7.4 |
93 | 26 | ||
94 | 27 | diff view generated by jsdifflib |