]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
If the image is nocow, make the ephemeral copy nocow as well
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 23 Jul 2024 20:36:55 +0000 (22:36 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 24 Jul 2024 08:32:08 +0000 (10:32 +0200)
On btrfs, VM images are generally recommended to be made nocow as
cow (copy-on-write) and random writes don't play well together. Let's
take this into account in copy_ephemeral() and make the ephemeral
copy nocow as well if the source is nocow.

mkosi/qemu.py

index e62db3f4115cfc9cfdaa87d60f800415a2fdbe9e..b6d3bb036876b6b014fcdf9038ecb61cb65048d2 100644 (file)
@@ -533,6 +533,19 @@ def copy_ephemeral(config: Config, src: Path) -> Iterator[Path]:
         def copy() -> None:
             if config.output_format == OutputFormat.directory:
                 become_root()
+            elif config.output_format in (OutputFormat.disk, OutputFormat.esp):
+                attr = run(
+                    ["lsattr", "-l", src],
+                    sandbox=config.sandbox(binary="lsattr", mounts=[Mount(src, src, ro=True)]),
+                    stdout=subprocess.PIPE,
+                ).stdout
+
+                if "No_COW" in attr:
+                    tmp.touch()
+                    run(
+                        ["chattr", "+C", tmp],
+                        sandbox=config.sandbox(binary="chattr", mounts=[Mount(tmp, tmp)]),
+                    )
 
             copy_tree(
                 src, tmp,