From patchwork Fri Feb 22 16:36:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 222567 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 3FEF52C0085 for ; Sat, 23 Feb 2013 03:59:05 +1100 (EST) Received: from localhost ([::1]:51961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8vxf-0002sU-IQ for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2013 11:59:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8vd0-00055X-TT for qemu-devel@nongnu.org; Fri, 22 Feb 2013 11:37:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U8vcv-0006lj-3X for qemu-devel@nongnu.org; Fri, 22 Feb 2013 11:37:42 -0500 Received: from mail-ve0-f178.google.com ([209.85.128.178]:55965) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8vcu-0006lZ-Vw for qemu-devel@nongnu.org; Fri, 22 Feb 2013 11:37:37 -0500 Received: by mail-ve0-f178.google.com with SMTP id db10so700620veb.23 for ; Fri, 22 Feb 2013 08:37:36 -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=+VJtYEH9oeT+dpqlK4+pzxmoofcnHQ24y5ey8kjWg+o=; b=EIR3n4nfZDfUOihTAo3tXFd944Cd9TKjhVeIEb7NqXNPYWVYrs52bh6MWEc/5kx+UX RWaWaL5gzOeUVODAscSDqCvRi2nmK9mTHTCgmHr2r/iSxPt7QsLtlo+CHVNRoMbzrcm9 LxBNfsFj8Io/Rsi8C/GfIv9mE4RYNSMx4b05tf/ScgnvDmpNodIYz+Xi0Z6viphrfweo 34pWwCt8R/bCU/d0zZzZP9h09SgmrwMP0XU743FPb7i9QtWEaziudbS+EiW5TDEL7LhU woI94lmDix27FSm4Pu2+pjaIzM7llERIat7gq8lmWcvciNJ1xtq9d098eLCZabr0v4+c i40A== X-Received: by 10.220.231.196 with SMTP id jr4mr3451451vcb.16.1361551053454; Fri, 22 Feb 2013 08:37:33 -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.31 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 22 Feb 2013 08:37:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 22 Feb 2013 17:36:21 +0100 Message-Id: <1361551008-12430-16-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.178 Cc: owasserm@redhat.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 15/42] migration: cleanup migration (including thread) in the iothread 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 Perform final cleanup in a bottom half, and add joining the thread to the series of cleanup actions. migrate_fd_error remains for connection error, but it doesn't need to cleanup anything anymore. Reviewed-by: Orit Wasserman Reviewed-by: Juan Quintela Signed-off-by: Paolo Bonzini --- include/migration/migration.h | 1 + migration.c | 38 ++++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 3e680af..ed20bed 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -38,6 +38,7 @@ struct MigrationState size_t buffer_size; size_t buffer_capacity; QemuThread thread; + QEMUBH *cleanup_bh; QEMUFile *file; int fd; diff --git a/migration.c b/migration.c index b40755f..729578b 100644 --- a/migration.c +++ b/migration.c @@ -261,8 +261,13 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, /* shared migration helpers */ -static void migrate_fd_cleanup(MigrationState *s) +static void migrate_fd_cleanup(void *opaque) { + MigrationState *s = opaque; + + qemu_bh_delete(s->cleanup_bh); + s->cleanup_bh = NULL; + if (s->file) { DPRINTF("closing file\n"); qemu_fclose(s->file); @@ -290,15 +295,10 @@ static void migrate_finish_set_state(MigrationState *s, int new_state) void migrate_fd_error(MigrationState *s) { DPRINTF("setting error state\n"); - migrate_finish_set_state(s, MIG_STATE_ERROR); - migrate_fd_cleanup(s); -} - -static void migrate_fd_completed(MigrationState *s) -{ - DPRINTF("setting completed state\n"); - migrate_finish_set_state(s, MIG_STATE_COMPLETED); - migrate_fd_cleanup(s); + assert(s->file == NULL); + s->state = MIG_STATE_ERROR; + trace_migrate_set_state(MIG_STATE_ERROR); + notifier_list_notify(&migration_state_notifiers, s); } static ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data, @@ -325,7 +325,6 @@ static void migrate_fd_cancel(MigrationState *s) DPRINTF("cancelling migration\n"); migrate_finish_set_state(s, MIG_STATE_CANCELLED); - migrate_fd_cleanup(s); } int migrate_fd_close(MigrationState *s) @@ -590,6 +589,11 @@ static int buffered_close(void *opaque) DPRINTF("closing\n"); + qemu_mutex_unlock_iothread(); + qemu_thread_join(&s->thread); + qemu_mutex_lock_iothread(); + assert(s->state != MIG_STATE_ACTIVE); + return migrate_fd_close(s); } @@ -712,13 +716,9 @@ static void *buffered_file_thread(void *opaque) } buffered_flush(s); if (qemu_file_get_error(s->file)) { - qemu_mutex_lock_iothread(); - migrate_fd_error(s); - qemu_mutex_unlock_iothread(); + migrate_finish_set_state(s, MIG_STATE_ERROR); } else if (last_round && s->buffer_size == 0) { - qemu_mutex_lock_iothread(); - migrate_fd_completed(s); - qemu_mutex_unlock_iothread(); + migrate_finish_set_state(s, MIG_STATE_COMPLETED); } } @@ -734,6 +734,7 @@ static void *buffered_file_thread(void *opaque) vm_start(); } } + qemu_bh_schedule(s->cleanup_bh); qemu_mutex_unlock_iothread(); g_free(s->buffer); @@ -763,9 +764,10 @@ void migrate_fd_connect(MigrationState *s) s->xfer_limit = s->bandwidth_limit / XFER_LIMIT_RATIO; + s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s); s->file = qemu_fopen_ops(s, &buffered_file_ops); qemu_thread_create(&s->thread, buffered_file_thread, s, - QEMU_THREAD_DETACHED); + QEMU_THREAD_JOINABLE); notifier_list_notify(&migration_state_notifiers, s); }