From: Daan De Meyer Date: Tue, 22 Oct 2024 17:35:51 +0000 (+0200) Subject: Make qemu drives and scratch device NOCOW as well X-Git-Tag: v25~212^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11bc8e28a47fbb4260adb4134e770a33ce3f2ed4;p=thirdparty%2Fmkosi.git Make qemu drives and scratch device NOCOW as well These will face lots of random writes as well so let's make these NOCOW as well. --- diff --git a/mkosi/qemu.py b/mkosi/qemu.py index 00e283531..f089d8d21 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -468,6 +468,15 @@ def vsock_notify_handler() -> Iterator[tuple[str, dict[str, str]]]: logging.debug(f"- {k}={v}") +def make_nocow(config: Config, path: Path) -> None: + run( + ["chattr", "+C", workdir(path)], + check=False, + stderr=subprocess.DEVNULL if not ARG_DEBUG.get() else None, + sandbox=config.sandbox(binary="chattr", options=["--bind", path, workdir(path)]), + ) + + @contextlib.contextmanager def start_journal_remote(config: Config, sockfd: int) -> Iterator[None]: assert config.forward_journal @@ -486,7 +495,7 @@ def start_journal_remote(config: Config, sockfd: int) -> Iterator[None]: # at the same time. d.mkdir(exist_ok=True, parents=True) # Make sure COW is disabled so systemd-journal-remote doesn't complain on btrfs filesystems. - run(["chattr", "+C", d], check=False, stderr=subprocess.DEVNULL if not ARG_DEBUG.get() else None) + make_nocow(config, d) INVOKING_USER.chown(d) with tempfile.NamedTemporaryFile(mode="w", prefix="mkosi-journal-remote-config-") as f: @@ -585,10 +594,7 @@ def copy_ephemeral(config: Config, src: Path) -> Iterator[Path]: if "No_COW" in attr: tmp.touch() - run( - ["chattr", "+C", workdir(tmp)], - sandbox=config.sandbox(binary="chattr", options=["--bind", tmp, workdir(tmp)]), - ) + make_nocow(config, tmp) copy_tree( src, @@ -740,10 +746,12 @@ def apply_runtime_size(config: Config, image: Path) -> None: @contextlib.contextmanager -def finalize_drive(drive: QemuDrive) -> Iterator[Path]: +def finalize_drive(config: Config, drive: QemuDrive) -> Iterator[Path]: with tempfile.NamedTemporaryFile( - dir=drive.directory or "/var/tmp", prefix=f"mkosi-drive-{drive.id}" + dir=drive.directory or "/var/tmp", + prefix=f"mkosi-drive-{drive.id}", ) as file: + make_nocow(config, Path(file.name)) file.truncate(drive.size) yield Path(file.name) @@ -1337,7 +1345,7 @@ def run_qemu(args: Args, config: Config) -> None: ] for _, drives in groupby(config.qemu_drives, key=lambda d: d.file_id): - file = stack.enter_context(finalize_drive(drives[0])) + file = stack.enter_context(finalize_drive(config, drives[0])) for drive in drives: arg = f"if=none,id={drive.id},file={file},format=raw,file.locking=off"