From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtbVY-0007eV-U2 for qemu-devel@nongnu.org; Tue, 03 Nov 2015 08:20:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtbVV-0007u9-0B for qemu-devel@nongnu.org; Tue, 03 Nov 2015 08:20:16 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:46730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtbVT-0007sm-OA for qemu-devel@nongnu.org; Tue, 03 Nov 2015 08:20:12 -0500 References: <1446551816-15768-1-git-send-email-zhang.zhanghailiang@huawei.com> <1446551816-15768-33-git-send-email-zhang.zhanghailiang@huawei.com> <5638AB11.80607@easystack.cn> From: zhanghailiang Message-ID: <5638B478.8090402@huawei.com> Date: Tue, 3 Nov 2015 21:19:52 +0800 MIME-Version: 1.0 In-Reply-To: <5638AB11.80607@easystack.cn> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH COLO-Frame v10 32/38] netfilter: Add a public API to release all the buffered packets List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Yang Hongyang , qemu-devel@nongnu.org Cc: lizhijian@cn.fujitsu.com, quintela@redhat.com, Jason Wang , yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com On 2015/11/3 20:39, Yang Hongyang wrote: > On 2015年11月03日 19:56, zhanghailiang wrote: >> For COLO or MC FT, We need a function to release all the buffered packets >> actively. >> >> Signed-off-by: zhanghailiang >> Cc: Jason Wang >> --- >> v10: new patch >> --- >> include/net/filter.h | 1 + >> include/net/net.h | 4 ++++ >> net/filter-buffer.c | 15 +++++++++++++++ >> net/net.c | 24 ++++++++++++++++++++++++ >> 4 files changed, 44 insertions(+) >> >> diff --git a/include/net/filter.h b/include/net/filter.h >> index 2deda36..5a09607 100644 >> --- a/include/net/filter.h >> +++ b/include/net/filter.h >> @@ -73,5 +73,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, >> const struct iovec *iov, >> int iovcnt, >> void *opaque); >> +void filter_buffer_release_all(void); >> >> #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 57be149..b344901 100644 >> --- a/net/filter-buffer.c >> +++ b/net/filter-buffer.c >> @@ -14,6 +14,7 @@ >> #include "qapi/qmp/qerror.h" >> #include "qapi-visit.h" >> #include "qom/object.h" >> +#include "net/net.h" >> >> #define TYPE_FILTER_BUFFER "filter-buffer" >> >> @@ -163,6 +164,20 @@ out: >> error_propagate(errp, local_err); >> } >> >> +static void filter_buffer_release_packets(NetFilterState *nf, void *opaque, >> + Error **errp) >> +{ >> + if (!strcmp(object_get_typename(OBJECT(nf)), TYPE_FILTER_BUFFER)) { >> + filter_buffer_flush(nf); >> + } >> +} >> + >> +/* public APIs */ >> +void filter_buffer_release_all(void) >> +{ >> + qemu_foreach_netfilter(filter_buffer_release_packets, NULL, NULL); >> +} >> + >> static void filter_buffer_init(Object *obj) >> { >> object_property_add(obj, "interval", "int", >> diff --git a/net/net.c b/net/net.c >> index a3e9d1a..a333b01 100644 >> --- a/net/net.c >> +++ b/net/net.c >> @@ -259,6 +259,30 @@ 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) { > > Going through every filters this way might cause problem under > multiqueue case. IIRC, Jason suggested that we implement multiqueue > by this way: attach the same filter to all queues instead of > attach the clone of the filter obj to other queues. So if we > attach the same filter to all queues, going through filters > this way will cause the func been called multiple(=num of queues) times. > Got it, i will investigate it. Thanks. zhanghailiang >> + if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC) { >> + continue; >> + } >> + 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); >> >