mirror of https://github.com/trapexit/mergerfs.git
Browse Source
Merge pull request #677 from trapexit/moveonenospc
Merge pull request #677 from trapexit/moveonenospc
fix short writes on >2GB files when cloning filepull/685/head 2.28.3
trapexit
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 286 additions and 212 deletions
-
38src/fs_clonefile.cpp
-
20src/fs_copy_file_range.hpp
-
82src/fs_copy_file_range_linux.icpp
-
67src/fs_copydata_copy_file_range.cpp
-
24src/fs_copydata_copy_file_range.hpp
-
113src/fs_copydata_readwrite.cpp
-
4src/fs_copydata_readwrite.hpp
-
110src/fs_copyfile.cpp
@ -0,0 +1,67 @@ |
|||
/*
|
|||
Copyright (c) 2019, 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. |
|||
*/ |
|||
|
|||
#include "errno.hpp"
|
|||
#include "fs_base_stat.hpp"
|
|||
#include "fs_copy_file_range.hpp"
|
|||
|
|||
namespace l |
|||
{ |
|||
int64_t |
|||
copydata_copy_file_range(const int src_fd_, |
|||
const int dst_fd_, |
|||
uint64_t size_) |
|||
{ |
|||
int64_t rv; |
|||
uint64_t len; |
|||
int64_t src_off; |
|||
int64_t dst_off; |
|||
|
|||
src_off = 0; |
|||
dst_off = 0; |
|||
len = size_; |
|||
do |
|||
{ |
|||
rv = fs::copy_file_range(src_fd_,&src_off,dst_fd_,&dst_off,len,0); |
|||
if(rv == -1) |
|||
return -1; |
|||
|
|||
len -= rv; |
|||
} |
|||
while((len > 0) && (rv > 0)); |
|||
|
|||
return size_; |
|||
} |
|||
} |
|||
|
|||
namespace fs |
|||
{ |
|||
int64_t |
|||
copydata_copy_file_range(const int src_fd_, |
|||
const int dst_fd_) |
|||
{ |
|||
int rv; |
|||
struct stat st; |
|||
|
|||
rv = fs::fstat(src_fd_,&st); |
|||
if(rv == -1) |
|||
return -1; |
|||
|
|||
return l::copydata_copy_file_range(src_fd_, |
|||
dst_fd_, |
|||
st.st_size); |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
/*
|
|||
Copyright (c) 2016, 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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
namespace fs |
|||
{ |
|||
int |
|||
copydata_copy_file_range(const int src_fd, |
|||
const int dst_fd); |
|||
} |
@ -0,0 +1,113 @@ |
|||
/*
|
|||
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. |
|||
*/ |
|||
|
|||
#include "errno.hpp"
|
|||
#include "fs_base_stat.hpp"
|
|||
#include "fs_base_lseek.hpp"
|
|||
#include "fs_base_read.hpp"
|
|||
#include "fs_base_write.hpp"
|
|||
|
|||
#include <vector>
|
|||
|
|||
using std::vector; |
|||
|
|||
namespace l |
|||
{ |
|||
static |
|||
int |
|||
writen(const int fd_, |
|||
const char *buf_, |
|||
const size_t count_) |
|||
{ |
|||
size_t nleft; |
|||
ssize_t nwritten; |
|||
|
|||
nleft = count_; |
|||
do |
|||
{ |
|||
nwritten = fs::write(fd_,buf_,nleft); |
|||
if((nwritten == -1) && (errno == EINTR)) |
|||
continue; |
|||
if(nwritten == -1) |
|||
return -1; |
|||
|
|||
nleft -= nwritten; |
|||
buf_ += nwritten; |
|||
} |
|||
while(nleft > 0); |
|||
|
|||
return count_; |
|||
} |
|||
|
|||
static |
|||
int |
|||
copydata_readwrite(const int src_fd_, |
|||
const int dst_fd_, |
|||
const size_t count_, |
|||
const size_t blocksize_) |
|||
{ |
|||
ssize_t nr; |
|||
ssize_t nw; |
|||
ssize_t bufsize; |
|||
size_t totalwritten; |
|||
vector<char> buf; |
|||
|
|||
bufsize = (blocksize_ * 16); |
|||
buf.resize(bufsize); |
|||
|
|||
fs::lseek(src_fd_,0,SEEK_SET); |
|||
|
|||
totalwritten = 0; |
|||
while(totalwritten < count_) |
|||
{ |
|||
nr = fs::read(src_fd_,&buf[0],bufsize); |
|||
if(nr == 0) |
|||
return totalwritten; |
|||
if((nr == -1) && (errno == EINTR)) |
|||
continue; |
|||
if(nr == -1) |
|||
return -1; |
|||
|
|||
nw = l::writen(dst_fd_,&buf[0],nr); |
|||
if(nw == -1) |
|||
return -1; |
|||
|
|||
totalwritten += nw; |
|||
} |
|||
|
|||
return totalwritten; |
|||
} |
|||
} |
|||
|
|||
namespace fs |
|||
{ |
|||
int |
|||
copydata_readwrite(const int src_fd_, |
|||
const int dst_fd_) |
|||
{ |
|||
int rv; |
|||
struct stat st; |
|||
|
|||
rv = fs::fstat(src_fd_,&st); |
|||
if(rv == -1) |
|||
return -1; |
|||
|
|||
return l::copydata_readwrite(src_fd_, |
|||
dst_fd_, |
|||
st.st_size, |
|||
st.st_blksize); |
|||
} |
|||
} |
@ -1,110 +0,0 @@ |
|||
/*
|
|||
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. |
|||
*/ |
|||
|
|||
#include "errno.hpp"
|
|||
#include "fs_base_stat.hpp"
|
|||
#include "fs_base_lseek.hpp"
|
|||
#include "fs_base_read.hpp"
|
|||
#include "fs_base_write.hpp"
|
|||
|
|||
#include <vector>
|
|||
|
|||
using std::vector; |
|||
|
|||
static |
|||
int |
|||
writen(const int fd_, |
|||
const char *buf_, |
|||
const size_t count_) |
|||
{ |
|||
size_t nleft; |
|||
ssize_t nwritten; |
|||
|
|||
nleft = count_; |
|||
do |
|||
{ |
|||
nwritten = fs::write(fd_,buf_,nleft); |
|||
if((nwritten == -1) && (errno == EINTR)) |
|||
continue; |
|||
if(nwritten == -1) |
|||
return -1; |
|||
|
|||
nleft -= nwritten; |
|||
buf_ += nwritten; |
|||
} |
|||
while(nleft > 0); |
|||
|
|||
return count_; |
|||
} |
|||
|
|||
static |
|||
int |
|||
copyfile(const int src_fd_, |
|||
const int dst_fd_, |
|||
const size_t count_, |
|||
const size_t blocksize_) |
|||
{ |
|||
ssize_t nr; |
|||
ssize_t nw; |
|||
ssize_t bufsize; |
|||
size_t totalwritten; |
|||
vector<char> buf; |
|||
|
|||
bufsize = (blocksize_ * 16); |
|||
buf.resize(bufsize); |
|||
|
|||
fs::lseek(src_fd_,0,SEEK_SET); |
|||
|
|||
totalwritten = 0; |
|||
while(totalwritten < count_) |
|||
{ |
|||
nr = fs::read(src_fd_,&buf[0],bufsize); |
|||
if(nr == 0) |
|||
return totalwritten; |
|||
if((nr == -1) && (errno == EINTR)) |
|||
continue; |
|||
if(nr == -1) |
|||
return -1; |
|||
|
|||
nw = writen(dst_fd_,&buf[0],nr); |
|||
if(nw == -1) |
|||
return -1; |
|||
|
|||
totalwritten += nw; |
|||
} |
|||
|
|||
return totalwritten; |
|||
} |
|||
|
|||
namespace fs |
|||
{ |
|||
int |
|||
copyfile(const int src_fd_, |
|||
const int dst_fd_) |
|||
{ |
|||
int rv; |
|||
struct stat st; |
|||
|
|||
rv = fs::fstat(src_fd_,&st); |
|||
if(rv == -1) |
|||
return rv; |
|||
|
|||
return ::copyfile(src_fd_, |
|||
dst_fd_, |
|||
st.st_size, |
|||
st.st_blksize); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue