From patchwork Thu Aug 21 15:07:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 4758431 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 1D9E8C0338 for ; Thu, 21 Aug 2014 15:05:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EECB6200FE for ; Thu, 21 Aug 2014 15:05:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F8B1200F4 for ; Thu, 21 Aug 2014 15:05:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752116AbaHUPF3 (ORCPT ); Thu, 21 Aug 2014 11:05:29 -0400 Received: from casper.infradead.org ([85.118.1.10]:50825 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750861AbaHUPF3 (ORCPT ); Thu, 21 Aug 2014 11:05:29 -0400 Received: from ip-64-134-168-64.public.wayport.net ([64.134.168.64] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1XKTvb-0007jC-Qy for linux-nfs@vger.kernel.org; Thu, 21 Aug 2014 15:05:28 +0000 From: Christoph Hellwig To: linux-nfs@vger.kernel.org Subject: [PATCH] nfs: update time staps on truncate Date: Thu, 21 Aug 2014 10:07:47 -0500 Message-Id: <1408633667-24177-1-git-send-email-hch@lst.de> X-Mailer: git-send-email 1.9.1 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=-7.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 handle it properly by copying a small code sniplet from XFS. Signed-off-by: Christoph Hellwig --- fs/nfs/inode.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 577a36f..5bbd991 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -505,8 +505,28 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) attr->ia_valid &= ~ATTR_MODE; if (attr->ia_valid & ATTR_SIZE) { - if (!S_ISREG(inode->i_mode) || attr->ia_size == i_size_read(inode)) + if (!S_ISREG(inode->i_mode) || + attr->ia_size == i_size_read(inode)) attr->ia_valid &= ~ATTR_SIZE; + + /* + * Only change the c/mtime if we are changing the size or we + * are explicitly asked to change it. This handles the + * semantic difference between truncate() and ftruncate() as + * implemented in the VFS. + * + * The regular truncate() case without ATTR_CTIME and + * ATTR_MTIME is a special case where we need to update the + * times despite not having these flags set. For all other + * operations the VFS set these flags explicitly if it wants + * a timestamp update. + */ + if (attr->ia_size != i_size_read(inode) && + !(attr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) { + attr->ia_ctime = attr->ia_mtime = + current_fs_time(inode->i_sb); + attr->ia_valid |= ATTR_CTIME | ATTR_MTIME; + } } /* Optimization: if the end result is no change, don't RPC */