[systemd-commits] 3 commits - Makefile.am src/manager.c src/test-engine.c test2/a.service test2/b.service test2/c.service test2/d.service test2/e.service test2/f.service test2/g.service test2/h.service

Lennart Poettering lennart at kemper.freedesktop.org
Wed Jun 2 18:01:36 PDT 2010


 Makefile.am       |    2 +-
 src/manager.c     |   34 ++++++++++++++++++++++------------
 src/test-engine.c |   14 +++++++-------
 test2/a.service   |    5 ++++-
 test2/b.service   |    5 ++++-
 test2/c.service   |    5 ++++-
 test2/d.service   |    5 ++++-
 test2/e.service   |    5 ++++-
 test2/f.service   |    5 ++++-
 test2/g.service   |    5 ++++-
 test2/h.service   |    5 ++++-
 11 files changed, 62 insertions(+), 28 deletions(-)

New commits:
commit 35374c804d252b949c4bba7604fcf3430013595e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jun 3 03:01:29 2010 +0200

    test: update test-engine.c to work again

diff --git a/src/test-engine.c b/src/test-engine.c
index 27e16f3..eb17f58 100644
--- a/src/test-engine.c
+++ b/src/test-engine.c
@@ -36,9 +36,9 @@ int main(int argc, char *argv[]) {
         assert_se(manager_new(MANAGER_INIT, false, &m) >= 0);
 
         printf("Load1:\n");
-        assert_se(manager_load_unit(m, "a.service", NULL, &a) == 0);
-        assert_se(manager_load_unit(m, "b.service", NULL, &b) == 0);
-        assert_se(manager_load_unit(m, "c.service", NULL, &c) == 0);
+        assert_se(manager_load_unit(m, "a.service", NULL, &a) >= 0);
+        assert_se(manager_load_unit(m, "b.service", NULL, &b) >= 0);
+        assert_se(manager_load_unit(m, "c.service", NULL, &c) >= 0);
         manager_dump_units(m, stdout, "\t");
 
         printf("Test1: (Trivial)\n");
@@ -47,8 +47,8 @@ int main(int argc, char *argv[]) {
 
         printf("Load2:\n");
         manager_clear_jobs(m);
-        assert_se(manager_load_unit(m, "d.service", NULL, &d) == 0);
-        assert_se(manager_load_unit(m, "e.service", NULL, &e) == 0);
+        assert_se(manager_load_unit(m, "d.service", NULL, &d) >= 0);
+        assert_se(manager_load_unit(m, "e.service", NULL, &e) >= 0);
         manager_dump_units(m, stdout, "\t");
 
         printf("Test2: (Cyclic Order, Unfixable)\n");
@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
         manager_dump_jobs(m, stdout, "\t");
 
         printf("Load3:\n");
-        assert_se(manager_load_unit(m, "g.service", NULL, &g) == 0);
+        assert_se(manager_load_unit(m, "g.service", NULL, &g) >= 0);
         manager_dump_units(m, stdout, "\t");
 
         printf("Test5: (Colliding transaction, fail)\n");
@@ -86,7 +86,7 @@ int main(int argc, char *argv[]) {
         manager_dump_jobs(m, stdout, "\t");
 
         printf("Load4:\n");
-        assert_se(manager_load_unit(m, "h.service", NULL, &h) == 0);
+        assert_se(manager_load_unit(m, "h.service", NULL, &h) >= 0);
         manager_dump_units(m, stdout, "\t");
 
         printf("Test10: (Unmeargable job type of auxiliary job, fail)\n");
diff --git a/test2/a.service b/test2/a.service
index 4ddb8b4..4168d2d 100644
--- a/test2/a.service
+++ b/test2/a.service
@@ -1,4 +1,7 @@
-[Meta]
+[Unit]
 Description=A
 Requires=b.service
 Before=b.service
+
+[Service]
+ExecStart=/bin/true
diff --git a/test2/b.service b/test2/b.service
index ca94607..e03bae3 100644
--- a/test2/b.service
+++ b/test2/b.service
@@ -1,3 +1,6 @@
-[Meta]
+[Unit]
 Description=B
 Wants=f.service
+
+[Service]
+ExecStart=/bin/true
diff --git a/test2/c.service b/test2/c.service
index 8800ff7..e2f60a8 100644
--- a/test2/c.service
+++ b/test2/c.service
@@ -1,3 +1,6 @@
-[Meta]
+[Unit]
 Description=C
 Requires=a.service
+
+[Service]
+ExecStart=/bin/true
diff --git a/test2/d.service b/test2/d.service
index 279c171..921fd2e 100644
--- a/test2/d.service
+++ b/test2/d.service
@@ -1,5 +1,8 @@
-[Meta]
+[Unit]
 Description=D:Cyclic
 After=b.service
 Before=a.service
 Requires=a.service
+
+[Service]
+ExecStart=/bin/true
diff --git a/test2/e.service b/test2/e.service
index 2e86e33..5ba98c7 100644
--- a/test2/e.service
+++ b/test2/e.service
@@ -1,5 +1,8 @@
-[Meta]
+[Unit]
 Description=E:Cyclic
 After=b.service
 Before=a.service
 Wants=a.service
+
+[Service]
+ExecStart=/bin/true
diff --git a/test2/f.service b/test2/f.service
index d0b30ef..7dde681 100644
--- a/test2/f.service
+++ b/test2/f.service
@@ -1,2 +1,5 @@
-[Meta]
+[Unit]
 Description=F
+
+[Service]
+ExecStart=/bin/true
diff --git a/test2/g.service b/test2/g.service
index e811e60..cbfa82a 100644
--- a/test2/g.service
+++ b/test2/g.service
@@ -1,3 +1,6 @@
-[Meta]
+[Unit]
 Description=G
 Conflicts=e.service
+
+[Service]
+ExecStart=/bin/true
diff --git a/test2/h.service b/test2/h.service
index 4b9ffa3..74a7751 100644
--- a/test2/h.service
+++ b/test2/h.service
@@ -1,3 +1,6 @@
-[Meta]
+[Unit]
 Description=H
 Wants=g.service
+
+[Service]
+ExecStart=/bin/true
commit e1d680ad556bc15b6e5821746a5fbc42a736aaf4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jun 3 03:01:12 2010 +0200

    tests: build the right tests

diff --git a/Makefile.am b/Makefile.am
index 2ab7995..b255b7a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -288,7 +288,7 @@ test_engine_LDADD = $(systemd_LDADD)
 
 test_job_type_SOURCES = \
 	$(COMMON_SOURCES) \
-	src/test-engine.c
+	src/test-job-type.c
 
 test_job_type_CPPFLAGS = $(systemd_CPPFLAGS)
 test_job_type_LDADD = $(systemd_LDADD)
commit 23e3c5880901f5d744f88d1c5cd5397b5640868d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jun 3 03:00:47 2010 +0200

    manager: when we sweep the tree when looking for ordering cycles, remember and reuse if we already decided a tree was loop free, to improve speed drastically

diff --git a/src/manager.c b/src/manager.c
index 933dd50..a71150d 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -964,20 +964,25 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned
         /* Does a recursive sweep through the ordering graph, looking
          * for a cycle. If we find cycle we try to break it. */
 
-        /* Did we find a cycle? */
-        if (j->marker && j->generation == generation) {
+        /* Have we seen this before? */
+        if (j->generation == generation) {
                 Job *k;
 
-                /* So, we already have been here. We have a
-                 * cycle. Let's try to break it. We go backwards in
-                 * our path and try to find a suitable job to
-                 * remove. We use the marker to find our way back,
-                 * since smart how we are we stored our way back in
-                 * there. */
+                /* If the marker is NULL we have been here already and
+                 * decided the job was loop-free from here. Hence
+                 * shortcut things and return right-away. */
+                if (!j->marker)
+                        return 0;
 
+                /* So, the marker is not NULL and we already have been
+                 * here. We have a cycle. Let's try to break it. We go
+                 * backwards in our path and try to find a suitable
+                 * job to remove. We use the marker to find our way
+                 * back, since smart how we are we stored our way back
+                 * in there. */
                 log_debug("Found ordering cycle on %s/%s", j->unit->meta.id, job_type_to_string(j->type));
 
-                for (k = from; k; k = (k->generation == generation ? k->marker : NULL)) {
+                for (k = from; k; k = ((k->generation == generation && k->marker != k) ? k->marker : NULL)) {
 
                         log_debug("Walked on cycle path to %s/%s", k->unit->meta.id, job_type_to_string(k->type));
 
@@ -1002,8 +1007,10 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned
         }
 
         /* Make the marker point to where we come from, so that we can
-         * find our way backwards if we want to break a cycle */
-        j->marker = from;
+         * find our way backwards if we want to break a cycle. We use
+         * a special marker for the beginning: we point to
+         * ourselves. */
+        j->marker = from ? from : j;
         j->generation = generation;
 
         /* We assume that the the dependencies are bidirectional, and
@@ -1035,6 +1042,7 @@ static int transaction_verify_order(Manager *m, unsigned *generation) {
         Job *j;
         int r;
         Iterator i;
+        unsigned g;
 
         assert(m);
         assert(generation);
@@ -1042,8 +1050,10 @@ static int transaction_verify_order(Manager *m, unsigned *generation) {
         /* Check if the ordering graph is cyclic. If it is, try to fix
          * that up by dropping one of the jobs. */
 
+        g = (*generation)++;
+
         HASHMAP_FOREACH(j, m->transaction_jobs, i)
-                if ((r = transaction_verify_order_one(m, j, NULL, (*generation)++)) < 0)
+                if ((r = transaction_verify_order_one(m, j, NULL, g)) < 0)
                         return r;
 
         return 0;


More information about the systemd-commits mailing list