From owner-svn-src-head@freebsd.org Mon Jul 1 20:41:45 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 403A715E40D4; Mon, 1 Jul 2019 20:41:45 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BE7F18F45D; Mon, 1 Jul 2019 20:41:44 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8A75A1A3F3; Mon, 1 Jul 2019 20:41:44 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x61KfiSC095467; Mon, 1 Jul 2019 20:41:44 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x61KfiMD095201; Mon, 1 Jul 2019 20:41:44 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201907012041.x61KfiMD095201@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Mon, 1 Jul 2019 20:41:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r349582 - in head/sys: kern sys X-SVN-Group: head X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: in head/sys: kern sys X-SVN-Commit-Revision: 349582 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: BE7F18F45D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.96)[-0.965,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jul 2019 20:41:45 -0000 Author: rmacklem Date: Mon Jul 1 20:41:43 2019 New Revision: 349582 URL: https://svnweb.freebsd.org/changeset/base/349582 Log: Factor out the code that does a VOP_SETATTR(size) from vn_truncate(). This patch factors the code in vn_truncate() that does the actual VOP_SETATTR() of size into a separate function called vn_truncate_locked(). This will allow the NFS server and the patch that adds a copy_file_range(2) syscall to call this function instead of duplicating the code and carrying over changes, such as the recent r347151. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D20808 Modified: head/sys/kern/vfs_vnops.c head/sys/sys/vnode.h Modified: head/sys/kern/vfs_vnops.c ============================================================================== --- head/sys/kern/vfs_vnops.c Mon Jul 1 20:37:35 2019 (r349581) +++ head/sys/kern/vfs_vnops.c Mon Jul 1 20:41:43 2019 (r349582) @@ -1289,7 +1289,6 @@ static int vn_truncate(struct file *fp, off_t length, struct ucred *active_cred, struct thread *td) { - struct vattr vattr; struct mount *mp; struct vnode *vp; void *rl_cookie; @@ -1316,20 +1315,35 @@ vn_truncate(struct file *fp, off_t length, struct ucre if (error) goto out; #endif + error = vn_truncate_locked(vp, length, (fp->f_flag & O_FSYNC) != 0, + fp->f_cred); +out: + VOP_UNLOCK(vp, 0); + vn_finished_write(mp); +out1: + vn_rangelock_unlock(vp, rl_cookie); + return (error); +} + +/* + * Truncate a file that is already locked. + */ +int +vn_truncate_locked(struct vnode *vp, off_t length, bool sync, + struct ucred *cred) +{ + struct vattr vattr; + int error; + error = VOP_ADD_WRITECOUNT(vp, 1); if (error == 0) { VATTR_NULL(&vattr); vattr.va_size = length; - if ((fp->f_flag & O_FSYNC) != 0) + if (sync) vattr.va_vaflags |= VA_SYNC; - error = VOP_SETATTR(vp, &vattr, fp->f_cred); + error = VOP_SETATTR(vp, &vattr, cred); VOP_ADD_WRITECOUNT_CHECKED(vp, -1); } -out: - VOP_UNLOCK(vp, 0); - vn_finished_write(mp); -out1: - vn_rangelock_unlock(vp, rl_cookie); return (error); } Modified: head/sys/sys/vnode.h ============================================================================== --- head/sys/sys/vnode.h Mon Jul 1 20:37:35 2019 (r349581) +++ head/sys/sys/vnode.h Mon Jul 1 20:41:43 2019 (r349582) @@ -695,6 +695,8 @@ int vn_stat(struct vnode *vp, struct stat *sb, struct int vn_start_write(struct vnode *vp, struct mount **mpp, int flags); int vn_start_secondary_write(struct vnode *vp, struct mount **mpp, int flags); +int vn_truncate_locked(struct vnode *vp, off_t length, bool sync, + struct ucred *cred); int vn_writechk(struct vnode *vp); int vn_extattr_get(struct vnode *vp, int ioflg, int attrnamespace, const char *attrname, int *buflen, char *buf, struct thread *td);