From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4EE91C00144 for ; Mon, 1 Aug 2022 08:11:41 +0000 (UTC) Received: from localhost ([::1]:48830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIQWa-0008ID-8O for qemu-devel@archiver.kernel.org; Mon, 01 Aug 2022 04:11:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIQSt-0005ho-6i for qemu-devel@nongnu.org; Mon, 01 Aug 2022 04:07:52 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:3949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIQSp-00061z-7n for qemu-devel@nongnu.org; Mon, 01 Aug 2022 04:07:49 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Lx9fV5vJgzmVfL; Mon, 1 Aug 2022 16:05:38 +0800 (CST) Received: from kwepemm600015.china.huawei.com (7.193.23.52) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 1 Aug 2022 16:07:33 +0800 Received: from localhost (10.174.149.172) by kwepemm600015.china.huawei.com (7.193.23.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 1 Aug 2022 16:07:32 +0800 To: , , , , CC: , Subject: [PATCH v4 1/3] dump: support cancel dump process Date: Mon, 1 Aug 2022 16:07:20 +0800 Message-ID: <20220801080722.3318-1-hogan.wang@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.174.149.172] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600015.china.huawei.com (7.193.23.52) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.187; envelope-from=hogan.wang@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: Hogan Wang From: Hogan Wang via 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 --- dump/dump.c | 23 +++++++++++++++++++++++ include/sysemu/dump.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/dump/dump.c b/dump/dump.c index 4d9658ffa2..a57c580b12 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), @@ -1540,6 +1554,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) 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