首页 > 解决方案 > 为什么 libvirt virdomain guest os 可能会忽略重新启动或关闭的请求?

问题描述

来自 libvirt-domain 的 virdomain 类的重启功能:

def reboot(self, flags=0):
        """Reboot a domain, the domain object is still usable thereafter, but
        the domain OS is being stopped for a restart.
        Note that the guest OS may ignore the request.
        Additionally, the hypervisor may check and support the domain
        'on_reboot' XML setting resulting in a domain that shuts down instead
        of rebooting.

        If @flags is set to zero, then the hypervisor will choose the
        method of shutdown it considers best. To have greater control
        pass one or more of the virDomainRebootFlagValues. The order
        in which the hypervisor tries each shutdown method is undefined,
        and a hypervisor is not required to support all methods.

        To use guest agent (VIR_DOMAIN_REBOOT_GUEST_AGENT) the domain XML
        must have <channel> configured.

        Due to implementation limitations in some drivers (the qemu driver,
        for instance) it is not advised to migrate or save a guest that is
        rebooting as a result of this API. Migrating such a guest can lead
        to a plain shutdown on the destination. """
        ret = libvirtmod.virDomainReboot(self._o, flags)
        if ret == -1: raise libvirtError ('virDomainReboot() failed', dom=self)
        return ret

并且我的 qemu/kvm vm 不响应重新启动或关闭的请求,而它响应重置请求。我想知道为什么以及我能做什么。谢谢~

标签: pythonkvmlibvirt

解决方案


您没有提到您正在使用哪个管理程序,所以我将在我的回答中假设 QEMU/KVM。

有两种方法shutdownreboot可以工作。

libvirt/QEMU 采用的默认方法是注入 ACPI 电源按钮事件。大多数来宾操作系统的构建使得某些东西会看到 ACPI 事件并开始正常关闭,但情况并非总是如此。对于重新启动,libvirt 将执行相同的 ACPI 电源按钮注入,但是当客户机完成其关闭序列时,它将被重置以再次启动。

第二种可选方法是在来宾操作系统中安装 QEMU 来宾代理。然后你可以告诉 virsh 使用来宾代理来触发关机/重启。但是,如果您安装了 virtio 驱动程序包,则来宾代理仅适用于某些操作系统、现代 Linux 和 windows。

Avirsh reset完全不同 - 这只是立即重置虚拟 CPU,导致来宾立即重新启动,而没有正常关闭过程。


推荐阅读