mirror of
https://github.com/systemd/systemd.git
synced 2025-02-15 09:57:39 +03:00
core: rename manager_unit_file_maybe_loadable_from_cache()
The name is misleading, since we aren't really loading the unit from cache — if this function returns true, we'll try to load the unit from disk, updating the cache in the process.
This commit is contained in:
parent
c1afa2ed39
commit
81be23886d
@ -1947,18 +1947,24 @@ unsigned manager_dispatch_load_queue(Manager *m) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool manager_unit_file_maybe_loadable_from_cache(Unit *u) {
|
bool manager_unit_cache_should_retry_load(Unit *u) {
|
||||||
assert(u);
|
assert(u);
|
||||||
|
|
||||||
|
/* Automatic reloading from disk only applies to units which were not found sometime in the past, and
|
||||||
|
* the not-found stub is kept pinned in the unit graph by dependencies. For units that were
|
||||||
|
* previously loaded, we don't do automatic reloading, and daemon-reload is necessary to update. */
|
||||||
if (u->load_state != UNIT_NOT_FOUND)
|
if (u->load_state != UNIT_NOT_FOUND)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (u->manager->unit_cache_mtime == 0)
|
if (u->manager->unit_cache_mtime == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/* The cache has been updated since the last time we tried to load the unit. There might be new
|
||||||
|
* fragment paths to read. */
|
||||||
if (u->manager->unit_cache_mtime > u->fragment_loadtime)
|
if (u->manager->unit_cache_mtime > u->fragment_loadtime)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
/* The cache needs to be updated because there are modifications on disk. */
|
||||||
return !lookup_paths_mtime_good(&u->manager->lookup_paths, u->manager->unit_cache_mtime);
|
return !lookup_paths_mtime_good(&u->manager->lookup_paths, u->manager->unit_cache_mtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2008,10 +2014,10 @@ int manager_load_unit_prepare(
|
|||||||
* first if anything in the usual paths was modified since the last time
|
* first if anything in the usual paths was modified since the last time
|
||||||
* the cache was loaded. Also check if the last time an attempt to load the
|
* the cache was loaded. Also check if the last time an attempt to load the
|
||||||
* unit was made was before the most recent cache refresh, so that we know
|
* unit was made was before the most recent cache refresh, so that we know
|
||||||
* we need to try again - even if the cache is current, it might have been
|
* we need to try again — even if the cache is current, it might have been
|
||||||
* updated in a different context before we had a chance to retry loading
|
* updated in a different context before we had a chance to retry loading
|
||||||
* this particular unit. */
|
* this particular unit. */
|
||||||
if (manager_unit_file_maybe_loadable_from_cache(ret))
|
if (manager_unit_cache_should_retry_load(ret))
|
||||||
ret->load_state = UNIT_STUB;
|
ret->load_state = UNIT_STUB;
|
||||||
else {
|
else {
|
||||||
*_ret = ret;
|
*_ret = ret;
|
||||||
|
@ -464,7 +464,7 @@ Unit *manager_get_unit(Manager *m, const char *name);
|
|||||||
|
|
||||||
int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j);
|
int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j);
|
||||||
|
|
||||||
bool manager_unit_file_maybe_loadable_from_cache(Unit *u);
|
bool manager_unit_cache_should_retry_load(Unit *u);
|
||||||
int manager_load_unit_prepare(Manager *m, const char *name, const char *path, sd_bus_error *e, Unit **_ret);
|
int manager_load_unit_prepare(Manager *m, const char *name, const char *path, sd_bus_error *e, Unit **_ret);
|
||||||
int manager_load_unit(Manager *m, const char *name, const char *path, sd_bus_error *e, Unit **_ret);
|
int manager_load_unit(Manager *m, const char *name, const char *path, sd_bus_error *e, Unit **_ret);
|
||||||
int manager_load_startable_unit_or_warn(Manager *m, const char *name, const char *path, Unit **ret);
|
int manager_load_startable_unit_or_warn(Manager *m, const char *name, const char *path, Unit **ret);
|
||||||
|
@ -960,12 +960,13 @@ int transaction_add_job_and_dependencies(
|
|||||||
* first if anything in the usual paths was modified since the last time
|
* first if anything in the usual paths was modified since the last time
|
||||||
* the cache was loaded. Also check if the last time an attempt to load the
|
* the cache was loaded. Also check if the last time an attempt to load the
|
||||||
* unit was made was before the most recent cache refresh, so that we know
|
* unit was made was before the most recent cache refresh, so that we know
|
||||||
* we need to try again - even if the cache is current, it might have been
|
* we need to try again — even if the cache is current, it might have been
|
||||||
* updated in a different context before we had a chance to retry loading
|
* updated in a different context before we had a chance to retry loading
|
||||||
* this particular unit.
|
* this particular unit.
|
||||||
|
*
|
||||||
* Given building up the transaction is a synchronous operation, attempt
|
* Given building up the transaction is a synchronous operation, attempt
|
||||||
* to load the unit immediately. */
|
* to load the unit immediately. */
|
||||||
if (r < 0 && manager_unit_file_maybe_loadable_from_cache(unit)) {
|
if (r < 0 && manager_unit_cache_should_retry_load(unit)) {
|
||||||
sd_bus_error_free(e);
|
sd_bus_error_free(e);
|
||||||
unit->load_state = UNIT_STUB;
|
unit->load_state = UNIT_STUB;
|
||||||
r = unit_load(unit);
|
r = unit_load(unit);
|
||||||
|
@ -1671,8 +1671,8 @@ int unit_load(Unit *u) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* We convert ENOEXEC errors to the UNIT_BAD_SETTING load state here. Configuration parsing code should hence
|
/* We convert ENOEXEC errors to the UNIT_BAD_SETTING load state here. Configuration parsing code
|
||||||
* return ENOEXEC to ensure units are placed in this state after loading */
|
* should hence return ENOEXEC to ensure units are placed in this state after loading. */
|
||||||
|
|
||||||
u->load_state = u->load_state == UNIT_STUB ? UNIT_NOT_FOUND :
|
u->load_state = u->load_state == UNIT_STUB ? UNIT_NOT_FOUND :
|
||||||
r == -ENOEXEC ? UNIT_BAD_SETTING :
|
r == -ENOEXEC ? UNIT_BAD_SETTING :
|
||||||
@ -1680,7 +1680,7 @@ fail:
|
|||||||
u->load_error = r;
|
u->load_error = r;
|
||||||
|
|
||||||
/* Record the last time we tried to load the unit, so that if the cache gets updated between now
|
/* Record the last time we tried to load the unit, so that if the cache gets updated between now
|
||||||
* and the next time an attempt is made to load this unit, we know we need to check again */
|
* and the next time an attempt is made to load this unit, we know we need to check again. */
|
||||||
if (u->load_state == UNIT_NOT_FOUND)
|
if (u->load_state == UNIT_NOT_FOUND)
|
||||||
u->fragment_loadtime = now(CLOCK_REALTIME);
|
u->fragment_loadtime = now(CLOCK_REALTIME);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user