From patchwork Wed Aug 19 05:49:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Tao X-Patchwork-Id: 7035451 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F0C29C05AC for ; Wed, 19 Aug 2015 05:49:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1AC5A207CF for ; Wed, 19 Aug 2015 05:49:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1E5C204D3 for ; Wed, 19 Aug 2015 05:49:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752664AbbHSFt3 (ORCPT ); Wed, 19 Aug 2015 01:49:29 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:33380 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752605AbbHSFt2 (ORCPT ); Wed, 19 Aug 2015 01:49:28 -0400 Received: by pabyb7 with SMTP id yb7so149603194pab.0 for ; Tue, 18 Aug 2015 22:49:28 -0700 (PDT) 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; bh=/rI9wl3XBydeo6w1vmwfov6GlQiBzaQjaTlv/HVoAoY=; b=aYQj3euNR64kumlHsGUENcN0gc/M8bg3vkmwNzAkP9PGzle7QL17Euyz5FULP5iknu DgTyH4xVCFq7r7Ug6nGMa2kDaB2pTocZYo7c3/XoAhruZVu5JubUIAYM1ZFYpSEjXOY6 QSgMjSWee4CW5NClzRgh1s4ol+z4vw+PiFoipDqTswHiWetcZQHpRQ0DW5rSNwnJV3ai FhJacNZqGoF9D8Bo+slVGszrpnAOrTICb3MbU6QLskQ+tLy0a2ojRPSYC5wwKMAObJ4x M8Hq7BGC384cBWHBdL8/0ioOdPY3rwP/kUobXfuCAnKcw3uPFG4QeR/+aWBafjUnPYhj utgg== X-Gm-Message-State: ALoCoQmKfaNCO4CHo/W61ol98RcIidYPZMJNeSzxGh8M4FvFXSsy4CE1em/jeij1ttYBnXcwcMOM X-Received: by 10.68.226.134 with SMTP id rs6mr21155727pbc.11.1439963368374; Tue, 18 Aug 2015 22:49:28 -0700 (PDT) Received: from lear.localdomain (63-157-6-18.dia.static.qwest.net. [63.157.6.18]) by smtp.gmail.com with ESMTPSA id hz5sm20051288pbb.39.2015.08.18.22.49.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Aug 2015 22:49:27 -0700 (PDT) From: Peng Tao To: linux-nfs@vger.kernel.org Cc: Trond Myklebust , Peng Tao Subject: [PATCH] NFS41: make sure sending LAYOUTRETURN before close if marked so Date: Wed, 19 Aug 2015 13:49:19 +0800 Message-Id: <1439963359-17186-1-git-send-email-tao.peng@primarydata.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 If layout is marked by NFS_LAYOUT_RETURN_BEFORE_CLOSE, we should always send LAYOUTRETURN before close, and we don't need to do ROC drain if we do send LAYOUTRETURN. Signed-off-by: Peng Tao --- fs/nfs/pnfs.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 6aabbb6..e101a49 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1064,7 +1064,7 @@ bool pnfs_roc(struct inode *ino) struct pnfs_layout_segment *lseg, *tmp; nfs4_stateid stateid; LIST_HEAD(tmp_list); - bool found = false, layoutreturn = false; + bool found = false, layoutreturn = false, roc = false; spin_lock(&ino->i_lock); lo = nfsi->layout; @@ -1072,7 +1072,7 @@ bool pnfs_roc(struct inode *ino) test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) goto out_noroc; - /* Don't return layout if we hold a delegation */ + /* no roc if we hold a delegation */ if (nfs4_check_delegation(ino, FMODE_READ)) goto out_noroc; @@ -1083,36 +1083,41 @@ bool pnfs_roc(struct inode *ino) goto out_noroc; } + stateid = lo->plh_stateid; + /* always send layoutreturn if being marked so */ + if (test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, + &lo->plh_flags)) + layoutreturn = pnfs_prepare_layoutreturn(lo); + pnfs_clear_retry_layoutget(lo); list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list) - if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { + /* If we are sending layoutreturn, invalidate all valid lsegs */ + if (layoutreturn || test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { mark_lseg_invalid(lseg, &tmp_list); found = true; } - if (!found) - goto out_noroc; - if (test_and_set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) - goto out_noroc; - lo->plh_return_iomode = IOMODE_ANY; - pnfs_get_layout_hdr(lo); /* matched in pnfs_roc_release */ - spin_unlock(&ino->i_lock); - pnfs_free_lseg_list(&tmp_list); - pnfs_layoutcommit_inode(ino, true); - return true; + /* pnfs_prepare_layoutreturn() grabs lo ref and it will be put + * in pnfs_roc_release(). We don't really send a layoutreturn but + * still want others to view us like we are sending one! + * + * If pnfs_prepare_layoutreturn() fails, it means someone else is doing + * LAYOUTRETURN, so we proceed like there are no layouts to return. + * + * ROC in three conditions: + * 1. there are ROC lsegs + * 2. we don't send layoutreturn + * 3. no others are sending layoutreturn + */ + if (found && !layoutreturn && pnfs_prepare_layoutreturn(lo)) + roc = true; out_noroc: - if (lo) { - stateid = lo->plh_stateid; - if (test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, - &lo->plh_flags)) - layoutreturn = pnfs_prepare_layoutreturn(lo); - } spin_unlock(&ino->i_lock); - if (layoutreturn) { - pnfs_layoutcommit_inode(ino, true); + pnfs_free_lseg_list(&tmp_list); + pnfs_layoutcommit_inode(ino, true); + if (layoutreturn) pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, true); - } - return false; + return roc; } void pnfs_roc_release(struct inode *ino)