Skip to content

Commit

Permalink
Fix .snapshots mount methods
Browse files Browse the repository at this point in the history
Signed-off-by: David Cassany <[email protected]>
  • Loading branch information
davidcassany committed Dec 17, 2024
1 parent 4adf0c4 commit 6e398a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pkg/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/snapshotter/btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions pkg/snapshotter/snapper-backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6e398a1

Please sign in to comment.