X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Fiface-file.c;h=062a6d226dafecfa5a7cf2e8c1e84d86fdfb11b4;hb=8f7141b61d0c58befc5433a22d9af728fe3bb6f9;hp=96a247765c6fd65311ca786c22d44986c4491c32;hpb=71339a5a1f4efa93438ab9ab78e1317034b84da6;p=palacios.git diff --git a/linux_module/iface-file.c b/linux_module/iface-file.c index 96a2477..062a6d2 100644 --- a/linux_module/iface-file.c +++ b/linux_module/iface-file.c @@ -66,7 +66,7 @@ static int mkdir_recursive(const char * path, unsigned short perms) { (*tmp_iter != '\0')) { if ( (!isprint(*tmp_iter))) { - printk("Invalid character in path name (%d)\n", *tmp_iter); + ERROR("Invalid character in path name (%d)\n", *tmp_iter); return -1; } else { tmp_iter++; @@ -82,7 +82,7 @@ static int mkdir_recursive(const char * path, unsigned short perms) { // Ignore empty directories if ((tmp_iter - dirname_ptr) > 1) { if (palacios_file_mkdir(tmp_str, perms, 0) != 0) { - printk("Could not create directory (%s)\n", tmp_str); + ERROR("Could not create directory (%s)\n", tmp_str); return -1; } } @@ -106,7 +106,7 @@ static int mkdir_recursive(const char * path, unsigned short perms) { static int palacios_file_mkdir(const char * pathname, unsigned short perms, int recurse) { /* Welcome to the jungle... */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,41) /* DO NOT REFERENCE THIS VARIABLE */ /* It only exists to provide version compatibility */ struct path tmp_path; @@ -123,12 +123,12 @@ static int palacios_file_mkdir(const char * pathname, unsigned short perms, int } /* Before Linux 3.1 this was somewhat more difficult */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,41) { struct nameidata nd; // I'm not 100% sure about the version here, but it was around this time that the API changed -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35) +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38) ret = kern_path_parent(pathname, &nd); #else @@ -142,7 +142,7 @@ static int palacios_file_mkdir(const char * pathname, unsigned short perms, int #endif if (ret != 0) { - printk("%s:%d - Error: kern_path_parent() returned error for (%s)\n", __FILE__, __LINE__, + ERROR("%s:%d - Error: kern_path_parent() returned error for (%s)\n", __FILE__, __LINE__, pathname); return -1; } @@ -183,7 +183,7 @@ static void * palacios_file_open(const char * path, int mode, void * private_dat 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"); + ERROR("ERROR: Could not locate vm file state for extension FILE_INTERFACE\n"); return NULL; } } @@ -204,10 +204,13 @@ static void * palacios_file_open(const char * path, int mode, void * private_dat } + pfile->mode |= O_LARGEFILE; + + pfile->filp = filp_open(path, pfile->mode, 0); - if (pfile->filp == NULL) { - printk("Cannot open file: %s\n", path); + if (IS_ERR(pfile->filp)) { + ERROR("Cannot open file: %s\n", path); return NULL; } @@ -240,7 +243,7 @@ static int palacios_file_close(void * file_ptr) { return 0; } -static long long palacios_file_size(void * file_ptr) { +static unsigned long long palacios_file_size(void * file_ptr) { struct palacios_file * pfile = (struct palacios_file *)file_ptr; struct file * filp = pfile->filp; struct kstat s; @@ -249,14 +252,14 @@ static long long palacios_file_size(void * file_ptr) { ret = vfs_getattr(filp->f_path.mnt, filp->f_path.dentry, &s); if (ret != 0) { - printk("Failed to fstat file\n"); + ERROR("Failed to fstat file\n"); return -1; } return s.size; } -static long long palacios_file_read(void * file_ptr, void * buffer, long long length, long long offset){ +static unsigned long long palacios_file_read(void * file_ptr, void * buffer, unsigned long long length, unsigned long long offset){ struct palacios_file * pfile = (struct palacios_file *)file_ptr; struct file * filp = pfile->filp; ssize_t ret; @@ -270,14 +273,14 @@ static long long palacios_file_read(void * file_ptr, void * buffer, long long le set_fs(old_fs); if (ret <= 0) { - printk("sys_read of %p for %lld bytes failed\n", filp, length); + ERROR("sys_read of %p for %lld bytes at offset %llu failed (ret=%ld)\n", filp, length, offset, ret); } return ret; } -static long long palacios_file_write(void * file_ptr, void * buffer, long long length, long long offset) { +static unsigned long long palacios_file_write(void * file_ptr, void * buffer, unsigned long long length, unsigned long long offset) { struct palacios_file * pfile = (struct palacios_file *)file_ptr; struct file * filp = pfile->filp; mm_segment_t old_fs; @@ -292,7 +295,7 @@ static long long palacios_file_write(void * file_ptr, void * buffer, long long l if (ret <= 0) { - printk("sys_write failed\n"); + ERROR("sys_write for %llu bytes at offset %llu failed (ret=%ld)\n", length, offset, ret); } return ret; @@ -321,7 +324,7 @@ static int file_init( void ) { static int file_deinit( void ) { if (!list_empty(&(global_files))) { - printk("Error removing module with open files\n"); + ERROR("Error removing module with open files\n"); } return 0; @@ -341,6 +344,7 @@ static int guest_file_init(struct v3_guest * guest, void ** vm_data) { static int guest_file_deinit(struct v3_guest * guest, void * vm_data) { + kfree(vm_data); return 0; }