Commit e2e694b9 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'work.init' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull root filesystem type handling updates from Al Viro:
 "Teach init/do_mounts.c to handle non-block filesystems, hopefully
  preventing even more special-cased kludges (such as root=/dev/nfs,
  etc)"

* 'work.init' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  fs: simplify get_filesystem_list / get_all_fs_names
  init: allow mounting arbitrary non-blockdevice filesystems as root
  init: split get_fs_names
parents 7b7699c0 6e7c1770
...@@ -209,21 +209,28 @@ SYSCALL_DEFINE3(sysfs, int, option, unsigned long, arg1, unsigned long, arg2) ...@@ -209,21 +209,28 @@ SYSCALL_DEFINE3(sysfs, int, option, unsigned long, arg1, unsigned long, arg2)
} }
#endif #endif
int __init get_filesystem_list(char *buf) int __init list_bdev_fs_names(char *buf, size_t size)
{ {
int len = 0; struct file_system_type *p;
struct file_system_type * tmp; size_t len;
int count = 0;
read_lock(&file_systems_lock); read_lock(&file_systems_lock);
tmp = file_systems; for (p = file_systems; p; p = p->next) {
while (tmp && len < PAGE_SIZE - 80) { if (!(p->fs_flags & FS_REQUIRES_DEV))
len += sprintf(buf+len, "%s\t%s\n", continue;
(tmp->fs_flags & FS_REQUIRES_DEV) ? "" : "nodev", len = strlen(p->name) + 1;
tmp->name); if (len > size) {
tmp = tmp->next; pr_warn("%s: truncating file system list\n", __func__);
break;
}
memcpy(buf, p->name, len);
buf += len;
size -= len;
count++;
} }
read_unlock(&file_systems_lock); read_unlock(&file_systems_lock);
return len; return count;
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
......
...@@ -3592,7 +3592,7 @@ int proc_nr_dentry(struct ctl_table *table, int write, ...@@ -3592,7 +3592,7 @@ int proc_nr_dentry(struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos); void *buffer, size_t *lenp, loff_t *ppos);
int proc_nr_inodes(struct ctl_table *table, int write, int proc_nr_inodes(struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos); void *buffer, size_t *lenp, loff_t *ppos);
int __init get_filesystem_list(char *buf); int __init list_bdev_fs_names(char *buf, size_t size);
#define __FMODE_EXEC ((__force int) FMODE_EXEC) #define __FMODE_EXEC ((__force int) FMODE_EXEC)
#define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY) #define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY)
......
...@@ -338,31 +338,22 @@ __setup("rootflags=", root_data_setup); ...@@ -338,31 +338,22 @@ __setup("rootflags=", root_data_setup);
__setup("rootfstype=", fs_names_setup); __setup("rootfstype=", fs_names_setup);
__setup("rootdelay=", root_delay_setup); __setup("rootdelay=", root_delay_setup);
static void __init get_fs_names(char *page) static int __init split_fs_names(char *page, char *names)
{ {
char *s = page; int count = 0;
char *p = page;
if (root_fs_names) { strcpy(p, root_fs_names);
strcpy(page, root_fs_names); while (*p++) {
while (*s++) { if (p[-1] == ',')
if (s[-1] == ',') p[-1] = '\0';
s[-1] = '\0';
}
} else {
int len = get_filesystem_list(page);
char *p, *next;
page[len] = '\0';
for (p = page-1; p; p = next) {
next = strchr(++p, '\n');
if (*p++ != '\t')
continue;
while ((*s++ = *p++) != '\n')
;
s[-1] = '\0';
}
} }
*s = '\0'; *p = '\0';
for (p = page; *p; p += strlen(p)+1)
count++;
return count;
} }
static int __init do_mount_root(const char *name, const char *fs, static int __init do_mount_root(const char *name, const char *fs,
...@@ -408,12 +399,16 @@ void __init mount_block_root(char *name, int flags) ...@@ -408,12 +399,16 @@ void __init mount_block_root(char *name, int flags)
char *fs_names = page_address(page); char *fs_names = page_address(page);
char *p; char *p;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
int num_fs, i;
scnprintf(b, BDEVNAME_SIZE, "unknown-block(%u,%u)", scnprintf(b, BDEVNAME_SIZE, "unknown-block(%u,%u)",
MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
get_fs_names(fs_names); if (root_fs_names)
num_fs = split_fs_names(fs_names, root_fs_names);
else
num_fs = list_bdev_fs_names(fs_names, PAGE_SIZE);
retry: retry:
for (p = fs_names; *p; p += strlen(p)+1) { for (i = 0, p = fs_names; i < num_fs; i++, p += strlen(p)+1) {
int err = do_mount_root(name, p, flags, root_mount_data); int err = do_mount_root(name, p, flags, root_mount_data);
switch (err) { switch (err) {
case 0: case 0:
...@@ -442,7 +437,7 @@ void __init mount_block_root(char *name, int flags) ...@@ -442,7 +437,7 @@ void __init mount_block_root(char *name, int flags)
printk("List of all partitions:\n"); printk("List of all partitions:\n");
printk_all_partitions(); printk_all_partitions();
printk("No filesystem could mount root, tried: "); printk("No filesystem could mount root, tried: ");
for (p = fs_names; *p; p += strlen(p)+1) for (i = 0, p = fs_names; i < num_fs; i++, p += strlen(p)+1)
printk(" %s", p); printk(" %s", p);
printk("\n"); printk("\n");
panic("VFS: Unable to mount root fs on %s", b); panic("VFS: Unable to mount root fs on %s", b);
...@@ -526,6 +521,47 @@ static int __init mount_cifs_root(void) ...@@ -526,6 +521,47 @@ static int __init mount_cifs_root(void)
} }
#endif #endif
static bool __init fs_is_nodev(char *fstype)
{
struct file_system_type *fs = get_fs_type(fstype);
bool ret = false;
if (fs) {
ret = !(fs->fs_flags & FS_REQUIRES_DEV);
put_filesystem(fs);
}
return ret;
}
static int __init mount_nodev_root(void)
{
char *fs_names, *fstype;
int err = -EINVAL;
int num_fs, i;
fs_names = (void *)__get_free_page(GFP_KERNEL);
if (!fs_names)
return -EINVAL;
num_fs = split_fs_names(fs_names, root_fs_names);
for (i = 0, fstype = fs_names; i < num_fs;
i++, fstype += strlen(fstype) + 1) {
if (!fs_is_nodev(fstype))
continue;
err = do_mount_root(root_device_name, fstype, root_mountflags,
root_mount_data);
if (!err)
break;
if (err != -EACCES && err != -EINVAL)
panic("VFS: Unable to mount root \"%s\" (%s), err=%d\n",
root_device_name, fstype, err);
}
free_page((unsigned long)fs_names);
return err;
}
void __init mount_root(void) void __init mount_root(void)
{ {
#ifdef CONFIG_ROOT_NFS #ifdef CONFIG_ROOT_NFS
...@@ -542,6 +578,10 @@ void __init mount_root(void) ...@@ -542,6 +578,10 @@ void __init mount_root(void)
return; return;
} }
#endif #endif
if (ROOT_DEV == 0 && root_device_name && root_fs_names) {
if (mount_nodev_root() == 0)
return;
}
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
{ {
int err = create_dev("/dev/root", ROOT_DEV); int err = create_dev("/dev/root", ROOT_DEV);
......
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