X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_dev_mgr.c;h=d08b227816fb2d709ab749674afbc5321402dd85;hb=517acba107414f29b95967ecc46f4c7afdb782be;hp=e6fad6929ca673cebaa216c9968f893a2f88803c;hpb=5d1bbcc86de011e3f0d115b6f10fd8645cdf855e;p=palacios.git diff --git a/palacios/src/palacios/vmm_dev_mgr.c b/palacios/src/palacios/vmm_dev_mgr.c index e6fad69..d08b227 100644 --- a/palacios/src/palacios/vmm_dev_mgr.c +++ b/palacios/src/palacios/vmm_dev_mgr.c @@ -153,7 +153,8 @@ int v3_save_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { if (dev->ops->save) { struct v3_chkpt_ctx * dev_ctx = NULL; - + + V3_Print("Saving state for device (%s)\n", dev->name); dev_ctx = v3_chkpt_open_ctx(chkpt, dev_mgr_ctx, dev->name); @@ -184,11 +185,47 @@ int v3_save_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { int v3_load_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { + struct vm_device * dev; + struct v3_chkpt_ctx * dev_mgr_ctx = NULL; + uint32_t num_devs = 0; + char * name_table = NULL; + int i = 0; - PrintError("TODO... \n"); + dev_mgr_ctx = v3_chkpt_open_ctx(chkpt, NULL, "devices"); - // Read devices from checkpoint data - // selectively load them + v3_chkpt_load(dev_mgr_ctx, "num_devs", 4, &num_devs); + + V3_Print("Loading State for %d devices\n", num_devs); + + name_table = V3_Malloc(32 * num_devs); + + v3_chkpt_load(dev_mgr_ctx, "names", 32 * num_devs, name_table); + + for (i = 0; i < num_devs; i++) { + char * name = &(name_table[i * 32]); + struct v3_chkpt_ctx * dev_ctx = NULL; + dev = v3_find_dev(vm, name); + + if (!dev) { + PrintError("Tried to load state into non existant device: %s\n", name); + continue; + } + + if (!dev->ops->load) { + PrintError("Error Device (%s) does not support load operation\n", name); + continue; + } + + dev_ctx = v3_chkpt_open_ctx(chkpt, dev_mgr_ctx, name); + + if (!dev_ctx) { + PrintError("Error missing device context (%s)\n", name); + continue; + } + + + dev->ops->load(dev_ctx, dev->private_data); + } return 0; } @@ -400,6 +437,13 @@ struct vm_device * v3_add_device(struct v3_vm_info * vm, struct vmm_dev_mgr * mgr = &(vm->dev_mgr); struct vm_device * dev = NULL; + + // Check if we already registered a device of the same name + if (v3_htable_search(mgr->dev_table, (addr_t)name) != (addr_t)NULL) { + PrintError("Device with name (%s) already registered with VM\n", name); + return NULL; + } + dev = (struct vm_device *)V3_Malloc(sizeof(struct vm_device)); if (dev == NULL) {