Merge branch 'drm-next-4.6' of git://people.freedesktop.org/~agd5f/linux into drm...
[deliverable/linux.git] / fs / orangefs / devorangefs-req.c
index 790855a72e3209b8ab570e1faa311e07b78c25e2..db170beba7974c3d5d4491df452f0d75ca15ea13 100644 (file)
@@ -46,6 +46,10 @@ static void orangefs_devreq_add_op(struct orangefs_kernel_op_s *op)
        list_add_tail(&op->list, &htable_ops_in_progress[index]);
 }
 
+/*
+ * find the op with this tag and remove it from the in progress
+ * hash table.
+ */
 static struct orangefs_kernel_op_s *orangefs_devreq_remove_op(__u64 tag)
 {
        struct orangefs_kernel_op_s *op, *next;
@@ -58,9 +62,9 @@ static struct orangefs_kernel_op_s *orangefs_devreq_remove_op(__u64 tag)
                                 next,
                                 &htable_ops_in_progress[index],
                                 list) {
-               if (op->tag == tag && !op_state_purged(op)) {
+               if (op->tag == tag && !op_state_purged(op) &&
+                   !op_state_given_up(op)) {
                        list_del_init(&op->list);
-                       get_op(op); /* increase ref count. */
                        spin_unlock(&htable_ops_in_progress_lock);
                        return op;
                }
@@ -70,6 +74,44 @@ static struct orangefs_kernel_op_s *orangefs_devreq_remove_op(__u64 tag)
        return NULL;
 }
 
+/* Returns whether any FS are still pending remounted */
+static int mark_all_pending_mounts(void)
+{
+       int unmounted = 1;
+       struct orangefs_sb_info_s *orangefs_sb = NULL;
+
+       spin_lock(&orangefs_superblocks_lock);
+       list_for_each_entry(orangefs_sb, &orangefs_superblocks, list) {
+               /* All of these file system require a remount */
+               orangefs_sb->mount_pending = 1;
+               unmounted = 0;
+       }
+       spin_unlock(&orangefs_superblocks_lock);
+       return unmounted;
+}
+
+/*
+ * Determine if a given file system needs to be remounted or not
+ *  Returns -1 on error
+ *           0 if already mounted
+ *           1 if needs remount
+ */
+static int fs_mount_pending(__s32 fsid)
+{
+       int mount_pending = -1;
+       struct orangefs_sb_info_s *orangefs_sb = NULL;
+
+       spin_lock(&orangefs_superblocks_lock);
+       list_for_each_entry(orangefs_sb, &orangefs_superblocks, list) {
+               if (orangefs_sb->fs_id == fsid) {
+                       mount_pending = orangefs_sb->mount_pending;
+                       break;
+               }
+       }
+       spin_unlock(&orangefs_superblocks_lock);
+       return mount_pending;
+}
+
 static int orangefs_devreq_open(struct inode *inode, struct file *file)
 {
        int ret = -EINVAL;
@@ -133,7 +175,7 @@ restart:
                __s32 fsid;
                /* This lock is held past the end of the loop when we break. */
                spin_lock(&op->lock);
-               if (unlikely(op_state_purged(op))) {
+               if (unlikely(op_state_purged(op) || op_state_given_up(op))) {
                        spin_unlock(&op->lock);
                        continue;
                }
@@ -190,8 +232,10 @@ restart:
                return -EAGAIN;
        }
 
-       gossip_debug(GOSSIP_DEV_DEBUG, "orangefs: reading op tag %llu %s\n",
-                    llu(cur_op->tag), get_opname_string(cur_op));
+       gossip_debug(GOSSIP_DEV_DEBUG, "%s: reading op tag %llu %s\n",
+                    __func__,
+                    llu(cur_op->tag),
+                    get_opname_string(cur_op));
 
        /*
         * Such an op should never be on the list in the first place. If so, we
@@ -199,13 +243,13 @@ restart:
         */
        if (op_state_in_progress(cur_op) || op_state_serviced(cur_op)) {
                gossip_err("orangefs: ERROR: Current op already queued.\n");
-               list_del(&cur_op->list);
+               list_del_init(&cur_op->list);
                spin_unlock(&cur_op->lock);
                spin_unlock(&orangefs_request_list_lock);
                return -EAGAIN;
        }
+
        list_del_init(&cur_op->list);
-       get_op(op);
        spin_unlock(&orangefs_request_list_lock);
 
        spin_unlock(&cur_op->lock);
@@ -230,7 +274,7 @@ restart:
        if (unlikely(op_state_given_up(cur_op))) {
                spin_unlock(&cur_op->lock);
                spin_unlock(&htable_ops_in_progress_lock);
-               op_release(cur_op);
+               complete(&cur_op->waitq);
                goto restart;
        }
 
@@ -239,10 +283,15 @@ restart:
         * it has been sent to the client.
         */
        set_op_state_inprogress(cur_op);
+       gossip_debug(GOSSIP_DEV_DEBUG,
+                    "%s: 1 op:%s: op_state:%d: process:%s:\n",
+                    __func__,
+                    get_opname_string(cur_op),
+                    cur_op->op_state,
+                    current->comm);
        orangefs_devreq_add_op(cur_op);
        spin_unlock(&cur_op->lock);
        spin_unlock(&htable_ops_in_progress_lock);
-       op_release(cur_op);
 
        /* The client only asks to read one size buffer. */
        return MAX_DEV_REQ_UPSIZE;
@@ -257,11 +306,19 @@ error:
        spin_lock(&cur_op->lock);
        if (likely(!op_state_given_up(cur_op))) {
                set_op_state_waiting(cur_op);
+               gossip_debug(GOSSIP_DEV_DEBUG,
+                            "%s: 2 op:%s: op_state:%d: process:%s:\n",
+                            __func__,
+                            get_opname_string(cur_op),
+                            cur_op->op_state,
+                            current->comm);
                list_add(&cur_op->list, &orangefs_request_list);
+               spin_unlock(&cur_op->lock);
+       } else {
+               spin_unlock(&cur_op->lock);
+               complete(&cur_op->waitq);
        }
-       spin_unlock(&cur_op->lock);
        spin_unlock(&orangefs_request_list_lock);
-       op_release(cur_op);
        return -EFAULT;
 }
 
@@ -323,6 +380,7 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
                return -EPROTO;
        }
 
