blob: 6248f0e727a395fc1a03bfe6bb9d3aea7924f49f [file] [log] [blame]
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -08001/*
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 Hensbergen42e8c502006-03-25 03:07:28 -080010 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080012 *
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 Hensbergen147b31c2006-01-18 17:43:02 -080032#include <linux/inet.h>
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080033#include <linux/pagemap.h>
34#include <linux/idr.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040035#include <linux/sched.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050036#include <net/9p/9p.h>
37#include <net/9p/client.h>
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080038
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080039#include "v9fs.h"
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080040#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
51static int v9fs_vfs_readpage(struct file *filp, struct page *page)
52{
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050053 int retval;
54 loff_t offset;
55 char *buffer;
56 struct p9_fid *fid;
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080057
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050058 P9_DPRINTK(P9_DEBUG_VFS, "\n");
59 fid = filp->private_data;
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080060 buffer = kmap(page);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050061 offset = page_offset(page);
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080062
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050063 retval = p9_client_readn(fid, buffer, offset, PAGE_CACHE_SIZE);
64 if (retval < 0)
65 goto done;
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080066
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050067 memset(buffer + retval, 0, PAGE_CACHE_SIZE - retval);
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080068 flush_dcache_page(page);
69 SetPageUptodate(page);
70 retval = 0;
71
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050072done:
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080073 kunmap(page);
74 unlock_page(page);
75 return retval;
76}
77
Christoph Hellwigf5e54d62006-06-28 04:26:44 -070078const struct address_space_operations v9fs_addr_operations = {
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080079 .readpage = v9fs_vfs_readpage,
80};