mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-19 12:14:11 +00:00
clh: Pass the tuntap fds down to Cloud Hypervisor
This is basically a no-op right now, as: * netPair.TapInterface.VMFds is nil * the tap name is still passed to Cloud Hypervisor, which is the Cloud Hypervisor's first choice when opening a tap device. In the very near future we'll stop passing the tap name to Cloud Hypervisor, and start passing the file descriptors of the opened tap instead. Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
parent
55ed32e924
commit
bf3ddc125d
@ -181,12 +181,18 @@ var vmAddNetPutRequest = func(clh *cloudHypervisor) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadn, err := conn.Write([]byte(payload))
|
files := clh.netDevicesFiles[*netDevice.Mac]
|
||||||
|
var fds []int
|
||||||
|
for _, f := range files {
|
||||||
|
fds = append(fds, int(f.Fd()))
|
||||||
|
}
|
||||||
|
oob := syscall.UnixRights(fds...)
|
||||||
|
payloadn, oobn, err := conn.WriteMsgUnix([]byte(payload), oob, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if payloadn != len(payload) {
|
if payloadn != len(payload) || oobn != len(oob) {
|
||||||
return fmt.Errorf("Failed to send all the request to Cloud Hypervisor. %d bytes expect to send, but only %d sent", len(payload), payloadn)
|
return fmt.Errorf("Failed to send all the request to Cloud Hypervisor. %d bytes expect to send as payload, %d bytes expect to send as oob date, but only %d sent as payload, and %d sent as oob", len(payload), len(oob), payloadn, oobn)
|
||||||
}
|
}
|
||||||
|
|
||||||
reader := bufio.NewReader(conn)
|
reader := bufio.NewReader(conn)
|
||||||
@ -236,6 +242,7 @@ type cloudHypervisor struct {
|
|||||||
id string
|
id string
|
||||||
netDevices *[]chclient.NetConfig
|
netDevices *[]chclient.NetConfig
|
||||||
devicesIds map[string]string
|
devicesIds map[string]string
|
||||||
|
netDevicesFiles map[string][]*os.File
|
||||||
vmconfig chclient.VmConfig
|
vmconfig chclient.VmConfig
|
||||||
state CloudHypervisorState
|
state CloudHypervisorState
|
||||||
config HypervisorConfig
|
config HypervisorConfig
|
||||||
@ -430,6 +437,7 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net
|
|||||||
clh.id = id
|
clh.id = id
|
||||||
clh.state.state = clhNotReady
|
clh.state.state = clhNotReady
|
||||||
clh.devicesIds = make(map[string]string)
|
clh.devicesIds = make(map[string]string)
|
||||||
|
clh.netDevicesFiles = make(map[string][]*os.File)
|
||||||
|
|
||||||
clh.Logger().WithField("function", "CreateVM").Info("creating Sandbox")
|
clh.Logger().WithField("function", "CreateVM").Info("creating Sandbox")
|
||||||
|
|
||||||
@ -1456,6 +1464,7 @@ func (clh *cloudHypervisor) addNet(e Endpoint) error {
|
|||||||
if tapPath == "" {
|
if tapPath == "" {
|
||||||
return errors.New("TAP path in network pair is empty")
|
return errors.New("TAP path in network pair is empty")
|
||||||
}
|
}
|
||||||
|
clh.netDevicesFiles[mac] = netPair.TapInterface.VMFds
|
||||||
|
|
||||||
clh.Logger().WithFields(log.Fields{
|
clh.Logger().WithFields(log.Fields{
|
||||||
"mac": mac,
|
"mac": mac,
|
||||||
|
@ -135,6 +135,7 @@ func TestCloudHypervisorAddNetCheckNetConfigListValues(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
clh := cloudHypervisor{}
|
clh := cloudHypervisor{}
|
||||||
|
clh.netDevicesFiles = make(map[string][]*os.File)
|
||||||
|
|
||||||
e := &VethEndpoint{}
|
e := &VethEndpoint{}
|
||||||
e.NetPair.TAPIface.HardAddr = macTest
|
e.NetPair.TAPIface.HardAddr = macTest
|
||||||
@ -185,6 +186,7 @@ func TestCloudHypervisorAddNetCheckEnpointTypes(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
clh := &cloudHypervisor{}
|
clh := &cloudHypervisor{}
|
||||||
|
clh.netDevicesFiles = make(map[string][]*os.File)
|
||||||
if err := clh.addNet(tt.args.e); (err != nil) != tt.wantErr {
|
if err := clh.addNet(tt.args.e); (err != nil) != tt.wantErr {
|
||||||
t.Errorf("cloudHypervisor.addNet() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("cloudHypervisor.addNet() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
|
||||||
@ -339,6 +341,7 @@ func TestCloudHypervisorNetRateLimiter(t *testing.T) {
|
|||||||
clhConfig.NetRateLimiterOpsOneTimeBurst = tt.args.opsOneTimeBurst
|
clhConfig.NetRateLimiterOpsOneTimeBurst = tt.args.opsOneTimeBurst
|
||||||
|
|
||||||
clh := &cloudHypervisor{}
|
clh := &cloudHypervisor{}
|
||||||
|
clh.netDevicesFiles = make(map[string][]*os.File)
|
||||||
clh.config = clhConfig
|
clh.config = clhConfig
|
||||||
clh.APIClient = &clhClientMock{}
|
clh.APIClient = &clhClientMock{}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user