Skip to content

Commit 09aa58b

Browse files
authored
Merge pull request #2705 from jterry75/detachvhd
Dismount sandbox VHD on snapshot remove
2 parents f674599 + 00242e1 commit 09aa58b

5 files changed

Lines changed: 359 additions & 140 deletions

File tree

snapshots/windows/windows.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"syscall"
2828
"unsafe"
2929

30+
"github.com/Microsoft/go-winio/vhd"
3031
"github.com/Microsoft/hcsshim"
3132
"github.com/containerd/containerd/errdefs"
3233
"github.com/containerd/containerd/log"
@@ -206,9 +207,20 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
206207

207208
path := s.getSnapshotDir(id)
208209
renamedID := "rm-" + id
209-
renamed := filepath.Join(s.root, "snapshots", renamedID)
210+
renamed := s.getSnapshotDir(renamedID)
210211
if err := os.Rename(path, renamed); err != nil && !os.IsNotExist(err) {
211-
return err
212+
if !os.IsPermission(err) {
213+
return err
214+
}
215+
// If permission denied, it's possible that the scratch is still mounted, an
216+
// artifact after a hard daemon crash for example. Worth a shot to try detaching it
217+
// before retrying the rename.
218+
if detachErr := vhd.DetachVhd(filepath.Join(path, "sandbox.vhdx")); detachErr != nil {
219+
return errors.Wrapf(err, "failed to detach VHD: %s", detachErr)
220+
}
221+
if renameErr := os.Rename(path, renamed); renameErr != nil && !os.IsNotExist(renameErr) {
222+
return errors.Wrapf(err, "second rename attempt following detach failed: %s", renameErr)
223+
}
212224
}
213225

214226
if err := t.Commit(); err != nil {

vendor.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ github.com/opencontainers/image-spec v1.0.1
3232
golang.org/x/sync 450f422ab23cf9881c94e2db30cac0eb1b7cf80c
3333
github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895
3434
github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0
35-
github.com/Microsoft/go-winio v0.4.10
35+
github.com/Microsoft/go-winio v0.4.11
3636
github.com/Microsoft/hcsshim v0.7.9
3737
google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944
3838
golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4

vendor/github.com/Microsoft/go-winio/ea.go

Lines changed: 137 additions & 137 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)