diff mbox

[LEDE-DEV] fstools: ext4 overlay support - rootfs mounted twice bug

Message ID 5768f92a-d15a-37f5-28c7-e7a78d6703ac@gmail.com
State Changes Requested
Delegated to: John Crispin
Headers show

Commit Message

Josua Mayer June 19, 2016, 11:59 a.m. UTC
Hi everybody,

Some of you might remember that there was a bug where an ext4 rootfs was
mounted twice, first as / and then as overlay.
After staring down the mount_root.c file I think I spotted the reason
for it. Sadly I was not able to reproduce the original problem so I am
looking for somebody who had this issue and would be willing to try out
a patch of mine.
Please get back at me if you can.

For any interested people I am attaching the patch to this mail (this is
not yet a patch submission, just discussion).

br
Josua Mayer

Comments

John Crispin June 29, 2016, 6:30 a.m. UTC | #1
Hi,

the patch is an attachement making inline commenting impossible. please
send patches inline

> mount_root: Don't mount ext4 rootfs twice

the patch is incorrect, it breaks the vase where there is an overlay
setup + extroot. after your patch the extroot codepath wont ever run if
there is a rootfs_data partition

	John
diff mbox

Patch

From 01139eeee6474898dff8024ea411e1385d3b5858 Mon Sep 17 00:00:00 2001
From: Josua Mayer <josua.mayer97@gmail.com>
Date: Thu, 16 Jun 2016 18:35:30 +0200
Subject: [PATCH 2/2] mount_root: Don't mount ext4 rootfs twice

When there is a) no rootfs_data overlay partition,
and b) /dev/root points to an ext4 partition
the partition would be mounted twice, once as / and then as /overlay.
The essence of this change is to return before mounting /overlay,
if /dev/root has been mounted as /.
---
 mount_root.c | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/mount_root.c b/mount_root.c
index 608ce5d..13e5772 100644
--- a/mount_root.c
+++ b/mount_root.c
@@ -37,25 +37,45 @@  start(int argc, char *argv[1])
 	if (!getenv("PREINIT") && stat("/tmp/.preinit", &s))
 		return -1;
 
+	/*
+	 * When the default overlay partition name rootfs_data can not be found,
+	 * fall back to the special /dev/root device.
+	 */
 	if (!data) {
 		root = volume_find("rootfs");
 		volume_init(root);
+
+		// mount /dev/root at /
 		ULOG_NOTE("mounting /dev/root\n");
 		mount("/dev/root", "/", NULL, MS_NOATIME | MS_REMOUNT, 0);
-	}
 
-	/*
-	 * Before trying to mount and use "rootfs_data" let's check if there is
-	 * extroot configured. Following call will handle reading config from
-	 * the "rootfs_data" on its own.
-	 */
-	extroot_prefix = "";
-	if (!mount_extroot()) {
-		ULOG_NOTE("switched to extroot\n");
+		/*
+		 * Now that / has been mounted, and there is no overlay device,
+		 * see if extroot is configured.
+		 * 
+		 * The following call will handle reading configuration from
+		 * rootfs on its own.
+		 */
+		extroot_prefix = "";
+		if (!mount_extroot()) {
+			ULOG_NOTE("switched to extroot\n");
+			/*
+			 * extroot succeeded mounting an overlay partition, return.
+			 */
+			return 0;
+		}
+
+		/*
+		 * Even if extroot was not configured, considering that no overlay
+		 * partition was found, and / was mounted, return now.
+		 */
 		return 0;
 	}
 
-	/* There isn't extroot, so just try to mount "rootfs_data" */
+	/*
+	 * neither /dev/root nor extroot were used.
+	 * Attempt to mount the overlay partition.
+	 */
 	switch (volume_identify(data)) {
 	case FS_NONE:
 		ULOG_WARN("no usable overlay filesystem found, using tmpfs overlay\n");
-- 
2.8.4