+       /* remove the op from the in progress hash table */
        op = orangefs_devreq_remove_op(head.tag);
        if (!op) {
                gossip_err("WARNING: No one's waiting for tag %llu\n",
@@ -333,8 +391,7 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
        n = copy_from_iter(&op->downcall, downcall_size, iter);
        if (n != downcall_size) {
                gossip_err("%s: failed to copy downcall.\n", __func__);
-               ret = -EFAULT;
-               goto Broken;
+               goto Efault;
        }
 
        if (op->downcall.status)
@@ -354,8 +411,7 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
                           downcall_size,
                           op->downcall.trailer_size,
                           total);
-               ret = -EFAULT;
-               goto Broken;
+               goto Efault;
        }
 
        /* Only READDIR operations should have trailers. */
@@ -364,8 +420,7 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
                gossip_err("%s: %x operation with trailer.",
                           __func__,
                           op->downcall.type);
-               ret = -EFAULT;
-               goto Broken;
+               goto Efault;
        }
 
        /* READDIR operations should always have trailers. */
@@ -374,8 +429,7 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
                gossip_err("%s: %x operation with no trailer.",
                           __func__,
                           op->downcall.type);
-               ret = -EFAULT;
-               goto Broken;
+               goto Efault;
        }
 
        if (op->downcall.type != ORANGEFS_VFS_OP_READDIR)
