From 6e398a16e60a2b57484788d02d5fb06a9ca2b93a Mon Sep 17 00:00:00 2001 From: David Cassany Date: Tue, 17 Dec 2024 16:52:02 +0100 Subject: [PATCH] Fix .snapshots mount methods Signed-off-by: David Cassany --- pkg/action/upgrade.go | 2 ++ pkg/snapshotter/btrfs.go | 14 +++++++------- pkg/snapshotter/snapper-backend.go | 7 +++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index cb75bde8c13..14325ea465e 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -136,6 +136,8 @@ func (u *UpgradeAction) upgradeInstallStateYaml() error { var oldActiveID int var deletedIDs []int + u.cfg.Logger.Infof("Upgrading install state") + if u.spec.Partitions.Recovery == nil || u.spec.Partitions.State == nil { return fmt.Errorf("undefined state or recovery partition") } diff --git a/pkg/snapshotter/btrfs.go b/pkg/snapshotter/btrfs.go index 6f220300e57..5825829ee0a 100644 --- a/pkg/snapshotter/btrfs.go +++ b/pkg/snapshotter/btrfs.go @@ -83,7 +83,7 @@ type Btrfs struct { bootloader types.Bootloader backend subvolumeBackend snapshotsUmount func() error - snapshotsMount func() error + snapshotsMount func(id int) error } // newBtrfsSnapshotter creates a new btrfs snapshotter vased on the given configuration and the given bootloader @@ -109,7 +109,7 @@ func newBtrfsSnapshotter(cfg types.Config, snapCfg types.SnapshotterConfig, boot cfg: cfg, snapshotterCfg: snapCfg, btrfsCfg: *btrfsCfg, bootloader: bootloader, snapshotsUmount: func() error { return nil }, - snapshotsMount: func() error { return nil }, + snapshotsMount: func(_ int) error { return nil }, backend: NewSubvolumeBackend(&cfg, *btrfsCfg, snapCfg.MaxSnaps), }, nil } @@ -301,7 +301,7 @@ func (b *Btrfs) GetSnapshots() (snapshots []int, err error) { // Check if snapshots subvolume is mounted snapshotsSubolume := filepath.Join(b.rootDir, fmt.Sprintf(snapshotPathTmpl, b.activeSnapshotID), snapshotsPath) if notMnt, _ := b.cfg.Mounter.IsLikelyNotMountPoint(snapshotsSubolume); notMnt { - err = b.snapshotsMount() + err = b.snapshotsMount(b.activeSnapshotID) if err != nil { return nil, err } @@ -445,13 +445,13 @@ func (b *Btrfs) remountStatePartition(state *types.Partition) error { func (b *Btrfs) mountSnapshotsSubvolumeInSnapshot(root, device string, snapshotID int) error { var mountpoint, subvol string - b.snapshotsMount = func() error { - b.cfg.Logger.Debugf("Mount snapshots subvolume in active snapshot %d", snapshotID) - mountpoint = filepath.Join(filepath.Join(root, fmt.Sprintf(snapshotPathTmpl, snapshotID)), snapshotsPath) + b.snapshotsMount = func(id int) error { + b.cfg.Logger.Debugf("Mount snapshots subvolume in active snapshot %d", id) + mountpoint = filepath.Join(filepath.Join(root, fmt.Sprintf(snapshotPathTmpl, id)), snapshotsPath) subvol = fmt.Sprintf("subvol=%s", filepath.Join(rootSubvol, snapshotsPath)) return b.cfg.Mounter.Mount(device, mountpoint, "btrfs", []string{"rw", subvol}) } - err := b.snapshotsMount() + err := b.snapshotsMount(snapshotID) if err != nil { b.cfg.Logger.Errorf("failed mounting subvolume %s at %s", subvol, mountpoint) return err diff --git a/pkg/snapshotter/snapper-backend.go b/pkg/snapshotter/snapper-backend.go index b230e849604..37c4b4e9974 100644 --- a/pkg/snapshotter/snapper-backend.go +++ b/pkg/snapshotter/snapper-backend.go @@ -74,8 +74,9 @@ func (s *snapperBackend) Probe(device, mountpoint string) (stat backendStat, ret stat.RootDir = rootDir stat.StateMount = stateMount - stat.CurrentID, s.currentID = currentID, currentID + stat.CurrentID = currentID stat.ActiveID = sl.ActiveID + s.activeID, s.currentID = stat.ActiveID, stat.CurrentID return stat, nil } else if ok, _ := utils.Exists(s.cfg.Fs, snapshots); ok { // We must mount .snapshots to ensure snapper is capable to list snapshots @@ -100,6 +101,7 @@ func (s *snapperBackend) Probe(device, mountpoint string) (stat backendStat, ret stat.RootDir = mountpoint stat.StateMount = mountpoint + s.activeID, s.currentID = stat.ActiveID, stat.CurrentID return stat, nil } @@ -247,9 +249,6 @@ func (s *snapperBackend) ListSnapshots(rootDir string) (snapshotsList, error) { // DeleteSnapshot deletes the given snapshot func (s snapperBackend) DeleteSnapshot(rootDir string, id int) error { if s.activeID == 0 && s.currentID == 0 { - // With snapper is not possible to delete any snapshot without an active one - //return s.btrfs.DeleteSnapshot(rootDir, id) - s.cfg.Logger.Warnf("cannot delete snapshot %d without a current and active snapshot defined, nothing to do", id) return nil }