Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Fail gracefully on VM create or free errors
Kyle Hale [Sat, 7 Jul 2012 22:47:17 +0000 (17:47 -0500)]
linux_module/main.c
linux_module/vm.c

index c432e3c..57917e0 100644 (file)
@@ -89,16 +89,14 @@ static long v3_dev_ioctl(struct file * filp,
 
            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;
@@ -108,14 +106,12 @@ static long v3_dev_ioctl(struct file * filp,
 
            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);
@@ -124,18 +120,32 @@ static long v3_dev_ioctl(struct file * filp,
 
            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);
index 842d472..1e9b275 100644 (file)
@@ -303,16 +303,18 @@ extern u32 frees;
 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);
@@ -326,20 +328,25 @@ int create_palacios_vm(struct v3_guest * guest)  {
 
     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;
 }