qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yang Hongyang <yanghy@cn.fujitsu.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: thuth@redhat.com, zhang.zhanghailiang@huawei.com,
	lizhijian@cn.fujitsu.com, jasowang@redhat.com,
	qemu-devel@nongnu.org, mrhines@linux.vnet.ibm.com,
	armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v9 05/10] move out net queue structs define
Date: Thu, 3 Sep 2015 00:18:18 +0800	[thread overview]
Message-ID: <55E7214A.20803@cn.fujitsu.com> (raw)
In-Reply-To: <20150902130245.GI17873@stefanha-thinkpad.redhat.com>



On 09/02/2015 09:02 PM, Stefan Hajnoczi wrote:
> On Wed, Sep 02, 2015 at 09:49:18AM +0800, Yang Hongyang wrote:
>> On 09/01/2015 10:43 PM, Stefan Hajnoczi wrote:
>>> On Tue, Sep 01, 2015 at 05:06:18PM +0800, Yang Hongyang wrote:
>>>> This will be used by the next patch in this series.
>>>>
>>>> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
>>>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>>>> ---
>>>>   include/net/queue.h | 19 +++++++++++++++++++
>>>>   net/queue.c         | 19 -------------------
>>>>   2 files changed, 19 insertions(+), 19 deletions(-)
>>>>
>>>> diff --git a/include/net/queue.h b/include/net/queue.h
>>>> index fc02b33..1d65e47 100644
>>>> --- a/include/net/queue.h
>>>> +++ b/include/net/queue.h
>>>> @@ -31,6 +31,25 @@ typedef struct NetQueue NetQueue;
>>>>
>>>>   typedef void (NetPacketSent) (NetClientState *sender, ssize_t ret);
>>>>
>>>> +struct NetPacket {
>>>> +    QTAILQ_ENTRY(NetPacket) entry;
>>>> +    NetClientState *sender;
>>>> +    unsigned flags;
>>>> +    int size;
>>>> +    NetPacketSent *sent_cb;
>>>> +    uint8_t data[0];
>>>> +};
>>>> +
>>>> +struct NetQueue {
>>>> +    void *opaque;
>>>> +    uint32_t nq_maxlen;
>>>> +    uint32_t nq_count;
>>>> +
>>>> +    QTAILQ_HEAD(packets, NetPacket) packets;
>>>> +
>>>> +    unsigned delivering:1;
>>>> +};
>>>> +
>>>
>>> Why is it necessary to expose both structs?
>>
>> In next patch, we add a API to pass the packet to next filter:
>> ssize_t qemu_netfilter_pass_to_next(NetFilterState *nf, NetPacket *packet);
>> which will access the internals of NetPacket.
>>
>> and in buffer filter, we need the NetQueue to Queue packets, and also to
>> access queue->packets(pass this packets to next filter).
>
> Can you do these things by introducing net queue APIs instead of
> exposing the struct?
>
> It's a C anti-pattern to expose structs.  It makes code complex because
> now the net queue code no longer contains all the assumptions about
> NetQueue/NetPacket fields.  People modifying the code now also need to
> go into the net filter code to figure out how this struct works.
>
> Exposing the fields also leads to code duplication since every user will
> reimplement similar stuff if they access the fields directly instead of
> using a function interface.

I can't think of a interface that no need to access the NetPacket internals
to archive the needs. Except I do not reuse the NetPacket and NetQueue,
implement a Queue myself. But that will be more complex.
So in order to not expose those structs, I shall add lots of public get
functions to use these internals, like:
Qemu_NetQueue_get_xxx
Qemu_NetPacket_get_xxx

I'd be very happy if you could give me a better suggestion on this.

Thanks!

>
> Stefan
> .
>

-- 
Thanks,
Yang.

  reply	other threads:[~2015-09-02 16:19 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-01  9:06 [Qemu-devel] [PATCH v9 00/10] Add a netfilter object and netbuffer filter Yang Hongyang
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 01/10] net: add a new object netfilter Yang Hongyang
2015-09-01 14:36   ` Stefan Hajnoczi
2015-09-02  1:39     ` Yang Hongyang
2015-09-02 12:58       ` Stefan Hajnoczi
2015-09-02 13:04         ` Daniel P. Berrange
2015-09-02 13:06       ` Stefan Hajnoczi
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 02/10] init/cleanup of netfilter object Yang Hongyang
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 03/10] netfilter: add netfilter_{add|del} commands Yang Hongyang
2015-09-01 14:37   ` Stefan Hajnoczi
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 04/10] netfilter: hook packets before net queue send Yang Hongyang
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 05/10] move out net queue structs define Yang Hongyang
2015-09-01 14:43   ` Stefan Hajnoczi
2015-09-02  1:49     ` Yang Hongyang
2015-09-02 13:02       ` Stefan Hajnoczi
2015-09-02 16:18         ` Yang Hongyang [this message]
2015-09-04 10:32           ` Stefan Hajnoczi
2015-09-07  7:37             ` Yang Hongyang
2015-09-07  9:06               ` Markus Armbruster
2015-09-07  9:21                 ` Yang Hongyang
2015-09-07  9:11               ` Stefan Hajnoczi
2015-09-07  9:26                 ` Yang Hongyang
2015-09-07 10:53                 ` Yang Hongyang
2015-09-07 11:00                   ` Daniel P. Berrange
2015-09-07 11:41                     ` Yang Hongyang
2015-09-07 11:43                       ` Daniel P. Berrange
2015-09-07 11:46                         ` Yang Hongyang
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 06/10] netfilter: add an API to pass the packet to next filter Yang Hongyang
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 07/10] netfilter: print filter info associate with the netdev Yang Hongyang
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 08/10] net/queue: export qemu_net_queue_append_iov Yang Hongyang
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 09/10] netfilter: add a netbuffer filter Yang Hongyang
2015-09-01  9:06 ` [Qemu-devel] [PATCH v9 10/10] tests: add test cases for netfilter object Yang Hongyang

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=55E7214A.20803@cn.fujitsu.com \
    --to=yanghy@cn.fujitsu.com \
    --cc=armbru@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=mrhines@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /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).