Introduce zfs rewrite subcommand (#17246)

This allows to rewrite content of specified file(s) as-is without
modifications, but at a different location, compression, checksum,
dedup, copies and other parameter values.  It is faster than read
plus write, since it does not require data copying to user-space.
It is also faster for sync=always datasets, since without data
modification it does not require ZIL writing.  Also since it is
protected by normal range range locks, it can be done under any
other load.  Also it does not affect file's modification time or
other properties.

Signed-off-by:	Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Rob Norris <robn@despairlabs.com>
This commit is contained in:
Alexander Motin
2025-05-12 13:22:17 -04:00
committed by GitHub
parent 9aae14a14a
commit 49fbdd4533
16 changed files with 636 additions and 5 deletions
+12
View File
@@ -305,6 +305,18 @@ zfs_ioctl(vnode_t *vp, ulong_t com, intptr_t data, int flag, cred_t *cred,
*(offset_t *)data = off;
return (0);
}
case ZFS_IOC_REWRITE: {
zfs_rewrite_args_t *args = (zfs_rewrite_args_t *)data;
if ((flag & FWRITE) == 0)
return (SET_ERROR(EBADF));
error = vn_lock(vp, LK_SHARED);
if (error)
return (error);
error = zfs_rewrite(VTOZ(vp), args->off, args->len,
args->flags, args->arg);
VOP_UNLOCK(vp);
return (error);
}
}
return (SET_ERROR(ENOTTY));
}
+23
View File
@@ -985,6 +985,27 @@ zpl_ioctl_setdosflags(struct file *filp, void __user *arg)
return (err);
}
static int
zpl_ioctl_rewrite(struct file *filp, void __user *arg)
{
struct inode *ip = file_inode(filp);
zfs_rewrite_args_t args;
fstrans_cookie_t cookie;
int err;
if (copy_from_user(&args, arg, sizeof (args)))
return (-EFAULT);
if (unlikely(!(filp->f_mode & FMODE_WRITE)))
return (-EBADF);
cookie = spl_fstrans_mark();
err = -zfs_rewrite(ITOZ(ip), args.off, args.len, args.flags, args.arg);
spl_fstrans_unmark(cookie);
return (err);
}
static long
zpl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
@@ -1003,6 +1024,8 @@ zpl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return (zpl_ioctl_getdosflags(filp, (void *)arg));
case ZFS_IOC_SETDOSFLAGS:
return (zpl_ioctl_setdosflags(filp, (void *)arg));
case ZFS_IOC_REWRITE:
return (zpl_ioctl_rewrite(filp, (void *)arg));
default:
return (-ENOTTY);
}