From 1074d2c1d3dd703acf7b2cc16615fb92c54922ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Fri, 6 Jan 2023 18:47:29 +0100 Subject: [PATCH 1/2] clh: Make vmAddNetPutRequest capable of doing hotplugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit THe only bit needed for having the vmAddNetPutRequest() capable of dealing with hotplugs, instead of only coldplugs, is making sure it doesn't error out in case a `200` response is returned. The 200 response means: """ The new device was successfully added to the VM instance. """ Signed-off-by: Fabiano FidĂȘncio --- src/runtime/virtcontainers/clh.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index 92089a537b7e..cd7513d66695 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -220,7 +220,7 @@ var vmAddNetPutRequest = func(clh *cloudHypervisor) error { resp.Body.Close() resp.Body = io.NopCloser(bytes.NewBuffer(respBody)) - if resp.StatusCode != 204 { + if resp.StatusCode != 200 && resp.StatusCode != 204 { clh.Logger().Errorf("vmAddNetPut failed with error '%d'. Response: %+v", resp.StatusCode, resp) return fmt.Errorf("Failed to add the network device '%+v' to Cloud Hypervisor: %v", netDevice, resp.StatusCode) } From efa4fc0b25e4ab934a497fdb2ba936511c154271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Fri, 6 Jan 2023 18:53:36 +0100 Subject: [PATCH 2/2] clh: Add hotplug support for network devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is needed in order to have Moby / Docker working properly with Cloud Hypervisor, as Moby / Docker relies on hotplugging a network device to the VM as a preStartHook. Fixes: #5997 Signed-off-by: Fabiano FidĂȘncio --- src/runtime/virtcontainers/clh.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index cd7513d66695..75261c49c2bf 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -886,6 +886,15 @@ func (clh *cloudHypervisor) hotPlugVFIODevice(device *config.VFIODev) error { return err } +func (clh *cloudHypervisor) hotplugAddNetDevice(e Endpoint) error { + err := clh.addNet(e) + if err != nil { + return err + } + + return clh.vmAddNetPut() +} + func (clh *cloudHypervisor) HotplugAddDevice(ctx context.Context, devInfo interface{}, devType DeviceType) (interface{}, error) { span, _ := katatrace.Trace(ctx, clh.Logger(), "HotplugAddDevice", clhTracingTags, map[string]string{"sandbox_id": clh.id}) defer span.End() @@ -897,6 +906,9 @@ func (clh *cloudHypervisor) HotplugAddDevice(ctx context.Context, devInfo interf case VfioDev: device := devInfo.(*config.VFIODev) return nil, clh.hotPlugVFIODevice(device) + case NetDev: + device := devInfo.(Endpoint) + return nil, clh.hotplugAddNetDevice(device) default: return nil, fmt.Errorf("cannot hotplug device: unsupported device type '%v'", devType) }