[OpenWrt-Devel] [PATCH fstools WIP] block: check for parent mount point before mounting

Rafał Miłecki zajec5 at gmail.com
Thu Apr 2 12:15:13 EDT 2020


From: Rafał Miłecki <rafal at milecki.pl>

Some devices may have mount target set to directory used by another
device. Detect it and print a warning.

In future we should mount such "parent" devices first.

Cc: Yousong Zhou <yszhou4tech at gmail.com>
Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 block.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/block.c b/block.c
index dfee7fb..7cd1944 100644
--- a/block.c
+++ b/block.c
@@ -1029,6 +1029,34 @@ static int blockd_notify(char *device, struct mount *m, struct probe_info *pr)
 	return err;
 }
 
+/**
+ * find_parent_device - find "parent" device for a given target path
+ *
+ * Some devices may have target path set to directory that is used as another
+ * device mount point. This function allows finding such devices so they can be
+ * mounted first.
+ */
+static struct probe_info *find_parent_device(struct probe_info *pr, const char *target)
+{
+	struct probe_info *e;
+
+	list_for_each_entry(e, &devices, list) {
+		struct mount *mp;
+
+		if (e == pr)
+			continue;
+
+		mp = find_block(e->uuid, e->label, basename(e->dev), NULL);
+		if (mp && mp->target) {
+			if (strlen(mp->target) < strlen(target) &&
+			    !strncmp(mp->target, target, strlen(mp->target)))
+				return e;
+		}
+	}
+
+	return NULL;
+}
+
 static int mount_device(struct probe_info *pr, int type)
 {
 	struct mount *m;
@@ -1069,6 +1097,14 @@ static int mount_device(struct probe_info *pr, int type)
 		return err;
 	}
 
+	/* Check if there is device for parent dir */
+	if (m && m->target) {
+		struct probe_info *parent = find_parent_device(pr, m->target);
+
+		if (parent)
+			ULOG_WARN("Device %s should be mounted first!\n", parent->dev);
+	}
+
 	if (type == TYPE_HOTPLUG)
 		blockd_notify(device, m, pr);
 
-- 
2.25.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list