blockd: don't unmount device when removing it from the list
authorRafał Miłecki <rafal@milecki.pl>
Thu, 6 Dec 2018 08:13:39 +0000 (09:13 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Thu, 6 Dec 2018 08:13:39 +0000 (09:13 +0100)
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 <rafal@milecki.pl>
Acked-by: John Crispin <john@phrozen.org>
blockd.c

index a5da32c..1379635 100644 (file)
--- 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