X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Flnx_virtio_blk.c;h=7e26b3081566e8d51d71a2cc4dedc4376d81f422;hb=0a7690f54cb5bda83780dac26ce433ad24b1d766;hp=6cb8fa33f9a539479cedd2b33d992fd5a12b5502;hpb=e2964f7234daa3429275c039769a313f0870c212;p=palacios.git diff --git a/palacios/src/devices/lnx_virtio_blk.c b/palacios/src/devices/lnx_virtio_blk.c index 6cb8fa3..7e26b30 100644 --- a/palacios/src/devices/lnx_virtio_blk.c +++ b/palacios/src/devices/lnx_virtio_blk.c @@ -104,9 +104,7 @@ struct virtio_blk_state { }; -static int virtio_free(struct vm_device * dev) { - return -1; -} + static int blk_reset(struct virtio_blk_state * virtio) { @@ -473,10 +471,28 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u } +static int virtio_free(struct virtio_dev_state * virtio) { + struct virtio_blk_state * blk_state = NULL; + struct virtio_blk_state * tmp = NULL; + + list_for_each_entry_safe(blk_state, tmp, &(virtio->dev_list), dev_link) { + + // unregister from PCI + + list_del(&(blk_state->dev_link)); + V3_Free(blk_state); + } + + + V3_Free(virtio); + + return 0; +} + static struct v3_device_ops dev_ops = { - .free = virtio_free, + .free = (int (*)(void *))virtio_free, }; @@ -550,6 +566,10 @@ static int register_dev(struct virtio_dev_state * virtio, struct virtio_blk_stat blk_state->pci_dev = pci_dev; + + + /* Add backend to list of devices */ + list_add(&(blk_state->dev_link), &(virtio->dev_list)); /* Block configuration */ blk_state->virtio_cfg.host_features = VIRTIO_SEG_MAX; @@ -612,14 +632,17 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { virtio_state->pci_bus = pci_bus; - struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, virtio_state); - if (v3_attach_device(vm, dev) == -1) { + struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, virtio_state); + + if (dev == NULL) { PrintError("Could not attach device %s\n", dev_id); + V3_Free(virtio_state); return -1; } if (v3_dev_add_blk_frontend(vm, dev_id, connect_fn, (void *)virtio_state) == -1) { PrintError("Could not register %s as block frontend\n", dev_id); + v3_remove_device(dev); return -1; }