From patchwork Thu Sep 17 09:51:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 7204891 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 263E29F39B for ; Thu, 17 Sep 2015 09:52:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 569D7207F5 for ; Thu, 17 Sep 2015 09:52:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74CDE207EF for ; Thu, 17 Sep 2015 09:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752122AbbIQJv6 (ORCPT ); Thu, 17 Sep 2015 05:51:58 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:35264 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751104AbbIQJv5 (ORCPT ); Thu, 17 Sep 2015 05:51:57 -0400 Received: by pacfv12 with SMTP id fv12so16446016pac.2 for ; Thu, 17 Sep 2015 02:51:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-type:content-transfer-encoding; bh=20zfN/ZcnGrzCe8p41M+NQoRCITvCb08q6r3+FsFzUc=; b=ZxM0zgYqU4pzprWF2qWKB3Bq1PQlLj2Pdli5C3AP1/Ofqt7y7E61G8pbv3i3i4nXpe a5nD4AElnNQwpabNWBJvI2ZsQxe3B2e8qGZYW0Kg4A2xVD0GzIjSol6PgxY1WEpk0Qtc ygY1fILMY7kdPpAB39vL6zON5hpjKcjzdGJ24QtTRj7qyfc8lhpo952/F+m2BBeiZnqb tJNjDZ5qwuSbV4XX35dit9+xSolPEgZTNuHBWypQAZyEl626Xu7WMgcPYoC8+Ckm8B+J 5fW4yrtkddEjGgUeMzida9tdVYPZnZVEQP2la14ak7r1fxxDldkKlWDNP6q/cGDgc2kw qH6g== X-Received: by 10.66.142.101 with SMTP id rv5mr14183216pab.25.1442483517008; Thu, 17 Sep 2015 02:51:57 -0700 (PDT) Received: from [192.168.99.5] ([104.143.41.79]) by smtp.googlemail.com with ESMTPSA id xg2sm2625961pbb.77.2015.09.17.02.51.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 02:51:56 -0700 (PDT) From: Kinglong Mee Subject: [PATCH] nfs: Fix open state losing after delegation return To: Trond Myklebust Cc: "linux-nfs@vger.kernel.org" , NeilBrown , kinglongmee@gmail.com Message-ID: <55FA8D22.2010003@gmail.com> Date: Thu, 17 Sep 2015 17:51:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 After delegation return caused by setting file mode, client lost the open state, DESTROY_CLIENTID will get error NFS4ERR_CLIENTID_BUSY from server. The delegation_type passed to nfs4_open_recover_helper with NFS4_OPEN_CLAIM_DELEG_CUR_FH is never set. Reproduce steps, # mount -t nfs nfs-server:/ /mnt/ # ./delegation_test /mnt/ # umount /mnt <--- costs 10 seconds The delegation_test.c is, #include #include #include #include #include #include #include int main(int argc, char **argv) { int fd1, fd2; char fname1[1024], fname2[1024]; struct stat sb; if (argc < 2) return -1; sprintf(fname1, "%s/test1", argv[1]); sprintf(fname2, "%s/test2", argv[1]); fd1 = open(fname1, O_RDONLY); fd2 = open(fname2, O_RDONLY); fstat(fd1, &sb); fchmod(fd1, sb.st_mode + 1); close(fd1); close(fd2); return 0; } Fixes: 39f897fdbd ("NFSv4: When returning a delegation, don't reclaim an incompatible open mode.") Signed-off-by: Kinglong Mee --- fs/nfs/nfs4proc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 693b903..472a52f 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1576,8 +1576,7 @@ static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmod struct nfs4_state *newstate; int ret; - if ((opendata->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR || - opendata->o_arg.claim == NFS4_OPEN_CLAIM_DELEG_CUR_FH) && + if (opendata->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR && (opendata->o_arg.u.delegation_type & fmode) != fmode) /* This mode can't have been delegated, so we must have * a valid open_stateid to cover it - not need to reclaim.