Author: mjg
Date: Fri Oct 9 20:31:42 2020
New Revision: 366587
URL: https://svnweb.freebsd.org/changeset/base/366587
Log:
vfs: fix a panic when truncating comming from copy_file_range
Truncating requires an exclusive lock, but it was not taken if the
filesystem indicates support for shared writes. This only concerns
ZFS.
In particular fixes cp of files which have trailing holes.
Reported by: bdrewery
Modified:
head/sys/kern/vfs_vnops.c
Modified: head/sys/kern/vfs_vnops.c
==============================================================================
--- head/sys/kern/vfs_vnops.c Fri Oct 9 20:30:27 2020 (r366586)
+++ head/sys/kern/vfs_vnops.c Fri Oct 9 20:31:42 2020 (r366587)
@@ -2975,18 +2975,22 @@ vn_write_outvp(struct vnode *outvp, char *dat, off_t o
bwillwrite();
mp = NULL;
error = vn_start_write(outvp, &mp, V_WAIT);
- if (error == 0) {
+ if (error != 0)
+ break;
+ if (growfile) {
+ error = vn_lock(outvp, LK_EXCLUSIVE);
+ if (error == 0) {
+ error = vn_truncate_locked(outvp, outoff + xfer,
+ false, cred);
+ VOP_UNLOCK(outvp);
+ }
+ } else {
if (MNT_SHARED_WRITES(mp))
lckf = LK_SHARED;
else
lckf = LK_EXCLUSIVE;
error = vn_lock(outvp, lckf);
- }
- if (error == 0) {
- if (growfile)
- error = vn_truncate_locked(outvp, outoff + xfer,
- false, cred);
- else {
+ if (error == 0) {
error = vn_rdwr(UIO_WRITE, outvp, dat, xfer2,
outoff, UIO_SYSSPACE, IO_NODELOCKED,
curthread->td_ucred, cred, NULL, curthread);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"