From patchwork Thu Feb 10 14:14:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12742230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EBDB6C433F5 for ; Thu, 10 Feb 2022 17:06:23 +0000 (UTC) Received: from localhost ([::1]:57546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nICti-00032H-Ui for qemu-devel@archiver.kernel.org; Thu, 10 Feb 2022 12:06:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIATm-0005XV-9H for qemu-devel@nongnu.org; Thu, 10 Feb 2022 09:31:26 -0500 Received: from [2a01:111:f400:fe1e::72c] (port=41191 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIATF-0005X3-U4 for qemu-devel@nongnu.org; Thu, 10 Feb 2022 09:30:56 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S3rurBybYzkoKwHTbGU3+D1Bf3N4+1rlyX/et7zRfC0AZBVndQJy881/+waAagVgrcYhub7eOBCReR6PTINnMa26qR+L1t6qmOVsgYrXq7isqbbOyGHDVaPLB9XVRz4jZuQc9xCMBVTA181cqApmigS+OTGuuCqsL4Yfu58qYAhUVQRsJ5M8S71tNdU0Q09kEiI+eCBO6b0zCbVbHrbCWp6kehTXAcWNZ/pVXQ9bXfhDTn5vJJx6y2X7FJWhn+Kg3xvm7Q6Mp8Nr9bXfh4H8c/iznpLVf/IXr7JuVvbbKcHkeLMzF/xc5QKzPQNnC7LdmUf7aurMU0zRarSjBiB9HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aadJ4ExH3KQ+75/4/9k8ql2bl0KZ61ZerqL7j1feb2w=; b=CE8tiHRhAN0xN9BsdRm0x5UUlkjXkDVE3J9SKYpiz0iHIxh5CaIWKzwJo+jL6zICtD35CrNvAyhU29jNprj4IjNJVYamdNmbMDAancliNnPh/1KoZPgH7n8bTt5Khp1T4f/0M2HChKuOhh7alMI+lPCbeiff9XKaVIXMQd5fjNDQM4A12DrSY2cZGJMfYQx3nlXScorswIh9Pw8nNnc3KqpOf2n8KZLKE5XFROMCC/a/YQ16LEayXGZnYke0R+r1Dmg/bJGmI09nI4OHtGT5fr4gva5TjCo49YpuSpV1g5tvU0fKyqL/Z6yDNVnd2Jbz3uSyUikTTkizkzwRe2bZ3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aadJ4ExH3KQ+75/4/9k8ql2bl0KZ61ZerqL7j1feb2w=; b=Mf1gaMsx2Cm/sV69DlCK/DisGp57K7cnV0osZCJUj+4sej8eQEFsfVEOVeZYmR3D7x/lUETdNZg2rIgSNhZ6rM9/ESwFU+GvAUwFnuCJgd/mRcaz+PToeoLlHAtkPrAqV0CjaJiXdA0ieTbgo4/kK5ySVuv4+HWT+0AkibnehyM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM7PR08MB5413.eurprd08.prod.outlook.com (2603:10a6:20b:10a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 14:15:11 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4975.011; Thu, 10 Feb 2022 14:15:10 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: bleal@redhat.com, wainersm@redhat.com, f4bug@amsat.org, crosa@redhat.com, eblake@redhat.com, armbru@redhat.com, kraxel@redhat.com, vsementsov@virtuozzo.com, berrange@redhat.com, marcandre.lureau@redhat.com Subject: [PATCH v4 1/3] ui/vnc: refactor arrays of addresses to SocketAddressList Date: Thu, 10 Feb 2022 15:14:55 +0100 Message-Id: <20220210141457.539582-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220210141457.539582-1-vsementsov@virtuozzo.com> References: <20220210141457.539582-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6PR05CA0036.eurprd05.prod.outlook.com (2603:10a6:20b:2e::49) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 68c5237d-18c4-4ed7-13ba-08d9ec9fbf1d X-MS-TrafficTypeDiagnostic: AM7PR08MB5413:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:454; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WOkqc3Yqi89MkFJzizTShp7n2NOvjdpV+4amD5J27fK30VorW4UwBoEgFimNkE/XxmxHunyQm8MY9++DQ2JYrWig1+9Y25ohlSUKkEm7K8/DH+nDZoX0SxR5aLvy+NfI/QCOQizUt23C0WrzThoupJJCFML3x85LbKtDdWUu8l9dwrqyk2bm0qlJHbwpZT4dEk779wjab8Z45M1dLZfWFJNU0ruie4NGlkWiA+HlqPh6j4/eJIjXfpxiEr9cGCJqC6xPy5R4gtfaiWK6xgbWc6C+Zn7mA6rxL5L4hCt6xhOgvYy7b2C+qmmx1lOB0sJAE4wnTF7jiMpevTBcKCevWjj6xcp17KlylPdHRqo+D39ogthu02dp+0U+KKFG1ffnhj99zuTN40jiK2Xb8c+Ua1ifhPoTUSAZxhwHdsN//rq0daTcjKoVbziwRtUtc+ctFYqkF3idtBYAb7Xx0LH56pR7hBrdj+XlPic80p5G3TJ8xaBojA+p/Yi9bs3KFMmS789AgAJ5VUoJPx2ekCTdJMJ5zMRX0yK6zgtEf7kqKmq9/V2R76dswWmw35m6ef9N8CGuk25GTX17jj24GOpZurl1SBAg93iBG63eKLG2beUgmMXTe60Q0ZfoxPo6j75vwP32byCSxUh5mrDLZe7TBNaLb5wd80A9MqnE/Q5zRAcz5yBKtM9d23w9ekdz0YbHOB82lqd17T5xpxbp9oQTCw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(26005)(186003)(52116002)(2616005)(2906002)(6506007)(38100700002)(316002)(86362001)(6916009)(38350700002)(66946007)(1076003)(66556008)(66476007)(4326008)(8676002)(5660300002)(8936002)(6486002)(6512007)(83380400001)(7416002)(6666004)(508600001)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Ex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N36Po3Ea4HFFH081bG1v95/4SKLogVvu/S8cdETrP6FXuS4x2qS8tb/X3eLG?= =?utf-8?q?DEzu+Vog0+DtiGH/h0EnljDjY9kfpP4al6ol4JvHrxlFdI3ASgQHPQu75VqY8nng/?= =?utf-8?q?ZRo49nFobchmPqkIFqvyP8QhBdfFdq9gEcrjLwrkq4j2brYGs51WCrkLByqFSQ9q0?= =?utf-8?q?J+eX0LFgLpV4tPPmLBteq0c1qwEHNt/d/bm4R1WNuVRCUmaKqHUeAzt/7pr+/r200?= =?utf-8?q?Mdtnz+/b9CTlTWdLQtwJ+xVCZZTGDPSVfi9Bqfr4CkDuZF+46ZNFH4VULYIGQQu3s?= =?utf-8?q?lyJJG7asNpXif3xi5k6hBvphl7iHkquLG+YlhYKYV1H8IreY5B0/TY0upCiPBbr0T?= =?utf-8?q?TON3FkYtRrHhAV3OjuTr3Kas3Y9oTAxNBjI/rP/t0fQG0RQ6NU+UzOSJxYkYzVp+L?= =?utf-8?q?IAFHeEy89qk3raq7vfC2so9BDFiB1P7RmiLcbz57bUS5dd+CseZur4dhS0Hpx1CQP?= =?utf-8?q?KE4IE/acVtrDN3kQbOar/ez/2L6gYu7aAzGbEfjn/Q+1sXV7YiPuYCYvyVxhqBTBq?= =?utf-8?q?2MleP0yPTaydRzCe7i498FXZMlszCABgFvrik6xLITZWNCSOtHnxglO9lGfLPaapr?= =?utf-8?q?7JkrPCzWycDiXSOBhnPcJLVWgIDxCbd+oKPv9UoptDS320TtaAgQS3KDJ+ElLYVt/?= =?utf-8?q?y7lXgsKLKASBLuyTOTLzF6T8fiNJrOCIg+P0G1eDgNIxowARf6DG+JsWuELzSGkbY?= =?utf-8?q?Nsggpj6Zu8/GOWMcr3Y1u3trXK9r2l02Q=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68c5237d-18c4-4ed7-13ba-08d9ec9fbf1d X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2022 14:15:10.8385 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +etmNaEF6AIeMsHbLGyecB6w766ScPjft2mhQjBjM+KZaGwc/wYFvS7fqLhqWloFKWahxP+HeLRc+kQiXygUtAyM91qzOVW+923Z3i3cwg4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5413 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe1e::72c (failed) Received-SPF: pass client-ip=2a01:111:f400:fe1e::72c; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Let's use SocketAddressList instead of dynamic arrays. Benefits: - Automatic cleanup: don't need specific freeing function and drop some gotos. - Less indirection: no triple asterix anymore! - Prepare for the following commit, which will reuse new interface of vnc_display_listen(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé --- ui/vnc.c | 129 ++++++++++++++++++++++--------------------------------- 1 file changed, 51 insertions(+), 78 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 3ccd33dedc..fa0fb736d3 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3812,30 +3812,19 @@ static int vnc_display_get_address(const char *addrstr, return ret; } -static void vnc_free_addresses(SocketAddress ***retsaddr, - size_t *retnsaddr) -{ - size_t i; - - for (i = 0; i < *retnsaddr; i++) { - qapi_free_SocketAddress((*retsaddr)[i]); - } - g_free(*retsaddr); - - *retsaddr = NULL; - *retnsaddr = 0; -} - static int vnc_display_get_addresses(QemuOpts *opts, bool reverse, - SocketAddress ***retsaddr, - size_t *retnsaddr, - SocketAddress ***retwsaddr, - size_t *retnwsaddr, + SocketAddressList **saddr_list_ret, + SocketAddressList **wsaddr_list_ret, Error **errp) { SocketAddress *saddr = NULL; SocketAddress *wsaddr = NULL; + g_autoptr(SocketAddressList) saddr_list = NULL; + SocketAddressList **saddr_tail = &saddr_list; + SocketAddress *single_saddr = NULL; + g_autoptr(SocketAddressList) wsaddr_list = NULL; + SocketAddressList **wsaddr_tail = &wsaddr_list; QemuOptsIter addriter; const char *addr; int to = qemu_opt_get_number(opts, "to", 0); @@ -3844,23 +3833,16 @@ static int vnc_display_get_addresses(QemuOpts *opts, bool ipv4 = qemu_opt_get_bool(opts, "ipv4", false); bool ipv6 = qemu_opt_get_bool(opts, "ipv6", false); int displaynum = -1; - int ret = -1; - - *retsaddr = NULL; - *retnsaddr = 0; - *retwsaddr = NULL; - *retnwsaddr = 0; addr = qemu_opt_get(opts, "vnc"); if (addr == NULL || g_str_equal(addr, "none")) { - ret = 0; - goto cleanup; + return 0; } if (qemu_opt_get(opts, "websocket") && !qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) { error_setg(errp, "SHA1 hash support is required for websockets"); - goto cleanup; + return -1; } qemu_opt_iter_init(&addriter, opts, "vnc"); @@ -3871,7 +3853,7 @@ static int vnc_display_get_addresses(QemuOpts *opts, ipv4, ipv6, &saddr, errp); if (rv < 0) { - goto cleanup; + return -1; } /* Historical compat - first listen address can be used * to set the default websocket port @@ -3879,13 +3861,16 @@ static int vnc_display_get_addresses(QemuOpts *opts, if (displaynum == -1) { displaynum = rv; } - *retsaddr = g_renew(SocketAddress *, *retsaddr, *retnsaddr + 1); - (*retsaddr)[(*retnsaddr)++] = saddr; + QAPI_LIST_APPEND(saddr_tail, saddr); } - /* If we had multiple primary displays, we don't do defaults - * for websocket, and require explicit config instead. */ - if (*retnsaddr > 1) { + if (saddr_list && !saddr_list->next) { + single_saddr = saddr_list->value; + } else { + /* + * If we had multiple primary displays, we don't do defaults + * for websocket, and require explicit config instead. + */ displaynum = -1; } @@ -3895,57 +3880,50 @@ static int vnc_display_get_addresses(QemuOpts *opts, has_ipv4, has_ipv6, ipv4, ipv6, &wsaddr, errp) < 0) { - goto cleanup; + return -1; } /* Historical compat - if only a single listen address was * provided, then this is used to set the default listen * address for websocket too */ - if (*retnsaddr == 1 && - (*retsaddr)[0]->type == SOCKET_ADDRESS_TYPE_INET && + if (single_saddr && + single_saddr->type == SOCKET_ADDRESS_TYPE_INET && wsaddr->type == SOCKET_ADDRESS_TYPE_INET && g_str_equal(wsaddr->u.inet.host, "") && - !g_str_equal((*retsaddr)[0]->u.inet.host, "")) { + !g_str_equal(single_saddr->u.inet.host, "")) { g_free(wsaddr->u.inet.host); - wsaddr->u.inet.host = g_strdup((*retsaddr)[0]->u.inet.host); + wsaddr->u.inet.host = g_strdup(single_saddr->u.inet.host); } - *retwsaddr = g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + 1); - (*retwsaddr)[(*retnwsaddr)++] = wsaddr; + QAPI_LIST_APPEND(wsaddr_tail, wsaddr); } - ret = 0; - cleanup: - if (ret < 0) { - vnc_free_addresses(retsaddr, retnsaddr); - vnc_free_addresses(retwsaddr, retnwsaddr); - } - return ret; + *saddr_list_ret = g_steal_pointer(&saddr_list); + *wsaddr_list_ret = g_steal_pointer(&wsaddr_list); + return 0; } static int vnc_display_connect(VncDisplay *vd, - SocketAddress **saddr, - size_t nsaddr, - SocketAddress **wsaddr, - size_t nwsaddr, + SocketAddressList *saddr_list, + SocketAddressList *wsaddr_list, Error **errp) { /* connect to viewer */ QIOChannelSocket *sioc = NULL; - if (nwsaddr != 0) { + if (wsaddr_list) { error_setg(errp, "Cannot use websockets in reverse mode"); return -1; } - if (nsaddr != 1) { + if (!saddr_list || saddr_list->next) { error_setg(errp, "Expected a single address in reverse mode"); return -1; } /* TODO SOCKET_ADDRESS_TYPE_FD when fd has AF_UNIX */ - vd->is_unix = saddr[0]->type == SOCKET_ADDRESS_TYPE_UNIX; + vd->is_unix = saddr_list->value->type == SOCKET_ADDRESS_TYPE_UNIX; sioc = qio_channel_socket_new(); qio_channel_set_name(QIO_CHANNEL(sioc), "vnc-reverse"); - if (qio_channel_socket_connect_sync(sioc, saddr[0], errp) < 0) { + if (qio_channel_socket_connect_sync(sioc, saddr_list->value, errp) < 0) { object_unref(OBJECT(sioc)); return -1; } @@ -3956,20 +3934,18 @@ static int vnc_display_connect(VncDisplay *vd, static int vnc_display_listen(VncDisplay *vd, - SocketAddress **saddr, - size_t nsaddr, - SocketAddress **wsaddr, - size_t nwsaddr, + SocketAddressList *saddr_list, + SocketAddressList *wsaddr_list, Error **errp) { - size_t i; + SocketAddressList *el; - if (nsaddr) { + if (saddr_list) { vd->listener = qio_net_listener_new(); qio_net_listener_set_name(vd->listener, "vnc-listen"); - for (i = 0; i < nsaddr; i++) { + for (el = saddr_list; el; el = el->next) { if (qio_net_listener_open_sync(vd->listener, - saddr[i], 1, + el->value, 1, errp) < 0) { return -1; } @@ -3979,12 +3955,12 @@ static int vnc_display_listen(VncDisplay *vd, vnc_listen_io, vd, NULL); } - if (nwsaddr) { + if (wsaddr_list) { vd->wslistener = qio_net_listener_new(); qio_net_listener_set_name(vd->wslistener, "vnc-ws-listen"); - for (i = 0; i < nwsaddr; i++) { + for (el = wsaddr_list; el; el = el->next) { if (qio_net_listener_open_sync(vd->wslistener, - wsaddr[i], 1, + el->value, 1, errp) < 0) { return -1; } @@ -4002,8 +3978,8 @@ void vnc_display_open(const char *id, Error **errp) { VncDisplay *vd = vnc_display_find(id); QemuOpts *opts = qemu_opts_find(&qemu_vnc_opts, id); - SocketAddress **saddr = NULL, **wsaddr = NULL; - size_t nsaddr, nwsaddr; + g_autoptr(SocketAddressList) saddr_list = NULL; + g_autoptr(SocketAddressList) wsaddr_list = NULL; const char *share, *device_id; QemuConsole *con; bool password = false; @@ -4028,8 +4004,8 @@ void vnc_display_open(const char *id, Error **errp) } reverse = qemu_opt_get_bool(opts, "reverse", false); - if (vnc_display_get_addresses(opts, reverse, &saddr, &nsaddr, - &wsaddr, &nwsaddr, errp) < 0) { + if (vnc_display_get_addresses(opts, reverse, &saddr_list, &wsaddr_list, + errp) < 0) { goto fail; } @@ -4211,16 +4187,16 @@ void vnc_display_open(const char *id, Error **errp) } qkbd_state_set_delay(vd->kbd, key_delay_ms); - if (saddr == NULL) { - goto cleanup; + if (saddr_list == NULL) { + return; } if (reverse) { - if (vnc_display_connect(vd, saddr, nsaddr, wsaddr, nwsaddr, errp) < 0) { + if (vnc_display_connect(vd, saddr_list, wsaddr_list, errp) < 0) { goto fail; } } else { - if (vnc_display_listen(vd, saddr, nsaddr, wsaddr, nwsaddr, errp) < 0) { + if (vnc_display_listen(vd, saddr_list, wsaddr_list, errp) < 0) { goto fail; } } @@ -4229,14 +4205,11 @@ void vnc_display_open(const char *id, Error **errp) vnc_display_print_local_addr(vd); } - cleanup: - vnc_free_addresses(&saddr, &nsaddr); - vnc_free_addresses(&wsaddr, &nwsaddr); + /* Success */ return; fail: vnc_display_close(vd); - goto cleanup; } void vnc_display_add_client(const char *id, int csock, bool skipauth) From patchwork Thu Feb 10 14:14:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12742162 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D7A9C433F5 for ; Thu, 10 Feb 2022 16:32:29 +0000 (UTC) Received: from localhost ([::1]:35804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nICMu-0001WO-6D for qemu-devel@archiver.kernel.org; Thu, 10 Feb 2022 11:32:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIAjn-0001EY-KP for qemu-devel@nongnu.org; Thu, 10 Feb 2022 09:47:59 -0500 Received: from [2a01:111:f400:fe0c::702] (port=44267 helo=EUR04-DB3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIAjl-00038U-JN for qemu-devel@nongnu.org; Thu, 10 Feb 2022 09:47:59 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UwzxvabF9aEv0FuusY7eT5S7vyHYMR8mHsrYrnvwxSLCa6UdKAilP586+eV44OGuhVfCsgH35vRJjVgpkEVEylfZ/In42ZeUuFc9Ud6ouOyZhB/GW1xnHySd7kpnUw+YDW1k8ADkWQpHHsZXOC8MVWHVlP6O7Bx1M9XUow2Mpkrxu7SxTngwJF6dBwvshEf7EHH70dXqMaxrxqmSMamGgFsPCXcd/7TVMoQexkR6ew7SM6UxXWddfzzLjR4LP6j9BYDhvEAKMF8mXtopX0qXASaW8pilyHnft6xPKGaW84NHQk/qDUACbrmF82Hc99LMkbAr1Kd2wLUOXLZvES9mug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=d9qLf2HmZWferDuV6qhpZKzALdt2LF+VsCTyvCRhCQE=; b=MCuwrlaAqU5vGpUGMxJzm9kv1zXgM9uQIWpxkWMOQv+nWl2tRYHFn4NAp+MplTY/KPQj6JviMQKE1TLMlUEbQj7qmS2gbdVzWApFkXPaiL9LYCv7Xpy7Y13YdYr0P5Ywb7KuWYabgRhZomvGKxEsmJ20Ygj1dl5Ev8Y70uXskM623v0cpBYC/MbtE5n52zGGPJNrVQfkMH+EdFgF+7oZ5XFhO5W6k5prOTSqDiBw2UKaBJCXQWM0+IQkc532SSzDRPSaPUK8pGM7TQd/XgkFgq/EtLWob86fZon8asH9H7zLhhibEwQpHvDiWDMAdbLXSBA7TRvEW0WTrbS52wW1Aw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d9qLf2HmZWferDuV6qhpZKzALdt2LF+VsCTyvCRhCQE=; b=OJo6sY2O9pN323Jgrpb/Gg2tUUJCSfzoeK7FrOszmiVvVK+eLciLeirI5iSjwPhiOEOcHQHZIxdVUCZznb8mcYPtesbYY4VDIWJFFxSsHA5n0hSEzDF8rIP7ev5h8xO9t0onMePVU/WlXPEvGALvNmKOUkvMFfrQRoQnBA26BVc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM7PR08MB5413.eurprd08.prod.outlook.com (2603:10a6:20b:10a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 14:15:12 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4975.011; Thu, 10 Feb 2022 14:15:11 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: bleal@redhat.com, wainersm@redhat.com, f4bug@amsat.org, crosa@redhat.com, eblake@redhat.com, armbru@redhat.com, kraxel@redhat.com, vsementsov@virtuozzo.com, berrange@redhat.com, marcandre.lureau@redhat.com Subject: [PATCH v4 2/3] qapi/ui: display-update: add possibility to change listen address Date: Thu, 10 Feb 2022 15:14:56 +0100 Message-Id: <20220210141457.539582-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220210141457.539582-1-vsementsov@virtuozzo.com> References: <20220210141457.539582-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6PR05CA0036.eurprd05.prod.outlook.com (2603:10a6:20b:2e::49) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4c27e64c-3eee-4376-8788-08d9ec9fbfec X-MS-TrafficTypeDiagnostic: AM7PR08MB5413:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0bOVVJPm1tIo4hSCdSu+HkNQ5ejPUdJq6FrjdHUty9xVwPvH0coOwvsD82tUTlew37nRtTIsGnekhZG0+mUti7/SdKcrSoiIf6ndsu4pbDNr9e5G1EsE9XevyCMkH7pSRcOYZ3ypZk46mM8bp4/k9I5DeBqrBqXxkIfZMdSDuxjy9hbfFNfGA+j6ooj/PA3SYHBdHTh4wVG7Nz+vfytY5wZ+gPfNJZxS5FwUePMMrKAVj1Gv7kRQvSpjW3f8PcWkN0Vv9Ei2qXHBKtggEI9wzc9DnebQxMACajxiTe+4pEQWdd2/Kkig0hNJ8PUBVC+QiGDdmJGtSeD1Jq9CL+DtOsqcuGjLXKbOfj6NogfNd4rKEnEOtuSycgHq3qPNfPhn+tb3NqN9h48+ZIt9iWFovYF3pSUKzSIjCixL7oP5iypM9VfqD/zCPAt7aYb3dPfzEMO/MwDzsVo+EMp/2oE48sa3bu6zrgWefmIzjU0+O+sUpDPyLAYIMLrIpHTlghll4SyiHyCSm0eY4lGCIj2UwqKOO+z7m7Zc2jdpfSVi2VMFoUkR6MpoHmxYLRo5/nVJ8yi2khlJyJ9UnMOo2tiGm9hE1htL5RVgssDI90lH3ZLF6Zi8UIOsb+YTPVwS2LGBHQZpdxzwYNtdLmlgkIlwMK1hDq3HMLCIsNWqPu7yk59WFjHLSK+PEHaTrdPkrzOL9ByDF/zDrL2o4O/FZKxXQg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(26005)(186003)(52116002)(2616005)(15650500001)(2906002)(6506007)(38100700002)(316002)(86362001)(6916009)(38350700002)(66946007)(1076003)(66556008)(66476007)(4326008)(8676002)(5660300002)(8936002)(6486002)(6512007)(83380400001)(7416002)(6666004)(508600001)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: w4HBc6q6IYyU1A4Ig2dtTQ3FdB7CtaaG+xVzr+l15tE7VWWcVpmMfC+ts2Yc6s53b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ShyaYp28vnbPhrwEmIAldDAiaMct8eOBzOlpT5DFq3RlgLAjtGeXFaY2ha+qZH4wIDqpZNVRMWeUqOvBog1FnXh1/azIS1z+p4Wgqu8aWCwq9el5GIwYU7n6OY6J8a4FA5ZcvyujdSMg84pJiD2RNF+vOFvKreoovR0yiER1epnUHaji45FUJIlrVYNPvoLjFfkIhbmDwoomRdI6HCI/OmYjtvjqXN/aSlO/bdtA5e/aorY/gc1ZnG4Uk5gq0XjDIV6OvrE9w8ehtd7/VzRL27ECCan+/8gASuXUtJCSPy3vtyOFJEVFY/2s+kmvnq7QAQ1T8Qx0waPGa75vZD7rATXwAf0LtKewLBQrSBXBHOvySjevAG19+YhKz/BYbEKUIjHUYtnVTg583iOCWLi5Sh+p0dBMf+3vFwIMGTZpeeRw3aTkFhbzbcH5dg7bdCcnJc4lL5jvwz+dIkZBzFyrmrB0+jToOeALn4Avupknbc/ODV2W3QgEzSCdZaSBsZdu2Sy8OWlDrwaPpeGt7arjer5hB4p/aJA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c27e64c-3eee-4376-8788-08d9ec9fbfec X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2022 14:15:11.6664 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Jcb5RbNPbeyeCIxIKFNAx1ZycEWiH1Snu2thOFunTCFxL3PF/AIhvPni5gWZU4Bi6dA95mLSIfSb25xk2+Bi419OJRlNF/XSGsK+MTt8ayM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5413 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe0c::702 (failed) Received-SPF: pass client-ip=2a01:111:f400:fe0c::702; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add possibility to change addresses where VNC server listens for new connections. Prior to 6.0 this functionality was available through 'change' qmp command which was deleted. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniel P. Berrangé --- docs/about/removed-features.rst | 3 +- qapi/ui.json | 65 +++++++++++++++++++++++++++++++++ include/ui/console.h | 1 + monitor/qmp-cmds.c | 15 ++++++++ ui/vnc.c | 23 ++++++++++++ 5 files changed, 106 insertions(+), 1 deletion(-) diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.rst index 4c4da20d0f..63aba60873 100644 --- a/docs/about/removed-features.rst +++ b/docs/about/removed-features.rst @@ -355,7 +355,8 @@ documentation of ``query-hotpluggable-cpus`` for additional details. ``change`` (removed in 6.0) ''''''''''''''''''''''''''' -Use ``blockdev-change-medium`` or ``change-vnc-password`` instead. +Use ``blockdev-change-medium`` or ``change-vnc-password`` or +``display-update`` instead. ``query-events`` (removed in 6.0) ''''''''''''''''''''''''''''''''' diff --git a/qapi/ui.json b/qapi/ui.json index 9354f4c467..a0851eeefa 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1334,3 +1334,68 @@ { 'command': 'display-reload', 'data': 'DisplayReloadOptions', 'boxed' : true } + +## +# @DisplayUpdateType: +# +# Available DisplayUpdate types. +# +# @vnc: VNC display +# +# Since: 7.0 +# +## +{ 'enum': 'DisplayUpdateType', + 'data': ['vnc'] } + +## +# @DisplayUpdateOptionsVNC: +# +# Specify the VNC reload options. +# +# @addresses: If specified, change set of addresses +# to listen for connections. Addresses configured +# for websockets are not touched. +# +# Since: 7.0 +# +## +{ 'struct': 'DisplayUpdateOptionsVNC', + 'data': { '*addresses': ['SocketAddress'] } } + +## +# @DisplayUpdateOptions: +# +# Options of the display configuration reload. +# +# @type: Specify the display type. +# +# Since: 7.0 +# +## +{ 'union': 'DisplayUpdateOptions', + 'base': {'type': 'DisplayUpdateType'}, + 'discriminator': 'type', + 'data': { 'vnc': 'DisplayUpdateOptionsVNC' } } + +## +# @display-update: +# +# Update display configuration. +# +# Returns: Nothing on success. +# +# Since: 7.0 +# +# Example: +# +# -> { "execute": "display-reload", +# "arguments": { "type": "vnc", "addresses": +# [ { "type": "inet", "host": "0.0.0.0", +# "port": "5901" } ] } } +# <- { "return": {} } +# +## +{ 'command': 'display-update', + 'data': 'DisplayUpdateOptions', + 'boxed' : true } diff --git a/include/ui/console.h b/include/ui/console.h index f590819880..45f2ed4e2c 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -513,6 +513,7 @@ int vnc_display_pw_expire(const char *id, time_t expires); void vnc_parse(const char *str); int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp); bool vnc_display_reload_certs(const char *id, Error **errp); +bool vnc_display_update(DisplayUpdateOptionsVNC *arg, Error **errp); /* input.c */ int index_from_key(const char *key, size_t key_length); diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index db4d186448..246c8c1202 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -368,6 +368,21 @@ void qmp_display_reload(DisplayReloadOptions *arg, Error **errp) } } +void qmp_display_update(DisplayUpdateOptions *arg, Error **errp) +{ + switch (arg->type) { + case DISPLAY_UPDATE_TYPE_VNC: +#ifdef CONFIG_VNC + vnc_display_update(&arg->u.vnc, errp); +#else + error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'"); +#endif + break; + default: + abort(); + } +} + static int qmp_x_query_rdma_foreach(Object *obj, void *opaque) { RdmaProvider *rdma; diff --git a/ui/vnc.c b/ui/vnc.c index fa0fb736d3..c57146d9f8 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3973,6 +3973,29 @@ static int vnc_display_listen(VncDisplay *vd, return 0; } +bool vnc_display_update(DisplayUpdateOptionsVNC *arg, Error **errp) +{ + VncDisplay *vd = vnc_display_find(NULL); + + if (!vd) { + error_setg(errp, "Can not find vnc display"); + return false; + } + + if (arg->has_addresses) { + if (vd->listener) { + qio_net_listener_disconnect(vd->listener); + object_unref(OBJECT(vd->listener)); + vd->listener = NULL; + } + + if (vnc_display_listen(vd, arg->addresses, NULL, errp) < 0) { + return false; + } + } + + return true; +} void vnc_display_open(const char *id, Error **errp) { From patchwork Thu Feb 10 14:14:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12742240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2B4CC433F5 for ; Thu, 10 Feb 2022 17:19:13 +0000 (UTC) Received: from localhost ([::1]:50204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nID68-0001E9-Oy for qemu-devel@archiver.kernel.org; Thu, 10 Feb 2022 12:19:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIATq-0005gZ-7t for qemu-devel@nongnu.org; Thu, 10 Feb 2022 09:31:30 -0500 Received: from [2a01:111:f400:fe0e::713] (port=59205 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIATl-0005YP-Uj for qemu-devel@nongnu.org; Thu, 10 Feb 2022 09:31:29 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e3oqBuBhBosEQ8FhdmZWTk9FQsH/zIHi2MQZ674a5A5QBOdL5c04KMICJmbf8bFsYTOoMDUhL3najkAoW/qXwnPlGhlbGkO2CblEJAY2JFkBQsP/duCioTe68iUxi7UyJt5yRyrzpLBbAWWorNOi0VxH+kjTK+doKqk3GPdmTbX/6idDWWwzA7saDjYCd67xrMNfg3C6P8Z2t+QqHo8rHM3iyeh5C+O3/VgiviQ9UUSjKYoXKhUYauB3g3hiFeNKpF63jcue+93swrii6WgB2hz4g3QMB7e3z08KY7F33d22JB0i/2K73c9eGmvjNKo9ED8zchB9HnBkcTThOylAPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=w9MWv8VsixDzIlWBcFWId4t9t43WSQXY3R+K47DAjSQ=; b=I3WKf5sPBXGCGbIe3VwErp/F8fd6qSuUs8TlGKUu3Hc4/DtQYSqI+khpsx5Zawb3l+Zu4zbt/yOR/9tZttSzyN531YsfBgyHhhhBeeXBnoDTu+nWfzDtkgoQTCr6X9HMLn/LLadchmS0DN0Ci5mkEHh20YdPs+tZHNK1v8sIP8dfMQexBanYl+UDseUwYQisQ77yVF+S2C2W1GUjynPWIlmttmbPyczAZ8IKl+e/8TgIOqhM7miwKS0E2EVmfUQC8r19np87oVU3wFXX6tTQuHW1ycuRh7sM5wbVY/V+Q2/YXivsF6RWlRLgLliE4/2ESZ1YbKzmNH3J5i3zyvGKWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w9MWv8VsixDzIlWBcFWId4t9t43WSQXY3R+K47DAjSQ=; b=EOAks1Zfl5nISzwpar5ea4xYKegDpA2E6rACCtgzwPvtr8/DxorASBnPXrM7tUPRX9h3RJ3W4O01Pmu/MV1pAAfccbLLp6F8zy/KZYkjAbbC2p6Li3b3It4ikGzcdLfJWK0VKvCXNCVR0gDy7yyEFZhijy/LY0EYVRTblzjnxHY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM7PR08MB5413.eurprd08.prod.outlook.com (2603:10a6:20b:10a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 14:15:13 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4975.011; Thu, 10 Feb 2022 14:15:13 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: bleal@redhat.com, wainersm@redhat.com, f4bug@amsat.org, crosa@redhat.com, eblake@redhat.com, armbru@redhat.com, kraxel@redhat.com, vsementsov@virtuozzo.com, berrange@redhat.com, marcandre.lureau@redhat.com Subject: [PATCH v4 3/3] avocado/vnc: add test_change_listen Date: Thu, 10 Feb 2022 15:14:57 +0100 Message-Id: <20220210141457.539582-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220210141457.539582-1-vsementsov@virtuozzo.com> References: <20220210141457.539582-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6PR05CA0036.eurprd05.prod.outlook.com (2603:10a6:20b:2e::49) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c775fec1-323d-4a78-6458-08d9ec9fc093 X-MS-TrafficTypeDiagnostic: AM7PR08MB5413:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8dQ1cdB/9sietSPMmiZmyFa41lV2HyjnplrJKWRYzv2yUgh3Ec6u1ZOgo6JqpdME3agYCTPjFfQlscPd5c/tNBxTpMbIAiIuTJqbLFqbRmTNoFI4o6p/99gAhCqoPmaWAvH+iPtcRXiOH/LIWkGz+jKHJclQGhg/1O1m/CrcwakSgH5OwPNLmKiwNCw5okQw1BU2kGJpGv2iXtd+yaVR8zKoCE4uJh7wv5feT/hXuk0pmSio2NRpC7dXNg9jlqGepnrVqsdU/tOSsBc9FyEXf7bFtMnu+OyrKX+epPWj0Bu/8MbB3BhVmkU0ali2isutrlGaMszzSsnGmRg76x2P4ucmTNfOEBFvVfh+PnQS/EgmtXxlhgzPgW6dLmiFekXB+xPxrUPXsWlOzuDzV23wJWVeppfduUjx7BfvsjWkIuUoBF6P8XXXGeXpBuHlTvUmKLCemRA4AdNTPKJEgCVN6ON0R18bXXWRzal+mdYs4mlP8/6ctJ9oW8+C7UBlvG03el7wwbVLwCYbuh72uj6eNRvMy7jsUHt2iscAvUDRc0DX4T1V62dM2LfCfEQK/PsY6vDz3vZ85k9aSGnNjNW0FUok024/G8WM+iIVvyObZfdAD1ToDzGSxwVggkz8YI3rwVT62V5fK8FmnX+xbfAPearwnIXSdrmYj4yDNV6y0e/FoieFKUHtVMF7trLHUGPDNUNR6oDMPDJ8Rpwc7dtlfQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(26005)(186003)(52116002)(2616005)(2906002)(6506007)(38100700002)(316002)(86362001)(6916009)(38350700002)(66946007)(1076003)(66556008)(66476007)(4326008)(8676002)(5660300002)(8936002)(6486002)(6512007)(83380400001)(7416002)(6666004)(508600001)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ARR2Sna7vkiBZYw9DaP18FQXN1w2SY17XijpezhuXBBFWDj4PBr2v122R6lZO7l5vU9nSIGg6EPJrqNR50Xpxoe8DVhYHT5+wpfv+yQ8ePTkpa+LzmTAQGPS1glSQsC9kEG4zbzkWZBvM0KQw91e0N90OBNDKDHij/vAZLqDVJgKqxVnhq+14D+mNoFjzj05UB5n8HNFEdazkeNSGNdPtwqIB3/D5UtU/p51hHIdBCXNZ3Z313OsL84Q2I9Rb6HTQHRHzoHp0tAMjNFnIlvpg9nBBmDzjjzchKGNSVuHdDGMFVQSnNEZcCo1MotlOpwvM2sh9lM8Set1V1rvEHod/acMOotJlz5xDB1N57MSzTHFN4ZykDRej/9tAJTx+bjYO8yKKpevBq6kjJGbpJtuq2EyIwpqxyk1r2hbB1hfzRdxh3iCcwFPUPyhkDz1pEFWSOQKgSks6wZgBgG1R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f0rhwhnSsJ5eLZ9g2/D88ccYYv4P6bb+gTsQQ9V5jVqm/YoDay0ja8+6Z3W08LJMZX2LHCbwOwJHlhagTyZCZx8HnpVkFrhBFsapohG0Y7AgaeUrHXte+StdQWuaJZFeHeh7KlCBBh28RZpp/5gel5FCdOTQ== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c775fec1-323d-4a78-6458-08d9ec9fc093 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2022 14:15:12.6987 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 458QR2x125Yg/Sodh1NxVq5fIALY5uEUD60G4mJj5kc3aHRwwh77kn0Sy+jz0fj4Ihn+wXV1gd/wdmog0SHmUp7z+l8K2stZexyet9fB9yw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5413 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe0e::713 (failed) Received-SPF: pass client-ip=2a01:111:f400:fe0e::713; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add simple test-case for new display-update qmp command. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniel P. Berrangé --- tests/avocado/vnc.py | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/avocado/vnc.py b/tests/avocado/vnc.py index 096432988f..187fd3febc 100644 --- a/tests/avocado/vnc.py +++ b/tests/avocado/vnc.py @@ -8,9 +8,48 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. +import socket +from typing import List + from avocado_qemu import QemuSystemTest +VNC_ADDR = '127.0.0.1' +VNC_PORT_START = 32768 +VNC_PORT_END = VNC_PORT_START + 1024 + + +def check_bind(port: int) -> bool: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + try: + sock.bind((VNC_ADDR, port)) + except OSError: + return False + + return True + + +def check_connect(port: int) -> bool: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + try: + sock.connect((VNC_ADDR, port)) + except ConnectionRefusedError: + return False + + return True + + +def find_free_ports(count: int) -> List[int]: + result = [] + for port in range(VNC_PORT_START, VNC_PORT_END): + if check_bind(port): + result.append(port) + if len(result) >= count: + break + assert len(result) == count + return result + + class Vnc(QemuSystemTest): """ :avocado: tags=vnc,quick @@ -51,3 +90,27 @@ def test_change_password(self): set_password_response = self.vm.qmp('change-vnc-password', password='new_password') self.assertEqual(set_password_response['return'], {}) + + def test_change_listen(self): + a, b, c = find_free_ports(3) + self.assertFalse(check_connect(a)) + self.assertFalse(check_connect(b)) + self.assertFalse(check_connect(c)) + + self.vm.add_args('-nodefaults', '-S', '-vnc', f'{VNC_ADDR}:{a - 5900}') + self.vm.launch() + self.assertEqual(self.vm.qmp('query-vnc')['return']['service'], str(a)) + self.assertTrue(check_connect(a)) + self.assertFalse(check_connect(b)) + self.assertFalse(check_connect(c)) + + res = self.vm.qmp('display-update', type='vnc', + addresses=[{'type': 'inet', 'host': VNC_ADDR, + 'port': str(b)}, + {'type': 'inet', 'host': VNC_ADDR, + 'port': str(c)}]) + self.assertEqual(res['return'], {}) + self.assertEqual(self.vm.qmp('query-vnc')['return']['service'], str(b)) + self.assertFalse(check_connect(a)) + self.assertTrue(check_connect(b)) + self.assertTrue(check_connect(c))