[systemd-commits] 6 commits - src/cryptsetup-generator.c src/device.c src/load-dropin.c src/manager.c src/path.c src/path.h src/unit.c src/unit.h TODO
Lennart Poettering
lennart at kemper.freedesktop.org
Mon Nov 15 09:26:46 PST 2010
TODO | 10 ++--
src/cryptsetup-generator.c | 6 +-
src/device.c | 1
src/load-dropin.c | 95 +++++++++++++++++++++++++++------------------
src/manager.c | 19 ++++++---
src/path.c | 53 ++++++++++++++++++-------
src/path.h | 1
src/unit.c | 9 ----
src/unit.h | 5 --
9 files changed, 118 insertions(+), 81 deletions(-)
New commits:
commit 8c4dd542afde23d21d736b24b5ab66c25ab091e8
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Nov 15 18:26:37 2010 +0100
units: get rid of no_requires unit flag, and make crypto disks require cryptsetup service
diff --git a/src/cryptsetup-generator.c b/src/cryptsetup-generator.c
index b8db0d5..a2b398d 100644
--- a/src/cryptsetup-generator.c
+++ b/src/cryptsetup-generator.c
@@ -163,7 +163,7 @@ static int create_disk(
to = NULL;
e = unit_name_escape(name);
- if (asprintf(&to, "%s/dev-mapper-%s.device.wants/%s", arg_dest, e, n) < 0) {
+ if (asprintf(&to, "%s/dev-mapper-%s.device.requires/%s", arg_dest, e, n) < 0) {
r = -ENOMEM;
goto fail;
}
diff --git a/src/device.c b/src/device.c
index 7cb4ff6..5c18d99 100644
--- a/src/device.c
+++ b/src/device.c
@@ -562,7 +562,6 @@ DEFINE_STRING_TABLE_LOOKUP(device_state, DeviceState);
const UnitVTable device_vtable = {
.suffix = ".device",
- .no_requires = true,
.no_instances = true,
.no_snapshots = true,
.no_isolate = true,
diff --git a/src/unit.c b/src/unit.c
index b3a8210..edc6364 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -1456,15 +1456,6 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
if (u == other)
return 0;
- if (UNIT_VTABLE(u)->no_requires &&
- (d == UNIT_REQUIRES ||
- d == UNIT_REQUIRES_OVERRIDABLE ||
- d == UNIT_REQUISITE ||
- d == UNIT_REQUISITE_OVERRIDABLE ||
- d == UNIT_BIND_TO)) {
- return -EINVAL;
- }
-
if ((r = set_ensure_allocated(&u->meta.dependencies[d], trivial_hash_func, trivial_compare_func)) < 0)
return r;
diff --git a/src/unit.h b/src/unit.h
index b260dd5..fbe88c2 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -353,11 +353,6 @@ struct UnitVTable {
/* Can units of this type have multiple names? */
bool no_alias:1;
- /* If true units of this types can never have "Requires"
- * dependencies, because state changes can only be observed,
- * not triggered */
- bool no_requires:1;
-
/* Instances make no sense for this type */
bool no_instances:1;
commit 99f08d14a7e4210bdb97b8c9d0752ec318ecca30
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Nov 15 04:24:04 2010 +0100
load-dropin: add support for .requires directories
diff --git a/src/load-dropin.c b/src/load-dropin.c
index eef3e6a..d30865c 100644
--- a/src/load-dropin.c
+++ b/src/load-dropin.c
@@ -28,11 +28,14 @@
#include "strv.h"
#include "unit-name.h"
-static int iterate_dir(Unit *u, const char *path) {
+static int iterate_dir(Unit *u, const char *path, UnitDependency dependency) {
DIR *d;
struct dirent *de;
int r;
+ assert(u);
+ assert(path);
+
if (!(d = opendir(path))) {
if (errno == ENOENT)
@@ -52,7 +55,7 @@ static int iterate_dir(Unit *u, const char *path) {
goto finish;
}
- r = unit_add_dependency_by_name(u, UNIT_WANTS, de->d_name, f, true);
+ r = unit_add_dependency_by_name(u, dependency, de->d_name, f, true);
free(f);
if (r < 0)
@@ -66,58 +69,74 @@ finish:
return r;
}
-int unit_load_dropin(Unit *u) {
- Iterator i;
+static int process_dir(Unit *u, const char *unit_path, const char *name, const char *suffix, UnitDependency dependency) {
int r;
- char *t;
+ char *path;
assert(u);
+ assert(unit_path);
+ assert(name);
+ assert(suffix);
- /* Load dependencies from supplementary drop-in directories */
+ if (asprintf(&path, "%s/%s%s", unit_path, name, suffix) < 0)
+ return -ENOMEM;
- SET_FOREACH(t, u->meta.names, i) {
- char *path;
- char **p;
+ if (u->meta.manager->unit_path_cache &&
+ !set_get(u->meta.manager->unit_path_cache, path))
+ r = 0;
+ else
+ r = iterate_dir(u, path, dependency);
+ free(path);
- STRV_FOREACH(p, u->meta.manager->lookup_paths.unit_path) {
+ if (r < 0)
+ return r;
- if (asprintf(&path, "%s/%s.wants", *p, t) < 0)
- return -ENOMEM;
+ if (u->meta.instance) {
+ char *template;
+ /* Also try the template dir */
- if (u->meta.manager->unit_path_cache &&
- !set_get(u->meta.manager->unit_path_cache, path))
- r = 0;
- else
- r = iterate_dir(u, path);
- free(path);
+ if (!(template = unit_name_template(name)))
+ return -ENOMEM;
- if (r < 0)
- return r;
+ r = asprintf(&path, "%s/%s%s", unit_path, template, suffix);
+ free(template);
- if (u->meta.instance) {
- char *template;
- /* Also try the template dir */
+ if (r < 0)
+ return -ENOMEM;
- if (!(template = unit_name_template(t)))
- return -ENOMEM;
+ if (u->meta.manager->unit_path_cache &&
+ !set_get(u->meta.manager->unit_path_cache, path))
+ r = 0;
+ else
+ r = iterate_dir(u, path, dependency);
+ free(path);
- r = asprintf(&path, "%s/%s.wants", *p, template);
- free(template);
+ if (r < 0)
+ return r;
+ }
- if (r < 0)
- return -ENOMEM;
+ return 0;
+}
- if (u->meta.manager->unit_path_cache &&
- !set_get(u->meta.manager->unit_path_cache, path))
- r = 0;
- else
- r = iterate_dir(u, path);
- free(path);
+int unit_load_dropin(Unit *u) {
+ Iterator i;
+ char *t;
+
+ assert(u);
+
+ /* Load dependencies from supplementary drop-in directories */
- if (r < 0)
- return r;
- }
+ SET_FOREACH(t, u->meta.names, i) {
+ char **p;
+
+ STRV_FOREACH(p, u->meta.manager->lookup_paths.unit_path) {
+ int r;
+ if ((r = process_dir(u, *p, t, ".wants", UNIT_WANTS)) < 0)
+ return r;
+
+ if ((r = process_dir(u, *p, t, ".requires", UNIT_REQUIRES)) < 0)
+ return r;
}
}
commit 49d50c55bb78849f25bdf46fa76da5a6bdc5571f
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Nov 15 04:11:42 2010 +0100
cryptsetup: bind cryptsetup service to both source and destination device
diff --git a/TODO b/TODO
index 770ac41..7b41702 100644
--- a/TODO
+++ b/TODO
@@ -82,6 +82,8 @@
* declare /etc/os-release cross-distro standard
+* add ConditionDirectoryNotEmpty=
+
Pre v12:
* fix hotplug transactions
@@ -96,6 +98,8 @@ External:
* pam_securetty should honour console=
+* sysctl should support sysctl.conf.d directory
+
* procps, psmisc, sysvinit-tools, hostname â util-linux-ng
https://bugzilla.redhat.com/show_bug.cgi?id=614245 -- plymouth
diff --git a/src/cryptsetup-generator.c b/src/cryptsetup-generator.c
index 3c3b99d..b8db0d5 100644
--- a/src/cryptsetup-generator.c
+++ b/src/cryptsetup-generator.c
@@ -100,9 +100,9 @@ static int create_disk(
"[Unit]\n"
"Description=Cryptography Setup for %%f\n"
"DefaultDependencies=no\n"
- "BindTo=%s\n"
+ "BindTo=%s dev-mapper-%%i.device\n"
"After=systemd-readahead-collect.service systemd-readahead-replay.service %s\n"
- "Before=dev-mapper-%%i.device shutdown.target\n",
+ "Before=dev-mapper-%%i.device shutdown.target local-fs.target\n",
d, d);
if (password && (streq(password, "/dev/urandom") ||
commit 9b3d90907461b6328cb7ff7fe8160d8d409f2b03
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Nov 15 03:44:11 2010 +0100
manager: consider jobs already installed as redundant when reducing new transactions
diff --git a/TODO b/TODO
index 4fafcad..770ac41 100644
--- a/TODO
+++ b/TODO
@@ -84,8 +84,6 @@
Pre v12:
-* fsck-root.service/start gets queued twice
-
* fix hotplug transactions
External:
diff --git a/src/manager.c b/src/manager.c
index 32cd642..a39427b 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -907,7 +907,7 @@ static void transaction_drop_redundant(Manager *m) {
LIST_FOREACH(transaction, k, j) {
if (!job_is_anchor(k) &&
- job_type_is_redundant(k->type, unit_active_state(k->unit)))
+ (j->installed || job_type_is_redundant(k->type, unit_active_state(k->unit))))
continue;
changes_something = true;
@@ -917,7 +917,7 @@ static void transaction_drop_redundant(Manager *m) {
if (changes_something)
continue;
- log_debug("Found redundant job %s/%s, dropping.", j->unit->meta.id, job_type_to_string(j->type));
+ /* log_debug("Found redundant job %s/%s, dropping.", j->unit->meta.id, job_type_to_string(j->type)); */
transaction_delete_job(m, j, false);
again = true;
break;
@@ -1069,10 +1069,15 @@ static void transaction_collect_garbage(Manager *m) {
again = false;
HASHMAP_FOREACH(j, m->transaction_jobs, i) {
- if (j->object_list)
+ if (j->object_list) {
+ /* log_debug("Keeping job %s/%s because of %s/%s", */
+ /* j->unit->meta.id, job_type_to_string(j->type), */
+ /* j->object_list->subject ? j->object_list->subject->unit->meta.id : "root", */
+ /* j->object_list->subject ? job_type_to_string(j->object_list->subject->type) : "root"); */
continue;
+ }
- log_debug("Garbage collecting job %s/%s", j->unit->meta.id, job_type_to_string(j->type));
+ /* log_debug("Garbage collecting job %s/%s", j->unit->meta.id, job_type_to_string(j->type)); */
transaction_delete_job(m, j, true);
again = true;
break;
@@ -1184,8 +1189,10 @@ static int transaction_apply(Manager *m) {
}
while ((j = hashmap_steal_first(m->transaction_jobs))) {
- if (j->installed)
+ if (j->installed) {
+ /* log_debug("Skipping already installed job %s/%s as %u", j->unit->meta.id, job_type_to_string(j->type), (unsigned) j->id); */
continue;
+ }
if (j->unit->meta.job)
job_free(j->unit->meta.job);
@@ -1352,7 +1359,7 @@ static Job* transaction_add_one_job(Manager *m, JobType type, Unit *unit, bool o
if (is_new)
*is_new = true;
- log_debug("Added job %s/%s to transaction.", unit->meta.id, job_type_to_string(type));
+ /* log_debug("Added job %s/%s to transaction.", unit->meta.id, job_type_to_string(type)); */
return j;
}
commit 672028dc4e587d510a5fc7f6cdf8038d779b4560
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Nov 15 00:49:21 2010 +0100
path: avoid immediate restarting of units triggered by paths if nothing actually changed on disk
diff --git a/TODO b/TODO
index f68e6de..4fafcad 100644
--- a/TODO
+++ b/TODO
@@ -88,8 +88,6 @@ Pre v12:
* fix hotplug transactions
-* plymouth agent start loop
-
External:
* patch kernel for xattr support in /dev, /proc/, /sys and /sys/fs/cgroup.
diff --git a/src/path.c b/src/path.c
index 3e28569..f4a0a28 100644
--- a/src/path.c
+++ b/src/path.c
@@ -267,7 +267,8 @@ static void path_set_state(Path *p, PathState state) {
old_state = p->state;
p->state = state;
- if (state != PATH_WAITING)
+ if (state != PATH_WAITING &&
+ (state != PATH_RUNNING || p->inotify_triggered))
path_unwatch(p);
if (state != old_state)
@@ -279,7 +280,7 @@ static void path_set_state(Path *p, PathState state) {
unit_notify(UNIT(p), state_translation_table[old_state], state_translation_table[state]);
}
-static void path_enter_waiting(Path *p, bool initial);
+static void path_enter_waiting(Path *p, bool initial, bool recheck);
static int path_coldplug(Unit *u) {
Path *p = PATH(u);
@@ -291,7 +292,7 @@ static int path_coldplug(Unit *u) {
if (p->deserialized_state == PATH_WAITING ||
p->deserialized_state == PATH_RUNNING)
- path_enter_waiting(p, true);
+ path_enter_waiting(p, true, true);
else
path_set_state(p, p->deserialized_state);
}
@@ -322,6 +323,11 @@ static void path_enter_running(Path *p) {
if ((r = manager_add_job(p->meta.manager, JOB_START, p->unit, JOB_REPLACE, true, &error, NULL)) < 0)
goto fail;
+ p->inotify_triggered = false;
+
+ if ((r = path_watch(p)) < 0)
+ goto fail;
+
path_set_state(p, PATH_RUNNING);
return;
@@ -333,11 +339,14 @@ fail:
}
-static void path_enter_waiting(Path *p, bool initial) {
+static void path_enter_waiting(Path *p, bool initial, bool recheck) {
PathSpec *s;
int r;
bool good = false;
+ if (!recheck)
+ goto waiting;
+
LIST_FOREACH(spec, s, p->specs) {
switch (s->type) {
@@ -372,6 +381,7 @@ static void path_enter_waiting(Path *p, bool initial) {
return;
}
+waiting:
if ((r = path_watch(p)) < 0)
goto fail;
@@ -393,7 +403,7 @@ static int path_start(Unit *u) {
return -ENOENT;
p->failure = false;
- path_enter_waiting(p, true);
+ path_enter_waiting(p, true, true);
return 0;
}
@@ -460,11 +470,13 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
uint8_t *buf = NULL;
struct inotify_event *e;
PathSpec *s;
+ bool changed;
assert(p);
assert(fd >= 0);
- if (p->state != PATH_WAITING)
+ if (p->state != PATH_WAITING &&
+ p->state != PATH_RUNNING)
return;
log_debug("inotify wakeup on %s.", u->meta.id);
@@ -498,15 +510,19 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
goto fail;
}
+ /* If we are already running, then remember that one event was
+ * dispatched so that we restart the service only if something
+ * actually changed on disk */
+ p->inotify_triggered = true;
+
e = (struct inotify_event*) buf;
+ changed = false;
while (k > 0) {
size_t step;
if (s->type == PATH_CHANGED && s->primary_wd == e->wd)
- path_enter_running(p);
- else
- path_enter_waiting(p, false);
+ changed = true;
step = sizeof(struct inotify_event) + e->len;
assert(step <= (size_t) k);
@@ -515,6 +531,11 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
k -= step;
}
+ if (changed)
+ path_enter_running(p);
+ else
+ path_enter_waiting(p, false, true);
+
free(buf);
return;
@@ -558,7 +579,11 @@ void path_unit_notify(Unit *u, UnitActiveState new_state) {
if (p->state == PATH_RUNNING && new_state == UNIT_INACTIVE) {
log_debug("%s got notified about unit deactivation.", p->meta.id);
- path_enter_waiting(p, false);
+
+ /* Hmm, so inotify was triggered since the
+ * last activation, so I guess we need to
+ * recheck what is going on. */
+ path_enter_waiting(p, false, p->inotify_triggered);
}
}
diff --git a/src/path.h b/src/path.h
index ea2331c..0dff120 100644
--- a/src/path.h
+++ b/src/path.h
@@ -69,6 +69,7 @@ struct Path {
PathState state, deserialized_state;
bool failure;
+ bool inotify_triggered;
};
void path_unit_notify(Unit *u, UnitActiveState new_state);
commit 782195a3c31a79428874a32e0264c0aa97a664f7
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Nov 15 00:47:29 2010 +0100
path: always look for IN_ATTRIB since deletion is signalled that way
diff --git a/TODO b/TODO
index 645b075..f68e6de 100644
--- a/TODO
+++ b/TODO
@@ -80,7 +80,7 @@
* automatically determine TERM= based on tty name. (TERM=linux vs. TERM=vt100-nav)
-* declare /etc/system-release cross-distro standard
+* declare /etc/os-release cross-distro standard
Pre v12:
diff --git a/src/path.c b/src/path.c
index f62157e..3e28569 100644
--- a/src/path.c
+++ b/src/path.c
@@ -181,9 +181,9 @@ static void path_unwatch_one(Path *p, PathSpec *s) {
static int path_watch_one(Path *p, PathSpec *s) {
static const int flags_table[_PATH_TYPE_MAX] = {
- [PATH_EXISTS] = IN_DELETE_SELF|IN_MOVE_SELF,
+ [PATH_EXISTS] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB,
[PATH_CHANGED] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_MOVED_FROM|IN_MOVED_TO,
- [PATH_DIRECTORY_NOT_EMPTY] = IN_DELETE_SELF|IN_MOVE_SELF|IN_CREATE|IN_MOVED_TO
+ [PATH_DIRECTORY_NOT_EMPTY] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB|IN_CREATE|IN_MOVED_TO
};
bool exists = false;
@@ -221,9 +221,9 @@ static int path_watch_one(Path *p, PathSpec *s) {
*slash = 0;
- flags = IN_DELETE_SELF|IN_MOVE_SELF;
+ flags = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB;
if (!exists)
- flags |= IN_CREATE | IN_MOVED_TO | IN_ATTRIB;
+ flags |= IN_CREATE | IN_MOVED_TO;
if (inotify_add_watch(s->inotify_fd, k, flags) >= 0)
exists = true;
More information about the systemd-commits
mailing list