Eric Van Hensbergen | 147b31c | 2006-01-18 17:43:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/9p/vfs_addr.c |
| 3 | * |
| 4 | * This file contians vfs address (mmap) ops for 9P2000. |
| 5 | * |
| 6 | * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com> |
| 7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Eric Van Hensbergen | 42e8c50 | 2006-03-25 03:07:28 -0800 | [diff] [blame] | 10 | * it under the terms of the GNU General Public License version 2 |
| 11 | * as published by the Free Software Foundation. |
Eric Van Hensbergen | 147b31c | 2006-01-18 17:43:02 -0800 | [diff] [blame] | 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to: |
| 20 | * Free Software Foundation |
| 21 | * 51 Franklin Street, Fifth Floor |
| 22 | * Boston, MA 02111-1301 USA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/file.h> |
| 30 | #include <linux/stat.h> |
| 31 | #include <linux/string.h> |
Eric Van Hensbergen | 147b31c | 2006-01-18 17:43:02 -0800 | [diff] [blame] | 32 | #include <linux/inet.h> |
Eric Van Hensbergen | 147b31c | 2006-01-18 17:43:02 -0800 | [diff] [blame] | 33 | #include <linux/pagemap.h> |
| 34 | #include <linux/idr.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame^] | 35 | #include <linux/sched.h> |
Eric Van Hensbergen | 147b31c | 2006-01-18 17:43:02 -0800 | [diff] [blame] | 36 | |
| 37 | #include "debug.h" |
| 38 | #include "v9fs.h" |
| 39 | #include "9p.h" |
| 40 | #include "v9fs_vfs.h" |
| 41 | #include "fid.h" |
| 42 | |
| 43 | /** |
| 44 | * v9fs_vfs_readpage - read an entire page in from 9P |
| 45 | * |
| 46 | * @file: file being read |
| 47 | * @page: structure to page |
| 48 | * |
| 49 | */ |
| 50 | |
| 51 | static int v9fs_vfs_readpage(struct file *filp, struct page *page) |
| 52 | { |
| 53 | char *buffer = NULL; |
| 54 | int retval = -EIO; |
| 55 | loff_t offset = page_offset(page); |
| 56 | int count = PAGE_CACHE_SIZE; |
Josef "Jeff" Sipek | d6f787b | 2006-12-08 02:36:45 -0800 | [diff] [blame] | 57 | struct inode *inode = filp->f_path.dentry->d_inode; |
Eric Van Hensbergen | 147b31c | 2006-01-18 17:43:02 -0800 | [diff] [blame] | 58 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); |
| 59 | int rsize = v9ses->maxdata - V9FS_IOHDRSZ; |
| 60 | struct v9fs_fid *v9f = filp->private_data; |
| 61 | struct v9fs_fcall *fcall = NULL; |
| 62 | int fid = v9f->fid; |
| 63 | int total = 0; |
| 64 | int result = 0; |
| 65 | |
Eric Van Hensbergen | e03abc0 | 2007-02-11 13:21:39 -0600 | [diff] [blame] | 66 | dprintk(DEBUG_VFS, "\n"); |
| 67 | |
Eric Van Hensbergen | 147b31c | 2006-01-18 17:43:02 -0800 | [diff] [blame] | 68 | buffer = kmap(page); |
| 69 | do { |
| 70 | if (count < rsize) |
| 71 | rsize = count; |
| 72 | |
| 73 | result = v9fs_t_read(v9ses, fid, offset, rsize, &fcall); |
| 74 | |
| 75 | if (result < 0) { |
| 76 | printk(KERN_ERR "v9fs_t_read returned %d\n", |
| 77 | result); |
| 78 | |
| 79 | kfree(fcall); |
| 80 | goto UnmapAndUnlock; |
| 81 | } else |
| 82 | offset += result; |
| 83 | |
| 84 | memcpy(buffer, fcall->params.rread.data, result); |
| 85 | |
| 86 | count -= result; |
| 87 | buffer += result; |
| 88 | total += result; |
| 89 | |
| 90 | kfree(fcall); |
| 91 | |
| 92 | if (result < rsize) |
| 93 | break; |
| 94 | } while (count); |
| 95 | |
| 96 | memset(buffer, 0, count); |
| 97 | flush_dcache_page(page); |
| 98 | SetPageUptodate(page); |
| 99 | retval = 0; |
| 100 | |
| 101 | UnmapAndUnlock: |
| 102 | kunmap(page); |
| 103 | unlock_page(page); |
| 104 | return retval; |
| 105 | } |
| 106 | |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 107 | const struct address_space_operations v9fs_addr_operations = { |
Eric Van Hensbergen | 147b31c | 2006-01-18 17:43:02 -0800 | [diff] [blame] | 108 | .readpage = v9fs_vfs_readpage, |
| 109 | }; |