From 82fde4431eddcdafb19bbb76f233eff258576cc6 Mon Sep 17 00:00:00 2001 From: Xuewei Niu Date: Mon, 11 Dec 2023 10:09:22 +0800 Subject: [PATCH] dragonball: Set default queue config for vhost-net device Dragonball sets a default queue config in the case of `None`. The queue_size and num_queues of vhost-net are set to `Some(0)` by default. Therefore, we might get an invalid queue config. This patch fixes this issue. Signed-off-by: Xuewei Niu --- src/dragonball/src/api/v1/virtio_net.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/dragonball/src/api/v1/virtio_net.rs b/src/dragonball/src/api/v1/virtio_net.rs index d2acde677f..4f6c829e5f 100644 --- a/src/dragonball/src/api/v1/virtio_net.rs +++ b/src/dragonball/src/api/v1/virtio_net.rs @@ -128,9 +128,23 @@ impl From<&NetworkInterfaceConfig> for VhostNetDeviceConfigInfo { fn from(value: &NetworkInterfaceConfig) -> Self { let num_queues = value .num_queues + .map(|nq| { + if nq == 0 { + vhost_net_dev_mgr::DEFAULT_NUM_QUEUES + } else { + nq + } + }) .unwrap_or(vhost_net_dev_mgr::DEFAULT_NUM_QUEUES); let queue_size = value .queue_size + .map(|qs| { + if qs == 0 { + vhost_net_dev_mgr::DEFAULT_QUEUE_SIZE + } else { + qs + } + }) .unwrap_or(vhost_net_dev_mgr::DEFAULT_QUEUE_SIZE); // It is safe because we tested the type of config before.