Support virDomainOpenConsole with QEMU

This provides an implementation of the virDomainOpenConsole
API with the QEMU driver. For the streams code, this reuses
most of the code previously added for the tunnelled migration
streams since it is generic.

* src/qemu/qemu_driver.c: Support virDomainOpenConsole
This commit is contained in:
Daniel P. Berrange 2010-07-23 16:00:07 +01:00
parent 7c08fcc439
commit bdb28f4426

View File

@ -13051,6 +13051,82 @@ cleanup:
return ret;
}
static int
qemuDomainOpenConsole(virDomainPtr dom,
const char *devname,
virStreamPtr st,
unsigned int flags)
{
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
int ret = -1;
int i;
virDomainChrDefPtr chr = NULL;
virCheckFlags(0, -1);
qemuDriverLock(driver);
virUUIDFormat(dom->uuid, uuidstr);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) {
qemuReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup;
}
if (!virDomainObjIsActive(vm)) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto cleanup;
}
if (devname) {
if (vm->def->console &&
STREQ(devname, vm->def->console->info.alias))
chr = vm->def->console;
for (i = 0 ; !chr && i < vm->def->nserials ; i++) {
if (STREQ(devname, vm->def->serials[i]->info.alias))
chr = vm->def->serials[i];
}
for (i = 0 ; !chr && i < vm->def->nparallels ; i++) {
if (STREQ(devname, vm->def->parallels[i]->info.alias))
chr = vm->def->parallels[i];
}
} else {
if (vm->def->console)
chr = vm->def->console;
else if (vm->def->nserials)
chr = vm->def->serials[0];
}
if (!chr) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot find character device %s"),
NULLSTR(devname));
goto cleanup;
}
if (chr->type != VIR_DOMAIN_CHR_TYPE_PTY) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
_("character device %s is not using a PTY"),
NULLSTR(devname));
goto cleanup;
}
if (virFDStreamOpenFile(st, chr->data.file.path, O_RDWR) < 0)
goto cleanup;
ret = 0;
cleanup:
if (vm)
virDomainObjUnlock(vm);
qemuDriverUnlock(driver);
return ret;
}
static virDriver qemuDriver = {
VIR_DRV_QEMU,
"QEMU",
@ -13155,7 +13231,7 @@ static virDriver qemuDriver = {
qemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */
qemuDomainGetMemoryParameters, /* domainGetMemoryParameters */
NULL, /* domainOpenConsole */
qemuDomainOpenConsole, /* domainOpenConsole */
};