if (vm_minor == -1) {
ERROR("Palacios Error: Too many VMs are currently running\n");
- palacios_free(guest);
- return -EFAULT;
+ goto out_err;
}
guest->vm_dev = MKDEV(v3_major_num, vm_minor);
if (copy_from_user(&user_image, argp, sizeof(struct v3_guest_img))) {
ERROR("Palacios Error: copy from user error getting guest image...\n");
- palacios_free(guest);
- return -EFAULT;
+ goto out_err1;
}
guest->img_size = user_image.size;
if (IS_ERR(guest->img)) {
ERROR("Palacios Error: Could not allocate space for guest image\n");
- palacios_free(guest);
- return -EFAULT;
+ goto out_err1;
}
if (copy_from_user(guest->img, user_image.guest_data, guest->img_size)) {
ERROR("Palacios: Error loading guest data\n");
- palacios_free(guest);
- return -EFAULT;
+ goto out_err2;
}
strncpy(guest->name, user_image.name, 127);
if (create_palacios_vm(guest) == -1) {
ERROR("Palacios: Error creating guest\n");
- vfree(guest->img);
- palacios_free(guest);
- return -EFAULT;
+ goto out_err2;
}
return vm_minor;
+
+
+out_err2:
+ vfree(guest->img);
+out_err1:
+ guest_map[vm_minor] = NULL;
+out_err:
+ palacios_free(guest);
+
+ return -1;
+
break;
}
case V3_FREE_GUEST: {
unsigned long vm_idx = arg;
struct v3_guest * guest = guest_map[vm_idx];
+ if (!guest) {
+ ERROR("No VM at index %ld\n",vm_idx);
+ return -1;
+ }
+
INFO("Freeing VM (%s) (%p)\n", guest->name, guest);
free_palacios_vm(guest);
int create_palacios_vm(struct v3_guest * guest) {
int err;
- init_vm_extensions(guest);
+ if (init_vm_extensions(guest) < 0) {
+ WARNING("palacios: failed to initialize extensions\n");
+ return -1;
+ }
guest->v3_ctx = v3_create_vm(guest->img, (void *)guest, guest->name);
if (guest->v3_ctx == NULL) {
WARNING("palacios: failed to create vm\n");
- return -1;
+ goto out_err;
}
-
NOTICE("Creating VM device: Major %d, Minor %d\n", MAJOR(guest->vm_dev), MINOR(guest->vm_dev));
cdev_init(&(guest->cdev), &v3_vm_fops);
if (err) {
WARNING("Fails to add cdev\n");
- v3_free_vm(guest->v3_ctx);
- return -1;
+ goto out_err1;
}
if (device_create(v3_class, NULL, guest->vm_dev, guest, "v3-vm%d", MINOR(guest->vm_dev)) == NULL){
WARNING("Fails to create device\n");
- cdev_del(&(guest->cdev));
- v3_free_vm(guest->v3_ctx);
- return -1;
+ goto out_err2;
}
NOTICE("palacios: vm created at /dev/v3-vm%d\n", MINOR(guest->vm_dev));
return 0;
+
+out_err2:
+ cdev_del(&(guest->cdev));
+out_err1:
+ v3_free_vm(guest->v3_ctx);
+out_err:
+ deinit_vm_extensions(guest);
+ return -1;
}