Skip to content

Commit

Permalink
AFS: implement basic file write support
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dhowells authored and Linus Torvalds committed May 9, 2007
1 parent 416351f commit 31143d5
Show file tree
Hide file tree
Showing 11 changed files with 1,483 additions and 27 deletions.
3 changes: 2 additions & 1 deletion fs/afs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kafs-objs := \
vlclient.o \
vlocation.o \
vnode.o \
volume.o
volume.o \
write.o

obj-$(CONFIG_AFS_FS) := kafs.o
2 changes: 2 additions & 0 deletions fs/afs/afs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
enum AFS_FS_Operations {
FSFETCHDATA = 130, /* AFS Fetch file data */
FSFETCHSTATUS = 132, /* AFS Fetch file status */
FSSTOREDATA = 133, /* AFS Store file data */
FSSTORESTATUS = 135, /* AFS Store file status */
FSREMOVEFILE = 136, /* AFS Remove a file */
FSCREATEFILE = 137, /* AFS Create a file */
FSRENAME = 138, /* AFS Rename or move a file or directory */
Expand Down
1 change: 1 addition & 0 deletions fs/afs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const struct inode_operations afs_dir_inode_operations = {
.rename = afs_rename,
.permission = afs_permission,
.getattr = afs_getattr,
.setattr = afs_setattr,
};

static struct dentry_operations afs_fs_dentry_operations = {
Expand Down
32 changes: 26 additions & 6 deletions fs/afs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,43 @@
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/pagemap.h>
#include <linux/writeback.h>
#include "internal.h"

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);
static int afs_launder_page(struct page *page);

const struct file_operations afs_file_operations = {
.open = afs_open,
.release = afs_release,
.llseek = generic_file_llseek,
.read = do_sync_read,
.write = do_sync_write,
.aio_read = generic_file_aio_read,
.aio_write = afs_file_write,
.mmap = generic_file_readonly_mmap,
.sendfile = generic_file_sendfile,
.fsync = afs_fsync,
};

const struct inode_operations afs_file_inode_operations = {
.getattr = afs_getattr,
.setattr = afs_setattr,
.permission = afs_permission,
};

const struct address_space_operations afs_fs_aops = {
.readpage = afs_readpage,
.set_page_dirty = __set_page_dirty_nobuffers,
.set_page_dirty = afs_set_page_dirty,
.launder_page = afs_launder_page,
.releasepage = afs_releasepage,
.invalidatepage = afs_invalidatepage,
.prepare_write = afs_prepare_write,
.commit_write = afs_commit_write,
.writepage = afs_writepage,
.writepages = afs_writepages,
};

/*
Expand Down Expand Up @@ -230,11 +241,6 @@ static void afs_invalidatepage(struct page *page, unsigned long offset)
BUG_ON(!PageLocked(page));

if (PagePrivate(page)) {
#ifdef AFS_CACHING_SUPPORT
struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
cachefs_uncache_page(vnode->cache,page);
#endif

/* We release buffers only if the entire page is being
* invalidated.
* The get_block cached value has been unconditionally
Expand All @@ -254,20 +260,34 @@ static void afs_invalidatepage(struct page *page, unsigned long offset)
_leave(" = %d", ret);
}

/*
* write back a dirty page
*/
static int afs_launder_page(struct page *page)
{
_enter("{%lu}", page->index);

return 0;
}

/*
* release a page and cleanup its private data
*/
static int afs_releasepage(struct page *page, gfp_t gfp_flags)
{
struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
struct afs_writeback *wb;

_enter("{{%x:%u}[%lu],%lx},%x",
vnode->fid.vid, vnode->fid.vnode, page->index, page->flags,
gfp_flags);

if (PagePrivate(page)) {
wb = (struct afs_writeback *) page_private(page);
ASSERT(wb != NULL);
set_page_private(page, 0);
ClearPagePrivate(page);
afs_put_writeback(wb);
}

_leave(" = 0");
Expand Down

0 comments on commit 31143d5

Please sign in to comment.