Skip to content

Commit

Permalink
Don't re-run migration if aufs and overlay roots exist
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Günzler <robertg@balena.io>
  • Loading branch information
robertgzr committed Sep 24, 2020
1 parent a52b473 commit 8cb45b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
25 changes: 15 additions & 10 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,21 +942,26 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
start := time.Now()
var err error
err = storagemigration.Migrate(config.Root)
// gracefully handle non-existing aufs root
// we have nothing to migrate from
if err != nil && err != storagemigration.ErrAuFSRootNotExists {
if err := storagemigration.FailCleanup(config.Root); err != nil {
return nil, errors.Wrap(err, "failed to cleanup after failed migration")
if err != nil {
if err == storagemigration.ErrAuFSRootNotExists ||
err == storagemigration.ErrOverlayRootExists {
// gracefully handle missing aufs root or existing
// overlay root - we have nothing to migrate from
logrus.Infof("Storage migartion skipped: %s", err)
} else {
// rollback on errors
if err := storagemigration.FailCleanup(config.Root); err != nil {
return nil, errors.Wrap(err, "failed to cleanup after failed storage migration")
}
return nil, errors.Wrap(err, "failed to migrate storage")
}
return nil, errors.Wrap(err, "failed to migrate storage")
}
// only commit if migration succeded
if err == nil {
} else {
// only commit if migration succeded
if err := storagemigration.Commit(config.Root); err != nil {
return nil, errors.Wrap(err, "failed to commit storage migration")
}
logrus.Infof("Storage migration from aufs to overlay2, took %s", time.Now().Sub(start))
}
logrus.Infof("Storage migration from aufs to overlay2, took %s", time.Now().Sub(start))
}

for operatingSystem, gd := range d.graphDrivers {
Expand Down
7 changes: 1 addition & 6 deletions pkg/storagemigration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@ func Migrate(root string) error {
return err
}

// TODO this needs to go... we can't overwrite the previous migration
// make sure there isn't an overlay2 tree already
err = CheckOvlRootExists(root)
if err == nil {
logrus.Warn("overlay root found, cleaning up...")
err := os.RemoveAll(overlayRoot(root))
if err != nil {
return fmt.Errorf("Error cleaning up overlay2 root: %v", err)
}
return ErrOverlayRootExists
}

var state State
Expand Down
2 changes: 2 additions & 0 deletions pkg/storagemigration/overlayutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
var (
// ErrOverlayRootNotExists indicates the overlay2 root directory wasn't found
ErrOverlayRootNotExists = errors.New("Overlay2 root doesn't exists")
// ErrOverlayRootExists indicates the migration was already run sucessfully
ErrOverlayRootExists = errors.New("Overlay2 root exists")
)

// CheckRootExists checks for the overlay storage root directory
Expand Down
4 changes: 0 additions & 4 deletions pkg/storagemigration/storagemigration.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO we can probably re-use containerd libs?
package storagemigration

import "path/filepath"
Expand Down Expand Up @@ -29,9 +28,6 @@ const (
MetaWhiteout

// MetaOther is a catch-all for everything else
//
// TODO(robertgzr): replace this with more meta types
// for better mapping from a->o, o->a
MetaOther
)

Expand Down

0 comments on commit 8cb45b5

Please sign in to comment.