From owner-svn-src-head@freebsd.org Thu Jul 25 16:49:13 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CAA68A8D2A; Thu, 25 Jul 2019 16:49:13 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7C82D8A985; Thu, 25 Jul 2019 16:49:13 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) (Authenticated sender: kevans) by smtp.freebsd.org (Postfix) with ESMTPSA id 287C0888B; Thu, 25 Jul 2019 16:49:13 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mail-wm1-f51.google.com with SMTP id l2so45337469wmg.0; Thu, 25 Jul 2019 09:49:13 -0700 (PDT) X-Gm-Message-State: APjAAAVufpnQctdcs4vSKIIUBGqrJX2nH/e6WZexVvhuCuZrjw9o+FsS Io5odt3dkQiCX++2q8N6MF36RaK52MFDXGEhBhc= X-Google-Smtp-Source: APXvYqyTipxcHMlygfJCId0nvMzOkYnc+90zTxcpHUDsNLBjmhvRLA41IVVw6fGwWWuwlOgLuWyosPcXUd4t+pMu6wA= X-Received: by 2002:a05:600c:389:: with SMTP id w9mr54900791wmd.139.1564073352135; Thu, 25 Jul 2019 09:49:12 -0700 (PDT) MIME-Version: 1.0 References: <201907250546.x6P5kHWq076756@repo.freebsd.org> <20190725164607.zpa7w2pgrnahaxz4@mutt-hbsd> In-Reply-To: <20190725164607.zpa7w2pgrnahaxz4@mutt-hbsd> From: Kyle Evans Date: Thu, 25 Jul 2019 11:48:39 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r350315 - in head/sys: kern sys To: Shawn Webb Cc: Rick Macklem , svn-src-head , svn-src-all , src-committers Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 7C82D8A985 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)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.960,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:96.47.64.0/20, 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: Thu, 25 Jul 2019 16:49:13 -0000 On Thu, Jul 25, 2019 at 11:46 AM Shawn Webb wrote: > > Hey Rick, > > On Thu, Jul 25, 2019 at 05:46:17AM +0000, Rick Macklem wrote: > > Author: rmacklem > > Date: Thu Jul 25 05:46:16 2019 > > New Revision: 350315 > > URL: https://svnweb.freebsd.org/changeset/base/350315 > > > > Log: > > Add kernel support for a Linux compatible copy_file_range(2) syscall. > > > > This patch adds support to the kernel for a Linux compatible > > copy_file_range(2) syscall and the related VOP_COPY_FILE_RANGE(9). > > This syscall/VOP can be used by the NFSv4.2 client to implement the > > Copy operation against an NFSv4.2 server to do file copies locally on > > the server. > > The vn_generic_copy_file_range() function in this patch can be used > > by the NFSv4.2 server to implement the Copy operation. > > Fuse may also me able to use the VOP_COPY_FILE_RANGE() method. > > > > vn_generic_copy_file_range() attempts to maintain holes in the output > > file in the range to be copied, but may fail to do so if the input and > > output files are on different file systems with different _PC_MIN_HOLE_SIZE > > values. > > > > Separate commits will be done for the generated syscall files and userland > > changes. A commit for a compat32 syscall will be done later. > > > > Reviewed by: kib, asomers (plus comments by brooks, jilles) > > Relnotes: yes > > Differential Revision: https://reviews.freebsd.org/D20584 > > > > Modified: > > head/sys/kern/syscalls.master > > head/sys/kern/vfs_default.c > > head/sys/kern/vfs_syscalls.c > > head/sys/kern/vfs_vnops.c > > head/sys/kern/vnode_if.src > > head/sys/sys/syscallsubr.h > > head/sys/sys/vnode.h > > > > Modified: head/sys/kern/syscalls.master > > ============================================================================== > > --- head/sys/kern/syscalls.master Thu Jul 25 03:55:05 2019 (r350314) > > +++ head/sys/kern/syscalls.master Thu Jul 25 05:46:16 2019 (r350315) > > @@ -3175,6 +3175,16 @@ > > int flag > > ); > > } > > +569 AUE_NULL STD { > > + ssize_t copy_file_range( > > + int infd, > > + _Inout_opt_ off_t *inoffp, > > + int outfd, > > + _Inout_opt_ off_t *outoffp, > > + size_t len, > > + unsigned int flags > > + ); > > + } > > > > ; Please copy any additions and changes to the following compatability tables: > > ; sys/compat/freebsd32/syscalls.master > > > > Modified: head/sys/kern/vfs_default.c > > ============================================================================== > > --- head/sys/kern/vfs_default.c Thu Jul 25 03:55:05 2019 (r350314) > > +++ head/sys/kern/vfs_default.c Thu Jul 25 05:46:16 2019 (r350315) > > @@ -83,6 +83,7 @@ static int dirent_exists(struct vnode *vp, const char > > static int vop_stdis_text(struct vop_is_text_args *ap); > > static int vop_stdunset_text(struct vop_unset_text_args *ap); > > static int vop_stdadd_writecount(struct vop_add_writecount_args *ap); > > +static int vop_stdcopy_file_range(struct vop_copy_file_range_args *ap); > > static int vop_stdfdatasync(struct vop_fdatasync_args *ap); > > static int vop_stdgetpages_async(struct vop_getpages_async_args *ap); > > > > @@ -140,6 +141,7 @@ struct vop_vector default_vnodeops = { > > .vop_set_text = vop_stdset_text, > > .vop_unset_text = vop_stdunset_text, > > .vop_add_writecount = vop_stdadd_writecount, > > + .vop_copy_file_range = vop_stdcopy_file_range, > > }; > > > > /* > > @@ -1210,6 +1212,17 @@ vfs_stdnosync (mp, waitfor) > > { > > > > return (0); > > +} > > + > > +static int > > +vop_stdcopy_file_range(struct vop_copy_file_range_args *ap) > > +{ > > + int error; > > + > > + error = vn_generic_copy_file_range(ap->a_invp, ap->a_inoffp, > > + ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags, ap->a_incred, > > + ap->a_outcred, ap->a_fsizetd); > > + return (error); > > } > > > > int > > > > Modified: head/sys/kern/vfs_syscalls.c > > ============================================================================== > > --- head/sys/kern/vfs_syscalls.c Thu Jul 25 03:55:05 2019 (r350314) > > +++ head/sys/kern/vfs_syscalls.c Thu Jul 25 05:46:16 2019 (r350315) > > @@ -4814,3 +4814,122 @@ sys_posix_fadvise(struct thread *td, struct posix_fadv > > uap->advice); > > return (kern_posix_error(td, error)); > > } > > + > > +int > > +kern_copy_file_range(struct thread *td, int infd, off_t *inoffp, int outfd, > > + off_t *outoffp, size_t len, unsigned int flags) > > +{ > > + struct file *infp, *outfp; > > + struct vnode *invp, *outvp; > > + int error; > > + size_t retlen; > > + void *rl_rcookie, *rl_wcookie; > > + off_t savinoff, savoutoff; > > + > > + infp = outfp = NULL; > > + rl_rcookie = rl_wcookie = NULL; > > + savinoff = -1; > > + error = 0; > > + retlen = 0; > > + > > + if (flags != 0) { > > + error = EINVAL; > > + goto out; > > + } > > + if (len > SSIZE_MAX) > > + /* > > + * Although the len argument is size_t, the return argument > > + * is ssize_t (which is signed). Therefore a size that won't > > + * fit in ssize_t can't be returned. > > + */ > > + len = SSIZE_MAX; > > + > > + /* Get the file structures for the file descriptors. */ > > + error = fget_read(td, infd, &cap_read_rights, &infp); > > + if (error != 0) > > + goto out; > > + error = fget_write(td, outfd, &cap_write_rights, &outfp); > > + if (error != 0) > > + goto out; > > + > > + /* Set the offset pointers to the correct place. */ > > + if (inoffp == NULL) > > + inoffp = &infp->f_offset; > > + if (outoffp == NULL) > > + outoffp = &outfp->f_offset; > > + savinoff = *inoffp; > > + savoutoff = *outoffp; > > Should these two lines, saving the old inoffp and outoffp, be moved > before the two conditionals above? > Dereferencing potentially NULL pointers like that seems like a scary proposition; I think this reads most correctly given the context.