From: Jack Lange Date: Tue, 23 Nov 2010 22:56:54 +0000 (-0600) Subject: deallocation of devices X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=6d6988cc9c8bac21d96afd800076afe0915cf2cd deallocation of devices --- diff --git a/palacios/include/palacios/vmm.h b/palacios/include/palacios/vmm.h index a0827fd..d2873c8 100644 --- a/palacios/include/palacios/vmm.h +++ b/palacios/include/palacios/vmm.h @@ -325,6 +325,7 @@ void Init_V3(struct v3_os_hooks * hooks, int num_cpus); struct v3_vm_info * v3_create_vm(void * cfg, void * priv_data, char * name); int v3_start_vm(struct v3_vm_info * vm, unsigned int cpu_mask); int v3_stop_vm(struct v3_vm_info * vm); +int v3_free_vm(struct v3_vm_info * vm); int v3_deliver_irq(struct v3_vm_info * vm, struct v3_interrupt * intr); diff --git a/palacios/include/palacios/vmm_dev_mgr.h b/palacios/include/palacios/vmm_dev_mgr.h index f18664b..3e52d9a 100644 --- a/palacios/include/palacios/vmm_dev_mgr.h +++ b/palacios/include/palacios/vmm_dev_mgr.h @@ -99,7 +99,7 @@ int v3_init_devices(); struct v3_device_ops { - int (*free)(struct vm_device * dev); + int (*free)(void * private_data); //int (*save)(struct vm_device *dev, struct *iostream); //int (*restore)(struct vm_device *dev, struct *iostream); diff --git a/palacios/src/devices/8254.c b/palacios/src/devices/8254.c index 5a78e93..e5498b9 100644 --- a/palacios/src/devices/8254.c +++ b/palacios/src/devices/8254.c @@ -89,6 +89,8 @@ struct pit { struct v3_timer * timer; + struct v3_vm_info * vm; + struct channel ch_0; struct channel ch_1; struct channel ch_2; @@ -642,9 +644,9 @@ static void init_channel(struct channel * ch) { -static int pit_free(struct vm_device * dev) { - struct pit * state = (struct pit *)dev->private_data; - struct guest_info * info = &(dev->vm->cores[0]); +static int pit_free(void * private_data) { + struct pit * state = (struct pit *)private_data; + struct guest_info * info = &(state->vm->cores[0]); if (state->timer) { @@ -657,7 +659,7 @@ static int pit_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = pit_free, + .free = (int (*)(void *))pit_free, }; diff --git a/palacios/src/devices/8259a.c b/palacios/src/devices/8259a.c index bbe6e39..69707b9 100644 --- a/palacios/src/devices/8259a.c +++ b/palacios/src/devices/8259a.c @@ -721,8 +721,13 @@ static int write_elcr_port(struct guest_info * core, ushort_t port, void * src, -static int pic_free(struct vm_device * dev) { +static int pic_free(struct pic_internal * state) { + + // unregister intr_controller + // unregister intr router + + V3_Free(state); return 0; } @@ -733,7 +738,7 @@ static int pic_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = pic_free, + .free = (int (*)(void *))pic_free, }; diff --git a/palacios/src/devices/apic.c b/palacios/src/devices/apic.c index 8e07132..3d7f792 100644 --- a/palacios/src/devices/apic.c +++ b/palacios/src/devices/apic.c @@ -1462,14 +1462,15 @@ static struct v3_timer_ops timer_ops = { -static int apic_free(struct vm_device * dev) { - struct apic_dev_state * apic_dev = (struct apic_dev_state *)dev->private_data; +static int apic_free(struct apic_dev_state * apic_dev) { int i = 0; + struct v3_vm_info * vm = NULL; - for (i = 0; i < dev->vm->num_cores; i++) { + for (i = 0; i < apic_dev->num_apics; i++) { struct apic_state * apic = &(apic_dev->apics[i]); - struct guest_info * core = &(dev->vm->cores[i]); + struct guest_info * core = apic->core; + vm = core->vm_info; // unregister intr controller @@ -1481,7 +1482,7 @@ static int apic_free(struct vm_device * dev) { } - v3_unhook_msr(dev->vm, BASE_ADDR_MSR); + v3_unhook_msr(vm, BASE_ADDR_MSR); V3_Free(apic_dev); return 0; @@ -1489,7 +1490,7 @@ static int apic_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = apic_free, + .free = (int (*)(void *))apic_free, }; diff --git a/palacios/src/devices/bochs_debug.c b/palacios/src/devices/bochs_debug.c index c12c1f8..339999d 100644 --- a/palacios/src/devices/bochs_debug.c +++ b/palacios/src/devices/bochs_debug.c @@ -113,11 +113,9 @@ static int handle_gen_write(struct guest_info * core, ushort_t port, void * src, -static int debug_free(struct vm_device * dev) { - struct debug_state * state = dev->private_data; +static int debug_free(struct debug_state * state) { V3_Free(state); - return 0; }; @@ -125,7 +123,7 @@ static int debug_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = debug_free, + .free = (int (*)(void *))debug_free, }; diff --git a/palacios/src/devices/cga.c b/palacios/src/devices/cga.c index 10722dd..febc36e 100644 --- a/palacios/src/devices/cga.c +++ b/palacios/src/devices/cga.c @@ -70,6 +70,8 @@ struct video_internal { // so we need a temp variable to hold the partial update uint16_t tmp_screen_offset; + struct vm_device * dev; + uint8_t passthrough; @@ -307,14 +309,13 @@ int v3_cons_get_fb(struct vm_device * frontend_dev, uint8_t * dst, uint_t offset -static int free_device(struct vm_device * dev) { - struct video_internal * video_state = (struct video_internal *)dev->private_data; +static int free_device(struct video_internal * video_state) { if (video_state->framebuf_pa) { V3_FreePages((void *)(video_state->framebuf_pa), (FRAMEBUF_SIZE / 4096)); } - v3_unhook_mem(dev->vm, V3_MEM_CORE_ANY, START_ADDR); + v3_unhook_mem(video_state->dev->vm, V3_MEM_CORE_ANY, START_ADDR); V3_Free(video_state); @@ -324,7 +325,7 @@ static int free_device(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = free_device, + .free = (int (*)(void *))free_device, }; static int cga_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { @@ -345,6 +346,8 @@ static int cga_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { V3_Free(video_state); return -1; } + + video_state->dev = dev; video_state->framebuf_pa = (addr_t)V3_AllocPages(FRAMEBUF_SIZE / 4096); video_state->framebuf = V3_VAddr((void *)(video_state->framebuf_pa)); diff --git a/palacios/src/devices/char_stream.c b/palacios/src/devices/char_stream.c index be72399..2bf4841 100644 --- a/palacios/src/devices/char_stream.c +++ b/palacios/src/devices/char_stream.c @@ -53,9 +53,7 @@ static int stream_write(uint8_t * buf, uint64_t length, void * private_data) { return v3_stream_write(state->stream, buf, length); } -static int stream_free(struct vm_device * dev) { - struct stream_state * state = (struct stream_state *)(dev->private_data); - +static int stream_free(struct stream_state * state) { v3_stream_close(state->stream); // detach host event @@ -67,7 +65,7 @@ static int stream_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = stream_free, + .free = (int (*)(void *))stream_free, }; static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { diff --git a/palacios/src/devices/curses_cons.c b/palacios/src/devices/curses_cons.c index c4aba1d..2a96eb5 100644 --- a/palacios/src/devices/curses_cons.c +++ b/palacios/src/devices/curses_cons.c @@ -161,9 +161,7 @@ static int scroll(int rows, void * private_data) { } -static int cons_free(struct vm_device * dev) { - struct cons_state * state = (struct cons_state *)dev->private_data; - +static int cons_free(struct cons_state * state) { v3_console_close(state->cons); // remove host event @@ -188,7 +186,7 @@ static struct v3_console_ops cons_ops = { }; static struct v3_device_ops dev_ops = { - .free = cons_free, + .free = (int (*)(void *))cons_free, }; static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) diff --git a/palacios/src/devices/disk_model.c b/palacios/src/devices/disk_model.c index c1d8836..b142547 100644 --- a/palacios/src/devices/disk_model.c +++ b/palacios/src/devices/disk_model.c @@ -58,8 +58,12 @@ static uint64_t model_get_capacity(void * private_data) { return model->ops->get_capacity(model->private_data); } -static int model_free(struct vm_device * dev) { - return -1; +static int model_free(struct disk_state * model) { + + // unhook from frontend + + V3_Free(model); + return 0; } @@ -73,7 +77,7 @@ static struct v3_dev_blk_ops blk_ops = { static struct v3_device_ops dev_ops = { - .free = model_free, + .free = (int (*)(void *))model_free, }; diff --git a/palacios/src/devices/filedisk.c b/palacios/src/devices/filedisk.c index 001f1da..b007ace 100644 --- a/palacios/src/devices/filedisk.c +++ b/palacios/src/devices/filedisk.c @@ -111,9 +111,7 @@ static struct v3_dev_blk_ops blk_ops = { -static int disk_free(struct vm_device * dev) { - struct disk_state * disk = dev->private_data; - +static int disk_free(struct disk_state * disk) { v3_file_close(disk->fd); V3_Free(disk); @@ -121,7 +119,7 @@ static int disk_free(struct vm_device * dev) { } static struct v3_device_ops dev_ops = { - .free = disk_free, + .free = (int (*)(void *))disk_free, }; diff --git a/palacios/src/devices/generic.c b/palacios/src/devices/generic.c index f10048d..3142488 100644 --- a/palacios/src/devices/generic.c +++ b/palacios/src/devices/generic.c @@ -148,9 +148,7 @@ static int generic_read_port_ignore(struct guest_info * core, uint16_t port, voi -static int generic_free(struct vm_device * dev) { - struct generic_internal * state = (struct generic_internal *)(dev->private_data); - +static int generic_free(struct generic_internal * state) { PrintDebug("generic: deinit_device\n"); V3_Free(state); @@ -162,7 +160,7 @@ static int generic_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = generic_free, + .free = (int (*)(void *))generic_free, }; diff --git a/palacios/src/devices/i440fx.c b/palacios/src/devices/i440fx.c index f1fc628..6c587d3 100644 --- a/palacios/src/devices/i440fx.c +++ b/palacios/src/devices/i440fx.c @@ -45,8 +45,7 @@ static int io_write(struct guest_info * core, ushort_t port, void * src, uint_t -static int i440_free(struct vm_device * dev) { - struct i440_state * state = dev->private_data; +static int i440_free(struct i440_state * state) { // unregister from PCI @@ -56,7 +55,7 @@ static int i440_free(struct vm_device * dev) { } static struct v3_device_ops dev_ops = { - .free = i440_free, + .free = (int (*)(void *))i440_free, }; diff --git a/palacios/src/devices/ide.c b/palacios/src/devices/ide.c index 0af2198..6bc37fb 100644 --- a/palacios/src/devices/ide.c +++ b/palacios/src/devices/ide.c @@ -1430,20 +1430,18 @@ static int init_ide_state(struct ide_internal * ide) { -static int ide_free(struct vm_device * dev) { - // unhook io ports.... - +static int ide_free(struct ide_internal * ide) { // deregister from PCI? - + V3_Free(ide); return 0; } static struct v3_device_ops dev_ops = { - .free = ide_free, + .free = (int (*)(void *))ide_free, }; diff --git a/palacios/src/devices/io_apic.c b/palacios/src/devices/io_apic.c index 31169f4..b0e9584 100644 --- a/palacios/src/devices/io_apic.c +++ b/palacios/src/devices/io_apic.c @@ -307,15 +307,20 @@ static struct intr_router_ops router_ops = { -static int io_apic_free(struct vm_device * dev) { - // struct guest_info * info = dev->vm; +static int io_apic_free(struct io_apic_state * ioapic) { + + // unregister intr router + + // unhook memory + + V3_Free(ioapic); return 0; } static struct v3_device_ops dev_ops = { - .free = io_apic_free, + .free = (int (*)(void *))io_apic_free, }; diff --git a/palacios/src/devices/keyboard.c b/palacios/src/devices/keyboard.c index 71bed11..2aa4bec 100644 --- a/palacios/src/devices/keyboard.c +++ b/palacios/src/devices/keyboard.c @@ -957,8 +957,12 @@ static int keyboard_read_input(struct guest_info * core, ushort_t port, void * d -static int keyboard_free(struct vm_device * dev) { +static int keyboard_free(struct keyboard_internal * kbd) { + + // unhook host events + + V3_Free(kbd); return 0; } @@ -1010,7 +1014,7 @@ static int keyboard_reset_device(struct keyboard_internal * kbd) { } static struct v3_device_ops dev_ops = { - .free = keyboard_free, + .free = (int (*)(void *))keyboard_free, }; diff --git a/palacios/src/devices/lnx_virtio_balloon.c b/palacios/src/devices/lnx_virtio_balloon.c index 0bd5727..e936f9e 100644 --- a/palacios/src/devices/lnx_virtio_balloon.c +++ b/palacios/src/devices/lnx_virtio_balloon.c @@ -77,9 +77,7 @@ struct virtio_balloon_state { }; -static int virtio_free(struct vm_device * dev) { - return -1; -} + static int virtio_reset(struct virtio_balloon_state * virtio) { @@ -361,10 +359,17 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u } +static int virtio_free(struct virtio_balloon_state * virtio) { + + // unregister from PCI + + V3_Free(virtio); + return 0; +} static struct v3_device_ops dev_ops = { - .free = virtio_free, + .free = (int (*)(void *))virtio_free, }; diff --git a/palacios/src/devices/lnx_virtio_blk.c b/palacios/src/devices/lnx_virtio_blk.c index bb29d9a..2c871d9 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,17 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u } +static int virtio_free(struct virtio_dev_state * virtio) { + + V3_Free(virtio); + + return 0; +} + static struct v3_device_ops dev_ops = { - .free = virtio_free, + .free = (int (*)(void *))virtio_free, }; diff --git a/palacios/src/devices/lnx_virtio_nic.c b/palacios/src/devices/lnx_virtio_nic.c index fb5c18b..d0ac9a5 100644 --- a/palacios/src/devices/lnx_virtio_nic.c +++ b/palacios/src/devices/lnx_virtio_nic.c @@ -115,11 +115,7 @@ struct virtio_net_state { #define ERR_VIRTIO_TXQ_DISABLED 6 -static int virtio_free(struct vm_device * dev) -{ - - return 0; -} + static int virtio_init_state(struct virtio_net_state * virtio) { @@ -651,9 +647,17 @@ exit: return ret_val; } +static int virtio_free(struct virtio_net_state * virtio) { + + // unregister from PCI + + V3_Free(virtio); + return 0; +} + static struct v3_device_ops dev_ops = { - .free = virtio_free, + .free = (int (*)(void *))virtio_free, }; diff --git a/palacios/src/devices/lnx_virtio_sym.c b/palacios/src/devices/lnx_virtio_sym.c index b5ca9e8..f5b6501 100644 --- a/palacios/src/devices/lnx_virtio_sym.c +++ b/palacios/src/devices/lnx_virtio_sym.c @@ -337,11 +337,18 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u } +int virtio_free(struct virtio_sym_state * virtio_state) { + + // unregister from PCI + + V3_Free(virtio_state); + return 0; +} static struct v3_device_ops dev_ops = { - .free = NULL, + .free = (int (*)(void *))virtio_free, }; @@ -365,9 +372,11 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { memset(virtio_state, 0, sizeof(struct virtio_sym_state)); - 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; } @@ -415,6 +424,7 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { if (!pci_dev) { PrintError("Could not register PCI Device\n"); + v3_remove_device(dev); return -1; } diff --git a/palacios/src/devices/lnx_virtio_symmod.c b/palacios/src/devices/lnx_virtio_symmod.c index d3d5d7e..993dcb6 100644 --- a/palacios/src/devices/lnx_virtio_symmod.c +++ b/palacios/src/devices/lnx_virtio_symmod.c @@ -588,15 +588,16 @@ static int virtio_load_capsule(struct v3_vm_info * vm, struct v3_sym_capsule * m } -static int virtio_free(struct vm_device * dev) -{ - +static int virtio_free(struct virtio_sym_state * virtio_state) { + // unregister from PCI + + V3_Free(virtio_state); return 0; } static struct v3_device_ops dev_ops = { - .free = virtio_free, + .free = (int (*)(void *))virtio_free, }; diff --git a/palacios/src/devices/lnx_virtio_vnet.c b/palacios/src/devices/lnx_virtio_vnet.c index 7746bcc..9e10784 100644 --- a/palacios/src/devices/lnx_virtio_vnet.c +++ b/palacios/src/devices/lnx_virtio_vnet.c @@ -562,12 +562,17 @@ static int vnet_virtio_io_read(struct guest_info * core, } +static int virtio_free(struct virtio_vnet_state * vnet_state) { + + // unregister from PCI + + V3_Free(vnet_state); + return 0; +} + static struct v3_device_ops dev_ops = { - .free = NULL, - .reset = NULL, - .start = NULL, - .stop = NULL, + .free = (int (*)(void *))virtio_free, }; static int dev_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { diff --git a/palacios/src/devices/netdisk.c b/palacios/src/devices/netdisk.c index 60f71ff..7121d4f 100644 --- a/palacios/src/devices/netdisk.c +++ b/palacios/src/devices/netdisk.c @@ -210,12 +210,16 @@ static struct v3_dev_blk_ops blk_ops = { -static int disk_free(struct vm_device * dev) { +static int disk_free(struct disk_state * disk) { + + v3_socket_close(disk->socket); + + V3_Free(disk); return 0; } static struct v3_device_ops dev_ops = { - .free = disk_free, + .free = (int (*)(void *))disk_free, }; diff --git a/palacios/src/devices/nic_bridge.c b/palacios/src/devices/nic_bridge.c index 7cdf392..60f606f 100644 --- a/palacios/src/devices/nic_bridge.c +++ b/palacios/src/devices/nic_bridge.c @@ -62,8 +62,7 @@ static int packet_input(struct v3_vm_info * vm, } -static int vnet_nic_free(struct vm_device * dev) { - struct nic_bridge_state * bridge = dev->private_data; +static int vnet_nic_free(struct nic_bridge_state * bridge) { /*detach from front device */ @@ -73,7 +72,7 @@ static int vnet_nic_free(struct vm_device * dev) { } static struct v3_device_ops dev_ops = { - .free = vnet_nic_free, + .free = (int (*)(void *))vnet_nic_free, }; diff --git a/palacios/src/devices/nvram.c b/palacios/src/devices/nvram.c index 38e9794..6fc974f 100644 --- a/palacios/src/devices/nvram.c +++ b/palacios/src/devices/nvram.c @@ -743,7 +743,11 @@ static int nvram_write_data_port(struct guest_info * core, ushort_t port, -static int nvram_free(struct vm_device * dev) { +static int nvram_free(struct nvram_internal * nvram_state) { + + // unregister host events + + V3_Free(nvram_state); return 0; } @@ -752,7 +756,7 @@ static int nvram_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = nvram_free, + .free = (int (*)(void *))nvram_free, }; diff --git a/palacios/src/devices/os_debug.c b/palacios/src/devices/os_debug.c index b97da12..97cdabc 100644 --- a/palacios/src/devices/os_debug.c +++ b/palacios/src/devices/os_debug.c @@ -81,8 +81,11 @@ static int handle_hcall(struct guest_info * info, uint_t hcall_id, void * priv_d -static int debug_free(struct vm_device * dev) { +static int debug_free(struct debug_state * state) { + // unregister hypercall + + V3_Free(state); return 0; }; @@ -90,7 +93,7 @@ static int debug_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = debug_free, + .free = (int (*)(void *))debug_free, }; diff --git a/palacios/src/devices/pci.c b/palacios/src/devices/pci.c index 5a12909..04d56f3 100644 --- a/palacios/src/devices/pci.c +++ b/palacios/src/devices/pci.c @@ -597,11 +597,6 @@ static int data_port_write(struct guest_info * core, ushort_t port, void * src, -static int pci_free(struct vm_device * dev) { - - return 0; -} - static void init_pci_busses(struct pci_internal * pci_state) { @@ -615,10 +610,17 @@ static void init_pci_busses(struct pci_internal * pci_state) { } +static int pci_free(struct pci_internal * pci_state) { + + // cleanup devices (?) + + V3_Free(pci_state); + return 0; +} static struct v3_device_ops dev_ops = { - .free = pci_free, + .free = (int (*)(void *))pci_free, }; diff --git a/palacios/src/devices/piix3.c b/palacios/src/devices/piix3.c index 669d147..ab82bdb 100644 --- a/palacios/src/devices/piix3.c +++ b/palacios/src/devices/piix3.c @@ -395,13 +395,17 @@ static int lower_pci_irq(struct pci_device * pci_dev, void * dev_data) { -static int piix_free(struct vm_device * dev) { +static int piix_free(struct v3_southbridge * piix3) { + + // unregister pci + + V3_Free(piix3); return 0; } static struct v3_device_ops dev_ops = { - .free = piix_free, + .free = (int (*)(void *))piix_free, }; diff --git a/palacios/src/devices/ramdisk.c b/palacios/src/devices/ramdisk.c index 5695bc4..4598707 100644 --- a/palacios/src/devices/ramdisk.c +++ b/palacios/src/devices/ramdisk.c @@ -72,12 +72,14 @@ static struct v3_dev_blk_ops blk_ops = { -static int disk_free(struct vm_device * dev) { +static int disk_free(struct disk_state * state) { + + V3_Free(state); return 0; } static struct v3_device_ops dev_ops = { - .free = disk_free, + .free = (int (*)(void *))disk_free, }; diff --git a/palacios/src/devices/serial.c b/palacios/src/devices/serial.c index e6adf3c..0035a7f 100644 --- a/palacios/src/devices/serial.c +++ b/palacios/src/devices/serial.c @@ -834,7 +834,9 @@ static int read_status_port(struct guest_info * core, uint16_t port, void * dst, return length; } -static int serial_free(struct vm_device * dev) { +static int serial_free(struct serial_state * state) { + + V3_Free(state); return 0; } @@ -842,7 +844,7 @@ static int serial_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = serial_free, + .free = (int (*)(void *))serial_free, }; diff --git a/palacios/src/devices/telnet_cons.c b/palacios/src/devices/telnet_cons.c index fc03c88..bd379cc 100644 --- a/palacios/src/devices/telnet_cons.c +++ b/palacios/src/devices/telnet_cons.c @@ -392,13 +392,17 @@ static struct v3_console_ops cons_ops = { .scroll = scroll, }; -static int cons_free(struct vm_device * dev) { - return -1; +static int cons_free(struct cons_state * state) { + + // kill thread... ? + + V3_Free(state); + return 0; } static struct v3_device_ops dev_ops = { - .free = cons_free, + .free = (int (*)(void *))cons_free, }; diff --git a/palacios/src/devices/tmpdisk.c b/palacios/src/devices/tmpdisk.c index 96bffef..0be279f 100644 --- a/palacios/src/devices/tmpdisk.c +++ b/palacios/src/devices/tmpdisk.c @@ -73,8 +73,11 @@ static int blk_write(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * pr } -static int blk_free(struct vm_device * dev) { - return -1; +static int blk_free(struct blk_state * blk) { + V3_FreePages((void *)blk->blk_base_addr, blk->capacity / 4096); + + V3_Free(blk); + return 0; } @@ -87,7 +90,7 @@ static struct v3_dev_blk_ops blk_ops = { static struct v3_device_ops dev_ops = { - .free = blk_free, + .free = (int (*)(void *))blk_free, }; diff --git a/palacios/src/devices/vnet_nic.c b/palacios/src/devices/vnet_nic.c index 4850d93..526da07 100644 --- a/palacios/src/devices/vnet_nic.c +++ b/palacios/src/devices/vnet_nic.c @@ -117,12 +117,15 @@ static void stop_tx(void * private_data){ } -static int vnet_nic_free(struct vm_device * dev) { +static int vnet_nic_free(struct vnet_nic_state * vnetnic) { + + + V3_Free(vnetnic); return 0; } static struct v3_device_ops dev_ops = { - .free = vnet_nic_free, + .free = (int (*)(void *))vnet_nic_free, }; diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index 14d1963..65b4b49 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -274,8 +274,17 @@ int v3_stop_vm(struct v3_vm_info * vm) { // Wait for all cores to enter CORE_STOPPED state + + + return 0; +} + + +int v3_free_vm(struct v3_vm_info * vm) { // deinitialize guest (free memory, etc...) + v3_dev_mgr_deinit(vm); + return 0; } diff --git a/palacios/src/palacios/vmm_dev_mgr.c b/palacios/src/palacios/vmm_dev_mgr.c index 70d0d5e..6f80ba9 100644 --- a/palacios/src/palacios/vmm_dev_mgr.c +++ b/palacios/src/palacios/vmm_dev_mgr.c @@ -234,7 +234,7 @@ int v3_remove_device(struct vm_device * dev) { } if (dev->ops->free) { - dev->ops->free(dev); + dev->ops->free(dev->private_data); } else { PrintError("Error: %s free() not implemented\n", dev->name); }