mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-10 09:39:24 +00:00
When imported, the vc files carried in the 'full style' apache license text, but the standard for kata is to use SPDX style. Update the relevant files to SPDX. Fixes: #227 Signed-off-by: Graham whaley <graham.whaley@intel.com>
50 lines
976 B
Go
50 lines
976 B
Go
// Copyright (c) 2018 HyperHQ Inc.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package virtcontainers
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
type sandboxList struct {
|
|
lock sync.RWMutex
|
|
sandboxes map[string]*Sandbox
|
|
}
|
|
|
|
// globalSandboxList tracks sandboxes globally
|
|
var globalSandboxList = &sandboxList{sandboxes: make(map[string]*Sandbox)}
|
|
|
|
func (p *sandboxList) addSandbox(sandbox *Sandbox) (err error) {
|
|
if sandbox == nil {
|
|
return nil
|
|
}
|
|
|
|
p.lock.Lock()
|
|
defer p.lock.Unlock()
|
|
if p.sandboxes[sandbox.id] == nil {
|
|
p.sandboxes[sandbox.id] = sandbox
|
|
} else {
|
|
err = fmt.Errorf("sandbox %s exists", sandbox.id)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (p *sandboxList) removeSandbox(id string) {
|
|
p.lock.Lock()
|
|
defer p.lock.Unlock()
|
|
delete(p.sandboxes, id)
|
|
}
|
|
|
|
func (p *sandboxList) lookupSandbox(id string) (*Sandbox, error) {
|
|
p.lock.RLock()
|
|
defer p.lock.RUnlock()
|
|
if p.sandboxes[id] != nil {
|
|
return p.sandboxes[id], nil
|
|
}
|
|
return nil, fmt.Errorf("sandbox %s does not exist", id)
|
|
}
|