-
Notifications
You must be signed in to change notification settings - Fork 562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
overlord,systemd: do not restart mount units on snapd start #13685
overlord,systemd: do not restart mount units on snapd start #13685
Conversation
6dd279d
to
5bfb319
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, so this is beyond just snapd itself, as we turn off restarting of all mounts in snapmgr?
systemd/systemd_test.go
Outdated
@@ -1160,7 +1160,7 @@ func (s *SystemdTestSuite) TestAddMountUnit(c *C) { | |||
mockSnapPath := filepath.Join(c.MkDir(), "/var/lib/snappy/snaps/foo_1.0.snap") | |||
makeMockFile(c, mockSnapPath) | |||
|
|||
mountUnitName, err := NewUnderRoot(rootDir, SystemMode, nil).EnsureMountUnitFile("Mount unit for foo, revision 42", mockSnapPath, "/snap/snapname/123", "squashfs") | |||
mountUnitName, err := NewUnderRoot(rootDir, SystemMode, nil).EnsureMountUnitFile("Mount unit for foo, revision 42", mockSnapPath, "/snap/snapname/123", "squashfs", &systemd.EnsureMountUnitFlags{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to add a test with IgnoreModified: true here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added now (see testEnsureMountUnitChanged
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I have left some comments more for discussion. I think the PR is fine to merge if the tests pass.
systemd/systemd.go
Outdated
@@ -323,6 +323,9 @@ type MountUnitOptions struct { | |||
Fstype string | |||
Options []string | |||
Origin string | |||
// IgnoreModified is set if we do not want to restart the | |||
// mount unit if modified | |||
IgnoreModified bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this is obvious from the name. Maybe PreventRestartModified
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
systemd/systemd.go
Outdated
@@ -1508,19 +1518,20 @@ func hostFsTypeAndMountOptions(fstype string) (hostFsType string, options []stri | |||
return hostFsType, options | |||
} | |||
|
|||
func (s *systemd) EnsureMountUnitFile(description, what, where, fstype string) (string, error) { | |||
func (s *systemd) EnsureMountUnitFile(description, what, where, fstype string, flags *EnsureMountUnitFlags) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should just not use this function when we need to set the flag, but use EnsureMountUnitFileWithOptions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but hostFsTypeAndMountOptions
would need to be public as well or build fstype/options slightly differently. Maybe something to consider in the future, I've added a TODO about this now.
systemd/systemd.go
Outdated
return "", err | ||
|
||
// If just modified, some times it is not convenient to restart | ||
if modified != mountUpdated || !unitOptions.IgnoreModified { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the else case, we could make a reload
. I think that will safely change the options if they changed with a -o remount
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the previous call to daemon-reload
already reloading the unit configuration? Afaiu, reload-or-restart
would only run anything under ExecReload=
in the unit if present, or restart otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
daemon-reload
does not do the remount. Maybe it is not well documented in systemd, but the mount unit has a reload
. See https://github.com/systemd/systemd/blob/7b44a24c1bc764b5c0555fed08911665e1e7d446/src/core/mount.c#L2437
That calls in the end mount_enter_remounting
https://github.com/systemd/systemd/blob/7b44a24c1bc764b5c0555fed08911665e1e7d446/src/core/mount.c#L1228
Which will use -o remount
.
That said, -o remount
does not support all changes. For example, you cannot change the device.
overlord/snapstate/snapmgr.go
Outdated
// Ensure mount files, but do not restart mount units | ||
// of snap files if the units are modified as services | ||
// in the snap have a Requires= on them. Otherwise the | ||
// services would be restarted. | ||
if _, err = sysd.EnsureMountUnitFile(info.MountDescription(), | ||
squashfsPath, whereDir, "squashfs", | ||
&systemd.EnsureMountUnitFlags{IgnoreModified: true}); err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you decided not to restart any mount units not just snapd. I think this is fine. Could you add in the comment, that if we decided to revert that we should never restart the mount for snapd otherwise snapd will kill itself on first start after an update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an additional comment about snapd
5bfb319
to
54e4291
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reviews, I've answered the comments and squashed the commits.
overlord/snapstate/snapmgr.go
Outdated
// Ensure mount files, but do not restart mount units | ||
// of snap files if the units are modified as services | ||
// in the snap have a Requires= on them. Otherwise the | ||
// services would be restarted. | ||
if _, err = sysd.EnsureMountUnitFile(info.MountDescription(), | ||
squashfsPath, whereDir, "squashfs", | ||
&systemd.EnsureMountUnitFlags{IgnoreModified: true}); err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an additional comment about snapd
systemd/systemd.go
Outdated
@@ -323,6 +323,9 @@ type MountUnitOptions struct { | |||
Fstype string | |||
Options []string | |||
Origin string | |||
// IgnoreModified is set if we do not want to restart the | |||
// mount unit if modified | |||
IgnoreModified bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
systemd/systemd.go
Outdated
return "", err | ||
|
||
// If just modified, some times it is not convenient to restart | ||
if modified != mountUpdated || !unitOptions.IgnoreModified { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the previous call to daemon-reload
already reloading the unit configuration? Afaiu, reload-or-restart
would only run anything under ExecReload=
in the unit if present, or restart otherwise.
systemd/systemd.go
Outdated
@@ -1508,19 +1518,20 @@ func hostFsTypeAndMountOptions(fstype string) (hostFsType string, options []stri | |||
return hostFsType, options | |||
} | |||
|
|||
func (s *systemd) EnsureMountUnitFile(description, what, where, fstype string) (string, error) { | |||
func (s *systemd) EnsureMountUnitFile(description, what, where, fstype string, flags *EnsureMountUnitFlags) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but hostFsTypeAndMountOptions
would need to be public as well or build fstype/options slightly differently. Maybe something to consider in the future, I've added a TODO about this now.
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #13685 +/- ##
=======================================
Coverage 78.89% 78.89%
=======================================
Files 1040 1040
Lines 133862 133876 +14
=======================================
+ Hits 105610 105624 +14
- Misses 21658 21659 +1
+ Partials 6594 6593 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one comment about passing flags by value and one comment about wording of the documentation.
systemd/emulation.go
Outdated
@@ -124,20 +124,21 @@ func (s *emulation) LogReader(services []string, n int, follow, namespaces bool) | |||
return nil, fmt.Errorf("LogReader") | |||
} | |||
|
|||
func (s *emulation) EnsureMountUnitFile(description, what, where, fstype string) (string, error) { | |||
func (s *emulation) EnsureMountUnitFile(description, what, where, fstype string, flags *EnsureMountUnitFlags) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing EnsureMountUnitFlags by value is probably better here. It's less worrying about escape analysis to optimize this away, less chance of a nil pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed now
systemd/systemd.go
Outdated
// remove this type instead? | ||
type EnsureMountUnitFlags struct { | ||
// PreventRestartIfModified is set if we do not want to restart the | ||
// mount unit if modified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// mount unit if modified | |
// mount unit even thought it has been modified.``` |
Do not restart the mount units when starting snapd even if the file itself has been modified. This is to prevent systemd stopping services when the mount unit gets restarted, as there are required dependencies in the mount path for services defined in snaps.
54e4291
to
2fad2d1
Compare
related to remounting units for installed snaps if we have new options set in snapd.
7bb4cea
to
a2be009
Compare
Do not restart the mount units when starting snapd even if the file
itself has been modified. This is to prevent systemd stopping services
when the mount unit gets restarted, as there are required dependencies
in the mount path for services defined in snaps.