summaryrefslogtreecommitdiff
path: root/src/core/load-fragment.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/load-fragment.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/load-fragment.c')
-rw-r--r--src/core/load-fragment.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 74454abe49..70ea13aa80 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -1773,33 +1773,48 @@ int config_parse_unit_condition_null(const char *unit,
DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
DEFINE_CONFIG_PARSE_ENUM(config_parse_start_limit_action, start_limit_action, StartLimitAction, "Failed to parse start limit action specifier");
-int config_parse_unit_requires_mounts_for(const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
+int config_parse_unit_requires_mounts_for(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
Unit *u = userdata;
+ char *state;
+ size_t l;
+ char *w;
int r;
- bool empty_before;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
- empty_before = !u->requires_mounts_for;
+ FOREACH_WORD_QUOTED(w, l, rvalue, state) {
+ _cleanup_free_ char *n;
+
+ n = strndup(w, l);
+ if (!n)
+ return log_oom();
- r = config_parse_path_strv(unit, filename, line, section, lvalue, ltype,
- rvalue, data, userdata);
+ if (!utf8_is_valid(n)) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
+ continue;
+ }
- /* Make it easy to find units with requires_mounts set */
- if (empty_before && u->requires_mounts_for)
- LIST_PREPEND(Unit, has_requires_mounts_for, u->manager->has_requires_mounts_for, u);
+ r = unit_require_mounts_for(u, n);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, r,
+ "Failed to add required mount for, ignoring: %s", rvalue);
+ continue;
+ }
+ }
return r;
}