dump: Minor fixes & improvements
v2 cover dump: Minor fixes & improvements
v2:
* PATCH 2: Use g_clear_pointer() [Marc-André]
* PATCH 4: Avoid QERR_INVALID_PARAMETER_VALUE [Philippe]. Replace qemu_open_old() by qemu_create().
Markus Armbruster (5):
dump: Rename qmp_dump_guest_memory() parameter to match QAPI schema
dump: Fix g_array_unref(NULL) in dump-guest-memory
dump: Recognize "fd:" protocols on Windows hosts
dump: Improve some dump-guest-memory error messages
dump: Drop redundant check for empty dump
dump/dump.c | 59 +++++++++++++---------------------------------------- 1 file changed, 14 insertions(+), 45 deletions(-)
Signature · 1 line
2.41.0
PATCH v2 1/5 dump: Rename qmp_dump_guest_memory() parameter to match QAPI schema
The name of the second parameter differs between QAPI schema and C
implementation: it's @protocol in the former and @file in the latter. Potentially confusing. Change the C implementation to match the QAPI schema.
--- dump/dump.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
dump/dump.c +7 -6
@@ -2061,11 +2061,12 @@ DumpQueryResult *qmp_query_dump(Error **errp)return result; } -void qmp_dump_guest_memory (bool paging,const char *file, +void qmp_dump_guest_memory (bool paging,const char *protocol,bool has_detach,bool detach, -bool has_begin,int64_t begin,bool has_length, -int64_t length,bool has_format, -DumpGuestMemoryFormat format,Error **errp) +bool has_begin,int64_t begin, +bool has_length,int64_t length, +bool has_format,DumpGuestMemoryFormat format, +Error **errp) {ERRP_GUARD ();const char *p;
@@ -2128,7 +2129,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, }#if !defined(WIN32 ) -if (strstart (file,"fd:" , &p)) { +if (strstart (protocol,"fd:" , &p)) { fd =monitor_get_fd (monitor_cur (), p, errp);if (fd ==-1 ) {return ;
@@ -2136,7 +2137,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, }#endif -if (strstart (file,"file:" , &p)) { +if (strstart (protocol,"file:" , &p)) { fd =qemu_open_old (p,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,S_IRUSR );if (fd <0 ) {error_setg_file_open (errp, errno, p);
Signature · 1 line
2.41.0
PATCH v2 2/5 dump: Fix g_array_unref(NULL) in dump-guest-memory
In reply to Markus ArmbrusterWhen dump_init()'s check for non-zero @length fails, dump_cleanup() passes null s->string_table_buf to g_array_unref(), which spews "GLib:g_array_unref: assertion 'array' failed" to stderr.
Guard the g_array_unref().
--- dump/dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
dump/dump.c +1 -1
@@ -100,7 +100,7 @@ static int dump_cleanup(DumpState *s)memory_mapping_list_free (&s->list);close (s->fd);g_free (s->guest_note); -g_array_unref (s->string_table_buf); +g_clear_pointer (&s->string_table_buf, g_array_unref); s->guest_note =NULL ;if (s->resume) {if (s->detached) {
Signature · 1 line
2.41.0
PATCH v2 3/5 dump: Recognize "fd:" protocols on Windows hosts
In reply to Markus ArmbrusterA few QMP command can work with named file descriptors.
The only way to create a named file descriptor used to be QMP command getfd, which only works on POSIX hosts. Thus, named file descriptors were actually usable only there.
They became usable on Windows hosts when we added QMP command get-win32-socket (commit 4cda177c601 "qmp: add 'get-win32-socket'").
Except in dump-guest-memory, because qmp_dump_guest_memory() compiles its named file descriptor code only #if !defined(WIN32).
Compile it unconditionally, like we do for the other commands supporting them.
--- dump/dump.c | 2 -- 1 file changed, 2 deletions(-)
dump/dump.c +0 -2
@@ -2128,14 +2128,12 @@ void qmp_dump_guest_memory(bool paging, const char *protocol,return ; } -#if !defined(WIN32 )if (strstart (protocol,"fd:" , &p)) { fd =monitor_get_fd (monitor_cur (), p, errp);if (fd ==-1 ) {return ; } } -#endif if (strstart (protocol,"file:" , &p)) { fd =qemu_open_old (p,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,S_IRUSR );
Signature · 1 line
2.41.0
PATCH v2 4/5 dump: Improve some dump-guest-memory error messages
In reply to Markus ArmbrusterZero @length is rejected with "Invalid parameter 'length'". Improve to "parameter 'length' expects a non-zero length".
qemu_open_old() is a wrapper around qemu_open_internal() that throws away error information. Switch to the wrapper that doesn't:qemu_create(). Example improvement:
(qemu) dump-guest-memory /dev/fdset/x 0 1
Error: Could not open '/dev/fdset/x': Invalid argument
becomes
Error: Could not parse fdset /dev/fdset/x
@protocol values not starting with "fd:" or "file:" are rejected with "Invalid parameter 'protocol'". Improve to "parameter 'protocol' must start with 'file:' or 'fd:'".
While there, make the conditional checking @protocol a little more obvious.
--- dump/dump.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
dump/dump.c +7 -11
@@ -1810,7 +1810,7 @@ static void dump_init(DumpState *s, int fd, bool has_format, s->fd = fd;if (has_filter && !length) { -error_setg (errp,QERR_INVALID_PARAMETER ,"length" ); +error_setg (errp,"parameter 'length' expects a non-zero size" ); goto cleanup; } s->filter_area_begin = begin;
@@ -2070,7 +2070,7 @@ void qmp_dump_guest_memory(bool paging, const char *protocol, {ERRP_GUARD ();const char *p; -int fd =-1 ; +int fd;DumpState *s;bool detach_p = false;
@@ -2133,18 +2133,14 @@ void qmp_dump_guest_memory(bool paging, const char *protocol,if (fd ==-1 ) {return ; } - } - -if (strstart (protocol,"file:" , &p)) { - fd =qemu_open_old (p,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,S_IRUSR ); + }else if (strstart (protocol,"file:" , &p)) { + fd =qemu_create (p,O_WRONLY |O_TRUNC |O_BINARY ,S_IRUSR , errp);if (fd <0 ) { -error_setg_file_open (errp, errno, p);return ; } - } - -if (fd ==-1 ) { -error_setg (errp,QERR_INVALID_PARAMETER ,"protocol" ); + }else { +error_setg (errp, +"parameter 'protocol' must start with 'file:' or 'fd:'" );return ; }
Signature · 1 line
2.41.0
PATCH v2 5/5 dump: Drop redundant check for empty dump
In reply to Markus Armbrusterdump_init() first computes the size of the dump, taking the filter area into account, and fails if its zero. It then looks for memory in the filter area, and fails if there is none.
This is redundant: if the size of the dump is zero, there is no memory, and vice versa. Delete this check.
--- dump/dump.c | 26 -------------------------- 1 file changed, 26 deletions(-)
dump/dump.c +0 -26
@@ -1672,26 +1672,6 @@ static void create_kdump_vmcore(DumpState *s, Error **errp) } } -static int validate_start_block (DumpState *s) -{ -GuestPhysBlock *block; - -if (!dump_has_filter (s)) { -return 0 ; - } - - QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { -/* This block is out of the range */ -if (block->target_start >= s->filter_area_begin + s->filter_area_length || - block->target_end <= s->filter_area_begin) { -continue ; - } -return 0 ; - } - -return -1 ; -} -static void get_max_mapnr (DumpState *s) {GuestPhysBlock *last_block;
@@ -1839,12 +1819,6 @@ static void dump_init(DumpState *s, int fd, bool has_format, goto cleanup; } -/* Is the filter filtering everything? */ -if (validate_start_block (s) ==-1 ) { -error_setg (errp,QERR_INVALID_PARAMETER ,"begin" ); - goto cleanup; - } -/* get dump info: endian, class and architecture. * If the target architecture is not supported, cpu_get_dump_info() will * return -1.
Signature · 1 line
2.41.0