Skip to content

Commit

Permalink
zfs: Add vfs.zfs.bclone_enabled sysctl.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Pawel Jakub Dawidek authored and Pawel Jakub Dawidek committed Apr 17, 2023
1 parent 401f034 commit 068913e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ typedef struct zfid_long {

extern uint_t zfs_fsyncer_key;
extern int zfs_super_owner;
extern int zfs_bclone_enabled;

extern void zfs_init(void);
extern void zfs_fini(void);
Expand Down
4 changes: 4 additions & 0 deletions sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vfsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ int zfs_debug_level;
SYSCTL_INT(_vfs_zfs, OID_AUTO, debug, CTLFLAG_RWTUN, &zfs_debug_level, 0,
"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 {
int mount_snapshot;
};
Expand Down
8 changes: 6 additions & 2 deletions sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -6214,7 +6214,6 @@ zfs_deallocate(struct vop_deallocate_args *ap)
}
#endif

#if 0
#ifndef _SYS_SYSPROTO_H_
struct vop_copy_file_range_args {
struct vnode *a_invp;
Expand Down Expand Up @@ -6245,6 +6244,11 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range_args *ap)
int error;
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
* vn_generic_copy_file_range() on this fragment.
Expand Down Expand Up @@ -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);
return (error);
}
#endif

struct vop_vector zfs_vnodeops;
struct vop_vector zfs_fifoops;
Expand Down Expand Up @@ -6375,6 +6378,7 @@ struct vop_vector zfs_vnodeops = {
#if __FreeBSD_version >= 1400043
.vop_add_writecount = vop_stdadd_writecount_nomsync,
#endif
.vop_copy_file_range = zfs_freebsd_copy_file_range,
};
VFS_VOP_VECTOR_REGISTER(zfs_vnodeops);

Expand Down

0 comments on commit 068913e

Please sign in to comment.