Skip to content

Commit 4776c43

Browse files
committed
fix: successful ACPI shutdown in maintenance mode
Fixes #6817 The original problem wasn't reproducible with `main`, but there was a set of bugs in the shutdown sequence which was preventing it from completing successfully, as in the maintenance mode nothing is running and initialized yet. Most of the bugs were `nil` pointer dereferences. Fixed a small issue with final 'RebootError' printed as a failure in the ACPI shutdown path. Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com> (cherry picked from commit fda6da6)
1 parent 042adbf commit 4776c43

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_controller.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ func (c *Controller) ListenForEvents(ctx context.Context) error {
158158
log.Printf("shutdown via SIGTERM received")
159159

160160
if err := c.Run(ctx, runtime.SequenceShutdown, &machine.ShutdownRequest{Force: true}, runtime.WithTakeover()); err != nil {
161-
log.Printf("shutdown failed: %v", err)
161+
if !runtime.IsRebootError(err) {
162+
log.Printf("shutdown failed: %v", err)
163+
}
162164
}
163165

164166
errCh <- nil
@@ -178,7 +180,9 @@ func (c *Controller) ListenForEvents(ctx context.Context) error {
178180
log.Printf("shutdown via ACPI received")
179181

180182
if err := c.Run(ctx, runtime.SequenceShutdown, &machine.ShutdownRequest{Force: true}, runtime.WithTakeover()); err != nil {
181-
log.Printf("failed to run shutdown sequence: %s", err)
183+
if !runtime.IsRebootError(err) {
184+
log.Printf("failed to run shutdown sequence: %s", err)
185+
}
182186
}
183187

184188
errCh <- nil

internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_dbus.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@ func (dbus *DBusState) Start() error {
5555

5656
// Stop the D-Bus broker and logind mock.
5757
func (dbus *DBusState) Stop() error {
58+
if dbus.cancel == nil {
59+
return nil
60+
}
61+
5862
dbus.cancel()
5963

64+
if dbus.logindMock == nil || dbus.broker == nil {
65+
return nil
66+
}
67+
6068
if err := dbus.logindMock.Close(); err != nil {
6169
return err
6270
}

internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,25 +1080,6 @@ func mountDisks(r runtime.Runtime) (err error) {
10801080
return mount.Mount(mountpoints)
10811081
}
10821082

1083-
func unmountDisks(r runtime.Runtime) (err error) {
1084-
mountpoints := mount.NewMountPoints()
1085-
1086-
for _, disk := range r.Config().Machine().Disks() {
1087-
for i, part := range disk.Partitions() {
1088-
var partname string
1089-
1090-
partname, err = util.PartPath(disk.Device(), i+1)
1091-
if err != nil {
1092-
return err
1093-
}
1094-
1095-
mountpoints.Set(partname, mount.NewMountPoint(partname, part.MountPoint(), "xfs", unix.MS_NOATIME, ""))
1096-
}
1097-
}
1098-
1099-
return mount.Unmount(mountpoints)
1100-
}
1101-
11021083
// WriteUserFiles represents the WriteUserFiles task.
11031084
//
11041085
//nolint:gocyclo,cyclop
@@ -1320,7 +1301,26 @@ func UnmountOverlayFilesystems(seq runtime.Sequence, data interface{}) (runtime.
13201301
// UnmountUserDisks represents the UnmountUserDisks task.
13211302
func UnmountUserDisks(seq runtime.Sequence, data interface{}) (runtime.TaskExecutionFunc, string) {
13221303
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) (err error) {
1323-
return unmountDisks(r)
1304+
if r.Config() == nil {
1305+
return nil
1306+
}
1307+
1308+
mountpoints := mount.NewMountPoints()
1309+
1310+
for _, disk := range r.Config().Machine().Disks() {
1311+
for i, part := range disk.Partitions() {
1312+
var partname string
1313+
1314+
partname, err = util.PartPath(disk.Device(), i+1)
1315+
if err != nil {
1316+
return err
1317+
}
1318+
1319+
mountpoints.Set(partname, mount.NewMountPoint(partname, part.MountPoint(), "xfs", unix.MS_NOATIME, ""))
1320+
}
1321+
}
1322+
1323+
return mount.Unmount(mountpoints)
13241324
}, "unmountUserDisks"
13251325
}
13261326

@@ -1364,7 +1364,12 @@ func UnmountPodMounts(seq runtime.Sequence, data interface{}) (runtime.TaskExecu
13641364
// UnmountSystemDiskBindMounts represents the UnmountSystemDiskBindMounts task.
13651365
func UnmountSystemDiskBindMounts(seq runtime.Sequence, data interface{}) (runtime.TaskExecutionFunc, string) {
13661366
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) (err error) {
1367-
devname := r.State().Machine().Disk().BlockDevice.Device().Name()
1367+
systemDisk := r.State().Machine().Disk()
1368+
if systemDisk == nil {
1369+
return nil
1370+
}
1371+
1372+
devname := systemDisk.BlockDevice.Device().Name()
13681373

13691374
f, err := os.Open("/proc/mounts")
13701375
if err != nil {
@@ -1584,6 +1589,11 @@ func stopAndRemoveAllPods(stopAction cri.StopAction) runtime.TaskExecutionFunc {
15841589
return err
15851590
}
15861591

1592+
// check that the CRI is running and the socket is available, if not, skip the rest
1593+
if _, err = os.Stat(constants.CRIContainerdAddress); os.IsNotExist(err) {
1594+
return nil
1595+
}
1596+
15871597
client, err := cri.NewClient("unix://"+constants.CRIContainerdAddress, 10*time.Second)
15881598
if err != nil {
15891599
return err

0 commit comments

Comments
 (0)