summaryrefslogtreecommitdiff
path: root/src/core/transaction.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2012-04-20 09:38:43 +0200
committerMichal Schmidt <mschmidt@redhat.com>2012-04-20 17:12:29 +0200
commit656bbffc6c45bdd8d5c28a96ca948ba16c546547 (patch)
tree72ae472a5d5bb05b7b5c8cfcceefbfce0898537b /src/core/transaction.c
parent05d576f1f77699ea5c2e5ed0e04451b14dfc45a0 (diff)
transaction: rework merging with installed jobs
Previously transactions could reference installed jobs. It made some issues difficult to fix. This sets new rules for jobs: A job cannot be both a member of a transaction and installed. When jobs are created, they are linked to a transaction. The whole transaction is constructed (with merging of jobs within, etc.). When it's complete, all the jobs are unlinked from it one by one and let to install themselves. It is during the installation when merging with previously installed jobs (from older transactions) is contemplated. Merging with installed jobs has different rules than merging within a transaction: - An installed conflicting job gets cancelled. It cannot be simply deleted, because someone might be waiting for its completion on DBus. - An installed, but still waiting, job can be safely merged into. - An installed and running job can be tricky. For some job types it is safe to just merge. For the other types we merge anyway, but put the job back into JOB_WAITING to allow it to run again. This may be suboptimal, but it is not currently possible to have more than one installed job for a unit. Note this also fixes a bug where the anchor job could be deleted during merging within the transaction.
Diffstat (limited to 'src/core/transaction.c')
-rw-r--r--src/core/transaction.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/core/transaction.c b/src/core/transaction.c
index d495cbddc6..aa0cedf6eb 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -243,21 +243,14 @@ static int transaction_merge_jobs(Transaction *tr, DBusError *e) {
LIST_FOREACH(transaction, k, j->transaction_next)
assert_se(job_type_merge(&t, k->type) == 0);
- /* If an active job is mergeable, merge it too */
- if (j->unit->job)
- job_type_merge(&t, j->unit->job->type); /* Might fail. Which is OK */
-
while ((k = j->transaction_next)) {
- if (j->installed) {
+ if (tr->anchor_job == k) {
transaction_merge_and_delete_job(tr, k, j, t);
j = k;
} else
transaction_merge_and_delete_job(tr, j, k, t);
}
- if (j->unit->job && !j->installed)
- transaction_merge_and_delete_job(tr, j, j->unit->job, t);
-
assert(!j->transaction_next);
assert(!j->transaction_prev);
}
@@ -592,6 +585,8 @@ static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) {
}
while ((j = hashmap_steal_first(tr->jobs))) {
+ Job *installed_job;
+
if (j->installed) {
/* log_debug("Skipping already installed job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id); */
continue;
@@ -600,7 +595,15 @@ static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) {
/* Clean the job dependencies */
transaction_unlink_job(tr, j, false);
- job_install(j);
+ installed_job = job_install(j);
+ if (installed_job != j) {
+ /* j has been merged into a previously installed job */
+ if (tr->anchor_job == j)
+ tr->anchor_job = installed_job;
+ hashmap_remove(m->jobs, UINT32_TO_PTR(j->id));
+ job_free(j);
+ j = installed_job;
+ }
job_add_to_run_queue(j);
job_add_to_dbus_queue(j);