: qmp/hmp: dump-guest-memory fixes
cover : qmp/hmp: dump-guest-memory fixes
Please see individual patches for details.
dump.c | 13 +++---------- hmp-commands.hx | 8 +++----- hmp.c | 11 ++++++++--- qapi-schema.json | 32 ++++++++++++++++++++------------ 4 files changed, 34 insertions(+), 30 deletions(-)
PATCH 1/3 qmp: dump-guest-memory: improve schema doc (again)
o Add a note about memory allocation with paging=true
o Fix indentation
--- qapi-schema.json | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
qapi-schema.json +20 -12
@@ -1982,26 +1982,33 @@ # supported on i386 and x86_64. # # @paging: if true, do paging to get guest's memory mapping. This allows -# using gdb to process the core file. However, setting @paging to false -# may be desirable because of two reasons: +# using gdb to process the core file. # -# 1. The guest may be in a catastrophic state or can have corrupted -# memory, which cannot be trusted -# 2. The guest can be in real-mode even if paging is enabled. For example, -# the guest uses ACPI to sleep, and ACPI sleep state goes in real-mode +# IMPORTANT: this option can make QEMU allocates several gigabytes +# of RAM. This can happen for a large guest, or a +# malicious guest pretending to be large. +# +# Also, paging=true has the following limitations: +# +# 1. The guest may be in a catastrophic state or can have corrupted +# memory, which cannot be trusted +# 2. The guest can be in real-mode even if paging is enabled. For +# example, the guest uses ACPI to sleep, and ACPI sleep state +# goes in real-mode # # @protocol: the filename or file descriptor of the vmcore. The supported -# protocols are: +# protocols are: # -# 1. file: the protocol starts with "file:", and the following string is -# the file's path. -# 2. fd: the protocol starts with "fd:", and the following string is the -# fd's name. +# 1. file: the protocol starts with "file:", and the following +# string is the file's path. +# 2. fd: the protocol starts with "fd:", and the following string +# is the fd's name. # # @begin: #optional if specified, the starting physical address. # # @length: #optional if specified, the memory size, in bytes. If you don't -# want to dump all guest's memory, please specify the start @begin and @length +# want to dump all guest's memory, please specify the start @begin +# and @length # # Returns: nothing on success #
@@ -2010,6 +2017,7 @@ { 'command': 'dump-guest-memory', 'data': { 'paging': 'bool', 'protocol': 'str', '*begin': 'int', '*length': 'int' } } + ## # @netdev_add: #
Signature · 1 line
1.7.12.315.g682ce8b
Re: [Qemu-devel] [PATCH 1/3] qmp: dump-guest-memory: improve schema doc (again)
Quoted 13 lines · Luiz Capitulino
o Add a note about memory allocation with paging=true
o Fix indentationSigned-off-by Luiz Capitulino <[email protected]>--- qapi-schema.json | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)qapi-schema.json +0
-0
qapi-schema.json line 1985
Quoted 6 lines
qapi-schema.json +1
-2@@ -1982,26 +1982,33 @@ # supported on i386 and x86_64. # # @paging: if true, do paging to get guest's memory mapping. This allows -# using gdb to process the core file. However, setting @paging to false -# may be desirable because of two reasons: +# using gdb to process the core file.
You've got a TAB in there, that made it hard to see what the intended indentation really is. The rest of the file doesn't have TABs, so you need to respin this.
qapi-schema.json line 1987
Quoted 1 line
qapi-schema.json +1
-0+# IMPORTANT: this option can make QEMU allocates several gigabytes
s/allocates/allocate/
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/3 qmp: dump-guest-memory: don't spin if non-blocking fd would block
In reply to Luiz Capitulinofd_write_vmcore() will indefinitely spin for a non-blocking file-descriptor that would block. However, if the fd is non-blocking, how does it make sense to spin?
Change this behavior to return an error instead.
Note that this can only happen with an fd provided by a management application. The fd opened internally by dump-guest-memory is blocking.
--- dump.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
dump.c +3 -10
@@ -100,18 +100,11 @@ static void dump_error(DumpState *s, const char *reason)static int fd_write_vmcore (void *buf,size_t size,void *opaque) {DumpState *s = opaque; -int fd = s->fd;size_t writen_size; -/* The fd may be passed from user, and it can be non-blocked */ -while (size) { - writen_size =qemu_write_full (fd, buf, size); -if (writen_size != size && errno !=EAGAIN ) { -return -1 ; - } - - buf += writen_size; - size -= writen_size; + writen_size =qemu_write_full (s->fd, buf, size); +if (writen_size != size) { +return -1 ; }return 0 ;
Signature · 1 line
1.7.12.315.g682ce8b
Re: [Qemu-devel] [PATCH 2/3] qmp: dump-guest-memory: don't spin if non-blocking fd would block
Quoted 19 lines · Luiz Capitulino
fd_write_vmcore()will indefinitely spin for a non-blocking file-descriptor that would block. However, if the fd is non-blocking, how does it make sense to spin?Change this behavior to return an error instead.
Note that this can only happen with an fd provided by a management application. The fd opened internally by dump-guest-memory is blocking.
Signed-off-by Luiz Capitulino <[email protected]>--- dump.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)dump.c +0
-0
dump.c static void dump_error(DumpState *s, const char *reason) · line 103
Quoted 5 lines
dump.c +0
-1@@ -100,18 +100,11 @@ static void dump_error(DumpState *s, const char *reason)static int fd_write_vmcore (void *buf,size_t size,void *opaque) {DumpState *s = opaque; -int fd = s->fd;size_t writen_size;
While you are here, s/writen/written/ in the local variable.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/3] qmp: dump-guest-memory: don't spin if non-blocking fd would block
In reply to Luiz CapitulinoAt 09/22/2012 01:07 AM, Luiz Capitulino Wrote:
Quoted 19 lines
fd_write_vmcore()will indefinitely spin for a non-blocking file-descriptor that would block. However, if the fd is non-blocking, how does it make sense to spin?Change this behavior to return an error instead.
Note that this can only happen with an fd provided by a management application. The fd opened internally by dump-guest-memory is blocking.
Signed-off-by Luiz Capitulino <[email protected]>--- dump.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)dump.c +0
-0
dump.c static void dump_error(DumpState *s, const char *reason) · line 109
Quoted 10 lines
dump.c +0
-5@@ -100,18 +100,11 @@ static void dump_error(DumpState *s, const char *reason)static int fd_write_vmcore (void *buf,size_t size,void *opaque) {DumpState *s = opaque; -int fd = s->fd;size_t writen_size; -/* The fd may be passed from user, and it can be non-blocked */ -while (size) { - writen_size =qemu_write_full (fd, buf, size); -if (writen_size != size && errno !=EAGAIN ) {
Hmm, if the fd is a blocking fd, errno can't be EAGAIN. So the function doesn't spin. What problems do you meet?
Thanks
Wen Congyang
Quoted 11 lines
dump.c +3
-5-return -1 ; - } - - buf += writen_size; - size -= writen_size; + writen_size =qemu_write_full (s->fd, buf, size); +if (writen_size != size) { +return -1 ; }return 0 ;
Re: [Qemu-devel] [PATCH 2/3] qmp: dump-guest-memory: don't spin if non-blocking fd would block
Quoted 26 lines · On Mon, 24 Sep 2012 14:27:17 +0800 Wen Congyang <[email protected]> wrote:
At 09/22/2012 01:07 AM, Luiz Capitulino Wrote:
Quoted 25 lines
fd_write_vmcore()will indefinitely spin for a non-blocking file-descriptor that would block. However, if the fd is non-blocking, how does it make sense to spin?Change this behavior to return an error instead.
Note that this can only happen with an fd provided by a management application. The fd opened internally by dump-guest-memory is blocking.
Signed-off-by Luiz Capitulino <[email protected]>--- dump.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)dump.c +0
-1@@ -100,18 +100,11 @@ static void dump_error(DumpState *s, const char *reason)static int fd_write_vmcore (void *buf,size_t size,void *opaque) {DumpState *s = opaque; -int fd = s->fd;size_t writen_size;
Quoted 7 lines
dump.c static void dump_error(DumpState *s, const char *reason) · line 109
Quoted 4 lines
dump.c +0
-4-/* The fd may be passed from user, and it can be non-blocked */ -while (size) { - writen_size =qemu_write_full (fd, buf, size); -if (writen_size != size && errno !=EAGAIN ) {Hmm, if the fd is a blocking fd, errno can't be EAGAIN. So the function doesn't spin. What problems do you meet?
The problem is with non-blocking fds, where spinning isn't correct, for two reasons:
1. If the fd is non-blocking, that means you don't want to block and spinning for a long time will have the same effects
2. Spinning consumes host resources
Re: [Qemu-devel] [PATCH 2/3] qmp: dump-guest-memory: don't spin if non-blocking fd would block
At 09/24/2012 09:34 PM, Luiz Capitulino Wrote:
Quoted 37 lines
Quoted 26 lines · On Mon, 24 Sep 2012 14:27:17 +0800 Wen Congyang <[email protected]> wrote:
At 09/22/2012 01:07 AM, Luiz Capitulino Wrote:
Quoted 25 lines
fd_write_vmcore()will indefinitely spin for a non-blocking file-descriptor that would block. However, if the fd is non-blocking, how does it make sense to spin?Change this behavior to return an error instead.
Note that this can only happen with an fd provided by a management application. The fd opened internally by dump-guest-memory is blocking.
Signed-off-by Luiz Capitulino <[email protected]>--- dump.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)dump.c +0
-1@@ -100,18 +100,11 @@ static void dump_error(DumpState *s, const char *reason)static int fd_write_vmcore (void *buf,size_t size,void *opaque) {DumpState *s = opaque; -int fd = s->fd;size_t writen_size;Quoted 7 lines
dump.c static void dump_error(DumpState *s, const char *reason) · line 109
Quoted 4 lines
dump.c +0
-4-/* The fd may be passed from user, and it can be non-blocked */ -while (size) { - writen_size =qemu_write_full (fd, buf, size); -if (writen_size != size && errno !=EAGAIN ) {Hmm, if the fd is a blocking fd, errno can't be EAGAIN. So the function doesn't spin. What problems do you meet?
Quoted 2 lines
The problem is with non-blocking fds, where spinning isn't correct, for two reasons:
But, If the fd is non-blocking, errno can't be EAGAIN. So it doesn't spin.
Thanks
Wen Congyang
Quoted 6 lines
1. If the fd is non-blocking, that means you don't want to block and spinning for a long time will have the same effects
2. Spinning consumes host resources
Re: [Qemu-devel] [PATCH 2/3] qmp: dump-guest-memory: don't spin if non-blocking fd would block
Quoted 38 lines · Wen Congyang
At 09/24/2012 09:34 PM, Luiz Capitulino Wrote:
Quoted 37 lines
Quoted 33 lines · On Mon, 24 Sep 2012 14:27:17 +0800 Wen Congyang <[email protected]> wrote:
At 09/22/2012 01:07 AM, Luiz Capitulino Wrote:
Quoted 19 lines
fd_write_vmcore()will indefinitely spin for a non-blocking file-descriptor that would block. However, if the fd is non-blocking, how does it make sense to spin?Change this behavior to return an error instead.
Note that this can only happen with an fd provided by a management application. The fd opened internally by dump-guest-memory is blocking.
Signed-off-by Luiz Capitulino <[email protected]>--- dump.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)dump.c +0
-0dump.c static void dump_error(DumpState *s, const char *reason) · line 109
Quoted 10 lines
dump.c +0
-5@@ -100,18 +100,11 @@ static void dump_error(DumpState *s, const char *reason)static int fd_write_vmcore (void *buf,size_t size,void *opaque) {DumpState *s = opaque; -int fd = s->fd;size_t writen_size; -/* The fd may be passed from user, and it can be non-blocked */ -while (size) { - writen_size =qemu_write_full (fd, buf, size); -if (writen_size != size && errno !=EAGAIN ) {Hmm, if the fd is a blocking fd, errno can't be EAGAIN. So the function doesn't spin. What problems do you meet?
Quoted 4 lines
Quoted 2 lines
The problem is with non-blocking fds, where spinning isn't correct, for two reasons:
But, If the fd is non-blocking, errno can't be EAGAIN. So it doesn't spin.
I'm afraid you're confused.
http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
[EAGAIN] The O_NONBLOCK flag is set for the file descriptor and the thread would be delayed in the write() operation.
Re: [Qemu-devel] [PATCH 2/3] qmp: dump-guest-memory: don't spin if non-blocking fd would block
At 09/25/2012 05:01 PM, Markus Armbruster Wrote:
Quoted 43 lines
Quoted 41 lines · Wen Congyang
At 09/24/2012 09:34 PM, Luiz Capitulino Wrote:
Quoted 39 lines
Quoted 26 lines · On Mon, 24 Sep 2012 14:27:17 +0800 Wen Congyang <[email protected]> wrote:
At 09/22/2012 01:07 AM, Luiz Capitulino Wrote:
Quoted 25 lines
fd_write_vmcore()will indefinitely spin for a non-blocking file-descriptor that would block. However, if the fd is non-blocking, how does it make sense to spin?Change this behavior to return an error instead.
Note that this can only happen with an fd provided by a management application. The fd opened internally by dump-guest-memory is blocking.
Signed-off-by Luiz Capitulino <[email protected]>--- dump.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)dump.c +0
-1@@ -100,18 +100,11 @@ static void dump_error(DumpState *s, const char *reason)static int fd_write_vmcore (void *buf,size_t size,void *opaque) {DumpState *s = opaque; -int fd = s->fd;size_t writen_size;Quoted 7 lines
dump.c static void dump_error(DumpState *s, const char *reason) · line 109
Quoted 4 lines
dump.c +0
-4-/* The fd may be passed from user, and it can be non-blocked */ -while (size) { - writen_size =qemu_write_full (fd, buf, size); -if (writen_size != size && errno !=EAGAIN ) {Hmm, if the fd is a blocking fd, errno can't be EAGAIN. So the function doesn't spin. What problems do you meet?
The problem is with non-blocking fds, where spinning isn't correct, for two reasons:
Quoted 9 lines
Quoted 1 line
But, If the fd is non-blocking, errno can't be EAGAIN. So it doesn't spin.
I'm afraid you're confused.
http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
[EAGAIN] The
O_NONBLOCKflag is set for the file descriptor and the thread would be delayed in thewrite()operation.
Ahh, you are right.
Thanks
Wen Congyang
Re: [Qemu-devel] [PATCH 2/3] qmp: dump-guest-memory: don't spin if non-blocking fd would block
In reply to Luiz CapitulinoAt 09/24/2012 09:34 PM, Luiz Capitulino Wrote:
Quoted 37 lines
Quoted 26 lines · On Mon, 24 Sep 2012 14:27:17 +0800 Wen Congyang <[email protected]> wrote:
At 09/22/2012 01:07 AM, Luiz Capitulino Wrote:
Quoted 25 lines
fd_write_vmcore()will indefinitely spin for a non-blocking file-descriptor that would block. However, if the fd is non-blocking, how does it make sense to spin?Change this behavior to return an error instead.
Note that this can only happen with an fd provided by a management application. The fd opened internally by dump-guest-memory is blocking.
Signed-off-by Luiz Capitulino <[email protected]>--- dump.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)dump.c +0
-1@@ -100,18 +100,11 @@ static void dump_error(DumpState *s, const char *reason)static int fd_write_vmcore (void *buf,size_t size,void *opaque) {DumpState *s = opaque; -int fd = s->fd;size_t writen_size;Quoted 7 lines
dump.c static void dump_error(DumpState *s, const char *reason) · line 109
Quoted 4 lines
dump.c +0
-4-/* The fd may be passed from user, and it can be non-blocked */ -while (size) { - writen_size =qemu_write_full (fd, buf, size); -if (writen_size != size && errno !=EAGAIN ) {Hmm, if the fd is a blocking fd, errno can't be EAGAIN. So the function doesn't spin. What problems do you meet?
Quoted 8 lines
The problem is with non-blocking fds, where spinning isn't correct, for two reasons:
1. If the fd is non-blocking, that means you don't want to block and spinning for a long time will have the same effects
2. Spinning consumes host resources
If so, I agree with it, and the patch looks fine to me
Thanks
Wen Congyang
PATCH 3/3 hmp: dump-guest-memory: hardcode protocol argument to file:
In reply to Luiz CapitulinoToday, it's necessary to specify the protocol you want to use when dumping the guest memory, for example:
(qemu) dump-guest-memory file:/tmp/guest-memory
This has a few issues:
1. It's cumbersome to type
2. We loose file path autocompletion
3. Being able to specify fd:X in HMP makes little sense for humans
Because of these reasons, hardcode the 'protocol' argument to 'file:' in HMP.
--- hmp-commands.hx | 8 +++----- hmp.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 8 deletions(-)
hmp-commands.hx +3 -5
@@ -914,12 +914,11 @@ ETEXI #if defined(CONFIG_HAVE_CORE_DUMP) { .name = "dump-guest-memory", - .args_type = "paging:-p,protocol:s,begin:i?,length:i?", - .params = "[-p] protocol [begin] [length]", + .args_type = "paging:-p,filename:F,begin:i?,length:i?", + .params = "[-p] filename [begin] [length]", .help = "dump guest memory to file" "\n\t\t\t begin(optional): the starting physical address" "\n\t\t\t length(optional): the memory size, in bytes", - .user_print = monitor_user_noop, .mhandler.cmd = hmp_dump_guest_memory, },
@@ -929,8 +928,7 @@ STEXI @findex dump-guest-memory Dump guest memory to @var{protocol}. The file can be processed with crash or gdb. - protocol: destination file(started with "file:") or destination file - descriptor (started with "fd:") + filename: dump file name paging: do paging to get guest's memory mapping begin: the starting physical address. It's optional, and should be specified with length together.
hmp.c +8 -3
@@ -1042,11 +1042,12 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) {Error *errp =NULL ;int paging =qdict_get_try_bool (qdict,"paging" ,0 ); -const char *file =qdict_get_str (qdict,"protocol" ); +const char *file =qdict_get_str (qdict,"filename" );bool has_begin =qdict_haskey (qdict,"begin" );bool has_length =qdict_haskey (qdict,"length" );int64_t begin =0 ;int64_t length =0 ; +QString *prot;if (has_begin) { begin =qdict_get_int (qdict,"begin" );
@@ -1055,9 +1056,13 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) length =qdict_get_int (qdict,"length" ); } -qmp_dump_guest_memory (paging, file, has_begin, begin, has_length, length, - &errp); + prot =qstring_from_str ("file:" ); +qstring_append (prot, file); + +qmp_dump_guest_memory (paging,qstring_get_str (prot), has_begin, begin, + has_length, length, &errp);hmp_handle_error (mon, &errp); +QDECREF (prot); }void hmp_netdev_add (Monitor *mon,const QDict *qdict)
Signature · 1 line
1.7.12.315.g682ce8b
Re: [Qemu-devel] [PATCH 3/3] hmp: dump-guest-memory: hardcode protocol argument to file:
Quoted 5 lines · Luiz Capitulino
Today, it's necessary to specify the protocol you want to use when dumping the guest memory, for example:
(qemu) dump-guest-memory file:/tmp/guest-memory
Quoted 8 lines
This has a few issues:
1. It's cumbersome to type
2. We loose file path autocompletion
3. Being able to specify fd:X in HMP makes little sense for humansBecause of these reasons, hardcode the 'protocol' argument to 'file:' in HMP.
No impact to libvirt as a QMP client, and we've already declared that HMP can change for better UI even if it is not back-compatible.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/3] hmp: dump-guest-memory: hardcode protocol argument to file:
In reply to Luiz CapitulinoQuoted 5 lines · Luiz Capitulino
Today, it's necessary to specify the protocol you want to use when dumping the guest memory, for example:
(qemu) dump-guest-memory file:/tmp/guest-memory
Quoted 8 lines
This has a few issues:
1. It's cumbersome to type
2. We loose file path autocompletion
3. Being able to specify fd:X in HMP makes little sense for humansBecause of these reasons, hardcode the 'protocol' argument to 'file:' in HMP.
No objection.
The QMP wart remains: protocol is a string that needs to be parsed. I feel that should be avoided in QMP. We should have expressed "either filename or file descriptor name" in the schema. Let's avoid such mistakes in the future.
One remark inline.
Quoted 54 lines
Signed-off-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 8 +++----- hmp.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 8 deletions(-)hmp-commands.hx +3
-5@@ -914,12 +914,11 @@ ETEXI #if defined(CONFIG_HAVE_CORE_DUMP) { .name = "dump-guest-memory", - .args_type = "paging:-p,protocol:s,begin:i?,length:i?", - .params = "[-p] protocol [begin] [length]", + .args_type = "paging:-p,filename:F,begin:i?,length:i?", + .params = "[-p] filename [begin] [length]", .help = "dump guest memory to file" "\n\t\t\t begin(optional): the starting physical address" "\n\t\t\t length(optional): the memory size, in bytes", - .user_print = monitor_user_noop, .mhandler.cmd = hmp_dump_guest_memory, },@@ -929,8 +928,7 @@ STEXI @findex dump-guest-memory Dump guest memory to @var{protocol}. The file can be processed with crash or gdb. - protocol: destination file(started with "file:") or destination file - descriptor (started with "fd:") + filename: dump file name paging: do paging to get guest's memory mapping begin: the starting physical address. It's optional, and should be specified with length together.hmp.c +2
-1@@ -1042,11 +1042,12 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) {Error *errp =NULL ;int paging =qdict_get_try_bool (qdict,"paging" ,0 ); -const char *file =qdict_get_str (qdict,"protocol" ); +const char *file =qdict_get_str (qdict,"filename" );bool has_begin =qdict_haskey (qdict,"begin" );bool has_length =qdict_haskey (qdict,"length" );int64_t begin =0 ;int64_t length =0 ; +QString *prot;if (has_begin) { begin =qdict_get_int (qdict,"begin" );
hmp.c void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) · line 1060
Quoted 7 lines
hmp.c +2
-2@@ -1055,9 +1056,13 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) length =qdict_get_int (qdict,"length" ); } -qmp_dump_guest_memory (paging, file, has_begin, begin, has_length, length, - &errp); + prot =qstring_from_str ("file:" ); +qstring_append (prot, file);
What about prot = g_strconcat("file:", file, NULL) ... g_free(prot) ?
Quoted 8 lines
hmp.c +4
-0+ +qmp_dump_guest_memory (paging,qstring_get_str (prot), has_begin, begin, + has_length, length, &errp);hmp_handle_error (mon, &errp); +QDECREF (prot); }void hmp_netdev_add (Monitor *mon,const QDict *qdict)
Re: [Qemu-devel] [PATCH 3/3] hmp: dump-guest-memory: hardcode protocol argument to file:
Quoted 16 lines · On Tue, 25 Sep 2012 10:48:05 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
Today, it's necessary to specify the protocol you want to use when dumping the guest memory, for example:
(qemu) dump-guest-memory file:/tmp/guest-memory
Quoted 8 lines
This has a few issues:
1. It's cumbersome to type
2. We loose file path autocompletion
3. Being able to specify fd:X in HMP makes little sense for humansBecause of these reasons, hardcode the 'protocol' argument to 'file:' in HMP.
Quoted 6 lines
No objection.
The QMP wart remains: protocol is a string that needs to be parsed. I feel that should be avoided in QMP. We should have expressed "either filename or file descriptor name" in the schema. Let's avoid such mistakes in the future.
I think that the right solution would be to have an URI.
Quoted 59 lines
One remark inline.
Quoted 57 lines
Signed-off-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 8 +++----- hmp.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 8 deletions(-)hmp-commands.hx +3
-5@@ -914,12 +914,11 @@ ETEXI #if defined(CONFIG_HAVE_CORE_DUMP) { .name = "dump-guest-memory", - .args_type = "paging:-p,protocol:s,begin:i?,length:i?", - .params = "[-p] protocol [begin] [length]", + .args_type = "paging:-p,filename:F,begin:i?,length:i?", + .params = "[-p] filename [begin] [length]", .help = "dump guest memory to file" "\n\t\t\t begin(optional): the starting physical address" "\n\t\t\t length(optional): the memory size, in bytes", - .user_print = monitor_user_noop, .mhandler.cmd = hmp_dump_guest_memory, },@@ -929,8 +928,7 @@ STEXI @findex dump-guest-memory Dump guest memory to @var{protocol}. The file can be processed with crash or gdb. - protocol: destination file(started with "file:") or destination file - descriptor (started with "fd:") + filename: dump file name paging: do paging to get guest's memory mapping begin: the starting physical address. It's optional, and should be specified with length together.hmp.c +2
-1@@ -1042,11 +1042,12 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) {Error *errp =NULL ;int paging =qdict_get_try_bool (qdict,"paging" ,0 ); -const char *file =qdict_get_str (qdict,"protocol" ); +const char *file =qdict_get_str (qdict,"filename" );bool has_begin =qdict_haskey (qdict,"begin" );bool has_length =qdict_haskey (qdict,"length" );int64_t begin =0 ;int64_t length =0 ; +QString *prot;if (has_begin) { begin =qdict_get_int (qdict,"begin" );@@ -1055,9 +1056,13 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) length =qdict_get_int (qdict,"length" ); }
Quoted 6 lines
hmp.c void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) · line 1060
Quoted 4 lines
hmp.c +2
-2-qmp_dump_guest_memory (paging, file, has_begin, begin, has_length, length, - &errp); + prot =qstring_from_str ("file:" ); +qstring_append (prot, file);What about prot =
g_strconcat("file:", file, NULL)...g_free(prot)?
Good suggestion.
Quoted 10 lines
Quoted 9 lines
hmp.c +4
-0+ +qmp_dump_guest_memory (paging,qstring_get_str (prot), has_begin, begin, + has_length, length, &errp);hmp_handle_error (mon, &errp); +QDECREF (prot); }void hmp_netdev_add (Monitor *mon,const QDict *qdict)
Re: [Qemu-devel] [PATCH 3/3] hmp: dump-guest-memory: hardcode protocol argument to file:
In reply to Luiz CapitulinoAt 09/22/2012 01:07 AM, Luiz Capitulino Wrote:
Quoted 7 lines
Today, it's necessary to specify the protocol you want to use when dumping the guest memory, for example:
(qemu) dump-guest-memory file:/tmp/guest-memory
This has a few issues:
Quoted 8 lines
1. It's cumbersome to type
2. We loose file path autocompletion
3. Being able to specify fd:X in HMP makes little sense for humansBecause of these reasons, hardcode the 'protocol' argument to 'file:' in HMP.
Signed-off-by Luiz Capitulino <[email protected]>
This patch looks fine to me.
Thanks
Wen Congyang
Quoted 68 lines
--- hmp-commands.hx | 8 +++----- hmp.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 8 deletions(-)hmp-commands.hx +3
-5@@ -914,12 +914,11 @@ ETEXI #if defined(CONFIG_HAVE_CORE_DUMP) { .name = "dump-guest-memory", - .args_type = "paging:-p,protocol:s,begin:i?,length:i?", - .params = "[-p] protocol [begin] [length]", + .args_type = "paging:-p,filename:F,begin:i?,length:i?", + .params = "[-p] filename [begin] [length]", .help = "dump guest memory to file" "\n\t\t\t begin(optional): the starting physical address" "\n\t\t\t length(optional): the memory size, in bytes", - .user_print = monitor_user_noop, .mhandler.cmd = hmp_dump_guest_memory, },@@ -929,8 +928,7 @@ STEXI @findex dump-guest-memory Dump guest memory to @var{protocol}. The file can be processed with crash or gdb. - protocol: destination file(started with "file:") or destination file - descriptor (started with "fd:") + filename: dump file name paging: do paging to get guest's memory mapping begin: the starting physical address. It's optional, and should be specified with length together.hmp.c +8
-3@@ -1042,11 +1042,12 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) {Error *errp =NULL ;int paging =qdict_get_try_bool (qdict,"paging" ,0 ); -const char *file =qdict_get_str (qdict,"protocol" ); +const char *file =qdict_get_str (qdict,"filename" );bool has_begin =qdict_haskey (qdict,"begin" );bool has_length =qdict_haskey (qdict,"length" );int64_t begin =0 ;int64_t length =0 ; +QString *prot;if (has_begin) { begin =qdict_get_int (qdict,"begin" );@@ -1055,9 +1056,13 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) length =qdict_get_int (qdict,"length" ); } -qmp_dump_guest_memory (paging, file, has_begin, begin, has_length, length, - &errp); + prot =qstring_from_str ("file:" ); +qstring_append (prot, file); + +qmp_dump_guest_memory (paging,qstring_get_str (prot), has_begin, begin, + has_length, length, &errp);hmp_handle_error (mon, &errp); +QDECREF (prot); }void hmp_netdev_add (Monitor *mon,const QDict *qdict)
Quoted 1 line · Luiz Capitulino
Please see individual patches for details.
Looks good to me, except for the tab damage Eric noted. The simplification I suggested for 3/3 is optional; use it if you like it.