From nobody Sun Nov 2 11:43:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527673743529883.2709187683447; Wed, 30 May 2018 02:49:03 -0700 (PDT) Received: from localhost ([::1]:37259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNxj4-0003nP-Mb for importer@patchew.org; Wed, 30 May 2018 05:49:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNxeH-0000Q0-NL for qemu-devel@nongnu.org; Wed, 30 May 2018 05:44:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNxeE-0006ps-K6 for qemu-devel@nongnu.org; Wed, 30 May 2018 05:44:05 -0400 Received: from mail-pf0-x22a.google.com ([2607:f8b0:400e:c00::22a]:42774) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fNxeE-0006pg-EP for qemu-devel@nongnu.org; Wed, 30 May 2018 05:44:02 -0400 Received: by mail-pf0-x22a.google.com with SMTP id p14-v6so8747481pfh.9 for ; Wed, 30 May 2018 02:44:02 -0700 (PDT) Received: from VM_93_245_centos.localdomain ([150.109.57.149]) by smtp.gmail.com with ESMTPSA id 29-v6sm60565257pfj.14.2018.05.30.02.43.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 May 2018 02:44:01 -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=L0Ramt5azYV3DW/8/DFcHqf/V23s75JfWn8Ox5NsZwI=; b=FNjjq88vNrmeNKVjiVx0SAY2upFBDFh8+hpmVBUxuoIezdvhZ1o/OXNbInGVaiKceB weEgagox2nSixupg3VXDLjXPlcAs2MaSuV6JIF82lcxAtq+r2f5h7p5S1dbu5yP7oXFh x4Tpnp4njGz4z2zQhauqTxpUDL0/R6BbzyjvhF9KSXWq0Bd2YOACzkPnFkYJDotQXXzE LFzdispk19ThEwXwpdyWp2zQ/iPpFwOI/1dNy9j7j7WeUimTlnCdNT8FZYEbY0u1J95G aDGRHC9WOfw200I57qd+PYt7YQlzTcyTeafGgzeINv3iVJeAWVAcKGdmbDBlAqIt2Q5Z +cpA== 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=L0Ramt5azYV3DW/8/DFcHqf/V23s75JfWn8Ox5NsZwI=; b=C9LQerrxIXwZbqpv+W5bpNIshk222vxZ5qV9Lr06/h5QPU7pAmQMQGhegXdP8yHEt/ 14a7DukhBR3qosstovoDuvJaeHGJIrKxPj5l/lwYRFGLiVDqumvlLyUfz2XT8wY7ty+4 GbshM3X5TbTbv3q9mXRF2hwde6KhqbRhmtSOXvBzHA6iiWyZCR6NVJUgTxlvNlMyJrdK El2fY4OIamwIICAXDYpHY21tAiu6NgIOj3GLXLT6iYCUnFymr4D3Z7pD8PXrlleMOQjL owwjgiikOdlfgiKHGxok4IxSNSLYML72OPRIGBO1zxZY2W6UhDMzgLHnQ+X9iatzQopx Qa1Q== X-Gm-Message-State: ALKqPwd3lab8mf35ikPTPXHHjtNBRTTJFaNLQL1n70pXNiyZDi0SwTiz 1XrWkfb1SxlyzOAlNXoylC0= X-Google-Smtp-Source: ADUXVKJIYHr1R+UJo2XeWRfbRmoOEDGASmPJg//mC7qxxGpmAwwwoz6rb6yydpK/vSdvjpLLpiUu+A== X-Received: by 2002:a63:6d05:: with SMTP id i5-v6mr1660211pgc.321.1527673441622; Wed, 30 May 2018 02:44:01 -0700 (PDT) From: Lidong Chen X-Google-Original-From: Lidong Chen To: zhang.zhanghailiang@huawei.com, quintela@redhat.com, dgilbert@redhat.com, berrange@redhat.com, aviadye@mellanox.com, pbonzini@redhat.com Date: Wed, 30 May 2018 17:43:28 +0800 Message-Id: <1527673416-31268-5-git-send-email-lidongchen@tencent.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527673416-31268-1-git-send-email-lidongchen@tencent.com> References: <1527673416-31268-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:c00::22a Subject: [Qemu-devel] [PATCH v4 04/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 , adido@mellanox.com, qemu-devel@nongnu.org, Lidong Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. 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; =20 int last_error; + QemuMutex lock; }; =20 /* @@ -96,6 +97,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps = *ops) =20 f =3D g_new0(QEMUFile, 1); =20 + qemu_mutex_init(&f->lock); f->opaque =3D opaque; f->ops =3D ops; return f; @@ -328,7 +330,9 @@ int qemu_fclose(QEMUFile *f) ret =3D qemu_file_get_error(f); =20 if (f->ops->close) { + qemu_mutex_lock(&f->lock); int ret2 =3D f->ops->close(f->opaque); + qemu_mutex_unlock(&f->lock); if (ret >=3D 0) { ret =3D ret2; } @@ -339,6 +343,7 @@ int qemu_fclose(QEMUFile *f) if (f->last_error) { ret =3D f->last_error; } + qemu_mutex_destroy(&f->lock); g_free(f); trace_qemu_file_fclose(); return ret; --=20 1.8.3.1