From: Chris Down Date: Thu, 6 Nov 2025 15:11:55 +0000 (+0800) Subject: mkfs-util: Ignore btrfs compression when there is no dir to copy X-Git-Tag: v259-rc1~119^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=adf88771ff0c11fb0e51ef14f129d584fb471420;p=thirdparty%2Fsystemd.git mkfs-util: Ignore btrfs compression when there is no dir to copy mkfs.btrfs requires that the --compress option be used together with --rootdir, as compression only makes sense in that context (because compression is not a persistent setting). Right now, If --compress is specified without --rootdir, mkfs.btrfs fails with: ERROR: --compression must be used with --rootdir This can occur when repart is configured with Compression= but the partition populate logic doesn't use the --rootdir code path (eg. when using loop device mounting to copy files after mkfs). Add a defensive check to skip compression and emit a user-friendly warning when compression is requested but no root directory is provided. The warning message references the repart directive names (Compression= and CopyFiles=) rather than low-level mkfs options to help users understand the requirement. This prevents crashes but doesn't enable compression, that requires ensuring the --rootdir code path is used, which it currently is not and will be addressed in the next patch. Fixes: https://github.com/systemd/systemd/issues/39584 --- diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c index 629d02207c1..455c627ff6b 100644 --- a/src/shared/mkfs-util.c +++ b/src/shared/mkfs-util.c @@ -466,17 +466,22 @@ int make_filesystem( return log_oom(); if (compression) { - _cleanup_free_ char *c = NULL; - - c = strdup(compression); - if (!c) - return log_oom(); + if (!root) + log_warning("Btrfs compression setting ignored because no files are being copied. " + "Compression= can only be applied when CopyFiles= is also specified."); + else { + _cleanup_free_ char *c = NULL; + + c = strdup(compression); + if (!c) + return log_oom(); - if (compression_level && !strextend(&c, ":", compression_level)) - return log_oom(); + if (compression_level && !strextend(&c, ":", compression_level)) + return log_oom(); - if (strv_extend_many(&argv, "--compress", c) < 0) - return log_oom(); + if (strv_extend_many(&argv, "--compress", c) < 0) + return log_oom(); + } } /* mkfs.btrfs unconditionally warns about several settings changing from v5.15 onwards which