block devices record/replay update
v2 cover block devices record/replay update
This set of patches includes several fixes for preserving the state of the block device images while recording and replaying virtual machine execution.
blkreplay driver now creates temporary overlay for underlaying devices This patch implicitly enables '-snapshot' behavior in record/replay mode. blkreplay layer creates temporary overlays on top of underlaying disk images. It is needed, because creating an overlay over blkreplay with explicit '-snapshot' option breaks the determinism.
v2 changes:
- removed useless bdrv_ref/unref calls (as suggested by Kevin Wolf)
- updated commit messages
- minor changes
---
Pavel Dovgalyuk (3):
block: implement bdrv_snapshot_goto for blkreplay
blkreplay: create temporary overlay for underlaying devices
replay: disable default snapshot for record/replay
block/blkreplay.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ stubs/replay.c | 1 + vl.c | 10 ++++++- 3 files changed, 82 insertions(+), 2 deletions(-)
Signature · 1 line
Pavel Dovgalyuk
PATCH v2 1/3 block: implement bdrv_snapshot_goto for blkreplay
This patch enables making snapshots with blkreplay used in block devices.
This function is required to make bdrv_snapshot_goto without calling .bdrv_open which is not implemented.
v2: updated commit message
--- block/blkreplay.c | 8 ++++++++ 1 file changed, 8 insertions(+)
block/blkreplay.c +8 -0
@@ -130,6 +130,12 @@ static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs)return ret; } +static int blkreplay_snapshot_goto (BlockDriverState *bs, +const char *snapshot_id) +{ +return bdrv_snapshot_goto (bs->file->bs, snapshot_id); +} +static BlockDriver bdrv_blkreplay = { .format_name ="blkreplay" , .protocol_name ="blkreplay" ,
@@ -145,6 +151,8 @@ static BlockDriver bdrv_blkreplay = { .bdrv_co_pwrite_zeroes = blkreplay_co_pwrite_zeroes, .bdrv_co_pdiscard = blkreplay_co_pdiscard, .bdrv_co_flush = blkreplay_co_flush, + + .bdrv_snapshot_goto = blkreplay_snapshot_goto, };static void bdrv_blkreplay_init (void )
Re: [Qemu-devel] [PATCH v2 1/3] block: implement bdrv_snapshot_goto for blkreplay
On 02/28/2017 04:55 AM, Pavel Dovgalyuk wrote:
[meta-comment]
Quoted 6 lines
This patch enables making snapshots with blkreplay used in block devices.
This function is required to makebdrv_snapshot_gotowithout calling .bdrv_open which is not implemented.v2: updated commit message
The v2 information...
Quoted 3 lines
Signed-off-by Pavel Dovgalyuk <[email protected]>---
...fits best here. Anything after the --- is stripped by 'git am', making it ideal for information that is useful to the reviewers but not important to a long-term reader (a year from now, we won't care if it was v2 or v10 that was committed, because git only stores the version that was checked in, and not the iterations prior to it).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 2/3 blkreplay: create temporary overlay for underlaying devices
In reply to Pavel DovgalyukThis patch allows using '-snapshot' behavior in record/replay mode. blkreplay layer creates temporary overlays on top of underlaying disk images. It is needed, because creating an overlay over blkreplay breaks the determinism.
This patch creates similar temporary overlay (when it is needed) under the blkreplay driver. Therefore all block operations are controlled by blkreplay.
v2: removed useless ref/unref (as suggested by Kevin Wolf)
--- block/blkreplay.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ stubs/replay.c | 1 + vl.c | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-)
block/blkreplay.c +65 -0
@@ -14,12 +14,69 @@#include "block/block_int.h" #include "sysemu/replay.h" #include "qapi/error.h" +#include "qapi/qmp/qstring.h" typedef struct Request {Coroutine *co;QEMUBH *bh; }Request ; +static BlockDriverState *blkreplay_append_snapshot (BlockDriverState *bs, +Error **errp) +{ +int ret; +BlockDriverState *bs_snapshot; +int64_t total_size; +QemuOpts *opts =NULL ; +char tmp_filename[PATH_MAX +1 ]; +QDict *snapshot_options =qdict_new (); + +/* Prepare options QDict for the overlay file */ +qdict_put (snapshot_options,"file.driver" ,qstring_from_str ("file" )); +qdict_put (snapshot_options,"driver" ,qstring_from_str ("qcow2" )); + +/* Create temporary file */ + ret =get_tmp_filename (tmp_filename,PATH_MAX +1 ); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Could not get temporary filename" ); + goto out; + } +qdict_put (snapshot_options,"file.filename" , +qstring_from_str (tmp_filename)); + +/* Get the required size from the image */ + total_size =bdrv_getlength (bs); +if (total_size <0 ) { +error_setg_errno (errp, -total_size,"Could not get image size" ); + goto out; + } + + opts =qemu_opts_create (bdrv_qcow2.create_opts,NULL ,0 , &error_abort); +qemu_opt_set_number (opts,BLOCK_OPT_SIZE , total_size, &error_abort); + ret =bdrv_create (&bdrv_qcow2, tmp_filename, opts, errp); +qemu_opts_del (opts); +if (ret <0 ) { +error_prepend (errp,"Could not create temporary overlay '%s': " , + tmp_filename); + goto out; + } + + bs_snapshot =bdrv_open (NULL ,NULL , snapshot_options, +BDRV_O_RDWR |BDRV_O_TEMPORARY , errp); + snapshot_options =NULL ; +if (!bs_snapshot) { + goto out; + } + +bdrv_append (bs_snapshot, bs); + +return bs_snapshot; + +out: +QDECREF (snapshot_options); +return NULL ; +} +static int blkreplay_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) {
@@ -35,6 +92,14 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } +/* Add temporary snapshot to preserve the image */ +if (!replay_snapshot + && !blkreplay_append_snapshot (bs->file->bs, &local_err)) { + ret = -EINVAL ; +error_propagate (errp, local_err); + goto fail; + } + ret =0 ; fail:if (ret <0 ) {
stubs/replay.c +1 -0
@@ -3,6 +3,7 @@#include "sysemu/sysemu.h" ReplayMode replay_mode; +char *replay_snapshot;int64_t replay_save_clock (unsigned int kind,int64_t clock) {
vl.c +1 -1
@@ -4450,7 +4450,7 @@ int main(int argc, char **argv, char **envp) }/* open the virtual block devices */ -if (snapshot || replay_mode !=REPLAY_MODE_NONE ) { +if (snapshot) {qemu_opts_foreach (qemu_find_opts ("drive" ), drive_enable_snapshot,NULL ,NULL ); }
PATCH v2 3/3 replay: disable default snapshot for record/replay
In reply to Pavel DovgalyukThis patch disables setting '-snapshot' option on by default in record/replay mode. This is needed for creating vmstates in record and replay modes.
--- vl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +7 -1
@@ -3140,7 +3140,13 @@ int main(int argc, char **argv, char **envp)drive_add (IF_PFLASH ,-1 , optarg,PFLASH_OPTS );break ;case QEMU_OPTION_snapshot: - snapshot =1 ; + { +Error *blocker =NULL ; + snapshot =1 ; +error_setg (&blocker,QERR_REPLAY_NOT_SUPPORTED , +"-snapshot" ); +replay_add_blocker (blocker); + }break ;case QEMU_OPTION_hdachs: {