On Mon, Sep 07, 2015 at 03:37:20PM +0800, Yang Hongyang wrote: > Hi Stefan, > > On 09/04/2015 06:32 PM, Stefan Hajnoczi wrote: > [...] > > > >net/queue.c has logic to send/queue/flush packets but a > >qemu_deliver_packet() call is hardcoded. > > > >Maybe you can extend qemu_new_net_queue() like this: > > > >/* Returns: > > * >0 - success > > * 0 - queue packet for future redelivery > > * <0 - failure (discard packet) > > */ > >typedef ssize_t NetQueueDeliverFunc(NetClientState *sender, > > unsigned flags, > > const struct iovec *iov, > > int iovcnt, > > void *opaque); > > > >NetQueue *qemu_new_net_queue(NetQueueDeliverFunc deliver, > > void *opaque); > > > >Now net/net.c:qemu_net_client_setup() needs to call: > > > > nc->incoming_queue = qemu_new_net_queue(qemu_deliver_packet_iov, nc); > > > >And the filter code can use qemu_net_queue_send_iov() and > >qemu_net_queue_flush(). The filter just needs to provide its own > >NetQueueDeliveryFunc. > > > >I haven't checked the details (e.g. non-iov delivery, etc) but the idea > >is to use the net/queue.c API instead of duplicating similar logic in > >the filter code. > > Thanks very much for the suggestion, I've already implemented it and tested, > the code looks cleaner now. > > The last issue is the QOM thing, do Markus and Andreas have more input > about that?
If you would like to see examples of QOM usage, take a look at iothread.c and/or backends/hostmem.c. The key things are: 1. They use include/qom/object.h to register a type based on TYPE_OBJECT and their properties are registered using object_property_add_*(). 2. They implement the TYPE_USER_CREATABLE interface so the -object command-line option can be used to instantiate them. See object_interfaces.h. As a result, a lot of code becomes unnecessary and iothread.c, in particular, is quite short. Stefan