diff options
author | Janne Heß <dasJ@users.noreply.github.com> | 2023-08-28 09:18:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-28 09:18:44 +0200 |
commit | fd454fe4b6d4a4deb446e661e818f392291812a6 (patch) | |
tree | d5eabe471261db1058ee15bbba2f22c177582166 /nixos/modules/system | |
parent | c9c99c053abe3c6be42d3f4d7deedd7282103567 (diff) | |
parent | eb831f759bc2c98ef84a0a97c60e5ab0b73f309c (diff) |
Merge pull request #250316 from helsinki-systems/feat/stc-improve-mount-units
nixos/switch-to-configuration: Improve mount unit handling
Diffstat (limited to 'nixos/modules/system')
-rwxr-xr-x | nixos/modules/system/activation/switch-to-configuration.pl | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index 04d90968c4c12..8bd450d7343b2 100755 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -313,7 +313,8 @@ sub unrecord_unit { # needs to be restarted or reloaded. If the units differ, the service # is restarted unless the only difference is `X-Reload-Triggers` in the # `Unit` section. If this is the only modification, the unit is reloaded -# instead of restarted. +# instead of restarted. If the only difference is `Options` in the +# `[Mount]` section, the unit is reloaded rather than restarted. # Returns: # - 0 if the units are equal # - 1 if the units are different and a restart action is required @@ -390,6 +391,11 @@ sub compare_units { ## no critic(Subroutines::ProhibitExcessComplexity) next; } } + # If this is a mount unit, check if it was only `Options` + if ($section_name eq "Mount" and $ini_key eq "Options") { + $ret = 2; + next; + } return 1; } } @@ -440,10 +446,18 @@ sub handle_modified_unit { ## no critic(Subroutines::ProhibitManyArgs, Subroutin # properties (resource limits and inotify watches) # seem to get applied on daemon-reload. } elsif ($unit =~ /\.mount$/msx) { - # Reload the changed mount unit to force a remount. - # FIXME: only reload when Options= changed, restart otherwise - $units_to_reload->{$unit} = 1; - record_unit($reload_list_file, $unit); + # Just restart the unit. We wouldn't have gotten into this subroutine + # if only `Options` was changed, in which case the unit would be reloaded. + # The only exception is / and /nix because it's very unlikely we can safely + # unmount them so we reload them instead. This means that we may not get + # all changes into the running system but it's better than crashing it. + if ($unit eq "-.mount" or $unit eq "nix.mount") { + $units_to_reload->{$unit} = 1; + record_unit($reload_list_file, $unit); + } else { + $units_to_restart->{$unit} = 1; + record_unit($restart_list_file, $unit); + } } elsif ($unit =~ /\.socket$/msx) { # FIXME: do something? # Attempt to fix this: https://github.com/NixOS/nixpkgs/pull/141192 |