803fb7
From c6bb93f0b564d6c0eea9e35197b66521693b2078 Mon Sep 17 00:00:00 2001
803fb7
From: NeilBrown <neil@brown.name>
803fb7
Date: Thu, 31 Aug 2017 02:48:25 +1000
803fb7
Subject: [PATCH] shutdown: don't remount,ro network filesystems. (#6588)
803fb7
803fb7
systemd-shutdown is run after the network is stopped,
803fb7
so remounting a network filesystem read-only can hang.
803fb7
A simple umount is the most useful thing that can
803fb7
be done for a network filesystem once the network is down.
803fb7
803fb7
(cherry picked from commit 9cbc4547702aac28466c497f720038b9e2dc510c)
803fb7
803fb7
Resolves: #1312002
803fb7
---
803fb7
 src/core/umount.c | 17 ++++++++++++-----
803fb7
 1 file changed, 12 insertions(+), 5 deletions(-)
803fb7
803fb7
diff --git a/src/core/umount.c b/src/core/umount.c
803fb7
index bfd8aa5f8..6e8ccc794 100644
803fb7
--- a/src/core/umount.c
803fb7
+++ b/src/core/umount.c
803fb7
@@ -41,6 +41,7 @@
803fb7
 typedef struct MountPoint {
803fb7
         char *path;
803fb7
         char *options;
803fb7
+        char *type;
803fb7
         dev_t devnum;
803fb7
         LIST_FIELDS(struct MountPoint, mount_point);
803fb7
 } MountPoint;
803fb7
@@ -73,7 +74,7 @@ static int mount_points_list_get(MountPoint **head) {
803fb7
                 return -errno;
803fb7
 
803fb7
         for (i = 1;; i++) {
803fb7
-                _cleanup_free_ char *path = NULL, *options = NULL;
803fb7
+                _cleanup_free_ char *path = NULL, *options = NULL, *type = NULL;
803fb7
                 char *p = NULL;
803fb7
                 MountPoint *m;
803fb7
                 int k;
803fb7
@@ -87,11 +88,11 @@ static int mount_points_list_get(MountPoint **head) {
803fb7
                            "%*s"        /* (6) mount flags */
803fb7
                            "%*[^-]"     /* (7) optional fields */
803fb7
                            "- "         /* (8) separator */
803fb7
-                           "%*s "       /* (9) file system type */
803fb7
+                           "%ms "       /* (9) file system type */
803fb7
                            "%*s"        /* (10) mount source */
803fb7
                            "%ms"        /* (11) mount options */
803fb7
                            "%*[^\n]",   /* some rubbish at the end */
803fb7
-                           &path, &options);
803fb7
+                           &path, &type, &options);
803fb7
                 if (k != 2) {
803fb7
                         if (k == EOF)
803fb7
                                 break;
803fb7
@@ -129,6 +130,8 @@ static int mount_points_list_get(MountPoint **head) {
803fb7
                 m->path = p;
803fb7
                 m->options = options;
803fb7
                 options = NULL;
803fb7
+                m->type = type;
803fb7
+                type = NULL;
803fb7
 
803fb7
                 LIST_PREPEND(mount_point, *head, m);
803fb7
         }
803fb7
@@ -371,8 +374,12 @@ static int mount_points_list_umount(MountPoint **head, bool *changed, bool log_e
803fb7
                 /* If we are in a container, don't attempt to
803fb7
                    read-only mount anything as that brings no real
803fb7
                    benefits, but might confuse the host, as we remount
803fb7
-                   the superblock here, not the bind mound. */
803fb7
-                if (detect_container(NULL) <= 0)  {
803fb7
+                   the superblock here, not the bind mount.
803fb7
+                   If the filesystem is a network fs, also skip the
803fb7
+                   remount.  It brings no value (we cannot leave
803fb7
+                   a "dirty fs") and could hang if the network is down.  */
803fb7
+                if (detect_container(NULL) <= 0 &&
803fb7
+                    !fstype_is_network(m->type)) {
803fb7
                         _cleanup_free_ char *options = NULL;
803fb7
                         /* MS_REMOUNT requires that the data parameter
803fb7
                          * should be the same from the original mount