[libvirt] [PATCH 06/11] Support virDomainOpenConsole with QEMU
Daniel P. Berrange
berrange at redhat.com
Mon Nov 8 16:40:03 UTC 2010
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
---
src/qemu/qemu_driver.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 77 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c6c3133..db3546f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13031,6 +13031,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",
@@ -13135,7 +13211,7 @@ static virDriver qemuDriver = {
qemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */
qemuDomainGetMemoryParameters, /* domainGetMemoryParameters */
- NULL, /* domainOpenConsole */
+ qemuDomainOpenConsole, /* domainOpenConsole */
};
--
1.7.2.3
More information about the libvir-list
mailing list