On Fri, Oct 03, 2014 at 06:47:12PM +0100, Dr. David Alan Gilbert (git) wrote: > From: "Dr. David Alan Gilbert" <dgilb...@redhat.com> > > and use it in loadvm_state. > > Signed-off-by: Dr. David Alan Gilbert <dgilb...@redhat.com> > --- > include/migration/qemu-file.h | 2 ++ > qemu-file.c | 15 +++++++++++++++ > savevm.c | 18 ++++++++++-------- > 3 files changed, 27 insertions(+), 8 deletions(-) > > diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h > index 6ef8ebc..a8cac7a 100644 > --- a/include/migration/qemu-file.h > +++ b/include/migration/qemu-file.h > @@ -300,4 +300,6 @@ static inline void qemu_get_sbe64s(QEMUFile *f, int64_t > *pv) > { > qemu_get_be64s(f, (uint64_t *)pv); > } > + > +int qemu_get_counted_string(QEMUFile *f, uint8_t *buf);
I'd suggest writing the prototype as int qemu_get_counted_string(QEMUFile *f, uint8_t buf[256]); The compiled code will be identical, of course, but it helps to document what the function expects. > #endif > diff --git a/qemu-file.c b/qemu-file.c > index ccc516c..a057b3e 100644 > --- a/qemu-file.c > +++ b/qemu-file.c > @@ -879,6 +879,21 @@ uint64_t qemu_get_be64(QEMUFile *f) > return v; > } > > +/* > + * Get a string whose length is determined by a single preceding byte > + * A preallocated 256 byte buffer must be passed in. > + * Returns: 0 on success and a 0 terminated string in the buffer > + */ > +int qemu_get_counted_string(QEMUFile *f, uint8_t *buf) > +{ > + unsigned int len = qemu_get_byte(f); > + int res = qemu_get_buffer(f, buf, len); > + > + buf[len] = 0; > + > + return res != len; > +} > + > #define QSB_CHUNK_SIZE (1 << 10) > #define QSB_MAX_CHUNK_SIZE (16 * QSB_CHUNK_SIZE) > > diff --git a/savevm.c b/savevm.c > index c3a1f68..cb6f0de 100644 > --- a/savevm.c > +++ b/savevm.c > @@ -908,7 +908,7 @@ int qemu_loadvm_state(QEMUFile *f) > > v = qemu_get_be32(f); > if (v == QEMU_VM_FILE_VERSION_COMPAT) { > - fprintf(stderr, "SaveVM v2 format is obsolete and don't work > anymore\n"); > + error_report("SaveVM v2 format is obsolete and don't work anymore"); These changes of fprintf() to error_report() look like an unrelated cleanup. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
pgpnZj3JTqnDs.pgp
Description: PGP signature