]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Revert "tree-wide: Don't explicity disable copy-on-write when copying images"
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 22 Aug 2024 15:23:58 +0000 (17:23 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 4 Sep 2024 16:49:05 +0000 (18:49 +0200)
Let's still try to disable COW after copying. It won't do much, but
it doesn't hurt either.

See https://github.com/systemd/systemd/pull/33825/files#r1727288871.

This reverts commit 42e9288180ce37abd86c58774950636ebce35432.

src/core/exec-invoke.c
src/nspawn/nspawn.c
src/shared/discover-image.c

index af5552379efc13ca90f600345586ba6c12dc462c..57f96f7eab543868a181063ce6594fc70c42f5b8 100644 (file)
@@ -2891,6 +2891,16 @@ static int setup_ephemeral(
                 if (fd < 0)
                         return log_debug_errno(fd, "Failed to copy image %s to %s: %m",
                                                *root_image, new_root);
+
+                /* A root image might be subject to lots of random writes so let's try to disable COW on it
+                 * which tends to not perform well in combination with lots of random writes.
+                 *
+                 * Note: btrfs actually isn't impressed by us setting the flag after making the reflink'ed
+                 * copy, but we at least want to make the intention clear.
+                 */
+                r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+                if (r < 0)
+                        log_debug_errno(r, "Failed to disable copy-on-write for %s, ignoring: %m", new_root);
         } else {
                 assert(*root_directory);
 
index 9cd52e06c08629cc54b14db710e41be49e6ad066..c1820690310d1f1daaaf1851d764c30ef14fd304 100644 (file)
@@ -6072,8 +6072,10 @@ 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);
+                                r = copy_file_full(arg_image, np, O_EXCL, arg_read_only ? 0400 : 0600,
+                                                   FS_NOCOW_FL, FS_NOCOW_FL,
+                                                   COPY_REFLINK|COPY_CRTIME|COPY_SIGINT,
+                                                   NULL, NULL);
                         }
                         if (r == -EINTR) {
                                 log_error_errno(r, "Interrupted while copying image file to %s, removed again.", np);
index 1386452203f11e6528a2f178594fa88810a2d200..dd78a013aaf26c49d3b94ff6c1c21b27477c0dac 100644 (file)
@@ -1205,7 +1205,8 @@ int image_clone(Image *i, const char *new_name, bool read_only) {
         case IMAGE_RAW:
                 new_path = strjoina("/var/lib/machines/", new_name, ".raw");
 
-                r = copy_file_atomic(i->path, new_path, read_only ? 0444 : 0644, COPY_REFLINK|COPY_CRTIME);
+                r = copy_file_atomic_full(i->path, new_path, read_only ? 0444 : 0644, FS_NOCOW_FL, FS_NOCOW_FL,
+                                          COPY_REFLINK|COPY_CRTIME, NULL, NULL);
                 break;
 
         case IMAGE_BLOCK: