From: Lennart Poettering Date: Wed, 24 Mar 2021 12:56:55 +0000 (+0100) Subject: mount-util: reorder a few things X-Git-Tag: v249-rc1~502^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d6bfab118d2e7c4c07566718175f4f7ec7a2387b;p=thirdparty%2Fsystemd.git mount-util: reorder a few things Let's always query one property, check it, and then query the next, preferring "cheap" ones over "slow" ones (i.e. cheap are the ones we can check directly, and slow are the ones we need to check with some loop of some kind). --- diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 5a3d4b18d00..6180d9c8c0c 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -251,19 +251,33 @@ int bind_remount_recursive_with_mountinfo( const char *path, *type; r = mnt_table_next_fs(table, iter, &fs); - if (r == 1) + if (r == 1) /* EOF */ break; if (r < 0) return log_debug_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m"); path = mnt_fs_get_target(fs); - type = mnt_fs_get_fstype(fs); - if (!path || !type) + if (!path) continue; if (!path_startswith(path, prefix)) continue; + type = mnt_fs_get_fstype(fs); + if (!type) + continue; + + /* Let's ignore autofs mounts. If they aren't triggered yet, we want to avoid + * triggering them, as we don't make any guarantees for future submounts anyway. If + * they are already triggered, then we will find another entry for this. */ + if (streq(type, "autofs")) { + top_autofs = top_autofs || path_equal(path, prefix); + continue; + } + + if (set_contains(done, path)) + continue; + /* Ignore this mount if it is deny-listed, but only if it isn't the top-level mount * we shall operate on. */ if (!path_equal(path, prefix)) { @@ -279,31 +293,18 @@ int bind_remount_recursive_with_mountinfo( if (path_startswith(path, *i)) { deny_listed = true; - log_debug("Not remounting %s deny-listed by %s, called for %s", - path, *i, prefix); + log_debug("Not remounting %s deny-listed by %s, called for %s", path, *i, prefix); break; } } + if (deny_listed) continue; } - /* Let's ignore autofs mounts. If they aren't - * triggered yet, we want to avoid triggering - * them, as we don't make any guarantees for - * future submounts anyway. If they are - * already triggered, then we will find - * another entry for this. */ - if (streq(type, "autofs")) { - top_autofs = top_autofs || path_equal(path, prefix); - continue; - } - - if (!set_contains(done, path)) { - r = set_put_strdup(&todo, path); - if (r < 0) - return r; - } + r = set_put_strdup(&todo, path); + if (r < 0) + return r; } /* If we have no submounts to process anymore and if