* [PATCH] hw/i386: Use qemu_open_old for kernel/initrd
@ 2026-04-19 19:35 Sertonix
2026-04-20 20:12 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 2+ messages in thread
From: Sertonix @ 2026-04-19 19:35 UTC (permalink / raw)
To: qemu-devel
Allows using "-kernel /dev/fdset/0" and "-initrd /dev/fdset/1" (if the
file descriptors are opened read-only).
For the sake of consistency it would be best to do the same change in
the other hw/* subdirectories as well but I lack the means to test all
of them.
---
hw/i386/x86-common.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c
index fde05fa7d7..5d8be30f4d 100644
--- a/hw/i386/x86-common.c
+++ b/hw/i386/x86-common.c
@@ -651,6 +651,7 @@ void x86_load_linux(X86MachineState *x86ms,
uint8_t header[8192], *setup, *kernel;
hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
FILE *f;
+ int fd;
const char *vmode;
MachineState *machine = MACHINE(x86ms);
struct setup_data *setup_data;
@@ -664,8 +665,8 @@ void x86_load_linux(X86MachineState *x86ms,
cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
/* load the kernel header */
- f = fopen(kernel_filename, "rb");
- if (!f) {
+ fd = qemu_open_old(kernel_filename, O_RDONLY);
+ if (fd < 0 || !(f = fdopen(fd, "rb"))) {
fprintf(stderr, "qemu: could not open kernel file '%s': %s\n",
kernel_filename, strerror(errno));
exit(1);
@@ -719,12 +720,14 @@ void x86_load_linux(X86MachineState *x86ms,
/* load initrd */
if (initrd_filename) {
+ int mapped_file_fd;
GMappedFile *mapped_file;
gsize initrd_size;
gchar *initrd_data;
GError *gerr = NULL;
- mapped_file = g_mapped_file_new(initrd_filename, false, &gerr);
+ mapped_file_fd = qemu_open_old(initrd_filename, O_RDONLY);
+ mapped_file = g_mapped_file_new_from_fd(mapped_file_fd, false, &gerr);
if (!mapped_file) {
fprintf(stderr, "qemu: error reading initrd %s: %s\n",
initrd_filename, gerr->message);
@@ -860,6 +863,7 @@ void x86_load_linux(X86MachineState *x86ms,
/* load initrd */
if (initrd_filename) {
+ int mapped_file_fd;
GMappedFile *mapped_file;
gsize initrd_size;
gchar *initrd_data;
@@ -870,7 +874,8 @@ void x86_load_linux(X86MachineState *x86ms,
exit(1);
}
- mapped_file = g_mapped_file_new(initrd_filename, false, &gerr);
+ mapped_file_fd = qemu_open_old(initrd_filename, O_RDONLY);
+ mapped_file = g_mapped_file_new_from_fd(mapped_file_fd, false, &gerr);
if (!mapped_file) {
fprintf(stderr, "qemu: error reading initrd %s: %s\n",
initrd_filename, gerr->message);
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] hw/i386: Use qemu_open_old for kernel/initrd
2026-04-19 19:35 [PATCH] hw/i386: Use qemu_open_old for kernel/initrd Sertonix
@ 2026-04-20 20:12 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-04-20 20:12 UTC (permalink / raw)
To: Sertonix, qemu-devel
Hi,
On 19/4/26 21:35, Sertonix wrote:
>
> Allows using "-kernel /dev/fdset/0" and "-initrd /dev/fdset/1" (if the
> file descriptors are opened read-only).
>
> For the sake of consistency it would be best to do the same change in
> the other hw/* subdirectories as well but I lack the means to test all
> of them.
Thanks for this patch. Note however there is a comment before
the qemu_open_old() declaration in "qemu/osdep.h":
/*
* Don't introduce new usage of this function, prefer the following
* qemu_open/qemu_create that take an "Error **errp"
*/
Do you mind using the latter in your patch?
Thanks,
Phil.
> ---
> hw/i386/x86-common.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-20 20:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-19 19:35 [PATCH] hw/i386: Use qemu_open_old for kernel/initrd Sertonix
2026-04-20 20:12 ` Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.