From: Jack Lange Date: Wed, 8 Jun 2011 20:01:51 +0000 (-0500) Subject: ported file interface to new extension framework X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=8792ea4ea6462c30e016293fbbd2659b3befdad4;p=palacios.git ported file interface to new extension framework --- diff --git a/linux_module/linux-exts.c b/linux_module/linux-exts.c index d6409b8..d07cef0 100644 --- a/linux_module/linux-exts.c +++ b/linux_module/linux-exts.c @@ -17,6 +17,18 @@ struct vm_ext { }; +void * get_vm_ext_data(struct v3_guest * guest, char * ext_name) { + struct vm_ext * ext = NULL; + + list_for_each_entry(ext, &(guest->exts), node) { + if (strncmp(ext->impl->name, ext_name, strlen(ext->impl->name)) == 0) { + return ext->vm_data; + } + } + + return NULL; +} + int init_vm_extensions(struct v3_guest * guest) { extern struct linux_ext * __start__lnx_exts[]; @@ -29,6 +41,7 @@ int init_vm_extensions(struct v3_guest * guest) { if (ext_impl->guest_init == NULL) { // We can have global extensions without per guest state + ext_impl = __start__lnx_exts[++i]; continue; } @@ -54,6 +67,7 @@ int init_vm_extensions(struct v3_guest * guest) { } + int deinit_vm_extensions(struct v3_guest * guest) { struct vm_ext * ext = NULL; struct vm_ext * tmp = NULL; diff --git a/linux_module/linux-exts.h b/linux_module/linux-exts.h index 041d8dc..c5aeea1 100644 --- a/linux_module/linux-exts.h +++ b/linux_module/linux-exts.h @@ -19,6 +19,11 @@ struct linux_ext { int init_lnx_extensions( void ); int deinit_lnx_extensions( void ); +int init_vm_extensions(struct v3_guest * guest); +int deinit_vm_extensions(struct v3_guest * guest); + +void * get_vm_ext_data(struct v3_guest * guest, char * ext_name); + #define register_extension(ext) \ diff --git a/linux_module/palacios-dev.c b/linux_module/palacios-dev.c index 7e796cf..cc4553d 100644 --- a/linux_module/palacios-dev.c +++ b/linux_module/palacios-dev.c @@ -22,7 +22,6 @@ #include "palacios-mm.h" #include "palacios-vm.h" #include "palacios-stream.h" -#include "palacios-file.h" #include "palacios-serial.h" #include "palacios-socket.h" #include "palacios-vnet.h" @@ -140,7 +139,6 @@ static long v3_dev_ioctl(struct file * filp, INIT_LIST_HEAD(&(guest->streams)); - INIT_LIST_HEAD(&(guest->files)); INIT_LIST_HEAD(&(guest->sockets)); #ifdef V3_CONFIG_HOST_DEVICE INIT_LIST_HEAD(&(guest->hostdev.devs)); @@ -267,10 +265,6 @@ static int __init v3_init(void) { palacios_init_stream(); #endif -#ifdef V3_CONFIG_FILE - palacios_file_init(); -#endif - #ifdef V3_CONFIG_KEYED_STREAMS palacios_init_keyed_streams(); #endif @@ -339,14 +333,13 @@ static void __exit v3_exit(void) { class_destroy(v3_class); + deinit_lnx_extensions(); + #ifdef V3_CONFIG_EXT_INSPECTOR palacios_deinit_inspector(); #endif -#ifdef V3_CONFIG_FILE - palacios_file_deinit(); -#endif #ifdef V3_CONFIG_STREAM palacios_deinit_stream(); diff --git a/linux_module/palacios-file.c b/linux_module/palacios-file.c index 2f414b5..396183b 100644 --- a/linux_module/palacios-file.c +++ b/linux_module/palacios-file.c @@ -10,11 +10,13 @@ #include #include "palacios.h" +#include "linux-exts.h" #include static struct list_head global_files; + struct palacios_file { struct file * filp; @@ -30,10 +32,26 @@ struct palacios_file { }; +// Currently this just holds the list of open files +struct vm_file_state { + struct list_head open_files; +}; + + static void * palacios_file_open(const char * path, int mode, void * private_data) { struct v3_guest * guest = (struct v3_guest *)private_data; - struct palacios_file * pfile = NULL; + struct palacios_file * pfile = NULL; + struct vm_file_state * vm_state = NULL; + + if (guest != NULL) { + vm_state = get_vm_ext_data(guest, "FILE_INTERFACE"); + + if (vm_state == NULL) { + printk("ERROR: Could not locate vm file state for extension FILE_INTERFACE\n"); + return NULL; + } + } pfile = kmalloc(sizeof(struct palacios_file), GFP_KERNEL); memset(pfile, 0, sizeof(struct palacios_file)); @@ -62,7 +80,7 @@ static void * palacios_file_open(const char * path, int mode, void * private_dat if (guest == NULL) { list_add(&(pfile->file_node), &(global_files)); } else { - list_add(&(pfile->file_node), &(guest->files)); + list_add(&(pfile->file_node), &(vm_state->open_files)); } @@ -150,7 +168,8 @@ static struct v3_file_hooks palacios_file_hooks = { }; -int palacios_file_init( void ) { + +static int file_init( void ) { INIT_LIST_HEAD(&(global_files)); V3_Init_File(&palacios_file_hooks); @@ -159,10 +178,38 @@ int palacios_file_init( void ) { } -int palacios_file_deinit( void ) { +static int file_deinit( void ) { if (!list_empty(&(global_files))) { printk("Error removing module with open files\n"); } return 0; } + +static int guest_file_init(struct v3_guest * guest, void ** vm_data) { + struct vm_file_state * state = kmalloc(sizeof(struct vm_file_state), GFP_KERNEL); + + INIT_LIST_HEAD(&(state->open_files)); + + *vm_data = state; + + return 0; +} + + +static int guest_file_deinit(struct v3_guest * guest, void * vm_data) { + + return 0; +} + + +static struct linux_ext file_ext = { + .name = "FILE_INTERFACE", + .init = file_init, + .deinit = file_deinit, + .guest_init = guest_file_init, + .guest_deinit = guest_file_deinit +}; + + +register_extension(&file_ext); diff --git a/linux_module/palacios-file.h b/linux_module/palacios-file.h deleted file mode 100644 index 280585a..0000000 --- a/linux_module/palacios-file.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __PALACIOS_FILE_H__ -#define __PALACISO_FILE_H__ - -int palacios_file_init(void); -int palacios_file_deinit(void); - -#endif diff --git a/linux_module/palacios-vm.c b/linux_module/palacios-vm.c index d3ae315..715d626 100644 --- a/linux_module/palacios-vm.c +++ b/linux_module/palacios-vm.c @@ -22,6 +22,7 @@ #include "palacios.h" #include "palacios-vm.h" +#include "linux-exts.h" struct vm_ctrl { @@ -262,6 +263,7 @@ int start_palacios_vm(void * arg) { // allow_signal(SIGKILL); unlock_kernel(); + init_vm_extensions(guest); guest->v3_ctx = v3_create_vm(guest->img, (void *)guest, guest->name); diff --git a/linux_module/palacios.h b/linux_module/palacios.h index 936b71a..bd01430 100644 --- a/linux_module/palacios.h +++ b/linux_module/palacios.h @@ -65,7 +65,6 @@ struct v3_guest { struct rb_root vm_ctrls; struct list_head exts; - struct list_head files; struct list_head streams; struct list_head sockets;