Skip to content

Commit 87dfd68

Browse files
macdiceamotin
authored andcommitted
Add FreeBSD posix_fadvise support.
As commit 320f0c6 did for Linux, connect POSIX_FADV_WILLNEED up to dmu_prefetch() on FreeBSD. Reviewed-by: Mateusz Guzik <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Thomas Munro <[email protected]>
1 parent bb2cc31 commit 87dfd68

File tree

5 files changed

+90
-5
lines changed

5 files changed

+90
-5
lines changed

module/os/freebsd/zfs/zfs_vnops_os.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6055,6 +6055,78 @@ zfs_freebsd_aclcheck(struct vop_aclcheck_args *ap)
60556055
return (EOPNOTSUPP);
60566056
}
60576057

6058+
#ifndef _SYS_SYSPROTO_H_
6059+
struct vop_advise_args {
6060+
struct vnode *a_vp;
6061+
off_t a_start;
6062+
off_t a_end;
6063+
int a_advice;
6064+
};
6065+
#endif
6066+
6067+
static int
6068+
zfs_freebsd_advise(struct vop_advise_args *ap)
6069+
{
6070+
vnode_t *vp = ap->a_vp;
6071+
off_t start = ap->a_start;
6072+
off_t end = ap->a_end;
6073+
int advice = ap->a_advice;
6074+
off_t len;
6075+
znode_t *zp;
6076+
zfsvfs_t *zfsvfs;
6077+
objset_t *os;
6078+
int error = 0;
6079+
6080+
if (end < start)
6081+
return (EINVAL);
6082+
6083+
error = vn_lock(vp, LK_SHARED);
6084+
if (error)
6085+
return (error);
6086+
6087+
zp = VTOZ(vp);
6088+
zfsvfs = zp->z_zfsvfs;
6089+
os = zp->z_zfsvfs->z_os;
6090+
6091+
if ((error = zfs_enter_verify_zp(zfsvfs, zp, FTAG)) != 0)
6092+
goto out_unlock;
6093+
6094+
/* kern_posix_fadvise points to the last byte, we want one past */
6095+
if (end != OFF_MAX)
6096+
end += 1;
6097+
len = end - start;
6098+
6099+
switch (advice) {
6100+
case POSIX_FADV_WILLNEED:
6101+
/*
6102+
* Pass on the caller's size directly, but note that
6103+
* dmu_prefetch_max will effectively cap it. If there really
6104+
* is a larger sequential access pattern, perhaps dmu_zfetch
6105+
* will detect it.
6106+
*/
6107+
dmu_prefetch(os, zp->z_id, 0, start, len,
6108+
ZIO_PRIORITY_ASYNC_READ);
6109+
break;
6110+
case POSIX_FADV_NORMAL:
6111+
case POSIX_FADV_RANDOM:
6112+
case POSIX_FADV_SEQUENTIAL:
6113+
case POSIX_FADV_DONTNEED:
6114+
case POSIX_FADV_NOREUSE:
6115+
/* ignored for now */
6116+
break;
6117+
default:
6118+
error = EINVAL;
6119+
break;
6120+
}
6121+
6122+
zfs_exit(zfsvfs, FTAG);
6123+
6124+
out_unlock:
6125+
VOP_UNLOCK(vp);
6126+
6127+
return (error);
6128+
}
6129+
60586130
static int
60596131
zfs_vptocnp(struct vop_vptocnp_args *ap)
60606132
{
@@ -6293,6 +6365,7 @@ struct vop_vector zfs_vnodeops = {
62936365
.vop_link = zfs_freebsd_link,
62946366
.vop_symlink = zfs_freebsd_symlink,
62956367
.vop_readlink = zfs_freebsd_readlink,
6368+
.vop_advise = zfs_freebsd_advise,
62966369
.vop_read = zfs_freebsd_read,
62976370
.vop_write = zfs_freebsd_write,
62986371
.vop_remove = zfs_freebsd_remove,

module/zfs/dmu.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,18 @@ dmu_prefetch_by_dnode(dnode_t *dn, int64_t level, uint64_t offset,
730730
*/
731731
rw_enter(&dn->dn_struct_rwlock, RW_READER);
732732
if (dn->dn_datablkshift != 0) {
733+
734+
/*
735+
* Limit prefetch to present blocks.
736+
*/
737+
uint64_t size = (dn->dn_maxblkid + 1) << dn->dn_datablkshift;
738+
if (offset >= size) {
739+
rw_exit(&dn->dn_struct_rwlock);
740+
return;
741+
}
742+
if (offset + len < offset || offset + len > size)
743+
len = size - offset;
744+
733745
/*
734746
* The object has multiple blocks. Calculate the full range
735747
* of blocks [start, end2) and then split it into two parts,

tests/runfiles/common.run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,10 @@ tags = ['functional', 'direct']
717717
tests = ['exec_001_pos', 'exec_002_neg']
718718
tags = ['functional', 'exec']
719719

720+
[tests/functional/fadvise]
721+
tests = ['fadvise_willneed']
722+
tags = ['functional', 'fadvise']
723+
720724
[tests/functional/failmode]
721725
tests = ['failmode_dmu_tx_wait', 'failmode_dmu_tx_continue']
722726
tags = ['functional', 'failmode']

tests/runfiles/linux.run

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ tests = ['events_001_pos', 'events_002_pos', 'zed_rc_filter', 'zed_fd_spill',
112112
'zed_slow_io', 'zed_slow_io_many_vdevs', 'zed_diagnose_multiple']
113113
tags = ['functional', 'events']
114114

115-
[tests/functional/fadvise:Linux]
116-
tests = ['fadvise_willneed']
117-
tags = ['functional', 'fadvise']
118-
119115
[tests/functional/fallocate:Linux]
120116
tests = ['fallocate_prealloc', 'fallocate_zero-range']
121117
tags = ['functional', 'fallocate']

tests/zfs-tests/cmd/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ scripts_zfs_tests_bin_PROGRAMS += %D%/read_dos_attributes %D%/write_dos_attribu
140140

141141
scripts_zfs_tests_bin_PROGRAMS += %D%/randfree_file
142142
%C%_randfree_file_SOURCES = %D%/file/randfree_file.c
143+
endif
143144

144145
scripts_zfs_tests_bin_PROGRAMS += %D%/file_fadvise
145146
%C%_file_fadvise_SOURCES = %D%/file/file_fadvise.c
146-
endif

0 commit comments

Comments
 (0)