2007-04-26 22:55:03 +00:00
|
|
|
/* AFS filesystem file handling
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2007-04-26 22:55:03 +00:00
|
|
|
* Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
|
2005-04-16 22:20:36 +00:00
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/pagemap.h>
|
AFS: implement basic file write support
Implement support for writing to regular AFS files, including:
(1) write
(2) truncate
(3) fsync, fdatasync
(4) chmod, chown, chgrp, utime.
AFS writeback attempts to batch writes into as chunks as large as it can manage
up to the point that it writes back 65535 pages in one chunk or it meets a
locked page.
Furthermore, if a page has been written to using a particular key, then should
another write to that page use some other key, the first write will be flushed
before the second is allowed to take place. If the first write fails due to a
security error, then the page will be scrapped and reread before the second
write takes place.
If a page is dirty and the callback on it is broken by the server, then the
dirty data is not discarded (same behaviour as NFS).
Shared-writable mappings are not supported by this patch.
[akpm@linux-foundation.org: fix a bunch of warnings]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-09 09:33:46 +00:00
|
|
|
#include <linux/writeback.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/gfp.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
2007-05-09 09:33:45 +00:00
|
|
|
static int afs_readpage(struct file *file, struct page *page);
|
2013-05-22 03:17:23 +00:00
|
|
|
static void afs_invalidatepage(struct page *page, unsigned int offset,
|
|
|
|
unsigned int length);
|
2007-05-09 09:33:45 +00:00
|
|
|
static int afs_releasepage(struct page *page, gfp_t gfp_flags);
|
AFS: implement basic file write support
Implement support for writing to regular AFS files, including:
(1) write
(2) truncate
(3) fsync, fdatasync
(4) chmod, chown, chgrp, utime.
AFS writeback attempts to batch writes into as chunks as large as it can manage
up to the point that it writes back 65535 pages in one chunk or it meets a
locked page.
Furthermore, if a page has been written to using a particular key, then should
another write to that page use some other key, the first write will be flushed
before the second is allowed to take place. If the first write fails due to a
security error, then the page will be scrapped and reread before the second
write takes place.
If a page is dirty and the callback on it is broken by the server, then the
dirty data is not discarded (same behaviour as NFS).
Shared-writable mappings are not supported by this patch.
[akpm@linux-foundation.org: fix a bunch of warnings]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-09 09:33:46 +00:00
|
|
|
static int afs_launder_page(struct page *page);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
static int afs_readpages(struct file *filp, struct address_space *mapping,
|
|
|
|
struct list_head *pages, unsigned nr_pages);
|
|
|
|
|
2007-04-26 22:57:07 +00:00
|
|
|
const struct file_operations afs_file_operations = {
|
|
|
|
.open = afs_open,
|
|
|
|
.release = afs_release,
|
|
|
|
.llseek = generic_file_llseek,
|
2014-04-02 18:33:16 +00:00
|
|
|
.read_iter = generic_file_read_iter,
|
2014-04-03 18:13:46 +00:00
|
|
|
.write_iter = afs_file_write,
|
2007-04-26 22:57:07 +00:00
|
|
|
.mmap = generic_file_readonly_mmap,
|
2007-06-01 09:49:19 +00:00
|
|
|
.splice_read = generic_file_splice_read,
|
AFS: implement basic file write support
Implement support for writing to regular AFS files, including:
(1) write
(2) truncate
(3) fsync, fdatasync
(4) chmod, chown, chgrp, utime.
AFS writeback attempts to batch writes into as chunks as large as it can manage
up to the point that it writes back 65535 pages in one chunk or it meets a
locked page.
Furthermore, if a page has been written to using a particular key, then should
another write to that page use some other key, the first write will be flushed
before the second is allowed to take place. If the first write fails due to a
security error, then the page will be scrapped and reread before the second
write takes place.
If a page is dirty and the callback on it is broken by the server, then the
dirty data is not discarded (same behaviour as NFS).
Shared-writable mappings are not supported by this patch.
[akpm@linux-foundation.org: fix a bunch of warnings]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-09 09:33:46 +00:00
|
|
|
.fsync = afs_fsync,
|
2007-07-16 06:40:12 +00:00
|
|
|
.lock = afs_lock,
|
|
|
|
.flock = afs_flock,
|
2007-04-26 22:57:07 +00:00
|
|
|
};
|
|
|
|
|
2007-02-12 08:55:38 +00:00
|
|
|
const struct inode_operations afs_file_inode_operations = {
|
2007-05-09 09:33:45 +00:00
|
|
|
.getattr = afs_getattr,
|
AFS: implement basic file write support
Implement support for writing to regular AFS files, including:
(1) write
(2) truncate
(3) fsync, fdatasync
(4) chmod, chown, chgrp, utime.
AFS writeback attempts to batch writes into as chunks as large as it can manage
up to the point that it writes back 65535 pages in one chunk or it meets a
locked page.
Furthermore, if a page has been written to using a particular key, then should
another write to that page use some other key, the first write will be flushed
before the second is allowed to take place. If the first write fails due to a
security error, then the page will be scrapped and reread before the second
write takes place.
If a page is dirty and the callback on it is broken by the server, then the
dirty data is not discarded (same behaviour as NFS).
Shared-writable mappings are not supported by this patch.
[akpm@linux-foundation.org: fix a bunch of warnings]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-09 09:33:46 +00:00
|
|
|
.setattr = afs_setattr,
|
2007-04-26 22:57:07 +00:00
|
|
|
.permission = afs_permission,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2006-06-28 11:26:44 +00:00
|
|
|
const struct address_space_operations afs_fs_aops = {
|
2007-05-09 09:33:45 +00:00
|
|
|
.readpage = afs_readpage,
|
2009-04-03 15:42:41 +00:00
|
|
|
.readpages = afs_readpages,
|
AFS: implement basic file write support
Implement support for writing to regular AFS files, including:
(1) write
(2) truncate
(3) fsync, fdatasync
(4) chmod, chown, chgrp, utime.
AFS writeback attempts to batch writes into as chunks as large as it can manage
up to the point that it writes back 65535 pages in one chunk or it meets a
locked page.
Furthermore, if a page has been written to using a particular key, then should
another write to that page use some other key, the first write will be flushed
before the second is allowed to take place. If the first write fails due to a
security error, then the page will be scrapped and reread before the second
write takes place.
If a page is dirty and the callback on it is broken by the server, then the
dirty data is not discarded (same behaviour as NFS).
Shared-writable mappings are not supported by this patch.
[akpm@linux-foundation.org: fix a bunch of warnings]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-09 09:33:46 +00:00
|
|
|
.set_page_dirty = afs_set_page_dirty,
|
|
|
|
.launder_page = afs_launder_page,
|
2007-05-09 09:33:45 +00:00
|
|
|
.releasepage = afs_releasepage,
|
|
|
|
.invalidatepage = afs_invalidatepage,
|
2008-10-16 05:04:32 +00:00
|
|
|
.write_begin = afs_write_begin,
|
|
|
|
.write_end = afs_write_end,
|
AFS: implement basic file write support
Implement support for writing to regular AFS files, including:
(1) write
(2) truncate
(3) fsync, fdatasync
(4) chmod, chown, chgrp, utime.
AFS writeback attempts to batch writes into as chunks as large as it can manage
up to the point that it writes back 65535 pages in one chunk or it meets a
locked page.
Furthermore, if a page has been written to using a particular key, then should
another write to that page use some other key, the first write will be flushed
before the second is allowed to take place. If the first write fails due to a
security error, then the page will be scrapped and reread before the second
write takes place.
If a page is dirty and the callback on it is broken by the server, then the
dirty data is not discarded (same behaviour as NFS).
Shared-writable mappings are not supported by this patch.
[akpm@linux-foundation.org: fix a bunch of warnings]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-09 09:33:46 +00:00
|
|
|
.writepage = afs_writepage,
|
|
|
|
.writepages = afs_writepages,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2007-04-26 22:57:07 +00:00
|
|
|
/*
|
|
|
|
* open an AFS file or directory and attach a key to it
|
|
|
|
*/
|
|
|
|
int afs_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct afs_vnode *vnode = AFS_FS_I(inode);
|
|
|
|
struct key *key;
|
2007-04-26 22:59:35 +00:00
|
|
|
int ret;
|
2007-04-26 22:57:07 +00:00
|
|
|
|
2007-05-09 09:33:45 +00:00
|
|
|
_enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
|
2007-04-26 22:57:07 +00:00
|
|
|
|
|
|
|
key = afs_request_key(vnode->volume->cell);
|
|
|
|
if (IS_ERR(key)) {
|
|
|
|
_leave(" = %ld [key]", PTR_ERR(key));
|
|
|
|
return PTR_ERR(key);
|
|
|
|
}
|
|
|
|
|
2007-04-26 22:59:35 +00:00
|
|
|
ret = afs_validate(vnode, key);
|
|
|
|
if (ret < 0) {
|
|
|
|
_leave(" = %d [val]", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-04-26 22:57:07 +00:00
|
|
|
file->private_data = key;
|
|
|
|
_leave(" = 0");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* release an AFS file or directory and discard its key
|
|
|
|
*/
|
|
|
|
int afs_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct afs_vnode *vnode = AFS_FS_I(inode);
|
|
|
|
|
2007-05-09 09:33:45 +00:00
|
|
|
_enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
|
2007-04-26 22:57:07 +00:00
|
|
|
|
|
|
|
key_put(file->private_data);
|
|
|
|
_leave(" = 0");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-17 11:56:38 +00:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* deal with notification that a page was read from the cache
|
|
|
|
*/
|
2009-04-03 15:42:41 +00:00
|
|
|
static void afs_file_readpage_read_complete(struct page *page,
|
|
|
|
void *data,
|
|
|
|
int error)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-04-03 15:42:41 +00:00
|
|
|
_enter("%p,%p,%d", page, data, error);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/* if the read completes with an error, we just unlock the page and let
|
|
|
|
* the VM reissue the readpage */
|
|
|
|
if (!error)
|
2005-04-16 22:20:36 +00:00
|
|
|
SetPageUptodate(page);
|
|
|
|
unlock_page(page);
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|
2009-04-17 11:56:38 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
2010-05-21 14:27:09 +00:00
|
|
|
* read page from file, directory or symlink, given a key to use
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2010-05-21 14:27:09 +00:00
|
|
|
int afs_page_filler(void *data, struct page *page)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2010-05-21 14:27:09 +00:00
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
struct afs_vnode *vnode = AFS_FS_I(inode);
|
|
|
|
struct key *key = data;
|
2007-04-26 22:55:03 +00:00
|
|
|
size_t len;
|
|
|
|
off_t offset;
|
2005-04-16 22:20:36 +00:00
|
|
|
int ret;
|
|
|
|
|
2007-04-26 22:57:07 +00:00
|
|
|
_enter("{%x},{%lu},{%lu}", key_serial(key), inode->i_ino, page->index);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-05-01 15:59:01 +00:00
|
|
|
BUG_ON(!PageLocked(page));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
ret = -ESTALE;
|
2007-04-26 22:55:03 +00:00
|
|
|
if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* is it cached? */
|
2009-04-03 15:42:41 +00:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
ret = fscache_read_or_alloc_page(vnode->cache,
|
2005-04-16 22:20:36 +00:00
|
|
|
page,
|
|
|
|
afs_file_readpage_read_complete,
|
|
|
|
NULL,
|
|
|
|
GFP_KERNEL);
|
|
|
|
#else
|
|
|
|
ret = -ENOBUFS;
|
|
|
|
#endif
|
|
|
|
switch (ret) {
|
|
|
|
/* read BIO submitted (page in cache) */
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/* page not yet cached */
|
2005-04-16 22:20:36 +00:00
|
|
|
case -ENODATA:
|
2009-04-03 15:42:41 +00:00
|
|
|
_debug("cache said ENODATA");
|
|
|
|
goto go_on;
|
|
|
|
|
|
|
|
/* page will not be cached */
|
|
|
|
case -ENOBUFS:
|
|
|
|
_debug("cache said ENOBUFS");
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
2009-04-03 15:42:41 +00:00
|
|
|
go_on:
|
2007-04-26 22:55:03 +00:00
|
|
|
offset = page->index << PAGE_CACHE_SHIFT;
|
|
|
|
len = min_t(size_t, i_size_read(inode) - offset, PAGE_SIZE);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* read the contents of the file from the server into the
|
|
|
|
* page */
|
2007-04-26 22:57:07 +00:00
|
|
|
ret = afs_vnode_fetch_data(vnode, key, offset, len, page);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ret < 0) {
|
2007-04-26 22:55:03 +00:00
|
|
|
if (ret == -ENOENT) {
|
2005-04-16 22:20:36 +00:00
|
|
|
_debug("got NOENT from server"
|
|
|
|
" - marking file deleted and stale");
|
2007-04-26 22:55:03 +00:00
|
|
|
set_bit(AFS_VNODE_DELETED, &vnode->flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = -ESTALE;
|
|
|
|
}
|
2009-04-03 15:42:41 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
fscache_uncache_page(vnode->cache, page);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
2009-04-03 15:42:41 +00:00
|
|
|
BUG_ON(PageFsCache(page));
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetPageUptodate(page);
|
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/* send the page to the cache */
|
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
if (PageFsCache(page) &&
|
|
|
|
fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
|
|
|
|
fscache_uncache_page(vnode->cache, page);
|
|
|
|
BUG_ON(PageFsCache(page));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-04-03 15:42:41 +00:00
|
|
|
unlock_page(page);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_leave(" = 0");
|
|
|
|
return 0;
|
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
error:
|
2005-04-16 22:20:36 +00:00
|
|
|
SetPageError(page);
|
|
|
|
unlock_page(page);
|
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ret;
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-05-21 14:27:09 +00:00
|
|
|
/*
|
|
|
|
* read page from file, directory or symlink, given a file to nominate the key
|
|
|
|
* to be used
|
|
|
|
*/
|
|
|
|
static int afs_readpage(struct file *file, struct page *page)
|
|
|
|
{
|
|
|
|
struct key *key;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
key = file->private_data;
|
|
|
|
ASSERT(key != NULL);
|
|
|
|
ret = afs_page_filler(key, page);
|
|
|
|
} else {
|
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
key = afs_request_key(AFS_FS_S(inode->i_sb)->volume->cell);
|
|
|
|
if (IS_ERR(key)) {
|
|
|
|
ret = PTR_ERR(key);
|
|
|
|
} else {
|
|
|
|
ret = afs_page_filler(key, page);
|
|
|
|
key_put(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2009-04-03 15:42:41 +00:00
|
|
|
* read a set of pages
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2009-04-03 15:42:41 +00:00
|
|
|
static int afs_readpages(struct file *file, struct address_space *mapping,
|
|
|
|
struct list_head *pages, unsigned nr_pages)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2010-05-21 14:27:09 +00:00
|
|
|
struct key *key = file->private_data;
|
2009-04-03 15:42:41 +00:00
|
|
|
struct afs_vnode *vnode;
|
|
|
|
int ret = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-05-21 14:27:09 +00:00
|
|
|
_enter("{%d},{%lu},,%d",
|
|
|
|
key_serial(key), mapping->host->i_ino, nr_pages);
|
|
|
|
|
|
|
|
ASSERT(key != NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
vnode = AFS_FS_I(mapping->host);
|
2012-03-20 16:58:06 +00:00
|
|
|
if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
|
2009-04-03 15:42:41 +00:00
|
|
|
_leave(" = -ESTALE");
|
|
|
|
return -ESTALE;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/* attempt to read as many of the pages as possible */
|
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
ret = fscache_read_or_alloc_pages(vnode->cache,
|
|
|
|
mapping,
|
|
|
|
pages,
|
|
|
|
&nr_pages,
|
|
|
|
afs_file_readpage_read_complete,
|
|
|
|
NULL,
|
|
|
|
mapping_gfp_mask(mapping));
|
|
|
|
#else
|
|
|
|
ret = -ENOBUFS;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
/* all pages are being read from the cache */
|
|
|
|
case 0:
|
|
|
|
BUG_ON(!list_empty(pages));
|
|
|
|
BUG_ON(nr_pages != 0);
|
|
|
|
_leave(" = 0 [reading all]");
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* there were pages that couldn't be read from the cache */
|
|
|
|
case -ENODATA:
|
|
|
|
case -ENOBUFS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* other error */
|
|
|
|
default:
|
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/* load the missing pages from the network */
|
2010-05-21 14:27:09 +00:00
|
|
|
ret = read_cache_pages(mapping, pages, afs_page_filler, key);
|
2009-04-03 15:42:41 +00:00
|
|
|
|
|
|
|
_leave(" = %d [netting]", ret);
|
|
|
|
return ret;
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
AFS: implement basic file write support
Implement support for writing to regular AFS files, including:
(1) write
(2) truncate
(3) fsync, fdatasync
(4) chmod, chown, chgrp, utime.
AFS writeback attempts to batch writes into as chunks as large as it can manage
up to the point that it writes back 65535 pages in one chunk or it meets a
locked page.
Furthermore, if a page has been written to using a particular key, then should
another write to that page use some other key, the first write will be flushed
before the second is allowed to take place. If the first write fails due to a
security error, then the page will be scrapped and reread before the second
write takes place.
If a page is dirty and the callback on it is broken by the server, then the
dirty data is not discarded (same behaviour as NFS).
Shared-writable mappings are not supported by this patch.
[akpm@linux-foundation.org: fix a bunch of warnings]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-09 09:33:46 +00:00
|
|
|
/*
|
|
|
|
* write back a dirty page
|
|
|
|
*/
|
|
|
|
static int afs_launder_page(struct page *page)
|
|
|
|
{
|
|
|
|
_enter("{%lu}", page->index);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2009-04-03 15:42:41 +00:00
|
|
|
* invalidate part or all of a page
|
|
|
|
* - release a page and clean up its private data if offset is 0 (indicating
|
|
|
|
* the entire page)
|
|
|
|
*/
|
2013-05-22 03:17:23 +00:00
|
|
|
static void afs_invalidatepage(struct page *page, unsigned int offset,
|
|
|
|
unsigned int length)
|
2009-04-03 15:42:41 +00:00
|
|
|
{
|
|
|
|
struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
|
|
|
|
|
2013-05-22 03:17:23 +00:00
|
|
|
_enter("{%lu},%u,%u", page->index, offset, length);
|
2009-04-03 15:42:41 +00:00
|
|
|
|
|
|
|
BUG_ON(!PageLocked(page));
|
|
|
|
|
|
|
|
/* we clean up only if the entire page is being invalidated */
|
2013-05-22 03:17:23 +00:00
|
|
|
if (offset == 0 && length == PAGE_CACHE_SIZE) {
|
2009-04-03 15:42:41 +00:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
if (PageFsCache(page)) {
|
|
|
|
struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
|
|
|
|
fscache_wait_on_page_write(vnode->cache, page);
|
|
|
|
fscache_uncache_page(vnode->cache, page);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (PagePrivate(page)) {
|
|
|
|
if (wb && !PageWriteback(page)) {
|
|
|
|
set_page_private(page, 0);
|
|
|
|
afs_put_writeback(wb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!page_private(page))
|
|
|
|
ClearPagePrivate(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_leave("");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* release a page and clean up its private state if it's not busy
|
|
|
|
* - return true if the page can now be released, false if not
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2007-05-09 09:33:45 +00:00
|
|
|
static int afs_releasepage(struct page *page, gfp_t gfp_flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-04-03 15:42:41 +00:00
|
|
|
struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
|
2007-05-09 09:33:45 +00:00
|
|
|
struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-09 09:33:45 +00:00
|
|
|
_enter("{{%x:%u}[%lu],%lx},%x",
|
|
|
|
vnode->fid.vid, vnode->fid.vnode, page->index, page->flags,
|
|
|
|
gfp_flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/* deny if page is being written to the cache and the caller hasn't
|
|
|
|
* elected to wait */
|
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
FS-Cache: Handle pages pending storage that get evicted under OOM conditions
Handle netfs pages that the vmscan algorithm wants to evict from the pagecache
under OOM conditions, but that are waiting for write to the cache. Under these
conditions, vmscan calls the releasepage() function of the netfs, asking if a
page can be discarded.
The problem is typified by the following trace of a stuck process:
kslowd005 D 0000000000000000 0 4253 2 0x00000080
ffff88001b14f370 0000000000000046 ffff880020d0d000 0000000000000007
0000000000000006 0000000000000001 ffff88001b14ffd8 ffff880020d0d2a8
000000000000ddf0 00000000000118c0 00000000000118c0 ffff880020d0d2a8
Call Trace:
[<ffffffffa00782d8>] __fscache_wait_on_page_write+0x8b/0xa7 [fscache]
[<ffffffff8104c0f1>] ? autoremove_wake_function+0x0/0x34
[<ffffffffa0078240>] ? __fscache_check_page_write+0x63/0x70 [fscache]
[<ffffffffa00b671d>] nfs_fscache_release_page+0x4e/0xc4 [nfs]
[<ffffffffa00927f0>] nfs_release_page+0x3c/0x41 [nfs]
[<ffffffff810885d3>] try_to_release_page+0x32/0x3b
[<ffffffff81093203>] shrink_page_list+0x316/0x4ac
[<ffffffff8109372b>] shrink_inactive_list+0x392/0x67c
[<ffffffff813532fa>] ? __mutex_unlock_slowpath+0x100/0x10b
[<ffffffff81058df0>] ? trace_hardirqs_on_caller+0x10c/0x130
[<ffffffff8135330e>] ? mutex_unlock+0x9/0xb
[<ffffffff81093aa2>] shrink_list+0x8d/0x8f
[<ffffffff81093d1c>] shrink_zone+0x278/0x33c
[<ffffffff81052d6c>] ? ktime_get_ts+0xad/0xba
[<ffffffff81094b13>] try_to_free_pages+0x22e/0x392
[<ffffffff81091e24>] ? isolate_pages_global+0x0/0x212
[<ffffffff8108e743>] __alloc_pages_nodemask+0x3dc/0x5cf
[<ffffffff81089529>] grab_cache_page_write_begin+0x65/0xaa
[<ffffffff8110f8c0>] ext3_write_begin+0x78/0x1eb
[<ffffffff81089ec5>] generic_file_buffered_write+0x109/0x28c
[<ffffffff8103cb69>] ? current_fs_time+0x22/0x29
[<ffffffff8108a509>] __generic_file_aio_write+0x350/0x385
[<ffffffff8108a588>] ? generic_file_aio_write+0x4a/0xae
[<ffffffff8108a59e>] generic_file_aio_write+0x60/0xae
[<ffffffff810b2e82>] do_sync_write+0xe3/0x120
[<ffffffff8104c0f1>] ? autoremove_wake_function+0x0/0x34
[<ffffffff810b18e1>] ? __dentry_open+0x1a5/0x2b8
[<ffffffff810b1a76>] ? dentry_open+0x82/0x89
[<ffffffffa00e693c>] cachefiles_write_page+0x298/0x335 [cachefiles]
[<ffffffffa0077147>] fscache_write_op+0x178/0x2c2 [fscache]
[<ffffffffa0075656>] fscache_op_execute+0x7a/0xd1 [fscache]
[<ffffffff81082093>] slow_work_execute+0x18f/0x2d1
[<ffffffff8108239a>] slow_work_thread+0x1c5/0x308
[<ffffffff8104c0f1>] ? autoremove_wake_function+0x0/0x34
[<ffffffff810821d5>] ? slow_work_thread+0x0/0x308
[<ffffffff8104be91>] kthread+0x7a/0x82
[<ffffffff8100beda>] child_rip+0xa/0x20
[<ffffffff8100b87c>] ? restore_args+0x0/0x30
[<ffffffff8102ef83>] ? tg_shares_up+0x171/0x227
[<ffffffff8104be17>] ? kthread+0x0/0x82
[<ffffffff8100bed0>] ? child_rip+0x0/0x20
In the above backtrace, the following is happening:
(1) A page storage operation is being executed by a slow-work thread
(fscache_write_op()).
(2) FS-Cache farms the operation out to the cache to perform
(cachefiles_write_page()).
(3) CacheFiles is then calling Ext3 to perform the actual write, using Ext3's
standard write (do_sync_write()) under KERNEL_DS directly from the netfs
page.
(4) However, for Ext3 to perform the write, it must allocate some memory, in
particular, it must allocate at least one page cache page into which it
can copy the data from the netfs page.
(5) Under OOM conditions, the memory allocator can't immediately come up with
a page, so it uses vmscan to find something to discard
(try_to_free_pages()).
(6) vmscan finds a clean netfs page it might be able to discard (possibly the
one it's trying to write out).
(7) The netfs is called to throw the page away (nfs_release_page()) - but it's
called with __GFP_WAIT, so the netfs decides to wait for the store to
complete (__fscache_wait_on_page_write()).
(8) This blocks a slow-work processing thread - possibly against itself.
The system ends up stuck because it can't write out any netfs pages to the
cache without allocating more memory.
To avoid this, we make FS-Cache cancel some writes that aren't in the middle of
actually being performed. This means that some data won't make it into the
cache this time. To support this, a new FS-Cache function is added
fscache_maybe_release_page() that replaces what the netfs releasepage()
functions used to do with respect to the cache.
The decisions fscache_maybe_release_page() makes are counted and displayed
through /proc/fs/fscache/stats on a line labelled "VmScan". There are four
counters provided: "nos=N" - pages that weren't pending storage; "gon=N" -
pages that were pending storage when we first looked, but weren't by the time
we got the object lock; "bsy=N" - pages that we ignored as they were actively
being written when we looked; and "can=N" - pages that we cancelled the storage
of.
What I'd really like to do is alter the behaviour of the cancellation
heuristics, depending on how necessary it is to expel pages. If there are
plenty of other pages that aren't waiting to be written to the cache that
could be ejected first, then it would be nice to hold up on immediate
cancellation of cache writes - but I don't see a way of doing that.
Signed-off-by: David Howells <dhowells@redhat.com>
2009-11-19 18:11:35 +00:00
|
|
|
if (!fscache_maybe_release_page(vnode->cache, page, gfp_flags)) {
|
|
|
|
_leave(" = F [cache busy]");
|
|
|
|
return 0;
|
2009-04-03 15:42:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (PagePrivate(page)) {
|
2009-04-03 15:42:41 +00:00
|
|
|
if (wb) {
|
|
|
|
set_page_private(page, 0);
|
|
|
|
afs_put_writeback(wb);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
ClearPagePrivate(page);
|
|
|
|
}
|
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/* indicate that the page can be released */
|
|
|
|
_leave(" = T");
|
|
|
|
return 1;
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|