From: Hogan Wang via <qemu-devel@nongnu.org>
To: <qemu-devel@nongnu.org>, <marcandre.lureau@redhat.com>
Cc: <wangxinxin.wang@huawei.com>, <hogan.wang@huawei.com>
Subject: [PATCH] dump: introduce dump-cancel QMP command
Date: Thu, 21 Jul 2022 14:21:18 +0800 [thread overview]
Message-ID: <20220721062118.2015-1-hogan.wang@huawei.com> (raw)
There's no way to cancel the current executing dump process, lead to the
virtual machine manager daemon((e.g. libvirtd) cannot restore the dump
job after daemon restart.
Add the 'cancelling' and 'cancelled' dump states.
Use 'dump-cancel' qmp command Set the dump state as 'cancelling'.
The dump process check the 'cancelling' state and break loops.
The 'cancelled' state mark the dump process cancelled success.
---
dump/dump.c | 38 ++++++++++++++++++++++++++++++++++++--
include/sysemu/runstate.h | 1 +
qapi/dump.json | 21 ++++++++++++++++++++-
3 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/dump/dump.c b/dump/dump.c
index 4d9658ffa2..a0ac85aa02 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -118,6 +118,10 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
DumpState *s = opaque;
size_t written_size;
+ if (qemu_system_dump_cancelling()) {
+ return -ECANCELED;
+ }
+
written_size = qemu_write_full(s->fd, buf, size);
if (written_size != size) {
return -errno;
@@ -627,6 +631,10 @@ static void dump_iterate(DumpState *s, Error **errp)
do {
block = s->next_block;
+ if (qemu_system_dump_cancelling()) {
+ error_setg(errp, "dump: job cancelled");
+ return;
+ }
size = block->target_end - block->target_start;
if (s->has_filter) {
@@ -1321,6 +1329,11 @@ static void write_dump_pages(DumpState *s, Error **errp)
* first page of page section
*/
while (get_next_page(&block_iter, &pfn_iter, &buf, s)) {
+ if (qemu_system_dump_cancelling()) {
+ error_setg(errp, "dump: job cancelled");
+ goto out;
+ }
+
/* check zero page */
if (buffer_is_zero(buf, s->dump_info.page_size)) {
ret = write_cache(&page_desc, &pd_zero, sizeof(PageDescriptor),
@@ -1540,6 +1553,22 @@ bool qemu_system_dump_in_progress(void)
return (qatomic_read(&state->status) == DUMP_STATUS_ACTIVE);
}
+bool qemu_system_dump_cancelling(void)
+{
+ DumpState *state = &dump_state_global;
+ return (qatomic_read(&state->status) == DUMP_STATUS_CANCELLING);
+}
+
+void qmp_dump_cancel(Error **errp)
+{
+ DumpState *state = &dump_state_global;
+ if (!qemu_system_dump_in_progress()) {
+ return;
+ }
+ qatomic_set(&state->status, DUMP_STATUS_CANCELLING);
+}
+
+
/* calculate total size of memory to be dumped (taking filter into
* acoount.) */
static int64_t dump_calculate_size(DumpState *s)
@@ -1838,8 +1867,13 @@ static void dump_process(DumpState *s, Error **errp)
/* make sure status is written after written_size updates */
smp_wmb();
- qatomic_set(&s->status,
- (*errp ? DUMP_STATUS_FAILED : DUMP_STATUS_COMPLETED));
+ if (qemu_system_dump_cancelling()) {
+ qatomic_set(&s->status, DUMP_STATUS_CANCELLED);
+ } else if (*errp) {
+ qatomic_set(&s->status, DUMP_STATUS_FAILED);
+ } else {
+ qatomic_set(&s->status, DUMP_STATUS_COMPLETED);
+ }
/* send DUMP_COMPLETED message (unconditionally) */
result = qmp_query_dump(NULL);
diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h
index f3ed52548e..a36c1d43f6 100644
--- a/include/sysemu/runstate.h
+++ b/include/sysemu/runstate.h
@@ -76,6 +76,7 @@ void qemu_system_reset(ShutdownCause reason);
void qemu_system_guest_panicked(GuestPanicInformation *info);
void qemu_system_guest_crashloaded(GuestPanicInformation *info);
bool qemu_system_dump_in_progress(void);
+bool qemu_system_dump_cancelling(void);
#endif
diff --git a/qapi/dump.json b/qapi/dump.json
index 90859c5483..6dfbb6b7de 100644
--- a/qapi/dump.json
+++ b/qapi/dump.json
@@ -108,7 +108,7 @@
# Since: 2.6
##
{ 'enum': 'DumpStatus',
- 'data': [ 'none', 'active', 'completed', 'failed' ] }
+ 'data': [ 'none', 'active', 'completed', 'failed', 'cancelling', 'cancelled' ] }
##
# @DumpQueryResult:
@@ -200,3 +200,22 @@
##
{ 'command': 'query-dump-guest-memory-capability',
'returns': 'DumpGuestMemoryCapability' }
+
+##
+# @dump-cancel:
+#
+# Cancel the current executing dump process.
+#
+# Returns: nothing on success
+#
+# Notes: This command succeeds even if there is no dump process running.
+#
+# Since: 7.2
+#
+# Example:
+#
+# -> { "execute": "dump-cancel" }
+# <- { "return": {} }
+#
+##
+{ 'command': 'dump-cancel' }
--
2.33.0
next reply other threads:[~2022-07-21 6:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-21 6:21 Hogan Wang via [this message]
2022-07-21 8:05 ` [PATCH] dump: introduce dump-cancel QMP command Marc-André Lureau
2022-07-21 8:13 ` Daniel P. Berrangé
2022-07-21 10:57 ` Markus Armbruster
2022-07-21 11:40 ` Daniel P. Berrangé
-- strict thread matches above, loose matches on Subject: below --
2022-07-21 11:25 Wangjing(Hogan) via
2022-07-22 8:56 Wangjing(Hogan) via
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220721062118.2015-1-hogan.wang@huawei.com \
--to=qemu-devel@nongnu.org \
--cc=hogan.wang@huawei.com \
--cc=marcandre.lureau@redhat.com \
--cc=wangxinxin.wang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).