VMState testing
v3 cover VMState testing
Hi,
The following patch introduce a mechanism to test the correctness of the vmstate's information. This is achieved by saving the device states' information to a memory buffer and then clearing the states, followed by loading the data from the saved memory buffer.
v2 --> v3
* Made the devices list generic by removing the qdevified format. But, it only supports the qdevified devices.
* Extended the SaveStateEntry for the VMstate testing purpose.
* Replaced DPRINTF with trace_##name functions.
* Squashed all of the hmp and qmp patches into one.
* Rectified some mistakes in the documentation of the hmp and qmp interface explanations (the ones which I have introduced).
* Now, I am relying only on the devices that have been qdevified. I am not using the qemu_system_reset() function for resetting the devices.
v1 --> v2:
* Added a list containing all the devices that have been qdevified and gets registered with the SaveStateEntry.
* Have provided a way to use either qemu_system_reset functionality or my own version of qdev entries untill all the devices have been qdevified. This gives us the privilege to test any device we want.
* Rename some of the variables. I am very bad at naming convention, thanks to community, specially Eric, I try to improve it with every version.
* On Eric's advice, I have separated all of the qmp and hmp interface patches.
* Changed the DPRINTF statements as required.
Dr. David Alan Gilbert (1):
QEMUSizedBuffer/QEMUFile
Sanidhya Kashyap (5):
VMState test: get information about the registered devices VMstate test: basic VMState testing mechanism
VMState test: querying the vmstate testing process
VMState test: update period of vmstate testing process VMState test: cancel mechanism for an already running vmstate testing
process
hmp-commands.hx | 49 +++++ hmp.c | 90 +++++++++ hmp.h | 5 + include/migration/qemu-file.h | 27 +++ monitor.c | 14 ++ qapi-schema.json | 106 +++++++++++ qemu-file.c | 411 ++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 145 +++++++++++++++ savevm.c | 332 ++++++++++++++++++++++++++++++++++ trace-events | 2 + 10 files changed, 1181 insertions(+)
Signature · 1 line
1.9.3
RFC PATCH v3 1/6 QEMUSizedBuffer/QEMUFile
From: "Dr. David Alan Gilbert" <[email protected]>
Stefan Berger's to create a QEMUFile that goes to a memory buffer; from:
http://lists.gnu.org/archive/html/qemu-devel/2013-03/msg05036.html
Using the QEMUFile interface, this patch adds support functions for operating
on in-memory sized buffers that can be written to or read from.
--- include/migration/qemu-file.h | 27 +++ qemu-file.c | 411 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 438 insertions(+)
include/migration/qemu-file.h +27 -0
@@ -25,6 +25,8 @@#define QEMU_FILE_H 1#include "exec/cpu-common.h" +#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.
@@ -94,11 +96,31 @@ typedef struct QEMUFileOps {QEMURamSaveFunc *save_page; } QEMUFileOps; +struct QEMUSizedBuffer { +struct iovec *iov; +size_t n_iov; +size_t size;/* total allocated size in all iov's */ +size_t used;/* number of used bytes */ +}; + +typedef struct QEMUSizedBuffer QEMUSizedBuffer ; +QEMUSizedBuffer *qsb_create (const uint8_t *buffer,size_t len); +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *); +void qsb_free (QEMUSizedBuffer *); +size_t qsb_set_length (QEMUSizedBuffer *qsb,size_t length); +size_t qsb_get_length (const QEMUSizedBuffer *qsb); +ssize_t qsb_get_buffer (const QEMUSizedBuffer *,off_t start,size_t count, +uint8_t **buf); +ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf, +off_t pos,size_t count); + +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);QEMUFile *qemu_fopen_socket (int fd,const char *mode);QEMUFile *qemu_popen_cmd (const char *command,const char *mode); +QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);int64_t qemu_ftell (QEMUFile *f);
@@ -111,6 +133,11 @@ void qemu_put_byte(QEMUFile *f, int v);void qemu_put_buffer_async (QEMUFile *f,const uint8_t *buf,int size);bool qemu_file_mode_is_not_valid (const char *mode); +/* +* For use on files opened with qemu_bufopen +*/ +const QEMUSizedBuffer *qemu_buf_get (QEMUFile *f); +static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {qemu_put_byte (f, (int )v);
qemu-file.c +411 -0
414 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [Qemu-devel] [RFC PATCH v3 1/6] QEMUSizedBuffer/QEMUFile
Quoted 318 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Sanidhya Kashyap
Sent: Saturday, August 09, 2014 2:27 PM
To: qemu list
Cc: Sanidhya Kashyap; Joel Schopp; Stefan Berger; Dr. David Alan Gilbert; Juan Quintela
Subject: [Qemu-devel] [RFC PATCH v3 1/6] QEMUSizedBuffer/QEMUFileFrom: "Dr. David Alan Gilbert" <[email protected]>
Stefan Berger's to create a QEMUFile that goes to a memory buffer; from:
http://lists.gnu.org/archive/html/qemu-devel/2013-03/msg05036.html
Using the QEMUFile interface, this patch adds support functions for operating
on in-memory sized buffers that can be written to or read from.Signed-off-by Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>Signed-off-by Sanidhya Kashyap <[email protected]>--- include/migration/qemu-file.h | 27 +++ qemu-file.c | 411 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 438 insertions(+)include/migration/qemu-file.h +27
-0@@ -25,6 +25,8 @@#define QEMU_FILE_H 1#include "exec/cpu-common.h" +#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. @@ -94,11 +96,31 @@ typedef struct QEMUFileOps {QEMURamSaveFunc *save_page; } QEMUFileOps; +struct QEMUSizedBuffer { +struct iovec *iov; +size_t n_iov; +size_t size;/* total allocated size in all iov's */ +size_t used;/* number of used bytes */ +}; + +typedef struct QEMUSizedBuffer QEMUSizedBuffer ; +QEMUSizedBuffer *qsb_create (const uint8_t *buffer,size_t len); +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *); +void qsb_free (QEMUSizedBuffer *); +size_t qsb_set_length (QEMUSizedBuffer *qsb,size_t length); +size_t qsb_get_length (const QEMUSizedBuffer *qsb); +ssize_t qsb_get_buffer (const QEMUSizedBuffer *,off_t start,size_t count, +uint8_t **buf); +ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf, +off_t pos,size_t count); + +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);QEMUFile *qemu_fopen_socket (int fd,const char *mode);QEMUFile *qemu_popen_cmd (const char *command,const char *mode); +QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);int64_t qemu_ftell (QEMUFile *f);@@ -111,6 +133,11 @@ void qemu_put_byte(QEMUFile *f, int v);void qemu_put_buffer_async (QEMUFile *f,const uint8_t *buf,int size);bool qemu_file_mode_is_not_valid (const char *mode); +/* +* For use on files opened with qemu_bufopen +*/ +const QEMUSizedBuffer *qemu_buf_get (QEMUFile *f); +static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {qemu_put_byte (f, (int )v);qemu-file.c +223
-0@@ -878,3 +878,414 @@ uint64_t qemu_get_be64(QEMUFile *f) v |=qemu_get_be32 (f);return v; } + + +#define QSB_CHUNK_SIZE (1 << 10) +#define QSB_MAX_CHUNK_SIZE (10 * QSB_CHUNK_SIZE) + +/** +* Create a QEMUSizedBuffer +* This type of buffer uses scatter-gather lists internally and +* can grow to any size. Any data array in the scatter-gather list +* can hold different amount of bytes. +* +* @buffer: Optional buffer to copy into the QSB +* @len: size of initial buffer; if @buffer is given, buffer must +* hold at least len bytes +* +* Returns a pointer to a QEMUSizedBuffer +*/ +QEMUSizedBuffer *qsb_create (const uint8_t *buffer,size_t len) +{ +QEMUSizedBuffer *qsb; +size_t alloc_len, num_chunks, i, to_copy; +size_t chunk_size = (len >QSB_MAX_CHUNK_SIZE ) + ?QSB_MAX_CHUNK_SIZE + :QSB_CHUNK_SIZE ; + +if (len ==0 ) { +/* we want to allocate at least one chunk */ + len =QSB_CHUNK_SIZE ; + } + + num_chunks =DIV_ROUND_UP (len, chunk_size); + alloc_len = num_chunks * chunk_size; + + qsb =g_new0 (QEMUSizedBuffer,1 ); + qsb->iov = g_new0(struct iovec, num_chunks); + qsb->n_iov = num_chunks; + +for (i =0 ; i < num_chunks; i++) { + qsb->iov[i].iov_base =g_malloc0 (chunk_size); + qsb->iov[i].iov_len = chunk_size; +if (buffer) { + to_copy = (len - qsb->used) > chunk_size + ? chunk_size : (len - qsb->used); +memcpy (qsb->iov[i].iov_base, &buffer[qsb->used], to_copy); + qsb->used += to_copy; + } + } + + qsb->size = alloc_len; + +return qsb; +} + +/** +* Free the QEMUSizedBuffer +* +* @qsb: The QEMUSizedBuffer to free +*/ +void qsb_free (QEMUSizedBuffer *qsb) +{ +size_t i; + +if (!qsb) { +return ; + } + +for (i =0 ; i < qsb->n_iov; i++) { +g_free (qsb->iov[i].iov_base); + } +g_free (qsb->iov); +g_free (qsb); +} + +/** +* Get the number of of used bytes in the QEMUSizedBuffer +* +* @qsb: A QEMUSizedBuffer +* +* Returns the number of bytes currently used in this buffer +*/ +size_t qsb_get_length (const QEMUSizedBuffer *qsb) +{ +return qsb->used; +} + +/** +* Set the length of the buffer; The primary usage of this +* function is to truncate the number of used bytes in the buffer. +* The size will not be extended beyond the current number of +* allocated bytes in the QEMUSizedBuffer. +* +* @qsb: A QEMUSizedBuffer +* @new_len : The new length of bytes in the buffer +* +* Returns the number of bytes the buffer was trucated or extended +* to. +*/ +size_t qsb_set_length (QEMUSizedBuffer *qsb,size_t new_len) +{ +if (new_len <= qsb->size) { + qsb->used = new_len; + }else { + qsb->used = qsb->size; + } +return qsb->used; +} + +/** +* Get the iovec that holds the data for a given position @pos. +* +* @qsb: A QEMUSizedBuffer +* @pos: The index of a byte in the buffer +* @d_off: Pointer to an offset that this function will indicate +* at what position within the returned iovec the byte +* is to be found +* +* Returns the index of the iovec that holds the byte at the given +* index @pos in the byte stream; a negative number if the iovec +* for the given position @pos does not exist. +*/ +static ssize_t qsb_get_iovec (const QEMUSizedBuffer *qsb, +off_t pos,off_t *d_off) +{ +ssize_t i; +off_t curr =0 ; + +if (pos > qsb->used) { +return -1 ; + } + +for (i =0 ; i < qsb->n_iov; i++) { +if (curr + qsb->iov[i].iov_len > pos) { + *d_off = pos - curr; +return i; + } + curr += qsb->iov[i].iov_len; + } +return -1 ; +} + +/* +* Convert the QEMUSizedBuffer into a flat buffer. +* +* Note: If at all possible, try to avoid this function since it +* may unnecessarily copy memory around. +* +* @qsb: pointer to QEMUSizedBuffer +* @start : offset to start at +* @count: number of bytes to copy +* @buf: a pointer to an optional buffer to write into; the pointer may +* point to NULL in which case the buffer will be allocated; +* if buffer is provided, it must be large enough to hold @count bytes +* +* Returns the number of bytes copied into the output buffer +*/ +ssize_t qsb_get_buffer (const QEMUSizedBuffer *qsb,off_t start, +size_t count,uint8_t **buf) +{ +uint8_t *buffer; +const struct iovec *iov; +size_t to_copy, all_copy; +ssize_t index; +off_t s_off; +off_t d_off =0 ; +char *s; + +if (start > qsb->used) { +return 0 ; + } + + all_copy = qsb->used - start; +if (all_copy > count) { + all_copy = count; + }else { + count = all_copy; + } + +if (*buf ==NULL ) { + *buf =g_malloc (all_copy); + } + buffer = *buf; + + index =qsb_get_iovec (qsb, start, &s_off); +if (index <0 ) { +return 0 ; + } + +while (all_copy >0 ) { + iov = &qsb->iov[index]; + + s = iov->iov_base; + + to_copy = iov->iov_len - s_off; +if (to_copy > all_copy) { + to_copy = all_copy; + } +memcpy (&buffer[d_off], &s[s_off], to_copy); + + d_off += to_copy; + all_copy -= to_copy; + + s_off =0 ; + index++; + } + +return count; +} + +/** +* Grow the QEMUSizedBuffer to the given size and allocated +* memory for it. +* +* @qsb: A QEMUSizedBuffer +* @new_size: The new size of the buffer +* +* Returns an error code in case of memory allocation failure +* or the new size of the buffer otherwise. The returned size +* may be greater or equal to @new_size. +*/ +static ssize_t qsb_grow (QEMUSizedBuffer *qsb,size_t new_size) +{ +size_t needed_chunks, i; +size_t chunk_size =QSB_CHUNK_SIZE ;
qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 1113
Quoted 10 lines
qemu-file.c +10
-0+ +if (qsb->size < new_size) { + needed_chunks =DIV_ROUND_UP (new_size - qsb->size, + chunk_size); + + qsb->iov =g_realloc_n (qsb->iov, qsb->n_iov + needed_chunks, +sizeof (struct iovec )); +if (qsb->iov ==NULL ) { +return -ENOMEM ; + }
OK...
Quoted 31 lines
qemu-file.c +31
-0+ +for (i = qsb->n_iov; i < qsb->n_iov + needed_chunks; i++) { + qsb->iov[i].iov_base =g_malloc0 (chunk_size); + qsb->iov[i].iov_len = chunk_size; + } + + qsb->n_iov += needed_chunks; + qsb->size += (needed_chunks * chunk_size); + } + +return qsb->size; +} + +/** +* Write into the QEMUSizedBuffer at a given position and a given +* number of bytes. This function will automatically grow the +* QEMUSizedBuffer. +* +* @qsb: A QEMUSizedBuffer +* @source: A byte array to copy data from +* @pos: The position withing the @qsb to write data to +* @size: The number of bytes to copy into the @qsb +* +* Returns an error code in case of memory allocation failure, +* @size otherwise. +*/ +ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *source, +off_t pos,size_t count) +{ +ssize_t rc =qsb_grow (qsb, pos + count); +size_t to_copy;
qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 1154
Quoted 10 lines
qemu-file.c +10
-0+size_t all_copy = count; +const struct iovec *iov; +ssize_t index; +char *dest; +off_t d_off, s_off =0 ; + +if (rc <0 ) { +return rc; + } +
OK...
Quoted 37 lines
qemu-file.c +37
-0+if (pos + count > qsb->used) { + qsb->used = pos + count; + } + + index =qsb_get_iovec (qsb, pos, &d_off); +if (index <0 ) { +return 0 ; + } + +while (all_copy >0 ) { + iov = &qsb->iov[index]; + + dest = iov->iov_base; + + to_copy = iov->iov_len - d_off; +if (to_copy > all_copy) { + to_copy = all_copy; + } + +memcpy (&dest[d_off], &source[s_off], to_copy); + + s_off += to_copy; + all_copy -= to_copy; + + d_off =0 ; + index++; + } + +return count; +} + +/** +* Create an exact copy of the given QEMUSizedBuffer. +* +* @qsb : A QEMUSizedBuffer +* +* Returns a clone of @qsb
qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 1201
Quoted 10 lines
qemu-file.c +10
-0+*/ +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *qsb) +{ +QEMUSizedBuffer *out =qsb_create (NULL ,qsb_get_length (qsb)); +size_t i; +off_t pos =0 ; + +for (i =0 ; i < qsb->n_iov; i++) { + pos +=qsb_write_at (out, qsb->iov[i].iov_base, + pos, qsb->iov[i].iov_len);
If qsb_write_at() return -ENOMEM, just simply add it to pos ?
Best regards,
-Gonglei
Re: [Qemu-devel] [RFC PATCH v3 1/6] QEMUSizedBuffer/QEMUFile
* Gonglei (Arei) ([email protected]) wrote:
<snip>
Quoted 19 lines
Quoted 19 lines
qemu-file.c +19
-0+/** +* Grow the QEMUSizedBuffer to the given size and allocated +* memory for it. +* +* @qsb: A QEMUSizedBuffer +* @new_size: The new size of the buffer +* +* Returns an error code in case of memory allocation failure +* or the new size of the buffer otherwise. The returned size +* may be greater or equal to @new_size. +*/ +static ssize_t qsb_grow (QEMUSizedBuffer *qsb,size_t new_size) +{ +size_t needed_chunks, i; +size_t chunk_size =QSB_CHUNK_SIZE ; + +if (qsb->size < new_size) { + needed_chunks =DIV_ROUND_UP (new_size - qsb->size, + chunk_size);
Quoted 8 lines
qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 1113
Quoted 6 lines
qemu-file.c +6
-0+ + qsb->iov =g_realloc_n (qsb->iov, qsb->n_iov + needed_chunks, +sizeof (struct iovec )); +if (qsb->iov ==NULL ) { +return -ENOMEM ; + }OK...
Is it? https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html
says that g_realloc_n is 'similar to g_realloc()' except for overflow protection, g_realloc() doesn't say what it's behaviour on OOM is, but g_try_realloc says that 'Contrast with g_realloc(), which aborts the program on failure' So the only case iov will return NULL there is if the size is 0 which it can't be. So should that be a g_try_realloc_n ?
Quoted 85 lines
Quoted 31 lines
qemu-file.c +31
-0+ +for (i = qsb->n_iov; i < qsb->n_iov + needed_chunks; i++) { + qsb->iov[i].iov_base =g_malloc0 (chunk_size); + qsb->iov[i].iov_len = chunk_size; + } + + qsb->n_iov += needed_chunks; + qsb->size += (needed_chunks * chunk_size); + } + +return qsb->size; +} + +/** +* Write into the QEMUSizedBuffer at a given position and a given +* number of bytes. This function will automatically grow the +* QEMUSizedBuffer. +* +* @qsb: A QEMUSizedBuffer +* @source: A byte array to copy data from +* @pos: The position withing the @qsb to write data to +* @size: The number of bytes to copy into the @qsb +* +* Returns an error code in case of memory allocation failure, +* @size otherwise. +*/ +ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *source, +off_t pos,size_t count) +{ +ssize_t rc =qsb_grow (qsb, pos + count); +size_t to_copy;qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 1154
Quoted 10 lines
qemu-file.c +10
-0+size_t all_copy = count; +const struct iovec *iov; +ssize_t index; +char *dest; +off_t d_off, s_off =0 ; + +if (rc <0 ) { +return rc; + } +OK...
Quoted 41 lines
qemu-file.c +41
-0+if (pos + count > qsb->used) { + qsb->used = pos + count; + } + + index =qsb_get_iovec (qsb, pos, &d_off); +if (index <0 ) { +return 0 ; + } + +while (all_copy >0 ) { + iov = &qsb->iov[index]; + + dest = iov->iov_base; + + to_copy = iov->iov_len - d_off; +if (to_copy > all_copy) { + to_copy = all_copy; + } + +memcpy (&dest[d_off], &source[s_off], to_copy); + + s_off += to_copy; + all_copy -= to_copy; + + d_off =0 ; + index++; + } + +return count; +} + +/** +* Create an exact copy of the given QEMUSizedBuffer. +* +* @qsb : A QEMUSizedBuffer +* +* Returns a clone of @qsb +*/ +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *qsb) +{ +QEMUSizedBuffer *out =qsb_create (NULL ,qsb_get_length (qsb));
Quoted 8 lines
qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 1201
Quoted 6 lines
qemu-file.c +6
-0+size_t i; +off_t pos =0 ; + +for (i =0 ; i < qsb->n_iov; i++) { + pos +=qsb_write_at (out, qsb->iov[i].iov_base, + pos, qsb->iov[i].iov_len);If
qsb_write_at()return-ENOMEM, just simply add it to pos ?
qsb_create uses g_new0 so it will abort on out of memory; what should qsb_clone do if qsb_write_at returns -ENOMEM? (Admittedly anything is better than getting the position wrong). I guess the choice is to allow it to return NULL, tidying up and offering the chance sometime in the future of tidying up the other allocators.
Dave
Quoted 3 lines
Best regards,
-Gonglei
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [RFC PATCH v3 1/6] QEMUSizedBuffer/QEMUFile
Quoted 128 lines · Dr. David Alan Gilbert
* Gonglei (Arei) ([email protected]) wrote:
<snip>
Quoted 18 lines
Quoted 18 lines
qemu-file.c +18
-0+/** +* Grow the QEMUSizedBuffer to the given size and allocated +* memory for it. +* +* @qsb: A QEMUSizedBuffer +* @new_size: The new size of the buffer +* +* Returns an error code in case of memory allocation failure +* or the new size of the buffer otherwise. The returned size +* may be greater or equal to @new_size. +*/ +static ssize_t qsb_grow (QEMUSizedBuffer *qsb,size_t new_size) +{ +size_t needed_chunks, i; +size_t chunk_size =QSB_CHUNK_SIZE ; + +if (qsb->size < new_size) { + needed_chunks = DIV_ROUND_UP(new_size - qsb->size,Quoted 8 lines
qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 1113
Quoted 7 lines
qemu-file.c +7
-0+ chunk_size); + + qsb->iov =g_realloc_n (qsb->iov, qsb->n_iov + needed_chunks, +sizeof (struct iovec )); +if (qsb->iov ==NULL ) { +return -ENOMEM ; + }OK...
Is it? https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html
says thatg_realloc_nis 'similar tog_realloc()' except for overflow protection,g_realloc()doesn't say what it's behaviour on OOM is, butg_try_reallocsays that 'Contrast withg_realloc(), which aborts the program on failure' So the only case iov will return NULL there is if the size is 0 which it can't be. So should that be ag_try_realloc_n?Quoted 83 lines
Quoted 31 lines
qemu-file.c +31
-0+ +for (i = qsb->n_iov; i < qsb->n_iov + needed_chunks; i++) { + qsb->iov[i].iov_base =g_malloc0 (chunk_size); + qsb->iov[i].iov_len = chunk_size; + } + + qsb->n_iov += needed_chunks; + qsb->size += (needed_chunks * chunk_size); + } + +return qsb->size; +} + +/** +* Write into the QEMUSizedBuffer at a given position and a given +* number of bytes. This function will automatically grow the +* QEMUSizedBuffer. +* +* @qsb: A QEMUSizedBuffer +* @source: A byte array to copy data from +* @pos: The position withing the @qsb to write data to +* @size: The number of bytes to copy into the @qsb +* +* Returns an error code in case of memory allocation failure, +* @size otherwise. +*/ +ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *source, +off_t pos,size_t count) +{ +ssize_t rc =qsb_grow (qsb, pos + count); +size_t to_copy;qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 1154
Quoted 10 lines
qemu-file.c +10
-0+size_t all_copy = count; +const struct iovec *iov; +ssize_t index; +char *dest; +off_t d_off, s_off =0 ; + +if (rc <0 ) { +return rc; + } +OK...
Quoted 40 lines
qemu-file.c +40
-0+if (pos + count > qsb->used) { + qsb->used = pos + count; + } + + index =qsb_get_iovec (qsb, pos, &d_off); +if (index <0 ) { +return 0 ; + } + +while (all_copy >0 ) { + iov = &qsb->iov[index]; + + dest = iov->iov_base; + + to_copy = iov->iov_len - d_off; +if (to_copy > all_copy) { + to_copy = all_copy; + } + +memcpy (&dest[d_off], &source[s_off], to_copy); + + s_off += to_copy; + all_copy -= to_copy; + + d_off =0 ; + index++; + } + +return count; +} + +/** +* Create an exact copy of the given QEMUSizedBuffer. +* +* @qsb : A QEMUSizedBuffer +* +* Returns a clone of @qsb +*/ +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *qsb) +{Quoted 8 lines
qemu-file.c uint64_t qemu_get_be64(QEMUFile *f) · line 1201
Quoted 7 lines
qemu-file.c +7
-0+QEMUSizedBuffer *out =qsb_create (NULL ,qsb_get_length (qsb)); +size_t i; +off_t pos =0 ; + +for (i =0 ; i < qsb->n_iov; i++) { + pos +=qsb_write_at (out, qsb->iov[i].iov_base, + pos, qsb->iov[i].iov_len);If
qsb_write_at()return-ENOMEM, just simply add it to pos ?
Quoted 6 lines
qsb_createusesg_new0so it will abort on out of memory; what shouldqsb_clonedo ifqsb_write_atreturns-ENOMEM? (Admittedly anything is better than getting the position wrong). I guess the choice is to allow it to return NULL, tidying up and offering the chance sometime in the future of tidying up the other allocators.
I remember looking at all the allocation API as well. It seems QEMU would terminate upon OOM since g_new0 is used all over the place.
Stefan
Re: [Qemu-devel] [RFC PATCH v3 1/6] QEMUSizedBuffer/QEMUFile
In reply to Sanidhya KashyapQuoted 11 lines · Sanidhya Kashyap
From: "Dr. David Alan Gilbert" <[email protected]>
Stefan Berger's to create a QEMUFile that goes to a memory buffer; from:
http://lists.gnu.org/archive/html/qemu-devel/2013-03/msg05036.html
Using the QEMUFile interface, this patch adds support functions for operating
on in-memory sized buffers that can be written to or read from.
Quoted 7 lines
Signed-off-by Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>Signed-off-by Sanidhya Kashyap <[email protected]>--- include/migration/qemu-file.h | 27 +++ qemu-file.c | 411 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 438 insertions(+)
I'd rather see us take the version most recently updated by David:
https://lists.gnu.org/archive/html/qemu-devel/2014-08/msg01099.html
then you rebase the rest of your series on top of that.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
RFC PATCH v3 2/6 VMState test: get information about the registered devices
In reply to Sanidhya KashyapAdded both qmp and hmp interface to get the information about the devices that have been qdevified and are registered with the SaveVMHandlers. I have not used any format to print the device information for the hmp interface. It would be great if anyone can give me some pointers about this about the printing format if there is something.
The qmp command to extract the information about the devices is qmp_query_devices which provides the list of device names and their respective version. The hmp command name is 'info devices' which lists the same information as provided by the qmp interface.
--- hmp-commands.hx | 2 ++ hmp.c | 23 +++++++++++++++++++++++ hmp.h | 1 + monitor.c | 7 +++++++ qapi-schema.json | 26 ++++++++++++++++++++++++++ qmp-commands.hx | 43 +++++++++++++++++++++++++++++++++++++++++++ savevm.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 147 insertions(+)
hmp-commands.hx +2 -0
@@ -1780,6 +1780,8 @@ show qdev device model list show roms @item info tpm show the TPM device +@item info devices +show the devices registered with migration capability @end table ETEXI
hmp.c +23 -0
@@ -1714,3 +1714,26 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)monitor_printf (mon,"\n" ); } + +void hmp_info_devices (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; +QemuDeviceList *device_list =qmp_query_devices (&err); + +if (device_list) { +monitor_printf (mon,"devices:\n" ); +while (device_list) { +monitor_printf (mon,"device-name: %s, " , + device_list->value->device_name); +monitor_printf (mon,"version: %ld\n" , + device_list->value->version); + device_list = device_list->next; + } + } + +if (err) { +hmp_handle_error (mon, &err); + } + +qapi_free_QemuDeviceList (device_list); +}
hmp.h +1 -0
@@ -38,6 +38,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict);void hmp_info_pci (Monitor *mon,const QDict *qdict);void hmp_info_block_jobs (Monitor *mon,const QDict *qdict);void hmp_info_tpm (Monitor *mon,const QDict *qdict); +void hmp_info_devices (Monitor *mon,const QDict *qdict);void hmp_quit (Monitor *mon,const QDict *qdict);void hmp_stop (Monitor *mon,const QDict *qdict);void hmp_system_reset (Monitor *mon,const QDict *qdict);
monitor.c +7 -0
@@ -2918,6 +2918,13 @@ static mon_cmd_t info_cmds[] = { .mhandler.cmd = hmp_info_memdev, }, { + .name = "devices", + .args_type = "", + .params = "", + .help = "show registered devices", + .mhandler.cmd = hmp_info_devices, + }, + { .name = NULL, }, };
qapi-schema.json +26 -0
@@ -3480,3 +3480,29 @@ # Since: 2.1 ## { 'command': 'rtc-reset-reinjection' } + +## +# @QemuDevice +# +# device that is registered with SaveVMHandlers +# +# @device-name: name of the device that is registered with +# SaveVMHandlers (in vmsd structure). +# +# @version: version of the device. +# +# Since 2.2 +## +{ 'type': 'QemuDevice', + 'data': { 'device-name': 'str', + '*version': 'int' } } + +## +# @query-devices +# +# returns the list of QemuDevice +# +# Since 2.2 +## +{ 'command': 'query-devices', + 'returns': [ 'QemuDevice' ] }
qmp-commands.hx +43 -0
46 lines not on this page · raw message
savevm.c +45 -0
69 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [Qemu-devel] [RFC PATCH v3 2/6] VMState test: get information about the registered devices
Quoted 24 lines · Sanidhya Kashyap
Added both qmp and hmp interface to get the information about the devices that have been qdevified and are registered with the SaveVMHandlers. I have not used any format to print the device information for the hmp interface. It would be great if anyone can give me some pointers about this about the printing format if there is something.
The qmp command to extract the information about the devices is
qmp_query_deviceswhich provides the list of device names and their respective version. The hmp command name is 'info devices' which lists the same information as provided by the qmp interface.Signed-off-by Sanidhya Kashyap <[email protected]>--- hmp-commands.hx | 2 ++ hmp.c | 23 +++++++++++++++++++++++ hmp.h | 1 + monitor.c | 7 +++++++ qapi-schema.json | 26 ++++++++++++++++++++++++++ qmp-commands.hx | 43 +++++++++++++++++++++++++++++++++++++++++++ savevm.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 147 insertions(+)+++
b/qapi-schema.json
qapi-schema.json line 3487
Quoted 8 lines
qapi-schema.json +5
-0@@ -3480,3 +3480,29 @@ # Since: 2.1 ## { 'command': 'rtc-reset-reinjection' } + +## +# @QemuDevice +# +# device that is registered with SaveVMHandlers
This sounds like an internal implementation detail; is there a better description more suited to what this struct represents from the API point of view, maybe as simple as: "Information about a device"
qapi-schema.json line 3508
Quoted 2 lines
qapi-schema.json +2
-0+{ 'command': 'query-devices', + 'returns': [ 'QemuDevice' ] }
Looks okay here...
qmp-commands.hx Example: · line 3771
Quoted 7 lines
qmp-commands.hx +2
-0+ +Example (1):
s/ (1)// - unless you have a second example, you don't need to label the first example with a 1 suffix
qmp-commands.hx Example: · line 3776
Quoted 5 lines
qmp-commands.hx +5
-0+ +-> { "execute": "query-devices" } +<- { "return": [ + { + [ { 'device-name': 'kvm-tpr-opt', 'version': 1 },
... but this doesn't match your command. You have too many layers. Also, QMP wire format uses ONLY ", never '. It should look like:
{ "return": [ { "device-name": "kvm-tpr-opt", "version": 1 },
...
] }In fact, rather than trying to write it by hand, actually compile your code and test the actual QMP output and paste that in - then you'll know you got it right.
qmp-commands.hx
Quoted 2 lines
qmp-commands.hx +2
-0+static QemuDeviceList *create_device_list(const char *name, int version, + QemuDeviceList *list)
Indentation is off.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
RFC PATCH v3 3/6 VMstate test: basic VMState testing mechanism
In reply to Sanidhya KashyapThis patch implements the basic way of testing the VMStates' information whether it is correct or not while saving and loading the states. The qmp interface - test-vmstates can take three parameters as an input to test the device states. Now, one can check for any of the devices that have been registered with the SaveVMHandlers aka the migration protocol. Similarly, the hmp interface (test_vmstates) has only two input parameters - iterations and period.
I have removed the following from the patch on previous comments:
* replaed DPRINTF with trace_##name.
* removed the noqdev and completely removed the support for resetting of devices based on qemu_system_reset()
As Juan pointed out that there might be a memory leak as I did not close the QEMUFile pointer. But, it is not required as that pointer is directly referenced by the QEMUBuffer that has been implemented by David. So, IMHO the case pointed out by Juan does not exist.
--- hmp-commands.hx | 16 ++++ hmp.c | 17 ++++ hmp.h | 1 + qapi-schema.json | 22 ++++++ qmp-commands.hx | 33 ++++++++ savevm.c | 233 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ trace-events | 2 + 7 files changed, 324 insertions(+)
hmp-commands.hx +16 -0
@@ -1790,6 +1790,22 @@ STEXI show available trace events and their state ETEXI + { + .name = "test_vmstates", + .args_type = "iterations:i?,period:i?", + .params = "iterations period", + .help = "test the vmstates by dumping and loading form memory\n\t\t\t" + "iterations: (optional) number of times, the vmstates will be tested\n\t\t\t" + "period: (optional) sleep interval in milliseconds between each iteration", + .mhandler.cmd = hmp_test_vmstates, + }, +STEXI +@item test_vmstates +@findex test_vmstates +dumps and reads the device state's data from the memory for testing purpose +ETEXI + + STEXI @end table ETEXI
hmp.c +17 -0
@@ -1737,3 +1737,20 @@ void hmp_info_devices(Monitor *mon, const QDict *qdict)qapi_free_QemuDeviceList (device_list); } +void hmp_test_vmstates (Monitor *mon,const QDict *qdict) +{ +int has_iterations =qdict_haskey (qdict,"iterations" ); +int64_t iterations =qdict_get_try_int (qdict,"iterations" ,10 ); +int has_period =qdict_haskey (qdict,"period" ); +int64_t period =qdict_get_try_int (qdict,"period" ,100 ); + +Error *err =NULL ; + +qmp_test_vmstates (has_iterations, iterations, has_period, period, + false,NULL , &err); + +if (err) { +monitor_printf (mon,"test-vmstates: %s\n" ,error_get_pretty (err)); +error_free (err); + } +}
hmp.h +1 -0
@@ -95,6 +95,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict);void hmp_object_add (Monitor *mon,const QDict *qdict);void hmp_object_del (Monitor *mon,const QDict *qdict);void hmp_info_memdev (Monitor *mon,const QDict *qdict); +void hmp_test_vmstates (Monitor *mon,const QDict *qdict);void object_add_completion (ReadLineState *rs,int nb_args,const char *str);void object_del_completion (ReadLineState *rs,int nb_args,const char *str);void device_add_completion (ReadLineState *rs,int nb_args,const char *str);
qapi-schema.json +22 -0
@@ -3506,3 +3506,25 @@ ## { 'command': 'query-devices', 'returns': [ 'QemuDevice' ] } + +## +# @test-vmstates +# +# tests the vmstates' value by dumping and loading in memory +# +# @iterations: (optional) The total iterations for vmstate testing. +# The min and max defind value is 10 and 100 respectively. +# +# @period: (optional) sleep interval between iteration (in milliseconds). +# The default interval is 100 milliseconds with min and max being +# 1 and 10000 respectively. +# +# @devices: (optional) helps in resetting particular device(s) that +# have been registered with SaveStateEntry. +# +# Since 2.2 +## +{ 'command': 'test-vmstates', + 'data': {'*iterations': 'int', + '*period': 'int', + '*devices': [ 'QemuDevice' ] } }
qmp-commands.hx +33 -0
@@ -3798,3 +3798,36 @@ Example (1): ] } EQMP + + { + .name = "test-vmstates", + .args_type = "iterations:i?,period:i?,devices:O?", + .mhandler.cmd_new = qmp_marshal_input_test_vmstates, + }, + +SQMP +test-vmstates +------------- + +Tests the vmstates' entry by dumping and loading in/from memory + +Arguments: + +- "iterations": (optional) The total iterations for vmstate testing. + The min and max defined value is 10 and 100 respectively. + +- "period": (optional) sleep interval between iteration (in milliseconds). + The default interval is 100 milliseconds with min and max being + 1 and 10000 respectively. + +- "devices": (optional) helps in resetting particular device(s) + that have been registered with SaveStateEntry. + +Example: + +-> { "execute": "test-vmstates", + "arguments": { + "iterations": 10, + "period": 100, } } +<- { "return": {} } +EQMP
savevm.c +233 -0
239 lines not on this page · raw message
trace-events +2 -0
@@ -1086,6 +1086,8 @@ vmstate_save(const char *idstr, const char *vmsd_name) "%s, %s" vmstate_load(const char *idstr, const char *vmsd_name) "%s, %s" vmstate_load_field_error(const char *field, int ret) "field \"%s\" load failed, ret = %d" qemu_announce_self_iter(const char *mac) "%s" +test_vmstates_reset_devices(const char *name) "resetting device: \"%s\"" +test_vmstates_cb(int64_t iteration, int64_t time, const char *info) "iteration: %ld, %s: %ld" # qemu-file.c qemu_file_fclose(void) ""
Signature · 1 line
1.9.3
Re: [Qemu-devel] [RFC PATCH v3 3/6] VMstate test: basic VMState testing mechanism
Quoted 8 lines · Sanidhya Kashyap
This patch implements the basic way of testing the VMStates' information whether it is correct or not while saving and loading the states. The qmp interface - test-vmstates can take three parameters as an input to test the device states. Now, one can check for any of the devices that have been registered with the SaveVMHandlers aka the migration protocol. Similarly, the hmp interface (
test_vmstates) has only two input parameters - iterations and period.
This paragraph:
vvvvvvv
Quoted 4 lines
I have removed the following from the patch on previous comments:
* replaed DPRINTF with trace_##name.
* removed the noqdev and completely removed the support for resetting of devices based onqemu_system_reset()
^^^^^^^
should not be part of the commit message proper, but...
Quoted 9 lines
As Juan pointed out that there might be a memory leak as I did not close the QEMUFile pointer. But, it is not required as that pointer is directly referenced by the QEMUBuffer that has been implemented by David. So, IMHO the case pointed out by Juan does not exist.
Signed-off-by Sanidhya Kashyap <[email protected]>---
...listed here, as a changelog to guide reviewers. Remember, anything before the --- should stand alone as what you would read in qemu.git, without regards to how many revisions the patch went through; and anything after the --- is useful for reviewers but intentionally stripped by the maintainer when using 'git am' as fluff that doesn't help explain the commit in isolation.
Quoted 12 lines
hmp-commands.hx | 16 ++++ hmp.c | 17 ++++ hmp.h | 1 + qapi-schema.json | 22 ++++++ qmp-commands.hx | 33 ++++++++ savevm.c | 233 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ trace-events | 2 + 7 files changed, 324 insertions(+)+++
b/qapi-schema.json
qapi-schema.json line 3515
Quoted 10 lines
qapi-schema.json +7
-0@@ -3506,3 +3506,25 @@ ## { 'command': 'query-devices', 'returns': [ 'QemuDevice' ] } + +## +# @test-vmstates +# +# tests the vmstates' value by dumping and loading in memory +# +# @iterations: (optional) The total iterations for vmstate testing.
For consistency, and in case we ever start generating documentation from the .json file,
s/(optional)/#optional/
qapi-schema.json line 3516
Quoted 1 line
qapi-schema.json +1
-0+# The min and max defind value is 10 and 100 respectively.
s/defind value is/defined values are/
Review line 3518
Quoted 2 lines
(quoted diff) +2
-0+# +# @period: (optional) sleep interval between iteration (in milliseconds).
s/(optional)/#optional/
Quoted 9 lines
qapi-schema.json +9
-0+# The default interval is 100 milliseconds with min and max being +# 1 and 10000 respectively. +# +# @devices: (optional) helps in resetting particular device(s) that +# have been registered with SaveStateEntry. +# +# Since 2.2 +## +{ 'command': 'test-vmstates',
qapi-schema.json
Quoted 10 lines
qapi-schema.json +9
-0+ 'data': {'*iterations': 'int', + '*period': 'int', + '*devices': [ 'QemuDevice' ] } } +Example: + +-> { "execute": "test-vmstates", + "arguments": { + "iterations": 10, + "period": 100, } }
That is not valid JSON. You cannot have a trailing , inside {}. Also, it might be worth an example of the proper use of the optional "devices" parameter.
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static inline bool test_vmstates_check_device_name(VMStateLogState *v,
The compiler is good enough about inlining static functions that you seldom need to use 'inline'. That, and 'static inline' has changed semantics over the years of gcc, so you really want to avoid it unless you know what you are doing.
Quoted 4 lines
savevm.c +4
-0+static void test_vmstates_cb (void *opaque) +{ +VMStateLogState *v = opaque; +int saved_vm_running =runstate_is_running ();
savevm.c QemuDeviceList *qmp_query_devices(Error **errp) · line 1324
Quoted 10 lines
savevm.c +9
-0+const QEMUSizedBuffer *qsb; + + qsb =qemu_buf_get (f); + +/* clearing the states of the guest */ +test_vmstates_reset_devices (v); + + start_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME ); + f =qemu_bufopen ("r" , (QEMUSizedBuffer *)qsb);
Ewww. Why are you casting away const? Make qsb the correct type to begin with.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
RFC PATCH v3 4/6 VMState test: querying the vmstate testing process
In reply to Sanidhya KashyapThis patch has been updated to provide the following information:
* Added a new return value in the form of devices' info that provides the device name as well as the version number.
* provides the hmp interface - info test_vmstates and qmp interface - query-test-vmstates to obtain the information about the running vmstate testing process.
--- hmp-commands.hx | 4 +++- hmp.c | 31 +++++++++++++++++++++++++++++++ hmp.h | 1 + monitor.c | 7 +++++++ qapi-schema.json | 37 +++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 28 ++++++++++++++++++++++++++++ savevm.c | 29 +++++++++++++++++++++++++++++ 7 files changed, 136 insertions(+), 1 deletion(-)
hmp-commands.hx +3 -1
@@ -1770,6 +1770,8 @@ show migration status show current migration capabilities @item info migrate_cache_size show current migration XBZRLE cache size +@item info test_vmstates +show current vmstates testing process info @item info balloon show balloon information @item info qtree
@@ -1799,13 +1801,13 @@ ETEXI "period: (optional) sleep interval in milliseconds between each iteration", .mhandler.cmd = hmp_test_vmstates, }, + STEXI @item test_vmstates @findex test_vmstates dumps and reads the device state's data from the memory for testing purpose ETEXI - STEXI @end table ETEXI
hmp.c +31 -0
@@ -1754,3 +1754,34 @@ void hmp_test_vmstates(Monitor *mon, const QDict *qdict)error_free (err); } } + +void hmp_info_test_vmstates (Monitor *mon,const QDict *qdict) +{ +VMStateLogStateInfo *log_info =qmp_query_test_vmstates (NULL ); +QemuDeviceList *device_list = log_info->devices; +Error *err =NULL ; + +if (log_info) { +monitor_printf (mon,"current-iteration: %" PRId64"\n" +"iterations: %" PRId64"\n" +"period: %" PRId64"\n" , log_info->current_iteration, + log_info->iterations, log_info->period); +if (device_list) { +monitor_printf (mon,"devices:\n" ); +while (device_list) { +monitor_printf (mon,"device_name: %s, " , + device_list->value->device_name); +monitor_printf (mon,"version: %ld\n" , + device_list->value->version); + device_list = device_list->next; + } + } + } + +if (err) { +monitor_printf (mon,"test-vmstates: %s\n" ,error_get_pretty (err)); +error_free (err); + } + +qapi_free_VMStateLogStateInfo (log_info); +}
hmp.h +1 -0
@@ -39,6 +39,7 @@ void hmp_info_pci(Monitor *mon, const QDict *qdict);void hmp_info_block_jobs (Monitor *mon,const QDict *qdict);void hmp_info_tpm (Monitor *mon,const QDict *qdict);void hmp_info_devices (Monitor *mon,const QDict *qdict); +void hmp_info_test_vmstates (Monitor *mon,const QDict *qdict);void hmp_quit (Monitor *mon,const QDict *qdict);void hmp_stop (Monitor *mon,const QDict *qdict);void hmp_system_reset (Monitor *mon,const QDict *qdict);
monitor.c +7 -0
@@ -2925,6 +2925,13 @@ static mon_cmd_t info_cmds[] = { .mhandler.cmd = hmp_info_devices, }, { + .name = "test_vmstates", + .args_type = "", + .params = "", + .help = "show the current vmstates testing information", + .mhandler.cmd = hmp_info_test_vmstates, + }, + { .name = NULL, }, };
qapi-schema.json +37 -0
@@ -3528,3 +3528,40 @@ 'data': {'*iterations': 'int', '*period': 'int', '*devices': [ 'QemuDevice' ] } } + +## +# @VMStateLogStateInfo +# +# VMState testing information +# Tells about the current iteration, the total iterations +# that have been provided and the sleep interval +# +# @current-iteration: shows the current iteration at which +# the test is in. +# +# @iterations: the allocated total iterations for the vmstate +# testing process. +# +# @period: the allowed sleep interval between each iteration +# (in milliseconds). +# +# @devices: returns the list of devices that are being tested +# +# Since 2.2 +## +{ 'type': 'VMStateLogStateInfo', + 'data': { 'current-iteration': 'int', + 'iterations': 'int', + 'period': 'int', + 'devices': [ 'QemuDevice' ] } } + +## +# @query-test-vmstates +# +# Get the current parameters value of the vmstate testing process. +# +# Returns VMStateLogStateInfo structure. +# +# Since 2.2 +## +{ 'command': 'query-test-vmstates', 'returns': 'VMStateLogStateInfo' }
qmp-commands.hx +28 -0
@@ -3831,3 +3831,31 @@ Example: "period": 100, } } <- { "return": {} } EQMP + + { + .name = "query-test-vmstates", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_test_vmstates, + }, + +SQMP +query-test-vmstates +------------------- + +Get the parameters information + +- "current_iteration": the current iteration going on +- "iterations:" the total number of assigned iterations +- "period": the sleep interval between the iteration +- "devices": list of devices that are being tested + +Example: + +-> { "execute": "query-test-vmstates" } +<- { "return": { + "current_iteration": 3, + "iterations": 100, + "period": 100, + "devices": [ { 'device': 'hpet', 'version': 2 }, + { 'device': 'mc146818rtc', 'version': 3 } ] } } +EQMP
savevm.c +29 -0
@@ -1411,6 +1411,35 @@ void qmp_test_vmstates(bool has_iterations, int64_t iterations,timer_mod (v->timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME )); } +VMStateLogStateInfo *qmp_query_test_vmstates (Error **errp) +{ +VMStateLogState *v =test_vmstates_get_current_state (); +VMStateLogStateInfo *log_info =NULL ; +DeviceInfoEntry *de; + +if (!v->active_state) { +return log_info; + } + + log_info =g_malloc0 (sizeof (VMStateLogStateInfo)); + + log_info->current_iteration = v->current_iteration; + log_info->iterations = v->iterations; + log_info->period = v->period; + log_info->devices =NULL ; +if (QTAILQ_EMPTY (&v->device_list)) { + log_info->devices =qmp_query_devices (NULL ); + }else { + QTAILQ_FOREACH(de, &v->device_list, entry) { + log_info->devices =create_device_list (de->device->device_name, + de->device->version, + log_info->devices); + } + } + +return log_info; +} +/* * ---------------------------------------------------------------------------- */
Signature · 1 line
1.9.3
Re: [Qemu-devel] [RFC PATCH v3 4/6] VMState test: querying the vmstate testing process
Quoted 6 lines · Sanidhya Kashyap
This patch has been updated to provide the following information:
* Added a new return value in the form of devices' info that provides the device name as well as the version number.
* provides the hmp interface - infotest_vmstatesand qmp interface - query-test-vmstates to obtain the information about the running vmstate testing process.
Patch changelog information belongs...
Quoted 3 lines
Signed-off-by Sanidhya Kashyap <[email protected]>---
...after the --- separator.
Quoted 14 lines
hmp-commands.hx | 4 +++- hmp.c | 31 +++++++++++++++++++++++++++++++ hmp.h | 1 + monitor.c | 7 +++++++ qapi-schema.json | 37 +++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 28 ++++++++++++++++++++++++++++ savevm.c | 29 +++++++++++++++++++++++++++++ 7 files changed, 136 insertions(+), 1 deletion(-)hmp-commands.hx +0
-0@@ -1799,13 +1801,13 @@ ETEXI "period: (optional) sleep interval in milliseconds between each iteration", .mhandler.cmd = hmp_test_vmstates,
hmp-commands.hx ETEXI · line 1811
Quoted 10 lines
hmp-commands.hx +1
-1}, + STEXI @item test_vmstates @findex test_vmstates dumps and reads the device state's data from the memory for testing purpose ETEXI - STEXI
Spurious whitespace changes?
hmp-commands.hx line 3533
Quoted 8 lines
hmp-commands.hx +4
-0+++ b/qapi-schema.json@@ -3528,3 +3528,40 @@ 'data': {'*iterations': 'int', '*period': 'int', '*devices': [ 'QemuDevice' ] } } + +## +# @VMStateLogStateInfo
Having State in the name twice sounds redundant. Would 'VMStateLogInfo' be sufficient?
Quoted 12 lines
hmp-commands.hx +12
-0+{ 'type': 'VMStateLogStateInfo', + 'data': { 'current-iteration': 'int', + 'iterations': 'int', + 'period': 'int', + 'devices': [ 'QemuDevice' ] } } + +## +# @query-test-vmstates +# +# Get the current parameters value of the vmstate testing process. +# +# Returns VMStateLogStateInfo structure.
hmp-commands.hx
Quoted 10 lines
hmp-commands.hx +9
-0+# +# Since 2.2 +## +{ 'command': 'query-test-vmstates', 'returns': 'VMStateLogStateInfo' } +Example: + +-> { "execute": "query-test-vmstates" } +<- { "return": { + "current_iteration": 3,
Doesn't match the spelling documented in the .json.
hmp-commands.hx
Quoted 3 lines
hmp-commands.hx +3
-0+ "iterations": 100, + "period": 100, + "devices": [ { 'device': 'hpet', 'version': 2 },
QMP uses ", not '. Please paste an actual example (possibly trimmed, if the list of devices is otherwise too huge) rather than trying to write it by hand.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
RFC PATCH v3 5/6 VMState test: update period of vmstate testing process
In reply to Sanidhya Kashyap--- hmp-commands.hx | 15 +++++++++++++++ hmp.c | 14 ++++++++++++++ hmp.h | 1 + qapi-schema.json | 12 ++++++++++++ qmp-commands.hx | 21 +++++++++++++++++++++ savevm.c | 13 +++++++++++++ 6 files changed, 76 insertions(+)
hmp-commands.hx +15 -0
@@ -1808,6 +1808,21 @@ STEXI dumps and reads the device state's data from the memory for testing purpose ETEXI + { + .name = "test_vmstates_set_period", + .args_type = "period:i", + .params = "period", + .help = "set the sleep interval for vmstates testing process\n\t\t\t" + "period: the new sleep interval value to replace the existing", + .mhandler.cmd = hmp_test_vmstates_set_period, + }, + +STEXI +@item test_vmstates_set_period @var{period} +@findex test_vmstates_set_period +Set the period to @var{period} (int) for vmstate testing process. +ETEXI + STEXI @end table ETEXI
hmp.c +14 -0
@@ -1785,3 +1785,17 @@ void hmp_info_test_vmstates(Monitor *mon, const QDict *qdict)qapi_free_VMStateLogStateInfo (log_info); } + +void hmp_test_vmstates_set_period (Monitor *mon,const QDict *qdict) +{ +int64_t period =qdict_get_int (qdict,"period" ); +Error *err =NULL ; + +qmp_test_vmstates_set_period (period, &err); + +if (err) { +monitor_printf (mon,"test-vmstates-set-period: %s\n" , +error_get_pretty (err)); +error_free (err); + } +}
hmp.h +1 -0
@@ -97,6 +97,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict);void hmp_object_del (Monitor *mon,const QDict *qdict);void hmp_info_memdev (Monitor *mon,const QDict *qdict);void hmp_test_vmstates (Monitor *mon,const QDict *qdict); +void hmp_test_vmstates_set_period (Monitor *mon,const QDict *qdict);void object_add_completion (ReadLineState *rs,int nb_args,const char *str);void object_del_completion (ReadLineState *rs,int nb_args,const char *str);void device_add_completion (ReadLineState *rs,int nb_args,const char *str);
qapi-schema.json +12 -0
@@ -3565,3 +3565,15 @@ # Since 2.2 ## { 'command': 'query-test-vmstates', 'returns': 'VMStateLogStateInfo' } + +## +# @test-vmstates-set-period +# +# sets the sleep interval between iterations of the vmstate testing process +# +# @period: the updated sleep interval value (in milliseconds) +# +# Since 2.2 +## +{ 'command' : 'test-vmstates-set-period', + 'data' : { 'period': 'int' } }
qmp-commands.hx +21 -0
@@ -3859,3 +3859,24 @@ Example: "devices": [ { 'device': 'hpet', 'version': 2 }, { 'device': 'mc146818rtc', 'version': 3 } ] } } EQMP + { + .name = "test-vmstates-set-period", + .args_type = "period:i", + .mhandler.cmd_new = qmp_marshal_input_test_vmstates_set_period, + }, + +SQMP +test-vmstates-set-period +------------------------ + +Update the sleep interval for the remaining iterations + +Arguments: + +- "period": the updated sleep interval between iterations (json-int) + +Example: + +-> { "execute": "test-vmstates-set-period", "arguments": { "period": 1024 } } +<- { "return": {} } +EQMP
savevm.c +13 -0
@@ -1440,6 +1440,19 @@ VMStateLogStateInfo *qmp_query_test_vmstates(Error **errp)return log_info; } +void qmp_test_vmstates_set_period (int64_t period,Error **errp) +{ +VMStateLogState *v =test_vmstates_get_current_state (); +if (period <TEST_VMSTATE_MIN_INTERVAL_MS || + period >TEST_VMSTATE_MAX_INTERVAL_MS ) { +error_setg (errp,"sleep interval (period) value must be " +"in the defined range [%d, %d](ms)\n" , +TEST_VMSTATE_MIN_INTERVAL_MS ,TEST_VMSTATE_MAX_INTERVAL_MS ); +return ; + } + v->period = period; +} +/* * ---------------------------------------------------------------------------- */
Signature · 1 line
1.9.3
RFC PATCH v3 6/6 VMState test: cancel mechanism for an already running vmstate testing process
In reply to Sanidhya Kashyap--- hmp-commands.hx | 14 ++++++++++++++ hmp.c | 6 ++++++ hmp.h | 1 + qapi-schema.json | 9 +++++++++ qmp-commands.hx | 20 ++++++++++++++++++++ savevm.c | 16 ++++++++++++++-- 6 files changed, 64 insertions(+), 2 deletions(-)
hmp-commands.hx +14 -0
@@ -1823,6 +1823,20 @@ STEXI Set the period to @var{period} (int) for vmstate testing process. ETEXI + { + .name = "test_vmstates_cancel", + .args_type = "", + .params = "", + .help = "cancel the current vmstates testing process", + .mhandler.cmd = hmp_test_vmstates_cancel, +}, + +STEXI +@item test_vmstates_cancel +@findex test_vmstates_cancel +Cancel the current vmstates testing process +ETEXI + STEXI @end table ETEXI
hmp.c +6 -0
@@ -1799,3 +1799,9 @@ void hmp_test_vmstates_set_period(Monitor *mon, const QDict *qdict)error_free (err); } } + +void hmp_test_vmstates_cancel (Monitor *mon,const QDict *qdict) +{ +qmp_test_vmstates_cancel (NULL ); +} +
hmp.h +1 -0
@@ -98,6 +98,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict);void hmp_info_memdev (Monitor *mon,const QDict *qdict);void hmp_test_vmstates (Monitor *mon,const QDict *qdict);void hmp_test_vmstates_set_period (Monitor *mon,const QDict *qdict); +void hmp_test_vmstates_cancel (Monitor *mon,const QDict *qdict);void object_add_completion (ReadLineState *rs,int nb_args,const char *str);void object_del_completion (ReadLineState *rs,int nb_args,const char *str);void device_add_completion (ReadLineState *rs,int nb_args,const char *str);
qapi-schema.json +9 -0
@@ -3577,3 +3577,12 @@ ## { 'command' : 'test-vmstates-set-period', 'data' : { 'period': 'int' } } + +## +# @test-vmstates-cancel +# +# cancel the testing vmstates process +# +# Since 2.2 +## +{ 'command': 'test-vmstates-cancel' }
qmp-commands.hx +20 -0
@@ -3880,3 +3880,23 @@ Example: -> { "execute": "test-vmstates-set-period", "arguments": { "period": 1024 } } <- { "return": {} } EQMP + + { + .name = "test-vmstates-cancel", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_test_vmstates_cancel, + }, + +SQMP +test-vmstates-cancel +-------------------- + +Cancel the current vmstate testing process. + +Arguments: None. + +Example: + +-> { "execute": "test-vmstates-cancel" } +<- { "return": {} } +EQMP
savevm.c +14 -2
@@ -1340,8 +1340,12 @@ static void test_vmstates_cb(void *opaque)if (saved_vm_running) {vm_start (); } -timer_mod (v->timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) + - v->period); +if (v->active_state) { +timer_mod (v->timer, v->period + +qemu_clock_get_ms (QEMU_CLOCK_REALTIME )); + }else { + goto testing_end; + }return ; }
@@ -1453,6 +1457,14 @@ void qmp_test_vmstates_set_period(int64_t period, Error **errp) v->period = period; } +void qmp_test_vmstates_cancel (Error **errp) +{ +VMStateLogState *v =test_vmstates_get_current_state (); +if (v->active_state) { + v->active_state = false; + } +} +/* * ---------------------------------------------------------------------------- */
Signature · 1 line
1.9.3