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.


added extension framework with initial inspector extension
[palacios.git] / linux_module / palacios-vm.c
1 /* 
2  * VM specific Controls
3  * (c) Jack Lange, 2010
4  */
5
6 #include <linux/device.h>
7 #include <linux/cdev.h>
8 #include <linux/errno.h>
9 #include <linux/percpu.h>
10 #include <linux/fs.h>
11 #include <linux/uaccess.h>
12 #include <linux/poll.h>
13 #include <linux/anon_inodes.h>
14 #include <linux/sched.h>
15
16 #include <linux/smp_lock.h>
17 #include <linux/file.h>
18 #include <linux/spinlock.h>
19
20 #ifdef CONFIG_DEBUG_FS
21 #include "palacios-debugfs.h"
22 #endif
23
24 #include <palacios/vmm.h>
25
26 #include "palacios.h"
27 #include "palacios-console.h"
28 #include "palacios-serial.h"
29 #include "palacios-vm.h"
30
31
32 extern struct class * v3_class;
33 #define STREAM_NAME_LEN 128
34
35 static long v3_vm_ioctl(struct file * filp,
36                         unsigned int ioctl, unsigned long arg) {
37     void __user * argp = (void __user *)arg;
38     char path_name[STREAM_NAME_LEN];
39
40     struct v3_guest * guest = filp->private_data;
41
42     printk("V3 IOCTL %d\n", ioctl);
43
44     switch (ioctl) {
45
46         case V3_VM_CONSOLE_CONNECT: {
47             return connect_console(guest);
48             break;
49         }
50         case V3_VM_SERIAL_CONNECT: {
51             if (copy_from_user(path_name, argp, STREAM_NAME_LEN)) {
52                 printk("copy from user error getting guest image...\n");
53                 return -EFAULT;
54             }
55
56             return open_serial(path_name);
57             break;
58         }
59         case V3_VM_STOP: {
60             printk("Stopping VM\n");
61             stop_palacios_vm(guest);
62             break;
63         }
64         default: 
65             printk("\tUnhandled\n");
66             return -EINVAL;
67     }
68
69     return 0;
70 }
71
72 static int v3_vm_open(struct inode * inode, struct file * filp) {
73     struct v3_guest * guest = container_of(inode->i_cdev, struct v3_guest, cdev);
74     filp->private_data = guest;
75     return 0;
76 }
77
78
79 static ssize_t v3_vm_read(struct file * filp, char __user * buf, size_t size, loff_t * offset) {
80     
81     return 0;
82 }
83
84
85 static ssize_t v3_vm_write(struct file * filp, const char __user * buf, size_t size, loff_t * offset) {
86     
87
88     return 0;
89 }
90
91
92 static struct file_operations v3_vm_fops = {
93     .owner = THIS_MODULE,
94     .unlocked_ioctl = v3_vm_ioctl,
95     .compat_ioctl = v3_vm_ioctl,
96     .open = v3_vm_open,
97     .read = v3_vm_read, 
98     .write = v3_vm_write,
99 };
100
101
102
103 extern int vm_running;
104 extern u32 pg_allocs;
105 extern u32 pg_frees;
106 extern u32 mallocs;
107 extern u32 frees;
108
109 int start_palacios_vm(void * arg)  {
110     struct v3_guest * guest = (struct v3_guest *)arg;
111     int err;
112
113     lock_kernel();
114     daemonize(guest->name);
115 //    allow_signal(SIGKILL);
116     unlock_kernel();
117     
118
119     guest->v3_ctx = v3_create_vm(guest->img, (void *)guest, guest->name);
120
121     if (guest->v3_ctx == NULL) { 
122         printk("palacios: failed to create vm\n");
123         return -1;
124     }
125
126     printk("Creating VM device: Major %d, Minor %d\n", MAJOR(guest->vm_dev), MINOR(guest->vm_dev));
127
128     cdev_init(&(guest->cdev), &v3_vm_fops);     
129
130     guest->cdev.owner = THIS_MODULE;
131     guest->cdev.ops = &v3_vm_fops;
132
133
134     printk("Adding VM device\n");
135     err = cdev_add(&(guest->cdev), guest->vm_dev, 1);
136
137     if (err) {
138         printk("Fails to add cdev\n");
139         return -1;
140     }
141
142     if (device_create(v3_class, NULL, guest->vm_dev, guest, "v3-vm%d", MINOR(guest->vm_dev)) == NULL){
143         printk("Fails to create device\n");
144         return -1;
145     }
146
147     complete(&(guest->start_done));
148
149     printk("palacios: launching vm\n");   
150
151
152
153 #if CONFIG_DEBUG_FS
154     dfs_register_vm(guest);
155 #endif
156
157
158     if (v3_start_vm(guest->v3_ctx, 0xffffffff) < 0) { 
159         printk("palacios: launch of vm failed\n");
160         return -1;
161     }
162     
163     complete(&(guest->thread_done));
164
165     printk("palacios: vm completed.  returning.\n");
166
167     return 0;
168 }
169
170
171
172
173 int stop_palacios_vm(struct v3_guest * guest) {
174
175     v3_stop_vm(guest->v3_ctx);
176
177     wait_for_completion(&(guest->thread_done));
178
179     v3_free_vm(guest->v3_ctx);
180     
181     device_destroy(v3_class, guest->vm_dev);
182
183     cdev_del(&(guest->cdev));
184
185     kfree(guest->img);
186     kfree(guest);
187
188     return 0;
189 }