From patchwork Tue Feb 3 21:59:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 5772001 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 57E91BF6C3 for ; Tue, 3 Feb 2015 21:59:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 78252202A1 for ; Tue, 3 Feb 2015 21:59:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A62F20295 for ; Tue, 3 Feb 2015 21:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750844AbbBCV7t (ORCPT ); Tue, 3 Feb 2015 16:59:49 -0500 Received: from mail-ig0-f174.google.com ([209.85.213.174]:64416 "EHLO mail-ig0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752601AbbBCV7s (ORCPT ); Tue, 3 Feb 2015 16:59:48 -0500 Received: by mail-ig0-f174.google.com with SMTP id b16so30324213igk.1 for ; Tue, 03 Feb 2015 13:59:47 -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=K6o4SwPB9pIgu0F7SJI+g6Xb0IM/gGppVHU+woRlZwQ=; b=bCoR8CY1rfVDvB6fv4IqYAB84dIlSUktsIarbSKntQonra3MscvbiKCX/6+XvIPC0p 4VYHcw9OXO6UvTDn3BBw+7IRxdqUwN1WpsArtLupGiDSGyJBE1okECX3ToKvArikg2RW yhneVVHRAGlCj5Zt0GYARIYib5z15Yhug0yOsYCtam9hKDE63LBOZSvJ038UXUqoFFxt ZypFlRK/3E3EAKIntrOfXdRhfQUFqHyLYn1aaPa0Bm8YNSW4f2glt/q5dKv19MAT2s4W wFQ1W7+L/OIYSHSi8gaOwNLA3kIuwsBdQnkNcZzDvr9mn2hJg+qXQ0Fxd/jaXZl5RaDx 8zzA== X-Gm-Message-State: ALoCoQnZy88JF4rvtm2qhVM5+MiotjzZiDEV44nVn/cCJZKO5tN/jcQTHoIFQOqT5E1Td4OpqSdH X-Received: by 10.42.71.194 with SMTP id l2mr25725968icj.71.1423000787776; Tue, 03 Feb 2015 13:59:47 -0800 (PST) Received: from leira.trondhjem.org.localdomain (c-68-40-185-14.hsd1.mi.comcast.net. [68.40.185.14]) by mx.google.com with ESMTPSA id w4sm5843929ioi.10.2015.02.03.13.59.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Feb 2015 13:59:47 -0800 (PST) From: Trond Myklebust To: linux-nfs@vger.kernel.org Cc: Olga.Kornievskaia@netapp.com Subject: [PATCH 2/2] NFSv4.1: Ask for no delegation on OPEN if already holding one Date: Tue, 3 Feb 2015 16:59:44 -0500 Message-Id: <1423000784-93180-2-git-send-email-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1423000784-93180-1-git-send-email-trond.myklebust@primarydata.com> References: <1423000784-93180-1-git-send-email-trond.myklebust@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 If we already hold a delegation, there should be no reason for the server to issue it to us again. Unfortunately, there appear to be servers out there that engage in this practice. While it is often harmless to do so, there is one case where this creates a problem and that is when the client is in the process of returning that delegation. This patch uses the NFSv4.1 NFS4_SHARE_WANT_NO_DELEG flag to inform the server not to return a delegation in these cases. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index cd4295d84d54..fb41624bafc9 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -942,8 +942,10 @@ static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, static u32 nfs4_map_atomic_open_share(struct nfs_server *server, + struct inode *inode, fmode_t fmode, int openflags) { + struct nfs_delegation *delegation; u32 res = 0; switch (fmode & (FMODE_READ | FMODE_WRITE)) { @@ -959,8 +961,25 @@ nfs4_map_atomic_open_share(struct nfs_server *server, if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) goto out; /* Want no delegation if we're using O_DIRECT */ - if (openflags & O_DIRECT) + if (openflags & O_DIRECT) { res |= NFS4_SHARE_WANT_NO_DELEG; + goto out; + } + if (inode == NULL) + goto out; + rcu_read_lock(); + delegation = rcu_dereference(NFS_I(inode)->delegation); + /* + * If we have a delegation, either ask for an upgrade or ask for + * no delegation + */ + if (delegation) { + if ((fmode & FMODE_WRITE) && !(delegation->type & FMODE_WRITE)) + res |= NFS4_SHARE_WANT_WRITE_DELEG; + else + res |= NFS4_SHARE_WANT_NO_DELEG; + } + rcu_read_unlock(); out: return res; } @@ -1028,7 +1047,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, p->o_arg.open_flags = flags; p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); p->o_arg.share_access = nfs4_map_atomic_open_share(server, - fmode, flags); + dentry->d_inode, fmode, flags); /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS * will return permission denied for all bits until close */ if (!(flags & O_EXCL)) { @@ -2724,7 +2743,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) } calldata->arg.share_access = nfs4_map_atomic_open_share(NFS_SERVER(inode), - calldata->arg.fmode, 0); + NULL, calldata->arg.fmode, 0); nfs_fattr_init(calldata->res.fattr); calldata->timestamp = jiffies;