From nobody Tue Feb 10 01:14:54 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1592757363; cv=none; d=zohomail.com; s=zohoarc; b=ZaW+btjkOpGHVnMviz3JQnVksKG7aKvu+1LzzMSD4f+ATZtwtfvLgs2YZrkgEjSuPoFNvw2QTTHZvjwOeJqT2piTfshM6ri09ziEflNtqQd6pE4ZH9AJCbRUigt7lbOI4R9RBQPS9LNrWDP/1wIOumPgvCOK11suV924Lio8fZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592757363; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q2aSrf1EjsOvJpOxHsvMeL3ETTLqp6nu/7mQtqEiP9s=; b=OIqeiCGwBjkh+CuDx2IrivNFN2ALVTDIoYXnzMlwTNwMF05rOikqSAo+/F5ETTJUS/TNwmnXYpYZP027ePp5ptNgnDPeDhw8PZfhZ7o7I2m4MD9mU4Ra4t6IM5DEvuL8QCgw9K3zGLwCraoPCgzmMH5weNOyNwm1JDs6b0uue90= ARC-Authentication-Results: i=1; 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+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592757363273326.10084033653015; Sun, 21 Jun 2020 09:36:03 -0700 (PDT) Received: from localhost ([::1]:56440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jn2wr-0007af-Rs for importer@patchew.org; Sun, 21 Jun 2020 12:36:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jn2jo-0006ov-BW for qemu-devel@nongnu.org; Sun, 21 Jun 2020 12:22:32 -0400 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]:43589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jn2jm-0007yX-Nx for qemu-devel@nongnu.org; Sun, 21 Jun 2020 12:22:32 -0400 Received: by mail-lf1-x142.google.com with SMTP id g139so7439638lfd.10 for ; Sun, 21 Jun 2020 09:22:30 -0700 (PDT) Received: from localhost.localdomain (193-239-39-51.ksi-system.net. [193.239.39.51]) by smtp.gmail.com with ESMTPSA id k7sm2822838lfd.67.2020.06.21.09.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jun 2020 09:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q2aSrf1EjsOvJpOxHsvMeL3ETTLqp6nu/7mQtqEiP9s=; b=H03A6ihttpKK3VflZUmPrTBPZbEJxZKofg5laNIMhTqWGQpwoXrRtbMNGhP/u+4JVy bds3YKL8pSfX9v8TF/vAWpwrKc9/c//3hywq2y1S1DVbmYsT5m48eCFbgGpyr+WlFsuJ Zb+jXeZIbnd/61y0IE1VS3Wjf22UcRRj1C/Lib4gmOEHcV2d7300aHUBk8xqBSAyMznf lDjEXNJIP66Rvs714CnQ115koMWDzBUVUY/DDDQSZqBGdnGyfTCcblH3AYWgUU5qCfmN 3QP5zF3HPxq762vxbY20iJmj682jCGqnkQoD1PEEvk1Yjpstn4wYGWsLqR2UPddAuFcd N/hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q2aSrf1EjsOvJpOxHsvMeL3ETTLqp6nu/7mQtqEiP9s=; b=WnbQJKYBn4cLmleGAyC/8O18DMfpDw4qoDQy3AfINdqjxIZXx2++pG+5MJRrww9Zq0 c49eaG9FzNU/lFB9vKGYeFHoPionTcIIqzD9fx8Sfuuoevg2Z0jAhRzGKuZJC5pBLqC4 Lkw94SjComdYb1YhVaFnjz6mkW1ElKIDdGlUaS3K49P4JJ60JdiEN0cb5xEruroFeCMI myHuzwIVzioKdwMeoImgU2UUZw8tMt25gzUEmoKd/khEq7qpzkObqhC3Ay0OxeD3IjII sHHGTTucfPi4nGMLagbEpv9TAIhstTSC3su5qv0eKYWNC940OdjEDyojbabBmdjigE8G ct8Q== X-Gm-Message-State: AOAM532g8rzqMyyncyYZT+k1fF0K/FqFrHY7XMh0ivy5qSBj1a2rUrm6 PGDzNs9FrOTGR80jNuSEpUM2NOyFho5vpA== X-Google-Smtp-Source: ABdhPJx3pOxtSxnLFDrQOKItyvSoJmuOKWnZ51s+DP4Rf3ck+0Cp4aIl7KsD+14fp1yTqVNFM/u0+g== X-Received: by 2002:a05:6512:303:: with SMTP id t3mr7487637lfp.159.1592756548935; Sun, 21 Jun 2020 09:22:28 -0700 (PDT) From: Szymon Lukasz To: qemu-devel@nongnu.org Subject: [PATCH 6/6] virtio-console: notify the guest about terminal resizes Date: Sun, 21 Jun 2020 18:21:32 +0200 Message-Id: <20200621162132.62797-7-noh4hss@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200621162132.62797-1-noh4hss@gmail.com> References: <20200621162132.62797-1-noh4hss@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::142; envelope-from=noh4hss@gmail.com; helo=mail-lf1-x142.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Mailman-Approved-At: Sun, 21 Jun 2020 12:30:17 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, amit@kernel.org, mst@redhat.com, Szymon Lukasz , marcandre.lureau@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If a virtio serial port is a console port forward terminal resize messages from the chardev backend to the guest. Signed-off-by: Szymon Lukasz --- hw/char/virtio-console.c | 64 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c index 97b9240ef5..1ea06aad08 100644 --- a/hw/char/virtio-console.c +++ b/hw/char/virtio-console.c @@ -29,6 +29,7 @@ typedef struct VirtConsole { =20 CharBackend chr; guint watch; + uint16_t cols, rows; } VirtConsole; =20 /* @@ -104,6 +105,36 @@ static ssize_t flush_buf(VirtIOSerialPort *port, return ret; } =20 +static void virtconsole_send_resize(VirtIOSerialPort *port) +{ + uint16_t cols, rows; + VirtConsole *vcon =3D VIRTIO_CONSOLE(port); + + /* + * We probably shouldn't send these messages before + * we told the guest it is a console port (which we do + * by sending VIRTIO_CONSOLE_CONSOLE_PORT message). + * Instead of adding a new field to the device state + * lets just use the guest_connected field for that purpose + * since the guest should not care about the terminal size + * before opening the port. + */ + if (!port->guest_connected) { + return; + } + + if (qemu_chr_fe_get_winsize(&vcon->chr, &cols, &rows) < 0) { + cols =3D 0; + rows =3D 0; + } + + if (cols !=3D vcon->cols || rows !=3D vcon->rows) { + vcon->cols =3D cols; + vcon->rows =3D rows; + virtio_serial_send_console_resize(port, cols, rows); + } +} + /* Callback function that's called when the guest opens/closes the port */ static void set_guest_connected(VirtIOSerialPort *port, int guest_connecte= d) { @@ -111,7 +142,9 @@ static void set_guest_connected(VirtIOSerialPort *port,= int guest_connected) DeviceState *dev =3D DEVICE(port); VirtIOSerialPortClass *k =3D VIRTIO_SERIAL_PORT_GET_CLASS(port); =20 - if (!k->is_console) { + if (k->is_console) { + virtconsole_send_resize(port); + } else { qemu_chr_fe_set_open(&vcon->chr, guest_connected); } =20 @@ -171,6 +204,22 @@ static void chr_event(void *opaque, QEMUChrEvent event) } } =20 +static void chr_event_console(void *opaque, QEMUChrEvent event) +{ + VirtConsole *vcon =3D opaque; + VirtIOSerialPort *port =3D VIRTIO_SERIAL_PORT(vcon); + + switch (event) { + case CHR_EVENT_OPENED: + case CHR_EVENT_RESIZE: + trace_virtio_console_chr_event(port->id, event); + virtconsole_send_resize(port); + break; + default: + break; + } +} + static int chr_be_change(void *opaque) { VirtConsole *vcon =3D opaque; @@ -179,7 +228,9 @@ static int chr_be_change(void *opaque) =20 if (k->is_console) { qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read, - NULL, chr_be_change, vcon, NULL, true); + chr_event_console, chr_be_change, + vcon, NULL, true); + virtconsole_send_resize(port); } else { qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read, chr_event, chr_be_change, vcon, NULL, fal= se); @@ -207,7 +258,7 @@ static void virtconsole_enable_backend(VirtIOSerialPort= *port, bool enable) VirtIOSerialPortClass *k =3D VIRTIO_SERIAL_PORT_GET_CLASS(port); =20 qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read, - k->is_console ? NULL : chr_event, + k->is_console ? chr_event_console : chr_e= vent, chr_be_change, vcon, NULL, false); } else { qemu_chr_fe_set_handlers(&vcon->chr, NULL, NULL, NULL, @@ -227,6 +278,11 @@ static void virtconsole_realize(DeviceState *dev, Erro= r **errp) return; } =20 + if (k->is_console) { + vcon->cols =3D (uint16_t) -1; + vcon->rows =3D (uint16_t) -1; + } + if (qemu_chr_fe_backend_connected(&vcon->chr)) { /* * For consoles we don't block guest data transfer just @@ -239,7 +295,7 @@ static void virtconsole_realize(DeviceState *dev, Error= **errp) */ if (k->is_console) { qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read, - NULL, chr_be_change, + chr_event_console, chr_be_change, vcon, NULL, true); virtio_serial_open(port); } else { --=20 2.27.0