Linux-CIFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH net-next 0/2] Experimental SMB rootfs support
@ 2019-10-01 17:10 Paulo Alcantara (SUSE)
  2019-10-01 17:10 ` [PATCH net-next 1/2] init: Support mounting root file systems over SMB Paulo Alcantara (SUSE)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Paulo Alcantara (SUSE) @ 2019-10-01 17:10 UTC (permalink / raw)
  To: netdev, linux-cifs, samba-technical, davem, smfrench
  Cc: Paulo Alcantara (SUSE)

Hi,

This patch series enables Linux to mount root file systems over the
network by utilizing SMB protocol.

Upstream commit 8eecd1c2e5bc ("cifs: Add support for root file
systems") introduced a new CONFIG_CIFS_ROOT option, a virtual device
(Root_CIFS) and a kernel cmdline parameter "cifsroot=" which tells the
kernel to actually mount the root filesystem over a SMB share.

The feature relies on ipconfig to set up the network prior to mounting
the rootfs, so when it is set along with "cifsroot=" parameter:

    (1) cifs_root_setup() parses all necessary data out of "cifsroot="
    parameter for the init process know how to mount the SMB rootfs
    (e.g. SMB server address, mount options).

    (2) If DHCP failed for some reason in ipconfig, we keep retrying
    forever as we have nowhere to go for NFS or SMB root
    filesystems (see PATCH 2/2). Otherwise go to (3).

    (3) mount_cifs_root() is then called by mount_root() (ROOT_DEV ==
    Root_CIFS), retrieves early parsed data from (1), then attempt to
    mount SMB rootfs by CIFSROOT_RETRY_MAX times at most (see PATCH
    1/2).

    (4) If all attempts failed, fall back to floppy drive, otherwise
    continue the boot process with rootfs mounted over a SMB share.

My idea was to keep the same behavior of nfsroot - as it seems to work
for most users so far.

For more information on how this feature works, see
Documentation/filesystems/cifs/cifsroot.txt.

Paulo Alcantara (SUSE) (2):
  init: Support mounting root file systems over SMB
  ipconfig: Handle CONFIG_CIFS_ROOT option

 init/do_mounts.c    | 49 +++++++++++++++++++++++++++++++++++++++++++++
 net/ipv4/ipconfig.c | 10 +++++++--
 2 files changed, 57 insertions(+), 2 deletions(-)

-- 
2.23.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] init: Support mounting root file systems over SMB
  2019-10-01 17:10 [PATCH net-next 0/2] Experimental SMB rootfs support Paulo Alcantara (SUSE)
@ 2019-10-01 17:10 ` Paulo Alcantara (SUSE)
  2019-10-01 17:10 ` [PATCH net-next 2/2] ipconfig: Handle CONFIG_CIFS_ROOT option Paulo Alcantara (SUSE)
  2019-10-02 16:15 ` [PATCH net-next 0/2] Experimental SMB rootfs support David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Paulo Alcantara (SUSE) @ 2019-10-01 17:10 UTC (permalink / raw)
  To: netdev, linux-cifs, samba-technical, davem, smfrench
  Cc: Paulo Alcantara (SUSE)

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>
---
 init/do_mounts.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index 9634ecf3743d..af9cda887a23 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -212,6 +212,7 @@ static int match_dev_by_label(struct device *dev, const void *data)
  *	   a colon.
  *	9) PARTLABEL=<name> with name being the GPT partition label.
  *	   MSDOS partitions do not support labels!
+ *	10) /dev/cifs represents Root_CIFS (0xfe)
  *
  *	If name doesn't have fall into the categories above, we return (0,0).
  *	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)
 	res = Root_NFS;
 	if (strcmp(name, "nfs") == 0)
 		goto done;
+	res = Root_CIFS;
+	if (strcmp(name, "cifs") == 0)
+		goto done;
 	res = Root_RAM0;
 	if (strcmp(name, "ram") == 0)
 		goto done;
@@ -501,6 +505,42 @@ static int __init mount_nfs_root(void)
 }
 #endif
 
+#ifdef CONFIG_CIFS_ROOT
+
+extern int cifs_root_data(char **dev, char **opts);
+
+#define CIFSROOT_TIMEOUT_MIN	5
+#define CIFSROOT_TIMEOUT_MAX	30
+#define CIFSROOT_RETRY_MAX	5
+
+static int __init mount_cifs_root(void)
+{
+	char *root_dev, *root_data;
+	unsigned int timeout;
+	int try, err;
+
+	err = cifs_root_data(&root_dev, &root_data);
+	if (err != 0)
+		return 0;
+
+	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 (try > CIFSROOT_RETRY_MAX)
+			break;
+
+		ssleep(timeout);
+		timeout <<= 1;
+		if (timeout > CIFSROOT_TIMEOUT_MAX)
+			timeout = CIFSROOT_TIMEOUT_MAX;
+	}
+	return 0;
+}
+#endif
+
 #if defined(CONFIG_BLK_DEV_RAM) || defined(CONFIG_BLK_DEV_FD)
 void __init change_floppy(char *fmt, ...)
 {
@@ -542,6 +582,15 @@ void __init mount_root(void)
 		ROOT_DEV = Root_FD0;
 	}
 #endif
