[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251007121719.45090b21.ddiss@suse.de>
Date: Tue, 7 Oct 2025 12:17:19 +1100
From: David Disseldorp <ddiss@...e.de>
To: Dmitry Safonov via B4 Relay <devnull+dima.arista.com@...nel.org>
Cc: dima@...sta.com, Nathan Chancellor <nathan@...nel.org>, Nicolas Schier
<nicolas.schier@...ux.dev>, linux-kbuild@...r.kernel.org,
linux-kernel@...r.kernel.org, Nicolas Schier <nsc@...nel.org>
Subject: Re: [PATCH RFC] gen_init_cpio: Do fsync() only on regular files
Thanks for reporting this regression, Dmitry...
On Tue, 07 Oct 2025 00:55:03 +0100, Dmitry Safonov via B4 Relay wrote:
> From: Dmitry Safonov <dima@...sta.com>
>
> Here at Arista gen_init_cpio is used in testing in order to create
> an initramfs for specific tests. Most notably, there is a test that does
> essentially a fork-bomb in kdump/panic kernel, replacing build-time
> generated init script: instead of doing makedumpfile, it does call
> shell tests.
>
> In comparison to usr/Makefile, which creates an intermediate .cpio file,
> the Makefile that generates initrd for tests is a one-liner:
> > file lib/kdump ${src_dir}/oom-crashkernel 0644 0 0 | usr/gen_init_cpio /dev/stdin | xz -z -c -e -Ccrc32 > ${target_dir}/oom-crashkernel.initrd
>
> As fsync() on a pipe fd returns -EINVAL, that stopped working.
> Check that outfd is a regular file descriptor before calling fsync().
>
> Sending this as RFC as these are local tests, rather than upstream ones,
> unfortunately. Yet, the fix is trivial and increases correctness of
> gen_init_cpio (and maybe saves some time for another person debugging
> it). A workaround to use temporary cpio file is also trivial, so not
> insisting on merging.
The code change looks fine, but the commit message is a bit verbose IMO.
Please drop the first and last paragraphs. The reproducer could also be
simplified to e.g.
echo | usr/gen_init_cpio /dev/stdin > /dev/null
With that:
Reviewed-by: David Disseldorp <ddiss@...e.de>
> Fixes: ae18b94099b0 ("gen_init_cpio: support -o <output_file> parameter")
> Cc: David Disseldorp <ddiss@...e.de>
> Cc: Nicolas Schier <nsc@...nel.org>
> Signed-off-by: Dmitry Safonov <dima@...sta.com>
> ---
> usr/gen_init_cpio.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
> index 75e9561ba31392e12536e76a918245a8ea07f9b8..845e2d92f0e56b02ba5fc12ecd243ce99c53f552 100644
> --- a/usr/gen_init_cpio.c
> +++ b/usr/gen_init_cpio.c
> @@ -6,6 +6,7 @@
> #include <stdbool.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> +#include <sys/socket.h>
> #include <string.h>
> #include <unistd.h>
> #include <time.h>
> @@ -112,6 +113,9 @@ static int cpio_trailer(void)
> push_pad(padlen(offset, 512)) < 0)
> return -1;
>
> + if (!isfdtype(outfd, S_IFREG))
> + return 0;
> +
> return fsync(outfd);
> }
Another option would be to catch the EINVAL error, e.g.
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -112,7 +112,10 @@ static int cpio_trailer(void)
push_pad(padlen(offset, 512)) < 0)
return -1;
- return fsync(outfd);
+ if (fsync(outfd) < 0 && errno != EINVAL)
+ return -1;
+
+ return 0;
}
It may be a little portable than isfdtype(), but I don't feel strongly
either way.
Thanks, David
Powered by blists - more mailing lists