3620ae5
From 6f202edb2c2e340523c6c0f2c0a93690eaab7a68 Mon Sep 17 00:00:00 2001
3620ae5
From: Adam Williamson <awilliam@redhat.com>
3620ae5
Date: Tue, 18 Feb 2020 08:44:34 -0800
3620ae5
Subject: [PATCH] Revert "job: Don't mark as redundant if deps are relevant"
3620ae5
3620ae5
This reverts commit 097537f07a2fab3cb73aef7bc59f2a66aa93f533. It
3620ae5
causes https://bugzilla.redhat.com/show_bug.cgi?id=1803293 .
3620ae5
---
3620ae5
 src/core/job.c         | 51 ++++++------------------------------------
3620ae5
 src/core/job.h         |  3 +--
3620ae5
 src/core/transaction.c |  8 +++----
3620ae5
 3 files changed, 12 insertions(+), 50 deletions(-)
3620ae5
3620ae5
diff --git a/src/core/job.c b/src/core/job.c
3620ae5
index 5982404cf0..5048a5093e 100644
3620ae5
--- a/src/core/job.c
3620ae5
+++ b/src/core/job.c
3620ae5
@@ -383,62 +383,25 @@ JobType job_type_lookup_merge(JobType a, JobType b) {
3620ae5
         return job_merging_table[(a - 1) * a / 2 + b];
3620ae5
 }
3620ae5
 
