Hi On Wed, Jul 27, 2022 at 6:02 PM Hogan Wang via <qemu-devel@nongnu.org> wrote:
> Break saving pages or dump iterate when dump job in cancel state, > make sure dump process exits as soon as possible. > > Signed-off-by: Hogan Wang <hogan.w...@huawei.com> > Overall, the series looks good to me. Please send it with a top cover letter, so it can be processed by patchew too. I am not familiar with the job infrastructure, it would be nice if Kevin could check the usage or give some advice. thanks --- > dump/dump.c | 24 ++++++++++++++++++++++++ > include/sysemu/dump.h | 2 ++ > 2 files changed, 26 insertions(+) > > diff --git a/dump/dump.c b/dump/dump.c > index 51dc933c7c..881895e831 100644 > --- a/dump/dump.c > +++ b/dump/dump.c > @@ -54,6 +54,8 @@ static Error *dump_migration_blocker; > DIV_ROUND_UP((name_size), 4) + \ > DIV_ROUND_UP((desc_size), 4)) * 4) > > +static bool dump_cancelling(void); > + > static inline bool dump_is_64bit(DumpState *s) > { > return s->dump_info.d_class == ELFCLASS64; > @@ -118,6 +120,10 @@ static int fd_write_vmcore(const void *buf, size_t > size, void *opaque) > DumpState *s = opaque; > size_t written_size; > > + if (dump_cancelling()) { > + return -ECANCELED; > + } > + > written_size = qemu_write_full(s->fd, buf, size); > if (written_size != size) { > return -errno; > @@ -627,6 +633,10 @@ static void dump_iterate(DumpState *s, Error **errp) > > do { > block = s->next_block; > + if (dump_cancelling()) { > + error_setg(errp, "dump: job cancelled"); > + return; > + } > > size = block->target_end - block->target_start; > if (s->has_filter) { > @@ -1321,6 +1331,10 @@ 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 (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), > @@ -1548,6 +1562,15 @@ bool qemu_system_dump_in_progress(void) > return (qatomic_read(&state->status) == DUMP_STATUS_ACTIVE); > } > > +static bool dump_cancelling(void) > +{ > + DumpState *state = &dump_state_global; > + if (state->job && job_is_cancelled(state->job)) { > + return true; > + } > + return false; > +} > + > /* calculate total size of memory to be dumped (taking filter into > * acoount.) */ > static int64_t dump_calculate_size(DumpState *s) > @@ -1894,6 +1917,7 @@ static int coroutine_fn > dump_guest_memory_job_run(Job *job, Error **errp) > > s->errp = errp; > s->co = qemu_coroutine_self(); > + state->job = job; > > if (state->detached) { > /* detached dump */ > diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h > index ffc2ea1072..41bdbe595f 100644 > --- a/include/sysemu/dump.h > +++ b/include/sysemu/dump.h > @@ -15,6 +15,7 @@ > #define DUMP_H > > #include "qapi/qapi-types-dump.h" > +#include "qemu/job.h" > > #define MAKEDUMPFILE_SIGNATURE "makedumpfile" > #define MAX_SIZE_MDF_HEADER (4096) /* max size of > makedumpfile_header */ > @@ -154,6 +155,7 @@ typedef struct DumpState { > GuestPhysBlockList guest_phys_blocks; > ArchDumpInfo dump_info; > MemoryMappingList list; > + Job *job; > uint32_t phdr_num; > uint32_t shdr_num; > bool resume; > -- > 2.33.0 > > > -- Marc-André Lureau