2 * (C) 2001 Clemson University and The University of Chicago
4 * See COPYING in top-level directory.
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.
15 * Declarations and macros for the PVFS2 Linux kernel support.
18 #ifndef __PVFS2KERNEL_H
19 #define __PVFS2KERNEL_H
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>
34 #include <linux/vmalloc.h>
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>
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>
54 #include <asm/unaligned.h>
56 #include "pvfs2-dev-proto.h"
58 #ifdef PVFS2_KERNEL_DEBUG
59 #define PVFS2_DEFAULT_OP_TIMEOUT_SECS 10
61 #define PVFS2_DEFAULT_OP_TIMEOUT_SECS 20
64 #define PVFS2_BUFMAP_WAIT_TIMEOUT_SECS 30
66 #define PVFS2_DEFAULT_SLOT_TIMEOUT_SECS 900 /* 15 minutes */
68 #define PVFS2_REQDEVICE_NAME "pvfs2-req"
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
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))
83 #define BITS_PER_LONG_DIV_8 (BITS_PER_LONG >> 3)
85 /* borrowed from irda.h */
86 #ifndef MSECS_TO_JIFFIES
87 #define MSECS_TO_JIFFIES(ms) (((ms)*HZ+999)/1000)
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)) - \
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))
107 * valid pvfs2 kernel operation states
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
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,
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)
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)
136 atomic_inc(&(op)->aio_ref_count); \
137 gossip_debug(GOSSIP_DEV_DEBUG, \
138 "(get) Alloced OP (%p:%llu)\n", \
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", \
154 #define op_wait(op) (atomic_read(&(op)->aio_ref_count) <= 2 ? 0 : 1)
157 * Defines for controlling whether I/O upcalls are for async or sync operations
159 enum PVFS_async_io_type {
160 PVFS_VFS_SYNC_IO = 0,
161 PVFS_VFS_ASYNC_IO = 1,
165 * An array of client_debug_mask will be built to hold debug keyword/mask
166 * values fetched from userspace.
168 struct client_debug_mask {
175 * pvfs2 kernel memory related flags
178 #if ((defined PVFS2_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB))
179 #define PVFS2_CACHE_CREATE_FLAGS SLAB_RED_ZONE
181 #define PVFS2_CACHE_CREATE_FLAGS 0
182 #endif /* ((defined PVFS2_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) */
184 #define PVFS2_CACHE_ALLOC_FLAGS (GFP_KERNEL)
185 #define PVFS2_GFP_FLAGS (GFP_KERNEL)
186 #define PVFS2_BUFMAP_GFP_FLAGS (GFP_KERNEL)
188 #define pvfs2_kmap(page) kmap(page)
189 #define pvfs2_kunmap(page) kunmap(page)
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
198 #ifndef POSIX_ACL_XATTR_ACCESS
199 #define POSIX_ACL_XATTR_ACCESS "system.posix_acl_access"
201 #ifndef POSIX_ACL_XATTR_DEFAULT
202 #define POSIX_ACL_XATTR_DEFAULT "system.posix_acl_default"
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 ""
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);
215 /* defined in pvfs2-debugfs.c */
216 int pvfs2_client_debug_init(void);
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 **);
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 *);
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 extern unsigned int kernel_mask_set_mod_init;
234 extern int pvfs2_init_acl(struct inode *inode, struct inode *dir);
235 extern const struct xattr_handler *pvfs2_xattr_handlers[];
237 extern struct posix_acl *pvfs2_get_acl(struct inode *inode, int type);
238 extern int pvfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
240 int pvfs2_xattr_set_default(struct dentry *dentry,
247 int pvfs2_xattr_get_default(struct dentry *dentry,
254 * Redefine xtvec structure so that we could move helper functions out of
258 __kernel_off_t xtv_off; /* must be off_t */
259 __kernel_size_t xtv_len; /* must be size_t */
263 * pvfs2 data structures
265 struct pvfs2_kernel_op_s {
266 enum pvfs2_vfs_op_states op_state;
270 * Set uses_shared_memory to 1 if this operation uses shared memory.
271 * If true, then a retry on the op must also get a new shared memory
272 * buffer and re-populate it.
274 int uses_shared_memory;
276 struct pvfs2_upcall_s upcall;
277 struct pvfs2_downcall_s downcall;
279 wait_queue_head_t waitq;
283 wait_queue_head_t io_completion_waitq;
286 * upcalls requiring variable length trailers require that this struct
287 * be in the request list even after client-core does a read() on the
288 * device to dequeue the upcall.
289 * if op_linger field goes to 0, we dequeue this op off the list.
290 * else we let it stay. What gets passed to the read() is
291 * a) if op_linger field is = 1, pvfs2_kernel_op_s itself
292 * b) else if = 0, we pass ->upcall.trailer_buf
293 * We expect to have only a single upcall trailer buffer,
294 * so we expect callers with trailers
295 * to set this field to 2 and others to set it to 1.
297 __s32 op_linger, op_linger_tmp;
300 /* used by the async I/O code to stash the pvfs2_kiocb_s structure */
303 /* used again for the async I/O code for deallocation */
304 atomic_t aio_ref_count;
308 struct list_head list;
311 /* per inode private pvfs2 info */
312 struct pvfs2_inode_s {
313 struct pvfs2_object_kref refn;
314 char link_target[PVFS_NAME_MAX];
317 * Reading/Writing Extended attributes need to acquire the appropriate
318 * reader/writer semaphore on the pvfs2_inode_s structure.
320 struct rw_semaphore xattr_sem;
322 struct inode vfs_inode;
323 sector_t last_failed_block_index_read;
326 * State of in-memory attributes not yet flushed to disk associated
329 unsigned long pinode_flags;
331 /* All allocated pvfs2_inode_s objects are chained to a list */
332 struct list_head list;
335 #define P_ATIME_FLAG 0
336 #define P_MTIME_FLAG 1
337 #define P_CTIME_FLAG 2
338 #define P_MODE_FLAG 3
340 #define ClearAtimeFlag(pinode) clear_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
341 #define SetAtimeFlag(pinode) set_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
342 #define AtimeFlag(pinode) test_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
344 #define ClearMtimeFlag(pinode) clear_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
345 #define SetMtimeFlag(pinode) set_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
346 #define MtimeFlag(pinode) test_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
348 #define ClearCtimeFlag(pinode) clear_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
349 #define SetCtimeFlag(pinode) set_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
350 #define CtimeFlag(pinode) test_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
352 #define ClearModeFlag(pinode) clear_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
353 #define SetModeFlag(pinode) set_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
354 #define ModeFlag(pinode) test_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
356 /* per superblock private pvfs2 info */
357 struct pvfs2_sb_info_s {
358 struct pvfs2_khandle root_khandle;
362 #define PVFS2_OPT_INTR 0x01
363 #define PVFS2_OPT_LOCAL_LOCK 0x02
364 char devname[PVFS_MAX_SERVER_ADDR_LEN];
365 struct super_block *sb;
367 struct list_head list;
371 * a temporary structure used only for sb mount time that groups the
372 * mount time data provided along with a private superblock structure
373 * that is allocated before a 'kernel' superblock is allocated.
375 struct pvfs2_mount_sb_info_s {
377 struct pvfs2_khandle root_khandle;
383 * structure that holds the state of any async I/O operation issued
384 * through the VFS. Needed especially to handle cancellation requests
385 * or even completion notification so that the VFS client-side daemon
386 * can free up its vfs_request slots.
388 struct pvfs2_kiocb_s {
389 /* the pointer to the task that initiated the AIO */
390 struct task_struct *tsk;
392 /* pointer to the kiocb that kicked this operation */
395 /* buffer index that was used for the I/O */
396 struct pvfs2_bufmap *bufmap;
399 /* pvfs2 kernel operation type */
400 struct pvfs2_kernel_op_s *op;
402 /* The user space buffers from/to which I/O is being staged */
405 /* number of elements in the iovector */
406 unsigned long nr_segs;
408 /* set to indicate the type of the operation */
414 /* and the count in bytes */
415 size_t bytes_to_be_copied;
417 ssize_t bytes_copied;
422 unsigned long cache_hits;
423 unsigned long cache_misses;
425 unsigned long writes;
428 extern struct pvfs2_stats g_pvfs2_stats;
431 * NOTE: See Documentation/filesystems/porting for information
432 * on implementing FOO_I and properly accessing fs private data
434 static inline struct pvfs2_inode_s *PVFS2_I(struct inode *inode)
436 return container_of(inode, struct pvfs2_inode_s, vfs_inode);
439 static inline struct pvfs2_sb_info_s *PVFS2_SB(struct super_block *sb)
441 return (struct pvfs2_sb_info_s *) sb->s_fs_info;
444 /* ino_t descends from "unsigned long", 8 bytes, 64 bits. */
445 static inline ino_t pvfs2_khandle_to_ino(struct pvfs2_khandle *khandle)
452 ihandle.u[0] = khandle->u[0] ^ khandle->u[4];
453 ihandle.u[1] = khandle->u[1] ^ khandle->u[5];
454 ihandle.u[2] = khandle->u[2] ^ khandle->u[6];
455 ihandle.u[3] = khandle->u[3] ^ khandle->u[7];
456 ihandle.u[4] = khandle->u[12] ^ khandle->u[8];
457 ihandle.u[5] = khandle->u[13] ^ khandle->u[9];
458 ihandle.u[6] = khandle->u[14] ^ khandle->u[10];
459 ihandle.u[7] = khandle->u[15] ^ khandle->u[11];
464 static inline struct pvfs2_khandle *get_khandle_from_ino(struct inode *inode)
466 return &(PVFS2_I(inode)->refn.khandle);
469 static inline __s32 get_fsid_from_ino(struct inode *inode)
471 return PVFS2_I(inode)->refn.fs_id;
474 static inline ino_t get_ino_from_khandle(struct inode *inode)
476 struct pvfs2_khandle *khandle;
479 khandle = get_khandle_from_ino(inode);
480 ino = pvfs2_khandle_to_ino(khandle);
484 static inline ino_t get_parent_ino_from_dentry(struct dentry *dentry)
486 return get_ino_from_khandle(dentry->d_parent->d_inode);
489 static inline int is_root_handle(struct inode *inode)
491 gossip_debug(GOSSIP_DCACHE_DEBUG,
492 "%s: root handle: %pU, this handle: %pU:\n",
494 &PVFS2_SB(inode->i_sb)->root_khandle,
495 get_khandle_from_ino(inode));
497 if (PVFS_khandle_cmp(&(PVFS2_SB(inode->i_sb)->root_khandle),
498 get_khandle_from_ino(inode)))
504 static inline int match_handle(struct pvfs2_khandle resp_handle,
507 gossip_debug(GOSSIP_DCACHE_DEBUG,
508 "%s: one handle: %pU, another handle:%pU:\n",
511 get_khandle_from_ino(inode));
513 if (PVFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode)))
520 * defined in pvfs2-cache.c
522 int op_cache_initialize(void);
523 int op_cache_finalize(void);
524 struct pvfs2_kernel_op_s *op_alloc(__s32 type);
525 struct pvfs2_kernel_op_s *op_alloc_trailer(__s32 type);
526 char *get_opname_string(struct pvfs2_kernel_op_s *new_op);
527 void op_release(struct pvfs2_kernel_op_s *op);
529 int dev_req_cache_initialize(void);
530 int dev_req_cache_finalize(void);
531 void *dev_req_alloc(void);
532 void dev_req_release(void *);
534 int pvfs2_inode_cache_initialize(void);
535 int pvfs2_inode_cache_finalize(void);
537 int kiocb_cache_initialize(void);
538 int kiocb_cache_finalize(void);
539 struct pvfs2_kiocb_s *kiocb_alloc(void);
540 void kiocb_release(struct pvfs2_kiocb_s *ptr);
543 * defined in pvfs2-mod.c
545 void purge_inprogress_ops(void);
548 * defined in waitqueue.c
550 int wait_for_matching_downcall(struct pvfs2_kernel_op_s *op);
551 int wait_for_cancellation_downcall(struct pvfs2_kernel_op_s *op);
552 void pvfs2_clean_up_interrupted_operation(struct pvfs2_kernel_op_s *op);
553 void purge_waiting_ops(void);
558 struct dentry *pvfs2_mount(struct file_system_type *fst,
563 void pvfs2_kill_sb(struct super_block *sb);
564 int pvfs2_remount(struct super_block *sb);
566 int fsid_key_table_initialize(void);
567 void fsid_key_table_finalize(void);
572 __u32 convert_to_pvfs2_mask(unsigned long lite_mask);
573 struct inode *pvfs2_new_inode(struct super_block *sb,
577 struct pvfs2_object_kref *ref);
579 int pvfs2_setattr(struct dentry *dentry, struct iattr *iattr);
581 int pvfs2_getattr(struct vfsmount *mnt,
582 struct dentry *dentry,
583 struct kstat *kstat);
588 int pvfs2_setxattr(struct dentry *dentry,
594 ssize_t pvfs2_getxattr(struct dentry *dentry,
599 ssize_t pvfs2_listxattr(struct dentry *dentry, char *buffer, size_t size);
604 struct inode *pvfs2_iget(struct super_block *sb,
605 struct pvfs2_object_kref *ref);
607 ssize_t pvfs2_inode_read(struct inode *inode,
611 loff_t readahead_size);
614 * defined in devpvfs2-req.c
616 int pvfs2_dev_init(void);
617 void pvfs2_dev_cleanup(void);
618 int is_daemon_in_service(void);
619 int fs_mount_pending(__s32 fsid);
622 * defined in pvfs2-utils.c
624 __s32 fsid_of_op(struct pvfs2_kernel_op_s *op);
626 int pvfs2_flush_inode(struct inode *inode);
628 ssize_t pvfs2_inode_getxattr(struct inode *inode,
634 int pvfs2_inode_setxattr(struct inode *inode,
641 int pvfs2_inode_getattr(struct inode *inode, __u32 mask);
643 int pvfs2_inode_setattr(struct inode *inode, struct iattr *iattr);
645 void pvfs2_op_initialize(struct pvfs2_kernel_op_s *op);
647 void pvfs2_make_bad_inode(struct inode *inode);
649 void block_signals(sigset_t *);
651 void set_signals(sigset_t *);
653 int pvfs2_unmount_sb(struct super_block *sb);
655 int pvfs2_cancel_op_in_progress(__u64 tag);
657 __u64 pvfs2_convert_time_field(void *time_ptr);
659 int pvfs2_normalize_to_errno(__s32 error_code);
661 extern struct mutex devreq_mutex;
662 extern struct mutex request_mutex;
664 extern int op_timeout_secs;
665 extern int slot_timeout_secs;
666 extern struct list_head pvfs2_superblocks;
667 extern spinlock_t pvfs2_superblocks_lock;
668 extern struct list_head pvfs2_request_list;
669 extern spinlock_t pvfs2_request_list_lock;
670 extern wait_queue_head_t pvfs2_request_list_waitq;
671 extern struct list_head *htable_ops_in_progress;
672 extern spinlock_t htable_ops_in_progress_lock;
673 extern int hash_table_size;
675 extern const struct address_space_operations pvfs2_address_operations;
676 extern struct backing_dev_info pvfs2_backing_dev_info;
677 extern struct inode_operations pvfs2_file_inode_operations;
678 extern const struct file_operations pvfs2_file_operations;
679 extern struct inode_operations pvfs2_symlink_inode_operations;
680 extern struct inode_operations pvfs2_dir_inode_operations;
681 extern const struct file_operations pvfs2_dir_operations;
682 extern const struct dentry_operations pvfs2_dentry_operations;
683 extern const struct file_operations pvfs2_devreq_file_operations;
685 extern wait_queue_head_t pvfs2_bufmap_init_waitq;
688 * misc convenience macros
690 #define add_op_to_request_list(op) \
692 spin_lock(&pvfs2_request_list_lock); \
693 spin_lock(&op->lock); \
694 set_op_state_waiting(op); \
695 list_add_tail(&op->list, &pvfs2_request_list); \
696 spin_unlock(&pvfs2_request_list_lock); \
697 spin_unlock(&op->lock); \
698 wake_up_interruptible(&pvfs2_request_list_waitq); \
701 #define add_priority_op_to_request_list(op) \
703 spin_lock(&pvfs2_request_list_lock); \
704 spin_lock(&op->lock); \
705 set_op_state_waiting(op); \
707 list_add(&op->list, &pvfs2_request_list); \
708 spin_unlock(&pvfs2_request_list_lock); \
709 spin_unlock(&op->lock); \
710 wake_up_interruptible(&pvfs2_request_list_waitq); \
713 #define remove_op_from_request_list(op) \
715 struct list_head *tmp = NULL; \
716 struct list_head *tmp_safe = NULL; \
717 struct pvfs2_kernel_op_s *tmp_op = NULL; \
719 spin_lock(&pvfs2_request_list_lock); \
720 list_for_each_safe(tmp, tmp_safe, &pvfs2_request_list) { \
721 tmp_op = list_entry(tmp, \
722 struct pvfs2_kernel_op_s, \
724 if (tmp_op && (tmp_op == op)) { \
725 list_del(&tmp_op->list); \
729 spin_unlock(&pvfs2_request_list_lock); \
732 #define PVFS2_OP_INTERRUPTIBLE 1 /* service_operation() is interruptible */
733 #define PVFS2_OP_PRIORITY 2 /* service_operation() is high priority */
734 #define PVFS2_OP_CANCELLATION 4 /* this is a cancellation */
735 #define PVFS2_OP_NO_SEMAPHORE 8 /* don't acquire semaphore */
736 #define PVFS2_OP_ASYNC 16 /* Queue it, but don't wait */
738 int service_operation(struct pvfs2_kernel_op_s *op,
743 * handles two possible error cases, depending on context.
745 * by design, our vfs i/o errors need to be handled in one of two ways,
746 * depending on where the error occured.
748 * if the error happens in the waitqueue code because we either timed
749 * out or a signal was raised while waiting, we need to cancel the
750 * userspace i/o operation and free the op manually. this is done to
751 * avoid having the device start writing application data to our shared
752 * bufmap pages without us expecting it.
754 * FIXME: POSSIBLE OPTIMIZATION:
755 * However, if we timed out or if we got a signal AND our upcall was never
756 * picked off the queue (i.e. we were in OP_VFS_STATE_WAITING), then we don't
757 * need to send a cancellation upcall. The way we can handle this is
758 * set error_exit to 2 in such cases and 1 whenever cancellation has to be
759 * sent and have handle_error
760 * take care of this situation as well..
762 * if a pvfs2 sysint level error occured and i/o has been completed,
763 * there is no need to cancel the operation, as the user has finished
764 * using the bufmap page and so there is no danger in this case. in
765 * this case, we wake up the device normally so that it may free the
768 * note the only reason this is a macro is because both read and write
769 * cases need the exact same handling code.
771 #define handle_io_error() \
773 if (!op_state_serviced(new_op)) { \
774 pvfs2_cancel_op_in_progress(new_op->tag); \
775 op_release(new_op); \
777 wake_up_daemon_for_return(new_op); \
780 pvfs_bufmap_put(bufmap, buffer_index); \
784 #define get_interruptible_flag(inode) \
785 ((PVFS2_SB(inode->i_sb)->flags & PVFS2_OPT_INTR) ? \
786 PVFS2_OP_INTERRUPTIBLE : 0)
788 #define add_pvfs2_sb(sb) \
790 gossip_debug(GOSSIP_SUPER_DEBUG, \
791 "Adding SB %p to pvfs2 superblocks\n", \
793 spin_lock(&pvfs2_superblocks_lock); \
794 list_add_tail(&PVFS2_SB(sb)->list, &pvfs2_superblocks); \
795 spin_unlock(&pvfs2_superblocks_lock); \
798 #define remove_pvfs2_sb(sb) \
800 struct list_head *tmp = NULL; \
801 struct list_head *tmp_safe = NULL; \
802 struct pvfs2_sb_info_s *pvfs2_sb = NULL; \
804 spin_lock(&pvfs2_superblocks_lock); \
805 list_for_each_safe(tmp, tmp_safe, &pvfs2_superblocks) { \
806 pvfs2_sb = list_entry(tmp, \
807 struct pvfs2_sb_info_s, \
809 if (pvfs2_sb && (pvfs2_sb->sb == sb)) { \
810 gossip_debug(GOSSIP_SUPER_DEBUG, \
811 "Removing SB %p from pvfs2 superblocks\n", \
813 list_del(&pvfs2_sb->list); \
817 spin_unlock(&pvfs2_superblocks_lock); \
820 #define pvfs2_lock_inode(inode) spin_lock(&inode->i_lock)
821 #define pvfs2_unlock_inode(inode) spin_unlock(&inode->i_lock)
822 #define pvfs2_current_signal_lock current->sighand->siglock
823 #define pvfs2_current_sigaction current->sighand->action
825 #define fill_default_sys_attrs(sys_attr, type, mode) \
827 sys_attr.owner = from_kuid(current_user_ns(), current_fsuid()); \
828 sys_attr.group = from_kgid(current_user_ns(), current_fsgid()); \
830 sys_attr.perms = PVFS_util_translate_mode(mode); \
831 sys_attr.objtype = type; \
832 sys_attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; \
835 #define pvfs2_inode_lock(__i) mutex_lock(&(__i)->i_mutex)
837 #define pvfs2_inode_unlock(__i) mutex_unlock(&(__i)->i_mutex)
839 static inline void pvfs2_i_size_write(struct inode *inode, loff_t i_size)
841 #if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
842 pvfs2_inode_lock(inode);
844 i_size_write(inode, i_size);
845 #if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
846 pvfs2_inode_unlock(inode);
850 static inline unsigned int diff(struct timeval *end, struct timeval *begin)
852 if (end->tv_usec < begin->tv_usec) {
853 end->tv_usec += 1000000;
856 end->tv_sec -= begin->tv_sec;
857 end->tv_usec -= begin->tv_usec;
858 return (end->tv_sec * 1000000) + end->tv_usec;
861 #endif /* __PVFS2KERNEL_H */