|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
From 207b45b46c41b84cbd2be29331c105308d66b3bd Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
Date: Thu, 11 May 2017 12:12:41 -0400
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
Subject: [PATCH] pid1: improve logging when failing to remount / ro (#5940)
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
https://bugzilla.redhat.com/show_bug.cgi?id=1227736#c49
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
We counted how many filesystems could not be unmounted, but only for those
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
filesystems which we tried to unmount. Since we only remount / ro, without
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
attempting to unmount, we would emit a confusing error message:
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
Remounting '/' read-only with options 'seclabel,space_cache,subvolid=5,subvol=/'.
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
Remounting '/' read-only with options 'seclabel,space_cache,subvolid=5,subvol=/'.
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
Remounting '/' read-only with options 'seclabel,space_cache,subvolid=5,subvol=/'.
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
All filesystems unmounted.
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
Warn when remount-ro fails, and for filesystems which we won't try to unmount,
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
include the failure to remount-ro in n_failed.
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
A few minor cleanups:
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- remove unecessary goto which jumps to the next line anyway
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- always calculate n_failed, even if log_error is false. This causes no change
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
in behaviour, but I think the code is easier to follow, since the log setting
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
cannot influence other logic.
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
(cherry picked from commit c826cd3f7cfd950c8a86d57dfa6303f70de3e207)
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
src/core/umount.c | 33 ++++++++++++++++++++-------------
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
1 file changed, 20 insertions(+), 13 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
diff --git a/src/core/umount.c b/src/core/umount.c
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
index 2f4b12bdb9..77b5bd9556 100644
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
--- a/src/core/umount.c
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+++ b/src/core/umount.c
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
@@ -369,6 +369,14 @@ static int delete_dm(dev_t devnum) {
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+static bool nonunmountable_path(const char *path) {
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ return path_equal(path, "/")
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+#ifndef HAVE_SPLIT_USR
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ || path_equal(path, "/usr")
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+#endif
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ || path_startswith(path, "/run/initramfs");
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
static int mount_points_list_umount(MountPoint **head, bool *changed, bool log_error) {
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
MountPoint *m, *n;
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
int n_failed = 0;
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
@@ -404,21 +412,21 @@ static int mount_points_list_umount(MountPoint **head, bool *changed, bool log_e
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
* somehwere else via a bind mount. If we
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
* explicitly remount the super block of that
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
* alias read-only we hence should be
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- * relatively safe regarding keeping the fs we
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- * can otherwise not see dirty. */
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ * relatively safe regarding keeping dirty an fs
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ * we cannot otherwise see. */
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
log_info("Remounting '%s' read-only with options '%s'.", m->path, options);
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- (void) mount(NULL, m->path, NULL, MS_REMOUNT|MS_RDONLY, options);
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ if (mount(NULL, m->path, NULL, MS_REMOUNT|MS_RDONLY, options) < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ if (log_error)
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ log_notice_errno(errno, "Failed to remount '%s' read-only: %m", m->path);
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ if (nonunmountable_path(m->path))
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ n_failed++;
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
/* Skip / and /usr since we cannot unmount that
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
* anyway, since we are running from it. They have
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
* already been remounted ro. */
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- if (path_equal(m->path, "/")
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
-#ifndef HAVE_SPLIT_USR
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- || path_equal(m->path, "/usr")
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
-#endif
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- || path_startswith(m->path, "/run/initramfs")
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- )
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ if (nonunmountable_path(m->path))
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
continue;
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
/* Trying to umount. We don't force here since we rely
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
@@ -430,8 +438,9 @@ static int mount_points_list_umount(MountPoint **head, bool *changed, bool log_e
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
*changed = true;
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
mount_point_free(head, m);
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- } else if (log_error) {
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- log_warning_errno(errno, "Could not unmount %s: %m", m->path);
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ } else {
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ if (log_error)
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
+ log_warning_errno(errno, "Could not unmount %s: %m", m->path);
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
n_failed++;
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
@@ -555,8 +564,6 @@ int umount_all(bool *changed) {
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
/* umount one more time with logging enabled */
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
r = mount_points_list_umount(&mp_list_head, &umount_changed, true);
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- if (r <= 0)
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
- goto end;
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
end:
|
|
Zbigniew Jędrzejewski-Szmek |
f4a676 |
mount_points_list_free(&mp_list_head);
|