From nobody Sat May 18 22:54:09 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1554888495; cv=none; d=zoho.com; s=zohoarc; b=UShh6dideno+ERAPVtVvAhss+F8J3FUoTwaD75Vi21oUca8esLOFlDOQzScjRpcLtXcmOQuai/V8PawnGPdkVhbl2YXtC0Ewj79yaQKR7MPpx13iuhLcIMLbm3hGy5OsNwDBIWpqz2W/eT1m+tCgG9HZJsIjqOcWkLCi/DG9cE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554888495; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=XldZ2szDL7vpaTWGCEY1yqvMOECV7mZWK4lewJYbGDM=; b=JvtYvhbkOCnULPhs0iEjSwQ7LKDLc3Mn1XRQoLJv71CDbLnJiEVcuFz1U12UOWf2L3SPusgz21zFePSu5UTZlQsUPULRvE4uwCcPTtQdIxzfHBPH5EP5W/SWkEBet8AUpPQTzt3lfkeCMVAj9i7VISQuF9MUI6L+W6j4VmJX8Xo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15548884948611016.262549580487; Wed, 10 Apr 2019 02:28:14 -0700 (PDT) Received: from localhost ([127.0.0.1]:56367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hE9WR-0000EE-50 for importer@patchew.org; Wed, 10 Apr 2019 05:27:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hE9VZ-0008Kv-6X for qemu-devel@nongnu.org; Wed, 10 Apr 2019 05:27:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hE9VY-00014A-5q for qemu-devel@nongnu.org; Wed, 10 Apr 2019 05:27:05 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:38784) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hE9VX-0000xk-G2 for qemu-devel@nongnu.org; Wed, 10 Apr 2019 05:27:04 -0400 Received: from mxbackcorp1j.mail.yandex.net (mxbackcorp1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::162]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 441122E1512; Wed, 10 Apr 2019 12:26:59 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [2a02:6b8:0:1a2d::30]) by mxbackcorp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 2yLQePubGh-QwMqtOd1; Wed, 10 Apr 2019 12:26:59 +0300 Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:1c6a:cfcd:3ad6:4876]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 4IllViJHpG-QwYeQP9I; Wed, 10 Apr 2019 12:26:58 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1554888419; bh=qzVUe+kFoue1PLwKTfFPiIOFXUwUUgzArHlxHpLVHgc=; h=Message-Id:Date:Subject:To:From:Cc; b=VCbfWikvBVL0wXcHp5Jm9saEbV74OQsrZdVFhsmQuXKJfRvY7gGENyZv/vuu5VADM gJLXSJZuprOs900ZwmHrscKpFDYnUnwIyyAoPI2LC0MCkHevMjouYtOiHcIaFiqEMp 265tSwqkxvZrwfdxgYP/tQa4Cn8sTxh+z/23G1/U= Authentication-Results: mxbackcorp1j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Yury Kotov To: "Dr. David Alan Gilbert" , Juan Quintela Date: Wed, 10 Apr 2019 12:26:52 +0300 Message-Id: <20190410092652.22616-1-yury-kotov@yandex-team.ru> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a02:6b8:0:1619::183 Subject: [Qemu-devel] [PATCH] migration: Fix handling fd protocol X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, yc-core@yandex-team.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Currently such case is possible for incoming: QMP: add-fd (fdset =3D 0, fd of some file): adds fd to fdset 0 and returns QEMU's fd (e.g. 33) QMP: migrate-incoming (uri =3D "fd:33"): fd is stored in QIOChannel *ioc ... Incoming migration completes and unrefs ioc -> close(33) QMP: remove-fd (fdset =3D 0, fd =3D 33): removes fd from fdset 0 and qemu_close() -> close(33) =3D> double close For outgoing migration the case is the same but getfd instead of add-fd. Fix it by duping client's fd. Signed-off-by: Yury Kotov --- migration/fd.c | 39 +++++++++++++++++++++++++++++++-------- migration/trace-events | 4 ++-- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/migration/fd.c b/migration/fd.c index a7c13df4ad..c9ff07ac41 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -15,6 +15,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "channel.h" #include "fd.h" #include "migration.h" @@ -26,15 +27,27 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Er= ror **errp) { QIOChannel *ioc; - int fd =3D monitor_get_fd(cur_mon, fdname, errp); + int fd, dup_fd; + + fd =3D monitor_get_fd(cur_mon, fdname, errp); if (fd =3D=3D -1) { return; } =20 - trace_migration_fd_outgoing(fd); - ioc =3D qio_channel_new_fd(fd, errp); + /* fd is previously created by qmp command 'getfd', + * so client is responsible to close it. Dup it to save original value= from + * QIOChannel's destructor */ + dup_fd =3D qemu_dup(fd); + if (dup_fd =3D=3D -1) { + error_setg(errp, "Cannot dup fd %s: %s (%d)", fdname, strerror(err= no), + errno); + return; + } + + trace_migration_fd_outgoing(fd, dup_fd); + ioc =3D qio_channel_new_fd(dup_fd, errp); if (!ioc) { - close(fd); + close(dup_fd); return; } =20 @@ -55,14 +68,24 @@ static gboolean fd_accept_incoming_migration(QIOChannel= *ioc, void fd_start_incoming_migration(const char *infd, Error **errp) { QIOChannel *ioc; - int fd; + int fd, dup_fd; =20 fd =3D strtol(infd, NULL, 0); - trace_migration_fd_incoming(fd); =20 - ioc =3D qio_channel_new_fd(fd, errp); + /* fd is previously created by qmp command 'add-fd' or something else, + * so client is responsible to close it. Dup it to save original value= from + * QIOChannel's destructor */ + dup_fd =3D qemu_dup(fd); + if (dup_fd =3D=3D -1) { + error_setg(errp, "Cannot dup fd %d: %s (%d)", fd, strerror(errno), + errno); + return; + } + + trace_migration_fd_incoming(fd, dup_fd); + ioc =3D qio_channel_new_fd(dup_fd, errp); if (!ioc) { - close(fd); + close(dup_fd); return; } =20 diff --git a/migration/trace-events b/migration/trace-events index de2e136e57..d2d30a6b3c 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -258,8 +258,8 @@ migration_exec_outgoing(const char *cmd) "cmd=3D%s" migration_exec_incoming(const char *cmd) "cmd=3D%s" =20 # fd.c -migration_fd_outgoing(int fd) "fd=3D%d" -migration_fd_incoming(int fd) "fd=3D%d" +migration_fd_outgoing(int fd, int dup_fd) "fd=3D%d dup_fd=3D%d" +migration_fd_incoming(int fd, int dup_fd) "fd=3D%d dup_fd=3D%d" =20 # socket.c migration_socket_incoming_accepted(void) "" --=20 2.21.0