runtime: remove global sandbox variable

Remove global sandbox variable, and save *Sandbox to hypervisor struct.
For some needs, hypervisor may need to use methods from Sandbox.

Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
bin liu
2020-11-04 16:18:09 +08:00
parent 290203943c
commit 4e3a8c0124
19 changed files with 59 additions and 50 deletions

View File

@@ -7,6 +7,7 @@ package virtcontainers
import (
"context"
"fmt"
"runtime"
deviceApi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
@@ -135,26 +136,24 @@ func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, f
// CleanupContainer is used by shimv2 to stop and delete a container exclusively, once there is no container
// in the sandbox left, do stop the sandbox and delete it. Those serial operations will be done exclusively by
// locking the sandbox.
func CleanupContainer(ctx context.Context, sandboxID, containerID string, force bool) error {
func CleanupContainer(ctx context.Context, sandbox VCSandbox, containerID string, force bool) error {
span, ctx := trace(ctx, "CleanupContainer")
defer span.Finish()
if sandboxID == "" {
return vcTypes.ErrNeedSandboxID
}
if containerID == "" {
return vcTypes.ErrNeedContainerID
}
unlock, err := rwLockSandbox(sandboxID)
s, ok := sandbox.(*Sandbox)
if !ok {
return fmt.Errorf("not a Sandbox reference")
}
unlock, err := rwLockSandbox(s.id)
if err != nil {
return err
}
defer unlock()
s := globalSandbox
defer s.Release()
_, err = s.StopContainer(containerID, force)