mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
container.NetworkMounts(): don't lookup mounts twice
The code in question looks up mounts two times: first by using HasMountFor(), and then directly by looking in container.MountPoints. There is no need to do it twice. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
9de84a78d7
commit
eab3ac3e70
1 changed files with 6 additions and 9 deletions
|
@ -65,12 +65,11 @@ func (container *Container) NetworkMounts() []Mount {
|
||||||
if _, err := os.Stat(container.ResolvConfPath); err != nil {
|
if _, err := os.Stat(container.ResolvConfPath); err != nil {
|
||||||
logrus.Warnf("ResolvConfPath set to %q, but can't stat this filename (err = %v); skipping", container.ResolvConfPath, err)
|
logrus.Warnf("ResolvConfPath set to %q, but can't stat this filename (err = %v); skipping", container.ResolvConfPath, err)
|
||||||
} else {
|
} else {
|
||||||
if !container.HasMountFor("/etc/resolv.conf") {
|
|
||||||
label.Relabel(container.ResolvConfPath, container.MountLabel, shared)
|
|
||||||
}
|
|
||||||
writable := !container.HostConfig.ReadonlyRootfs
|
writable := !container.HostConfig.ReadonlyRootfs
|
||||||
if m, exists := container.MountPoints["/etc/resolv.conf"]; exists {
|
if m, exists := container.MountPoints["/etc/resolv.conf"]; exists {
|
||||||
writable = m.RW
|
writable = m.RW
|
||||||
|
} else {
|
||||||
|
label.Relabel(container.ResolvConfPath, container.MountLabel, shared)
|
||||||
}
|
}
|
||||||
mounts = append(mounts, Mount{
|
mounts = append(mounts, Mount{
|
||||||
Source: container.ResolvConfPath,
|
Source: container.ResolvConfPath,
|
||||||
|
@ -84,12 +83,11 @@ func (container *Container) NetworkMounts() []Mount {
|
||||||
if _, err := os.Stat(container.HostnamePath); err != nil {
|
if _, err := os.Stat(container.HostnamePath); err != nil {
|
||||||
logrus.Warnf("HostnamePath set to %q, but can't stat this filename (err = %v); skipping", container.HostnamePath, err)
|
logrus.Warnf("HostnamePath set to %q, but can't stat this filename (err = %v); skipping", container.HostnamePath, err)
|
||||||
} else {
|
} else {
|
||||||
if !container.HasMountFor("/etc/hostname") {
|
|
||||||
label.Relabel(container.HostnamePath, container.MountLabel, shared)
|
|
||||||
}
|
|
||||||
writable := !container.HostConfig.ReadonlyRootfs
|
writable := !container.HostConfig.ReadonlyRootfs
|
||||||
if m, exists := container.MountPoints["/etc/hostname"]; exists {
|
if m, exists := container.MountPoints["/etc/hostname"]; exists {
|
||||||
writable = m.RW
|
writable = m.RW
|
||||||
|
} else {
|
||||||
|
label.Relabel(container.HostnamePath, container.MountLabel, shared)
|
||||||
}
|
}
|
||||||
mounts = append(mounts, Mount{
|
mounts = append(mounts, Mount{
|
||||||
Source: container.HostnamePath,
|
Source: container.HostnamePath,
|
||||||
|
@ -103,12 +101,11 @@ func (container *Container) NetworkMounts() []Mount {
|
||||||
if _, err := os.Stat(container.HostsPath); err != nil {
|
if _, err := os.Stat(container.HostsPath); err != nil {
|
||||||
logrus.Warnf("HostsPath set to %q, but can't stat this filename (err = %v); skipping", container.HostsPath, err)
|
logrus.Warnf("HostsPath set to %q, but can't stat this filename (err = %v); skipping", container.HostsPath, err)
|
||||||
} else {
|
} else {
|
||||||
if !container.HasMountFor("/etc/hosts") {
|
|
||||||
label.Relabel(container.HostsPath, container.MountLabel, shared)
|
|
||||||
}
|
|
||||||
writable := !container.HostConfig.ReadonlyRootfs
|
writable := !container.HostConfig.ReadonlyRootfs
|
||||||
if m, exists := container.MountPoints["/etc/hosts"]; exists {
|
if m, exists := container.MountPoints["/etc/hosts"]; exists {
|
||||||
writable = m.RW
|
writable = m.RW
|
||||||
|
} else {
|
||||||
|
label.Relabel(container.HostsPath, container.MountLabel, shared)
|
||||||
}
|
}
|
||||||
mounts = append(mounts, Mount{
|
mounts = append(mounts, Mount{
|
||||||
Source: container.HostsPath,
|
Source: container.HostsPath,
|
||||||
|
|
Loading…
Add table
Reference in a new issue