mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
Fix bug of attaching redirdev device
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1298070 The corresponding chardev must be attached first, otherwise the the qemu command line won't be complete (missing the host part),
This commit is contained in:
parent
5ea3a690a2
commit
c92547c34a
@ -1378,45 +1378,56 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
|
|||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainRedirdevDefPtr redirdev)
|
virDomainRedirdevDefPtr redirdev)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = -1;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virDomainDefPtr def = vm->def;
|
virDomainDefPtr def = vm->def;
|
||||||
|
char *charAlias = NULL;
|
||||||
char *devstr = NULL;
|
char *devstr = NULL;
|
||||||
|
|
||||||
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
|
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("redirected devices are not supported by this QEMU"));
|
_("redirected devices are not supported by this QEMU"));
|
||||||
goto error;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuAssignDeviceRedirdevAlias(vm->def, redirdev, -1) < 0)
|
if (qemuAssignDeviceRedirdevAlias(vm->def, redirdev, -1) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virAsprintf(&charAlias, "char%s", redirdev->info.alias) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!(devstr = qemuBuildRedirdevDevStr(def, redirdev, priv->qemuCaps)))
|
if (!(devstr = qemuBuildRedirdevDevStr(def, redirdev, priv->qemuCaps)))
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(vm->def->redirdevs, vm->def->nredirdevs+1) < 0)
|
if (VIR_REALLOC_N(vm->def->redirdevs, vm->def->nredirdevs+1) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
ret = qemuMonitorAddDevice(priv->mon, devstr);
|
if (qemuMonitorAttachCharDev(priv->mon,
|
||||||
|
charAlias,
|
||||||
|
&(redirdev->source.chr)) < 0) {
|
||||||
|
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
||||||
|
goto audit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
|
||||||
|
/* detach associated chardev on error */
|
||||||
|
qemuMonitorDetachCharDev(priv->mon, charAlias);
|
||||||
|
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
||||||
|
goto audit;
|
||||||
|
}
|
||||||
|
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
goto error;
|
goto audit;
|
||||||
|
|
||||||
virDomainAuditRedirdev(vm, redirdev, "attach", ret == 0);
|
|
||||||
if (ret < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
vm->def->redirdevs[vm->def->nredirdevs++] = redirdev;
|
vm->def->redirdevs[vm->def->nredirdevs++] = redirdev;
|
||||||
|
ret = 0;
|
||||||
|
audit:
|
||||||
|
virDomainAuditRedirdev(vm, redirdev, "attach", ret == 0);
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(charAlias);
|
||||||
VIR_FREE(devstr);
|
VIR_FREE(devstr);
|
||||||
|
return ret;
|
||||||
return 0;
|
|
||||||
|
|
||||||
error:
|
|
||||||
VIR_FREE(devstr);
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user