提交 2a9a5bef 编写于 作者: M Michal Privoznik

qemu_command: Honour chardev alias assignment with a function

The chardev alias assignment is going to be needed in a separate
places, so it should be moved into a separate function rather
than copying code randomly around.
上级 0f7a7ce5
...@@ -863,6 +863,36 @@ qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller) ...@@ -863,6 +863,36 @@ qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller)
return virAsprintf(&controller->info.alias, "%s%d", prefix, controller->idx); return virAsprintf(&controller->info.alias, "%s%d", prefix, controller->idx);
} }
int
qemuAssignDeviceChrAlias(virDomainDefPtr def ATTRIBUTE_UNUSED,
virDomainChrDefPtr chr,
ssize_t idx)
{
const char *prefix = NULL;
switch ((enum virDomainChrDeviceType) chr->deviceType) {
case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
prefix = "parallel";
break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
prefix = "serial";
break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
prefix = "console";
break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
prefix = "channel";
break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
return -1;
}
return virAsprintf(&chr->info.alias, "%s%zd", prefix, idx);
}
int int
qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
...@@ -918,19 +948,19 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) ...@@ -918,19 +948,19 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1; return -1;
} }
for (i = 0; i < def->nparallels; i++) { for (i = 0; i < def->nparallels; i++) {
if (virAsprintf(&def->parallels[i]->info.alias, "parallel%zu", i) < 0) if (qemuAssignDeviceChrAlias(def, def->parallels[i], i) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nserials; i++) { for (i = 0; i < def->nserials; i++) {
if (virAsprintf(&def->serials[i]->info.alias, "serial%zu", i) < 0) if (qemuAssignDeviceChrAlias(def, def->serials[i], i) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nchannels; i++) { for (i = 0; i < def->nchannels; i++) {
if (virAsprintf(&def->channels[i]->info.alias, "channel%zu", i) < 0) if (qemuAssignDeviceChrAlias(def, def->channels[i], i) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nconsoles; i++) { for (i = 0; i < def->nconsoles; i++) {
if (virAsprintf(&def->consoles[i]->info.alias, "console%zu", i) < 0) if (qemuAssignDeviceChrAlias(def, def->consoles[i], i) < 0)
return -1; return -1;
} }
for (i = 0; i < def->nhubs; i++) { for (i = 0; i < def->nhubs; i++) {
......
...@@ -260,6 +260,9 @@ int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef, ...@@ -260,6 +260,9 @@ int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev, int idx); int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev, int idx);
int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller); int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller);
int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev, int idx); int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev, int idx);
int qemuAssignDeviceChrAlias(virDomainDefPtr def,
virDomainChrDefPtr chr,
ssize_t idx);
int int
qemuParseKeywords(const char *str, qemuParseKeywords(const char *str,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册