ia64/linux-2.6.18-xen.hg

view fs/afs/file.c @ 524:7f8b544237bf

netfront: Allow netfront in domain 0.

This is useful if your physical network device is in a utility domain.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 15 15:18:58 2008 +0100 (2008-04-15)
parents 831230e53067
children
line source
1 /* file.c: AFS filesystem file handling
2 *
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/sched.h>
16 #include <linux/slab.h>
17 #include <linux/fs.h>
18 #include <linux/pagemap.h>
19 #include <linux/buffer_head.h>
20 #include "volume.h"
21 #include "vnode.h"
22 #include <rxrpc/call.h>
23 #include "internal.h"
25 #if 0
26 static int afs_file_open(struct inode *inode, struct file *file);
27 static int afs_file_release(struct inode *inode, struct file *file);
28 #endif
30 static int afs_file_readpage(struct file *file, struct page *page);
31 static void afs_file_invalidatepage(struct page *page, unsigned long offset);
32 static int afs_file_releasepage(struct page *page, gfp_t gfp_flags);
34 struct inode_operations afs_file_inode_operations = {
35 .getattr = afs_inode_getattr,
36 };
38 const struct address_space_operations afs_fs_aops = {
39 .readpage = afs_file_readpage,
40 .sync_page = block_sync_page,
41 .set_page_dirty = __set_page_dirty_nobuffers,
42 .releasepage = afs_file_releasepage,
43 .invalidatepage = afs_file_invalidatepage,
44 };
46 /*****************************************************************************/
47 /*
48 * deal with notification that a page was read from the cache
49 */
50 #ifdef AFS_CACHING_SUPPORT
51 static void afs_file_readpage_read_complete(void *cookie_data,
52 struct page *page,
53 void *data,
54 int error)
55 {
56 _enter("%p,%p,%p,%d", cookie_data, page, data, error);
58 if (error)
59 SetPageError(page);
60 else
61 SetPageUptodate(page);
62 unlock_page(page);
64 } /* end afs_file_readpage_read_complete() */
65 #endif
67 /*****************************************************************************/
68 /*
69 * deal with notification that a page was written to the cache
70 */
71 #ifdef AFS_CACHING_SUPPORT
72 static void afs_file_readpage_write_complete(void *cookie_data,
73 struct page *page,
74 void *data,
75 int error)
76 {
77 _enter("%p,%p,%p,%d", cookie_data, page, data, error);
79 unlock_page(page);
81 } /* end afs_file_readpage_write_complete() */
82 #endif
84 /*****************************************************************************/
85 /*
86 * AFS read page from file (or symlink)
87 */
88 static int afs_file_readpage(struct file *file, struct page *page)
89 {
90 struct afs_rxfs_fetch_descriptor desc;
91 #ifdef AFS_CACHING_SUPPORT
92 struct cachefs_page *pageio;
93 #endif
94 struct afs_vnode *vnode;
95 struct inode *inode;
96 int ret;
98 inode = page->mapping->host;
100 _enter("{%lu},{%lu}", inode->i_ino, page->index);
102 vnode = AFS_FS_I(inode);
104 BUG_ON(!PageLocked(page));
106 ret = -ESTALE;
107 if (vnode->flags & AFS_VNODE_DELETED)
108 goto error;
110 #ifdef AFS_CACHING_SUPPORT
111 ret = cachefs_page_get_private(page, &pageio, GFP_NOIO);
112 if (ret < 0)
113 goto error;
115 /* is it cached? */
116 ret = cachefs_read_or_alloc_page(vnode->cache,
117 page,
118 afs_file_readpage_read_complete,
119 NULL,
120 GFP_KERNEL);
121 #else
122 ret = -ENOBUFS;
123 #endif
125 switch (ret) {
126 /* read BIO submitted and wb-journal entry found */
127 case 1:
128 BUG(); // TODO - handle wb-journal match
130 /* read BIO submitted (page in cache) */
131 case 0:
132 break;
134 /* no page available in cache */
135 case -ENOBUFS:
136 case -ENODATA:
137 default:
138 desc.fid = vnode->fid;
139 desc.offset = page->index << PAGE_CACHE_SHIFT;
140 desc.size = min((size_t) (inode->i_size - desc.offset),
141 (size_t) PAGE_SIZE);
142 desc.buffer = kmap(page);
144 clear_page(desc.buffer);
146 /* read the contents of the file from the server into the
147 * page */
148 ret = afs_vnode_fetch_data(vnode, &desc);
149 kunmap(page);
150 if (ret < 0) {
151 if (ret==-ENOENT) {
152 _debug("got NOENT from server"
153 " - marking file deleted and stale");
154 vnode->flags |= AFS_VNODE_DELETED;
155 ret = -ESTALE;
156 }
158 #ifdef AFS_CACHING_SUPPORT
159 cachefs_uncache_page(vnode->cache, page);
160 #endif
161 goto error;
162 }
164 SetPageUptodate(page);
166 #ifdef AFS_CACHING_SUPPORT
167 if (cachefs_write_page(vnode->cache,
168 page,
169 afs_file_readpage_write_complete,
170 NULL,
171 GFP_KERNEL) != 0
172 ) {
173 cachefs_uncache_page(vnode->cache, page);
174 unlock_page(page);
175 }
176 #else
177 unlock_page(page);
178 #endif
179 }
181 _leave(" = 0");
182 return 0;
184 error:
185 SetPageError(page);
186 unlock_page(page);
188 _leave(" = %d", ret);
189 return ret;
191 } /* end afs_file_readpage() */
193 /*****************************************************************************/
194 /*
195 * get a page cookie for the specified page
196 */
197 #ifdef AFS_CACHING_SUPPORT
198 int afs_cache_get_page_cookie(struct page *page,
199 struct cachefs_page **_page_cookie)
200 {
201 int ret;
203 _enter("");
204 ret = cachefs_page_get_private(page,_page_cookie, GFP_NOIO);
206 _leave(" = %d", ret);
207 return ret;
208 } /* end afs_cache_get_page_cookie() */
209 #endif
211 /*****************************************************************************/
212 /*
213 * invalidate part or all of a page
214 */
215 static void afs_file_invalidatepage(struct page *page, unsigned long offset)
216 {
217 int ret = 1;
219 _enter("{%lu},%lu", page->index, offset);
221 BUG_ON(!PageLocked(page));
223 if (PagePrivate(page)) {
224 #ifdef AFS_CACHING_SUPPORT
225 struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
226 cachefs_uncache_page(vnode->cache,page);
227 #endif
229 /* We release buffers only if the entire page is being
230 * invalidated.
231 * The get_block cached value has been unconditionally
232 * invalidated, so real IO is not possible anymore.
233 */
234 if (offset == 0) {
235 BUG_ON(!PageLocked(page));
237 ret = 0;
238 if (!PageWriteback(page))
239 ret = page->mapping->a_ops->releasepage(page,
240 0);
241 /* possibly should BUG_ON(!ret); - neilb */
242 }
243 }
245 _leave(" = %d", ret);
246 } /* end afs_file_invalidatepage() */
248 /*****************************************************************************/
249 /*
250 * release a page and cleanup its private data
251 */
252 static int afs_file_releasepage(struct page *page, gfp_t gfp_flags)
253 {
254 struct cachefs_page *pageio;
256 _enter("{%lu},%x", page->index, gfp_flags);
258 if (PagePrivate(page)) {
259 #ifdef AFS_CACHING_SUPPORT
260 struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
261 cachefs_uncache_page(vnode->cache, page);
262 #endif
264 pageio = (struct cachefs_page *) page_private(page);
265 set_page_private(page, 0);
266 ClearPagePrivate(page);
268 kfree(pageio);
269 }
271 _leave(" = 0");
272 return 0;
273 } /* end afs_file_releasepage() */