From 75778e21dfeee51036d24501e39ea7398fabe502 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Thu, 19 Apr 2012 23:54:11 +0200 Subject: manager: split transaction.[ch] manager.c takes care of the main loop, unit management, signal handling, ... transaction.c computes transactions. After split: manager.c: 65 KB transaction.c: 40 KB --- src/core/transaction.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/core/transaction.h (limited to 'src/core/transaction.h') diff --git a/src/core/transaction.h b/src/core/transaction.h new file mode 100644 index 0000000000..d519ffb1f5 --- /dev/null +++ b/src/core/transaction.h @@ -0,0 +1,36 @@ +#ifndef footransactionhfoo +#define footransactionhfoo + +typedef struct Transaction Transaction; + +#include "unit.h" +#include "manager.h" +#include "job.h" +#include "hashmap.h" + +struct Transaction { + /* Jobs to be added */ + Hashmap *jobs; /* Unit object => Job object list 1:1 */ + JobDependency *anchor; +}; + +Transaction *transaction_new(void); +void transaction_free(Transaction *tr); + +int transaction_add_job_and_dependencies( + Transaction *tr, + JobType type, + Unit *unit, + Job *by, + bool matters, + bool override, + bool conflicts, + bool ignore_requirements, + bool ignore_order, + DBusError *e, + Job **_ret); +int transaction_activate(Transaction *tr, Manager *m, JobMode mode, DBusError *e); +int transaction_add_isolate_jobs(Transaction *tr, Manager *m); +void transaction_abort(Transaction *tr); + +#endif -- cgit v1.2.3-54-g00ecf From b94fbd30781d7533492cec65bf7d86fa19a1a074 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Fri, 20 Apr 2012 00:33:26 +0200 Subject: transaction: maintain anchor_job Track which job is the anchor in the transaction. --- src/core/manager.c | 7 +++---- src/core/transaction.c | 37 ++++++++++++++++++------------------- src/core/transaction.h | 4 ++-- 3 files changed, 23 insertions(+), 25 deletions(-) (limited to 'src/core/transaction.h') diff --git a/src/core/manager.c b/src/core/manager.c index f070295d88..636aaa364b 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -656,7 +656,6 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, DBusError *e, Job **_ret) { int r; - Job *ret; Transaction *tr; assert(m); @@ -682,7 +681,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove r = transaction_add_job_and_dependencies(tr, type, unit, NULL, true, override, false, mode == JOB_IGNORE_DEPENDENCIES || mode == JOB_IGNORE_REQUIREMENTS, - mode == JOB_IGNORE_DEPENDENCIES, e, &ret); + mode == JOB_IGNORE_DEPENDENCIES, e); if (r < 0) goto tr_abort; @@ -696,10 +695,10 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove if (r < 0) goto tr_abort; - log_debug("Enqueued job %s/%s as %u", unit->id, job_type_to_string(type), (unsigned) ret->id); + log_debug("Enqueued job %s/%s as %u", unit->id, job_type_to_string(type), (unsigned) tr->anchor_job->id); if (_ret) - *_ret = ret; + *_ret = tr->anchor_job; transaction_free(tr); return 0; diff --git a/src/core/transaction.c b/src/core/transaction.c index c00dd452eb..d7ecfdb446 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -834,8 +834,7 @@ int transaction_add_job_and_dependencies( bool conflicts, bool ignore_requirements, bool ignore_order, - DBusError *e, - Job **_ret) { + DBusError *e) { Job *ret; JobDependency *l; Iterator i; @@ -892,8 +891,11 @@ int transaction_add_job_and_dependencies( return -ENOMEM; /* If the link has no subject job, it's the anchor link. */ - if (!by) + if (!by) { LIST_PREPEND(JobDependency, subject, tr->anchor, l); + if (!tr->anchor_job) + tr->anchor_job = ret; + } if (is_new && !ignore_requirements) { Set *following; @@ -902,7 +904,7 @@ int transaction_add_job_and_dependencies( * add all dependencies of everybody following. */ if (unit_following_set(ret->unit, &following) > 0) { SET_FOREACH(dep, following, i) { - r = transaction_add_job_and_dependencies(tr, type, dep, ret, false, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, type, dep, ret, false, override, false, false, ignore_order, e); if (r < 0) { log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r)); @@ -917,7 +919,7 @@ int transaction_add_job_and_dependencies( /* Finally, recursively add in all dependencies. */ if (type == JOB_START || type == JOB_RELOAD_OR_START) { SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES], i) { - r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, override, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) goto fail; @@ -928,7 +930,7 @@ int transaction_add_job_and_dependencies( } SET_FOREACH(dep, ret->unit->dependencies[UNIT_BIND_TO], i) { - r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, override, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) goto fail; @@ -939,7 +941,7 @@ int transaction_add_job_and_dependencies( } SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES_OVERRIDABLE], i) { - r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, !override, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, !override, override, false, false, ignore_order, e); if (r < 0) { log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r)); @@ -949,7 +951,7 @@ int transaction_add_job_and_dependencies( } SET_FOREACH(dep, ret->unit->dependencies[UNIT_WANTS], i) { - r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, false, false, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, false, false, false, false, ignore_order, e); if (r < 0) { log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r)); @@ -959,7 +961,7 @@ int transaction_add_job_and_dependencies( } SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUISITE], i) { - r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, true, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, true, override, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) goto fail; @@ -970,7 +972,7 @@ int transaction_add_job_and_dependencies( } SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUISITE_OVERRIDABLE], i) { - r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, !override, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, !override, override, false, false, ignore_order, e); if (r < 0) { log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r)); @@ -980,7 +982,7 @@ int transaction_add_job_and_dependencies( } SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONFLICTS], i) { - r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, true, override, true, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, true, override, true, false, ignore_order, e); if (r < 0) { if (r != -EBADR) goto fail; @@ -991,7 +993,7 @@ int transaction_add_job_and_dependencies( } SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONFLICTED_BY], i) { - r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, false, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, false, override, false, false, ignore_order, e); if (r < 0) { log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r)); @@ -1005,7 +1007,7 @@ int transaction_add_job_and_dependencies( if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) { SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRED_BY], i) { - r = transaction_add_job_and_dependencies(tr, type, dep, ret, true, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, type, dep, ret, true, override, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) goto fail; @@ -1016,7 +1018,7 @@ int transaction_add_job_and_dependencies( } SET_FOREACH(dep, ret->unit->dependencies[UNIT_BOUND_BY], i) { - r = transaction_add_job_and_dependencies(tr, type, dep, ret, true, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, type, dep, ret, true, override, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) goto fail; @@ -1030,7 +1032,7 @@ int transaction_add_job_and_dependencies( if (type == JOB_RELOAD || type == JOB_RELOAD_OR_START) { SET_FOREACH(dep, ret->unit->dependencies[UNIT_PROPAGATE_RELOAD_TO], i) { - r = transaction_add_job_and_dependencies(tr, JOB_RELOAD, dep, ret, false, override, false, false, ignore_order, e, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_RELOAD, dep, ret, false, override, false, false, ignore_order, e); if (r < 0) { log_warning("Cannot add dependency reload job for unit %s, ignoring: %s", dep->id, bus_error(e, r)); @@ -1043,9 +1045,6 @@ int transaction_add_job_and_dependencies( /* JOB_VERIFY_STARTED, JOB_RELOAD require no dependency handling */ } - if (_ret) - *_ret = ret; - return 0; fail: @@ -1078,7 +1077,7 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) { if (hashmap_get(tr->jobs, u)) continue; - r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, NULL, true, false, false, false, false, NULL, NULL); + r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, NULL, true, false, false, false, false, NULL); if (r < 0) log_warning("Cannot add isolate job for unit %s, ignoring: %s", u->id, strerror(-r)); } diff --git a/src/core/transaction.h b/src/core/transaction.h index d519ffb1f5..4818cea38e 100644 --- a/src/core/transaction.h +++ b/src/core/transaction.h @@ -12,6 +12,7 @@ struct Transaction { /* Jobs to be added */ Hashmap *jobs; /* Unit object => Job object list 1:1 */ JobDependency *anchor; + Job *anchor_job; /* the job the user asked for */ }; Transaction *transaction_new(void); @@ -27,8 +28,7 @@ int transaction_add_job_and_dependencies( bool conflicts, bool ignore_requirements, bool ignore_order, - DBusError *e, - Job **_ret); + DBusError *e); int transaction_activate(Transaction *tr, Manager *m, JobMode mode, DBusError *e); int transaction_add_isolate_jobs(Transaction *tr, Manager *m); void transaction_abort(Transaction *tr); -- cgit v1.2.3-54-g00ecf From e6eda1f23efab618bb26e7015230d8552b401dc6 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Fri, 20 Apr 2012 02:11:14 +0200 Subject: transaction: remove the anchor link tr->anchor_job is sufficient. --- src/core/job.c | 12 ------------ src/core/job.h | 2 -- src/core/transaction.c | 31 ++++++++----------------------- src/core/transaction.h | 1 - 4 files changed, 8 insertions(+), 38 deletions(-) (limited to 'src/core/transaction.h') diff --git a/src/core/job.c b/src/core/job.c index 18ec823ebe..aa7cdbff2a 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -151,18 +151,6 @@ void job_dump(Job *j, FILE*f, const char *prefix) { prefix, yes_no(j->override)); } -bool job_is_anchor(Job *j) { - JobDependency *l; - - assert(j); - - LIST_FOREACH(object, l, j->object_list) - if (!l->subject) - return true; - - return false; -} - /* * Merging is commutative, so imagine the matrix as symmetric. We store only * its lower triangle to avoid duplication. We don't store the main diagonal, diff --git a/src/core/job.h b/src/core/job.h index c7cf58dbfe..4e0c7ca81e 100644 --- a/src/core/job.h +++ b/src/core/job.h @@ -144,8 +144,6 @@ void job_dump(Job *j, FILE*f, const char *prefix); JobDependency* job_dependency_new(Job *subject, Job *object, bool matters, bool conflicts); void job_dependency_free(JobDependency *l); -bool job_is_anchor(Job *j); - int job_merge(Job *j, Job *other); JobType job_type_lookup_merge(JobType a, JobType b); diff --git a/src/core/transaction.c b/src/core/transaction.c index ddb02c068a..39cfe54b0a 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -34,8 +34,6 @@ void transaction_abort(Transaction *tr) { transaction_delete_job(tr, j, true); assert(hashmap_isempty(tr->jobs)); - - assert(!tr->anchor); } static void transaction_find_jobs_that_matter_to_anchor(Job *j, unsigned generation) { @@ -287,7 +285,7 @@ static void transaction_drop_redundant(Transaction *tr) { LIST_FOREACH(transaction, k, j) { - if (!job_is_anchor(k) && + if (tr->anchor_job != k && (k->installed || job_type_is_redundant(k->type, unit_active_state(k->unit))) && (!k->unit->job || !job_type_is_conflicting(k->type, k->unit->job->type))) continue; @@ -626,8 +624,6 @@ static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) { log_debug("Installed new job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id); } - assert(!tr->anchor); - return 0; rollback: @@ -726,7 +722,6 @@ int transaction_activate(Transaction *tr, Manager *m, JobMode mode, DBusError *e } assert(hashmap_isempty(tr->jobs)); - assert(!tr->anchor); return 0; } @@ -778,12 +773,6 @@ static Job* transaction_add_one_job(Transaction *tr, JobType type, Unit *unit, b return j; } -static void transaction_job_dependency_free(Transaction *tr, JobDependency *l) { - if (!l->subject) - LIST_REMOVE(JobDependency, subject, tr->anchor, l); - job_dependency_free(l); -} - static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies) { assert(tr); assert(j); @@ -801,12 +790,12 @@ static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependen j->transaction_prev = j->transaction_next = NULL; while (j->subject_list) - transaction_job_dependency_free(tr, j->subject_list); + job_dependency_free(j->subject_list); while (j->object_list) { Job *other = j->object_list->matters ? j->object_list->subject : NULL; - transaction_job_dependency_free(tr, j->object_list); + job_dependency_free(j->object_list); if (other && delete_dependencies) { log_debug("Deleting job %s/%s as dependency of job %s/%s", @@ -829,7 +818,6 @@ int transaction_add_job_and_dependencies( bool ignore_order, DBusError *e) { Job *ret; - JobDependency *l; Iterator i; Unit *dep; int r; @@ -879,17 +867,14 @@ int transaction_add_job_and_dependencies( ret->ignore_order = ret->ignore_order || ignore_order; /* Then, add a link to the job. */ - l = job_dependency_new(by, ret, matters, conflicts); - if (!l) - return -ENOMEM; - - /* If the link has no subject job, it's the anchor link. */ - if (!by) { - LIST_PREPEND(JobDependency, subject, tr->anchor, l); + if (by) { + if (!job_dependency_new(by, ret, matters, conflicts)) + return -ENOMEM; + } else { + /* If the job has no parent job, it is the anchor job. */ assert(!tr->anchor_job); tr->anchor_job = ret; } - if (is_new && !ignore_requirements) { Set *following; diff --git a/src/core/transaction.h b/src/core/transaction.h index 4818cea38e..74d74616a3 100644 --- a/src/core/transaction.h +++ b/src/core/transaction.h @@ -11,7 +11,6 @@ typedef struct Transaction Transaction; struct Transaction { /* Jobs to be added */ Hashmap *jobs; /* Unit object => Job object list 1:1 */ - JobDependency *anchor; Job *anchor_job; /* the job the user asked for */ }; -- cgit v1.2.3-54-g00ecf From 7c0436b94c52915f2c39fe4a29616313378c3b78 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 22 Apr 2012 15:22:27 +0200 Subject: transaction: add missing emacs and license headers --- src/core/transaction.c | 21 +++++++++++++++++++++ src/core/transaction.h | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'src/core/transaction.h') diff --git a/src/core/transaction.c b/src/core/transaction.c index a2efcbcff4..91feab0398 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -1,3 +1,24 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + #include "transaction.h" #include "bus-errors.h" diff --git a/src/core/transaction.h b/src/core/transaction.h index 74d74616a3..67ace4da0b 100644 --- a/src/core/transaction.h +++ b/src/core/transaction.h @@ -1,6 +1,27 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + #ifndef footransactionhfoo #define footransactionhfoo +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + typedef struct Transaction Transaction; #include "unit.h" -- cgit v1.2.3-54-g00ecf