1
The following changes since commit 6632f6ff96f0537fc34cdc00c760656fc62e23c5:
1
The following changes since commit 7fe7fae8b48e3f9c647fd685e5155ebc8e6fb84d:
2
2
3
Merge remote-tracking branch 'remotes/famz/tags/block-and-testing-pull-request' into staging (2017-07-17 11:46:36 +0100)
3
Merge remote-tracking branch 'remotes/dgilbert-gitlab/tags/pull-migration-20210609a' into staging (2021-06-09 16:40:21 +0100)
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 189ae6bb5ce1f5a322f8691d00fe942ba43dd601:
9
for you to fetch changes up to 5a2d9929ac1f01a1e8ef2a3f56f69e6069863dad:
10
10
11
virtio-net: fix offload ctrl endian (2017-07-17 20:13:56 +0800)
11
Fixed calculation error of pkt->header_size in fill_pkt_tcp_info() (2021-06-11 10:30:13 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
14
15
- fix virtio-net ctrl offload endian
15
----------------------------------------------------------------
16
- vnet header support for variou COLO netfilters and compare thread
16
Jason Wang (4):
17
vhost-vdpa: skip ram device from the IOTLB mapping
18
vhost-vdpa: map virtqueue notification area if possible
19
vhost-vdpa: don't initialize backend_features
20
vhost-vdpa: remove the unused vhost_vdpa_get_acked_features()
17
21
18
----------------------------------------------------------------
22
Paolo Bonzini (1):
19
Jason Wang (1):
23
netdev: add more commands to preconfig mode
20
virtio-net: fix offload ctrl endian
21
24
22
Michal Privoznik (1):
25
Rao, Lei (7):
23
virtion-net: Prefer is_power_of_2()
26
Remove some duplicate trace code.
27
Fix the qemu crash when guest shutdown during checkpoint
28
Optimize the function of filter_send
29
Remove migrate_set_block_enabled in checkpoint
30
Add a function named packet_new_nocopy for COLO.
31
Add the function of colo_compare_cleanup
32
Fixed calculation error of pkt->header_size in fill_pkt_tcp_info()
24
33
25
Zhang Chen (12):
34
hmp-commands.hx | 2 +
26
net: Add vnet_hdr_len arguments in NetClientState
35
hw/virtio/vhost-vdpa.c | 100 +++++++++++++++++++++++++++++++++++------
27
net/net.c: Add vnet_hdr support in SocketReadState
36
include/hw/virtio/vhost-vdpa.h | 6 +++
28
net/filter-mirror.c: Introduce parameter for filter_send()
37
include/net/vhost-vdpa.h | 1 -
29
net/filter-mirror.c: Make filter mirror support vnet support.
38
migration/colo.c | 6 ---
30
net/filter-mirror.c: Add new option to enable vnet support for filter-redirector
39
migration/migration.c | 4 ++
31
net/colo.c: Make vnet_hdr_len as packet property
40
net/colo-compare.c | 25 +++++------
32
net/colo-compare.c: Introduce parameter for compare_chr_send()
41
net/colo-compare.h | 1 +
33
net/colo-compare.c: Make colo-compare support vnet_hdr_len
42
net/colo.c | 25 +++++++----
34
net/colo.c: Add vnet packet parse feature in colo-proxy
43
net/colo.h | 1 +
35
net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare
44
net/filter-mirror.c | 8 ++--
36
net/filter-rewriter.c: Make filter-rewriter support vnet_hdr_len
45
net/filter-rewriter.c | 3 +-
37
docs/colo-proxy.txt: Update colo-proxy usage of net driver with vnet_header
46
net/net.c | 4 ++
38
47
net/vhost-vdpa.c | 9 ----
39
docs/colo-proxy.txt | 26 ++++++++++++++++
48
qapi/net.json | 6 ++-
40
hw/net/virtio-net.c | 4 ++-
49
softmmu/runstate.c | 1 +
41
include/net/net.h | 10 ++++--
50
16 files changed, 143 insertions(+), 59 deletions(-)
42
net/colo-compare.c | 84 ++++++++++++++++++++++++++++++++++++++++++---------
43
net/colo.c | 9 +++---
44
net/colo.h | 4 ++-
45
net/filter-mirror.c | 75 +++++++++++++++++++++++++++++++++++++++++----
46
net/filter-rewriter.c | 37 ++++++++++++++++++++++-
47
net/net.c | 37 ++++++++++++++++++++---
48
net/socket.c | 8 ++---
49
qemu-options.hx | 19 ++++++------
50
11 files changed, 265 insertions(+), 48 deletions(-)
51
51
52
52
53
54
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
vDPA is not tie to any specific hardware, for safety and simplicity,
2
vhost-vDPA doesn't allow MMIO area to be mapped via IOTLB. Only the
3
doorbell could be mapped via mmap(). So this patch exclude skip the
4
ram device from the IOTLB mapping.
2
5
3
COLO-Proxy just focus on packet payload, so we skip vnet header.
6
Reviewed-by: Si-Wei Liu <si-wei.liu@oracle.com>
4
5
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
---
8
---
8
net/colo-compare.c | 8 ++++++--
9
hw/virtio/vhost-vdpa.c | 12 ++----------
9
1 file changed, 6 insertions(+), 2 deletions(-)
10
1 file changed, 2 insertions(+), 10 deletions(-)
10
11
11
diff --git a/net/colo-compare.c b/net/colo-compare.c
12
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
12
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
13
--- a/net/colo-compare.c
14
--- a/hw/virtio/vhost-vdpa.c
14
+++ b/net/colo-compare.c
15
+++ b/hw/virtio/vhost-vdpa.c
15
@@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offset)
16
@@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section)
16
sec_ip_src, sec_ip_dst);
17
{
18
return (!memory_region_is_ram(section->mr) &&
19
!memory_region_is_iommu(section->mr)) ||
20
+ /* vhost-vDPA doesn't allow MMIO to be mapped */
21
+ memory_region_is_ram_device(section->mr) ||
22
/*
23
* Sizing an enabled 64-bit BAR can cause spurious mappings to
24
* addresses in the upper part of the 64-bit address space. These
25
@@ -XXX,XX +XXX,XX @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener,
26
vaddr, section->readonly);
27
if (ret) {
28
error_report("vhost vdpa map fail!");
29
- if (memory_region_is_ram_device(section->mr)) {
30
- /* Allow unexpected mappings not to be fatal for RAM devices */
31
- error_report("map ram fail!");
32
- return ;
33
- }
34
goto fail;
17
}
35
}
18
36
19
+ offset = ppkt->vnet_hdr_len + offset;
37
return;
20
+
38
21
if (ppkt->size == spkt->size) {
39
fail:
22
- return memcmp(ppkt->data + offset, spkt->data + offset,
40
- if (memory_region_is_ram_device(section->mr)) {
23
+ return memcmp(ppkt->data + offset,
41
- error_report("failed to vdpa_dma_map. pci p2p may not work");
24
+ spkt->data + offset,
42
- return;
25
spkt->size - offset);
43
-
26
} else {
44
- }
27
trace_colo_compare_main("Net packet size are not the same");
45
/*
28
@@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
46
* On the initfn path, store the first error in the container so we
29
*/
47
* can gracefully fail. Runtime, there's not much we can do other
30
if (ptcp->th_off > 5) {
31
ptrdiff_t tcp_offset;
32
+
33
tcp_offset = ppkt->transport_header - (uint8_t *)ppkt->data
34
- + (ptcp->th_off * 4);
35
+ + (ptcp->th_off * 4) - ppkt->vnet_hdr_len;
36
res = colo_packet_compare_common(ppkt, spkt, tcp_offset);
37
} else if (ptcp->th_sum == stcp->th_sum) {
38
res = colo_packet_compare_common(ppkt, spkt, ETH_HLEN);
39
--
48
--
40
2.7.4
49
2.7.4
41
50
42
51
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
This patch implements the vq notification mapping support for
2
vhost-vDPA. This is simply done by using mmap()/munmap() for the
3
vhost-vDPA fd during device start/stop. For the device without
4
notification mapping support, we fall back to eventfd based
5
notification gracefully.
2
6
3
We add the vnet_hdr_support option for filter-mirror, default is disabled.
7
Reviewed-by: Si-Wei Liu <si-wei.liu@oracle.com>
4
If you use virtio-net-pci or other driver needs vnet_hdr, please enable it.
5
You can use it for example:
6
-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support
7
8
If it has vnet_hdr_support flag, we will change the sending packet format from
9
struct {int size; const uint8_t buf[];} to {int size; int vnet_hdr_len; const uint8_t buf[];}.
10
make other module(like colo-compare) know how to parse net packet correctly.
11
12
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
Signed-off-by: Jason Wang <jasowang@redhat.com>
14
---
9
---
15
net/filter-mirror.c | 42 +++++++++++++++++++++++++++++++++++++++++-
10
hw/virtio/vhost-vdpa.c | 85 ++++++++++++++++++++++++++++++++++++++++++
16
qemu-options.hx | 5 ++---
11
include/hw/virtio/vhost-vdpa.h | 6 +++
17
2 files changed, 43 insertions(+), 4 deletions(-)
12
2 files changed, 91 insertions(+)
18
13
19
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
14
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
20
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
21
--- a/net/filter-mirror.c
16
--- a/hw/virtio/vhost-vdpa.c
22
+++ b/net/filter-mirror.c
17
+++ b/hw/virtio/vhost-vdpa.c
23
@@ -XXX,XX +XXX,XX @@ typedef struct MirrorState {
18
@@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)
24
CharBackend chr_in;
19
return 0;
25
CharBackend chr_out;
20
}
26
SocketReadState rs;
21
27
+ bool vnet_hdr;
22
+static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev,
28
} MirrorState;
23
+ int queue_index)
29
24
+{
30
static int filter_send(MirrorState *s,
25
+ size_t page_size = qemu_real_host_page_size;
31
const struct iovec *iov,
26
+ struct vhost_vdpa *v = dev->opaque;
32
int iovcnt)
27
+ VirtIODevice *vdev = dev->vdev;
33
{
28
+ VhostVDPAHostNotifier *n;
34
+ NetFilterState *nf = NETFILTER(s);
35
int ret = 0;
36
ssize_t size = 0;
37
uint32_t len = 0;
38
@@ -XXX,XX +XXX,XX @@ static int filter_send(MirrorState *s,
39
goto err;
40
}
41
42
+ if (s->vnet_hdr) {
43
+ /*
44
+ * If vnet_hdr = on, we send vnet header len to make other
45
+ * module(like colo-compare) know how to parse net
46
+ * packet correctly.
47
+ */
48
+ ssize_t vnet_hdr_len;
49
+
29
+
50
+ vnet_hdr_len = nf->netdev->vnet_hdr_len;
30
+ n = &v->notifier[queue_index];
51
+
31
+
52
+ len = htonl(vnet_hdr_len);
32
+ if (n->addr) {
53
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
33
+ virtio_queue_set_host_notifier_mr(vdev, queue_index, &n->mr, false);
54
+ if (ret != sizeof(len)) {
34
+ object_unparent(OBJECT(&n->mr));
35
+ munmap(n->addr, page_size);
36
+ n->addr = NULL;
37
+ }
38
+}
39
+
40
+static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
41
+{
42
+ int i;
43
+
44
+ for (i = 0; i < n; i++) {
45
+ vhost_vdpa_host_notifier_uninit(dev, i);
46
+ }
47
+}
48
+
49
+static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index)
50
+{
51
+ size_t page_size = qemu_real_host_page_size;
52
+ struct vhost_vdpa *v = dev->opaque;
53
+ VirtIODevice *vdev = dev->vdev;
54
+ VhostVDPAHostNotifier *n;
55
+ int fd = v->device_fd;
56
+ void *addr;
57
+ char *name;
58
+
59
+ vhost_vdpa_host_notifier_uninit(dev, queue_index);
60
+
61
+ n = &v->notifier[queue_index];
62
+
63
+ addr = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED, fd,
64
+ queue_index * page_size);
65
+ if (addr == MAP_FAILED) {
66
+ goto err;
67
+ }
68
+
69
+ name = g_strdup_printf("vhost-vdpa/host-notifier@%p mmaps[%d]",
70
+ v, queue_index);
71
+ memory_region_init_ram_device_ptr(&n->mr, OBJECT(vdev), name,
72
+ page_size, addr);
73
+ g_free(name);
74
+
75
+ if (virtio_queue_set_host_notifier_mr(vdev, queue_index, &n->mr, true)) {
76
+ munmap(addr, page_size);
77
+ goto err;
78
+ }
79
+ n->addr = addr;
80
+
81
+ return 0;
82
+
83
+err:
84
+ return -1;
85
+}
86
+
87
+static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev)
88
+{
89
+ int i;
90
+
91
+ for (i = dev->vq_index; i < dev->vq_index + dev->nvqs; i++) {
92
+ if (vhost_vdpa_host_notifier_init(dev, i)) {
55
+ goto err;
93
+ goto err;
56
+ }
94
+ }
57
+ }
95
+ }
58
+
96
+
59
buf = g_malloc(size);
97
+ return;
60
iov_to_buf(iov, iovcnt, 0, buf, size);
61
ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
62
@@ -XXX,XX +XXX,XX @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp)
63
}
64
}
65
66
- net_socket_rs_init(&s->rs, redirector_rs_finalize, false);
67
+ net_socket_rs_init(&s->rs, redirector_rs_finalize, s->vnet_hdr);
68
69
if (s->indev) {
70
chr = qemu_chr_find(s->indev);
71
@@ -XXX,XX +XXX,XX @@ static void filter_mirror_set_outdev(Object *obj,
72
}
73
}
74
75
+static bool filter_mirror_get_vnet_hdr(Object *obj, Error **errp)
76
+{
77
+ MirrorState *s = FILTER_MIRROR(obj);
78
+
98
+
79
+ return s->vnet_hdr;
99
+err:
100
+ vhost_vdpa_host_notifiers_uninit(dev, i);
101
+ return;
80
+}
102
+}
81
+
103
+
82
+static void filter_mirror_set_vnet_hdr(Object *obj, bool value, Error **errp)
104
static int vhost_vdpa_cleanup(struct vhost_dev *dev)
83
+{
105
{
84
+ MirrorState *s = FILTER_MIRROR(obj);
106
struct vhost_vdpa *v;
107
assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
108
v = dev->opaque;
109
trace_vhost_vdpa_cleanup(dev, v);
110
+ vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs);
111
memory_listener_unregister(&v->listener);
112
113
dev->opaque = NULL;
114
@@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
115
if (started) {
116
uint8_t status = 0;
117
memory_listener_register(&v->listener, &address_space_memory);
118
+ vhost_vdpa_host_notifiers_init(dev);
119
vhost_vdpa_set_vring_ready(dev);
120
vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
121
vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
122
@@ -XXX,XX +XXX,XX @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
123
vhost_vdpa_reset_device(dev);
124
vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
125
VIRTIO_CONFIG_S_DRIVER);
126
+ vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs);
127
memory_listener_unregister(&v->listener);
128
129
return 0;
130
diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
131
index XXXXXXX..XXXXXXX 100644
132
--- a/include/hw/virtio/vhost-vdpa.h
133
+++ b/include/hw/virtio/vhost-vdpa.h
134
@@ -XXX,XX +XXX,XX @@
135
136
#include "hw/virtio/virtio.h"
137
138
+typedef struct VhostVDPAHostNotifier {
139
+ MemoryRegion mr;
140
+ void *addr;
141
+} VhostVDPAHostNotifier;
85
+
142
+
86
+ s->vnet_hdr = value;
143
typedef struct vhost_vdpa {
87
+}
144
int device_fd;
88
+
145
uint32_t msg_type;
89
static char *filter_redirector_get_outdev(Object *obj, Error **errp)
146
MemoryListener listener;
90
{
147
struct vhost_dev *dev;
91
MirrorState *s = FILTER_REDIRECTOR(obj);
148
+ VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
92
@@ -XXX,XX +XXX,XX @@ static void filter_redirector_set_outdev(Object *obj,
149
} VhostVDPA;
93
150
94
static void filter_mirror_init(Object *obj)
151
#endif
95
{
96
+ MirrorState *s = FILTER_MIRROR(obj);
97
+
98
object_property_add_str(obj, "outdev", filter_mirror_get_outdev,
99
filter_mirror_set_outdev, NULL);
100
+
101
+ s->vnet_hdr = false;
102
+ object_property_add_bool(obj, "vnet_hdr_support",
103
+ filter_mirror_get_vnet_hdr,
104
+ filter_mirror_set_vnet_hdr, NULL);
105
}
106
107
static void filter_redirector_init(Object *obj)
108
diff --git a/qemu-options.hx b/qemu-options.hx
109
index XXXXXXX..XXXXXXX 100644
110
--- a/qemu-options.hx
111
+++ b/qemu-options.hx
112
@@ -XXX,XX +XXX,XX @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter.
113
@option{tx}: the filter is attached to the transmit queue of the netdev,
114
where it will receive packets sent by the netdev.
115
116
-@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid}[,queue=@var{all|rx|tx}]
117
+@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support]
118
119
-filter-mirror on netdev @var{netdevid},mirror net packet to chardev
120
-@var{chardevid}
121
+filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if it has the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len.
122
123
@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},
124
outdev=@var{chardevid}[,queue=@var{all|rx|tx}]
125
--
152
--
126
2.7.4
153
2.7.4
127
154
128
155
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
We used to initialize backend_features during vhost_vdpa_init()
2
regardless whether or not it was supported by vhost. This will lead
3
the unsupported features like VIRTIO_F_IN_ORDER to be included and set
4
to the vhost-vdpa during vhost_dev_start. Because the
5
VIRTIO_F_IN_ORDER is not supported by vhost-vdpa so it won't be
6
advertised to guest which will break the datapath.
2
7
3
Add vnet_hdr_len arguments in NetClientState
8
Fix this by not initializing the backend_features, so the
4
that make other module get real vnet_hdr_len easily.
9
acked_features could be built only from guest features via
10
vhost_net_ack_features().
5
11
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
12
Fixes: 108a64818e69b ("vhost-vdpa: introduce vhost-vdpa backend")
13
Cc: qemu-stable@nongnu.org
14
Cc: Gautam Dawar <gdawar@xilinx.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
15
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
16
---
9
include/net/net.h | 1 +
17
hw/virtio/vhost-vdpa.c | 3 ---
10
net/net.c | 1 +
18
1 file changed, 3 deletions(-)
11
2 files changed, 2 insertions(+)
12
19
13
diff --git a/include/net/net.h b/include/net/net.h
20
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
14
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
15
--- a/include/net/net.h
22
--- a/hw/virtio/vhost-vdpa.c
16
+++ b/include/net/net.h
23
+++ b/hw/virtio/vhost-vdpa.c
17
@@ -XXX,XX +XXX,XX @@ struct NetClientState {
24
@@ -XXX,XX +XXX,XX @@ static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
18
unsigned int queue_index;
25
static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)
19
unsigned rxfilter_notify_enabled:1;
26
{
20
int vring_enable;
27
struct vhost_vdpa *v;
21
+ int vnet_hdr_len;
28
- uint64_t features;
22
QTAILQ_HEAD(NetFilterHead, NetFilterState) filters;
29
assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
23
};
30
trace_vhost_vdpa_init(dev, opaque);
24
31
25
diff --git a/net/net.c b/net/net.c
32
v = opaque;
26
index XXXXXXX..XXXXXXX 100644
33
v->dev = dev;
27
--- a/net/net.c
34
dev->opaque = opaque ;
28
+++ b/net/net.c
35
- vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features);
29
@@ -XXX,XX +XXX,XX @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len)
36
- dev->backend_features = features;
30
return;
37
v->listener = vhost_vdpa_memory_listener;
31
}
38
v->msg_type = VHOST_IOTLB_MSG_V2;
32
33
+ nc->vnet_hdr_len = len;
34
nc->info->set_vnet_hdr_len(nc, len);
35
}
36
39
37
--
40
--
38
2.7.4
41
2.7.4
39
42
40
43
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
No user for this helper, let's remove it.
2
2
3
We add the vnet_hdr_support option for filter-rewriter, default is disabled.
4
If you use virtio-net-pci or other driver needs vnet_hdr, please enable it.
5
You can use it for example:
6
-object filter-rewriter,id=rew0,netdev=hn0,queue=all,vnet_hdr_support
7
8
We get the vnet_hdr_len from NetClientState that make us
9
parse net packet correctly.
10
11
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
12
Signed-off-by: Jason Wang <jasowang@redhat.com>
3
Signed-off-by: Jason Wang <jasowang@redhat.com>
13
---
4
---
14
net/filter-rewriter.c | 37 ++++++++++++++++++++++++++++++++++++-
5
include/net/vhost-vdpa.h | 1 -
15
qemu-options.hx | 4 ++--
6
net/vhost-vdpa.c | 9 ---------
16
2 files changed, 38 insertions(+), 3 deletions(-)
7
2 files changed, 10 deletions(-)
17
8
18
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
9
diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h
19
index XXXXXXX..XXXXXXX 100644
10
index XXXXXXX..XXXXXXX 100644
20
--- a/net/filter-rewriter.c
11
--- a/include/net/vhost-vdpa.h
21
+++ b/net/filter-rewriter.c
12
+++ b/include/net/vhost-vdpa.h
22
@@ -XXX,XX +XXX,XX @@
13
@@ -XXX,XX +XXX,XX @@
23
#include "qemu-common.h"
14
#define TYPE_VHOST_VDPA "vhost-vdpa"
24
#include "qapi/error.h"
15
25
#include "qapi/qmp/qerror.h"
16
struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc);
26
+#include "qemu/error-report.h"
17
-uint64_t vhost_vdpa_get_acked_features(NetClientState *nc);
27
#include "qapi-visit.h"
18
28
#include "qom/object.h"
19
extern const int vdpa_feature_bits[];
29
#include "qemu/main-loop.h"
20
30
@@ -XXX,XX +XXX,XX @@ typedef struct RewriterState {
21
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
31
NetQueue *incoming_queue;
22
index XXXXXXX..XXXXXXX 100644
32
/* hashtable to save connection */
23
--- a/net/vhost-vdpa.c
33
GHashTable *connection_track_table;
24
+++ b/net/vhost-vdpa.c
34
+ bool vnet_hdr;
25
@@ -XXX,XX +XXX,XX @@ VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc)
35
} RewriterState;
26
return s->vhost_net;
36
37
static void filter_rewriter_flush(NetFilterState *nf)
38
@@ -XXX,XX +XXX,XX @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
39
ConnectionKey key;
40
Packet *pkt;
41
ssize_t size = iov_size(iov, iovcnt);
42
+ ssize_t vnet_hdr_len = 0;
43
char *buf = g_malloc0(size);
44
45
iov_to_buf(iov, iovcnt, 0, buf, size);
46
- pkt = packet_new(buf, size, 0);
47
+
48
+ if (s->vnet_hdr) {
49
+ vnet_hdr_len = nf->netdev->vnet_hdr_len;
50
+ }
51
+
52
+ pkt = packet_new(buf, size, vnet_hdr_len);
53
g_free(buf);
54
55
/*
56
@@ -XXX,XX +XXX,XX @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp)
57
s->incoming_queue = qemu_new_net_queue(qemu_netfilter_pass_to_next, nf);
58
}
27
}
59
28
60
+static bool filter_rewriter_get_vnet_hdr(Object *obj, Error **errp)
29
-uint64_t vhost_vdpa_get_acked_features(NetClientState *nc)
61
+{
30
-{
62
+ RewriterState *s = FILTER_COLO_REWRITER(obj);
31
- VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
63
+
32
- assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);
64
+ return s->vnet_hdr;
33
- s->acked_features = vhost_net_get_acked_features(s->vhost_net);
65
+}
34
-
66
+
35
- return s->acked_features;
67
+static void filter_rewriter_set_vnet_hdr(Object *obj,
36
-}
68
+ bool value,
37
-
69
+ Error **errp)
38
static int vhost_vdpa_net_check_device_id(struct vhost_net *net)
70
+{
71
+ RewriterState *s = FILTER_COLO_REWRITER(obj);
72
+
73
+ s->vnet_hdr = value;
74
+}
75
+
76
+static void filter_rewriter_init(Object *obj)
77
+{
78
+ RewriterState *s = FILTER_COLO_REWRITER(obj);
79
+
80
+ s->vnet_hdr = false;
81
+ object_property_add_bool(obj, "vnet_hdr_support",
82
+ filter_rewriter_get_vnet_hdr,
83
+ filter_rewriter_set_vnet_hdr, NULL);
84
+}
85
+
86
static void colo_rewriter_class_init(ObjectClass *oc, void *data)
87
{
39
{
88
NetFilterClass *nfc = NETFILTER_CLASS(oc);
40
uint32_t device_id;
89
@@ -XXX,XX +XXX,XX @@ static const TypeInfo colo_rewriter_info = {
90
.name = TYPE_FILTER_REWRITER,
91
.parent = TYPE_NETFILTER,
92
.class_init = colo_rewriter_class_init,
93
+ .instance_init = filter_rewriter_init,
94
.instance_size = sizeof(RewriterState),
95
};
96
97
diff --git a/qemu-options.hx b/qemu-options.hx
98
index XXXXXXX..XXXXXXX 100644
99
--- a/qemu-options.hx
100
+++ b/qemu-options.hx
101
@@ -XXX,XX +XXX,XX @@ Create a filter-redirector we need to differ outdev id from indev id, id can not
102
be the same. we can just use indev or outdev, but at least one of indev or outdev
103
need to be specified.
104
105
-@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid}[,queue=@var{all|rx|tx}]
106
+@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},queue=@var{all|rx|tx},[vnet_hdr_support]
107
108
Filter-rewriter is a part of COLO project.It will rewrite tcp packet to
109
secondary from primary to keep secondary tcp connection,and rewrite
110
tcp packet to primary from secondary make tcp packet can be handled by
111
-client.
112
+client.if it has the vnet_hdr_support flag, we can parse packet with vnet header.
113
114
usage:
115
colo secondary:
116
--
41
--
117
2.7.4
42
2.7.4
118
43
119
44
diff view generated by jsdifflib
1
Spec said offloads should be le64, so use virtio_ldq_p() to guarantee
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
valid endian.
3
2
4
Fixes: 644c98587d4c ("virtio-net: dynamic network offloads configuration")
3
Creating and destroying network backend does not require a fully
5
Cc: qemu-stable@nongnu.org
4
constructed machine. Allow the related monitor commands to run before
6
Cc: Dmitry Fleytman <dfleytma@redhat.com>
5
machine initialization has concluded.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
9
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
10
---
9
hw/net/virtio-net.c | 2 ++
11
hmp-commands.hx | 2 ++
10
1 file changed, 2 insertions(+)
12
qapi/net.json | 6 ++++--
13
2 files changed, 6 insertions(+), 2 deletions(-)
11
14
12
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
15
diff --git a/hmp-commands.hx b/hmp-commands.hx
13
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/net/virtio-net.c
17
--- a/hmp-commands.hx
15
+++ b/hw/net/virtio-net.c
18
+++ b/hmp-commands.hx
16
@@ -XXX,XX +XXX,XX @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
19
@@ -XXX,XX +XXX,XX @@ ERST
17
if (cmd == VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET) {
20
.help = "add host network device",
18
uint64_t supported_offloads;
21
.cmd = hmp_netdev_add,
19
22
.command_completion = netdev_add_completion,
20
+ offloads = virtio_ldq_p(vdev, &offloads);
23
+ .flags = "p",
21
+
24
},
22
if (!n->has_vnet_hdr) {
25
23
return VIRTIO_NET_ERR;
26
SRST
24
}
27
@@ -XXX,XX +XXX,XX @@ ERST
28
.help = "remove host network device",
29
.cmd = hmp_netdev_del,
30
.command_completion = netdev_del_completion,
31
+ .flags = "p",
32
},
33
34
SRST
35
diff --git a/qapi/net.json b/qapi/net.json
36
index XXXXXXX..XXXXXXX 100644
37
--- a/qapi/net.json
38
+++ b/qapi/net.json
39
@@ -XXX,XX +XXX,XX @@
40
# <- { "return": {} }
41
#
42
##
43
-{ 'command': 'netdev_add', 'data': 'Netdev', 'boxed': true }
44
+{ 'command': 'netdev_add', 'data': 'Netdev', 'boxed': true,
45
+ 'allow-preconfig': true }
46
47
##
48
# @netdev_del:
49
@@ -XXX,XX +XXX,XX @@
50
# <- { "return": {} }
51
#
52
##
53
-{ 'command': 'netdev_del', 'data': {'id': 'str'} }
54
+{ 'command': 'netdev_del', 'data': {'id': 'str'},
55
+ 'allow-preconfig': true }
56
57
##
58
# @NetLegacyNicOptions:
25
--
59
--
26
2.7.4
60
2.7.4
27
61
28
62
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: "Rao, Lei" <lei.rao@intel.com>
2
2
3
We add the vnet_hdr_support option for colo-compare, default is disabled.
3
There is the same trace code in the colo_compare_packet_payload.
4
If you use virtio-net-pci or other driver needs vnet_hdr, please enable it.
5
You can use it for example:
6
-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support
7
4
8
COLO-compare can get vnet header length from filter,
5
Signed-off-by: Lei Rao <lei.rao@intel.com>
9
Add vnet_hdr_len to struct packet and output packet with
6
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
10
the vnet_hdr_len.
7
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
11
8
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
12
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
9
Tested-by: Lukas Straub <lukasstraub2@web.de>
10
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
14
---
12
---
15
net/colo-compare.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++-------
13
net/colo-compare.c | 13 -------------
16
qemu-options.hx | 4 ++--
14
1 file changed, 13 deletions(-)
17
2 files changed, 55 insertions(+), 9 deletions(-)
18
15
19
diff --git a/net/colo-compare.c b/net/colo-compare.c
16
diff --git a/net/colo-compare.c b/net/colo-compare.c
20
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
21
--- a/net/colo-compare.c
18
--- a/net/colo-compare.c
22
+++ b/net/colo-compare.c
19
+++ b/net/colo-compare.c
23
@@ -XXX,XX +XXX,XX @@ typedef struct CompareState {
20
@@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_other(Packet *spkt, Packet *ppkt)
24
CharBackend chr_out;
21
uint16_t offset = ppkt->vnet_hdr_len;
25
SocketReadState pri_rs;
22
26
SocketReadState sec_rs;
23
trace_colo_compare_main("compare other");
27
+ bool vnet_hdr;
24
- if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO)) {
28
25
- char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];
29
/* connection list: the connections belonged to this NIC could be found
26
-
30
* in this list.
27
- strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src));
31
@@ -XXX,XX +XXX,XX @@ enum {
28
- strcpy(pri_ip_dst, inet_ntoa(ppkt->ip->ip_dst));
32
29
- strcpy(sec_ip_src, inet_ntoa(spkt->ip->ip_src));
33
static int compare_chr_send(CompareState *s,
30
- strcpy(sec_ip_dst, inet_ntoa(spkt->ip->ip_dst));
34
const uint8_t *buf,
31
-
35
- uint32_t size);
32
- trace_colo_compare_ip_info(ppkt->size, pri_ip_src,
36
+ uint32_t size,
33
- pri_ip_dst, spkt->size,
37
+ uint32_t vnet_hdr_len);
34
- sec_ip_src, sec_ip_dst);
38
35
- }
39
static gint seq_sorter(Packet *a, Packet *b, gpointer data)
36
-
40
{
37
if (ppkt->size != spkt->size) {
41
@@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data)
38
trace_colo_compare_main("Other: payload size of packets are different");
42
}
39
return -1;
43
44
if (result) {
45
- ret = compare_chr_send(s, pkt->data, pkt->size);
46
+ ret = compare_chr_send(s,
47
+ pkt->data,
48
+ pkt->size,
49
+ pkt->vnet_hdr_len);
50
if (ret < 0) {
51
error_report("colo_send_primary_packet failed");
52
}
53
@@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data)
54
55
static int compare_chr_send(CompareState *s,
56
const uint8_t *buf,
57
- uint32_t size)
58
+ uint32_t size,
59
+ uint32_t vnet_hdr_len)
60
{
61
int ret = 0;
62
uint32_t len = htonl(size);
63
@@ -XXX,XX +XXX,XX @@ static int compare_chr_send(CompareState *s,
64
goto err;
65
}
66
67
+ if (s->vnet_hdr) {
68
+ /*
69
+ * We send vnet header len make other module(like filter-redirector)
70
+ * know how to parse net packet correctly.
71
+ */
72
+ len = htonl(vnet_hdr_len);
73
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
74
+ if (ret != sizeof(len)) {
75
+ goto err;
76
+ }
77
+ }
78
+
79
ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
80
if (ret != size) {
81
goto err;
82
@@ -XXX,XX +XXX,XX @@ static void compare_set_outdev(Object *obj, const char *value, Error **errp)
83
s->outdev = g_strdup(value);
84
}
85
86
+static bool compare_get_vnet_hdr(Object *obj, Error **errp)
87
+{
88
+ CompareState *s = COLO_COMPARE(obj);
89
+
90
+ return s->vnet_hdr;
91
+}
92
+
93
+static void compare_set_vnet_hdr(Object *obj,
94
+ bool value,
95
+ Error **errp)
96
+{
97
+ CompareState *s = COLO_COMPARE(obj);
98
+
99
+ s->vnet_hdr = value;
100
+}
101
+
102
static void compare_pri_rs_finalize(SocketReadState *pri_rs)
103
{
104
CompareState *s = container_of(pri_rs, CompareState, pri_rs);
105
106
if (packet_enqueue(s, PRIMARY_IN)) {
107
trace_colo_compare_main("primary: unsupported packet in");
108
- compare_chr_send(s, pri_rs->buf, pri_rs->packet_len);
109
+ compare_chr_send(s,
110
+ pri_rs->buf,
111
+ pri_rs->packet_len,
112
+ pri_rs->vnet_hdr_len);
113
} else {
114
/* compare connection */
115
g_queue_foreach(&s->conn_list, colo_compare_connection, s);
116
@@ -XXX,XX +XXX,XX @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
117
return;
118
}
119
120
- net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, false);
121
- net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, false);
122
+ net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);
123
+ net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr);
124
125
g_queue_init(&s->conn_list);
126
127
@@ -XXX,XX +XXX,XX @@ static void colo_flush_packets(void *opaque, void *user_data)
128
129
while (!g_queue_is_empty(&conn->primary_list)) {
130
pkt = g_queue_pop_head(&conn->primary_list);
131
- compare_chr_send(s, pkt->data, pkt->size);
132
+ compare_chr_send(s,
133
+ pkt->data,
134
+ pkt->size,
135
+ pkt->vnet_hdr_len);
136
packet_destroy(pkt, NULL);
137
}
138
while (!g_queue_is_empty(&conn->secondary_list)) {
139
@@ -XXX,XX +XXX,XX @@ static void colo_compare_class_init(ObjectClass *oc, void *data)
140
141
static void colo_compare_init(Object *obj)
142
{
143
+ CompareState *s = COLO_COMPARE(obj);
144
+
145
object_property_add_str(obj, "primary_in",
146
compare_get_pri_indev, compare_set_pri_indev,
147
NULL);
148
@@ -XXX,XX +XXX,XX @@ static void colo_compare_init(Object *obj)
149
object_property_add_str(obj, "outdev",
150
compare_get_outdev, compare_set_outdev,
151
NULL);
152
+
153
+ s->vnet_hdr = false;
154
+ object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr,
155
+ compare_set_vnet_hdr, NULL);
156
}
157
158
static void colo_compare_finalize(Object *obj)
159
diff --git a/qemu-options.hx b/qemu-options.hx
160
index XXXXXXX..XXXXXXX 100644
161
--- a/qemu-options.hx
162
+++ b/qemu-options.hx
163
@@ -XXX,XX +XXX,XX @@ Dump the network traffic on netdev @var{dev} to the file specified by
164
The file format is libpcap, so it can be analyzed with tools such as tcpdump
165
or Wireshark.
166
167
-@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid},
168
-outdev=@var{chardevid}
169
+@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid},outdev=@var{chardevid}[,vnet_hdr_support]
170
171
Colo-compare gets packet from primary_in@var{chardevid} and secondary_in@var{chardevid}, than compare primary packet with
172
secondary packet. If the packets are same, we will output primary
173
packet to outdev@var{chardevid}, else we will notify colo-frame
174
do checkpoint and send primary packet to outdev@var{chardevid}.
175
+if it has the vnet_hdr_support flag, colo compare will send/recv packet with vnet_hdr_len.
176
177
we must use it with the help of filter-mirror and filter-redirector.
178
179
--
40
--
180
2.7.4
41
2.7.4
181
42
182
43
diff view generated by jsdifflib
1
From: Michal Privoznik <mprivozn@redhat.com>
1
From: "Rao, Lei" <lei.rao@intel.com>
2
2
3
We have a function that checks if given number is power of two.
3
This patch fixes the following:
4
We should prefer it instead of expanding the check on our own.
4
qemu-system-x86_64: invalid runstate transition: 'colo' ->'shutdown'
5
Aborted (core dumped)
5
6
6
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7
Signed-off-by: Lei Rao <lei.rao@intel.com>
8
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
9
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
10
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
11
Tested-by: Lukas Straub <lukasstraub2@web.de>
12
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
14
---
9
hw/net/virtio-net.c | 2 +-
15
softmmu/runstate.c | 1 +
10
1 file changed, 1 insertion(+), 1 deletion(-)
16
1 file changed, 1 insertion(+)
11
17
12
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
18
diff --git a/softmmu/runstate.c b/softmmu/runstate.c
13
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/net/virtio-net.c
20
--- a/softmmu/runstate.c
15
+++ b/hw/net/virtio-net.c
21
+++ b/softmmu/runstate.c
16
@@ -XXX,XX +XXX,XX @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
22
@@ -XXX,XX +XXX,XX @@ static const RunStateTransition runstate_transitions_def[] = {
17
*/
23
{ RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
18
if (n->net_conf.rx_queue_size < VIRTIO_NET_RX_QUEUE_MIN_SIZE ||
24
19
n->net_conf.rx_queue_size > VIRTQUEUE_MAX_SIZE ||
25
{ RUN_STATE_COLO, RUN_STATE_RUNNING },
20
- (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size - 1))) {
26
+ { RUN_STATE_COLO, RUN_STATE_SHUTDOWN},
21
+ !is_power_of_2(n->net_conf.rx_queue_size)) {
27
22
error_setg(errp, "Invalid rx_queue_size (= %" PRIu16 "), "
28
{ RUN_STATE_RUNNING, RUN_STATE_DEBUG },
23
"must be a power of 2 between %d and %d.",
29
{ RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
24
n->net_conf.rx_queue_size, VIRTIO_NET_RX_QUEUE_MIN_SIZE,
25
--
30
--
26
2.7.4
31
2.7.4
27
32
28
33
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: "Rao, Lei" <lei.rao@intel.com>
2
2
3
This patch change the filter_send() parameter from CharBackend to MirrorState,
3
The iov_size has been calculated in filter_send(). we can directly
4
we can get more information like vnet_hdr(We use it to support packet with vnet_header).
4
return the size.In this way, this is no need to repeat calculations
5
in filter_redirector_receive_iov();
5
6
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
7
Signed-off-by: Lei Rao <lei.rao@intel.com>
8
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
9
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
10
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
11
Tested-by: Lukas Straub <lukasstraub2@web.de>
12
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
14
---
9
net/filter-mirror.c | 10 +++++-----
15
net/filter-mirror.c | 8 ++++----
10
1 file changed, 5 insertions(+), 5 deletions(-)
16
1 file changed, 4 insertions(+), 4 deletions(-)
11
17
12
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
18
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
13
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
14
--- a/net/filter-mirror.c
20
--- a/net/filter-mirror.c
15
+++ b/net/filter-mirror.c
21
+++ b/net/filter-mirror.c
16
@@ -XXX,XX +XXX,XX @@ typedef struct MirrorState {
22
@@ -XXX,XX +XXX,XX @@ static int filter_send(MirrorState *s,
17
SocketReadState rs;
18
} MirrorState;
19
20
-static int filter_send(CharBackend *chr_out,
21
+static int filter_send(MirrorState *s,
22
const struct iovec *iov,
23
int iovcnt)
24
{
25
@@ -XXX,XX +XXX,XX @@ static int filter_send(CharBackend *chr_out,
26
}
27
28
len = htonl(size);
29
- ret = qemu_chr_fe_write_all(chr_out, (uint8_t *)&len, sizeof(len));
30
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
31
if (ret != sizeof(len)) {
32
goto err;
23
goto err;
33
}
24
}
34
25
35
buf = g_malloc(size);
26
- return 0;
36
iov_to_buf(iov, iovcnt, 0, buf, size);
27
+ return size;
37
- ret = qemu_chr_fe_write_all(chr_out, (uint8_t *)buf, size);
28
38
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
29
err:
39
g_free(buf);
30
return ret < 0 ? ret : -EIO;
40
if (ret != size) {
41
goto err;
42
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_mirror_receive_iov(NetFilterState *nf,
31
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_mirror_receive_iov(NetFilterState *nf,
43
MirrorState *s = FILTER_MIRROR(nf);
44
int ret;
32
int ret;
45
33
46
- ret = filter_send(&s->chr_out, iov, iovcnt);
34
ret = filter_send(s, iov, iovcnt);
47
+ ret = filter_send(s, iov, iovcnt);
35
- if (ret) {
48
if (ret) {
36
+ if (ret < 0) {
49
error_report("filter mirror send failed(%s)", strerror(-ret));
37
error_report("filter mirror send failed(%s)", strerror(-ret));
50
}
38
}
39
51
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_redirector_receive_iov(NetFilterState *nf,
40
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_redirector_receive_iov(NetFilterState *nf,
52
int ret;
53
41
54
if (qemu_chr_fe_backend_connected(&s->chr_out)) {
42
if (qemu_chr_fe_backend_connected(&s->chr_out)) {
55
- ret = filter_send(&s->chr_out, iov, iovcnt);
43
ret = filter_send(s, iov, iovcnt);
56
+ ret = filter_send(s, iov, iovcnt);
44
- if (ret) {
57
if (ret) {
45
+ if (ret < 0) {
58
error_report("filter redirector send failed(%s)", strerror(-ret));
46
error_report("filter redirector send failed(%s)", strerror(-ret));
59
}
47
}
48
- return iov_size(iov, iovcnt);
49
+ return ret;
50
} else {
51
return 0;
52
}
60
--
53
--
61
2.7.4
54
2.7.4
62
55
63
56
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: "Rao, Lei" <lei.rao@intel.com>
2
2
3
Make colo-compare and filter-rewriter can parse vnet packet.
3
We can detect disk migration in migrate_prepare, if disk migration
4
is enabled in COLO mode, we can directly report an error.and there
5
is no need to disable block migration at every checkpoint.
4
6
5
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
7
Signed-off-by: Lei Rao <lei.rao@intel.com>
8
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
9
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
10
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
11
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
12
Tested-by: Lukas Straub <lukasstraub2@web.de>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
---
14
---
8
net/colo.c | 6 +++---
15
migration/colo.c | 6 ------
9
1 file changed, 3 insertions(+), 3 deletions(-)
16
migration/migration.c | 4 ++++
17
2 files changed, 4 insertions(+), 6 deletions(-)
10
18
11
diff --git a/net/colo.c b/net/colo.c
19
diff --git a/migration/colo.c b/migration/colo.c
12
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
13
--- a/net/colo.c
21
--- a/migration/colo.c
14
+++ b/net/colo.c
22
+++ b/migration/colo.c
15
@@ -XXX,XX +XXX,XX @@ int parse_packet_early(Packet *pkt)
23
@@ -XXX,XX +XXX,XX @@ static int colo_do_checkpoint_transaction(MigrationState *s,
16
{
24
if (failover_get_state() != FAILOVER_STATUS_NONE) {
17
int network_length;
25
goto out;
18
static const uint8_t vlan[] = {0x81, 0x00};
19
- uint8_t *data = pkt->data;
20
+ uint8_t *data = pkt->data + pkt->vnet_hdr_len;
21
uint16_t l3_proto;
22
ssize_t l2hdr_len = eth_get_l2_hdr_length(data);
23
24
- if (pkt->size < ETH_HLEN) {
25
+ if (pkt->size < ETH_HLEN + pkt->vnet_hdr_len) {
26
trace_colo_proxy_main("pkt->size < ETH_HLEN");
27
return 1;
28
}
26
}
29
@@ -XXX,XX +XXX,XX @@ int parse_packet_early(Packet *pkt)
27
-
28
- /* Disable block migration */
29
- migrate_set_block_enabled(false, &local_err);
30
- if (local_err) {
31
- goto out;
32
- }
33
qemu_mutex_lock_iothread();
34
35
#ifdef CONFIG_REPLICATION
36
diff --git a/migration/migration.c b/migration/migration.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/migration/migration.c
39
+++ b/migration/migration.c
40
@@ -XXX,XX +XXX,XX @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc,
30
}
41
}
31
42
32
network_length = pkt->ip->ip_hl * 4;
43
if (blk || blk_inc) {
33
- if (pkt->size < l2hdr_len + network_length) {
44
+ if (migrate_colo_enabled()) {
34
+ if (pkt->size < l2hdr_len + network_length + pkt->vnet_hdr_len) {
45
+ error_setg(errp, "No disk migration is required in COLO mode");
35
trace_colo_proxy_main("pkt->size < network_header + network_length");
46
+ return false;
36
return 1;
47
+ }
37
}
48
if (migrate_use_block() || migrate_use_block_incremental()) {
49
error_setg(errp, "Command options are incompatible with "
50
"current migration capabilities");
38
--
51
--
39
2.7.4
52
2.7.4
40
53
41
54
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: "Rao, Lei" <lei.rao@intel.com>
2
2
3
We can use this property flush and send packet with vnet_hdr_len.
3
Use the packet_new_nocopy instead of packet_new in the
4
filter-rewriter module. There will be one less memory
5
copy in the processing of each network packet.
4
6
5
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
7
Signed-off-by: Lei Rao <lei.rao@intel.com>
8
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
9
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
10
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
---
11
---
8
net/colo-compare.c | 8 ++++++--
12
net/colo.c | 25 +++++++++++++++++--------
9
net/colo.c | 3 ++-
13
net/colo.h | 1 +
10
net/colo.h | 4 +++-
14
net/filter-rewriter.c | 3 +--
11
net/filter-rewriter.c | 2 +-
15
3 files changed, 19 insertions(+), 10 deletions(-)
12
4 files changed, 12 insertions(+), 5 deletions(-)
13
16
14
diff --git a/net/colo-compare.c b/net/colo-compare.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/net/colo-compare.c
17
+++ b/net/colo-compare.c
18
@@ -XXX,XX +XXX,XX @@ static int packet_enqueue(CompareState *s, int mode)
19
Connection *conn;
20
21
if (mode == PRIMARY_IN) {
22
- pkt = packet_new(s->pri_rs.buf, s->pri_rs.packet_len);
23
+ pkt = packet_new(s->pri_rs.buf,
24
+ s->pri_rs.packet_len,
25
+ s->pri_rs.vnet_hdr_len);
26
} else {
27
- pkt = packet_new(s->sec_rs.buf, s->sec_rs.packet_len);
28
+ pkt = packet_new(s->sec_rs.buf,
29
+ s->sec_rs.packet_len,
30
+ s->sec_rs.vnet_hdr_len);
31
}
32
33
if (parse_packet_early(pkt)) {
34
diff --git a/net/colo.c b/net/colo.c
17
diff --git a/net/colo.c b/net/colo.c
35
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
36
--- a/net/colo.c
19
--- a/net/colo.c
37
+++ b/net/colo.c
20
+++ b/net/colo.c
38
@@ -XXX,XX +XXX,XX @@ void connection_destroy(void *opaque)
21
@@ -XXX,XX +XXX,XX @@ void connection_destroy(void *opaque)
39
g_slice_free(Connection, conn);
22
40
}
23
Packet *packet_new(const void *data, int size, int vnet_hdr_len)
41
42
-Packet *packet_new(const void *data, int size)
43
+Packet *packet_new(const void *data, int size, int vnet_hdr_len)
44
{
24
{
45
Packet *pkt = g_slice_new(Packet);
25
- Packet *pkt = g_slice_new(Packet);
26
+ Packet *pkt = g_slice_new0(Packet);
46
27
47
pkt->data = g_memdup(data, size);
28
pkt->data = g_memdup(data, size);
48
pkt->size = size;
29
pkt->size = size;
49
pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST);
30
pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST);
31
pkt->vnet_hdr_len = vnet_hdr_len;
32
- pkt->tcp_seq = 0;
33
- pkt->tcp_ack = 0;
34
- pkt->seq_end = 0;
35
- pkt->header_size = 0;
36
- pkt->payload_size = 0;
37
- pkt->offset = 0;
38
- pkt->flags = 0;
39
+
40
+ return pkt;
41
+}
42
+
43
+/*
44
+ * packet_new_nocopy will not copy data, so the caller can't release
45
+ * the data. And it will be released in packet_destroy.
46
+ */
47
+Packet *packet_new_nocopy(void *data, int size, int vnet_hdr_len)
48
+{
49
+ Packet *pkt = g_slice_new0(Packet);
50
+
51
+ pkt->data = data;
52
+ pkt->size = size;
53
+ pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST);
50
+ pkt->vnet_hdr_len = vnet_hdr_len;
54
+ pkt->vnet_hdr_len = vnet_hdr_len;
51
55
52
return pkt;
56
return pkt;
53
}
57
}
54
diff --git a/net/colo.h b/net/colo.h
58
diff --git a/net/colo.h b/net/colo.h
55
index XXXXXXX..XXXXXXX 100644
59
index XXXXXXX..XXXXXXX 100644
56
--- a/net/colo.h
60
--- a/net/colo.h
57
+++ b/net/colo.h
61
+++ b/net/colo.h
58
@@ -XXX,XX +XXX,XX @@ typedef struct Packet {
62
@@ -XXX,XX +XXX,XX @@ bool connection_has_tracked(GHashTable *connection_track_table,
59
int size;
63
ConnectionKey *key);
60
/* Time of packet creation, in wall clock ms */
61
int64_t creation_ms;
62
+ /* Get vnet_hdr_len from filter */
63
+ uint32_t vnet_hdr_len;
64
} Packet;
65
66
typedef struct ConnectionKey {
67
@@ -XXX,XX +XXX,XX @@ Connection *connection_get(GHashTable *connection_track_table,
68
ConnectionKey *key,
69
GQueue *conn_list);
70
void connection_hashtable_reset(GHashTable *connection_track_table);
64
void connection_hashtable_reset(GHashTable *connection_track_table);
71
-Packet *packet_new(const void *data, int size);
65
Packet *packet_new(const void *data, int size, int vnet_hdr_len);
72
+Packet *packet_new(const void *data, int size, int vnet_hdr_len);
66
+Packet *packet_new_nocopy(void *data, int size, int vnet_hdr_len);
73
void packet_destroy(void *opaque, void *user_data);
67
void packet_destroy(void *opaque, void *user_data);
74
68
void packet_destroy_partial(void *opaque, void *user_data);
75
#endif /* QEMU_COLO_PROXY_H */
69
76
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
70
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
77
index XXXXXXX..XXXXXXX 100644
71
index XXXXXXX..XXXXXXX 100644
78
--- a/net/filter-rewriter.c
72
--- a/net/filter-rewriter.c
79
+++ b/net/filter-rewriter.c
73
+++ b/net/filter-rewriter.c
80
@@ -XXX,XX +XXX,XX @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
74
@@ -XXX,XX +XXX,XX @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
81
char *buf = g_malloc0(size);
75
vnet_hdr_len = nf->netdev->vnet_hdr_len;
82
76
}
83
iov_to_buf(iov, iovcnt, 0, buf, size);
77
84
- pkt = packet_new(buf, size);
78
- pkt = packet_new(buf, size, vnet_hdr_len);
85
+ pkt = packet_new(buf, size, 0);
79
- g_free(buf);
86
g_free(buf);
80
+ pkt = packet_new_nocopy(buf, size, vnet_hdr_len);
87
81
88
/*
82
/*
83
* if we get tcp packet
89
--
84
--
90
2.7.4
85
2.7.4
91
86
92
87
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: "Rao, Lei" <lei.rao@intel.com>
2
2
3
We add a flag to decide whether net_fill_rstate() need read
3
This patch fixes the following:
4
the vnet_hdr_len or not.
4
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
5
#1 0x00007f6ae4559859 in __GI_abort () at abort.c:79
6
#2 0x0000559aaa386720 in error_exit (err=16, msg=0x559aaa5973d0 <__func__.16227> "qemu_mutex_destroy") at util/qemu-thread-posix.c:36
7
#3 0x0000559aaa3868c5 in qemu_mutex_destroy (mutex=0x559aabffe828) at util/qemu-thread-posix.c:69
8
#4 0x0000559aaa2f93a8 in char_finalize (obj=0x559aabffe800) at chardev/char.c:285
9
#5 0x0000559aaa23318a in object_deinit (obj=0x559aabffe800, type=0x559aabfd7d20) at qom/object.c:606
10
#6 0x0000559aaa2331b8 in object_deinit (obj=0x559aabffe800, type=0x559aabfd9060) at qom/object.c:610
11
#7 0x0000559aaa233200 in object_finalize (data=0x559aabffe800) at qom/object.c:620
12
#8 0x0000559aaa234202 in object_unref (obj=0x559aabffe800) at qom/object.c:1074
13
#9 0x0000559aaa2356b6 in object_finalize_child_property (obj=0x559aac0dac10, name=0x559aac778760 "compare0-0", opaque=0x559aabffe800) at qom/object.c:1584
14
#10 0x0000559aaa232f70 in object_property_del_all (obj=0x559aac0dac10) at qom/object.c:557
15
#11 0x0000559aaa2331ed in object_finalize (data=0x559aac0dac10) at qom/object.c:619
16
#12 0x0000559aaa234202 in object_unref (obj=0x559aac0dac10) at qom/object.c:1074
17
#13 0x0000559aaa2356b6 in object_finalize_child_property (obj=0x559aac0c75c0, name=0x559aac0dadc0 "chardevs", opaque=0x559aac0dac10) at qom/object.c:1584
18
#14 0x0000559aaa233071 in object_property_del_child (obj=0x559aac0c75c0, child=0x559aac0dac10, errp=0x0) at qom/object.c:580
19
#15 0x0000559aaa233155 in object_unparent (obj=0x559aac0dac10) at qom/object.c:599
20
#16 0x0000559aaa2fb721 in qemu_chr_cleanup () at chardev/char.c:1159
21
#17 0x0000559aa9f9b110 in main (argc=54, argv=0x7ffeb62fa998, envp=0x7ffeb62fab50) at vl.c:4539
5
22
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
23
When chardev is cleaned up, chr_write_lock needs to be destroyed. But
7
Suggested-by: Jason Wang <jasowang@redhat.com>
24
the colo-compare module is not cleaned up normally before it when the
25
guest poweroff. It is holding chr_write_lock at this time. This will
26
cause qemu crash.So we add the function of colo_compare_cleanup() before
27
qemu_chr_cleanup() to fix the bug.
28
29
Signed-off-by: Lei Rao <lei.rao@intel.com>
30
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
31
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
32
Tested-by: Lukas Straub <lukasstraub2@web.de>
33
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
8
Signed-off-by: Jason Wang <jasowang@redhat.com>
34
Signed-off-by: Jason Wang <jasowang@redhat.com>
9
---
35
---
10
include/net/net.h | 9 +++++++--
36
net/colo-compare.c | 10 ++++++++++
11
net/colo-compare.c | 4 ++--
37
net/colo-compare.h | 1 +
12
net/filter-mirror.c | 2 +-
38
net/net.c | 4 ++++
13
net/net.c | 36 ++++++++++++++++++++++++++++++++----
39
3 files changed, 15 insertions(+)
14
net/socket.c | 8 ++++----
15
5 files changed, 46 insertions(+), 13 deletions(-)
16
40
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 @@ typedef struct NICState {
22
} NICState;
23
24
struct SocketReadState {
25
- int state; /* 0 = getting length, 1 = getting data */
26
+ /* 0 = getting length, 1 = getting vnet header length, 2 = getting data */
27
+ int state;
28
+ /* This flag decide whether to read the vnet_hdr_len field */
29
+ bool vnet_hdr;
30
uint32_t index;
31
uint32_t packet_len;
32
+ uint32_t vnet_hdr_len;
33
uint8_t buf[NET_BUFSIZE];
34
SocketReadStateFinalize *finalize;
35
};
36
@@ -XXX,XX +XXX,XX @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender,
37
void print_net_client(Monitor *mon, NetClientState *nc);
38
void hmp_info_network(Monitor *mon, const QDict *qdict);
39
void net_socket_rs_init(SocketReadState *rs,
40
- SocketReadStateFinalize *finalize);
41
+ SocketReadStateFinalize *finalize,
42
+ bool vnet_hdr);
43
44
/* NIC info */
45
46
diff --git a/net/colo-compare.c b/net/colo-compare.c
41
diff --git a/net/colo-compare.c b/net/colo-compare.c
47
index XXXXXXX..XXXXXXX 100644
42
index XXXXXXX..XXXXXXX 100644
48
--- a/net/colo-compare.c
43
--- a/net/colo-compare.c
49
+++ b/net/colo-compare.c
44
+++ b/net/colo-compare.c
50
@@ -XXX,XX +XXX,XX @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
45
@@ -XXX,XX +XXX,XX @@ static void colo_compare_init(Object *obj)
51
return;
46
compare_set_vnet_hdr);
52
}
47
}
53
48
54
- net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize);
49
+void colo_compare_cleanup(void)
55
- net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize);
50
+{
56
+ net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, false);
51
+ CompareState *tmp = NULL;
57
+ net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, false);
52
+ CompareState *n = NULL;
58
53
+
59
g_queue_init(&s->conn_list);
54
+ QTAILQ_FOREACH_SAFE(tmp, &net_compares, next, n) {
60
55
+ object_unparent(OBJECT(tmp));
61
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
56
+ }
57
+}
58
+
59
static void colo_compare_finalize(Object *obj)
60
{
61
CompareState *s = COLO_COMPARE(obj);
62
diff --git a/net/colo-compare.h b/net/colo-compare.h
62
index XXXXXXX..XXXXXXX 100644
63
index XXXXXXX..XXXXXXX 100644
63
--- a/net/filter-mirror.c
64
--- a/net/colo-compare.h
64
+++ b/net/filter-mirror.c
65
+++ b/net/colo-compare.h
65
@@ -XXX,XX +XXX,XX @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp)
66
@@ -XXX,XX +XXX,XX @@
66
}
67
void colo_notify_compares_event(void *opaque, int event, Error **errp);
67
}
68
void colo_compare_register_notifier(Notifier *notify);
68
69
void colo_compare_unregister_notifier(Notifier *notify);
69
- net_socket_rs_init(&s->rs, redirector_rs_finalize);
70
+void colo_compare_cleanup(void);
70
+ net_socket_rs_init(&s->rs, redirector_rs_finalize, false);
71
71
72
#endif /* QEMU_COLO_COMPARE_H */
72
if (s->indev) {
73
chr = qemu_chr_find(s->indev);
74
diff --git a/net/net.c b/net/net.c
73
diff --git a/net/net.c b/net/net.c
75
index XXXXXXX..XXXXXXX 100644
74
index XXXXXXX..XXXXXXX 100644
76
--- a/net/net.c
75
--- a/net/net.c
77
+++ b/net/net.c
76
+++ b/net/net.c
78
@@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_net_opts = {
77
@@ -XXX,XX +XXX,XX @@
79
};
78
#include "qapi/error.h"
80
79
#include "qapi/opts-visitor.h"
81
void net_socket_rs_init(SocketReadState *rs,
80
#include "sysemu/runstate.h"
82
- SocketReadStateFinalize *finalize)
81
+#include "net/colo-compare.h"
83
+ SocketReadStateFinalize *finalize,
82
#include "net/filter.h"
84
+ bool vnet_hdr)
83
#include "qapi/string-output-visitor.h"
84
85
@@ -XXX,XX +XXX,XX @@ void net_cleanup(void)
85
{
86
{
86
rs->state = 0;
87
NetClientState *nc;
87
+ rs->vnet_hdr = vnet_hdr;
88
88
rs->index = 0;
89
+ /*cleanup colo compare module for COLO*/
89
rs->packet_len = 0;
90
+ colo_compare_cleanup();
90
+ rs->vnet_hdr_len = 0;
91
+
91
memset(rs->buf, 0, sizeof(rs->buf));
92
/* We may del multiple entries during qemu_del_net_client(),
92
rs->finalize = finalize;
93
* so QTAILQ_FOREACH_SAFE() is also not safe here.
93
}
94
*/
94
@@ -XXX,XX +XXX,XX @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
95
unsigned int l;
96
97
while (size > 0) {
98
- /* reassemble a packet from the network */
99
- switch (rs->state) { /* 0 = getting length, 1 = getting data */
100
+ /* Reassemble a packet from the network.
101
+ * 0 = getting length.
102
+ * 1 = getting vnet header length.
103
+ * 2 = getting data.
104
+ */
105
+ switch (rs->state) {
106
case 0:
107
l = 4 - rs->index;
108
if (l > size) {
109
@@ -XXX,XX +XXX,XX @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
110
/* got length */
111
rs->packet_len = ntohl(*(uint32_t *)rs->buf);
112
rs->index = 0;
113
- rs->state = 1;
114
+ if (rs->vnet_hdr) {
115
+ rs->state = 1;
116
+ } else {
117
+ rs->state = 2;
118
+ rs->vnet_hdr_len = 0;
119
+ }
120
}
121
break;
122
case 1:
123
+ l = 4 - rs->index;
124
+ if (l > size) {
125
+ l = size;
126
+ }
127
+ memcpy(rs->buf + rs->index, buf, l);
128
+ buf += l;
129
+ size -= l;
130
+ rs->index += l;
131
+ if (rs->index == 4) {
132
+ /* got vnet header length */
133
+ rs->vnet_hdr_len = ntohl(*(uint32_t *)rs->buf);
134
+ rs->index = 0;
135
+ rs->state = 2;
136
+ }
137
+ break;
138
+ case 2:
139
l = rs->packet_len - rs->index;
140
if (l > size) {
141
l = size;
142
diff --git a/net/socket.c b/net/socket.c
143
index XXXXXXX..XXXXXXX 100644
144
--- a/net/socket.c
145
+++ b/net/socket.c
146
@@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque)
147
closesocket(s->fd);
148
149
s->fd = -1;
150
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
151
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
152
s->nc.link_down = true;
153
memset(s->nc.info_str, 0, sizeof(s->nc.info_str));
154
155
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
156
s->fd = fd;
157
s->listen_fd = -1;
158
s->send_fn = net_socket_send_dgram;
159
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
160
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
161
net_socket_read_poll(s, true);
162
163
/* mcast: save bound address as dst */
164
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
165
166
s->fd = fd;
167
s->listen_fd = -1;
168
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
169
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
170
171
/* Disable Nagle algorithm on TCP sockets to reduce latency */
172
socket_set_nodelay(fd);
173
@@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer,
174
s->fd = -1;
175
s->listen_fd = fd;
176
s->nc.link_down = true;
177
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
178
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
179
180
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
181
return 0;
182
--
95
--
183
2.7.4
96
2.7.4
184
97
185
98
diff view generated by jsdifflib
Deleted patch
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
1
3
We add the vnet_hdr_support option for filter-redirector, default is disabled.
4
If you use virtio-net-pci net driver or other driver needs vnet_hdr, please enable it.
5
Because colo-compare or other modules needs the vnet_hdr_len to parse
6
packet, we add this new option send the len to others.
7
You can use it for example:
8
-object filter-redirector,id=r0,netdev=hn0,queue=tx,outdev=red0,vnet_hdr_support
9
10
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
12
---
13
net/filter-mirror.c | 23 +++++++++++++++++++++++
14
qemu-options.hx | 6 +++---
15
2 files changed, 26 insertions(+), 3 deletions(-)
16
17
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/net/filter-mirror.c
20
+++ b/net/filter-mirror.c
21
@@ -XXX,XX +XXX,XX @@ static void filter_redirector_set_outdev(Object *obj,
22
s->outdev = g_strdup(value);
23
}
24
25
+static bool filter_redirector_get_vnet_hdr(Object *obj, Error **errp)
26
+{
27
+ MirrorState *s = FILTER_REDIRECTOR(obj);
28
+
29
+ return s->vnet_hdr;
30
+}
31
+
32
+static void filter_redirector_set_vnet_hdr(Object *obj,
33
+ bool value,
34
+ Error **errp)
35
+{
36
+ MirrorState *s = FILTER_REDIRECTOR(obj);
37
+
38
+ s->vnet_hdr = value;
39
+}
40
+
41
static void filter_mirror_init(Object *obj)
42
{
43
MirrorState *s = FILTER_MIRROR(obj);
44
@@ -XXX,XX +XXX,XX @@ static void filter_mirror_init(Object *obj)
45
46
static void filter_redirector_init(Object *obj)
47
{
48
+ MirrorState *s = FILTER_REDIRECTOR(obj);
49
+
50
object_property_add_str(obj, "indev", filter_redirector_get_indev,
51
filter_redirector_set_indev, NULL);
52
object_property_add_str(obj, "outdev", filter_redirector_get_outdev,
53
filter_redirector_set_outdev, NULL);
54
+
55
+ s->vnet_hdr = false;
56
+ object_property_add_bool(obj, "vnet_hdr_support",
57
+ filter_redirector_get_vnet_hdr,
58
+ filter_redirector_set_vnet_hdr, NULL);
59
}
60
61
static void filter_mirror_fini(Object *obj)
62
diff --git a/qemu-options.hx b/qemu-options.hx
63
index XXXXXXX..XXXXXXX 100644
64
--- a/qemu-options.hx
65
+++ b/qemu-options.hx
66
@@ -XXX,XX +XXX,XX @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter.
67
68
filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if it has the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len.
69
70
-@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},
71
-outdev=@var{chardevid}[,queue=@var{all|rx|tx}]
72
+@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support]
73
74
filter-redirector on netdev @var{netdevid},redirect filter's net packet to chardev
75
-@var{chardevid},and redirect indev's packet to filter.
76
+@var{chardevid},and redirect indev's packet to filter.if it has the vnet_hdr_support flag,
77
+filter-redirector will redirect packet with vnet_hdr_len.
78
Create a filter-redirector we need to differ outdev id from indev id, id can not
79
be the same. we can just use indev or outdev, but at least one of indev or outdev
80
need to be specified.
81
--
82
2.7.4
83
84
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: "Rao, Lei" <lei.rao@intel.com>
2
2
3
This patch change the compare_chr_send() parameter from CharBackend to CompareState,
3
The data pointer has skipped vnet_hdr_len in the function of
4
we can get more information like vnet_hdr(We use it to support packet with vnet_header).
4
parse_packet_early().So, we can not subtract vnet_hdr_len again
5
when calculating pkt->header_size in fill_pkt_tcp_info(). Otherwise,
6
it will cause network packet comparsion errors and greatly increase
7
the frequency of checkpoints.
5
8
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
9
Signed-off-by: Lei Rao <lei.rao@intel.com>
10
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
11
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
12
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
13
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
14
Tested-by: Lukas Straub <lukasstraub2@web.de>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
15
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
16
---
9
net/colo-compare.c | 14 +++++++-------
17
net/colo-compare.c | 2 +-
10
1 file changed, 7 insertions(+), 7 deletions(-)
18
1 file changed, 1 insertion(+), 1 deletion(-)
11
19
12
diff --git a/net/colo-compare.c b/net/colo-compare.c
20
diff --git a/net/colo-compare.c b/net/colo-compare.c
13
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
14
--- a/net/colo-compare.c
22
--- a/net/colo-compare.c
15
+++ b/net/colo-compare.c
23
+++ b/net/colo-compare.c
16
@@ -XXX,XX +XXX,XX @@ enum {
24
@@ -XXX,XX +XXX,XX @@ static void fill_pkt_tcp_info(void *data, uint32_t *max_ack)
17
SECONDARY_IN,
25
pkt->tcp_ack = ntohl(tcphd->th_ack);
18
};
26
*max_ack = *max_ack > pkt->tcp_ack ? *max_ack : pkt->tcp_ack;
19
27
pkt->header_size = pkt->transport_header - (uint8_t *)pkt->data
20
-static int compare_chr_send(CharBackend *out,
28
- + (tcphd->th_off << 2) - pkt->vnet_hdr_len;
21
+static int compare_chr_send(CompareState *s,
29
+ + (tcphd->th_off << 2);
22
const uint8_t *buf,
30
pkt->payload_size = pkt->size - pkt->header_size;
23
uint32_t size);
31
pkt->seq_end = pkt->tcp_seq + pkt->payload_size;
24
32
pkt->flags = tcphd->th_flags;
25
@@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data)
26
}
27
28
if (result) {
29
- ret = compare_chr_send(&s->chr_out, pkt->data, pkt->size);
30
+ ret = compare_chr_send(s, pkt->data, pkt->size);
31
if (ret < 0) {
32
error_report("colo_send_primary_packet failed");
33
}
34
@@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data)
35
}
36
}
37
38
-static int compare_chr_send(CharBackend *out,
39
+static int compare_chr_send(CompareState *s,
40
const uint8_t *buf,
41
uint32_t size)
42
{
43
@@ -XXX,XX +XXX,XX @@ static int compare_chr_send(CharBackend *out,
44
return 0;
45
}
46
47
- ret = qemu_chr_fe_write_all(out, (uint8_t *)&len, sizeof(len));
48
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
49
if (ret != sizeof(len)) {
50
goto err;
51
}
52
53
- ret = qemu_chr_fe_write_all(out, (uint8_t *)buf, size);
54
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
55
if (ret != size) {
56
goto err;
57
}
58
@@ -XXX,XX +XXX,XX @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs)
59
60
if (packet_enqueue(s, PRIMARY_IN)) {
61
trace_colo_compare_main("primary: unsupported packet in");
62
- compare_chr_send(&s->chr_out, pri_rs->buf, pri_rs->packet_len);
63
+ compare_chr_send(s, pri_rs->buf, pri_rs->packet_len);
64
} else {
65
/* compare connection */
66
g_queue_foreach(&s->conn_list, colo_compare_connection, s);
67
@@ -XXX,XX +XXX,XX @@ static void colo_flush_packets(void *opaque, void *user_data)
68
69
while (!g_queue_is_empty(&conn->primary_list)) {
70
pkt = g_queue_pop_head(&conn->primary_list);
71
- compare_chr_send(&s->chr_out, pkt->data, pkt->size);
72
+ compare_chr_send(s, pkt->data, pkt->size);
73
packet_destroy(pkt, NULL);
74
}
75
while (!g_queue_is_empty(&conn->secondary_list)) {
76
--
33
--
77
2.7.4
34
2.7.4
78
35
79
36
diff view generated by jsdifflib
Deleted patch
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
1
3
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
4
Signed-off-by: Jason Wang <jasowang@redhat.com>
5
---
6
docs/colo-proxy.txt | 26 ++++++++++++++++++++++++++
7
1 file changed, 26 insertions(+)
8
9
diff --git a/docs/colo-proxy.txt b/docs/colo-proxy.txt
10
index XXXXXXX..XXXXXXX 100644
11
--- a/docs/colo-proxy.txt
12
+++ b/docs/colo-proxy.txt
13
@@ -XXX,XX +XXX,XX @@ Secondary(ip:3.3.3.8):
14
-chardev socket,id=red1,host=3.3.3.3,port=9004
15
-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0
16
-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1
17
+-object filter-rewriter,id=f3,netdev=hn0,queue=all
18
+
19
+If you want to use virtio-net-pci or other driver with vnet_header:
20
+
21
+Primary(ip:3.3.3.3):
22
+-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown
23
+-device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66
24
+-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server,nowait
25
+-chardev socket,id=compare1,host=3.3.3.3,port=9004,server,nowait
26
+-chardev socket,id=compare0,host=3.3.3.3,port=9001,server,nowait
27
+-chardev socket,id=compare0-0,host=3.3.3.3,port=9001
28
+-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server,nowait
29
+-chardev socket,id=compare_out0,host=3.3.3.3,port=9005
30
+-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support
31
+-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out,vnet_hdr_support
32
+-object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0,vnet_hdr_support
33
+-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support
34
+
35
+Secondary(ip:3.3.3.8):
36
+-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,down script=/etc/qemu-ifdown
37
+-device e1000,netdev=hn0,mac=52:a4:00:12:78:66
38
+-chardev socket,id=red0,host=3.3.3.3,port=9003
39
+-chardev socket,id=red1,host=3.3.3.3,port=9004
40
+-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0,vnet_hdr_support
41
+-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1,vnet_hdr_support
42
+-object filter-rewriter,id=f3,netdev=hn0,queue=all,vnet_hdr_support
43
44
Note:
45
a.COLO-proxy must work with COLO-frame and Block-replication.
46
--
47
2.7.4
48
49
diff view generated by jsdifflib