luposlip wrote:
Actually it seems like Sun already fixed this issue witg version 2.1.2. From the changelog:
Code: Select all
Mac OS X hosts: save the state of running or paused VMs when the host machine’s battery reaches critical level
Can any Sun guy/gal confirm this? I'm not sure it fixes all of the problem, because if the power is suddenly out on i.e. a desktop computer w/o UPS, the above fix isn't probably sufficient, and your suggestion might be a thing to look at.
Explicitly sensing battery level is nice (though such system integration will be very difficult to get right on all platforms, given that low-battery-shutdown thresholds might be implemented in messy window-system software).
IMO it would be most helpful to let us tell VMs to catch any termination signal and save the VM state before exiting. That would safely handle normal user log-offs, accidental window closing, X-server crashes, etc. It could also handle OS shut-down (including due to low battery) because unix, when shutting down, sends sig 15 and waits a while before doing kill -9. However, the delay would have to be long enough to allow VMs to save their state.
On my system (ubuntu 8.10, 2.67GHz i7, 10kRPM disk), it takes just about 10 seconds to save the state of a Windows VM using 2GB of memory. This is exactly how long Ubuntu waits for processes to exit after kill -15 before they get kill -9. This is controlled by code in /etc/init.d/{killprocs,sendsigs} which could be hacked to wait longer.
As a practical matter, VirtualBox would have to install some intercept in the OS-shutdown machinery to reliably allow enough time to save VM state.
Here's an idea: If kernel modules can intercept arbitrary system calls (by hook or crook), then make vboxdrv guarantee a minimum delay between sig 1 or 15 and sig 9 when sent to processes executing VMs. That way, -if- the VM is set up to save state when it gets sig 1 or 15 then it will get enough time; if it's not set up to do that, it will die immediately as usual.