diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 41fe0d1daeabe516369e5c3caed34284649e93be..c40ca04f01e89a6418c2e9de99a1fe21f3486bbb 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2068,6 +2068,61 @@ qemuProcessFindCharDevicePTYs(virDomainObjPtr vm, } +static int +qemuProcessRefreshChannelVirtioState(virDomainObjPtr vm, + virHashTablePtr info) +{ + size_t i; + qemuMonitorChardevInfoPtr entry; + char id[32]; + + for (i = 0; i < vm->def->nchannels; i++) { + virDomainChrDefPtr chr = vm->def->channels[i]; + if (chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) { + if (snprintf(id, sizeof(id), "char%s", + chr->info.alias) >= sizeof(id)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to format device alias " + "for PTY retrieval")); + return -1; + } + + /* port state not reported */ + if (!(entry = virHashLookup(info, id)) || + !entry->state) + continue; + + chr->state = entry->state; + } + } + + return 0; +} + + +static int +qemuProcessReconnectRefreshChannelVirtioState(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + qemuDomainObjPrivatePtr priv = vm->privateData; + virHashTablePtr info = NULL; + int ret = -1; + + qemuDomainObjEnterMonitor(driver, vm); + ret = qemuMonitorGetChardevInfo(priv->mon, &info); + qemuDomainObjExitMonitor(driver, vm); + + if (ret < 0) + goto cleanup; + + ret = qemuProcessRefreshChannelVirtioState(vm, info); + + cleanup: + virHashFree(info); + return ret; +} + + static int qemuProcessWaitForMonitor(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -2111,8 +2166,14 @@ qemuProcessWaitForMonitor(virQEMUDriverPtr driver, qemuDomainObjExitMonitor(driver, vm); VIR_DEBUG("qemuMonitorGetChardevInfo returned %i", ret); - if (ret == 0) - ret = qemuProcessFindCharDevicePTYsMonitor(vm, qemuCaps, info); + if (ret == 0) { + if ((ret = qemuProcessFindCharDevicePTYsMonitor(vm, qemuCaps, + info)) < 0) + goto cleanup; + + if ((ret = qemuProcessRefreshChannelVirtioState(vm, info)) < 0) + goto cleanup; + } cleanup: virHashFree(info); @@ -3595,6 +3656,9 @@ qemuProcessReconnect(void *opaque) if (qemuDomainCheckEjectableMedia(driver, obj, QEMU_ASYNC_JOB_NONE) < 0) goto error; + if (qemuProcessReconnectRefreshChannelVirtioState(driver, obj) < 0) + goto error; + if (qemuProcessRecoverJob(driver, obj, conn, &oldjob) < 0) goto error;