FreeBSD: Implement hole-punching support
This adds supports for hole-punching facilities in the FreeBSD kernel starting from __FreeBSD_version 1400032. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Signed-off-by: Ka Ho Ng <khng@FreeBSD.org> Sponsored-by: The FreeBSD Foundation Closes #12458
This commit is contained in:
parent
1467a1bb33
commit
1f31889046
|
@ -5237,6 +5237,11 @@ zfs_freebsd_pathconf(struct vop_pathconf_args *ap)
|
|||
case _PC_NAME_MAX:
|
||||
*ap->a_retval = NAME_MAX;
|
||||
return (0);
|
||||
#if __FreeBSD_version >= 1400032
|
||||
case _PC_DEALLOC_PRESENT:
|
||||
*ap->a_retval = 1;
|
||||
return (0);
|
||||
#endif
|
||||
case _PC_PIPE_BUF:
|
||||
if (ap->a_vp->v_type == VDIR || ap->a_vp->v_type == VFIFO) {
|
||||
*ap->a_retval = PIPE_BUF;
|
||||
|
@ -6076,6 +6081,55 @@ zfs_vptocnp(struct vop_vptocnp_args *ap)
|
|||
return (error);
|
||||
}
|
||||
|
||||
#if __FreeBSD_version >= 1400032
|
||||
static int
|
||||
zfs_deallocate(struct vop_deallocate_args *ap)
|
||||
{
|
||||
znode_t *zp = VTOZ(ap->a_vp);
|
||||
zfsvfs_t *zfsvfs = zp->z_zfsvfs;
|
||||
zilog_t *zilog;
|
||||
off_t off, len, file_sz;
|
||||
int error;
|
||||
|
||||
ZFS_ENTER(zfsvfs);
|
||||
ZFS_VERIFY_ZP(zp);
|
||||
|
||||
/*
|
||||
* Callers might not be able to detect properly that we are read-only,
|
||||
* so check it explicitly here.
|
||||
*/
|
||||
if (zfs_is_readonly(zfsvfs)) {
|
||||
ZFS_EXIT(zfsvfs);
|
||||
return (SET_ERROR(EROFS));
|
||||
}
|
||||
|
||||
zilog = zfsvfs->z_log;
|
||||
off = *ap->a_offset;
|
||||
len = *ap->a_len;
|
||||
file_sz = zp->z_size;
|
||||
if (off + len > file_sz)
|
||||
len = file_sz - off;
|
||||
/* Fast path for out-of-range request. */
|
||||
if (len <= 0) {
|
||||
*ap->a_len = 0;
|
||||
ZFS_EXIT(zfsvfs);
|
||||
return (0);
|
||||
}
|
||||
|
||||
error = zfs_freesp(zp, off, len, O_RDWR, TRUE);
|
||||
if (error == 0) {
|
||||
if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS ||
|
||||
(ap->a_ioflag & IO_SYNC) != 0)
|
||||
zil_commit(zilog, zp->z_id);
|
||||
*ap->a_offset = off + len;
|
||||
*ap->a_len = 0;
|
||||
}
|
||||
|
||||
ZFS_EXIT(zfsvfs);
|
||||
return (error);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct vop_vector zfs_vnodeops;
|
||||
struct vop_vector zfs_fifoops;
|
||||
struct vop_vector zfs_shareops;
|
||||
|
@ -6095,6 +6149,9 @@ struct vop_vector zfs_vnodeops = {
|
|||
#endif
|
||||
.vop_access = zfs_freebsd_access,
|
||||
.vop_allocate = VOP_EINVAL,
|
||||
#if __FreeBSD_version >= 1400032
|
||||
.vop_deallocate = zfs_deallocate,
|
||||
#endif
|
||||
.vop_lookup = zfs_cache_lookup,
|
||||
.vop_cachedlookup = zfs_freebsd_cachedlookup,
|
||||
.vop_getattr = zfs_freebsd_getattr,
|
||||
|
|
|
@ -1487,12 +1487,16 @@ zfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
|
|||
error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, off, len);
|
||||
|
||||
if (error == 0) {
|
||||
#if __FreeBSD_version >= 1400032
|
||||
vnode_pager_purge_range(ZTOV(zp), off, off + len);
|
||||
#else
|
||||
/*
|
||||
* In FreeBSD we cannot free block in the middle of a file,
|
||||
* but only at the end of a file, so this code path should
|
||||
* never happen.
|
||||
* Before __FreeBSD_version 1400032 we cannot free block in the
|
||||
* middle of a file, but only at the end of a file, so this code
|
||||
* path should never happen.
|
||||
*/
|
||||
vnode_pager_setsize(ZTOV(zp), off);
|
||||
#endif
|
||||
}
|
||||
|
||||
zfs_rangelock_exit(lr);
|
||||
|
|
Loading…
Reference in New Issue