Skip to content

Commit

Permalink
Improve recovery management
Browse files Browse the repository at this point in the history
Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany committed Jan 30, 2024
1 parent df27abd commit d6a2136
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
12 changes: 12 additions & 0 deletions pkg/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ func (u *UpgradeAction) Run() (err error) {
return err
}

// Manage legacy recovery. This logic should be removed once toolkit v1.1 gets unsupported.
legacyImg := filepath.Join(u.spec.Partitions.Recovery.MountPoint, constants.LegacyImagesPath, constants.RecoveryImgFile)
if ok, _ := utils.Exists(u.cfg.Fs, legacyImg); ok {
u.cfg.Logger.Debug("Manage legacy recovery image")
recoveryImg := filepath.Join(u.spec.Partitions.Recovery.MountPoint, constants.RecoveryImgFile)
err = u.cfg.Fs.Rename(legacyImg, recoveryImg)
if err != nil {
u.cfg.Logger.Error("failed renaming recovery image from legacy path")
return err
}
}

// Closing snapshotter transaction
u.cfg.Logger.Info("Closing snapshotter transaction")
err = u.snapshotter.CloseTransaction(u.snapshot)
Expand Down
5 changes: 5 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ const (
LoopDeviceSnapshotterType = "loopdevice"
ActiveSnapshot = "active"
PassiveSnapshot = "passive_%d"

// Legacy paths
LegacyImagesPath = "cOS"
LegacyPassivePath = LegacyImagesPath + "/passive.img"
LegacyActivePath = LegacyImagesPath + "/active.img"
)

// GetDefaultSystemEcludes returns a list of transient paths
Expand Down
3 changes: 2 additions & 1 deletion pkg/features/embedded/grub-config/etc/elemental/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ insmod loopback
insmod squash4

set loopdev="loop0"
search --no-floppy --label --set=root $state_label

menuentry "${display_name}" --id active {
set img=/.snapshots/active
set mode=active
search --no-floppy --label --set=root $state_label
loopback $loopdev $img
source ($loopdev)/etc/cos/bootargs.cfg
linux ($loopdev)$kernel $kernelcmd ${extra_cmdline} ${extra_active_cmdline}
Expand All @@ -65,6 +65,7 @@ for passive_snap in ${passive_snaps}; do
menuentry "${display_name} (snapshot ${passive_snap})" --id ${passive_snap} {
set img=/.snapshots/passives/${passive_snap}
set mode=passive
search --no-floppy --label --set=root $state_label
loopback $loopdev $img
source ($loopdev)/etc/cos/bootargs.cfg
linux ($loopdev)$kernel $kernelcmd ${extra_cmdline} ${extra_passive_cmdline}
Expand Down
16 changes: 6 additions & 10 deletions pkg/snapshotter/loopdevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ const (
loopDevicePassivePath = loopDeviceSnapsPath + "/passives"
)

const legacyImagesPath = "cOS"
const legacyPassivePath = legacyImagesPath + "/passive.img"
const legacyActivePath = legacyImagesPath + "/active.img"

var _ v1.Snapshotter = (*LoopDevice)(nil)

type LoopDevice struct {
Expand Down Expand Up @@ -87,15 +83,15 @@ func (l *LoopDevice) InitSnapshotter(rootDir string) error {
}

// Check the existence of a legacy deployment
if ok, _ := utils.Exists(l.cfg.Fs, filepath.Join(rootDir, legacyImagesPath)); ok {
if ok, _ := utils.Exists(l.cfg.Fs, filepath.Join(rootDir, constants.LegacyImagesPath)); ok {
l.cfg.Logger.Info("Legacy deployment detected running migration logic")
l.legacyClean = true
image := filepath.Join(rootDir, legacyActivePath)
image := filepath.Join(rootDir, constants.LegacyActivePath)

// Migrate passive image if running the transaction in passive mode
if elemental.IsPassiveMode(l.cfg) {
l.cfg.Logger.Debug("Running in passive mode, migrating passive image")
image = filepath.Join(rootDir, legacyPassivePath)
image = filepath.Join(rootDir, constants.LegacyPassivePath)
}
err = l.legacyImageToSnapsot(image)
if err != nil {
Expand Down Expand Up @@ -575,13 +571,13 @@ func (l *LoopDevice) cleanLegacyImages() error {

if l.legacyClean {
// delete passive image
path = filepath.Join(l.rootDir, legacyPassivePath)
path = filepath.Join(l.rootDir, constants.LegacyPassivePath)
if elemental.IsPassiveMode(l.cfg) {
// delete active image
path = filepath.Join(l.rootDir, legacyActivePath)
path = filepath.Join(l.rootDir, constants.LegacyActivePath)
} else if l.currentSnapshotID > 0 || elemental.IsRecoveryMode(l.cfg) {
// delete passive and active if we are not booting from any of them
path = filepath.Join(l.rootDir, legacyImagesPath)
path = filepath.Join(l.rootDir, constants.LegacyImagesPath)
}
if ok, _ := utils.Exists(l.cfg.Fs, path); ok {
return l.cfg.Fs.RemoveAll(path)
Expand Down

0 comments on commit d6a2136

Please sign in to comment.