From patchwork Fri Aug 3 09:13:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: 858585 jemmy X-Patchwork-Id: 953141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="G1kEGg4U"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hhQ704S1z9s2g for ; Fri, 3 Aug 2018 19:22:05 +1000 (AEST) Received: from localhost ([::1]:49779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flWHa-0007rF-Nw for incoming@patchwork.ozlabs.org; Fri, 03 Aug 2018 05:22:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flW9t-0001Op-L9 for qemu-devel@nongnu.org; Fri, 03 Aug 2018 05:14:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1flW9s-0001Jg-HN for qemu-devel@nongnu.org; Fri, 03 Aug 2018 05:14:05 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:41479) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1flW9s-0001Ih-AR for qemu-devel@nongnu.org; Fri, 03 Aug 2018 05:14:04 -0400 Received: by mail-pg1-x544.google.com with SMTP id z8-v6so2562220pgu.8 for ; Fri, 03 Aug 2018 02:14:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RWIMgk03BRlmqbTHDnYPfsRwdbqRWy3x1CB6C7/BT8U=; b=G1kEGg4U8pxR/FODrvmwCGKxtALOW8R6RAjXi0IjCrr2Kn8k30tQDh1TBbOLEkCjyN PItYE0I+/9eisNtf7Qlthm6RZhJhu2SZehqwlMXepJ1QucLlzbmyoPt0iV9eUZgbZLPI B1aEYQL6DUHRYhhG5wfL8/J+fJdF6utMhtW2awgDbg0zjg3WMEOJZEeDaK/hmADbrwjO fAP4ueNtYTsu7hL6/4Adzqlth33HOf4Ek5cWXadnyfVC/+dTGJGjYia+PMUy1KhT4vou c8U0TEbwzDaMbzNRASnDRDGxbZOL3noziAwOGCFEghpUFhTvzZVM8Vjc+rU6lpfu+Lfe cZiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RWIMgk03BRlmqbTHDnYPfsRwdbqRWy3x1CB6C7/BT8U=; b=dIJ0/IdIHmJ0rFY7Z3l9QT7InH/svLtgxfxLh1AtqgWfB+gIpTqAaUnU+MTx65skV2 9oWn2BckVWrT5Ge9/Txr5hUgb1WL1OIU+8NHnDIAyq2qCrnYm76pEMCI/5k7Uy6qJAm7 zVKDBKOs1z8Sj5NVwH6zfn5c+nnyPibMSrPkUHdng2UqI2hWKvU5fyJ9mHTQBbFQg65T p9vTom7dNfgd5mHu6gxZosXi9r2vM+l92lwow2AELMA2KdlkUnNzvEXY6I2VR/buiKhZ oePoCb5jOOMIlHnmobLpBLeKwE/brNJjUwGgm9jn8t5NswQIPceqOphEiKWpNxKxMnyS DmtA== X-Gm-Message-State: AOUpUlEQzb615Du3SOAZVGseA4nSaV+OasEBd+YulCQHNvUvIxn0x3F+ Ghcha3bPnf3tjrEycK+7R5I= X-Google-Smtp-Source: AAOMgpcCjbqsZg7MIqZ0sAB7gIZoQkVYucj1p3oF3G3kesf8t1w4/QBH0x1/huqy+85XrlTH/C94GA== X-Received: by 2002:a65:5004:: with SMTP id f4-v6mr2902535pgo.54.1533287643507; Fri, 03 Aug 2018 02:14:03 -0700 (PDT) Received: from VM_120_46_centos.localdomain ([119.28.87.64]) by smtp.gmail.com with ESMTPSA id e21-v6sm7991352pfl.187.2018.08.03.02.14.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Aug 2018 02:14:02 -0700 (PDT) From: Lidong Chen X-Google-Original-From: Lidong Chen To: zhang.zhanghailiang@huawei.com, quintela@redhat.com, dgilbert@redhat.com Date: Fri, 3 Aug 2018 17:13:41 +0800 Message-Id: <1533287630-4221-4-git-send-email-lidongchen@tencent.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1533287630-4221-1-git-send-email-lidongchen@tencent.com> References: <1533287630-4221-1-git-send-email-lidongchen@tencent.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v6 03/12] migration: avoid concurrent invoke channel_close by different threads 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: Lidong Chen , qemu-devel@nongnu.org, Lidong Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Lidong Chen The channel_close maybe invoked by different threads. For example, source qemu invokes qemu_fclose in main thread, migration thread and return path thread. Destination qemu invokes qemu_fclose in main thread, listen thread and COLO incoming thread. Signed-off-by: Lidong Chen Reviewed-by: Daniel P. Berrangé --- migration/migration.c | 2 ++ migration/migration.h | 7 +++++++ migration/qemu-file.c | 6 ++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b7d9854..a3a0756 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3200,6 +3200,7 @@ static void migration_instance_finalize(Object *obj) qemu_sem_destroy(&ms->postcopy_pause_sem); qemu_sem_destroy(&ms->postcopy_pause_rp_sem); qemu_sem_destroy(&ms->rp_state.rp_sem); + qemu_mutex_destroy(&ms->qemu_file_close_lock); error_free(ms->error); } @@ -3236,6 +3237,7 @@ static void migration_instance_init(Object *obj) qemu_sem_init(&ms->rp_state.rp_sem, 0); qemu_sem_init(&ms->rate_limit_sem, 0); qemu_mutex_init(&ms->qemu_file_lock); + qemu_mutex_init(&ms->qemu_file_close_lock); } /* diff --git a/migration/migration.h b/migration/migration.h index 64a7b33..a50c2de 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -122,6 +122,13 @@ struct MigrationState QemuMutex qemu_file_lock; /* + * The to_src_file and from_dst_file point to one QIOChannelRDMA, + * And qemu_fclose maybe invoked by different threads. use this lock + * to avoid concurrent invoke channel_close by different threads. + */ + QemuMutex qemu_file_close_lock; + + /* * Used to allow urgent requests to override rate limiting. */ QemuSemaphore rate_limit_sem; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 977b9ae..74c48e0 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -323,12 +323,14 @@ void qemu_update_position(QEMUFile *f, size_t size) */ int qemu_fclose(QEMUFile *f) { - int ret; + int ret, ret2; qemu_fflush(f); ret = qemu_file_get_error(f); if (f->ops->close) { - int ret2 = f->ops->close(f->opaque); + qemu_mutex_lock(&migrate_get_current()->qemu_file_close_lock); + ret2 = f->ops->close(f->opaque); + qemu_mutex_unlock(&migrate_get_current()->qemu_file_close_lock); if (ret >= 0) { ret = ret2; }