[PATCH] v9fs: print 9p messages
[safe/jmp/linux-2.6] / fs / 9p / vfs_addr.c
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
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to:
21  *  Free Software Foundation
22  *  51 Franklin Street, Fifth Floor
23  *  Boston, MA  02111-1301  USA
24  *
25  */
26
27 #include <linux/module.h>
28 #include <linux/errno.h>
29 #include <linux/fs.h>
30 #include <linux/file.h>
31 #include <linux/stat.h>
32 #include <linux/string.h>
33 #include <linux/smp_lock.h>
34 #include <linux/inet.h>
35 #include <linux/version.h>
36 #include <linux/pagemap.h>
37 #include <linux/idr.h>
38
39 #include "debug.h"
40 #include "v9fs.h"
41 #include "9p.h"
42 #include "v9fs_vfs.h"
43 #include "fid.h"
44
45 /**
46  * v9fs_vfs_readpage - read an entire page in from 9P
47  *
48  * @file: file being read
49  * @page: structure to page
50  *
51  */
52
53 static int v9fs_vfs_readpage(struct file *filp, struct page *page)
54 {
55         char *buffer = NULL;
56         int retval = -EIO;
57         loff_t offset = page_offset(page);
58         int count = PAGE_CACHE_SIZE;
59         struct inode *inode = filp->f_dentry->d_inode;
60         struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
61         int rsize = v9ses->maxdata - V9FS_IOHDRSZ;
62         struct v9fs_fid *v9f = filp->private_data;
63         struct v9fs_fcall *fcall = NULL;
64         int fid = v9f->fid;
65         int total = 0;
66         int result = 0;
67
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
107 struct address_space_operations v9fs_addr_operations = {
108       .readpage = v9fs_vfs_readpage,
109 };