A helper that will execute a callback on every USB device in the domain definition. With an ability to skip USB hubs, since we will want to treat them differently in some cases. --- src/conf/domain_conf.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 7 ++++ src/libvirt_private.syms | 1 + 3 files changed, 97 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 780d705..396655a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -24054,6 +24054,95 @@ virDomainSmartcardDefForeach(virDomainDefPtr def, } +int +virDomainUSBDeviceDefForeach(virDomainDefPtr def, + virDomainUSBDeviceDefIterator iter, + void *opaque, + bool skipHubs) +{ + size_t i; + + /* usb-hub */ + if (!skipHubs) { + for (i = 0; i < def->nhubs; i++) { + virDomainHubDefPtr hub = def->hubs[i]; + if (hub->type == VIR_DOMAIN_HUB_TYPE_USB) { + if (iter(&hub->info, opaque) < 0) + return -1; + } + } + } + + /* usb-host */ + for (i = 0; i < def->nhostdevs; i++) { + virDomainHostdevDefPtr hostdev = def->hostdevs[i]; + if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) { + if (iter(hostdev->info, opaque) < 0) + return -1; + } + } + + /* usb-storage */ + for (i = 0; i < def->ndisks; i++) { + virDomainDiskDefPtr disk = def->disks[i]; + if (disk->bus == VIR_DOMAIN_DISK_BUS_USB) { + if (iter(&disk->info, opaque) < 0) + return -1; + } + } + + /* TODO: add def->nets here when libvirt starts supporting usb-net */ + + /* usb-ccid */ + for (i = 0; i < def->ncontrollers; i++) { + virDomainControllerDefPtr cont = def->controllers[i]; + if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_CCID) { + if (iter(&cont->info, opaque) < 0) + return -1; + } + } + + /* usb-kbd, usb-mouse, usb-tablet */ + for (i = 0; i < def->ninputs; i++) { + virDomainInputDefPtr input = def->inputs[i]; + + if (input->bus == VIR_DOMAIN_INPUT_BUS_USB) { + if (iter(&input->info, opaque) < 0) + return -1; + } + } + + /* usb-serial */ + for (i = 0; i < def->nserials; i++) { + virDomainChrDefPtr serial = def->serials[i]; + if (serial->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB) { + if (iter(&serial->info, opaque) < 0) + return -1; + } + } + + /* usb-audio model=usb */ + for (i = 0; i < def->nsounds; i++) { + virDomainSoundDefPtr sound = def->sounds[i]; + if (sound->model == VIR_DOMAIN_SOUND_MODEL_USB) { + if (iter(&sound->info, opaque) < 0) + return -1; + } + } + + /* usb-redir */ + for (i = 0; i < def->nredirdevs; i++) { + virDomainRedirdevDefPtr redirdev = def->redirdevs[i]; + if (redirdev->bus == VIR_DOMAIN_REDIRDEV_BUS_USB) { + if (iter(&redirdev->info, opaque) < 0) + return -1; + } + } + + return 0; +} + + /* Call iter(disk, name, depth, opaque) for each element of disk and * its backing chain in the pre-populated disk->src.backingStore. * ignoreOpenFailure determines whether to warn about a chain that diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6e81e52..149b75f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2898,6 +2898,13 @@ typedef int (*virDomainDiskDefPathIterator)(virDomainDiskDefPtr disk, size_t depth, void *opaque); +typedef int (*virDomainUSBDeviceDefIterator)(virDomainDeviceInfoPtr info, + void *opaque); +int virDomainUSBDeviceDefForeach(virDomainDefPtr def, + virDomainUSBDeviceDefIterator iter, + void *opaque, + bool skipHubs); + int virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, bool ignoreOpenFailure, virDomainDiskDefPathIterator iter, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1fb06b1..414d990 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -476,6 +476,7 @@ virDomainTPMBackendTypeToString; virDomainTPMDefFree; virDomainTPMModelTypeFromString; virDomainTPMModelTypeToString; +virDomainUSBDeviceDefForeach; virDomainVideoDefaultRAM; virDomainVideoDefaultType; virDomainVideoDefFree; -- 2.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list