Use DeactivateLayer to recover layers that we cannot rename
It seems that something has shifted in an API, and vhd.DetachVhd is
returning "failed to open virtual disk: invalid argument" on Windows
Server LTSC 2019.
@@ -31,7 +31,6 @@ import (
"github.com/Microsoft/go-winio"
winfs "github.com/Microsoft/go-winio/pkg/fs"
- "github.com/Microsoft/go-winio/vhd"
"github.com/Microsoft/hcsshim"
"github.com/Microsoft/hcsshim/computestorage"
"github.com/Microsoft/hcsshim/pkg/ociwclayer"
@@ -256,11 +255,19 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
return err
}
// If permission denied, it's possible that the scratch is still mounted, an
- // artifact after a hard daemon crash for example. Worth a shot to try detaching it
+ // artifact after a hard daemon crash for example. Worth a shot to try deactivating it
// before retrying the rename.
- if detachErr := vhd.DetachVhd(filepath.Join(path, "sandbox.vhdx")); detachErr != nil {
- return errors.Wrapf(err, "failed to detach VHD: %s", detachErr)
+ var (
+ home, layerID = filepath.Split(path)
+ di = hcsshim.DriverInfo{
+ HomeDir: home,
}
+ )
+
+ if deactvateErr := hcsshim.DeactivateLayer(di, layerID); deactvateErr != nil {
+ return errors.Wrapf(err, "failed to deactivate layer following failed rename: %s", deactvateErr)
+ }
+
if renameErr := os.Rename(path, renamed); renameErr != nil && !os.IsNotExist(renameErr) {
return errors.Wrapf(err, "second rename attempt following detach failed: %s", renameErr)
}