@@ -386,8 +440,7 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
        if (op->downcall.trailer_buf == NULL) {
                gossip_err("%s: failed trailer vmalloc.\n",
                           __func__);
-               ret = -ENOMEM;
-               goto Broken;
+               goto Enomem;
        }
        memset(op->downcall.trailer_buf, 0, op->downcall.trailer_size);
        n = copy_from_iter(op->downcall.trailer_buf,
@@ -396,99 +449,42 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
        if (n != op->downcall.trailer_size) {
                gossip_err("%s: failed to copy trailer.\n", __func__);
                vfree(op->downcall.trailer_buf);
-               ret = -EFAULT;
-               goto Broken;
+               goto Efault;
        }
 
 wakeup:
        /*
-        * tell the vfs op waiting on a waitqueue
-        * that this op is done
+        * Return to vfs waitqueue, and back to service_operation
+        * through wait_for_matching_downcall. 
         */
        spin_lock(&op->lock);
-       if (unlikely(op_state_given_up(op))) {
+       if (unlikely(op_is_cancel(op))) {
                spin_unlock(&op->lock);
-               goto out;
-       }
-       set_op_state_serviced(op);
-       spin_unlock(&op->lock);
-
-       /*
-        * If this operation is an I/O operation we need to wait
-        * for all data to be copied before we can return to avoid
-        * buffer corruption and races that can pull the buffers
-        * out from under us.
-        *
-        * Essentially we're synchronizing with other parts of the
-        * vfs implicitly by not allowing the user space
-        * application reading/writing this device to return until
-        * the buffers are done being used.
-        */
-       if (op->downcall.type == ORANGEFS_VFS_OP_FILE_IO) {
-               long n = wait_for_completion_interruptible_timeout(&op->done,
-                                                       op_timeout_secs * HZ);
-               if (unlikely(n < 0)) {
-                       gossip_debug(GOSSIP_DEV_DEBUG,
-                               "%s: signal on I/O wait, aborting\n",
-                               __func__);
-               } else if (unlikely(n == 0)) {
-                       gossip_debug(GOSSIP_DEV_DEBUG,
-                               "%s: timed out.\n",
-                               __func__);
-               }
-       }
-out:
-       if (unlikely(op_is_cancel(op)))
                put_cancel(op);
-       op_release(op);
-       return ret;
-
-Broken:
-       spin_lock(&op->lock);
-       if (!op_state_given_up(op)) {
-               op->downcall.status = ret;
+       } else if (unlikely(op_state_given_up(op))) {
+               spin_unlock(&op->lock);
+               complete(&op->waitq);
+       } else {
                set_op_state_serviced(op);
+               gossip_debug(GOSSIP_DEV_DEBUG,
+                            "%s: op:%s: op_state:%d: process:%s:\n",
+                            __func__,
+                            get_opname_string(op),
+                            op->op_state,
+                            current->comm);
+               spin_unlock(&op->lock);
        }
-       spin_unlock(&op->lock);
-       goto out;
-}
+       return ret;
 
-/* Returns whether any FS are still pending remounted */
-static int mark_all_pending_mounts(void)
-{
-       int unmounted = 1;
-       struct orangefs_sb_info_s *orangefs_sb = NULL;
+Efault:
+       op->downcall.status = -(ORANGEFS_ERROR_BIT | 9);
+       ret = -EFAULT;
+       goto wakeup;
 
-       spin_lock(&orangefs_superblocks_lock);
-       list_for_each_entry(orangefs_sb, &orangefs_superblocks, list) {
-               /* All of these file system require a remount */
-               orangefs_sb->mount_pending = 1;
-               unmounted = 0;
-       }
-       spin_unlock(&orangefs_superblocks_lock);
-       return unmounted;
-}
-
-/*
- * Determine if a given file system needs to be remounted or not
- *  Returns -1 on error
- *           0 if already mounted
- *           1 if needs remount
- */
-int fs_mount_pending(__s32 fsid)
-{
-       int mount_pending = -1;
-       struct orangefs_sb_info_s *orangefs_sb = NULL;
-
-       spin_lock(&orangefs_superblocks_lock);
-       list_for_each_entry(orangefs_sb, &orangefs_superblocks, list) {
-               if (orangefs_sb->fs_id == fsid) {
-                       mount_pending = orangefs_sb->mount_pending;
-                       break;
-               }
-       }
-       spin_unlock(&orangefs_superblocks_lock);
-       return mount_pending;
+Enomem:
+       op->downcall.status = -(ORANGEFS_ERROR_BIT | 8);
+       ret = -ENOMEM;
+       goto wakeup;
 }
 
 /*
@@ -516,15 +512,7 @@ static int orangefs_devreq_release(struct inode *inode, struct file *file)
        gossip_debug(GOSSIP_DEV_DEBUG, "ORANGEFS Device Close: Filesystem(s) %s\n",
                     (unmounted ? "UNMOUNTED" : "MOUNTED"));
 
-       /*
-        * Walk through the list of ops in the request list, mark them
-        * as purged and wake them up.
-        */
        purge_waiting_ops();
-       /*
-        * Walk through the hash table of in progress operations; mark
-        * them as purged and wake them up
-        */
        purge_inprogress_ops();
 
        orangefs_bufmap_run_down();
@@ -584,8 +572,7 @@ static long dispatch_ioctl_command(unsigned int command, unsigned long arg)
        struct dev_mask_info_s mask_info = { 0 };
        struct dev_mask2_info_s mask2_info = { 0, 0 };
        int upstream_kmod = 1;
-       struct list_head *tmp = NULL;
-       struct orangefs_sb_info_s *orangefs_sb = NULL;
+       struct orangefs_sb_info_s *orangefs_sb;
 
        /* mtmoore: add locking here */
 
@@ -620,7 +607,7 @@ static long dispatch_ioctl_command(unsigned int command, unsigned long arg)
                 * remount all mounted orangefs volumes to regain the lost
                 * dynamic mount tables (if any) -- NOTE: this is done
                 * without keeping the superblock list locked due to the
-                * upcall/downcall waiting.  also, the request semaphore is
+                * upcall/downcall waiting.  also, the request mutex is
                 * used to ensure that no operations will be serviced until
                 * all of the remounts are serviced (to avoid ops between
                 * mounts to fail)
@@ -631,26 +618,32 @@ static long dispatch_ioctl_command(unsigned int command, unsigned long arg)
                gossip_debug(GOSSIP_DEV_DEBUG,
                             "%s: priority remount in progress\n",
                             __func__);
-               list_for_each(tmp, &orangefs_superblocks) {
-                       orangefs_sb =
-                               list_entry(tmp,
-                                          struct orangefs_sb_info_s,
-                                          list);
-                       if (orangefs_sb && (orangefs_sb->sb)) {
+               spin_lock(&orangefs_superblocks_lock);
+               list_for_each_entry(orangefs_sb, &orangefs_superblocks, list) {
+                       /*
+                        * We have to drop the spinlock, so entries can be
+                        * removed.  They can't be freed, though, so we just
+                        * keep the forward pointers and zero the back ones -
+                        * that way we can get to the rest of the list.
+                        */
+                       if (!orangefs_sb->list.prev)
+                               continue;
+                       gossip_debug(GOSSIP_DEV_DEBUG,
+                                    "%s: Remounting SB %p\n",
+                                    __func__,
+                                    orangefs_sb);
+
+                       spin_unlock(&orangefs_superblocks_lock);
+                       ret = orangefs_remount(orangefs_sb);
+                       spin_lock(&orangefs_superblocks_lock);
+                       if (ret) {
                                gossip_debug(GOSSIP_DEV_DEBUG,
-                                            "%s: Remounting SB %p\n",
-                                            __func__,
+                                            "SB %p remount failed\n",
                                             orangefs_sb);
-
-                               ret = orangefs_remount(orangefs_sb->sb);
-                               if (ret) {
-                                       gossip_debug(GOSSIP_DEV_DEBUG,
-                                                    "SB %p remount failed\n",
-                                                    orangefs_sb);
-                                       break;
-                               }
+                               break;
                        }
                }
+               spin_unlock(&orangefs_superblocks_lock);
                gossip_debug(GOSSIP_DEV_DEBUG,
                             "%s: priority remount complete\n",
                             __func__);
@@ -690,6 +683,19 @@ static long dispatch_ioctl_command(unsigned int command, unsigned long arg)
                ret = copy_from_user(&client_debug_array_string,
                                     (void __user *)arg,
                                     ORANGEFS_MAX_DEBUG_STRING_LEN);
+               /*
+                * The real client-core makes an effort to ensure
+                * that actual strings that aren't too long to fit in
+                * this buffer is what we get here. We're going to use
+                * string functions on the stuff we got, so we'll make
+                * this extra effort to try and keep from
+                * flowing out of this buffer when we use the string
+                * functions, even if somehow the stuff we end up
+                * with here is garbage.
+                */
+               client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN - 1] =
+                       '\0';
+               
                if (ret != 0) {
                        pr_info("%s: CLIENT_STRING: copy_from_user failed\n",
                                __func__);
This page took 0.030441 seconds and 5 git commands to generate.