From patchwork Sun Sep 7 15:36:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 4858671 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 33900C033A for ; Sun, 7 Sep 2014 15:34:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6CEED20122 for ; Sun, 7 Sep 2014 15:34:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7117020127 for ; Sun, 7 Sep 2014 15:34:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752482AbaIGPeY (ORCPT ); Sun, 7 Sep 2014 11:34:24 -0400 Received: from casper.infradead.org ([85.118.1.10]:34903 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752375AbaIGPeY (ORCPT ); Sun, 7 Sep 2014 11:34:24 -0400 Received: from [50.247.105.171] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1XQeTu-0005mv-VM for linux-nfs@vger.kernel.org; Sun, 07 Sep 2014 15:34:23 +0000 From: Christoph Hellwig To: linux-nfs@vger.kernel.org Subject: [PATCH 2/2] nfs: update time staps on truncate Date: Sun, 7 Sep 2014 08:36:41 -0700 Message-Id: <1410104201-32517-2-git-send-email-hch@lst.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1410104201-32517-1-git-send-email-hch@lst.de> References: <1410104201-32517-1-git-send-email-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org See http://www.infradead.org/rpr.html Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 VFS handles attributes on truncate in a strange way, fix NFS to properly update timestamps on truncate(). Signed-off-by: Christoph Hellwig --- fs/nfs/inode.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 141c9f4..97bc485 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -507,8 +507,20 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) if (attr->ia_valid & ATTR_SIZE) { BUG_ON(!S_ISREG(inode->i_mode)); + /* + * Calling conventions are a little "unconventional" for + * truncate: + * - for truncate() the VFS does not set ATTR_CTIME and + * ATTR_MTIME, but we still need need to update the time + * stamps if we change the file size. + * - for ftruncate() the VFS sets ATTR_CTIME and ATTR_MTIME, + * and we always need to change the time stamp, even if + * the size does not change. + */ if (attr->ia_size == i_size_read(inode)) attr->ia_valid &= ~ATTR_SIZE; + else if (!(attr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) + attr->ia_valid |= ATTR_CTIME | ATTR_MTIME; } /* Optimization: if the end result is no change, don't RPC */