* [PATCH v2 1/5] dump: Rename qmp_dump_guest_memory() parameter to match QAPI schema
2023-10-31 10:45 [PATCH v2 0/5] dump: Minor fixes & improvements Markus Armbruster
@ 2023-10-31 10:45 ` Markus Armbruster
2023-10-31 10:45 ` [PATCH v2 2/5] dump: Fix g_array_unref(NULL) in dump-guest-memory Markus Armbruster
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2023-10-31 10:45 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, philmd
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.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
dump/dump.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/dump/dump.c b/dump/dump.c
index d355ada62e..a1fad17f9c 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -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);
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/5] dump: Fix g_array_unref(NULL) in dump-guest-memory
2023-10-31 10:45 [PATCH v2 0/5] dump: Minor fixes & improvements Markus Armbruster
2023-10-31 10:45 ` [PATCH v2 1/5] dump: Rename qmp_dump_guest_memory() parameter to match QAPI schema Markus Armbruster
@ 2023-10-31 10:45 ` Markus Armbruster
2023-10-31 10:45 ` [PATCH v2 3/5] dump: Recognize "fd:" protocols on Windows hosts Markus Armbruster
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2023-10-31 10:45 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, philmd
When 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().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
dump/dump.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dump/dump.c b/dump/dump.c
index a1fad17f9c..dad36e09de 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -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) {
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/5] dump: Recognize "fd:" protocols on Windows hosts
2023-10-31 10:45 [PATCH v2 0/5] dump: Minor fixes & improvements Markus Armbruster
2023-10-31 10:45 ` [PATCH v2 1/5] dump: Rename qmp_dump_guest_memory() parameter to match QAPI schema Markus Armbruster
2023-10-31 10:45 ` [PATCH v2 2/5] dump: Fix g_array_unref(NULL) in dump-guest-memory Markus Armbruster
@ 2023-10-31 10:45 ` Markus Armbruster
2023-10-31 10:45 ` [PATCH v2 4/5] dump: Improve some dump-guest-memory error messages Markus Armbruster
2023-10-31 10:45 ` [PATCH v2 5/5] dump: Drop redundant check for empty dump Markus Armbruster
4 siblings, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2023-10-31 10:45 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, philmd
A 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.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
dump/dump.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/dump/dump.c b/dump/dump.c
index dad36e09de..30fb2cb0c6 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -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);
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 4/5] dump: Improve some dump-guest-memory error messages
2023-10-31 10:45 [PATCH v2 0/5] dump: Minor fixes & improvements Markus Armbruster
` (2 preceding siblings ...)
2023-10-31 10:45 ` [PATCH v2 3/5] dump: Recognize "fd:" protocols on Windows hosts Markus Armbruster
@ 2023-10-31 10:45 ` Markus Armbruster
2023-10-31 10:45 ` [PATCH v2 5/5] dump: Drop redundant check for empty dump Markus Armbruster
4 siblings, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2023-10-31 10:45 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, philmd
Zero @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.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
dump/dump.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/dump/dump.c b/dump/dump.c
index 30fb2cb0c6..66f62d0891 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -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;
}
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 5/5] dump: Drop redundant check for empty dump
2023-10-31 10:45 [PATCH v2 0/5] dump: Minor fixes & improvements Markus Armbruster
` (3 preceding siblings ...)
2023-10-31 10:45 ` [PATCH v2 4/5] dump: Improve some dump-guest-memory error messages Markus Armbruster
@ 2023-10-31 10:45 ` Markus Armbruster
4 siblings, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2023-10-31 10:45 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, philmd
dump_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.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
dump/dump.c | 26 --------------------------
1 file changed, 26 deletions(-)
diff --git a/dump/dump.c b/dump/dump.c
index 66f62d0891..ea15c5d221 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -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.
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread