From nobody Sat Apr 27 21:25:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509447150240671.143790329915; Tue, 31 Oct 2017 03:52:30 -0700 (PDT) Received: from localhost ([::1]:44707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9U9g-0000EX-Dt for importer@patchew.org; Tue, 31 Oct 2017 06:52:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9U5J-0005Uc-E3 for qemu-devel@nongnu.org; Tue, 31 Oct 2017 06:48:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9U5I-0003bB-9M for qemu-devel@nongnu.org; Tue, 31 Oct 2017 06:47:53 -0400 Received: from mail.ispras.ru ([83.149.199.45]:39790) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9U5H-0003Zu-Tt for qemu-devel@nongnu.org; Tue, 31 Oct 2017 06:47:52 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 304EA54006A; Tue, 31 Oct 2017 13:47:51 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 31 Oct 2017 13:47:52 +0300 Message-ID: <20171031104752.3079.69062.stgit@pasha-VirtualBox> In-Reply-To: <20171031104741.3079.26584.stgit@pasha-VirtualBox> References: <20171031104741.3079.26584.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFCPATCH02/20] blkreplay: create temporary overlay for underlaying devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dovgaluk@ispras.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This 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. Signed-off-by: Pavel Dovgalyuk --- block/blkreplay.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ stubs/replay.c | 1 + vl.c | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/block/blkreplay.c b/block/blkreplay.c index 82a88f8..c489d50 100755 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -14,12 +14,69 @@ #include "block/block_int.h" #include "sysemu/replay.h" #include "qapi/error.h" +#include "qapi/qmp/qstring.h" =20 typedef struct Request { Coroutine *co; QEMUBH *bh; } Request; =20 +static BlockDriverState *blkreplay_append_snapshot(BlockDriverState *bs, + Error **errp) +{ + int ret; + BlockDriverState *bs_snapshot; + int64_t total_size; + QemuOpts *opts =3D NULL; + char tmp_filename[PATH_MAX + 1]; + QDict *snapshot_options =3D 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 =3D 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 =3D bdrv_getlength(bs); + if (total_size < 0) { + error_setg_errno(errp, -total_size, "Could not get image size"); + goto out; + } + + opts =3D qemu_opts_create(bdrv_qcow2.create_opts, NULL, 0, &error_abor= t); + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size, &error_abort); + ret =3D 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 =3D bdrv_open(NULL, NULL, snapshot_options, + BDRV_O_RDWR | BDRV_O_TEMPORARY, errp); + snapshot_options =3D NULL; + if (!bs_snapshot) { + goto out; + } + + bdrv_append(bs_snapshot, bs, errp); + + 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 *o= ptions, int flags, goto fail; } =20 + /* Add temporary snapshot to preserve the image */ + if (!replay_snapshot + && !blkreplay_append_snapshot(bs->file->bs, &local_err)) { + ret =3D -EINVAL; + error_propagate(errp, local_err); + goto fail; + } + ret =3D 0; fail: return ret; diff --git a/stubs/replay.c b/stubs/replay.c index 9c8aa48..9991ee5 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -3,6 +3,7 @@ #include "sysemu/sysemu.h" =20 ReplayMode replay_mode; +char *replay_snapshot; =20 int64_t replay_save_clock(unsigned int kind, int64_t clock) { diff --git a/vl.c b/vl.c index ec29909..7aa59f0 100644 --- a/vl.c +++ b/vl.c @@ -4661,7 +4661,7 @@ int main(int argc, char **argv, char **envp) qapi_free_BlockdevOptions(bdo->bdo); g_free(bdo); } - if (snapshot || replay_mode !=3D REPLAY_MODE_NONE) { + if (snapshot) { qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, NULL); }