Skip to content

Commit af5dde2

Browse files
authored
core/transaction: fix issue in dropping unmergeable jobs (#38776)
Fixes #38765.
2 parents fcb90e6 + 5b89cc2 commit af5dde2

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/core/transaction.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "strv.h"
1616
#include "transaction.h"
1717

18+
static bool job_matters_to_anchor(Job *job);
1819
static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies);
1920

2021
static void transaction_delete_job(Transaction *tr, Job *j, bool delete_dependencies) {
@@ -171,6 +172,7 @@ static int delete_one_unmergeable_job(Transaction *tr, Job *job) {
171172
* another unit in which case we
172173
* rather remove the start. */
173174

175+
/* Update test/units/TEST-87-AUX-UTILS-VM.sh when logs below are changed. */
174176
log_unit_debug(j->unit,
175177
"Looking at job %s/%s conflicted_by=%s",
176178
j->unit->id, job_type_to_string(j->type),
@@ -216,17 +218,18 @@ static int delete_one_unmergeable_job(Transaction *tr, Job *job) {
216218
return -EINVAL;
217219
}
218220

219-
static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) {
221+
static int transaction_ensure_mergeable(Transaction *tr, bool matters_to_anchor, sd_bus_error *e) {
220222
Job *j;
221223
int r;
222224

223225
assert(tr);
224226

225-
/* First step, check whether any of the jobs for one specific
226-
* task conflict. If so, try to drop one of them. */
227227
HASHMAP_FOREACH(j, tr->jobs) {
228228
JobType t;
229229

230+
if (job_matters_to_anchor(j) != matters_to_anchor)
231+
continue;
232+
230233
t = j->type;
231234
LIST_FOREACH(transaction, k, j->transaction_next) {
232235
if (job_type_merge_and_collapse(&t, k->type, j->unit) >= 0)
@@ -253,7 +256,26 @@ static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) {
253256
}
254257
}
255258

256-
/* Second step, merge the jobs. */
259+
return 0;
260+
}
261+
262+
static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) {
263+
Job *j;
264+
int r;
265+
266+
assert(tr);
267+
268+
/* First step, try to drop unmergeable jobs for jobs that matter to anchor. */
269+
r = transaction_ensure_mergeable(tr, /* matters_to_anchor = */ true, e);
270+
if (r < 0)
271+
return r;
272+
273+
/* Second step, do the same for jobs that not matter to anchor. */
274+
r = transaction_ensure_mergeable(tr, /* matters_to_anchor = */ false, e);
275+
if (r < 0)
276+
return r;
277+
278+
/* Third step, merge the jobs. */
257279
HASHMAP_FOREACH(j, tr->jobs) {
258280
JobType t = j->type;
259281

test/units/TEST-87-AUX-UTILS-VM.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
set -eux
44
set -o pipefail
55

6+
# For issue #38765
7+
journalctl --sync
8+
if journalctl -q -o short-monotonic --grep "Looking at job .*/.* conflicted_by=(yes|no)" >/failed; then
9+
echo "Found unexpected unmergeable jobs"
10+
cat /failed
11+
exit 1
12+
fi
13+
614
# shellcheck source=test/units/test-control.sh
715
. "$(dirname "$0")"/test-control.sh
816

0 commit comments

Comments
 (0)