dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
a9339c
From 048ed4b2fecef7003925772740bab651cb08b260 Mon Sep 17 00:00:00 2001
a9339c
From: brulon <barron@lexmark.com>
a9339c
Date: Fri, 26 Aug 2016 11:57:22 -0400
a9339c
Subject: [PATCH] mount: add new LazyUnmount= setting for mount units, mapping
a9339c
 to umount(8)'s "-l" switch (#3827)
a9339c
a9339c
(cherry-picked commit from e520950a03419957875034bc27795b0b81d8e793)
a9339c
a9339c
Resolves: #1497264
a9339c
---
a9339c
 man/systemd.mount.xml                 | 13 +++++++++++++
a9339c
 src/core/dbus-mount.c                 |  1 +
a9339c
 src/core/load-fragment-gperf.gperf.m4 |  1 +
a9339c
 src/core/mount.c                      |  8 ++++++--
a9339c
 src/core/mount.h                      |  2 ++
a9339c
 5 files changed, 23 insertions(+), 2 deletions(-)
a9339c
a9339c
diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml
a9339c
index dfa437b5d..1590c44ce 100644
a9339c
--- a/man/systemd.mount.xml
a9339c
+++ b/man/systemd.mount.xml
a9339c
@@ -329,6 +329,19 @@
a9339c
         off.</para></listitem>
a9339c
       </varlistentry>
a9339c
 
a9339c
+      <varlistentry>
a9339c
+        <term><varname>LazyUnmount=</varname></term>
a9339c
+
a9339c
+        <listitem><para>Takes a boolean argument. If true, detach the
a9339c
+        filesystem from the filesystem hierarchy at time of the unmount
a9339c
+        operation, and clean up all references to the filesystem as
a9339c
+        soon as they are not busy anymore.
a9339c
+        This corresponds with
a9339c
+        <citerefentry project='man-pages'><refentrytitle>umount</refentrytitle><manvolnum>8</manvolnum></citerefentry>'s
a9339c
+        <parameter>-l</parameter> switch. Defaults to
a9339c
+        off.</para></listitem>
a9339c
+      </varlistentry>
a9339c
+
a9339c
       <varlistentry>
a9339c
         <term><varname>DirectoryMode=</varname></term>
a9339c
         <listitem><para>Directories of mount points (and any parent
a9339c
diff --git a/src/core/dbus-mount.c b/src/core/dbus-mount.c
a9339c
index 04beba631..cbb842f70 100644
a9339c
--- a/src/core/dbus-mount.c
a9339c
+++ b/src/core/dbus-mount.c
a9339c
@@ -110,6 +110,7 @@ const sd_bus_vtable bus_mount_vtable[] = {
a9339c
         SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Mount, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
a9339c
         SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Mount, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
a9339c
         SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool, offsetof(Mount, sloppy_options), SD_BUS_VTABLE_PROPERTY_CONST),
a9339c
+        SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool, offsetof(Mount, lazy_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
a9339c
         SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Mount, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
a9339c
         BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
a9339c
         BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
a9339c
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
a9339c
index b2fe627af..664bba0ef 100644
a9339c
--- a/src/core/load-fragment-gperf.gperf.m4
a9339c
+++ b/src/core/load-fragment-gperf.gperf.m4
a9339c
@@ -316,6 +316,7 @@ Mount.Type,                      config_parse_string,                0,
a9339c
 Mount.TimeoutSec,                config_parse_sec,                   0,                             offsetof(Mount, timeout_usec)
a9339c
 Mount.DirectoryMode,             config_parse_mode,                  0,                             offsetof(Mount, directory_mode)
a9339c
 Mount.SloppyOptions,             config_parse_bool,                  0,                             offsetof(Mount, sloppy_options)
a9339c
+Mount.LazyUnmount,               config_parse_bool,                  0,                             offsetof(Mount, lazy_unmount)
a9339c
 EXEC_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl
a9339c
 CGROUP_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl
a9339c
 KILL_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl
a9339c
diff --git a/src/core/mount.c b/src/core/mount.c
a9339c
index 0dc67dde6..5fd7a86dd 100644
a9339c
--- a/src/core/mount.c
a9339c
+++ b/src/core/mount.c
a9339c
@@ -690,7 +690,8 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
a9339c
                 "%sOptions: %s\n"
a9339c
                 "%sFrom /proc/self/mountinfo: %s\n"
a9339c
                 "%sFrom fragment: %s\n"
a9339c
-                "%sDirectoryMode: %04o\n",
a9339c
+                "%sDirectoryMode: %04o\n"
a9339c
+                "%sLazyUnmount: %s\n",
a9339c
                 prefix, mount_state_to_string(m->state),
a9339c
                 prefix, mount_result_to_string(m->result),
a9339c
                 prefix, m->where,
a9339c
@@ -699,7 +700,8 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
a9339c
                 prefix, p ? strna(p->options) : "n/a",
a9339c
                 prefix, yes_no(m->from_proc_self_mountinfo),
a9339c
                 prefix, yes_no(m->from_fragment),
a9339c
-                prefix, m->directory_mode);
a9339c
+                prefix, m->directory_mode,
a9339c
+                prefix, yes_no(m->lazy_unmount));
a9339c
 
a9339c
         if (m->control_pid > 0)
a9339c
                 fprintf(f,
a9339c
@@ -891,6 +893,8 @@ static void mount_enter_unmounting(Mount *m) {
a9339c
         m->control_command = m->exec_command + MOUNT_EXEC_UNMOUNT;
a9339c
 
a9339c
         r = exec_command_set(m->control_command, "/bin/umount", m->where, NULL);
a9339c
+        if (r >= 0 && m->lazy_unmount)
a9339c
+                r = exec_command_append(m->control_command, "-l", NULL);
a9339c
         if (r < 0)
a9339c
                 goto fail;
a9339c
 
a9339c
diff --git a/src/core/mount.h b/src/core/mount.h
a9339c
index 353222000..4e870299c 100644
a9339c
--- a/src/core/mount.h
a9339c
+++ b/src/core/mount.h
a9339c
@@ -90,6 +90,8 @@ struct Mount {
a9339c
 
a9339c
         bool sloppy_options;
a9339c
 
a9339c
+        bool lazy_unmount;
a9339c
+
a9339c
         MountResult result;
a9339c
         MountResult reload_result;
a9339c