* [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net
@ 2021-08-19 1:27 Tao Xu
2021-08-20 21:42 ` Eric Blake
2021-08-21 16:25 ` Lukas Straub
0 siblings, 2 replies; 7+ messages in thread
From: Tao Xu @ 2021-08-19 1:27 UTC (permalink / raw)
To: chen.zhang, lizhijian, jasowang; +Cc: Tao Xu, qemu-devel
When COLO use only one vnet_hdr_support parameter between
COLO network filter(filter-mirror, filter-redirector or
filter-rewriter and colo-compare, packet will not be parsed
correctly. Acquire network driver related to COLO, if it is
nirtio-net, check vnet_hdr_support flag of COLO network filter
and colo-compare.
Signed-off-by: Tao Xu <tao3.xu@intel.com>
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
Changelog:
v2:
Detect virtio-net driver and apply vnet_hdr_support
automatically. (Jason)
---
net/colo-compare.c | 57 +++++++++++++++++++++++++++++++++++++++++++
net/colo.c | 20 +++++++++++++++
net/colo.h | 4 +++
net/filter-mirror.c | 21 ++++++++++++++++
net/filter-rewriter.c | 10 ++++++++
qapi/qom.json | 6 +++++
qemu-options.hx | 6 +++--
7 files changed, 122 insertions(+), 2 deletions(-)
diff --git a/net/colo-compare.c b/net/colo-compare.c
index b100e7b51f..870bd05a41 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -110,6 +110,7 @@ struct CompareState {
char *sec_indev;
char *outdev;
char *notify_dev;
+ char *netdev;
CharBackend chr_pri_in;
CharBackend chr_sec_in;
CharBackend chr_out;
@@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)
return COMPARE_READ_LEN_MAX;
}
+static int colo_set_default_netdev(void *opaque, QemuOpts *opts, Error **errp)
+{
+ const char *colo_obj_type, *netdev_from_filter;
+ char **netdev = (char **)opaque;
+
+ colo_obj_type = qemu_opt_get(opts, "qom-type");
+
+ if (colo_obj_type &&
+ (strcmp(colo_obj_type, "filter-mirror") == 0 ||
+ strcmp(colo_obj_type, "filter-redirector") == 0 ||
+ strcmp(colo_obj_type, "filter-rewriter") == 0)) {
+ netdev_from_filter = qemu_opt_get(opts, "netdev");
+ if (*netdev == NULL) {
+ *netdev = g_strdup(netdev_from_filter);
+ } else if (strcmp(*netdev, netdev_from_filter) != 0) {
+ warn_report("%s is using a different netdev from other COLO "
+ "component", colo_obj_type);
+ }
+ }
+ return 0;
+}
+
/*
* Called from the main thread on the primary for packets
* arriving over the socket from the primary.
@@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object *obj,
s->vnet_hdr = value;
}
+static char *compare_get_netdev(Object *obj, Error **errp)
+{
+ CompareState *s = COLO_COMPARE(obj);
+
+ return g_strdup(s->netdev);
+}
+
+static void compare_set_netdev(Object *obj, const char *value, Error **errp)
+{
+ CompareState *s = COLO_COMPARE(obj);
+
+ g_free(s->netdev);
+ s->netdev = g_strdup(value);
+}
+
static char *compare_get_notify_dev(Object *obj, Error **errp)
{
CompareState *s = COLO_COMPARE(obj);
@@ -1274,6 +1312,12 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
max_queue_size = MAX_QUEUE_SIZE;
}
+ if (!s->netdev) {
+ /* Set default netdev as the first colo netfilter found */
+ qemu_opts_foreach(qemu_find_opts("object"),
+ colo_set_default_netdev, &s->netdev, NULL);
+ }
+
if (find_and_check_chardev(&chr, s->pri_indev, errp) ||
!qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) {
return;
@@ -1289,6 +1333,16 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
return;
}
+ if (!s->vnet_hdr &&
+ qemu_opts_foreach(qemu_find_opts("device"),
+ vnet_driver_check, s->netdev, NULL)) {
+ /*
+ * colo compare needs 'vnet_hdr_support' when it works on virtio-net,
+ * add 'vnet_hdr_support' automatically
+ */
+ s->vnet_hdr = true;
+ }
+
net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);
net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr);
@@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj)
s->vnet_hdr = false;
object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr,
compare_set_vnet_hdr);
+ /* colo compare can't varify that netdev is correct */
+ object_property_add_str(obj, "netdev", compare_get_netdev,
+ compare_set_netdev);
}
void colo_compare_cleanup(void)
diff --git a/net/colo.c b/net/colo.c
index 3a3e6e89a0..4a03780f45 100644
--- a/net/colo.c
+++ b/net/colo.c
@@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable *connection_track_table,
return conn ? true : false;
}
+
+/* check the network driver related to COLO, return 1 if it is virtio-net */
+int vnet_driver_check(void *opaque, QemuOpts *opts, Error **errp)
+{
+ const char *driver_type, *netdev_from_driver;
+ char *netdev_from_filter = (char *)opaque;
+
+ driver_type = qemu_opt_get(opts, "driver");
+ netdev_from_driver = qemu_opt_get(opts, "netdev");
+
+ if (!driver_type || !netdev_from_driver || !netdev_from_filter) {
+ return 0;
+ }
+
+ if (g_str_has_prefix(driver_type, "virtio-net") &&
+ strcmp(netdev_from_driver, netdev_from_filter) == 0) {
+ return 1;
+ }
+ return 0;
+}
diff --git a/net/colo.h b/net/colo.h
index d91cd245c4..d401fc76b6 100644
--- a/net/colo.h
+++ b/net/colo.h
@@ -18,6 +18,9 @@
#include "qemu/jhash.h"
#include "qemu/timer.h"
#include "net/eth.h"
+#include "qemu/option.h"
+#include "qemu/option_int.h"
+#include "qemu/config-file.h"
#define HASHTABLE_MAX_SIZE 16384
@@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size, int vnet_hdr_len);
Packet *packet_new_nocopy(void *data, int size, int vnet_hdr_len);
void packet_destroy(void *opaque, void *user_data);
void packet_destroy_partial(void *opaque, void *user_data);
+int vnet_driver_check(void *opaque, QemuOpts *opts, Error **errp);
#endif /* NET_COLO_H */
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
index f20240cc9f..69ca9c9839 100644
--- a/net/filter-mirror.c
+++ b/net/filter-mirror.c
@@ -12,6 +12,7 @@
#include "qemu/osdep.h"
#include "net/filter.h"
#include "net/net.h"
+#include "net/colo.h"
#include "qapi/error.h"
#include "qom/object.h"
#include "qemu/main-loop.h"
@@ -224,6 +225,16 @@ static void filter_mirror_setup(NetFilterState *nf, Error **errp)
return;
}
+ if (!s->vnet_hdr &&
+ qemu_opts_foreach(qemu_find_opts("device"),
+ vnet_driver_check, nf->netdev_id, NULL)) {
+ /*
+ * filter mirror needs 'vnet_hdr_support' when colo filter modules
+ * work on virtio-net, add 'vnet_hdr_support' automatically
+ */
+ s->vnet_hdr = true;
+ }
+
qemu_chr_fe_init(&s->chr_out, chr, errp);
}
@@ -252,6 +263,16 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp)
}
}
+ if (!s->vnet_hdr &&
+ qemu_opts_foreach(qemu_find_opts("device"),
+ vnet_driver_check, nf->netdev_id, NULL)) {
+ /*
+ * filter redirector needs 'vnet_hdr_support' when colo filter modules
+ * work on virtio-net, add 'vnet_hdr_support' automatically
+ */
+ s->vnet_hdr = true;
+ }
+
net_socket_rs_init(&s->rs, redirector_rs_finalize, s->vnet_hdr);
if (s->indev) {
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index cb3a96cde1..637ef4ce71 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -388,6 +388,16 @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp)
{
RewriterState *s = FILTER_REWRITER(nf);
+ if (!s->vnet_hdr &&
+ qemu_opts_foreach(qemu_find_opts("device"),
+ vnet_driver_check, nf->netdev_id, NULL)) {
+ /*
+ * filter rewriter needs 'vnet_hdr_support' when colo filter modules
+ * work on virtio-net, add 'vnet_hdr_support' automatically
+ */
+ s->vnet_hdr = true;
+ }
+
s->connection_track_table = g_hash_table_new_full(connection_key_hash,
connection_key_equal,
g_free,
diff --git a/qapi/qom.json b/qapi/qom.json
index 6d5f4a88e6..442a963ba4 100644
--- a/qapi/qom.json
+++ b/qapi/qom.json
@@ -241,6 +241,11 @@
# @notify_dev: name of the character device backend to be used to communicate
# with the remote colo-frame (only for Xen COLO)
#
+# @netdev: id of the network device backend to colo-compare, although
+# colo-compare doesn't depend on network device directly, this
+# parameter help colo-compare know what network driver it is
+# working on
+#
# @compare_timeout: the maximum time to hold a packet from @primary_in for
# comparison with an incoming packet on @secondary_in in
# milliseconds (default: 3000)
@@ -264,6 +269,7 @@
'outdev': 'str',
'iothread': 'str',
'*notify_dev': 'str',
+ '*netdev': 'str',
'*compare_timeout': 'uint64',
'*expired_scan_cycle': 'uint32',
'*max_queue_size': 'uint32',
diff --git a/qemu-options.hx b/qemu-options.hx
index 83aa59a920..b31ce3c87d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4957,12 +4957,14 @@ SRST
stored. The file format is libpcap, so it can be analyzed with
tools such as tcpdump or Wireshark.
- ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
+ ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
Colo-compare gets packet from primary\_in chardevid and
secondary\_in, then compare whether the payload of primary packet
and secondary packet are the same. If same, it will output
primary packet to out\_dev, else it will notify COLO-framework to do
- checkpoint and send primary packet to out\_dev. In order to
+ checkpoint and send primary packet to out\_dev. Although colo-compare
+ does not depend on network device directly, netdevid help
+ colo-compare know what network driver it is working on. In order to
improve efficiency, we need to put the task of comparison in
another iothread. If it has the vnet\_hdr\_support flag,
colo compare will send/recv packet with vnet\_hdr\_len.
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net
2021-08-19 1:27 [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net Tao Xu
@ 2021-08-20 21:42 ` Eric Blake
2021-08-26 5:59 ` Zhang, Chen
2021-08-21 16:25 ` Lukas Straub
1 sibling, 1 reply; 7+ messages in thread
From: Eric Blake @ 2021-08-20 21:42 UTC (permalink / raw)
To: Tao Xu; +Cc: chen.zhang, jasowang, qemu-devel, lizhijian
On Thu, Aug 19, 2021 at 09:27:17AM +0800, Tao Xu wrote:
> When COLO use only one vnet_hdr_support parameter between
> COLO network filter(filter-mirror, filter-redirector or
> filter-rewriter and colo-compare, packet will not be parsed
> correctly. Acquire network driver related to COLO, if it is
> nirtio-net, check vnet_hdr_support flag of COLO network filter
> and colo-compare.
>
> Signed-off-by: Tao Xu <tao3.xu@intel.com>
> Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> ---
> +++ b/qapi/qom.json
> @@ -241,6 +241,11 @@
> # @notify_dev: name of the character device backend to be used to communicate
> # with the remote colo-frame (only for Xen COLO)
> #
> +# @netdev: id of the network device backend to colo-compare, although
> +# colo-compare doesn't depend on network device directly, this
> +# parameter help colo-compare know what network driver it is
> +# working on
Missing a '(since 6.2)' tag.
Grammar suggestion: s/colo-compare, although/colo-compare. Although/
s/help/helps/
> +#
> # @compare_timeout: the maximum time to hold a packet from @primary_in for
> # comparison with an incoming packet on @secondary_in in
> # milliseconds (default: 3000)
> @@ -264,6 +269,7 @@
> 'outdev': 'str',
> 'iothread': 'str',
> '*notify_dev': 'str',
> + '*netdev': 'str',
> '*compare_timeout': 'uint64',
> '*expired_scan_cycle': 'uint32',
> '*max_queue_size': 'uint32',
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 83aa59a920..b31ce3c87d 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -4957,12 +4957,14 @@ SRST
> stored. The file format is libpcap, so it can be analyzed with
> tools such as tcpdump or Wireshark.
>
> - ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
> + ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
> Colo-compare gets packet from primary\_in chardevid and
> secondary\_in, then compare whether the payload of primary packet
> and secondary packet are the same. If same, it will output
> primary packet to out\_dev, else it will notify COLO-framework to do
> - checkpoint and send primary packet to out\_dev. In order to
> + checkpoint and send primary packet to out\_dev. Although colo-compare
> + does not depend on network device directly, netdevid help
s/help/helps/
> + colo-compare know what network driver it is working on. In order to
> improve efficiency, we need to put the task of comparison in
> another iothread. If it has the vnet\_hdr\_support flag,
> colo compare will send/recv packet with vnet\_hdr\_len.
> --
> 2.25.1
>
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net
2021-08-19 1:27 [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net Tao Xu
2021-08-20 21:42 ` Eric Blake
@ 2021-08-21 16:25 ` Lukas Straub
2021-08-26 5:49 ` Zhang, Chen
1 sibling, 1 reply; 7+ messages in thread
From: Lukas Straub @ 2021-08-21 16:25 UTC (permalink / raw)
To: Tao Xu; +Cc: chen.zhang, jasowang, qemu-devel, lizhijian
[-- Attachment #1: Type: text/plain, Size: 11887 bytes --]
On Thu, 19 Aug 2021 09:27:17 +0800
Tao Xu <tao3.xu@intel.com> wrote:
> When COLO use only one vnet_hdr_support parameter between
> COLO network filter(filter-mirror, filter-redirector or
> filter-rewriter and colo-compare, packet will not be parsed
> correctly. Acquire network driver related to COLO, if it is
> nirtio-net, check vnet_hdr_support flag of COLO network filter
> and colo-compare.
>
> Signed-off-by: Tao Xu <tao3.xu@intel.com>
> Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> ---
>
> Changelog:
> v2:
> Detect virtio-net driver and apply vnet_hdr_support
> automatically. (Jason)
> ---
> net/colo-compare.c | 57 +++++++++++++++++++++++++++++++++++++++++++
> net/colo.c | 20 +++++++++++++++
> net/colo.h | 4 +++
> net/filter-mirror.c | 21 ++++++++++++++++
> net/filter-rewriter.c | 10 ++++++++
> qapi/qom.json | 6 +++++
> qemu-options.hx | 6 +++--
> 7 files changed, 122 insertions(+), 2 deletions(-)
>
> diff --git a/net/colo-compare.c b/net/colo-compare.c
> index b100e7b51f..870bd05a41 100644
> --- a/net/colo-compare.c
> +++ b/net/colo-compare.c
> @@ -110,6 +110,7 @@ struct CompareState {
> char *sec_indev;
> char *outdev;
> char *notify_dev;
> + char *netdev;
> CharBackend chr_pri_in;
> CharBackend chr_sec_in;
> CharBackend chr_out;
> @@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)
> return COMPARE_READ_LEN_MAX;
> }
>
> +static int colo_set_default_netdev(void *opaque, QemuOpts *opts, Error **errp)
> +{
> + const char *colo_obj_type, *netdev_from_filter;
> + char **netdev = (char **)opaque;
> +
> + colo_obj_type = qemu_opt_get(opts, "qom-type");
> +
> + if (colo_obj_type &&
> + (strcmp(colo_obj_type, "filter-mirror") == 0 ||
> + strcmp(colo_obj_type, "filter-redirector") == 0 ||
> + strcmp(colo_obj_type, "filter-rewriter") == 0)) {
> + netdev_from_filter = qemu_opt_get(opts, "netdev");
> + if (*netdev == NULL) {
> + *netdev = g_strdup(netdev_from_filter);
> + } else if (strcmp(*netdev, netdev_from_filter) != 0) {
> + warn_report("%s is using a different netdev from other COLO "
> + "component", colo_obj_type);
> + }
> + }
> + return 0;
> +}
> +
Hi,
This doesn't properly handle the case where there are multiple network
devices and one is virtio-net and the other isn't. This would be a
regression as this worked fine before.
> /*
> * Called from the main thread on the primary for packets
> * arriving over the socket from the primary.
> @@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object *obj,
> s->vnet_hdr = value;
> }
>
> +static char *compare_get_netdev(Object *obj, Error **errp)
> +{
> + CompareState *s = COLO_COMPARE(obj);
> +
> + return g_strdup(s->netdev);
> +}
> +
> +static void compare_set_netdev(Object *obj, const char *value, Error **errp)
> +{
> + CompareState *s = COLO_COMPARE(obj);
> +
> + g_free(s->netdev);
> + s->netdev = g_strdup(value);
> +}
> +
> static char *compare_get_notify_dev(Object *obj, Error **errp)
> {
> CompareState *s = COLO_COMPARE(obj);
> @@ -1274,6 +1312,12 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
> max_queue_size = MAX_QUEUE_SIZE;
> }
>
> + if (!s->netdev) {
> + /* Set default netdev as the first colo netfilter found */
> + qemu_opts_foreach(qemu_find_opts("object"),
> + colo_set_default_netdev, &s->netdev, NULL);
> + }
> +
> if (find_and_check_chardev(&chr, s->pri_indev, errp) ||
> !qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) {
> return;
> @@ -1289,6 +1333,16 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
> return;
> }
>
> + if (!s->vnet_hdr &&
> + qemu_opts_foreach(qemu_find_opts("device"),
> + vnet_driver_check, s->netdev, NULL)) {
> + /*
> + * colo compare needs 'vnet_hdr_support' when it works on virtio-net,
> + * add 'vnet_hdr_support' automatically
> + */
> + s->vnet_hdr = true;
> + }
> +
There is no way to disable vnet_hdr_support with virtio-net now.
> net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);
> net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr);
>
> @@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj)
> s->vnet_hdr = false;
> object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr,
> compare_set_vnet_hdr);
> + /* colo compare can't varify that netdev is correct */
> + object_property_add_str(obj, "netdev", compare_get_netdev,
> + compare_set_netdev);
> }
>
> void colo_compare_cleanup(void)
> diff --git a/net/colo.c b/net/colo.c
> index 3a3e6e89a0..4a03780f45 100644
> --- a/net/colo.c
> +++ b/net/colo.c
> @@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable *connection_track_table,
>
> return conn ? true : false;
> }
> +
> +/* check the network driver related to COLO, return 1 if it is virtio-net */
> +int vnet_driver_check(void *opaque, QemuOpts *opts, Error **errp)
> +{
> + const char *driver_type, *netdev_from_driver;
> + char *netdev_from_filter = (char *)opaque;
> +
> + driver_type = qemu_opt_get(opts, "driver");
> + netdev_from_driver = qemu_opt_get(opts, "netdev");
> +
> + if (!driver_type || !netdev_from_driver || !netdev_from_filter) {
> + return 0;
> + }
> +
> + if (g_str_has_prefix(driver_type, "virtio-net") &&
> + strcmp(netdev_from_driver, netdev_from_filter) == 0) {
> + return 1;
> + }
> + return 0;
> +}
> diff --git a/net/colo.h b/net/colo.h
> index d91cd245c4..d401fc76b6 100644
> --- a/net/colo.h
> +++ b/net/colo.h
> @@ -18,6 +18,9 @@
> #include "qemu/jhash.h"
> #include "qemu/timer.h"
> #include "net/eth.h"
> +#include "qemu/option.h"
> +#include "qemu/option_int.h"
> +#include "qemu/config-file.h"
>
> #define HASHTABLE_MAX_SIZE 16384
>
> @@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size, int vnet_hdr_len);
> Packet *packet_new_nocopy(void *data, int size, int vnet_hdr_len);
> void packet_destroy(void *opaque, void *user_data);
> void packet_destroy_partial(void *opaque, void *user_data);
> +int vnet_driver_check(void *opaque, QemuOpts *opts, Error **errp);
>
> #endif /* NET_COLO_H */
> diff --git a/net/filter-mirror.c b/net/filter-mirror.c
> index f20240cc9f..69ca9c9839 100644
> --- a/net/filter-mirror.c
> +++ b/net/filter-mirror.c
> @@ -12,6 +12,7 @@
> #include "qemu/osdep.h"
> #include "net/filter.h"
> #include "net/net.h"
> +#include "net/colo.h"
> #include "qapi/error.h"
> #include "qom/object.h"
> #include "qemu/main-loop.h"
> @@ -224,6 +225,16 @@ static void filter_mirror_setup(NetFilterState *nf, Error **errp)
> return;
> }
>
> + if (!s->vnet_hdr &&
> + qemu_opts_foreach(qemu_find_opts("device"),
> + vnet_driver_check, nf->netdev_id, NULL)) {
> + /*
> + * filter mirror needs 'vnet_hdr_support' when colo filter modules
> + * work on virtio-net, add 'vnet_hdr_support' automatically
> + */
> + s->vnet_hdr = true;
> + }
> +
> qemu_chr_fe_init(&s->chr_out, chr, errp);
> }
>
> @@ -252,6 +263,16 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp)
> }
> }
>
> + if (!s->vnet_hdr &&
> + qemu_opts_foreach(qemu_find_opts("device"),
> + vnet_driver_check, nf->netdev_id, NULL)) {
> + /*
> + * filter redirector needs 'vnet_hdr_support' when colo filter modules
> + * work on virtio-net, add 'vnet_hdr_support' automatically
> + */
> + s->vnet_hdr = true;
> + }
> +
> net_socket_rs_init(&s->rs, redirector_rs_finalize, s->vnet_hdr);
>
> if (s->indev) {
> diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
> index cb3a96cde1..637ef4ce71 100644
> --- a/net/filter-rewriter.c
> +++ b/net/filter-rewriter.c
> @@ -388,6 +388,16 @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp)
> {
> RewriterState *s = FILTER_REWRITER(nf);
>
> + if (!s->vnet_hdr &&
> + qemu_opts_foreach(qemu_find_opts("device"),
> + vnet_driver_check, nf->netdev_id, NULL)) {
> + /*
> + * filter rewriter needs 'vnet_hdr_support' when colo filter modules
> + * work on virtio-net, add 'vnet_hdr_support' automatically
> + */
> + s->vnet_hdr = true;
> + }
> +
> s->connection_track_table = g_hash_table_new_full(connection_key_hash,
> connection_key_equal,
> g_free,
> diff --git a/qapi/qom.json b/qapi/qom.json
> index 6d5f4a88e6..442a963ba4 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -241,6 +241,11 @@
> # @notify_dev: name of the character device backend to be used to communicate
> # with the remote colo-frame (only for Xen COLO)
> #
> +# @netdev: id of the network device backend to colo-compare, although
> +# colo-compare doesn't depend on network device directly, this
> +# parameter help colo-compare know what network driver it is
> +# working on
> +#
> # @compare_timeout: the maximum time to hold a packet from @primary_in for
> # comparison with an incoming packet on @secondary_in in
> # milliseconds (default: 3000)
> @@ -264,6 +269,7 @@
> 'outdev': 'str',
> 'iothread': 'str',
> '*notify_dev': 'str',
> + '*netdev': 'str',
> '*compare_timeout': 'uint64',
> '*expired_scan_cycle': 'uint32',
> '*max_queue_size': 'uint32',
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 83aa59a920..b31ce3c87d 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -4957,12 +4957,14 @@ SRST
> stored. The file format is libpcap, so it can be analyzed with
> tools such as tcpdump or Wireshark.
>
> - ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
> + ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
> Colo-compare gets packet from primary\_in chardevid and
> secondary\_in, then compare whether the payload of primary packet
> and secondary packet are the same. If same, it will output
> primary packet to out\_dev, else it will notify COLO-framework to do
> - checkpoint and send primary packet to out\_dev. In order to
> + checkpoint and send primary packet to out\_dev. Although colo-compare
> + does not depend on network device directly, netdevid help
> + colo-compare know what network driver it is working on. In order to
> improve efficiency, we need to put the task of comparison in
> another iothread. If it has the vnet\_hdr\_support flag,
> colo compare will send/recv packet with vnet\_hdr\_len.
--
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net
2021-08-21 16:25 ` Lukas Straub
@ 2021-08-26 5:49 ` Zhang, Chen
2021-09-05 11:48 ` Lukas Straub
0 siblings, 1 reply; 7+ messages in thread
From: Zhang, Chen @ 2021-08-26 5:49 UTC (permalink / raw)
To: Lukas Straub, Xu, Tao3; +Cc: jasowang, qemu-devel, lizhijian
> -----Original Message-----
> From: Lukas Straub <lukasstraub2@web.de>
> Sent: Sunday, August 22, 2021 12:25 AM
> To: Xu, Tao3 <tao3.xu@intel.com>
> Cc: Zhang, Chen <chen.zhang@intel.com>; lizhijian@cn.fujitsu.com;
> jasowang@redhat.com; qemu-devel@nongnu.org
> Subject: Re: [PATCH v2] net/colo: check vnet_hdr_support flag when using
> virtio-net
>
> On Thu, 19 Aug 2021 09:27:17 +0800
> Tao Xu <tao3.xu@intel.com> wrote:
>
> > When COLO use only one vnet_hdr_support parameter between COLO
> network
> > filter(filter-mirror, filter-redirector or filter-rewriter and
> > colo-compare, packet will not be parsed correctly. Acquire network
> > driver related to COLO, if it is nirtio-net, check vnet_hdr_support
> > flag of COLO network filter and colo-compare.
> >
> > Signed-off-by: Tao Xu <tao3.xu@intel.com>
> > Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> > ---
> >
> > Changelog:
> > v2:
> > Detect virtio-net driver and apply vnet_hdr_support
> > automatically. (Jason)
> > ---
> > net/colo-compare.c | 57
> +++++++++++++++++++++++++++++++++++++++++++
> > net/colo.c | 20 +++++++++++++++
> > net/colo.h | 4 +++
> > net/filter-mirror.c | 21 ++++++++++++++++
> > net/filter-rewriter.c | 10 ++++++++
> > qapi/qom.json | 6 +++++
> > qemu-options.hx | 6 +++--
> > 7 files changed, 122 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/colo-compare.c b/net/colo-compare.c index
> > b100e7b51f..870bd05a41 100644
> > --- a/net/colo-compare.c
> > +++ b/net/colo-compare.c
> > @@ -110,6 +110,7 @@ struct CompareState {
> > char *sec_indev;
> > char *outdev;
> > char *notify_dev;
> > + char *netdev;
> > CharBackend chr_pri_in;
> > CharBackend chr_sec_in;
> > CharBackend chr_out;
> > @@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)
> > return COMPARE_READ_LEN_MAX;
> > }
> >
> > +static int colo_set_default_netdev(void *opaque, QemuOpts *opts,
> > +Error **errp) {
> > + const char *colo_obj_type, *netdev_from_filter;
> > + char **netdev = (char **)opaque;
> > +
> > + colo_obj_type = qemu_opt_get(opts, "qom-type");
> > +
> > + if (colo_obj_type &&
> > + (strcmp(colo_obj_type, "filter-mirror") == 0 ||
> > + strcmp(colo_obj_type, "filter-redirector") == 0 ||
> > + strcmp(colo_obj_type, "filter-rewriter") == 0)) {
> > + netdev_from_filter = qemu_opt_get(opts, "netdev");
> > + if (*netdev == NULL) {
> > + *netdev = g_strdup(netdev_from_filter);
> > + } else if (strcmp(*netdev, netdev_from_filter) != 0) {
> > + warn_report("%s is using a different netdev from other COLO "
> > + "component", colo_obj_type);
> > + }
> > + }
> > + return 0;
> > +}
> > +
>
> Hi,
> This doesn't properly handle the case where there are multiple network
> devices and one is virtio-net and the other isn't. This would be a regression as
> this worked fine before.
No, If have multiple network device this patch just report a warning for it.
You can still use virtio-net and others at the same time.
>
> > /*
> > * Called from the main thread on the primary for packets
> > * arriving over the socket from the primary.
> > @@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object *obj,
> > s->vnet_hdr = value;
> > }
> >
> > +static char *compare_get_netdev(Object *obj, Error **errp) {
> > + CompareState *s = COLO_COMPARE(obj);
> > +
> > + return g_strdup(s->netdev);
> > +}
> > +
> > +static void compare_set_netdev(Object *obj, const char *value, Error
> > +**errp) {
> > + CompareState *s = COLO_COMPARE(obj);
> > +
> > + g_free(s->netdev);
> > + s->netdev = g_strdup(value);
> > +}
> > +
> > static char *compare_get_notify_dev(Object *obj, Error **errp) {
> > CompareState *s = COLO_COMPARE(obj); @@ -1274,6 +1312,12 @@
> > static void colo_compare_complete(UserCreatable *uc, Error **errp)
> > max_queue_size = MAX_QUEUE_SIZE;
> > }
> >
> > + if (!s->netdev) {
> > + /* Set default netdev as the first colo netfilter found */
> > + qemu_opts_foreach(qemu_find_opts("object"),
> > + colo_set_default_netdev, &s->netdev, NULL);
> > + }
> > +
> > if (find_and_check_chardev(&chr, s->pri_indev, errp) ||
> > !qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) {
> > return;
> > @@ -1289,6 +1333,16 @@ static void
> colo_compare_complete(UserCreatable *uc, Error **errp)
> > return;
> > }
> >
> > + if (!s->vnet_hdr &&
> > + qemu_opts_foreach(qemu_find_opts("device"),
> > + vnet_driver_check, s->netdev, NULL)) {
> > + /*
> > + * colo compare needs 'vnet_hdr_support' when it works on virtio-net,
> > + * add 'vnet_hdr_support' automatically
> > + */
> > + s->vnet_hdr = true;
> > + }
> > +
>
> There is no way to disable vnet_hdr_support with virtio-net now.
Yes, It looks no reason to do this.
Please show me some details?
Thanks
Chen
>
> > net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);
> > net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize,
> > s->vnet_hdr);
> >
> > @@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj)
> > s->vnet_hdr = false;
> > object_property_add_bool(obj, "vnet_hdr_support",
> compare_get_vnet_hdr,
> > compare_set_vnet_hdr);
> > + /* colo compare can't varify that netdev is correct */
> > + object_property_add_str(obj, "netdev", compare_get_netdev,
> > + compare_set_netdev);
> > }
> >
> > void colo_compare_cleanup(void)
> > diff --git a/net/colo.c b/net/colo.c
> > index 3a3e6e89a0..4a03780f45 100644
> > --- a/net/colo.c
> > +++ b/net/colo.c
> > @@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable
> > *connection_track_table,
> >
> > return conn ? true : false;
> > }
> > +
> > +/* check the network driver related to COLO, return 1 if it is
> > +virtio-net */ int vnet_driver_check(void *opaque, QemuOpts *opts,
> > +Error **errp) {
> > + const char *driver_type, *netdev_from_driver;
> > + char *netdev_from_filter = (char *)opaque;
> > +
> > + driver_type = qemu_opt_get(opts, "driver");
> > + netdev_from_driver = qemu_opt_get(opts, "netdev");
> > +
> > + if (!driver_type || !netdev_from_driver || !netdev_from_filter) {
> > + return 0;
> > + }
> > +
> > + if (g_str_has_prefix(driver_type, "virtio-net") &&
> > + strcmp(netdev_from_driver, netdev_from_filter) == 0) {
> > + return 1;
> > + }
> > + return 0;
> > +}
> > diff --git a/net/colo.h b/net/colo.h
> > index d91cd245c4..d401fc76b6 100644
> > --- a/net/colo.h
> > +++ b/net/colo.h
> > @@ -18,6 +18,9 @@
> > #include "qemu/jhash.h"
> > #include "qemu/timer.h"
> > #include "net/eth.h"
> > +#include "qemu/option.h"
> > +#include "qemu/option_int.h"
> > +#include "qemu/config-file.h"
> >
> > #define HASHTABLE_MAX_SIZE 16384
> >
> > @@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size, int
> > vnet_hdr_len); Packet *packet_new_nocopy(void *data, int size, int
> > vnet_hdr_len); void packet_destroy(void *opaque, void *user_data);
> > void packet_destroy_partial(void *opaque, void *user_data);
> > +int vnet_driver_check(void *opaque, QemuOpts *opts, Error **errp);
> >
> > #endif /* NET_COLO_H */
> > diff --git a/net/filter-mirror.c b/net/filter-mirror.c index
> > f20240cc9f..69ca9c9839 100644
> > --- a/net/filter-mirror.c
> > +++ b/net/filter-mirror.c
> > @@ -12,6 +12,7 @@
> > #include "qemu/osdep.h"
> > #include "net/filter.h"
> > #include "net/net.h"
> > +#include "net/colo.h"
> > #include "qapi/error.h"
> > #include "qom/object.h"
> > #include "qemu/main-loop.h"
> > @@ -224,6 +225,16 @@ static void filter_mirror_setup(NetFilterState *nf,
> Error **errp)
> > return;
> > }
> >
> > + if (!s->vnet_hdr &&
> > + qemu_opts_foreach(qemu_find_opts("device"),
> > + vnet_driver_check, nf->netdev_id, NULL)) {
> > + /*
> > + * filter mirror needs 'vnet_hdr_support' when colo filter modules
> > + * work on virtio-net, add 'vnet_hdr_support' automatically
> > + */
> > + s->vnet_hdr = true;
> > + }
> > +
> > qemu_chr_fe_init(&s->chr_out, chr, errp); }
> >
> > @@ -252,6 +263,16 @@ static void filter_redirector_setup(NetFilterState
> *nf, Error **errp)
> > }
> > }
> >
> > + if (!s->vnet_hdr &&
> > + qemu_opts_foreach(qemu_find_opts("device"),
> > + vnet_driver_check, nf->netdev_id, NULL)) {
> > + /*
> > + * filter redirector needs 'vnet_hdr_support' when colo filter modules
> > + * work on virtio-net, add 'vnet_hdr_support' automatically
> > + */
> > + s->vnet_hdr = true;
> > + }
> > +
> > net_socket_rs_init(&s->rs, redirector_rs_finalize, s->vnet_hdr);
> >
> > if (s->indev) {
> > diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index
> > cb3a96cde1..637ef4ce71 100644
> > --- a/net/filter-rewriter.c
> > +++ b/net/filter-rewriter.c
> > @@ -388,6 +388,16 @@ static void colo_rewriter_setup(NetFilterState
> > *nf, Error **errp) {
> > RewriterState *s = FILTER_REWRITER(nf);
> >
> > + if (!s->vnet_hdr &&
> > + qemu_opts_foreach(qemu_find_opts("device"),
> > + vnet_driver_check, nf->netdev_id, NULL)) {
> > + /*
> > + * filter rewriter needs 'vnet_hdr_support' when colo filter modules
> > + * work on virtio-net, add 'vnet_hdr_support' automatically
> > + */
> > + s->vnet_hdr = true;
> > + }
> > +
> > s->connection_track_table =
> g_hash_table_new_full(connection_key_hash,
> > connection_key_equal,
> > g_free, diff
> > --git a/qapi/qom.json b/qapi/qom.json index 6d5f4a88e6..442a963ba4
> > 100644
> > --- a/qapi/qom.json
> > +++ b/qapi/qom.json
> > @@ -241,6 +241,11 @@
> > # @notify_dev: name of the character device backend to be used to
> communicate
> > # with the remote colo-frame (only for Xen COLO)
> > #
> > +# @netdev: id of the network device backend to colo-compare, although
> > +# colo-compare doesn't depend on network device directly, this
> > +# parameter help colo-compare know what network driver it is
> > +# working on
> > +#
> > # @compare_timeout: the maximum time to hold a packet from
> @primary_in for
> > # comparison with an incoming packet on @secondary_in in
> > # milliseconds (default: 3000)
> > @@ -264,6 +269,7 @@
> > 'outdev': 'str',
> > 'iothread': 'str',
> > '*notify_dev': 'str',
> > + '*netdev': 'str',
> > '*compare_timeout': 'uint64',
> > '*expired_scan_cycle': 'uint32',
> > '*max_queue_size': 'uint32', diff --git a/qemu-options.hx
> > b/qemu-options.hx index 83aa59a920..b31ce3c87d 100644
> > --- a/qemu-options.hx
> > +++ b/qemu-options.hx
> > @@ -4957,12 +4957,14 @@ SRST
> > stored. The file format is libpcap, so it can be analyzed with
> > tools such as tcpdump or Wireshark.
> >
> > - ``-object colo-
> compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chard
> evid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@
> var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
> > + ``-object
> > + colo-
> compare,id=id,primary_in=chardevid,secondary_in=chardevid,outde
> > + v=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify
> > +
> _dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,
> m
> > + ax_queue_size=@var{size}]``
> > Colo-compare gets packet from primary\_in chardevid and
> > secondary\_in, then compare whether the payload of primary packet
> > and secondary packet are the same. If same, it will output
> > primary packet to out\_dev, else it will notify COLO-framework to do
> > - checkpoint and send primary packet to out\_dev. In order to
> > + checkpoint and send primary packet to out\_dev. Although colo-
> compare
> > + does not depend on network device directly, netdevid help
> > + colo-compare know what network driver it is working on. In
> > + order to
> > improve efficiency, we need to put the task of comparison in
> > another iothread. If it has the vnet\_hdr\_support flag,
> > colo compare will send/recv packet with vnet\_hdr\_len.
>
>
>
> --
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net
2021-08-20 21:42 ` Eric Blake
@ 2021-08-26 5:59 ` Zhang, Chen
0 siblings, 0 replies; 7+ messages in thread
From: Zhang, Chen @ 2021-08-26 5:59 UTC (permalink / raw)
To: Eric Blake, Xu, Tao3; +Cc: jasowang, qemu-devel, lizhijian
> -----Original Message-----
> From: Eric Blake <eblake@redhat.com>
> Sent: Saturday, August 21, 2021 5:43 AM
> To: Xu, Tao3 <tao3.xu@intel.com>
> Cc: Zhang, Chen <chen.zhang@intel.com>; lizhijian@cn.fujitsu.com;
> jasowang@redhat.com; qemu-devel@nongnu.org
> Subject: Re: [PATCH v2] net/colo: check vnet_hdr_support flag when using
> virtio-net
>
> On Thu, Aug 19, 2021 at 09:27:17AM +0800, Tao Xu wrote:
> > When COLO use only one vnet_hdr_support parameter between COLO
> network
> > filter(filter-mirror, filter-redirector or filter-rewriter and
> > colo-compare, packet will not be parsed correctly. Acquire network
> > driver related to COLO, if it is nirtio-net, check vnet_hdr_support
> > flag of COLO network filter and colo-compare.
> >
> > Signed-off-by: Tao Xu <tao3.xu@intel.com>
> > Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> > ---
>
> > +++ b/qapi/qom.json
> > @@ -241,6 +241,11 @@
> > # @notify_dev: name of the character device backend to be used to
> communicate
> > # with the remote colo-frame (only for Xen COLO)
> > #
> > +# @netdev: id of the network device backend to colo-compare, although
> > +# colo-compare doesn't depend on network device directly, this
> > +# parameter help colo-compare know what network driver it is
> > +# working on
>
> Missing a '(since 6.2)' tag.
>
> Grammar suggestion: s/colo-compare, although/colo-compare. Although/
> s/help/helps/
>
OK.
>
>
> > +#
> > # @compare_timeout: the maximum time to hold a packet from
> @primary_in for
> > # comparison with an incoming packet on @secondary_in in
> > # milliseconds (default: 3000)
> > @@ -264,6 +269,7 @@
> > 'outdev': 'str',
> > 'iothread': 'str',
> > '*notify_dev': 'str',
> > + '*netdev': 'str',
> > '*compare_timeout': 'uint64',
> > '*expired_scan_cycle': 'uint32',
> > '*max_queue_size': 'uint32', diff --git a/qemu-options.hx
> > b/qemu-options.hx index 83aa59a920..b31ce3c87d 100644
> > --- a/qemu-options.hx
> > +++ b/qemu-options.hx
> > @@ -4957,12 +4957,14 @@ SRST
> > stored. The file format is libpcap, so it can be analyzed with
> > tools such as tcpdump or Wireshark.
> >
> > - ``-object colo-
> compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chard
> evid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@
> var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
> > + ``-object
> > + colo-
> compare,id=id,primary_in=chardevid,secondary_in=chardevid,outde
> > + v=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify
> > +
> _dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,
> m
> > + ax_queue_size=@var{size}]``
> > Colo-compare gets packet from primary\_in chardevid and
> > secondary\_in, then compare whether the payload of primary packet
> > and secondary packet are the same. If same, it will output
> > primary packet to out\_dev, else it will notify COLO-framework to do
> > - checkpoint and send primary packet to out\_dev. In order to
> > + checkpoint and send primary packet to out\_dev. Although colo-
> compare
> > + does not depend on network device directly, netdevid help
>
> s/help/helps/
OK, will fix in next version.
Thanks
Chen
>
> > + colo-compare know what network driver it is working on. In
> > + order to
> > improve efficiency, we need to put the task of comparison in
> > another iothread. If it has the vnet\_hdr\_support flag,
> > colo compare will send/recv packet with vnet\_hdr\_len.
> > --
> > 2.25.1
> >
> >
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc. +1-919-301-3266
> Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net
2021-08-26 5:49 ` Zhang, Chen
@ 2021-09-05 11:48 ` Lukas Straub
2021-09-09 13:43 ` Zhang, Chen
0 siblings, 1 reply; 7+ messages in thread
From: Lukas Straub @ 2021-09-05 11:48 UTC (permalink / raw)
To: Zhang, Chen; +Cc: Xu, Tao3, jasowang, lizhijian, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 14386 bytes --]
On Thu, 26 Aug 2021 05:49:23 +0000
"Zhang, Chen" <chen.zhang@intel.com> wrote:
> > -----Original Message-----
> > From: Lukas Straub <lukasstraub2@web.de>
> > Sent: Sunday, August 22, 2021 12:25 AM
> > To: Xu, Tao3 <tao3.xu@intel.com>
> > Cc: Zhang, Chen <chen.zhang@intel.com>; lizhijian@cn.fujitsu.com;
> > jasowang@redhat.com; qemu-devel@nongnu.org
> > Subject: Re: [PATCH v2] net/colo: check vnet_hdr_support flag when using
> > virtio-net
> >
> > On Thu, 19 Aug 2021 09:27:17 +0800
> > Tao Xu <tao3.xu@intel.com> wrote:
> >
> > > When COLO use only one vnet_hdr_support parameter between COLO
> > network
> > > filter(filter-mirror, filter-redirector or filter-rewriter and
> > > colo-compare, packet will not be parsed correctly. Acquire network
> > > driver related to COLO, if it is nirtio-net, check vnet_hdr_support
> > > flag of COLO network filter and colo-compare.
> > >
> > > Signed-off-by: Tao Xu <tao3.xu@intel.com>
> > > Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> > > ---
> > >
> > > Changelog:
> > > v2:
> > > Detect virtio-net driver and apply vnet_hdr_support
> > > automatically. (Jason)
> > > ---
> > > net/colo-compare.c | 57
> > +++++++++++++++++++++++++++++++++++++++++++
> > > net/colo.c | 20 +++++++++++++++
> > > net/colo.h | 4 +++
> > > net/filter-mirror.c | 21 ++++++++++++++++
> > > net/filter-rewriter.c | 10 ++++++++
> > > qapi/qom.json | 6 +++++
> > > qemu-options.hx | 6 +++--
> > > 7 files changed, 122 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/net/colo-compare.c b/net/colo-compare.c index
> > > b100e7b51f..870bd05a41 100644
> > > --- a/net/colo-compare.c
> > > +++ b/net/colo-compare.c
> > > @@ -110,6 +110,7 @@ struct CompareState {
> > > char *sec_indev;
> > > char *outdev;
> > > char *notify_dev;
> > > + char *netdev;
> > > CharBackend chr_pri_in;
> > > CharBackend chr_sec_in;
> > > CharBackend chr_out;
> > > @@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)
> > > return COMPARE_READ_LEN_MAX;
> > > }
> > >
> > > +static int colo_set_default_netdev(void *opaque, QemuOpts *opts,
> > > +Error **errp) {
> > > + const char *colo_obj_type, *netdev_from_filter;
> > > + char **netdev = (char **)opaque;
> > > +
> > > + colo_obj_type = qemu_opt_get(opts, "qom-type");
> > > +
> > > + if (colo_obj_type &&
> > > + (strcmp(colo_obj_type, "filter-mirror") == 0 ||
> > > + strcmp(colo_obj_type, "filter-redirector") == 0 ||
> > > + strcmp(colo_obj_type, "filter-rewriter") == 0)) {
> > > + netdev_from_filter = qemu_opt_get(opts, "netdev");
> > > + if (*netdev == NULL) {
> > > + *netdev = g_strdup(netdev_from_filter);
> > > + } else if (strcmp(*netdev, netdev_from_filter) != 0) {
> > > + warn_report("%s is using a different netdev from other COLO "
> > > + "component", colo_obj_type);
> > > + }
> > > + }
> > > + return 0;
> > > +}
> > > +
> >
> > Hi,
> > This doesn't properly handle the case where there are multiple network
> > devices and one is virtio-net and the other isn't. This would be a regression as
> > this worked fine before.
>
> No, If have multiple network device this patch just report a warning for it.
> You can still use virtio-net and others at the same time.
As you see it sets netdev to the first filter's netdev. So if
the first netdev is virtio-net and the 2nd is e1000 (for example) it'll
see virtio-net first and set *netdev to it for _both_ devices. Then it
sees the e1000 and prints the warning, but *netdev is still set to
virtio-net. So it'll enable vnet_hdr for e1000 too and segfault when
processing a packet because e1000 doesn't support vnet_hdr.
> >
> > > /*
> > > * Called from the main thread on the primary for packets
> > > * arriving over the socket from the primary.
> > > @@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object *obj,
> > > s->vnet_hdr = value;
> > > }
> > >
> > > +static char *compare_get_netdev(Object *obj, Error **errp) {
> > > + CompareState *s = COLO_COMPARE(obj);
> > > +
> > > + return g_strdup(s->netdev);
> > > +}
> > > +
> > > +static void compare_set_netdev(Object *obj, const char *value, Error
> > > +**errp) {
> > > + CompareState *s = COLO_COMPARE(obj);
> > > +
> > > + g_free(s->netdev);
> > > + s->netdev = g_strdup(value);
> > > +}
> > > +
> > > static char *compare_get_notify_dev(Object *obj, Error **errp) {
> > > CompareState *s = COLO_COMPARE(obj); @@ -1274,6 +1312,12 @@
> > > static void colo_compare_complete(UserCreatable *uc, Error **errp)
> > > max_queue_size = MAX_QUEUE_SIZE;
> > > }
> > >
> > > + if (!s->netdev) {
> > > + /* Set default netdev as the first colo netfilter found */
> > > + qemu_opts_foreach(qemu_find_opts("object"),
> > > + colo_set_default_netdev, &s->netdev, NULL);
> > > + }
> > > +
> > > if (find_and_check_chardev(&chr, s->pri_indev, errp) ||
> > > !qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) {
> > > return;
> > > @@ -1289,6 +1333,16 @@ static void
> > colo_compare_complete(UserCreatable *uc, Error **errp)
> > > return;
> > > }
> > >
> > > + if (!s->vnet_hdr &&
> > > + qemu_opts_foreach(qemu_find_opts("device"),
> > > + vnet_driver_check, s->netdev, NULL)) {
> > > + /*
> > > + * colo compare needs 'vnet_hdr_support' when it works on virtio-net,
> > > + * add 'vnet_hdr_support' automatically
> > > + */
> > > + s->vnet_hdr = true;
> > > + }
> > > +
> >
> > There is no way to disable vnet_hdr_support with virtio-net now.
>
> Yes, It looks no reason to do this.
> Please show me some details?
>
> Thanks
> Chen
>
> >
> > > net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);
> > > net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize,
> > > s->vnet_hdr);
> > >
> > > @@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj)
> > > s->vnet_hdr = false;
> > > object_property_add_bool(obj, "vnet_hdr_support",
> > compare_get_vnet_hdr,
> > > compare_set_vnet_hdr);
> > > + /* colo compare can't varify that netdev is correct */
> > > + object_property_add_str(obj, "netdev", compare_get_netdev,
> > > + compare_set_netdev);
> > > }
> > >
> > > void colo_compare_cleanup(void)
> > > diff --git a/net/colo.c b/net/colo.c
> > > index 3a3e6e89a0..4a03780f45 100644
> > > --- a/net/colo.c
> > > +++ b/net/colo.c
> > > @@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable
> > > *connection_track_table,
> > >
> > > return conn ? true : false;
> > > }
> > > +
> > > +/* check the network driver related to COLO, return 1 if it is
> > > +virtio-net */ int vnet_driver_check(void *opaque, QemuOpts *opts,
> > > +Error **errp) {
> > > + const char *driver_type, *netdev_from_driver;
> > > + char *netdev_from_filter = (char *)opaque;
> > > +
> > > + driver_type = qemu_opt_get(opts, "driver");
> > > + netdev_from_driver = qemu_opt_get(opts, "netdev");
> > > +
> > > + if (!driver_type || !netdev_from_driver || !netdev_from_filter) {
> > > + return 0;
> > > + }
> > > +
> > > + if (g_str_has_prefix(driver_type, "virtio-net") &&
> > > + strcmp(netdev_from_driver, netdev_from_filter) == 0) {
> > > + return 1;
> > > + }
> > > + return 0;
> > > +}
> > > diff --git a/net/colo.h b/net/colo.h
> > > index d91cd245c4..d401fc76b6 100644
> > > --- a/net/colo.h
> > > +++ b/net/colo.h
> > > @@ -18,6 +18,9 @@
> > > #include "qemu/jhash.h"
> > > #include "qemu/timer.h"
> > > #include "net/eth.h"
> > > +#include "qemu/option.h"
> > > +#include "qemu/option_int.h"
> > > +#include "qemu/config-file.h"
> > >
> > > #define HASHTABLE_MAX_SIZE 16384
> > >
> > > @@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size, int
> > > vnet_hdr_len); Packet *packet_new_nocopy(void *data, int size, int
> > > vnet_hdr_len); void packet_destroy(void *opaque, void *user_data);
> > > void packet_destroy_partial(void *opaque, void *user_data);
> > > +int vnet_driver_check(void *opaque, QemuOpts *opts, Error **errp);
> > >
> > > #endif /* NET_COLO_H */
> > > diff --git a/net/filter-mirror.c b/net/filter-mirror.c index
> > > f20240cc9f..69ca9c9839 100644
> > > --- a/net/filter-mirror.c
> > > +++ b/net/filter-mirror.c
> > > @@ -12,6 +12,7 @@
> > > #include "qemu/osdep.h"
> > > #include "net/filter.h"
> > > #include "net/net.h"
> > > +#include "net/colo.h"
> > > #include "qapi/error.h"
> > > #include "qom/object.h"
> > > #include "qemu/main-loop.h"
> > > @@ -224,6 +225,16 @@ static void filter_mirror_setup(NetFilterState *nf,
> > Error **errp)
> > > return;
> > > }
> > >
> > > + if (!s->vnet_hdr &&
> > > + qemu_opts_foreach(qemu_find_opts("device"),
> > > + vnet_driver_check, nf->netdev_id, NULL)) {
> > > + /*
> > > + * filter mirror needs 'vnet_hdr_support' when colo filter modules
> > > + * work on virtio-net, add 'vnet_hdr_support' automatically
> > > + */
> > > + s->vnet_hdr = true;
> > > + }
> > > +
> > > qemu_chr_fe_init(&s->chr_out, chr, errp); }
> > >
> > > @@ -252,6 +263,16 @@ static void filter_redirector_setup(NetFilterState
> > *nf, Error **errp)
> > > }
> > > }
> > >
> > > + if (!s->vnet_hdr &&
> > > + qemu_opts_foreach(qemu_find_opts("device"),
> > > + vnet_driver_check, nf->netdev_id, NULL)) {
> > > + /*
> > > + * filter redirector needs 'vnet_hdr_support' when colo filter modules
> > > + * work on virtio-net, add 'vnet_hdr_support' automatically
> > > + */
> > > + s->vnet_hdr = true;
> > > + }
> > > +
> > > net_socket_rs_init(&s->rs, redirector_rs_finalize, s->vnet_hdr);
> > >
> > > if (s->indev) {
> > > diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index
> > > cb3a96cde1..637ef4ce71 100644
> > > --- a/net/filter-rewriter.c
> > > +++ b/net/filter-rewriter.c
> > > @@ -388,6 +388,16 @@ static void colo_rewriter_setup(NetFilterState
> > > *nf, Error **errp) {
> > > RewriterState *s = FILTER_REWRITER(nf);
> > >
> > > + if (!s->vnet_hdr &&
> > > + qemu_opts_foreach(qemu_find_opts("device"),
> > > + vnet_driver_check, nf->netdev_id, NULL)) {
> > > + /*
> > > + * filter rewriter needs 'vnet_hdr_support' when colo filter modules
> > > + * work on virtio-net, add 'vnet_hdr_support' automatically
> > > + */
> > > + s->vnet_hdr = true;
> > > + }
> > > +
> > > s->connection_track_table =
> > g_hash_table_new_full(connection_key_hash,
> > > connection_key_equal,
> > > g_free, diff
> > > --git a/qapi/qom.json b/qapi/qom.json index 6d5f4a88e6..442a963ba4
> > > 100644
> > > --- a/qapi/qom.json
> > > +++ b/qapi/qom.json
> > > @@ -241,6 +241,11 @@
> > > # @notify_dev: name of the character device backend to be used to
> > communicate
> > > # with the remote colo-frame (only for Xen COLO)
> > > #
> > > +# @netdev: id of the network device backend to colo-compare, although
> > > +# colo-compare doesn't depend on network device directly, this
> > > +# parameter help colo-compare know what network driver it is
> > > +# working on
> > > +#
> > > # @compare_timeout: the maximum time to hold a packet from
> > @primary_in for
> > > # comparison with an incoming packet on @secondary_in in
> > > # milliseconds (default: 3000)
> > > @@ -264,6 +269,7 @@
> > > 'outdev': 'str',
> > > 'iothread': 'str',
> > > '*notify_dev': 'str',
> > > + '*netdev': 'str',
> > > '*compare_timeout': 'uint64',
> > > '*expired_scan_cycle': 'uint32',
> > > '*max_queue_size': 'uint32', diff --git a/qemu-options.hx
> > > b/qemu-options.hx index 83aa59a920..b31ce3c87d 100644
> > > --- a/qemu-options.hx
> > > +++ b/qemu-options.hx
> > > @@ -4957,12 +4957,14 @@ SRST
> > > stored. The file format is libpcap, so it can be analyzed with
> > > tools such as tcpdump or Wireshark.
> > >
> > > - ``-object colo-
> > compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chard
> > evid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@
> > var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
> > > + ``-object
> > > + colo-
> > compare,id=id,primary_in=chardevid,secondary_in=chardevid,outde
> > > + v=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify
> > > +
> > _dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,
> > m
> > > + ax_queue_size=@var{size}]``
> > > Colo-compare gets packet from primary\_in chardevid and
> > > secondary\_in, then compare whether the payload of primary packet
> > > and secondary packet are the same. If same, it will output
> > > primary packet to out\_dev, else it will notify COLO-framework to do
> > > - checkpoint and send primary packet to out\_dev. In order to
> > > + checkpoint and send primary packet to out\_dev. Although colo-
> > compare
> > > + does not depend on network device directly, netdevid help
> > > + colo-compare know what network driver it is working on. In
> > > + order to
> > > improve efficiency, we need to put the task of comparison in
> > > another iothread. If it has the vnet\_hdr\_support flag,
> > > colo compare will send/recv packet with vnet\_hdr\_len.
> >
> >
> >
> > --
>
--
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net
2021-09-05 11:48 ` Lukas Straub
@ 2021-09-09 13:43 ` Zhang, Chen
0 siblings, 0 replies; 7+ messages in thread
From: Zhang, Chen @ 2021-09-09 13:43 UTC (permalink / raw)
To: Lukas Straub; +Cc: Xu, Tao3, jasowang, lizhijian, qemu-devel
> -----Original Message-----
> From: Lukas Straub <lukasstraub2@web.de>
> Sent: Sunday, September 5, 2021 7:48 PM
> To: Zhang, Chen <chen.zhang@intel.com>
> Cc: Xu, Tao3 <tao3.xu@intel.com>; lizhijian@cn.fujitsu.com;
> jasowang@redhat.com; qemu-devel@nongnu.org
> Subject: Re: [PATCH v2] net/colo: check vnet_hdr_support flag when using
> virtio-net
>
> On Thu, 26 Aug 2021 05:49:23 +0000
> "Zhang, Chen" <chen.zhang@intel.com> wrote:
>
> > > -----Original Message-----
> > > From: Lukas Straub <lukasstraub2@web.de>
> > > Sent: Sunday, August 22, 2021 12:25 AM
> > > To: Xu, Tao3 <tao3.xu@intel.com>
> > > Cc: Zhang, Chen <chen.zhang@intel.com>; lizhijian@cn.fujitsu.com;
> > > jasowang@redhat.com; qemu-devel@nongnu.org
> > > Subject: Re: [PATCH v2] net/colo: check vnet_hdr_support flag when
> > > using virtio-net
> > >
> > > On Thu, 19 Aug 2021 09:27:17 +0800
> > > Tao Xu <tao3.xu@intel.com> wrote:
> > >
> > > > When COLO use only one vnet_hdr_support parameter between COLO
> > > network
> > > > filter(filter-mirror, filter-redirector or filter-rewriter and
> > > > colo-compare, packet will not be parsed correctly. Acquire network
> > > > driver related to COLO, if it is nirtio-net, check
> > > > vnet_hdr_support flag of COLO network filter and colo-compare.
> > > >
> > > > Signed-off-by: Tao Xu <tao3.xu@intel.com>
> > > > Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> > > > ---
> > > >
> > > > Changelog:
> > > > v2:
> > > > Detect virtio-net driver and apply vnet_hdr_support
> > > > automatically. (Jason)
> > > > ---
> > > > net/colo-compare.c | 57
> > > +++++++++++++++++++++++++++++++++++++++++++
> > > > net/colo.c | 20 +++++++++++++++
> > > > net/colo.h | 4 +++
> > > > net/filter-mirror.c | 21 ++++++++++++++++
> > > > net/filter-rewriter.c | 10 ++++++++
> > > > qapi/qom.json | 6 +++++
> > > > qemu-options.hx | 6 +++--
> > > > 7 files changed, 122 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/net/colo-compare.c b/net/colo-compare.c index
> > > > b100e7b51f..870bd05a41 100644
> > > > --- a/net/colo-compare.c
> > > > +++ b/net/colo-compare.c
> > > > @@ -110,6 +110,7 @@ struct CompareState {
> > > > char *sec_indev;
> > > > char *outdev;
> > > > char *notify_dev;
> > > > + char *netdev;
> > > > CharBackend chr_pri_in;
> > > > CharBackend chr_sec_in;
> > > > CharBackend chr_out;
> > > > @@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)
> > > > return COMPARE_READ_LEN_MAX;
> > > > }
> > > >
> > > > +static int colo_set_default_netdev(void *opaque, QemuOpts *opts,
> > > > +Error **errp) {
> > > > + const char *colo_obj_type, *netdev_from_filter;
> > > > + char **netdev = (char **)opaque;
> > > > +
> > > > + colo_obj_type = qemu_opt_get(opts, "qom-type");
> > > > +
> > > > + if (colo_obj_type &&
> > > > + (strcmp(colo_obj_type, "filter-mirror") == 0 ||
> > > > + strcmp(colo_obj_type, "filter-redirector") == 0 ||
> > > > + strcmp(colo_obj_type, "filter-rewriter") == 0)) {
> > > > + netdev_from_filter = qemu_opt_get(opts, "netdev");
> > > > + if (*netdev == NULL) {
> > > > + *netdev = g_strdup(netdev_from_filter);
> > > > + } else if (strcmp(*netdev, netdev_from_filter) != 0) {
> > > > + warn_report("%s is using a different netdev from other COLO "
> > > > + "component", colo_obj_type);
> > > > + }
> > > > + }
> > > > + return 0;
> > > > +}
> > > > +
> > >
> > > Hi,
> > > This doesn't properly handle the case where there are multiple
> > > network devices and one is virtio-net and the other isn't. This
> > > would be a regression as this worked fine before.
> >
> > No, If have multiple network device this patch just report a warning for it.
> > You can still use virtio-net and others at the same time.
>
> As you see it sets netdev to the first filter's netdev. So if the first netdev is
> virtio-net and the 2nd is e1000 (for example) it'll see virtio-net first and set
> *netdev to it for _both_ devices. Then it sees the e1000 and prints the
> warning, but *netdev is still set to virtio-net. So it'll enable vnet_hdr for
> e1000 too and segfault when processing a packet because e1000 doesn't
> support vnet_hdr.
Hi Lukas,
Thanks your review~ This patch just focus on colo-compare and net-filter's vnet_hdr flag, not related to real netdev's flag (like e1000 vnet_hdr).
So, we can't setup the vnet_hdr to e1000 at any time.
Back to this question, If the first filter's netdev is virtio-net, we will set the "*netdev" in colo-compare module,
As we know, The colo-compare module won't really attach to any netdev, the "*netdev" just a flag to show we have a related filter used virtio-net.
We'd better to enable other filter's flag to make all colo-proxy works. And the filter module with e1000, we haven't enough information to repair.
Thanks
Chen
>
> > >
> > > > /*
> > > > * Called from the main thread on the primary for packets
> > > > * arriving over the socket from the primary.
> > > > @@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object
> *obj,
> > > > s->vnet_hdr = value;
> > > > }
> > > >
> > > > +static char *compare_get_netdev(Object *obj, Error **errp) {
> > > > + CompareState *s = COLO_COMPARE(obj);
> > > > +
> > > > + return g_strdup(s->netdev);
> > > > +}
> > > > +
> > > > +static void compare_set_netdev(Object *obj, const char *value,
> > > > +Error
> > > > +**errp) {
> > > > + CompareState *s = COLO_COMPARE(obj);
> > > > +
> > > > + g_free(s->netdev);
> > > > + s->netdev = g_strdup(value);
> > > > +}
> > > > +
> > > > static char *compare_get_notify_dev(Object *obj, Error **errp) {
> > > > CompareState *s = COLO_COMPARE(obj); @@ -1274,6 +1312,12 @@
> > > > static void colo_compare_complete(UserCreatable *uc, Error **errp)
> > > > max_queue_size = MAX_QUEUE_SIZE;
> > > > }
> > > >
> > > > + if (!s->netdev) {
> > > > + /* Set default netdev as the first colo netfilter found */
> > > > + qemu_opts_foreach(qemu_find_opts("object"),
> > > > + colo_set_default_netdev, &s->netdev, NULL);
> > > > + }
> > > > +
> > > > if (find_and_check_chardev(&chr, s->pri_indev, errp) ||
> > > > !qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) {
> > > > return;
> > > > @@ -1289,6 +1333,16 @@ static void
> > > colo_compare_complete(UserCreatable *uc, Error **errp)
> > > > return;
> > > > }
> > > >
> > > > + if (!s->vnet_hdr &&
> > > > + qemu_opts_foreach(qemu_find_opts("device"),
> > > > + vnet_driver_check, s->netdev, NULL)) {
> > > > + /*
> > > > + * colo compare needs 'vnet_hdr_support' when it works on
> virtio-net,
> > > > + * add 'vnet_hdr_support' automatically
> > > > + */
> > > > + s->vnet_hdr = true;
> > > > + }
> > > > +
> > >
> > > There is no way to disable vnet_hdr_support with virtio-net now.
> >
> > Yes, It looks no reason to do this.
> > Please show me some details?
> >
> > Thanks
> > Chen
> >
> > >
> > > > net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s-
> >vnet_hdr);
> > > > net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize,
> > > > s->vnet_hdr);
> > > >
> > > > @@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj)
> > > > s->vnet_hdr = false;
> > > > object_property_add_bool(obj, "vnet_hdr_support",
> > > compare_get_vnet_hdr,
> > > > compare_set_vnet_hdr);
> > > > + /* colo compare can't varify that netdev is correct */
> > > > + object_property_add_str(obj, "netdev", compare_get_netdev,
> > > > + compare_set_netdev);
> > > > }
> > > >
> > > > void colo_compare_cleanup(void)
> > > > diff --git a/net/colo.c b/net/colo.c index 3a3e6e89a0..4a03780f45
> > > > 100644
> > > > --- a/net/colo.c
> > > > +++ b/net/colo.c
> > > > @@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable
> > > > *connection_track_table,
> > > >
> > > > return conn ? true : false;
> > > > }
> > > > +
> > > > +/* check the network driver related to COLO, return 1 if it is
> > > > +virtio-net */ int vnet_driver_check(void *opaque, QemuOpts *opts,
> > > > +Error **errp) {
> > > > + const char *driver_type, *netdev_from_driver;
> > > > + char *netdev_from_filter = (char *)opaque;
> > > > +
> > > > + driver_type = qemu_opt_get(opts, "driver");
> > > > + netdev_from_driver = qemu_opt_get(opts, "netdev");
> > > > +
> > > > + if (!driver_type || !netdev_from_driver || !netdev_from_filter) {
> > > > + return 0;
> > > > + }
> > > > +
> > > > + if (g_str_has_prefix(driver_type, "virtio-net") &&
> > > > + strcmp(netdev_from_driver, netdev_from_filter) == 0) {
> > > > + return 1;
> > > > + }
> > > > + return 0;
> > > > +}
> > > > diff --git a/net/colo.h b/net/colo.h index d91cd245c4..d401fc76b6
> > > > 100644
> > > > --- a/net/colo.h
> > > > +++ b/net/colo.h
> > > > @@ -18,6 +18,9 @@
> > > > #include "qemu/jhash.h"
> > > > #include "qemu/timer.h"
> > > > #include "net/eth.h"
> > > > +#include "qemu/option.h"
> > > > +#include "qemu/option_int.h"
> > > > +#include "qemu/config-file.h"
> > > >
> > > > #define HASHTABLE_MAX_SIZE 16384
> > > >
> > > > @@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size,
> > > > int vnet_hdr_len); Packet *packet_new_nocopy(void *data, int
> > > > size, int vnet_hdr_len); void packet_destroy(void *opaque, void
> > > > *user_data); void packet_destroy_partial(void *opaque, void
> > > > *user_data);
> > > > +int vnet_driver_check(void *opaque, QemuOpts *opts, Error
> > > > +**errp);
> > > >
> > > > #endif /* NET_COLO_H */
> > > > diff --git a/net/filter-mirror.c b/net/filter-mirror.c index
> > > > f20240cc9f..69ca9c9839 100644
> > > > --- a/net/filter-mirror.c
> > > > +++ b/net/filter-mirror.c
> > > > @@ -12,6 +12,7 @@
> > > > #include "qemu/osdep.h"
> > > > #include "net/filter.h"
> > > > #include "net/net.h"
> > > > +#include "net/colo.h"
> > > > #include "qapi/error.h"
> > > > #include "qom/object.h"
> > > > #include "qemu/main-loop.h"
> > > > @@ -224,6 +225,16 @@ static void
> > > > filter_mirror_setup(NetFilterState *nf,
> > > Error **errp)
> > > > return;
> > > > }
> > > >
> > > > + if (!s->vnet_hdr &&
> > > > + qemu_opts_foreach(qemu_find_opts("device"),
> > > > + vnet_driver_check, nf->netdev_id, NULL)) {
> > > > + /*
> > > > + * filter mirror needs 'vnet_hdr_support' when colo filter modules
> > > > + * work on virtio-net, add 'vnet_hdr_support' automatically
> > > > + */
> > > > + s->vnet_hdr = true;
> > > > + }
> > > > +
> > > > qemu_chr_fe_init(&s->chr_out, chr, errp); }
> > > >
> > > > @@ -252,6 +263,16 @@ static void
> > > > filter_redirector_setup(NetFilterState
> > > *nf, Error **errp)
> > > > }
> > > > }
> > > >
> > > > + if (!s->vnet_hdr &&
> > > > + qemu_opts_foreach(qemu_find_opts("device"),
> > > > + vnet_driver_check, nf->netdev_id, NULL)) {
> > > > + /*
> > > > + * filter redirector needs 'vnet_hdr_support' when colo filter
> modules
> > > > + * work on virtio-net, add 'vnet_hdr_support' automatically
> > > > + */
> > > > + s->vnet_hdr = true;
> > > > + }
> > > > +
> > > > net_socket_rs_init(&s->rs, redirector_rs_finalize,
> > > > s->vnet_hdr);
> > > >
> > > > if (s->indev) {
> > > > diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index
> > > > cb3a96cde1..637ef4ce71 100644
> > > > --- a/net/filter-rewriter.c
> > > > +++ b/net/filter-rewriter.c
> > > > @@ -388,6 +388,16 @@ static void
> > > > colo_rewriter_setup(NetFilterState
> > > > *nf, Error **errp) {
> > > > RewriterState *s = FILTER_REWRITER(nf);
> > > >
> > > > + if (!s->vnet_hdr &&
> > > > + qemu_opts_foreach(qemu_find_opts("device"),
> > > > + vnet_driver_check, nf->netdev_id, NULL)) {
> > > > + /*
> > > > + * filter rewriter needs 'vnet_hdr_support' when colo filter
> modules
> > > > + * work on virtio-net, add 'vnet_hdr_support' automatically
> > > > + */
> > > > + s->vnet_hdr = true;
> > > > + }
> > > > +
> > > > s->connection_track_table =
> > > g_hash_table_new_full(connection_key_hash,
> > > > connection_key_equal,
> > > > g_free,
> > > > diff --git a/qapi/qom.json b/qapi/qom.json index
> > > > 6d5f4a88e6..442a963ba4
> > > > 100644
> > > > --- a/qapi/qom.json
> > > > +++ b/qapi/qom.json
> > > > @@ -241,6 +241,11 @@
> > > > # @notify_dev: name of the character device backend to be used to
> > > communicate
> > > > # with the remote colo-frame (only for Xen COLO)
> > > > #
> > > > +# @netdev: id of the network device backend to colo-compare,
> although
> > > > +# colo-compare doesn't depend on network device directly, this
> > > > +# parameter help colo-compare know what network driver it is
> > > > +# working on
> > > > +#
> > > > # @compare_timeout: the maximum time to hold a packet from
> > > @primary_in for
> > > > # comparison with an incoming packet on @secondary_in in
> > > > # milliseconds (default: 3000)
> > > > @@ -264,6 +269,7 @@
> > > > 'outdev': 'str',
> > > > 'iothread': 'str',
> > > > '*notify_dev': 'str',
> > > > + '*netdev': 'str',
> > > > '*compare_timeout': 'uint64',
> > > > '*expired_scan_cycle': 'uint32',
> > > > '*max_queue_size': 'uint32', diff --git
> > > > a/qemu-options.hx b/qemu-options.hx index 83aa59a920..b31ce3c87d
> > > > 100644
> > > > --- a/qemu-options.hx
> > > > +++ b/qemu-options.hx
> > > > @@ -4957,12 +4957,14 @@ SRST
> > > > stored. The file format is libpcap, so it can be analyzed with
> > > > tools such as tcpdump or Wireshark.
> > > >
> > > > - ``-object colo-
> > >
> compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=cha
> > > rd
> > > evid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout
> > > =@
> > >
> var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
> > > > + ``-object
> > > > + colo-
> > > compare,id=id,primary_in=chardevid,secondary_in=chardevid,outde
> > > > + v=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,no
> > > > + tify
> > > > +
> > >
> _dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,
> > > m
> > > > + ax_queue_size=@var{size}]``
> > > > Colo-compare gets packet from primary\_in chardevid and
> > > > secondary\_in, then compare whether the payload of primary
> packet
> > > > and secondary packet are the same. If same, it will output
> > > > primary packet to out\_dev, else it will notify COLO-framework to
> do
> > > > - checkpoint and send primary packet to out\_dev. In order to
> > > > + checkpoint and send primary packet to out\_dev. Although
> > > > + colo-
> > > compare
> > > > + does not depend on network device directly, netdevid help
> > > > + colo-compare know what network driver it is working on.
> > > > + In order to
> > > > improve efficiency, we need to put the task of comparison in
> > > > another iothread. If it has the vnet\_hdr\_support flag,
> > > > colo compare will send/recv packet with vnet\_hdr\_len.
> > >
> > >
> > >
> > > --
> >
>
>
>
> --
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-09-09 13:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 1:27 [PATCH v2] net/colo: check vnet_hdr_support flag when using virtio-net Tao Xu
2021-08-20 21:42 ` Eric Blake
2021-08-26 5:59 ` Zhang, Chen
2021-08-21 16:25 ` Lukas Straub
2021-08-26 5:49 ` Zhang, Chen
2021-09-05 11:48 ` Lukas Straub
2021-09-09 13:43 ` Zhang, Chen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.