From f2162705950a1b220fbbb8c396738d7155928212 Mon Sep 17 00:00:00 2001 From: "Paul \"TBBle\" Hampson" Date: Sun, 25 Apr 2021 04:28:43 +1000 Subject: [PATCH 1/2] 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 --- snapshots/windows/windows.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/snapshots/windows/windows.go b/snapshots/windows/windows.go index 87c0f4cc6..19e3e386c 100644 --- a/snapshots/windows/windows.go +++ b/snapshots/windows/windows.go @@ -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) } From 402acd7c1e20aa6ea88ce6cd6f77e486c5e88478 Mon Sep 17 00:00:00 2001 From: "Paul \"TBBle\" Hampson" Date: Sun, 25 Apr 2021 05:09:08 +1000 Subject: [PATCH 2/2] Small typo fix "reimporst" Signed-off-by: Paul "TBBle" Hampson --- snapshots/windows/windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snapshots/windows/windows.go b/snapshots/windows/windows.go index 19e3e386c..9c609d4f8 100644 --- a/snapshots/windows/windows.go +++ b/snapshots/windows/windows.go @@ -468,7 +468,7 @@ func (s *snapshotter) createScratchLayer(ctx context.Context, snDir string, pare return nil } -// convertScratchToReadOnlyLayer reimporst the layer over itself, to transfer the files from the sandbox.vhdx to the on-disk storage. +// convertScratchToReadOnlyLayer reimports the layer over itself, to transfer the files from the sandbox.vhdx to the on-disk storage. func (s *snapshotter) convertScratchToReadOnlyLayer(ctx context.Context, snapshot storage.Snapshot, path string) (retErr error) { // TODO darrenstahlmsft: When this is done isolated, we should disable these.