On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / fs / reiser4 / plugin / file_ops.c
blob135f8a751315273304ab9c1015cabb81336c00b3
1 /* Copyright 2005 by Hans Reiser, licensing governed by
2 reiser4/README */
4 /* this file contains typical implementations for some of methods of
5 struct file_operations and of struct address_space_operations
6 */
8 #include "../inode.h"
9 #include "object.h"
11 /* file operations */
13 /* implementation of vfs's llseek method of struct file_operations for
14 typical directory can be found in readdir_common.c
16 loff_t reiser4_llseek_dir_common(struct file *, loff_t, int origin);
18 /* implementation of vfs's readdir method of struct file_operations for
19 typical directory can be found in readdir_common.c
21 int reiser4_readdir_common(struct file *, void *dirent, filldir_t);
23 /**
24 * reiser4_release_dir_common - release of struct file_operations
25 * @inode: inode of released file
26 * @file: file to release
28 * Implementation of release method of struct file_operations for typical
29 * directory. All it does is freeing of reiser4 specific file data.
31 int reiser4_release_dir_common(struct inode *inode, struct file *file)
33 reiser4_context *ctx;
35 ctx = reiser4_init_context(inode->i_sb);
36 if (IS_ERR(ctx))
37 return PTR_ERR(ctx);
38 reiser4_free_file_fsdata(file);
39 reiser4_exit_context(ctx);
40 return 0;
43 /* this is common implementation of vfs's fsync method of struct
44 file_operations
46 int reiser4_sync_common(struct file *file, struct dentry *dentry, int datasync)
48 reiser4_context *ctx;
49 int result;
51 ctx = reiser4_init_context(dentry->d_inode->i_sb);
52 if (IS_ERR(ctx))
53 return PTR_ERR(ctx);
54 result = txnmgr_force_commit_all(dentry->d_inode->i_sb, 0);
56 context_set_commit_async(ctx);
57 reiser4_exit_context(ctx);
58 return result;
62 * common sync method for regular files.
64 * We are trying to be smart here. Instead of committing all atoms (original
65 * solution), we scan dirty pages of this file and commit all atoms they are
66 * part of.
68 * Situation is complicated by anonymous pages: i.e., extent-less pages
69 * dirtied through mmap. Fortunately sys_fsync() first calls
70 * filemap_fdatawrite() that will ultimately call reiser4_writepages(), insert
71 * all missing extents and capture anonymous pages.
73 int reiser4_sync_file_common(struct file *file,
74 struct dentry *dentry, int datasync)
76 reiser4_context *ctx;
77 txn_atom *atom;
78 reiser4_block_nr reserve;
80 ctx = reiser4_init_context(dentry->d_inode->i_sb);
81 if (IS_ERR(ctx))
82 return PTR_ERR(ctx);
84 reserve = estimate_update_common(dentry->d_inode);
85 if (reiser4_grab_space(reserve, BA_CAN_COMMIT)) {
86 reiser4_exit_context(ctx);
87 return RETERR(-ENOSPC);
89 write_sd_by_inode_common(dentry->d_inode);
91 atom = get_current_atom_locked();
92 spin_lock_txnh(ctx->trans);
93 force_commit_atom(ctx->trans);
94 reiser4_exit_context(ctx);
95 return 0;
99 /* address space operations */
102 /* this is helper for plugin->write_begin() */
103 int do_prepare_write(struct file *file, struct page *page, unsigned from,
104 unsigned to)
106 int result;
107 file_plugin *fplug;
108 struct inode *inode;
110 assert("umka-3099", file != NULL);
111 assert("umka-3100", page != NULL);
112 assert("umka-3095", PageLocked(page));
114 if (to - from == PAGE_CACHE_SIZE || PageUptodate(page))
115 return 0;
117 inode = page->mapping->host;
118 fplug = inode_file_plugin(inode);
120 if (page->mapping->a_ops->readpage == NULL)
121 return RETERR(-EINVAL);
123 result = page->mapping->a_ops->readpage(file, page);
124 if (result != 0) {
125 SetPageError(page);
126 ClearPageUptodate(page);
127 /* All reiser4 readpage() implementations should return the
128 * page locked in case of error. */
129 assert("nikita-3472", PageLocked(page));
130 } else {
132 * ->readpage() either:
134 * 1. starts IO against @page. @page is locked for IO in
135 * this case.
137 * 2. doesn't start IO. @page is unlocked.
139 * In either case, page should be locked.
141 lock_page(page);
143 * IO (if any) is completed at this point. Check for IO
144 * errors.
146 if (!PageUptodate(page))
147 result = RETERR(-EIO);
149 assert("umka-3098", PageLocked(page));
150 return result;
154 * Local variables:
155 * c-indentation-style: "K&R"
156 * mode-name: "LC"
157 * c-basic-offset: 8
158 * tab-width: 8
159 * fill-column: 79
160 * scroll-step: 1
161 * End: