mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-03 21:30:11 -05:00
add FICLONE and copy_file_range to clonefile
If available FICLONE and copy_file_range will be tried in addition to sendfile when copying data between two files. The fallback is a tradition read/write loop. On systems that support these it should improve performance.
This commit is contained in:
parent
bb2e6eb605
commit
85026d5780
12 changed files with 472 additions and 97 deletions
87
src/fs_copy_file_range_linux.icpp
Normal file
87
src/fs_copy_file_range_linux.icpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "errno.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static
|
||||
loff_t
|
||||
copy_file_range_(int fd_in_,
|
||||
loff_t *off_in_,
|
||||
int fd_out_,
|
||||
loff_t *off_out_,
|
||||
size_t len_,
|
||||
unsigned int flags_)
|
||||
{
|
||||
#ifdef SYS_copy_file_range
|
||||
return ::syscall(SYS_copy_file_range,
|
||||
fd_in_,
|
||||
off_in_,
|
||||
fd_out_,
|
||||
off_out_,
|
||||
len_,
|
||||
flags_);
|
||||
#else
|
||||
return (errno=EOPNOTSUPP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
ssize_t
|
||||
copy_file_range(const int fd_in_,
|
||||
loff_t *off_in_,
|
||||
const int fd_out_,
|
||||
loff_t *off_out_,
|
||||
const size_t len_,
|
||||
const unsigned int flags_)
|
||||
{
|
||||
return ::copy_file_range_(fd_in_,
|
||||
off_in_,
|
||||
fd_out_,
|
||||
off_out_,
|
||||
len_,
|
||||
flags_);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
copy_file_range(const int fd_in_,
|
||||
const int fd_out_,
|
||||
const size_t len_,
|
||||
const unsigned int flags_)
|
||||
{
|
||||
loff_t off_in;
|
||||
loff_t off_out;
|
||||
|
||||
off_in = 0;
|
||||
off_out = 0;
|
||||
|
||||
return fs::copy_file_range(fd_in_,
|
||||
&off_in,
|
||||
fd_out_,
|
||||
&off_out,
|
||||
len_,
|
||||
flags_);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue