summaryrefslogtreecommitdiff
path: root/src/shutdown/umount.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-12-20 17:02:05 +0100
committerLennart Poettering <lennart@poettering.net>2019-12-20 18:16:02 +0100
commit63135a2d8db0b89b226aad2838702a1813b761e3 (patch)
tree12cd105e8838c15f71b57a10a4db6584169f10bf /src/shutdown/umount.c
parent88287615e631d2023ff337a08b6ff45b1cfa58ee (diff)
downloadsystemd-63135a2d8db0b89b226aad2838702a1813b761e3.tar.gz
umount: detect root loopback device the same way as we detect root DM devices
get_block_device() is just the nicer way to do it (since it also odes btrfs). Also, let's already collect the dev_t of the loopback device when we enumerate things, that allows us to do the checks simpler without constantly stat()ing things over and over again.
Diffstat (limited to 'src/shutdown/umount.c')
-rw-r--r--src/shutdown/umount.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/shutdown/umount.c b/src/shutdown/umount.c
index 51ed05cb6a..47d1a3d676 100644
--- a/src/shutdown/umount.c
+++ b/src/shutdown/umount.c
@@ -249,8 +249,10 @@ static int loopback_list_get(MountPoint **head) {
_cleanup_free_ char *p = NULL;
const char *dn;
MountPoint *lb;
+ dev_t devnum;
- if (sd_device_get_devname(d, &dn) < 0)
+ if (sd_device_get_devnum(d, &devnum) < 0 ||
+ sd_device_get_devname(d, &dn) < 0)
continue;
p = strdup(dn);
@@ -263,6 +265,7 @@ static int loopback_list_get(MountPoint **head) {
*lb = (MountPoint) {
.path = TAKE_PTR(p),
+ .devnum = devnum,
};
LIST_PREPEND(mount_point, *head, lb);
@@ -530,22 +533,16 @@ static int swap_points_list_off(MountPoint **head, bool *changed) {
static int loopback_points_list_detach(MountPoint **head, bool *changed, int umount_log_level) {
MountPoint *m, *n;
- int n_failed = 0, k;
- struct stat root_st;
+ int n_failed = 0, r;
+ dev_t rootdev = 0;
assert(head);
assert(changed);
- k = lstat("/", &root_st);
+ (void) get_block_device("/", &rootdev);
LIST_FOREACH_SAFE(mount_point, m, n, *head) {
- int r;
- struct stat loopback_st;
-
- if (k >= 0 &&
- major(root_st.st_dev) != 0 &&
- lstat(m->path, &loopback_st) >= 0 &&
- root_st.st_dev == loopback_st.st_rdev) {
+ if (major(rootdev) != 0 && rootdev == m->devnum) {
n_failed++;
continue;
}
@@ -569,17 +566,14 @@ static int loopback_points_list_detach(MountPoint **head, bool *changed, int umo
static int dm_points_list_detach(MountPoint **head, bool *changed, int umount_log_level) {
MountPoint *m, *n;
int n_failed = 0, r;
- dev_t rootdev;
+ dev_t rootdev = 0;
assert(head);
assert(changed);
- r = get_block_device("/", &rootdev);
- if (r <= 0)
- rootdev = 0;
+ (void) get_block_device("/", &rootdev);
LIST_FOREACH_SAFE(mount_point, m, n, *head) {
-
if (major(rootdev) != 0 && rootdev == m->devnum) {
n_failed ++;
continue;