From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFcIw-000720-Tu for qemu-devel@nongnu.org; Tue, 01 Dec 2009 18:38:46 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFcIr-0006zS-Th for qemu-devel@nongnu.org; Tue, 01 Dec 2009 18:38:46 -0500 Received: from [199.232.76.173] (port=48157 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFcIr-0006zJ-Pb for qemu-devel@nongnu.org; Tue, 01 Dec 2009 18:38:41 -0500 Received: from fmmailgate03.web.de ([217.72.192.234]:42386) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFcIr-0008JG-7o for qemu-devel@nongnu.org; Tue, 01 Dec 2009 18:38:41 -0500 Message-ID: <4B15A8FA.5080804@web.de> Date: Wed, 02 Dec 2009 00:38:34 +0100 From: Jan Kiszka MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigEBED8C0BC233B32879F14D50" Sender: jan.kiszka@web.de Subject: [Qemu-devel] [PATCH] vmstate: Avoid seeking List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Pierre Riteau , qemu-devel , Liran Schour , Juan Quintela This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigEBED8C0BC233B32879F14D50 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Seeking on vmstate save/load does not work if the underlying file is a stream. We could try to make all QEMUFile* forward-seek-aware, but first attempts in this direction indicated that it's saner to convert the few qemu_fseek-on-vmstates users to plain reads/writes. This fixes various subtle vmstate corruptions where unused fields were involved. Signed-off-by: Jan Kiszka --- hw/virtio-net.c | 7 ++----- savevm.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 2f147e5..9ccd4c8 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -745,12 +745,9 @@ static int virtio_net_load(QEMUFile *f, void *opaque= , int version_id) =20 if (version_id >=3D 5) { n->mac_table.in_use =3D qemu_get_be32(f); + qemu_get_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_= ALEN); /* MAC_TABLE_ENTRIES may be different from the saved image */ - if (n->mac_table.in_use <=3D MAC_TABLE_ENTRIES) { - qemu_get_buffer(f, n->mac_table.macs, - n->mac_table.in_use * ETH_ALEN); - } else if (n->mac_table.in_use) { - qemu_fseek(f, n->mac_table.in_use * ETH_ALEN, SEEK_CUR); + if (n->mac_table.in_use > MAC_TABLE_ENTRIES) { n->mac_table.multi_overflow =3D n->mac_table.uni_overflow =3D= 1; n->mac_table.in_use =3D 0; } diff --git a/savevm.c b/savevm.c index 8fe9349..1e54a42 100644 --- a/savevm.c +++ b/savevm.c @@ -959,13 +959,27 @@ const VMStateInfo vmstate_info_buffer =3D { =20 static int get_unused_buffer(QEMUFile *f, void *pv, size_t size) { - qemu_fseek(f, size, SEEK_CUR); + uint8_t buf[1024]; + int block_len; + + while (size > 0) { + block_len =3D MIN(sizeof(buf), size); + size -=3D block_len; + qemu_get_buffer(f, buf, block_len); + } return 0; } =20 static void put_unused_buffer(QEMUFile *f, void *pv, size_t size) { - qemu_fseek(f, size, SEEK_CUR); + static const uint8_t buf[1024]; + int block_len; + + while (size > 0) { + block_len =3D MIN(sizeof(buf), size); + size -=3D block_len; + qemu_put_buffer(f, buf, block_len); + } } =20 const VMStateInfo vmstate_info_unused_buffer =3D { --------------enigEBED8C0BC233B32879F14D50 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAksVqP4ACgkQitSsb3rl5xR4SwCgvcP2/MCrAtqKmdSCxr7enQ03 zOEAoN1IpfHpUMU98UcW3zoUdQJ3N/Rw =u5Jw -----END PGP SIGNATURE----- --------------enigEBED8C0BC233B32879F14D50--