copy: drop COPY_REFLINK
Reflinking is a safe optimization whenever the source and destination are regular, seekable files on a filesystem that supports cloning. Requiring each caller to opt in through COPY_REFLINK adds flag plumbing without changing the necessary fallback behavior. Drop COPY_REFLINK, renumber the remaining flags, and have copy_bytes_full() unconditionally try FICLONE or FICLONERANGE before entering its normal copy loop. Isolate the clone attempt and its file-offset bookkeeping in a helper so copy_bytes_full() only has to handle its cloned, unavailable, and error results. A successful clone therefore completes in one operation, while an unsupported or rejected clone falls back to progress-limited copy_file_range(), sendfile(), or buffered copying. Keep the public reflink helpers for operations that specifically require clone semantics. Existing test-copy coverage exercises both bounded and unbounded regular-file copies through copy_bytes_full(). Signed-off-by: Daan De Meyer <daan@amutable.com>
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
28b1e4ea16
commit
5a12005c83
+4
-4
@@ -1877,7 +1877,7 @@ static int setup_timezone(const char *dest) {
|
||||
|
||||
case TIMEZONE_COPY:
|
||||
/* If mounting failed, try to copy */
|
||||
r = copy_file_atomic("/etc/localtime", where, 0644, COPY_REFLINK|COPY_REPLACE);
|
||||
r = copy_file_atomic("/etc/localtime", where, 0644, COPY_REPLACE);
|
||||
if (r < 0) {
|
||||
log_full_errno(ERRNO_IS_NEG_FS_WRITE_REFUSED(r) ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"Failed to copy /etc/localtime to %s, ignoring: %m", where);
|
||||
@@ -2005,9 +2005,9 @@ static int setup_resolv_conf(const char *dest) {
|
||||
}
|
||||
|
||||
if (IN_SET(m, RESOLV_CONF_REPLACE_HOST, RESOLV_CONF_REPLACE_STATIC, RESOLV_CONF_REPLACE_UPLINK, RESOLV_CONF_REPLACE_STUB))
|
||||
r = copy_file_atomic(what, where, 0644, COPY_REFLINK|COPY_REPLACE);
|
||||
r = copy_file_atomic(what, where, 0644, COPY_REPLACE);
|
||||
else
|
||||
r = copy_file(what, where, O_TRUNC|O_NOFOLLOW, 0644, COPY_REFLINK);
|
||||
r = copy_file(what, where, O_TRUNC|O_NOFOLLOW, 0644, /* copy_flags= */ 0);
|
||||
if (r < 0) {
|
||||
/* If the file already exists as symlink, let's suppress the warning, under the assumption that
|
||||
* resolved or something similar runs inside and the symlink points there.
|
||||
@@ -6474,7 +6474,7 @@ static int run(int argc, char *argv[]) {
|
||||
{
|
||||
BLOCK_SIGNALS(SIGINT);
|
||||
r = copy_file(arg_image, np, O_EXCL, arg_read_only ? 0400 : 0600,
|
||||
COPY_REFLINK|COPY_CRTIME|COPY_SIGINT|COPY_NOCOW_AFTER);
|
||||
COPY_CRTIME|COPY_SIGINT|COPY_NOCOW_AFTER);
|
||||
}
|
||||
if (r == -EINTR) {
|
||||
log_error_errno(r, "Interrupted while copying image file to %s, removed again.", np);
|
||||
|
||||
Reference in New Issue
Block a user