From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbQS8-00017x-LK for qemu-devel@nongnu.org; Mon, 14 Sep 2015 05:53:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZbQS4-0000kY-1M for qemu-devel@nongnu.org; Mon, 14 Sep 2015 05:53:36 -0400 Received: from [59.151.112.132] (port=61056 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbQS3-0000k3-7n for qemu-devel@nongnu.org; Mon, 14 Sep 2015 05:53:31 -0400 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t8E9rCbP009295 for ; Mon, 14 Sep 2015 17:53:12 +0800 Message-ID: <55F69906.9000708@cn.fujitsu.com> Date: Mon, 14 Sep 2015 17:53:10 +0800 From: Yang Hongyang MIME-Version: 1.0 References: <1441783481-17698-1-git-send-email-yanghy@cn.fujitsu.com> <1441783481-17698-10-git-send-email-yanghy@cn.fujitsu.com> <20150914090406.GC7611@redhat.com> In-Reply-To: <20150914090406.GC7611@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v10 09/10] netfilter: add a netbuffer filter List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org On 09/14/2015 05:04 PM, Daniel P. Berrange wrote: > On Wed, Sep 09, 2015 at 03:24:40PM +0800, Yang Hongyang wrote: >> This filter is to buffer/release packets, this feature can be used >> when using MicroCheckpointing, or other Remus like VM FT solutions, you >> can also use it to simulate the network delay. >> It has an interval option, if supplied, this filter will release >> packets by interval. >> >> Usage: >> -netdev tap,id=bn0 >> -object filter-buffer,id=f0,netdev=bn0,chain=in,interval=1000 >> >> NOTE: >> the scale of interval is microsecond. >> >> Signed-off-by: Yang Hongyang > >> diff --git a/net/filter-buffer.c b/net/filter-buffer.c >> new file mode 100644 >> index 0000000..26698d9 >> --- /dev/null >> +++ b/net/filter-buffer.c >> @@ -0,0 +1,169 @@ >> +/* >> + * Copyright (c) 2015 FUJITSU LIMITED >> + * Author: Yang Hongyang >> + * >> + * This work is licensed under the terms of the GNU GPL, version 2 or >> + * later. See the COPYING file in the top-level directory. >> + */ >> + >> +#include "net/filter.h" >> +#include "net/queue.h" >> +#include "qemu-common.h" >> +#include "qemu/timer.h" >> +#include "qemu/iov.h" >> +#include "qapi/qmp/qerror.h" >> +#include "qapi-visit.h" >> +#include "qom/object.h" >> + >> +#define TYPE_FILTER_BUFFER "filter-buffer" >> + >> +#define FILTER_BUFFER(obj) \ >> + OBJECT_CHECK(FilterBufferState, (obj), TYPE_FILTER_BUFFER) >> + >> +typedef struct FilterBufferState { >> + NetFilterState parent_obj; >> + >> + NetQueue *incoming_queue; >> + uint32_t interval; >> + QEMUTimer release_timer; >> +} FilterBufferState; >> + >> +static void filter_buffer_flush(NetFilterState *nf) >> +{ >> + FilterBufferState *s = FILTER_BUFFER(nf); >> + >> + if (!qemu_net_queue_flush(s->incoming_queue)) { >> + /* Unable to empty the queue, purge remaining packets */ >> + qemu_net_queue_purge(s->incoming_queue, nf->netdev); >> + } >> +} >> + >> +static void filter_buffer_release_timer(void *opaque) >> +{ >> + NetFilterState *nf = opaque; >> + FilterBufferState *s = FILTER_BUFFER(nf); >> + filter_buffer_flush(nf); >> + timer_mod(&s->release_timer, >> + qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + s->interval); >> +} >> + >> +/* filter APIs */ >> +static ssize_t filter_buffer_receive_iov(NetFilterState *nf, >> + NetClientState *sender, >> + unsigned flags, >> + const struct iovec *iov, >> + int iovcnt, >> + NetPacketSent *sent_cb) >> +{ >> + FilterBufferState *s = FILTER_BUFFER(nf); >> + >> + /* >> + * we return size when buffer a packet, the sender will take it as >> + * a already sent packet, so sent_cb should not be called later >> + */ >> + qemu_net_queue_append_iov(s->incoming_queue, sender, flags, >> + iov, iovcnt, NULL); >> + return iov_size(iov, iovcnt); >> +} >> + >> +static void filter_buffer_cleanup(NetFilterState *nf) > > Same comment about s/cleanup/finalize/ This is not the .instance_finalize func, although it is called in netfilter_finalize, it is a cleanup virtual method in the filter class: include/net/filter.h 39 typedef struct NetFilterClass { 40 ObjectClass parent_class; 41 42 FilterSetup *setup; 43 FilterCleanup *cleanup; 44 FilterReceiveIOV *receive_iov; 45 } NetFilterClass; > >> +{ >> + FilterBufferState *s = FILTER_BUFFER(nf); >> + >> + if (s->interval) { >> + timer_del(&s->release_timer); >> + } >> + >> + /* flush packets */ >> + if (s->incoming_queue) { >> + filter_buffer_flush(nf); >> + g_free(s->incoming_queue); >> + } >> +} > >> diff --git a/vl.c b/vl.c >> index 672f8b2..30196e4 100644 >> --- a/vl.c >> +++ b/vl.c >> @@ -2783,7 +2783,12 @@ static bool object_create_initial(const char *type) >> if (g_str_equal(type, "rng-egd")) { >> return false; >> } >> - /* TODO: reture false for concrete netfilters */ > > Oh, I missed the typo in your earlier patch - s/reture/return/ > >> + >> + /* reture false for concrete netfilters */ > > And again in the line you changed here. All fixed as well as your comments in patch 2, thank you. > >> + if (g_str_equal(type, "filter-buffer")) { >> + return false; >> + } >> + > > > Regards, > Daniel > -- Thanks, Yang.