Blame SOURCES/0551-mount-make-sure-we-unmount-tmpfs-mounts-before-we-de.patch

17b0f1
From e7e3e1d230c15079a3d1480c47076ffd89f1de63 Mon Sep 17 00:00:00 2001
17b0f1
From: Michal Sekletar <msekletar@users.noreply.github.com>
17b0f1
Date: Mon, 16 Oct 2017 16:15:05 +0200
17b0f1
Subject: [PATCH] mount: make sure we unmount tmpfs mounts before we deactivate
17b0f1
 swaps (#7076)
17b0f1
17b0f1
In the past we introduced this property just for tmp.mount. However on
17b0f1
todays systems usually there are many more tmpfs mounts. Most notably
17b0f1
mounts backing XDG_RUNTIME_DIR for each user.
17b0f1
17b0f1
Let's generalize what we already have for tmp.mount and implement the
17b0f1
ordering After=swap.target for all tmpfs based mounts.
17b0f1
17b0f1
(cherry picked from commit fab35afabf01a5dea651187a1ccb5ae7cd778f9d)
17b0f1
17b0f1
Conflicts:
17b0f1
	src/core/mount.h
17b0f1
17b0f1
Resolves: #1437518
17b0f1
---
17b0f1
 src/core/dbus-mount.c | 10 +---------
17b0f1
 src/core/mount.c      | 24 ++++++++++++++++++++++++
17b0f1
 src/core/mount.h      |  1 +
17b0f1
 units/tmp.mount       |  1 -
17b0f1
 4 files changed, 26 insertions(+), 10 deletions(-)
17b0f1
17b0f1
diff --git a/src/core/dbus-mount.c b/src/core/dbus-mount.c
17b0f1
index 53fe4edc34..04beba631b 100644
17b0f1
--- a/src/core/dbus-mount.c
17b0f1
+++ b/src/core/dbus-mount.c
17b0f1
@@ -90,20 +90,12 @@ static int property_get_type(
17b0f1
                 sd_bus_error *error) {
17b0f1
 
17b0f1
         Mount *m = userdata;
17b0f1
-        const char *d;
17b0f1
 
17b0f1
         assert(bus);
17b0f1
         assert(reply);
17b0f1
         assert(m);
17b0f1
 
17b0f1
-        if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
17b0f1
-                d = m->parameters_proc_self_mountinfo.fstype;
17b0f1
-        else if (m->from_fragment && m->parameters_fragment.fstype)
17b0f1
-                d = m->parameters_fragment.fstype;
17b0f1
-        else
17b0f1
-                d = "";
17b0f1
-
17b0f1
-        return sd_bus_message_append(reply, "s", d);
17b0f1
+        return sd_bus_message_append(reply, "s", mount_get_fstype(m));
17b0f1
 }
17b0f1
 
17b0f1
 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, mount_result, MountResult);
17b0f1
diff --git a/src/core/mount.c b/src/core/mount.c
17b0f1
index 7ca7f5a258..a6d93b8691 100644
17b0f1
--- a/src/core/mount.c
17b0f1
+++ b/src/core/mount.c
17b0f1
@@ -119,6 +119,21 @@ static bool needs_quota(const MountParameters *p) {
17b0f1
                                  "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
17b0f1
 }
17b0f1
 
17b0f1
+const char *mount_get_fstype(const Mount *m) {
17b0f1
+        const char *type = NULL;
17b0f1
+
17b0f1
+        assert(m);
17b0f1
+
17b0f1
+        if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
17b0f1
+                type = m->parameters_proc_self_mountinfo.fstype;
17b0f1
+        else if (m->from_fragment && m->parameters_fragment.fstype)
17b0f1
+                type = m->parameters_fragment.fstype;
17b0f1
+        else
17b0f1
+                type = "";
17b0f1
+
17b0f1
+        return type;
17b0f1
+}
17b0f1
+
17b0f1
 static void mount_init(Unit *u) {
17b0f1
         Mount *m = MOUNT(u);
17b0f1
 
17b0f1
@@ -236,6 +251,7 @@ _pure_ static MountParameters* get_mount_parameters(Mount *m) {
17b0f1
 
17b0f1
 static int mount_add_mount_links(Mount *m) {
17b0f1
         _cleanup_free_ char *parent = NULL;
17b0f1
+        const char *fstype;
17b0f1
         MountParameters *pm;
17b0f1
         Unit *other;
17b0f1
         Iterator i;
17b0f1
@@ -292,6 +308,14 @@ static int mount_add_mount_links(Mount *m) {
17b0f1
                 }
17b0f1
         }
17b0f1
 
17b0f1
+        /* If this is a tmpfs mount then we have to unmount it before we try to deactivate swaps */
17b0f1
+        fstype = mount_get_fstype(m);
17b0f1
+        if (streq(fstype, "tmpfs")) {
17b0f1
+                r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, SPECIAL_SWAP_TARGET, NULL, true);
17b0f1
+                if (r < 0)
17b0f1
+                        return r;
17b0f1
+        }
17b0f1
+
17b0f1
         return 0;
17b0f1
 }
17b0f1
 
17b0f1
diff --git a/src/core/mount.h b/src/core/mount.h
17b0f1
index d6987e6fa1..353222000f 100644
17b0f1
--- a/src/core/mount.h
17b0f1
+++ b/src/core/mount.h
17b0f1
@@ -130,3 +130,4 @@ const char* mount_result_to_string(MountResult i) _const_;
17b0f1
 MountResult mount_result_from_string(const char *s) _pure_;
17b0f1
 
17b0f1
 void warn_if_dir_nonempty(const char *unit, const char* where);
17b0f1
+const char *mount_get_fstype(const Mount *m);
17b0f1
diff --git a/units/tmp.mount b/units/tmp.mount
17b0f1
index 8c53a87052..af0cf4a551 100644
17b0f1
--- a/units/tmp.mount
17b0f1
+++ b/units/tmp.mount
17b0f1
@@ -13,7 +13,6 @@ ConditionPathIsSymbolicLink=!/tmp
17b0f1
 DefaultDependencies=no
17b0f1
 Conflicts=umount.target
17b0f1
 Before=local-fs.target umount.target
17b0f1
-After=swap.target
17b0f1
 
17b0f1
 [Mount]
17b0f1
 What=tmpfs