From patchwork Sat May 5 14:35:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 858585 jemmy X-Patchwork-Id: 909157 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="ceS0qhOf"; 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 40dWlD2hfQz9s3G for ; Sun, 6 May 2018 00:40:40 +1000 (AEST) Received: from localhost ([::1]:39050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEyMX-0002tq-Ur for incoming@patchwork.ozlabs.org; Sat, 05 May 2018 10:40:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEyIF-0008Qt-BM for qemu-devel@nongnu.org; Sat, 05 May 2018 10:36:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEyIE-0008Cl-AH for qemu-devel@nongnu.org; Sat, 05 May 2018 10:36:11 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:40382) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fEyIE-0008BN-3R for qemu-devel@nongnu.org; Sat, 05 May 2018 10:36:10 -0400 Received: by mail-pg0-x242.google.com with SMTP id l2-v6so17312785pgc.7 for ; Sat, 05 May 2018 07:36:09 -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; bh=2uQY15QStn6Po6OCGcb7M+5H4LvOklMk0X5aqrbF9/Y=; b=ceS0qhOfYTK+2cHiq3+WVTnWgZpv/1irdN9P7zJfgCoKZAJrZ5ifloEIwGtu+mbWuS PHqfHkQuF6HdkeeY2nwmSjecSIR2d3zVl6KpIxMRWbWUWTcP7njXyvyk/m19cglpVhPZ 3zGrI+xp4aozraqsfxfwDH+kgFZU7SmIInj2ZuoNoObzpwn1q2kEKZWsh+dLrcx3dsNn 5ZVOUg9YahHraWmz2R1HDRWzpTB4EwmgFTdI0VznDpTH+Mam7qQZHPrN0TUwDlyKCwow 60b9z7c8NRGtoXzEnjBgekXdbtZ6b29QNvEns8JwtDAFLDSCsPlBDv/Xv0Y1zrtUperJ SPAQ== 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; bh=2uQY15QStn6Po6OCGcb7M+5H4LvOklMk0X5aqrbF9/Y=; b=CPMtiSeI42ZWsT3WLraaYB1i46smwH4WM9rGFUCcgX9LxT55jQXiuAK7H4/2F3AcO9 wlOUS+etF1bWZbC50VPMnP/mnVgkb8Ivee30/lBztC6zXoYXTyxVNO0z4wdUq6pdIG5e q3U3v5/SuYJL76pI/dq5boeK+0FXukz91lrCVaxhFDcMPgsXJaet6ubyO6o1Zu644dEP WIHj0OEyGSF415+ipAJj4n4KlSf/t2dRiFRH2ZlTn/rdKLT/ZK/84DjFU2sMRVnqPtbJ 7zFILbkhL5WmXaxJgotd3HDwhFvZIB3AJGi3Dxe6uo1B3u34Af2Zo8nvlOc7UnJQgxmZ ZnBA== X-Gm-Message-State: ALQs6tDmapezR43nkt36pRUF4q6iBP5EaYZhQ+ac566bjRGWbFL3Lq9d tHmkzh+vbbYNroX+37ouqWw= X-Google-Smtp-Source: AB8JxZroet8Vp+O3K5h5DUHDvzuaqcelrvLjT98Sg3oNuOWujfjrWVCytRwWbGibPRv8iooMeFFIuA== X-Received: by 2002:a63:41c5:: with SMTP id o188-v6mr24679560pga.7.1525530969275; Sat, 05 May 2018 07:36:09 -0700 (PDT) Received: from VM_127_91_centos.localdomain ([119.28.195.137]) by smtp.gmail.com with ESMTPSA id n67sm38529640pfh.188.2018.05.05.07.36.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 May 2018 07:36:08 -0700 (PDT) From: Lidong Chen X-Google-Original-From: Lidong Chen To: quintela@redhat.com, dgilbert@redhat.com, berrange@redhat.com Date: Sat, 5 May 2018 22:35:34 +0800 Message-Id: <1525530936-21835-5-git-send-email-lidongchen@tencent.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525530936-21835-1-git-send-email-lidongchen@tencent.com> References: <1525530936-21835-1-git-send-email-lidongchen@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH v3 4/6] 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: adido@mellanox.com, galsha@mellanox.com, aviadye@mellanox.com, qemu-devel@nongnu.org, Lidong Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Add a mutex in QEMUFile struct to avoid concurrent invoke channel_close. Signed-off-by: Lidong Chen --- migration/qemu-file.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 977b9ae..87d0f05 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -52,6 +52,7 @@ struct QEMUFile { unsigned int iovcnt; int last_error; + QemuMutex lock; }; /* @@ -96,6 +97,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops) f = g_new0(QEMUFile, 1); + qemu_mutex_init(&f->lock); f->opaque = opaque; f->ops = ops; return f; @@ -328,7 +330,9 @@ int qemu_fclose(QEMUFile *f) ret = qemu_file_get_error(f); if (f->ops->close) { + qemu_mutex_lock(&f->lock); int ret2 = f->ops->close(f->opaque); + qemu_mutex_unlock(&f->lock); if (ret >= 0) { ret = ret2; } @@ -339,6 +343,7 @@ int qemu_fclose(QEMUFile *f) if (f->last_error) { ret = f->last_error; } + qemu_mutex_destroy(&f->lock); g_free(f); trace_qemu_file_fclose(); return ret;