summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYousong Zhou <yszhou4tech@gmail.com>2019-10-29 12:39:48 +0000
committerJohn Crispin <john@phrozen.org>2019-11-02 19:22:44 +0100
commit32c3126b2f0464106d74317336b6aef1d7d5f82f (patch)
tree2a164ed6db2413fd35777ec5cb9db3a698c768c2
parentfb0700f0fdfc4bec220203d31df87be2b4ccc467 (diff)
downloadfstools-32c3126b2f0464106d74317336b6aef1d7d5f82f.tar.gz
block: mount_action: handle mount/umount deps
This is required at least in system startup when "block hotplug" will be triggered by udevtrigger. E.g. /dev/vdb needs to be mounted at /mnt/s and /dev/vdc /mnt. It does not work if /dev/vdb was triggered then mounted first Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
-rw-r--r--block.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/block.c b/block.c
index 66dcf9c..15caaba 100644
--- a/block.c
+++ b/block.c
@@ -1188,30 +1188,47 @@ static int umount_device(char *path, int type, bool all)
static int mount_action(char *action, char *device, int type)
{
+ struct device *the_dev, *dev;
char path[32];
if (!action || !device)
return -1;
- snprintf(path, sizeof(path), "/dev/%s", device);
+
+ if (config_load(NULL))
+ return -1;
+ cache_load(0);
+
+ the_dev = find_block_device(NULL, NULL, device);
if (!strcmp(action, "remove")) {
if (type == TYPE_HOTPLUG)
blockd_notify(device, NULL, NULL);
- umount_device(path, type, true);
-
+ if (!the_dev || !the_dev->m || the_dev->m->type != TYPE_MOUNT) {
+ snprintf(path, sizeof(path), "/dev/%s", device);
+ umount_device(path, type, true);
+ } else
+ vlist_for_element_to_last_reverse(&devices, the_dev, dev, node)
+ if (dev->m && dev->m->type == TYPE_MOUNT)
+ umount_device(dev->pr->dev, type, true);
return 0;
- } else if (strcmp(action, "add")) {
- ULOG_ERR("Unkown action %s\n", action);
-
- return -1;
+ } else if (!strcmp(action, "add")) {
+ if (!the_dev)
+ return -1;
+ if (the_dev->m && the_dev->m->type == TYPE_MOUNT) {
+ vlist_for_first_to_element(&devices, the_dev, dev, node) {
+ if (dev->m && dev->m->type == TYPE_MOUNT) {
+ int err = mount_device(dev, type);
+ if (err)
+ return err;
+ }
+ }
+ return 0;
+ } else
+ return mount_device(the_dev, type);
}
-
- if (config_load(NULL))
- return -1;
- cache_load(0);
-
- return mount_device(find_block_device(NULL, NULL, path), type);
+ ULOG_ERR("Unkown action %s\n", action);
+ return -1;
}
static int main_hotplug(int argc, char **argv)