On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / fs / reiser4 / plugin / file / file.h
blobf51f0ac4598ef88255ad63abe59acf210a108923
1 /* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
2 * reiser4/README */
4 /* this file contains declarations of methods implementing
5 file plugins (UNIX_FILE_PLUGIN_ID, CRYPTCOMPRESS_FILE_PLUGIN_ID
6 and SYMLINK_FILE_PLUGIN_ID) */
8 #if !defined( __REISER4_FILE_H__ )
9 #define __REISER4_FILE_H__
11 /* possible states in dispatching process */
12 typedef enum {
13 DISPATCH_INVAL_STATE, /* invalid state */
14 DISPATCH_POINT, /* dispatching point has been achieved */
15 DISPATCH_REMAINS_OLD, /* made a decision to manage by old plugin */
16 DISPATCH_ASSIGNED_NEW /* a new plugin has been assigned */
17 } dispatch_state;
19 struct dispatch_context {
20 int nr_pages;
21 struct page **pages;
22 dispatch_state state;
25 /**
26 * Declarations of common/careful/generic methods.
27 * Suppose ->foo() is a vs method (of f_ops, i_ops, or a_ops);
28 * Then common reiser4 method for foo looks like reiser4_foo_common;
29 * careful method looks like reiser4_foo_careful;
30 * generic method looks like reiser4_foo.
32 * Common method is a simple instruction set eligible for more
33 * then one plugin id.
35 * Generic method looks at the plugin installed in inode's
36 * plugin set and calls its appropriate method.
38 * Careful method looks like generic method with protected pset
39 * (see plugin/file/file_conversion.c for details).
42 /* inode operations */
43 int reiser4_setattr(struct dentry *, struct iattr *);
45 /* file operations */
46 ssize_t reiser4_read_careful(struct file *, char __user *buf,
47 size_t count, loff_t *off);
48 ssize_t reiser4_write_careful(struct file *, const char __user *buf,
49 size_t count, loff_t * off);
50 int reiser4_ioctl_careful(struct inode *inode, struct file *filp,
51 unsigned int cmd, unsigned long arg);
52 int reiser4_mmap_careful(struct file *, struct vm_area_struct *);
53 int reiser4_open_careful(struct inode *inode, struct file *file);
54 int reiser4_release_careful(struct inode *, struct file *);
55 int reiser4_sync_file_common(struct file *, struct dentry *, int datasync);
57 /* address space operations */
58 int reiser4_readpage(struct file *, struct page *);
59 int reiser4_readpages(struct file*, struct address_space*, struct list_head*,
60 unsigned);
61 int reiser4_writepages(struct address_space *, struct writeback_control *);
62 int reiser4_write_begin_careful(struct file *file,
63 struct address_space *mapping,
64 loff_t pos, unsigned len, unsigned flags,
65 struct page **pagep, void **fsdata);
66 int reiser4_write_end_careful(struct file *file,
67 struct address_space *mapping,
68 loff_t pos, unsigned len, unsigned copied,
69 struct page *page, void *fsdata);
70 sector_t reiser4_bmap_careful(struct address_space *, sector_t lblock);
73 * Private methods of unix-file plugin
74 * (UNIX_FILE_PLUGIN_ID)
77 /* private inode operations */
78 int setattr_unix_file(struct dentry *, struct iattr *);
80 /* private file operations */
82 ssize_t read_unix_file(struct file *, char __user *buf, size_t read_amount,
83 loff_t *off);
84 ssize_t write_unix_file(struct file *, const char __user *buf, size_t write_amount,
85 loff_t * off, struct dispatch_context * cont);
86 int ioctl_unix_file(struct inode *, struct file *, unsigned int cmd,
87 unsigned long arg);
88 int mmap_unix_file(struct file *, struct vm_area_struct *);
89 int open_unix_file(struct inode *, struct file *);
90 int release_unix_file(struct inode *, struct file *);
92 /* private address space operations */
93 int readpage_unix_file(struct file *, struct page *);
94 int readpages_unix_file(struct file*, struct address_space*, struct list_head*,
95 unsigned);
96 int writepages_unix_file(struct address_space *, struct writeback_control *);
97 int write_begin_unix_file(struct file *file, struct page *page,
98 unsigned from, unsigned to);
99 int write_end_unix_file(struct file *file, struct page *page,
100 unsigned from, unsigned to);
101 sector_t bmap_unix_file(struct address_space *, sector_t lblock);
103 /* other private methods */
104 int delete_object_unix_file(struct inode *);
105 int flow_by_inode_unix_file(struct inode *, const char __user *buf,
106 int user, loff_t, loff_t, rw_op, flow_t *);
107 int owns_item_unix_file(const struct inode *, const coord_t *);
108 void init_inode_data_unix_file(struct inode *, reiser4_object_create_data *,
109 int create);
112 * Private methods of cryptcompress file plugin
113 * (CRYPTCOMPRESS_FILE_PLUGIN_ID)
116 /* private inode operations */
117 int setattr_cryptcompress(struct dentry *, struct iattr *);
119 /* private file operations */
120 ssize_t read_cryptcompress(struct file *, char __user *buf,
121 size_t count, loff_t *off);
122 ssize_t write_cryptcompress(struct file *, const char __user *buf,
123 size_t count, loff_t * off,
124 struct dispatch_context *cont);
125 int ioctl_cryptcompress(struct inode *, struct file *, unsigned int cmd,
126 unsigned long arg);
127 int mmap_cryptcompress(struct file *, struct vm_area_struct *);
128 int open_cryptcompress(struct inode *, struct file *);
129 int release_cryptcompress(struct inode *, struct file *);
131 /* private address space operations */
132 int readpage_cryptcompress(struct file *, struct page *);
133 int readpages_cryptcompress(struct file*, struct address_space*,
134 struct list_head*, unsigned);
135 int writepages_cryptcompress(struct address_space *,
136 struct writeback_control *);
137 int write_begin_cryptcompress(struct file *file, struct page *page,
138 unsigned from, unsigned to);
139 int write_end_cryptcompress(struct file *file, struct page *page,
140 unsigned from, unsigned to);
141 sector_t bmap_cryptcompress(struct address_space *, sector_t lblock);
143 /* other private methods */
144 int flow_by_inode_cryptcompress(struct inode *, const char __user *buf,
145 int user, loff_t, loff_t, rw_op, flow_t *);
146 int key_by_inode_cryptcompress(struct inode *, loff_t off, reiser4_key *);
147 int create_object_cryptcompress(struct inode *, struct inode *,
148 reiser4_object_create_data *);
149 int delete_object_cryptcompress(struct inode *);
150 void init_inode_data_cryptcompress(struct inode *, reiser4_object_create_data *,
151 int create);
152 int cut_tree_worker_cryptcompress(tap_t *, const reiser4_key * from_key,
153 const reiser4_key * to_key,
154 reiser4_key * smallest_removed,
155 struct inode *object, int truncate,
156 int *progress);
157 void destroy_inode_cryptcompress(struct inode *);
160 * Private methods of symlink file plugin
161 * (SYMLINK_FILE_PLUGIN_ID)
163 int reiser4_create_symlink(struct inode *symlink, struct inode *dir,
164 reiser4_object_create_data *);
165 void destroy_inode_symlink(struct inode *);
168 * all the write into unix file is performed by item write method. Write method
169 * of unix file plugin only decides which item plugin (extent or tail) and in
170 * which mode (one from the enum below) to call
172 typedef enum {
173 FIRST_ITEM = 1,
174 APPEND_ITEM = 2,
175 OVERWRITE_ITEM = 3
176 } write_mode_t;
178 /* unix file may be in one the following states */
179 typedef enum {
180 UF_CONTAINER_UNKNOWN = 0,
181 UF_CONTAINER_TAILS = 1,
182 UF_CONTAINER_EXTENTS = 2,
183 UF_CONTAINER_EMPTY = 3
184 } file_container_t;
186 struct formatting_plugin;
187 struct inode;
189 /* unix file plugin specific part of reiser4 inode */
190 struct unix_file_info {
192 * this read-write lock protects file containerization change. Accesses
193 * which do not change file containerization (see file_container_t)
194 * (read, readpage, writepage, write (until tail conversion is
195 * involved)) take read-lock. Accesses which modify file
196 * containerization (truncate, conversion from tail to extent and back)
197 * take write-lock.
199 struct rw_semaphore latch;
200 /* this enum specifies which items are used to build the file */
201 file_container_t container;
203 * plugin which controls when file is to be converted to extents and
204 * back to tail
206 struct formatting_plugin *tplug;
207 /* if this is set, file is in exclusive use */
208 int exclusive_use;
209 #if REISER4_DEBUG
210 /* pointer to task struct of thread owning exclusive access to file */
211 void *ea_owner;
212 atomic_t nr_neas;
213 void *last_reader;
214 #endif
217 struct unix_file_info *unix_file_inode_data(const struct inode *inode);
218 void get_exclusive_access(struct unix_file_info *);
219 void drop_exclusive_access(struct unix_file_info *);
220 void get_nonexclusive_access(struct unix_file_info *);
221 void drop_nonexclusive_access(struct unix_file_info *);
222 int try_to_get_nonexclusive_access(struct unix_file_info *);
223 int find_file_item(hint_t *, const reiser4_key *, znode_lock_mode,
224 struct inode *);
225 int find_file_item_nohint(coord_t *, lock_handle *,
226 const reiser4_key *, znode_lock_mode,
227 struct inode *);
229 int load_file_hint(struct file *, hint_t *);
230 void save_file_hint(struct file *, const hint_t *);
232 #include "../item/extent.h"
233 #include "../item/tail.h"
234 #include "../item/ctail.h"
236 struct uf_coord {
237 coord_t coord;
238 lock_handle *lh;
239 int valid;
240 union {
241 struct extent_coord_extension extent;
242 struct tail_coord_extension tail;
243 struct ctail_coord_extension ctail;
244 } extension;
247 #include "../../forward.h"
248 #include "../../seal.h"
249 #include "../../lock.h"
252 * This structure is used to speed up file operations (reads and writes). A
253 * hint is a suggestion about where a key resolved to last time. A seal
254 * indicates whether a node has been modified since a hint was last recorded.
255 * You check the seal, and if the seal is still valid, you can use the hint
256 * without traversing the tree again.
258 struct hint {
259 seal_t seal; /* a seal over last file item accessed */
260 uf_coord_t ext_coord;
261 loff_t offset;
262 znode_lock_mode mode;
263 lock_handle lh;
266 static inline int hint_is_valid(hint_t * hint)
268 return hint->ext_coord.valid;
271 static inline void hint_set_valid(hint_t * hint)
273 hint->ext_coord.valid = 1;
276 static inline void hint_clr_valid(hint_t * hint)
278 hint->ext_coord.valid = 0;
281 int load_file_hint(struct file *, hint_t *);
282 void save_file_hint(struct file *, const hint_t *);
283 void hint_init_zero(hint_t *);
284 void reiser4_set_hint(hint_t *, const reiser4_key *, znode_lock_mode);
285 int hint_is_set(const hint_t *);
286 void reiser4_unset_hint(hint_t *);
288 int reiser4_update_file_size(struct inode *, loff_t, int update_sd);
289 int cut_file_items(struct inode *, loff_t new_size,
290 int update_sd, loff_t cur_size,
291 int (*update_actor) (struct inode *, loff_t, int));
292 #if REISER4_DEBUG
294 /* return 1 is exclusive access is obtained, 0 - otherwise */
295 static inline int ea_obtained(struct unix_file_info * uf_info)
297 int ret;
299 ret = down_read_trylock(&uf_info->latch);
300 if (ret)
301 up_read(&uf_info->latch);
302 return !ret;
305 #endif
307 #define WRITE_GRANULARITY 32
309 int tail2extent(struct unix_file_info *);
310 int extent2tail(struct file *, struct unix_file_info *);
312 int goto_right_neighbor(coord_t *, lock_handle *);
313 int find_or_create_extent(struct page *);
314 int equal_to_ldk(znode *, const reiser4_key *);
316 void init_uf_coord(uf_coord_t *uf_coord, lock_handle *lh);
318 static inline int cbk_errored(int cbk_result)
320 return (cbk_result != CBK_COORD_NOTFOUND
321 && cbk_result != CBK_COORD_FOUND);
324 /* __REISER4_FILE_H__ */
325 #endif
328 * Local variables:
329 * c-indentation-style: "K&R"
330 * mode-name: "LC"
331 * c-basic-offset: 8
332 * tab-width: 8
333 * fill-column: 79
334 * scroll-step: 1
335 * End: