Skip to content

Commit

Permalink
chore: unify kexec phase
Browse files Browse the repository at this point in the history
This changes the mounting/unmounting of `BOOT` partiton code into
`kexecPrepare` phase. Also skips if `BOOT` partition cannot be found.

Signed-off-by: Noel Georgi <git@frezbo.dev>
  • Loading branch information
frezbo committed Jun 6, 2023
1 parent 3a86537 commit 47986cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 45 deletions.
26 changes: 0 additions & 26 deletions internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,9 @@ func (*Sequencer) Install(r runtime.Runtime) []runtime.Phase {
).Append(
"stopEverything",
StopAllServices,
).Append(
"mountBoot",
MountBootPartition,
).Append(
"kexec",
KexecPrepare,
).Append(
"unmountBoot",
UnmountBootPartition,
).Append(
"reboot",
Reboot,
Expand Down Expand Up @@ -467,15 +461,9 @@ func (*Sequencer) MaintenanceUpgrade(r runtime.Runtime, _ *machineapi.UpgradeReq
).Append(
"meta",
ReloadMeta,
).Append(
"mountBoot",
MountBootPartition,
).Append(
"kexec",
KexecPrepare,
).Append(
"unmountBoot",
UnmountBootPartition,
).Append(
"stopEverything",
StopAllServices,
Expand Down Expand Up @@ -541,15 +529,9 @@ func (*Sequencer) Upgrade(r runtime.Runtime, in *machineapi.UpgradeRequest) []ru
).Append(
"meta",
ReloadMeta,
).Append(
"mountBoot",
MountBootPartition,
).Append(
"kexec",
KexecPrepare,
).Append(
"unmountBoot",
UnmountBootPartition,
).Append(
"stopEverything",
StopAllServices,
Expand Down Expand Up @@ -589,18 +571,10 @@ func stopAllPhaselist(r runtime.Runtime, enableKexec bool) PhaseList {
"unmountSystem",
UnmountEphemeralPartition,
UnmountStatePartition,
).AppendWhen(
enableKexec,
"mountBoot",
MountBootPartition,
).AppendWhen(
enableKexec,
"kexec",
KexecPrepare,
).AppendWhen(
enableKexec,
"unmountBoot",
UnmountBootPartition,
).Append(
"stopEverything",
StopAllServices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (

installer "github.com/siderolabs/talos/cmd/installer/pkg/install"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/disk"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/platform"
perrors "github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
Expand Down Expand Up @@ -2065,20 +2066,6 @@ func SaveStateEncryptionConfig(runtime.Sequence, any) (runtime.TaskExecutionFunc
}, "SaveStateEncryptionConfig"
}

// MountBootPartition mounts the boot partition.
func MountBootPartition(runtime.Sequence, any) (runtime.TaskExecutionFunc, string) {
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) (err error) {
return mount.SystemPartitionMount(r, logger, constants.BootPartitionLabel)
}, "mountBootPartition"
}

// UnmountBootPartition unmounts the boot partition.
func UnmountBootPartition(runtime.Sequence, any) (runtime.TaskExecutionFunc, string) {
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) error {
return mount.SystemPartitionUnmount(r, logger, constants.BootPartitionLabel)
}, "unmountBootPartition"
}

// MountEFIPartition mounts the EFI partition.
func MountEFIPartition(runtime.Sequence, any) (runtime.TaskExecutionFunc, string) {
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) (err error) {
Expand Down Expand Up @@ -2290,6 +2277,18 @@ func KexecPrepare(_ runtime.Sequence, data any) (runtime.TaskExecutionFunc, stri
return nil
}

// check if partition with label BOOT exists
if device := r.State().Machine().Disk(disk.WithPartitionLabel(constants.BootPartitionLabel)); device == nil {
return nil
}

// BOOT partition exists and we can mount it
if err := mount.SystemPartitionMount(r, logger, constants.BootPartitionLabel); err != nil {
return err
}

defer mount.SystemPartitionUnmount(r, logger, constants.BootPartitionLabel) //nolint:errcheck

conf, err := grub.Read(grub.ConfigPath)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func TestPhaseList_Append(t *testing.T) {
p: PhaseList{},
args: args{
name: "mount",
tasks: []runtime.TaskSetupFunc{MountBootPartition},
tasks: []runtime.TaskSetupFunc{KexecPrepare},
},
want: PhaseList{runtime.Phase{Name: "mount", Tasks: []runtime.TaskSetupFunc{MountBootPartition}}},
want: PhaseList{runtime.Phase{Name: "mount", Tasks: []runtime.TaskSetupFunc{KexecPrepare}}},
},
}

Expand Down Expand Up @@ -87,16 +87,16 @@ func TestPhaseList_AppendWhen(t *testing.T) {
args: args{
when: true,
name: "mount",
tasks: []runtime.TaskSetupFunc{MountBootPartition},
tasks: []runtime.TaskSetupFunc{KexecPrepare},
},
want: PhaseList{runtime.Phase{Name: "mount", Tasks: []runtime.TaskSetupFunc{MountBootPartition}}},
want: PhaseList{runtime.Phase{Name: "mount", Tasks: []runtime.TaskSetupFunc{KexecPrepare}}},
},
{
name: "false",
p: PhaseList{},
args: args{
when: false,
tasks: []runtime.TaskSetupFunc{MountBootPartition},
tasks: []runtime.TaskSetupFunc{KexecPrepare},
},
want: PhaseList{},
},
Expand Down

0 comments on commit 47986cb

Please sign in to comment.