zfs: Add vfs.zfs.bclone_enabled sysctl.

Keep block cloning disabled by default for now, but allow to enable and
use it after setting vfs.zfs.bclone_enabled to 1, so people can easily
try it.

Approved by:	oshogbo
Reviewed by:	mm, oshogbo
Differential Revision:	https://reviews.freebsd.org/D39613
This commit is contained in:
Pawel Jakub Dawidek 2023-04-17 03:38:30 -07:00
parent 401f03445e
commit 068913e4ba
3 changed files with 11 additions and 2 deletions

View File

@ -287,6 +287,7 @@ typedef struct zfid_long {
extern uint_t zfs_fsyncer_key; extern uint_t zfs_fsyncer_key;
extern int zfs_super_owner; extern int zfs_super_owner;
extern int zfs_bclone_enabled;
extern void zfs_init(void); extern void zfs_init(void);
extern void zfs_fini(void); extern void zfs_fini(void);

View File

@ -89,6 +89,10 @@ int zfs_debug_level;
SYSCTL_INT(_vfs_zfs, OID_AUTO, debug, CTLFLAG_RWTUN, &zfs_debug_level, 0, SYSCTL_INT(_vfs_zfs, OID_AUTO, debug, CTLFLAG_RWTUN, &zfs_debug_level, 0,
"Debug level"); "Debug level");
int zfs_bclone_enabled;
SYSCTL_INT(_vfs_zfs, OID_AUTO, bclone_enabled, CTLFLAG_RWTUN,
&zfs_bclone_enabled, 0, "Enable block cloning");
struct zfs_jailparam { struct zfs_jailparam {
int mount_snapshot; int mount_snapshot;
}; };

View File

@ -6214,7 +6214,6 @@ zfs_deallocate(struct vop_deallocate_args *ap)
} }
#endif #endif
#if 0
#ifndef _SYS_SYSPROTO_H_ #ifndef _SYS_SYSPROTO_H_
struct vop_copy_file_range_args { struct vop_copy_file_range_args {
struct vnode *a_invp; struct vnode *a_invp;
@ -6245,6 +6244,11 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range_args *ap)
int error; int error;
uint64_t len = *ap->a_lenp; uint64_t len = *ap->a_lenp;
if (!zfs_bclone_enabled) {
mp = NULL;
goto bad_write_fallback;
}
/* /*
* TODO: If offset/length is not aligned to recordsize, use * TODO: If offset/length is not aligned to recordsize, use
* vn_generic_copy_file_range() on this fragment. * vn_generic_copy_file_range() on this fragment.
@ -6310,7 +6314,6 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range_args *ap)
ap->a_incred, ap->a_outcred, ap->a_fsizetd); ap->a_incred, ap->a_outcred, ap->a_fsizetd);
return (error); return (error);
} }
#endif
struct vop_vector zfs_vnodeops; struct vop_vector zfs_vnodeops;
struct vop_vector zfs_fifoops; struct vop_vector zfs_fifoops;
@ -6375,6 +6378,7 @@ struct vop_vector zfs_vnodeops = {
#if __FreeBSD_version >= 1400043 #if __FreeBSD_version >= 1400043
.vop_add_writecount = vop_stdadd_writecount_nomsync, .vop_add_writecount = vop_stdadd_writecount_nomsync,
#endif #endif
.vop_copy_file_range = zfs_freebsd_copy_file_range,
}; };
VFS_VOP_VECTOR_REGISTER(zfs_vnodeops); VFS_VOP_VECTOR_REGISTER(zfs_vnodeops);