ryantimwilson / rpms / systemd

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