split out qemuAssignDeviceInputAlias

Move assignment of input device alias into a separate function,
for reuse on hotplug.
This commit is contained in:
Ján Tomko 2017-10-04 11:09:22 +02:00
parent 513a8d4588
commit d059b24aea
2 changed files with 27 additions and 1 deletions

View File

@ -412,6 +412,28 @@ qemuAssignDeviceWatchdogAlias(virDomainWatchdogDefPtr watchdog)
if (VIR_STRDUP(watchdog->info.alias, "watchdog0") < 0) if (VIR_STRDUP(watchdog->info.alias, "watchdog0") < 0)
return -1; return -1;
return 0;
}
int
qemuAssignDeviceInputAlias(virDomainDefPtr def,
virDomainInputDefPtr input,
int idx)
{
if (idx == -1) {
int thisidx;
size_t i;
for (i = 0; i < def->ninputs; i++) {
if ((thisidx = qemuDomainDeviceAliasIndex(&def->inputs[i]->info, "input")) >= idx)
idx = thisidx + 1;
}
}
if (virAsprintf(&input->info.alias, "input%d", idx) < 0)
return -1;
return 0; return 0;
} }
@ -461,7 +483,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1; return -1;
} }
for (i = 0; i < def->ninputs; i++) { for (i = 0; i < def->ninputs; i++) {
if (virAsprintf(&def->inputs[i]->info.alias, "input%zu", i) < 0) if (qemuAssignDeviceInputAlias(def, def->inputs[i], i) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nparallels; i++) { for (i = 0; i < def->nparallels; i++) {

View File

@ -67,6 +67,10 @@ int qemuAssignDeviceShmemAlias(virDomainDefPtr def,
int qemuAssignDeviceWatchdogAlias(virDomainWatchdogDefPtr watchdog); int qemuAssignDeviceWatchdogAlias(virDomainWatchdogDefPtr watchdog);
int qemuAssignDeviceInputAlias(virDomainDefPtr def,
virDomainInputDefPtr input,
int idx);
int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps); int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
int qemuDomainDeviceAliasIndex(const virDomainDeviceInfo *info, int qemuDomainDeviceAliasIndex(const virDomainDeviceInfo *info,