From patchwork Fri Feb 22 16:36:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 222604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 669852C02A4 for ; Sat, 23 Feb 2013 05:48:42 +1100 (EST) Received: from localhost ([::1]:55110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8vdS-0005HR-EB for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2013 11:38:10 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8vco-0004nE-Fr for qemu-devel@nongnu.org; Fri, 22 Feb 2013 11:37:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U8vcj-0006j9-TW for qemu-devel@nongnu.org; Fri, 22 Feb 2013 11:37:30 -0500 Received: from mail-ve0-f177.google.com ([209.85.128.177]:37426) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8vcj-0006j1-Mx for qemu-devel@nongnu.org; Fri, 22 Feb 2013 11:37:25 -0500 Received: by mail-ve0-f177.google.com with SMTP id m1so700081ves.22 for ; Fri, 22 Feb 2013 08:37:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=AZepyKh7trQ7swB/Q4ZLKfx+W1i2mrZcQq1URlqefKg=; b=fVIDFCc++m/Es4Sdu67z9aKOWsvaoWnu0sPXB1oXaW/rTDgP/OWp22M36QYn383WCQ 1iBBCet3zVbT7VhewZ887F0gQgLME8R66kYV9oOvLj5saJDg3r/fTkshs6jF9enn/JWk ohIjTZ6zxdV8HX5NsLgpnyT+z+7ZNkWqLZ8TeokD/S3jbTrqS/X8Y2lP53Hdn+CHuUYY B9MWxIuISgEWQleMuM+S6KFgBLHPFPXTxsTKPSc8oZUkbjCc/b0+ZSZesiTLAIz56Cz+ rds/iF51GtDIhh6IzaOCi8MOlsv0CrtVwBlUSNRGiQPVoMz2zXWpRTu+1uCJQ3wkewjN 4OCg== X-Received: by 10.52.31.103 with SMTP id z7mr2998940vdh.56.1361551044302; Fri, 22 Feb 2013 08:37:24 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id tp10sm4291733vec.1.2013.02.22.08.37.22 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 22 Feb 2013 08:37:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 22 Feb 2013 17:36:17 +0100 Message-Id: <1361551008-12430-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1361551008-12430-1-git-send-email-pbonzini@redhat.com> References: <1361551008-12430-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.128.177 Cc: owasserm@redhat.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 11/42] migration: simplify error handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Always use qemu_file_get_error to detect errors, since that is how QEMUFile itself drops I/O after an error occurs. There is no need to propagate and check return values all the time. Also remove the "complete" member, since we know that it is set (via migrate_fd_cleanup) only when the state changes. Reviewed-by: Orit Wasserman Reviewed-by: Juan Quintela Signed-off-by: Paolo Bonzini --- include/migration/migration.h | 1 - migration.c | 46 +++++++++++++------------------------------ 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index d121409..3e680af 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -54,7 +54,6 @@ struct MigrationState int64_t dirty_bytes_rate; bool enabled_capabilities[MIGRATION_CAPABILITY_MAX]; int64_t xbzrle_cache_size; - bool complete; }; void process_incoming_migration(QEMUFile *f); diff --git a/migration.c b/migration.c index 939c3f7..18f97cf 100644 --- a/migration.c +++ b/migration.c @@ -525,6 +525,10 @@ static void buffered_flush(MigrationState *s) DPRINTF("flushing %zu byte(s) of data\n", s->buffer_size); + if (qemu_file_get_error(s->file)) { + s->buffer_size = 0; + return; + } qemu_fflush(s->file); while (s->bytes_xfer < s->xfer_limit && offset < s->buffer_size) { @@ -592,7 +596,6 @@ static int buffered_close(void *opaque) while (!qemu_file_get_error(s->file) && s->buffer_size) { buffered_flush(s); } - s->complete = true; return migrate_fd_close(s); } @@ -656,37 +659,21 @@ static void *buffered_file_thread(void *opaque) int64_t sleep_time = 0; int64_t max_size = 0; bool last_round = false; - int ret; qemu_mutex_lock_iothread(); DPRINTF("beginning savevm\n"); - ret = qemu_savevm_state_begin(s->file, &s->params); - qemu_mutex_unlock_iothread(); + qemu_savevm_state_begin(s->file, &s->params); - while (ret >= 0) { + while (s->state == MIG_STATE_ACTIVE) { int64_t current_time; uint64_t pending_size; - qemu_mutex_lock_iothread(); - if (s->state != MIG_STATE_ACTIVE) { - DPRINTF("put_ready returning because of non-active state\n"); - qemu_mutex_unlock_iothread(); - break; - } - if (s->complete) { - qemu_mutex_unlock_iothread(); - break; - } if (s->bytes_xfer < s->xfer_limit) { DPRINTF("iterate\n"); pending_size = qemu_savevm_state_pending(s->file, max_size); DPRINTF("pending size %lu max %lu\n", pending_size, max_size); if (pending_size && pending_size >= max_size) { - ret = qemu_savevm_state_iterate(s->file); - if (ret < 0) { - qemu_mutex_unlock_iothread(); - break; - } + qemu_savevm_state_iterate(s->file); } else { int old_vm_running = runstate_is_running(); int64_t start_time, end_time; @@ -695,13 +682,8 @@ static void *buffered_file_thread(void *opaque) start_time = qemu_get_clock_ms(rt_clock); qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); - ret = qemu_savevm_state_complete(s->file); - if (ret < 0) { - qemu_mutex_unlock_iothread(); - break; - } else { - migrate_fd_completed(s); - } + qemu_savevm_state_complete(s->file); + migrate_fd_completed(s); end_time = qemu_get_clock_ms(rt_clock); s->total_time = end_time - s->total_time; s->downtime = end_time - start_time; @@ -740,12 +722,13 @@ static void *buffered_file_thread(void *opaque) sleep_time += qemu_get_clock_ms(rt_clock) - current_time; } buffered_flush(s); - ret = qemu_file_get_error(s->file); + qemu_mutex_lock_iothread(); + if (qemu_file_get_error(s->file)) { + migrate_fd_error(s); + } } - if (ret < 0) { - migrate_fd_error(s); - } + qemu_mutex_unlock_iothread(); g_free(s->buffer); return NULL; } @@ -770,7 +753,6 @@ void migrate_fd_connect(MigrationState *s) s->expected_downtime = max_downtime/1000000; s->xfer_limit = s->bandwidth_limit / XFER_LIMIT_RATIO; - s->complete = false; s->file = qemu_fopen_ops(s, &buffered_file_ops);