15
15
#include "strv.h"
16
16
#include "transaction.h"
17
17
18
+ static bool job_matters_to_anchor (Job * job );
18
19
static void transaction_unlink_job (Transaction * tr , Job * j , bool delete_dependencies );
19
20
20
21
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) {
171
172
* another unit in which case we
172
173
* rather remove the start. */
173
174
175
+ /* Update test/units/TEST-87-AUX-UTILS-VM.sh when logs below are changed. */
174
176
log_unit_debug (j -> unit ,
175
177
"Looking at job %s/%s conflicted_by=%s" ,
176
178
j -> unit -> id , job_type_to_string (j -> type ),
@@ -216,17 +218,18 @@ static int delete_one_unmergeable_job(Transaction *tr, Job *job) {
216
218
return - EINVAL ;
217
219
}
218
220
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 ) {
220
222
Job * j ;
221
223
int r ;
222
224
223
225
assert (tr );
224
226
225
- /* First step, check whether any of the jobs for one specific
226
- * task conflict. If so, try to drop one of them. */
227
227
HASHMAP_FOREACH (j , tr -> jobs ) {
228
228
JobType t ;
229
229
230
+ if (job_matters_to_anchor (j ) != matters_to_anchor )
231
+ continue ;
232
+
230
233
t = j -> type ;
231
234
LIST_FOREACH (transaction , k , j -> transaction_next ) {
232
235
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) {
253
256
}
254
257
}
255
258
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. */
257
279
HASHMAP_FOREACH (j , tr -> jobs ) {
258
280
JobType t = j -> type ;
259
281
0 commit comments