mirror of
https://github.com/systemd/systemd
synced 2024-10-15 12:34:37 +00:00
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]
This commit is contained in:
parent
a341dfe563
commit
2d058a87ff
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue