Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more constraints for block cloning #15251

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions module/zfs/zfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,9 +1172,20 @@ zfs_clone_range(znode_t *inzp, uint64_t *inoffp, znode_t *outzp,
inblksz = inzp->z_blksz;

/*
* We cannot clone into files with different block size.
* We cannot clone into files with different block size if we can't
* grow it (block size is already bigger or more than one block).
*/
if (inblksz != outzp->z_blksz && outzp->z_size > inblksz) {
if (inblksz != outzp->z_blksz && (outzp->z_size > outzp->z_blksz ||
outzp->z_size > inblksz)) {
error = SET_ERROR(EINVAL);
goto unlock;
}

/*
* Block size must be power-of-2 if destination offset != 0.
* There can be no multiple blocks of non-power-of-2 size.
*/
if (outoff != 0 && !ISP2(inblksz)) {
error = SET_ERROR(EINVAL);
goto unlock;
}
Expand Down Expand Up @@ -1358,6 +1369,12 @@ zfs_clone_range(znode_t *inzp, uint64_t *inoffp, znode_t *outzp,
*inoffp += done;
*outoffp += done;
*lenp = done;
} else {
/*
* If we made no progress, there must be a good reason.
* EOF is handled explicitly above, before the loop.
*/
ASSERT3S(error, !=, 0);
}

zfs_exit_two(inzfsvfs, outzfsvfs, FTAG);
Expand Down