Przeglądaj źródła

Windows: Fix unmount for Hyper-V Containers

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 9 lat temu
rodzic
commit
4461bc45b6
1 zmienionych plików z 14 dodań i 15 usunięć
  1. 14 15
      daemon/daemon_windows.go

+ 14 - 15
daemon/daemon_windows.go

@@ -310,25 +310,24 @@ func setupDaemonRoot(config *Config, rootDir string, rootUID, rootGID int) error
 	return nil
 	return nil
 }
 }
 
 
-// conditionalMountOnStart is a platform specific helper function during the
-// container start to call mount.
-func (daemon *Daemon) conditionalMountOnStart(container *container.Container) error {
-
-	// Are we going to run as a Hyper-V container?
-	hv := false
+// runasHyperVContainer returns true if we are going to run as a Hyper-V container
+func (daemon *Daemon) runAsHyperVContainer(container *container.Container) bool {
 	if container.HostConfig.Isolation.IsDefault() {
 	if container.HostConfig.Isolation.IsDefault() {
 		// Container is set to use the default, so take the default from the daemon configuration
 		// Container is set to use the default, so take the default from the daemon configuration
-		hv = daemon.defaultIsolation.IsHyperV()
-	} else {
-		// Container is requesting an isolation mode. Honour it.
-		hv = container.HostConfig.Isolation.IsHyperV()
+		return daemon.defaultIsolation.IsHyperV()
 	}
 	}
 
 
+	// Container is requesting an isolation mode. Honour it.
+	return container.HostConfig.Isolation.IsHyperV()
+
+}
+
+// conditionalMountOnStart is a platform specific helper function during the
+// container start to call mount.
+func (daemon *Daemon) conditionalMountOnStart(container *container.Container) error {
 	// We do not mount if a Hyper-V container
 	// We do not mount if a Hyper-V container
-	if !hv {
-		if err := daemon.Mount(container); err != nil {
-			return err
-		}
+	if !daemon.runAsHyperVContainer(container) {
+		return daemon.Mount(container)
 	}
 	}
 	return nil
 	return nil
 }
 }
@@ -337,7 +336,7 @@ func (daemon *Daemon) conditionalMountOnStart(container *container.Container) er
 // during the cleanup of a container to unmount.
 // during the cleanup of a container to unmount.
 func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) error {
 func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) error {
 	// We do not unmount if a Hyper-V container
 	// We do not unmount if a Hyper-V container
-	if !container.HostConfig.Isolation.IsHyperV() {
+	if !daemon.runAsHyperVContainer(container) {
 		return daemon.Unmount(container)
 		return daemon.Unmount(container)
 	}
 	}
 	return nil
 	return nil