2007-04-26 16:55:03 -06:00
|
|
|
/* AFS filesystem file handling
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
2007-04-26 16:55:03 -06:00
|
|
|
* Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
|
2005-04-16 16:20:36 -06: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/slab.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 03:33:46 -06:00
|
|
|
#include <linux/writeback.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include "internal.h"
|
|
|
|
|
2007-05-09 03:33:45 -06:00
|
|
|
static int afs_readpage(struct file *file, struct page *page);
|
|
|
|
static void afs_invalidatepage(struct page *page, unsigned long offset);
|
|
|
|
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 03:33:46 -06:00
|
|
|
static int afs_launder_page(struct page *page);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-04-03 09:42:41 -06:00
|
|
|
static int afs_readpages(struct file *filp, struct address_space *mapping,
|
|
|
|
struct list_head *pages, unsigned nr_pages);
|
|
|
|
|
2007-04-26 16:57:07 -06:00
|
|
|
const struct file_operations afs_file_operations = {
|
|
|
|
.open = afs_open,
|
|
|
|
.release = afs_release,
|
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
.read = do_sync_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 03:33:46 -06:00
|
|
|
.write = do_sync_write,
|
2007-04-26 16:57:07 -06:00
|
|
|
.aio_read = generic_file_aio_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 03:33:46 -06:00
|
|
|
.aio_write = afs_file_write,
|
2007-04-26 16:57:07 -06:00
|
|
|
.mmap = generic_file_readonly_mmap,
|
2007-06-01 03:49:19 -06: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 03:33:46 -06:00
|
|
|
.fsync = afs_fsync,
|
2007-07-16 00:40:12 -06:00
|
|
|
.lock = afs_lock,
|
|
|
|
.flock = afs_flock,
|
2007-04-26 16:57:07 -06:00
|
|
|
};
|
|
|
|
|
2007-02-12 01:55:38 -07:00
|
|
|
const struct inode_operations afs_file_inode_operations = {
|
2007-05-09 03:33:45 -06: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 03:33:46 -06:00
|
|
|
.setattr = afs_setattr,
|
2007-04-26 16:57:07 -06:00
|
|
|
.permission = afs_permission,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2006-06-28 05:26:44 -06:00
|
|
|
const struct address_space_operations afs_fs_aops = {
|
2007-05-09 03:33:45 -06:00
|
|
|
.readpage = afs_readpage,
|
2009-04-03 09:42:41 -06: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 03:33:46 -06:00
|
|
|
.set_page_dirty = afs_set_page_dirty,
|
|
|
|
.launder_page = afs_launder_page,
|
2007-05-09 03:33:45 -06:00
|
|
|
.releasepage = afs_releasepage,
|
|
|
|
.invalidatepage = afs_invalidatepage,
|
2008-10-15 23:04:32 -06: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 03:33:46 -06:00
|
|
|
.writepage = afs_writepage,
|
|
|
|
.writepages = afs_writepages,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2007-04-26 16:57:07 -06: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 16:59:35 -06:00
|
|
|
int ret;
|
2007-04-26 16:57:07 -06:00
|
|
|
|
2007-05-09 03:33:45 -06:00
|
|
|
_enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
|
2007-04-26 16:57:07 -06: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 16:59:35 -06:00
|
|
|
ret = afs_validate(vnode, key);
|
|
|
|
if (ret < 0) {
|
|
|
|
_leave(" = %d [val]", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-04-26 16:57:07 -06: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 03:33:45 -06:00
|
|
|
_enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
|
2007-04-26 16:57:07 -06:00
|
|
|
|
|
|
|
key_put(file->private_data);
|
|
|
|
_leave(" = 0");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-17 05:56:38 -06:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* deal with notification that a page was read from the cache
|
|
|
|
*/
|
2009-04-03 09:42:41 -06:00
|
|
|
static void afs_file_readpage_read_complete(struct page *page,
|
|
|
|
void *data,
|
|
|
|
int error)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2009-04-03 09:42:41 -06:00
|
|
|
_enter("%p,%p,%d", page, data, error);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-04-03 09:42:41 -06: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 16:20:36 -06:00
|
|
|
SetPageUptodate(page);
|
|
|
|
unlock_page(page);
|
2007-04-26 16:49:28 -06:00
|
|
|
}
|
2009-04-17 05:56:38 -06:00
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
2007-05-09 03:33:45 -06:00
|
|
|
* AFS read page from file, directory or symlink
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2007-05-09 03:33:45 -06:00
|
|
|
static int afs_readpage(struct file *file, struct page *page)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct afs_vnode *vnode;
|
|
|
|
struct inode *inode;
|
2007-04-26 16:57:07 -06:00
|
|
|
struct key *key;
|
2007-04-26 16:55:03 -06:00
|
|
|
size_t len;
|
|
|
|
off_t offset;
|
2005-04-16 16:20:36 -06:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
inode = page->mapping->host;
|
|
|
|
|
2009-08-27 06:09:06 -06:00
|
|
|
if (file) {
|
|
|
|
key = file->private_data;
|
|
|
|
ASSERT(key != NULL);
|
|
|
|
} else {
|
|
|
|
key = afs_request_key(AFS_FS_S(inode->i_sb)->volume->cell);
|
|
|
|
if (IS_ERR(key)) {
|
|
|
|
ret = PTR_ERR(key);
|
|
|
|
goto error_nokey;
|
|
|
|
}
|
|
|
|
}
|
2007-04-26 16:57:07 -06:00
|
|
|
|
|
|
|
_enter("{%x},{%lu},{%lu}", key_serial(key), inode->i_ino, page->index);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
vnode = AFS_FS_I(inode);
|
|
|
|
|
2005-05-01 09:59:01 -06:00
|
|
|
BUG_ON(!PageLocked(page));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
ret = -ESTALE;
|
2007-04-26 16:55:03 -06:00
|
|
|
if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
|
2005-04-16 16:20:36 -06:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* is it cached? */
|
2009-04-03 09:42:41 -06:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
ret = fscache_read_or_alloc_page(vnode->cache,
|
2005-04-16 16:20:36 -06: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 09:42:41 -06:00
|
|
|
/* page not yet cached */
|
2005-04-16 16:20:36 -06:00
|
|
|
case -ENODATA:
|
2009-04-03 09:42:41 -06:00
|
|
|
_debug("cache said ENODATA");
|
|
|
|
goto go_on;
|
|
|
|
|
|
|
|
/* page will not be cached */
|
|
|
|
case -ENOBUFS:
|
|
|
|
_debug("cache said ENOBUFS");
|
2005-04-16 16:20:36 -06:00
|
|
|
default:
|
2009-04-03 09:42:41 -06:00
|
|
|
go_on:
|
2007-04-26 16:55:03 -06:00
|
|
|
offset = page->index << PAGE_CACHE_SHIFT;
|
|
|
|
len = min_t(size_t, i_size_read(inode) - offset, PAGE_SIZE);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* read the contents of the file from the server into the
|
|
|
|
* page */
|
2007-04-26 16:57:07 -06:00
|
|
|
ret = afs_vnode_fetch_data(vnode, key, offset, len, page);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (ret < 0) {
|
2007-04-26 16:55:03 -06:00
|
|
|
if (ret == -ENOENT) {
|
2005-04-16 16:20:36 -06:00
|
|
|
_debug("got NOENT from server"
|
|
|
|
" - marking file deleted and stale");
|
2007-04-26 16:55:03 -06:00
|
|
|
set_bit(AFS_VNODE_DELETED, &vnode->flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = -ESTALE;
|
|
|
|
}
|
2009-04-03 09:42:41 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
fscache_uncache_page(vnode->cache, page);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
2009-04-03 09:42:41 -06:00
|
|
|
BUG_ON(PageFsCache(page));
|
2005-04-16 16:20:36 -06:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetPageUptodate(page);
|
|
|
|
|
2009-04-03 09:42:41 -06: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 16:20:36 -06:00
|
|
|
}
|
|
|
|
#endif
|
2009-04-03 09:42:41 -06:00
|
|
|
unlock_page(page);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-08-27 06:09:06 -06:00
|
|
|
if (!file)
|
|
|
|
key_put(key);
|
2005-04-16 16:20:36 -06:00
|
|
|
_leave(" = 0");
|
|
|
|
return 0;
|
|
|
|
|
2007-04-26 16:55:03 -06:00
|
|
|
error:
|
2005-04-16 16:20:36 -06:00
|
|
|
SetPageError(page);
|
|
|
|
unlock_page(page);
|
2009-08-27 06:09:06 -06:00
|
|
|
if (!file)
|
|
|
|
key_put(key);
|
|
|
|
error_nokey:
|
2005-04-16 16:20:36 -06:00
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ret;
|
2007-04-26 16:49:28 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
2009-04-03 09:42:41 -06:00
|
|
|
* read a set of pages
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2009-04-03 09:42:41 -06:00
|
|
|
static int afs_readpages(struct file *file, struct address_space *mapping,
|
|
|
|
struct list_head *pages, unsigned nr_pages)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2009-04-03 09:42:41 -06:00
|
|
|
struct afs_vnode *vnode;
|
|
|
|
int ret = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-04-03 09:42:41 -06:00
|
|
|
_enter(",{%lu},,%d", mapping->host->i_ino, nr_pages);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-04-03 09:42:41 -06:00
|
|
|
vnode = AFS_FS_I(mapping->host);
|
|
|
|
if (vnode->flags & AFS_VNODE_DELETED) {
|
|
|
|
_leave(" = -ESTALE");
|
|
|
|
return -ESTALE;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-04-03 09:42:41 -06: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 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-04-03 09:42:41 -06:00
|
|
|
/* load the missing pages from the network */
|
|
|
|
ret = read_cache_pages(mapping, pages, (void *) afs_readpage, file);
|
|
|
|
|
|
|
|
_leave(" = %d [netting]", ret);
|
|
|
|
return ret;
|
2007-04-26 16:49:28 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06: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 03:33:46 -06:00
|
|
|
/*
|
|
|
|
* write back a dirty page
|
|
|
|
*/
|
|
|
|
static int afs_launder_page(struct page *page)
|
|
|
|
{
|
|
|
|
_enter("{%lu}", page->index);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2009-04-03 09:42:41 -06: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)
|
|
|
|
*/
|
|
|
|
static void afs_invalidatepage(struct page *page, unsigned long offset)
|
|
|
|
{
|
|
|
|
struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
|
|
|
|
|
|
|
|
_enter("{%lu},%lu", page->index, offset);
|
|
|
|
|
|
|
|
BUG_ON(!PageLocked(page));
|
|
|
|
|
|
|
|
/* we clean up only if the entire page is being invalidated */
|
|
|
|
if (offset == 0) {
|
|
|
|
#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);
|
|
|
|
ClearPageFsCache(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 16:20:36 -06:00
|
|
|
*/
|
2007-05-09 03:33:45 -06:00
|
|
|
static int afs_releasepage(struct page *page, gfp_t gfp_flags)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2009-04-03 09:42:41 -06:00
|
|
|
struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
|
2007-05-09 03:33:45 -06:00
|
|
|
struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-05-09 03:33:45 -06:00
|
|
|
_enter("{{%x:%u}[%lu],%lx},%x",
|
|
|
|
vnode->fid.vid, vnode->fid.vnode, page->index, page->flags,
|
|
|
|
gfp_flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-04-03 09:42:41 -06:00
|
|
|
/* deny if page is being written to the cache and the caller hasn't
|
|
|
|
* elected to wait */
|
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
if (PageFsCache(page)) {
|
|
|
|
if (fscache_check_page_write(vnode->cache, page)) {
|
|
|
|
if (!(gfp_flags & __GFP_WAIT)) {
|
|
|
|
_leave(" = F [cache busy]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fscache_wait_on_page_write(vnode->cache, page);
|
|
|
|
}
|
|
|
|
|
|
|
|
fscache_uncache_page(vnode->cache, page);
|
|
|
|
ClearPageFsCache(page);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (PagePrivate(page)) {
|
2009-04-03 09:42:41 -06:00
|
|
|
if (wb) {
|
|
|
|
set_page_private(page, 0);
|
|
|
|
afs_put_writeback(wb);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
ClearPagePrivate(page);
|
|
|
|
}
|
|
|
|
|
2009-04-03 09:42:41 -06:00
|
|
|
/* indicate that the page can be released */
|
|
|
|
_leave(" = T");
|
|
|
|
return 1;
|
2007-04-26 16:49:28 -06:00
|
|
|
}
|