Skip to content

Commit 8902dd5

Browse files
Paulo Alcantara (SUSE)davem330
authored andcommitted
init: Support mounting root file systems over SMB
Add a new virtual device named /dev/cifs (0xfe) to tell the kernel to mount the root file system over the network by using SMB protocol. cifs_root_data() will be responsible to retrieve the parsed information of the new command-line option (cifsroot=) and then call do_mount_root() with the appropriate mount options for cifs.ko. Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1f6d768 commit 8902dd5

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

‎init/do_mounts.c‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static int match_dev_by_label(struct device *dev, const void *data)
212212
* a colon.
213213
* 9) PARTLABEL=<name> with name being the GPT partition label.
214214
* MSDOS partitions do not support labels!
215+
* 10) /dev/cifs represents Root_CIFS (0xfe)
215216
*
216217
* If name doesn't have fall into the categories above, we return (0,0).
217218
* block_class is used to check if something is a disk name. If the disk
@@ -268,6 +269,9 @@ dev_t name_to_dev_t(const char *name)
268269
res = Root_NFS;
269270
if (strcmp(name, "nfs") == 0)
270271
goto done;
272+
res = Root_CIFS;
273+
if (strcmp(name, "cifs") == 0)
274+
goto done;
271275
res = Root_RAM0;
272276
if (strcmp(name, "ram") == 0)
273277
goto done;
@@ -501,6 +505,42 @@ static int __init mount_nfs_root(void)
501505
}
502506
#endif
503507

508+
#ifdef CONFIG_CIFS_ROOT
509+
510+
extern int cifs_root_data(char **dev, char **opts);
511+
512+
#define CIFSROOT_TIMEOUT_MIN 5
513+
#define CIFSROOT_TIMEOUT_MAX 30
514+
#define CIFSROOT_RETRY_MAX 5
515+
516+
static int __init mount_cifs_root(void)
517+
{
518+
char *root_dev, *root_data;
519+
unsigned int timeout;
520+
int try, err;
521+
522+
err = cifs_root_data(&root_dev, &root_data);
523+
if (err != 0)
524+
return 0;
525+
526+
timeout = CIFSROOT_TIMEOUT_MIN;
527+
for (try = 1; ; try++) {
528+
err = do_mount_root(root_dev, "cifs", root_mountflags,
529+
root_data);
530+
if (err == 0)
531+
return 1;
532+
if (try > CIFSROOT_RETRY_MAX)
533+
break;
534+
535+
ssleep(timeout);
536+
timeout <<= 1;
537+
if (timeout > CIFSROOT_TIMEOUT_MAX)
538+
timeout = CIFSROOT_TIMEOUT_MAX;
539+
}
540+
return 0;
541+
}
542+
#endif
543+
504544
#if defined(CONFIG_BLK_DEV_RAM) || defined(CONFIG_BLK_DEV_FD)
505545
void __init change_floppy(char *fmt, ...)
506546
{
@@ -542,6 +582,15 @@ void __init mount_root(void)
542582
ROOT_DEV = Root_FD0;
543583
}
544584
#endif
585+
#ifdef CONFIG_CIFS_ROOT
586+
if (ROOT_DEV == Root_CIFS) {
587+
if (mount_cifs_root())
588+
return;
589+
590+
printk(KERN_ERR "VFS: Unable to mount root fs via SMB, trying floppy.\n");
591+
ROOT_DEV = Root_FD0;
592+
}
593+
#endif
545594
#ifdef CONFIG_BLK_DEV_FD
546595
if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) {
547596
/* rd_doload is 2 for a dual initrd/ramload setup */

0 commit comments

Comments
 (0)