From 34f23de512f4499b7e8edf46159dc16ce19d2196 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Tue, 9 Nov 2021 11:31:44 -0800 Subject: [PATCH] vc: hypervisor: Remove need to get shared address from sandbox Add shared path as part of the hypervisor config Signed-off-by: Eric Ernst --- src/runtime/pkg/katautils/create.go | 3 +++ src/runtime/virtcontainers/clh.go | 2 +- src/runtime/virtcontainers/hypervisor.go | 13 ++++++++----- src/runtime/virtcontainers/kata_agent.go | 2 +- src/runtime/virtcontainers/qemu.go | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/runtime/pkg/katautils/create.go b/src/runtime/pkg/katautils/create.go index fc593c6712..dd7056214a 100644 --- a/src/runtime/pkg/katautils/create.go +++ b/src/runtime/pkg/katautils/create.go @@ -120,6 +120,9 @@ func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec specs.Spec, runtimeCo return nil, vc.Process{}, err } + // setup shared path in hypervisor config: + sandboxConfig.HypervisorConfig.SharedPath = vc.GetSharePath(containerID) + if err := checkForFIPS(&sandboxConfig); err != nil { return nil, vc.Process{}, err } diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index 9236c832cd..315cb599f5 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -226,7 +226,7 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, networkNS N clh.Logger().WithField("function", "CreateVM").Info("Sandbox already exist, loading from state") clh.virtiofsd = &virtiofsd{ PID: clh.state.VirtiofsdPID, - sourcePath: filepath.Join(getSharePath(clh.id)), + sourcePath: hypervisorConfig.SharedPath, debug: clh.config.Debug, socketPath: virtiofsdSocketPath, } diff --git a/src/runtime/virtcontainers/hypervisor.go b/src/runtime/virtcontainers/hypervisor.go index 0186c397ed..bc22a17112 100644 --- a/src/runtime/virtcontainers/hypervisor.go +++ b/src/runtime/virtcontainers/hypervisor.go @@ -315,13 +315,19 @@ type HypervisorConfig struct { EntropySource string // Shared file system type: - // - virtio-9p (default) - // - virtio-fs + // - virtio-9p + // - virtio-fs (default) SharedFS string + // Path for filesystem sharing + SharedPath string + // VirtioFSDaemon is the virtio-fs vhost-user daemon path VirtioFSDaemon string + // VirtioFSCache cache mode for fs version cache or "none" + VirtioFSCache string + // File based memory backend root directory FileBackedMemRootDir string @@ -342,9 +348,6 @@ type HypervisorConfig struct { // SELinux label for the VM SELinuxProcessLabel string - // VirtioFSCache cache mode for fs version cache or "none" - VirtioFSCache string - // HypervisorPathList is the list of hypervisor paths names allowed in annotations HypervisorPathList []string diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index 3562c9216b..b604917b2c 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -162,7 +162,7 @@ var kataHostSharedDir = func() string { // 2. /run/kata-containers/shared/sandboxes/$sbx_id/mounts/ is bind mounted readonly to /run/kata-containers/shared/sandboxes/$sbx_id/shared/, so guest cannot modify it // // 3. host-guest shared files/directories are mounted one-level under /run/kata-containers/shared/sandboxes/$sbx_id/mounts/ and thus present to guest at one level under /run/kata-containers/shared/sandboxes/$sbx_id/shared/ -func getSharePath(id string) string { +func GetSharePath(id string) string { return filepath.Join(kataHostSharedDir(), id, "shared") } diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 29cd0d1731..8db487a809 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -655,7 +655,7 @@ func (q *qemu) CreateVM(ctx context.Context, id string, networkNS NetworkNamespa q.virtiofsd = &virtiofsd{ path: q.config.VirtioFSDaemon, - sourcePath: filepath.Join(getSharePath(q.id)), + sourcePath: hypervisorConfig.SharedPath, socketPath: virtiofsdSocketPath, extraArgs: q.config.VirtioFSExtraArgs, debug: q.config.Debug,