qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: zhanghailiang <zhang.zhanghailiang@huawei.com>
To: qemu-devel@nongnu.org
Cc: jasowang@redhat.com,
	zhanghailiang <zhang.zhanghailiang@huawei.com>,
	hongyang.yang@easystack.cn
Subject: [Qemu-devel] [PATCH v2 2/2] filter-buffer: Add status_changed callback processing
Date: Mon, 29 Feb 2016 09:46:06 +0800	[thread overview]
Message-ID: <1456710366-10980-3-git-send-email-zhang.zhanghailiang@huawei.com> (raw)
In-Reply-To: <1456710366-10980-1-git-send-email-zhang.zhanghailiang@huawei.com>

While the status of filter-buffer changing from 'on' to 'off',
it need to release all the buffered packets, and delete the related
timer, while switch from 'off' to 'on', it need to resume the release
packets timer.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Yang Hongyang <hongyang.yang@easystack.cn>
---
v2:
- New patch
---
 net/filter-buffer.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/net/filter-buffer.c b/net/filter-buffer.c
index 12ad2e3..ed3f19e 100644
--- a/net/filter-buffer.c
+++ b/net/filter-buffer.c
@@ -124,6 +124,24 @@ static void filter_buffer_setup(NetFilterState *nf, Error **errp)
     }
 }
 
+static void filter_buffer_status_changed(NetFilterState *nf, Error **errp)
+{
+    FilterBufferState *s = FILTER_BUFFER(nf);
+
+    if (!strcmp(nf->status, "off")) {
+        if (s->interval) {
+            timer_del(&s->release_timer);
+        }
+        filter_buffer_flush(nf);
+    } else {
+        if (s->interval) {
+            timer_init_us(&s->release_timer, QEMU_CLOCK_VIRTUAL,
+                filter_buffer_release_timer, nf);
+            timer_mod(&s->release_timer,
+                qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + s->interval);
+        }
+    }
+}
 static void filter_buffer_class_init(ObjectClass *oc, void *data)
 {
     NetFilterClass *nfc = NETFILTER_CLASS(oc);
@@ -131,6 +149,7 @@ static void filter_buffer_class_init(ObjectClass *oc, void *data)
     nfc->setup = filter_buffer_setup;
     nfc->cleanup = filter_buffer_cleanup;
     nfc->receive_iov = filter_buffer_receive_iov;
+    nfc->status_changed = filter_buffer_status_changed;
 }
 
 static void filter_buffer_get_interval(Object *obj, Visitor *v,
-- 
1.8.3.1

  parent reply	other threads:[~2016-02-29  1:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-29  1:46 [Qemu-devel] [PATCH v2 0/2] Introduce 'status' property for netfilter zhanghailiang
2016-02-29  1:46 ` [Qemu-devel] [PATCH v2 1/2] filter: Add 'status' property for filter object zhanghailiang
2016-02-29  7:26   ` Jason Wang
2016-02-29  7:34     ` Hailiang Zhang
2016-03-01  2:37       ` Jason Wang
2016-02-29  1:46 ` zhanghailiang [this message]
2016-02-29  7:27   ` [Qemu-devel] [PATCH v2 2/2] filter-buffer: Add status_changed callback processing Jason Wang
2016-02-29  7:36     ` Hailiang Zhang
2016-03-01  2:40       ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456710366-10980-3-git-send-email-zhang.zhanghailiang@huawei.com \
    --to=zhang.zhanghailiang@huawei.com \
    --cc=hongyang.yang@easystack.cn \
    --cc=jasowang@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).