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.


Allow spaces in key names for textfile: saves
[palacios.git] / linux_module / main.c
index 57917e0..17229c5 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <linux/proc_fs.h>
 
+#include <palacios/vmm.h>
+
 #include "palacios.h"
 #include "mm.h"
 #include "vm.h"
@@ -139,7 +141,14 @@ out_err:
        }
        case V3_FREE_GUEST: {
            unsigned long vm_idx = arg;
-           struct v3_guest * guest = guest_map[vm_idx];
+            struct v3_guest * guest;
+
+            if (vm_idx > MAX_VMS) {
+                ERROR("Invalid VM index: %ld\n", vm_idx);
+                return -1;
+            }
+
+           guest = guest_map[vm_idx];
 
            if (!guest) {
                ERROR("No VM at index %ld\n",vm_idx);
@@ -148,7 +157,11 @@ out_err:
 
            INFO("Freeing VM (%s) (%p)\n", guest->name, guest);
 
-           free_palacios_vm(guest);
+           if (free_palacios_vm(guest)<0) { 
+               ERROR("Cannot free guest at index %ld\n",vm_idx);
+               return -1;
+           }
+
            guest_map[vm_idx] = NULL;
            break;
        }
@@ -172,9 +185,25 @@ out_err:
            break;
        }
 
-       default: 
-           ERROR("\tUnhandled\n");
+        case V3_RESET_MEMORY: {
+            if (palacios_init_mm() == -1) {
+                ERROR("Error resetting Palacios memory\n");
+                return -EFAULT;
+            }
+            break;  
+        }
+
+       default: {
+           struct global_ctrl * ctrl = get_global_ctrl(ioctl);
+           
+           if (ctrl) {
+               return ctrl->handler(ioctl, arg);
+           }
+
+           WARNING("\tUnhandled global ctrl cmd: %d\n", ioctl);
+
            return -EINVAL;
+       }
     }
 
     return 0;
@@ -316,13 +345,25 @@ static void __exit v3_exit(void) {
     extern u32 pg_frees;
     extern u32 mallocs;
     extern u32 frees;
+    int i = 0;
+    struct v3_guest * guest;
+    dev_t dev;
 
 
-    // should probably try to stop any guests
+    /* Stop and free any running VMs */ 
+    for (i = 0; i < MAX_VMS; i++) {
+       if (guest_map[i] != NULL) {
+                guest = (struct v3_guest *)guest_map[i];
 
+                if (v3_stop_vm(guest->v3_ctx) < 0) 
+                        ERROR("Couldn't stop VM %d\n", i);
 
+                free_palacios_vm(guest);
+                guest_map[i] = NULL;
+       }
+    }
 
-    dev_t dev = MKDEV(v3_major_num, MAX_VMS + 1);
+    dev = MKDEV(v3_major_num, MAX_VMS + 1);
 
     INFO("Removing V3 Control device\n");