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.


updated linux module to new build framework
[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
21 #include <palacios/vmm.h>
22
23 #include "palacios.h"
24 #include "palacios-vm.h"
25
26 #ifdef V3_CONFIG_STREAM
27 #include "palacios-stream.h"
28 #endif
29
30 #ifdef V3_CONFIG_CONSOLE
31 #include "palacios-console.h"
32 #endif
33
34 #ifdef V3_CONFIG_EXT_INSPECTOR
35 #include "palacios-debugfs.h"
36 #endif
37
38
39
40 extern struct class * v3_class;
41 #define STREAM_NAME_LEN 128
42
43 static long v3_vm_ioctl(struct file * filp,
44                         unsigned int ioctl, unsigned long arg) {
45
46     struct v3_guest * guest = filp->private_data;
47
48     printk("V3 IOCTL %d\n", ioctl);
49
50     switch (ioctl) {
51
52         case V3_VM_STOP: {
53             printk("Stopping VM\n");
54             stop_palacios_vm(guest);
55             break;
56         }
57
58         case V3_VM_CONSOLE_CONNECT: {
59 #ifdef V3_CONFIG_CONSOLE
60             return connect_console(guest);
61 #else
62             printk("Console support not available\n");
63             return -EFAULT;
64 #endif
65             break;
66         }
67         case V3_VM_STREAM_CONNECT: {
68 #ifdef V3_CONFIG_STREAM
69             void __user * argp = (void __user *)arg;
70             char path_name[STREAM_NAME_LEN];
71
72             if (copy_from_user(path_name, argp, STREAM_NAME_LEN)) {
73                 printk("%s(%d): copy from user error...\n", __FILE__, __LINE__);
74                 return -EFAULT;
75             }
76
77             return open_stream(path_name);
78 #else
79             printk("Stream support Not available\n");
80             return -EFAULT;
81 #endif
82             break;
83         }
84
85         default: 
86             printk("\tUnhandled\n");
87             return -EINVAL;
88     }
89
90     return 0;
91 }
92
93 static int v3_vm_open(struct inode * inode, struct file * filp) {
94     struct v3_guest * guest = container_of(inode->i_cdev, struct v3_guest, cdev);
95     filp->private_data = guest;
96     return 0;
97 }
98
99
100 static ssize_t v3_vm_read(struct file * filp, char __user * buf, size_t size, loff_t * offset) {
101     
102     return 0;
103 }
104
105
106 static ssize_t v3_vm_write(struct file * filp, const char __user * buf, size_t size, loff_t * offset) {
107     
108
109     return 0;
110 }
111
112
113 static struct file_operations v3_vm_fops = {
114     .owner = THIS_MODULE,
115     .unlocked_ioctl = v3_vm_ioctl,
116     .compat_ioctl = v3_vm_ioctl,
117     .open = v3_vm_open,
118     .read = v3_vm_read, 
119     .write = v3_vm_write,
120 };
121
122
123
124 extern int vm_running;
125 extern u32 pg_allocs;
126 extern u32 pg_frees;
127 extern u32 mallocs;
128 extern u32 frees;
129
130 int start_palacios_vm(void * arg)  {
131     struct v3_guest * guest = (struct v3_guest *)arg;
132     int err;
133
134     lock_kernel();
135     daemonize(guest->name);
136 //    allow_signal(SIGKILL);
137     unlock_kernel();
138     
139
140     guest->v3_ctx = v3_create_vm(guest->img, (void *)guest, guest->name);
141
142     if (guest->v3_ctx == NULL) { 
143         printk("palacios: failed to create vm\n");
144         return -1;
145     }
146
147     printk("Creating VM device: Major %d, Minor %d\n", MAJOR(guest->vm_dev), MINOR(guest->vm_dev));
148
149     cdev_init(&(guest->cdev), &v3_vm_fops);     
150
151     guest->cdev.owner = THIS_MODULE;
152     guest->cdev.ops = &v3_vm_fops;
153
154
155     printk("Adding VM device\n");
156     err = cdev_add(&(guest->cdev), guest->vm_dev, 1);
157
158     if (err) {
159         printk("Fails to add cdev\n");
160         return -1;
161     }
162
163     if (device_create(v3_class, NULL, guest->vm_dev, guest, "v3-vm%d", MINOR(guest->vm_dev)) == NULL){
164         printk("Fails to create device\n");
165         return -1;
166     }
167
168     complete(&(guest->start_done));
169
170     printk("palacios: launching vm\n");   
171
172
173
174 #if V3_CONFIG_EXT_INSPECTOR
175     dfs_register_vm(guest);
176 #endif
177
178
179     if (v3_start_vm(guest->v3_ctx, 0xffffffff) < 0) { 
180         printk("palacios: launch of vm failed\n");
181         return -1;
182     }
183     
184     complete(&(guest->thread_done));
185
186     printk("palacios: vm completed.  returning.\n");
187
188     return 0;
189 }
190
191
192
193
194 int stop_palacios_vm(struct v3_guest * guest) {
195
196     v3_stop_vm(guest->v3_ctx);
197
198     wait_for_completion(&(guest->thread_done));
199
200     v3_free_vm(guest->v3_ctx);
201     
202     device_destroy(v3_class, guest->vm_dev);
203
204     cdev_del(&(guest->cdev));
205
206     kfree(guest->img);
207     kfree(guest);
208
209     return 0;
210 }