diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c index 107cd69c756c..e799a7091b8e 100644 --- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c +++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c @@ -6270,6 +6270,11 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range_args *ap) goto bad_write_fallback; } } + + if (invp->v_mount->mnt_vfc != outvp->v_mount->mnt_vfc) { + goto bad_write_fallback; + } + if (invp == outvp) { if (vn_lock(outvp, LK_EXCLUSIVE) != 0) { goto bad_write_fallback; diff --git a/sys/fs/nullfs/null_vnops.c b/sys/fs/nullfs/null_vnops.c index 7607b44e36c3..4747b1dd5b82 100644 --- a/sys/fs/nullfs/null_vnops.c +++ b/sys/fs/nullfs/null_vnops.c @@ -1127,6 +1127,23 @@ null_vput_pair(struct vop_vput_pair_args *ap) return (res); } +static int +null_getlowvnode(struct vop_getlowvnode_args *ap) +{ + struct vnode *vp, *vpl; + + vp = ap->a_vp; + if (vn_lock(vp, LK_SHARED) != 0) + return (EBADF); + + vpl = NULLVPTOLOWERVP(vp); + vhold(vpl); + VOP_UNLOCK(vp); + VOP_GETLOWVNODE(vpl, ap->a_vplp, ap->a_flags); + vdrop(vpl); + return (0); +} + /* * Global vfs data structures */ @@ -1139,6 +1156,7 @@ struct vop_vector null_vnodeops = { .vop_bmap = VOP_EOPNOTSUPP, .vop_stat = null_stat, .vop_getattr = null_getattr, + .vop_getlowvnode = null_getlowvnode, .vop_getwritemount = null_getwritemount, .vop_inactive = null_inactive, .vop_need_inactive = null_need_inactive, @@ -1159,5 +1177,6 @@ struct vop_vector null_vnodeops = { .vop_vptofh = null_vptofh, .vop_add_writecount = null_add_writecount, .vop_vput_pair = null_vput_pair, + .vop_copy_file_range = VOP_PANIC, }; VFS_VOP_VECTOR_REGISTER(null_vnodeops); diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index a342cbb80c9c..67c7ace5f72f 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -82,6 +82,7 @@ static int vop_stdgetpages_async(struct vop_getpages_async_args *ap); static int vop_stdread_pgcache(struct vop_read_pgcache_args *ap); static int vop_stdstat(struct vop_stat_args *ap); static int vop_stdvput_pair(struct vop_vput_pair_args *ap); +static int vop_stdgetlowvnode(struct vop_getlowvnode_args *ap); /* * This vnode table stores what we want to do if the filesystem doesn't @@ -112,6 +113,7 @@ struct vop_vector default_vnodeops = { .vop_fsync = VOP_NULL, .vop_stat = vop_stdstat, .vop_fdatasync = vop_stdfdatasync, + .vop_getlowvnode = vop_stdgetlowvnode, .vop_getpages = vop_stdgetpages, .vop_getpages_async = vop_stdgetpages_async, .vop_getwritemount = vop_stdgetwritemount, @@ -1607,3 +1609,11 @@ vop_stdvput_pair(struct vop_vput_pair_args *ap) vput(vp); return (0); } + +static int +vop_stdgetlowvnode(struct vop_getlowvnode_args *ap) +{ + vref(ap->a_vp); + *ap->a_vplp = ap->a_vp; + return (0); +} diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index e90330b08cbc..67d719caec18 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -3070,10 +3070,12 @@ vn_copy_file_range(struct vnode *invp, off_t *inoffp, struct vnode *outvp, struct ucred *outcred, struct thread *fsize_td) { struct mount *inmp, *outmp; + struct vnode *invpl, *outvpl; int error; size_t len; uint64_t uval; + invpl = outvpl = NULL; len = *lenp; *lenp = 0; /* For error returns. */ error = 0; @@ -3099,17 +3101,22 @@ vn_copy_file_range(struct vnode *invp, off_t *inoffp, struct vnode *outvp, if (len == 0) goto out; - inmp = invp->v_mount; - outmp = outvp->v_mount; - if (inmp == NULL || outmp == NULL) { - error = EBADF; + error = VOP_GETLOWVNODE(invp, &invpl, FREAD); + if (error != 0) goto out; - } + error = VOP_GETLOWVNODE(outvp, &outvpl, FWRITE); + if (error != 0) + goto out1; + + inmp = invpl->v_mount; + outmp = outvpl->v_mount; + if (inmp == NULL || outmp == NULL) + goto out2; for (;;) { error = vfs_busy(inmp, 0); if (error != 0) - goto out; + goto out2; if (inmp == outmp) break; error = vfs_busy(outmp, MBF_NOWAIT); @@ -3120,27 +3127,23 @@ vn_copy_file_range(struct vnode *invp, off_t *inoffp, struct vnode *outvp, vfs_unbusy(outmp); continue; } - goto out; + goto out2; } break; } - /* - * If the two vnodes are for the same file system type, call - * VOP_COPY_FILE_RANGE(), otherwise call vn_generic_copy_file_range() - * which can handle copies across multiple file system types. - */ *lenp = len; - if (inmp == outmp || strcmp(inmp->mnt_vfc->vfc_name, - outmp->mnt_vfc->vfc_name) == 0) - error = VOP_COPY_FILE_RANGE(invp, inoffp, outvp, outoffp, - lenp, flags, incred, outcred, fsize_td); - else - error = vn_generic_copy_file_range(invp, inoffp, outvp, - outoffp, lenp, flags, incred, outcred, fsize_td); + error = VOP_COPY_FILE_RANGE(invpl, inoffp, outvpl, outoffp, + lenp, flags, incred, outcred, fsize_td); vfs_unbusy(outmp); if (inmp != outmp) vfs_unbusy(inmp); +out2: + if (outvpl != NULL) + vrele(outvpl); +out1: + if (invpl != NULL) + vrele(invpl); out: return (error); } diff --git a/sys/kern/vnode_if.src b/sys/kern/vnode_if.src index c4051fdfe327..a2b6a7c8ff9f 100644 --- a/sys/kern/vnode_if.src +++ b/sys/kern/vnode_if.src @@ -468,6 +468,13 @@ vop_getwritemount { OUT struct mount **mpp; }; +%% getwritevnode vp = = = + +vop_getlowvnode { + IN struct vnode *vp; + OUT struct vnode **vplp; + IN int flags; +}; %% print vp - - -