4295e263e25b153df3ac42d47571a0242a954d7c
[deliverable/linux.git] / fs / orangefs / pvfs2-kernel.h
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 /* pvfs2 xattr and acl related defines */
189 #define PVFS2_XATTR_INDEX_POSIX_ACL_ACCESS 1
190 #define PVFS2_XATTR_INDEX_POSIX_ACL_DEFAULT 2
191 #define PVFS2_XATTR_INDEX_TRUSTED 3
192 #define PVFS2_XATTR_INDEX_DEFAULT 4
193
194 #if 0
195 #ifndef POSIX_ACL_XATTR_ACCESS
196 #define POSIX_ACL_XATTR_ACCESS "system.posix_acl_access"
197 #endif
198 #ifndef POSIX_ACL_XATTR_DEFAULT
199 #define POSIX_ACL_XATTR_DEFAULT "system.posix_acl_default"
200 #endif
201 #endif
202
203 #define PVFS2_XATTR_NAME_ACL_ACCESS POSIX_ACL_XATTR_ACCESS
204 #define PVFS2_XATTR_NAME_ACL_DEFAULT POSIX_ACL_XATTR_DEFAULT
205 #define PVFS2_XATTR_NAME_TRUSTED_PREFIX "trusted."
206 #define PVFS2_XATTR_NAME_DEFAULT_PREFIX ""
207
208 /* these functions are defined in pvfs2-utils.c */
209 int orangefs_prepare_cdm_array(char *debug_array_string);
210 int orangefs_prepare_debugfs_help_string(int);
211
212 /* defined in pvfs2-debugfs.c */
213 int pvfs2_client_debug_init(void);
214
215 void debug_string_to_mask(char *, void *, int);
216 void do_c_mask(int, char *, struct client_debug_mask **);
217 void do_k_mask(int, char *, __u64 **);
218
219 void debug_mask_to_string(void *, int);
220 void do_k_string(void *, int);
221 void do_c_string(void *, int);
222 int check_amalgam_keyword(void *, int);
223 int keyword_is_amalgam(char *);
224
225 /*these variables are defined in pvfs2-mod.c */
226 extern char kernel_debug_string[PVFS2_MAX_DEBUG_STRING_LEN];
227 extern char client_debug_string[PVFS2_MAX_DEBUG_STRING_LEN];
228 extern char client_debug_array_string[PVFS2_MAX_DEBUG_STRING_LEN];
229 extern unsigned int kernel_mask_set_mod_init;
230
231 extern int pvfs2_init_acl(struct inode *inode, struct inode *dir);
232 extern const struct xattr_handler *pvfs2_xattr_handlers[];
233
234 extern struct posix_acl *pvfs2_get_acl(struct inode *inode, int type);
235 extern int pvfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
236
237 /*
238 * Redefine xtvec structure so that we could move helper functions out of
239 * the define
240 */
241 struct xtvec {
242 __kernel_off_t xtv_off; /* must be off_t */
243 __kernel_size_t xtv_len; /* must be size_t */
244 };
245
246 /*
247 * pvfs2 data structures
248 */
249 struct pvfs2_kernel_op_s {
250 enum pvfs2_vfs_op_states op_state;
251 __u64 tag;
252
253 /*
254 * Set uses_shared_memory to 1 if this operation uses shared memory.
255 * If true, then a retry on the op must also get a new shared memory
256 * buffer and re-populate it.
257 */
258 int uses_shared_memory;
259
260 struct pvfs2_upcall_s upcall;
261 struct pvfs2_downcall_s downcall;
262
263 wait_queue_head_t waitq;
264 spinlock_t lock;
265
266 int io_completed;
267 wait_queue_head_t io_completion_waitq;
268
269 /* VFS aio fields */
270
271 /* used by the async I/O code to stash the pvfs2_kiocb_s structure */
272 void *priv;
273
274 /* used again for the async I/O code for deallocation */
275 atomic_t aio_ref_count;
276
277 int attempts;
278
279 struct list_head list;
280 };
281
282 /* per inode private pvfs2 info */
283 struct pvfs2_inode_s {
284 struct pvfs2_object_kref refn;
285 char link_target[PVFS_NAME_MAX];
286 __s64 blksize;
287 /*
288 * Reading/Writing Extended attributes need to acquire the appropriate
289 * reader/writer semaphore on the pvfs2_inode_s structure.
290 */
291 struct rw_semaphore xattr_sem;
292
293 struct inode vfs_inode;
294 sector_t last_failed_block_index_read;
295
296 /*
297 * State of in-memory attributes not yet flushed to disk associated
298 * with this object
299 */
300 unsigned long pinode_flags;
301
302 /* All allocated pvfs2_inode_s objects are chained to a list */
303 struct list_head list;
304 };
305
306 #define P_ATIME_FLAG 0
307 #define P_MTIME_FLAG 1
308 #define P_CTIME_FLAG 2
309 #define P_MODE_FLAG 3
310
311 #define ClearAtimeFlag(pinode) clear_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
312 #define SetAtimeFlag(pinode) set_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
313 #define AtimeFlag(pinode) test_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
314
315 #define ClearMtimeFlag(pinode) clear_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
316 #define SetMtimeFlag(pinode) set_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
317 #define MtimeFlag(pinode) test_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
318
319 #define ClearCtimeFlag(pinode) clear_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
320 #define SetCtimeFlag(pinode) set_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
321 #define CtimeFlag(pinode) test_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
322
323 #define ClearModeFlag(pinode) clear_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
324 #define SetModeFlag(pinode) set_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
325 #define ModeFlag(pinode) test_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
326
327 /* per superblock private pvfs2 info */
328 struct pvfs2_sb_info_s {
329 struct pvfs2_khandle root_khandle;
330 __s32 fs_id;
331 int id;
332 int flags;
333 #define PVFS2_OPT_INTR 0x01
334 #define PVFS2_OPT_LOCAL_LOCK 0x02
335 char devname[PVFS_MAX_SERVER_ADDR_LEN];
336 struct super_block *sb;
337 int mount_pending;
338 struct list_head list;
339 };
340
341 /*
342 * structure that holds the state of any async I/O operation issued
343 * through the VFS. Needed especially to handle cancellation requests
344 * or even completion notification so that the VFS client-side daemon
345 * can free up its vfs_request slots.
346 */
347 struct pvfs2_kiocb_s {
348 /* the pointer to the task that initiated the AIO */
349 struct task_struct *tsk;
350
351 /* pointer to the kiocb that kicked this operation */
352 struct kiocb *kiocb;
353
354 /* buffer index that was used for the I/O */
355 struct pvfs2_bufmap *bufmap;
356 int buffer_index;
357
358 /* pvfs2 kernel operation type */
359 struct pvfs2_kernel_op_s *op;
360
361 /* The user space buffers from/to which I/O is being staged */
362 struct iovec *iov;
363
364 /* number of elements in the iovector */
365 unsigned long nr_segs;
366
367 /* set to indicate the type of the operation */
368 int rw;
369
370 /* file offset */
371 loff_t offset;
372
373 /* and the count in bytes */
374 size_t bytes_to_be_copied;
375
376 ssize_t bytes_copied;
377 int needs_cleanup;
378 };
379
380 struct pvfs2_stats {
381 unsigned long cache_hits;
382 unsigned long cache_misses;
383 unsigned long reads;
384 unsigned long writes;
385 };
386
387 extern struct pvfs2_stats g_pvfs2_stats;
388
389 /*
390 * NOTE: See Documentation/filesystems/porting for information
391 * on implementing FOO_I and properly accessing fs private data
392 */
393 static inline struct pvfs2_inode_s *PVFS2_I(struct inode *inode)
394 {
395 return container_of(inode, struct pvfs2_inode_s, vfs_inode);
396 }
397
398 static inline struct pvfs2_sb_info_s *PVFS2_SB(struct super_block *sb)
399 {
400 return (struct pvfs2_sb_info_s *) sb->s_fs_info;
401 }
402
403 /* ino_t descends from "unsigned long", 8 bytes, 64 bits. */
404 static inline ino_t pvfs2_khandle_to_ino(struct pvfs2_khandle *khandle)
405 {
406 union {
407 unsigned char u[8];
408 __u64 ino;
409 } ihandle;
410
411 ihandle.u[0] = khandle->u[0] ^ khandle->u[4];
412 ihandle.u[1] = khandle->u[1] ^ khandle->u[5];
413 ihandle.u[2] = khandle->u[2] ^ khandle->u[6];
414 ihandle.u[3] = khandle->u[3] ^ khandle->u[7];
415 ihandle.u[4] = khandle->u[12] ^ khandle->u[8];
416 ihandle.u[5] = khandle->u[13] ^ khandle->u[9];
417 ihandle.u[6] = khandle->u[14] ^ khandle->u[10];
418 ihandle.u[7] = khandle->u[15] ^ khandle->u[11];
419
420 return ihandle.ino;
421 }
422
423 static inline struct pvfs2_khandle *get_khandle_from_ino(struct inode *inode)
424 {
425 return &(PVFS2_I(inode)->refn.khandle);
426 }
427
428 static inline __s32 get_fsid_from_ino(struct inode *inode)
429 {
430 return PVFS2_I(inode)->refn.fs_id;
431 }
432
433 static inline ino_t get_ino_from_khandle(struct inode *inode)
434 {
435 struct pvfs2_khandle *khandle;
436 ino_t ino;
437
438 khandle = get_khandle_from_ino(inode);
439 ino = pvfs2_khandle_to_ino(khandle);
440 return ino;
441 }
442
443 static inline ino_t get_parent_ino_from_dentry(struct dentry *dentry)
444 {
445 return get_ino_from_khandle(dentry->d_parent->d_inode);
446 }
447
448 static inline int is_root_handle(struct inode *inode)
449 {
450 gossip_debug(GOSSIP_DCACHE_DEBUG,
451 "%s: root handle: %pU, this handle: %pU:\n",
452 __func__,
453 &PVFS2_SB(inode->i_sb)->root_khandle,
454 get_khandle_from_ino(inode));
455
456 if (PVFS_khandle_cmp(&(PVFS2_SB(inode->i_sb)->root_khandle),
457 get_khandle_from_ino(inode)))
458 return 0;
459 else
460 return 1;
461 }
462
463 static inline int match_handle(struct pvfs2_khandle resp_handle,
464 struct inode *inode)
465 {
466 gossip_debug(GOSSIP_DCACHE_DEBUG,
467 "%s: one handle: %pU, another handle:%pU:\n",
468 __func__,
469 &resp_handle,
470 get_khandle_from_ino(inode));
471
472 if (PVFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode)))
473 return 0;
474 else
475 return 1;
476 }
477
478 /*
479 * defined in pvfs2-cache.c
480 */
481 int op_cache_initialize(void);
482 int op_cache_finalize(void);
483 struct pvfs2_kernel_op_s *op_alloc(__s32 type);
484 char *get_opname_string(struct pvfs2_kernel_op_s *new_op);
485 void op_release(struct pvfs2_kernel_op_s *op);
486
487 int dev_req_cache_initialize(void);
488 int dev_req_cache_finalize(void);
489 void *dev_req_alloc(void);
490 void dev_req_release(void *);
491
492 int pvfs2_inode_cache_initialize(void);
493 int pvfs2_inode_cache_finalize(void);
494
495 int kiocb_cache_initialize(void);
496 int kiocb_cache_finalize(void);
497 struct pvfs2_kiocb_s *kiocb_alloc(void);
498 void kiocb_release(struct pvfs2_kiocb_s *ptr);
499
500 /*
501 * defined in pvfs2-mod.c
502 */
503 void purge_inprogress_ops(void);
504
505 /*
506 * defined in waitqueue.c
507 */
508 int wait_for_matching_downcall(struct pvfs2_kernel_op_s *op);
509 int wait_for_cancellation_downcall(struct pvfs2_kernel_op_s *op);
510 void pvfs2_clean_up_interrupted_operation(struct pvfs2_kernel_op_s *op);
511 void purge_waiting_ops(void);
512
513 /*
514 * defined in super.c
515 */
516 struct dentry *pvfs2_mount(struct file_system_type *fst,
517 int flags,
518 const char *devname,
519 void *data);
520
521 void pvfs2_kill_sb(struct super_block *sb);
522 int pvfs2_remount(struct super_block *sb);
523
524 int fsid_key_table_initialize(void);
525 void fsid_key_table_finalize(void);
526
527 /*
528 * defined in inode.c
529 */
530 __u32 convert_to_pvfs2_mask(unsigned long lite_mask);
531 struct inode *pvfs2_new_inode(struct super_block *sb,
532 struct inode *dir,
533 int mode,
534 dev_t dev,
535 struct pvfs2_object_kref *ref);
536
537 int pvfs2_setattr(struct dentry *dentry, struct iattr *iattr);
538
539 int pvfs2_getattr(struct vfsmount *mnt,
540 struct dentry *dentry,
541 struct kstat *kstat);
542
543 /*
544 * defined in xattr.c
545 */
546 int pvfs2_setxattr(struct dentry *dentry,
547 const char *name,
548 const void *value,
549 size_t size,
550 int flags);
551
552 ssize_t pvfs2_getxattr(struct dentry *dentry,
553 const char *name,
554 void *buffer,
555 size_t size);
556
557 ssize_t pvfs2_listxattr(struct dentry *dentry, char *buffer, size_t size);
558
559 /*
560 * defined in namei.c
561 */
562 struct inode *pvfs2_iget(struct super_block *sb,
563 struct pvfs2_object_kref *ref);
564
565 ssize_t pvfs2_inode_read(struct inode *inode,
566 struct iov_iter *iter,
567 loff_t *offset,
568 loff_t readahead_size);
569
570 /*
571 * defined in devpvfs2-req.c
572 */
573 int pvfs2_dev_init(void);
574 void pvfs2_dev_cleanup(void);
575 int is_daemon_in_service(void);
576 int fs_mount_pending(__s32 fsid);
577
578 /*
579 * defined in pvfs2-utils.c
580 */
581 __s32 fsid_of_op(struct pvfs2_kernel_op_s *op);
582
583 int pvfs2_flush_inode(struct inode *inode);
584
585 ssize_t pvfs2_inode_getxattr(struct inode *inode,
586 const char *prefix,
587 const char *name,
588 void *buffer,
589 size_t size);
590
591 int pvfs2_inode_setxattr(struct inode *inode,
592 const char *prefix,
593 const char *name,
594 const void *value,
595 size_t size,
596 int flags);
597
598 int pvfs2_inode_getattr(struct inode *inode, __u32 mask);
599
600 int pvfs2_inode_setattr(struct inode *inode, struct iattr *iattr);
601
602 void pvfs2_op_initialize(struct pvfs2_kernel_op_s *op);
603
604 void pvfs2_make_bad_inode(struct inode *inode);
605
606 void block_signals(sigset_t *);
607
608 void set_signals(sigset_t *);
609
610 int pvfs2_unmount_sb(struct super_block *sb);
611
612 int pvfs2_cancel_op_in_progress(__u64 tag);
613
614 static inline __u64 pvfs2_convert_time_field(const struct timespec *ts)
615 {
616 return (__u64)ts->tv_sec;
617 }
618
619 int pvfs2_normalize_to_errno(__s32 error_code);
620
621 extern struct mutex devreq_mutex;
622 extern struct mutex request_mutex;
623 extern int debug;
624 extern int op_timeout_secs;
625 extern int slot_timeout_secs;
626 extern struct list_head pvfs2_superblocks;
627 extern spinlock_t pvfs2_superblocks_lock;
628 extern struct list_head pvfs2_request_list;
629 extern spinlock_t pvfs2_request_list_lock;
630 extern wait_queue_head_t pvfs2_request_list_waitq;
631 extern struct list_head *htable_ops_in_progress;
632 extern spinlock_t htable_ops_in_progress_lock;
633 extern int hash_table_size;
634
635 extern const struct address_space_operations pvfs2_address_operations;
636 extern struct backing_dev_info pvfs2_backing_dev_info;
637 extern struct inode_operations pvfs2_file_inode_operations;
638 extern const struct file_operations pvfs2_file_operations;
639 extern struct inode_operations pvfs2_symlink_inode_operations;
640 extern struct inode_operations pvfs2_dir_inode_operations;
641 extern const struct file_operations pvfs2_dir_operations;
642 extern const struct dentry_operations pvfs2_dentry_operations;
643 extern const struct file_operations pvfs2_devreq_file_operations;
644
645 extern wait_queue_head_t pvfs2_bufmap_init_waitq;
646
647 /*
648 * misc convenience macros
649 */
650 #define add_op_to_request_list(op) \
651 do { \
652 spin_lock(&pvfs2_request_list_lock); \
653 spin_lock(&op->lock); \
654 set_op_state_waiting(op); \
655 list_add_tail(&op->list, &pvfs2_request_list); \
656 spin_unlock(&pvfs2_request_list_lock); \
657 spin_unlock(&op->lock); \
658 wake_up_interruptible(&pvfs2_request_list_waitq); \
659 } while (0)
660
661 #define add_priority_op_to_request_list(op) \
662 do { \
663 spin_lock(&pvfs2_request_list_lock); \
664 spin_lock(&op->lock); \
665 set_op_state_waiting(op); \
666 \
667 list_add(&op->list, &pvfs2_request_list); \
668 spin_unlock(&pvfs2_request_list_lock); \
669 spin_unlock(&op->lock); \
670 wake_up_interruptible(&pvfs2_request_list_waitq); \
671 } while (0)
672
673 #define remove_op_from_request_list(op) \
674 do { \
675 struct list_head *tmp = NULL; \
676 struct list_head *tmp_safe = NULL; \
677 struct pvfs2_kernel_op_s *tmp_op = NULL; \
678 \
679 spin_lock(&pvfs2_request_list_lock); \
680 list_for_each_safe(tmp, tmp_safe, &pvfs2_request_list) { \
681 tmp_op = list_entry(tmp, \
682 struct pvfs2_kernel_op_s, \
683 list); \
684 if (tmp_op && (tmp_op == op)) { \
685 list_del(&tmp_op->list); \
686 break; \
687 } \
688 } \
689 spin_unlock(&pvfs2_request_list_lock); \
690 } while (0)
691
692 #define PVFS2_OP_INTERRUPTIBLE 1 /* service_operation() is interruptible */
693 #define PVFS2_OP_PRIORITY 2 /* service_operation() is high priority */
694 #define PVFS2_OP_CANCELLATION 4 /* this is a cancellation */
695 #define PVFS2_OP_NO_SEMAPHORE 8 /* don't acquire semaphore */
696 #define PVFS2_OP_ASYNC 16 /* Queue it, but don't wait */
697
698 int service_operation(struct pvfs2_kernel_op_s *op,
699 const char *op_name,
700 int flags);
701
702 /*
703 * handles two possible error cases, depending on context.
704 *
705 * by design, our vfs i/o errors need to be handled in one of two ways,
706 * depending on where the error occured.
707 *
708 * if the error happens in the waitqueue code because we either timed
709 * out or a signal was raised while waiting, we need to cancel the
710 * userspace i/o operation and free the op manually. this is done to
711 * avoid having the device start writing application data to our shared
712 * bufmap pages without us expecting it.
713 *
714 * FIXME: POSSIBLE OPTIMIZATION:
715 * However, if we timed out or if we got a signal AND our upcall was never
716 * picked off the queue (i.e. we were in OP_VFS_STATE_WAITING), then we don't
717 * need to send a cancellation upcall. The way we can handle this is
718 * set error_exit to 2 in such cases and 1 whenever cancellation has to be
719 * sent and have handle_error
720 * take care of this situation as well..
721 *
722 * if a pvfs2 sysint level error occured and i/o has been completed,
723 * there is no need to cancel the operation, as the user has finished
724 * using the bufmap page and so there is no danger in this case. in
725 * this case, we wake up the device normally so that it may free the
726 * op, as normal.
727 *
728 * note the only reason this is a macro is because both read and write
729 * cases need the exact same handling code.
730 */
731 #define handle_io_error() \
732 do { \
733 if (!op_state_serviced(new_op)) { \
734 pvfs2_cancel_op_in_progress(new_op->tag); \
735 op_release(new_op); \
736 } else { \
737 wake_up_daemon_for_return(new_op); \
738 } \
739 new_op = NULL; \
740 pvfs_bufmap_put(bufmap, buffer_index); \
741 buffer_index = -1; \
742 } while (0)
743
744 #define get_interruptible_flag(inode) \
745 ((PVFS2_SB(inode->i_sb)->flags & PVFS2_OPT_INTR) ? \
746 PVFS2_OP_INTERRUPTIBLE : 0)
747
748 #define add_pvfs2_sb(sb) \
749 do { \
750 gossip_debug(GOSSIP_SUPER_DEBUG, \
751 "Adding SB %p to pvfs2 superblocks\n", \
752 PVFS2_SB(sb)); \
753 spin_lock(&pvfs2_superblocks_lock); \
754 list_add_tail(&PVFS2_SB(sb)->list, &pvfs2_superblocks); \
755 spin_unlock(&pvfs2_superblocks_lock); \
756 } while (0)
757
758 #define remove_pvfs2_sb(sb) \
759 do { \
760 struct list_head *tmp = NULL; \
761 struct list_head *tmp_safe = NULL; \
762 struct pvfs2_sb_info_s *pvfs2_sb = NULL; \
763 \
764 spin_lock(&pvfs2_superblocks_lock); \
765 list_for_each_safe(tmp, tmp_safe, &pvfs2_superblocks) { \
766 pvfs2_sb = list_entry(tmp, \
767 struct pvfs2_sb_info_s, \
768 list); \
769 if (pvfs2_sb && (pvfs2_sb->sb == sb)) { \
770 gossip_debug(GOSSIP_SUPER_DEBUG, \
771 "Removing SB %p from pvfs2 superblocks\n", \
772 pvfs2_sb); \
773 list_del(&pvfs2_sb->list); \
774 break; \
775 } \
776 } \
777 spin_unlock(&pvfs2_superblocks_lock); \
778 } while (0)
779
780 #define pvfs2_lock_inode(inode) spin_lock(&inode->i_lock)
781 #define pvfs2_unlock_inode(inode) spin_unlock(&inode->i_lock)
782
783 #define fill_default_sys_attrs(sys_attr, type, mode) \
784 do { \
785 sys_attr.owner = from_kuid(current_user_ns(), current_fsuid()); \
786 sys_attr.group = from_kgid(current_user_ns(), current_fsgid()); \
787 sys_attr.size = 0; \
788 sys_attr.perms = PVFS_util_translate_mode(mode); \
789 sys_attr.objtype = type; \
790 sys_attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; \
791 } while (0)
792
793 #define pvfs2_inode_lock(__i) mutex_lock(&(__i)->i_mutex)
794
795 #define pvfs2_inode_unlock(__i) mutex_unlock(&(__i)->i_mutex)
796
797 static inline void pvfs2_i_size_write(struct inode *inode, loff_t i_size)
798 {
799 #if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
800 pvfs2_inode_lock(inode);
801 #endif
802 i_size_write(inode, i_size);
803 #if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
804 pvfs2_inode_unlock(inode);
805 #endif
806 }
807
808 static inline unsigned int diff(struct timeval *end, struct timeval *begin)
809 {
810 if (end->tv_usec < begin->tv_usec) {
811 end->tv_usec += 1000000;
812 end->tv_sec--;
813 }
814 end->tv_sec -= begin->tv_sec;
815 end->tv_usec -= begin->tv_usec;
816 return (end->tv_sec * 1000000) + end->tv_usec;
817 }
818
819 #endif /* __PVFS2KERNEL_H */
This page took 0.048415 seconds and 4 git commands to generate.