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>
This commit is contained in:
Cory Snider 2022-10-07 18:47:14 -04:00
parent 84cbe29d5b
commit 4fd91c3f37
3 changed files with 22 additions and 28 deletions

View file

@ -16,11 +16,6 @@ func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, 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)
if err == nil {
return data, nil
@ -40,11 +35,6 @@ func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.C
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)
if err == nil {
return stat, nil
@ -65,11 +55,6 @@ func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io
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)
if err == nil {
return content, stat, nil
@ -93,11 +78,6 @@ func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOve
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)
if err == nil {
return nil

View file

@ -332,9 +332,3 @@ func checkIfPathIsInAVolume(container *container.Container, absPath string) (boo
}
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
}

View file

@ -23,6 +23,11 @@ func (daemon *Daemon) containerStatPath(container *container.Container, path str
container.Lock()
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 {
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 {
return nil, nil, err
}
@ -142,6 +152,11 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
container.Lock()
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 {
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 {
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
// cannot have their file-system interrogated from the host as the filter is
// 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 {
if !container.IsRunning() {
if !container.Running {
return nil
}