4.1.16: Power-off and restore snapshot failing erratically

This is for discussing general topics about how to use VirtualBox.
Post Reply
Studley
Posts: 2
Joined: 13. Sep 2011, 20:48
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Lots

4.1.16: Power-off and restore snapshot failing erratically

Post by Studley »

Hi,

For some time I've been running a nightly test process (Windows 7 64-bit host) on a VirtualBox guest (Windows XP 32-bit) which is restored to a known snapshot and started. The VM was controlled via a basic command script -

Code: Select all

VBoxManage snapshot "My Test VM" restore "Clean Machine"
VBoxManage startvm "My Test VM"
However, since upgrading from 4.1.12 (I think) to 4.1.16, the restore command fails if the specified VM is already running. (If the VM is stopped, it works correctly.)

Code: Select all

C:\Program Files\Oracle\VirtualBox>VBoxManage snapshot "My Test VM" restore "Clean Machine"
Restoring snapshot d8903d92-a25f-4593-8380-3eafaa290d88
VBoxManage.exe: error: Cannot delete the current state of the running machine (machine state: Running)
VBoxManage.exe: error: Details: code VBOX_E_INVALID_VM_STATE (0x80bb0002), component Console, interface IConsole, callee IUnknown Context: "RestoreSnapshot(pSnapshot, pProgress.asOutParam())" at line 424 of file VBoxManageSnapshot.cpp

C:\Program Files\Oracle\VirtualBox>VBoxManage startvm "My Test VM"
VBoxManage.exe: error: The machine 'My Test VM' is already locked by a session (or being locked or unlocked)
VBoxManage.exe: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interface IMachine, callee IUnknown Context: "LaunchVMProcess(a->session, sessionType.raw(), env.raw(), progress.asOutParam())" at line 561 of file VBoxManageMisc.cpp
It definitely didn't do this prior to my upgrade. I can't see anything related to this in the changelog - is this a deliberate change? I wouldn't be surprised (nor necessarily bothered) if this is intentional, as snapshots are fragile at the best of times - reverting whilst a machine is running is probably not particularly smart, even if it were previously possible.

Which brings me on to Part 2 of this problem. To resolve this new issue, I modified my batch file to pull the plug on the VM prior to reverting it:

Code: Select all

VBoxManage controlvm "My Test VM" poweroff
VBoxManage snapshot "My Test VM" restore "Clean Machine"
VBoxManage startvm "My Test VM"
However, when running this batch file whilst the VM is running, I've observed two different behaviours. Firstly, I've seen it fail to perform the snapshot restore, but still start the VM (so it starts the VM in an unreverted, unclean state):

Code: Select all

C:\Program Files\Oracle\VirtualBox>VBoxManage controlvm "My Test VM" poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

C:\Program Files\Oracle\VirtualBox>VBoxManage snapshot "My Test VM" restore "Clean Machine"
VBoxManage.exe: error: The session is not locked (session state: Unlocked)
VBoxManage.exe: error: Details: code E_UNEXPECTED (0x8000ffff), component Session, interface ISession, callee IUnknown Context: "COMGETTER(Console (console.asOutParam())" at line 284 of file VBoxManageSnapshot.cpp

C:\Program Files\Oracle\VirtualBox>VBoxManage startvm "My Test VM"
Waiting for VM "My Test VM" to power on...
VM "My Test VM" has been successfully started.
Secondly, I've also seen it fail with a more critical error, and also seemingly leave the VM in a locked state. This surprised me as I assumed that when the poweroff command returned, the machine would be ready to receive other commands?:

Code: Select all

C:\Program Files\Oracle\VirtualBox>VBoxManage controlvm "My Test VM" poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

C:\Program Files\Oracle\VirtualBox>VBoxManage snapshot "My Test VM" restore "Clean Machine"
Restoring snapshot d8903d92-a25f-4593-8380-3eafaa290d88
VBoxManage.exe: error: The object is not ready
VBoxManage.exe: error: Details: code E_ACCESSDENIED (0x80070005), component Console, interface IConsole, callee IUnknown Context: "RestoreSnapshot(pSnapshot, pProgress.asOutParam())" at line 424 of file VBoxManageSnapshot.cpp

C:\Program Files\Oracle\VirtualBox>VBoxManage startvm "My Test VM"
VBoxManage.exe: error: The machine 'My Test VM' is already locked by a session (or being locked or unlocked)
VBoxManage.exe: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interface IMachine, callee IUnknown Context: "LaunchVMProcess(a->session, sessionType.raw(), env.raw(), progress.asOutParam())" at line 561 of file VBoxManageMisc.cpp
I seem to have eradicated the problem by hard-coding a delay between the poweroff and restore commands, therefore giving VirtualBox a bit more time to finish cleaning itself up. However, a lot of the above seems very strange, particularly the issues when performing a restore immediately following a poweroff. Does anybody agree/disagree? I am happy to create a bug ticket for it if someone agrees this is a bug.
Post Reply