goto out;
}
- /*
- if ((ret = v3_chkpt_save_dev(vm)) == -1) {
+
+ if ((ret = v3_save_vm_devices(vm, chkpt)) == -1) {
PrintError("Unable to save devices\n");
goto out;
}
- */
+
if ((ret = save_header(vm, chkpt)) == -1) {
PrintError("Unable to save header\n");
}
- /* Don't handle devices just yet
- if (v3_chkpt_load_dev(vm) == -1) {
+ if ((ret = v3_load_vm_devices(vm, chkpt)) == -1) {
PrintError("Unable to load devies\n");
+ goto out;
}
- */
if ((ret = load_header(vm, chkpt)) == -1) {
PrintError("Unable to load header\n");
}
}
- out:
+ out:
/* Resume the guest if it was running and we didn't just trash the state*/
if (vm->run_state == VM_RUNNING) {
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;
+
+ dev_mgr_ctx = v3_chkpt_open_ctx(chkpt, NULL, "devices");
+
+ 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);
- PrintError("TODO... \n");
+ 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);
- // Read devices from checkpoint data
- // selectively load them
+ 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;
}