Re: [systemd-devel] [PATCH v2] automount: add expire support
On Tue, Apr 21, 2015 at 08:45:30PM +0200, Lennart Poettering wrote: > On Tue, 14.04.15 22:01, Michael Olbrich (m.olbr...@pengutronix.de) wrote: > > I added some more logging (so that automount_dispatch_expire() can > never fail without this being logged) and applied it! > > I only gave this superficial testing though, please check if this all > still works fine for you now! Looks good. My test-cases work just fine. Michael -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0| Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917- | ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] [PATCH v2] automount: add expire support
On Tue, Apr 21, 2015 at 8:45 PM, Lennart Poettering wrote: > On Tue, 14.04.15 22:01, Michael Olbrich (m.olbr...@pengutronix.de) wrote: > > I added some more logging (so that automount_dispatch_expire() can > never fail without this being logged) and applied it! > > I only gave this superficial testing though, please check if this all > still works fine for you now! I added 120 seconds for the EFI FAT /boot mount: http://cgit.freedesktop.org/systemd/systemd/commit/?id=163ab2961268232e1cb49e990a8ccefe24b7649f $ journalctl -b -u boot.mount Apr 22 00:49:22 ank systemd[1]: Mounting EFI System Partition... Apr 22 00:49:22 ank systemd[1]: Mounted EFI System Partition. Apr 22 00:51:24 ank systemd[1]: Unmounting EFI System Partition... Apr 22 00:51:24 ank systemd[1]: Unmounted EFI System Partition. Apr 22 00:51:48 ank systemd[1]: Mounting EFI System Partition... Apr 22 00:51:48 ank systemd[1]: Mounted EFI System Partition. Apr 22 00:53:51 ank systemd[1]: Unmounting EFI System Partition... Apr 22 00:53:51 ank systemd[1]: Unmounted EFI System Partition. Michael, thanks a lot for adding that feature. Kay ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] [PATCH v2] automount: add expire support
On Tue, 14.04.15 22:01, Michael Olbrich (m.olbr...@pengutronix.de) wrote: I added some more logging (so that automount_dispatch_expire() can never fail without this being logged) and applied it! I only gave this superficial testing though, please check if this all still works fine for you now! Thanks! > --- > Changes in v2: > - addressed comments > - check every MAX(a->timeout_idle_usec/10, USEC_PER_SEC) instead of every >5 seconds > > man/systemd.automount.xml | 8 ++ > man/systemd.mount.xml | 9 ++ > src/core/automount.c | 221 > -- > src/core/automount.h | 6 +- > src/core/dbus-automount.c | 1 + > src/core/load-fragment-gperf.gperf.m4 | 1 + > src/core/mount.c | 20 +-- > src/fstab-generator/fstab-generator.c | 24 > 8 files changed, 262 insertions(+), 28 deletions(-) > > diff --git a/man/systemd.automount.xml b/man/systemd.automount.xml > index b5b5885cdff2..9561590c5c89 100644 > --- a/man/systemd.automount.xml > +++ b/man/systemd.automount.xml > @@ -135,6 +135,14 @@ > creating these directories. Takes an access mode in octal > notation. Defaults to 0755. > > + > +TimeoutIdleSec= > +Configures an idleness timeout. Once the mount has > been > +idle for the specified time, systemd will attempt to unmount. Takes a > +unit-less value in seconds, or a time span value such as "5min 20s". > +Pass 0 to disable the timeout logic. The timeout is disabled by > +default. > + > > > > diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml > index fcb9a4416104..e102d27ab762 100644 > --- a/man/systemd.mount.xml > +++ b/man/systemd.mount.xml > @@ -148,6 +148,15 @@ > > > > +x-systemd.idle-timeout= > + > +Configures the idleness timeout of the > +automount unit. See TimeoutIdleSec= in > + > systemd.automount5 > +for details. > + > + > + > x-systemd.device-timeout= > > Configure how long systemd should wait for a > diff --git a/src/core/automount.c b/src/core/automount.c > index ce484ff1cd16..1cf108524a80 100644 > --- a/src/core/automount.c > +++ b/src/core/automount.c > @@ -42,6 +42,7 @@ > #include "bus-error.h" > #include "formats-util.h" > #include "process-util.h" > +#include "async.h" > > static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = > { > [AUTOMOUNT_DEAD] = UNIT_INACTIVE, > @@ -50,6 +51,22 @@ static const UnitActiveState > state_translation_table[_AUTOMOUNT_STATE_MAX] = { > [AUTOMOUNT_FAILED] = UNIT_FAILED > }; > > +struct expire_data { > +int dev_autofs_fd; > +int ioctl_fd; > +}; > + > +static inline void expire_data_free(struct expire_data *data) { > +if (!data) > +return; > + > +safe_close(data->dev_autofs_fd); > +safe_close(data->ioctl_fd); > +free(data); > +} > + > +DEFINE_TRIVIAL_CLEANUP_FUNC(struct expire_data*, expire_data_free); > + > static int open_dev_autofs(Manager *m); > static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t > events, void *userdata); > > @@ -81,13 +98,16 @@ static void repeat_unmount(const char *path) { > } > } > > +static int automount_send_ready(Automount *a, Set *tokens, int status); > + > static void unmount_autofs(Automount *a) { > assert(a); > > if (a->pipe_fd < 0) > return; > > -automount_send_ready(a, -EHOSTDOWN); > +automount_send_ready(a, a->tokens, -EHOSTDOWN); > +automount_send_ready(a, a->expire_tokens, -EHOSTDOWN); > > a->pipe_event_source = sd_event_source_unref(a->pipe_event_source); > a->pipe_fd = safe_close(a->pipe_fd); > @@ -112,6 +132,10 @@ static void automount_done(Unit *u) { > > set_free(a->tokens); > a->tokens = NULL; > +set_free(a->expire_tokens); > +a->expire_tokens = NULL; > + > +a->expire_event_source = > sd_event_source_unref(a->expire_event_source); > } > > static int automount_add_mount_links(Automount *a) { > @@ -265,6 +289,7 @@ static int automount_coldplug(Unit *u, Hashmap > *deferred_work) { > } > > static void automount_dump(Unit *u, FILE *f, const char *prefix) { > +char time_string[FORMAT_TIMESPAN_MAX]; > Automount *a = AUTOMOUNT(u); > > assert(a); > @@ -273,11 +298,13 @@ static void automount_dump(Unit *u, FILE *f, const char > *prefix) { > "%sAutomount State: %s\n" > "%sResult: %s\n" > "%sWhere: %s\n" > -"%sDirectoryMode: %04o\n", > +"%sDirectoryMode: %04o\n" > +"%sTimeoutIdleUSec: %s\n", > prefix, automount_state_to_string(a->state), > prefix, automoun
[systemd-devel] [PATCH v2] automount: add expire support
--- Changes in v2: - addressed comments - check every MAX(a->timeout_idle_usec/10, USEC_PER_SEC) instead of every 5 seconds man/systemd.automount.xml | 8 ++ man/systemd.mount.xml | 9 ++ src/core/automount.c | 221 -- src/core/automount.h | 6 +- src/core/dbus-automount.c | 1 + src/core/load-fragment-gperf.gperf.m4 | 1 + src/core/mount.c | 20 +-- src/fstab-generator/fstab-generator.c | 24 8 files changed, 262 insertions(+), 28 deletions(-) diff --git a/man/systemd.automount.xml b/man/systemd.automount.xml index b5b5885cdff2..9561590c5c89 100644 --- a/man/systemd.automount.xml +++ b/man/systemd.automount.xml @@ -135,6 +135,14 @@ creating these directories. Takes an access mode in octal notation. Defaults to 0755. + +TimeoutIdleSec= +Configures an idleness timeout. Once the mount has been +idle for the specified time, systemd will attempt to unmount. Takes a +unit-less value in seconds, or a time span value such as "5min 20s". +Pass 0 to disable the timeout logic. The timeout is disabled by +default. + diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml index fcb9a4416104..e102d27ab762 100644 --- a/man/systemd.mount.xml +++ b/man/systemd.mount.xml @@ -148,6 +148,15 @@ +x-systemd.idle-timeout= + +Configures the idleness timeout of the +automount unit. See TimeoutIdleSec= in + systemd.automount5 +for details. + + + x-systemd.device-timeout= Configure how long systemd should wait for a diff --git a/src/core/automount.c b/src/core/automount.c index ce484ff1cd16..1cf108524a80 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -42,6 +42,7 @@ #include "bus-error.h" #include "formats-util.h" #include "process-util.h" +#include "async.h" static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = { [AUTOMOUNT_DEAD] = UNIT_INACTIVE, @@ -50,6 +51,22 @@ static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = { [AUTOMOUNT_FAILED] = UNIT_FAILED }; +struct expire_data { +int dev_autofs_fd; +int ioctl_fd; +}; + +static inline void expire_data_free(struct expire_data *data) { +if (!data) +return; + +safe_close(data->dev_autofs_fd); +safe_close(data->ioctl_fd); +free(data); +} + +DEFINE_TRIVIAL_CLEANUP_FUNC(struct expire_data*, expire_data_free); + static int open_dev_autofs(Manager *m); static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, void *userdata); @@ -81,13 +98,16 @@ static void repeat_unmount(const char *path) { } } +static int automount_send_ready(Automount *a, Set *tokens, int status); + static void unmount_autofs(Automount *a) { assert(a); if (a->pipe_fd < 0) return; -automount_send_ready(a, -EHOSTDOWN); +automount_send_ready(a, a->tokens, -EHOSTDOWN); +automount_send_ready(a, a->expire_tokens, -EHOSTDOWN); a->pipe_event_source = sd_event_source_unref(a->pipe_event_source); a->pipe_fd = safe_close(a->pipe_fd); @@ -112,6 +132,10 @@ static void automount_done(Unit *u) { set_free(a->tokens); a->tokens = NULL; +set_free(a->expire_tokens); +a->expire_tokens = NULL; + +a->expire_event_source = sd_event_source_unref(a->expire_event_source); } static int automount_add_mount_links(Automount *a) { @@ -265,6 +289,7 @@ static int automount_coldplug(Unit *u, Hashmap *deferred_work) { } static void automount_dump(Unit *u, FILE *f, const char *prefix) { +char time_string[FORMAT_TIMESPAN_MAX]; Automount *a = AUTOMOUNT(u); assert(a); @@ -273,11 +298,13 @@ static void automount_dump(Unit *u, FILE *f, const char *prefix) { "%sAutomount State: %s\n" "%sResult: %s\n" "%sWhere: %s\n" -"%sDirectoryMode: %04o\n", +"%sDirectoryMode: %04o\n" +"%sTimeoutIdleUSec: %s\n", prefix, automount_state_to_string(a->state), prefix, automount_result_to_string(a->result), prefix, a->where, -prefix, a->directory_mode); +prefix, a->directory_mode, +prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, a->timeout_idle_usec, USEC_PER_SEC)); } static void automount_enter_dead(Automount *a, AutomountResult f) { @@ -367,7 +394,7 @@ static int autofs_protocol(int dev_autofs_fd, int ioctl_fd) { return 0; } -static int autofs_set_timeout(int dev_autofs_fd, int ioctl_fd, time_t sec) { +static int autofs_set_timeout(int dev_autofs_fd, int ioctl_fd, usec_t us