From nobody Fri May 3 10:45:11 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16508680305321013.2986340647376; Sun, 24 Apr 2022 23:27:10 -0700 (PDT) Received: from localhost ([::1]:53670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nisBf-0000zN-0N for importer2@patchew.org; Mon, 25 Apr 2022 02:27:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvi-0003gJ-UA for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:46701) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvg-0006IT-8x for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:37 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-115-ftfI9Nr-PleUMiVIeY58Jw-1; Mon, 25 Apr 2022 02:10:31 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 574483804062; Mon, 25 Apr 2022 06:10:31 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 074E7463DF9; Mon, 25 Apr 2022 06:10:31 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C568B18003BA; Mon, 25 Apr 2022 08:10:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650867033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oJ9Ufvj12vzxAT3bkAQJ/3nh94mDOPCyRdbWI9L4yLw=; b=LnMogsVrBUlfho0McYJtZFS4WM9I/cjyRpFdfEBNV7y3h38youtmI0r5cd9z+vSW+iy+Od gSS0xz7jjIk4tSIN3YqHezxIoQIN1NVF3Jo69EN90w+NSx+zQuq3j4pVjQDnRXeUtwjjcA m1KLtaguKZR8eDczTYVnEm91JUkhHYA= X-MC-Unique: ftfI9Nr-PleUMiVIeY58Jw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 1/6] hw/display/vmware_vga: do not discard screen updates Date: Mon, 25 Apr 2022 08:10:24 +0200 Message-Id: <20220425061029.3932731-2-kraxel@redhat.com> In-Reply-To: <20220425061029.3932731-1-kraxel@redhat.com> References: <20220425061029.3932731-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Cc: Beraldo Leal , Markus Armbruster , Carwyn Ellis , "Dr. David Alan Gilbert" , Wainer dos Santos Moschetta , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650868032409100001 Content-Type: text/plain; charset="utf-8" From: Carwyn Ellis In certain circumstances, typically when there is lots changing on the screen, updates will be discarded resulting in garbled output. This change simplifies the traversal of the display update FIFO queue when applying updates. We just track the queue length and iterate up to the end of the queue. Additionally when adding updates to the queue, if the buffer reaches capacity we force a flush before accepting further events. Signed-off-by: Carwyn Ellis Message-Id: <20220206183956.10694-3-carwynellis@gmail.com> Signed-off-by: Gerd Hoffmann --- hw/display/vmware_vga.c | 45 +++++++++++++++++++++++------------------ hw/display/trace-events | 1 + 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c index 45d06cbe2544..cedbbde522ec 100644 --- a/hw/display/vmware_vga.c +++ b/hw/display/vmware_vga.c @@ -80,7 +80,7 @@ struct vmsvga_state_s { struct vmsvga_rect_s { int x, y, w, h; } redraw_fifo[REDRAW_FIFO_LEN]; - int redraw_fifo_first, redraw_fifo_last; + int redraw_fifo_last; }; =20 #define TYPE_VMWARE_SVGA "vmware-svga" @@ -380,35 +380,41 @@ static inline void vmsvga_update_rect(struct vmsvga_s= tate_s *s, dpy_gfx_update(s->vga.con, x, y, w, h); } =20 +static inline void vmsvga_update_rect_flush(struct vmsvga_state_s *s) +{ + struct vmsvga_rect_s *rect; + + if (s->invalidated) { + s->redraw_fifo_last =3D 0; + return; + } + /* Overlapping region updates can be optimised out here - if someone + * knows a smart algorithm to do that, please share. */ + for (int i =3D 0; i < s->redraw_fifo_last; i++) { + rect =3D &s->redraw_fifo[i]; + vmsvga_update_rect(s, rect->x, rect->y, rect->w, rect->h); + } + + s->redraw_fifo_last =3D 0; +} + static inline void vmsvga_update_rect_delayed(struct vmsvga_state_s *s, int x, int y, int w, int h) { + + if (s->redraw_fifo_last >=3D REDRAW_FIFO_LEN) { + trace_vmware_update_rect_delayed_flush(); + vmsvga_update_rect_flush(s); + } + struct vmsvga_rect_s *rect =3D &s->redraw_fifo[s->redraw_fifo_last++]; =20 - s->redraw_fifo_last &=3D REDRAW_FIFO_LEN - 1; rect->x =3D x; rect->y =3D y; rect->w =3D w; rect->h =3D h; } =20 -static inline void vmsvga_update_rect_flush(struct vmsvga_state_s *s) -{ - struct vmsvga_rect_s *rect; - - if (s->invalidated) { - s->redraw_fifo_first =3D s->redraw_fifo_last; - return; - } - /* Overlapping region updates can be optimised out here - if someone - * knows a smart algorithm to do that, please share. */ - while (s->redraw_fifo_first !=3D s->redraw_fifo_last) { - rect =3D &s->redraw_fifo[s->redraw_fifo_first++]; - s->redraw_fifo_first &=3D REDRAW_FIFO_LEN - 1; - vmsvga_update_rect(s, rect->x, rect->y, rect->w, rect->h); - } -} - #ifdef HW_RECT_ACCEL static inline int vmsvga_copy_rect(struct vmsvga_state_s *s, int x0, int y0, int x1, int y1, int w, int h) @@ -1161,7 +1167,6 @@ static void vmsvga_reset(DeviceState *dev) s->config =3D 0; s->svgaid =3D SVGA_ID; s->cursor.on =3D 0; - s->redraw_fifo_first =3D 0; s->redraw_fifo_last =3D 0; s->syncing =3D 0; =20 diff --git a/hw/display/trace-events b/hw/display/trace-events index 91efc88f04f5..0c0ffcbe42c1 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -24,6 +24,7 @@ vmware_setmode(uint32_t w, uint32_t h, uint32_t bpp) "%dx= %d @ %d bpp" vmware_verify_rect_less_than_zero(const char *name, const char *param, int= x) "%s: %s was < 0 (%d)" vmware_verify_rect_greater_than_bound(const char *name, const char *param,= int bound, int x) "%s: %s was > %d (%d)" vmware_verify_rect_surface_bound_exceeded(const char *name, const char *co= mponent, int bound, const char *param1, int value1, const char *param2, int= value2) "%s: %s > %d (%s: %d, %s: %d)" +vmware_update_rect_delayed_flush(void) "display update FIFO full - forcing= flush" =20 # virtio-gpu-base.c virtio_gpu_features(bool virgl) "virgl %d" --=20 2.35.1 From nobody Fri May 3 10:45:11 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650867461231438.7983589018221; Sun, 24 Apr 2022 23:17:41 -0700 (PDT) Received: from localhost ([::1]:48736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nis2W-0005Zw-70 for importer2@patchew.org; Mon, 25 Apr 2022 02:17:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvj-0003gP-SY for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23808) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvg-0006Il-95 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:38 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-442-hbUGocDkM5CK6VWjyAo8EQ-1; Mon, 25 Apr 2022 02:10:33 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 583E21C05EA2; Mon, 25 Apr 2022 06:10:33 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB89C145BEF8; Mon, 25 Apr 2022 06:10:32 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id DC71D1800617; Mon, 25 Apr 2022 08:10:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650867035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FbYPk+94g04Moi0TxRdJRuTfjONgtgsT2fIdXHO79cU=; b=eJMy2uCKpHYfL3FyqxtS4FPjXJzwZAYU97zIoFCUPEjXsrII0VOOqh2L86UHUQr8Nd42Va U71pvwC7+Gns+RAG9zCjjthEzT+8Z+fo+0srec0LDlTxoI4qUlZ8iPoqMsgMt4ytVI/9PM 89lQES3mSzULc1rFZWCJ7k2lf8YIl34= X-MC-Unique: hbUGocDkM5CK6VWjyAo8EQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 2/6] Replacing CONFIG_VNC_PNG with CONFIG_PNG Date: Mon, 25 Apr 2022 08:10:25 +0200 Message-Id: <20220425061029.3932731-3-kraxel@redhat.com> In-Reply-To: <20220425061029.3932731-1-kraxel@redhat.com> References: <20220425061029.3932731-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Beraldo Leal , Markus Armbruster , "Dr. David Alan Gilbert" , Wainer dos Santos Moschetta , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kshitij Suri , Gerd Hoffmann , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650867463231100001 From: Kshitij Suri Libpng is only detected if VNC is enabled currently. This patch adds a generalised png option in the meson build which is aimed to replace use of CONFIG_VNC_PNG with CONFIG_PNG. Signed-off-by: Kshitij Suri Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20220408071336.99839-2-kshitij.suri@nutanix.com> [ kraxel: add meson-buildoptions.sh updates ] Signed-off-by: Gerd Hoffmann --- meson_options.txt | 4 ++-- ui/vnc.h | 2 +- ui/vnc-enc-tight.c | 18 +++++++++--------- ui/vnc.c | 4 ++-- meson.build | 12 +++++++----- scripts/meson-buildoptions.sh | 6 +++--- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index 52b11cead44a..d85734f8e6bf 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -177,12 +177,12 @@ option('vde', type : 'feature', value : 'auto', description: 'vde network backend support') option('virglrenderer', type : 'feature', value : 'auto', description: 'virgl rendering support') +option('png', type : 'feature', value : 'auto', + description: 'PNG support with libpng') option('vnc', type : 'feature', value : 'auto', description: 'VNC server') option('vnc_jpeg', type : 'feature', value : 'auto', description: 'JPEG lossy compression for VNC server') -option('vnc_png', type : 'feature', value : 'auto', - description: 'PNG compression for VNC server') option('vnc_sasl', type : 'feature', value : 'auto', description: 'SASL authentication for VNC server') option('vte', type : 'feature', value : 'auto', diff --git a/ui/vnc.h b/ui/vnc.h index a7149831f906..a60fb13115c9 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -201,7 +201,7 @@ typedef struct VncTight { #ifdef CONFIG_VNC_JPEG Buffer jpeg; #endif -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG Buffer png; #endif int levels[4]; diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index 5a4b8a4fc0f6..09200d71b8cf 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -32,7 +32,7 @@ INT32 definitions between jmorecfg.h (included by jpeglib.h) and Win32 basetsd.h (included by windows.h). */ =20 -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG /* The following define is needed by pngconf.h. Otherwise it won't compile, because setjmp.h was already included by osdep.h. */ #define PNG_SKIP_SETJMP_CHECK @@ -95,7 +95,7 @@ static const struct { }; #endif =20 -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG static const struct { int png_zlib_level, png_filters; } tight_png_conf[] =3D { @@ -919,7 +919,7 @@ static int send_full_color_rect(VncState *vs, int x, in= t y, int w, int h) int stream =3D 0; ssize_t bytes; =20 -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG if (tight_can_send_png_rect(vs, w, h)) { return send_png_rect(vs, x, y, w, h, NULL); } @@ -966,7 +966,7 @@ static int send_mono_rect(VncState *vs, int x, int y, int stream =3D 1; int level =3D tight_conf[vs->tight->compression].mono_zlib_level; =20 -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG if (tight_can_send_png_rect(vs, w, h)) { int ret; int bpp =3D vs->client_pf.bytes_per_pixel * 8; @@ -1020,7 +1020,7 @@ static int send_mono_rect(VncState *vs, int x, int y, struct palette_cb_priv { VncState *vs; uint8_t *header; -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG png_colorp png_palette; #endif }; @@ -1082,7 +1082,7 @@ static int send_palette_rect(VncState *vs, int x, int= y, int colors; ssize_t bytes; =20 -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG if (tight_can_send_png_rect(vs, w, h)) { return send_png_rect(vs, x, y, w, h, palette); } @@ -1233,7 +1233,7 @@ static int send_jpeg_rect(VncState *vs, int x, int y,= int w, int h, int quality) /* * PNG compression stuff. */ -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG static void write_png_palette(int idx, uint32_t pix, void *opaque) { struct palette_cb_priv *priv =3D opaque; @@ -1379,7 +1379,7 @@ static int send_png_rect(VncState *vs, int x, int y, = int w, int h, buffer_reset(&vs->tight->png); return 1; } -#endif /* CONFIG_VNC_PNG */ +#endif /* CONFIG_PNG */ =20 static void vnc_tight_start(VncState *vs) { @@ -1706,7 +1706,7 @@ void vnc_tight_clear(VncState *vs) #ifdef CONFIG_VNC_JPEG buffer_free(&vs->tight->jpeg); #endif -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG buffer_free(&vs->tight->png); #endif } diff --git a/ui/vnc.c b/ui/vnc.c index badf1d7664fe..7d55e1500a42 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2165,7 +2165,7 @@ static void set_encodings(VncState *vs, int32_t *enco= dings, size_t n_encodings) vs->features |=3D VNC_FEATURE_TIGHT_MASK; vs->vnc_encoding =3D enc; break; -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG case VNC_ENCODING_TIGHT_PNG: vs->features |=3D VNC_FEATURE_TIGHT_PNG_MASK; vs->vnc_encoding =3D enc; @@ -3256,7 +3256,7 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSoc= ket *sioc, #ifdef CONFIG_VNC_JPEG buffer_init(&vs->tight->jpeg, "vnc-tight-jpeg/%p", sioc); #endif -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG buffer_init(&vs->tight->png, "vnc-tight-png/%p", sioc); #endif buffer_init(&vs->zlib.zlib, "vnc-zlib/%p", sioc); diff --git a/meson.build b/meson.build index d083c6b7bf90..0c38e491f488 100644 --- a/meson.build +++ b/meson.build @@ -1115,14 +1115,16 @@ if gtkx11.found() x11 =3D dependency('x11', method: 'pkg-config', required: gtkx11.found(), kwargs: static_kwargs) endif -vnc =3D not_found png =3D not_found +if get_option('png').allowed() and have_system + png =3D dependency('libpng', required: get_option('png'), + method: 'pkg-config', kwargs: static_kwargs) +endif +vnc =3D not_found jpeg =3D not_found sasl =3D not_found if get_option('vnc').allowed() and have_system vnc =3D declare_dependency() # dummy dependency - png =3D dependency('libpng', required: get_option('vnc_png'), - method: 'pkg-config', kwargs: static_kwargs) jpeg =3D dependency('libjpeg', required: get_option('vnc_jpeg'), method: 'pkg-config', kwargs: static_kwargs) sasl =3D cc.find_library('sasl2', has_headers: ['sasl/sasl.h'], @@ -1554,9 +1556,9 @@ config_host_data.set('CONFIG_TPM', have_tpm) config_host_data.set('CONFIG_USB_LIBUSB', libusb.found()) config_host_data.set('CONFIG_VDE', vde.found()) config_host_data.set('CONFIG_VHOST_USER_BLK_SERVER', have_vhost_user_blk_s= erver) +config_host_data.set('CONFIG_PNG', png.found()) config_host_data.set('CONFIG_VNC', vnc.found()) config_host_data.set('CONFIG_VNC_JPEG', jpeg.found()) -config_host_data.set('CONFIG_VNC_PNG', png.found()) config_host_data.set('CONFIG_VNC_SASL', sasl.found()) config_host_data.set('CONFIG_VIRTFS', have_virtfs) config_host_data.set('CONFIG_VTE', vte.found()) @@ -3667,11 +3669,11 @@ summary_info +=3D {'curses support': curses} summary_info +=3D {'virgl support': virgl} summary_info +=3D {'curl support': curl} summary_info +=3D {'Multipath support': mpathpersist} +summary_info +=3D {'PNG support': png} summary_info +=3D {'VNC support': vnc} if vnc.found() summary_info +=3D {'VNC SASL support': sasl} summary_info +=3D {'VNC JPEG support': jpeg} - summary_info +=3D {'VNC PNG support': png} endif if targetos not in ['darwin', 'haiku', 'windows'] summary_info +=3D {'OSS support': oss} diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 1e26f4571ef4..ef0dcd4a7768 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -94,6 +94,7 @@ meson_options_help() { printf "%s\n" ' oss OSS sound support' printf "%s\n" ' pa PulseAudio sound support' printf "%s\n" ' parallels parallels image format support' + printf "%s\n" ' png PNG support with libpng' printf "%s\n" ' qcow1 qcow1 image format support' printf "%s\n" ' qed qed image format support' printf "%s\n" ' qga-vss build QGA VSS support (broken with MinG= W)' @@ -123,7 +124,6 @@ meson_options_help() { printf "%s\n" ' virtiofsd build virtiofs daemon (virtiofsd)' printf "%s\n" ' vnc VNC server' printf "%s\n" ' vnc-jpeg JPEG lossy compression for VNC server' - printf "%s\n" ' vnc-png PNG compression for VNC server' printf "%s\n" ' vnc-sasl SASL authentication for VNC server' printf "%s\n" ' vte vte support for the gtk UI' printf "%s\n" ' vvfat vvfat image format support' @@ -277,6 +277,8 @@ _meson_option_parse() { --disable-pa) printf "%s" -Dpa=3Ddisabled ;; --enable-parallels) printf "%s" -Dparallels=3Denabled ;; --disable-parallels) printf "%s" -Dparallels=3Ddisabled ;; + --enable-png) printf "%s" -Dpng=3Denabled ;; + --disable-png) printf "%s" -Dpng=3Ddisabled ;; --enable-profiler) printf "%s" -Dprofiler=3Dtrue ;; --disable-profiler) printf "%s" -Dprofiler=3Dfalse ;; --enable-qcow1) printf "%s" -Dqcow1=3Denabled ;; @@ -347,8 +349,6 @@ _meson_option_parse() { --disable-vnc) printf "%s" -Dvnc=3Ddisabled ;; --enable-vnc-jpeg) printf "%s" -Dvnc_jpeg=3Denabled ;; --disable-vnc-jpeg) printf "%s" -Dvnc_jpeg=3Ddisabled ;; - --enable-vnc-png) printf "%s" -Dvnc_png=3Denabled ;; - --disable-vnc-png) printf "%s" -Dvnc_png=3Ddisabled ;; --enable-vnc-sasl) printf "%s" -Dvnc_sasl=3Denabled ;; --disable-vnc-sasl) printf "%s" -Dvnc_sasl=3Ddisabled ;; --enable-vte) printf "%s" -Dvte=3Denabled ;; --=20 2.35.1 From nobody Fri May 3 10:45:11 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650868487872886.0864439641846; Sun, 24 Apr 2022 23:34:47 -0700 (PDT) Received: from localhost ([::1]:58084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nisJ3-0004iF-NK for importer2@patchew.org; Mon, 25 Apr 2022 02:34:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvj-0003gU-ST for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:45840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvg-0006It-92 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:38 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-BteiSzr_OmmcnEMPZNN5wg-1; Mon, 25 Apr 2022 02:10:33 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F5903C02B83; Mon, 25 Apr 2022 06:10:33 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0B6F432108; Mon, 25 Apr 2022 06:10:32 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id F14041800624; Mon, 25 Apr 2022 08:10:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650867035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+I1ngTZVLqcdmFgdt6x0Rr5TgDsIKRVdOnKz0z1zUdU=; b=CuTgsIyE3oSgOYW4+no0sDLatcY8lvSOkzHItNPU+0CStkwJfNBxZ5QNY/hRMkiYjXelr/ 6G3fg8b3Igg4Bl0wL+fnrfuEzIK5GXhKBxbkMpNf610YfoEzNzhJkbeGLrV3PgJqUjcDvE OiBm3meiut/u5G9rFqwWlFthJ20Re7Y= X-MC-Unique: BteiSzr_OmmcnEMPZNN5wg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 3/6] Added parameter to take screenshot with screendump as PNG Date: Mon, 25 Apr 2022 08:10:26 +0200 Message-Id: <20220425061029.3932731-4-kraxel@redhat.com> In-Reply-To: <20220425061029.3932731-1-kraxel@redhat.com> References: <20220425061029.3932731-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Beraldo Leal , Markus Armbruster , "Dr. David Alan Gilbert" , Wainer dos Santos Moschetta , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kshitij Suri , Gerd Hoffmann , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650868488793100001 From: Kshitij Suri Currently screendump only supports PPM format, which is un-compressed. Added a "format" parameter to QMP and HMP screendump command to support PNG image capture using libpng. QMP example usage: { "execute": "screendump", "arguments": { "filename": "/tmp/image", "format":"png" } } HMP example usage: screendump /tmp/image -f png Resolves: https://gitlab.com/qemu-project/qemu/-/issues/718 Signed-off-by: Kshitij Suri Reviewed-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster Acked-by: Dr. David Alan Gilbert Message-Id: <20220408071336.99839-3-kshitij.suri@nutanix.com> Signed-off-by: Gerd Hoffmann --- monitor/hmp-cmds.c | 12 +++++- ui/console.c | 101 +++++++++++++++++++++++++++++++++++++++++++-- hmp-commands.hx | 11 ++--- qapi/ui.json | 24 +++++++++-- 4 files changed, 136 insertions(+), 12 deletions(-) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 634968498b58..2442bfa98984 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1720,9 +1720,19 @@ hmp_screendump(Monitor *mon, const QDict *qdict) const char *filename =3D qdict_get_str(qdict, "filename"); const char *id =3D qdict_get_try_str(qdict, "device"); int64_t head =3D qdict_get_try_int(qdict, "head", 0); + const char *input_format =3D qdict_get_try_str(qdict, "format"); Error *err =3D NULL; + ImageFormat format; =20 - qmp_screendump(filename, id !=3D NULL, id, id !=3D NULL, head, &err); + format =3D qapi_enum_parse(&ImageFormat_lookup, input_format, + IMAGE_FORMAT_PPM, &err); + if (err) { + goto end; + } + + qmp_screendump(filename, id !=3D NULL, id, id !=3D NULL, head, + input_format !=3D NULL, format, &err); +end: hmp_handle_error(mon, err); } =20 diff --git a/ui/console.c b/ui/console.c index 1752f2ec8897..15d0f6affd4c 100644 --- a/ui/console.c +++ b/ui/console.c @@ -37,6 +37,9 @@ #include "exec/memory.h" #include "io/channel-file.h" #include "qom/object.h" +#ifdef CONFIG_PNG +#include +#endif =20 #define DEFAULT_BACKSCROLL 512 #define CONSOLE_CURSOR_PERIOD 500 @@ -291,6 +294,89 @@ void graphic_hw_invalidate(QemuConsole *con) } } =20 +#ifdef CONFIG_PNG +/** + * png_save: Take a screenshot as PNG + * + * Saves screendump as a PNG file + * + * Returns true for success or false for error. + * + * @fd: File descriptor for PNG file. + * @image: Image data in pixman format. + * @errp: Pointer to an error. + */ +static bool png_save(int fd, pixman_image_t *image, Error **errp) +{ + int width =3D pixman_image_get_width(image); + int height =3D pixman_image_get_height(image); + g_autofree png_struct *png_ptr =3D NULL; + g_autofree png_info *info_ptr =3D NULL; + g_autoptr(pixman_image_t) linebuf =3D + qemu_pixman_linebuf_create(PIXMAN_a8r8g8b8, wi= dth); + uint8_t *buf =3D (uint8_t *)pixman_image_get_data(linebuf); + FILE *f =3D fdopen(fd, "wb"); + int y; + if (!f) { + error_setg_errno(errp, errno, + "Failed to create file from file descriptor"); + return false; + } + + png_ptr =3D png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); + if (!png_ptr) { + error_setg(errp, "PNG creation failed. Unable to write struct"); + fclose(f); + return false; + } + + info_ptr =3D png_create_info_struct(png_ptr); + + if (!info_ptr) { + error_setg(errp, "PNG creation failed. Unable to write info"); + fclose(f); + png_destroy_write_struct(&png_ptr, &info_ptr); + return false; + } + + png_init_io(png_ptr, f); + + png_set_IHDR(png_ptr, info_ptr, width, height, 8, + PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_write_info(png_ptr, info_ptr); + + for (y =3D 0; y < height; ++y) { + qemu_pixman_linebuf_fill(linebuf, image, width, 0, y); + png_write_row(png_ptr, buf); + } + qemu_pixman_image_unref(linebuf); + + png_write_end(png_ptr, NULL); + + png_destroy_write_struct(&png_ptr, &info_ptr); + + if (fclose(f) !=3D 0) { + error_setg_errno(errp, errno, + "PNG creation failed. Unable to close file"); + return false; + } + + return true; +} + +#else /* no png support */ + +static bool png_save(int fd, pixman_image_t *image, Error **errp) +{ + error_setg(errp, "Enable PNG support with libpng for screendump"); + return false; +} + +#endif /* CONFIG_PNG */ + static bool ppm_save(int fd, pixman_image_t *image, Error **errp) { int width =3D pixman_image_get_width(image); @@ -329,7 +415,8 @@ static void graphic_hw_update_bh(void *con) /* Safety: coroutine-only, concurrent-coroutine safe, main thread only */ void coroutine_fn qmp_screendump(const char *filename, bool has_device, const char *device, - bool has_head, int64_t head, Error **errp) + bool has_head, int64_t head, + bool has_format, ImageFormat format, Error **errp) { g_autoptr(pixman_image_t) image =3D NULL; QemuConsole *con; @@ -385,8 +472,16 @@ qmp_screendump(const char *filename, bool has_device, = const char *device, * yields and releases the BQL. It could produce corrupted dump, but * it should be otherwise safe. */ - if (!ppm_save(fd, image, errp)) { - qemu_unlink(filename); + if (has_format && format =3D=3D IMAGE_FORMAT_PNG) { + /* PNG format specified for screendump */ + if (!png_save(fd, image, errp)) { + qemu_unlink(filename); + } + } else { + /* PPM format specified/default for screendump */ + if (!ppm_save(fd, image, errp)) { + qemu_unlink(filename); + } } } =20 diff --git a/hmp-commands.hx b/hmp-commands.hx index 8476277aa9c9..808020d0051b 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -244,11 +244,12 @@ ERST =20 { .name =3D "screendump", - .args_type =3D "filename:F,device:s?,head:i?", - .params =3D "filename [device [head]]", - .help =3D "save screen from head 'head' of display device 'd= evice' " - "into PPM image 'filename'", - .cmd =3D hmp_screendump, + .args_type =3D "filename:F,format:-fs,device:s?,head:i?", + .params =3D "filename [-f format] [device [head]]", + .help =3D "save screen from head 'head' of display device 'd= evice'" + "in specified format 'format' as image 'filename'." + "Currently only 'png' and 'ppm' formats are supporte= d.", + .cmd =3D hmp_screendump, .coroutine =3D true, }, =20 diff --git a/qapi/ui.json b/qapi/ui.json index 13a8bb82aa05..596f37fc37aa 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -157,12 +157,27 @@ ## { 'command': 'expire_password', 'boxed': true, 'data': 'ExpirePasswordOpti= ons' } =20 +## +# @ImageFormat: +# +# Supported image format types. +# +# @png: PNG format +# +# @ppm: PPM format +# +# Since: 7.1 +# +## +{ 'enum': 'ImageFormat', + 'data': ['ppm', 'png'] } + ## # @screendump: # -# Write a PPM of the VGA screen to a file. +# Capture the contents of a screen and write it to a file. # -# @filename: the path of a new PPM file to store the image +# @filename: the path of a new file to store the image # # @device: ID of the display device that should be dumped. If this paramet= er # is missing, the primary display will be used. (Since 2.12) @@ -171,6 +186,8 @@ # parameter is missing, head #0 will be used. Also note that the he= ad # can only be specified in conjunction with the device ID. (Since 2= .12) # +# @format: image format for screendump. (default: ppm) (Since 7.1) +# # Returns: Nothing on success # # Since: 0.14 @@ -183,7 +200,8 @@ # ## { 'command': 'screendump', - 'data': {'filename': 'str', '*device': 'str', '*head': 'int'}, + 'data': {'filename': 'str', '*device': 'str', '*head': 'int', + '*format': 'ImageFormat'}, 'coroutine': true } =20 ## --=20 2.35.1 From nobody Fri May 3 10:45:11 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650868741139206.7494345068975; Sun, 24 Apr 2022 23:39:01 -0700 (PDT) Received: from localhost ([::1]:33908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nisN9-0007mV-Gn for importer2@patchew.org; Mon, 25 Apr 2022 02:38:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvl-0003jE-VZ for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46436) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvk-0006Js-0Q for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:41 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-148-0-vFxItyMA-pfcI21TulGw-1; Mon, 25 Apr 2022 02:10:37 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 36084800882; Mon, 25 Apr 2022 06:10:37 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C285548FB08; Mon, 25 Apr 2022 06:10:34 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 0B18F1800628; Mon, 25 Apr 2022 08:10:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650867039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=98j8qiT91Vb8seAfv03Kw8HQOkGmbfgKG/QLFVtoXss=; b=XzjCZhdcCgOoT41pQs+fhuc3aQmJ+2Cogbb4PTegrxo6PqdGfIDbA9KrA9jEOLTatneTt2 dsrnh2bjsgiNs+V96YVm2cxqMi6pNrt4nAwgOjoNJ7ZhxtLy/5UsoEZWC1CCO20LODFSo9 pDZfmzWnq8cce9+ohP8msyGqAE3X0Bk= X-MC-Unique: 0-vFxItyMA-pfcI21TulGw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 4/6] ui/vnc: refactor arrays of addresses to SocketAddressList Date: Mon, 25 Apr 2022 08:10:27 +0200 Message-Id: <20220425061029.3932731-5-kraxel@redhat.com> In-Reply-To: <20220425061029.3932731-1-kraxel@redhat.com> References: <20220425061029.3932731-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Beraldo Leal , Vladimir Sementsov-Ogievskiy , Markus Armbruster , "Dr. David Alan Gilbert" , Wainer dos Santos Moschetta , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Vladimir Sementsov-Ogievskiy , Gerd Hoffmann , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650868742898100001 From: Vladimir Sementsov-Ogievskiy 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=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20220401143936.356460-2-vsementsov@openvz.org> Signed-off-by: Gerd Hoffmann --- ui/vnc.c | 129 ++++++++++++++++++++++--------------------------------- 1 file changed, 51 insertions(+), 78 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 7d55e1500a42..77a660fccb3f 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3820,30 +3820,19 @@ static int vnc_display_get_address(const char *addr= str, return ret; } =20 -static void vnc_free_addresses(SocketAddress ***retsaddr, - size_t *retnsaddr) -{ - size_t i; - - for (i =3D 0; i < *retnsaddr; i++) { - qapi_free_SocketAddress((*retsaddr)[i]); - } - g_free(*retsaddr); - - *retsaddr =3D NULL; - *retnsaddr =3D 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 =3D NULL; SocketAddress *wsaddr =3D NULL; + g_autoptr(SocketAddressList) saddr_list =3D NULL; + SocketAddressList **saddr_tail =3D &saddr_list; + SocketAddress *single_saddr =3D NULL; + g_autoptr(SocketAddressList) wsaddr_list =3D NULL; + SocketAddressList **wsaddr_tail =3D &wsaddr_list; QemuOptsIter addriter; const char *addr; int to =3D qemu_opt_get_number(opts, "to", 0); @@ -3852,23 +3841,16 @@ static int vnc_display_get_addresses(QemuOpts *opts, bool ipv4 =3D qemu_opt_get_bool(opts, "ipv4", false); bool ipv6 =3D qemu_opt_get_bool(opts, "ipv6", false); int displaynum =3D -1; - int ret =3D -1; - - *retsaddr =3D NULL; - *retnsaddr =3D 0; - *retwsaddr =3D NULL; - *retnwsaddr =3D 0; =20 addr =3D qemu_opt_get(opts, "vnc"); if (addr =3D=3D NULL || g_str_equal(addr, "none")) { - ret =3D 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; } =20 qemu_opt_iter_init(&addriter, opts, "vnc"); @@ -3879,7 +3861,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 @@ -3887,13 +3869,16 @@ static int vnc_display_get_addresses(QemuOpts *opts, if (displaynum =3D=3D -1) { displaynum =3D rv; } - *retsaddr =3D g_renew(SocketAddress *, *retsaddr, *retnsaddr + 1); - (*retsaddr)[(*retnsaddr)++] =3D saddr; + QAPI_LIST_APPEND(saddr_tail, saddr); } =20 - /* 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 =3D saddr_list->value; + } else { + /* + * If we had multiple primary displays, we don't do defaults + * for websocket, and require explicit config instead. + */ displaynum =3D -1; } =20 @@ -3903,57 +3888,50 @@ static int vnc_display_get_addresses(QemuOpts *opts, has_ipv4, has_ipv6, ipv4, ipv6, &wsaddr, errp) < 0) { - goto cleanup; + return -1; } =20 /* 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 =3D=3D 1 && - (*retsaddr)[0]->type =3D=3D SOCKET_ADDRESS_TYPE_INET && + if (single_saddr && + single_saddr->type =3D=3D SOCKET_ADDRESS_TYPE_INET && wsaddr->type =3D=3D 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 =3D g_strdup((*retsaddr)[0]->u.inet.host); + wsaddr->u.inet.host =3D g_strdup(single_saddr->u.inet.host); } =20 - *retwsaddr =3D g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + = 1); - (*retwsaddr)[(*retnwsaddr)++] =3D wsaddr; + QAPI_LIST_APPEND(wsaddr_tail, wsaddr); } =20 - ret =3D 0; - cleanup: - if (ret < 0) { - vnc_free_addresses(retsaddr, retnsaddr); - vnc_free_addresses(retwsaddr, retnwsaddr); - } - return ret; + *saddr_list_ret =3D g_steal_pointer(&saddr_list); + *wsaddr_list_ret =3D g_steal_pointer(&wsaddr_list); + return 0; } =20 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 =3D NULL; - if (nwsaddr !=3D 0) { + if (wsaddr_list) { error_setg(errp, "Cannot use websockets in reverse mode"); return -1; } - if (nsaddr !=3D 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 =3D saddr[0]->type =3D=3D SOCKET_ADDRESS_TYPE_UNIX; + vd->is_unix =3D saddr_list->value->type =3D=3D SOCKET_ADDRESS_TYPE_UNI= X; sioc =3D 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; } @@ -3964,20 +3942,18 @@ static int vnc_display_connect(VncDisplay *vd, =20 =20 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; =20 - if (nsaddr) { + if (saddr_list) { vd->listener =3D qio_net_listener_new(); qio_net_listener_set_name(vd->listener, "vnc-listen"); - for (i =3D 0; i < nsaddr; i++) { + for (el =3D saddr_list; el; el =3D el->next) { if (qio_net_listener_open_sync(vd->listener, - saddr[i], 1, + el->value, 1, errp) < 0) { return -1; } @@ -3987,12 +3963,12 @@ static int vnc_display_listen(VncDisplay *vd, vnc_listen_io, vd, NULL); } =20 - if (nwsaddr) { + if (wsaddr_list) { vd->wslistener =3D qio_net_listener_new(); qio_net_listener_set_name(vd->wslistener, "vnc-ws-listen"); - for (i =3D 0; i < nwsaddr; i++) { + for (el =3D wsaddr_list; el; el =3D el->next) { if (qio_net_listener_open_sync(vd->wslistener, - wsaddr[i], 1, + el->value, 1, errp) < 0) { return -1; } @@ -4010,8 +3986,8 @@ void vnc_display_open(const char *id, Error **errp) { VncDisplay *vd =3D vnc_display_find(id); QemuOpts *opts =3D qemu_opts_find(&qemu_vnc_opts, id); - SocketAddress **saddr =3D NULL, **wsaddr =3D NULL; - size_t nsaddr, nwsaddr; + g_autoptr(SocketAddressList) saddr_list =3D NULL; + g_autoptr(SocketAddressList) wsaddr_list =3D NULL; const char *share, *device_id; QemuConsole *con; bool password =3D false; @@ -4036,8 +4012,8 @@ void vnc_display_open(const char *id, Error **errp) } =20 reverse =3D 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; } =20 @@ -4219,16 +4195,16 @@ void vnc_display_open(const char *id, Error **errp) } qkbd_state_set_delay(vd->kbd, key_delay_ms); =20 - if (saddr =3D=3D NULL) { - goto cleanup; + if (saddr_list =3D=3D NULL) { + return; } =20 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; } } @@ -4237,14 +4213,11 @@ void vnc_display_open(const char *id, Error **errp) vnc_display_print_local_addr(vd); } =20 - cleanup: - vnc_free_addresses(&saddr, &nsaddr); - vnc_free_addresses(&wsaddr, &nwsaddr); + /* Success */ return; =20 fail: vnc_display_close(vd); - goto cleanup; } =20 void vnc_display_add_client(const char *id, int csock, bool skipauth) --=20 2.35.1 From nobody Fri May 3 10:45:11 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650868488788946.4720894772526; Sun, 24 Apr 2022 23:34:48 -0700 (PDT) Received: from localhost ([::1]:58094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nisJ5-0004ik-MK for importer2@patchew.org; Mon, 25 Apr 2022 02:34:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvx-00040q-2H for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20041) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvv-0006MJ-Cz for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:52 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-31-kTx597jCPqmMBkD84O4qJw-1; Mon, 25 Apr 2022 02:10:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ECCCB833942; Mon, 25 Apr 2022 06:10:48 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC8DA2166B26; Mon, 25 Apr 2022 06:10:34 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 204ED180062F; Mon, 25 Apr 2022 08:10:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650867050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IUKl7FayplcAMe+oqYrNHhYGiZhfgVAqjMKZGJ6cvr8=; b=Aqw873gteWYlWdyLaWOvcY2M3Pu+XldudCGVWu135jwUk091WUdAImac+JzURKCGehYcYQ e8IA2yANDKK0/F6wt9Zv54O0mo4ayy1nqdW3G9zu1oESvvFcEyV1MVZpiS/OQ1ZSawvjt5 fDN0hbYrrjUewl/ZMn4bTMJbJV2ZTUs= X-MC-Unique: kTx597jCPqmMBkD84O4qJw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 5/6] qapi/ui: add 'display-update' command for changing listen address Date: Mon, 25 Apr 2022 08:10:28 +0200 Message-Id: <20220425061029.3932731-6-kraxel@redhat.com> In-Reply-To: <20220425061029.3932731-1-kraxel@redhat.com> References: <20220425061029.3932731-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Beraldo Leal , Vladimir Sementsov-Ogievskiy , Markus Armbruster , "Dr. David Alan Gilbert" , Wainer dos Santos Moschetta , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Vladimir Sementsov-Ogievskiy , Gerd Hoffmann , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650868490759100003 From: Vladimir Sementsov-Ogievskiy 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=C3=A9 Message-Id: <20220401143936.356460-3-vsementsov@openvz.org> Signed-off-by: Gerd Hoffmann --- include/ui/console.h | 1 + monitor/qmp-cmds.c | 15 ++++++++ ui/vnc.c | 23 ++++++++++++ docs/about/removed-features.rst | 3 +- qapi/ui.json | 65 +++++++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 1 deletion(-) diff --git a/include/ui/console.h b/include/ui/console.h index 0f84861933e1..c44b28a972ca 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -518,6 +518,7 @@ int vnc_display_pw_expire(const char *id, time_t expire= s); 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); =20 /* 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 5e7302cbb995..1ebb89f46c12 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -346,6 +346,21 @@ void qmp_display_reload(DisplayReloadOptions *arg, Err= or **errp) } } =20 +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 77a660fccb3f..b02cb3f405b9 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3981,6 +3981,29 @@ static int vnc_display_listen(VncDisplay *vd, return 0; } =20 +bool vnc_display_update(DisplayUpdateOptionsVNC *arg, Error **errp) +{ + VncDisplay *vd =3D 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 =3D NULL; + } + + if (vnc_display_listen(vd, arg->addresses, NULL, errp) < 0) { + return false; + } + } + + return true; +} =20 void vnc_display_open(const char *id, Error **errp) { diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.= rst index 4b831ea29176..b367418ca7da 100644 --- a/docs/about/removed-features.rst +++ b/docs/about/removed-features.rst @@ -355,7 +355,8 @@ documentation of ``query-hotpluggable-cpus`` for additi= onal details. ``change`` (removed in 6.0) ''''''''''''''''''''''''''' =20 -Use ``blockdev-change-medium`` or ``change-vnc-password`` instead. +Use ``blockdev-change-medium`` or ``change-vnc-password`` or +``display-update`` instead. =20 ``query-events`` (removed in 6.0) ''''''''''''''''''''''''''''''''' diff --git a/qapi/ui.json b/qapi/ui.json index 596f37fc37aa..059302a5efcb 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1468,3 +1468,68 @@ { 'command': 'display-reload', 'data': 'DisplayReloadOptions', 'boxed' : true } + +## +# @DisplayUpdateType: +# +# Available DisplayUpdate types. +# +# @vnc: VNC display +# +# Since: 7.1 +# +## +{ '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.1 +# +## +{ 'struct': 'DisplayUpdateOptionsVNC', + 'data': { '*addresses': ['SocketAddress'] } } + +## +# @DisplayUpdateOptions: +# +# Options of the display configuration reload. +# +# @type: Specify the display type. +# +# Since: 7.1 +# +## +{ 'union': 'DisplayUpdateOptions', + 'base': {'type': 'DisplayUpdateType'}, + 'discriminator': 'type', + 'data': { 'vnc': 'DisplayUpdateOptionsVNC' } } + +## +# @display-update: +# +# Update display configuration. +# +# Returns: Nothing on success. +# +# Since: 7.1 +# +# Example: +# +# -> { "execute": "display-update", +# "arguments": { "type": "vnc", "addresses": +# [ { "type": "inet", "host": "0.0.0.0", +# "port": "5901" } ] } } +# <- { "return": {} } +# +## +{ 'command': 'display-update', + 'data': 'DisplayUpdateOptions', + 'boxed' : true } --=20 2.35.1 From nobody Fri May 3 10:45:11 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650868034998984.8835431638147; Sun, 24 Apr 2022 23:27:14 -0700 (PDT) Received: from localhost ([::1]:53690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nisBl-000109-SD for importer2@patchew.org; Mon, 25 Apr 2022 02:27:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvp-0003ov-B5 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nirvn-0006Ks-PU for qemu-devel@nongnu.org; Mon, 25 Apr 2022 02:10:45 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-658-ZKD947F6NEmZiphjCZfGoQ-1; Mon, 25 Apr 2022 02:10:39 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B7ED802809; Mon, 25 Apr 2022 06:10:39 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD0E2409B3F3; Mon, 25 Apr 2022 06:10:38 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2E52A1800636; Mon, 25 Apr 2022 08:10:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650867043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PrGCZVM389hjCQzgZPb8u6IS3jwWK0ndVF5vnCevEXQ=; b=euLMNdRU6CjiAJMAFZ3GMGGRLQx2wfbW+8qMFSO2EmmwLQStgpurAHoe45r5ROYgUXQ+ge XPgrZFQcX4RFKqwwPVmg16vcKnd+mrqwC1Qm0ytzYe6Oy/2MsoPEB3VvipupSQ0MxNTF3q WhgfalglAbrt6OKN6/7uXBm5i7g2oLM= X-MC-Unique: ZKD947F6NEmZiphjCZfGoQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 6/6] avocado/vnc: add test_change_listen Date: Mon, 25 Apr 2022 08:10:29 +0200 Message-Id: <20220425061029.3932731-7-kraxel@redhat.com> In-Reply-To: <20220425061029.3932731-1-kraxel@redhat.com> References: <20220425061029.3932731-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Beraldo Leal , Vladimir Sementsov-Ogievskiy , Markus Armbruster , "Dr. David Alan Gilbert" , Wainer dos Santos Moschetta , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Vladimir Sementsov-Ogievskiy , Gerd Hoffmann , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650868036566100001 From: Vladimir Sementsov-Ogievskiy Add simple test-case for new display-update qmp command. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20220401143936.356460-4-vsementsov@openvz.org> Signed-off-by: Gerd Hoffmann --- tests/avocado/vnc.py | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/avocado/vnc.py b/tests/avocado/vnc.py index 096432988fbb..187fd3febca4 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. =20 +import socket +from typing import List + from avocado_qemu import QemuSystemTest =20 =20 +VNC_ADDR =3D '127.0.0.1' +VNC_PORT_START =3D 32768 +VNC_PORT_END =3D 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 =3D [] + for port in range(VNC_PORT_START, VNC_PORT_END): + if check_bind(port): + result.append(port) + if len(result) >=3D count: + break + assert len(result) =3D=3D count + return result + + class Vnc(QemuSystemTest): """ :avocado: tags=3Dvnc,quick @@ -51,3 +90,27 @@ def test_change_password(self): set_password_response =3D self.vm.qmp('change-vnc-password', password=3D'new_password') self.assertEqual(set_password_response['return'], {}) + + def test_change_listen(self): + a, b, c =3D 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 - 59= 00}') + self.vm.launch() + self.assertEqual(self.vm.qmp('query-vnc')['return']['service'], st= r(a)) + self.assertTrue(check_connect(a)) + self.assertFalse(check_connect(b)) + self.assertFalse(check_connect(c)) + + res =3D self.vm.qmp('display-update', type=3D'vnc', + addresses=3D[{'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'], st= r(b)) + self.assertFalse(check_connect(a)) + self.assertTrue(check_connect(b)) + self.assertTrue(check_connect(c)) --=20 2.35.1