From 6b445fa39bc1ffa88e871c31999b57719c3909f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 30 Nov 2018 18:26:11 +0100 Subject: [PATCH] block: make umount_device() function more generic MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- block.c | 37 +++++++++++++++++-------------------- 1 file 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; } -- 2.30.2