handling Hyper-V automatic startup values
mcoleman at datto.com
Wed Sep 23 23:06:01 UTC 2020
I’m implementing some new functionality in the Hyper-V driver and could use some input on how I should handle automatic startup values.
Microsoft’s Msvm_VirtualSystemSettingData class stores this setting in a property named AutomaticStartupAction:
This property has several possible values with different meanings:
* 2 means “None.”, which represents that the VM will not automatically start at boot. This corresponds to libvirt’s domainGetAutostart outputting boolean false.
* 3 means “Restart if previously active.” This will start the machine at boot if it was running when the host was shut down or unexpectedly powered off. It appears libvirt does not have a way to represent this.
* 4 means “Always start.” This corresponds to libvirt’s domainGetAutostart outputting boolean true.
* 5 through 32768 are reserved.
I’m unsure how to handle the value 3, since libvirt treats this setting as a boolean...
The domainGetAutostart function places the value in an int:
However, virDomainGetAutostart’s docblock says that it will be treated as a boolean:
Its usage in `virsh dominfo` confirms that:
I haven’t investigated how other languages' bindings treat the field.
Currently, my code treats anything over 2 as autostart being enabled (although, perhaps I should ignore 5+). I feel like that pretty closely represents the VM’s configuration, since it will autostart in certain cases and it definitely isn’t configured to never autostart.
For 3 (“Restart if previously active.”), it could be argued that libvirt should only say that autostart is enabled when the VM is running. This would more closely represent what the VM’s runtime behavior will be, since `virsh list —autostart` would show you which VMs would boot if the hypervisor rebooted at that point in time. However, it could be considered confusing because the VM’s configuration would appear to change depending on whether or not it was running.
Ultimately, it seems like libvirt’s concept of autostart functionality needs to be extended. Along those lines, it was pointed out on IRC that libvirt lacks the ability to represent hypervisors’ host shutdown activities:
> danpb: we should introduce a <on_hoststop>..</on_hoststop> lifecycle action in the XML to express what actions to take on host shutdown and one of those actions can be “stop-and-restart-on-next-boot”
Hyper-V has a separate setting, AutomaticShutdownAction, which governs the actions taken when the host stops:
* 2 means “Turn off.” This abruptly powers off the VM.
* 3 means “Save state.” This saves the running VM’s state to disk.
* 4 means “Shutdown.” The performs a clean shutdown of the VM.
* 5 through 32768 are reserved.
It seems to me that the two settings complement each other but cover different functionality. I feel like 3 (“Restart if previously active.”) is more closely related to startup activities than the host stopping.
Since it seems like more pervasive changes are needed, I’d prefer to commit something “good enough” for the Hyper-V driver and then refine it along with the rest of the drivers.
Should I make domainGetAutostart only output true for Hyper-V VMs configured with AutomaticStartupAction=3 when they are running? Or, should I leave it as I currently have it (2 = autostart is disabled; 3+ = autostart is enabled)?
Thanks for your time and input, and apologies for how long this got.
More information about the libvir-list