X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Fpalacios-vm.c;h=e98be0c98d9609f3465a0b36814133c5355ea7e5;hb=3518e3eb158edabb0d471ceb406c450490a4d07a;hp=943bbff17c2ea77e020fe355e99975e2b0d7f3a5;hpb=374b2d6d22a0e0dc6ed8d3d628e635ab935072e0;p=palacios-OLD.git diff --git a/linux_module/palacios-vm.c b/linux_module/palacios-vm.c index 943bbff..e98be0c 100644 --- a/linux_module/palacios-vm.c +++ b/linux_module/palacios-vm.c @@ -13,29 +13,114 @@ #include #include -#include #include #include - -#ifdef CONFIG_DEBUG_FS -#include -#endif +#include #include #include "palacios.h" -#include "palacios-console.h" -#include "palacios-serial.h" #include "palacios-vm.h" +#include "linux-exts.h" + + +struct vm_ctrl { + unsigned int cmd; + + int (*handler)(struct v3_guest * guest, + unsigned int cmd, unsigned long arg, + void * priv_data); + + void * priv_data; + + struct rb_node tree_node; +}; + + +static inline struct vm_ctrl * __insert_ctrl(struct v3_guest * vm, + struct vm_ctrl * ctrl) { + struct rb_node ** p = &(vm->vm_ctrls.rb_node); + struct rb_node * parent = NULL; + struct vm_ctrl * tmp_ctrl = NULL; + + while (*p) { + parent = *p; + tmp_ctrl = rb_entry(parent, struct vm_ctrl, tree_node); + + if (ctrl->cmd < tmp_ctrl->cmd) { + p = &(*p)->rb_left; + } else if (ctrl->cmd > tmp_ctrl->cmd) { + p = &(*p)->rb_right; + } else { + return tmp_ctrl; + } + } + + rb_link_node(&(ctrl->tree_node), parent, p); + + return NULL; +} + + + +int add_guest_ctrl(struct v3_guest * guest, unsigned int cmd, + int (*handler)(struct v3_guest * guest, + unsigned int cmd, unsigned long arg, + void * priv_data), + void * priv_data) { + struct vm_ctrl * ctrl = kmalloc(sizeof(struct vm_ctrl), GFP_KERNEL); + + if (ctrl == NULL) { + printk("Error: Could not allocate vm ctrl %d\n", cmd); + return -1; + } + + ctrl->cmd = cmd; + ctrl->handler = handler; + ctrl->priv_data = priv_data; + + if (__insert_ctrl(guest, ctrl) != NULL) { + printk("Could not insert guest ctrl %d\n", cmd); + kfree(ctrl); + return -1; + } + + rb_insert_color(&(ctrl->tree_node), &(guest->vm_ctrls)); + + return 0; +} + + +static struct vm_ctrl * get_ctrl(struct v3_guest * guest, unsigned int cmd) { + struct rb_node * n = guest->vm_ctrls.rb_node; + struct vm_ctrl * ctrl = NULL; + + while (n) { + ctrl = rb_entry(n, struct vm_ctrl, tree_node); + + if (cmd < ctrl->cmd) { + n = n->rb_left; + } else if (cmd > ctrl->cmd) { + n = n->rb_right; + } else { + return ctrl; + } + } + + return NULL; +} + + + + + extern struct class * v3_class; -#define STREAM_NAME_LEN 128 + static long v3_vm_ioctl(struct file * filp, unsigned int ioctl, unsigned long arg) { - void __user * argp = (void __user *)arg; - char path_name[STREAM_NAME_LEN]; struct v3_guest * guest = filp->private_data; @@ -43,27 +128,23 @@ static long v3_vm_ioctl(struct file * filp, switch (ioctl) { - case V3_VM_CONSOLE_CONNECT: { - return connect_console(guest); - break; - } - case V3_VM_SERIAL_CONNECT: { - if (copy_from_user(path_name, argp, STREAM_NAME_LEN)) { - printk("copy from user error getting guest image...\n"); - return -EFAULT; - } - - return open_serial(path_name); - break; - } case V3_VM_STOP: { printk("Stopping VM\n"); stop_palacios_vm(guest); break; } - default: - printk("\tUnhandled\n"); + + default: { + struct vm_ctrl * ctrl = get_ctrl(guest, ioctl); + + if (ctrl) { + return ctrl->handler(guest, ioctl, arg, ctrl->priv_data); + } + + + printk("\tUnhandled ctrl cmd: %d\n", ioctl); return -EINVAL; + } } return 0; @@ -83,7 +164,6 @@ static ssize_t v3_vm_read(struct file * filp, char __user * buf, size_t size, lo static ssize_t v3_vm_write(struct file * filp, const char __user * buf, size_t size, loff_t * offset) { - return 0; } @@ -99,35 +179,34 @@ static struct file_operations v3_vm_fops = { }; - -extern int vm_running; extern u32 pg_allocs; extern u32 pg_frees; extern u32 mallocs; extern u32 frees; -#include - int start_palacios_vm(void * arg) { struct v3_guest * guest = (struct v3_guest *)arg; int err; - lock_kernel(); + daemonize(guest->name); -// allow_signal(SIGKILL); - unlock_kernel(); + // allow_signal(SIGKILL); + + init_vm_extensions(guest); guest->v3_ctx = v3_create_vm(guest->img, (void *)guest, guest->name); if (guest->v3_ctx == NULL) { printk("palacios: failed to create vm\n"); + complete(&(guest->start_done)); return -1; } + printk("Creating VM device: Major %d, Minor %d\n", MAJOR(guest->vm_dev), MINOR(guest->vm_dev)); - cdev_init(&(guest->cdev), &v3_vm_fops); + cdev_init(&(guest->cdev), &v3_vm_fops); guest->cdev.owner = THIS_MODULE; guest->cdev.ops = &v3_vm_fops; @@ -138,51 +217,28 @@ int start_palacios_vm(void * arg) { if (err) { printk("Fails to add cdev\n"); + v3_free_vm(guest->v3_ctx); + complete(&(guest->start_done)); return -1; } if (device_create(v3_class, NULL, guest->vm_dev, guest, "v3-vm%d", MINOR(guest->vm_dev)) == NULL){ printk("Fails to create device\n"); + cdev_del(&(guest->cdev)); + v3_free_vm(guest->v3_ctx); + complete(&(guest->start_done)); return -1; } complete(&(guest->start_done)); - printk("palacios: launching vm\n"); - - - -#if 0 - // Inspection Test - { - struct v3_inspection_value rax; - v3_inspect_node_t * core = NULL; - v3_inspect_node_t * gprs = NULL; - v3_inspect_node_t * root = v3_get_inspection_root(guest->v3_ctx); - - if (!root) { - printk("NULL root inspection tree\n"); - } - - core = v3_get_inspection_subtree(root, "core.0"); - if (!core) { - printk("NULL core inspection tree\n"); - } - - gprs = v3_get_inspection_subtree(core, "GPRS"); - if (!gprs) { - printk("NULL gprs inspection tree\n"); - } - - v3_get_inspection_value(gprs, "RAX", &rax); - - debugfs_create_u64("RAX", 0644, NULL, (u64 *)rax.value); - } -#endif - + printk("palacios: launching vm\n"); if (v3_start_vm(guest->v3_ctx, 0xffffffff) < 0) { printk("palacios: launch of vm failed\n"); + device_destroy(v3_class, guest->vm_dev); + cdev_del(&(guest->cdev)); + v3_free_vm(guest->v3_ctx); return -1; }