Sfoglia il codice sorgente

daemon: refactor isOnlineFSOperationPermitted

It is only applicable to Windows so it does not need to be called from
platform-generic code. Fix locking in the Windows implementation.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider 2 anni fa
parent
commit
4fd91c3f37
3 ha cambiato i file con 22 aggiunte e 28 eliminazioni
  1. 0 20
      daemon/archive.go
  2. 0 6
      daemon/archive_unix.go
  3. 22 2
      daemon/archive_windows.go

+ 0 - 20
daemon/archive.go

@@ -16,11 +16,6 @@ func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, err
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	// Make sure an online file-system operation is permitted.
-	if err := daemon.isOnlineFSOperationPermitted(ctr); err != nil {
-		return nil, errdefs.System(err)
-	}
-
 	data, err := daemon.containerCopy(ctr, res)
 	data, err := daemon.containerCopy(ctr, res)
 	if err == nil {
 	if err == nil {
 		return data, nil
 		return data, nil
@@ -40,11 +35,6 @@ func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.C
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	// Make sure an online file-system operation is permitted.
-	if err := daemon.isOnlineFSOperationPermitted(ctr); err != nil {
-		return nil, errdefs.System(err)
-	}
-
 	stat, err = daemon.containerStatPath(ctr, path)
 	stat, err = daemon.containerStatPath(ctr, path)
 	if err == nil {
 	if err == nil {
 		return stat, nil
 		return stat, nil
@@ -65,11 +55,6 @@ func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io
 		return nil, nil, err
 		return nil, nil, err
 	}
 	}
 
 
-	// Make sure an online file-system operation is permitted.
-	if err := daemon.isOnlineFSOperationPermitted(ctr); err != nil {
-		return nil, nil, errdefs.System(err)
-	}
-
 	content, stat, err = daemon.containerArchivePath(ctr, path)
 	content, stat, err = daemon.containerArchivePath(ctr, path)
 	if err == nil {
 	if err == nil {
 		return content, stat, nil
 		return content, stat, nil
@@ -93,11 +78,6 @@ func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOve
 		return err
 		return err
 	}
 	}
 
 
-	// Make sure an online file-system operation is permitted.
-	if err := daemon.isOnlineFSOperationPermitted(ctr); err != nil {
-		return errdefs.System(err)
-	}
-
 	err = daemon.containerExtractToDir(ctr, path, copyUIDGID, noOverwriteDirNonDir, content)
 	err = daemon.containerExtractToDir(ctr, path, copyUIDGID, noOverwriteDirNonDir, content)
 	if err == nil {
 	if err == nil {
 		return nil
 		return nil

+ 0 - 6
daemon/archive_unix.go

@@ -332,9 +332,3 @@ func checkIfPathIsInAVolume(container *container.Container, absPath string) (boo
 	}
 	}
 	return toVolume, nil
 	return toVolume, nil
 }
 }
-
-// isOnlineFSOperationPermitted returns an error if an online filesystem operation
-// is not permitted.
-func (daemon *Daemon) isOnlineFSOperationPermitted(container *container.Container) error {
-	return nil
-}

+ 22 - 2
daemon/archive_windows.go

@@ -23,6 +23,11 @@ func (daemon *Daemon) containerStatPath(container *container.Container, path str
 	container.Lock()
 	container.Lock()
 	defer container.Unlock()
 	defer container.Unlock()
 
 
+	// Make sure an online file-system operation is permitted.
+	if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
+		return nil, err
+	}
+
 	if err = daemon.Mount(container); err != nil {
 	if err = daemon.Mount(container); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -60,6 +65,11 @@ func (daemon *Daemon) containerArchivePath(container *container.Container, path
 		}
 		}
 	}()
 	}()
 
 
+	// Make sure an online file-system operation is permitted.
+	if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
+		return nil, nil, err
+	}
+
 	if err = daemon.Mount(container); err != nil {
 	if err = daemon.Mount(container); err != nil {
 		return nil, nil, err
 		return nil, nil, err
 	}
 	}
@@ -142,6 +152,11 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
 	container.Lock()
 	container.Lock()
 	defer container.Unlock()
 	defer container.Unlock()
 
 
+	// Make sure an online file-system operation is permitted.
+	if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
+		return err
+	}
+
 	if err = daemon.Mount(container); err != nil {
 	if err = daemon.Mount(container); err != nil {
 		return err
 		return err
 	}
 	}
@@ -260,6 +275,11 @@ func (daemon *Daemon) containerCopy(container *container.Container, resource str
 		}
 		}
 	}()
 	}()
 
 
+	// Make sure an online file-system operation is permitted.
+	if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
+		return nil, err
+	}
+
 	if err := daemon.Mount(container); err != nil {
 	if err := daemon.Mount(container); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -327,9 +347,9 @@ func checkIfPathIsInAVolume(container *container.Container, absPath string) (boo
 // is not permitted (such as stat or for copying). Running Hyper-V containers
 // is not permitted (such as stat or for copying). Running Hyper-V containers
 // cannot have their file-system interrogated from the host as the filter is
 // cannot have their file-system interrogated from the host as the filter is
 // loaded inside the utility VM, not the host.
 // loaded inside the utility VM, not the host.
-// IMPORTANT: The container lock must NOT be held when calling this function.
+// IMPORTANT: The container lock MUST be held when calling this function.
 func (daemon *Daemon) isOnlineFSOperationPermitted(container *container.Container) error {
 func (daemon *Daemon) isOnlineFSOperationPermitted(container *container.Container) error {
-	if !container.IsRunning() {
+	if !container.Running {
 		return nil
 		return nil
 	}
 	}