qemu: Move device alias assignment to separate functions

Let's move all the virAsprintf()-s into separate functions for
better structure of the code. Later, when somebody wants to
generate a device alias, all they need is to expose the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2017-09-20 18:17:32 +02:00
parent 16bb5a710e
commit 215ab7aa03

View File

@ -286,6 +286,62 @@ qemuAssignDeviceNetAlias(virDomainDefPtr def,
} }
static int
qemuAssignDeviceFSAlias(virDomainFSDefPtr fss,
int idx)
{
return virAsprintf(&fss->info.alias, "fs%d", idx);
}
static int
qemuAssignDeviceSoundAlias(virDomainSoundDefPtr sound,
int idx)
{
return virAsprintf(&sound->info.alias, "sound%d", idx);
}
static int
qemuAssignDeviceVideoAlias(virDomainVideoDefPtr video,
int idx)
{
return virAsprintf(&video->info.alias, "video%d", idx);
}
static int
qemuAssignDeviceHubAlias(virDomainHubDefPtr hub,
int idx)
{
return virAsprintf(&hub->info.alias, "hub%d", idx);
}
static int
qemuAssignDeviceSmartcardAlias(virDomainSmartcardDefPtr smartcard,
int idx)
{
return virAsprintf(&smartcard->info.alias, "smartcard%d", idx);
}
static int
qemuAssingDeviceMemballoonAlias(virDomainMemballoonDefPtr memballoon,
int idx)
{
return virAsprintf(&memballoon->info.alias, "balloon%d", idx);
}
static int
qemuAssignDeviceTPMAlias(virDomainTPMDefPtr tpm,
int idx)
{
return virAsprintf(&tpm->info.alias, "tpm%d", idx);
}
int int
qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, qemuAssignDeviceRedirdevAlias(virDomainDefPtr def,
virDomainRedirdevDefPtr redirdev, virDomainRedirdevDefPtr redirdev,
@ -453,11 +509,11 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
} }
for (i = 0; i < def->nfss; i++) { for (i = 0; i < def->nfss; i++) {
if (virAsprintf(&def->fss[i]->info.alias, "fs%zu", i) < 0) if (qemuAssignDeviceFSAlias(def->fss[i], i) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nsounds; i++) { for (i = 0; i < def->nsounds; i++) {
if (virAsprintf(&def->sounds[i]->info.alias, "sound%zu", i) < 0) if (qemuAssignDeviceSoundAlias(def->sounds[i], i) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nhostdevs; i++) { for (i = 0; i < def->nhostdevs; i++) {
@ -475,7 +531,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1; return -1;
} }
for (i = 0; i < def->nvideos; i++) { for (i = 0; i < def->nvideos; i++) {
if (virAsprintf(&def->videos[i]->info.alias, "video%zu", i) < 0) if (qemuAssignDeviceVideoAlias(def->videos[i], i) < 0)
return -1; return -1;
} }
for (i = 0; i < def->ncontrollers; i++) { for (i = 0; i < def->ncontrollers; i++) {
@ -503,7 +559,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1; return -1;
} }
for (i = 0; i < def->nhubs; i++) { for (i = 0; i < def->nhubs; i++) {
if (virAsprintf(&def->hubs[i]->info.alias, "hub%zu", i) < 0) if (qemuAssignDeviceHubAlias(def->hubs[i], i) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nshmems; i++) { for (i = 0; i < def->nshmems; i++) {
@ -511,7 +567,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1; return -1;
} }
for (i = 0; i < def->nsmartcards; i++) { for (i = 0; i < def->nsmartcards; i++) {
if (virAsprintf(&def->smartcards[i]->info.alias, "smartcard%zu", i) < 0) if (qemuAssignDeviceSmartcardAlias(def->smartcards[i], i) < 0)
return -1; return -1;
} }
if (def->watchdog) { if (def->watchdog) {
@ -519,7 +575,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1; return -1;
} }
if (def->memballoon) { if (def->memballoon) {
if (virAsprintf(&def->memballoon->info.alias, "balloon%d", 0) < 0) if (qemuAssingDeviceMemballoonAlias(def->memballoon, 0) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nrngs; i++) { for (i = 0; i < def->nrngs; i++) {
@ -527,7 +583,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1; return -1;
} }
if (def->tpm) { if (def->tpm) {
if (virAsprintf(&def->tpm->info.alias, "tpm%d", 0) < 0) if (qemuAssignDeviceTPMAlias(def->tpm, 0) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nmems; i++) { for (i = 0; i < def->nmems; i++) {