[libvirt] [PATCH] Reboot support for QEMU/KVM

This patch implements reboot support on qemu_driver. It is so simple that I am wondering if there is some problem I am missing, that would be the reason it wasn't implemented yet. I hope not. :) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- src/qemu_driver.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/src/qemu_driver.c b/src/qemu_driver.c index a88cb75..9ce53ad 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -2182,6 +2182,27 @@ static int qemudDomainShutdown(virDomainPtr dom) { } +static int qemudDomainReboot(virDomainPtr dom) { + struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; + virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + char* info; + + if (!vm) { + qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, + _("no domain with matching id %d"), dom->id); + return -1; + } + + if (qemudMonitorCommand(driver, vm, "system_reset", &info) < 0) { + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + "%s", _("reboot operation failed")); + return -1; + } + VIR_FREE(info); + return 0; +} + + static int qemudDomainDestroy(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); @@ -4032,7 +4053,7 @@ static virDriver qemuDriver = { qemudDomainSuspend, /* domainSuspend */ qemudDomainResume, /* domainResume */ qemudDomainShutdown, /* domainShutdown */ - NULL, /* domainReboot */ + qemudDomainReboot, /* domainReboot */ qemudDomainDestroy, /* domainDestroy */ qemudDomainGetOSType, /* domainGetOSType */ qemudDomainGetMaxMemory, /* domainGetMaxMemory */ -- 1.5.5.GIT

On Tue, Oct 07, 2008 at 05:55:37PM -0300, Eduardo Habkost wrote:
This patch implements reboot support on qemu_driver.
It is so simple that I am wondering if there is some problem I am missing, that would be the reason it wasn't implemented yet. I hope not. :)
The reboot command is intended todo a controlled shutdown, followed by warm restart. Doesn't the system_reset command do an immediate warm reboot ? I think we needs to happen is that we invoke the 'system_shutdown' command, and when we detect the VM has quit, then manually start it again. This is technically a cold reboot, but its close enough
+static int qemudDomainReboot(virDomainPtr dom) { + struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; + virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + char* info; + + if (!vm) { + qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, + _("no domain with matching id %d"), dom->id); + return -1; + } + + if (qemudMonitorCommand(driver, vm, "system_reset", &info) < 0) { + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + "%s", _("reboot operation failed")); + return -1; + } + VIR_FREE(info); + return 0; +} + + static int qemudDomainDestroy(virDomainPtr dom) {
Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Tue, Oct 07, 2008 at 09:58:47PM +0100, Daniel P. Berrange wrote:
On Tue, Oct 07, 2008 at 05:55:37PM -0300, Eduardo Habkost wrote:
This patch implements reboot support on qemu_driver.
It is so simple that I am wondering if there is some problem I am missing, that would be the reason it wasn't implemented yet. I hope not. :)
The reboot command is intended todo a controlled shutdown, followed by warm restart. Doesn't the system_reset command do an immediate warm reboot ?
Yes, it does. Sorry, I should have read the virDomainReboot() description on the API documentation first.
I think we needs to happen is that we invoke the 'system_shutdown' command, and when we detect the VM has quit, then manually start it again. This is technically a cold reboot, but its close enough
It would be better than not supporting reboot at all. Maybe libvirt itself could fallback to this if reboot is not implemented? If not, maybe the UIs using libvirt could do that? -- Eduardo
participants (2)
-
Daniel P. Berrange
-
Eduardo Habkost