From e18c69bcd80beb1bffc67071f989836092904c0c Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Tue, 2 Apr 2024 14:48:35 +0530 Subject: [PATCH] conf: Automatically assign address to usb-net device This patch will allow usb-net devices to be automatically assigned a USB address (and skip any attempt to assign a PCI one). Signed-off-by: Rayhan Faizel Reviewed-by: Peter Krempa --- docs/formatdomain.rst | 1 + src/conf/domain_conf.c | 9 ++++++++- src/qemu/qemu_domain_address.c | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index fc19c1a6f1..e2f66b982c 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -5608,6 +5608,7 @@ ne2k_pci pcnet rtl8139 e1000 virtio. :since:`Since 5.2.0`, ``virtio-transitional`` and ``virtio-non-transitional`` values are supported. See `Virtio transitional devices`_ for more details. :since:`Since 9.3.0` igb is also supported. +:since:`Since 10.3.0` usb-net is supported. Setting NIC driver-specific options ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 11a0b0ecda..48c5d546da 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28695,7 +28695,14 @@ virDomainUSBDeviceDefForeach(virDomainDef *def, } } - /* TODO: add def->nets here when libvirt starts supporting usb-net */ + /* usb-net */ + for (i = 0; i < def->nnets; i++) { + virDomainNetDef *net = def->nets[i]; + if (net->model == VIR_DOMAIN_NET_MODEL_USB_NET) { + if (iter(&net->info, opaque) < 0) + return -1; + } + } /* usb-ccid */ for (i = 0; i < def->ncontrollers; i++) { diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index cc3bc76971..7690021ca7 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2087,6 +2087,10 @@ qemuDomainAssignDevicePCISlots(virDomainDef *def, for (i = 0; i < def->nnets; i++) { virDomainNetDef *net = def->nets[i]; + if (net->model == VIR_DOMAIN_NET_MODEL_USB_NET) { + continue; + } + /* type='hostdev' network devices might be USB, and are also * in hostdevs list anyway, so handle them with other hostdevs * instead of here.