From c2c331056a7c331a5478124b3cd6a34c9f539839 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: May 07 2021 09:57:43 +0000 Subject: mount-util: shortcut things after generating top-level bind mount Instead of marking the bind mount read-only right-away, let's just restart the loop, so that we'll pick it up like any other mount and then remount like that. (cherry picked from commit 5c5753b9ea5cc012586ae90d357d460dec4301a4) --- diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 6180d9c..fb7e513 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -307,34 +307,25 @@ int bind_remount_recursive_with_mountinfo( return r; } - /* If we have no submounts to process anymore and if - * the root is either already done, or an autofs, we - * are done */ - if (set_isempty(todo) && - (top_autofs || set_contains(done, prefix))) - return 0; - + /* Check if the top-level directory was among what we have seen so far. For that check both + * 'done' and 'todo'. Also check 'top_autofs' because if the top-level dir is an autofs we'll + * not include it in either set but will set this bool. */ if (!set_contains(done, prefix) && - !set_contains(todo, prefix)) { + !(top_autofs || set_contains(todo, prefix))) { + /* The prefix directory itself is not yet a mount, make it one. */ r = mount_nofollow(prefix, prefix, NULL, MS_BIND|MS_REC, NULL); if (r < 0) return r; - orig_flags = 0; - (void) get_mount_flags(table, prefix, &orig_flags); - - r = mount_nofollow(NULL, prefix, NULL, (orig_flags & ~flags_mask)|MS_BIND|MS_REMOUNT|new_flags, NULL); - if (r < 0) - return r; - - log_debug("Made top-level directory %s a mount point.", prefix); - - r = set_put_strdup(&done, prefix); - if (r < 0) - return r; + /* Immediately rescan, so that we pick up the new mount's flags */ + continue; } + /* If we have no submounts to process anymore, we are done */ + if (set_isempty(todo)) + return 0; + while ((x = set_steal_first(todo))) { r = set_consume(done, x);