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.


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