From nobody Fri May 20 19:39:01 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7337E1AEB83E; Fri, 20 May 2022 19:39:10 +0000 (UTC) (envelope-from dchagin@heemeyer.club) Received: from heemeyer.club (heemeyer.club [195.93.173.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4L4cVP1wSfz3MTF; Fri, 20 May 2022 19:39:09 +0000 (UTC) (envelope-from dchagin@heemeyer.club) Received: from heemeyer.club (localhost [127.0.0.1]) by heemeyer.club (8.17.1/8.16.1) with ESMTP id 24KJd1mS018498; Fri, 20 May 2022 22:39:01 +0300 (MSK) (envelope-from dchagin@heemeyer.club) Received: (from dchagin@localhost) by heemeyer.club (8.17.1/8.16.1/Submit) id 24KJd1mQ018497; Fri, 20 May 2022 22:39:01 +0300 (MSK) (envelope-from dchagin) Date: Fri, 20 May 2022 22:39:01 +0300 From: Dmitry Chagin To: Mateusz Guzik Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: ec3c225711ae - main - vfs: call vn_truncate_locked from kern_truncate Message-ID: References: <202205201725.24KHPxLt058778@gitrepo.freebsd.org> List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="QcIKgUAnjsmZRbWM" Content-Disposition: inline In-Reply-To: <202205201725.24KHPxLt058778@gitrepo.freebsd.org> X-Rspamd-Queue-Id: 4L4cVP1wSfz3MTF X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of dchagin@heemeyer.club has no SPF policy when checking 195.93.173.158) smtp.mailfrom=dchagin@heemeyer.club X-Spamd-Result: default: False [-0.20 / 15.00]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; FREEFALL_USER(0.00)[dchagin]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[multipart/mixed,text/plain,text/x-csrc]; MIME_BAD_ATTACHMENT(1.60)[c]; DMARC_NA(0.00)[freebsd.org]; HAS_ATTACHMENT(0.00)[]; AUTH_NA(1.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.998]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MLMMJ_DEST(0.00)[dev-commits-src-all,dev-commits-src-main]; FORGED_SENDER(0.30)[dchagin@freebsd.org,dchagin@heemeyer.club]; R_SPF_NA(0.00)[no SPF record]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:+]; ASN(0.00)[asn:61400, ipnet:195.93.173.0/24, country:RU]; FROM_NEQ_ENVFROM(0.00)[dchagin@freebsd.org,dchagin@heemeyer.club]; RCVD_COUNT_TWO(0.00)[2] X-ThisMailContainsUnwantedMimeParts: N --QcIKgUAnjsmZRbWM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, May 20, 2022 at 05:25:59PM +0000, Mateusz Guzik wrote: > The branch main has been updated by mjg: > > URL: https://cgit.FreeBSD.org/src/commit/?id=ec3c225711ae7d5b8e71ed036aada09ef91149ec > > commit ec3c225711ae7d5b8e71ed036aada09ef91149ec > Author: Mateusz Guzik > AuthorDate: 2022-05-16 01:28:22 +0000 > Commit: Mateusz Guzik > CommitDate: 2022-05-20 17:25:51 +0000 > > vfs: call vn_truncate_locked from kern_truncate > > This fixes a bug where the syscall would not bump writecount. > > PR: 263999 > --- > sys/kern/vfs_syscalls.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c > index 86ef3fc7a095..600299fbe6eb 100644 > --- a/sys/kern/vfs_syscalls.c > +++ b/sys/kern/vfs_syscalls.c > @@ -3460,7 +3460,6 @@ kern_truncate(struct thread *td, const char *path, enum uio_seg pathseg, > struct mount *mp; > struct vnode *vp; > void *rl_cookie; > - struct vattr vattr; > struct nameidata nd; > int error; > > @@ -3480,18 +3479,21 @@ retry: > return (error); > } > vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); > - if (vp->v_type == VDIR) > + if (vp->v_type == VDIR) { > error = EISDIR; > -#ifdef MAC > - else if ((error = mac_vnode_check_write(td->td_ucred, NOCRED, vp))) { > + goto out; > } > +#ifdef MAC > + error = mac_vnode_check_write(td->td_ucred, NOCRED, vp); > + if (error != 0) > + goto out; > #endif > - else if ((error = vn_writechk(vp)) == 0 && > - (error = VOP_ACCESS(vp, VWRITE, td->td_ucred, td)) == 0) { > - VATTR_NULL(&vattr); > - vattr.va_size = length; > - error = VOP_SETATTR(vp, &vattr, td->td_ucred); > - } > + error = VOP_ACCESS(vp, VWRITE, td->td_ucred, td); > + if (error != 0) > + goto out; > + > + error = vn_truncate_locked(vp, 0, false, td->td_ucred); > +out: > VOP_UNLOCK(vp); > vn_finished_write(mp); > vn_rangelock_unlock(vp, rl_cookie); seems this broke truncate, test attached. --QcIKgUAnjsmZRbWM Content-Type: text/x-csrc; charset=us-ascii Content-Disposition: attachment; filename="tst-tc.c" #include #include #include #include #include static char *temp_filename; static int temp_fd; #define FAIL(str) \ do { printf ("error: %s (line %d)\n", str, __LINE__); return 1; } while (0) int main(void) { struct stat st; char buf[1000]; off_t offset=0; asprintf(&temp_filename, "/%s/%sXXXXXX", "tmp", "trunc"); temp_fd = mkstemp(temp_filename); memset (buf, 0xcf, sizeof (buf)); if (pwrite (temp_fd, buf, sizeof (buf), offset) != sizeof (buf)) FAIL ("write failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + sizeof (buf))) FAIL ("initial size wrong"); if (ftruncate (temp_fd, offset + 800) < 0) FAIL ("size reduction with ftruncate failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800)) FAIL ("size after reduction with ftruncate is incorrect"); /* The following test covers more than POSIX. POSIX does not require that ftruncate() can increase the file size. But we are testing Unix systems. */ if (ftruncate (temp_fd, offset + 1200) < 0) FAIL ("size increate with ftruncate failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200)) FAIL ("size after increase is incorrect"); if (truncate (temp_filename, offset + 800) < 0) FAIL ("size reduction with truncate failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800)) FAIL ("size after reduction with truncate incorrect"); /* The following test covers more than POSIX. POSIX does not require that truncate() can increase the file size. But we are testing Unix systems. */ if (truncate (temp_filename, (offset + 1200)) < 0) FAIL ("size increase with truncate failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200)) FAIL ("size increase with truncate is incorrect"); return 0; } --QcIKgUAnjsmZRbWM--