* [PATCH 1/1] initrd: use O_SYNC flag while opening /dev/ram for write
@ 2024-07-08 20:09 George Stark
2024-07-09 6:03 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: George Stark @ 2024-07-08 20:09 UTC (permalink / raw)
To: linux-kernel; +Cc: kernel, George Stark
initrd image is written to the /dev/ram block device using filp_open(),
kernel_write(). After fput() /dev/ram is mounted and may fail due to not
all data is actually written to the device yet. The mount error remains
hidden due to MS_SILENT flag usage and mount_root_generic has retries.
So use O_SYNC flag to have all data written to /dev/ram before mounting.
Signed-off-by: George Stark <gnstark@salutedevices.com>
---
init/do_mounts_rd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index ac021ae6e6fa..c9a4721c8362 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -195,7 +195,7 @@ int __init rd_load_image(char *from)
char rotator[4] = { '|' , '/' , '-' , '\\' };
#endif
- out_file = filp_open("/dev/ram", O_RDWR, 0);
+ out_file = filp_open("/dev/ram", O_RDWR | O_SYNC, 0);
if (IS_ERR(out_file))
goto out;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] initrd: use O_SYNC flag while opening /dev/ram for write
2024-07-08 20:09 [PATCH 1/1] initrd: use O_SYNC flag while opening /dev/ram for write George Stark
@ 2024-07-09 6:03 ` Christoph Hellwig
2024-07-09 16:18 ` George Stark
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2024-07-09 6:03 UTC (permalink / raw)
To: George Stark; +Cc: linux-kernel, kernel
On Mon, Jul 08, 2024 at 11:09:23PM +0300, George Stark wrote:
> initrd image is written to the /dev/ram block device using filp_open(),
> kernel_write()
First question: why are you using the legacy initrd and not initramfs?
> . After fput() /dev/ram is mounted and may fail due to not
> all data is actually written to the device yet. The mount error remains
> hidden due to MS_SILENT flag usage and mount_root_generic has retries.
> So use O_SYNC flag to have all data written to /dev/ram before mounting.
O_SYNC is highly inefficient. If you have a valid reason to care about
a corner case in the hopefully soon to be remvoved legacy initrd code,
the right way to do this is a single fdatasync after the writes have
finished.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] initrd: use O_SYNC flag while opening /dev/ram for write
2024-07-09 6:03 ` Christoph Hellwig
@ 2024-07-09 16:18 ` George Stark
0 siblings, 0 replies; 3+ messages in thread
From: George Stark @ 2024-07-09 16:18 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-kernel, kernel
Hello Christoph
Thanks for the review
On 7/9/24 09:03, Christoph Hellwig wrote:
> On Mon, Jul 08, 2024 at 11:09:23PM +0300, George Stark wrote:
>> initrd image is written to the /dev/ram block device using filp_open(),
>> kernel_write()
>
> First question: why are you using the legacy initrd and not initramfs?
I was playing around with initrd to have ability to mount initrd fs from
disk after switching to main root and use files from it. We can't mount
initramfs image. In embedded system mounting vs extracting makes a
difference due to resource limitations. In the end we dropped that idea
partly because of initrd is marked as deprecated.
But since it has been deprecated since 2020 and it's still there I
thought may be it was used by someone so this patch was worth publishing.
If initrd really counts its last days then this patch can be thrown away.
>
>> . After fput() /dev/ram is mounted and may fail due to not
>> all data is actually written to the device yet. The mount error remains
>> hidden due to MS_SILENT flag usage and mount_root_generic has retries.
>> So use O_SYNC flag to have all data written to /dev/ram before mounting.
>
> O_SYNC is highly inefficient. If you have a valid reason to care about
> a corner case in the hopefully soon to be remvoved legacy initrd code,
> the right way to do this is a single fdatasync after the writes have
> finished.
Ok.
--
Best regards
George
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-09 16:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-08 20:09 [PATCH 1/1] initrd: use O_SYNC flag while opening /dev/ram for write George Stark
2024-07-09 6:03 ` Christoph Hellwig
2024-07-09 16:18 ` George Stark
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox