6 #include <linux/device.h>
7 #include <linux/cdev.h>
8 #include <linux/errno.h>
9 #include <linux/percpu.h>
11 #include <linux/uaccess.h>
12 #include <linux/poll.h>
13 #include <linux/anon_inodes.h>
14 #include <linux/sched.h>
16 #include <linux/smp_lock.h>
17 #include <linux/file.h>
18 #include <linux/spinlock.h>
20 #ifdef CONFIG_DEBUG_FS
21 #include "palacios-debugfs.h"
24 #include <palacios/vmm.h>
27 #include "palacios-console.h"
28 #include "palacios-serial.h"
29 #include "palacios-vm.h"
32 extern struct class * v3_class;
33 #define STREAM_NAME_LEN 128
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];
40 struct v3_guest * guest = filp->private_data;
42 printk("V3 IOCTL %d\n", ioctl);
46 case V3_VM_CONSOLE_CONNECT: {
47 return connect_console(guest);
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");
56 return open_serial(path_name);
60 printk("Stopping VM\n");
61 stop_palacios_vm(guest);
65 printk("\tUnhandled\n");
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;
79 static ssize_t v3_vm_read(struct file * filp, char __user * buf, size_t size, loff_t * offset) {
85 static ssize_t v3_vm_write(struct file * filp, const char __user * buf, size_t size, loff_t * offset) {
92 static struct file_operations v3_vm_fops = {
94 .unlocked_ioctl = v3_vm_ioctl,
95 .compat_ioctl = v3_vm_ioctl,
103 extern int vm_running;
104 extern u32 pg_allocs;
109 int start_palacios_vm(void * arg) {
110 struct v3_guest * guest = (struct v3_guest *)arg;
114 daemonize(guest->name);
115 // allow_signal(SIGKILL);
119 guest->v3_ctx = v3_create_vm(guest->img, (void *)guest, guest->name);
121 if (guest->v3_ctx == NULL) {
122 printk("palacios: failed to create vm\n");
126 printk("Creating VM device: Major %d, Minor %d\n", MAJOR(guest->vm_dev), MINOR(guest->vm_dev));
128 cdev_init(&(guest->cdev), &v3_vm_fops);
130 guest->cdev.owner = THIS_MODULE;
131 guest->cdev.ops = &v3_vm_fops;
134 printk("Adding VM device\n");
135 err = cdev_add(&(guest->cdev), guest->vm_dev, 1);
138 printk("Fails to add cdev\n");
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");
147 complete(&(guest->start_done));
149 printk("palacios: launching vm\n");
154 dfs_register_vm(guest);
158 if (v3_start_vm(guest->v3_ctx, 0xffffffff) < 0) {
159 printk("palacios: launch of vm failed\n");
163 complete(&(guest->thread_done));
165 printk("palacios: vm completed. returning.\n");
173 int stop_palacios_vm(struct v3_guest * guest) {
175 v3_stop_vm(guest->v3_ctx);
177 wait_for_completion(&(guest->thread_done));
179 v3_free_vm(guest->v3_ctx);
181 device_destroy(v3_class, guest->vm_dev);
183 cdev_del(&(guest->cdev));