Skip to content

Commit 063daa8

Browse files
authored
Fix handling of errors from dmu_write_uio_dbuf() on FreeBSD
FreeBSD's implementation of zfs_uio_fault_move() returns EFAULT when a page fault occurs while copying data in or out of user buffers. The VFS treats such errors specially and will retry the I/O operation (which may have made some partial progress). When the FreeBSD and Linux implementations of zfs_write() were merged, the handling of errors from dmu_write_uio_dbuf() changed such that EFAULT is not handled as a partial write. For example, when appending to a file, the z_size field of the znode is not updated after a partial write resulting in EFAULT. Restore the old handling of errors from dmu_write_uio_dbuf() to fix this. This should have no impact on Linux, which has special handling for EFAULT already. Reviewed-by: Andriy Gapon <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Mark Johnston <[email protected]> Closes #12964
1 parent 63a2645 commit 063daa8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

module/zfs/zfs_vnops.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ zfs_read(struct znode *zp, zfs_uio_t *uio, int ioflag, cred_t *cr)
338338
int
339339
zfs_write(znode_t *zp, zfs_uio_t *uio, int ioflag, cred_t *cr)
340340
{
341-
int error = 0;
341+
int error = 0, error1;
342342
ssize_t start_resid = zfs_uio_resid(uio);
343343

344344
/*
@@ -576,7 +576,11 @@ zfs_write(znode_t *zp, zfs_uio_t *uio, int ioflag, cred_t *cr)
576576
continue;
577577
}
578578
#endif
579-
if (error != 0) {
579+
/*
580+
* On FreeBSD, EFAULT should be propagated back to the
581+
* VFS, which will handle faulting and will retry.
582+
*/
583+
if (error != 0 && error != EFAULT) {
580584
dmu_tx_commit(tx);
581585
break;
582586
}
@@ -660,7 +664,7 @@ zfs_write(znode_t *zp, zfs_uio_t *uio, int ioflag, cred_t *cr)
660664
while ((end_size = zp->z_size) < zfs_uio_offset(uio)) {
661665
(void) atomic_cas_64(&zp->z_size, end_size,
662666
zfs_uio_offset(uio));
663-
ASSERT(error == 0);
667+
ASSERT(error == 0 || error == EFAULT);
664668
}
665669
/*
666670
* If we are replaying and eof is non zero then force
@@ -670,7 +674,10 @@ zfs_write(znode_t *zp, zfs_uio_t *uio, int ioflag, cred_t *cr)
670674
if (zfsvfs->z_replay && zfsvfs->z_replay_eof != 0)
671675
zp->z_size = zfsvfs->z_replay_eof;
672676

673-
error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
677+
error1 = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
678+
if (error1 != 0)
679+
/* Avoid clobbering EFAULT. */
680+
error = error1;
674681

675682
zfs_log_write(zilog, tx, TX_WRITE, zp, woff, tx_bytes, ioflag,
676683
NULL, NULL);

0 commit comments

Comments
 (0)