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(a)redhat.com>
---
src/qemu/qemu_alias.c | 80 +++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 72 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index eca1dc64c..33bd4c10d 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -286,6 +286,70 @@ 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
+qemuAssignDeviceInputAlias(virDomainInputDefPtr input,
+ int idx)
+{
+ return virAsprintf(&input->info.alias, "input%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
qemuAssignDeviceRedirdevAlias(virDomainDefPtr def,
virDomainRedirdevDefPtr redirdev,
@@ -431,11 +495,11 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr
qemuCaps)
}
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;
}
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;
}
for (i = 0; i < def->nhostdevs; i++) {
@@ -453,7 +517,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1;
}
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;
}
for (i = 0; i < def->ncontrollers; i++) {
@@ -461,7 +525,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1;
}
for (i = 0; i < def->ninputs; i++) {
- if (virAsprintf(&def->inputs[i]->info.alias, "input%zu", i)
< 0)
+ if (qemuAssignDeviceInputAlias(def->inputs[i], i) < 0)
return -1;
}
for (i = 0; i < def->nparallels; i++) {
@@ -481,7 +545,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1;
}
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;
}
for (i = 0; i < def->nshmems; i++) {
@@ -489,7 +553,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1;
}
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;
}
if (def->watchdog) {
@@ -497,7 +561,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1;
}
if (def->memballoon) {
- if (virAsprintf(&def->memballoon->info.alias, "balloon%d", 0)
< 0)
+ if (qemuAssingDeviceMemballoonAlias(def->memballoon, 0) < 0)
return -1;
}
for (i = 0; i < def->nrngs; i++) {
@@ -505,7 +569,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1;
}
if (def->tpm) {
- if (virAsprintf(&def->tpm->info.alias, "tpm%d", 0) < 0)
+ if (qemuAssignDeviceTPMAlias(def->tpm, 0) < 0)
return -1;
}
for (i = 0; i < def->nmems; i++) {
--
2.13.6