ocfs2/dlm: return zero if deref_done message is successfully handled
[cascardo/linux.git] / fs / orangefs / orangefs-kernel.h
index c337a52..a9925e2 100644 (file)
 #define ORANGEFS_DEVREQ_MAGIC             0x20030529
 #define ORANGEFS_LINK_MAX                 0x000000FF
 #define ORANGEFS_PURGE_RETRY_COUNT     0x00000005
-#define ORANGEFS_SEEK_END              0x00000002
 #define ORANGEFS_MAX_NUM_OPTIONS          0x00000004
 #define ORANGEFS_MAX_MOUNT_OPT_LEN        0x00000080
 #define ORANGEFS_MAX_FSKEY_LEN            64
 
-#define MAX_DEV_REQ_UPSIZE (2*sizeof(__s32) +   \
+#define MAX_DEV_REQ_UPSIZE (2 * sizeof(__s32) +   \
 sizeof(__u64) + sizeof(struct orangefs_upcall_s))
-#define MAX_DEV_REQ_DOWNSIZE (2*sizeof(__s32) + \
+#define MAX_DEV_REQ_DOWNSIZE (2 * sizeof(__s32) + \
 sizeof(__u64) + sizeof(struct orangefs_downcall_s))
 
-/* borrowed from irda.h */
-#ifndef MSECS_TO_JIFFIES
-#define MSECS_TO_JIFFIES(ms) (((ms)*HZ+999)/1000)
-#endif
-
 /*
  * valid orangefs kernel operation states
  *
@@ -94,6 +88,7 @@ sizeof(__u64) + sizeof(struct orangefs_downcall_s))
  * serviced - op has matching downcall; ok
  * purged   - op has to start a timer since client-core
  *            exited uncleanly before servicing op
+ * given up - submitter has given up waiting for it
  */
 enum orangefs_vfs_op_states {
        OP_VFS_STATE_UNKNOWN = 0,
@@ -101,46 +96,7 @@ enum orangefs_vfs_op_states {
        OP_VFS_STATE_INPROGR = 2,
        OP_VFS_STATE_SERVICED = 4,
        OP_VFS_STATE_PURGED = 8,
-};
-
-#define set_op_state_waiting(op)     ((op)->op_state = OP_VFS_STATE_WAITING)
-#define set_op_state_inprogress(op)  ((op)->op_state = OP_VFS_STATE_INPROGR)
-#define set_op_state_serviced(op)    ((op)->op_state = OP_VFS_STATE_SERVICED)
-#define set_op_state_purged(op)      ((op)->op_state |= OP_VFS_STATE_PURGED)
-
-#define op_state_waiting(op)     ((op)->op_state & OP_VFS_STATE_WAITING)
-#define op_state_in_progress(op) ((op)->op_state & OP_VFS_STATE_INPROGR)
-#define op_state_serviced(op)    ((op)->op_state & OP_VFS_STATE_SERVICED)
-#define op_state_purged(op)      ((op)->op_state & OP_VFS_STATE_PURGED)
-
-#define get_op(op)                                     \
-       do {                                            \
-               atomic_inc(&(op)->aio_ref_count);       \
-               gossip_debug(GOSSIP_DEV_DEBUG,  \
-                       "(get) Alloced OP (%p:%llu)\n", \
-                       op,                             \
-                       llu((op)->tag));                \
-       } while (0)
-
-#define put_op(op)                                                     \
-       do {                                                            \
-               if (atomic_sub_and_test(1, &(op)->aio_ref_count) == 1) {  \
-                       gossip_debug(GOSSIP_DEV_DEBUG,          \
-                               "(put) Releasing OP (%p:%llu)\n",       \
-                               op,                                     \
-                               llu((op)->tag));                        \
-                       op_release(op);                                 \
-                       }                                               \
-       } while (0)
-
-#define op_wait(op) (atomic_read(&(op)->aio_ref_count) <= 2 ? 0 : 1)
-
-/*
- * Defines for controlling whether I/O upcalls are for async or sync operations
- */
-enum ORANGEFS_async_io_type {
-       ORANGEFS_VFS_SYNC_IO = 0,
-       ORANGEFS_VFS_ASYNC_IO = 1,
+       OP_VFS_STATE_GIVEN_UP = 16,
 };
 
 /*
@@ -163,27 +119,14 @@ struct client_debug_mask {
 #define ORANGEFS_CACHE_CREATE_FLAGS 0
 #endif /* ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) */
 
-#define ORANGEFS_CACHE_ALLOC_FLAGS (GFP_KERNEL)
-#define ORANGEFS_GFP_FLAGS (GFP_KERNEL)
-#define ORANGEFS_BUFMAP_GFP_FLAGS (GFP_KERNEL)
-
 /* orangefs xattr and acl related defines */
 #define ORANGEFS_XATTR_INDEX_POSIX_ACL_ACCESS  1
 #define ORANGEFS_XATTR_INDEX_POSIX_ACL_DEFAULT 2
 #define ORANGEFS_XATTR_INDEX_TRUSTED           3
 #define ORANGEFS_XATTR_INDEX_DEFAULT           4
 
-#if 0
-#ifndef POSIX_ACL_XATTR_ACCESS
-#define POSIX_ACL_XATTR_ACCESS "system.posix_acl_access"
-#endif
-#ifndef POSIX_ACL_XATTR_DEFAULT
-#define POSIX_ACL_XATTR_DEFAULT        "system.posix_acl_default"
-#endif
-#endif
-
-#define ORANGEFS_XATTR_NAME_ACL_ACCESS  POSIX_ACL_XATTR_ACCESS
-#define ORANGEFS_XATTR_NAME_ACL_DEFAULT POSIX_ACL_XATTR_DEFAULT
+#define ORANGEFS_XATTR_NAME_ACL_ACCESS XATTR_NAME_POSIX_ACL_ACCESS
+#define ORANGEFS_XATTR_NAME_ACL_DEFAULT XATTR_NAME_POSIX_ACL_DEFAULT
 #define ORANGEFS_XATTR_NAME_TRUSTED_PREFIX "trusted."
 #define ORANGEFS_XATTR_NAME_DEFAULT_PREFIX ""
 
@@ -233,33 +176,67 @@ struct orangefs_kernel_op_s {
        __u64 tag;
 
        /*
-        * Set uses_shared_memory to 1 if this operation uses shared memory.
-        * If true, then a retry on the op must also get a new shared memory
-        * buffer and re-populate it.
+        * Set uses_shared_memory to non zero if this operation uses
+        * shared memory. If true, then a retry on the op must also
+        * get a new shared memory buffer and re-populate it.
+        * Cancels don't care - it only matters for service_operation()
+        * retry logics and cancels don't go through it anymore. It
+        * safely stays non-zero when we use it as slot_to_free.
         */
-       int uses_shared_memory;
+       union {
+               int uses_shared_memory;
+               int slot_to_free;
+       };
 
        struct orangefs_upcall_s upcall;
        struct orangefs_downcall_s downcall;
 
-       wait_queue_head_t waitq;
+       struct completion waitq;
        spinlock_t lock;
 
-       int io_completed;
-       wait_queue_head_t io_completion_waitq;
+       int attempts;
 
-       /* VFS aio fields */
+       struct list_head list;
+};
 
-       /* used by the async I/O code to stash the orangefs_kiocb_s structure */
-       void *priv;
+#define set_op_state_waiting(op)     ((op)->op_state = OP_VFS_STATE_WAITING)
+#define set_op_state_inprogress(op)  ((op)->op_state = OP_VFS_STATE_INPROGR)
+#define set_op_state_given_up(op)  ((op)->op_state = OP_VFS_STATE_GIVEN_UP)
+static inline void set_op_state_serviced(struct orangefs_kernel_op_s *op)
+{
+       op->op_state = OP_VFS_STATE_SERVICED;
+       complete(&op->waitq);
+}
 
-       /* used again for the async I/O code for deallocation */
-       atomic_t aio_ref_count;
+#define op_state_waiting(op)     ((op)->op_state & OP_VFS_STATE_WAITING)
+#define op_state_in_progress(op) ((op)->op_state & OP_VFS_STATE_INPROGR)
+#define op_state_serviced(op)    ((op)->op_state & OP_VFS_STATE_SERVICED)
+#define op_state_purged(op)      ((op)->op_state & OP_VFS_STATE_PURGED)
+#define op_state_given_up(op)    ((op)->op_state & OP_VFS_STATE_GIVEN_UP)
+#define op_is_cancel(op)         ((op)->upcall.type == ORANGEFS_VFS_OP_CANCEL)
 
-       int attempts;
+void op_release(struct orangefs_kernel_op_s *op);
 
-       struct list_head list;
-};
+extern void orangefs_bufmap_put(int);
+static inline void put_cancel(struct orangefs_kernel_op_s *op)
+{
+       orangefs_bufmap_put(op->slot_to_free);
+       op_release(op);
+}
+
+static inline void set_op_state_purged(struct orangefs_kernel_op_s *op)
+{
+       spin_lock(&op->lock);
+       if (unlikely(op_is_cancel(op))) {
+               list_del_init(&op->list);
+               spin_unlock(&op->lock);
+               put_cancel(op);
+       } else {
+               op->op_state |= OP_VFS_STATE_PURGED;
+               complete(&op->waitq);
+               spin_unlock(&op->lock);
+       }
+}
 
 /* per inode private orangefs info */
 struct orangefs_inode_s {
@@ -280,9 +257,6 @@ struct orangefs_inode_s {
         * with this object
         */
        unsigned long pinode_flags;
-
-       /* All allocated orangefs_inode_s objects are chained to a list */
-       struct list_head list;
 };
 
 #define P_ATIME_FLAG 0
@@ -463,22 +437,12 @@ static inline int match_handle(struct orangefs_khandle resp_handle,
 int op_cache_initialize(void);
 int op_cache_finalize(void);
 struct orangefs_kernel_op_s *op_alloc(__s32 type);
+void orangefs_new_tag(struct orangefs_kernel_op_s *op);
 char *get_opname_string(struct orangefs_kernel_op_s *new_op);
-void op_release(struct orangefs_kernel_op_s *op);
-
-int dev_req_cache_initialize(void);
-int dev_req_cache_finalize(void);
-void *dev_req_alloc(void);
-void dev_req_release(void *);
 
 int orangefs_inode_cache_initialize(void);
 int orangefs_inode_cache_finalize(void);
 
-int kiocb_cache_initialize(void);
-int kiocb_cache_finalize(void);
-struct orangefs_kiocb_s *kiocb_alloc(void);
-void kiocb_release(struct orangefs_kiocb_s *ptr);
-
 /*
  * defined in orangefs-mod.c
  */
@@ -487,9 +451,6 @@ void purge_inprogress_ops(void);
 /*
  * defined in waitqueue.c
  */
-int wait_for_matching_downcall(struct orangefs_kernel_op_s *op);
-int wait_for_cancellation_downcall(struct orangefs_kernel_op_s *op);
-void orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s *op);
 void purge_waiting_ops(void);
 
 /*
@@ -501,7 +462,7 @@ struct dentry *orangefs_mount(struct file_system_type *fst,
                           void *data);
 
 void orangefs_kill_sb(struct super_block *sb);
-int orangefs_remount(struct super_block *sb);
+int orangefs_remount(struct orangefs_sb_info_s *);
 
 int fsid_key_table_initialize(void);
 void fsid_key_table_finalize(void);
@@ -522,6 +483,8 @@ int orangefs_getattr(struct vfsmount *mnt,
                  struct dentry *dentry,
                  struct kstat *kstat);
 
+int orangefs_permission(struct inode *inode, int mask);
+
 /*
  * defined in xattr.c
  */
@@ -555,7 +518,7 @@ ssize_t orangefs_inode_read(struct inode *inode,
 int orangefs_dev_init(void);
 void orangefs_dev_cleanup(void);
 int is_daemon_in_service(void);
-int fs_mount_pending(__s32 fsid);
+bool __is_daemon_in_service(void);
 
 /*
  * defined in orangefs-utils.c
@@ -577,26 +540,17 @@ int orangefs_inode_setxattr(struct inode *inode,
                         size_t size,
                         int flags);
 
-int orangefs_inode_getattr(struct inode *inode, __u32 mask);
+int orangefs_inode_getattr(struct inode *inode, int new, int size);
 
-int orangefs_inode_setattr(struct inode *inode, struct iattr *iattr);
+int orangefs_inode_check_changed(struct inode *inode);
 
-void orangefs_op_initialize(struct orangefs_kernel_op_s *op);
+int orangefs_inode_setattr(struct inode *inode, struct iattr *iattr);
 
 void orangefs_make_bad_inode(struct inode *inode);
 
-void block_signals(sigset_t *);
-
-void set_signals(sigset_t *);
-
 int orangefs_unmount_sb(struct super_block *sb);
 
-int orangefs_cancel_op_in_progress(__u64 tag);
-
-static inline __u64 orangefs_convert_time_field(const struct timespec *ts)
-{
-       return (__u64)ts->tv_sec;
-}
+bool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op);
 
 int orangefs_normalize_to_errno(__s32 error_code);
 
@@ -629,173 +583,41 @@ extern wait_queue_head_t orangefs_bufmap_init_waitq;
 /*
  * misc convenience macros
  */
-#define add_op_to_request_list(op)                             \
-do {                                                           \
-       spin_lock(&orangefs_request_list_lock);                 \
-       spin_lock(&op->lock);                                   \
-       set_op_state_waiting(op);                               \
-       list_add_tail(&op->list, &orangefs_request_list);               \
-       spin_unlock(&orangefs_request_list_lock);                       \
-       spin_unlock(&op->lock);                                 \
-       wake_up_interruptible(&orangefs_request_list_waitq);    \
-} while (0)
-
-#define add_priority_op_to_request_list(op)                            \
-       do {                                                            \
-               spin_lock(&orangefs_request_list_lock);                 \
-               spin_lock(&op->lock);                                   \
-               set_op_state_waiting(op);                               \
-                                                                       \
-               list_add(&op->list, &orangefs_request_list);            \
-               spin_unlock(&orangefs_request_list_lock);                       \
-               spin_unlock(&op->lock);                                 \
-               wake_up_interruptible(&orangefs_request_list_waitq);    \
-} while (0)
-
-#define remove_op_from_request_list(op)                                        \
-       do {                                                            \
-               struct list_head *tmp = NULL;                           \
-               struct list_head *tmp_safe = NULL;                      \
-               struct orangefs_kernel_op_s *tmp_op = NULL;             \
-                                                                       \
-               spin_lock(&orangefs_request_list_lock);                 \
-               list_for_each_safe(tmp, tmp_safe, &orangefs_request_list) { \
-                       tmp_op = list_entry(tmp,                        \
-                                           struct orangefs_kernel_op_s,        \
-                                           list);                      \
-                       if (tmp_op && (tmp_op == op)) {                 \
-                               list_del(&tmp_op->list);                \
-                               break;                                  \
-                       }                                               \
-               }                                                       \
-               spin_unlock(&orangefs_request_list_lock);                       \
-       } while (0)
 
 #define ORANGEFS_OP_INTERRUPTIBLE 1   /* service_operation() is interruptible */
 #define ORANGEFS_OP_PRIORITY      2   /* service_operation() is high priority */
 #define ORANGEFS_OP_CANCELLATION  4   /* this is a cancellation */
-#define ORANGEFS_OP_NO_SEMAPHORE  8   /* don't acquire semaphore */
+#define ORANGEFS_OP_NO_MUTEX      8   /* don't acquire request_mutex */
 #define ORANGEFS_OP_ASYNC         16  /* Queue it, but don't wait */
 
 int service_operation(struct orangefs_kernel_op_s *op,
                      const char *op_name,
                      int flags);
 
-/*
- * handles two possible error cases, depending on context.
- *
- * by design, our vfs i/o errors need to be handled in one of two ways,
- * depending on where the error occured.
- *
- * if the error happens in the waitqueue code because we either timed
- * out or a signal was raised while waiting, we need to cancel the
- * userspace i/o operation and free the op manually.  this is done to
- * avoid having the device start writing application data to our shared
- * bufmap pages without us expecting it.
- *
- * FIXME: POSSIBLE OPTIMIZATION:
- * However, if we timed out or if we got a signal AND our upcall was never
- * picked off the queue (i.e. we were in OP_VFS_STATE_WAITING), then we don't
- * need to send a cancellation upcall. The way we can handle this is
- * set error_exit to 2 in such cases and 1 whenever cancellation has to be
- * sent and have handle_error
- * take care of this situation as well..
- *
- * if a orangefs sysint level error occured and i/o has been completed,
- * there is no need to cancel the operation, as the user has finished
- * using the bufmap page and so there is no danger in this case.  in
- * this case, we wake up the device normally so that it may free the
- * op, as normal.
- *
- * note the only reason this is a macro is because both read and write
- * cases need the exact same handling code.
- */
-#define handle_io_error()                                      \
-do {                                                           \
-       if (!op_state_serviced(new_op)) {                       \
-               orangefs_cancel_op_in_progress(new_op->tag);    \
-               op_release(new_op);                             \
-       } else {                                                \
-               wake_up_daemon_for_return(new_op);              \
-       }                                                       \
-       new_op = NULL;                                          \
-       orangefs_bufmap_put(bufmap, buffer_index);                              \
-       buffer_index = -1;                                      \
-} while (0)
-
 #define get_interruptible_flag(inode) \
        ((ORANGEFS_SB(inode->i_sb)->flags & ORANGEFS_OPT_INTR) ? \
                ORANGEFS_OP_INTERRUPTIBLE : 0)
 
-#define add_orangefs_sb(sb)                                            \
-do {                                                                   \
-       gossip_debug(GOSSIP_SUPER_DEBUG,                                \
-                    "Adding SB %p to orangefs superblocks\n",          \
-                    ORANGEFS_SB(sb));                                  \
-       spin_lock(&orangefs_superblocks_lock);                          \
-       list_add_tail(&ORANGEFS_SB(sb)->list, &orangefs_superblocks);           \
-       spin_unlock(&orangefs_superblocks_lock); \
-} while (0)
-
-#define remove_orangefs_sb(sb)                                         \
-do {                                                                   \
-       struct list_head *tmp = NULL;                                   \
-       struct list_head *tmp_safe = NULL;                              \
-       struct orangefs_sb_info_s *orangefs_sb = NULL;                  \
-                                                                       \
-       spin_lock(&orangefs_superblocks_lock);                          \
-       list_for_each_safe(tmp, tmp_safe, &orangefs_superblocks) {              \
-               orangefs_sb = list_entry(tmp,                           \
-                                     struct orangefs_sb_info_s,                \
-                                     list);                            \
-               if (orangefs_sb && (orangefs_sb->sb == sb)) {                   \
-                       gossip_debug(GOSSIP_SUPER_DEBUG,                \
-                           "Removing SB %p from orangefs superblocks\n",       \
-                       orangefs_sb);                                   \
-                       list_del(&orangefs_sb->list);                   \
-                       break;                                          \
-               }                                                       \
-       }                                                               \
-       spin_unlock(&orangefs_superblocks_lock);                                \
-} while (0)
-
-#define orangefs_lock_inode(inode) spin_lock(&inode->i_lock)
-#define orangefs_unlock_inode(inode) spin_unlock(&inode->i_lock)
-
 #define fill_default_sys_attrs(sys_attr, type, mode)                   \
 do {                                                                   \
        sys_attr.owner = from_kuid(current_user_ns(), current_fsuid()); \
        sys_attr.group = from_kgid(current_user_ns(), current_fsgid()); \
-       sys_attr.size = 0;                                              \
        sys_attr.perms = ORANGEFS_util_translate_mode(mode);            \
-       sys_attr.objtype = type;                                        \
+       sys_attr.mtime = 0;                                             \
+       sys_attr.atime = 0;                                             \
+       sys_attr.ctime = 0;                                             \
        sys_attr.mask = ORANGEFS_ATTR_SYS_ALL_SETABLE;                  \
 } while (0)
 
-#define orangefs_inode_lock(__i)  mutex_lock(&(__i)->i_mutex)
-
-#define orangefs_inode_unlock(__i) mutex_unlock(&(__i)->i_mutex)
-
 static inline void orangefs_i_size_write(struct inode *inode, loff_t i_size)
 {
 #if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
-       ornagefs_inode_lock(inode);
+       mutex_lock(&inode->i_mutex);
 #endif
        i_size_write(inode, i_size);
 #if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
-       orangefs_inode_unlock(inode);
+       mutex_unlock(&inode->i_mutex);
 #endif
 }
 
-static inline unsigned int diff(struct timeval *end, struct timeval *begin)
-{
-       if (end->tv_usec < begin->tv_usec) {
-               end->tv_usec += 1000000;
-               end->tv_sec--;
-       }
-       end->tv_sec -= begin->tv_sec;
-       end->tv_usec -= begin->tv_usec;
-       return (end->tv_sec * 1000000) + end->tv_usec;
-}
-
 #endif /* __ORANGEFSKERNEL_H */