blob: 90e38449f4b3a7dd0ab5c642e63bc504eb5adaef [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"
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050041#include "cache.h"
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080042
43/**
44 * v9fs_vfs_readpage - read an entire page in from 9P
45 *
Eric Van Hensbergenee443992008-03-05 07:08:09 -060046 * @filp: file being read
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080047 * @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;
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050056 struct inode *inode;
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080057
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050058 inode = page->mapping->host;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050059 P9_DPRINTK(P9_DEBUG_VFS, "\n");
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050060
61 BUG_ON(!PageLocked(page));
62
63 retval = v9fs_readpage_from_fscache(inode, page);
64 if (retval == 0)
65 return retval;
66
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080067 buffer = kmap(page);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050068 offset = page_offset(page);
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080069
Abhishek Kulkarni9c9ad612009-07-14 13:26:52 -050070 retval = v9fs_file_readn(filp, buffer, NULL, PAGE_CACHE_SIZE, offset);
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050071 if (retval < 0) {
72 v9fs_uncache_page(inode, page);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050073 goto done;
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050074 }
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080075
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050076 memset(buffer + retval, 0, PAGE_CACHE_SIZE - retval);
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080077 flush_dcache_page(page);
78 SetPageUptodate(page);
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050079
80 v9fs_readpage_to_fscache(inode, page);
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080081 retval = 0;
82
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050083done:
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -080084 kunmap(page);
85 unlock_page(page);
86 return retval;
87}
88
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050089/**
90 * v9fs_vfs_readpages - read a set of pages from 9P
91 *
92 * @filp: file being read
93 * @mapping: the address space
94 * @pages: list of pages to read
95 * @nr_pages: count of pages to read
96 *
97 */
98
99static int v9fs_vfs_readpages(struct file *filp, struct address_space *mapping,
100 struct list_head *pages, unsigned nr_pages)
101{
102 int ret = 0;
103 struct inode *inode;
104
105 inode = mapping->host;
106 P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, filp);
107
108 ret = v9fs_readpages_from_fscache(inode, mapping, pages, &nr_pages);
109 if (ret == 0)
110 return ret;
111
112 ret = read_cache_pages(mapping, pages, (void *)v9fs_vfs_readpage, filp);
113 P9_DPRINTK(P9_DEBUG_VFS, " = %d\n", ret);
114 return ret;
115}
116
117/**
118 * v9fs_release_page - release the private state associated with a page
119 *
120 * Returns 1 if the page can be released, false otherwise.
121 */
122
123static int v9fs_release_page(struct page *page, gfp_t gfp)
124{
125 if (PagePrivate(page))
126 return 0;
127
128 return v9fs_fscache_release_page(page, gfp);
129}
130
131/**
132 * v9fs_invalidate_page - Invalidate a page completely or partially
133 *
134 * @page: structure to page
135 * @offset: offset in the page
136 */
137
138static void v9fs_invalidate_page(struct page *page, unsigned long offset)
139{
140 if (offset == 0)
141 v9fs_fscache_invalidate_page(page);
142}
143
144/**
145 * v9fs_launder_page - Writeback a dirty page
146 * Since the writes go directly to the server, we simply return a 0
147 * here to indicate success.
148 *
149 * Returns 0 on success.
150 */
151
152static int v9fs_launder_page(struct page *page)
153{
154 return 0;
155}
156
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700157const struct address_space_operations v9fs_addr_operations = {
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -0800158 .readpage = v9fs_vfs_readpage,
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500159 .readpages = v9fs_vfs_readpages,
160 .releasepage = v9fs_release_page,
161 .invalidatepage = v9fs_invalidate_page,
162 .launder_page = v9fs_launder_page,
Eric Van Hensbergen147b31c2006-01-18 17:43:02 -0800163};