X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fautomount.c;h=d1379e091376a5ce11ee1a4d6466c0c5f75b6f45;hb=accdd018ede77ef1c057775396c18c73406cbcb4;hp=4a98540d8282346ea9d194998a6d833f44329abc;hpb=66870f90dec9b5bf4ad76f9757fafce703560a67;p=elogind.git diff --git a/src/core/automount.c b/src/core/automount.c index 4a98540d8..d1379e091 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -66,7 +66,7 @@ static void automount_init(Unit *u) { UNIT(a)->ignore_on_isolate = true; } -static void repeat_unmout(const char *path) { +static void repeat_unmount(const char *path) { assert(path); for (;;) { @@ -100,7 +100,7 @@ static void unmount_autofs(Automount *a) { if (a->where && (UNIT(a)->manager->exit_code != MANAGER_RELOAD && UNIT(a)->manager->exit_code != MANAGER_REEXECUTE)) - repeat_unmout(a->where); + repeat_unmount(a->where); } static void automount_done(Unit *u) { @@ -109,7 +109,6 @@ static void automount_done(Unit *u) { assert(a); unmount_autofs(a); - unit_ref_unset(&a->mount); free(a->where); a->where = NULL; @@ -118,42 +117,17 @@ static void automount_done(Unit *u) { a->tokens = NULL; } -int automount_add_one_mount_link(Automount *a, Mount *m) { +static int automount_add_mount_links(Automount *a) { + _cleanup_free_ char *parent = NULL; int r; assert(a); - assert(m); - - if (UNIT(a)->load_state != UNIT_LOADED || - UNIT(m)->load_state != UNIT_LOADED) - return 0; - - if (!path_startswith(a->where, m->where)) - return 0; - if (path_equal(a->where, m->where)) - return 0; - - r = unit_add_two_dependencies(UNIT(a), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true); + r = path_get_parent(a->where, &parent); if (r < 0) return r; - return 0; -} - -static int automount_add_mount_links(Automount *a) { - Unit *other; - int r; - - assert(a); - - LIST_FOREACH(units_by_type, other, UNIT(a)->manager->units_by_type[UNIT_MOUNT]) { - r = automount_add_one_mount_link(a, MOUNT(other)); - if (r < 0) - return r; - } - - return 0; + return unit_require_mounts_for(UNIT(a), parent); } static int automount_add_default_dependencies(Automount *a) { @@ -200,8 +174,8 @@ static int automount_verify(Automount *a) { } static int automount_load(Unit *u) { - int r; Automount *a = AUTOMOUNT(u); + int r; assert(u); assert(u->load_state == UNIT_STUB); @@ -222,17 +196,15 @@ static int automount_load(Unit *u) { path_kill_slashes(a->where); - r = automount_add_mount_links(a); + r = unit_load_related_unit(u, ".mount", &x); if (r < 0) return r; - r = unit_load_related_unit(u, ".mount", &x); + r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, x, true); if (r < 0) return r; - unit_ref_set(&a->mount, x); - - r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(a->mount), true); + r = automount_add_mount_links(a); if (r < 0) return r; @@ -578,7 +550,7 @@ fail: close_nointr_nofail(ioctl_fd); if (mounted) - repeat_unmout(a->where); + repeat_unmount(a->where); log_error_unit(UNIT(a)->id, "Failed to initialize automounter: %s", strerror(-r)); @@ -586,18 +558,17 @@ fail: } static void automount_enter_runnning(Automount *a) { - int r; - struct stat st; _cleanup_dbus_error_free_ DBusError error; + struct stat st; + int r; assert(a); - assert(UNIT_DEREF(a->mount)); dbus_error_init(&error); /* We don't take mount requests anymore if we are supposed to * shut down anyway */ - if (unit_pending_inactive(UNIT(a))) { + if (unit_stop_pending(UNIT(a))) { log_debug_unit(UNIT(a)->id, "Suppressing automount request on %s since unit stop is scheduled.", UNIT(a)->id); automount_send_ready(a, -EHOSTDOWN); @@ -616,11 +587,15 @@ static void automount_enter_runnning(Automount *a) { if (!S_ISDIR(st.st_mode) || st.st_dev != a->dev_id) log_info_unit(UNIT(a)->id, "%s's automount point already active?", UNIT(a)->id); - else if ((r = manager_add_job(UNIT(a)->manager, JOB_START, UNIT_DEREF(a->mount), JOB_REPLACE, true, &error, NULL)) < 0) { - log_warning_unit(UNIT(a)->id, - "%s failed to queue mount startup job: %s", - UNIT(a)->id, bus_error(&error, r)); - goto fail; + else { + r = manager_add_job(UNIT(a)->manager, JOB_START, UNIT_TRIGGER(UNIT(a)), + JOB_REPLACE, true, &error, NULL); + if (r < 0) { + log_warning_unit(UNIT(a)->id, + "%s failed to queue mount startup job: %s", + UNIT(a)->id, bus_error(&error, r)); + goto fail; + } } automount_set_state(a, AUTOMOUNT_RUNNING); @@ -643,7 +618,7 @@ static int automount_start(Unit *u) { return -EEXIST; } - if (UNIT_DEREF(a->mount)->load_state != UNIT_LOADED) + if (UNIT_TRIGGER(u)->load_state != UNIT_LOADED) return -ENOENT; a->result = AUTOMOUNT_SUCCESS; @@ -765,14 +740,12 @@ static const char *automount_sub_state_to_string(Unit *u) { } static bool automount_check_gc(Unit *u) { - Automount *a = AUTOMOUNT(u); - - assert(a); + assert(u); - if (!UNIT_DEREF(a->mount)) + if (!UNIT_TRIGGER(u)) return false; - return UNIT_VTABLE(UNIT_DEREF(a->mount))->check_gc(UNIT_DEREF(a->mount)); + return UNIT_VTABLE(UNIT_TRIGGER(u))->check_gc(UNIT_TRIGGER(u)); } static void automount_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {