mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-23 05:04:07 +00:00
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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user