接前一篇文章:
上一回对于virtio_device_realize函数进行了详细解析。在第2步中virtio_device_realize函数调用了具体类的realize函数,对于virtio balloon设备来说是virtio_balloon_device_realize函数。本回就来对于virtio_balloon_device_realize函数进行解析。
为了便于理解,再次贴出virtio_device_realize函数源码,在hw/virtio/virtio.c中,如下:
static void virtio_device_realize(DeviceState *dev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
Error *err = NULL;
/* Devices should either use vmsd or the load/save methods */
assert(!vdc->vmsd || !vdc->load);
if (vdc->realize != NULL) {
vdc->realize(dev, &err);
if (err != NULL) {
e