From patchwork Wed May 6 06:50:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Andreas_Gr=C3=BCnbacher?= X-Patchwork-Id: 6346771 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 C4EBDBEEE1 for ; Wed, 6 May 2015 06:51:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E3D7E20225 for ; Wed, 6 May 2015 06:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E99EE2021F for ; Wed, 6 May 2015 06:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753140AbbEFGvI (ORCPT ); Wed, 6 May 2015 02:51:08 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:34402 "EHLO mail-wi0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753112AbbEFGvH (ORCPT ); Wed, 6 May 2015 02:51:07 -0400 Received: by wicmx19 with SMTP id mx19so117587959wic.1 for ; Tue, 05 May 2015 23:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=SHBfLXLUIeazIujPuXwhyyj5po3qekHcE2xWgxTkyMw=; b=KR2kGzwsmrKSDJiUg5/RSMcfV38dW8ZqmrDYUPKAPq74yc/dG0W2zJV7/AARRTrlCY AAElxEcmHptcYQlTz6eeGEv6aGBjW+nMJAgpLPn2evfTEwBn+JnO0QDteW3GP7PW1AV6 M2l6KBiDDYKy1iBpib1Qjg04PWAaT6wu8TBVOGaC4SsQy2iYurcQqiC1MW4+zJAVD7JJ NvbKPr7/PdYNwg3+3VYaIjEksEQENH4ksnTSkAgjw4BbiT8vjpwLCApEaVE3q3bxYoA2 Gegrj+4aAaSmnN4GG3m2Zs8q1DCvyrQTL+pHQ9yPnFfpQuamit36Qz7ZQC6ZdP3cirvT gUcA== X-Received: by 10.194.79.199 with SMTP id l7mr57894993wjx.158.1430895066094; Tue, 05 May 2015 23:51:06 -0700 (PDT) Received: from nuc.home.com (80-110-112-232.cgn.dynamic.surfer.at. [80.110.112.232]) by mx.google.com with ESMTPSA id l20sm1182920wjw.42.2015.05.05.23.51.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 May 2015 23:51:05 -0700 (PDT) From: Andreas Gruenbacher To: "J. Bruce Fields" , linux-nfs@vger.kernel.org Cc: Christoph Hellwig , Andreas Gruenbacher Subject: [PATCH] nfsd: Disable NFSv2 timestamp workaround for NFSv3+ Date: Wed, 6 May 2015 08:50:24 +0200 Message-Id: <1430895024-1403-1-git-send-email-andreas.gruenbacher@gmail.com> X-Mailer: git-send-email 2.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 The NFSv2 protocol does not have a way to set the atime or mtime of a file to the server's current time, only to specific timestamps. To make up for that, when a client sets both atime and mtime to the same timestamp and that timestamp is within the last half hour, the server sets them to its own current time instead. The NFSv3 and later protocols do support setting atime or mtime to the server's current time and clients do use that, so skip the NFSv2 workaround there. With this change, clients which have write access but are not the owner can still do the equivalent of utimes("file", NULL), for example with "touch", but setting atime or mtime to any other value will now consistently fail. This is also the local, non-NFS behavior. Signed-off-by: Andreas Gruenbacher --- fs/nfsd/vfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 84d770b..41d3359 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -300,7 +300,7 @@ commit_metadata(struct svc_fh *fhp) * NFS semantics and what Linux expects. */ static void -nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap) +nfsd_sanitize_attrs(struct svc_rqst *rqstp, struct inode *inode, struct iattr *iap) { /* * NFSv2 does not differentiate between "set-[ac]time-to-now" @@ -316,7 +316,8 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap) #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET) #define MAX_TOUCH_TIME_ERROR (30*60) if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET && - iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) { + iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec && + rqstp->rq_vers == 2) { /* * Looks probable. * @@ -435,7 +436,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap, if (!iap->ia_valid) goto out; - nfsd_sanitize_attrs(inode, iap); + nfsd_sanitize_attrs(rqstp, inode, iap); /* * The size case is special, it changes the file in addition to the