From patchwork Tue Dec 16 19:01:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haynes X-Patchwork-Id: 5503201 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 957EABEEA8 for ; Tue, 16 Dec 2014 19:03:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF13420A16 for ; Tue, 16 Dec 2014 19:03:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEAC1209BD for ; Tue, 16 Dec 2014 19:03:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751331AbaLPTDi (ORCPT ); Tue, 16 Dec 2014 14:03:38 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:56719 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750983AbaLPTDi (ORCPT ); Tue, 16 Dec 2014 14:03:38 -0500 Received: by mail-pa0-f46.google.com with SMTP id lf10so13943682pab.5 for ; Tue, 16 Dec 2014 11:03:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cjpnZSSQvHPlfFjRb6MM3jwVOR1Gaqbx7Gjakry6weE=; b=A3w0PKCxz9vt63QEWgXG5lq28hkqBNiApbaAB0/i5VIETZiAXasvYDSOdDEAVRR3Db SrAlib0bdwUo/rW+tnvOYLOBBIcEAk1oqobrmA4Rfe5lrr98swyrAlFg6kAzR1rCbEMP q/BZXcD9zY5P+VHJMVq0Lf5L3peN+PrmZqnvp1D1sxUOlim5X+9MsgG0+GZiX5sXESO5 t/FmXWjK9dqg9Hh0C4My1TRb3x2vbY3M62uQxKngE9M/98ks0RvGgEx95+XrWWzKdb6w RjLV5ZCNWqpXxskWMdNQcbDao2A+O2Lz4qwnjnV0AMWbq1tAzXjNp+NOFQZyjg0Ah4Qk yaOw== X-Gm-Message-State: ALoCoQmj9pRpeS3odcQIPmzU87hxkF6eoRqzlljT4+3vRzyVXF2CgM3Uiy2kjd8NOwTEljmG7WLG X-Received: by 10.66.251.167 with SMTP id zl7mr64114331pac.140.1418756617267; Tue, 16 Dec 2014 11:03:37 -0800 (PST) Received: from localhost.localdomain ([50.242.95.105]) by mx.google.com with ESMTPSA id q4sm1620669pdh.79.2014.12.16.11.03.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Dec 2014 11:03:36 -0800 (PST) From: Tom Haynes X-Google-Original-From: Tom Haynes To: Trond Myklebust Cc: Linux NFS Mailing List Subject: [PATCH 46/50] nfs/flexfiles: defer sending layoutreturn in pnfs_put_lseg Date: Tue, 16 Dec 2014 11:01:49 -0800 Message-Id: <1418756513-95187-47-git-send-email-loghyr@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1418756513-95187-1-git-send-email-loghyr@primarydata.com> References: <1418756513-95187-1-git-send-email-loghyr@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Peng Tao pnfs_put_lseg may be called from rpc callbacks. So we should not call pnfs_send_layoutreturn directly because it can deadlock in the rpc layer. Signed-off-by: Peng Tao --- fs/nfs/pnfs.c | 67 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index a3a5e22..9e7092f 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -347,8 +347,7 @@ pnfs_layout_remove_lseg(struct pnfs_layout_hdr *lo, /* Return true if layoutreturn is needed */ static bool pnfs_layout_need_return(struct pnfs_layout_hdr *lo, - struct pnfs_layout_segment *lseg, - nfs4_stateid *stateid, enum pnfs_iomode *iomode) + struct pnfs_layout_segment *lseg) { struct pnfs_layout_segment *s; @@ -359,14 +358,52 @@ pnfs_layout_need_return(struct pnfs_layout_hdr *lo, if (s != lseg && test_bit(NFS_LSEG_LAYOUTRETURN, &s->pls_flags)) return false; - *stateid = lo->plh_stateid; - *iomode = lo->plh_return_iomode; - /* decreased in pnfs_send_layoutreturn() */ - lo->plh_block_lgets++; - lo->plh_return_iomode = 0; return true; } +static void pnfs_layoutreturn_free_lseg(struct work_struct *work) +{ + struct pnfs_layout_segment *lseg; + struct pnfs_layout_hdr *lo; + struct inode *inode; + + lseg = container_of(work, struct pnfs_layout_segment, pls_work); + WARN_ON(atomic_read(&lseg->pls_refcount)); + lo = lseg->pls_layout; + inode = lo->plh_inode; + + spin_lock(&inode->i_lock); + if (pnfs_layout_need_return(lo, lseg)) { + nfs4_stateid stateid; + enum pnfs_iomode iomode; + + stateid = lo->plh_stateid; + iomode = lo->plh_return_iomode; + /* decreased in pnfs_send_layoutreturn() */ + lo->plh_block_lgets++; + lo->plh_return_iomode = 0; + spin_unlock(&inode->i_lock); + + pnfs_send_layoutreturn(lo, stateid, iomode, 0, + NFS4_MAX_UINT64, true); + spin_lock(&inode->i_lock); + } else + /* match pnfs_get_layout_hdr #2 in pnfs_put_lseg */ + pnfs_put_layout_hdr(lo); + pnfs_layout_remove_lseg(lo, lseg); + spin_unlock(&inode->i_lock); + pnfs_free_lseg(lseg); + /* match pnfs_get_layout_hdr #1 in pnfs_put_lseg */ + pnfs_put_layout_hdr(lo); +} + +static void +pnfs_layoutreturn_free_lseg_async(struct pnfs_layout_segment *lseg) +{ + INIT_WORK(&lseg->pls_work, pnfs_layoutreturn_free_lseg); + queue_work(nfsiod_workqueue, &lseg->pls_work); +} + void pnfs_put_lseg(struct pnfs_layout_segment *lseg) { @@ -382,22 +419,12 @@ pnfs_put_lseg(struct pnfs_layout_segment *lseg) lo = lseg->pls_layout; inode = lo->plh_inode; if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) { - bool need_return; - nfs4_stateid stateid; - enum pnfs_iomode iomode; - pnfs_get_layout_hdr(lo); - need_return = pnfs_layout_need_return(lo, lseg, - &stateid, &iomode); - if (need_return) { + if (pnfs_layout_need_return(lo, lseg)) { spin_unlock(&inode->i_lock); /* hdr reference dropped in nfs4_layoutreturn_release */ - pnfs_send_layoutreturn(lo, stateid, iomode, 0, - NFS4_MAX_UINT64, true); - spin_lock(&inode->i_lock); - pnfs_layout_remove_lseg(lo, lseg); - spin_unlock(&inode->i_lock); - pnfs_free_lseg(lseg); + pnfs_get_layout_hdr(lo); + pnfs_layoutreturn_free_lseg_async(lseg); } else { pnfs_layout_remove_lseg(lo, lseg); spin_unlock(&inode->i_lock);