Commit | Line | Data |
---|---|---|
f7ab093f MM |
1 | /* |
2 | * (C) 2001 Clemson University and The University of Chicago | |
3 | * | |
4 | * See COPYING in top-level directory. | |
5 | */ | |
6 | ||
7 | /* | |
8 | * The PVFS2 Linux kernel support allows PVFS2 volumes to be mounted and | |
9 | * accessed through the Linux VFS (i.e. using standard I/O system calls). | |
10 | * This support is only needed on clients that wish to mount the file system. | |
11 | * | |
12 | */ | |
13 | ||
14 | /* | |
15 | * Declarations and macros for the PVFS2 Linux kernel support. | |
16 | */ | |
17 | ||
18 | #ifndef __PVFS2KERNEL_H | |
19 | #define __PVFS2KERNEL_H | |
20 | ||
21 | #include <linux/kernel.h> | |
22 | #include <linux/moduleparam.h> | |
23 | #include <linux/statfs.h> | |
24 | #include <linux/backing-dev.h> | |
25 | #include <linux/device.h> | |
26 | #include <linux/mpage.h> | |
27 | #include <linux/namei.h> | |
28 | #include <linux/errno.h> | |
29 | #include <linux/init.h> | |
30 | #include <linux/module.h> | |
31 | #include <linux/slab.h> | |
32 | #include <linux/types.h> | |
33 | #include <linux/fs.h> | |
34 | #include <linux/vmalloc.h> | |
35 | ||
36 | #include <linux/aio.h> | |
37 | #include <linux/posix_acl.h> | |
38 | #include <linux/posix_acl_xattr.h> | |
39 | #include <linux/compat.h> | |
40 | #include <linux/mount.h> | |
41 | #include <linux/uaccess.h> | |
42 | #include <linux/atomic.h> | |
43 | #include <linux/uio.h> | |
44 | #include <linux/sched.h> | |
45 | #include <linux/mm.h> | |
46 | #include <linux/wait.h> | |
47 | #include <linux/dcache.h> | |
48 | #include <linux/pagemap.h> | |
49 | #include <linux/poll.h> | |
50 | #include <linux/rwsem.h> | |
51 | #include <linux/xattr.h> | |
52 | #include <linux/exportfs.h> | |
53 | ||
54 | #include <asm/unaligned.h> | |
55 | ||
56 | #include "pvfs2-dev-proto.h" | |
57 | ||
58 | #ifdef PVFS2_KERNEL_DEBUG | |
59 | #define PVFS2_DEFAULT_OP_TIMEOUT_SECS 10 | |
60 | #else | |
61 | #define PVFS2_DEFAULT_OP_TIMEOUT_SECS 20 | |
62 | #endif | |
63 | ||
64 | #define PVFS2_BUFMAP_WAIT_TIMEOUT_SECS 30 | |
65 | ||
66 | #define PVFS2_DEFAULT_SLOT_TIMEOUT_SECS 900 /* 15 minutes */ | |
67 | ||
68 | #define PVFS2_REQDEVICE_NAME "pvfs2-req" | |
69 | ||
70 | #define PVFS2_DEVREQ_MAGIC 0x20030529 | |
71 | #define PVFS2_LINK_MAX 0x000000FF | |
72 | #define PVFS2_PURGE_RETRY_COUNT 0x00000005 | |
73 | #define PVFS2_SEEK_END 0x00000002 | |
74 | #define PVFS2_MAX_NUM_OPTIONS 0x00000004 | |
75 | #define PVFS2_MAX_MOUNT_OPT_LEN 0x00000080 | |
76 | #define PVFS2_MAX_FSKEY_LEN 64 | |
77 | ||
78 | #define MAX_DEV_REQ_UPSIZE (2*sizeof(__s32) + \ | |
79 | sizeof(__u64) + sizeof(struct pvfs2_upcall_s)) | |
80 | #define MAX_DEV_REQ_DOWNSIZE (2*sizeof(__s32) + \ | |
81 | sizeof(__u64) + sizeof(struct pvfs2_downcall_s)) | |
82 | ||
83 | #define BITS_PER_LONG_DIV_8 (BITS_PER_LONG >> 3) | |
84 | ||
85 | /* borrowed from irda.h */ | |
86 | #ifndef MSECS_TO_JIFFIES | |
87 | #define MSECS_TO_JIFFIES(ms) (((ms)*HZ+999)/1000) | |
88 | #endif | |
89 | ||
90 | #define MAX_ALIGNED_DEV_REQ_UPSIZE \ | |
91 | (MAX_DEV_REQ_UPSIZE + \ | |
92 | ((((MAX_DEV_REQ_UPSIZE / \ | |
93 | (BITS_PER_LONG_DIV_8)) * \ | |
94 | (BITS_PER_LONG_DIV_8)) + \ | |
95 | (BITS_PER_LONG_DIV_8)) - \ | |
96 | MAX_DEV_REQ_UPSIZE)) | |
97 | ||
98 | #define MAX_ALIGNED_DEV_REQ_DOWNSIZE \ | |
99 | (MAX_DEV_REQ_DOWNSIZE + \ | |
100 | ((((MAX_DEV_REQ_DOWNSIZE / \ | |
101 | (BITS_PER_LONG_DIV_8)) * \ | |
102 | (BITS_PER_LONG_DIV_8)) + \ | |
103 | (BITS_PER_LONG_DIV_8)) - \ | |
104 | MAX_DEV_REQ_DOWNSIZE)) | |
105 | ||
106 | /* | |
107 | * valid pvfs2 kernel operation states | |
108 | * | |
109 | * unknown - op was just initialized | |
110 | * waiting - op is on request_list (upward bound) | |
111 | * inprogr - op is in progress (waiting for downcall) | |
112 | * serviced - op has matching downcall; ok | |
113 | * purged - op has to start a timer since client-core | |
114 | * exited uncleanly before servicing op | |
115 | */ | |
116 | enum pvfs2_vfs_op_states { | |
117 | OP_VFS_STATE_UNKNOWN = 0, | |
118 | OP_VFS_STATE_WAITING = 1, | |
119 | OP_VFS_STATE_INPROGR = 2, | |
120 | OP_VFS_STATE_SERVICED = 4, | |
121 | OP_VFS_STATE_PURGED = 8, | |
122 | }; | |
123 | ||
124 | #define set_op_state_waiting(op) ((op)->op_state = OP_VFS_STATE_WAITING) | |
125 | #define set_op_state_inprogress(op) ((op)->op_state = OP_VFS_STATE_INPROGR) | |
126 | #define set_op_state_serviced(op) ((op)->op_state = OP_VFS_STATE_SERVICED) | |
127 | #define set_op_state_purged(op) ((op)->op_state |= OP_VFS_STATE_PURGED) | |
128 | ||
129 | #define op_state_waiting(op) ((op)->op_state & OP_VFS_STATE_WAITING) | |
130 | #define op_state_in_progress(op) ((op)->op_state & OP_VFS_STATE_INPROGR) | |
131 | #define op_state_serviced(op) ((op)->op_state & OP_VFS_STATE_SERVICED) | |
132 | #define op_state_purged(op) ((op)->op_state & OP_VFS_STATE_PURGED) | |
133 | ||
134 | #define get_op(op) \ | |
135 | do { \ | |
136 | atomic_inc(&(op)->aio_ref_count); \ | |
137 | gossip_debug(GOSSIP_DEV_DEBUG, \ | |
138 | "(get) Alloced OP (%p:%llu)\n", \ | |
139 | op, \ | |
140 | llu((op)->tag)); \ | |
141 | } while (0) | |
142 | ||
143 | #define put_op(op) \ | |
144 | do { \ | |
145 | if (atomic_sub_and_test(1, &(op)->aio_ref_count) == 1) { \ | |
146 | gossip_debug(GOSSIP_DEV_DEBUG, \ | |
147 | "(put) Releasing OP (%p:%llu)\n", \ | |
148 | op, \ | |
149 | llu((op)->tag)); \ | |
150 | op_release(op); \ | |
151 | } \ | |
152 | } while (0) | |
153 | ||
154 | #define op_wait(op) (atomic_read(&(op)->aio_ref_count) <= 2 ? 0 : 1) | |
155 | ||
156 | /* | |
157 | * Defines for controlling whether I/O upcalls are for async or sync operations | |
158 | */ | |
159 | enum PVFS_async_io_type { | |
160 | PVFS_VFS_SYNC_IO = 0, | |
161 | PVFS_VFS_ASYNC_IO = 1, | |
162 | }; | |
163 | ||
164 | /* | |
165 | * An array of client_debug_mask will be built to hold debug keyword/mask | |
166 | * values fetched from userspace. | |
167 | */ | |
168 | struct client_debug_mask { | |
169 | char *keyword; | |
170 | __u64 mask1; | |
171 | __u64 mask2; | |
172 | }; | |
173 | ||
174 | /* | |
175 | * pvfs2 kernel memory related flags | |
176 | */ | |
177 | ||
178 | #if ((defined PVFS2_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) | |
179 | #define PVFS2_CACHE_CREATE_FLAGS SLAB_RED_ZONE | |
180 | #else | |
181 | #define PVFS2_CACHE_CREATE_FLAGS 0 | |
182 | #endif /* ((defined PVFS2_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) */ | |
183 | ||
184 | #define PVFS2_CACHE_ALLOC_FLAGS (GFP_KERNEL) | |
185 | #define PVFS2_GFP_FLAGS (GFP_KERNEL) | |
186 | #define PVFS2_BUFMAP_GFP_FLAGS (GFP_KERNEL) | |
187 | ||
188 | #define pvfs2_kmap(page) kmap(page) | |
189 | #define pvfs2_kunmap(page) kunmap(page) | |
190 | ||
191 | /* pvfs2 xattr and acl related defines */ | |
192 | #define PVFS2_XATTR_INDEX_POSIX_ACL_ACCESS 1 | |
193 | #define PVFS2_XATTR_INDEX_POSIX_ACL_DEFAULT 2 | |
194 | #define PVFS2_XATTR_INDEX_TRUSTED 3 | |
195 | #define PVFS2_XATTR_INDEX_DEFAULT 4 | |
196 | ||
197 | #if 0 | |
198 | #ifndef POSIX_ACL_XATTR_ACCESS | |
199 | #define POSIX_ACL_XATTR_ACCESS "system.posix_acl_access" | |
200 | #endif | |
201 | #ifndef POSIX_ACL_XATTR_DEFAULT | |
202 | #define POSIX_ACL_XATTR_DEFAULT "system.posix_acl_default" | |
203 | #endif | |
204 | #endif | |
205 | ||
206 | #define PVFS2_XATTR_NAME_ACL_ACCESS POSIX_ACL_XATTR_ACCESS | |
207 | #define PVFS2_XATTR_NAME_ACL_DEFAULT POSIX_ACL_XATTR_DEFAULT | |
208 | #define PVFS2_XATTR_NAME_TRUSTED_PREFIX "trusted." | |
209 | #define PVFS2_XATTR_NAME_DEFAULT_PREFIX "" | |
210 | ||
211 | /* these functions are defined in pvfs2-utils.c */ | |
212 | int orangefs_prepare_cdm_array(char *debug_array_string); | |
213 | int orangefs_prepare_debugfs_help_string(int); | |
214 | ||
215 | /* defined in pvfs2-debugfs.c */ | |
216 | int pvfs2_client_debug_init(void); | |
217 | ||
218 | void debug_string_to_mask(char *, void *, int); | |
219 | void do_c_mask(int, char *, struct client_debug_mask **); | |
220 | void do_k_mask(int, char *, __u64 **); | |
221 | ||
222 | void debug_mask_to_string(void *, int); | |
223 | void do_k_string(void *, int); | |
224 | void do_c_string(void *, int); | |
225 | int check_amalgam_keyword(void *, int); | |
226 | int keyword_is_amalgam(char *); | |
227 | ||
228 | /*these variables are defined in pvfs2-mod.c */ | |
229 | extern char kernel_debug_string[PVFS2_MAX_DEBUG_STRING_LEN]; | |
230 | extern char client_debug_string[PVFS2_MAX_DEBUG_STRING_LEN]; | |
231 | extern char client_debug_array_string[PVFS2_MAX_DEBUG_STRING_LEN]; | |
232 | /* HELLO | |
233 | extern struct client_debug_mask current_client_mask; | |
234 | */ | |
235 | extern unsigned int kernel_mask_set_mod_init; | |
236 | ||
237 | extern int pvfs2_init_acl(struct inode *inode, struct inode *dir); | |
238 | extern const struct xattr_handler *pvfs2_xattr_handlers[]; | |
239 | ||
240 | extern struct posix_acl *pvfs2_get_acl(struct inode *inode, int type); | |
241 | extern int pvfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type); | |
242 | ||
243 | int pvfs2_xattr_set_default(struct dentry *dentry, | |
244 | const char *name, | |
245 | const void *buffer, | |
246 | size_t size, | |
247 | int flags, | |
248 | int handler_flags); | |
249 | ||
250 | int pvfs2_xattr_get_default(struct dentry *dentry, | |
251 | const char *name, | |
252 | void *buffer, | |
253 | size_t size, | |
254 | int handler_flags); | |
255 | ||
256 | /* | |
257 | * Redefine xtvec structure so that we could move helper functions out of | |
258 | * the define | |
259 | */ | |
260 | struct xtvec { | |
261 | __kernel_off_t xtv_off; /* must be off_t */ | |
262 | __kernel_size_t xtv_len; /* must be size_t */ | |
263 | }; | |
264 | ||
265 | /* | |
266 | * pvfs2 data structures | |
267 | */ | |
268 | struct pvfs2_kernel_op_s { | |
269 | enum pvfs2_vfs_op_states op_state; | |
270 | __u64 tag; | |
271 | ||
272 | /* | |
273 | * Set uses_shared_memory to 1 if this operation uses shared memory. | |
274 | * If true, then a retry on the op must also get a new shared memory | |
275 | * buffer and re-populate it. | |
276 | */ | |
277 | int uses_shared_memory; | |
278 | ||
279 | struct pvfs2_upcall_s upcall; | |
280 | struct pvfs2_downcall_s downcall; | |
281 | ||
282 | wait_queue_head_t waitq; | |
283 | spinlock_t lock; | |
284 | ||
285 | int io_completed; | |
286 | wait_queue_head_t io_completion_waitq; | |
287 | ||
288 | /* | |
289 | * upcalls requiring variable length trailers require that this struct | |
290 | * be in the request list even after client-core does a read() on the | |
291 | * device to dequeue the upcall. | |
292 | * if op_linger field goes to 0, we dequeue this op off the list. | |
293 | * else we let it stay. What gets passed to the read() is | |
294 | * a) if op_linger field is = 1, pvfs2_kernel_op_s itself | |
295 | * b) else if = 0, we pass ->upcall.trailer_buf | |
296 | * We expect to have only a single upcall trailer buffer, | |
297 | * so we expect callers with trailers | |
298 | * to set this field to 2 and others to set it to 1. | |
299 | */ | |
300 | __s32 op_linger, op_linger_tmp; | |
301 | /* VFS aio fields */ | |
302 | ||
303 | /* used by the async I/O code to stash the pvfs2_kiocb_s structure */ | |
304 | void *priv; | |
305 | ||
306 | /* used again for the async I/O code for deallocation */ | |
307 | atomic_t aio_ref_count; | |
308 | ||
309 | int attempts; | |
310 | ||
311 | struct list_head list; | |
312 | }; | |
313 | ||
314 | /* per inode private pvfs2 info */ | |
315 | struct pvfs2_inode_s { | |
316 | struct pvfs2_object_kref refn; | |
317 | char link_target[PVFS_NAME_MAX]; | |
318 | __s64 blksize; | |
319 | /* | |
320 | * Reading/Writing Extended attributes need to acquire the appropriate | |
321 | * reader/writer semaphore on the pvfs2_inode_s structure. | |
322 | */ | |
323 | struct rw_semaphore xattr_sem; | |
324 | ||
325 | struct inode vfs_inode; | |
326 | sector_t last_failed_block_index_read; | |
327 | ||
328 | /* | |
329 | * State of in-memory attributes not yet flushed to disk associated | |
330 | * with this object | |
331 | */ | |
332 | unsigned long pinode_flags; | |
333 | ||
334 | /* All allocated pvfs2_inode_s objects are chained to a list */ | |
335 | struct list_head list; | |
336 | }; | |
337 | ||
338 | #define P_ATIME_FLAG 0 | |
339 | #define P_MTIME_FLAG 1 | |
340 | #define P_CTIME_FLAG 2 | |
341 | #define P_MODE_FLAG 3 | |
342 | ||
343 | #define ClearAtimeFlag(pinode) clear_bit(P_ATIME_FLAG, &(pinode)->pinode_flags) | |
344 | #define SetAtimeFlag(pinode) set_bit(P_ATIME_FLAG, &(pinode)->pinode_flags) | |
345 | #define AtimeFlag(pinode) test_bit(P_ATIME_FLAG, &(pinode)->pinode_flags) | |
346 | ||
347 | #define ClearMtimeFlag(pinode) clear_bit(P_MTIME_FLAG, &(pinode)->pinode_flags) | |
348 | #define SetMtimeFlag(pinode) set_bit(P_MTIME_FLAG, &(pinode)->pinode_flags) | |
349 | #define MtimeFlag(pinode) test_bit(P_MTIME_FLAG, &(pinode)->pinode_flags) | |
350 | ||
351 | #define ClearCtimeFlag(pinode) clear_bit(P_CTIME_FLAG, &(pinode)->pinode_flags) | |
352 | #define SetCtimeFlag(pinode) set_bit(P_CTIME_FLAG, &(pinode)->pinode_flags) | |
353 | #define CtimeFlag(pinode) test_bit(P_CTIME_FLAG, &(pinode)->pinode_flags) | |
354 | ||
355 | #define ClearModeFlag(pinode) clear_bit(P_MODE_FLAG, &(pinode)->pinode_flags) | |
356 | #define SetModeFlag(pinode) set_bit(P_MODE_FLAG, &(pinode)->pinode_flags) | |
357 | #define ModeFlag(pinode) test_bit(P_MODE_FLAG, &(pinode)->pinode_flags) | |
358 | ||
359 | /* per superblock private pvfs2 info */ | |
360 | struct pvfs2_sb_info_s { | |
361 | struct pvfs2_khandle root_khandle; | |
362 | __s32 fs_id; | |
363 | int id; | |
364 | int flags; | |
365 | #define PVFS2_OPT_INTR 0x01 | |
366 | #define PVFS2_OPT_LOCAL_LOCK 0x02 | |
367 | char devname[PVFS_MAX_SERVER_ADDR_LEN]; | |
368 | struct super_block *sb; | |
369 | int mount_pending; | |
370 | struct list_head list; | |
371 | }; | |
372 | ||
373 | /* | |
374 | * a temporary structure used only for sb mount time that groups the | |
375 | * mount time data provided along with a private superblock structure | |
376 | * that is allocated before a 'kernel' superblock is allocated. | |
377 | */ | |
378 | struct pvfs2_mount_sb_info_s { | |
379 | void *data; | |
380 | struct pvfs2_khandle root_khandle; | |
381 | __s32 fs_id; | |
382 | int id; | |
383 | }; | |
384 | ||
385 | /* | |
386 | * structure that holds the state of any async I/O operation issued | |
387 | * through the VFS. Needed especially to handle cancellation requests | |
388 | * or even completion notification so that the VFS client-side daemon | |
389 | * can free up its vfs_request slots. | |
390 | */ | |
391 | struct pvfs2_kiocb_s { | |
392 | /* the pointer to the task that initiated the AIO */ | |
393 | struct task_struct *tsk; | |
394 | ||
395 | /* pointer to the kiocb that kicked this operation */ | |
396 | struct kiocb *kiocb; | |
397 | ||
398 | /* buffer index that was used for the I/O */ | |
399 | struct pvfs2_bufmap *bufmap; | |
400 | int buffer_index; | |
401 | ||
402 | /* pvfs2 kernel operation type */ | |
403 | struct pvfs2_kernel_op_s *op; | |
404 | ||
405 | /* The user space buffers from/to which I/O is being staged */ | |
406 | struct iovec *iov; | |
407 | ||
408 | /* number of elements in the iovector */ | |
409 | unsigned long nr_segs; | |
410 | ||
411 | /* set to indicate the type of the operation */ | |
412 | int rw; | |
413 | ||
414 | /* file offset */ | |
415 | loff_t offset; | |
416 | ||
417 | /* and the count in bytes */ | |
418 | size_t bytes_to_be_copied; | |
419 | ||
420 | ssize_t bytes_copied; | |
421 | int needs_cleanup; | |
422 | }; | |
423 | ||
424 | struct pvfs2_stats { | |
425 | unsigned long cache_hits; | |
426 | unsigned long cache_misses; | |
427 | unsigned long reads; | |
428 | unsigned long writes; | |
429 | }; | |
430 | ||
431 | extern struct pvfs2_stats g_pvfs2_stats; | |
432 | ||
433 | /* | |
434 | NOTE: See Documentation/filesystems/porting for information | |
435 | on implementing FOO_I and properly accessing fs private data | |
436 | */ | |
437 | static inline struct pvfs2_inode_s *PVFS2_I(struct inode *inode) | |
438 | { | |
439 | return container_of(inode, struct pvfs2_inode_s, vfs_inode); | |
440 | } | |
441 | ||
442 | static inline struct pvfs2_sb_info_s *PVFS2_SB(struct super_block *sb) | |
443 | { | |
444 | return (struct pvfs2_sb_info_s *) sb->s_fs_info; | |
445 | } | |
446 | ||
447 | /* ino_t descends from "unsigned long", 8 bytes, 64 bits. */ | |
448 | static inline ino_t pvfs2_khandle_to_ino(struct pvfs2_khandle *khandle) | |
449 | { | |
450 | union { | |
451 | unsigned char u[8]; | |
452 | __u64 ino; | |
453 | } ihandle; | |
454 | ||
455 | ihandle.u[0] = khandle->u[0] ^ khandle->u[4]; | |
456 | ihandle.u[1] = khandle->u[1] ^ khandle->u[5]; | |
457 | ihandle.u[2] = khandle->u[2] ^ khandle->u[6]; | |
458 | ihandle.u[3] = khandle->u[3] ^ khandle->u[7]; | |
459 | ihandle.u[4] = khandle->u[12] ^ khandle->u[8]; | |
460 | ihandle.u[5] = khandle->u[13] ^ khandle->u[9]; | |
461 | ihandle.u[6] = khandle->u[14] ^ khandle->u[10]; | |
462 | ihandle.u[7] = khandle->u[15] ^ khandle->u[11]; | |
463 | ||
464 | return ihandle.ino; | |
465 | } | |
466 | ||
467 | static inline struct pvfs2_khandle *get_khandle_from_ino(struct inode *inode) | |
468 | { | |
469 | return &(PVFS2_I(inode)->refn.khandle); | |
470 | } | |
471 | ||
472 | static inline __s32 get_fsid_from_ino(struct inode *inode) | |
473 | { | |
474 | return PVFS2_I(inode)->refn.fs_id; | |
475 | } | |
476 | ||
477 | static inline ino_t get_ino_from_khandle(struct inode *inode) | |
478 | { | |
479 | struct pvfs2_khandle *khandle; | |
480 | ino_t ino; | |
481 | ||
482 | khandle = get_khandle_from_ino(inode); | |
483 | ino = pvfs2_khandle_to_ino(khandle); | |
484 | return ino; | |
485 | } | |
486 | ||
487 | static inline ino_t get_parent_ino_from_dentry(struct dentry *dentry) | |
488 | { | |
489 | return get_ino_from_khandle(dentry->d_parent->d_inode); | |
490 | } | |
491 | ||
492 | static inline int is_root_handle(struct inode *inode) | |
493 | { | |
494 | gossip_debug(GOSSIP_DCACHE_DEBUG, | |
495 | "%s: root handle: %pU, this handle: %pU:\n", | |
496 | __func__, | |
497 | &PVFS2_SB(inode->i_sb)->root_khandle, | |
498 | get_khandle_from_ino(inode)); | |
499 | ||
500 | if (PVFS_khandle_cmp(&(PVFS2_SB(inode->i_sb)->root_khandle), | |
501 | get_khandle_from_ino(inode))) | |
502 | return 0; | |
503 | else | |
504 | return 1; | |
505 | } | |
506 | ||
507 | static inline int match_handle(struct pvfs2_khandle resp_handle, | |
508 | struct inode *inode) | |
509 | { | |
510 | gossip_debug(GOSSIP_DCACHE_DEBUG, | |
511 | "%s: one handle: %pU, another handle:%pU:\n", | |
512 | __func__, | |
513 | &resp_handle, | |
514 | get_khandle_from_ino(inode)); | |
515 | ||
516 | if (PVFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode))) | |
517 | return 0; | |
518 | else | |
519 | return 1; | |
520 | } | |
521 | ||
522 | /* | |
523 | * defined in pvfs2-cache.c | |
524 | */ | |
525 | int op_cache_initialize(void); | |
526 | int op_cache_finalize(void); | |
527 | struct pvfs2_kernel_op_s *op_alloc(__s32 type); | |
528 | struct pvfs2_kernel_op_s *op_alloc_trailer(__s32 type); | |
529 | char *get_opname_string(struct pvfs2_kernel_op_s *new_op); | |
530 | void op_release(struct pvfs2_kernel_op_s *op); | |
531 | ||
532 | int dev_req_cache_initialize(void); | |
533 | int dev_req_cache_finalize(void); | |
534 | void *dev_req_alloc(void); | |
535 | void dev_req_release(void *); | |
536 | ||
537 | int pvfs2_inode_cache_initialize(void); | |
538 | int pvfs2_inode_cache_finalize(void); | |
539 | ||
540 | int kiocb_cache_initialize(void); | |
541 | int kiocb_cache_finalize(void); | |
542 | struct pvfs2_kiocb_s *kiocb_alloc(void); | |
543 | void kiocb_release(struct pvfs2_kiocb_s *ptr); | |
544 | ||
545 | /* | |
546 | * defined in pvfs2-mod.c | |
547 | */ | |
548 | void purge_inprogress_ops(void); | |
549 | ||
550 | /* | |
551 | * defined in waitqueue.c | |
552 | */ | |
553 | int wait_for_matching_downcall(struct pvfs2_kernel_op_s *op); | |
554 | int wait_for_cancellation_downcall(struct pvfs2_kernel_op_s *op); | |
555 | void pvfs2_clean_up_interrupted_operation(struct pvfs2_kernel_op_s *op); | |
556 | void purge_waiting_ops(void); | |
557 | ||
558 | /* | |
559 | * defined in super.c | |
560 | */ | |
561 | struct dentry *pvfs2_mount(struct file_system_type *fst, | |
562 | int flags, | |
563 | const char *devname, | |
564 | void *data); | |
565 | ||
566 | void pvfs2_kill_sb(struct super_block *sb); | |
567 | int pvfs2_remount(struct super_block *sb); | |
568 | ||
569 | int fsid_key_table_initialize(void); | |
570 | void fsid_key_table_finalize(void); | |
571 | ||
572 | /* | |
573 | * defined in inode.c | |
574 | */ | |
575 | __u32 convert_to_pvfs2_mask(unsigned long lite_mask); | |
576 | struct inode *pvfs2_new_inode(struct super_block *sb, | |
577 | struct inode *dir, | |
578 | int mode, | |
579 | dev_t dev, | |
580 | struct pvfs2_object_kref *ref); | |
581 | ||
582 | int pvfs2_setattr(struct dentry *dentry, struct iattr *iattr); | |
583 | ||
584 | int pvfs2_getattr(struct vfsmount *mnt, | |
585 | struct dentry *dentry, | |
586 | struct kstat *kstat); | |
587 | ||
588 | /* | |
589 | * defined in xattr.c | |
590 | */ | |
591 | int pvfs2_setxattr(struct dentry *dentry, | |
592 | const char *name, | |
593 | const void *value, | |
594 | size_t size, | |
595 | int flags); | |
596 | ||
597 | ssize_t pvfs2_getxattr(struct dentry *dentry, | |
598 | const char *name, | |
599 | void *buffer, | |
600 | size_t size); | |
601 | ||
602 | ssize_t pvfs2_listxattr(struct dentry *dentry, char *buffer, size_t size); | |
603 | ||
604 | /* | |
605 | * defined in namei.c | |
606 | */ | |
607 | struct inode *pvfs2_iget(struct super_block *sb, | |
608 | struct pvfs2_object_kref *ref); | |
609 | ||
610 | ssize_t pvfs2_inode_read(struct inode *inode, | |
611 | char *buf, | |
612 | size_t count, | |
613 | loff_t *offset, | |
614 | loff_t readahead_size); | |
615 | ||
616 | /* | |
617 | * defined in devpvfs2-req.c | |
618 | */ | |
619 | int pvfs2_dev_init(void); | |
620 | void pvfs2_dev_cleanup(void); | |
621 | int is_daemon_in_service(void); | |
622 | int fs_mount_pending(__s32 fsid); | |
623 | ||
624 | /* | |
625 | * defined in pvfs2-utils.c | |
626 | */ | |
627 | __s32 fsid_of_op(struct pvfs2_kernel_op_s *op); | |
628 | ||
629 | int pvfs2_flush_inode(struct inode *inode); | |
630 | ||
631 | ssize_t pvfs2_inode_getxattr(struct inode *inode, | |
632 | const char *prefix, | |
633 | const char *name, | |
634 | void *buffer, | |
635 | size_t size); | |
636 | ||
637 | int pvfs2_inode_setxattr(struct inode *inode, | |
638 | const char *prefix, | |
639 | const char *name, | |
640 | const void *value, | |
641 | size_t size, | |
642 | int flags); | |
643 | ||
644 | int pvfs2_inode_getattr(struct inode *inode, __u32 mask); | |
645 | ||
646 | int pvfs2_inode_setattr(struct inode *inode, struct iattr *iattr); | |
647 | ||
648 | void pvfs2_op_initialize(struct pvfs2_kernel_op_s *op); | |
649 | ||
650 | void pvfs2_make_bad_inode(struct inode *inode); | |
651 | ||
652 | void mask_blocked_signals(sigset_t *orig_sigset); | |
653 | ||
654 | void unmask_blocked_signals(sigset_t *orig_sigset); | |
655 | ||
656 | int pvfs2_unmount_sb(struct super_block *sb); | |
657 | ||
658 | int pvfs2_cancel_op_in_progress(__u64 tag); | |
659 | ||
660 | __u64 pvfs2_convert_time_field(void *time_ptr); | |
661 | ||
662 | int pvfs2_normalize_to_errno(__s32 error_code); | |
663 | ||
664 | extern struct mutex devreq_mutex; | |
665 | extern struct mutex request_mutex; | |
666 | extern int debug; | |
667 | extern int op_timeout_secs; | |
668 | extern int slot_timeout_secs; | |
669 | extern struct list_head pvfs2_superblocks; | |
670 | extern spinlock_t pvfs2_superblocks_lock; | |
671 | extern struct list_head pvfs2_request_list; | |
672 | extern spinlock_t pvfs2_request_list_lock; | |
673 | extern wait_queue_head_t pvfs2_request_list_waitq; | |
674 | extern struct list_head *htable_ops_in_progress; | |
675 | extern spinlock_t htable_ops_in_progress_lock; | |
676 | extern int hash_table_size; | |
677 | ||
678 | extern const struct address_space_operations pvfs2_address_operations; | |
679 | extern struct backing_dev_info pvfs2_backing_dev_info; | |
680 | extern struct inode_operations pvfs2_file_inode_operations; | |
681 | extern const struct file_operations pvfs2_file_operations; | |
682 | extern struct inode_operations pvfs2_symlink_inode_operations; | |
683 | extern struct inode_operations pvfs2_dir_inode_operations; | |
684 | extern const struct file_operations pvfs2_dir_operations; | |
685 | extern const struct dentry_operations pvfs2_dentry_operations; | |
686 | extern const struct file_operations pvfs2_devreq_file_operations; | |
687 | ||
688 | extern wait_queue_head_t pvfs2_bufmap_init_waitq; | |
689 | ||
690 | /* | |
691 | * misc convenience macros | |
692 | */ | |
693 | #define add_op_to_request_list(op) \ | |
694 | do { \ | |
695 | spin_lock(&pvfs2_request_list_lock); \ | |
696 | spin_lock(&op->lock); \ | |
697 | set_op_state_waiting(op); \ | |
698 | list_add_tail(&op->list, &pvfs2_request_list); \ | |
699 | spin_unlock(&pvfs2_request_list_lock); \ | |
700 | spin_unlock(&op->lock); \ | |
701 | wake_up_interruptible(&pvfs2_request_list_waitq); \ | |
702 | } while (0) | |
703 | ||
704 | #define add_priority_op_to_request_list(op) \ | |
705 | do { \ | |
706 | spin_lock(&pvfs2_request_list_lock); \ | |
707 | spin_lock(&op->lock); \ | |
708 | set_op_state_waiting(op); \ | |
709 | \ | |
710 | list_add(&op->list, &pvfs2_request_list); \ | |
711 | spin_unlock(&pvfs2_request_list_lock); \ | |
712 | spin_unlock(&op->lock); \ | |
713 | wake_up_interruptible(&pvfs2_request_list_waitq); \ | |
714 | } while (0) | |
715 | ||
716 | #define remove_op_from_request_list(op) \ | |
717 | do { \ | |
718 | struct list_head *tmp = NULL; \ | |
719 | struct list_head *tmp_safe = NULL; \ | |
720 | struct pvfs2_kernel_op_s *tmp_op = NULL; \ | |
721 | \ | |
722 | spin_lock(&pvfs2_request_list_lock); \ | |
723 | list_for_each_safe(tmp, tmp_safe, &pvfs2_request_list) { \ | |
724 | tmp_op = list_entry(tmp, \ | |
725 | struct pvfs2_kernel_op_s, \ | |
726 | list); \ | |
727 | if (tmp_op && (tmp_op == op)) { \ | |
728 | list_del(&tmp_op->list); \ | |
729 | break; \ | |
730 | } \ | |
731 | } \ | |
732 | spin_unlock(&pvfs2_request_list_lock); \ | |
733 | } while (0) | |
734 | ||
735 | #define PVFS2_OP_INTERRUPTIBLE 1 /* service_operation() is interruptible */ | |
736 | #define PVFS2_OP_PRIORITY 2 /* service_operation() is high priority */ | |
737 | #define PVFS2_OP_CANCELLATION 4 /* this is a cancellation */ | |
738 | #define PVFS2_OP_NO_SEMAPHORE 8 /* don't acquire semaphore */ | |
739 | #define PVFS2_OP_ASYNC 16 /* Queue it, but don't wait */ | |
740 | ||
741 | int service_operation(struct pvfs2_kernel_op_s *op, | |
742 | const char *op_name, | |
743 | int flags); | |
744 | ||
745 | /* | |
746 | * handles two possible error cases, depending on context. | |
747 | * | |
748 | * by design, our vfs i/o errors need to be handled in one of two ways, | |
749 | * depending on where the error occured. | |
750 | * | |
751 | * if the error happens in the waitqueue code because we either timed | |
752 | * out or a signal was raised while waiting, we need to cancel the | |
753 | * userspace i/o operation and free the op manually. this is done to | |
754 | * avoid having the device start writing application data to our shared | |
755 | * bufmap pages without us expecting it. | |
756 | * | |
757 | * FIXME: POSSIBLE OPTIMIZATION: | |
758 | * However, if we timed out or if we got a signal AND our upcall was never | |
759 | * picked off the queue (i.e. we were in OP_VFS_STATE_WAITING), then we don't | |
760 | * need to send a cancellation upcall. The way we can handle this is | |
761 | * set error_exit to 2 in such cases and 1 whenever cancellation has to be | |
762 | * sent and have handle_error | |
763 | * take care of this situation as well.. | |
764 | * | |
765 | * if a pvfs2 sysint level error occured and i/o has been completed, | |
766 | * there is no need to cancel the operation, as the user has finished | |
767 | * using the bufmap page and so there is no danger in this case. in | |
768 | * this case, we wake up the device normally so that it may free the | |
769 | * op, as normal. | |
770 | * | |
771 | * note the only reason this is a macro is because both read and write | |
772 | * cases need the exact same handling code. | |
773 | */ | |
774 | #define handle_io_error() \ | |
775 | do { \ | |
776 | if (!op_state_serviced(new_op)) { \ | |
777 | pvfs2_cancel_op_in_progress(new_op->tag); \ | |
778 | op_release(new_op); \ | |
779 | } else { \ | |
780 | wake_up_daemon_for_return(new_op); \ | |
781 | } \ | |
782 | new_op = NULL; \ | |
783 | pvfs_bufmap_put(bufmap, buffer_index); \ | |
784 | buffer_index = -1; \ | |
785 | } while (0) | |
786 | ||
787 | #define get_interruptible_flag(inode) \ | |
788 | ((PVFS2_SB(inode->i_sb)->flags & PVFS2_OPT_INTR) ? \ | |
789 | PVFS2_OP_INTERRUPTIBLE : 0) | |
790 | ||
791 | #define add_pvfs2_sb(sb) \ | |
792 | do { \ | |
793 | gossip_debug(GOSSIP_SUPER_DEBUG, \ | |
794 | "Adding SB %p to pvfs2 superblocks\n", \ | |
795 | PVFS2_SB(sb)); \ | |
796 | spin_lock(&pvfs2_superblocks_lock); \ | |
797 | list_add_tail(&PVFS2_SB(sb)->list, &pvfs2_superblocks); \ | |
798 | spin_unlock(&pvfs2_superblocks_lock); \ | |
799 | } while (0) | |
800 | ||
801 | #define remove_pvfs2_sb(sb) \ | |
802 | do { \ | |
803 | struct list_head *tmp = NULL; \ | |
804 | struct list_head *tmp_safe = NULL; \ | |
805 | struct pvfs2_sb_info_s *pvfs2_sb = NULL; \ | |
806 | \ | |
807 | spin_lock(&pvfs2_superblocks_lock); \ | |
808 | list_for_each_safe(tmp, tmp_safe, &pvfs2_superblocks) { \ | |
809 | pvfs2_sb = list_entry(tmp, \ | |
810 | struct pvfs2_sb_info_s, \ | |
811 | list); \ | |
812 | if (pvfs2_sb && (pvfs2_sb->sb == sb)) { \ | |
813 | gossip_debug(GOSSIP_SUPER_DEBUG, \ | |
814 | "Removing SB %p from pvfs2 superblocks\n", \ | |
815 | pvfs2_sb); \ | |
816 | list_del(&pvfs2_sb->list); \ | |
817 | break; \ | |
818 | } \ | |
819 | } \ | |
820 | spin_unlock(&pvfs2_superblocks_lock); \ | |
821 | } while (0) | |
822 | ||
823 | #define pvfs2_lock_inode(inode) spin_lock(&inode->i_lock) | |
824 | #define pvfs2_unlock_inode(inode) spin_unlock(&inode->i_lock) | |
825 | #define pvfs2_current_signal_lock current->sighand->siglock | |
826 | #define pvfs2_current_sigaction current->sighand->action | |
827 | ||
828 | #define fill_default_sys_attrs(sys_attr, type, mode) \ | |
829 | do { \ | |
830 | sys_attr.owner = from_kuid(current_user_ns(), current_fsuid()); \ | |
831 | sys_attr.group = from_kgid(current_user_ns(), current_fsgid()); \ | |
832 | sys_attr.size = 0; \ | |
833 | sys_attr.perms = PVFS_util_translate_mode(mode); \ | |
834 | sys_attr.objtype = type; \ | |
835 | sys_attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; \ | |
836 | } while (0) | |
837 | ||
838 | #define pvfs2_inode_lock(__i) mutex_lock(&(__i)->i_mutex) | |
839 | ||
840 | #define pvfs2_inode_unlock(__i) mutex_unlock(&(__i)->i_mutex) | |
841 | ||
842 | static inline void pvfs2_i_size_write(struct inode *inode, loff_t i_size) | |
843 | { | |
844 | #if BITS_PER_LONG == 32 && defined(CONFIG_SMP) | |
845 | pvfs2_inode_lock(inode); | |
846 | #endif | |
847 | i_size_write(inode, i_size); | |
848 | #if BITS_PER_LONG == 32 && defined(CONFIG_SMP) | |
849 | pvfs2_inode_unlock(inode); | |
850 | #endif | |
851 | } | |
852 | ||
853 | static inline unsigned int diff(struct timeval *end, struct timeval *begin) | |
854 | { | |
855 | if (end->tv_usec < begin->tv_usec) { | |
856 | end->tv_usec += 1000000; | |
857 | end->tv_sec--; | |
858 | } | |
859 | end->tv_sec -= begin->tv_sec; | |
860 | end->tv_usec -= begin->tv_usec; | |
861 | return (end->tv_sec * 1000000) + end->tv_usec; | |
862 | } | |
863 | ||
864 | #endif /* __PVFS2KERNEL_H */ |