summaryrefslogtreecommitdiff
path: root/src/core/path.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-09-26 20:14:24 +0200
committerLennart Poettering <lennart@poettering.net>2013-09-26 20:20:30 +0200
commita57f7e2c828b852eb32fd810dcea041bb2975501 (patch)
tree9d088f212995c20b3ba2d2574ca8027fad25a51b /src/core/path.c
parent6270c1bd8f83e9985458c63688f452be7626766f (diff)
core: rework how we match mount units against each other
Previously to automatically create dependencies between mount units we matched every mount unit agains all others resulting in O(n^2) complexity. On setups with large amounts of mount units this might make things slow. This change replaces the matching code to use a hashtable that is keyed by a path prefix, and points to a set of units that require that path to be around. When a new mount unit is installed it is hence sufficient to simply look up this set of units via its own file system paths to know which units to order after itself. This patch also changes all unit types to only create automatic mount dependencies via the RequiresMountsFor= logic, and this is exposed to the outside to make things more transparent. With this change we still have some O(n) complexities in place when handling mounts, but that's currently unavoidable due to kernel APIs, and still substantially better than O(n^2) as before. https://bugs.freedesktop.org/show_bug.cgi?id=69740
Diffstat (limited to 'src/core/path.c')
-rw-r--r--src/core/path.c32
1 files changed, 2 insertions, 30 deletions
diff --git a/src/core/path.c b/src/core/path.c
index 8a09deb4f..99e2fedf2 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -241,10 +241,6 @@ static bool path_spec_check_good(PathSpec *s, bool initial) {
return good;
}
-static bool path_spec_startswith(PathSpec *s, const char *what) {
- return path_startswith(s->path, what);
-}
-
static void path_spec_mkdir(PathSpec *s, mode_t mode) {
int r;
@@ -301,38 +297,14 @@ static void path_done(Unit *u) {
path_free_specs(p);
}
-int path_add_one_mount_link(Path *p, Mount *m) {
+static int path_add_mount_links(Path *p) {
PathSpec *s;
int r;
assert(p);
- assert(m);
-
- if (UNIT(p)->load_state != UNIT_LOADED ||
- UNIT(m)->load_state != UNIT_LOADED)
- return 0;
LIST_FOREACH(spec, s, p->specs) {
- if (!path_spec_startswith(s, m->where))
- continue;
-
- r = unit_add_two_dependencies(UNIT(p), UNIT_AFTER, UNIT_REQUIRES,
- UNIT(m), true);
- if (r < 0)
- return r;
- }
-
- return 0;
-}
-
-static int path_add_mount_links(Path *p) {
- Unit *other;
- int r;
-
- assert(p);
-
- LIST_FOREACH(units_by_type, other, UNIT(p)->manager->units_by_type[UNIT_MOUNT]) {
- r = path_add_one_mount_link(p, MOUNT(other));
+ r = unit_require_mounts_for(UNIT(p), s->path);
if (r < 0)
return r;
}