Re: [PATCH-RFC] init: simplify initrd code (was Re: [PATCH RESEND 00/62] initrd: remove classic initrd support).

David Disseldorp <[email protected]>
Newsgroups gmane.linux.ports.sh.devel,gmane.linux.drivers.devicetree,gmane.linux.kernel.initramfs,gmane.linux.acpi.devel,gmane.linux.ports.alpha,gmane.linux.kernel.api,gmane.linux.kernel.cross-arch,gmane.linux.ports.arm.kernel,gmane.linux.block,gmane.linux.documentation,gmane.linux.kernel.efi,gmane.comp.file-systems.ext4,gmane.linux.file-systems,gmane.linux.ports.hexagon,gmane.linux.kernel,gmane.linux.ports.mips,gmane.linux.ports.parisc,gmane.linux.ports.riscv,gmane.linux.kernel.arc,gmane.linux.uml.devel,gmane.linux.ports.ppc64.devel,gmane.linux.ports.sparc
Message-ID <[email protected]>
Hi Nicolas,

On Thu, 25 Sep 2025 15:10:56 +0200, [email protected] wrote:

> From: Nicolas Schichan <[email protected]>
> 
> - drop prompt_ramdisk and ramdisk_start kernel parameters
> - drop compression support
> - drop image autodetection, the whole /initrd.image content is now
>   copied into /dev/ram0
> - remove rd_load_disk() which doesn't seem to be used anywhere.
> 
> There is now no more limitation on the type of initrd filesystem that
> can be loaded since the code trying to guess the initrd filesystem
> size is gone (the whole /initrd.image file is used).
> 
> A few global variables in do_mounts_rd.c are now put as local
> variables in rd_load_image() since they do not need to be visible
> outside this function.
> ---
> 
> Hello,
> 
> Hopefully my email config is now better and reaches gmail users
> correctly.
> 
> The patch below could probably split in a few patches, but I think
> this simplify the code greatly without removing the functionality we
> depend on (and this allows now to use EROFS initrd images).
> 
> Coupled with keeping the function populate_initrd_image() in
> init/initramfs.c, this will keep what we need from the initrd code.
> 
> This removes support of loading bzip/gz/xz/... compressed images as
> well, not sure if many user depend on this feature anymore.
> 
> No signoff because I'm only seeking comments about those changes right
> now.
> 
>  init/do_mounts.h    |   2 -
>  init/do_mounts_rd.c | 243 +-------------------------------------------
>  2 files changed, 4 insertions(+), 241 deletions(-)

This seems like a reasonable improvement to me. FWIW, one alternative
approach to clean up the FS specific code here was proposed by Al:
https://lore.kernel.org/all/20250321020826.GB2023217@ZenIV/

...
> diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
> index ac021ae6e6fa..5a69ff43f5ee 100644
> --- a/init/do_mounts_rd.c
> +++ b/init/do_mounts_rd.c
> @@ -14,173 +14,9 @@
>  
>  #include <linux/decompress/generic.h>
>  
> -static struct file *in_file, *out_file;
> -static loff_t in_pos, out_pos;
> -
> -static int __init prompt_ramdisk(char *str)
> -{
> -	pr_warn("ignoring the deprecated prompt_ramdisk= option\n");
> -	return 1;
> -}
> -__setup("prompt_ramdisk=", prompt_ramdisk);
> -
> -int __initdata rd_image_start;		/* starting block # of image */
> -
> -static int __init ramdisk_start_setup(char *str)
> -{
> -	rd_image_start = simple_strtol(str,NULL,0);
> -	return 1;
> -}
> -__setup("ramdisk_start=", ramdisk_start_setup);

There are a couple of other places that mention these parameters, which
should also be cleaned up.

...
>  static unsigned long nr_blocks(struct file *file)
>  {
> -	struct inode *inode = file->f_mapping->host;
> -
> -	if (!S_ISBLK(inode->i_mode))
> -		return 0;
> -	return i_size_read(inode) >> 10;
> +	return i_size_read(file->f_mapping->host) >> 10;

This should be >> BLOCK_SIZE_BITS, and dropped as a wrapper function
IMO.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.