+#ifdef CONFIG_CIFS_ROOT
+	if (ROOT_DEV == Root_CIFS) {
+		if (mount_cifs_root())
+			return;
+
+		printk(KERN_ERR "VFS: Unable to mount root fs via SMB, trying floppy.\n");
+		ROOT_DEV = Root_FD0;
+	}
+#endif
 #ifdef CONFIG_BLK_DEV_FD
 	if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) {
 		/* rd_doload is 2 for a dual initrd/ramload setup */
-- 
2.23.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] ipconfig: Handle CONFIG_CIFS_ROOT option
  2019-10-01 17:10 [PATCH net-next 0/2] Experimental SMB rootfs support Paulo Alcantara (SUSE)
  2019-10-01 17:10 ` [PATCH net-next 1/2] init: Support mounting root file systems over SMB Paulo Alcantara (SUSE)
@ 2019-10-01 17:10 ` Paulo Alcantara (SUSE)
  2019-10-02 16:15 ` [PATCH net-next 0/2] Experimental SMB rootfs support David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Paulo Alcantara (SUSE) @ 2019-10-01 17:10 UTC (permalink / raw)
  To: netdev, linux-cifs, samba-technical, davem, smfrench
  Cc: Paulo Alcantara (SUSE)

The experimental root file system support in cifs.ko relies on
ipconfig to set up the network stack and then accessing the SMB share
that contains the rootfs files.

Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
---
 net/ipv4/ipconfig.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 9bcca08efec9..32e20b758b68 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -1483,10 +1483,10 @@ static int __init ip_auto_config(void)
 	 * missing values.
 	 */
 	if (ic_myaddr == NONE ||
-#ifdef CONFIG_ROOT_NFS
+#if defined(CONFIG_ROOT_NFS) || defined(CONFIG_CIFS_ROOT)
 	    (root_server_addr == NONE &&
 	     ic_servaddr == NONE &&
-	     ROOT_DEV == Root_NFS) ||
+	     (ROOT_DEV == Root_NFS || ROOT_DEV == Root_CIFS)) ||
 #endif
 	    ic_first_dev->next) {
 #ifdef IPCONFIG_DYNAMIC
@@ -1513,6 +1513,12 @@ static int __init ip_auto_config(void)
 				goto try_try_again;
 			}
 #endif
+#ifdef CONFIG_CIFS_ROOT
+			if (ROOT_DEV == Root_CIFS) {
+				pr_err("IP-Config: Retrying forever (CIFS root)...\n");
+				goto try_try_again;
+			}
+#endif
 
 			if (--retries) {
 				pr_err("IP-Config: Reopening network devices...\n");
-- 
2.23.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] Experimental SMB rootfs support
  2019-10-01 17:10 [PATCH net-next 0/2] Experimental SMB rootfs support Paulo Alcantara (SUSE)
  2019-10-01 17:10 ` [PATCH net-next 1/2] init: Support mounting root file systems over SMB Paulo Alcantara (SUSE)
  2019-10-01 17:10 ` [PATCH net-next 2/2] ipconfig: Handle CONFIG_CIFS_ROOT option Paulo Alcantara (SUSE)
@ 2019-10-02 16:15 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-10-02 16:15 UTC (permalink / raw)
  To: pc; +Cc: netdev, linux-cifs, samba-technical, smfrench

From: "Paulo Alcantara (SUSE)" <pc@cjr.nz>
Date: Tue,  1 Oct 2019 14:10:26 -0300

> This patch series enables Linux to mount root file systems over the
> network by utilizing SMB protocol.
 ...

Series applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01 17:10 [PATCH net-next 0/2] Experimental SMB rootfs support Paulo Alcantara (SUSE)
2019-10-01 17:10 ` [PATCH net-next 1/2] init: Support mounting root file systems over SMB Paulo Alcantara (SUSE)
2019-10-01 17:10 ` [PATCH net-next 2/2] ipconfig: Handle CONFIG_CIFS_ROOT option Paulo Alcantara (SUSE)
2019-10-02 16:15 ` [PATCH net-next 0/2] Experimental SMB rootfs support David Miller

Linux-CIFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-cifs/0 linux-cifs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-cifs linux-cifs/ https://lore.kernel.org/linux-cifs \
		linux-cifs@vger.kernel.org
	public-inbox-index linux-cifs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-cifs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git