mount: fix removing mount point if it's expired
authorRafał Miłecki <rafal@milecki.pl>
Fri, 9 Feb 2018 16:18:21 +0000 (17:18 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Mon, 12 Feb 2018 09:55:34 +0000 (10:55 +0100)
Kernel can report mount point as expired and when that happens mountd
unmounts it. When such a device disappears it's still important to:
1) Cleanup directories
2) Call hotplug scripts
Fix this by adding a new EXPIRED status and checking it when block
device disappears.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
mount.c

diff --git a/mount.c b/mount.c
index 2d34a91be518cda9fb051527a9dccf0b9af13f26..cb3e03c6814fe18f1329574aa11afe326dd4f04d 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -38,11 +38,13 @@ static struct list_head mounts;
  *
  * @STATUS_UNMOUNTED: currently not mounted
  * @STATUS_MOUNTED: mounted & ready for usage
+ * @STATUS_EXPIRED: mount expired & *temporary* unmounted
  * @STATUS_IGNORE: entry should be ignored and never mounted
  */
 enum status {
        STATUS_UNMOUNTED = 0,
        STATUS_MOUNTED,
+       STATUS_EXPIRED,
        STATUS_IGNORE,
 };
 
@@ -330,7 +332,7 @@ int mount_remove(char *path, char *dev)
        rmdir(tmp);
        mount = mount_find(0, dev);
        if(mount)
-               mount->status = STATUS_UNMOUNTED;
+               mount->status = STATUS_EXPIRED;
        log_printf("finished unmounting\n");
        mount_dump_uci_state();
        return 0;
@@ -762,7 +764,7 @@ static void mount_enum_drives(void)
                        p->next->prev = p->prev;
                        p = p->next;
                        log_printf("removing %s\n", q->dev);
-                       if (q->status == STATUS_MOUNTED) {
+                       if (q->status == STATUS_MOUNTED || q->status == STATUS_EXPIRED) {
                                snprintf(tmp, 64, "%s%s", "/tmp/run/mountd/", q->dev);
                                rmdir(tmp);
                                snprintf(tmp, 64, "%s%s", uci_path, q->name);