orangefs: delay freeing slot until cancel completes
[deliverable/linux.git] / fs / orangefs / orangefs-kernel.h
index 4219b2f9a5aed97375d6eceec6fb4135baeee66e..3ceeeaed414327e64c0a1d6f2744639c46aeba80 100644 (file)
@@ -80,11 +80,6 @@ sizeof(__u64) + sizeof(struct orangefs_upcall_s))
 #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 +89,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,30 +97,9 @@ enum orangefs_vfs_op_states {
        OP_VFS_STATE_INPROGR = 2,
        OP_VFS_STATE_SERVICED = 4,
        OP_VFS_STATE_PURGED = 8,
+       OP_VFS_STATE_GIVEN_UP = 16,
 };
 
-#define get_op(op)                                     \
-       do {                                            \
-               atomic_inc(&(op)->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)->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)->ref_count) <= 2 ? 0 : 1)
-
 /*
  * Defines for controlling whether I/O upcalls are for async or sync operations
  */
@@ -153,7 +128,6 @@ 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)
 
@@ -216,9 +190,14 @@ struct orangefs_kernel_op_s {
        /*
         * 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.
+        * 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.
         */
-       int uses_shared_memory;
+       union {
+               int uses_shared_memory;
+               int slot_to_free;
+       };
 
        struct orangefs_upcall_s upcall;
        struct orangefs_downcall_s downcall;
@@ -226,16 +205,12 @@ struct orangefs_kernel_op_s {
        wait_queue_head_t waitq;
        spinlock_t lock;
 
-       int io_completed;
-       wait_queue_head_t io_completion_waitq;
+       struct completion done;
 
        atomic_t ref_count;
 
        /* VFS aio fields */
 
-       /* used by the async I/O code to stash the orangefs_kiocb_s structure */
-       void *priv;
-
        int attempts;
 
        struct list_head list;
@@ -243,21 +218,58 @@ struct orangefs_kernel_op_s {
 
 #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;
        wake_up_interruptible(&op->waitq);
 }
-static inline void set_op_state_purged(struct orangefs_kernel_op_s *op)
-{
-       op->op_state |= OP_VFS_STATE_PURGED;
-       wake_up_interruptible(&op->waitq);
-}
 
 #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)
+
+static inline void get_op(struct orangefs_kernel_op_s *op)
+{
+       atomic_inc(&op->ref_count);
+       gossip_debug(GOSSIP_DEV_DEBUG,
+                       "(get) Alloced OP (%p:%llu)\n", op, llu(op->tag));
+}
+
+void __op_release(struct orangefs_kernel_op_s *op);
+
+static inline void op_release(struct orangefs_kernel_op_s *op)
+{
+       if (atomic_dec_and_test(&op->ref_count)) {
+               gossip_debug(GOSSIP_DEV_DEBUG,
+                       "(put) Releasing OP (%p:%llu)\n", op, llu((op)->tag));
+               __op_release(op);
+       }
+}
+
+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(&op->list);
+               spin_unlock(&op->lock);
+               put_cancel(op);
+       } else {
+               op->op_state |= OP_VFS_STATE_PURGED;
+               wake_up_interruptible(&op->waitq);
+               spin_unlock(&op->lock);
+       }
+}
 
 /* per inode private orangefs info */
 struct orangefs_inode_s {
@@ -458,22 +470,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
  */
@@ -514,6 +516,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
  */
@@ -547,6 +551,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);
+bool __is_daemon_in_service(void);
 int fs_mount_pending(__s32 fsid);
 
 /*
@@ -569,12 +574,10 @@ 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, __u32 mask, int check);
 
 int orangefs_inode_setattr(struct inode *inode, struct iattr *iattr);
 
-void orangefs_op_initialize(struct orangefs_kernel_op_s *op);
-
 void orangefs_make_bad_inode(struct inode *inode);
 
 void orangefs_block_signals(sigset_t *);
@@ -583,7 +586,7 @@ void orangefs_set_signals(sigset_t *);
 
 int orangefs_unmount_sb(struct super_block *sb);
 
-int orangefs_cancel_op_in_progress(__u64 tag);
+bool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op);
 
 static inline __u64 orangefs_convert_time_field(const struct timespec *ts)
 {
@@ -632,48 +635,6 @@ 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)
This page took 0.029542 seconds and 5 git commands to generate.