From patchwork Tue Aug 16 00:25:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Md Haris Iqbal X-Patchwork-Id: 9282441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 25F66607FD for ; Tue, 16 Aug 2016 00:27:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 161BA28E8E for ; Tue, 16 Aug 2016 00:27:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AA8328E90; Tue, 16 Aug 2016 00:27:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 79D2628E8E for ; Tue, 16 Aug 2016 00:27:40 +0000 (UTC) Received: from localhost ([::1]:39433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZSEF-0002yh-EP for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Aug 2016 20:27:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZSCC-00022Q-De for qemu-devel@nongnu.org; Mon, 15 Aug 2016 20:25:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bZSC3-0007Nr-Cb for qemu-devel@nongnu.org; Mon, 15 Aug 2016 20:25:32 -0400 Received: from mail-pa0-x244.google.com ([2607:f8b0:400e:c03::244]:36647) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZSC3-0007Nn-1C for qemu-devel@nongnu.org; Mon, 15 Aug 2016 20:25:23 -0400 Received: by mail-pa0-x244.google.com with SMTP id ez1so4314492pab.3 for ; Mon, 15 Aug 2016 17:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=su2tvyuS3lVoA9ltDFYz96F2UOLxMK4ZjqGeT5fRKS4=; b=a3nxIRSnyMUcCwWCrQcvmGvMJmEbJ+VwvkaSAxh/BRS+izaZs9OxkPsqOkYUCt2sh1 zDbTXKg6bIjQzlrPAKMaTEa7RWVrkwCRQthzwOc/IL1IzPgCvf1u/WJg7g8bASERAaaI Dyo9OLtp9i4viI0l1DcpLOUILRrJOKW0GZkaoOdT6QPGzWCCTZKEqLE6rBBEtWcH2CZ6 ssroekTaqm1/c5OB8OBolLLpe0Yx6h201C/UspIU5GmQ7/6QEvEUDX1Yi12uteXYnRs8 fPGfJBVx8a7a6ig+ARMJxQUnCaZga+czABqElc8TVNU9ykETCUIUmzdV5/yy5Q3rzQsE /ZCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=su2tvyuS3lVoA9ltDFYz96F2UOLxMK4ZjqGeT5fRKS4=; b=IfbhfuRRAcSk92qjYOoLoy4M6Um2PYmpM88wigvAEw4VfGEInR6IHwoUeV7OOrTT51 HUVrr0NbhYVAqCAC7WVSpJnTRhFib0sT30e7g26qa42mgt4xzRgFxi/mlG3tunCUQyPI Pf3dBHiazkwy9pUf6S/lMfpVGKydrfTJmoqe1AnNREaU1UlCLror/+NGfFmU9lfdCRHi kbP3js/nn1zIN1GE5SCvMVfaMujEo7RFyC3f9HaautUtUzLLS500DEeCd964tfFZO3Bm /T+AkCPHUop/eyBTcXJQWPNpXZjL1lnKFEUZrraptvejPm3S8L0juMUOUe0k9U6vJy8P ZSgg== X-Gm-Message-State: AEkoouudzOBc8ANIQvq93K54emeUdrVgV+3yubUFrcDvmRwaHPtJliF1E3wwcwqFJSYRYA== X-Received: by 10.66.127.10 with SMTP id nc10mr58529631pab.109.1471307122255; Mon, 15 Aug 2016 17:25:22 -0700 (PDT) Received: from deepak.domain.name ([103.252.25.174]) by smtp.googlemail.com with ESMTPSA id s12sm34028656pfj.73.2016.08.15.17.25.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Aug 2016 17:25:21 -0700 (PDT) From: Md Haris Iqbal To: qemu-devel@nongnu.org Date: Tue, 16 Aug 2016 05:55:03 +0530 Message-Id: <1471307103-13316-3-git-send-email-haris.phnx@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471307103-13316-1-git-send-email-haris.phnx@gmail.com> References: <1471307103-13316-1-git-send-email-haris.phnx@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::244 Subject: [Qemu-devel] [PATCH 2/2] Migration: Request lost pages (due to n/w failure) from source X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Md Haris Iqbal , dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Md Haris Iqbal --- include/migration/migration.h | 7 +++++++ migration/migration.c | 2 ++ migration/ram.c | 35 +++++++++++++++++++++++++++++++++++ migration/savevm.c | 19 +++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index 0a42b87..4c787ce 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -36,6 +36,7 @@ #define QEMU_VM_CONFIGURATION 0x07 #define QEMU_VM_COMMAND 0x08 #define QEMU_VM_SECTION_FOOTER 0x7e +#define QEMU_VM_ALMOST_COMPLETE 0x09 struct MigrationParams { bool blk; @@ -145,6 +146,11 @@ struct MigrationState int state; /* Old style params from 'migrate' command */ MigrationParams params; + /* + * Don't need 2 variables for recovery. + * Clean this up, use a single variable with different states. + */ + bool recovered_once; bool in_recovery; /* State related to return path */ @@ -360,6 +366,7 @@ int qemu_migrate_postcopy_incoming_recovery(QEMUFile **f,MigrationIncomingState* void migrate_incoming_ram_bitmap_init(void); void migrate_incoming_ram_bitmap_update(RAMBlock *rb, ram_addr_t addr); +void *migrate_incoming_ram_req_pages(void *opaque); PostcopyState postcopy_state_get(void); /* Set the state and return the old state */ diff --git a/migration/migration.c b/migration/migration.c index 99138dd..be24b69 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1042,6 +1042,7 @@ MigrationState *migrate_init(const MigrationParams *params) s->xfer_limit = 0; s->cleanup_bh = 0; s->to_dst_file = NULL; + s->recovered_once = false; s->in_recovery = false; s->state = MIGRATION_STATUS_NONE; s->params = *params; @@ -1918,6 +1919,7 @@ static void *migration_thread(void *opaque) if(ret == 0) { current_active_state = MIGRATION_STATUS_POSTCOPY_ACTIVE; runstate_set(RUN_STATE_FINISH_MIGRATE); + s->recovered_once = true; qemu_file_clear_error(s->to_dst_file); continue; } diff --git a/migration/ram.c b/migration/ram.c index 4f16243..445b863 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2639,6 +2639,41 @@ void migrate_incoming_ram_bitmap_update(RAMBlock *rb, ram_addr_t addr) } } +void *migrate_incoming_ram_req_pages(void* opaque) +{ + MigrationIncomingState *mis = opaque; + struct RAMBlock *rb; + size_t hostpagesize = getpagesize(); + uint64_t addr; + unsigned long base; + unsigned long nr; + unsigned long size; + unsigned long next; + unsigned long *not_received; + + not_received = atomic_rcu_read(&migration_bitmap_rcu)->not_received; + QLIST_FOREACH_RCU(rb, &ram_list.blocks, next) { + addr = 0; + base = rb->offset >> TARGET_PAGE_BITS; + size = base + (rb->used_length >> TARGET_PAGE_BITS); + while (true) { + nr = base + (addr >> TARGET_PAGE_BITS); + next = find_next_bit(not_received, size, nr); + addr = (next - base) << TARGET_PAGE_BITS; + + if (addr >= rb->used_length) { + break; + } + else { + migrate_send_rp_req_pages(mis, qemu_ram_get_idstr(rb), + addr, hostpagesize); + addr++; + } + } + } + return NULL; +} + static SaveVMHandlers savevm_ram_handlers = { .save_live_setup = ram_save_setup, .save_live_iterate = ram_save_iterate, diff --git a/migration/savevm.c b/migration/savevm.c index 5fa39c1..103f0b8 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -986,6 +986,12 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f) { SaveStateEntry *se; int ret; + MigrationState* ms = migrate_get_current(); + + if (ms->recovered_once == true) { + qemu_put_byte(f, QEMU_VM_ALMOST_COMPLETE); + qemu_fflush(f); + } QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (!se->ops || !se->ops->save_live_complete_postcopy) { @@ -1830,6 +1836,7 @@ static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis) uint8_t section_type; int ret; PostcopyState ps; + QemuThread req_pages_not_received; while ((section_type = qemu_get_byte(f)) != QEMU_VM_EOF) { @@ -1851,6 +1858,18 @@ static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis) return ret; } break; + case QEMU_VM_ALMOST_COMPLETE: + /* + * This case will only be used when migration recovers from a + * network failure during a postcopy migration. + * Now, send the requests for pages that were lost due to the + * network failure. + */ + qemu_thread_create(&req_pages_not_received, + "postcopy/req_pages_not_received", + migrate_incoming_ram_req_pages, mis, + QEMU_THREAD_DETACHED); + break; default: error_report("Unknown savevm section type %d", section_type); return -EINVAL;