mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-25 11:47:43 +03:00
Fix lseek(SEEK_DATA/SEEK_HOLE) mmap consistency
When using lseek(2) to report data/holes memory mapped regions of the file were ignored. This could result in incorrect results. To handle this zfs_holey_common() was updated to asynchronously writeback any dirty mmap(2) regions prior to reporting holes. Additionally, while not strictly required, the dn_struct_rwlock is now held over the dirty check to prevent the dnode structure from changing. This ensures that a clean dnode can't be dirtied before the data/hole is located. The range lock is now also taken to ensure the call cannot race with zfs_write(). Furthermore, the code was refactored to provide a dnode_is_dirty() helper function which checks the dnode for any dirty records to determine its dirtiness. Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Tony Hutter <hutter2@llnl.gov> Reviewed-by: Rich Ercolani <rincebrain@gmail.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #11900 Closes #12724
This commit is contained in:
@@ -85,6 +85,7 @@ zfs_fsync(znode_t *zp, int syncflag, cred_t *cr)
|
||||
static int
|
||||
zfs_holey_common(znode_t *zp, ulong_t cmd, loff_t *off)
|
||||
{
|
||||
zfs_locked_range_t *lr;
|
||||
uint64_t noff = (uint64_t)*off; /* new offset */
|
||||
uint64_t file_sz;
|
||||
int error;
|
||||
@@ -100,12 +101,18 @@ zfs_holey_common(znode_t *zp, ulong_t cmd, loff_t *off)
|
||||
else
|
||||
hole = B_FALSE;
|
||||
|
||||
/* Flush any mmap()'d data to disk */
|
||||
if (zn_has_cached_data(zp))
|
||||
zn_flush_cached_data(zp, B_FALSE);
|
||||
|
||||
lr = zfs_rangelock_enter(&zp->z_rangelock, 0, file_sz, RL_READER);
|
||||
error = dmu_offset_next(ZTOZSB(zp)->z_os, zp->z_id, hole, &noff);
|
||||
zfs_rangelock_exit(lr);
|
||||
|
||||
if (error == ESRCH)
|
||||
return (SET_ERROR(ENXIO));
|
||||
|
||||
/* file was dirty, so fall back to using generic logic */
|
||||
/* File was dirty, so fall back to using generic logic */
|
||||
if (error == EBUSY) {
|
||||
if (hole)
|
||||
*off = file_sz;
|
||||
|
||||
Reference in New Issue
Block a user