On Sat, 27 Sep 2014 10:37:23 +0000
"Gonglei (Arei)" <arei.gong...@huawei.com> wrote:

> > > One thing I noticed is that the various devices end up with similar
> > > code in the end:
> > >
> > >      object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_WHATEVER);
> > >      object_property_add_child(obj, "virtio-backend",
> > OBJECT(&dev->vdev),
> > > NULL);
> > >      object_unref(OBJECT(&dev->vdev));
> > >      qdev_alias_all_properties(DEVICE(&dev->vdev), obj);
> > >
> > > Would it make sense to add a helper function for that?
> > 
> 
> Sorry, I'm afraid this is not helpful. Because dev and dev->vdev is different
> for different virtio devices, like VirtIOBlkPCI(and its vdev is VirtIOBlock), 
> VirtIONetPCI(and its vdev is VirtIONet). They have no the same parameters
> for above code segment. :) 

Hm...

void virtio_instance_init_common(Object *proxydev,
                                 DeviceState *vdev,
                                 size_t vdevsize,
                                 const char *vdevname)
{
    object_initialize(vdev, vdevsize, vdevname);
    object_property_add_child(proxydev, "virtio-backend", OBJECT(vdev), NULL);
    object_unref(OBJECT(vdev));
    qdev_alias_all_properties(vdev, proxydev);
}

and have the initializers call

virtio_instance_init_common(obj, DEVICE(&dev->vdev), sizeof(dev->vdev), 
TYPE_WHATEVER);

?


Reply via email to