From a44fcd3d27c06aaa60d8d1cbce169f0d982e74b1 Mon Sep 17 00:00:00 2001 From: John Howard Date: Thu, 25 Jan 2018 09:12:52 -0800 Subject: [PATCH] LCOW: Graphdriver fix deadlock Signed-off-by: John Howard --- daemon/graphdriver/lcow/lcow_svm.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/daemon/graphdriver/lcow/lcow_svm.go b/daemon/graphdriver/lcow/lcow_svm.go index 26f6df4f03..174a9dbbcd 100644 --- a/daemon/graphdriver/lcow/lcow_svm.go +++ b/daemon/graphdriver/lcow/lcow_svm.go @@ -208,7 +208,7 @@ func (svm *serviceVM) hotAddVHDsAtStart(mvds ...hcsshim.MappedVirtualDisk) error } if err := svm.config.HotAddVhd(mvd.HostPath, mvd.ContainerPath, mvd.ReadOnly, !mvd.AttachOnly); err != nil { - svm.hotRemoveVHDsAtStart(mvds[:i]...) + svm.hotRemoveVHDsNoLock(mvds[:i]...) return err } svm.attachedVHDs[mvd.HostPath] = 1 @@ -217,17 +217,19 @@ func (svm *serviceVM) hotAddVHDsAtStart(mvds ...hcsshim.MappedVirtualDisk) error } // hotRemoveVHDs waits for the service vm to start and then removes the vhds. +// The service VM must not be locked when calling this function. func (svm *serviceVM) hotRemoveVHDs(mvds ...hcsshim.MappedVirtualDisk) error { if err := svm.getStartError(); err != nil { return err } - return svm.hotRemoveVHDsAtStart(mvds...) -} - -// hotRemoveVHDsAtStart works the same way as hotRemoveVHDs but does not wait for the VM to start. -func (svm *serviceVM) hotRemoveVHDsAtStart(mvds ...hcsshim.MappedVirtualDisk) error { svm.Lock() defer svm.Unlock() + return svm.hotRemoveVHDsNoLock(mvds...) +} + +// hotRemoveVHDsNoLock removes VHDs from a service VM. When calling this function, +// the contract is the service VM lock must be held. +func (svm *serviceVM) hotRemoveVHDsNoLock(mvds ...hcsshim.MappedVirtualDisk) error { var retErr error for _, mvd := range mvds { if _, ok := svm.attachedVHDs[mvd.HostPath]; !ok {