3620ae5
-bool job_later_link_matters(Job *j, JobType type, unsigned generation) {
3620ae5
-        JobDependency *l;
3620ae5
-
3620ae5
-        assert(j);
3620ae5
-
3620ae5
-        j->generation = generation;
3620ae5
-
3620ae5
-        LIST_FOREACH(subject, l, j->subject_list) {
3620ae5
-                UnitActiveState state = _UNIT_ACTIVE_STATE_INVALID;
3620ae5
-
3620ae5
-                /* Have we seen this before? */
3620ae5
-                if (l->object->generation == generation)
3620ae5
-                        continue;
3620ae5
-
3620ae5
-                state = unit_active_state(l->object->unit);
3620ae5
-                switch (type) {
3620ae5
-
3620ae5
-                case JOB_START:
3620ae5
-                        return IN_SET(state, UNIT_INACTIVE, UNIT_FAILED) ||
3620ae5
-                               job_later_link_matters(l->object, type, generation);
3620ae5
-
3620ae5
-                case JOB_STOP:
3620ae5
-                        return IN_SET(state, UNIT_ACTIVE, UNIT_RELOADING) ||
3620ae5
-                               job_later_link_matters(l->object, type, generation);
3620ae5
-
3620ae5
-                default:
3620ae5
-                        assert_not_reached("Invalid job type");
3620ae5
-                }
3620ae5
-        }
3620ae5
-
3620ae5
-        return false;
3620ae5
-}
3620ae5
-
3620ae5
-bool job_is_redundant(Job *j, unsigned generation) {
3620ae5
-
3620ae5
-        assert(j);
3620ae5
-
3620ae5
-        UnitActiveState state = unit_active_state(j->unit);
3620ae5
-        switch (j->type) {
3620ae5
+bool job_type_is_redundant(JobType a, UnitActiveState b) {
3620ae5
+        switch (a) {
3620ae5
 
3620ae5
         case JOB_START:
3620ae5
-                return IN_SET(state, UNIT_ACTIVE, UNIT_RELOADING) && !job_later_link_matters(j, JOB_START, generation);
3620ae5
+                return IN_SET(b, UNIT_ACTIVE, UNIT_RELOADING);
3620ae5
 
3620ae5
         case JOB_STOP:
3620ae5
-                return IN_SET(state, UNIT_INACTIVE, UNIT_FAILED) && !job_later_link_matters(j, JOB_STOP, generation);
3620ae5
+                return IN_SET(b, UNIT_INACTIVE, UNIT_FAILED);
3620ae5
 
3620ae5
         case JOB_VERIFY_ACTIVE:
3620ae5
-                return IN_SET(state, UNIT_ACTIVE, UNIT_RELOADING);
3620ae5
+                return IN_SET(b, UNIT_ACTIVE, UNIT_RELOADING);
3620ae5
 
3620ae5
         case JOB_RELOAD:
3620ae5
                 return
3620ae5
-                        state == UNIT_RELOADING;
3620ae5
+                        b == UNIT_RELOADING;
3620ae5
 
3620ae5
         case JOB_RESTART:
3620ae5
                 return
3620ae5
-                        state == UNIT_ACTIVATING;
3620ae5
+                        b == UNIT_ACTIVATING;
3620ae5
 
3620ae5
         case JOB_NOP:
3620ae5
                 return true;
3620ae5
diff --git a/src/core/job.h b/src/core/job.h
3620ae5
index 02b057ee06..03ad640618 100644
3620ae5
--- a/src/core/job.h
3620ae5
+++ b/src/core/job.h
3620ae5
@@ -196,8 +196,7 @@ _pure_ static inline bool job_type_is_superset(JobType a, JobType b) {
3620ae5
         return a == job_type_lookup_merge(a, b);
3620ae5
 }
3620ae5
 
3620ae5
-bool job_later_link_matters(Job *j, JobType type, unsigned generation);
3620ae5
-bool job_is_redundant(Job *j, unsigned generation);
3620ae5
+bool job_type_is_redundant(JobType a, UnitActiveState b) _pure_;
3620ae5
 
3620ae5
 /* Collapses a state-dependent job type into a simpler type by observing
3620ae5
  * the state of the unit which it is going to be applied to. */
3620ae5
diff --git a/src/core/transaction.c b/src/core/transaction.c
3620ae5
index 8d67f9ce1a..a0ea0f0489 100644
3620ae5
--- a/src/core/transaction.c
3620ae5
+++ b/src/core/transaction.c
3620ae5
@@ -279,7 +279,7 @@ static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) {
3620ae5
         return 0;
3620ae5
 }
3620ae5
 
3620ae5
-static void transaction_drop_redundant(Transaction *tr, unsigned generation) {
3620ae5
+static void transaction_drop_redundant(Transaction *tr) {
3620ae5
         bool again;
3620ae5
 
3620ae5
         /* Goes through the transaction and removes all jobs of the units whose jobs are all noops. If not
3620ae5
@@ -299,7 +299,7 @@ static void transaction_drop_redundant(Transaction *tr, unsigned generation) {
3620ae5
 
3620ae5
                         LIST_FOREACH(transaction, k, j)
3620ae5
                                 if (tr->anchor_job == k ||
3620ae5
-                                    !job_is_redundant(k, generation) ||
3620ae5
+                                    !job_type_is_redundant(k->type, unit_active_state(k->unit)) ||
3620ae5
                                     (k->unit->job && job_type_is_conflicting(k->type, k->unit->job->type))) {
3620ae5
                                         keep = true;
3620ae5
                                         break;
3620ae5
@@ -730,7 +730,7 @@ int transaction_activate(
3620ae5
                 transaction_minimize_impact(tr);
3620ae5
 
3620ae5
         /* Third step: Drop redundant jobs */
3620ae5
-        transaction_drop_redundant(tr, generation++);
3620ae5
+        transaction_drop_redundant(tr);
3620ae5
 
3620ae5
         for (;;) {
3620ae5
                 /* Fourth step: Let's remove unneeded jobs that might
3620ae5
@@ -772,7 +772,7 @@ int transaction_activate(
3620ae5
         }
3620ae5
 
3620ae5
         /* Eights step: Drop redundant jobs again, if the merging now allows us to drop more. */
3620ae5
-        transaction_drop_redundant(tr, generation++);
3620ae5
+        transaction_drop_redundant(tr);
3620ae5
 
3620ae5
         /* Ninth step: check whether we can actually apply this */
3620ae5
         r = transaction_is_destructive(tr, mode, e);
3620ae5
-- 
3620ae5
2.25.0
3620ae5