mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 04:46:41 -05:00
fix: leave the source branch out before moveonenospc picks a branch
- The source branch was dropped from the create policy's result. ff, mfs, lfs, lus and pfrd return a single branch, so when that branch was the source nothing was left and the write kept ENOSPC even with room elsewhere. That happens when the source has free space by statvfs but still returns ENOSPC or EDQUOT: a quota, exhausted inodes, full btrfs metadata, or a cached statfs. - Build the candidate list without the source (matched by device and inode, as before) and run the policy on that, so it picks another branch. With no candidate left the move is still refused. - test_fs_movefile_and_open_same_branch now checks that ff relocates past a source listed first, by its own path or an alias, and that a list made only of the source is refused. Refuse relocation if a duplicate on another branch could become visible when the source is removed. Keep non-replacing publication to protect against a late arrival at the destination. The mounted test checks the original and duplicate contents, then reopens the file through the pool.
This commit is contained in:
parent
db9e991ebd
commit
cd0679b01f
6 changed files with 189 additions and 50 deletions
|
|
@ -33,11 +33,20 @@
|
|||
#include "fs_rename.hpp"
|
||||
#include "fs_unlink.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
#include "to_neg_errno.hpp"
|
||||
|
||||
#include "scope_guard/scope_guard.hpp"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/fs.h>
|
||||
#endif
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
|
||||
static
|
||||
|
|
@ -57,6 +66,36 @@ _ignorable_error(const s64 err_)
|
|||
return false;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_publish_noreplace(const char *tmppath_,
|
||||
const char *dstpath_)
|
||||
{
|
||||
int rv;
|
||||
|
||||
#if defined(SYS_renameat2) && defined(RENAME_NOREPLACE)
|
||||
rv = ::to_neg_errno(::syscall(SYS_renameat2,AT_FDCWD,tmppath_,
|
||||
AT_FDCWD,dstpath_,RENAME_NOREPLACE));
|
||||
#elif defined(__APPLE__) && defined(RENAME_EXCL)
|
||||
rv = ::to_neg_errno(::renamex_np(tmppath_,dstpath_,RENAME_EXCL));
|
||||
#else
|
||||
rv = -ENOSYS;
|
||||
#endif
|
||||
if((rv != -ENOSYS) && (rv != -EINVAL) &&
|
||||
(rv != -ENOTSUP) && (rv != -EOPNOTSUPP))
|
||||
return rv;
|
||||
|
||||
// Some filesystems reject the rename flag. The staging file is a
|
||||
// regular file in the same directory, so link can publish it atomically
|
||||
// without replacement. Never fall back to a replacing rename.
|
||||
rv = ::to_neg_errno(::link(tmppath_,dstpath_));
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
// The destination is now published. A cleanup error cannot undo that.
|
||||
fs::unlink(tmppath_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s64
|
||||
fs::copyfile(const int src_fd_,
|
||||
const struct stat &src_st_,
|
||||
|
|
@ -155,7 +194,10 @@ fs::copyfile(const int src_fd_,
|
|||
continue;
|
||||
}
|
||||
|
||||
rv = fs::rename(dst_tmppath,dst_filepath_);
|
||||
if(flags_.no_replace)
|
||||
rv = ::_publish_noreplace(dst_tmppath.c_str(),dst_filepath_.c_str());
|
||||
else
|
||||
rv = fs::rename(dst_tmppath.c_str(),dst_filepath_.c_str());
|
||||
if((rv < 0) && (flags_.cleanup_failure))
|
||||
fs::unlink(dst_tmppath);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue