From patchwork Wed May 30 09:43:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 858585 jemmy X-Patchwork-Id: 10438089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 84DD9602CC for ; Wed, 30 May 2018 09:49:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7409C2887F for ; Wed, 30 May 2018 09:49:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6829C288B7; Wed, 30 May 2018 09:49:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3791B2887F for ; Wed, 30 May 2018 09:49:25 +0000 (UTC) Received: from localhost ([::1]:37259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNxjQ-0003nP-EG for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 May 2018 05:49:24 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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; 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;