mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-18 07:18:27 +00:00
Merge pull request #2189 from liubin/2187
Update outdated comments and do some minor reworks
This commit is contained in:
@@ -63,7 +63,7 @@ func (endpoint *BridgedMacvlanEndpoint) HardwareAddr() string {
|
||||
return endpoint.NetPair.TAPIface.HardAddr
|
||||
}
|
||||
|
||||
// Type identifies the endpoint as a virtual endpoint.
|
||||
// Type identifies the endpoint as a bridged macvlan endpoint.
|
||||
func (endpoint *BridgedMacvlanEndpoint) Type() EndpointType {
|
||||
return endpoint.EndpointType
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (endpoint *BridgedMacvlanEndpoint) Attach(ctx context.Context, s *Sandbox)
|
||||
|
||||
h := s.hypervisor
|
||||
if err := xConnectVMNetwork(ctx, endpoint, h); err != nil {
|
||||
networkLogger().WithError(err).Error("Error bridging virtual ep")
|
||||
networkLogger().WithError(err).Error("Error bridging bridged macvlan ep")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -120,12 +120,12 @@ func (endpoint *BridgedMacvlanEndpoint) Detach(ctx context.Context, netNsCreated
|
||||
})
|
||||
}
|
||||
|
||||
// HotAttach for physical endpoint not supported yet
|
||||
// HotAttach for bridged macvlan endpoint not supported yet
|
||||
func (endpoint *BridgedMacvlanEndpoint) HotAttach(ctx context.Context, h hypervisor) error {
|
||||
return fmt.Errorf("BridgedMacvlanEndpoint does not support Hot attach")
|
||||
}
|
||||
|
||||
// HotDetach for physical endpoint not supported yet
|
||||
// HotDetach for bridged macvlan endpoint not supported yet
|
||||
func (endpoint *BridgedMacvlanEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error {
|
||||
return fmt.Errorf("BridgedMacvlanEndpoint does not support Hot detach")
|
||||
}
|
||||
|
@@ -91,7 +91,7 @@ func PmemDeviceInfo(source, destination string) (*DeviceInfo, error) {
|
||||
// required to use it as PMEM device and enable DAX.
|
||||
// See [1] to know more about the PFN signature.
|
||||
//
|
||||
// [1] - https://github.com/kata-containers/osbuilder/blob/master/image-builder/nsdax.gpl.c
|
||||
// [1] - https://github.com/kata-containers/kata-containers/blob/main/tools/osbuilder/image-builder/nsdax.gpl.c
|
||||
func hasPFNSignature(path string) bool {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
|
@@ -46,11 +46,9 @@ func deviceLogger() *logrus.Entry {
|
||||
return api.DeviceLogger()
|
||||
}
|
||||
|
||||
/*
|
||||
Identify PCIe device by /sys/bus/pci/slots/xx/max_bus_speed, sample content "8.0 GT/s PCIe"
|
||||
The /sys/bus/pci/slots/xx/address contains bdf, sample content "0000:04:00"
|
||||
bdf format: bus:slot.function
|
||||
*/
|
||||
// Identify PCIe device by /sys/bus/pci/slots/xx/max_bus_speed, sample content "8.0 GT/s PCIe"
|
||||
// The /sys/bus/pci/slots/xx/address contains bdf, sample content "0000:04:00"
|
||||
// bdf format: bus:slot.function
|
||||
func isPCIeDevice(bdf string) bool {
|
||||
if len(strings.Split(bdf, ":")) == 2 {
|
||||
bdf = PCIDomain + ":" + bdf
|
||||
@@ -59,11 +57,11 @@ func isPCIeDevice(bdf string) bool {
|
||||
configPath := filepath.Join(config.SysBusPciDevicesPath, bdf, "config")
|
||||
fi, err := os.Stat(configPath)
|
||||
if err != nil {
|
||||
deviceLogger().WithField("dev-bdf", bdf).WithField("error", err).Warning("Couldn't stat() configuration space file")
|
||||
deviceLogger().WithField("dev-bdf", bdf).WithError(err).Warning("Couldn't stat() configuration space file")
|
||||
return false //Who knows?
|
||||
}
|
||||
|
||||
// Plain PCI devices hav 256 bytes of configuration space,
|
||||
// Plain PCI devices have 256 bytes of configuration space,
|
||||
// PCI-Express devices have 4096 bytes
|
||||
return fi.Size() > PCIConfigSpaceSize
|
||||
}
|
||||
|
@@ -288,7 +288,7 @@ func BindDevicetoVFIO(bdf, hostDriver, vendorDeviceID string) (string, error) {
|
||||
return fmt.Sprintf(vfioDevPath, filepath.Base(groupPath)), nil
|
||||
}
|
||||
|
||||
// BindDevicetoHost binds the device to the host driver driver after unbinding from vfio-pci.
|
||||
// BindDevicetoHost binds the device to the host driver after unbinding from vfio-pci.
|
||||
func BindDevicetoHost(bdf, hostDriver, vendorDeviceID string) error {
|
||||
// Unbind from vfio-pci driver
|
||||
unbindDriverPath := fmt.Sprintf(pciDriverUnbindPath, bdf)
|
||||
|
@@ -57,7 +57,7 @@ type deviceManager struct {
|
||||
}
|
||||
|
||||
func deviceLogger() *logrus.Entry {
|
||||
return api.DeviceLogger().WithField("subsystem", "device")
|
||||
return api.DeviceLogger().WithField("subsystem", "deviceManager")
|
||||
}
|
||||
|
||||
// NewDeviceManager creates a deviceManager object behaved as api.DeviceManager
|
||||
@@ -252,7 +252,7 @@ func (dm *deviceManager) IsDeviceAttached(id string) bool {
|
||||
return d.GetAttachCount() > 0
|
||||
}
|
||||
|
||||
// NewDevice creates a device based on specified DeviceInfo
|
||||
// LoadDevices load devices from persist state
|
||||
func (dm *deviceManager) LoadDevices(devStates []persistapi.DeviceState) {
|
||||
dm.Lock()
|
||||
defer dm.Unlock()
|
||||
|
@@ -563,42 +563,43 @@ type VCSandbox interface {
|
||||
ID() string
|
||||
SetAnnotations(annotations map[string]string) error
|
||||
|
||||
Stats() (SandboxStats, error)
|
||||
Stats(ctx context.Context) (SandboxStats, error)
|
||||
|
||||
Start() error
|
||||
Stop(force bool) error
|
||||
Release() error
|
||||
Monitor() (chan error, error)
|
||||
Delete() error
|
||||
Start(ctx context.Context) error
|
||||
Stop(ctx context.Context, force bool) error
|
||||
Release(ctx context.Context) error
|
||||
Monitor(ctx context.Context) (chan error, error)
|
||||
Delete(ctx context.Context) error
|
||||
Status() SandboxStatus
|
||||
CreateContainer(contConfig ContainerConfig) (VCContainer, error)
|
||||
DeleteContainer(containerID string) (VCContainer, error)
|
||||
StartContainer(containerID string) (VCContainer, error)
|
||||
StopContainer(containerID string, force bool) (VCContainer, error)
|
||||
KillContainer(containerID string, signal syscall.Signal, all bool) error
|
||||
CreateContainer(ctx context.Context, contConfig ContainerConfig) (VCContainer, error)
|
||||
DeleteContainer(ctx context.Context, containerID string) (VCContainer, error)
|
||||
StartContainer(ctx context.Context, containerID string) (VCContainer, error)
|
||||
StopContainer(ctx context.Context, containerID string, force bool) (VCContainer, error)
|
||||
KillContainer(ctx context.Context, containerID string, signal syscall.Signal, all bool) error
|
||||
StatusContainer(containerID string) (ContainerStatus, error)
|
||||
StatsContainer(containerID string) (ContainerStats, error)
|
||||
PauseContainer(containerID string) error
|
||||
ResumeContainer(containerID string) error
|
||||
EnterContainer(containerID string, cmd types.Cmd) (VCContainer, *Process, error)
|
||||
UpdateContainer(containerID string, resources specs.LinuxResources) error
|
||||
WaitProcess(containerID, processID string) (int32, error)
|
||||
SignalProcess(containerID, processID string, signal syscall.Signal, all bool) error
|
||||
WinsizeProcess(containerID, processID string, height, width uint32) error
|
||||
StatsContainer(ctx context.Context, containerID string) (ContainerStats, error)
|
||||
PauseContainer(ctx context.Context, containerID string) error
|
||||
ResumeContainer(ctx context.Context, containerID string) error
|
||||
EnterContainer(ctx context.Context, containerID string, cmd types.Cmd) (VCContainer, *Process, error)
|
||||
UpdateContainer(ctx context.Context, containerID string, resources specs.LinuxResources) error
|
||||
WaitProcess(ctx context.Context, containerID, processID string) (int32, error)
|
||||
SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal, all bool) error
|
||||
WinsizeProcess(ctx context.Context, containerID, processID string, height, width uint32) error
|
||||
IOStream(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error)
|
||||
|
||||
AddDevice(info config.DeviceInfo) (api.Device, error)
|
||||
AddDevice(ctx context.Context, info config.DeviceInfo) (api.Device, error)
|
||||
|
||||
AddInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
RemoveInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
ListInterfaces() ([]*pbTypes.Interface, error)
|
||||
UpdateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error)
|
||||
ListRoutes() ([]*pbTypes.Route, error)
|
||||
AddInterface(ctx context.Context, inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
RemoveInterface(ctx context.Context, inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
ListInterfaces(ctx context.Context) ([]*pbTypes.Interface, error)
|
||||
UpdateRoutes(ctx context.Context, routes []*pbTypes.Route) ([]*pbTypes.Route, error)
|
||||
ListRoutes(ctx context.Context) ([]*pbTypes.Route, error)
|
||||
|
||||
GetOOMEvent() (string, error)
|
||||
GetOOMEvent(ctx context.Context) (string, error)
|
||||
GetHypervisorPid() (int, error)
|
||||
|
||||
UpdateRuntimeMetrics() error
|
||||
GetAgentMetrics() (string, error)
|
||||
GetAgentMetrics(ctx context.Context) (string, error)
|
||||
GetAgentURL() (string, error)
|
||||
}
|
||||
```
|
||||
@@ -614,7 +615,7 @@ type VCSandbox interface {
|
||||
```Go
|
||||
// CreateSandbox is the virtcontainers sandbox creation entry point.
|
||||
// CreateSandbox creates a sandbox and its containers. It does not start them.
|
||||
func CreateSandbox(sandboxConfig SandboxConfig) (VCSandbox, error)
|
||||
func CreateSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error)
|
||||
```
|
||||
|
||||
#### `CleanupContainer`
|
||||
@@ -928,7 +929,7 @@ type VCContainer interface {
|
||||
```Go
|
||||
// CreateContainer is the virtcontainers container creation entry point.
|
||||
// CreateContainer creates a container on a given sandbox.
|
||||
func CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error)
|
||||
func CreateContainer(ctx context.Context, contConfig ContainerConfig) (VCContainer, error)
|
||||
```
|
||||
|
||||
#### `DeleteContainer`
|
||||
@@ -936,35 +937,35 @@ func CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandb
|
||||
// DeleteContainer is the virtcontainers container deletion entry point.
|
||||
// DeleteContainer deletes a Container from a Sandbox. If the container is running,
|
||||
// it needs to be stopped first.
|
||||
func DeleteContainer(sandboxID, containerID string) (VCContainer, error)
|
||||
func DeleteContainer(ctx context.Context, containerID string) (VCContainer, error)
|
||||
```
|
||||
|
||||
#### `StartContainer`
|
||||
```Go
|
||||
// StartContainer is the virtcontainers container starting entry point.
|
||||
// StartContainer starts an already created container.
|
||||
func StartContainer(sandboxID, containerID string) (VCContainer, error)
|
||||
func StartContainer(ctx context.Context, containerID string) (VCContainer, error)
|
||||
```
|
||||
|
||||
#### `StopContainer`
|
||||
```Go
|
||||
// StopContainer is the virtcontainers container stopping entry point.
|
||||
// StopContainer stops an already running container.
|
||||
func StopContainer(sandboxID, containerID string) (VCContainer, error)
|
||||
func StopContainer(ctx context.Context, containerID string, force bool) (VCContainer, error)
|
||||
```
|
||||
|
||||
#### `EnterContainer`
|
||||
```Go
|
||||
// EnterContainer is the virtcontainers container command execution entry point.
|
||||
// EnterContainer enters an already running container and runs a given command.
|
||||
func EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error)
|
||||
func EnterContainer(ctx context.Context, containerID string, cmd types.Cmd) (VCContainer, *Process, error)
|
||||
```
|
||||
|
||||
#### `StatusContainer`
|
||||
```Go
|
||||
// StatusContainer is the virtcontainers container status entry point.
|
||||
// StatusContainer returns a detailed container status.
|
||||
func StatusContainer(sandboxID, containerID string) (ContainerStatus, error)
|
||||
func StatusContainer(containerID string) (ContainerStatus, error)
|
||||
```
|
||||
|
||||
#### `KillContainer`
|
||||
@@ -972,50 +973,50 @@ func StatusContainer(sandboxID, containerID string) (ContainerStatus, error)
|
||||
// KillContainer is the virtcontainers entry point to send a signal
|
||||
// to a container running inside a sandbox. If all is true, all processes in
|
||||
// the container will be sent the signal.
|
||||
func KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error
|
||||
func KillContainer(ctx context.Context, containerID string, signal syscall.Signal, all bool) error
|
||||
```
|
||||
|
||||
#### `StatsContainer`
|
||||
```Go
|
||||
// StatsContainer return the stats of a running container
|
||||
func StatsContainer(containerID string) (ContainerStats, error)
|
||||
func StatsContainer(ctx context.Context, containerID string) (ContainerStats, error)
|
||||
```
|
||||
|
||||
#### `PauseContainer`
|
||||
```Go
|
||||
// PauseContainer pauses a running container.
|
||||
func PauseContainer(containerID string) error
|
||||
func PauseContainer(ctx context.Context, containerID string) error
|
||||
```
|
||||
|
||||
#### `ResumeContainer`
|
||||
```Go
|
||||
// ResumeContainer resumes a paused container.
|
||||
func ResumeContainer(containerID string) error
|
||||
func ResumeContainer(ctx context.Context, containerID string) error
|
||||
```
|
||||
|
||||
#### `UpdateContainer`
|
||||
```Go
|
||||
// UpdateContainer update a running container.
|
||||
func UpdateContainer(containerID string, resources specs.LinuxResources) error
|
||||
func UpdateContainer(ctx context.Context, containerID string, resources specs.LinuxResources) error
|
||||
```
|
||||
|
||||
#### `WaitProcess`
|
||||
```Go
|
||||
// WaitProcess waits on a container process and return its exit code
|
||||
func WaitProcess(containerID, processID string) (int32, error)
|
||||
func WaitProcess(ctx context.Context, containerID, processID string) (int32, error)
|
||||
```
|
||||
|
||||
#### `SignalProcess`
|
||||
```Go
|
||||
// SignalProcess sends a signal to a process of a container when all is false.
|
||||
// When all is true, it sends the signal to all processes of a container.
|
||||
func SignalProcess(containerID, processID string, signal syscall.Signal, all bool) error
|
||||
func SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal, all bool) error
|
||||
```
|
||||
|
||||
#### `WinsizeProcess`
|
||||
```Go
|
||||
// WinsizeProcess resizes the tty window of a process
|
||||
func WinsizeProcess(containerID, processID string, height, width uint32) error
|
||||
func WinsizeProcess(ctx context.Context, containerID, processID string, height, width uint32) error
|
||||
```
|
||||
|
||||
#### `IOStream`
|
||||
|
@@ -66,7 +66,7 @@ func (endpoint *IPVlanEndpoint) HardwareAddr() string {
|
||||
return endpoint.NetPair.TAPIface.HardAddr
|
||||
}
|
||||
|
||||
// Type identifies the endpoint as a virtual endpoint.
|
||||
// Type identifies the endpoint as a ipvlan endpoint.
|
||||
func (endpoint *IPVlanEndpoint) Type() EndpointType {
|
||||
return endpoint.EndpointType
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func (endpoint *IPVlanEndpoint) NetworkPair() *NetworkInterfacePair {
|
||||
return &endpoint.NetPair
|
||||
}
|
||||
|
||||
// Attach for virtual endpoint bridges the network pair and adds the
|
||||
// Attach for ipvlan endpoint bridges the network pair and adds the
|
||||
// tap interface of the network pair to the hypervisor.
|
||||
func (endpoint *IPVlanEndpoint) Attach(ctx context.Context, s *Sandbox) error {
|
||||
span, ctx := ipvlanTrace(ctx, "Attach", endpoint)
|
||||
@@ -99,14 +99,14 @@ func (endpoint *IPVlanEndpoint) Attach(ctx context.Context, s *Sandbox) error {
|
||||
|
||||
h := s.hypervisor
|
||||
if err := xConnectVMNetwork(ctx, endpoint, h); err != nil {
|
||||
networkLogger().WithError(err).Error("Error bridging virtual ep")
|
||||
networkLogger().WithError(err).Error("Error bridging ipvlan ep")
|
||||
return err
|
||||
}
|
||||
|
||||
return h.addDevice(ctx, endpoint, netDev)
|
||||
}
|
||||
|
||||
// Detach for the virtual endpoint tears down the tap and bridge
|
||||
// Detach for the ipvlan endpoint tears down the tap and bridge
|
||||
// created for the veth interface.
|
||||
func (endpoint *IPVlanEndpoint) Detach(ctx context.Context, netNsCreated bool, netNsPath string) error {
|
||||
// The network namespace would have been deleted at this point
|
||||
@@ -123,12 +123,12 @@ func (endpoint *IPVlanEndpoint) Detach(ctx context.Context, netNsCreated bool, n
|
||||
})
|
||||
}
|
||||
|
||||
// HotAttach for physical endpoint not supported yet
|
||||
// HotAttach for ipvlan endpoint not supported yet
|
||||
func (endpoint *IPVlanEndpoint) HotAttach(ctx context.Context, h hypervisor) error {
|
||||
return fmt.Errorf("IPVlanEndpoint does not support Hot attach")
|
||||
}
|
||||
|
||||
// HotDetach for physical endpoint not supported yet
|
||||
// HotDetach for ipvlan endpoint not supported yet
|
||||
func (endpoint *IPVlanEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error {
|
||||
return fmt.Errorf("IPVlanEndpoint does not support Hot detach")
|
||||
}
|
||||
|
@@ -65,6 +65,10 @@ const (
|
||||
DirMode = os.FileMode(0750) | os.ModeDir
|
||||
)
|
||||
|
||||
var (
|
||||
errSandboxNotRunning = errors.New("Sandbox not running")
|
||||
)
|
||||
|
||||
// SandboxStatus describes a sandbox status.
|
||||
type SandboxStatus struct {
|
||||
ID string
|
||||
@@ -319,7 +323,7 @@ func (s *Sandbox) Status() SandboxStatus {
|
||||
// Monitor returns a error channel for watcher to watch at
|
||||
func (s *Sandbox) Monitor(ctx context.Context) (chan error, error) {
|
||||
if s.state.State != types.StateRunning {
|
||||
return nil, fmt.Errorf("Sandbox is not running")
|
||||
return nil, errSandboxNotRunning
|
||||
}
|
||||
|
||||
s.Lock()
|
||||
@@ -334,7 +338,7 @@ func (s *Sandbox) Monitor(ctx context.Context) (chan error, error) {
|
||||
// WaitProcess waits on a container process and return its exit code
|
||||
func (s *Sandbox) WaitProcess(ctx context.Context, containerID, processID string) (int32, error) {
|
||||
if s.state.State != types.StateRunning {
|
||||
return 0, fmt.Errorf("Sandbox not running")
|
||||
return 0, errSandboxNotRunning
|
||||
}
|
||||
|
||||
c, err := s.findContainer(containerID)
|
||||
@@ -349,7 +353,7 @@ func (s *Sandbox) WaitProcess(ctx context.Context, containerID, processID string
|
||||
// When all is true, it sends the signal to all processes of a container.
|
||||
func (s *Sandbox) SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal, all bool) error {
|
||||
if s.state.State != types.StateRunning {
|
||||
return fmt.Errorf("Sandbox not running")
|
||||
return errSandboxNotRunning
|
||||
}
|
||||
|
||||
c, err := s.findContainer(containerID)
|
||||
@@ -363,7 +367,7 @@ func (s *Sandbox) SignalProcess(ctx context.Context, containerID, processID stri
|
||||
// WinsizeProcess resizes the tty window of a process
|
||||
func (s *Sandbox) WinsizeProcess(ctx context.Context, containerID, processID string, height, width uint32) error {
|
||||
if s.state.State != types.StateRunning {
|
||||
return fmt.Errorf("Sandbox not running")
|
||||
return errSandboxNotRunning
|
||||
}
|
||||
|
||||
c, err := s.findContainer(containerID)
|
||||
@@ -377,7 +381,7 @@ func (s *Sandbox) WinsizeProcess(ctx context.Context, containerID, processID str
|
||||
// IOStream returns stdin writer, stdout reader and stderr reader of a process
|
||||
func (s *Sandbox) IOStream(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error) {
|
||||
if s.state.State != types.StateRunning {
|
||||
return nil, nil, nil, fmt.Errorf("Sandbox not running")
|
||||
return nil, nil, nil, errSandboxNotRunning
|
||||
}
|
||||
|
||||
c, err := s.findContainer(containerID)
|
||||
@@ -1122,8 +1126,7 @@ func (s *Sandbox) CreateContainer(ctx context.Context, contConfig ContainerConfi
|
||||
}
|
||||
|
||||
// create and start the container
|
||||
err = c.create(ctx)
|
||||
if err != nil {
|
||||
if err = c.create(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1138,8 +1141,8 @@ func (s *Sandbox) CreateContainer(ctx context.Context, contConfig ContainerConfi
|
||||
logger := s.Logger().WithFields(logrus.Fields{"container-id": c.id, "sandox-id": s.id, "rollback": true})
|
||||
logger.WithError(err).Error("Cleaning up partially created container")
|
||||
|
||||
if err2 := c.stop(ctx, true); err2 != nil {
|
||||
logger.WithError(err2).Error("Could not delete container")
|
||||
if errStop := c.stop(ctx, true); errStop != nil {
|
||||
logger.WithError(errStop).Error("Could not stop container")
|
||||
}
|
||||
|
||||
logger.Debug("Removing stopped container from sandbox store")
|
||||
@@ -1150,8 +1153,7 @@ func (s *Sandbox) CreateContainer(ctx context.Context, contConfig ContainerConfi
|
||||
// Sandbox is responsible to update VM resources needed by Containers
|
||||
// Update resources after having added containers to the sandbox, since
|
||||
// container status is requiered to know if more resources should be added.
|
||||
err = s.updateResources(ctx)
|
||||
if err != nil {
|
||||
if err = s.updateResources(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1175,8 +1177,7 @@ func (s *Sandbox) StartContainer(ctx context.Context, containerID string) (VCCon
|
||||
}
|
||||
|
||||
// Start it.
|
||||
err = c.start(ctx)
|
||||
if err != nil {
|
||||
if err = c.start(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1188,8 +1189,7 @@ func (s *Sandbox) StartContainer(ctx context.Context, containerID string) (VCCon
|
||||
|
||||
// Update sandbox resources in case a stopped container
|
||||
// is started
|
||||
err = s.updateResources(ctx)
|
||||
if err != nil {
|
||||
if err = s.updateResources(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1248,8 +1248,7 @@ func (s *Sandbox) DeleteContainer(ctx context.Context, containerID string) (VCCo
|
||||
}
|
||||
|
||||
// Delete it.
|
||||
err = c.delete(ctx)
|
||||
if err != nil {
|
||||
if err = c.delete(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1323,8 +1322,7 @@ func (s *Sandbox) UpdateContainer(ctx context.Context, containerID string, resou
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.update(ctx, resources)
|
||||
if err != nil {
|
||||
if err = c.update(ctx, resources); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -31,7 +31,7 @@ type TuntapEndpoint struct {
|
||||
TxRateLimiter bool
|
||||
}
|
||||
|
||||
// Properties returns the properties of the tap interface.
|
||||
// Properties returns the properties of the tun/tap interface.
|
||||
func (endpoint *TuntapEndpoint) Properties() NetworkInfo {
|
||||
return endpoint.EndpointProperties
|
||||
}
|
||||
@@ -41,12 +41,12 @@ func (endpoint *TuntapEndpoint) Name() string {
|
||||
return endpoint.TuntapInterface.Name
|
||||
}
|
||||
|
||||
// HardwareAddr returns the mac address that is assigned to the tap interface
|
||||
// HardwareAddr returns the mac address that is assigned to the tun/tap interface
|
||||
func (endpoint *TuntapEndpoint) HardwareAddr() string {
|
||||
return endpoint.TuntapInterface.TAPIface.HardAddr
|
||||
}
|
||||
|
||||
// Type identifies the endpoint as a tap endpoint.
|
||||
// Type identifies the endpoint as a tun/tap endpoint.
|
||||
func (endpoint *TuntapEndpoint) Type() EndpointType {
|
||||
return endpoint.EndpointType
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (endpoint *TuntapEndpoint) SetProperties(properties NetworkInfo) {
|
||||
endpoint.EndpointProperties = properties
|
||||
}
|
||||
|
||||
// Attach for tap endpoint adds the tap interface to the hypervisor.
|
||||
// Attach for tun/tap endpoint adds the tap interface to the hypervisor.
|
||||
func (endpoint *TuntapEndpoint) Attach(ctx context.Context, s *Sandbox) error {
|
||||
span, ctx := tuntapTrace(ctx, "Attach", endpoint)
|
||||
defer span.End()
|
||||
@@ -85,7 +85,7 @@ func (endpoint *TuntapEndpoint) Attach(ctx context.Context, s *Sandbox) error {
|
||||
return h.addDevice(ctx, endpoint, netDev)
|
||||
}
|
||||
|
||||
// Detach for the tap endpoint tears down the tap
|
||||
// Detach for the tun/tap endpoint tears down the tap
|
||||
func (endpoint *TuntapEndpoint) Detach(ctx context.Context, netNsCreated bool, netNsPath string) error {
|
||||
if !netNsCreated && netNsPath != "" {
|
||||
return nil
|
||||
@@ -100,28 +100,28 @@ func (endpoint *TuntapEndpoint) Detach(ctx context.Context, netNsCreated bool, n
|
||||
})
|
||||
}
|
||||
|
||||
// HotAttach for the tap endpoint uses hot plug device
|
||||
// HotAttach for the tun/tap endpoint uses hot plug device
|
||||
func (endpoint *TuntapEndpoint) HotAttach(ctx context.Context, h hypervisor) error {
|
||||
networkLogger().Info("Hot attaching tap endpoint")
|
||||
networkLogger().Info("Hot attaching tun/tap endpoint")
|
||||
|
||||
span, ctx := tuntapTrace(ctx, "HotAttach", endpoint)
|
||||
defer span.End()
|
||||
|
||||
if err := tuntapNetwork(endpoint, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil {
|
||||
networkLogger().WithError(err).Error("Error bridging tap ep")
|
||||
networkLogger().WithError(err).Error("Error bridging tun/tap ep")
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := h.hotplugAddDevice(ctx, endpoint, netDev); err != nil {
|
||||
networkLogger().WithError(err).Error("Error attach tap ep")
|
||||
networkLogger().WithError(err).Error("Error attach tun/tap ep")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// HotDetach for the tap endpoint uses hot pull device
|
||||
// HotDetach for the tun/tap endpoint uses hot pull device
|
||||
func (endpoint *TuntapEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error {
|
||||
networkLogger().Info("Hot detaching tap endpoint")
|
||||
networkLogger().Info("Hot detaching tun/tap endpoint")
|
||||
|
||||
span, ctx := tuntapTrace(ctx, "HotDetach", endpoint)
|
||||
defer span.End()
|
||||
@@ -129,11 +129,11 @@ func (endpoint *TuntapEndpoint) HotDetach(ctx context.Context, h hypervisor, net
|
||||
if err := doNetNS(netNsPath, func(_ ns.NetNS) error {
|
||||
return unTuntapNetwork(endpoint.TuntapInterface.TAPIface.Name)
|
||||
}); err != nil {
|
||||
networkLogger().WithError(err).Warn("Error un-bridging tap ep")
|
||||
networkLogger().WithError(err).Warn("Error un-bridging tun/tap ep")
|
||||
}
|
||||
|
||||
if _, err := h.hotplugRemoveDevice(ctx, endpoint, netDev); err != nil {
|
||||
networkLogger().WithError(err).Error("Error detach tap ep")
|
||||
networkLogger().WithError(err).Error("Error detach tun/tap ep")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user