Terminate template VMs on layer delete
Signed-off-by: Darren Stahl <darst@microsoft.com> Upstream-commit: c58e8dea6ce1e9ff02c383c1698733fd0554ba2e Component: engine
This commit is contained in:
@@ -244,6 +244,32 @@ func (d *Driver) Remove(id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get and terminate any template VMs that are currently using the layer
|
||||
computeSystems, err := hcsshim.GetContainers(hcsshim.ComputeSystemQuery{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, computeSystem := range computeSystems {
|
||||
if strings.Contains(computeSystem.RuntimeImagePath, id) && computeSystem.IsRuntimeTemplate {
|
||||
container, err := hcsshim.OpenContainer(computeSystem.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer container.Close()
|
||||
err = container.Terminate()
|
||||
if hcsshim.IsPending(err) {
|
||||
err = container.Wait()
|
||||
} else if hcsshim.IsAlreadyStopped(err) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layerPath := filepath.Join(d.info.HomeDir, rID)
|
||||
tmpID := fmt.Sprintf("%s-removing", rID)
|
||||
tmpLayerPath := filepath.Join(d.info.HomeDir, tmpID)
|
||||
|
||||
Reference in New Issue
Block a user