From owner-freebsd-fs@FreeBSD.ORG Thu Jul 17 23:41:25 2003 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C64E637B404 for ; Thu, 17 Jul 2003 23:41:25 -0700 (PDT) Received: from smtp01.syd.iprimus.net.au (smtp01.syd.iprimus.net.au [210.50.30.52]) by mx1.FreeBSD.org (Postfix) with ESMTP id 12D2A43FA3 for ; Thu, 17 Jul 2003 23:41:25 -0700 (PDT) (envelope-from tim@robbins.dropbear.id.au) Received: from mail.robbins.dropbear.id.au (210.50.202.39) by smtp01.syd.iprimus.net.au (7.0.018) id 3F146D0A000AEB89 for freebsd-fs@freebsd.org; Fri, 18 Jul 2003 16:41:23 +1000 Received: by mail.robbins.dropbear.id.au (Postfix, from userid 1000) id F0872C96E; Fri, 18 Jul 2003 16:41:20 +1000 (EST) Date: Fri, 18 Jul 2003 16:41:20 +1000 From: Tim Robbins To: freebsd-fs@freebsd.org Message-ID: <20030718064120.GA72366@dilbert.robbins.dropbear.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Subject: NFS ftruncate patch for review X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2003 06:41:26 -0000 Any comments on this patch? The referenced PR contains more comments and a test program. It's not obvious from the diff, but the changes are to nfs_setattr() in the va_size != VNOVAL && v_type == VREG case. Change 34590 by tjr@tjr_dev on 2003/07/16 04:40:35 Fix a nasty problem when truncating files over NFS that was introduced between FreeBSD 4.4 and 4.5: we need to set np->n_size again after flushing/truncating buffers in case the cache calls nfs_write(). For example, if the file is truncated to 0 bytes, nfs_write() will often detect that the file is being appended to (since the file is 0 bytes long and we're writing to offset 0), so it then updates np->n_size to reflect the size the file was before it was truncated. PR: 41792 Affected files ... ... //depot/user/tjr/freebsd-tjr/src/sys/nfsclient/nfs_vnops.c#7 edit Differences ... ==== //depot/user/tjr/freebsd-tjr/src/sys/nfsclient/nfs_vnops.c#7 (text+ko) ==== @@ -662,7 +662,13 @@ return (error); } } - np->n_vattr.va_size = vap->va_size; + /* + * np->n_size has already been set to vap->va_size + * in nfs_meta_setsize(). We must set it again since + * nfs_write() could be called when flushing dirty + * buffers, and nfs_write() can modify np->n_size. + */ + np->n_vattr.va_size = np->n_size = vap->va_size; }; } else if ((vap->va_mtime.tv_sec != VNOVAL || vap->va_atime.tv_sec != VNOVAL) && (np->n_flag & NMODIFIED) &&