From 2d058a87ffb2d31a50422a8aebd119bbb4427244 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Tue, 24 Jan 2017 14:29:57 +0100 Subject: [PATCH] core: don't load dropin data multiple times for the same unit (#5139) When an alias is loaded, we resolve this alias to its final unit first to load the dropin data. However if the final unit was already loaded, there's no point in reloading the dropin data a second time. This patch optimizes this case. Also this allows the dropin loading code to assume that only units not yet loaded are passed down. This assumption is not yet used but might be in the future. [zj: invert the condition in the if] --- src/core/unit.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index 409668f..44f1d5e 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1083,6 +1083,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) { /* Common implementation for multiple backends */ int unit_load_fragment_and_dropin(Unit *u) { + Unit *t; int r; assert(u); @@ -1095,16 +1096,18 @@ int unit_load_fragment_and_dropin(Unit *u) { if (u->load_state == UNIT_STUB) return -ENOENT; - /* Load drop-in directory data */ - r = unit_load_dropin(unit_follow_merge(u)); - if (r < 0) - return r; + /* If the unit is an alias and the final unit has already been + * loaded, there's no point in reloading the dropins one more time. */ + t = unit_follow_merge(u); + if (t != u && t->load_state != UNIT_STUB) + return 0; - return 0; + return unit_load_dropin(t); } /* Common implementation for multiple backends */ int unit_load_fragment_and_dropin_optional(Unit *u) { + Unit *t; int r; assert(u); @@ -1120,12 +1123,13 @@ int unit_load_fragment_and_dropin_optional(Unit *u) { if (u->load_state == UNIT_STUB) u->load_state = UNIT_LOADED; - /* Load drop-in directory data */ - r = unit_load_dropin(unit_follow_merge(u)); - if (r < 0) - return r; + /* If the unit is an alias and the final unit has already been + * loaded, there's no point in reloading the dropins one more time. */ + t = unit_follow_merge(u); + if (t != u && t->load_state != UNIT_STUB) + return 0; - return 0; + return unit_load_dropin(t); } int unit_add_default_target_dependency(Unit *u, Unit *target) { -- 2.7.4