[OpenWrt-Devel] [PATCH fstools 1/2] block: make umount_device() function more generic

Rafał Miłecki zajec5 at gmail.com
Fri Nov 30 12:26:11 EST 2018


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

Make it accept device path instead of struct probe_info. This way it can
be reused by code fired when device is already gone.

To keep existing functionality two checks have been moved to the
main_umount().

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 block.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/block.c b/block.c
index 20c14fe..bef5550 100644
--- a/block.c
+++ b/block.c
@@ -1109,34 +1109,21 @@ static int mount_device(struct probe_info *pr, int type)
 	return 0;
 }
 
-static int umount_device(struct probe_info *pr)
+static int umount_device(char *path)
 {
-	struct mount *m;
-	char *device = basename(pr->dev);
 	char *mp;
 	int err;
 
-	if (!pr)
-		return -1;
-
-	if (!strcmp(pr->type, "swap"))
-		return -1;
-
-	mp = find_mount_point(pr->dev);
+	mp = find_mount_point(path);
 	if (!mp)
 		return -1;
 
-	m = find_block(pr->uuid, pr->label, device, NULL);
-	if (m && m->extroot)
-		return -1;
-
 	err = umount2(mp, MNT_DETACH);
 	if (err)
-		ULOG_ERR("unmounting %s (%s)  failed (%d) - %m\n",
-		         pr->dev, mp, errno);
+		ULOG_ERR("unmounting %s (%s) failed (%d) - %m\n", path, mp,
+			 errno);
 	else
-		ULOG_INFO("unmounted %s (%s)\n",
-		          pr->dev, mp);
+		ULOG_INFO("unmounted %s (%s)\n", path, mp);
 
 	free(mp);
 	return err;
@@ -1604,8 +1591,18 @@ static int main_umount(int argc, char **argv)
 	handle_swapfiles(false);
 
 	cache_load(0);
-	list_for_each_entry(pr, &devices, list)
-		umount_device(pr);
+	list_for_each_entry(pr, &devices, list) {
+		struct mount *m;
+
+		if (!strcmp(pr->type, "swap"))
+			continue;
+
+		m = find_block(pr->uuid, pr->label, basename(pr->dev), NULL);
+		if (m && m->extroot)
+			continue;
+
+		umount_device(pr->dev);
+	}
 
 	return 0;
 }
-- 
2.13.7


_______________________________________________
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