Ticket #5393 (closed defect: wontfix)
'Discard Current Snapshot and State' sometimes copies current state into a base hard disk rather than disards it
|Reported by:||MarkCranness||Owned by:|
|Version:||VirtualBox 3.0.10||Keywords:||Snapshot, Discard, Revert|
'Discard Current Snapshot and State' sometimes copies the current state into a base hard disk, Confirming/Commiting/Saving the current state, rather than Reverting/Discarding the current state.
(Note: Please ignore my previous ticket re a similar issue: My thinking wasn't right: This one is a bug.)
1) To see this behaviour, perform the following steps:
- Create a new empty VDI file 'DiskB', attach it to a VM, partition it, format it and detach it again (or use an available VDI file that is not currently attached to any VM, AND was never attached to any VM at the time any existing snapshot was made - this is important).
- Choose or create a VM to perform the test. Ensure that the 'DiskB' VDI is not attached.
- Take a new Snapshot on the VM 'Snapshot 1'.
- Attach 'DiskB' to the VM, ensuring that there is NO blue cog icon to the left of the disk name (it will be attached as a Base disk and not via a differencing disk).
- Boot the VM and create a file named 'Change 1.5' on both DiskB and another disk on the VM. (At this point, file 'Change 1.5' is in the base VDI for DiskB, but in the current state differencing disk for the other VM disk.)
- Shutdown the VM.
- Take another new Snapshot 'Snapshot 2'.
- Boot the VM and create a file 'Change 2.5' on both DiskB and the other disk.
- Shutdown the VM.
- Select 'Current State' in the tree and mouse hover over 'Discard Current Snapshot and State' button. Note Status Bar explanatory text says: 'Discard the current snapshot and revert the machine to the state it had before the snapshot was taken'
- Click 'Discard Current Snapshot and State' button. According to the status bar text, this should rollback the 'Change 2.5' change, but leave the 'Change 1.5' file, on both disks.
- Re-attach DiskB to the VM and boot the VM.
- Examine the contents of the disks. You will note that the other VM disk is missing both 'Change 1.5' and 'Change 2.5' files, whereas it should still have 'Change 1.5' (which was the original problem reported at the head of this ticket).
You will also note that DiskB still has 'Change 2.5' on it, as it has been commited/merged into it. DiskB should only have 'Change 1.5' on it. This is a severe error.
2) The cause is that SessionMachine::discardCurrentStateHandler should never in any circumstances first Discard the current snapshot and then Revert the current state, as it currently does when there is more than one snaphot, because a Discard operation has the possibility (demonstrated above) of merging changes into the base hard disk.
It should instead (logically) Revert, then Discard (the now empty machine differencing disks), then Revert again. (Or probably have the first Revert not create new differencing disks anyway, then they won't need to be discarded.)