summaryrefslogtreecommitdiff
path: root/src/core/transaction.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2012-04-25 11:58:27 +0200
committerMichal Schmidt <mschmidt@redhat.com>2012-04-25 18:38:27 +0200
commite0209d83e7b30153f43b1a633c955f66eb2c2e4a (patch)
tree95841c9e763cecd6c2ed10d54de67e74e107122b /src/core/transaction.c
parente2875c46936a16efc0f58f9e6e2570cdda8d6d98 (diff)
core: add NOP jobs, job type collapsing
Two of our current job types are special: JOB_TRY_RESTART, JOB_RELOAD_OR_START. They differ from other job types by being sensitive to the unit active state. They perform some action when the unit is active and some other action otherwise. This raises a question: when exactly should the unit state be checked to make the decision? Currently the unit state is checked when the job becomes runnable. It's more sensible to check the state immediately when the job is added by the user. When the user types "systemctl try-restart foo.service", he really intends to restart the service if it's running right now. If it isn't running right now, the restart is pointless. Consider the example (from Bugzilla[1]): sleep.service takes some time to start. hello.service has After=sleep.service. Both services get started. Two jobs will appear: hello.service/start waiting sleep.service/start running Then someone runs "systemctl try-restart hello.service". Currently the try-restart operation will block and wait for sleep.service/start to complete. The correct result is to complete the try-restart operation immediately with success, because hello.service is not running. The two original jobs must not be disturbed by this. To fix this we introduce two new concepts: - a new job type: JOB_NOP A JOB_NOP job does not do anything to the unit. It does not pull in any dependencies. It is always immediately runnable. When installed to a unit, it sits in a special slot (u->nop_job) where it never conflicts with the installed job (u->job) of a different type. It never merges with jobs of other types, but it can merge into an already installed JOB_NOP job. - "collapsing" of job types When a job of one of the two special types is added, the state of the unit is checked immediately and the job type changes: JOB_TRY_RESTART -> JOB_RESTART or JOB_NOP JOB_RELOAD_OR_START -> JOB_RELOAD or JOB_START Should a job type JOB_RELOAD_OR_START appear later during job merging, it collapses immediately afterwards. Collapsing actually makes some things simpler, because there are now fewer job types that are allowed in the transaction. [1] Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=753586
Diffstat (limited to 'src/core/transaction.c')
-rw-r--r--src/core/transaction.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/core/transaction.c b/src/core/transaction.c
index 09ed80737d..44fdc06580 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -236,7 +236,7 @@ static int transaction_merge_jobs(Transaction *tr, DBusError *e) {
t = j->type;
LIST_FOREACH(transaction, k, j->transaction_next) {
- if (job_type_merge(&t, k->type) >= 0)
+ if (job_type_merge_and_collapse(&t, k->type, j->unit) >= 0)
continue;
/* OK, we could not merge all jobs for this
@@ -262,9 +262,9 @@ static int transaction_merge_jobs(Transaction *tr, DBusError *e) {
JobType t = j->type;
Job *k;
- /* Merge all transactions */
+ /* Merge all transaction jobs for j->unit */
LIST_FOREACH(transaction, k, j->transaction_next)
- assert_se(job_type_merge(&t, k->type) == 0);
+ assert_se(job_type_merge_and_collapse(&t, k->type, j->unit) == 0);
while ((k = j->transaction_next)) {
if (tr->anchor_job == k) {
@@ -809,6 +809,7 @@ int transaction_add_job_and_dependencies(
assert(tr);
assert(type < _JOB_TYPE_MAX);
+ assert(type < _JOB_TYPE_MAX_IN_TRANSACTION);
assert(unit);
/* log_debug("Pulling in %s/%s from %s/%s", */
@@ -859,7 +860,8 @@ int transaction_add_job_and_dependencies(
assert(!tr->anchor_job);
tr->anchor_job = ret;
}
- if (is_new && !ignore_requirements) {
+
+ if (is_new && !ignore_requirements && type != JOB_NOP) {
Set *following;
/* If we are following some other unit, make sure we
@@ -879,7 +881,7 @@ int transaction_add_job_and_dependencies(
}
/* Finally, recursively add in all dependencies. */
- if (type == JOB_START || type == JOB_RELOAD_OR_START || type == JOB_RESTART) {
+ if (type == JOB_START || type == JOB_RESTART) {
SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES], i) {
r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, override, false, false, ignore_order, e);
if (r < 0) {
@@ -969,7 +971,7 @@ int transaction_add_job_and_dependencies(
}
- if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
+ if (type == JOB_STOP || type == JOB_RESTART) {
SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRED_BY], i) {
r = transaction_add_job_and_dependencies(tr, type, dep, ret, true, override, false, false, ignore_order, e);
@@ -994,7 +996,7 @@ int transaction_add_job_and_dependencies(
}
}
- if (type == JOB_RELOAD || type == JOB_RELOAD_OR_START) {
+ if (type == JOB_RELOAD) {
SET_FOREACH(dep, ret->unit->dependencies[UNIT_PROPAGATE_RELOAD_TO], i) {
r = transaction_add_job_and_dependencies(tr, JOB_RELOAD, dep, ret, false, override, false, false, ignore_order, e);
@@ -1007,7 +1009,7 @@ int transaction_add_job_and_dependencies(
}
}
- /* JOB_VERIFY_STARTED, JOB_RELOAD require no dependency handling */
+ /* JOB_VERIFY_STARTED require no dependency handling */
}
return 0;