[LEDE-DEV] [PATCH mountd] mount: don't mount device that is already mounted

Rafał Miłecki zajec5 at gmail.com
Thu Feb 8 09:34:16 PST 2018


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

It may happen that on mountd start some devices are already mounted.
This could due to killing previous mountd instance or just a crash. In
such case device shouldn't get remounted but added to the list with a
mounted flag set. That will make mountd monitor it and take needed steps
when it disappears.

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 mount.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/mount.c b/mount.c
index f995745..d7aa27c 100644
--- a/mount.c
+++ b/mount.c
@@ -138,7 +138,7 @@ static void mount_add_list(char *name, char *dev, char *serial,
 	char *vendor, char *model, char *rev, int ignore, char *size, char *sector_size, int fs)
 {
 	struct mount *mount;
-	char tmp[64], tmp2[64];
+	char tmp[64], run_mount_path[64];
 
 	mount  = malloc(sizeof(struct mount));
 	INIT_LIST_HEAD(&mount->list);
@@ -154,12 +154,18 @@ static void mount_add_list(char *name, char *dev, char *serial,
 	mount->mounted = 0;
 	mount->fs = fs;
 	list_add(&mount->list, &mounts);
+
+	snprintf(run_mount_path, 64, "/tmp/run/mountd/%s", dev);
+	if (is_mounted(NULL, run_mount_path)) {
+		log_printf("mount point %s already exists!\n", run_mount_path);
+		mount->mounted = 1;
+		return;
+	}
 	if (!mount->ignore)
 	{
 		log_printf("new mount : %s -> %s (%s)\n", name, dev, fs_names[mount->fs]);
 		snprintf(tmp, 64, "%s%s", uci_path, name);
-		snprintf(tmp2, 64, "/tmp/run/mountd/%s", dev);
-		symlink(tmp2, tmp);
+		symlink(run_mount_path, tmp);
 		if (!mount_new("/tmp/run/mountd/", dev))
 			system_printf("ACTION=add DEVICE=%s NAME=%s /sbin/hotplug-call mount", dev, name);
 	}
-- 
2.11.0




More information about the Lede-dev mailing list