"Michael S. Tsirkin" <m...@redhat.com> wrote: > On Wed, Dec 02, 2009 at 01:04:31PM +0100, Juan Quintela wrote: >> >> Signed-off-by: Juan Quintela <quint...@redhat.com> >> --- >> 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). 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. > 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.