From 548f52ea06951c20f0b91cae6cde0512ec073c83 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Tue, 8 Apr 2014 15:29:37 +0100 Subject: Make qemu_peek_buffer loop until it gets it's data Make qemu_peek_buffer repeatedly call fill_buffer until it gets all the data it requires, or until there is an error. At the moment, qemu_peek_buffer will try one qemu_fill_buffer if there isn't enough data waiting, however the kernel is entitled to return just a few bytes, and still leave qemu_peek_buffer with less bytes than it needed. I've seen this fail in a dev world, and I think it could theoretically fail in the peeking of the subsection headers in the current world. Comment qemu_peek_byte to point out it's not guaranteed to work for non-continuous peeks Signed-off-by: Dr. David Alan Gilbert Reviewed-by: ChenLiang Signed-off-by: Juan Quintela --- include/migration/qemu-file.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/migration/qemu-file.h') diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index a191fb6..c90f529 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -123,6 +123,11 @@ void qemu_put_be32(QEMUFile *f, unsigned int v); void qemu_put_be64(QEMUFile *f, uint64_t v); int qemu_peek_buffer(QEMUFile *f, uint8_t *buf, int size, size_t offset); int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size); +/* + * Note that you can only peek continuous bytes from where the current pointer + * is; you aren't guaranteed to be able to peak to +n bytes unless you've + * previously peeked +n-1. + */ int qemu_peek_byte(QEMUFile *f, int offset); int qemu_get_byte(QEMUFile *f); void qemu_file_skip(QEMUFile *f, int size); -- cgit v1.1