Skip to content

Commit f216270

Browse files
committed
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. Signed-off-by: Paul "TBBle" Hampson <[email protected]>
1 parent 04f73e3 commit f216270

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

snapshots/windows/windows.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131

3232
"github.com/Microsoft/go-winio"
3333
winfs "github.com/Microsoft/go-winio/pkg/fs"
34-
"github.com/Microsoft/go-winio/vhd"
3534
"github.com/Microsoft/hcsshim"
3635
"github.com/Microsoft/hcsshim/computestorage"
3736
"github.com/Microsoft/hcsshim/pkg/ociwclayer"
@@ -256,11 +255,19 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
256255
return err
257256
}
258257
// If permission denied, it's possible that the scratch is still mounted, an
259-
// artifact after a hard daemon crash for example. Worth a shot to try detaching it
258+
// artifact after a hard daemon crash for example. Worth a shot to try deactivating it
260259
// before retrying the rename.
261-
if detachErr := vhd.DetachVhd(filepath.Join(path, "sandbox.vhdx")); detachErr != nil {
262-
return errors.Wrapf(err, "failed to detach VHD: %s", detachErr)
260+
var (
261+
home, layerID = filepath.Split(path)
262+
di = hcsshim.DriverInfo{
263+
HomeDir: home,
264+
}
265+
)
266+
267+
if deactvateErr := hcsshim.DeactivateLayer(di, layerID); deactvateErr != nil {
268+
return errors.Wrapf(err, "failed to deactivate layer following failed rename: %s", deactvateErr)
263269
}
270+
264271
if renameErr := os.Rename(path, renamed); renameErr != nil && !os.IsNotExist(renameErr) {
265272
return errors.Wrapf(err, "second rename attempt following detach failed: %s", renameErr)
266273
}

0 commit comments

Comments
 (0)