mirror of
https://github.com/systemd/systemd.git
synced 2025-03-14 04:58:28 +03:00
mount-util: rework umount_verbose() to take log level and flags arg
Let's make umount_verbose() more like mount_verbose_xyz(), i.e. take log level and flags param. In particular the latter matters, since we typically don't actually want to follow symlinks when unmounting.
This commit is contained in:
parent
511a8cfe30
commit
30f5d10421
@ -94,7 +94,7 @@ static void unmount_autofs(Automount *a) {
|
||||
automount_send_ready(a, a->expire_tokens, -EHOSTDOWN);
|
||||
|
||||
if (a->where) {
|
||||
r = repeat_unmount(a->where, MNT_DETACH);
|
||||
r = repeat_unmount(a->where, MNT_DETACH|UMOUNT_NOFOLLOW);
|
||||
if (r < 0)
|
||||
log_error_errno(r, "Failed to unmount: %m");
|
||||
}
|
||||
@ -647,7 +647,7 @@ fail:
|
||||
safe_close_pair(p);
|
||||
|
||||
if (mounted) {
|
||||
r = repeat_unmount(a->where, MNT_DETACH);
|
||||
r = repeat_unmount(a->where, MNT_DETACH|UMOUNT_NOFOLLOW);
|
||||
if (r < 0)
|
||||
log_error_errno(r, "Failed to unmount, ignoring: %m");
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ int home_activate_directory(
|
||||
|
||||
r = mount_nofollow_verbose(LOG_ERR, NULL, hd, NULL, MS_BIND|MS_REMOUNT|user_record_mount_flags(h), NULL);
|
||||
if (r < 0) {
|
||||
(void) umount_verbose(hd);
|
||||
(void) umount_verbose(LOG_ERR, hd, UMOUNT_NOFOLLOW);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -1259,7 +1259,7 @@ int home_prepare_luks(
|
||||
|
||||
fail:
|
||||
if (mounted)
|
||||
(void) umount_verbose("/run/systemd/user-home-mount");
|
||||
(void) umount_verbose(LOG_ERR, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
|
||||
|
||||
if (dm_activated)
|
||||
(void) crypt_deactivate(cd, setup->dm_name);
|
||||
@ -2168,7 +2168,7 @@ int home_create_luks(
|
||||
|
||||
root_fd = safe_close(root_fd);
|
||||
|
||||
r = umount_verbose("/run/systemd/user-home-mount");
|
||||
r = umount_verbose(LOG_ERR, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@ -2238,7 +2238,7 @@ fail:
|
||||
root_fd = safe_close(root_fd);
|
||||
|
||||
if (mounted)
|
||||
(void) umount_verbose("/run/systemd/user-home-mount");
|
||||
(void) umount_verbose(LOG_WARNING, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
|
||||
|
||||
if (dm_activated)
|
||||
(void) crypt_deactivate(cd, dm_name);
|
||||
@ -2340,7 +2340,7 @@ static int ext4_offline_resize_fs(HomeSetup *setup, uint64_t new_size, bool disc
|
||||
}
|
||||
|
||||
if (setup->undo_mount) {
|
||||
r = umount_verbose("/run/systemd/user-home-mount");
|
||||
r = umount_verbose(LOG_ERR, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -87,7 +87,7 @@ int home_move_mount(const char *user_name_and_realm, const char *target) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = umount_verbose("/run/systemd/user-home-mount");
|
||||
r = umount_verbose(LOG_ERR, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -291,7 +291,7 @@ int home_setup_undo(HomeSetup *setup) {
|
||||
}
|
||||
|
||||
if (setup->undo_mount) {
|
||||
q = umount_verbose("/run/systemd/user-home-mount");
|
||||
q = umount_verbose(LOG_DEBUG, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
|
||||
if (q < 0)
|
||||
r = q;
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ int sync_cgroup(pid_t pid, CGroupUnified unified_requested, uid_t uid_shift) {
|
||||
log_error_errno(r, "Failed to chown() cgroup %s: %m", fn);
|
||||
finish:
|
||||
if (undo_mount)
|
||||
(void) umount_verbose(tree);
|
||||
(void) umount_verbose(LOG_ERR, tree, UMOUNT_NOFOLLOW);
|
||||
|
||||
(void) rmdir(tree);
|
||||
return r;
|
||||
|
@ -472,7 +472,7 @@ int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
|
||||
return r;
|
||||
}
|
||||
|
||||
r = umount_verbose(full);
|
||||
r = umount_verbose(LOG_ERR, full, UMOUNT_NOFOLLOW);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -895,7 +895,7 @@ static int mount_inaccessible(const char *dest, CustomMount *m) {
|
||||
|
||||
r = mount_nofollow_verbose(m->graceful ? LOG_DEBUG : LOG_ERR, NULL, where, NULL, MS_BIND|MS_RDONLY|MS_REMOUNT, NULL);
|
||||
if (r < 0) {
|
||||
(void) umount_verbose(where);
|
||||
(void) umount_verbose(m->graceful ? LOG_DEBUG : LOG_ERR, where, UMOUNT_NOFOLLOW);
|
||||
return m->graceful ? 0 : r;
|
||||
}
|
||||
|
||||
@ -1099,10 +1099,11 @@ static int setup_volatile_yes(const char *directory, uid_t uid_shift, const char
|
||||
|
||||
fail:
|
||||
if (bind_mounted)
|
||||
(void) umount_verbose(t);
|
||||
(void) umount_verbose(LOG_ERR, t, UMOUNT_NOFOLLOW);
|
||||
|
||||
if (tmpfs_mounted)
|
||||
(void) umount_verbose(template);
|
||||
(void) umount_verbose(LOG_ERR, template, UMOUNT_NOFOLLOW);
|
||||
|
||||
(void) rmdir(template);
|
||||
return r;
|
||||
}
|
||||
@ -1163,7 +1164,7 @@ static int setup_volatile_overlay(const char *directory, uid_t uid_shift, const
|
||||
|
||||
finish:
|
||||
if (tmpfs_mounted)
|
||||
(void) umount_verbose(template);
|
||||
(void) umount_verbose(LOG_ERR, template, UMOUNT_NOFOLLOW);
|
||||
|
||||
(void) rmdir(template);
|
||||
return r;
|
||||
|
@ -658,10 +658,19 @@ int mount_verbose_full(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int umount_verbose(const char *what) {
|
||||
int umount_verbose(
|
||||
int error_log_level,
|
||||
const char *what,
|
||||
int flags) {
|
||||
|
||||
assert(what);
|
||||
|
||||
log_debug("Umounting %s...", what);
|
||||
if (umount(what) < 0)
|
||||
return log_error_errno(errno, "Failed to unmount %s: %m", what);
|
||||
|
||||
if (umount2(what, flags) < 0)
|
||||
return log_full_errno(error_log_level, errno,
|
||||
"Failed to unmount %s: %m", what);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,10 @@ static inline int mount_nofollow_verbose(
|
||||
return mount_verbose_full(error_log_level, what, where, type, flags, options, false);
|
||||
}
|
||||
|
||||
int umount_verbose(const char *where);
|
||||
int umount_verbose(
|
||||
int error_log_level,
|
||||
const char *where,
|
||||
int flags);
|
||||
|
||||
int mount_option_mangle(
|
||||
const char *options,
|
||||
|
@ -107,7 +107,7 @@ static int make_overlay(const char *path) {
|
||||
|
||||
finish:
|
||||
if (tmpfs_mounted)
|
||||
(void) umount_verbose("/run/systemd/overlay-sysroot");
|
||||
(void) umount_verbose(LOG_ERR, "/run/systemd/overlay-sysroot", UMOUNT_NOFOLLOW);
|
||||
|
||||
(void) rmdir("/run/systemd/overlay-sysroot");
|
||||
return r;
|
||||
|
Loading…
x
Reference in New Issue
Block a user