diff mbox

[v2,2/2] filter-buffer: Add status_changed callback processing

Message ID 1456710366-10980-3-git-send-email-zhang.zhanghailiang@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zhanghailiang Feb. 29, 2016, 1:46 a.m. UTC
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(+)

Comments

Jason Wang Feb. 29, 2016, 7:27 a.m. UTC | #1
On 02/29/2016 09:46 AM, zhanghailiang wrote:
> 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);
> +        }

The code looks duplicated with filter_buffer_setup().

> +    }
> +}
>  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,
Zhanghailiang Feb. 29, 2016, 7:36 a.m. UTC | #2
On 2016/2/29 15:27, Jason Wang wrote:
>
>
> On 02/29/2016 09:46 AM, zhanghailiang wrote:
>> 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);
>> +        }
>
> The code looks duplicated with filter_buffer_setup().
>

Yea, extract them into a new helper ? filter_buffer_setup_timer() ?

>> +    }
>> +}
>>   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,
>
>
> .
>
Jason Wang March 1, 2016, 2:40 a.m. UTC | #3
On 02/29/2016 03:36 PM, Hailiang Zhang wrote:
> On 2016/2/29 15:27, Jason Wang wrote:
>>
>>
>> On 02/29/2016 09:46 AM, zhanghailiang wrote:
>>> 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);
>>> +        }
>>
>> The code looks duplicated with filter_buffer_setup().
>>
>
> Yea, extract them into a new helper ? filter_buffer_setup_timer() ?

Right.

>
>>> +    }
>>> +}
>>>   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,
>>
>>
>> .
>>
>
>
diff mbox

Patch

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,