Add basic "detach" support for dump-guest-memory
v2 cover Add basic "detach" support for dump-guest-memory
Sorry that this v2 series cannot be aligned with the v1 series. One patch is added at the begining of the series to do some code cleanups (also fix potential memory leak). Meanwhile, several new patches are appended to the v1 series. Please see the change log for more info.
v2 changes:
- fixed English errors [Drew]
- reordered the "detach" field, first make it optional, then make sure it's order is consistent [Drew, Fam]
- added doc for new detach flag [Eric]
- collected error msg even detached [Drew]
- added qmp event DUMP_COMPLETED to notify user [Eric, Fam]
- added "dump-query" QMP & HMP commands to query dump status [Eric]
- "stop" is not allowed when dump in background (also include "cont" and "dump-guest-memory") [Fam]
- added codes to calculate how many dump work finished, which could be queried from "dump-query" [Laszlo]
- added list to track all used MemoryRegion objects, also ref before use [Paolo]
- dump-guest-memory will be forbidden during incoming migrate [Paolo]
- taking rcu lock when collecting memory info [Paolo]
Test Done:
- QMP & HMP
- test default dump (sync), work as usual
- test detached dump, command return immediately. When dump finished, will receive event DUMP_COMPLETED with a message.
- test dump-query before/during/after dump
- test kdump with zlib compression, w/ and w/o detach
- libvirt
- test "virsh dump --memory-only" with default format and kdump-zlib format, work as usual
Peter Xu (8):
dump-guest-memory: cleanup: removing dump_{error|cleanup}().
dump-guest-memory: add "detach" flag for QMP/HMP interfaces.
dump-guest-memory: add basic "detach" support.
dump-guest-memory: add qmp event DUMP_COMPLETED
dump-query: add "dump-query" command to query dump status
dump-query: implement "status" of "dump-query" command.
DumpState: adding total_size and written_size fields
dump-query: make the percentage accurate.
docs/qmp-events.txt | 12 ++ dump.c | 284 ++++++++++++++++++++++++++++++++-------- hmp-commands.hx | 20 ++- hmp.c | 18 ++- hmp.h | 1 + include/qemu-common.h | 8 ++ include/sysemu/dump.h | 28 ++++ include/sysemu/memory_mapping.h | 8 ++ memory_mapping.c | 46 ++++++- qapi-schema.json | 29 +++- qapi/event.json | 10 ++ qmp-commands.hx | 35 ++++- qmp.c | 14 ++ 13 files changed, 450 insertions(+), 63 deletions(-)
Signature · 1 line
2.4.3
PATCH v2 1/8 dump-guest-memory: cleanup: removing dump_{error|cleanup}().
It might be a little bit confusing to do dump_cleanup() in these two functions (and error prone, please see section below). A better way is to do dump_cleanup() before dump finish, no matter whether dump has succeeded or not.
Meanwhile, this patch will also fix the potential memory leaks that might happen when dump got errors within the process (e.g., when write_dump_header() fails, it will skip calling dump_cleanup(), which will leads to memory leak for list elements in DumpState).
--- dump.c | 78 +++++++++++++++++++++++++++--------------------------------------- 1 file changed, 32 insertions(+), 46 deletions(-)
dump.c +32 -46
@@ -82,12 +82,6 @@ static int dump_cleanup(DumpState *s)return 0 ; } -static void dump_error (DumpState *s,const char *reason,Error **errp) -{ -dump_cleanup (s); -error_setg (errp,"%s" , reason); -} -static int fd_write_vmcore (const void *buf,size_t size,void *opaque) {DumpState *s = opaque;
@@ -128,7 +122,7 @@ static void write_elf64_header(DumpState *s, Error **errp) ret =fd_write_vmcore (&elf_header,sizeof (elf_header), s);if (ret <0 ) { -dump_error (s,"dump: failed to write elf header" , errp); +error_setg (errp,"dump: failed to write elf header" ); } }
@@ -159,7 +153,7 @@ static void write_elf32_header(DumpState *s, Error **errp) ret =fd_write_vmcore (&elf_header,sizeof (elf_header), s);if (ret <0 ) { -dump_error (s,"dump: failed to write elf header" , errp); +error_setg (errp,"dump: failed to write elf header" ); } }
@@ -182,7 +176,7 @@ static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping, ret =fd_write_vmcore (&phdr,sizeof (Elf64_Phdr), s);if (ret <0 ) { -dump_error (s,"dump: failed to write program header table" , errp); +error_setg (errp,"dump: failed to write program header table" ); } }
@@ -205,7 +199,7 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping, ret =fd_write_vmcore (&phdr,sizeof (Elf32_Phdr), s);if (ret <0 ) { -dump_error (s,"dump: failed to write program header table" , errp); +error_setg (errp,"dump: failed to write program header table" ); } }
@@ -225,7 +219,7 @@ static void write_elf64_note(DumpState *s, Error **errp) ret =fd_write_vmcore (&phdr,sizeof (Elf64_Phdr), s);if (ret <0 ) { -dump_error (s,"dump: failed to write program header table" , errp); +error_setg (errp,"dump: failed to write program header table" ); } }
@@ -245,7 +239,7 @@ static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s, id =cpu_index (cpu); ret =cpu_write_elf64_note (f, cpu, id, s);if (ret <0 ) { -dump_error (s,"dump: failed to write elf notes" , errp); +error_setg (errp,"dump: failed to write elf notes" );return ; } }
@@ -253,7 +247,7 @@ static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,CPU_FOREACH (cpu) { ret =cpu_write_elf64_qemunote (f, cpu, s);if (ret <0 ) { -dump_error (s,"dump: failed to write CPU status" , errp); +error_setg (errp,"dump: failed to write CPU status" );return ; } }
@@ -275,7 +269,7 @@ static void write_elf32_note(DumpState *s, Error **errp) ret =fd_write_vmcore (&phdr,sizeof (Elf32_Phdr), s);if (ret <0 ) { -dump_error (s,"dump: failed to write program header table" , errp); +error_setg (errp,"dump: failed to write program header table" ); } }
@@ -290,7 +284,7 @@ static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s, id =cpu_index (cpu); ret =cpu_write_elf32_note (f, cpu, id, s);if (ret <0 ) { -dump_error (s,"dump: failed to write elf notes" , errp); +error_setg (errp,"dump: failed to write elf notes" );return ; } }
@@ -298,7 +292,7 @@ static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,CPU_FOREACH (cpu) { ret =cpu_write_elf32_qemunote (f, cpu, s);if (ret <0 ) { -dump_error (s,"dump: failed to write CPU status" , errp); +error_setg (errp,"dump: failed to write CPU status" );return ; } }
@@ -326,7 +320,7 @@ static void write_elf_section(DumpState *s, int type, Error **errp) ret =fd_write_vmcore (&shdr, shdr_size, s);if (ret <0 ) { -dump_error (s,"dump: failed to write section header table" , errp); +error_setg (errp,"dump: failed to write section header table" ); } }
@@ -336,7 +330,7 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp) ret =fd_write_vmcore (buf, length, s);if (ret <0 ) { -dump_error (s,"dump: failed to save memory" , errp); +error_setg (errp,"dump: failed to save memory" ); } }
@@ -568,11 +562,6 @@ static void dump_begin(DumpState *s, Error **errp) } } -static void dump_completed (DumpState *s) -{ -dump_cleanup (s); -} -static int get_next_block (DumpState *s,GuestPhysBlock *block) {while (1 ) {
@@ -624,8 +613,6 @@ static void dump_iterate(DumpState *s, Error **errp) } }while (!get_next_block (s, block)); - -dump_completed (s); }static void create_vmcore (DumpState *s,Error **errp)
@@ -765,7 +752,7 @@ static void create_header32(DumpState *s, Error **errp) dh->status =cpu_to_dump32 (s, status);if (write_buffer (s->fd,0 , dh, size) <0 ) { -dump_error (s,"dump: failed to write disk dump header" , errp); +error_setg (errp,"dump: failed to write disk dump header" ); goto out; }
@@ -784,7 +771,7 @@ static void create_header32(DumpState *s, Error **errp)if (write_buffer (s->fd,DISKDUMP_HEADER_BLOCKS * block_size, kh, size) <0 ) { -dump_error (s,"dump: failed to write kdump sub header" , errp); +error_setg (errp,"dump: failed to write kdump sub header" ); goto out; }
@@ -800,7 +787,7 @@ static void create_header32(DumpState *s, Error **errp) }if (write_buffer (s->fd, offset_note, s->note_buf, s->note_size) <0 ) { -dump_error (s,"dump: failed to write notes" , errp); +error_setg (errp,"dump: failed to write notes" ); goto out; }
@@ -865,7 +852,7 @@ static void create_header64(DumpState *s, Error **errp) dh->status =cpu_to_dump32 (s, status);if (write_buffer (s->fd,0 , dh, size) <0 ) { -dump_error (s,"dump: failed to write disk dump header" , errp); +error_setg (errp,"dump: failed to write disk dump header" ); goto out; }
@@ -884,7 +871,7 @@ static void create_header64(DumpState *s, Error **errp)if (write_buffer (s->fd,DISKDUMP_HEADER_BLOCKS * block_size, kh, size) <0 ) { -dump_error (s,"dump: failed to write kdump sub header" , errp); +error_setg (errp,"dump: failed to write kdump sub header" ); goto out; }
@@ -901,7 +888,7 @@ static void create_header64(DumpState *s, Error **errp)if (write_buffer (s->fd, offset_note, s->note_buf, s->note_size) <0 ) { -dump_error (s,"dump: failed to write notes" , errp); +error_setg (errp,"dump: failed to write notes" ); goto out; }
@@ -1064,7 +1051,7 @@ static void write_dump_bitmap(DumpState *s, Error **errp)while (get_next_page (&block_iter, &pfn,NULL , s)) { ret =set_dump_bitmap (last_pfn, pfn, true, dump_bitmap_buf, s);if (ret <0 ) { -dump_error (s,"dump: failed to set dump_bitmap" , errp); +error_setg (errp,"dump: failed to set dump_bitmap" ); goto out; }
@@ -1081,7 +1068,7 @@ static void write_dump_bitmap(DumpState *s, Error **errp) ret =set_dump_bitmap (last_pfn, last_pfn +PFN_BUFBITMAP , false, dump_bitmap_buf, s);if (ret <0 ) { -dump_error (s,"dump: failed to sync dump_bitmap" , errp); +error_setg (errp,"dump: failed to sync dump_bitmap" ); goto out; } }
@@ -1214,7 +1201,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf,TARGET_PAGE_SIZE , false);g_free (buf);if (ret <0 ) { -dump_error (s,"dump: failed to write page data (zero page)" , errp); +error_setg (errp,"dump: failed to write page data (zero page)" ); goto out; }
@@ -1230,7 +1217,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_desc, &pd_zero,sizeof (PageDescriptor), false);if (ret <0 ) { -dump_error (s,"dump: failed to write page desc" , errp); +error_setg (errp,"dump: failed to write page desc" ); goto out; } }else {
@@ -1255,7 +1242,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf_out, size_out, false);if (ret <0 ) { -dump_error (s,"dump: failed to write page data" , errp); +error_setg (errp,"dump: failed to write page data" ); goto out; }#ifdef CONFIG_LZO
@@ -1268,7 +1255,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf_out, size_out, false);if (ret <0 ) { -dump_error (s,"dump: failed to write page data" , errp); +error_setg (errp,"dump: failed to write page data" ); goto out; }#endif
@@ -1282,7 +1269,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf_out, size_out, false);if (ret <0 ) { -dump_error (s,"dump: failed to write page data" , errp); +error_setg (errp,"dump: failed to write page data" ); goto out; }#endif
@@ -1297,7 +1284,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf,TARGET_PAGE_SIZE , false);if (ret <0 ) { -dump_error (s,"dump: failed to write page data" , errp); +error_setg (errp,"dump: failed to write page data" ); goto out; } }
@@ -1309,7 +1296,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_desc, &pd,sizeof (PageDescriptor), false);if (ret <0 ) { -dump_error (s,"dump: failed to write page desc" , errp); +error_setg (errp,"dump: failed to write page desc" ); goto out; } }
@@ -1317,12 +1304,12 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_desc,NULL ,0 , true);if (ret <0 ) { -dump_error (s,"dump: failed to sync cache for page_desc" , errp); +error_setg (errp,"dump: failed to sync cache for page_desc" ); goto out; } ret =write_cache (&page_data,NULL ,0 , true);if (ret <0 ) { -dump_error (s,"dump: failed to sync cache for page_data" , errp); +error_setg (errp,"dump: failed to sync cache for page_data" ); goto out; }
@@ -1366,7 +1353,7 @@ static void create_kdump_vmcore(DumpState *s, Error **errp) ret =write_start_flat_header (s->fd);if (ret <0 ) { -dump_error (s,"dump: failed to write start flat header" , errp); +error_setg (errp,"dump: failed to write start flat header" );return ; }
@@ -1390,11 +1377,9 @@ static void create_kdump_vmcore(DumpState *s, Error **errp) ret =write_end_flat_header (s->fd);if (ret <0 ) { -dump_error (s,"dump: failed to write end flat header" , errp); +error_setg (errp,"dump: failed to write end flat header" );return ; } - -dump_completed (s); }static ram_addr_t get_start_block (DumpState *s)
@@ -1677,6 +1662,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,create_vmcore (s, errp); } +dump_cleanup (s);g_free (s); }
Signature · 1 line
2.4.3
PATCH v2 2/8 dump-guest-memory: add "detach" flag for QMP/HMP interfaces.
In reply to Peter XuThis patch only adds the interfaces, but not implements them. "detach" parameter is made optional, to make sure that all the old dump-guest-memory requests will still be able to work.
--- dump.c | 5 +++-- hmp-commands.hx | 5 +++-- hmp.c | 9 +++++++-- qapi-schema.json | 8 ++++++-- qmp-commands.hx | 6 ++++-- 5 files changed, 23 insertions(+), 10 deletions(-)
dump.c +3 -2
@@ -1580,8 +1580,9 @@ cleanup:dump_cleanup (s); } -void qmp_dump_guest_memory (bool paging,const char *file,bool has_begin, -int64_t begin,bool has_length, +void qmp_dump_guest_memory (bool paging,const char *file, +bool has_detach,bool detach, +bool has_begin,int64_t begin,bool has_length,int64_t length,bool has_format,DumpGuestMemoryFormat format,Error **errp) {
hmp-commands.hx +3 -2
@@ -1056,10 +1056,11 @@ ETEXI { .name = "dump-guest-memory", - .args_type = "paging:-p,zlib:-z,lzo:-l,snappy:-s,filename:F,begin:i?,length:i?", - .params = "[-p] [-z|-l|-s] filename [begin length]", + .args_type = "paging:-p,detach:-d,zlib:-z,lzo:-l,snappy:-s,filename:F,begin:i?,length:i?", + .params = "[-p] [-d] [-z|-l|-s] filename [begin length]", .help = "dump guest memory into file 'filename'.\n\t\t\t" "-p: do paging to get guest's memory mapping.\n\t\t\t" + "-d: return immediately (do not wait for completion).\n\t\t\t" "-z: dump in kdump-compressed format, with zlib compression.\n\t\t\t" "-l: dump in kdump-compressed format, with lzo compression.\n\t\t\t" "-s: dump in kdump-compressed format, with snappy compression.\n\t\t\t"
hmp.c +7 -2
@@ -1586,8 +1586,10 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)const char *file =qdict_get_str (qdict,"filename" );bool has_begin =qdict_haskey (qdict,"begin" );bool has_length =qdict_haskey (qdict,"length" ); +bool has_detach =qdict_haskey (qdict,"detach" );int64_t begin =0 ;int64_t length =0 ; +bool detach = false;enum DumpGuestMemoryFormat dump_format =DUMP_GUEST_MEMORY_FORMAT_ELF ;char *prot;
@@ -1615,11 +1617,14 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)if (has_length) { length =qdict_get_int (qdict,"length" ); } +if (has_detach) { + detach =qdict_get_try_bool (qdict,"detach" , false); + } prot =g_strconcat ("file:" , file,NULL ); -qmp_dump_guest_memory (paging, prot, has_begin, begin, has_length, length, - true, dump_format, &err); +qmp_dump_guest_memory (paging, prot, has_detach, detach, has_begin, begin, + has_length, length, true, dump_format, &err);hmp_handle_error (mon, &err);g_free (prot); }
qapi-schema.json +6 -2
@@ -2115,6 +2115,9 @@ # 2. fd: the protocol starts with "fd:", and the following string # is the fd's name. # +# @detach: #optional if true, QMP will return immediately rather than +# waiting dump to be finished (since 2.6). +# # @begin: #optional if specified, the starting physical address. # # @length: #optional if specified, the memory size, in bytes. If you don't
@@ -2131,8 +2134,9 @@ # Since: 1.2 ## { 'command': 'dump-guest-memory', - 'data': { 'paging': 'bool', 'protocol': 'str', '*begin': 'int', - '*length': 'int', '*format': 'DumpGuestMemoryFormat' } } + 'data': { 'paging': 'bool', 'protocol': 'str', '*detach': 'bool', + '*begin': 'int', '*length': 'int', + '*format': 'DumpGuestMemoryFormat'} } ## # @DumpGuestMemoryCapability:
qmp-commands.hx +4 -2
@@ -840,8 +840,8 @@ EQMP { .name = "dump-guest-memory", - .args_type = "paging:b,protocol:s,begin:i?,end:i?,format:s?", - .params = "-p protocol [begin] [length] [format]", + .args_type = "paging:b,protocol:s,detach:b?,begin:i?,end:i?,format:s?", + .params = "-p protocol [-d] [begin] [length] [format]", .help = "dump guest memory to file", .mhandler.cmd_new = qmp_marshal_dump_guest_memory, },
@@ -857,6 +857,8 @@ Arguments: - "paging": do paging to get guest's memory mapping (json-bool) - "protocol": destination file(started with "file:") or destination file descriptor (started with "fd:") (json-string) +- "detach": if specificed, command will return immediately, without waiting + for dump to be finished (json-bool) - "begin": the starting physical address. It's optional, and should be specified with length together (json-int) - "length": the memory size, in bytes. It's optional, and should be specified
Signature · 1 line
2.4.3
PATCH v2 3/8 dump-guest-memory: add basic "detach" support.
In reply to Peter XuThis patch implements "detach" for "dump-guest-memory" command. When specified, one background thread is created to do the dump work.
When there is a dump running in background, the commands "stop", "cont" and "dump-guest-memory" will fail directly, with a hint telling user: "there is a dump in progress".
Although it is not quite essential for now, the new codes are trying to make sure the dump is thread safe. To do this, one list is added into GuestPhysBlockList to track all the referenced MemoryRegions during dump process. We should make sure each MemoryRegion would only be referenced for once.
One global struct "GlobalDumpState" is added to store some global informations for dump procedures. One mutex is used to protect the global dump info.
--- dump.c | 114 +++++++++++++++++++++++++++++++++++++--- include/qemu-common.h | 4 ++ include/sysemu/dump.h | 10 ++++ include/sysemu/memory_mapping.h | 8 +++ memory_mapping.c | 46 +++++++++++++++- qmp.c | 14 +++++ 6 files changed, 188 insertions(+), 8 deletions(-)
dump.c +107 -7
@@ -73,6 +73,7 @@ uint64_t cpu_to_dump64(DumpState *s, uint64_t val)static int dump_cleanup (DumpState *s) {guest_phys_blocks_free (&s->guest_phys_blocks); +guest_memory_region_free (&s->guest_phys_blocks);memory_mapping_list_free (&s->list);close (s->fd);if (s->resume) {
@@ -1427,6 +1428,9 @@ static void dump_init(DumpState *s, int fd, bool has_format,Error *err =NULL ;int ret; + s->has_format = has_format; + s->format = format; +/* kdump-compressed is conflict with paging and filter */ if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) {assert (!paging && !has_filter);
@@ -1580,6 +1584,86 @@ cleanup:dump_cleanup (s); } +extern GlobalDumpState global_dump_state; + +static GlobalDumpState *dump_state_get_global (void ) +{ +static bool init = false; +static GlobalDumpState global_dump_state; +if (unlikely (!init)) { +qemu_mutex_init (&global_dump_state.gds_mutex); + global_dump_state.gds_cur =NULL ; + init = true; + } +return &global_dump_state; +} + +/* Returns non-zero if there is existing dump in progress, otherwise +* zero is returned. */ +bool dump_in_progress (void ) +{ +GlobalDumpState *global =dump_state_get_global (); +/* we do not need to take the mutex here if we are checking the +* pointer only. */ +return (!!global->gds_cur); +} + +/* Trying to create one DumpState. This will fail if there is an +* existing one. Return DumpState pointer if succeeded, otherwise +* NULL is returned. */ +static DumpState *dump_state_create (GlobalDumpState *global) +{ +DumpState *cur =NULL ; +qemu_mutex_lock (&global->gds_mutex); + + cur = global->gds_cur; +if (cur) { +/* one dump in progress */ + cur =NULL ; + }else { +/* we are the first! */ + cur =g_malloc0 (sizeof (*cur)); + global->gds_cur = cur; + } + +qemu_mutex_unlock (&global->gds_mutex); +return cur; +} + +/* release current DumpState structure */ +static void dump_state_release (GlobalDumpState *global) +{ +DumpState *cur =NULL ; +qemu_mutex_lock (&global->gds_mutex); + + cur = global->gds_cur; +/* we should never call release before having one */ +assert (cur); + global->gds_cur =NULL ; + +qemu_mutex_unlock (&global->gds_mutex); +dump_cleanup (cur); +g_free (cur); +} + +/* this operation might be time consuming. */ +static void dump_process (DumpState *s,Error **errp) +{ +if (s->has_format && s->format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { +create_kdump_vmcore (s, errp); + }else { +create_vmcore (s, errp); + } +} + +static void *dump_thread (void *data) +{ +GlobalDumpState *global = (GlobalDumpState *)data; +dump_process (global->gds_cur,NULL ); +dump_state_release (global); +return NULL ; +} + void qmp_dump_guest_memory(bool paging, const char *file, bool has_detach, bool detach, bool has_begin, int64_t begin, bool has_length,
@@ -1590,6 +1674,14 @@ void qmp_dump_guest_memory(bool paging, const char *file,int fd =-1 ;DumpState *s;Error *local_err =NULL ; +/* by default, we are keeping the old style, which is sync dump */ +bool detach_p = false; +GlobalDumpState *global =dump_state_get_global (); + +if (runstate_check (RUN_STATE_INMIGRATE )) { +error_setg (errp,"Dump not allowed during incoming migration." ); +return ; + }/* * kdump-compressed format need the whole memory dumped, so paging or
@@ -1609,6 +1701,9 @@ void qmp_dump_guest_memory(bool paging, const char *file,error_setg (errp,QERR_MISSING_PARAMETER ,"begin" );return ; } +if (has_detach) { + detach_p = detach; + }/* check whether lzo/snappy is supported */ #ifndef CONFIG_LZO
@@ -1647,7 +1742,11 @@ void qmp_dump_guest_memory(bool paging, const char *file,return ; } - s =g_malloc0 (sizeof (DumpState)); + s =dump_state_create (global); +if (!s) { +error_setg (errp,"One dump is in progress." ); +return ; + }dump_init (s, fd, has_format, format, paging, has_begin, begin, length, &local_err);
@@ -1657,14 +1756,15 @@ void qmp_dump_guest_memory(bool paging, const char *file,return ; } -if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { -create_kdump_vmcore (s, errp); +if (!detach_p) { +/* sync dump */ +dump_process (s, errp); +dump_state_release (global); }else { -create_vmcore (s, errp); +qemu_thread_create (&s->dump_thread,"dump_thread" , dump_thread, + global,QEMU_THREAD_DETACHED ); +/* DumpState is freed in dump thread */ } - -dump_cleanup (s); -g_free (s); }DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp)
include/qemu-common.h +4 -0
@@ -501,4 +501,8 @@ int parse_debug_env(const char *name, int max, int initial);const char *qemu_ether_ntoa (const MACAddr *mac);void page_size_init (void ); +/* returns non-zero if dump is in progress, otherwise zero is +* returned. */ +bool dump_in_progress (void ); +#endif
include/sysemu/dump.h +10 -0
@@ -183,9 +183,19 @@ typedef struct DumpState {off_t offset_page;/* offset of page part in vmcore */ size_t num_dumpable;/* number of page that can be dumped */ uint32_t flag_compress;/* indicate the compression format */ + +QemuThread dump_thread;/* only used when do async dump */ +bool has_format;/* whether format is provided */ + DumpGuestMemoryFormat format; /* valid only if has_format == true */ } DumpState; +typedef struct GlobalDumpState { +QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ +DumpState *gds_cur;/* current DumpState (might be NULL) */ +}GlobalDumpState ; +uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);uint32_t cpu_to_dump32 (DumpState *s,uint32_t val);uint64_t cpu_to_dump64 (DumpState *s,uint64_t val); +#endif
include/sysemu/memory_mapping.h +8 -0
@@ -30,10 +30,17 @@ typedef struct GuestPhysBlock {QTAILQ_ENTRY (GuestPhysBlock) next; } GuestPhysBlock; +typedef struct GuestMemoryRegion { +MemoryRegion *gmr_mr; +QTAILQ_ENTRY (GuestMemoryRegion) next; +}GuestMemoryRegion ; +/* point-in-time snapshot of guest-visible physical mappings */ typedef struct GuestPhysBlockList {unsigned num; QTAILQ_HEAD(GuestPhysBlockHead, GuestPhysBlock) head; +/* housekeep all the MemoryRegion that is referenced */ + QTAILQ_HEAD(GuestMemRegionHead, GuestMemoryRegion) head_mr; }GuestPhysBlockList ;/* The physical and virtual address in the memory mapping are contiguous. */
@@ -65,6 +72,7 @@ void memory_mapping_list_free(MemoryMappingList *list);void memory_mapping_list_init (MemoryMappingList *list);void guest_phys_blocks_free (GuestPhysBlockList *list); +void guest_memory_region_free (GuestPhysBlockList *list);void guest_phys_blocks_init (GuestPhysBlockList *list);void guest_phys_blocks_append (GuestPhysBlockList *list);
memory_mapping.c +45 -1
78 lines not on this page · raw message
qmp.c +14 -0
@@ -102,6 +102,13 @@ void qmp_quit(Error **errp)void qmp_stop (Error **errp) { +/* if there is a dump in background, we should wait until the dump +* finished */ +if (dump_in_progress ()) { +error_setg (errp,"There is a dump in process, please wait." ); +return ; + } +if (runstate_check (RUN_STATE_INMIGRATE )) { autostart =0 ; }else {
@@ -174,6 +181,13 @@ void qmp_cont(Error **errp)BlockBackend *blk;BlockDriverState *bs; +/* if there is a dump in background, we should wait until the dump +* finished */ +if (dump_in_progress ()) { +error_setg (errp,"There is a dump in process, please wait." ); +return ; + } +if (runstate_needs_reset ()) {error_setg (errp,"Resetting the Virtual Machine is required" );return ;
Signature · 1 line
2.4.3
PATCH v2 4/8 dump-guest-memory: add qmp event DUMP_COMPLETED
In reply to Peter XuTo get aligned with QMP interface, one new QMP event DUMP_COMPLETED is added. It is used when user specified "detach" in dump, and triggered when the dump finishes. Error message will be appended to this event if the dump has failed.
--- docs/qmp-events.txt | 12 ++++++++++++ dump.c | 12 +++++++++++- qapi/event.json | 10 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)
docs/qmp-events.txt +12 -0
@@ -674,3 +674,15 @@ Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is followed respectively by the RESET, SHUTDOWN, or STOP events. Note: this event is rate-limited. + +DUMP_COMPLETED +-------------- + +Emitted when the guest has finished one memory dump. + +Data: None. + +Example: + +{ "event": "DUMP_COMPLETED", + "data": { "msg": "Dump completed successfully" } }
dump.c +11 -1
@@ -25,6 +25,7 @@#include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "qmp-commands.h" +#include "qapi-event.h" #include <zlib.h> #ifdef CONFIG_LZO
@@ -1659,8 +1660,17 @@ static void dump_process(DumpState *s, Error **errp)static void *dump_thread (void *data) {GlobalDumpState *global = (GlobalDumpState *)data; -dump_process (global->gds_cur,NULL ); +Error *local_err =NULL ; +const char *msg ="Dump completed successfully" ; + +dump_process (global->gds_cur, &local_err);dump_state_release (global); + +/* if detach is used, notify user that dump has finished */ +if (local_err) { + msg =error_get_pretty (local_err); + } +qapi_event_send_dump_completed (msg, &error_abort);return NULL ; }
qapi/event.json +10 -0
@@ -356,3 +356,13 @@ ## { 'event': 'MEM_UNPLUG_ERROR', 'data': { 'device': 'str', 'msg': 'str' } } + +## +# @DUMP_COMPLETED +# +# Emitted when background dump has completed +# +# Since: 2.6 +## +{ 'event': 'DUMP_COMPLETED' , + 'data': { 'msg': 'str' } }
Signature · 1 line
2.4.3
PATCH v2 5/8 dump-query: add "dump-query" command to query dump status
In reply to Peter XuThis patch is only adding the QMP/HMP interface for "dump-query" command, but not implementing them. This command could be used to query background dump status. Please refer to the next patch to see how dump status are defined.
Currently, only fake results are returned.
--- dump.c | 9 +++++++++ hmp-commands.hx | 15 +++++++++++++++ hmp.c | 6 ++++++ hmp.h | 1 + qapi-schema.json | 21 +++++++++++++++++++++ qmp-commands.hx | 29 ++++++++++++++++++++++++++++- 6 files changed, 80 insertions(+), 1 deletion(-)
dump.c +9 -0
@@ -1777,6 +1777,15 @@ void qmp_dump_guest_memory(bool paging, const char *file, } } +DumpStatus *qmp_dump_query (Error **errp) +{ +DumpStatus *status =g_malloc0 (sizeof (*status)); +/* TBD */ + status->status =g_strdup ("WORKING" ); + status->percentage =g_strdup ("50%" ); +return status; +} +DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp) {DumpGuestMemoryFormatList *item;
hmp-commands.hx +15 -0
@@ -1087,6 +1087,21 @@ gdb. Without -z|-l|-s, the dump format is ELF. together with begin. ETEXI + { + .name = "dump-query", + .args_type = "", + .params = "", + .help = "query last guest memory dump status.\n\t\t\t", + .mhandler.cmd = hmp_dump_query, + }, + + +STEXI +@item dump-query +@findex dump-query +Query latest dump status. +ETEXI + #if defined(TARGET_S390X) { .name = "dump-skeys",
hmp.c +6 -0
@@ -1576,6 +1576,12 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &err); } +void hmp_dump_query (Monitor *mon,const QDict *qdict) +{ +/* TBD */ +monitor_printf (mon,"QUERY DUMP STATUS\n" ); +} +void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict) {Error *err =NULL ;
hmp.h +1 -0
@@ -85,6 +85,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict);void hmp_device_add (Monitor *mon,const QDict *qdict);void hmp_device_del (Monitor *mon,const QDict *qdict);void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict); +void hmp_dump_query (Monitor *mon,const QDict *qdict);void hmp_netdev_add (Monitor *mon,const QDict *qdict);void hmp_netdev_del (Monitor *mon,const QDict *qdict);void hmp_getfd (Monitor *mon,const QDict *qdict);
qapi-schema.json +21 -0
@@ -2139,6 +2139,27 @@ '*format': 'DumpGuestMemoryFormat'} } ## +# @DumpStatus +# +# Status for the last guest memory dump. +# +# Since: 2.6 +## +{ 'struct': 'DumpStatus', + 'data': { 'status': 'str', 'percentage': 'str' } } + +## +# @dump-query +# +# Query latest dump status. +# +# Returns: A @DumpStatus object showing the dump status. +# +# Since: 2.6 +## +{ 'command': 'dump-query', 'returns': 'DumpStatus' } + +## # @DumpGuestMemoryCapability: # # A list of the available formats for dump-guest-memory
qmp-commands.hx +28 -1
@@ -879,9 +879,36 @@ Notes: EQMP { + .name = "dump-query", + .args_type = "", + .params = "", + .help = "query background dump status", + .mhandler.cmd_new = qmp_marshal_dump_query, + }, + +SQMP +dump-query +---------- + +Query background dump status. + +Arguments: None. + +Example: + +-> { "execute": "dump-query" } +<- { "return": {"status": "IN_PROGRESS", "percentage": "85%" } } + +Notes: + +(1) All boolean arguments default to false + +EQMP + + { .name = "query-dump-guest-memory-capability", .args_type = "", - .mhandler.cmd_new = qmp_marshal_query_dump_guest_memory_capability, + .mhandler.cmd_new = qmp_marshal_query_dump_guest_memory_capability, }, SQMP
Signature · 1 line
2.4.3
PATCH v2 6/8 dump-query: implement "status" of "dump-query" command.
In reply to Peter XuThis patch implements the status changes inside dump process. When query dump status, three possible results could be:
1. never started dump:
{ "status": "NOT_STARTED", "percentage": "N/A" }
2. one dump is running in background:
{ "status": "IN_PROGRESS", "percentage": "{0..100}%" }
3. no dump is running, and the last dump has finished:
{ "status": "SUCCEEDED|FAILED", "percentage": "N/A" }
It's mostly done. Except that we might need more accurate "percentage" results (which is now 50% all the time!).
--- dump.c | 57 +++++++++++++++++++++++++++++++++++++++++++-------- hmp.c | 7 +++++-- include/qemu-common.h | 4 ++++ include/sysemu/dump.h | 13 ++++++++++-- 4 files changed, 68 insertions(+), 13 deletions(-)
dump.c +48 -9
@@ -1594,11 +1594,44 @@ static GlobalDumpState *dump_state_get_global(void)if (unlikely (!init)) {qemu_mutex_init (&global_dump_state.gds_mutex); global_dump_state.gds_cur =NULL ; + global_dump_state.gds_result =DUMP_RES_NOT_STARTED ; init = true; }return &global_dump_state; } +static const char *const dump_result_table[] = { + [DUMP_RES_NOT_STARTED ] ="NOT_STARTED" , + [DUMP_RES_IN_PROGRESS ] ="IN_PROGRESS" , + [DUMP_RES_SUCCEEDED ] ="SUCCEEDED" , + [DUMP_RES_FAILED ] ="FAILED" , +}; + +/* Returns DumpStatus. Caller should be responsible to free the +* resources using qapi_free_DumpStatus(). */ +DumpStatus *dump_status_query (void ) +{ +DumpStatus *status =g_malloc0 (sizeof (*status)); +int percentage =50 ; +char buf[64 ] = {0 }; + +GlobalDumpState *global =dump_state_get_global (); +qemu_mutex_lock (&global->gds_mutex); + +/* TBD: get correct percentage */ + status->status =g_strdup (dump_result_table[global->gds_result]); +if (global->gds_result ==DUMP_RES_IN_PROGRESS ) { +snprintf (buf,sizeof (buf) -1 ,"%d%%" , percentage); + status->percentage =g_strdup (buf); + }else { + status->percentage =g_strdup ("N/A" ); + } + +qemu_mutex_unlock (&global->gds_mutex); + +return status; +} +/* Returns non-zero if there is existing dump in progress, otherwise * zero is returned. */ bool dump_in_progress (void )
@@ -1620,27 +1653,37 @@ static DumpState *dump_state_create(GlobalDumpState *global) cur = global->gds_cur;if (cur) {/* one dump in progress */ +assert (global->gds_result ==DUMP_RES_IN_PROGRESS ); cur =NULL ; }else {/* we are the first! */ +assert (global->gds_result !=DUMP_RES_IN_PROGRESS ); cur =g_malloc0 (sizeof (*cur)); global->gds_cur = cur; } + global->gds_result =DUMP_RES_IN_PROGRESS ;qemu_mutex_unlock (&global->gds_mutex);return cur; } -/* release current DumpState structure */ -static void dump_state_release (GlobalDumpState *global) +/* release current DumpState structure. "done" is hint to show +* whether the dump is succeeded or not. */ +static void dump_state_release (GlobalDumpState *global,bool done) {DumpState *cur =NULL ;qemu_mutex_lock (&global->gds_mutex); +assert (global->gds_result ==DUMP_RES_IN_PROGRESS ); cur = global->gds_cur;/* we should never call release before having one */ assert (cur); global->gds_cur =NULL ; +if (done) { + global->gds_result =DUMP_RES_SUCCEEDED ; + }else { + global->gds_result =DUMP_RES_FAILED ; + }qemu_mutex_unlock (&global->gds_mutex);dump_cleanup (cur);
@@ -1664,7 +1707,7 @@ static void *dump_thread(void *data)const char *msg ="Dump completed successfully" ;dump_process (global->gds_cur, &local_err); -dump_state_release (global); +dump_state_release (global, (local_err ==NULL ));/* if detach is used, notify user that dump has finished */ if (local_err) {
@@ -1769,7 +1812,7 @@ void qmp_dump_guest_memory(bool paging, const char *file,if (!detach_p) {/* sync dump */ dump_process (s, errp); -dump_state_release (global); +dump_state_release (global, (*errp ==NULL )); }else {qemu_thread_create (&s->dump_thread,"dump_thread" , dump_thread, global,QEMU_THREAD_DETACHED );
@@ -1779,11 +1822,7 @@ void qmp_dump_guest_memory(bool paging, const char *file,DumpStatus *qmp_dump_query (Error **errp) { -DumpStatus *status =g_malloc0 (sizeof (*status)); -/* TBD */ - status->status =g_strdup ("WORKING" ); - status->percentage =g_strdup ("50%" ); -return status; +return dump_status_query (); }DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp)
hmp.c +5 -2
@@ -1578,8 +1578,11 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)void hmp_dump_query (Monitor *mon,const QDict *qdict) { -/* TBD */ -monitor_printf (mon,"QUERY DUMP STATUS\n" ); +DumpStatus *status =dump_status_query (); +assert (status); +monitor_printf (mon,"STATUS: %s\n" , status->status); +monitor_printf (mon,"PERCENTAGE: %s\n" , status->percentage); +qapi_free_DumpStatus (status); }void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict)
include/qemu-common.h +4 -0
@@ -505,4 +505,8 @@ void page_size_init(void);* returned. */ bool dump_in_progress (void ); +/* Returns DumpStatus. Caller should be responsible to free the +* resources using qapi_free_DumpStatus(). */ +DumpStatus *dump_status_query (void ); +#endif
include/sysemu/dump.h +11 -2
@@ -189,9 +189,18 @@ typedef struct DumpState {DumpGuestMemoryFormat format;/* valid only if has_format == true */ } DumpState; +typedef enum DumpResult { +DUMP_RES_NOT_STARTED =0 , +DUMP_RES_IN_PROGRESS , +DUMP_RES_SUCCEEDED , +DUMP_RES_FAILED , +DUMP_RES_MAX , +}DumpResult ; +typedef struct GlobalDumpState { -QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ -DumpState *gds_cur;/* current DumpState (might be NULL) */ +QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ +DumpState *gds_cur;/* current DumpState (might be NULL) */ +DumpResult gds_result;/* current dump result */ }GlobalDumpState ;uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);
Signature · 1 line
2.4.3
PATCH v2 7/8 DumpState: adding total_size and written_size fields
In reply to Peter XuHere, total_size is the size in bytes to be dumped (raw data, which means before compression), while written_size are bytes handled (raw size too).
These two fields could be used when do "dump-query". With these information, we could get a very accurate percentage of finished work.
--- dump.c | 36 +++++++++++++++++++++++++++++++++--- include/sysemu/dump.h | 9 +++++++++ 2 files changed, 42 insertions(+), 3 deletions(-)
dump.c +33 -3
@@ -334,6 +334,8 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp)if (ret <0 ) {error_setg (errp,"dump: failed to save memory" ); } + + s->written_size += length; }/* write the memory to vmcore. 1 page per I/O. */
@@ -1302,6 +1304,7 @@ static void write_dump_pages(DumpState *s, Error **errp) goto out; } } + s->written_size +=TARGET_PAGE_SIZE ; } ret =write_cache (&page_desc,NULL ,0 , true);
@@ -1420,6 +1423,30 @@ static void get_max_mapnr(DumpState *s) s->max_mapnr =paddr_to_pfn (last_block->target_end); } +/* calculate total size of memory to be dumped (taking filter into +* acoount.) */ +static size_t dump_calculate_size (DumpState *s) +{ +GuestPhysBlock *block; +int64_t size =0 , total =0 , left =0 , right =0 ; + + QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { +if (s->has_filter) { +/* calculate the overlapped region. */ + left =MAX (s->begin, block->target_start); + right =MIN (s->begin + s->length, block->target_end); + size = right - left; + size = size >0 ? size :0 ; + }else { +/* count the whole region in */ + size = (block->target_end - block->target_start); + } + total += size; + } + +return total; +} +static void dump_init (DumpState *s,int fd,bool has_format,DumpGuestMemoryFormat format,bool paging,bool has_filter,int64_t begin,int64_t length,Error **errp)
@@ -1431,6 +1458,7 @@ static void dump_init(DumpState *s, int fd, bool has_format, s->has_format = has_format; s->format = format; + s->written_size =0 ;/* kdump-compressed is conflict with paging and filter */ if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) {
@@ -1462,6 +1490,10 @@ static void dump_init(DumpState *s, int fd, bool has_format,guest_phys_blocks_init (&s->guest_phys_blocks);guest_phys_blocks_append (&s->guest_phys_blocks); + s->total_size =dump_calculate_size (s); +#ifdef DEBUG_DUMP_GUEST_MEMORY +fprintf (stderr,"DUMP: total memory to dump: %lu\n" , s->total_size); +#endif s->start =get_start_block (s);if (s->start ==-1 ) {
@@ -1680,6 +1712,7 @@ static void dump_state_release(GlobalDumpState *global, bool done)assert (cur); global->gds_cur =NULL ;if (done) { +assert (cur->total_size == cur->written_size); global->gds_result =DUMP_RES_SUCCEEDED ; }else { global->gds_result =DUMP_RES_FAILED ;
@@ -1710,9 +1743,6 @@ static void *dump_thread(void *data)dump_state_release (global, (local_err ==NULL ));/* if detach is used, notify user that dump has finished */ -if (local_err) { - msg =error_get_pretty (local_err); - }qapi_event_send_dump_completed (msg, &error_abort);return NULL ; }
include/sysemu/dump.h +9 -0
@@ -187,6 +187,15 @@ typedef struct DumpState {QemuThread dump_thread;/* only used when do async dump */ bool has_format;/* whether format is provided */ DumpGuestMemoryFormat format;/* valid only if has_format == true */ + +size_t total_size;/* total memory size (in bytes) to +* be dumped. When filter is +* enabled, this will only count +* those to be written. */ +size_t written_size;/* written memory size (in bytes), +* this could be used to calculate +* how many work we have +* finished. */ } DumpState; typedef enum DumpResult {
Signature · 1 line
2.4.3
PATCH v2 8/8 dump-query: make the percentage accurate.
In reply to Peter XuBy calculating the total_size and written_size of memory, we could get relatively accurate percentage of finished dump.
--- dump.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
dump.c +5 -2
@@ -1643,8 +1643,9 @@ static const char *const dump_result_table[] = {* resources using qapi_free_DumpStatus(). */ DumpStatus *dump_status_query (void ) { +DumpState *state =NULL ;DumpStatus *status =g_malloc0 (sizeof (*status)); -int percentage =50 ; +float percentage =0 ;char buf[64 ] = {0 };GlobalDumpState *global =dump_state_get_global ();
@@ -1653,7 +1654,9 @@ DumpStatus *dump_status_query(void)/* TBD: get correct percentage */ status->status =g_strdup (dump_result_table[global->gds_result]);if (global->gds_result ==DUMP_RES_IN_PROGRESS ) { -snprintf (buf,sizeof (buf) -1 ,"%d%%" , percentage); + state = global->gds_cur; + percentage =100.0 * state->written_size / state->total_size; +snprintf (buf,sizeof (buf) -1 ,"%.2f%%" , percentage); status->percentage =g_strdup (buf); }else { status->percentage =g_strdup ("N/A" );
Signature · 1 line
2.4.3
Hi, all,
Sorry that I forgot to CC reviewers and maintainers when posting the patch set. :(
Please review!
Thanks.
Peter
Quoted 59 lines · Peter Xu
Sorry that this v2 series cannot be aligned with the v1 series. One patch is added at the begining of the series to do some code cleanups (also fix potential memory leak). Meanwhile, several new patches are appended to the v1 series. Please see the change log for more info.
v2 changes:
- fixed English errors [Drew]
- reordered the "detach" field, first make it optional, then make sure it's order is consistent [Drew, Fam]
- added doc for new detach flag [Eric]
- collected error msg even detached [Drew]
- added qmp eventDUMP_COMPLETEDto notify user [Eric, Fam]
- added "dump-query" QMP & HMP commands to query dump status [Eric]
- "stop" is not allowed when dump in background (also include "cont" and "dump-guest-memory") [Fam]
- added codes to calculate how many dump work finished, which could be queried from "dump-query" [Laszlo]
- added list to track all used MemoryRegion objects, also ref before use [Paolo]
- dump-guest-memory will be forbidden during incoming migrate [Paolo]
- taking rcu lock when collecting memory info [Paolo]Test Done:
- QMP & HMP
- test default dump (sync), work as usual
- test detached dump, command return immediately. When dump finished, will receive eventDUMP_COMPLETEDwith a message.
- test dump-query before/during/after dump
- test kdump with zlib compression, w/ and w/o detach
- libvirt
- test "virsh dump --memory-only" with default format and kdump-zlib format, work as usualPeter Xu (8):
dump-guest-memory: cleanup: removing dump_{error|cleanup}().
dump-guest-memory: add "detach" flag for QMP/HMP interfaces.
dump-guest-memory: add basic "detach" support.
dump-guest-memory: add qmp eventDUMP_COMPLETED
dump-query: add "dump-query" command to query dump status
dump-query: implement "status" of "dump-query" command.
DumpState: addingtotal_sizeandwritten_sizefields
dump-query: make the percentage accurate.docs/qmp-events.txt | 12 ++ dump.c | 284 ++++++++++++++++++++++++++++++++-------- hmp-commands.hx | 20 ++- hmp.c | 18 ++- hmp.h | 1 + include/qemu-common.h | 8 ++ include/sysemu/dump.h | 28 ++++ include/sysemu/memory_mapping.h | 8 ++ memory_mapping.c | 46 ++++++- qapi-schema.json | 29 +++- qapi/event.json | 10 ++ qmp-commands.hx | 35 ++++- qmp.c | 14 ++ 13 files changed, 450 insertions(+), 63 deletions(-)
Re: [Qemu-devel] [PATCH v2 1/8] dump-guest-memory: cleanup: removing dump_{error|cleanup}().
In reply to Peter XuQuoted 9 lines · Peter Xu
It might be a little bit confusing to do
dump_cleanup()in these two functions (and error prone, please see section below). A better way is to dodump_cleanup()before dump finish, no matter whether dump has succeeded or not.Meanwhile, this patch will also fix the potential memory leaks that might happen when dump got errors within the process (e.g., when
write_dump_header()fails, it will skip callingdump_cleanup(), which will leads to memory leak for list elements in DumpState).
I think when write_dump_header() returns a failure, it does call dump_cleanup(), in create_header{32,64}.
But the changes of code in this patch look sane to me, and the new error handling is definitely looking better.
Fam
Quoted 336 lines
Signed-off-by Peter Xu <[email protected]>--- dump.c | 78 +++++++++++++++++++++++++++--------------------------------------- 1 file changed, 32 insertions(+), 46 deletions(-)dump.c +32
-46@@ -82,12 +82,6 @@ static int dump_cleanup(DumpState *s)return 0 ; } -static void dump_error (DumpState *s,const char *reason,Error **errp) -{ -dump_cleanup (s); -error_setg (errp,"%s" , reason); -} -static int fd_write_vmcore (const void *buf,size_t size,void *opaque) {DumpState *s = opaque;@@ -128,7 +122,7 @@ static void write_elf64_header(DumpState *s, Error **errp) ret =fd_write_vmcore (&elf_header,sizeof (elf_header), s);if (ret <0 ) { -dump_error (s,"dump: failed to write elf header" , errp); +error_setg (errp,"dump: failed to write elf header" ); } }@@ -159,7 +153,7 @@ static void write_elf32_header(DumpState *s, Error **errp) ret =fd_write_vmcore (&elf_header,sizeof (elf_header), s);if (ret <0 ) { -dump_error (s,"dump: failed to write elf header" , errp); +error_setg (errp,"dump: failed to write elf header" ); } }@@ -182,7 +176,7 @@ static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping, ret =fd_write_vmcore (&phdr,sizeof (Elf64_Phdr), s);if (ret <0 ) { -dump_error (s,"dump: failed to write program header table" , errp); +error_setg (errp,"dump: failed to write program header table" ); } }@@ -205,7 +199,7 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping, ret =fd_write_vmcore (&phdr,sizeof (Elf32_Phdr), s);if (ret <0 ) { -dump_error (s,"dump: failed to write program header table" , errp); +error_setg (errp,"dump: failed to write program header table" ); } }@@ -225,7 +219,7 @@ static void write_elf64_note(DumpState *s, Error **errp) ret =fd_write_vmcore (&phdr,sizeof (Elf64_Phdr), s);if (ret <0 ) { -dump_error (s,"dump: failed to write program header table" , errp); +error_setg (errp,"dump: failed to write program header table" ); } }@@ -245,7 +239,7 @@ static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s, id =cpu_index (cpu); ret =cpu_write_elf64_note (f, cpu, id, s);if (ret <0 ) { -dump_error (s,"dump: failed to write elf notes" , errp); +error_setg (errp,"dump: failed to write elf notes" );return ; } }@@ -253,7 +247,7 @@ static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,CPU_FOREACH (cpu) { ret =cpu_write_elf64_qemunote (f, cpu, s);if (ret <0 ) { -dump_error (s,"dump: failed to write CPU status" , errp); +error_setg (errp,"dump: failed to write CPU status" );return ; } }@@ -275,7 +269,7 @@ static void write_elf32_note(DumpState *s, Error **errp) ret =fd_write_vmcore (&phdr,sizeof (Elf32_Phdr), s);if (ret <0 ) { -dump_error (s,"dump: failed to write program header table" , errp); +error_setg (errp,"dump: failed to write program header table" ); } }@@ -290,7 +284,7 @@ static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s, id =cpu_index (cpu); ret =cpu_write_elf32_note (f, cpu, id, s);if (ret <0 ) { -dump_error (s,"dump: failed to write elf notes" , errp); +error_setg (errp,"dump: failed to write elf notes" );return ; } }@@ -298,7 +292,7 @@ static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,CPU_FOREACH (cpu) { ret =cpu_write_elf32_qemunote (f, cpu, s);if (ret <0 ) { -dump_error (s,"dump: failed to write CPU status" , errp); +error_setg (errp,"dump: failed to write CPU status" );return ; } }@@ -326,7 +320,7 @@ static void write_elf_section(DumpState *s, int type, Error **errp) ret =fd_write_vmcore (&shdr, shdr_size, s);if (ret <0 ) { -dump_error (s,"dump: failed to write section header table" , errp); +error_setg (errp,"dump: failed to write section header table" ); } }@@ -336,7 +330,7 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp) ret =fd_write_vmcore (buf, length, s);if (ret <0 ) { -dump_error (s,"dump: failed to save memory" , errp); +error_setg (errp,"dump: failed to save memory" ); } }@@ -568,11 +562,6 @@ static void dump_begin(DumpState *s, Error **errp) } } -static void dump_completed (DumpState *s) -{ -dump_cleanup (s); -} -static int get_next_block (DumpState *s,GuestPhysBlock *block) {while (1 ) {@@ -624,8 +613,6 @@ static void dump_iterate(DumpState *s, Error **errp) } }while (!get_next_block (s, block)); - -dump_completed (s); }static void create_vmcore (DumpState *s,Error **errp)@@ -765,7 +752,7 @@ static void create_header32(DumpState *s, Error **errp) dh->status =cpu_to_dump32 (s, status);if (write_buffer (s->fd,0 , dh, size) <0 ) { -dump_error (s,"dump: failed to write disk dump header" , errp); +error_setg (errp,"dump: failed to write disk dump header" ); goto out; }@@ -784,7 +771,7 @@ static void create_header32(DumpState *s, Error **errp)if (write_buffer (s->fd,DISKDUMP_HEADER_BLOCKS * block_size, kh, size) <0 ) { -dump_error (s,"dump: failed to write kdump sub header" , errp); +error_setg (errp,"dump: failed to write kdump sub header" ); goto out; }@@ -800,7 +787,7 @@ static void create_header32(DumpState *s, Error **errp) }if (write_buffer (s->fd, offset_note, s->note_buf, s->note_size) <0 ) { -dump_error (s,"dump: failed to write notes" , errp); +error_setg (errp,"dump: failed to write notes" ); goto out; }@@ -865,7 +852,7 @@ static void create_header64(DumpState *s, Error **errp) dh->status =cpu_to_dump32 (s, status);if (write_buffer (s->fd,0 , dh, size) <0 ) { -dump_error (s,"dump: failed to write disk dump header" , errp); +error_setg (errp,"dump: failed to write disk dump header" ); goto out; }@@ -884,7 +871,7 @@ static void create_header64(DumpState *s, Error **errp)if (write_buffer (s->fd,DISKDUMP_HEADER_BLOCKS * block_size, kh, size) <0 ) { -dump_error (s,"dump: failed to write kdump sub header" , errp); +error_setg (errp,"dump: failed to write kdump sub header" ); goto out; }@@ -901,7 +888,7 @@ static void create_header64(DumpState *s, Error **errp)if (write_buffer (s->fd, offset_note, s->note_buf, s->note_size) <0 ) { -dump_error (s,"dump: failed to write notes" , errp); +error_setg (errp,"dump: failed to write notes" ); goto out; }@@ -1064,7 +1051,7 @@ static void write_dump_bitmap(DumpState *s, Error **errp)while (get_next_page (&block_iter, &pfn,NULL , s)) { ret =set_dump_bitmap (last_pfn, pfn, true, dump_bitmap_buf, s);if (ret <0 ) { -dump_error (s,"dump: failed to set dump_bitmap" , errp); +error_setg (errp,"dump: failed to set dump_bitmap" ); goto out; }@@ -1081,7 +1068,7 @@ static void write_dump_bitmap(DumpState *s, Error **errp) ret =set_dump_bitmap (last_pfn, last_pfn +PFN_BUFBITMAP , false, dump_bitmap_buf, s);if (ret <0 ) { -dump_error (s,"dump: failed to sync dump_bitmap" , errp); +error_setg (errp,"dump: failed to sync dump_bitmap" ); goto out; } }@@ -1214,7 +1201,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf,TARGET_PAGE_SIZE , false);g_free (buf);if (ret <0 ) { -dump_error (s,"dump: failed to write page data (zero page)" , errp); +error_setg (errp,"dump: failed to write page data (zero page)" ); goto out; }@@ -1230,7 +1217,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_desc, &pd_zero,sizeof (PageDescriptor), false);if (ret <0 ) { -dump_error (s,"dump: failed to write page desc" , errp); +error_setg (errp,"dump: failed to write page desc" ); goto out; } }else {@@ -1255,7 +1242,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf_out, size_out, false);if (ret <0 ) { -dump_error (s,"dump: failed to write page data" , errp); +error_setg (errp,"dump: failed to write page data" ); goto out; }#ifdef CONFIG_LZO @@ -1268,7 +1255,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf_out, size_out, false);if (ret <0 ) { -dump_error (s,"dump: failed to write page data" , errp); +error_setg (errp,"dump: failed to write page data" ); goto out; }#endif @@ -1282,7 +1269,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf_out, size_out, false);if (ret <0 ) { -dump_error (s,"dump: failed to write page data" , errp); +error_setg (errp,"dump: failed to write page data" ); goto out; }#endif @@ -1297,7 +1284,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_data, buf,TARGET_PAGE_SIZE , false);if (ret <0 ) { -dump_error (s,"dump: failed to write page data" , errp); +error_setg (errp,"dump: failed to write page data" ); goto out; } }@@ -1309,7 +1296,7 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_desc, &pd,sizeof (PageDescriptor), false);if (ret <0 ) { -dump_error (s,"dump: failed to write page desc" , errp); +error_setg (errp,"dump: failed to write page desc" ); goto out; } }@@ -1317,12 +1304,12 @@ static void write_dump_pages(DumpState *s, Error **errp) ret =write_cache (&page_desc,NULL ,0 , true);if (ret <0 ) { -dump_error (s,"dump: failed to sync cache for page_desc" , errp); +error_setg (errp,"dump: failed to sync cache for page_desc" ); goto out; } ret =write_cache (&page_data,NULL ,0 , true);if (ret <0 ) { -dump_error (s,"dump: failed to sync cache for page_data" , errp); +error_setg (errp,"dump: failed to sync cache for page_data" ); goto out; }@@ -1366,7 +1353,7 @@ static void create_kdump_vmcore(DumpState *s, Error **errp) ret =write_start_flat_header (s->fd);if (ret <0 ) { -dump_error (s,"dump: failed to write start flat header" , errp); +error_setg (errp,"dump: failed to write start flat header" );return ; }@@ -1390,11 +1377,9 @@ static void create_kdump_vmcore(DumpState *s, Error **errp) ret =write_end_flat_header (s->fd);if (ret <0 ) { -dump_error (s,"dump: failed to write end flat header" , errp); +error_setg (errp,"dump: failed to write end flat header" );return ; } - -dump_completed (s); }static ram_addr_t get_start_block (DumpState *s)@@ -1677,6 +1662,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,create_vmcore (s, errp); } +dump_cleanup (s);g_free (s); }Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 2/8] dump-guest-memory: add "detach" flag for QMP/HMP interfaces.
In reply to Peter XuQuoted 84 lines · Peter Xu
This patch only adds the interfaces, but not implements them. "detach" parameter is made optional, to make sure that all the old dump-guest-memory requests will still be able to work.
Signed-off-by Peter Xu <[email protected]>--- dump.c | 5 +++-- hmp-commands.hx | 5 +++-- hmp.c | 9 +++++++-- qapi-schema.json | 8 ++++++-- qmp-commands.hx | 6 ++++-- 5 files changed, 23 insertions(+), 10 deletions(-)dump.c +3
-2@@ -1580,8 +1580,9 @@ cleanup:dump_cleanup (s); } -void qmp_dump_guest_memory (bool paging,const char *file,bool has_begin, -int64_t begin,bool has_length, +void qmp_dump_guest_memory (bool paging,const char *file, +bool has_detach,bool detach, +bool has_begin,int64_t begin,bool has_length,int64_t length,bool has_format,DumpGuestMemoryFormat format,Error **errp) {hmp-commands.hx +3
-2@@ -1056,10 +1056,11 @@ ETEXI { .name = "dump-guest-memory", - .args_type = "paging:-p,zlib:-z,lzo:-l,snappy:-s,filename:F,begin:i?,length:i?", - .params = "[-p] [-z|-l|-s] filename [begin length]", + .args_type = "paging:-p,detach:-d,zlib:-z,lzo:-l,snappy:-s,filename:F,begin:i?,length:i?", + .params = "[-p] [-d] [-z|-l|-s] filename [begin length]", .help = "dump guest memory into file 'filename'.\n\t\t\t" "-p: do paging to get guest's memory mapping.\n\t\t\t" + "-d: return immediately (do not wait for completion).\n\t\t\t" "-z: dump in kdump-compressed format, with zlib compression.\n\t\t\t" "-l: dump in kdump-compressed format, with lzo compression.\n\t\t\t" "-s: dump in kdump-compressed format, with snappy compression.\n\t\t\t"hmp.c +7
-2@@ -1586,8 +1586,10 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)const char *file =qdict_get_str (qdict,"filename" );bool has_begin =qdict_haskey (qdict,"begin" );bool has_length =qdict_haskey (qdict,"length" ); +bool has_detach =qdict_haskey (qdict,"detach" );int64_t begin =0 ;int64_t length =0 ; +bool detach = false;enum DumpGuestMemoryFormat dump_format =DUMP_GUEST_MEMORY_FORMAT_ELF ;char *prot;@@ -1615,11 +1617,14 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)if (has_length) { length =qdict_get_int (qdict,"length" ); } +if (has_detach) { + detach =qdict_get_try_bool (qdict,"detach" , false); + } prot =g_strconcat ("file:" , file,NULL ); -qmp_dump_guest_memory (paging, prot, has_begin, begin, has_length, length, - true, dump_format, &err); +qmp_dump_guest_memory (paging, prot, has_detach, detach, has_begin, begin, + has_length, length, true, dump_format, &err);hmp_handle_error (mon, &err);g_free (prot); }qapi-schema.json +0
-0
qapi-schema.json line 2120
Quoted 6 lines
qapi-schema.json +3
-0@@ -2115,6 +2115,9 @@ # 2. fd: the protocol starts with "fd:", and the following string # is the fd's name. # +# @detach: #optional if true, QMP will return immediately rather than +# waiting dump to be finished (since 2.6). +#
Is it better to mention the related query command and events here...
Quoted 31 lines
qapi-schema.json +3
-2# @begin: #optional if specified, the starting physical address. # # @length: #optional if specified, the memory size, in bytes. If you don't@@ -2131,8 +2134,9 @@ # Since: 1.2 ## { 'command': 'dump-guest-memory', - 'data': { 'paging': 'bool', 'protocol': 'str', '*begin': 'int', - '*length': 'int', '*format': 'DumpGuestMemoryFormat' } } + 'data': { 'paging': 'bool', 'protocol': 'str', '*detach': 'bool', + '*begin': 'int', '*length': 'int', + '*format': 'DumpGuestMemoryFormat'} } ## # @DumpGuestMemoryCapability:qmp-commands.hx +2
-2@@ -840,8 +840,8 @@ EQMP { .name = "dump-guest-memory", - .args_type = "paging:b,protocol:s,begin:i?,end:i?,format:s?", - .params = "-p protocol [begin] [length] [format]", + .args_type = "paging:b,protocol:s,detach:b?,begin:i?,end:i?,format:s?", + .params = "-p protocol [-d] [begin] [length] [format]", .help = "dump guest memory to file", .mhandler.cmd_new = qmp_marshal_dump_guest_memory, },
qmp-commands.hx Arguments: · line 861
Quoted 5 lines
qmp-commands.hx +2
-0@@ -857,6 +857,8 @@ Arguments: - "paging": do paging to get guest's memory mapping (json-bool) - "protocol": destination file(started with "file:") or destination file descriptor (started with "fd:") (json-string) +- "detach": if specificed, command will return immediately, without waiting + for dump to be finished (json-bool)
... and here?
Fam
Quoted 7 lines
qmp-commands.hx +0
-0- "begin": the starting physical address. It's optional, and should be specified with length together (json-int) - "length": the memory size, in bytes. It's optional, and should be specifiedSignature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
In reply to Peter XuQuoted 13 lines · Peter Xu
This patch implements "detach" for "dump-guest-memory" command. When specified, one background thread is created to do the dump work.
When there is a dump running in background, the commands "stop", "cont" and "dump-guest-memory" will fail directly, with a hint telling user: "there is a dump in progress".
Although it is not quite essential for now, the new codes are trying to make sure the dump is thread safe. To do this, one list is added into GuestPhysBlockList to track all the referenced MemoryRegions during dump process. We should make sure each MemoryRegion would only be referenced for once.
Quoted 3 lines
One global struct "GlobalDumpState" is added to store some global informations for dump procedures. One mutex is used to protect the global dump info.
This patch doesn't handle the incoming migration case, i.e. when QEMU is started with "-incoming", or "-incoming defer". Dump can go wrong when incoming migration happens at the same time.
Quoted 34 lines
Signed-off-by Peter Xu <[email protected]>--- dump.c | 114 +++++++++++++++++++++++++++++++++++++--- include/qemu-common.h | 4 ++ include/sysemu/dump.h | 10 ++++ include/sysemu/memory_mapping.h | 8 +++ memory_mapping.c | 46 +++++++++++++++- qmp.c | 14 +++++ 6 files changed, 188 insertions(+), 8 deletions(-)dump.c +4
-0@@ -73,6 +73,7 @@ uint64_t cpu_to_dump64(DumpState *s, uint64_t val)static int dump_cleanup (DumpState *s) {guest_phys_blocks_free (&s->guest_phys_blocks); +guest_memory_region_free (&s->guest_phys_blocks);memory_mapping_list_free (&s->list);close (s->fd);if (s->resume) {@@ -1427,6 +1428,9 @@ static void dump_init(DumpState *s, int fd, bool has_format,Error *err =NULL ;int ret; + s->has_format = has_format; + s->format = format; +/* kdump-compressed is conflict with paging and filter */ if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) {assert (!paging && !has_filter);
dump.c cleanup: · line 1587
Quoted 4 lines
dump.c +1
-0@@ -1580,6 +1584,86 @@ cleanup:dump_cleanup (s); } +extern GlobalDumpState global_dump_state;
dump_state_get_global() returns a pointer to the local static variable, why do you need this?
But what I really wonder is why a single boolean is not enough: the DumpState pointer can be passed to dump_thread, so it doesn't need to be global, then you don't need the mutex.
Quoted 224 lines
dump.c +102
-7+ +static GlobalDumpState *dump_state_get_global (void ) +{ +static bool init = false; +static GlobalDumpState global_dump_state; +if (unlikely (!init)) { +qemu_mutex_init (&global_dump_state.gds_mutex); + global_dump_state.gds_cur =NULL ; + init = true; + } +return &global_dump_state; +} + +/* Returns non-zero if there is existing dump in progress, otherwise +* zero is returned. */ +bool dump_in_progress (void ) +{ +GlobalDumpState *global =dump_state_get_global (); +/* we do not need to take the mutex here if we are checking the +* pointer only. */ +return (!!global->gds_cur); +} + +/* Trying to create one DumpState. This will fail if there is an +* existing one. Return DumpState pointer if succeeded, otherwise +* NULL is returned. */ +static DumpState *dump_state_create (GlobalDumpState *global) +{ +DumpState *cur =NULL ; +qemu_mutex_lock (&global->gds_mutex); + + cur = global->gds_cur; +if (cur) { +/* one dump in progress */ + cur =NULL ; + }else { +/* we are the first! */ + cur =g_malloc0 (sizeof (*cur)); + global->gds_cur = cur; + } + +qemu_mutex_unlock (&global->gds_mutex); +return cur; +} + +/* release current DumpState structure */ +static void dump_state_release (GlobalDumpState *global) +{ +DumpState *cur =NULL ; +qemu_mutex_lock (&global->gds_mutex); + + cur = global->gds_cur; +/* we should never call release before having one */ +assert (cur); + global->gds_cur =NULL ; + +qemu_mutex_unlock (&global->gds_mutex); +dump_cleanup (cur); +g_free (cur); +} + +/* this operation might be time consuming. */ +static void dump_process (DumpState *s,Error **errp) +{ +if (s->has_format && s->format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { +create_kdump_vmcore (s, errp); + }else { +create_vmcore (s, errp); + } +} + +static void *dump_thread (void *data) +{ +GlobalDumpState *global = (GlobalDumpState *)data; +dump_process (global->gds_cur,NULL ); +dump_state_release (global); +return NULL ; +} + void qmp_dump_guest_memory(bool paging, const char *file, bool has_detach, bool detach, bool has_begin, int64_t begin, bool has_length,@@ -1590,6 +1674,14 @@ void qmp_dump_guest_memory(bool paging, const char *file,int fd =-1 ;DumpState *s;Error *local_err =NULL ; +/* by default, we are keeping the old style, which is sync dump */ +bool detach_p = false; +GlobalDumpState *global =dump_state_get_global (); + +if (runstate_check (RUN_STATE_INMIGRATE )) { +error_setg (errp,"Dump not allowed during incoming migration." ); +return ; + }/* * kdump-compressed format need the whole memory dumped, so paging or @@ -1609,6 +1701,9 @@ void qmp_dump_guest_memory(bool paging, const char *file,error_setg (errp,QERR_MISSING_PARAMETER ,"begin" );return ; } +if (has_detach) { + detach_p = detach; + }/* check whether lzo/snappy is supported */ #ifndef CONFIG_LZO @@ -1647,7 +1742,11 @@ void qmp_dump_guest_memory(bool paging, const char *file,return ; } - s =g_malloc0 (sizeof (DumpState)); + s =dump_state_create (global); +if (!s) { +error_setg (errp,"One dump is in progress." ); +return ; + }dump_init (s, fd, has_format, format, paging, has_begin, begin, length, &local_err);@@ -1657,14 +1756,15 @@ void qmp_dump_guest_memory(bool paging, const char *file,return ; } -if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { -create_kdump_vmcore (s, errp); +if (!detach_p) { +/* sync dump */ +dump_process (s, errp); +dump_state_release (global); }else { -create_vmcore (s, errp); +qemu_thread_create (&s->dump_thread,"dump_thread" , dump_thread, + global,QEMU_THREAD_DETACHED ); +/* DumpState is freed in dump thread */ } - -dump_cleanup (s); -g_free (s); }DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp)include/qemu-common.h +4
-0@@ -501,4 +501,8 @@ int parse_debug_env(const char *name, int max, int initial);const char *qemu_ether_ntoa (const MACAddr *mac);void page_size_init (void ); +/* returns non-zero if dump is in progress, otherwise zero is +* returned. */ +bool dump_in_progress (void ); +#endif include/sysemu/dump.h +10
-0@@ -183,9 +183,19 @@ typedef struct DumpState {off_t offset_page;/* offset of page part in vmcore */ size_t num_dumpable;/* number of page that can be dumped */ uint32_t flag_compress;/* indicate the compression format */ + +QemuThread dump_thread;/* only used when do async dump */ +bool has_format;/* whether format is provided */ + DumpGuestMemoryFormat format; /* valid only if has_format == true */ } DumpState; +typedef struct GlobalDumpState { +QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ +DumpState *gds_cur;/* current DumpState (might be NULL) */ +}GlobalDumpState ; +uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);uint32_t cpu_to_dump32 (DumpState *s,uint32_t val);uint64_t cpu_to_dump64 (DumpState *s,uint64_t val); +#endif include/sysemu/memory_mapping.h +8
-0@@ -30,10 +30,17 @@ typedef struct GuestPhysBlock {QTAILQ_ENTRY (GuestPhysBlock) next; } GuestPhysBlock; +typedef struct GuestMemoryRegion { +MemoryRegion *gmr_mr; +QTAILQ_ENTRY (GuestMemoryRegion) next; +}GuestMemoryRegion ; +/* point-in-time snapshot of guest-visible physical mappings */ typedef struct GuestPhysBlockList {unsigned num; QTAILQ_HEAD(GuestPhysBlockHead, GuestPhysBlock) head; +/* housekeep all the MemoryRegion that is referenced */ + QTAILQ_HEAD(GuestMemRegionHead, GuestMemoryRegion) head_mr; }GuestPhysBlockList ;/* The physical and virtual address in the memory mapping are contiguous. */ @@ -65,6 +72,7 @@ void memory_mapping_list_free(MemoryMappingList *list);void memory_mapping_list_init (MemoryMappingList *list);void guest_phys_blocks_free (GuestPhysBlockList *list); +void guest_memory_region_free (GuestPhysBlockList *list);void guest_phys_blocks_init (GuestPhysBlockList *list);void guest_phys_blocks_append (GuestPhysBlockList *list);memory_mapping.c +1
-0@@ -186,6 +186,7 @@ void guest_phys_blocks_init(GuestPhysBlockList *list) { list->num =0 ;QTAILQ_INIT (&list->head); +QTAILQ_INIT (&list->head_mr); } typedef struct GuestPhysListener {@@ -193,6 +194,39 @@ typedef struct GuestPhysListener {MemoryListener listener; } GuestPhysListener;
memory_mapping.c typedef struct GuestPhysListener { · line 205
Quoted 10 lines
memory_mapping.c +9
-0+static void guest_memory_region_add (GuestPhysBlockList *list, +MemoryRegion *mr) +{ +GuestMemoryRegion *gmr =NULL ; + QTAILQ_FOREACH(gmr, &list->head_mr, next) { +if (gmr->gmr_mr == mr) { +/* we already refererenced the MemoryRegion */ +return ; + }
This is O(N^2). I think it should be fine to skip this check and just grab the reference. If that is the case, we can probably embed the mr pointer in GuestPhysBlock. Paolo?
Quoted 49 lines
memory_mapping.c +29
-1+ } +/* reference the MemoryRegion to make sure it's valid during dump */ +#ifdef DEBUG_DUMP_GUEST_MEMORY +fprintf (stderr,"DUMP: ref mem region: %s\n" , mr->name); +#endif +memory_region_ref (mr); + gmr =g_malloc0 (sizeof (*gmr)); + gmr->gmr_mr = mr; +QTAILQ_INSERT_TAIL (&list->head_mr, gmr, next); +} + +void guest_memory_region_free (GuestPhysBlockList *list) +{ +GuestMemoryRegion *gmr =NULL , *q =NULL ; + QTAILQ_FOREACH_SAFE(gmr, &list->head_mr, next, q) { +#ifdef DEBUG_DUMP_GUEST_MEMORY +fprintf (stderr,"DUMP: unref mem region: %s\n" , gmr->gmr_mr->name); +#endif +QTAILQ_REMOVE (&list->head_mr, gmr, next); +memory_region_unref (gmr->gmr_mr); +g_free (gmr); + } +} +static void guest_phys_blocks_region_add (MemoryListener *listener,MemoryRegionSection *section) {@@ -241,6 +275,10 @@ static void guest_phys_blocks_region_add(MemoryListener *listener, block->target_end = target_end; block->host_addr = host_addr; +/* keep all the MemoryRegion that is referenced by the dump +* process */ +guest_memory_region_add (g->list, section->mr); +QTAILQ_INSERT_TAIL (&g->list->head, block, next); ++g->list->num; }else {@@ -250,7 +288,7 @@ static void guest_phys_blocks_region_add(MemoryListener *listener, predecessor->target_end = target_end; } -#ifdef DEBUG_GUEST_PHYS_REGION_ADD +#ifdef DEBUG_DUMP_GUEST_MEMORY fprintf (stderr,"%s: target_start=" TARGET_FMT_plx" target_end=" TARGET_FMT_plx": %s (count: %u)\n" , __FUNCTION__, target_start, target_end, predecessor ?"joined" :"added" , g->list->num);@@ -263,8 +301,14 @@ void guest_phys_blocks_append(GuestPhysBlockList *list)
memory_mapping.c void guest_phys_blocks_append(GuestPhysBlockList *list) · line 311
Quoted 10 lines
memory_mapping.c +6
-0g.list = list; g.listener.region_add = &guest_phys_blocks_region_add; +/* We should make sure all the memory objects are valid during +* add dump regions. Before releasing it, we should also make +* sure all the MemoryRegions to be used during dump is +* referenced. */ +rcu_read_lock ();memory_listener_register (&g.listener, &address_space_memory);memory_listener_unregister (&g.listener); +rcu_read_unlock ();
I don't think this is necessary if VM is stopped and incoming migration is not running - address_space_memory will be safe to access as usual. Otherwise this is a separate problem.
Quoted 39 lines
memory_mapping.c +0
-0}static CPUState *find_paging_enabled_cpu (CPUState *start_cpu)qmp.c +14
-0@@ -102,6 +102,13 @@ void qmp_quit(Error **errp)void qmp_stop (Error **errp) { +/* if there is a dump in background, we should wait until the dump +* finished */ +if (dump_in_progress ()) { +error_setg (errp,"There is a dump in process, please wait." ); +return ; + } +if (runstate_check (RUN_STATE_INMIGRATE )) { autostart =0 ; }else {@@ -174,6 +181,13 @@ void qmp_cont(Error **errp)BlockBackend *blk;BlockDriverState *bs; +/* if there is a dump in background, we should wait until the dump +* finished */ +if (dump_in_progress ()) { +error_setg (errp,"There is a dump in process, please wait." ); +return ; + } +if (runstate_needs_reset ()) {error_setg (errp,"Resetting the Virtual Machine is required" );return ;Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 4/8] dump-guest-memory: add qmp event DUMP_COMPLETED
In reply to Peter XuQuoted 4 lines · Peter Xu
dump.c +0
-0@@ -1659,8 +1660,17 @@ static void dump_process(DumpState *s, Error **errp)static void *dump_thread (void *data) {GlobalDumpState *global = (GlobalDumpState *)data;
dump.c static void dump_process(DumpState *s, Error **errp) · line 1671
Quoted 10 lines
dump.c +8
-1-dump_process (global->gds_cur,NULL ); +Error *local_err =NULL ; +const char *msg ="Dump completed successfully" ; + +dump_process (global->gds_cur, &local_err);dump_state_release (global); + +/* if detach is used, notify user that dump has finished */ +if (local_err) { + msg =error_get_pretty (local_err);
error_free?
Quoted 5 lines
dump.c +2
-0+ } +qapi_event_send_dump_completed (msg, &error_abort);return NULL ; }
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
In reply to Fam ZhengQuoted 3 lines · Fam Zheng
But what I really wonder is why a single boolean is not enough: the DumpState pointer can be passed to
dump_thread, so it doesn't need to be global, then you don't need the mutex.
Never mind, it's useful in later patches.
Fam
Re: [Qemu-devel] [PATCH v2 5/8] dump-query: add "dump-query" command to query dump status
In reply to Peter XuQuoted 42 lines · Peter Xu
This patch is only adding the QMP/HMP interface for "dump-query" command, but not implementing them. This command could be used to query background dump status. Please refer to the next patch to see how dump status are defined.
Currently, only fake results are returned.
Signed-off-by Peter Xu <[email protected]>--- dump.c | 9 +++++++++ hmp-commands.hx | 15 +++++++++++++++ hmp.c | 6 ++++++ hmp.h | 1 + qapi-schema.json | 21 +++++++++++++++++++++ qmp-commands.hx | 29 ++++++++++++++++++++++++++++- 6 files changed, 80 insertions(+), 1 deletion(-)dump.c +9
-0@@ -1777,6 +1777,15 @@ void qmp_dump_guest_memory(bool paging, const char *file, } } +DumpStatus *qmp_dump_query (Error **errp) +{ +DumpStatus *status =g_malloc0 (sizeof (*status)); +/* TBD */ + status->status =g_strdup ("WORKING" ); + status->percentage =g_strdup ("50%" ); +return status; +} +DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp) {DumpGuestMemoryFormatList *item;hmp-commands.hx +0
-0
hmp-commands.hx gdb. Without -z|-l|-s, the dump format is ELF. · line 1094
Quoted 8 lines
hmp-commands.hx +5
-0@@ -1087,6 +1087,21 @@ gdb. Without -z|-l|-s, the dump format is ELF. together with begin. ETEXI + { + .name = "dump-query", + .args_type = "", + .params = "", + .help = "query last guest memory dump status.\n\t\t\t",
What are "\n\t\t\t" doing here?
Quoted 48 lines
hmp-commands.hx +10
-0+ .mhandler.cmd = hmp_dump_query, + }, + + +STEXI +@item dump-query +@findex dump-query +Query latest dump status. +ETEXI + #if defined(TARGET_S390X) { .name = "dump-skeys",hmp.c +6
-0@@ -1576,6 +1576,12 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &err); } +void hmp_dump_query (Monitor *mon,const QDict *qdict) +{ +/* TBD */ +monitor_printf (mon,"QUERY DUMP STATUS\n" ); +} +void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict) {Error *err =NULL ;hmp.h +1
-0@@ -85,6 +85,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict);void hmp_device_add (Monitor *mon,const QDict *qdict);void hmp_device_del (Monitor *mon,const QDict *qdict);void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict); +void hmp_dump_query (Monitor *mon,const QDict *qdict);void hmp_netdev_add (Monitor *mon,const QDict *qdict);void hmp_netdev_del (Monitor *mon,const QDict *qdict);void hmp_getfd (Monitor *mon,const QDict *qdict);qapi-schema.json +0
-0@@ -2139,6 +2139,27 @@ '*format': 'DumpGuestMemoryFormat'} }
qapi-schema.json line 2149
Quoted 10 lines
qapi-schema.json +8
-0## +# @DumpStatus +# +# Status for the last guest memory dump. +# +# Since: 2.6 +## +{ 'struct': 'DumpStatus', + 'data': { 'status': 'str', 'percentage': 'str' } }
I suggest using enum for "status" and int for "percentage" (or two ints for "total" and "current").
Quoted 37 lines
qapi-schema.json +13
-0+ +## +# @dump-query +# +# Query latest dump status. +# +# Returns: A @DumpStatus object showing the dump status. +# +# Since: 2.6 +## +{ 'command': 'dump-query', 'returns': 'DumpStatus' } + +## # @DumpGuestMemoryCapability: # # A list of the available formats for dump-guest-memoryqmp-commands.hx +13
-0@@ -879,9 +879,36 @@ Notes: EQMP { + .name = "dump-query", + .args_type = "", + .params = "", + .help = "query background dump status", + .mhandler.cmd_new = qmp_marshal_dump_query, + }, + +SQMP +dump-query +---------- + +Query background dump status. +
qmp-commands.hx Notes: · line 904
Quoted 10 lines
qmp-commands.hx +10
-0+Arguments: None. + +Example: + +-> { "execute": "dump-query" } +<- { "return": {"status": "IN_PROGRESS", "percentage": "85%" } } + +Notes: + +(1) All boolean arguments default to false
Which "boolean arguments"?
Quoted 15 lines
qmp-commands.hx +5
-1+ +EQMP + + { .name = "query-dump-guest-memory-capability", .args_type = "", - .mhandler.cmd_new = qmp_marshal_query_dump_guest_memory_capability, + .mhandler.cmd_new = qmp_marshal_query_dump_guest_memory_capability, }, SQMPSignature · 1 line
2.4.3
Quoted 5 lines · Peter Xu
Sorry that this v2 series cannot be aligned with the v1 series. One patch is added at the begining of the series to do some code cleanups (also fix potential memory leak). Meanwhile, several new patches are appended to the v1 series. Please see the change log for more info.
Looks good overall! I've replied patches with a few questions. Thanks!
Fam
Quoted 58 lines
v2 changes:
- fixed English errors [Drew]
- reordered the "detach" field, first make it optional, then make sure it's order is consistent [Drew, Fam]
- added doc for new detach flag [Eric]
- collected error msg even detached [Drew]
- added qmp eventDUMP_COMPLETEDto notify user [Eric, Fam]
- added "dump-query" QMP & HMP commands to query dump status [Eric]
- "stop" is not allowed when dump in background (also include "cont" and "dump-guest-memory") [Fam]
- added codes to calculate how many dump work finished, which could be queried from "dump-query" [Laszlo]
- added list to track all used MemoryRegion objects, also ref before use [Paolo]
- dump-guest-memory will be forbidden during incoming migrate [Paolo]
- taking rcu lock when collecting memory info [Paolo]Test Done:
- QMP & HMP
- test default dump (sync), work as usual
- test detached dump, command return immediately. When dump finished, will receive eventDUMP_COMPLETEDwith a message.
- test dump-query before/during/after dump
- test kdump with zlib compression, w/ and w/o detach
- libvirt
- test "virsh dump --memory-only" with default format and kdump-zlib format, work as usualPeter Xu (8):
dump-guest-memory: cleanup: removing dump_{error|cleanup}().
dump-guest-memory: add "detach" flag for QMP/HMP interfaces.
dump-guest-memory: add basic "detach" support.
dump-guest-memory: add qmp eventDUMP_COMPLETED
dump-query: add "dump-query" command to query dump status
dump-query: implement "status" of "dump-query" command.
DumpState: addingtotal_sizeandwritten_sizefields
dump-query: make the percentage accurate.docs/qmp-events.txt | 12 ++ dump.c | 284 ++++++++++++++++++++++++++++++++-------- hmp-commands.hx | 20 ++- hmp.c | 18 ++- hmp.h | 1 + include/qemu-common.h | 8 ++ include/sysemu/dump.h | 28 ++++ include/sysemu/memory_mapping.h | 8 ++ memory_mapping.c | 46 ++++++- qapi-schema.json | 29 +++- qapi/event.json | 10 ++ qmp-commands.hx | 35 ++++- qmp.c | 14 ++ 13 files changed, 450 insertions(+), 63 deletions(-)Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 2/8] dump-guest-memory: add "detach" flag for QMP/HMP interfaces.
In reply to Fam ZhengQuoted 85 lines · Fam Zheng
Quoted 84 lines · Peter Xu
This patch only adds the interfaces, but not implements them. "detach" parameter is made optional, to make sure that all the old dump-guest-memory requests will still be able to work.
Signed-off-by Peter Xu <[email protected]>--- dump.c | 5 +++-- hmp-commands.hx | 5 +++-- hmp.c | 9 +++++++-- qapi-schema.json | 8 ++++++-- qmp-commands.hx | 6 ++++-- 5 files changed, 23 insertions(+), 10 deletions(-)dump.c +3
-2@@ -1580,8 +1580,9 @@ cleanup:dump_cleanup (s); } -void qmp_dump_guest_memory (bool paging,const char *file,bool has_begin, -int64_t begin,bool has_length, +void qmp_dump_guest_memory (bool paging,const char *file, +bool has_detach,bool detach, +bool has_begin,int64_t begin,bool has_length,int64_t length,bool has_format,DumpGuestMemoryFormat format,Error **errp) {hmp-commands.hx +3
-2@@ -1056,10 +1056,11 @@ ETEXI { .name = "dump-guest-memory", - .args_type = "paging:-p,zlib:-z,lzo:-l,snappy:-s,filename:F,begin:i?,length:i?", - .params = "[-p] [-z|-l|-s] filename [begin length]", + .args_type = "paging:-p,detach:-d,zlib:-z,lzo:-l,snappy:-s,filename:F,begin:i?,length:i?", + .params = "[-p] [-d] [-z|-l|-s] filename [begin length]", .help = "dump guest memory into file 'filename'.\n\t\t\t" "-p: do paging to get guest's memory mapping.\n\t\t\t" + "-d: return immediately (do not wait for completion).\n\t\t\t" "-z: dump in kdump-compressed format, with zlib compression.\n\t\t\t" "-l: dump in kdump-compressed format, with lzo compression.\n\t\t\t" "-s: dump in kdump-compressed format, with snappy compression.\n\t\t\t"hmp.c +7
-2@@ -1586,8 +1586,10 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)const char *file =qdict_get_str (qdict,"filename" );bool has_begin =qdict_haskey (qdict,"begin" );bool has_length =qdict_haskey (qdict,"length" ); +bool has_detach =qdict_haskey (qdict,"detach" );int64_t begin =0 ;int64_t length =0 ; +bool detach = false;enum DumpGuestMemoryFormat dump_format =DUMP_GUEST_MEMORY_FORMAT_ELF ;char *prot;@@ -1615,11 +1617,14 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)if (has_length) { length =qdict_get_int (qdict,"length" ); } +if (has_detach) { + detach =qdict_get_try_bool (qdict,"detach" , false); + } prot =g_strconcat ("file:" , file,NULL ); -qmp_dump_guest_memory (paging, prot, has_begin, begin, has_length, length, - true, dump_format, &err); +qmp_dump_guest_memory (paging, prot, has_detach, detach, has_begin, begin, + has_length, length, true, dump_format, &err);hmp_handle_error (mon, &err);g_free (prot); }qapi-schema.json +0
-0@@ -2115,6 +2115,9 @@
Quoted 8 lines
qapi-schema.json line 2120
Quoted 6 lines
qapi-schema.json +3
-0# 2. fd: the protocol starts with "fd:", and the following string # is the fd's name. # +# @detach: #optional if true, QMP will return immediately rather than +# waiting dump to be finished (since 2.6). +#Is it better to mention the related query command and events here...
Yes, will add more documents in v3.
Quoted 31 lines
Quoted 31 lines
qapi-schema.json +3
-2# @begin: #optional if specified, the starting physical address. # # @length: #optional if specified, the memory size, in bytes. If you don't@@ -2131,8 +2134,9 @@ # Since: 1.2 ## { 'command': 'dump-guest-memory', - 'data': { 'paging': 'bool', 'protocol': 'str', '*begin': 'int', - '*length': 'int', '*format': 'DumpGuestMemoryFormat' } } + 'data': { 'paging': 'bool', 'protocol': 'str', '*detach': 'bool', + '*begin': 'int', '*length': 'int', + '*format': 'DumpGuestMemoryFormat'} } ## # @DumpGuestMemoryCapability:qmp-commands.hx +2
-2@@ -840,8 +840,8 @@ EQMP { .name = "dump-guest-memory", - .args_type = "paging:b,protocol:s,begin:i?,end:i?,format:s?", - .params = "-p protocol [begin] [length] [format]", + .args_type = "paging:b,protocol:s,detach:b?,begin:i?,end:i?,format:s?", + .params = "-p protocol [-d] [begin] [length] [format]", .help = "dump guest memory to file", .mhandler.cmd_new = qmp_marshal_dump_guest_memory, },
Quoted 8 lines
qmp-commands.hx Arguments: · line 861
Quoted 6 lines
qmp-commands.hx +2
-0@@ -857,6 +857,8 @@ Arguments: - "paging": do paging to get guest's memory mapping (json-bool) - "protocol": destination file(started with "file:") or destination file descriptor (started with "fd:") (json-string) +- "detach": if specificed, command will return immediately, without waiting + for dump to be finished (json-bool)... and here?
Here too. :)
Thanks.
Peter
Quoted 10 lines
Fam
Quoted 7 lines
qmp-commands.hx +0
-0- "begin": the starting physical address. It's optional, and should be specified with length together (json-int) - "length": the memory size, in bytes. It's optional, and should be specifiedSignature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
In reply to Fam ZhengQuoted 293 lines · Fam Zheng
Quoted 13 lines · Peter Xu
This patch implements "detach" for "dump-guest-memory" command. When specified, one background thread is created to do the dump work.
When there is a dump running in background, the commands "stop", "cont" and "dump-guest-memory" will fail directly, with a hint telling user: "there is a dump in progress".
Although it is not quite essential for now, the new codes are trying to make sure the dump is thread safe. To do this, one list is added into GuestPhysBlockList to track all the referenced MemoryRegions during dump process. We should make sure each MemoryRegion would only be referenced for once.
Quoted 3 lines
One global struct "GlobalDumpState" is added to store some global informations for dump procedures. One mutex is used to protect the global dump info.
This patch doesn't handle the incoming migration case, i.e. when QEMU is started with "-incoming", or "-incoming defer". Dump can go wrong when incoming migration happens at the same time.
Quoted 34 lines
Signed-off-by Peter Xu <[email protected]>--- dump.c | 114 +++++++++++++++++++++++++++++++++++++--- include/qemu-common.h | 4 ++ include/sysemu/dump.h | 10 ++++ include/sysemu/memory_mapping.h | 8 +++ memory_mapping.c | 46 +++++++++++++++- qmp.c | 14 +++++ 6 files changed, 188 insertions(+), 8 deletions(-)dump.c +4
-0@@ -73,6 +73,7 @@ uint64_t cpu_to_dump64(DumpState *s, uint64_t val)static int dump_cleanup (DumpState *s) {guest_phys_blocks_free (&s->guest_phys_blocks); +guest_memory_region_free (&s->guest_phys_blocks);memory_mapping_list_free (&s->list);close (s->fd);if (s->resume) {@@ -1427,6 +1428,9 @@ static void dump_init(DumpState *s, int fd, bool has_format,Error *err =NULL ;int ret; + s->has_format = has_format; + s->format = format; +/* kdump-compressed is conflict with paging and filter */ if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) {assert (!paging && !has_filter);dump.c cleanup: · line 1587
Quoted 4 lines
dump.c +1
-0@@ -1580,6 +1584,86 @@ cleanup:dump_cleanup (s); } +extern GlobalDumpState global_dump_state;
dump_state_get_global()returns a pointer to the local static variable, why do you need this?But what I really wonder is why a single boolean is not enough: the DumpState pointer can be passed to
dump_thread, so it doesn't need to be global, then you don't need the mutex.Quoted 225 lines
dump.c +102
-7+ +static GlobalDumpState *dump_state_get_global (void ) +{ +static bool init = false; +static GlobalDumpState global_dump_state; +if (unlikely (!init)) { +qemu_mutex_init (&global_dump_state.gds_mutex); + global_dump_state.gds_cur =NULL ; + init = true; + } +return &global_dump_state; +} + +/* Returns non-zero if there is existing dump in progress, otherwise +* zero is returned. */ +bool dump_in_progress (void ) +{ +GlobalDumpState *global =dump_state_get_global (); +/* we do not need to take the mutex here if we are checking the +* pointer only. */ +return (!!global->gds_cur); +} + +/* Trying to create one DumpState. This will fail if there is an +* existing one. Return DumpState pointer if succeeded, otherwise +* NULL is returned. */ +static DumpState *dump_state_create (GlobalDumpState *global) +{ +DumpState *cur =NULL ; +qemu_mutex_lock (&global->gds_mutex); + + cur = global->gds_cur; +if (cur) { +/* one dump in progress */ + cur =NULL ; + }else { +/* we are the first! */ + cur =g_malloc0 (sizeof (*cur)); + global->gds_cur = cur; + } + +qemu_mutex_unlock (&global->gds_mutex); +return cur; +} + +/* release current DumpState structure */ +static void dump_state_release (GlobalDumpState *global) +{ +DumpState *cur =NULL ; +qemu_mutex_lock (&global->gds_mutex); + + cur = global->gds_cur; +/* we should never call release before having one */ +assert (cur); + global->gds_cur =NULL ; + +qemu_mutex_unlock (&global->gds_mutex); +dump_cleanup (cur); +g_free (cur); +} + +/* this operation might be time consuming. */ +static void dump_process (DumpState *s,Error **errp) +{ +if (s->has_format && s->format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { +create_kdump_vmcore (s, errp); + }else { +create_vmcore (s, errp); + } +} + +static void *dump_thread (void *data) +{ +GlobalDumpState *global = (GlobalDumpState *)data; +dump_process (global->gds_cur,NULL ); +dump_state_release (global); +return NULL ; +} + void qmp_dump_guest_memory(bool paging, const char *file, bool has_detach, bool detach, bool has_begin, int64_t begin, bool has_length,@@ -1590,6 +1674,14 @@ void qmp_dump_guest_memory(bool paging, const char *file,int fd =-1 ;DumpState *s;Error *local_err =NULL ; +/* by default, we are keeping the old style, which is sync dump */ +bool detach_p = false; +GlobalDumpState *global =dump_state_get_global (); + +if (runstate_check (RUN_STATE_INMIGRATE )) { +error_setg (errp,"Dump not allowed during incoming migration." ); +return ; + }/* * kdump-compressed format need the whole memory dumped, so paging or @@ -1609,6 +1701,9 @@ void qmp_dump_guest_memory(bool paging, const char *file,error_setg (errp,QERR_MISSING_PARAMETER ,"begin" );return ; } +if (has_detach) { + detach_p = detach; + }/* check whether lzo/snappy is supported */ #ifndef CONFIG_LZO @@ -1647,7 +1742,11 @@ void qmp_dump_guest_memory(bool paging, const char *file,return ; } - s =g_malloc0 (sizeof (DumpState)); + s =dump_state_create (global); +if (!s) { +error_setg (errp,"One dump is in progress." ); +return ; + }dump_init (s, fd, has_format, format, paging, has_begin, begin, length, &local_err);@@ -1657,14 +1756,15 @@ void qmp_dump_guest_memory(bool paging, const char *file,return ; } -if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { -create_kdump_vmcore (s, errp); +if (!detach_p) { +/* sync dump */ +dump_process (s, errp); +dump_state_release (global); }else { -create_vmcore (s, errp); +qemu_thread_create (&s->dump_thread,"dump_thread" , dump_thread, + global,QEMU_THREAD_DETACHED ); +/* DumpState is freed in dump thread */ } - -dump_cleanup (s); -g_free (s); }DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp)include/qemu-common.h +4
-0@@ -501,4 +501,8 @@ int parse_debug_env(const char *name, int max, int initial);const char *qemu_ether_ntoa (const MACAddr *mac);void page_size_init (void ); +/* returns non-zero if dump is in progress, otherwise zero is +* returned. */ +bool dump_in_progress (void ); +#endif include/sysemu/dump.h +10
-0@@ -183,9 +183,19 @@ typedef struct DumpState {off_t offset_page;/* offset of page part in vmcore */ size_t num_dumpable;/* number of page that can be dumped */ uint32_t flag_compress;/* indicate the compression format */ + +QemuThread dump_thread;/* only used when do async dump */ +bool has_format;/* whether format is provided */ + DumpGuestMemoryFormat format; /* valid only if has_format == true */ } DumpState; +typedef struct GlobalDumpState { +QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ +DumpState *gds_cur;/* current DumpState (might be NULL) */ +}GlobalDumpState ; +uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);uint32_t cpu_to_dump32 (DumpState *s,uint32_t val);uint64_t cpu_to_dump64 (DumpState *s,uint64_t val); +#endif include/sysemu/memory_mapping.h +8
-0@@ -30,10 +30,17 @@ typedef struct GuestPhysBlock {QTAILQ_ENTRY (GuestPhysBlock) next; } GuestPhysBlock; +typedef struct GuestMemoryRegion { +MemoryRegion *gmr_mr; +QTAILQ_ENTRY (GuestMemoryRegion) next; +}GuestMemoryRegion ; +/* point-in-time snapshot of guest-visible physical mappings */ typedef struct GuestPhysBlockList {unsigned num; QTAILQ_HEAD(GuestPhysBlockHead, GuestPhysBlock) head; +/* housekeep all the MemoryRegion that is referenced */ + QTAILQ_HEAD(GuestMemRegionHead, GuestMemoryRegion) head_mr; }GuestPhysBlockList ;/* The physical and virtual address in the memory mapping are contiguous. */ @@ -65,6 +72,7 @@ void memory_mapping_list_free(MemoryMappingList *list);void memory_mapping_list_init (MemoryMappingList *list);void guest_phys_blocks_free (GuestPhysBlockList *list); +void guest_memory_region_free (GuestPhysBlockList *list);void guest_phys_blocks_init (GuestPhysBlockList *list);void guest_phys_blocks_append (GuestPhysBlockList *list);memory_mapping.c +1
-0@@ -186,6 +186,7 @@ void guest_phys_blocks_init(GuestPhysBlockList *list) { list->num =0 ;QTAILQ_INIT (&list->head); +QTAILQ_INIT (&list->head_mr); } typedef struct GuestPhysListener {@@ -193,6 +194,39 @@ typedef struct GuestPhysListener {MemoryListener listener; } GuestPhysListener;
Quoted 13 lines
memory_mapping.c typedef struct GuestPhysListener { · line 205
Quoted 9 lines
memory_mapping.c +9
-0+static void guest_memory_region_add (GuestPhysBlockList *list, +MemoryRegion *mr) +{ +GuestMemoryRegion *gmr =NULL ; + QTAILQ_FOREACH(gmr, &list->head_mr, next) { +if (gmr->gmr_mr == mr) { +/* we already refererenced the MemoryRegion */ +return ; + }This is O(N^2). I think it should be fine to skip this check and just grab the reference. If that is the case, we can probably embed the mr pointer in GuestPhysBlock. Paolo?
If embed the mr pointer into GuestPhyBlock, then we might need to ref/unref one MemoryRegion for multiple times (and I am not sure how many, maybe it could be a very big number especially the MemoryRegionSections are scattered?). Not sure whether it is more efficient.
For what I see, the number of MemoryRegions should be not big (<5 in my case). So even with O(N^2), it should merely like O(N). Not sure about this too.
Would like to hear more review comments from Paolo and others.
Quoted 50 lines
Quoted 50 lines
memory_mapping.c +29
-1+ } +/* reference the MemoryRegion to make sure it's valid during dump */ +#ifdef DEBUG_DUMP_GUEST_MEMORY +fprintf (stderr,"DUMP: ref mem region: %s\n" , mr->name); +#endif +memory_region_ref (mr); + gmr =g_malloc0 (sizeof (*gmr)); + gmr->gmr_mr = mr; +QTAILQ_INSERT_TAIL (&list->head_mr, gmr, next); +} + +void guest_memory_region_free (GuestPhysBlockList *list) +{ +GuestMemoryRegion *gmr =NULL , *q =NULL ; + QTAILQ_FOREACH_SAFE(gmr, &list->head_mr, next, q) { +#ifdef DEBUG_DUMP_GUEST_MEMORY +fprintf (stderr,"DUMP: unref mem region: %s\n" , gmr->gmr_mr->name); +#endif +QTAILQ_REMOVE (&list->head_mr, gmr, next); +memory_region_unref (gmr->gmr_mr); +g_free (gmr); + } +} +static void guest_phys_blocks_region_add (MemoryListener *listener,MemoryRegionSection *section) {@@ -241,6 +275,10 @@ static void guest_phys_blocks_region_add(MemoryListener *listener, block->target_end = target_end; block->host_addr = host_addr; +/* keep all the MemoryRegion that is referenced by the dump +* process */ +guest_memory_region_add (g->list, section->mr); +QTAILQ_INSERT_TAIL (&g->list->head, block, next); ++g->list->num; }else {@@ -250,7 +288,7 @@ static void guest_phys_blocks_region_add(MemoryListener *listener, predecessor->target_end = target_end; } -#ifdef DEBUG_GUEST_PHYS_REGION_ADD +#ifdef DEBUG_DUMP_GUEST_MEMORY fprintf (stderr,"%s: target_start=" TARGET_FMT_plx" target_end=" TARGET_FMT_plx": %s (count: %u)\n" , __FUNCTION__, target_start, target_end, predecessor ?"joined" :"added" , g->list->num);@@ -263,8 +301,14 @@ void guest_phys_blocks_append(GuestPhysBlockList *list)
Quoted 14 lines
memory_mapping.c void guest_phys_blocks_append(GuestPhysBlockList *list) · line 311
Quoted 10 lines
memory_mapping.c +6
-0g.list = list; g.listener.region_add = &guest_phys_blocks_region_add; +/* We should make sure all the memory objects are valid during +* add dump regions. Before releasing it, we should also make +* sure all the MemoryRegions to be used during dump is +* referenced. */ +rcu_read_lock ();memory_listener_register (&g.listener, &address_space_memory);memory_listener_unregister (&g.listener); +rcu_read_unlock ();I don't think this is necessary if VM is stopped and incoming migration is not running -
address_space_memorywill be safe to access as usual. Otherwise this is a separate problem.
Yes, I think it should work too without the two lines. I am just taking Paolo's suggestions. It should work too if we do not take the reference counts for MemoryRegion. However, without those things (ref counts, rcu locks), it's not thread safe even it could work. Not sure whether I am understanding it correctly.
Thanks!
Peter
Quoted 40 lines
Quoted 40 lines
memory_mapping.c +0
-0}static CPUState *find_paging_enabled_cpu (CPUState *start_cpu)qmp.c +14
-0@@ -102,6 +102,13 @@ void qmp_quit(Error **errp)void qmp_stop (Error **errp) { +/* if there is a dump in background, we should wait until the dump +* finished */ +if (dump_in_progress ()) { +error_setg (errp,"There is a dump in process, please wait." ); +return ; + } +if (runstate_check (RUN_STATE_INMIGRATE )) { autostart =0 ; }else {@@ -174,6 +181,13 @@ void qmp_cont(Error **errp)BlockBackend *blk;BlockDriverState *bs; +/* if there is a dump in background, we should wait until the dump +* finished */ +if (dump_in_progress ()) { +error_setg (errp,"There is a dump in process, please wait." ); +return ; + } +if (runstate_needs_reset ()) {error_setg (errp,"Resetting the Virtual Machine is required" );return ;Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 4/8] dump-guest-memory: add qmp event DUMP_COMPLETED
In reply to Fam ZhengQuoted 17 lines · Fam Zheng
Quoted 4 lines · Peter Xu
dump.c +0
-0@@ -1659,8 +1660,17 @@ static void dump_process(DumpState *s, Error **errp)static void *dump_thread (void *data) {GlobalDumpState *global = (GlobalDumpState *)data;dump.c static void dump_process(DumpState *s, Error **errp) · line 1671
Quoted 10 lines
dump.c +8
-1-dump_process (global->gds_cur,NULL ); +Error *local_err =NULL ; +const char *msg ="Dump completed successfully" ; + +dump_process (global->gds_cur, &local_err);dump_state_release (global); + +/* if detach is used, notify user that dump has finished */ +if (local_err) { + msg =error_get_pretty (local_err);
error_free?
Yes, thanks!
Peter
Quoted 7 lines
Quoted 7 lines
dump.c +2
-0+ } +qapi_event_send_dump_completed (msg, &error_abort);return NULL ; }
Re: [Qemu-devel] [PATCH v2 1/8] dump-guest-memory: cleanup: removing dump_{error|cleanup}().
In reply to Fam ZhengQuoted 5 lines · Fam Zheng
I think when
write_dump_header()returns a failure, it does calldump_cleanup(), in create_header{32,64}.But the changes of code in this patch look sane to me, and the new error handling is definitely looking better.
Yes, you are right. I will modify the commit message to correct mentioning about memory leak, and keep the codes itself.
Thanks.
Peter
Quoted 2 lines
Fam
Quoted 3 lines · Fam Zheng
Looks good overall! I've replied patches with a few questions. Thanks!
Fam
Thanks! Will wait for more comments and post v3 later.
Peter
Re: [Qemu-devel] [PATCH v2 5/8] dump-query: add "dump-query" command to query dump status
In reply to Fam ZhengQuoted 46 lines · Fam Zheng
Quoted 45 lines · Peter Xu
This patch is only adding the QMP/HMP interface for "dump-query" command, but not implementing them. This command could be used to query background dump status. Please refer to the next patch to see how dump status are defined.
Currently, only fake results are returned.
Signed-off-by Peter Xu <[email protected]>--- dump.c | 9 +++++++++ hmp-commands.hx | 15 +++++++++++++++ hmp.c | 6 ++++++ hmp.h | 1 + qapi-schema.json | 21 +++++++++++++++++++++ qmp-commands.hx | 29 ++++++++++++++++++++++++++++- 6 files changed, 80 insertions(+), 1 deletion(-)dump.c +9
-0@@ -1777,6 +1777,15 @@ void qmp_dump_guest_memory(bool paging, const char *file, } } +DumpStatus *qmp_dump_query (Error **errp) +{ +DumpStatus *status =g_malloc0 (sizeof (*status)); +/* TBD */ + status->status =g_strdup ("WORKING" ); + status->percentage =g_strdup ("50%" ); +return status; +} +DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp) {DumpGuestMemoryFormatList *item;hmp-commands.hx +0
-0@@ -1087,6 +1087,21 @@ gdb. Without -z|-l|-s, the dump format is ELF. together with begin. ETEXI
Quoted 7 lines
hmp-commands.hx gdb. Without -z|-l|-s, the dump format is ELF. · line 1094
Quoted 5 lines
hmp-commands.hx +5
-0+ { + .name = "dump-query", + .args_type = "", + .params = "", + .help = "query last guest memory dump status.\n\t\t\t",What are "\n\t\t\t" doing here?
Sorry I should remove that.
Quoted 50 lines
Quoted 50 lines
hmp-commands.hx +10
-0+ .mhandler.cmd = hmp_dump_query, + }, + + +STEXI +@item dump-query +@findex dump-query +Query latest dump status. +ETEXI + #if defined(TARGET_S390X) { .name = "dump-skeys",hmp.c +6
-0@@ -1576,6 +1576,12 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &err); } +void hmp_dump_query (Monitor *mon,const QDict *qdict) +{ +/* TBD */ +monitor_printf (mon,"QUERY DUMP STATUS\n" ); +} +void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict) {Error *err =NULL ;hmp.h +1
-0@@ -85,6 +85,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict);void hmp_device_add (Monitor *mon,const QDict *qdict);void hmp_device_del (Monitor *mon,const QDict *qdict);void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict); +void hmp_dump_query (Monitor *mon,const QDict *qdict);void hmp_netdev_add (Monitor *mon,const QDict *qdict);void hmp_netdev_del (Monitor *mon,const QDict *qdict);void hmp_getfd (Monitor *mon,const QDict *qdict);qapi-schema.json +0
-0@@ -2139,6 +2139,27 @@ '*format': 'DumpGuestMemoryFormat'} }
Quoted 12 lines
qapi-schema.json line 2149
Quoted 9 lines
qapi-schema.json +8
-0## +# @DumpStatus +# +# Status for the last guest memory dump. +# +# Since: 2.6 +## +{ 'struct': 'DumpStatus', + 'data': { 'status': 'str', 'percentage': 'str' } }I suggest using enum for "status" and int for "percentage" (or two ints for "total" and "current").
Yes, I picked string just for flexibility. Regarding to this interface issue, I'd like to wait for others' comments too before modification.
Quoted 42 lines
Quoted 42 lines
qapi-schema.json +13
-0+ +## +# @dump-query +# +# Query latest dump status. +# +# Returns: A @DumpStatus object showing the dump status. +# +# Since: 2.6 +## +{ 'command': 'dump-query', 'returns': 'DumpStatus' } + +## # @DumpGuestMemoryCapability: # # A list of the available formats for dump-guest-memoryqmp-commands.hx +17
-0@@ -879,9 +879,36 @@ Notes: EQMP { + .name = "dump-query", + .args_type = "", + .params = "", + .help = "query background dump status", + .mhandler.cmd_new = qmp_marshal_dump_query, + }, + +SQMP +dump-query +---------- + +Query background dump status. + +Arguments: None. + +Example: +
Quoted 8 lines
qmp-commands.hx Notes: · line 904
Quoted 6 lines
qmp-commands.hx +6
-0+-> { "execute": "dump-query" } +<- { "return": {"status": "IN_PROGRESS", "percentage": "85%" } } + +Notes: + +(1) All boolean arguments default to falseWhich "boolean arguments"?
Should remove. Sorry.
Peter
Quoted 17 lines
Quoted 17 lines
qmp-commands.hx +5
-1+ +EQMP + + { .name = "query-dump-guest-memory-capability", .args_type = "", - .mhandler.cmd_new = qmp_marshal_query_dump_guest_memory_capability, + .mhandler.cmd_new = qmp_marshal_query_dump_guest_memory_capability, }, SQMPSignature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
In reply to Peter XuQuoted 6 lines · Peter Xu
If embed the mr pointer into GuestPhyBlock, then we might need to ref/unref one MemoryRegion for multiple times (and I am not sure how many, maybe it could be a very big number especially the MemoryRegionSections are scattered?). Not sure whether it is more efficient.
Quoted 6 lines
For what I see, the number of MemoryRegions should be not big (<5 in my case). So even with O(N^2), it should merely like O(N). Not sure about this too.
Would like to hear more review comments from Paolo and others.
Fam suggestion is a good one, ref'ing one MemoryRegion many times is not a problem.
Also I noticed now that you do the dump_init in the main thread (using a listener), so the RCU lock/unlock is not needed. I don't know this code very well.
It's worth adding a comment at the top of functions that are called from a separate thread.
Thanks,
Paolo
Re: [Qemu-devel] [PATCH v2 4/8] dump-guest-memory: add qmp event DUMP_COMPLETED
In reply to Peter Xuqapi/event.json line 368
Quoted 9 lines · Peter Xu
qapi/event.json +9
-0+## +# @DUMP_COMPLETED +# +# Emitted when background dump has completed +# +# Since: 2.6 +## +{ 'event': 'DUMP_COMPLETED' , + 'data': { 'msg': 'str' } }
This makes it hard to understand whether there was an error or not. I suggest using '*error': 'str' instead, and omitting the error if the dump is successful.
Paolo
Re: [Qemu-devel] [PATCH v2 5/8] dump-query: add "dump-query" command to query dump status
In reply to Peter XuQuoted 9 lines · Peter Xu
Quoted 5 lines
qapi-schema.json line 2149
Quoted 2 lines
qapi-schema.json +2
-0+{ 'struct': 'DumpStatus', + 'data': { 'status': 'str', 'percentage': 'str' } }I suggest using enum for "status" and int for "percentage" (or two ints for "total" and "current").
Yes, I picked string just for flexibility. Regarding to this interface issue, I'd like to wait for others' comments too before modification.
I like Fam's idea of using an enum and two ints.
Also, the command should be named query-dump and the corresponding HMP command should be "info dump" (by defining "dump" in hmp-commands-info.h".
Paolo
Re: [Qemu-devel] [PATCH v2 6/8] dump-query: implement "status" of "dump-query" command.
In reply to Peter XuQuoted 6 lines · Peter Xu
This patch implements the status changes inside dump process. When query dump status, three possible results could be:
1. never started dump:
{ "status": "NOT_STARTED", "percentage": "N/A" }
Quoted 8 lines
2. one dump is running in background:
{ "status": "IN_PROGRESS", "percentage": "{0..100}%" }3. no dump is running, and the last dump has finished:
{ "status": "SUCCEEDED|FAILED", "percentage": "N/A" }It's mostly done. Except that we might need more accurate "percentage" results (which is now 50% all the time!).
As mentioned early, you can use an enum. QEMU usually prints enums in lowercase and separates words with "-". Similar to MigrationStatus you can use none, active, completed, failed. In fact you might even reuse MigrationStatus directly, it's simpler.
The percentage is not necessary as part of the QMP return value. You can compute it in hmp_info_dump however and print it to HMP only.
I think you can structure the patches like this:
add basic "detach" support
add qmp event DUMP_COMPLETED
add total_size and written_size to DumpState
add "query-dump" QMP command
add "info dump" HMP command
where the fourth patch already sets all fields correctly.
Thanks,
Paolo
Quoted 185 lines
Signed-off-by Peter Xu <[email protected]>--- dump.c | 57 +++++++++++++++++++++++++++++++++++++++++++-------- hmp.c | 7 +++++-- include/qemu-common.h | 4 ++++ include/sysemu/dump.h | 13 ++++++++++-- 4 files changed, 68 insertions(+), 13 deletions(-)dump.c +48
-9@@ -1594,11 +1594,44 @@ static GlobalDumpState *dump_state_get_global(void)if (unlikely (!init)) {qemu_mutex_init (&global_dump_state.gds_mutex); global_dump_state.gds_cur =NULL ; + global_dump_state.gds_result =DUMP_RES_NOT_STARTED ; init = true; }return &global_dump_state; } +static const char *const dump_result_table[] = { + [DUMP_RES_NOT_STARTED ] ="NOT_STARTED" , + [DUMP_RES_IN_PROGRESS ] ="IN_PROGRESS" , + [DUMP_RES_SUCCEEDED ] ="SUCCEEDED" , + [DUMP_RES_FAILED ] ="FAILED" , +}; + +/* Returns DumpStatus. Caller should be responsible to free the +* resources using qapi_free_DumpStatus(). */ +DumpStatus *dump_status_query (void ) +{ +DumpStatus *status =g_malloc0 (sizeof (*status)); +int percentage =50 ; +char buf[64 ] = {0 }; + +GlobalDumpState *global =dump_state_get_global (); +qemu_mutex_lock (&global->gds_mutex); + +/* TBD: get correct percentage */ + status->status =g_strdup (dump_result_table[global->gds_result]); +if (global->gds_result ==DUMP_RES_IN_PROGRESS ) { +snprintf (buf,sizeof (buf) -1 ,"%d%%" , percentage); + status->percentage =g_strdup (buf); + }else { + status->percentage =g_strdup ("N/A" ); + } + +qemu_mutex_unlock (&global->gds_mutex); + +return status; +} +/* Returns non-zero if there is existing dump in progress, otherwise * zero is returned. */ bool dump_in_progress (void )@@ -1620,27 +1653,37 @@ static DumpState *dump_state_create(GlobalDumpState *global) cur = global->gds_cur;if (cur) {/* one dump in progress */ +assert (global->gds_result ==DUMP_RES_IN_PROGRESS ); cur =NULL ; }else {/* we are the first! */ +assert (global->gds_result !=DUMP_RES_IN_PROGRESS ); cur =g_malloc0 (sizeof (*cur)); global->gds_cur = cur; } + global->gds_result =DUMP_RES_IN_PROGRESS ;qemu_mutex_unlock (&global->gds_mutex);return cur; } -/* release current DumpState structure */ -static void dump_state_release (GlobalDumpState *global) +/* release current DumpState structure. "done" is hint to show +* whether the dump is succeeded or not. */ +static void dump_state_release (GlobalDumpState *global,bool done) {DumpState *cur =NULL ;qemu_mutex_lock (&global->gds_mutex); +assert (global->gds_result ==DUMP_RES_IN_PROGRESS ); cur = global->gds_cur;/* we should never call release before having one */ assert (cur); global->gds_cur =NULL ; +if (done) { + global->gds_result =DUMP_RES_SUCCEEDED ; + }else { + global->gds_result =DUMP_RES_FAILED ; + }qemu_mutex_unlock (&global->gds_mutex);dump_cleanup (cur);@@ -1664,7 +1707,7 @@ static void *dump_thread(void *data)const char *msg ="Dump completed successfully" ;dump_process (global->gds_cur, &local_err); -dump_state_release (global); +dump_state_release (global, (local_err ==NULL ));/* if detach is used, notify user that dump has finished */ if (local_err) {@@ -1769,7 +1812,7 @@ void qmp_dump_guest_memory(bool paging, const char *file,if (!detach_p) {/* sync dump */ dump_process (s, errp); -dump_state_release (global); +dump_state_release (global, (*errp ==NULL )); }else {qemu_thread_create (&s->dump_thread,"dump_thread" , dump_thread, global,QEMU_THREAD_DETACHED );@@ -1779,11 +1822,7 @@ void qmp_dump_guest_memory(bool paging, const char *file,DumpStatus *qmp_dump_query (Error **errp) { -DumpStatus *status =g_malloc0 (sizeof (*status)); -/* TBD */ - status->status =g_strdup ("WORKING" ); - status->percentage =g_strdup ("50%" ); -return status; +return dump_status_query (); }DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp)hmp.c +5
-2@@ -1578,8 +1578,11 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)void hmp_dump_query (Monitor *mon,const QDict *qdict) { -/* TBD */ -monitor_printf (mon,"QUERY DUMP STATUS\n" ); +DumpStatus *status =dump_status_query (); +assert (status); +monitor_printf (mon,"STATUS: %s\n" , status->status); +monitor_printf (mon,"PERCENTAGE: %s\n" , status->percentage); +qapi_free_DumpStatus (status); }void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict)include/qemu-common.h +4
-0@@ -505,4 +505,8 @@ void page_size_init(void);* returned. */ bool dump_in_progress (void ); +/* Returns DumpStatus. Caller should be responsible to free the +* resources using qapi_free_DumpStatus(). */ +DumpStatus *dump_status_query (void ); +#endif include/sysemu/dump.h +11
-2@@ -189,9 +189,18 @@ typedef struct DumpState {DumpGuestMemoryFormat format;/* valid only if has_format == true */ } DumpState; +typedef enum DumpResult { +DUMP_RES_NOT_STARTED =0 , +DUMP_RES_IN_PROGRESS , +DUMP_RES_SUCCEEDED , +DUMP_RES_FAILED , +DUMP_RES_MAX , +}DumpResult ; +typedef struct GlobalDumpState { -QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ -DumpState *gds_cur;/* current DumpState (might be NULL) */ +QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ +DumpState *gds_cur;/* current DumpState (might be NULL) */ +DumpResult gds_result;/* current dump result */ }GlobalDumpState ;uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
In reply to Peter XuQuoted 51 lines · Peter Xu
This patch implements "detach" for "dump-guest-memory" command. When specified, one background thread is created to do the dump work.
When there is a dump running in background, the commands "stop", "cont" and "dump-guest-memory" will fail directly, with a hint telling user: "there is a dump in progress".
Although it is not quite essential for now, the new codes are trying to make sure the dump is thread safe. To do this, one list is added into GuestPhysBlockList to track all the referenced MemoryRegions during dump process. We should make sure each MemoryRegion would only be referenced for once.
One global struct "GlobalDumpState" is added to store some global informations for dump procedures. One mutex is used to protect the global dump info.
Signed-off-by Peter Xu <[email protected]>--- dump.c | 114 +++++++++++++++++++++++++++++++++++++--- include/qemu-common.h | 4 ++ include/sysemu/dump.h | 10 ++++ include/sysemu/memory_mapping.h | 8 +++ memory_mapping.c | 46 +++++++++++++++- qmp.c | 14 +++++ 6 files changed, 188 insertions(+), 8 deletions(-)dump.c +4
-0@@ -73,6 +73,7 @@ uint64_t cpu_to_dump64(DumpState *s, uint64_t val)static int dump_cleanup (DumpState *s) {guest_phys_blocks_free (&s->guest_phys_blocks); +guest_memory_region_free (&s->guest_phys_blocks);memory_mapping_list_free (&s->list);close (s->fd);if (s->resume) {@@ -1427,6 +1428,9 @@ static void dump_init(DumpState *s, int fd, bool has_format,Error *err =NULL ;int ret; + s->has_format = has_format; + s->format = format; +/* kdump-compressed is conflict with paging and filter */ if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) {assert (!paging && !has_filter);@@ -1580,6 +1584,86 @@ cleanup:dump_cleanup (s);
dump.c cleanup: · line 1594
Quoted 10 lines
dump.c +8
-0} +extern GlobalDumpState global_dump_state; + +static GlobalDumpState *dump_state_get_global (void ) +{ +static bool init = false; +static GlobalDumpState global_dump_state; +if (unlikely (!init)) { +qemu_mutex_init (&global_dump_state.gds_mutex);
The mutex is not necessary. The structure is always created in the main thread and released by the dump thread (of which there is just one).
You can then just make a global DumpState (not a pointer!), and separate the fields between:
- those that are protected by a mutex (most likely the DumpResult and written_size, possibly others)
- those that are only written before the thread is started, and thus do not need to be protected by a mutex
- those that are only accessed by the thread, and thus do not need to be protected by a mutex either.
See for example this extract from migration/block.c:
typedef struct BlkMigState {
/* Written during setup phase. Can be read without a lock. */
int blk_enable;
int shared_base;
QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list;
int64_t total_sector_sum;
bool zero_blocks;
/* Protected by lock. */
QSIMPLEQ_HEAD(blk_list, BlkMigBlock) blk_list;
int submitted;
int read_done;
/* Only used by migration thread. Does not need a lock. */
int transferred;
int prev_progress;
int bulk_completed;
/* The lock. */
QemuMutex lock;
} BlkMigState;static BlkMigState block_mig_state;
Paolo
Quoted 322 lines
dump.c +95
-7+ global_dump_state.gds_cur =NULL ; + init = true; + } +return &global_dump_state; +} + +/* Returns non-zero if there is existing dump in progress, otherwise +* zero is returned. */ +bool dump_in_progress (void ) +{ +GlobalDumpState *global =dump_state_get_global (); +/* we do not need to take the mutex here if we are checking the +* pointer only. */ +return (!!global->gds_cur); +} + +/* Trying to create one DumpState. This will fail if there is an +* existing one. Return DumpState pointer if succeeded, otherwise +* NULL is returned. */ +static DumpState *dump_state_create (GlobalDumpState *global) +{ +DumpState *cur =NULL ; +qemu_mutex_lock (&global->gds_mutex); + + cur = global->gds_cur; +if (cur) { +/* one dump in progress */ + cur =NULL ; + }else { +/* we are the first! */ + cur =g_malloc0 (sizeof (*cur)); + global->gds_cur = cur; + } + +qemu_mutex_unlock (&global->gds_mutex); +return cur; +} + +/* release current DumpState structure */ +static void dump_state_release (GlobalDumpState *global) +{ +DumpState *cur =NULL ; +qemu_mutex_lock (&global->gds_mutex); + + cur = global->gds_cur; +/* we should never call release before having one */ +assert (cur); + global->gds_cur =NULL ; + +qemu_mutex_unlock (&global->gds_mutex); +dump_cleanup (cur); +g_free (cur); +} + +/* this operation might be time consuming. */ +static void dump_process (DumpState *s,Error **errp) +{ +if (s->has_format && s->format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { +create_kdump_vmcore (s, errp); + }else { +create_vmcore (s, errp); + } +} + +static void *dump_thread (void *data) +{ +GlobalDumpState *global = (GlobalDumpState *)data; +dump_process (global->gds_cur,NULL ); +dump_state_release (global); +return NULL ; +} + void qmp_dump_guest_memory(bool paging, const char *file, bool has_detach, bool detach, bool has_begin, int64_t begin, bool has_length,@@ -1590,6 +1674,14 @@ void qmp_dump_guest_memory(bool paging, const char *file,int fd =-1 ;DumpState *s;Error *local_err =NULL ; +/* by default, we are keeping the old style, which is sync dump */ +bool detach_p = false; +GlobalDumpState *global =dump_state_get_global (); + +if (runstate_check (RUN_STATE_INMIGRATE )) { +error_setg (errp,"Dump not allowed during incoming migration." ); +return ; + }/* * kdump-compressed format need the whole memory dumped, so paging or @@ -1609,6 +1701,9 @@ void qmp_dump_guest_memory(bool paging, const char *file,error_setg (errp,QERR_MISSING_PARAMETER ,"begin" );return ; } +if (has_detach) { + detach_p = detach; + }/* check whether lzo/snappy is supported */ #ifndef CONFIG_LZO @@ -1647,7 +1742,11 @@ void qmp_dump_guest_memory(bool paging, const char *file,return ; } - s =g_malloc0 (sizeof (DumpState)); + s =dump_state_create (global); +if (!s) { +error_setg (errp,"One dump is in progress." ); +return ; + }dump_init (s, fd, has_format, format, paging, has_begin, begin, length, &local_err);@@ -1657,14 +1756,15 @@ void qmp_dump_guest_memory(bool paging, const char *file,return ; } -if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { -create_kdump_vmcore (s, errp); +if (!detach_p) { +/* sync dump */ +dump_process (s, errp); +dump_state_release (global); }else { -create_vmcore (s, errp); +qemu_thread_create (&s->dump_thread,"dump_thread" , dump_thread, + global,QEMU_THREAD_DETACHED ); +/* DumpState is freed in dump thread */ } - -dump_cleanup (s); -g_free (s); }DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp)include/qemu-common.h +4
-0@@ -501,4 +501,8 @@ int parse_debug_env(const char *name, int max, int initial);const char *qemu_ether_ntoa (const MACAddr *mac);void page_size_init (void ); +/* returns non-zero if dump is in progress, otherwise zero is +* returned. */ +bool dump_in_progress (void ); +#endif include/sysemu/dump.h +10
-0@@ -183,9 +183,19 @@ typedef struct DumpState {off_t offset_page;/* offset of page part in vmcore */ size_t num_dumpable;/* number of page that can be dumped */ uint32_t flag_compress;/* indicate the compression format */ + +QemuThread dump_thread;/* only used when do async dump */ +bool has_format;/* whether format is provided */ + DumpGuestMemoryFormat format; /* valid only if has_format == true */ } DumpState; +typedef struct GlobalDumpState { +QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ +DumpState *gds_cur;/* current DumpState (might be NULL) */ +}GlobalDumpState ; +uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);uint32_t cpu_to_dump32 (DumpState *s,uint32_t val);uint64_t cpu_to_dump64 (DumpState *s,uint64_t val); +#endif include/sysemu/memory_mapping.h +8
-0@@ -30,10 +30,17 @@ typedef struct GuestPhysBlock {QTAILQ_ENTRY (GuestPhysBlock) next; } GuestPhysBlock; +typedef struct GuestMemoryRegion { +MemoryRegion *gmr_mr; +QTAILQ_ENTRY (GuestMemoryRegion) next; +}GuestMemoryRegion ; +/* point-in-time snapshot of guest-visible physical mappings */ typedef struct GuestPhysBlockList {unsigned num; QTAILQ_HEAD(GuestPhysBlockHead, GuestPhysBlock) head; +/* housekeep all the MemoryRegion that is referenced */ + QTAILQ_HEAD(GuestMemRegionHead, GuestMemoryRegion) head_mr; }GuestPhysBlockList ;/* The physical and virtual address in the memory mapping are contiguous. */ @@ -65,6 +72,7 @@ void memory_mapping_list_free(MemoryMappingList *list);void memory_mapping_list_init (MemoryMappingList *list);void guest_phys_blocks_free (GuestPhysBlockList *list); +void guest_memory_region_free (GuestPhysBlockList *list);void guest_phys_blocks_init (GuestPhysBlockList *list);void guest_phys_blocks_append (GuestPhysBlockList *list);memory_mapping.c +45
-1@@ -186,6 +186,7 @@ void guest_phys_blocks_init(GuestPhysBlockList *list) { list->num =0 ;QTAILQ_INIT (&list->head); +QTAILQ_INIT (&list->head_mr); } typedef struct GuestPhysListener {@@ -193,6 +194,39 @@ typedef struct GuestPhysListener {MemoryListener listener; } GuestPhysListener; +static void guest_memory_region_add (GuestPhysBlockList *list, +MemoryRegion *mr) +{ +GuestMemoryRegion *gmr =NULL ; + QTAILQ_FOREACH(gmr, &list->head_mr, next) { +if (gmr->gmr_mr == mr) { +/* we already refererenced the MemoryRegion */ +return ; + } + } +/* reference the MemoryRegion to make sure it's valid during dump */ +#ifdef DEBUG_DUMP_GUEST_MEMORY +fprintf (stderr,"DUMP: ref mem region: %s\n" , mr->name); +#endif +memory_region_ref (mr); + gmr =g_malloc0 (sizeof (*gmr)); + gmr->gmr_mr = mr; +QTAILQ_INSERT_TAIL (&list->head_mr, gmr, next); +} + +void guest_memory_region_free (GuestPhysBlockList *list) +{ +GuestMemoryRegion *gmr =NULL , *q =NULL ; + QTAILQ_FOREACH_SAFE(gmr, &list->head_mr, next, q) { +#ifdef DEBUG_DUMP_GUEST_MEMORY +fprintf (stderr,"DUMP: unref mem region: %s\n" , gmr->gmr_mr->name); +#endif +QTAILQ_REMOVE (&list->head_mr, gmr, next); +memory_region_unref (gmr->gmr_mr); +g_free (gmr); + } +} +static void guest_phys_blocks_region_add (MemoryListener *listener,MemoryRegionSection *section) {@@ -241,6 +275,10 @@ static void guest_phys_blocks_region_add(MemoryListener *listener, block->target_end = target_end; block->host_addr = host_addr; +/* keep all the MemoryRegion that is referenced by the dump +* process */ +guest_memory_region_add (g->list, section->mr); +QTAILQ_INSERT_TAIL (&g->list->head, block, next); ++g->list->num; }else {@@ -250,7 +288,7 @@ static void guest_phys_blocks_region_add(MemoryListener *listener, predecessor->target_end = target_end; } -#ifdef DEBUG_GUEST_PHYS_REGION_ADD +#ifdef DEBUG_DUMP_GUEST_MEMORY fprintf (stderr,"%s: target_start=" TARGET_FMT_plx" target_end=" TARGET_FMT_plx": %s (count: %u)\n" , __FUNCTION__, target_start, target_end, predecessor ?"joined" :"added" , g->list->num);@@ -263,8 +301,14 @@ void guest_phys_blocks_append(GuestPhysBlockList *list) g.list = list; g.listener.region_add = &guest_phys_blocks_region_add; +/* We should make sure all the memory objects are valid during +* add dump regions. Before releasing it, we should also make +* sure all the MemoryRegions to be used during dump is +* referenced. */ +rcu_read_lock ();memory_listener_register (&g.listener, &address_space_memory);memory_listener_unregister (&g.listener); +rcu_read_unlock (); }static CPUState *find_paging_enabled_cpu (CPUState *start_cpu)qmp.c +14
-0@@ -102,6 +102,13 @@ void qmp_quit(Error **errp)void qmp_stop (Error **errp) { +/* if there is a dump in background, we should wait until the dump +* finished */ +if (dump_in_progress ()) { +error_setg (errp,"There is a dump in process, please wait." ); +return ; + } +if (runstate_check (RUN_STATE_INMIGRATE )) { autostart =0 ; }else {@@ -174,6 +181,13 @@ void qmp_cont(Error **errp)BlockBackend *blk;BlockDriverState *bs; +/* if there is a dump in background, we should wait until the dump +* finished */ +if (dump_in_progress ()) { +error_setg (errp,"There is a dump in process, please wait." ); +return ; + } +if (runstate_needs_reset ()) {error_setg (errp,"Resetting the Virtual Machine is required" );return ;
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
In reply to Paolo BonziniQuoted 13 lines · Paolo Bonzini
Quoted 10 lines · Peter Xu
If embed the mr pointer into GuestPhyBlock, then we might need to ref/unref one MemoryRegion for multiple times (and I am not sure how many, maybe it could be a very big number especially the MemoryRegionSections are scattered?). Not sure whether it is more efficient.
For what I see, the number of MemoryRegions should be not big (<5 in my case). So even with O(N^2), it should merely like O(N). Not sure about this too.
Quoted 5 lines
Quoted 2 lines
Would like to hear more review comments from Paolo and others.
Fam suggestion is a good one, ref'ing one MemoryRegion many times is not a problem.
Ok, then I will embed the MemoryRegion pointer into GuestPhysBlocks in v3.
Quoted 4 lines
Also I noticed now that you do the
dump_initin the main thread (using a listener), so the RCU lock/unlock is not needed. I don't know this code very well.
Yes, it's in main thread too in v1 patch, since I think that should not be the time consuming part. If so, I will remove the RCU lock/unlock too.
Quoted 3 lines
It's worth adding a comment at the top of functions that are called from a separate thread.
Ok. Will add that.
Thanks!
Peter
Quoted 4 lines
Thanks,
Paolo
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
In reply to Paolo BonziniQuoted 1 line · Paolo Bonzini
[snip]
Quoted 10 lines
dump.c cleanup: · line 1594
Quoted 7 lines
dump.c +7
-0+ +static GlobalDumpState *dump_state_get_global (void ) +{ +static bool init = false; +static GlobalDumpState global_dump_state; +if (unlikely (!init)) { +qemu_mutex_init (&global_dump_state.gds_mutex);The mutex is not necessary. The structure is always created in the main thread and released by the dump thread (of which there is just one).
[1]
Quoted 6 lines
You can then just make a global DumpState (not a pointer!), and separate the fields between:
- those that are protected by a mutex (most likely the DumpResult and
written_size, possibly others)
Hi, Paolo,
So mutex is still necessary, right? (refer to [1]) Since "dump-query" will read several fields of it, while the dump thread might be modifying them as well?
Quoted 31 lines
- those that are only written before the thread is started, and thus do not need to be protected by a mutex
- those that are only accessed by the thread, and thus do not need to be protected by a mutex either.
See for example this extract from
migration/block.c:typedef struct BlkMigState { /* Written during setup phase. Can be read without a lock. */ int blk_enable; int shared_base; QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list; int64_t total_sector_sum; bool zero_blocks; /* Protected by lock. */ QSIMPLEQ_HEAD(blk_list, BlkMigBlock) blk_list; int submitted; int read_done; /* Only used by migration thread. Does not need a lock. */ int transferred; int prev_progress; int bulk_completed; /* The lock. */ QemuMutex lock; } BlkMigState;
Quoted 1 line
static BlkMigState
block_mig_state;
Ok, I think I can remove the global state and make a static DumpState. When I was drafting the patch, I just tried to keep the old logic (malloc/free) and avoid introducing bugs. Maybe I was wrong. I should better not introduce new struct if not necessary.
Will try to follow this example in v3.
Thanks.
Peter
Quoted 3 lines
Paolo
Re: [Qemu-devel] [PATCH v2 4/8] dump-guest-memory: add qmp event DUMP_COMPLETED
In reply to Paolo BonziniQuoted 16 lines · Paolo Bonzini
qapi/event.json line 368
Quoted 9 lines · Peter Xu
qapi/event.json +9
-0+## +# @DUMP_COMPLETED +# +# Emitted when background dump has completed +# +# Since: 2.6 +## +{ 'event': 'DUMP_COMPLETED' , + 'data': { 'msg': 'str' } }This makes it hard to understand whether there was an error or not. I suggest using '*error': 'str' instead, and omitting the error if the dump is successful.
Will adopt it. Thanks!
Peter
Quoted 2 lines
Paolo
Re: [Qemu-devel] [PATCH v2 5/8] dump-query: add "dump-query" command to query dump status
In reply to Paolo BonziniQuoted 9 lines · Paolo Bonzini
Quoted 6 lines · Peter Xu
Quoted 5 lines
qapi-schema.json line 2149
Quoted 2 lines
qapi-schema.json +2
-0+{ 'struct': 'DumpStatus', + 'data': { 'status': 'str', 'percentage': 'str' } }I suggest using enum for "status" and int for "percentage" (or two ints for "total" and "current").
Quoted 8 lines
Quoted 3 lines
Yes, I picked string just for flexibility. Regarding to this interface issue, I'd like to wait for others' comments too before modification.
I like Fam's idea of using an enum and two ints.
Also, the command should be named query-dump and the corresponding HMP command should be "info dump" (by defining "dump" in
hmp-commands-info.h".
Ok, will change in v3.
Thanks.
Peter
Quoted 2 lines
Paolo
Re: [Qemu-devel] [PATCH v2 6/8] dump-query: implement "status" of "dump-query" command.
In reply to Paolo BonziniQuoted 15 lines · Paolo Bonzini
Quoted 12 lines · Peter Xu
This patch implements the status changes inside dump process. When query dump status, three possible results could be:
1. never started dump:
{ "status": "NOT_STARTED", "percentage": "N/A" }2. one dump is running in background:
{ "status": "IN_PROGRESS", "percentage": "{0..100}%" }3. no dump is running, and the last dump has finished:
{ "status": "SUCCEEDED|FAILED", "percentage": "N/A" }
Quoted 7 lines
Quoted 2 lines
It's mostly done. Except that we might need more accurate "percentage" results (which is now 50% all the time!).
As mentioned early, you can use an enum. QEMU usually prints enums in lowercase and separates words with "-". Similar to MigrationStatus you can use none, active, completed, failed. In fact you might even reuse MigrationStatus directly, it's simpler.
I think it might be a little big confusing if I use MigrationStatus directly. I can define a enum.
Quoted 3 lines
The percentage is not necessary as part of the QMP return value. You can compute it in
hmp_info_dumphowever and print it to HMP only.
Ok, Then I will drop percentage in QMP query.
Quoted 10 lines
I think you can structure the patches like this:
add basic "detach" support
add qmp eventDUMP_COMPLETED
addtotal_sizeandwritten_sizeto DumpState
add "query-dump" QMP command
add "info dump" HMP commandwhere the fourth patch already sets all fields correctly.
Ok. Will reorder the patches and make sure there are no fake values any more.
Thanks!
Peter
Quoted 190 lines
Thanks,
Paolo
Quoted 185 lines
Signed-off-by Peter Xu <[email protected]>--- dump.c | 57 +++++++++++++++++++++++++++++++++++++++++++-------- hmp.c | 7 +++++-- include/qemu-common.h | 4 ++++ include/sysemu/dump.h | 13 ++++++++++-- 4 files changed, 68 insertions(+), 13 deletions(-)dump.c +48
-9@@ -1594,11 +1594,44 @@ static GlobalDumpState *dump_state_get_global(void)if (unlikely (!init)) {qemu_mutex_init (&global_dump_state.gds_mutex); global_dump_state.gds_cur =NULL ; + global_dump_state.gds_result =DUMP_RES_NOT_STARTED ; init = true; }return &global_dump_state; } +static const char *const dump_result_table[] = { + [DUMP_RES_NOT_STARTED ] ="NOT_STARTED" , + [DUMP_RES_IN_PROGRESS ] ="IN_PROGRESS" , + [DUMP_RES_SUCCEEDED ] ="SUCCEEDED" , + [DUMP_RES_FAILED ] ="FAILED" , +}; + +/* Returns DumpStatus. Caller should be responsible to free the +* resources using qapi_free_DumpStatus(). */ +DumpStatus *dump_status_query (void ) +{ +DumpStatus *status =g_malloc0 (sizeof (*status)); +int percentage =50 ; +char buf[64 ] = {0 }; + +GlobalDumpState *global =dump_state_get_global (); +qemu_mutex_lock (&global->gds_mutex); + +/* TBD: get correct percentage */ + status->status =g_strdup (dump_result_table[global->gds_result]); +if (global->gds_result ==DUMP_RES_IN_PROGRESS ) { +snprintf (buf,sizeof (buf) -1 ,"%d%%" , percentage); + status->percentage =g_strdup (buf); + }else { + status->percentage =g_strdup ("N/A" ); + } + +qemu_mutex_unlock (&global->gds_mutex); + +return status; +} +/* Returns non-zero if there is existing dump in progress, otherwise * zero is returned. */ bool dump_in_progress (void )@@ -1620,27 +1653,37 @@ static DumpState *dump_state_create(GlobalDumpState *global) cur = global->gds_cur;if (cur) {/* one dump in progress */ +assert (global->gds_result ==DUMP_RES_IN_PROGRESS ); cur =NULL ; }else {/* we are the first! */ +assert (global->gds_result !=DUMP_RES_IN_PROGRESS ); cur =g_malloc0 (sizeof (*cur)); global->gds_cur = cur; } + global->gds_result =DUMP_RES_IN_PROGRESS ;qemu_mutex_unlock (&global->gds_mutex);return cur; } -/* release current DumpState structure */ -static void dump_state_release (GlobalDumpState *global) +/* release current DumpState structure. "done" is hint to show +* whether the dump is succeeded or not. */ +static void dump_state_release (GlobalDumpState *global,bool done) {DumpState *cur =NULL ;qemu_mutex_lock (&global->gds_mutex); +assert (global->gds_result ==DUMP_RES_IN_PROGRESS ); cur = global->gds_cur;/* we should never call release before having one */ assert (cur); global->gds_cur =NULL ; +if (done) { + global->gds_result =DUMP_RES_SUCCEEDED ; + }else { + global->gds_result =DUMP_RES_FAILED ; + }qemu_mutex_unlock (&global->gds_mutex);dump_cleanup (cur);@@ -1664,7 +1707,7 @@ static void *dump_thread(void *data)const char *msg ="Dump completed successfully" ;dump_process (global->gds_cur, &local_err); -dump_state_release (global); +dump_state_release (global, (local_err ==NULL ));/* if detach is used, notify user that dump has finished */ if (local_err) {@@ -1769,7 +1812,7 @@ void qmp_dump_guest_memory(bool paging, const char *file,if (!detach_p) {/* sync dump */ dump_process (s, errp); -dump_state_release (global); +dump_state_release (global, (*errp ==NULL )); }else {qemu_thread_create (&s->dump_thread,"dump_thread" , dump_thread, global,QEMU_THREAD_DETACHED );@@ -1779,11 +1822,7 @@ void qmp_dump_guest_memory(bool paging, const char *file,DumpStatus *qmp_dump_query (Error **errp) { -DumpStatus *status =g_malloc0 (sizeof (*status)); -/* TBD */ - status->status =g_strdup ("WORKING" ); - status->percentage =g_strdup ("50%" ); -return status; +return dump_status_query (); }DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability (Error **errp)hmp.c +5
-2@@ -1578,8 +1578,11 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)void hmp_dump_query (Monitor *mon,const QDict *qdict) { -/* TBD */ -monitor_printf (mon,"QUERY DUMP STATUS\n" ); +DumpStatus *status =dump_status_query (); +assert (status); +monitor_printf (mon,"STATUS: %s\n" , status->status); +monitor_printf (mon,"PERCENTAGE: %s\n" , status->percentage); +qapi_free_DumpStatus (status); }void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict)include/qemu-common.h +4
-0@@ -505,4 +505,8 @@ void page_size_init(void);* returned. */ bool dump_in_progress (void ); +/* Returns DumpStatus. Caller should be responsible to free the +* resources using qapi_free_DumpStatus(). */ +DumpStatus *dump_status_query (void ); +#endif include/sysemu/dump.h +11
-2@@ -189,9 +189,18 @@ typedef struct DumpState {DumpGuestMemoryFormat format;/* valid only if has_format == true */ } DumpState; +typedef enum DumpResult { +DUMP_RES_NOT_STARTED =0 , +DUMP_RES_IN_PROGRESS , +DUMP_RES_SUCCEEDED , +DUMP_RES_FAILED , +DUMP_RES_MAX , +}DumpResult ; +typedef struct GlobalDumpState { -QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ -DumpState *gds_cur;/* current DumpState (might be NULL) */ +QemuMutex gds_mutex;/* protector for GlobalDumpState itself */ +DumpState *gds_cur;/* current DumpState (might be NULL) */ +DumpResult gds_result;/* current dump result */ }GlobalDumpState ;uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
In reply to Peter XuQuoted 22 lines · Peter Xu
Quoted 1 line · Paolo Bonzini
[snip]
Quoted 10 lines
dump.c cleanup: · line 1594
Quoted 7 lines
dump.c +7
-0+ +static GlobalDumpState *dump_state_get_global (void ) +{ +static bool init = false; +static GlobalDumpState global_dump_state; +if (unlikely (!init)) { +qemu_mutex_init (&global_dump_state.gds_mutex);The mutex is not necessary. The structure is always created in the main thread and released by the dump thread (of which there is just one).
[1]
Quoted 4 lines
You can then just make a global DumpState (not a pointer!), and separate the fields between:
Quoted 8 lines
Quoted 2 lines
- those that are protected by a mutex (most likely the DumpResult and
written_size, possibly others)Hi, Paolo,
So mutex is still necessary, right? (refer to [1]) Since "dump-query" will read several fields of it, while the dump thread might be modifying them as well?
Right, initially I meant a mutex around the allocation. But then I read the other patches where you add more fields, and came back to add more content.
Strictly speaking it's likely that you can do everything without a mutex, but it's easier to use one.
Quoted 4 lines
Ok, I think I can remove the global state and make a static DumpState. When I was drafting the patch, I just tried to keep the old logic (malloc/free) and avoid introducing bugs. Maybe I was wrong. I should better not introduce new struct if not necessary.
It's okay. The only confusing bit was that you had to add more state to GlobalDumpState, and in the end it was split between DumpState and GlobalDumpState. As far as this patch is concerned, using malloc/free would have been okay, but then the subsequent changes suggest a different approach.
Thanks!
Paolo
Quoted 10 lines
Will try to follow this example in v3.
Thanks.
PeterQuoted 3 lines
Paolo
Re: [Qemu-devel] [PATCH v2 6/8] dump-query: implement "status" of "dump-query" command.
In reply to Peter XuQuoted 7 lines · Peter Xu
Quoted 4 lines
As mentioned early, you can use an enum. QEMU usually prints enums in lowercase and separates words with "-". Similar to MigrationStatus you can use none, active, completed, failed. In fact you might even reuse MigrationStatus directly, it's simpler.
I think it might be a little big confusing if I use MigrationStatus directly. I can define a enum.
Sure, that's fine. Though there is more than a little similarity between migration and dump... (essentially, migration is a dump with a custom format and with additional support for storing device state).
Paolo
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
In reply to Fam ZhengQuoted 1 line · Fam Zheng
On Fri, 11/27 10:48, Peter Xu wrote:
[snip]
Quoted 4 lines
This patch doesn't handle the incoming migration case, i.e. when QEMU is started with "-incoming", or "-incoming defer". Dump can go wrong when incoming migration happens at the same time.
Sorry to missed these lines. Still not understand why this patch cannot handle this if with [1] (Please check below for [1])?
[snip]
Quoted 5 lines
Quoted 2 lines
+extern GlobalDumpState
global_dump_state;
dump_state_get_global()returns a pointer to the local static variable, why do you need this?
Yes, I should remove that. Thanks!
[snip]
Quoted 9 lines
dump.c void qmp_dump_guest_memory(bool paging, const char *file, · line 1680
Quoted 9 lines
dump.c +5
-0+@@ -1590,6 +1674,14 @@ void qmp_dump_guest_memory(bool paging, const char *file,int fd =-1 ;DumpState *s;Error *local_err =NULL ; +/* by default, we are keeping the old style, which is sync dump */ +bool detach_p = false; +GlobalDumpState *global =dump_state_get_global (); +
[1]
Quoted 4 lines
dump.c void qmp_dump_guest_memory(bool paging, const char *file, · line 1684
Quoted 4 lines
dump.c +4
-0+if (runstate_check (RUN_STATE_INMIGRATE )) { +error_setg (errp,"Dump not allowed during incoming migration." ); +return ; + }
Thanks.
Peter
Re: [Qemu-devel] [PATCH v2 3/8] dump-guest-memory: add basic "detach" support.
Quoted 6 lines · Peter Xu
Quoted 1 line · Fam Zheng
On Fri, 11/27 10:48, Peter Xu wrote:
[snip]
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
This patch doesn't handle the incoming migration case, i.e. when QEMU is started with "-incoming", or "-incoming defer". Dump can go wrong when incoming migration happens at the same time.
Sorry to missed these lines. Still not understand why this patch cannot handle this if with [1] (Please check below for [1])?
You're right, that does work. I missed that "defer" also sets RUN_STATE_INMIGRATE.
Fam
Re: [Qemu-devel] [PATCH v2 4/8] dump-guest-memory: add qmp event DUMP_COMPLETED
In reply to Peter XuQuoted 4 lines · Peter Xu
To get aligned with QMP interface, one new QMP event
DUMP_COMPLETEDis added. It is used when user specified "detach" in dump, and triggered when the dump finishes. Error message will be appended to this event if the dump has failed.
Why not emit the new event unconditionally, instead of only when detach was specified?
Quoted 13 lines
Signed-off-by Peter Xu <[email protected]>--- docs/qmp-events.txt | 12 ++++++++++++ dump.c | 12 +++++++++++- qapi/event.json | 10 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)docs/qmp-events.txt +0
-0
docs/qmp-events.txt Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is · line 683
Quoted 10 lines
docs/qmp-events.txt +7
-0@@ -674,3 +674,15 @@ Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is followed respectively by the RESET, SHUTDOWN, or STOP events. Note: this event is rate-limited. + +DUMP_COMPLETED +-------------- + +Emitted when the guest has finished one memory dump. + +Data: None.
Wrong - you have 'msg' as data. Except that Paolo is right, 'msg' should be optional, and only present on error. You should also document that the contents of 'msg' are for human consumption and should not be machine-parsed (basically, only the presence of absence of 'msg' is useful for machines).
Quoted 9 lines
docs/qmp-events.txt +5
-0+ +Example: + +{ "event": "DUMP_COMPLETED", + "data": { "msg": "Dump completed successfully" } }dump.c +1
-0+++ b/qapi/event.json
dump.c line 364
Quoted 9 lines
dump.c +6
-0@@ -356,3 +356,13 @@ ## { 'event': 'MEM_UNPLUG_ERROR', 'data': { 'device': 'str', 'msg': 'str' } } + +## +# @DUMP_COMPLETED +# +# Emitted when background dump has completed +#
Missing documentation of 'msg', which should be optional.
Quoted 5 lines
dump.c +4
-0+# Since : 2.6 +## +{ 'event': 'DUMP_COMPLETED' , + 'data': { 'msg': 'str' } }
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 2/8] dump-guest-memory: add "detach" flag for QMP/HMP interfaces.
In reply to Peter XuQuoted 1 line · Peter Xu
This patch only adds the interfaces, but not implements them.
s/not implements/does not implement/
Quoted 5 lines
"detach" parameter is made optional, to make sure that all the old dump-guest-memory requests will still be able to work.
Signed-off-by Peter Xu <[email protected]>---
In addition to Fam's comments,
qapi-schema.json line 2119
Quoted 7 lines
+++
b/qapi-schema.jsonqapi-schema.json +2
-0@@ -2115,6 +2115,9 @@ # 2. fd: the protocol starts with "fd:", and the following string # is the fd's name. # +# @detach: #optional if true, QMP will return immediately rather than +# waiting dump to be finished (since 2.6).
s/waiting/waiting for the/
s/be finished/finish/
Quoted 13 lines
qmp-commands.hx +3
-2+++ b/qmp-commands.hx@@ -840,8 +840,8 @@ EQMP { .name = "dump-guest-memory", - .args_type = "paging:b,protocol:s,begin:i?,end:i?,format:s?", - .params = "-p protocol [begin] [length] [format]", + .args_type = "paging:b,protocol:s,detach:b?,begin:i?,end:i?,format:s?", + .params = "-p protocol [-d] [begin] [length] [format]", .help = "dump guest memory to file", .mhandler.cmd_new = qmp_marshal_dump_guest_memory, },
qmp-commands.hx Arguments: · line 860
Quoted 4 lines
qmp-commands.hx +1
-0@@ -857,6 +857,8 @@ Arguments: - "paging": do paging to get guest's memory mapping (json-bool) - "protocol": destination file(started with "file:") or destination file descriptor (started with "fd:") (json-string) +- "detach": if specificed, command will return immediately, without waiting
s/specificed/specified/
qmp-commands.hx Arguments: · line 861
Quoted 1 line
qmp-commands.hx +1
-0+ for dump to be finished (json-bool)
s/dump to be finished/the dump to finish/
Quoted 4 lines
qmp-commands.hx +0
-0- "begin": the starting physical address. It's optional, and should be specified with length together (json-int) - "length": the memory size, in bytes. It's optional, and should be specified
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 5/8] dump-query: add "dump-query" command to query dump status
In reply to Peter XuQuoted 6 lines · Peter Xu
This patch is only adding the QMP/HMP interface for "dump-query" command, but not implementing them. This command could be used to query background dump status. Please refer to the next patch to see how dump status are defined.
Currently, only fake results are returned.
Feels a bit awkward to return fake results; maybe you should squash some patches together or fail with an error instead of returning fake results.
Quoted 14 lines
Signed-off-by Peter Xu <[email protected]>--- dump.c | 9 +++++++++ hmp-commands.hx | 15 +++++++++++++++ hmp.c | 6 ++++++ hmp.h | 1 + qapi-schema.json | 21 +++++++++++++++++++++ qmp-commands.hx | 29 ++++++++++++++++++++++++++++- 6 files changed, 80 insertions(+), 1 deletion(-)+++
b/qapi-schema.json
qapi-schema.json line 2145
Quoted 7 lines
qapi-schema.json +4
-0@@ -2139,6 +2139,27 @@ '*format': 'DumpGuestMemoryFormat'} } ## +# @DumpStatus +# +# Status for the last guest memory dump. +#
Missing documentation for 'status' and 'percentage' fields.
qapi-schema.json line 2149
Quoted 4 lines
qapi-schema.json +4
-0+# Since: 2.6 +## +{ 'struct': 'DumpStatus', + 'data': { 'status': 'str', 'percentage': 'str' } }
What values will 'status' contain? If it is a finite set of status strings, then it should be an enum type.
'percentage' should NOT be a string. It should probably be numeric; 'number' if you intend to return a floating point value between 0 and 1.
Or, like other interfaces, you should probably return two numbers
(current and total, both 'int'), and let the caller compute percentage themselves.
qapi-schema.json line 2152
Quoted 3 lines
qapi-schema.json +3
-0+ +## +# @dump-query
Most query commands are named 'query-FOO', not 'FOO-query'. Unless you have a compelling reason otherwise, this should be 'query-dump'.
Quoted 12 lines
qmp-commands.hx +11
-0+# +# Query latest dump status. +# +# Returns: A @DumpStatus object showing the dump status. +# +# Since: 2.6 +## +{ 'command': 'dump-query', 'returns': 'DumpStatus' } + +SQMP +dump-query
qmp-commands.hx Notes: · line 900
Quoted 10 lines
qmp-commands.hx +10
-0+---------- + +Query background dump status. + +Arguments: None. + +Example: + +-> { "execute": "dump-query" } +<- { "return": {"status": "IN_PROGRESS", "percentage": "85%" } }
ALL_CAPS status is annoying to read; if you add an enum type, it should be 'lower-case' values.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 2/8] dump-guest-memory: add "detach" flag for QMP/HMP interfaces.
In reply to Eric BlakeQuoted 44 lines · Eric Blake
Quoted 1 line · Peter Xu
This patch only adds the interfaces, but not implements them.
s/not implements/does not implement/
Quoted 5 lines
"detach" parameter is made optional, to make sure that all the old dump-guest-memory requests will still be able to work.
Signed-off-by Peter Xu <[email protected]>---
In addition to Fam's comments,
qapi-schema.json line 2119
Quoted 7 lines
+++
b/qapi-schema.jsonqapi-schema.json +2
-0@@ -2115,6 +2115,9 @@ # 2. fd: the protocol starts with "fd:", and the following string # is the fd's name. # +# @detach: #optional if true, QMP will return immediately rather than +# waiting dump to be finished (since 2.6).s/waiting/waiting for the/
s/be finished/finish/Quoted 13 lines
qmp-commands.hx +3
-2+++ b/qmp-commands.hx@@ -840,8 +840,8 @@ EQMP { .name = "dump-guest-memory", - .args_type = "paging:b,protocol:s,begin:i?,end:i?,format:s?", - .params = "-p protocol [begin] [length] [format]", + .args_type = "paging:b,protocol:s,detach:b?,begin:i?,end:i?,format:s?", + .params = "-p protocol [-d] [begin] [length] [format]", .help = "dump guest memory to file", .mhandler.cmd_new = qmp_marshal_dump_guest_memory, },qmp-commands.hx Arguments: · line 860
Quoted 4 lines
qmp-commands.hx +1
-0@@ -857,6 +857,8 @@ Arguments: - "paging": do paging to get guest's memory mapping (json-bool) - "protocol": destination file(started with "file:") or destination file descriptor (started with "fd:") (json-string) +- "detach": if specificed, command will return immediately, without waitings/specificed/specified/
Quoted 3 lines
qmp-commands.hx Arguments: · line 861
Quoted 1 line
qmp-commands.hx +1
-0+ for dump to be finished (json-bool)s/dump to be finished/the dump to finish/
Thanks for the corrections. These errors exist in v3 too. Will fix them in v4.
Peter
Quoted 10 lines
Quoted 5 lines
qmp-commands.hx +0
-0- "begin": the starting physical address. It's optional, and should be specified with length together (json-int) - "length": the memory size, in bytes. It's optional, and should be specifiedSignature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 4/8] dump-guest-memory: add qmp event DUMP_COMPLETED
In reply to Eric BlakeQuoted 8 lines · Eric Blake
Quoted 4 lines · Peter Xu
To get aligned with QMP interface, one new QMP event
DUMP_COMPLETEDis added. It is used when user specified "detach" in dump, and triggered when the dump finishes. Error message will be appended to this event if the dump has failed.Why not emit the new event unconditionally, instead of only when detach was specified?
I was just trying to make sure that dump will work exactly as it is when detach is not used. Yes, I think I could emit it unconditionally if libvirt does not complain about it. :)
Quoted 16 lines
Quoted 16 lines
Signed-off-by Peter Xu <[email protected]>--- docs/qmp-events.txt | 12 ++++++++++++ dump.c | 12 +++++++++++- qapi/event.json | 10 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)docs/qmp-events.txt +0
-0@@ -674,3 +674,15 @@ Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is followed respectively by the RESET, SHUTDOWN, or STOP events.
Quoted 14 lines
docs/qmp-events.txt Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is · line 683
Quoted 8 lines
docs/qmp-events.txt +7
-0Note: this event is rate-limited. + +DUMP_COMPLETED +-------------- + +Emitted when the guest has finished one memory dump. + +Data: None.Wrong - you have 'msg' as data. Except that Paolo is right, 'msg' should be optional, and only present on error. You should also document that the contents of 'msg' are for human consumption and should not be machine-parsed (basically, only the presence of absence of 'msg' is useful for machines).
I will make sure v4 contains these suggestions. Thanks.
Quoted 8 lines
Quoted 7 lines
docs/qmp-events.txt +5
-0+ +Example: + +{ "event": "DUMP_COMPLETED", + "data": { "msg": "Dump completed successfully" } }dump.c +0
-0
Quoted 13 lines
dump.c line 364
Quoted 11 lines
+++
b/qapi/event.jsondump.c +6
-0@@ -356,3 +356,13 @@ ## { 'event': 'MEM_UNPLUG_ERROR', 'data': { 'device': 'str', 'msg': 'str' } } + +## +# @DUMP_COMPLETED +# +# Emitted when background dump has completed +#Missing documentation of 'msg', which should be optional.
Sorry I missed that. Thanks to point out!
Peter
Quoted 11 lines
Quoted 6 lines
dump.c +4
-0+# Since : 2.6 +## +{ 'event': 'DUMP_COMPLETED' , + 'data': { 'msg': 'str' } }Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 5/8] dump-query: add "dump-query" command to query dump status
In reply to Eric BlakeQuoted 10 lines · Eric Blake
Quoted 6 lines · Peter Xu
This patch is only adding the QMP/HMP interface for "dump-query" command, but not implementing them. This command could be used to query background dump status. Please refer to the next patch to see how dump status are defined.
Currently, only fake results are returned.
Feels a bit awkward to return fake results; maybe you should squash some patches together or fail with an error instead of returning fake results.
Yes, sorry for that. This was pointed out by Paolo and it's fixed in v3.
Quoted 17 lines
Quoted 17 lines
Signed-off-by Peter Xu <[email protected]>--- dump.c | 9 +++++++++ hmp-commands.hx | 15 +++++++++++++++ hmp.c | 6 ++++++ hmp.h | 1 + qapi-schema.json | 21 +++++++++++++++++++++ qmp-commands.hx | 29 ++++++++++++++++++++++++++++- 6 files changed, 80 insertions(+), 1 deletion(-)+++
b/qapi-schema.jsonqapi-schema.json +0
-0@@ -2139,6 +2139,27 @@ '*format': 'DumpGuestMemoryFormat'} }
Quoted 7 lines
qapi-schema.json line 2145
Quoted 5 lines
qapi-schema.json +4
-0## +# @DumpStatus +# +# Status for the last guest memory dump. +#Missing documentation for 'status' and 'percentage' fields.
Yes. Fixed in v3. Thanks!
Quoted 9 lines
qapi-schema.json line 2149
Quoted 5 lines
qapi-schema.json +4
-0+# Since: 2.6 +## +{ 'struct': 'DumpStatus', + 'data': { 'status': 'str', 'percentage': 'str' } }What values will 'status' contain? If it is a finite set of status strings, then it should be an enum type.
Quoted 5 lines
'percentage' should NOT be a string. It should probably be numeric; 'number' if you intend to return a floating point value between 0 and 1.
Or, like other interfaces, you should probably return two numbers
(current and total, both 'int'), and let the caller compute percentage themselves.
Sorry for the old unclear API. Now it contains:
- status: enum
- written_bytes: int
- total_bytes: int
These were modified in v3 (as Fam & Paolo suggested). Thanks!
Quoted 7 lines
qapi-schema.json line 2152
Quoted 4 lines
qapi-schema.json +3
-0+ +## +# @dump-queryMost query commands are named 'query-FOO', not 'FOO-query'. Unless you have a compelling reason otherwise, this should be 'query-dump'.
Changed in v3.
Quoted 11 lines
Quoted 10 lines
qapi-schema.json +9
-0+# +# Query latest dump status. +# +# Returns: A @DumpStatus object showing the dump status. +# +# Since: 2.6 +## +{ 'command': 'dump-query', 'returns': 'DumpStatus' } +
Quoted 15 lines
qmp-commands.hx Notes: · line 900
Quoted 12 lines
qmp-commands.hx +12
-0+SQMP +dump-query +---------- + +Query background dump status. + +Arguments: None. + +Example: + +-> { "execute": "dump-query" } +<- { "return": {"status": "IN_PROGRESS", "percentage": "85%" } }
ALL_CAPSstatus is annoying to read; if you add an enum type, it should be 'lower-case' values.
Changed in v3.
Thanks!
Peter
Quoted 5 lines
Signature · 3 lines
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org