Commit a6a41d39 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

init: refactor mount_root

Provide stubs for all the lower level mount helpers, and just switch
on ROOT_DEV in the main function.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230531125535.676098-8-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent e3102722
...@@ -453,15 +453,14 @@ void __init mount_root_generic(char *name, int flags) ...@@ -453,15 +453,14 @@ void __init mount_root_generic(char *name, int flags)
#define NFSROOT_TIMEOUT_MAX 30 #define NFSROOT_TIMEOUT_MAX 30
#define NFSROOT_RETRY_MAX 5 #define NFSROOT_RETRY_MAX 5
static int __init mount_nfs_root(void) static void __init mount_nfs_root(void)
{ {
char *root_dev, *root_data; char *root_dev, *root_data;
unsigned int timeout; unsigned int timeout;
int try, err; int try;
err = nfs_root_data(&root_dev, &root_data); if (nfs_root_data(&root_dev, &root_data))
if (err != 0) goto fail;
return 0;
/* /*
* The server or network may not be ready, so try several * The server or network may not be ready, so try several
...@@ -470,10 +469,8 @@ static int __init mount_nfs_root(void) ...@@ -470,10 +469,8 @@ static int __init mount_nfs_root(void)
*/ */
timeout = NFSROOT_TIMEOUT_MIN; timeout = NFSROOT_TIMEOUT_MIN;
for (try = 1; ; try++) { for (try = 1; ; try++) {
err = do_mount_root(root_dev, "nfs", if (!do_mount_root(root_dev, "nfs", root_mountflags, root_data))
root_mountflags, root_data); return;
if (err == 0)
return 1;
if (try > NFSROOT_RETRY_MAX) if (try > NFSROOT_RETRY_MAX)
break; break;
...@@ -483,9 +480,14 @@ static int __init mount_nfs_root(void) ...@@ -483,9 +480,14 @@ static int __init mount_nfs_root(void)
if (timeout > NFSROOT_TIMEOUT_MAX) if (timeout > NFSROOT_TIMEOUT_MAX)
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 #ifdef CONFIG_CIFS_ROOT
...@@ -495,22 +497,20 @@ extern int cifs_root_data(char **dev, char **opts); ...@@ -495,22 +497,20 @@ extern int cifs_root_data(char **dev, char **opts);
#define CIFSROOT_TIMEOUT_MAX 30 #define CIFSROOT_TIMEOUT_MAX 30
#define CIFSROOT_RETRY_MAX 5 #define CIFSROOT_RETRY_MAX 5
static int __init mount_cifs_root(void) static void __init mount_cifs_root(void)
{ {
char *root_dev, *root_data; char *root_dev, *root_data;
unsigned int timeout; unsigned int timeout;
int try, err; int try;
err = cifs_root_data(&root_dev, &root_data); if (cifs_root_data(&root_dev, &root_data))
if (err != 0) goto fail;
return 0;
timeout = CIFSROOT_TIMEOUT_MIN; timeout = CIFSROOT_TIMEOUT_MIN;
for (try = 1; ; try++) { for (try = 1; ; try++) {
err = do_mount_root(root_dev, "cifs", root_mountflags, if (!do_mount_root(root_dev, "cifs", root_mountflags,
root_data); root_data))
if (err == 0) return;
return 1;
if (try > CIFSROOT_RETRY_MAX) if (try > CIFSROOT_RETRY_MAX)
break; break;
...@@ -519,9 +519,14 @@ static int __init mount_cifs_root(void) ...@@ -519,9 +519,14 @@ static int __init mount_cifs_root(void)
if (timeout > CIFSROOT_TIMEOUT_MAX) if (timeout > CIFSROOT_TIMEOUT_MAX)
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) static bool __init fs_is_nodev(char *fstype)
{ {
...@@ -563,35 +568,38 @@ static int __init mount_nodev_root(void) ...@@ -563,35 +568,38 @@ static int __init mount_nodev_root(void)
return err; 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 #ifdef CONFIG_BLOCK
{ static void __init mount_block_root(void)
int err = create_dev("/dev/root", ROOT_DEV); {
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) void __init mount_root(void)
pr_emerg("Failed to create /dev/root: %d\n", err); {
mount_root_generic("/dev/root", root_mountflags); 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
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment