From patchwork Wed Aug 5 20:24:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11702531 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E11FB14E3 for ; Wed, 5 Aug 2020 20:26:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C300922CAD for ; Wed, 5 Aug 2020 20:26:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596659201; bh=+/SEhvz3yfboCZvGfwMRulF3eCn6Xxd2xSdIpXJ3Oec=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=lfQK4nKHfRbbCoHrZtgtJcrUhg0zoT8Dh2DI6+2F4UckcAvE/JLmgQDfG8Dz8lB2u eePnQtEdhfpELFigCk77uYWuRJOTJt4FdylQ0EbHEOFPtnASPTl+3Rtkg9F6J0xq8e uTDT9kOMCGni1eB6dfKCTMgdZ9nI6TODhAxLtJwM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726400AbgHEU0k (ORCPT ); Wed, 5 Aug 2020 16:26:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:57016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726149AbgHEU0k (ORCPT ); Wed, 5 Aug 2020 16:26:40 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2EB7F22CA1 for ; Wed, 5 Aug 2020 20:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596659200; bh=+/SEhvz3yfboCZvGfwMRulF3eCn6Xxd2xSdIpXJ3Oec=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QeVruGB6DH8Czm95N67wX1QPawfaZYySlqUgXVlB6hHNHMlB247pjn1yMfKRvlBhu ClhaI3rYGe8jQbsa70aXcPA06vZ+X3mTce5NG1o6cBIz7jiD8PeQj1X80tnBR1Uw2Q OrLcgKqsAY5lA5zC06+tU2L/E1cwwR0oSz6+PLGg= From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 1/2] NFS: Don't move layouts to plh_return_segs list while in use Date: Wed, 5 Aug 2020 16:24:30 -0400 Message-Id: <20200805202431.627013-2-trondmy@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200805202431.627013-1-trondmy@kernel.org> References: <20200805202431.627013-1-trondmy@kernel.org> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If the layout segment is still in use for a read or a write, we should not move it to the layout plh_return_segs list. If we do, we can end up returning the layout while I/O is still in progress. Fixes: e0b7d420f72a ("pNFS: Don't discard layout segments that are marked for return") Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index d8cdb94c6668..262ce01c7abe 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -2392,16 +2392,6 @@ pnfs_layout_process(struct nfs4_layoutget *lgp) return ERR_PTR(-EAGAIN); } -static int -mark_lseg_invalid_or_return(struct pnfs_layout_segment *lseg, - struct list_head *tmp_list) -{ - if (!mark_lseg_invalid(lseg, tmp_list)) - return 0; - pnfs_cache_lseg_for_layoutreturn(lseg->pls_layout, lseg); - return 1; -} - /** * pnfs_mark_matching_lsegs_return - Free or return matching layout segments * @lo: pointer to layout header @@ -2438,7 +2428,7 @@ pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo, lseg, lseg->pls_range.iomode, lseg->pls_range.offset, lseg->pls_range.length); - if (mark_lseg_invalid_or_return(lseg, tmp_list)) + if (mark_lseg_invalid(lseg, tmp_list)) continue; remaining++; set_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags); From patchwork Wed Aug 5 20:24:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11702533 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BEE613B6 for ; Wed, 5 Aug 2020 20:26:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C27722CA1 for ; Wed, 5 Aug 2020 20:26:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596659202; bh=+xdDK7UiSeg17vtYouNeo6HcNkdiq8oHOMNNJBmqyD0=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=Bf4S+by4Tpz3YcSX+/v+DM00oV/PQaZwc1Y/LgDLd/Z0mdXEyde5HgDHI+A8+FYGl pucnMkudjYPh9JaM5sdcPHJJ9Tu3/O8KL9QUNZtPXI+0oENDsAKv4mv33MzZ7GSzgh 3VFfSv18QZgAoyFNG7g2y8NHT9tgJdlWBxgOX+HE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726149AbgHEU0l (ORCPT ); Wed, 5 Aug 2020 16:26:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:57018 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726013AbgHEU0l (ORCPT ); Wed, 5 Aug 2020 16:26:41 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A406622B42 for ; Wed, 5 Aug 2020 20:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596659200; bh=+xdDK7UiSeg17vtYouNeo6HcNkdiq8oHOMNNJBmqyD0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hc4/CALOXoFuNxN08WyaTNoiAfA+QJst5LBsyVDcbBo/Z7XuO//VsM9TdhW6550Ub oQx/nq8+HXP7FLsNwOJA7xSSzOZR3s1JHwqeHeS+TGletpygGqNn0z4nhTahdg2y0F 3cPjOxkWHY9PX4fqO4cfQ8A/qKv1/ZFyR1kx8Clc= From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 2/2] NFS: Don't return layout segments that are in use Date: Wed, 5 Aug 2020 16:24:31 -0400 Message-Id: <20200805202431.627013-3-trondmy@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200805202431.627013-2-trondmy@kernel.org> References: <20200805202431.627013-1-trondmy@kernel.org> <20200805202431.627013-2-trondmy@kernel.org> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If the NFS_LAYOUT_RETURN_REQUESTED flag is set, we want to return the layout as soon as possible, meaning that the affected layout segments should be marked as invalid, and should no longer be in use for I/O. Fixes: f0b429819b5f ("pNFS: Ignore non-recalled layouts in pnfs_layout_need_return()") Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 262ce01c7abe..b5baf36d4de5 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1226,31 +1226,27 @@ pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, return status; } +static bool +pnfs_layout_segments_returnable(struct pnfs_layout_hdr *lo, + enum pnfs_iomode iomode, + u32 seq) +{ + struct pnfs_layout_range recall_range = { + .length = NFS4_MAX_UINT64, + .iomode = iomode, + }; + return pnfs_mark_matching_lsegs_return(lo, &lo->plh_return_segs, + &recall_range, seq) != -EBUSY; +} + /* Return true if layoutreturn is needed */ static bool pnfs_layout_need_return(struct pnfs_layout_hdr *lo) { - struct pnfs_layout_segment *s; - enum pnfs_iomode iomode; - u32 seq; - if (!test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) return false; - - seq = lo->plh_return_seq; - iomode = lo->plh_return_iomode; - - /* Defer layoutreturn until all recalled lsegs are done */ - list_for_each_entry(s, &lo->plh_segs, pls_list) { - if (seq && pnfs_seqid_is_newer(s->pls_seq, seq)) - continue; - if (iomode != IOMODE_ANY && s->pls_range.iomode != iomode) - continue; - if (test_bit(NFS_LSEG_LAYOUTRETURN, &s->pls_flags)) - return false; - } - - return true; + return pnfs_layout_segments_returnable(lo, lo->plh_return_iomode, + lo->plh_return_seq); } static void pnfs_layoutreturn_before_put_layout_hdr(struct pnfs_layout_hdr *lo)