Implement and test asn1 ber visitors
v3 cover Implement and test asn1 ber visitors
These patches implement asn1 ber visitors for encoding and decoding data.
changed since v2:
Moved qemu-file.c to util/
Left the bdrv functions in savevm.c
Fixed a typo in the introduction to qapi c arrays patch Fixed two indendations in the qapi c arrays patch
changed since v1:
Moved .c files into qapi directory
Moved .h files into include/qapi
Added sized buffer code
cleaned up Makefile changes to play nicer
Broke out patches for output/input visitors
New tests in tests/test-visitor-serialization.c
Fixed width integer encoding now marked with application specific bit Removed qapi array code
Added Mike Roth's previously sent carray qapi patch
misc small cleanups
forward ported to keep up with git HEAD
added real number support
PATCH v3 1/9 qemu-file
This patch reorganizes qemu file operations to be in their own source file instead of being lumped in savevm.c. Besides being more logical for maintenance it also makes it easier for future users of the file functions to add tests.
v4 move qemu-file.c into util/ , leave the bdrv functions where they are for now v3 forward port to resolve conflicts
v2 forward port to resolve conflicts, strip trailing whitespace during move
--- include/migration/qemu-file.h | 5 + savevm.c | 656 +-------------------------------------- util/Makefile.objs | 1 + util/qemu-file.c | 682 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 689 insertions(+), 655 deletions(-) create mode 100644 util/qemu-file.c
include/migration/qemu-file.h +5 -0
@@ -98,6 +98,11 @@ void qemu_file_reset_rate_limit(QEMUFile *f);void qemu_file_set_rate_limit (QEMUFile *f,int64_t new_rate);int64_t qemu_file_get_rate_limit (QEMUFile *f);int qemu_file_get_error (QEMUFile *f); +void qemu_file_set_error (QEMUFile *f,int ret); +int qemu_peek_buffer (QEMUFile *f,uint8_t *buf,int size,size_t offset); +int qemu_peek_byte (QEMUFile *f,int offset); +void qemu_file_skip (QEMUFile *f,int size); +void qemu_fflush (QEMUFile *f);static inline void qemu_put_be64s (QEMUFile *f,const uint64_t *pv) {
savevm.c +1 -655
668 lines not on this page · raw message
util/Makefile.objs +1 -0
@@ -9,3 +9,4 @@ util-obj-y += error.o qemu-error.o util-obj-$(CONFIG_POSIX) += compatfd.o util-obj-y += iov.o aes.o qemu-config.o qemu-sockets.o uri.o notify.o util-obj-y += qemu-option.o qemu-progress.o +util-obj-y += qemu-file.o
util/qemu-file.c new file +682 -0
682 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v3 2/9 qapi_c_arrays.diff
In reply to Joel SchoppForward ported Mike's previously sent patch
(see http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg05782.html ) in my series since it implements a qapi array interface the ASN.1 BER visitor needs.
Generally these will be serialized into lists, but the representation can be of any form so long as it can be deserialized into a single-dimension C array.
--- include/qapi/visitor-impl.h | 4 ++++ include/qapi/visitor.h | 4 ++++ qapi/qapi-visit-core.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+)
include/qapi/visitor-impl.h +4 -0
@@ -34,6 +34,10 @@ struct Visitorvoid (*type_str)(Visitor *v,char **obj,const char *name,Error **errp);void (*type_number)(Visitor *v,double *obj,const char *name,Error **errp); +void (*start_carray)(Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp); +void (*next_carray)(Visitor *v,Error **errp); +void (*end_carray)(Visitor *v,Error **errp);/* May be NULL */ void (*start_optional)(Visitor *v, bool *present, const char *name,
include/qapi/visitor.h +4 -0
@@ -51,5 +51,9 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_start_carray (Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp); +void visit_next_carray (Visitor *v,Error **errp); +void visit_end_carray (Visitor *v,Error **errp);#endif
qapi/qapi-visit-core.c +25 -0
@@ -313,3 +313,28 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],g_free (enum_str); *obj = value; } + +void visit_start_carray (Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp) +{ +g_assert (v->start_carray); +if (!error_is_set (errp)) { + v->start_carray (v, obj, name, elem_count, elem_size, errp); + } +} + +void visit_next_carray (Visitor *v,Error **errp) +{ +g_assert (v->next_carray); +if (!error_is_set (errp)) { + v->next_carray (v, errp); + } +} + +void visit_end_carray (Visitor *v,Error **errp) +{ +g_assert (v->end_carray); +if (!error_is_set (errp)) { + v->end_carray (v, errp); + } +}
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 2/9] qapi_c_arrays.diff
You need to adjust your patch script. This will make the summary in git be:
qapi_c_arrays.gdiff
Forward ported Mike's previously sent patch (see
http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg05782.html )
...
Regards,
Anthony Liguori
Quoted 82 lines · Joel Schopp
Forward ported Mike's previously sent patch
(see http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg05782.html ) in my series since it implements a qapi array interface the ASN.1 BER visitor needs.Generally these will be serialized into lists, but the representation can be of any form so long as it can be deserialized into a single-dimension C array.
Cc Michael Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Michael Roth <[email protected]>Signed-off-by Joel Schopp <[email protected]>--- include/qapi/visitor-impl.h | 4 ++++ include/qapi/visitor.h | 4 ++++ qapi/qapi-visit-core.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+)include/qapi/visitor-impl.h +4
-0@@ -34,6 +34,10 @@ struct Visitorvoid (*type_str)(Visitor *v,char **obj,const char *name,Error **errp);void (*type_number)(Visitor *v,double *obj,const char *name,Error **errp); +void (*start_carray)(Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp); +void (*next_carray)(Visitor *v,Error **errp); +void (*end_carray)(Visitor *v,Error **errp);/* May be NULL */ void (*start_optional)(Visitor *v, bool *present, const char *name,include/qapi/visitor.h +4
-0@@ -51,5 +51,9 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_start_carray (Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp); +void visit_next_carray (Visitor *v,Error **errp); +void visit_end_carray (Visitor *v,Error **errp);#endif qapi/qapi-visit-core.c +25
-0@@ -313,3 +313,28 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],g_free (enum_str); *obj = value; } + +void visit_start_carray (Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp) +{ +g_assert (v->start_carray); +if (!error_is_set (errp)) { + v->start_carray (v, obj, name, elem_count, elem_size, errp); + } +} + +void visit_next_carray (Visitor *v,Error **errp) +{ +g_assert (v->next_carray); +if (!error_is_set (errp)) { + v->next_carray (v, errp); + } +} + +void visit_end_carray (Visitor *v,Error **errp) +{ +g_assert (v->end_carray); +if (!error_is_set (errp)) { + v->end_carray (v, errp); + } +}Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 2/9] qapi_c_arrays.diff
In reply to Joel SchoppQuoted 35 lines · Joel Schopp
Forward ported Mike's previously sent patch
(see http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg05782.html ) in my series since it implements a qapi array interface the ASN.1 BER visitor needs.Generally these will be serialized into lists, but the representation can be of any form so long as it can be deserialized into a single-dimension C array.
Cc Michael Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Michael Roth <[email protected]>Signed-off-by Joel Schopp <[email protected]>--- include/qapi/visitor-impl.h | 4 ++++ include/qapi/visitor.h | 4 ++++ qapi/qapi-visit-core.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+)+++
b/include/qapi/visitor.hinclude/qapi/visitor.h +4
-0@@ -51,5 +51,9 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_start_carray (Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp); +void visit_next_carray (Visitor *v,Error **errp); +void visit_end_carray (Visitor *v,Error **errp);#endif qapi/qapi-visit-core.c +0
-0@@ -313,3 +313,28 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],g_free (enum_str);
qapi/qapi-visit-core.c void input_type_enum(Visitor *v, int *obj, const char *strings[], · line 323
Quoted 10 lines
qapi/qapi-visit-core.c +8
-0*obj = value; } + +void visit_start_carray (Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp) +{ +g_assert (v->start_carray); +if (!error_is_set (errp)) { + v->start_carray (v, obj, name, elem_count, elem_size, errp); + }
So this is a c-like array with a given number of elements and each element having to have the same size? As long as all use cases for QEMU can live with this, I guess it's fine, though an array of sized buffers, each with different size, may be more 'general'. How many other callers are there so that we can talk about disparities between visitors as mentioned in the comment in 5/9? At least we would have immediate callers for the sized buffer interface.
http://lists.gnu.org/archive/html/qemu-devel/2013-03/msg02254.html
Regards,
Stefan
PATCH v3 3/9 two new file wrappers
In reply to Joel SchoppAdd a 3 very short file wrapper functions to make code that follows more readable. Also export an existing function that is currently static.
--- include/migration/qemu-file.h | 3 +++ util/qemu-file.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/migration/qemu-file.h +3 -0
@@ -68,6 +68,9 @@ int qemu_fclose(QEMUFile *f);int64_t qemu_ftell (QEMUFile *f);void qemu_put_buffer (QEMUFile *f,const uint8_t *buf,int size);void qemu_put_byte (QEMUFile *f,int v); +int qemu_read_bytes (QEMUFile *f,uint8_t *buf,int size); +int qemu_peek_bytes (QEMUFile *f,uint8_t *buf,int size,size_t offset); +int qemu_write_bytes (QEMUFile *f,const uint8_t *buf,int size);static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {
util/qemu-file.c +30 -0
@@ -680,3 +680,33 @@ uint64_t qemu_get_be64(QEMUFile *f)return v; } +int qemu_read_bytes (QEMUFile *f,uint8_t *buf,int size) +{ +if (qemu_file_get_error (f)) { +return -1 ; + } +return qemu_get_buffer (f, buf, size); +} + +int qemu_peek_bytes (QEMUFile *f,uint8_t *buf,int size,size_t offset) +{ +if (qemu_file_get_error (f)) { +return -1 ; + } +return qemu_peek_buffer (f, buf, size, offset); +} + +int qemu_write_bytes (QEMUFile *f,const uint8_t *buf,int size) +{ +if (qemu_file_get_error (f)) { +return -1 ; + } + +qemu_put_buffer (f, buf, size); + +if (qemu_file_get_error (f)) { +return -1 ; + } + +return size; +}
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 3/9] two new file wrappers
Quoted 1 line · Joel Schopp
Add a 3 very short file wrapper functions to make code that follows more
s/a 3/3/
util/qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 691
Quoted 13 lines
readable. Also export an existing function that is currently static.
Cc Michael Tsirkin <[email protected]>Signed-off-by Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>--- include/migration/qemu-file.h | 3 +++ util/qemu-file.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)util/qemu-file.c +2
-0+ +int qemu_peek_bytes (QEMUFile *f,uint8_t *buf,int size,size_t offset)
Should we be using off_t instead of size_t for offset; and size_t instead of int for size (which implies ssize_t for return value)?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/9] two new file wrappers
Quoted 14 lines · Eric Blake
Quoted 1 line · Joel Schopp
Add a 3 very short file wrapper functions to make code that follows more
s/a 3/3/
Quoted 10 lines
readable. Also export an existing function that is currently static.
Cc Michael Tsirkin <[email protected]>Signed-off-by Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>--- include/migration/qemu-file.h | 3 +++ util/qemu-file.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
Quoted 5 lines
util/qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 691
Quoted 2 lines
util/qemu-file.c +2
-0+ +int qemu_peek_bytes (QEMUFile *f,uint8_t *buf,int size,size_t offset)Should we be using
off_tinstead ofsize_tfor offset; andsize_tinstead of int for size (which impliesssize_tfor return value)?
Good question. Existing functions have signatures like this:
void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) static void qemu_file_skip(QEMUFile *f, int size)
static int qemu_peek_buffer(QEMUFile *f, uint8_t *buf, int size, size_t offset) static int qemu_peek_byte(QEMUFile *f, int offset)
So it's better if we line up behind them...
Stefan
PATCH v3 4/9 qemu_qsb.diff
In reply to Joel SchoppThis patch adds support functions for operating on in memory sized file buffers.
--- include/migration/qemu-file.h | 12 +++ include/qemu-common.h | 15 ++++ util/qemu-file.c | 184 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+)
include/migration/qemu-file.h +12 -0
@@ -24,6 +24,8 @@#ifndef QEMU_FILE_H #define QEMU_FILE_H 1 +#include <stdint.h> +/* This function writes a chunk of data to a file at the given position. * The pos argument can be ignored if the file is only being used for * streaming. The handler should try to write all of the data it can.
@@ -58,6 +60,14 @@ typedef struct QEMUFileOps {QEMUFileGetFD *get_fd; } QEMUFileOps; +struct QEMUSizedBuffer { +unsigned char *buffer; +uint64_t size; +uint64_t used; +}; + +typedef struct QEMUSizedBuffer QEMUSizedBuffer ; +QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops);QEMUFile *qemu_fopen (const char *filename,const char *mode);QEMUFile *qemu_fdopen (int fd,const char *mode);
@@ -71,6 +81,8 @@ void qemu_put_byte(QEMUFile *f, int v);int qemu_read_bytes (QEMUFile *f,uint8_t *buf,int size);int qemu_peek_bytes (QEMUFile *f,uint8_t *buf,int size,size_t offset);int qemu_write_bytes (QEMUFile *f,const uint8_t *buf,int size); +QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input); +const QEMUSizedBuffer *qemu_buf_get (QEMUFile *f);static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {
include/qemu-common.h +15 -0
@@ -442,4 +442,19 @@ int64_t pow2floor(int64_t value);int uleb128_encode_small (uint8_t *out,uint32_t n);int uleb128_decode_small (const uint8_t *in,uint32_t *n); +/* QEMU Sized Buffer */ +#include "include/migration/qemu-file.h" +QEMUSizedBuffer *qsb_create (const uint8_t *buffer,uint64_t len); +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *); +void qsb_free (QEMUSizedBuffer *); +uint64_t qsb_set_length (QEMUSizedBuffer *qsb,uint64_t length); +uint64_t qsb_get_length (const QEMUSizedBuffer *qsb); +const unsigned char *qsb_get_buffer (const QEMUSizedBuffer *,int64_t pos); +int qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf, +int64_t pos,int size); +int qsb_append_qsb (QEMUSizedBuffer *dest,const QEMUSizedBuffer *src); +int qsb_append (QEMUSizedBuffer *dest,const uint8_t *buffer,uint64_t len); + + +#endif
util/qemu-file.c +184 -0
187 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 4/9] qemu_qsb.diff
Quoted 1 line · Joel Schopp
This patch adds support functions for operating on in memory sized file buffers.
There's been some past refactorings to remove non-migration users of QEMUFile, and AFAIK that's still the case today. QEMUFile satisfies funky requirements like rate-limiting, buffering, etc that were specific to migration.
IIUC all we want here is an abstraction on top of write()/memcpy(), and access to qemu_{put|get}_be* utility functions.
Have you considered rolling those abstractions in the visitor implementations as opposed to extending QEMUFile, and using be*_to_cpus/cpus_to_be* helpers directly instead (like block/qcow2.c does, for example)?
Quoted 266 lines
Signed-off-by Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>--- include/migration/qemu-file.h | 12 +++ include/qemu-common.h | 15 ++++ util/qemu-file.c | 184 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+)include/migration/qemu-file.h +12
-0@@ -24,6 +24,8 @@#ifndef QEMU_FILE_H #define QEMU_FILE_H 1 +#include <stdint.h> +/* This function writes a chunk of data to a file at the given position. * The pos argument can be ignored if the file is only being used for * streaming. The handler should try to write all of the data it can. @@ -58,6 +60,14 @@ typedef struct QEMUFileOps {QEMUFileGetFD *get_fd; } QEMUFileOps; +struct QEMUSizedBuffer { +unsigned char *buffer; +uint64_t size; +uint64_t used; +}; + +typedef struct QEMUSizedBuffer QEMUSizedBuffer ; +QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops);QEMUFile *qemu_fopen (const char *filename,const char *mode);QEMUFile *qemu_fdopen (int fd,const char *mode);@@ -71,6 +81,8 @@ void qemu_put_byte(QEMUFile *f, int v);int qemu_read_bytes (QEMUFile *f,uint8_t *buf,int size);int qemu_peek_bytes (QEMUFile *f,uint8_t *buf,int size,size_t offset);int qemu_write_bytes (QEMUFile *f,const uint8_t *buf,int size); +QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input); +const QEMUSizedBuffer *qemu_buf_get (QEMUFile *f);static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {include/qemu-common.h +15
-0@@ -442,4 +442,19 @@ int64_t pow2floor(int64_t value);int uleb128_encode_small (uint8_t *out,uint32_t n);int uleb128_decode_small (const uint8_t *in,uint32_t *n); +/* QEMU Sized Buffer */ +#include "include/migration/qemu-file.h" +QEMUSizedBuffer *qsb_create (const uint8_t *buffer,uint64_t len); +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *); +void qsb_free (QEMUSizedBuffer *); +uint64_t qsb_set_length (QEMUSizedBuffer *qsb,uint64_t length); +uint64_t qsb_get_length (const QEMUSizedBuffer *qsb); +const unsigned char *qsb_get_buffer (const QEMUSizedBuffer *,int64_t pos); +int qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf, +int64_t pos,int size); +int qsb_append_qsb (QEMUSizedBuffer *dest,const QEMUSizedBuffer *src); +int qsb_append (QEMUSizedBuffer *dest,const uint8_t *buffer,uint64_t len); + + +#endif util/qemu-file.c +184
-0@@ -710,3 +710,187 @@ int qemu_write_bytes(QEMUFile *f, const uint8_t *buf, int size)return size; } + + +QEMUSizedBuffer *qsb_create (const uint8_t *buffer,uint64_t len) +{ +QEMUSizedBuffer *qsb; +uint64_t alloc_len; + + alloc_len = (len >1024 ) ? len :1024 ; + + qsb =g_new0 (QEMUSizedBuffer,1 ); +if (!qsb) { +return NULL ; + } + + qsb->buffer =g_malloc (alloc_len); +if (!qsb->buffer) { +g_free (qsb); +return NULL ; + } + qsb->size = alloc_len; + +if (buffer) { +memcpy (qsb->buffer, buffer, len); + qsb->used = len; + } + +return qsb; +} + +void qsb_free (QEMUSizedBuffer *qsb) +{ +if (!qsb) { +return ; + } +g_free (qsb->buffer); +g_free (qsb); +} + +uint64_t qsb_get_length (const QEMUSizedBuffer *qsb) +{ +return qsb->used; +} + +uint64_t qsb_set_length (QEMUSizedBuffer *qsb,uint64_t new_len) +{ +if (new_len <= qsb->size) { + qsb->used = new_len; + }else { + qsb->used = qsb->size; + } +return qsb->used; +} + +const unsigned char *qsb_get_buffer (const QEMUSizedBuffer *qsb,int64_t pos) +{ +if (pos < qsb->used) { +return &qsb->buffer[pos]; + } +return NULL ; +} + +int qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf, +int64_t pos,int size) +{ +if (pos + size > qsb->size) { + qsb->buffer =g_realloc (qsb->buffer, pos + size +1024 ); +if (qsb->buffer ==NULL ) { +return -ENOMEM ; + } + qsb->size = pos + size; + } +memcpy (&qsb->buffer[pos], buf, size); +if (pos + size > qsb->used) { + qsb->used = pos + size; + } + +return size; +} + +int qsb_append_qsb (QEMUSizedBuffer *dest,const QEMUSizedBuffer *src) +{ +return qsb_write_at (dest,qsb_get_buffer (src,0 ), +qsb_get_length (dest),qsb_get_length (src)); +} + +int qsb_append (QEMUSizedBuffer *dest,const uint8_t *buf,uint64_t len) +{ +return qsb_write_at (dest, buf, +qsb_get_length (dest), len); +} + +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *in) +{ +return qsb_create (qsb_get_buffer (in,0 ), +qsb_get_length (in)); +} + +typedef struct QEMUBuffer { +QEMUSizedBuffer *qsb; +QEMUFile *file; +}QEMUBuffer ; + +static int buf_get_buffer (void *opaque,uint8_t *buf,int64_t pos,int size) +{ +QEMUBuffer *s = opaque; +ssize_t len =qsb_get_length (s->qsb) - pos; + +if (len <=0 ) { +return 0 ; + } + +if (len > size) { + len = size; + } +memcpy (buf,qsb_get_buffer (s->qsb, pos), len); + +return len; +} + +static int buf_put_buffer (void *opaque,const uint8_t *buf, +int64_t pos,int size) +{ +QEMUBuffer *s = opaque; + +return qsb_write_at (s->qsb, buf, pos, size); +} + +static int buf_close (void *opaque) +{ +QEMUBuffer *s = opaque; + +qsb_free (s->qsb); + +g_free (s); + +return 0 ; +} + +const QEMUSizedBuffer *qemu_buf_get (QEMUFile *f) +{ +QEMUBuffer *p; + +qemu_fflush (f); + + p = (QEMUBuffer *)f->opaque; + +return p->qsb; +} + +static const QEMUFileOps buf_read_ops = { + .get_buffer = buf_get_buffer, + .close = buf_close +}; + +static const QEMUFileOps buf_write_ops = { + .put_buffer = buf_put_buffer, + .close = buf_close +}; + +QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input) +{ +QEMUBuffer *s; + +if (mode ==NULL || (mode[0 ] !='r' && mode[0 ] !='w' ) || mode[1 ] !=0 ) { +fprintf (stderr,"qemu_bufopen: Argument validity check failed\n" ); +return NULL ; + } + + s =g_malloc0 (sizeof (QEMUBuffer)); +if (mode[0 ] =='r' ) { + s->qsb = input; + } + +if (s->qsb ==NULL ) { + s->qsb =qsb_create (NULL ,0 ); + } + +if (mode[0 ] =='r' ) { + s->file =qemu_fopen_ops (s, &buf_read_ops); + }else { + s->file =qemu_fopen_ops (s, &buf_write_ops); + } +return s->file; +}Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 4/9] qemu_qsb.diff
Quoted 7 lines · mdroth
Quoted 1 line · Joel Schopp
This patch adds support functions for operating on in memory sized file buffers.
There's been some past refactorings to remove non-migration users of QEMUFile, and AFAIK that's still the case today. QEMUFile satisfies funky requirements like rate-limiting, buffering, etc that were specific to migration.
Quoted 7 lines
IIUC all we want here is an abstraction on top of write()/memcpy(), and access to qemu_{put|get}_be* utility functions.
Have you considered rolling those abstractions in the visitor implementations as opposed to extending QEMUFile, and using be*_to_cpus/cpus_to_be* helpers directly instead (like
block/qcow2.cdoes, for example)?
The advantage of using the QEMUFile abstractions is that now you can build a visitor on top of it and read from buffers, sockets, BDRV's (later on), plain files, and whatever else you can hide underneath that interface. Back in 2011 when I initially wrote this code there at least was talk about using ASN.1 for migration, but this is nearly 2 years ago and it may never be done that way, so this was one driving force behind using QEMUFile inside the visitor. Besides that we later want to use the visitors for writing into virtual NVRAM, which we would build on top of a QEMUFile wrapping BDRVs. So there are some immediate advantages of using the common QEMUFile interface for reading and writing of data from different types of sources.
Regards,
Stefan
Re: [Qemu-devel] [PATCH 4/9] qemu_qsb.diff
Quoted 16 lines · Stefan Berger
Quoted 7 lines · mdroth
Quoted 1 line · Joel Schopp
This patch adds support functions for operating on in memory sized file buffers.
There's been some past refactorings to remove non-migration users of QEMUFile, and AFAIK that's still the case today. QEMUFile satisfies funky requirements like rate-limiting, buffering, etc that were specific to migration.
Quoted 7 lines
IIUC all we want here is an abstraction on top of write()/memcpy(), and access to qemu_{put|get}_be* utility functions.
Have you considered rolling those abstractions in the visitor implementations as opposed to extending QEMUFile, and using be*_to_cpus/cpus_to_be* helpers directly instead (like
block/qcow2.cdoes, for example)?
Quoted 4 lines
The advantage of using the QEMUFile abstractions is that now you can build a visitor on top of it and read from buffers, sockets, BDRV's (later on), plain files, and whatever else you can hide underneath that interface. Back in 2011 when I initially wrote this code there
Maybe a case can be made for making it a general utility library, but I'm having a hard time thinking of any reasons that aren't specific to migration, and I wonder if it's even necessary now that we have a migration thread that can handle the rate-limiting/buffering considerations.
But I'm not sure exactly why we decided to drop non-migration users, so I think it's worth clarifying before we attempt to tether another component to it.
Here's the thread I'm referencing:
https://lists.gnu.org/archive/html/qemu-devel/2011-09/msg02589.html
Juan, any background/input on this?
Quoted 4 lines
that interface. Back in 2011 when I initially wrote this code there at least was talk about using ASN.1 for migration, but this is nearly 2 years ago and it may never be done that way, so this was one driving force behind using QEMUFile inside the visitor. Besides
Well, even back then goal was to abstract away direct calls to QEMUFile and replace them with visitor calls, and then to provide legacy support via a QEMUFile Visitor. A BER visitor could then be dropped in to provide a BER migration protocol (how exactly this would be done was somewhat of a ???, might've ended up layering on to of the QEMUFile visitor anyway, but more out of pragmatism than anything else)
Quoted 5 lines
that we later want to use the visitors for writing into virtual NVRAM, which we would build on top of a QEMUFile wrapping BDRVs. So there are some immediate advantages of using the common QEMUFile interface for reading and writing of data from different types of sources.
Can you describe the requirements for the BDRV wrapper a bit more? Everything else seems reasonably doable via visitor internals but maybe there's more to it I'm not considering.
Quoted 4 lines
Regards,
Stefan
Re: [Qemu-devel] [PATCH 4/9] qemu_qsb.diff
Quoted 32 lines · mdroth
Quoted 16 lines · Stefan Berger
Quoted 7 lines · mdroth
Quoted 1 line · Joel Schopp
This patch adds support functions for operating on in memory sized file buffers.
There's been some past refactorings to remove non-migration users of QEMUFile, and AFAIK that's still the case today. QEMUFile satisfies funky requirements like rate-limiting, buffering, etc that were specific to migration.
Quoted 7 lines
IIUC all we want here is an abstraction on top of write()/memcpy(), and access to qemu_{put|get}_be* utility functions.
Have you considered rolling those abstractions in the visitor implementations as opposed to extending QEMUFile, and using be*_to_cpus/cpus_to_be* helpers directly instead (like
block/qcow2.cdoes, for example)?Quoted 4 lines
The advantage of using the QEMUFile abstractions is that now you can build a visitor on top of it and read from buffers, sockets, BDRV's (later on), plain files, and whatever else you can hide underneath that interface. Back in 2011 when I initially wrote this code there
Maybe a case can be made for making it a general utility library, but I'm having a hard time thinking of any reasons that aren't specific to migration, and I wonder if it's even necessary now that we have a migration thread that can handle the rate-limiting/buffering considerations.
But I'm not sure exactly why we decided to drop non-migration users, so I think it's worth clarifying before we attempt to tether another component to it.
Quoted 5 lines
Here's the thread I'm referencing:
https://lists.gnu.org/archive/html/qemu-devel/2011-09/msg02589.html
Juan, any background/input on this?
Sorry, forgot to CC Juan :)
Quoted 27 lines
Quoted 5 lines
that interface. Back in 2011 when I initially wrote this code there at least was talk about using ASN.1 for migration, but this is nearly 2 years ago and it may never be done that way, so this was one driving force behind using QEMUFile inside the visitor. Besides
Well, even back then goal was to abstract away direct calls to QEMUFile and replace them with visitor calls, and then to provide legacy support via a QEMUFile Visitor. A BER visitor could then be dropped in to provide a BER migration protocol (how exactly this would be done was somewhat of a ???, might've ended up layering on to of the QEMUFile visitor anyway, but more out of pragmatism than anything else)
Quoted 5 lines
that we later want to use the visitors for writing into virtual NVRAM, which we would build on top of a QEMUFile wrapping BDRVs. So there are some immediate advantages of using the common QEMUFile interface for reading and writing of data from different types of sources.
Can you describe the requirements for the BDRV wrapper a bit more? Everything else seems reasonably doable via visitor internals but maybe there's more to it I'm not considering.
Quoted 4 lines
Regards,
Stefan
Re: [Qemu-devel] [PATCH 4/9] qemu_qsb.diff
Quoted 27 lines · mdroth
Quoted 26 lines · mdroth
Quoted 11 lines · Stefan Berger
Quoted 10 lines · mdroth
Quoted 1 line · Joel Schopp
This patch adds support functions for operating on in memory sized file buffers.
There's been some past refactorings to remove non-migration users of QEMUFile, and AFAIK that's still the case today. QEMUFile satisfies funky requirements like rate-limiting, buffering, etc that were specific to migration.
IIUC all we want here is an abstraction on top of write()/memcpy(), and access to qemu_{put|get}_be* utility functions.
Quoted 8 lines
Quoted 4 lines
Have you considered rolling those abstractions in the visitor implementations as opposed to extending QEMUFile, and using be*_to_cpus/cpus_to_be* helpers directly instead (like
block/qcow2.cdoes, for example)?The advantage of using the QEMUFile abstractions is that now you can build a visitor on top of it and read from buffers, sockets, BDRV's (later on), plain files, and whatever else you can hide underneath that interface. Back in 2011 when I initially wrote this code there
Maybe a case can be made for making it a general utility library, but I'm having a hard time thinking of any reasons that aren't specific to migration, and I wonder if it's even necessary now that we have a migration thread that can handle the rate-limiting/buffering considerations.
Quoted 3 lines
Quoted 3 lines
But I'm not sure exactly why we decided to drop non-migration users, so I think it's worth clarifying before we attempt to tether another component to it.
It almost sounds like there is a lock on QEMUFile forbidding it to be used for anything else.. strange.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
that we later want to use the visitors for writing into virtual NVRAM, which we would build on top of a QEMUFile wrapping BDRVs. So there are some immediate advantages of using the common QEMUFile interface for reading and writing of data from different types of sources.
Can you describe the requirements for the BDRV wrapper a bit more? Everything else seems reasonably doable via visitor internals but maybe there's more to it I'm not considering.
The vNVRAM would be used for writing persistent state of the software TPM into. The vNVRAM uses the block devices and with that we get the benefit of encryption (QCOW2) and migration.
The contents of the vNVRAM are layed out as one large ASN.1 stream. At the beginning is the header, then come the individual blobs, which may each be of different size and each is identified by a unique name. When reading a certain blob (given its name), we use the input visitor to scan through the BDRV to find the blob and then read it (using the sized buffer input visitor). When writing we scan for the blob and switch from input visitor to output visitor to replace the blob. The requirement here is of course that the blob maintains its size so that the subsequent blobs are still part of that ASN.1 stream and don't destroy the integrity of the ASN.1 stream.
Code talks, so here's the hunk of the patch for BDRV support as it stands right now. The header may need some changes, but that's not the point.
qemu-bdrv-file.c new file +116 -0
@@ -0,0 +1,116 @@ +/* +* QEMU File : wrapper for bdrv +* +* Copyright (c) 2011, 2012, 2013 IBM Corporation +* +* Authors: +* Stefan Berger <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a cop +* of this software and associated documentation files (the "Software"), to de +* in the Software without restriction, including without limitation the right +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FRO +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +/* +* Note: This QEMUFile wrapper introduces a dependency on the block layer. +* We keep it in this separate file to avoid pulling block.o and its +* dependencies into test programs. +*/ + +#include "qemu-common.h" +#include "hw/hw.h" +#include "block/block.h" + +typedef struct QEMUBdrvFile { +BlockDriverState *bds; +uint64_t offset; +QEMUFile *file; +}QEMUBdrvFile ; + +static int qf_bdrv_put_buffer (void *opaque,const uint8_t *buf, +int64_t pos,int size) +{ +QEMUBdrvFile *s = opaque; + +return bdrv_pwrite (s->bds, pos + s->offset, buf, size); +} + +static int qf_bdrv_get_buffer (void *opaque,uint8_t *buf, +int64_t pos,int size) +{ +QEMUBdrvFile *s = opaque; +ssize_t len =bdrv_getlength (s->bds) - (s->offset + pos); + +if (len <=0 ) { +return 0 ; + } + +if (len > size) { + len = size; + } + + len =bdrv_pread (s->bds, pos + s->offset, buf, len); + +return len; +} + +static int qf_bdrv_close (void *opaque) +{ +QEMUBdrvFile *s = opaque; + +g_free (s); + +return 0 ; +} + +static const QEMUFileOps bdrv_read_ops = { + .get_buffer = qf_bdrv_get_buffer, + .close = qf_bdrv_close +}; + +static const QEMUFileOps bdrv_write_ops = { + .put_buffer = qf_bdrv_put_buffer, + .close = qf_bdrv_close +}; + + +QEMUFile *qemu_bdrv_open (const char *mode,BlockDriverState *bds, +uint64_t offset) +{ +QEMUBdrvFile *s; + +if (mode ==NULL || (mode[0 ] !='r' && mode[0 ] !='w' ) || mode[1 ] !=0 ) { +fprintf (stderr,"qemu_bdrv_open: Argument validity check failed\n" ); +return NULL ; + } + + s =g_malloc0 (sizeof (QEMUBdrvFile)); +if (!s) { +return NULL ; + } + + s->bds = bds; + s->offset = offset; + +if (mode[0 ] =='r' ) { + s->file =qemu_fopen_ops (s, &bdrv_read_ops); + }else { + s->file =qemu_fopen_ops (s, &bdrv_write_ops); + } +return s->file; +} +
Turns out this QEMUFile abstraction can be used for more than just migration...
Regards,
Stefan
PATCH v3 5/9 qapi_sized_buffer
In reply to Joel SchoppAdd a sized buffer interface to qapi.
--- include/qapi/visitor-impl.h | 2 ++ include/qapi/visitor.h | 2 ++ qapi/qapi-visit-core.c | 8 ++++++++ 3 files changed, 12 insertions(+)
include/qapi/visitor-impl.h +2 -0
@@ -38,6 +38,8 @@ struct Visitor size_t elem_count, size_t elem_size, Error **errp);void (*next_carray)(Visitor *v,Error **errp);void (*end_carray)(Visitor *v,Error **errp); +void (*type_sized_buffer)(Visitor *v,uint8_t **obj,size_t size, +const char *name,Error **errp);/* May be NULL */ void (*start_optional)(Visitor *v, bool *present, const char *name,
include/qapi/visitor.h +2 -0
@@ -55,5 +55,7 @@ void visit_start_carray(Visitor *v, void **obj, const char *name, size_t elem_count, size_t elem_size, Error **errp);void visit_next_carray (Visitor *v,Error **errp);void visit_end_carray (Visitor *v,Error **errp); +void visit_type_sized_buffer (Visitor *v,uint8_t **obj,size_t len, +const char *name,Error **errp);#endif
qapi/qapi-visit-core.c +8 -0
@@ -338,3 +338,11 @@ void visit_end_carray(Visitor *v, Error **errp) v->end_carray (v, errp); } } + +void visit_type_sized_buffer (Visitor *v,uint8_t **obj,size_t len, +const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_sized_buffer (v, obj, len, name, errp); + } +}
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 1 line · Joel Schopp
Add a sized buffer interface to qapi.
Isn't this just a special case of the visit_*_carray() interfaces? We should avoid new interfaces if possible, since it adds to feature disparities between visitor implementations.
Quoted 55 lines
Cc Michael Tsirkin <[email protected]>Signed-off-by Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>--- include/qapi/visitor-impl.h | 2 ++ include/qapi/visitor.h | 2 ++ qapi/qapi-visit-core.c | 8 ++++++++ 3 files changed, 12 insertions(+)include/qapi/visitor-impl.h +2
-0@@ -38,6 +38,8 @@ struct Visitor size_t elem_count, size_t elem_size, Error **errp);void (*next_carray)(Visitor *v,Error **errp);void (*end_carray)(Visitor *v,Error **errp); +void (*type_sized_buffer)(Visitor *v,uint8_t **obj,size_t size, +const char *name,Error **errp);/* May be NULL */ void (*start_optional)(Visitor *v, bool *present, const char *name,include/qapi/visitor.h +2
-0@@ -55,5 +55,7 @@ void visit_start_carray(Visitor *v, void **obj, const char *name, size_t elem_count, size_t elem_size, Error **errp);void visit_next_carray (Visitor *v,Error **errp);void visit_end_carray (Visitor *v,Error **errp); +void visit_type_sized_buffer (Visitor *v,uint8_t **obj,size_t len, +const char *name,Error **errp);#endif qapi/qapi-visit-core.c +8
-0@@ -338,3 +338,11 @@ void visit_end_carray(Visitor *v, Error **errp) v->end_carray (v, errp); } } + +void visit_type_sized_buffer (Visitor *v,uint8_t **obj,size_t len, +const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_sized_buffer (v, obj, len, name, errp); + } +}Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 5 lines · mdroth
Quoted 1 line · Joel Schopp
Add a sized buffer interface to qapi.
Isn't this just a special case of the visit_*_carray() interfaces? We should avoid new interfaces if possible, since it adds to feature disparities between visitor implementations.
Yes, it's a special case and carray seems more general.
However, I don't understand the interface of carray. It has a start_carray with all parameters given, then a next_carray and an end_carray. Why do we need multiple calls if one call (start_carray) could be used to serialize all the data already?
Regards,
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 7 lines · Stefan Berger
Quoted 5 lines · mdroth
Quoted 1 line · Joel Schopp
Add a sized buffer interface to qapi.
Isn't this just a special case of the visit_*_carray() interfaces? We should avoid new interfaces if possible, since it adds to feature disparities between visitor implementations.
Quoted 5 lines
Yes, it's a special case and carray seems more general. However, I don't understand the interface of carray. It has a
start_carraywith all parameters given, then anext_carrayand anend_carray. Why do we need multiple calls if one call (start_carray) could be used to serialize all the data already?
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
For output, visit_start_carray() only provides enough information to instruct a visitor on how to calculate the offsets of each element (and perhaps allocate some memory for it's own internal buffers etc.)
For input, it provides enough to allocate storage, and calculate offsets to each element it's deserializing into.
As far as what to do with each element, we need to make additional calls to instruct it.
For example, a visitor for a 16-element array of:
typedef struct ComplexType {
int32_t foo;
char *bar;
} ComplexType;would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...) // instruct visitor how to handle elem visit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize array
Quoted 6 lines
Regards,
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 15 lines · mdroth
Quoted 2 lines · Stefan Berger
On 03/13/2013 04:52 PM, mdroth wrote:
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
[...]
For example, a visitor for a 16-element array of:
typedef struct ComplexType { int32_t foo; char *bar; } ComplexType;
Quoted 8 lines
would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...)// instruct visitor how to handle elemvisit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize array
Given this example above, I think we will need the sized buffer. The sized buffer targets binary arrays and their encoding. If I was to encode an 'unsigned char[n]' (e.g., n=200) using n, or n/2 or n/4 loops like above breaking it apart in u8, u16 or u32 respectively I think this would 'not bed good' also considering the 2 bytes for tag and length being added by ASN.1 for every such datatype (u8,u16,u32). The sized buffer allows you to for example take a memory page and write it out in one chunk adding a few bytes of ASN.1 'decoration' around the actual data.
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 25 lines · Stefan Berger
Quoted 15 lines · mdroth
Quoted 2 lines · Stefan Berger
On 03/13/2013 04:52 PM, mdroth wrote:
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
[...]
For example, a visitor for a 16-element array of:
typedef struct ComplexType { int32_t foo; char *bar; } ComplexType;Quoted 8 lines
would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...)// instruct visitor how to handle elemvisit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize array
Quoted 9 lines
Given this example above, I think we will need the sized buffer. The sized buffer targets binary arrays and their encoding. If I was to encode an 'unsigned char[n]' (e.g., n=200) using n, or n/2 or n/4 loops like above breaking it apart in u8, u16 or u32 respectively I think this would 'not bed good' also considering the 2 bytes for tag and length being added by ASN.1 for every such datatype (u8,u16,u32). The sized buffer allows you to for example take a memory page and write it out in one chunk adding a few bytes of ASN.1 'decoration' around the actual data.
You could do it with this interface as well actually. The Visitor will need to maintain some internal state to differentiate what it does with subsequent visit_type*/visit_next_carray/visit_end_carry. There's no reason it couldn't also track the elem size so it could tag a buffer "en masse" when visit_end_carray() gets called.
QMP*Visitor does something similar already for building up lists/arrays before tacking them onto the parent structure.
Quoted 3 lines
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 34 lines · mdroth
Quoted 24 lines · Stefan Berger
Quoted 15 lines · mdroth
Quoted 2 lines · Stefan Berger
On 03/13/2013 04:52 PM, mdroth wrote:
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
[...]
For example, a visitor for a 16-element array of:
typedef struct ComplexType { int32_t foo; char *bar; } ComplexType;Quoted 8 lines
would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...)// instruct visitor how to handle elemvisit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize arrayQuoted 9 lines
Given this example above, I think we will need the sized buffer. The sized buffer targets binary arrays and their encoding. If I was to encode an 'unsigned char[n]' (e.g., n=200) using n, or n/2 or n/4 loops like above breaking it apart in u8, u16 or u32 respectively I think this would 'not bed good' also considering the 2 bytes for tag and length being added by ASN.1 for every such datatype (u8,u16,u32). The sized buffer allows you to for example take a memory page and write it out in one chunk adding a few bytes of ASN.1 'decoration' around the actual data.
Quoted 5 lines
You could do it with this interface as well actually. The Visitor will need to maintain some internal state to differentiate what it does with subsequent visit_type*/visit_next_carray/visit_end_carry. There's no reason it couldn't also track the elem size so it could tag a buffer "en masse" when
visit_end_carray()gets called.
It depends on what you pass into visit_start_carray. In your case if you pass in ComplexType you would pass in a sizeof(ComplexType) for the size of each element presumably. The problem is now you have char *foo, a string pointer, hanging off of this structure. How would you handle that? Serializing ComplexType's foo and pointer obviously won't do it. You need to follow the string pointer and serialize that as well. So we have different use cases here when wanting to serialize ComplexType versus a plain array with the carray calls somehow having to figure it out themselves -- how ??
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 41 lines · Stefan Berger
Quoted 34 lines · mdroth
Quoted 24 lines · Stefan Berger
Quoted 15 lines · mdroth
Quoted 2 lines · Stefan Berger
On 03/13/2013 04:52 PM, mdroth wrote:
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
[...]
For example, a visitor for a 16-element array of:
typedef struct ComplexType { int32_t foo; char *bar; } ComplexType;Quoted 8 lines
would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...)// instruct visitor how to handle elemvisit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize arrayQuoted 9 lines
Given this example above, I think we will need the sized buffer. The sized buffer targets binary arrays and their encoding. If I was to encode an 'unsigned char[n]' (e.g., n=200) using n, or n/2 or n/4 loops like above breaking it apart in u8, u16 or u32 respectively I think this would 'not bed good' also considering the 2 bytes for tag and length being added by ASN.1 for every such datatype (u8,u16,u32). The sized buffer allows you to for example take a memory page and write it out in one chunk adding a few bytes of ASN.1 'decoration' around the actual data.
Quoted 5 lines
You could do it with this interface as well actually. The Visitor will need to maintain some internal state to differentiate what it does with subsequent visit_type*/visit_next_carray/visit_end_carry. There's no reason it couldn't also track the elem size so it could tag a buffer "en masse" when
visit_end_carray()gets called.
Quoted 6 lines
It depends on what you pass into
visit_start_carray. In your case if you pass in ComplexType you would pass in a sizeof(ComplexType) for the size of each element presumably. The problem is now you have char *foo, a string pointer, hanging off of this structure. How would you handle that? Serializing ComplexType's foo and pointer obviously won't do it.
Why not? visit_type_ComplexType() knows how to deal with the individual fields, including the string pointer. I'm not sure what's at issue here.
In this case the handling for ComplexType would look something like:
visit_type_Complex:
visit_start_struct
visit_type_uin32 //foo
visit_type_str //bar
visit_end_structGranted, strings are easier to deal with. If char * was instead a plain old uint8_t*, we'd need a nested call to start_carray for each element. in this case it would look something like:
visit_type_Complex:
visit_start_struct
visit_type_uin32 //foo field
visit_start_carray //bar field
for (i = 0; i < len_of_bar; i++):
visit_type_uint8
visit_next_carray
visit_end_carray
visit_end_struct
The key is knowing the length. In open coded visitor routines we know this, or where to get it, for routines generated from QAPI schemas we'd a way to tell the code generators how to field the size, or state the size in the schema directly. I had some patches to do this, but we don't have a QAPI user that needs this yet. When we do, visit_*_carray() should be able to handle it, so we should consolidate around that interface since there are a lot of things to consider in the scope of what a visitor implementation may be used for.
Quoted 5 lines
would you handle that? Serializing ComplexType's foo and pointer obviously won't do it. You need to follow the string pointer and serialize that as well. So we have different use cases here when wanting to serialize ComplexType versus a plain array with the carray calls somehow having to figure it out themselves -- how ??
for a plain array we'd just replace visit_type_ComplexType() with visit_type_uint{8,16,32,64} and change loop/elem_size params accordingly.
Quoted 3 lines
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 63 lines · mdroth
Quoted 40 lines · Stefan Berger
Quoted 34 lines · mdroth
Quoted 24 lines · Stefan Berger
Quoted 15 lines · mdroth
Quoted 2 lines · Stefan Berger
On 03/13/2013 04:52 PM, mdroth wrote:
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
[...]
For example, a visitor for a 16-element array of:
typedef struct ComplexType { int32_t foo; char *bar; } ComplexType;Quoted 8 lines
would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...)// instruct visitor how to handle elemvisit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize arrayQuoted 9 lines
Given this example above, I think we will need the sized buffer. The sized buffer targets binary arrays and their encoding. If I was to encode an 'unsigned char[n]' (e.g., n=200) using n, or n/2 or n/4 loops like above breaking it apart in u8, u16 or u32 respectively I think this would 'not bed good' also considering the 2 bytes for tag and length being added by ASN.1 for every such datatype (u8,u16,u32). The sized buffer allows you to for example take a memory page and write it out in one chunk adding a few bytes of ASN.1 'decoration' around the actual data.
Quoted 5 lines
You could do it with this interface as well actually. The Visitor will need to maintain some internal state to differentiate what it does with subsequent visit_type*/visit_next_carray/visit_end_carry. There's no reason it couldn't also track the elem size so it could tag a buffer "en masse" when
visit_end_carray()gets called.Quoted 6 lines
It depends on what you pass into
visit_start_carray. In your case if you pass in ComplexType you would pass in a sizeof(ComplexType) for the size of each element presumably. The problem is now you have char *foo, a string pointer, hanging off of this structure. How would you handle that? Serializing ComplexType's foo and pointer obviously won't do it.Why not?
visit_type_ComplexType()knows how to deal with the individual fields, including the string pointer. I'm not sure what's at issue here.In this case the handling for ComplexType would look something like:
visit_type_Complex:visit_start_struct visit_type_uin32 //foo visit_type_str //bar visit_end_structGranted, strings are easier to deal with. If char * was instead a plain old uint8_t*, we'd need a nested call to
start_carrayfor each element. in this case it would look something like:
Quoted 8 lines
visit_type_Complex:
visit_start_struct
visit_type_uin32//foo field
visit_start_carray//bar field
for (i = 0; i <len_of_bar; i++):
visit_type_uint8
visit_next_carray
visit_end_carray
You really want to create a separate element for each element in this potentially large binary array? I guess it depends on the underlying data, but this has the potential of generating a lot of control code around each such byte... As said, for ASN.1 encoding, each such byte would be decorated with a tag and a length value, consuming 2 more bytes per byte.
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 73 lines · Stefan Berger
Quoted 63 lines · mdroth
Quoted 40 lines · Stefan Berger
Quoted 34 lines · mdroth
Quoted 24 lines · Stefan Berger
Quoted 15 lines · mdroth
Quoted 2 lines · Stefan Berger
On 03/13/2013 04:52 PM, mdroth wrote:
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
[...]
For example, a visitor for a 16-element array of:
typedef struct ComplexType { int32_t foo; char *bar; } ComplexType;Quoted 8 lines
would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...)// instruct visitor how to handle elemvisit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize arrayQuoted 9 lines
Given this example above, I think we will need the sized buffer. The sized buffer targets binary arrays and their encoding. If I was to encode an 'unsigned char[n]' (e.g., n=200) using n, or n/2 or n/4 loops like above breaking it apart in u8, u16 or u32 respectively I think this would 'not bed good' also considering the 2 bytes for tag and length being added by ASN.1 for every such datatype (u8,u16,u32). The sized buffer allows you to for example take a memory page and write it out in one chunk adding a few bytes of ASN.1 'decoration' around the actual data.
Quoted 5 lines
You could do it with this interface as well actually. The Visitor will need to maintain some internal state to differentiate what it does with subsequent visit_type*/visit_next_carray/visit_end_carry. There's no reason it couldn't also track the elem size so it could tag a buffer "en masse" when
visit_end_carray()gets called.Quoted 6 lines
It depends on what you pass into
visit_start_carray. In your case if you pass in ComplexType you would pass in a sizeof(ComplexType) for the size of each element presumably. The problem is now you have char *foo, a string pointer, hanging off of this structure. How would you handle that? Serializing ComplexType's foo and pointer obviously won't do it.Why not?
visit_type_ComplexType()knows how to deal with the individual fields, including the string pointer. I'm not sure what's at issue here.In this case the handling for ComplexType would look something like:
visit_type_Complex:visit_start_struct visit_type_uin32 //foo visit_type_str //bar visit_end_structGranted, strings are easier to deal with. If char * was instead a plain old uint8_t*, we'd need a nested call to
start_carrayfor each element. in this case it would look something like:Quoted 8 lines
visit_type_Complex:
visit_start_struct
visit_type_uin32//foo field
visit_start_carray//bar field
for (i = 0; i <len_of_bar; i++):
visit_type_uint8
visit_next_carray
visit_end_carray
Quoted 6 lines
You really want to create a separate element for each element in this potentially large binary array? I guess it depends on the underlying data, but this has the potential of generating a lot of control code around each such byte... As said, for ASN.1 encoding, each such byte would be decorated with a tag and a length value, consuming 2 more bytes per byte.
I addressed this earlier. Your visitor doesn't have tag each
element: if it know it's handling an array (because we told it via start_carray()), it can buffer them internally and tag the array en masse when end_carray() is issued.
Quoted 3 lines
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 78 lines · mdroth
Quoted 71 lines · Stefan Berger
Quoted 62 lines · mdroth
Quoted 40 lines · Stefan Berger
Quoted 34 lines · mdroth
Quoted 24 lines · Stefan Berger
Quoted 15 lines · mdroth
Quoted 2 lines · Stefan Berger
On 03/13/2013 04:52 PM, mdroth wrote:
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
[...]
For example, a visitor for a 16-element array of:
typedef struct ComplexType { int32_t foo; char *bar; } ComplexType;Quoted 8 lines
would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...)// instruct visitor how to handle elemvisit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize arrayQuoted 9 lines
Given this example above, I think we will need the sized buffer. The sized buffer targets binary arrays and their encoding. If I was to encode an 'unsigned char[n]' (e.g., n=200) using n, or n/2 or n/4 loops like above breaking it apart in u8, u16 or u32 respectively I think this would 'not bed good' also considering the 2 bytes for tag and length being added by ASN.1 for every such datatype (u8,u16,u32). The sized buffer allows you to for example take a memory page and write it out in one chunk adding a few bytes of ASN.1 'decoration' around the actual data.
Quoted 5 lines
You could do it with this interface as well actually. The Visitor will need to maintain some internal state to differentiate what it does with subsequent visit_type*/visit_next_carray/visit_end_carry. There's no reason it couldn't also track the elem size so it could tag a buffer "en masse" when
visit_end_carray()gets called.Quoted 5 lines
It depends on what you pass into
visit_start_carray. In your case if
you pass in ComplexType you would pass in a sizeof(ComplexType) for
the size of each element presumably. The problem is now you havechar *foo, a string pointer, hanging off of this structure. How would you handle that? Serializing ComplexType's foo and pointer
obviously won't do it.Why not?
visit_type_ComplexType()knows how to deal with the individual fields, including the string pointer. I'm not sure what's at issue here.In this case the handling for ComplexType would look something like:
visit_type_Complex:visit_start_struct visit_type_uin32 //foo visit_type_str //bar visit_end_structGranted, strings are easier to deal with. If char * was instead a plain old uint8_t*, we'd need a nested call to
start_carrayfor each element. in this case it would look something like:Quoted 8 lines
visit_type_Complex:
visit_start_struct
visit_type_uin32//foo field
visit_start_carray//bar field
for (i = 0; i <len_of_bar; i++):
visit_type_uint8
visit_next_carray
visit_end_carrayQuoted 6 lines
You really want to create a separate element for each element in this potentially large binary array? I guess it depends on the underlying data, but this has the potential of generating a lot of control code around each such byte... As said, for ASN.1 encoding, each such byte would be decorated with a tag and a length value, consuming 2 more bytes per byte.
Quoted 4 lines
I addressed this earlier. Your visitor doesn't have tag each
element: if it know it's handling an array (because we told it viastart_carray()), it can buffer them internally and tag the array en masse whenend_carray()is issued.
If we were to do this using carray on an array of structs of the following type
struct SimpleStruct {
uint8_t a;
uint8_t b;
uint32_t c;
}then the serialization of a and b would be buffered and flushed once the 32bit output visitor (or any other than uint8_t output visitor) would be called? Now this does makes the implementation a lot more difficult.
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 93 lines · Stefan Berger
Quoted 78 lines · mdroth
Quoted 71 lines · Stefan Berger
Quoted 62 lines · mdroth
Quoted 40 lines · Stefan Berger
Quoted 34 lines · mdroth
Quoted 24 lines · Stefan Berger
Quoted 15 lines · mdroth
Quoted 2 lines · Stefan Berger
On 03/13/2013 04:52 PM, mdroth wrote:
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
[...]
For example, a visitor for a 16-element array of:
typedef struct ComplexType { int32_t foo; char *bar; } ComplexType;Quoted 8 lines
would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...)// instruct visitor how to handle elemvisit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize arrayQuoted 9 lines
Given this example above, I think we will need the sized buffer. The sized buffer targets binary arrays and their encoding. If I was to encode an 'unsigned char[n]' (e.g., n=200) using n, or n/2 or n/4 loops like above breaking it apart in u8, u16 or u32 respectively I think this would 'not bed good' also considering the 2 bytes for tag and length being added by ASN.1 for every such datatype (u8,u16,u32). The sized buffer allows you to for example take a memory page and write it out in one chunk adding a few bytes of ASN.1 'decoration' around the actual data.
Quoted 5 lines
You could do it with this interface as well actually. The Visitor will need to maintain some internal state to differentiate what it does with subsequent visit_type*/visit_next_carray/visit_end_carry. There's no reason it couldn't also track the elem size so it could tag a buffer "en masse" when
visit_end_carray()gets called.Quoted 5 lines
It depends on what you pass into
visit_start_carray. In your case if
you pass in ComplexType you would pass in a sizeof(ComplexType) for
the size of each element presumably. The problem is now you havechar *foo, a string pointer, hanging off of this structure. How would you handle that? Serializing ComplexType's foo and pointer
obviously won't do it.Why not?
visit_type_ComplexType()knows how to deal with the individual fields, including the string pointer. I'm not sure what's at issue here.In this case the handling for ComplexType would look something like:
visit_type_Complex:visit_start_struct visit_type_uin32 //foo visit_type_str //bar visit_end_structGranted, strings are easier to deal with. If char * was instead a plain old uint8_t*, we'd need a nested call to
start_carrayfor each element. in this case it would look something like:Quoted 8 lines
visit_type_Complex:
visit_start_struct
visit_type_uin32//foo field
visit_start_carray//bar field
for (i = 0; i <len_of_bar; i++):
visit_type_uint8
visit_next_carray
visit_end_carrayQuoted 6 lines
You really want to create a separate element for each element in this potentially large binary array? I guess it depends on the underlying data, but this has the potential of generating a lot of control code around each such byte... As said, for ASN.1 encoding, each such byte would be decorated with a tag and a length value, consuming 2 more bytes per byte.
Quoted 4 lines
I addressed this earlier. Your visitor doesn't have tag each
element: if it know it's handling an array (because we told it viastart_carray()), it can buffer them internally and tag the array en masse whenend_carray()is issued.If we were to do this using carray on an array of structs of the following type
struct SimpleStruct { uint8_t a; uint8_t b; uint32_t c; }
Quoted 3 lines
then the serialization of a and b would be buffered and flushed once the 32bit output visitor (or any other than
uint8_toutput visitor) would be called?
I don't quite understand. For a struct, we'd tag each field individually, right?
It's avoiding the need to tag each element in a list, each SimpleStruct, that's at issue, right? We have a special case for u8 arrays that is currently handled by qapi_sized_buffer(), and now we're trying to generalize this optimized handling for more complex data types via visit_carray_*?
I guess my first question is whether or not it's possible for more complex data types. For u8 arrays we seem to use a special OCTET_STRING encoding.
If we're not sure we can do this more generally, we do have the option of only special-casing u8 arrays to use the OCTET_STRING encoding, and handle the others with "non-optimized" encodings.
If you have an idea for what a generalized, optimized encoding that's applicable for non-u8 types would look like, we can work through that if you have an example optimized encoding for, say, and array of SimpleStruct.
Quoted 3 lines
Stefan
Re: [Qemu-devel] [PATCH 5/9] qapi_sized_buffer
Quoted 96 lines · mdroth
Quoted 92 lines · Stefan Berger
Quoted 78 lines · mdroth
Quoted 71 lines · Stefan Berger
Quoted 62 lines · mdroth
Quoted 40 lines · Stefan Berger
Quoted 34 lines · mdroth
Quoted 24 lines · Stefan Berger
Quoted 15 lines · mdroth
Quoted 2 lines · Stefan Berger
On 03/13/2013 04:52 PM, mdroth wrote:
Visitors don't have any knowledge of the data structures they're visiting outside of what we tell them via the visit_*() API.
[...]
For example, a visitor for a 16-element array of:
typedef struct ComplexType { int32_t foo; char *bar; } ComplexType;Quoted 8 lines
would look something like:
visit_start_carray(v, ...); // instruct visitor how to calculate offsets for (i = 0; i < 16; i++) {
visit_type_ComplexType(v, ...)// instruct visitor how to handle elemvisit_next_carray(v, ...); // instruct visitor to move to next offset
}visit_end_carray(v, ...); // instruct visitor to finalize arrayQuoted 9 lines
Given this example above, I think we will need the sized buffer. The sized buffer targets binary arrays and their encoding. If I was to encode an 'unsigned char[n]' (e.g., n=200) using n, or n/2 or n/4 loops like above breaking it apart in u8, u16 or u32 respectively I think this would 'not bed good' also considering the 2 bytes for tag and length being added by ASN.1 for every such datatype (u8,u16,u32). The sized buffer allows you to for example take a memory page and write it out in one chunk adding a few bytes of ASN.1 'decoration' around the actual data.
Quoted 5 lines
You could do it with this interface as well actually. The Visitor will need to maintain some internal state to differentiate what it does with subsequent visit_type*/visit_next_carray/visit_end_carry. There's no reason it couldn't also track the elem size so it could tag a buffer "en masse" when
visit_end_carray()gets called.Quoted 5 lines
It depends on what you pass into
visit_start_carray. In your case if
you pass in ComplexType you would pass in a sizeof(ComplexType) for
the size of each element presumably. The problem is now you havechar *foo, a string pointer, hanging off of this structure. How would you handle that? Serializing ComplexType's foo and pointer
obviously won't do it.Why not?
visit_type_ComplexType()knows how to deal with the individual fields, including the string pointer. I'm not sure what's at issue here.In this case the handling for ComplexType would look something like:
visit_type_Complex:visit_start_struct visit_type_uin32 //foo visit_type_str //bar visit_end_structGranted, strings are easier to deal with. If char * was instead a plain old uint8_t*, we'd need a nested call to
start_carrayfor each element. in this case it would look something like:Quoted 8 lines
visit_type_Complex:
visit_start_struct
visit_type_uin32//foo field
visit_start_carray//bar field
for (i = 0; i <len_of_bar; i++):
visit_type_uint8
visit_next_carray
visit_end_carrayQuoted 6 lines
You really want to create a separate element for each element in this potentially large binary array? I guess it depends on the underlying data, but this has the potential of generating a lot of control code around each such byte... As said, for ASN.1 encoding, each such byte would be decorated with a tag and a length value, consuming 2 more bytes per byte.
Quoted 4 lines
I addressed this earlier. Your visitor doesn't have tag each
element: if it know it's handling an array (because we told it viastart_carray()), it can buffer them internally and tag the array en masse whenend_carray()is issued.If we were to do this using carray on an array of structs of the following type
struct SimpleStruct { uint8_t a; uint8_t b; uint32_t c; }Quoted 3 lines
then the serialization of a and b would be buffered and flushed once the 32bit output visitor (or any other than
uint8_toutput visitor) would be called?
Quoted 8 lines
I don't quite understand. For a struct, we'd tag each field individually, right?
It's avoiding the need to tag each element in a list, each SimpleStruct, that's at issue, right? We have a special case for u8 arrays that is currently handled by
qapi_sized_buffer(), and now we're trying to generalize this optimized handling for more complex data types via visit_carray_*?
I have to admit there's one mistake in the sized buffer implementation and that is it should take the width of each element so each element can be encoded in network byte order, which I think is the key point here so the bytestream becomes portable Using the element width we can then walk the array of n elements and write them out in network byte order in one go. I also see the sized buffer more as a generalization of the string visitor that just happens to work on a null terminated array of bytes.
Using the carray it seems we would create special cases in the implementation for when a u8, u16, u32, or u64 follows versus a string, list or any more complex data type. The examples above seem to need to buffer the u8 and then write them out versus when it was to handle an array of structs. With the sized buffer we can do this all with a single call.
Quoted 11 lines
I guess my first question is whether or not it's possible for more complex data types. For u8 arrays we seem to use a special
OCTET_STRINGencoding.If we're not sure we can do this more generally, we do have the option of only special-casing u8 arrays to use the
OCTET_STRINGencoding, and handle the others with "non-optimized" encodings.If you have an idea for what a generalized, optimized encoding that's applicable for non-u8 types would look like, we can work through that if you have an example optimized encoding for, say, and array of SimpleStruct.
For an array of SimpleStruct we use the carray. No endianess conversion is necessary here for the structure as a whole but each u16,u32, u64 inside such a structure will be written out correctly with their respective visitor. A u16[] or u32[] inside that structure would then be handled with a sized buffer walking the array and normalizing each element's endianess.
Strictly speaking, for ASN.1 encoding we don't need a carray visitor (but maybe other visitor types need it). It can be simulated with the struct visitor, which in effect also causes one more level of nesting, just that the identifier would be different, which really is the only difference then.
Stefan
PATCH v3 6/9 asn1_output-visitor.diff
In reply to Joel SchoppImplement an output visitor for ASN.1 BER encoding.
--- configure | 2 +- include/qapi/ber-output-visitor.h | 28 ++ include/qapi/ber.h | 107 +++++++ qapi/Makefile.objs | 1 + qapi/ber-common.c | 86 ++++++ qapi/ber-common.h | 29 ++ qapi/ber-output-visitor.c | 617 +++++++++++++++++++++++++++++++++++++ 7 files changed, 869 insertions(+), 1 deletion(-) create mode 100644 include/qapi/ber-output-visitor.h create mode 100644 include/qapi/ber.h create mode 100644 qapi/ber-common.c create mode 100644 qapi/ber-common.h create mode 100644 qapi/ber-output-visitor.c
configure +1 -1
@@ -2830,7 +2830,7 @@ fi # Do we need libm cat > $TMPC << EOF #include <math.h> -int main(void) { return isnan(sin(0.0)); } +int main(void) { return isnan(nan("NAN")); } EOF if compile_prog "" "" ; then :
include/qapi/ber-output-visitor.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* BER Output Visitor header +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Anthony Liguori <[email protected]> +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef BER_OUTPUT_VISITOR_H +#define BER_OUTPUT_VISITOR_H + +#include "qapi/visitor.h" +#include "qapi/ber.h" + +typedef struct BEROutputVisitor BEROutputVisitor ; + +BEROutputVisitor *ber_output_visitor_new (QEMUFile *,BERTypePC mode); +void ber_output_visitor_cleanup (BEROutputVisitor *v); + +Visitor *ber_output_get_visitor (BEROutputVisitor *v); + +#endif
include/qapi/ber.h new file +107 -0
107 lines not on this page · raw message
qapi/Makefile.objs +1 -0
@@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o util-obj-y += string-input-visitor.o string-output-visitor.o util-obj-y += opts-visitor.o +util-obj-y += ber-common.o ber-output-visitor.o
qapi/ber-common.c new file +86 -0
86 lines not on this page · raw message
qapi/ber-common.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* BER Visitor -- common code +* +* Copyright IBM, Corp. 2013 +* +* Authors: +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ +#ifndef __QAPI_BER_COMMON_H__ +#define __QAPI_BER_COMMON_H__ + +#include <stdint.h> + +#include "qemu/compiler.h" + +struct ieee754_buffer { +uint8_t type; +uint8_t length; +uint8_t first; +uint16_t exponent; +uint32_t mant_hi; +uint32_t mant_lo; +}QEMU_PACKED ; + +#endif /* __QAPI_BER_COMMON_H__ */
qapi/ber-output-visitor.c new file +617 -0
617 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v3 7/9 asn1_input-visitor.diff
In reply to Joel SchoppImplement an input visitor for ASN.1 BER encoding.
--- include/qapi/ber-input-visitor.h | 30 ++ qapi/Makefile.objs | 2 +- qapi/ber-input-visitor.c | 1073 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1104 insertions(+), 1 deletion(-) create mode 100644 include/qapi/ber-input-visitor.h create mode 100644 qapi/ber-input-visitor.c
include/qapi/ber-input-visitor.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* BER Input Visitor header +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Anthony Liguori <[email protected]> +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef BER_INPUT_VISITOR_H +#define BER_INPUT_VISITOR_H + +#include "qapi/visitor.h" + +typedef struct BERInputVisitor BERInputVisitor ; + +BERInputVisitor *ber_input_visitor_new (QEMUFile *, +uint64_t max_allowd_buffer_size); +void ber_input_visitor_cleanup (BERInputVisitor *v); +uint64_t ber_input_get_parser_position (BERInputVisitor *v); +uint64_t ber_input_get_largest_needed_buffer (BERInputVisitor *v); + +Visitor *ber_input_get_visitor (BERInputVisitor *v); + +#endif
qapi/Makefile.objs +1 -1
@@ -3,4 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o util-obj-y += string-input-visitor.o string-output-visitor.o util-obj-y += opts-visitor.o -util-obj-y += ber-common.o ber-output-visitor.o +util-obj-y += ber-common.o ber-output-visitor.o ber-input-visitor.o
qapi/ber-input-visitor.c new file +1073 -0
1,073 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v3 8/9 asn1_test_visitor_serialization.diff
In reply to Joel SchoppAdd BER Visitor hooks to test-visitor-serialization
--- tests/Makefile | 2 +- tests/test-visitor-serialization.c | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-)
tests/Makefile +1 -1
@@ -124,7 +124,7 @@ tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o $(test-q tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) qapi-types.o qapi-visit.o libqemuutil.a libqemustub.a -tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a +tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) $(block-obj-y) libqemuutil.a libqemustub.a tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
tests/test-visitor-serialization.c +72 -0
96 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v3 9/9 update_maintainers.diff
In reply to Joel SchoppSince I'm throwing all this code out there I'm also signing up to maintain it. Send me your bug reports.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -790,3 +790,11 @@ Stable 0.10 L: [email protected] T: git git://git.qemu.org/qemu-stable-0.10.git S: Orphan + +Visitors +--------------- +ASN.1 BER +M: Joel Schopp <[email protected]> +S: Maintained +F: /qapi/ber* +F: include/qapi/ber*
Signature · 1 line
1.7.10.4