linux(4): implement copy_file_range(2)

copy_file_range(2) is implemented natively since r350315, make it available
for Linux binaries too.

Reviewed by:	kib (mentor), trasz (previous version)
Approved by:	kib (mentor)
Differential Revision:	https://reviews.freebsd.org/D22959
This commit is contained in:
Pawel Biernacki 2019-12-30 18:11:06 +00:00
parent c5ccc92c41
commit 54666dffa8
5 changed files with 41 additions and 8 deletions

View file

@ -144,8 +144,6 @@ DUMMY(userfaultfd);
DUMMY(membarrier);
/* Linux 4.4: */
DUMMY(mlock2);
/* Linux 4.5: */
DUMMY(copy_file_range);
/* Linux 4.6: */
DUMMY(preadv2);
DUMMY(pwritev2);

View file

@ -148,8 +148,6 @@ DUMMY(userfaultfd);
DUMMY(membarrier);
/* Linux 4.4: */
DUMMY(mlock2);
/* Linux 4.5: */
DUMMY(copy_file_range);
/* Linux 4.6: */
DUMMY(preadv2);
DUMMY(pwritev2);

View file

@ -142,8 +142,6 @@ DUMMY(userfaultfd);
DUMMY(membarrier);
/* Linux 4.4: */
DUMMY(mlock2);
/* Linux 4.5: */
DUMMY(copy_file_range);
/* Linux 4.6: */
DUMMY(preadv2);
DUMMY(pwritev2);

View file

@ -1565,3 +1565,44 @@ linux_fallocate(struct thread *td, struct linux_fallocate_args *args)
return (kern_posix_fallocate(td, args->fd, args->offset,
args->len));
}
int
linux_copy_file_range(struct thread *td, struct linux_copy_file_range_args
*args)
{
l_loff_t inoff, outoff, *inoffp, *outoffp;
int error, flags;
/*
* copy_file_range(2) on Linux doesn't define any flags (yet), so is
* the native implementation. Enforce it.
*/
if (args->flags != 0) {
linux_msg(td, "copy_file_range unsupported flags 0x%x",
args->flags);
return (EINVAL);
}
flags = 0;
inoffp = outoffp = NULL;
if (args->off_in != NULL) {
error = copyin(args->off_in, &inoff, sizeof(l_loff_t));
if (error != 0)
return (error);
inoffp = &inoff;
}
if (args->off_out != NULL) {
error = copyin(args->off_out, &outoff, sizeof(l_loff_t));
if (error != 0)
return (error);
outoffp = &outoff;
}
error = kern_copy_file_range(td, args->fd_in, inoffp, args->fd_out,
outoffp, args->len, flags);
if (error == 0 && args->off_in != NULL)
error = copyout(inoffp, args->off_in, sizeof(l_loff_t));
if (error == 0 && args->off_out != NULL)
error = copyout(outoffp, args->off_out, sizeof(l_loff_t));
return (error);
}

View file

@ -144,8 +144,6 @@ DUMMY(userfaultfd);
DUMMY(membarrier);
/* Linux 4.4: */
DUMMY(mlock2);
/* Linux 4.5: */
DUMMY(copy_file_range);
/* Linux 4.6: */
DUMMY(preadv2);
DUMMY(pwritev2);