Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
init: refactor mount_root
Browse files Browse the repository at this point in the history
Provide stubs for all the lower level mount helpers, and just switch
on ROOT_DEV in the main function.

Signed-off-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jun 5, 2023
1 parent e310272 commit a6a41d3
Showing 1 changed file with 56 additions and 48 deletions.
104 changes: 56 additions & 48 deletions init/do_mounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,14 @@ void __init mount_root_generic(char *name, int flags)
#define NFSROOT_TIMEOUT_MAX 30
#define NFSROOT_RETRY_MAX 5

static int __init mount_nfs_root(void)
static void __init mount_nfs_root(void)
{
char *root_dev, *root_data;
unsigned int timeout;
int try, err;
int try;

err = nfs_root_data(&root_dev, &root_data);
if (err != 0)
return 0;
if (nfs_root_data(&root_dev, &root_data))
goto fail;

/*
* The server or network may not be ready, so try several
Expand All @@ -470,10 +469,8 @@ static int __init mount_nfs_root(void)
*/
timeout = NFSROOT_TIMEOUT_MIN;
for (try = 1; ; try++) {
err = do_mount_root(root_dev, "nfs",
root_mountflags, root_data);
if (err == 0)
return 1;
if (!do_mount_root(root_dev, "nfs", root_mountflags, root_data))
return;
if (try > NFSROOT_RETRY_MAX)
break;

Expand All @@ -483,9 +480,14 @@ static int __init mount_nfs_root(void)
if (timeout > NFSROOT_TIMEOUT_MAX)
timeout = NFSROOT_TIMEOUT_MAX;
}
return 0;
fail:
pr_err("VFS: Unable to mount root fs via NFS.\n");
}
#endif
#else
static inline void mount_nfs_root(void)
{
}
#endif /* CONFIG_ROOT_NFS */

#ifdef CONFIG_CIFS_ROOT

Expand All @@ -495,22 +497,20 @@ extern int cifs_root_data(char **dev, char **opts);
#define CIFSROOT_TIMEOUT_MAX 30
#define CIFSROOT_RETRY_MAX 5

static int __init mount_cifs_root(void)
static void __init mount_cifs_root(void)
{
char *root_dev, *root_data;
unsigned int timeout;
int try, err;
int try;

err = cifs_root_data(&root_dev, &root_data);
if (err != 0)
return 0;
if (cifs_root_data(&root_dev, &root_data))
goto fail;

timeout = CIFSROOT_TIMEOUT_MIN;
for (try = 1; ; try++) {
err = do_mount_root(root_dev, "cifs", root_mountflags,
root_data);
if (err == 0)
return 1;
if (!do_mount_root(root_dev, "cifs", root_mountflags,
root_data))
return;
if (try > CIFSROOT_RETRY_MAX)
break;

Expand All @@ -519,9 +519,14 @@ static int __init mount_cifs_root(void)
if (timeout > CIFSROOT_TIMEOUT_MAX)
timeout = CIFSROOT_TIMEOUT_MAX;
}
return 0;
fail:
pr_err("VFS: Unable to mount root fs via SMB.\n");
}
#endif
#else
static inline void mount_cifs_root(void)
{
}
#endif /* CONFIG_CIFS_ROOT */

static bool __init fs_is_nodev(char *fstype)
{
Expand Down Expand Up @@ -563,35 +568,38 @@ static int __init mount_nodev_root(void)
return err;
}

void __init mount_root(void)
{
#ifdef CONFIG_ROOT_NFS
if (ROOT_DEV == Root_NFS) {
if (!mount_nfs_root())
printk(KERN_ERR "VFS: Unable to mount root fs via NFS.\n");
return;
}
#endif
#ifdef CONFIG_CIFS_ROOT
if (ROOT_DEV == Root_CIFS) {
if (!mount_cifs_root())
printk(KERN_ERR "VFS: Unable to mount root fs via SMB.\n");
return;
}
#endif
if (ROOT_DEV == 0 && root_device_name && root_fs_names) {
if (mount_nodev_root() == 0)
return;
}
#ifdef CONFIG_BLOCK
{
int err = create_dev("/dev/root", ROOT_DEV);
static void __init mount_block_root(void)
{
int err = create_dev("/dev/root", ROOT_DEV);

if (err < 0)
pr_emerg("Failed to create /dev/root: %d\n", err);
mount_root_generic("/dev/root", root_mountflags);
}
#else
static inline void mount_block_root(void)
{
}
#endif /* CONFIG_BLOCK */

if (err < 0)
pr_emerg("Failed to create /dev/root: %d\n", err);
mount_root_generic("/dev/root", root_mountflags);
void __init mount_root(void)
{
switch (ROOT_DEV) {
case Root_NFS:
mount_nfs_root();
break;
case Root_CIFS:
mount_cifs_root();
break;
case 0:
if (root_device_name && root_fs_names && mount_nodev_root() == 0)
break;
fallthrough;
default:
mount_block_root();
break;
}
#endif
}

/*
Expand Down

0 comments on commit a6a41d3

Please sign in to comment.