mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 04:46:41 -05:00
fix: report a short write when ENOSPC recovery fails after a prefix
- 78a67fd0 kept the bytes written before ENOSPC when the move worked.
When it didn't (moveonenospc off, no branch to move to, the move or
the retry failing, or a non-ENOSPC error), write still returned the
error and dropped the count, though those bytes were on disk. An
O_APPEND writer that retried the whole buffer duplicated them.
- Return the bytes written as a short write whenever some reached the
file, as a local filesystem does. A write that wrote nothing still
returns the error.
- TEST_movefile_enospc checks it with moveonenospc=false and a write
bigger than the space left. Document it in moveonenospc.md.
This commit is contained in:
parent
33b0799d6b
commit
bc7b7ffeae
3 changed files with 54 additions and 10 deletions
|
|
@ -45,6 +45,17 @@ _out_of_space(const ssize_t err_)
|
|||
(err_ == -EDQUOT));
|
||||
}
|
||||
|
||||
// Bytes already written stay written. Report them as a short write,
|
||||
// as a local filesystem does, rather than the error: a caller that
|
||||
// retries the whole buffer would write them twice.
|
||||
static
|
||||
ssize_t
|
||||
_written_or_err(const ssize_t written_,
|
||||
const ssize_t err_)
|
||||
{
|
||||
return ((written_ > 0) ? written_ : err_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_move_and_pwrite(const char *buf_,
|
||||
|
|
@ -88,7 +99,7 @@ _move_and_pwriten(char const *buf_,
|
|||
ssize_t rv;
|
||||
|
||||
if(cfg.moveonenospc.enabled == false)
|
||||
return err_;
|
||||
return ::_written_or_err(written_,err_);
|
||||
|
||||
rv = fs::movefile_and_open_as_root(cfg.moveonenospc.policy,
|
||||
cfg.branches,
|
||||
|
|
@ -96,12 +107,12 @@ _move_and_pwriten(char const *buf_,
|
|||
fi_->fusepath,
|
||||
fi_->fd);
|
||||
if(rv < 0)
|
||||
return err_;
|
||||
return ::_written_or_err(written_,err_);
|
||||
|
||||
err = fs::dup2(rv,fi_->fd);
|
||||
fs::close(rv);
|
||||
if(err < 0)
|
||||
return err_;
|
||||
return ::_written_or_err(written_,err_);
|
||||
|
||||
rv = fs::pwriten(fi_->fd,
|
||||
buf_ + written_,
|
||||
|
|
@ -109,7 +120,7 @@ _move_and_pwriten(char const *buf_,
|
|||
offset_ + written_,
|
||||
&err);
|
||||
if(err < 0)
|
||||
return err;
|
||||
return ::_written_or_err(written_ + rv,err);
|
||||
|
||||
return (written_ + rv);
|
||||
}
|
||||
|
|
@ -178,8 +189,8 @@ _write(const fuse_req_ctx_t *ctx_,
|
|||
|
||||
if(err == 0)
|
||||
return written;
|
||||
if(err && not ::_out_of_space(err))
|
||||
return err;
|
||||
if(not ::_out_of_space(err))
|
||||
return ::_written_or_err(written,err);
|
||||
|
||||
std::unique_lock<std::shared_mutex> ulk(fi->mutex);
|
||||
// Re-check the remaining suffix under exclusive lock as another move
|
||||
|
|
@ -192,8 +203,8 @@ _write(const fuse_req_ctx_t *ctx_,
|
|||
&err);
|
||||
if(err == 0)
|
||||
return written;
|
||||
if(err && not ::_out_of_space(err))
|
||||
return err;
|
||||
if(not ::_out_of_space(err))
|
||||
return ::_written_or_err(written,err);
|
||||
|
||||
return ::_move_and_pwriten(buf_,count_,offset_,fi,err,written);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue