From: Peter Dinda Date: Sun, 2 Aug 2015 23:03:22 +0000 (-0500) Subject: Deallocation bug fix in device manager to allow backing out from VM creation failure X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=5257fd647c7873d682ccaece28b64fc0fb26d28a Deallocation bug fix in device manager to allow backing out from VM creation failure if VM creation fails before the device manager is inited, for example on running out of memory, device manager deinit needs to avoid running --- diff --git a/palacios/include/palacios/vmm_dev_mgr.h b/palacios/include/palacios/vmm_dev_mgr.h index f90232a..0f60313 100644 --- a/palacios/include/palacios/vmm_dev_mgr.h +++ b/palacios/include/palacios/vmm_dev_mgr.h @@ -58,6 +58,7 @@ struct vm_device { struct vmm_dev_mgr { + int inited; uint_t num_devs; struct list_head dev_list; struct hashtable * dev_table; diff --git a/palacios/src/palacios/vmm_dev_mgr.c b/palacios/src/palacios/vmm_dev_mgr.c index c75e633..0904ea1 100644 --- a/palacios/src/palacios/vmm_dev_mgr.c +++ b/palacios/src/palacios/vmm_dev_mgr.c @@ -119,7 +119,9 @@ int v3_init_dev_mgr(struct v3_vm_info * vm) { mgr->net_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn); mgr->char_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn); mgr->cons_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn); - + + mgr->inited = 1; + return 0; } @@ -328,8 +330,17 @@ int v3_load_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { static int free_frontends(struct v3_vm_info * vm, struct vmm_dev_mgr * mgr); int v3_deinit_dev_mgr(struct v3_vm_info * vm) { - struct vmm_dev_mgr * mgr = &(vm->dev_mgr); - + struct vmm_dev_mgr * mgr=0; + + if (vm) { + mgr = &(vm->dev_mgr); + if (!mgr->inited) { + return 0; + } + } else { + return 0; + } + // clear frontend lists free_frontends(vm, mgr); @@ -866,7 +877,7 @@ static int free_frontends(struct v3_vm_info * vm, struct vmm_dev_mgr * mgr) { struct blk_frontend * tmp_blk = NULL; - + list_for_each_entry_safe(chr, tmp_chr, &(mgr->char_list), char_node) { list_del(&(chr->char_node)); V3_Free(chr);