From nobody Sun May 5 00:28:05 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.zoho.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488280877902679.9038582471993; Tue, 28 Feb 2017 03:21:17 -0800 (PST) Received: from localhost ([::1]:60299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cifqF-0000IF-M6 for importer@patchew.org; Tue, 28 Feb 2017 06:21:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cifRK-0005A2-8v for qemu-devel@nongnu.org; Tue, 28 Feb 2017 05:55:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cifRJ-0006aA-FV for qemu-devel@nongnu.org; Tue, 28 Feb 2017 05:55:30 -0500 Received: from mail.ispras.ru ([83.149.199.45]:34304) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cifRG-0006Wx-Ty; Tue, 28 Feb 2017 05:55:27 -0500 Received: from [10.10.150.127] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 2097C54009E; Tue, 28 Feb 2017 13:55:26 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Tue, 28 Feb 2017 13:55:27 +0300 Message-ID: <20170228105527.1284.44425.stgit@PASHA-ISP> In-Reply-To: <20170228105521.1284.11059.stgit@PASHA-ISP> References: <20170228105521.1284.11059.stgit@PASHA-ISP> User-Agent: StGit/0.16 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] [PATCH v2 1/3] block: implement bdrv_snapshot_goto for blkreplay 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: kwolf@redhat.com, pbonzini@redhat.com, dovgaluk@ispras.ru, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 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 Signed-off-by: Pavel Dovgalyuk --- block/blkreplay.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/blkreplay.c b/block/blkreplay.c index cfc8c5b..ddcf344 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -130,6 +130,12 @@ static int coroutine_fn blkreplay_co_flush(BlockDriver= State *bs) return ret; } =20 +static int blkreplay_snapshot_goto(BlockDriverState *bs, + const char *snapshot_id) +{ + return bdrv_snapshot_goto(bs->file->bs, snapshot_id); +} + static BlockDriver bdrv_blkreplay =3D { .format_name =3D "blkreplay", .protocol_name =3D "blkreplay", @@ -145,6 +151,8 @@ static BlockDriver bdrv_blkreplay =3D { .bdrv_co_pwrite_zeroes =3D blkreplay_co_pwrite_zeroes, .bdrv_co_pdiscard =3D blkreplay_co_pdiscard, .bdrv_co_flush =3D blkreplay_co_flush, + + .bdrv_snapshot_goto =3D blkreplay_snapshot_goto, }; =20 static void bdrv_blkreplay_init(void) From nobody Sun May 5 00:28:05 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.zoho.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488281064799144.68325514384776; Tue, 28 Feb 2017 03:24:24 -0800 (PST) Received: from localhost ([::1]:60316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciftH-0002zY-6y for importer@patchew.org; Tue, 28 Feb 2017 06:24:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cifRU-0005IL-2T for qemu-devel@nongnu.org; Tue, 28 Feb 2017 05:55:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cifRT-0006kD-3O for qemu-devel@nongnu.org; Tue, 28 Feb 2017 05:55:40 -0500 Received: from mail.ispras.ru ([83.149.199.45]:34324) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cifRM-0006aw-GP; Tue, 28 Feb 2017 05:55:32 -0500 Received: from [10.10.150.127] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 9F5425400A0; Tue, 28 Feb 2017 13:55:31 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Tue, 28 Feb 2017 13:55:33 +0300 Message-ID: <20170228105532.1284.71515.stgit@PASHA-ISP> In-Reply-To: <20170228105521.1284.11059.stgit@PASHA-ISP> References: <20170228105521.1284.11059.stgit@PASHA-ISP> User-Agent: StGit/0.16 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] [PATCH v2 2/3] 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: kwolf@redhat.com, pbonzini@redhat.com, dovgaluk@ispras.ru, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 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. v2: removed useless ref/unref (as suggested by Kevin Wolf) 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 ddcf344..de91def 100644 --- 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); + + 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: if (ret < 0) { 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 e10a27b..876a55a 100644 --- a/vl.c +++ b/vl.c @@ -4450,7 +4450,7 @@ int main(int argc, char **argv, char **envp) } =20 /* open the virtual block devices */ - if (snapshot || replay_mode !=3D REPLAY_MODE_NONE) { + if (snapshot) { qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, NULL); } From nobody Sun May 5 00:28:05 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.zoho.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488280822389513.4950992584805; Tue, 28 Feb 2017 03:20:22 -0800 (PST) Received: from localhost ([::1]:60292 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cifpN-0007qV-3d for importer@patchew.org; Tue, 28 Feb 2017 06:20:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cifRU-0005J9-QF for qemu-devel@nongnu.org; Tue, 28 Feb 2017 05:55:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cifRU-0006lJ-2S for qemu-devel@nongnu.org; Tue, 28 Feb 2017 05:55:40 -0500 Received: from mail.ispras.ru ([83.149.199.45]:34340) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cifRS-0006hB-10; Tue, 28 Feb 2017 05:55:38 -0500 Received: from [10.10.150.127] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 396455400A2; Tue, 28 Feb 2017 13:55:37 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Tue, 28 Feb 2017 13:55:38 +0300 Message-ID: <20170228105538.1284.15548.stgit@PASHA-ISP> In-Reply-To: <20170228105521.1284.11059.stgit@PASHA-ISP> References: <20170228105521.1284.11059.stgit@PASHA-ISP> User-Agent: StGit/0.16 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] [PATCH v2 3/3] replay: disable default snapshot for record/replay 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: kwolf@redhat.com, pbonzini@redhat.com, dovgaluk@ispras.ru, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch disables setting '-snapshot' option on by default in record/replay mode. This is needed for creating vmstates in record and replay modes. Signed-off-by: Pavel Dovgalyuk --- vl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index 876a55a..1b85923 100644 --- a/vl.c +++ b/vl.c @@ -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 =3D 1; + { + Error *blocker =3D NULL; + snapshot =3D 1; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, + "-snapshot"); + replay_add_blocker(blocker); + } break; case QEMU_OPTION_hdachs: {