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.


cd3ba2c23e622fb76db87ea7011d23a8878c80f2
[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
117
118     guest->v3_ctx = v3_create_vm(guest->img, (void *)guest, guest->name);
119
120     if (guest->v3_ctx == NULL) { 
121         printk("palacios: failed to create vm\n");
122         return -1;
123     }
124
125     printk("Creating VM device: Major %d, Minor %d\n", MAJOR(guest->vm_dev), MINOR(guest->vm_dev));
126
127     cdev_init(&(guest->cdev), &v3_vm_fops);     
128
129     guest->cdev.owner = THIS_MODULE;
130     guest->cdev.ops = &v3_vm_fops;
131
132
133     printk("Adding VM device\n");
134     err = cdev_add(&(guest->cdev), guest->vm_dev, 1);
135
136     if (err) {
137         printk("Fails to add cdev\n");
138         return -1;
139     }
140
141     if (device_create(v3_class, NULL, guest->vm_dev, guest, "v3-vm%d", MINOR(guest->vm_dev)) == NULL){
142         printk("Fails to create device\n");
143         return -1;
144     }
145
146     complete(&(guest->thread_done));
147
148
149     printk("palacios: launching vm\n");   
150
151     if (v3_start_vm(guest->v3_ctx, 0xffffffff) < 0) { 
152         printk("palacios: launch of vm failed\n");
153         return -1;
154     } 
155     
156     complete(&(guest->thread_done));
157
158
159     printk("palacios: vm completed.  returning.\n");
160
161     return 0;
162 }
163
164
165
166
167 int stop_palacios_vm(struct v3_guest * guest) {
168     
169     v3_stop_vm(guest->v3_ctx);
170
171     wait_for_completion(&(guest->thread_done));
172
173     v3_free_vm(guest->v3_ctx);
174     
175
176     return 0;
177 }