loadvm: improve tests before bdrv_snapshot_goto()
PATCH v2 1/1 loadvm: improve tests before bdrv_snapshot_goto()
This patch improves the resilience of the load_vmstate() function, doing further and better ordered tests.
In load_vmstate(), if there is any error on bdrv_snapshot_goto(), except if the error is on VM state device, load_vmstate() will return zero and the VM will be started with major corruption chances.
The current process:
- test if there is any writable device without snapshot support
- if exists return -error
- get the device that saves the VM state, possible return -error but unlikely because it was tested earlier
- flush I/O
- run bdrv_snapshot_goto() on devices
- if fails, give an warning and goes to the next (not good!)
- if fails on the VM state device, return zero (not good!)
- check if the requested snapshot exists on the device that saves the VM state and the state is not zero
- if fails return -error
- open the file with the VM state
- if fails return -error
- load the VM state
- if fails return -error
- return zero
New behavior:
- get the device that saves the VM state
- if fails return -error
- check if the requested snapshot exists on the device that saves the VM state and the state is not zero
- if fails return -error
- test if there is any writable device without snapshot support
- if exists return -error
- test if the devices with snapshot support have the requested snapshot
- if anyone fails, return -error
- flush I/O
- run snapshot_goto() on devices
- if anyone fails, return -error
- open the file with the VM state
- if fails return -error
- load the VM state
- if fails return -error
- return zero
do_loadvm must not call vm_start if any error has occurred in load_vmstate.
Changelog from v1
---------------
- Use -ENOTSUP instead of -EINVAL when no device supports snapshots
- Split the verification of the existance of an snapshot on the VM state device and the verification of the size of the saved VM state
--- monitor.c | 3 +- savevm.c | 71 +++++++++++++++++++++++++++++------------------------------- 2 files changed, 36 insertions(+), 38 deletions(-)
monitor.c +2 -1
@@ -2270,8 +2270,9 @@ static void do_loadvm(Monitor *mon, const QDict *qdict)vm_stop (0 ); -if (load_vmstate (name) >=0 && saved_vm_running) +if (load_vmstate (name) ==0 && saved_vm_running) {vm_start (); + } }int monitor_get_fd (Monitor *mon,const char *fdname)
savevm.c +34 -37
109 lines not on this page · raw message
Signature · 1 line
1.7.1
Kevin Wolf
AppliedAm 19.07.2010 20:25, schrieb Miguel Di Ciurcio Filho:
Quoted 46 lines
This patch improves the resilience of the
load_vmstate()function, doing further and better ordered tests.In
load_vmstate(), if there is any error onbdrv_snapshot_goto(), except if the error is on VM state device,load_vmstate()will return zero and the VM will be started with major corruption chances.The current process:
- test if there is any writable device without snapshot support
- if exists return -error
- get the device that saves the VM state, possible return -error but unlikely because it was tested earlier
- flush I/O
- runbdrv_snapshot_goto()on devices
- if fails, give an warning and goes to the next (not good!)
- if fails on the VM state device, return zero (not good!)
- check if the requested snapshot exists on the device that saves the VM state and the state is not zero
- if fails return -error
- open the file with the VM state
- if fails return -error
- load the VM state
- if fails return -error
- return zeroNew behavior:
- get the device that saves the VM state
- if fails return -error
- check if the requested snapshot exists on the device that saves the VM state and the state is not zero
- if fails return -error
- test if there is any writable device without snapshot support
- if exists return -error
- test if the devices with snapshot support have the requested snapshot
- if anyone fails, return -error
- flush I/O
- runsnapshot_goto()on devices
- if anyone fails, return -error
- open the file with the VM state
- if fails return -error
- load the VM state
- if fails return -error
- return zero
do_loadvmmust not callvm_startif any error has occurred inload_vmstate.
Quoted 7 lines
Changelog from v1
---------------
- Use-ENOTSUPinstead of-EINVALwhen no device supports snapshots
- Split the verification of the existance of an snapshot on the VM state device and the verification of the size of the saved VM stateSigned-off-by Miguel Di Ciurcio Filho <[email protected]>
Thanks, applied to the block branch.
Kevin