Skip to content

Commit e2e694b

Browse files
committed
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
2 parents 7b7699c + 6e7c177 commit e2e694b

File tree

3 files changed

+83
-36
lines changed

3 files changed

+83
-36
lines changed

fs/filesystems.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,28 @@ SYSCALL_DEFINE3(sysfs, int, option, unsigned long, arg1, unsigned long, arg2)
209209
}
210210
#endif
211211

212-
int __init get_filesystem_list(char *buf)
212+
int __init list_bdev_fs_names(char *buf, size_t size)
213213
{
214-
int len = 0;
215-
struct file_system_type * tmp;
214+
struct file_system_type *p;
215+
size_t len;
216+
int count = 0;
216217

217218
read_lock(&file_systems_lock);
218-
tmp = file_systems;
219-
while (tmp && len < PAGE_SIZE - 80) {
220-
len += sprintf(buf+len, "%s\t%s\n",
221-
(tmp->fs_flags & FS_REQUIRES_DEV) ? "" : "nodev",
222-
tmp->name);
223-
tmp = tmp->next;
219+
for (p = file_systems; p; p = p->next) {
220+
if (!(p->fs_flags & FS_REQUIRES_DEV))
221+
continue;
222+
len = strlen(p->name) + 1;
223+
if (len > size) {
224+
pr_warn("%s: truncating file system list\n", __func__);
225+
break;
226+
}
227+
memcpy(buf, p->name, len);
228+
buf += len;
229+
size -= len;
230+
count++;
224231
}
225232
read_unlock(&file_systems_lock);
226-
return len;
233+
return count;
227234
}
228235

229236
#ifdef CONFIG_PROC_FS

include/linux/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,7 @@ int proc_nr_dentry(struct ctl_table *table, int write,
35923592
void *buffer, size_t *lenp, loff_t *ppos);
35933593
int proc_nr_inodes(struct ctl_table *table, int write,
35943594
void *buffer, size_t *lenp, loff_t *ppos);
3595-
int __init get_filesystem_list(char *buf);
3595+
int __init list_bdev_fs_names(char *buf, size_t size);
35963596

35973597
#define __FMODE_EXEC ((__force int) FMODE_EXEC)
35983598
#define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY)

init/do_mounts.c

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -338,31 +338,22 @@ __setup("rootflags=", root_data_setup);
338338
__setup("rootfstype=", fs_names_setup);
339339
__setup("rootdelay=", root_delay_setup);
340340

341-
static void __init get_fs_names(char *page)
341+
static int __init split_fs_names(char *page, char *names)
342342
{
343-
char *s = page;
343+
int count = 0;
344+
char *p = page;
344345

345-
if (root_fs_names) {
346-
strcpy(page, root_fs_names);
347-
while (*s++) {
348-
if (s[-1] == ',')
349-
s[-1] = '\0';
350-
}
351-
} else {
352-
int len = get_filesystem_list(page);
353-
char *p, *next;
354-
355-
page[len] = '\0';
356-
for (p = page-1; p; p = next) {
357-
next = strchr(++p, '\n');
358-
if (*p++ != '\t')
359-
continue;
360-
while ((*s++ = *p++) != '\n')
361-
;
362-
s[-1] = '\0';
363-
}
346+
strcpy(p, root_fs_names);
347+
while (*p++) {
348+
if (p[-1] == ',')
349+
p[-1] = '\0';
364350
}
365-
*s = '\0';
351+
*p = '\0';
352+
353+
for (p = page; *p; p += strlen(p)+1)
354+
count++;
355+
356+
return count;
366357
}
367358

368359
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)
408399
char *fs_names = page_address(page);
409400
char *p;
410401
char b[BDEVNAME_SIZE];
402+
int num_fs, i;
411403

412404
scnprintf(b, BDEVNAME_SIZE, "unknown-block(%u,%u)",
413405
MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
414-
get_fs_names(fs_names);
406+
if (root_fs_names)
407+
num_fs = split_fs_names(fs_names, root_fs_names);
408+
else
409+
num_fs = list_bdev_fs_names(fs_names, PAGE_SIZE);
415410
retry:
416-
for (p = fs_names; *p; p += strlen(p)+1) {
411+
for (i = 0, p = fs_names; i < num_fs; i++, p += strlen(p)+1) {
417412
int err = do_mount_root(name, p, flags, root_mount_data);
418413
switch (err) {
419414
case 0:
@@ -442,7 +437,7 @@ void __init mount_block_root(char *name, int flags)
442437
printk("List of all partitions:\n");
443438
printk_all_partitions();
444439
printk("No filesystem could mount root, tried: ");
445-
for (p = fs_names; *p; p += strlen(p)+1)
440+
for (i = 0, p = fs_names; i < num_fs; i++, p += strlen(p)+1)
446441
printk(" %s", p);
447442
printk("\n");
448443
panic("VFS: Unable to mount root fs on %s", b);
@@ -526,6 +521,47 @@ static int __init mount_cifs_root(void)
526521
}
527522
#endif
528523

524+
static bool __init fs_is_nodev(char *fstype)
525+
{
526+
struct file_system_type *fs = get_fs_type(fstype);
527+
bool ret = false;
528+
529+
if (fs) {
530+
ret = !(fs->fs_flags & FS_REQUIRES_DEV);
531+
put_filesystem(fs);
532+
}
533+
534+
return ret;
535+
}
536+
537+
static int __init mount_nodev_root(void)
538+
{
539+
char *fs_names, *fstype;
540+
int err = -EINVAL;
541+
int num_fs, i;
542+
543+
fs_names = (void *)__get_free_page(GFP_KERNEL);
544+
if (!fs_names)
545+
return -EINVAL;
546+
num_fs = split_fs_names(fs_names, root_fs_names);
547+
548+
for (i = 0, fstype = fs_names; i < num_fs;
549+
i++, fstype += strlen(fstype) + 1) {
550+
if (!fs_is_nodev(fstype))
551+
continue;
552+
err = do_mount_root(root_device_name, fstype, root_mountflags,
553+
root_mount_data);
554+
if (!err)
555+
break;
556+
if (err != -EACCES && err != -EINVAL)
557+
panic("VFS: Unable to mount root \"%s\" (%s), err=%d\n",
558+
root_device_name, fstype, err);
559+
}
560+
561+
free_page((unsigned long)fs_names);
562+
return err;
563+
}
564+
529565
void __init mount_root(void)
530566
{
531567
#ifdef CONFIG_ROOT_NFS
@@ -542,6 +578,10 @@ void __init mount_root(void)
542578
return;
543579
}
544580
#endif
581+
if (ROOT_DEV == 0 && root_device_name && root_fs_names) {
582+
if (mount_nodev_root() == 0)
583+
return;
584+
}
545585
#ifdef CONFIG_BLOCK
546586
{
547587
int err = create_dev("/dev/root", ROOT_DEV);

0 commit comments

Comments
 (0)