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