There will be cases where the iterator callback will need to know the
type of the device whose info is being operated on, and possibly even
need to use some of the device's config. This patch adds a
virDomainDeviceDefPtr to the args of every callback, and fills it in
appropriately as the devices are iterated through.
---
New patch in V2.
src/conf/domain_conf.c | 112 +++++++++++++++++++++++++++++++++-------------
src/conf/domain_conf.h | 3 +-
src/qemu/qemu_command.c | 2 +
src/qemu/qemu_hotplug.c | 1 +
4 files changed, 85 insertions(+), 33 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a2536de..03f8564 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1829,6 +1829,7 @@ void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
static int virDomainDeviceInfoClearAlias(virDomainDefPtr def ATTRIBUTE_UNUSED,
+ virDomainDeviceDefPtr device ATTRIBUTE_UNUSED,
virDomainDeviceInfoPtr info,
void *opaque ATTRIBUTE_UNUSED)
{
@@ -1837,6 +1838,7 @@ static int virDomainDeviceInfoClearAlias(virDomainDefPtr def
ATTRIBUTE_UNUSED,
}
static int virDomainDeviceInfoClearPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
+ virDomainDeviceDefPtr device
ATTRIBUTE_UNUSED,
virDomainDeviceInfoPtr info,
void *opaque ATTRIBUTE_UNUSED)
{
@@ -1852,55 +1854,101 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def,
void *opaque)
{
int i;
+ virDomainDeviceDef device;
- for (i = 0; i < def->ndisks ; i++)
- if (cb(def, &def->disks[i]->info, opaque) < 0)
+ device.type = VIR_DOMAIN_DEVICE_DISK;
+ for (i = 0; i < def->ndisks ; i++) {
+ device.data.disk = def->disks[i];
+ if (cb(def, &device, &def->disks[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nnets ; i++)
- if (cb(def, &def->nets[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_NET;
+ for (i = 0; i < def->nnets ; i++) {
+
device.data.net = def->nets[i];
+ if (cb(def, &device, &def->nets[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nsounds ; i++)
- if (cb(def, &def->sounds[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_SOUND;
+ for (i = 0; i < def->nsounds ; i++) {
+ device.data.sound = def->sounds[i];
+ if (cb(def, &device, &def->sounds[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nhostdevs ; i++)
- if (cb(def, &def->hostdevs[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_HOSTDEV;
+ for (i = 0; i < def->nhostdevs ; i++) {
+ device.data.hostdev = def->hostdevs[i];
+ if (cb(def, &device, &def->hostdevs[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nvideos ; i++)
- if (cb(def, &def->videos[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_VIDEO;
+ for (i = 0; i < def->nvideos ; i++) {
+ device.data.video = def->videos[i];
+ if (cb(def, &device, &def->videos[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->ncontrollers ; i++)
- if (cb(def, &def->controllers[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_CONTROLLER;
+ for (i = 0; i < def->ncontrollers ; i++) {
+ device.data.controller = def->controllers[i];
+ if (cb(def, &device, &def->controllers[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nsmartcards ; i++)
- if (cb(def, &def->smartcards[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_SMARTCARD;
+ for (i = 0; i < def->nsmartcards ; i++) {
+ device.data.smartcard = def->smartcards[i];
+ if (cb(def, &device, &def->smartcards[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nserials ; i++)
- if (cb(def, &def->serials[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_CHR;
+ for (i = 0; i < def->nserials ; i++) {
+ device.data.chr = def->serials[i];
+ if (cb(def, &device, &def->serials[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nparallels ; i++)
- if (cb(def, &def->parallels[i]->info, opaque) < 0)
+ }
+ for (i = 0; i < def->nparallels ; i++) {
+ device.data.chr = def->parallels[i];
+ if (cb(def, &device, &def->parallels[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nchannels ; i++)
- if (cb(def, &def->channels[i]->info, opaque) < 0)
+ }
+ for (i = 0; i < def->nchannels ; i++) {
+ device.data.chr = def->channels[i];
+ if (cb(def, &device, &def->channels[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nconsoles ; i++)
- if (cb(def, &def->consoles[i]->info, opaque) < 0)
+ }
+ for (i = 0; i < def->nconsoles ; i++) {
+ device.data.chr = def->consoles[i];
+ if (cb(def, &device, &def->consoles[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->ninputs ; i++)
- if (cb(def, &def->inputs[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_INPUT;
+ for (i = 0; i < def->ninputs ; i++) {
+ device.data.input = def->inputs[i];
+ if (cb(def, &device, &def->inputs[i]->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nfss ; i++)
- if (cb(def, &def->fss[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_FS;
+ for (i = 0; i < def->nfss ; i++) {
+ device.data.fs = def->fss[i];
+ if (cb(def, &device, &def->fss[i]->info, opaque) < 0)
return -1;
- if (def->watchdog)
- if (cb(def, &def->watchdog->info, opaque) < 0)
+ }
+ if (def->watchdog) {
+ device.type = VIR_DOMAIN_DEVICE_WATCHDOG;
+ device.data.watchdog = def->watchdog;
+ if (cb(def, &device, &def->watchdog->info, opaque) < 0)
return -1;
- if (def->memballoon)
- if (cb(def, &def->memballoon->info, opaque) < 0)
+ }
+ if (def->memballoon) {
+ device.type = VIR_DOMAIN_DEVICE_MEMBALLOON;
+ device.data.memballoon = def->memballoon;
+ if (cb(def, &device, &def->memballoon->info, opaque) < 0)
return -1;
- for (i = 0; i < def->nhubs ; i++)
- if (cb(def, &def->hubs[i]->info, opaque) < 0)
+ }
+ device.type = VIR_DOMAIN_DEVICE_HUB;
+ for (i = 0; i < def->nhubs ; i++) {
+ device.data.hub = def->hubs[i];
+ if (cb(def, &device, &def->hubs[i]->info, opaque) < 0)
return -1;
+ }
return 0;
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 68b7cfd..e9f2391 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1785,7 +1785,8 @@ void virDomainDefClearPCIAddresses(virDomainDefPtr def);
void virDomainDefClearDeviceAliases(virDomainDefPtr def);
typedef int (*virDomainDeviceInfoCallback)(virDomainDefPtr def,
- virDomainDeviceInfoPtr dev,
+ virDomainDeviceDefPtr dev,
+ virDomainDeviceInfoPtr info,
void *opaque);
int virDomainDeviceInfoIterate(virDomainDefPtr def,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 04e580f..de3054a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -721,6 +721,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virBitmapPtr qemuCaps)
static int
qemuSpaprVIOFindByReg(virDomainDefPtr def ATTRIBUTE_UNUSED,
+ virDomainDeviceDefPtr device ATTRIBUTE_UNUSED,
virDomainDeviceInfoPtr info, void *opaque)
{
virDomainDeviceInfoPtr target = opaque;
@@ -835,6 +836,7 @@ static char *qemuPCIAddressAsString(virDomainDeviceInfoPtr dev)
static int qemuCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
+ virDomainDeviceDefPtr device ATTRIBUTE_UNUSED,
virDomainDeviceInfoPtr info,
void *opaque)
{
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0ca3186..a7f0899 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1481,6 +1481,7 @@ static inline int qemuFindDisk(virDomainDefPtr def, const char
*dst)
}
static int qemuComparePCIDevice(virDomainDefPtr def ATTRIBUTE_UNUSED,
+ virDomainDeviceDefPtr device ATTRIBUTE_UNUSED,
virDomainDeviceInfoPtr info1,
void *opaque)
{
--
1.7.7.6