Skip to content

Commit

Permalink
vc: Utilize map for newMounts to speed up replaceOCIMountSource
Browse files Browse the repository at this point in the history
Fixes kata-containers#2212

Signed-off-by: Ted Yu <yuzhihong@gmail.com>
  • Loading branch information
yutedz committed Nov 19, 2019
1 parent c0d2867 commit 9a4ee4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 3 additions & 3 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ func (c *Container) shareFiles(m Mount, idx int, hostSharedDir, guestSharedDir s
// It also updates the container mount list with the HostPath info, and store
// container mounts to the storage. This way, we will have the HostPath info
// available when we will need to unmount those mounts.
func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) ([]Mount, []Mount, error) {
var sharedDirMounts []Mount
func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (map[string]Mount, []Mount, error) {
sharedDirMounts := make(map[string]Mount)
var ignoredMounts []Mount
for idx, m := range c.mounts {
// Skip mounting certain system paths from the source on the host side
Expand Down Expand Up @@ -607,7 +607,7 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (
ReadOnly: readonly,
}

sharedDirMounts = append(sharedDirMounts, sharedDirMount)
sharedDirMounts[sharedDirMount.Destination] = sharedDirMount
}

if !c.sandbox.supportNewStore() {
Expand Down
8 changes: 2 additions & 6 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,15 +962,11 @@ func (k *kataAgent) stopSandbox(sandbox *Sandbox) error {
return nil
}

func (k *kataAgent) replaceOCIMountSource(spec *specs.Spec, guestMounts []Mount) error {
func (k *kataAgent) replaceOCIMountSource(spec *specs.Spec, guestMounts map[string]Mount) error {
ociMounts := spec.Mounts

for index, m := range ociMounts {
for _, guestMount := range guestMounts {
if guestMount.Destination != m.Destination {
continue
}

if guestMount, ok := guestMounts[m.Destination]; ok {
k.Logger().Debugf("Replacing OCI mount (%s) source %s with %s", m.Destination, m.Source, guestMount.Source)
ociMounts[index].Source = guestMount.Source
}
Expand Down

0 comments on commit 9a4ee4f

Please sign in to comment.