From f6a96865da9162f45ea1d482c794fe14b26ecfe1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Thu, 6 Dec 2018 09:13:39 +0100 Subject: [PATCH] blockd: don't unmount device when removing it from the list MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Device gets removed from the list (vlist_delete()) when block calls "hotplug" method of blockd using ubus. Right after that block unmounts that device on its own. blockd shouldn't care about unmounting on its own for following reasons: 1) To avoid code/behavior duplication with block 2) To keep behavior consistent with mounting (blockd doesn't mount) 3) To allow implementing more features in block (e.g. hotplug.d events) To make unmounting the most reliable the plan is to have: 1) block receiving hotplug.d "block" subsystem events "remove" 2) blockd stopping reporting device (so we avoid new users & let existing ones realize mount can't be used anymore) 3) block notifying (through hotplug.d "mount" subsystem) all users about device being unmounted - that should stop all apps accessing it 4) block unmount device That should allow storage users stop accessing mount point & let block unmount device cleanly. Signed-off-by: Rafał Miłecki Acked-by: John Crispin --- blockd.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/blockd.c b/blockd.c index a5da32c..1379635 100644 --- a/blockd.c +++ b/blockd.c @@ -112,34 +112,12 @@ static void device_free(struct device *device) { struct blob_attr *data[__MOUNT_MAX]; - char *target = NULL; - char *path = NULL, _path[64], *mp; blobmsg_parse(mount_policy, __MOUNT_MAX, data, blob_data(device->msg), blob_len(device->msg)); - if (data[MOUNT_AUTOFS]) { - target = device->target; - snprintf(_path, sizeof(_path), "/tmp/run/blockd/%s", - blobmsg_get_string(data[MOUNT_DEVICE])); - path = _path; - } else { - path = target = device->target; - } - - mp = _find_mount_point(device->name); - if (path && mp) - if (umount2(path, MNT_DETACH)) - ULOG_ERR("failed to unmount %s\n", path); - free(mp); - - if (!target) - return; - - if (data[MOUNT_AUTOFS]) - unlink(target); - else - rmdir(target); + if (data[MOUNT_AUTOFS] && device->target) + unlink(device->target); } static void -- 2.30.2