From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFuA4-0006Oi-S4 for qemu-devel@nongnu.org; Wed, 02 Dec 2009 13:42:48 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFuA0-0006Md-9F for qemu-devel@nongnu.org; Wed, 02 Dec 2009 13:42:48 -0500 Received: from [199.232.76.173] (port=38672 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFuA0-0006MY-1p for qemu-devel@nongnu.org; Wed, 02 Dec 2009 13:42:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51563) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFu9z-00071D-KV for qemu-devel@nongnu.org; Wed, 02 Dec 2009 13:42:43 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB2IggJR009213 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 2 Dec 2009 13:42:42 -0500 Date: Wed, 2 Dec 2009 20:40:01 +0200 From: "Michael S. Tsirkin" Message-ID: <20091202184001.GG3956@redhat.com> References: <20091202145853.GH18519@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [Qemu-devel] Re: [PATCH 33/41] virtio-net: port to vmstate List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: qemu-devel@nongnu.org On Wed, Dec 02, 2009 at 07:38:03PM +0100, Juan Quintela wrote: > "Michael S. Tsirkin" wrote: > > On Wed, Dec 02, 2009 at 01:04:31PM +0100, Juan Quintela wrote: > >> > >> Signed-off-by: Juan Quintela > >> --- > >> hw/virtio-net.c | 148 ++++++++++++++++++++++++------------------------------- > >> 1 files changed, 64 insertions(+), 84 deletions(-) > >> > >> diff --git a/hw/virtio-net.c b/hw/virtio-net.c > >> index 4434827..3a59449 100644 > >> --- a/hw/virtio-net.c > >> +++ b/hw/virtio-net.c > >> @@ -703,6 +703,38 @@ static void virtio_net_tx_timer(void *opaque) > >> virtio_net_flush_tx(n, n->tx_vq); > >> } > >> > >> +/* Restore an uint8_t from an uint32_t > >> + This is a Big hack, but it is how the old state did it. > >> + */ > >> + > >> +static int get_uint8_from_uint32(QEMUFile *f, void *pv, size_t size) > >> +{ > >> + uint8_t *v = pv; > >> + *v = qemu_get_be32(f); > >> + return 0; > >> +} > >> + > >> +static void put_unused(QEMUFile *f, void *pv, size_t size) > >> +{ > >> + fprintf(stderr, "uint8_from_uint32 is used only for backwards compatibility.\n"); > > > > line too long > > > >> + fprintf(stderr, "Never should be used to write a new state.\n"); > >> + exit(0); > > > > I don't understand. what is this dong? > > it is used later. > current code is reading an uint32_t value into a int8_t value. As you > can guess that don't fit (that is the HACK part of it). I expect it fits in practice. But you should range check the value and fail migration on error. > That is only > needed for old versions that we are reading (get_* function has real > code). But we are supposed to never write old versions (*). > Thet that shouldn't happen ever. vmstate guarantees this won't be called? So just assert(1)? Let's not write a ton of code that isn't called? > > > > when > > is this called? Please supply a comment. > > Maybe call assert? > > > > assert or exit is ok for me, what does people preffer? > > Later, Juan. > > (*): My next series will propose to change that and allow to write old > versions, but that didn't exist when this code was written, and > there are still no agreement about how/if doing it.