From patchwork Tue May 24 19:12:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Peterson X-Patchwork-Id: 9134165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ADB3F607D7 for ; Tue, 24 May 2016 19:12:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CE94281FE for ; Tue, 24 May 2016 19:12:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 920BF2824F; Tue, 24 May 2016 19:12:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 327CE281FE for ; Tue, 24 May 2016 19:12:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752500AbcEXTMq (ORCPT ); Tue, 24 May 2016 15:12:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60849 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752237AbcEXTMn (ORCPT ); Tue, 24 May 2016 15:12:43 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56BC18E24A; Tue, 24 May 2016 19:12:43 +0000 (UTC) Received: from loki.redhat.com (ovpn-116-126.phx2.redhat.com [10.3.116.126]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4OJCeLP021530; Tue, 24 May 2016 15:12:42 -0400 From: Bob Peterson To: cluster-devel , Alexander Viro , Subject: [GFS2 PATCH 5/7] vfs: Introduce prepare_wait_on_freeing_inode Date: Tue, 24 May 2016 14:12:37 -0500 Message-Id: <1464117159-17874-6-git-send-email-rpeterso@redhat.com> In-Reply-To: <1464117159-17874-1-git-send-email-rpeterso@redhat.com> References: <1464117159-17874-1-git-send-email-rpeterso@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 24 May 2016 19:12:43 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andreas Gruenbacher Add function prepare_wait_on_freeing_inode: during an inode lookup, freeing an inode can require taking a lock that the filesystem already holds. The lock must be dropped before we can wait for the inode to go away; waiting inside find_inode / find_inode_fast would deadlock. In that case, filesystems can use find_inode_nowait. When an inode that is being freed is found, they can prepare to wait for the inode to go away inside find_inode_nowait, then drop the conflicting lock and wait outside of find_inode_nowait. Signed-off-by: Andreas Gruenbacher --- fs/inode.c | 17 ++++++++++++++--- include/linux/fs.h | 1 + include/linux/wait.h | 21 +++++++++++++++------ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 4ccbc21..e00fec4 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1819,6 +1819,17 @@ int inode_needs_sync(struct inode *inode) } EXPORT_SYMBOL(inode_needs_sync); +wait_queue_head_t *prepare_wait_on_freeing_inode( + struct inode *inode, struct wait_bit_queue *wait) +{ + wait_queue_head_t *wq = bit_waitqueue(&inode->i_state, __I_NEW); + + init_wait_bit(wait, &inode->i_state, __I_NEW); + prepare_to_wait(wq, &wait->wait, TASK_UNINTERRUPTIBLE); + return wq; +} +EXPORT_SYMBOL(prepare_wait_on_freeing_inode); + /* * If we try to find an inode in the inode hash while it is being * deleted, we have to wait until the filesystem completes its @@ -1832,10 +1843,10 @@ EXPORT_SYMBOL(inode_needs_sync); */ static void __wait_on_freeing_inode(struct inode *inode) { + struct wait_bit_queue wait; wait_queue_head_t *wq; - DEFINE_WAIT_BIT(wait, &inode->i_state, __I_NEW); - wq = bit_waitqueue(&inode->i_state, __I_NEW); - prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE); + + wq = prepare_wait_on_freeing_inode(inode, &wait); spin_unlock(&inode->i_lock); spin_unlock(&inode_hash_lock); schedule(); diff --git a/include/linux/fs.h b/include/linux/fs.h index 5f61431..fe129a7 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2686,6 +2686,7 @@ extern void address_space_init_once(struct address_space *mapping); extern struct inode * igrab(struct inode *); extern ino_t iunique(struct super_block *, ino_t); extern int inode_needs_sync(struct inode *inode); +extern wait_queue_head_t *prepare_wait_on_freeing_inode(struct inode *inode, struct wait_bit_queue *wait); extern int generic_delete_inode(struct inode *inode); static inline int generic_drop_inode(struct inode *inode) { diff --git a/include/linux/wait.h b/include/linux/wait.h index 27d7a0a..45ef1d2 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -991,6 +991,14 @@ int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key); #define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function) +#define init_wait(wait) \ + do { \ + (wait)->private = current; \ + (wait)->func = autoremove_wake_function; \ + INIT_LIST_HEAD(&(wait)->task_list); \ + (wait)->flags = 0; \ + } while (0) + #define DEFINE_WAIT_BIT(name, word, bit) \ struct wait_bit_queue name = { \ .key = __WAIT_BIT_KEY_INITIALIZER(word, bit), \ @@ -1002,15 +1010,16 @@ int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key); }, \ } -#define init_wait(wait) \ +#define init_wait_bit(wbit, word, bit) \ do { \ - (wait)->private = current; \ - (wait)->func = autoremove_wake_function; \ - INIT_LIST_HEAD(&(wait)->task_list); \ - (wait)->flags = 0; \ + (wbit)->key.flags = word; \ + (wbit)->key.bit_nr = bit; \ + (wbit)->wait.private = current; \ + (wbit)->wait.func = wake_bit_function; \ + INIT_LIST_HEAD(&(wbit)->wait.task_list); \ + (wbit)->wait.flags = 0; \ } while (0) - extern int bit_wait(struct wait_bit_key *, int); extern int bit_wait_io(struct wait_bit_key *, int); extern int bit_wait_timeout(struct wait_bit_key *, int);