From nobody Wed Apr 24 20:02:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) 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=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) 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=1555071794; cv=none; d=zoho.com; s=zohoarc; b=c7bG7xuW0Et0raestvQF5y3Xft2tvZzFv1Jij3rw1ZVSA4GsHVh4IdXMAvA3+bq8TLh777c0vMCm+7IzBLCMRHw3CQgMjowBaQLqvMtaCxtj3ijJkwQPd393i+wfjU5QiRObnhZBLBz7+nRlRp8KQGUWpFakL5yWQVzX/LYrAB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555071794; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=CpVpsHRqkIZ8KMsLfCbA1jkJDLZK9esT7ikzq2mUlP0=; b=V2Iwzmnnd9hlBGiMNtjiVH7XNu6lKL9uthYtcmu4iNFPkHezfgE8/p76N9/dVCQEIE7Y0tE3wnl/nJucGp8zzbbHmtfE4xrl+N4wFsF8Yt0yV/tm8+H3GGs4HK76fwGNUSVuP9wA9DozKFlMaQtq01YEzVLK1M6mewXh9q7KvOE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555071794500428.4757518353348; Fri, 12 Apr 2019 05:23:14 -0700 (PDT) Received: from localhost ([127.0.0.1]:35541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEvD5-0007SC-ET for importer@patchew.org; Fri, 12 Apr 2019 08:23:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEvAt-00067C-Ry for qemu-devel@nongnu.org; Fri, 12 Apr 2019 08:20:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEvAs-000716-Sz for qemu-devel@nongnu.org; Fri, 12 Apr 2019 08:20:55 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:38406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEvAs-0006zQ-Et for qemu-devel@nongnu.org; Fri, 12 Apr 2019 08:20:54 -0400 Received: from mxbackcorp1j.mail.yandex.net (mxbackcorp1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::162]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id A4EA92E1492; Fri, 12 Apr 2019 15:20:51 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:10]) by mxbackcorp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id yEKrHqEP7I-KpMSx8Gh; Fri, 12 Apr 2019 15:20:51 +0300 Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3404:6cb5:5ab:ed68]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id m4LakqlT7Q-Ko0WmlCv; Fri, 12 Apr 2019 15:20:50 +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=1555071651; bh=X5GmXqb1cHMB9+SLJFdxNHUQLC1wO/RQ408daMmcNII=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=G1FXis1JNaL87fH98myOLMYLAjuGzP6L6oow0QuX98QOsX+IS//oChKacPzy2E1Om e6sClb7vZOMhv24lILwi0OdzcMQ8JiWygs8tR7+v73LhJvDEAKCOY1ECauBqbCeSCz e8ec9Gg0tbzGQ4uBvfDxwg1+38ZT7lnxBljzqbeE= Authentication-Results: mxbackcorp1j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Yury Kotov To: Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Thomas Huth , Laurent Vivier , Paolo Bonzini Date: Fri, 12 Apr 2019 15:20:26 +0300 Message-Id: <20190412122028.7067-2-yury-kotov@yandex-team.ru> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190412122028.7067-1-yury-kotov@yandex-team.ru> References: <20190412122028.7067-1-yury-kotov@yandex-team.ru> 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:1a2d::193 Subject: [Qemu-devel] [PATCH 1/3] monitor: Add monitor_recv_fd function to work with sent fds 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: "open list:All patches CC here" , 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" Signed-off-by: Yury Kotov --- include/monitor/monitor.h | 1 + monitor.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index c1b40a9cac..9b9e593fb3 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -25,6 +25,7 @@ void monitor_cleanup(void); int monitor_suspend(Monitor *mon); void monitor_resume(Monitor *mon); =20 +int monitor_recv_fd(Monitor *mon, Error **errp); int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp); int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp); =20 diff --git a/monitor.c b/monitor.c index 4807bbe811..3ebbc08e5c 100644 --- a/monitor.c +++ b/monitor.c @@ -2206,9 +2206,8 @@ void qmp_getfd(const char *fdname, Error **errp) mon_fd_t *monfd; int fd, tmp_fd; =20 - fd =3D qemu_chr_fe_get_msgfd(&cur_mon->chr); + fd =3D monitor_recv_fd(cur_mon, errp); if (fd =3D=3D -1) { - error_setg(errp, QERR_FD_NOT_SUPPLIED); return; } =20 @@ -2266,6 +2265,15 @@ void qmp_closefd(const char *fdname, Error **errp) error_setg(errp, QERR_FD_NOT_FOUND, fdname); } =20 +int monitor_recv_fd(Monitor *mon, Error **errp) +{ + int fd =3D qemu_chr_fe_get_msgfd(&cur_mon->chr); + if (fd =3D=3D -1) { + error_setg(errp, QERR_FD_NOT_SUPPLIED); + } + return fd; +} + int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp) { mon_fd_t *monfd; @@ -2335,9 +2343,8 @@ AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdse= t_id, bool has_opaque, Monitor *mon =3D cur_mon; AddfdInfo *fdinfo; =20 - fd =3D qemu_chr_fe_get_msgfd(&mon->chr); + fd =3D monitor_recv_fd(mon, errp); if (fd =3D=3D -1) { - error_setg(errp, QERR_FD_NOT_SUPPLIED); goto error; } =20 --=20 2.21.0 From nobody Wed Apr 24 20:02:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) 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=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) 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=1555072085; cv=none; d=zoho.com; s=zohoarc; b=TslBZD9HdgbwR0viglrqfriLyK5VFUfIiUnOBsfDPRScEJCrXWlBJxKl28TFp1Zw/9B8DYIoVAkc5HtTYqRtGlnQvVDiw/F4nUVrgKZ21kac2KaHdxARUljLFWcjEHj4V2oj0GY2jGlSm6PsnN+XkB6TwjU3FimG9MXZimDeEFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555072085; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5scv9afxgsXH+WoOpf/RiIfo5/lFARF+RM03UY8Vi64=; b=YS8qvot9UH5gIEmILD1F9FGhJ/d1UUTBs8KE6oyTjzV1G0Y13Rq7qb5NLpq7KA6d/jofVA6kJjvCDEm4JZ+EU5MkrFkkzkx9RKUlWuZgrc/cG377h5MAfh0p5nIzHjH5X3th9cmdsfxSPFINbtd4WcORapJhs7z+y00zMYv+708= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555072085655213.47993109069353; Fri, 12 Apr 2019 05:28:05 -0700 (PDT) Received: from localhost ([127.0.0.1]:35630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEvHl-0004ge-JI for importer@patchew.org; Fri, 12 Apr 2019 08:28:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEvAt-00066j-Aa for qemu-devel@nongnu.org; Fri, 12 Apr 2019 08:20:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEvAs-00070P-0Q for qemu-devel@nongnu.org; Fri, 12 Apr 2019 08:20:55 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:38070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEvAr-0006ze-Jc for qemu-devel@nongnu.org; Fri, 12 Apr 2019 08:20:53 -0400 Received: from mxbackcorp1j.mail.yandex.net (mxbackcorp1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::162]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 5D4A32E128D; Fri, 12 Apr 2019 15:20:52 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:10]) by mxbackcorp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id VEn76H1FkC-KpMWKQuW; Fri, 12 Apr 2019 15:20:52 +0300 Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3404:6cb5:5ab:ed68]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id m4LakqlT7Q-Kp0WqXeM; Fri, 12 Apr 2019 15:20:51 +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=1555071652; bh=flDSQI+j21sPI4CmZ6PSn1OkpHEK4JepGKApSy2Uy2E=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=h/QxOBabfAIa4SQQPBUo07Osv0+2fitr/xvA/BEmeLlHk9DfNDIvo9u4VHwFrw86O oAX/HAWHbxRiVIbuSB4TLd6zxzIS4Zfu86t//s0CHv9v67fC9obBj0/sn5ILkEC3Wn oHzkoZF8ppaBCii+/+Nm6guocbebtvhpIYWvBi0g= Authentication-Results: mxbackcorp1j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Yury Kotov To: Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Thomas Huth , Laurent Vivier , Paolo Bonzini Date: Fri, 12 Apr 2019 15:20:27 +0300 Message-Id: <20190412122028.7067-3-yury-kotov@yandex-team.ru> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190412122028.7067-1-yury-kotov@yandex-team.ru> References: <20190412122028.7067-1-yury-kotov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 95.108.205.193 Subject: [Qemu-devel] [PATCH 2/3] migration: Add inline-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: "open list:All patches CC here" , 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" Existing 'fd:' proto works with previously added fd by getfd or add-fd comm= ands. If client doesn't want to work with this fd before or after migration then = it's easier to send an fd with the migrate-* command. Also, client shouldn't mai= ntain this fd. So, add 'inline-fd:' proto to work with sent fd. Usage: { 'execute': 'migrate', 'arguments': { 'uri': 'inline-fd:' } } { 'execute': 'migrate-incoming', 'arguments': { 'uri': 'inline-fd:' } } Signed-off-by: Yury Kotov --- migration/Makefile.objs | 2 +- migration/inline-fd.c | 89 +++++++++++++++++++++++++++++++++++++++++ migration/inline-fd.h | 22 ++++++++++ migration/migration.c | 15 +++++++ migration/trace-events | 4 ++ 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 migration/inline-fd.c create mode 100644 migration/inline-fd.h diff --git a/migration/Makefile.objs b/migration/Makefile.objs index a4f3bafd86..f4bb6c5803 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -1,4 +1,4 @@ -common-obj-y +=3D migration.o socket.o fd.o exec.o +common-obj-y +=3D migration.o socket.o fd.o inline-fd.o exec.o common-obj-y +=3D tls.o channel.o savevm.o common-obj-y +=3D colo.o colo-failover.o common-obj-y +=3D vmstate.o vmstate-types.o page_cache.o diff --git a/migration/inline-fd.c b/migration/inline-fd.c new file mode 100644 index 0000000000..90a0dc079f --- /dev/null +++ b/migration/inline-fd.c @@ -0,0 +1,89 @@ +/* + * QEMU live migration via generic fd passed with command + * + * Copyright Yandex, Inc. 2019 + * + * Authors: + * Yury Kotov + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "channel.h" +#include "inline-fd.h" +#include "monitor/monitor.h" +#include "io/channel-util.h" +#include "trace.h" + + +void inline_fd_start_outgoing_migration(MigrationState *s, Error **errp) +{ + QIOChannel *ioc; + int fd; + + if (!cur_mon) { + error_setg(errp, "Monitor is disabled"); + return; + } + + fd =3D monitor_recv_fd(cur_mon, errp); + if (fd =3D=3D -1) { + return; + } + + trace_migration_inline_fd_outgoing(fd); + ioc =3D qio_channel_new_fd(fd, errp); + if (!ioc) { + close(fd); + return; + } + + qio_channel_set_name(QIO_CHANNEL(ioc), "migration-infd-outgoing"); + migration_channel_connect(s, ioc, NULL, NULL); + object_unref(OBJECT(ioc)); +} + +static gboolean inline_fd_accept_incoming_migration(QIOChannel *ioc, + GIOCondition condition, + gpointer opaque) +{ + migration_channel_process_incoming(ioc); + object_unref(OBJECT(ioc)); + return G_SOURCE_REMOVE; +} + +void inline_fd_start_incoming_migration(Error **errp) +{ + QIOChannel *ioc; + int fd; + + if (!cur_mon) { + error_setg(errp, "Monitor is disabled"); + return; + } + + fd =3D monitor_recv_fd(cur_mon, errp); + if (fd =3D=3D -1) { + return; + } + + trace_migration_inline_fd_incoming(fd); + ioc =3D qio_channel_new_fd(fd, errp); + if (!ioc) { + close(fd); + return; + } + + qio_channel_set_name(QIO_CHANNEL(ioc), "migration-infd-incoming"); + qio_channel_add_watch(ioc, + G_IO_IN, + inline_fd_accept_incoming_migration, + NULL, + NULL); +} diff --git a/migration/inline-fd.h b/migration/inline-fd.h new file mode 100644 index 0000000000..5b23ce314d --- /dev/null +++ b/migration/inline-fd.h @@ -0,0 +1,22 @@ +/* + * QEMU live migration via generic fd passed with command + * + * Copyright Yandex, Inc. 2019 + * + * Authors: + * Yury Kotov + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#ifndef QEMU_MIGRATION_INLINE_FD_H +#define QEMU_MIGRATION_INLINE_FD_H + +void inline_fd_start_incoming_migration(Error **errp); +void inline_fd_start_outgoing_migration(MigrationState *s, Error **errp); + +#endif diff --git a/migration/migration.c b/migration/migration.c index 609e0df5d0..7b9fafe218 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -19,6 +19,7 @@ #include "migration/blocker.h" #include "exec.h" #include "fd.h" +#include "inline-fd.h" #include "socket.h" #include "rdma.h" #include "ram.h" @@ -364,6 +365,13 @@ void qemu_start_incoming_migration(const char *uri, Er= ror **errp) unix_start_incoming_migration(p, errp); } else if (strstart(uri, "fd:", &p)) { fd_start_incoming_migration(p, errp); + } else if (strstart(uri, "inline-fd:", &p)) { + if (!*p) { + inline_fd_start_incoming_migration(errp); + } else { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", + "an empty path for 'inline-fd:' protocol"); + } } else { error_setg(errp, "unknown migration protocol: %s", uri); } @@ -1924,6 +1932,13 @@ void qmp_migrate(const char *uri, bool has_blk, bool= blk, unix_start_outgoing_migration(s, p, &local_err); } else if (strstart(uri, "fd:", &p)) { fd_start_outgoing_migration(s, p, &local_err); + } else if (strstart(uri, "inline-fd:", &p)) { + if (!*p) { + inline_fd_start_outgoing_migration(s, &local_err); + } else { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", + "an empty path for 'inline-fd:' protocol"); + } } else { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); diff --git a/migration/trace-events b/migration/trace-events index de2e136e57..1afd11eab5 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -261,6 +261,10 @@ migration_exec_incoming(const char *cmd) "cmd=3D%s" migration_fd_outgoing(int fd) "fd=3D%d" migration_fd_incoming(int fd) "fd=3D%d" =20 +# inline-fd.c +migration_inline_fd_outgoing(int fd) "fd=3D%d" +migration_inline_fd_incoming(int fd) "fd=3D%d" + # socket.c migration_socket_incoming_accepted(void) "" migration_socket_outgoing_connected(const char *hostname) "hostname=3D%s" --=20 2.21.0 From nobody Wed Apr 24 20:02:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) 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=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) 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=1555071803; cv=none; d=zoho.com; s=zohoarc; b=QKZE4S6lDr+EIpcTk4seSAeM+NRXJ/U1ycoJzXnu5bVcKjppUIgYxPMEn/gWyNmB0liWNCpf5+zIpp6nJuLNeJtP8EnQRt+RKHBSL21C0Am6jpfav+CDXBdVPp5McgTn8Jn56iYg5/qwpxHwDHu7eBUbeFToeIGpCXo8h/bhw8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555071803; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=lH9SKWQJnA+IQm9U4KWybxipxzXQD71q9Zlz00nq5ms=; b=TN+TK1CGd62asWmlKLaByhtHZfCwrDgFgedEPA7kjpfPXp5aDSyabc4GdqU6KbsbX7+52xqyLx/N8lj1lCIC2UC+n7TU7pVVCRz/LJ6hLy2PuwztmVsBK3w9UoFrCa40o6uTfao+XINwDWy3zTZQXnTbGrko0CpwjYbGyhRQgzI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15550718035106.529455275252076; Fri, 12 Apr 2019 05:23:23 -0700 (PDT) Received: from localhost ([127.0.0.1]:35545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEvDE-0007aM-40 for importer@patchew.org; Fri, 12 Apr 2019 08:23:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEvAv-00068X-5K for qemu-devel@nongnu.org; Fri, 12 Apr 2019 08:20:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEvAs-00070l-DZ for qemu-devel@nongnu.org; Fri, 12 Apr 2019 08:20:57 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:38414) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEvAr-0006zv-Vm for qemu-devel@nongnu.org; Fri, 12 Apr 2019 08:20:54 -0400 Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 109382E1486; Fri, 12 Apr 2019 15:20:53 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:10]) by mxbackcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id fkXLnSVSLS-KqeamE1d; Fri, 12 Apr 2019 15:20:52 +0300 Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3404:6cb5:5ab:ed68]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id m4LakqlT7Q-Kq0WJcVJ; Fri, 12 Apr 2019 15:20:52 +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=1555071653; bh=bpb5m67jxdoY9/Ky15DVCIZmMJhR/DnnkdI4AV1WXhw=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=ms/6mVxbJh4fAsxwJXRC7UbRWewuwIk/x+rv8bGSKkPBliekHZ92AJedxphL8fa+W pfnyevIyMLSRFQzXbx9s8NHx8oOal65VBJN+cGpUrM8pZa7XvQwmXT4cBy9qHBMI+t 3NXz9yRC9p6NgXButrKu9DBcHCe6gsFN/Eag1mDg= Authentication-Results: mxbackcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Yury Kotov To: Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Thomas Huth , Laurent Vivier , Paolo Bonzini Date: Fri, 12 Apr 2019 15:20:28 +0300 Message-Id: <20190412122028.7067-4-yury-kotov@yandex-team.ru> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190412122028.7067-1-yury-kotov@yandex-team.ru> References: <20190412122028.7067-1-yury-kotov@yandex-team.ru> 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:1a2d::193 Subject: [Qemu-devel] [PATCH 3/3] migration-test: Add a test for inline_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: "open list:All patches CC here" , 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" Signed-off-by: Yury Kotov --- tests/libqtest.c | 83 +++++++++++++++++++++++++++-- tests/libqtest.h | 51 +++++++++++++++++- tests/migration-test.c | 117 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 236 insertions(+), 15 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index c49b85482d..2da9310052 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -32,6 +32,7 @@ =20 #define MAX_IRQ 256 #define SOCKET_TIMEOUT 50 +#define SOCKET_MAX_FDS 16 =20 QTestState *global_qtest; =20 @@ -391,6 +392,43 @@ static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState = *s, const char *fmt, ...) va_end(ap); } =20 +static void socket_send_fds(int fd, int *fds, size_t fds_num, + const char *buf, size_t buf_size) +{ +#ifndef WIN32 + ssize_t ret; + struct msghdr msg =3D { 0 }; + char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] =3D { 0 }; + size_t fdsize =3D sizeof(int) * fds_num; + struct cmsghdr *cmsg; + struct iovec iov =3D { .iov_base =3D (char *)buf, .iov_len =3D buf_siz= e }; + + msg.msg_iov =3D &iov; + msg.msg_iovlen =3D 1; + + if (fds && fds_num > 0) { + g_assert_cmpuint(fds_num, <, SOCKET_MAX_FDS); + + msg.msg_control =3D control; + msg.msg_controllen =3D CMSG_SPACE(fdsize); + + cmsg =3D CMSG_FIRSTHDR(&msg); + cmsg->cmsg_len =3D CMSG_LEN(fdsize); + cmsg->cmsg_level =3D SOL_SOCKET; + cmsg->cmsg_type =3D SCM_RIGHTS; + memcpy(CMSG_DATA(cmsg), fds, fdsize); + } + + do { + ret =3D sendmsg(fd, &msg, 0); + } while (ret < 0 && errno =3D=3D EINTR); + g_assert_cmpint(ret, >, 0); +#else + g_test_skip("sendmsg is not supported under Win32"); + return; +#endif +} + static GString *qtest_recv_line(QTestState *s) { GString *line; @@ -545,7 +583,8 @@ QDict *qtest_qmp_receive(QTestState *s) * in the case that they choose to discard all replies up until * a particular EVENT is received. */ -void qmp_fd_vsend(int fd, const char *fmt, va_list ap) +void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) { QObject *qobj; =20 @@ -569,25 +608,49 @@ void qmp_fd_vsend(int fd, const char *fmt, va_list ap) fprintf(stderr, "%s", str); } /* Send QMP request */ - socket_send(fd, str, qstring_get_length(qstr)); + if (fds && fds_num > 0) { + socket_send_fds(fd, fds, fds_num, str, qstring_get_length(qstr= )); + } else { + socket_send(fd, str, qstring_get_length(qstr)); + } =20 qobject_unref(qstr); qobject_unref(qobj); } } =20 +void qmp_fd_vsend(int fd, const char *fmt, va_list ap) +{ + qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); +} + +void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num, + const char *fmt, va_list ap) +{ + qmp_fd_vsend_fds(s->qmp_fd, fds, fds_num, fmt, ap); +} + void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap) { - qmp_fd_vsend(s->qmp_fd, fmt, ap); + qmp_fd_vsend_fds(s->qmp_fd, NULL, 0, fmt, ap); } =20 QDict *qmp_fdv(int fd, const char *fmt, va_list ap) { - qmp_fd_vsend(fd, fmt, ap); + qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); =20 return qmp_fd_receive(fd); } =20 +QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num, + const char *fmt, va_list ap) +{ + qtest_qmp_vsend_fds(s, fds, fds_num, fmt, ap); + + /* Receive reply */ + return qtest_qmp_receive(s); +} + QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap) { qtest_qmp_vsend(s, fmt, ap); @@ -616,6 +679,18 @@ void qmp_fd_send(int fd, const char *fmt, ...) va_end(ap); } =20 +QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num, + const char *fmt, ...) +{ + va_list ap; + QDict *response; + + va_start(ap, fmt); + response =3D qtest_vqmp_fds(s, fds, fds_num, fmt, ap); + va_end(ap); + return response; +} + QDict *qtest_qmp(QTestState *s, const char *fmt, ...) { va_list ap; diff --git a/tests/libqtest.h b/tests/libqtest.h index a16acd58a6..b471b9eeab 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -84,6 +84,21 @@ QTestState *qtest_init_with_serial(const char *extra_arg= s, int *sock_fd); */ void qtest_quit(QTestState *s); =20 +/** + * qtest_qmp_fds: + * @s: #QTestState instance to operate on. + * @fds: array of file descriptors + * @fds_num: number of elements in @fds + * @fmt...: QMP message to send to qemu, formatted like + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. + * + * Sends a QMP message to QEMU with fds and returns the response. + */ +QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num, + const char *fmt, ...) + GCC_FMT_ATTR(4, 5); + /** * qtest_qmp: * @s: #QTestState instance to operate on. @@ -120,7 +135,23 @@ void qtest_qmp_send_raw(QTestState *s, const char *fmt= , ...) GCC_FMT_ATTR(2, 3); =20 /** - * qtest_qmpv: + * qtest_vqmp_fds: + * @s: #QTestState instance to operate on. + * @fds: array of file descriptors + * @fds_num: number of elements in @fds + * @fmt: QMP message to send to QEMU, formatted like + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. + * @ap: QMP message arguments + * + * Sends a QMP message to QEMU with fds and returns the response. + */ +QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num, + const char *fmt, va_list ap) + GCC_FMT_ATTR(4, 0); + +/** + * qtest_vqmp: * @s: #QTestState instance to operate on. * @fmt: QMP message to send to QEMU, formatted like * qobject_from_jsonf_nofail(). See parse_escape() for what's @@ -132,6 +163,22 @@ void qtest_qmp_send_raw(QTestState *s, const char *fmt= , ...) QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); =20 +/** + * qtest_qmp_vsend_fds: + * @s: #QTestState instance to operate on. + * @fds: array of file descriptors + * @fds_num: number of elements in @fds + * @fmt: QMP message to send to QEMU, formatted like + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. + * @ap: QMP message arguments + * + * Sends a QMP message to QEMU and leaves the response in the stream. + */ +void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num, + const char *fmt, va_list ap) + GCC_FMT_ATTR(4, 0); + /** * qtest_qmp_vsend: * @s: #QTestState instance to operate on. @@ -985,6 +1032,8 @@ static inline int64_t clock_set(int64_t val) } =20 QDict *qmp_fd_receive(int fd); +void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) GCC_FMT_ATTR(4, 0); void qmp_fd_vsend(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); void qmp_fd_send(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); void qmp_fd_send_raw(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); diff --git a/tests/migration-test.c b/tests/migration-test.c index bd3f5c3125..538fffcc33 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -15,6 +15,7 @@ #include "libqtest.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" +#include "qapi/qmp/qstring.h" #include "qemu/option.h" #include "qemu/range.h" #include "qemu/sockets.h" @@ -174,6 +175,21 @@ static void stop_cb(void *opaque, const char *name, QD= ict *data) } } =20 +/* + * Events can get in the way of responses we are actually waiting for. + */ +GCC_FMT_ATTR(3, 4) +static QDict *wait_command_fd(QTestState *who, int fd, const char *command= , ...) +{ + va_list ap; + + va_start(ap, command); + qtest_qmp_vsend_fds(who, &fd, 1, command, ap); + va_end(ap); + + return qtest_qmp_receive_success(who, stop_cb, NULL); +} + /* * Events can get in the way of responses we are actually waiting for. */ @@ -461,6 +477,42 @@ static void migrate_set_capability(QTestState *who, co= nst char *capability, qobject_unref(rsp); } =20 +GCC_FMT_ATTR(4, 0) +static void migrate_to_fdv(QTestState *who, int fd, const char *uri, + const char *fmt, va_list ap) +{ + QDict *args, *rsp; + + args =3D qdict_from_vjsonf_nofail(fmt, ap); + g_assert(!qdict_haskey(args, "uri")); + qdict_put_str(args, "uri", uri); + + if (fd !=3D -1) { + rsp =3D qtest_qmp_fds(who, &fd, 1, + "{ 'execute': 'migrate', 'arguments': %p}", ar= gs); + } else { + rsp =3D qtest_qmp(who, "{ 'execute': 'migrate', 'arguments': %p}",= args); + } + + g_assert(qdict_haskey(rsp, "return")); + qobject_unref(rsp); +} + +/* + * Send QMP command "migrate" with fd. + * Arguments are built from @fmt... (formatted like + * qobject_from_jsonf_nofail()) with "uri": @uri spliced in. + */ +GCC_FMT_ATTR(4, 5) +static void migrate_to_fd(QTestState *who, int fd, const char *uri, + const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + migrate_to_fdv(who, fd, uri, fmt, ap); + va_end(ap); +} + /* * Send QMP command "migrate". * Arguments are built from @fmt... (formatted like @@ -470,18 +522,9 @@ GCC_FMT_ATTR(3, 4) static void migrate(QTestState *who, const char *uri, const char *fmt, ...) { va_list ap; - QDict *args, *rsp; - va_start(ap, fmt); - args =3D qdict_from_vjsonf_nofail(fmt, ap); + migrate_to_fdv(who, -1, uri, fmt, ap); va_end(ap); - - g_assert(!qdict_haskey(args, "uri")); - qdict_put_str(args, "uri", uri); - - rsp =3D qmp("{ 'execute': 'migrate', 'arguments': %p}", args); - g_assert(qdict_haskey(rsp, "return")); - qobject_unref(rsp); } =20 static void migrate_postcopy_start(QTestState *from, QTestState *to) @@ -1027,6 +1070,59 @@ static void test_precopy_tcp(void) g_free(uri); } =20 +static void test_migrate_inline_fd(void) +{ + QTestState *from, *to; + int ret; + int pair[2]; + QDict *rsp; + + if (test_migrate_start(&from, &to, "defer", false, false)) { + return; + } + + /* + * We want to pick a speed slow enough that the test completes + * quickly, but that it doesn't complete precopy even on a slow + * machine, so also set the downtime. + */ + /* 1 ms should make it not converge*/ + migrate_set_parameter(from, "downtime-limit", 1); + /* 1GB/s */ + migrate_set_parameter(from, "max-bandwidth", 1000000000); + + /* Wait for the first serial output from the source */ + wait_for_serial("src_serial"); + + ret =3D socketpair(PF_LOCAL, SOCK_STREAM, 0, pair); + g_assert_cmpint(ret, =3D=3D, 0); + + rsp =3D wait_command_fd(to, pair[0], + "{ 'execute': 'migrate-incoming'," + " 'arguments': { 'uri': 'inline-fd:' }}"); + qobject_unref(rsp); + + migrate_to_fd(from, pair[1], "inline-fd:", "{}"); + + close(pair[0]); + close(pair[1]); + + wait_for_migration_pass(from); + + /* 300ms should converge */ + migrate_set_parameter(from, "downtime-limit", 300); + + if (!got_stop) { + qtest_qmp_eventwait(from, "STOP"); + } + qtest_qmp_eventwait(to, "RESUME"); + + wait_for_serial("dest_serial"); + wait_for_migration_complete(from); + + test_migrate_end(from, to, true); +} + int main(int argc, char **argv) { char template[] =3D "/tmp/migration-test-XXXXXX"; @@ -1081,6 +1177,7 @@ int main(int argc, char **argv) qtest_add_func("/migration/precopy/tcp", test_precopy_tcp); /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */ qtest_add_func("/migration/xbzrle/unix", test_xbzrle_unix); + qtest_add_func("/migration/inline_fd", test_migrate_inline_fd); =20 ret =3D g_test_run(); =20 --=20 2.21.0