staging/lustre/llite: avoid nonatomic memory alloc under spinlock
authorLai Siyao <lai.siyao@intel.com>
Sun, 8 Mar 2015 00:24:28 +0000 (19:24 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Mar 2015 09:35:44 +0000 (10:35 +0100)
ll_intent_drop_lock() may sleep in memory allocation, which
should not be called inside spinlock.

Signed-off-by: Lai Siyao <lai.siyao@intel.com>
Signed-off-by: Jian Yu <jian.yu@intel.com>
Reviewed-on: http://review.whamcloud.com/10674
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2272
Signed-off-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/llite/statahead.c

index fe732fa0d01ffd2d4fa9586e6f96e14af3a5dd72..b75562c6b5de95700b6ee1ee8eeae6e6e54931a6 100644 (file)
@@ -706,11 +706,21 @@ static int ll_statahead_interpret(struct ptlrpc_request *req,
        struct ll_inode_info     *lli = ll_i2info(dir);
        struct ll_statahead_info *sai = NULL;
        struct ll_sa_entry       *entry;
+       __u64                     handle = 0;
        int                    wakeup;
 
        if (it_disposition(it, DISP_LOOKUP_NEG))
                rc = -ENOENT;
 
+       if (rc == 0) {
+               /* release ibits lock ASAP to avoid deadlock when statahead
+                * thread enqueues lock on parent in readdir and another
+                * process enqueues lock on child with parent lock held, eg.
+                * unlink. */
+               handle = it->d.lustre.it_lock_handle;
+               ll_intent_drop_lock(it);
+       }
+
        spin_lock(&lli->lli_sa_lock);
        /* stale entry */
        if (unlikely(lli->lli_sai == NULL ||
@@ -745,8 +755,7 @@ static int ll_statahead_interpret(struct ptlrpc_request *req,
                         * when statahead thread tries to enqueue lock on parent
                         * for readpage and other tries to enqueue lock on child
                         * with parent's lock held, for example: unlink. */
-                       entry->se_handle = it->d.lustre.it_lock_handle;
-                       ll_intent_drop_lock(it);
+                       entry->se_handle = handle;
                        wakeup = sa_received_empty(sai);
                        list_add_tail(&entry->se_list,
                                          &sai->sai_entries_received);