diff options
author | Peter Hunt <pehunt@redhat.com> | 2019-07-02 11:40:14 -0400 |
---|---|---|
committer | Peter Hunt <pehunt@redhat.com> | 2019-07-02 15:18:44 -0400 |
commit | aeabc45ccef10fc858677765675bd86944a93db6 (patch) | |
tree | 11629dba0ec30e90dd5c8a3aa728aa06e03fb650 /libpod/container_internal.go | |
parent | 341f5e22e5426e83e20174913fa274809a1f47ca (diff) | |
download | podman-aeabc45ccef10fc858677765675bd86944a93db6.tar.gz podman-aeabc45ccef10fc858677765675bd86944a93db6.tar.bz2 podman-aeabc45ccef10fc858677765675bd86944a93db6.zip |
Improve parsing of mounts
Specifically, we were needlessly doing a double lookup to find which config mounts were user volumes. Improve this by refactoring a bit of code from inspect
Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 43d2b6e61..884f5a0a9 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1534,3 +1534,34 @@ func (c *Container) prepareCheckpointExport() (err error) { return nil } + +// sortUserVolumes sorts the volumes specified for a container +// between named and normal volumes +func (c *Container) sortUserVolumes(ctrSpec *spec.Spec) ([]*ContainerNamedVolume, []spec.Mount) { + namedUserVolumes := []*ContainerNamedVolume{} + userMounts := []spec.Mount{} + + // We need to parse all named volumes and mounts into maps, so we don't + // end up with repeated lookups for each user volume. + // Map destination to struct, as destination is what is stored in + // UserVolumes. + namedVolumes := make(map[string]*ContainerNamedVolume) + mounts := make(map[string]spec.Mount) + for _, namedVol := range c.config.NamedVolumes { + namedVolumes[namedVol.Dest] = namedVol + } + for _, mount := range ctrSpec.Mounts { + mounts[mount.Destination] = mount + } + + for _, vol := range c.config.UserVolumes { + if volume, ok := namedVolumes[vol]; ok { + namedUserVolumes = append(namedUserVolumes, volume) + } else if mount, ok := mounts[vol]; ok { + userMounts = append(userMounts, mount) + } else { + logrus.Warnf("Could not find mount at destination %q when parsing user volumes for container %s", vol, c.ID()) + } + } + return namedUserVolumes, userMounts +} |