daandemeyer / rpms / systemd

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