The default buffer filter doesn't buffer packets in default, but we need to buffer packets for COLO or Micro-checkpoint, Here we add a helper function to enable/disable filter's buffer capability.
Signed-off-by: zhanghailiang <zhang.zhanghaili...@huawei.com> Cc: Jason Wang <jasow...@redhat.com> Cc: Yang Hongyang <hongyang.y...@easystack.cn> --- v11: - New patch --- include/net/filter.h | 1 + include/net/net.h | 4 ++++ net/filter-buffer.c | 20 ++++++++++++++++++++ net/net.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/include/net/filter.h b/include/net/filter.h index 01a7e90..b57b29a 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -77,4 +77,5 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void netdev_add_default_filter_buffer(const char *netdev_id, NetFilterDirection direction, Error **errp); +void qemu_set_default_filter_buffers(bool enable_buffer); #endif /* QEMU_NET_FILTER_H */ diff --git a/include/net/net.h b/include/net/net.h index 7af3e15..5c65c45 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -125,6 +125,10 @@ NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, const char *client_str); typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque); void qemu_foreach_nic(qemu_nic_foreach func, void *opaque); +typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, + Error **errp); +void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, + Error **errp); int qemu_can_send_packet(NetClientState *nc); ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov, int iovcnt); diff --git a/net/filter-buffer.c b/net/filter-buffer.c index 5cab4fc..7115a2b 100644 --- a/net/filter-buffer.c +++ b/net/filter-buffer.c @@ -167,6 +167,26 @@ out: error_propagate(errp, local_err); } +static void default_filter_set_buffer_flag(NetFilterState *nf, + void *opaque, + Error **errp) +{ + if (!strcmp(object_get_typename(OBJECT(nf)), TYPE_FILTER_BUFFER)) { + FilterBufferState *s = FILTER_BUFFER(nf); + bool *flag = opaque; + + if (s->is_default) { + s->enable_buffer = *flag; + } + } +} + +void qemu_set_default_filter_buffers(bool enable_buffer) +{ + qemu_foreach_netfilter(default_filter_set_buffer_flag, + &enable_buffer, NULL); +} + /* * This will be used by COLO or MC FT, for which they will need * to buffer the packets of VM's net devices, Here we add a default diff --git a/net/net.c b/net/net.c index b36d49f..aa8e128 100644 --- a/net/net.c +++ b/net/net.c @@ -259,6 +259,35 @@ static char *assign_name(NetClientState *nc1, const char *model) return g_strdup_printf("%s.%d", model, id); } +void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, + Error **errp) +{ + NetClientState *nc; + NetFilterState *nf; + + QTAILQ_FOREACH(nc, &net_clients, next) { + if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC) { + continue; + } + /* FIXME: Not support multiqueue */ + if (nc->queue_index > 1) { + error_setg(errp, "%s: multiqueue is not supported", __func__); + return; + } + QTAILQ_FOREACH(nf, &nc->filters, next) { + if (func) { + Error *local_err = NULL; + + func(nf, opaque, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } + } + } +} + static void qemu_net_client_destructor(NetClientState *nc) { g_free(nc); -- 1.8.3.1