qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Subject: [PULL 26/37] qcow2: introduce icount field for snapshots
Date: Tue,  6 Oct 2020 09:29:36 +0200	[thread overview]
Message-ID: <20201006072947.487729-27-pbonzini@redhat.com> (raw)
In-Reply-To: <20201006072947.487729-1-pbonzini@redhat.com>

From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>

This patch introduces the icount field for saving within the snapshot.
It is required for navigation between the snapshots in record/replay mode.

Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Acked-by: Kevin Wolf <kwolf@redhat.com>

--

v7 changes:
 - also fix the test which checks qcow2 snapshot extra data
Message-Id: <160174518284.12451.2301137308458777398.stgit@pasha-ThinkPad-X280>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/qcow2-snapshot.c     |  7 ++++++
 block/qcow2.h              |  3 +++
 docs/interop/qcow2.txt     |  5 ++++
 tests/qemu-iotests/261     | 15 ++++++-----
 tests/qemu-iotests/261.out | 51 +++++++++++++++++++++++++-------------
 5 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 9b68690f56..d68b25e0c5 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -164,6 +164,12 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair,
             sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
         }
 
+        if (sn->extra_data_size >= endof(QCowSnapshotExtraData, icount)) {
+            sn->icount = be64_to_cpu(extra.icount);
+        } else {
+            sn->icount = -1ULL;
+        }
+
         if (sn->extra_data_size > sizeof(extra)) {
             uint64_t extra_data_end;
             size_t unknown_extra_data_size;
@@ -333,6 +339,7 @@ int qcow2_write_snapshots(BlockDriverState *bs)
         memset(&extra, 0, sizeof(extra));
         extra.vm_state_size_large = cpu_to_be64(sn->vm_state_size);
         extra.disk_size = cpu_to_be64(sn->disk_size);
+        extra.icount = cpu_to_be64(sn->icount);
 
         id_str_size = strlen(sn->id_str);
         name_size = strlen(sn->name);
diff --git a/block/qcow2.h b/block/qcow2.h
index b71e444fca..125ea9679b 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -206,6 +206,7 @@ typedef struct QEMU_PACKED QCowSnapshotHeader {
 typedef struct QEMU_PACKED QCowSnapshotExtraData {
     uint64_t vm_state_size_large;
     uint64_t disk_size;
+    uint64_t icount;
 } QCowSnapshotExtraData;
 
 
@@ -219,6 +220,8 @@ typedef struct QCowSnapshot {
     uint32_t date_sec;
     uint32_t date_nsec;
     uint64_t vm_clock_nsec;
+    /* icount value for the moment when snapshot was taken */
+    uint64_t icount;
     /* Size of all extra data, including QCowSnapshotExtraData if available */
     uint32_t extra_data_size;
     /* Data beyond QCowSnapshotExtraData, if any */
diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt
index 7da0d81df8..0463f761ef 100644
--- a/docs/interop/qcow2.txt
+++ b/docs/interop/qcow2.txt
@@ -707,6 +707,11 @@ Snapshot table entry:
 
                     Byte 48 - 55:   Virtual disk size of the snapshot in bytes
 
+                    Byte 56 - 63:   icount value which corresponds to
+                                    the record/replay instruction count
+                                    when the snapshot was taken. Set to -1
+                                    if icount was disabled
+
                     Version 3 images must include extra data at least up to
                     byte 55.
 
diff --git a/tests/qemu-iotests/261 b/tests/qemu-iotests/261
index ddcb04f285..848ffa760d 100755
--- a/tests/qemu-iotests/261
+++ b/tests/qemu-iotests/261
@@ -91,7 +91,10 @@ print_snapshot_table()
         if [ $extra_len -ge 16 ]; then
             echo "    Disk size: $(peek_file_be "$1" $((extra_ofs + 8)) 8)"
         fi
-        if [ $extra_len -gt 16 ]; then
+        if [ $extra_len -ge 24 ]; then
+            echo "    Icount: $(peek_file_be "$1" $((extra_ofs + 16)) 8)"
+        fi
+        if [ $extra_len -gt 24 ]; then
             echo '    Unknown extra data:' \
                 "$(peek_file_raw "$1" $((extra_ofs + 16)) $((extra_len - 16)) \
                    | tr -d '\0')"
@@ -198,12 +201,12 @@ truncate -s 0 "$TEST_DIR/sn0-extra"
 truncate -s $(($(snapshot_table_entry_size "$TEST_DIR/sn0-pre") - 40)) \
     "$TEST_DIR/sn0-post"
 
-# Set sn1's extra data size to 42
-poke_file "$TEST_DIR/sn1-pre" 36 '\x00\x00\x00\x2a'
-truncate -s 42 "$TEST_DIR/sn1-extra"
-poke_file "$TEST_DIR/sn1-extra" 16 'very important data'
+# Set sn1's extra data size to 50
+poke_file "$TEST_DIR/sn1-pre" 36 '\x00\x00\x00\x32'
+truncate -s 50 "$TEST_DIR/sn1-extra"
+poke_file "$TEST_DIR/sn1-extra" 24 'very important data'
 # Grow sn1-post to pad
-truncate -s $(($(snapshot_table_entry_size "$TEST_DIR/sn1-pre") - 82)) \
+truncate -s $(($(snapshot_table_entry_size "$TEST_DIR/sn1-pre") - 90)) \
     "$TEST_DIR/sn1-post"
 
 # Set sn2's extra data size to 8
diff --git a/tests/qemu-iotests/261.out b/tests/qemu-iotests/261.out
index 2600354566..612433ae40 100644
--- a/tests/qemu-iotests/261.out
+++ b/tests/qemu-iotests/261.out
@@ -12,9 +12,10 @@ Snapshots in TEST_DIR/t.IMGFMT.v2.orig:
   [1]
     ID: 2
     Name: sn1
-    Extra data size: 42
+    Extra data size: 50
     VM state size: 0
     Disk size: 67108864
+    Icount: 0
     Unknown extra data: very important data
   [2]
     ID: 3
@@ -29,22 +30,25 @@ Snapshots in TEST_DIR/t.IMGFMT.v3.orig:
   [0]
     ID: 1
     Name: sn0
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
   [1]
     ID: 2
     Name: sn1
-    Extra data size: 42
+    Extra data size: 50
     VM state size: 0
     Disk size: 67108864
+    Icount: 0
     Unknown extra data: very important data
   [2]
     ID: 3
     Name: sn2
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
 
 === Repair botched v3 ===
 
@@ -61,22 +65,25 @@ Snapshots in TEST_DIR/t.IMGFMT:
   [0]
     ID: 1
     Name: sn0
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
   [1]
     ID: 2
     Name: sn1
-    Extra data size: 42
+    Extra data size: 50
     VM state size: 0
     Disk size: 67108864
+    Icount: 0
     Unknown extra data: very important data
   [2]
     ID: 3
     Name: sn2
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
 
 === Add new snapshot ===
 
@@ -85,28 +92,32 @@ Snapshots in TEST_DIR/t.IMGFMT:
   [0]
     ID: 1
     Name: sn0
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
   [1]
     ID: 2
     Name: sn1
-    Extra data size: 42
+    Extra data size: 50
     VM state size: 0
     Disk size: 67108864
+    Icount: 0
     Unknown extra data: very important data
   [2]
     ID: 3
     Name: sn2
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
   [3]
     ID: 4
     Name: sn3
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 0
 
 === Remove different snapshots ===
 
@@ -116,16 +127,18 @@ Snapshots in TEST_DIR/t.IMGFMT:
   [0]
     ID: 2
     Name: sn1
-    Extra data size: 42
+    Extra data size: 50
     VM state size: 0
     Disk size: 67108864
+    Icount: 0
     Unknown extra data: very important data
   [1]
     ID: 3
     Name: sn2
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
 
 --- sn1 ---
 No errors were found on the image.
@@ -133,15 +146,17 @@ Snapshots in TEST_DIR/t.IMGFMT:
   [0]
     ID: 1
     Name: sn0
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
   [1]
     ID: 3
     Name: sn2
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
 
 --- sn2 ---
 No errors were found on the image.
@@ -149,15 +164,17 @@ Snapshots in TEST_DIR/t.IMGFMT:
   [0]
     ID: 1
     Name: sn0
-    Extra data size: 16
+    Extra data size: 24
     VM state size: 0
     Disk size: 67108864
+    Icount: 18446744073709551615
   [1]
     ID: 2
     Name: sn1
-    Extra data size: 42
+    Extra data size: 50
     VM state size: 0
     Disk size: 67108864
+    Icount: 0
     Unknown extra data: very important data
 
 === Reject too much unknown extra data ===
-- 
2.26.2




  parent reply	other threads:[~2020-10-06  8:02 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06  7:29 [PULL 00/37] Build system + accel + record/replay patches for 2020-10-06 Paolo Bonzini
2020-10-06  7:29 ` [PULL 01/37] cpu-timers, icount: new modules Paolo Bonzini
2020-10-06  7:29 ` [PULL 02/37] icount: rename functions to be consistent with the module name Paolo Bonzini
2020-10-06  7:29 ` [PULL 03/37] cpus: prepare new CpusAccel cpu accelerator interface Paolo Bonzini
2020-10-06  7:29 ` [PULL 04/37] cpus: extract out TCG-specific code to accel/tcg Paolo Bonzini
2020-10-06  7:29 ` [PULL 05/37] cpus: extract out qtest-specific code to accel/qtest Paolo Bonzini
2020-10-06  7:29 ` [PULL 06/37] cpus: extract out kvm-specific code to accel/kvm Paolo Bonzini
2020-10-06  7:29 ` [PULL 07/37] cpus: extract out hax-specific code to target/i386/ Paolo Bonzini
2020-10-16  6:48   ` Volker Rümelin
2020-10-16  8:00     ` Claudio Fontana
2020-10-17  7:17       ` Volker Rümelin
2020-10-06  7:29 ` [PULL 08/37] cpus: extract out whpx-specific " Paolo Bonzini
2020-10-06  7:29 ` [PULL 09/37] cpus: extract out hvf-specific code to target/i386/hvf/ Paolo Bonzini
2020-10-06  7:29 ` [PULL 10/37] cpus: cleanup now unneeded includes Paolo Bonzini
2020-10-06  7:29 ` [PULL 11/37] cpus: remove checks for non-NULL cpus_accel Paolo Bonzini
2020-10-06  7:29 ` [PULL 12/37] cpus: add handle_interrupt to the CpusAccel interface Paolo Bonzini
2020-10-06  7:29 ` [PULL 13/37] hvf: remove hvf specific functions from global includes Paolo Bonzini
2020-10-06  7:29 ` [PULL 14/37] whpx: remove whpx " Paolo Bonzini
2020-10-06  7:29 ` [PULL 15/37] hax: remove hax " Paolo Bonzini
2020-10-06  7:29 ` [PULL 16/37] kvm: remove kvm " Paolo Bonzini
2020-10-06  7:29 ` [PULL 17/37] kvm: kvm_init_vcpu take Error pointer Paolo Bonzini
2020-10-06  7:29 ` [PULL 18/37] accel/tcg: use current_machine as it is always set for softmmu Paolo Bonzini
2020-10-06  7:29 ` [PULL 19/37] slirp: Convert Makefile bits to meson bits Paolo Bonzini
2020-10-06  7:29 ` [PULL 20/37] dtc: " Paolo Bonzini
2020-10-06  7:29 ` [PULL 21/37] configure: do not clobber environment CFLAGS/CXXFLAGS/LDFLAGS Paolo Bonzini
2020-10-06  7:29 ` [PULL 22/37] configure: consistently pass CFLAGS/CXXFLAGS/LDFLAGS to meson Paolo Bonzini
2020-10-06  7:29 ` [PULL 23/37] configure: don't enable ASLR for --enable-debug Windows builds Paolo Bonzini
2020-10-06  7:29 ` [PULL 24/37] replay: don't record interrupt poll Paolo Bonzini
2020-10-06  7:29 ` [PULL 25/37] replay: provide an accessor for rr filename Paolo Bonzini
2020-10-06  7:29 ` Paolo Bonzini [this message]
2020-10-06  7:29 ` [PULL 27/37] migration: introduce icount field for snapshots Paolo Bonzini
2020-10-06 13:44   ` Eric Blake
2020-10-06  7:29 ` [PULL 28/37] qapi: introduce replay.json for record/replay-related stuff Paolo Bonzini
2020-10-06  7:29 ` [PULL 29/37] replay: introduce info hmp/qmp command Paolo Bonzini
2020-10-06  7:29 ` [PULL 30/37] replay: introduce breakpoint at the specified step Paolo Bonzini
2020-10-06  7:29 ` [PULL 31/37] replay: implement replay-seek command Paolo Bonzini
2020-10-06  7:29 ` [PULL 32/37] replay: flush rr queue before loading the vmstate Paolo Bonzini
2020-10-06  7:29 ` [PULL 33/37] gdbstub: add reverse step support in replay mode Paolo Bonzini
2020-10-06  7:29 ` [PULL 34/37] gdbstub: add reverse continue " Paolo Bonzini
2020-10-30 15:15   ` Philippe Mathieu-Daudé
2020-10-06  7:29 ` [PULL 35/37] replay: describe reverse debugging in docs/replay.txt Paolo Bonzini
2020-10-06  7:29 ` [PULL 36/37] replay: create temporary snapshot at debugger connection Paolo Bonzini
2020-10-06  7:29 ` [PULL 37/37] tests/acceptance: add reverse debugging test Paolo Bonzini
2020-10-06 20:13 ` [PULL 00/37] Build system + accel + record/replay patches for 2020-10-06 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201006072947.487729-27-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=Pavel.Dovgalyuk@ispras.ru \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).