summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafał Miłecki <rafal@milecki.pl>2018-11-30 18:26:11 +0100
committerRafał Miłecki <rafal@milecki.pl>2018-12-05 21:56:37 +0100
commit6b445fa39bc1ffa88e871c31999b57719c3909f8 (patch)
tree91a6d375a11d4d4659c85906206bee40f7031c0c
parenta778468bca43a269d80b31b5d7b96bf745a00f38 (diff)
downloadfstools-6b445fa39bc1ffa88e871c31999b57719c3909f8.tar.gz
block: make umount_device() function more generic
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@milecki.pl>
-rw-r--r--block.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/block.c b/block.c
index a356315..e294ba4 100644
--- a/block.c
+++ b/block.c
@@ -1082,34 +1082,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;
@@ -1577,8 +1564,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;
}