From nobody Mon Apr 29 10:43:45 2024 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=1592998176; cv=none; d=zohomail.com; s=zohoarc; b=PxsxXouhCvvcRJXT+1HG+6IZr6WVQY/MpI114sFjoRfH7MLdkftIwjUlE6364t63+GeiR/c2JrpupyaVjdn/4T47RMdm07GUD2LoBx69fC8gqoPHg+3k0exLZ/D+VnBhQK5o0VeBhDifjLzNDL/ZhKrsFzC+6hrcB6Cpu3Dmb9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592998176; 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=v/NS9YgRb0NXpU+G0HRMzylRBMOp+QQCcs98Z10vCR8=; b=KD+tuvMixatNvDXHD7cem2mgUMtnzqvZi5x655ViYvrNkqQAPTkYwAGc3tXRWfeu2dOLimyvRgrLoP2kpfA3yDUzF9CDeUelsqz7mRfmD7ULTv48We9ZSFTKQM7KEDu/uaX8gh1Bfzz1Wpr5WxToHJmjwgsC26XdvknFVQVA+4Y= 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 159299817670478.2828152560395; Wed, 24 Jun 2020 04:29:36 -0700 (PDT) Received: from localhost ([::1]:37220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo3ax-00026E-4t for importer@patchew.org; Wed, 24 Jun 2020 07:29:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo3Yh-0006iR-Q5 for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:15 -0400 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:36075) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo3Yd-00075G-QN for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:15 -0400 Received: by mail-lj1-x244.google.com with SMTP id i3so2153207ljg.3 for ; Wed, 24 Jun 2020 04:27:11 -0700 (PDT) Received: from localhost.localdomain (193-239-39-51.ksi-system.net. [193.239.39.51]) by smtp.gmail.com with ESMTPSA id d6sm1202635lja.77.2020.06.24.04.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 04:27:09 -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=v/NS9YgRb0NXpU+G0HRMzylRBMOp+QQCcs98Z10vCR8=; b=LFN4WrbTHl5vTrshZmaHadc0Qnsu1rytPPNixo8yLuTJ0WR1ijl63DEZgCnk/QNNdw PNshVgPMrZWHF8ifp2ujUEf8SAquKwpZaivE1wZG5cYOCaazc6zzB8dYllCXgZcXh1+P P0aJK6U6RkOCRgb7PFxiPgRd/Saa5QAzCMVKZkO78wSKlILRza8Zz/mlXrM1cleZFa7Z SmPKUtLNFREi/1/FtvRo5niRFRgQATsREoGR12/GXPMjvxOoS4Fo0UdOr4QstkyieCUT NZe+WPaEO2Cl3T0YwzhnLcm0TpokHeX9prQ87EfJGiP2uPKEPw96p9RKWGva0QQvi67p eyyA== 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=v/NS9YgRb0NXpU+G0HRMzylRBMOp+QQCcs98Z10vCR8=; b=fEnpsfSKTS84b9j72RdL1TlIgIz0pIsD6J5YMC9v7Y4wY6SJMcCJhdJwkZdPQdPm12 oiPai0vvkYCND3UFin8D3E3v7SG02Uq7rNCn/xKc+64e4coZS9YbnvHROkYmHAcD0Zft aT6XEeBjrAhA6zX68lRXaRY4NVbidsRHEgz+Cl5j8F38bite+v9OsoD5H/jDYUsyqNzN AmsRpzWzVo5eQj0uq/KzQurMJNQLCOIJU/fX2/VF0Og7HgUy8GtcgH1iViCv1EHtG574 UPtfj1Em/evJGkZo947jVEr+zdiF78Id3m8RoxWZS6PYXBYBr7eSVOjps3b3/5nduVVc gu9g== X-Gm-Message-State: AOAM531teGV6pYCa/XYmXajpDyPiqn0eYuElcB7J8EyPQK2ea2a+J44+ llTgKtBd1fOdegGtoX6ksQn+fhGCmAg3VQ== X-Google-Smtp-Source: ABdhPJzqr/1zZummamrFZO2v2riepgtsy9VSAyfbkr8HQKRT0QJRwTd6aw1WRXQYI5IM9+/6iow9tg== X-Received: by 2002:a2e:3a17:: with SMTP id h23mr13128295lja.7.1592998029809; Wed, 24 Jun 2020 04:27:09 -0700 (PDT) From: Szymon Lukasz To: qemu-devel@nongnu.org Subject: [PATCH v2 1/6] main-loop: change the handling of SIGWINCH Date: Wed, 24 Jun 2020 13:26:35 +0200 Message-Id: <20200624112640.82673-2-noh4hss@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200624112640.82673-1-noh4hss@gmail.com> References: <20200624112640.82673-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::244; envelope-from=noh4hss@gmail.com; helo=mail-lj1-x244.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-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" Block SIGWINCH, so it is delivered only via signalfd. Install a handler that uses NotifierList to tell interested parties about SIGWINCH delivery. Signed-off-by: Szymon Lukasz --- include/qemu/main-loop.h | 4 ++++ ui/curses.c | 11 ++++++----- util/main-loop.c | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index a6d20b0719..f27dba1fd8 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -325,4 +325,8 @@ typedef struct MainLoopPoll { void main_loop_poll_add_notifier(Notifier *notify); void main_loop_poll_remove_notifier(Notifier *notify); =20 +#ifndef _WIN32 +void sigwinch_add_notifier(Notifier *n); +#endif + #endif diff --git a/ui/curses.c b/ui/curses.c index a59b23a9cf..e5895d506f 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -34,6 +34,7 @@ #include =20 #include "qapi/error.h" +#include "qemu/main-loop.h" #include "qemu/module.h" #include "ui/console.h" #include "ui/input.h" @@ -146,7 +147,7 @@ static void curses_resize(DisplayChangeListener *dcl, } =20 #if !defined(_WIN32) && defined(SIGWINCH) && defined(KEY_RESIZE) -static volatile sig_atomic_t got_sigwinch; +static bool got_sigwinch; static void curses_winch_check(void) { struct winsize { @@ -169,17 +170,17 @@ static void curses_winch_check(void) invalidate =3D 1; } =20 -static void curses_winch_handler(int signum) +static void curses_winch_handler(Notifier *n, void *data) { got_sigwinch =3D true; } =20 static void curses_winch_init(void) { - struct sigaction old, winch =3D { - .sa_handler =3D curses_winch_handler, + static Notifier n =3D { + .notify =3D curses_winch_handler }; - sigaction(SIGWINCH, &winch, &old); + sigwinch_add_notifier(&n); } #else static void curses_winch_check(void) {} diff --git a/util/main-loop.c b/util/main-loop.c index eda63fe4e0..0f5c8f3af1 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -90,6 +90,7 @@ static int qemu_signal_init(Error **errp) sigaddset(&set, SIGIO); sigaddset(&set, SIGALRM); sigaddset(&set, SIGBUS); + sigaddset(&set, SIGWINCH); /* SIGINT cannot be handled via signalfd, so that ^C can be used * to interrupt QEMU when it is being run under gdb. SIGHUP and * SIGTERM are also handled asynchronously, even though it is not @@ -111,6 +112,26 @@ static int qemu_signal_init(Error **errp) return 0; } =20 +static NotifierList sigwinch_notifiers =3D + NOTIFIER_LIST_INITIALIZER(sigwinch_notifiers); + +static void sigwinch_handler(int signum) +{ + notifier_list_notify(&sigwinch_notifiers, NULL); +} + +void sigwinch_add_notifier(Notifier *n) +{ + if (notifier_list_empty(&sigwinch_notifiers)) { + struct sigaction action =3D { + .sa_handler =3D sigwinch_handler, + }; + sigaction(SIGWINCH, &action, NULL); + } + + notifier_list_add(&sigwinch_notifiers, n); +} + #else /* _WIN32 */ =20 static int qemu_signal_init(Error **errp) --=20 2.27.0 From nobody Mon Apr 29 10:43:45 2024 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=1592998094; cv=none; d=zohomail.com; s=zohoarc; b=mZTqHBdBML6SzxRNtsc9y5a1aaYXaXjDevmv8XbyX8wFknbwhg8ofDQ+85irBFSCwl0zgueQHW4nInOEAZWppS5QZK+tEpHiPXJkz3JrrgXXyyQCjpqzVZSa/lLdf7Dflcy6CjBjEbBR7NHEHkeTnL+bqJOnvr3aBp0qs83+FEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592998094; 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=/OUUBKDsy3J40KxRYAgVxdYTHQyEXQLdkmrBWWB58eM=; b=CNlvfuvaZi4wR10skk+MjbMITWD5iGBrOFfdaHIbjE9w+l8rPpfaZ6DNRCqnLP7H+EpwVtrKHy4FDgFEeyQ5H9AYVMsfMyu2ddnRl1NDK6uh9PCcN76X0txO1Lc6DBAm7ZZV5tDEkcjmpk2/gOTUtUmBVNrJ21u62amq638XBak= 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 1592998094503122.36517647439837; Wed, 24 Jun 2020 04:28:14 -0700 (PDT) Received: from localhost ([::1]:59962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo3Zd-0008F2-93 for importer@patchew.org; Wed, 24 Jun 2020 07:28:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo3Yg-0006gL-Hl for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:14 -0400 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:33110) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo3Ye-00075P-G5 for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:14 -0400 Received: by mail-lj1-x244.google.com with SMTP id s1so2161832ljo.0 for ; Wed, 24 Jun 2020 04:27:12 -0700 (PDT) Received: from localhost.localdomain (193-239-39-51.ksi-system.net. [193.239.39.51]) by smtp.gmail.com with ESMTPSA id d6sm1202635lja.77.2020.06.24.04.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 04:27:10 -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=/OUUBKDsy3J40KxRYAgVxdYTHQyEXQLdkmrBWWB58eM=; b=I60Lgg7L32FLr/y5Fc9EgccglZhN+lt5L2cyzzO2QkdiiXifOoLcS+n47biuLDsE4c Ukx2zIDUETQxew4x0NgyhFUDYHniYgiaUhaoVfJfaCefb6GVrrbFydUHqJ3zKA16aRUf g9lBj3WRf6nRHqlncQZQbb45vsIjmttA6jv9CLbZB+bMIy4xPdVN9Mby838DbQYTn54e eBLIL2q7fRJfWBI3TP0JhbTEmajT4xnbTpf4MaY2GSVyNfVLNDHrrjQhQ6pk7yfZqojZ i5RFeH4xcNK7U5Yke/aQIn5Vy2P6lrv7R1F0f4xpNOkIYieVC3LuP1haDGj6TCjqYkMQ Ip7Q== 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=/OUUBKDsy3J40KxRYAgVxdYTHQyEXQLdkmrBWWB58eM=; b=rfYSVyhFkGR3mdkRqtzTuPoBpCatTBXLvcgAdYf5RsRmWuZeUZpO+fFnu1k6Dxa17P 0YGWbTFZhH5UZokqbfeGNXMOzY0oUwvbLrV0QZOMtdE52tXh3Ra4EGVN6eKCKnPTKZBz vrRRC2eup4DPAgTu3AIAsXFu49a8U5e83lEu2RF4dAINnSv2zmOqwiOhrB0KmjmAN/02 +ULuiEi6VKhbAv3nvNj5u7dlIUuB5+X2j2Bmjo+iBvgOx1r6GyFM46sX0RBV43jejtL3 DMRi/h8Ik+e76dfbCJGXPsmr+eltgPftgk8p0mKjaFLKaHjPES7YNOHWuxHGwwT4pCV+ XRvw== X-Gm-Message-State: AOAM531Dq9Utr+dlCZMLOS+xAGAxc6Kv6ik8+mp64Whq4pcw/0quSBl5 YuG5NrYXP3HcqamaA7TnCscuJxsSVItQ/Q== X-Google-Smtp-Source: ABdhPJzMz7CVgj5K8CgZVZ4/OO7O3PmRcNCwdky32WZ1W6F6ljd2HVHy4F9iuOPUfSmecq4RTq7FIg== X-Received: by 2002:a2e:7303:: with SMTP id o3mr14511620ljc.100.1592998030691; Wed, 24 Jun 2020 04:27:10 -0700 (PDT) From: Szymon Lukasz To: qemu-devel@nongnu.org Subject: [PATCH v2 2/6] chardev: add support for retrieving the terminal size Date: Wed, 24 Jun 2020 13:26:36 +0200 Message-Id: <20200624112640.82673-3-noh4hss@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200624112640.82673-1-noh4hss@gmail.com> References: <20200624112640.82673-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::244; envelope-from=noh4hss@gmail.com; helo=mail-lj1-x244.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-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" Extend the class of chardevs with a new function - chr_get_winsize. A chardev backend should implement if it is able to get the size of the connected terminal and can detect changes in the terminal size, i.e. if the backend cannot detect resizes it must not implement this (e.g. if we have a tty backend connected to some (pseudo)terminal there is no clean way to detect resizes since SIGWINCH is sent only for the controlling terminal). Signed-off-by: Szymon Lukasz --- chardev/char-fe.c | 11 +++++++++++ chardev/char-mux.c | 7 +++++++ include/chardev/char-fe.h | 11 +++++++++++ include/chardev/char.h | 1 + 4 files changed, 30 insertions(+) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index f3530a90e6..802d3096cd 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -336,6 +336,17 @@ void qemu_chr_fe_set_echo(CharBackend *be, bool echo) } } =20 +int qemu_chr_fe_get_winsize(CharBackend *be, uint16_t *cols, uint16_t *row= s) +{ + Chardev *chr =3D be->chr; + + if (chr && CHARDEV_GET_CLASS(chr)->chr_get_winsize) { + return CHARDEV_GET_CLASS(chr)->chr_get_winsize(chr, cols, rows); + } + + return -1; +} + void qemu_chr_fe_set_open(CharBackend *be, int fe_open) { Chardev *chr =3D be->chr; diff --git a/chardev/char-mux.c b/chardev/char-mux.c index 46c44af67c..368ce2334e 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -293,6 +293,12 @@ static void mux_chr_update_read_handlers(Chardev *chr) chr->gcontext, true, false); } =20 +static int mux_chr_get_winsize(Chardev *chr, uint16_t *cols, uint16_t *row= s) +{ + MuxChardev *d =3D MUX_CHARDEV(chr); + return qemu_chr_fe_get_winsize(&d->chr, cols, rows); +} + void mux_set_focus(Chardev *chr, int focus) { MuxChardev *d =3D MUX_CHARDEV(chr); @@ -385,6 +391,7 @@ static void char_mux_class_init(ObjectClass *oc, void *= data) cc->chr_be_event =3D mux_chr_be_event; cc->chr_machine_done =3D open_muxes; cc->chr_update_read_handler =3D mux_chr_update_read_handlers; + cc->chr_get_winsize =3D mux_chr_get_winsize; } =20 static const TypeInfo char_mux_type_info =3D { diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h index a553843364..b7943df93a 100644 --- a/include/chardev/char-fe.h +++ b/include/chardev/char-fe.h @@ -154,6 +154,17 @@ int qemu_chr_fe_wait_connected(CharBackend *be, Error = **errp); */ void qemu_chr_fe_set_echo(CharBackend *be, bool echo); =20 +/** + * qemu_chr_fe_get_winsize: + * @cols: the address for storing columns + * @rows: the address for storing rows + * + * Get the terminal size of the backend. + * + * Returns: 0 on success and < 0 on error + */ +int qemu_chr_fe_get_winsize(CharBackend *be, uint16_t *cols, uint16_t *row= s); + /** * qemu_chr_fe_set_open: * diff --git a/include/chardev/char.h b/include/chardev/char.h index 00589a6025..fb20707917 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -276,6 +276,7 @@ typedef struct ChardevClass { void (*chr_be_event)(Chardev *s, QEMUChrEvent event); /* Return 0 if succeeded, 1 if failed */ int (*chr_machine_done)(Chardev *chr); + int (*chr_get_winsize)(Chardev *chr, uint16_t *cols, uint16_t *rows); } ChardevClass; =20 Chardev *qemu_chardev_new(const char *id, const char *typename, --=20 2.27.0 From nobody Mon Apr 29 10:43:45 2024 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=1592998230; cv=none; d=zohomail.com; s=zohoarc; b=kAgGHz0bxlXm4gVc6r1N5jnlYLdLu/iztpt22YcxkYdpubfPDyukDQzwXloO2D+GRijUNz4YrbaJIDerLV3tl6uyowISjn2SubyYRoAmLxTUIoOt6Z3l1ghmHIhMA5FBxgF4jk8EpDuWSSMdLUtWz5puarEv0kXtunf7u6lk8jE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592998230; 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=okjFI9L7TqZfHlM0DvNcdByQI8MQ8azG7lBbIRoFOgk=; b=XXLrxreI1zl34y5Me2ojIA0LkrPrLixyVJOXFQHJUtQlMq/nuZZmolP7PSzKBI51ZFCrJX9P47inYbSO+QRyPJdXaV6PD4l+WFY97XXFPJmaZgy5HDl3KxMqSfjjwNNiyHa54/5e9rtYHf8g50l15VTdk0eEKBbe50rWbcQienA= 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 159299823074113.353576452742686; Wed, 24 Jun 2020 04:30:30 -0700 (PDT) Received: from localhost ([::1]:40208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo3bp-0003cV-3k for importer@patchew.org; Wed, 24 Jun 2020 07:30:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo3Yi-0006jf-Hn for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:16 -0400 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]:42222) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo3Yg-00076C-L1 for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:16 -0400 Received: by mail-lj1-x241.google.com with SMTP id y11so2112841ljm.9 for ; Wed, 24 Jun 2020 04:27:14 -0700 (PDT) Received: from localhost.localdomain (193-239-39-51.ksi-system.net. [193.239.39.51]) by smtp.gmail.com with ESMTPSA id d6sm1202635lja.77.2020.06.24.04.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 04:27:11 -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=okjFI9L7TqZfHlM0DvNcdByQI8MQ8azG7lBbIRoFOgk=; b=VIPXbgSYEJrB2lXCSqfZ8oTtGUMkpSbjTr2AWappvRyD0pu5uG4aAT+UsIjxWQK9dw Ak3As0ibyTbp22SBJfMhTjPUmil94MknLVqZ/Bxj8zNjtpa5ooeoK7Rnvn9SRDJvnW9+ 9jzsl2xvfUtpGH/CFB4eWDJCMdoqcWP+e1/2Dw1Pv5DNLovYtGlQhVsV2EfzEk+vB7lC aoWRfKnqAvK2Cidi5i0xjgq5GJKYIXUXxMr9Ns9FrBJRMvLY1gxpE5DeRe67DIWmYEhZ dr0QGNjFSgIkHTM7zU1bL3xdgmMUSAFdPKmcDtqrYbCpn7x/gH1E2kSQl3Hv5jN+2WZP n6yg== 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=okjFI9L7TqZfHlM0DvNcdByQI8MQ8azG7lBbIRoFOgk=; b=qy7aRWvN54dERBorsX45BSSPvZ7xcn7qwRHxE11MjI77lTtKzLQB4Y5fS3y7uyPYxm F0okOStl/Gp2F1kxzfuQUNmTUyGGURC92Rc+ne0VCad1CuiwW2m22BJxJGgyFXojiOnm N8jOr+/ix1ZD4tNSnssLHAjPZW7glKiqY2jbmABCBJ1PwhVTuDLw1BqYU0DjeIQYez66 6VInsh3cftXW0Nq8SOuSPZmGQqo20noYVPZO8b5F50m+eRRrNMqxQPxeOLBo+3vhglph mDx1j/cazKBfSuWBMIdGlocMD3/WRB2Nrbl2hVVqx/6+SOrlAA4itG6HVoX+vRsUSjCj 5eTQ== X-Gm-Message-State: AOAM532TMMQiDCnZtE9QB8Coa3ewO67suXeCYu9Le0V/go8+k4woRI1i dA0eRM6HRYmjdb+XN2qmx0ekB2odeOHQiQ== X-Google-Smtp-Source: ABdhPJxGaclMFq6AX2eTaBRoehM6jF9IYp1BIzErBEKItQeXT9TnnP8Y4Zmn67ye0Mz//g89AdW/yA== X-Received: by 2002:a2e:9a55:: with SMTP id k21mr14333059ljj.340.1592998031756; Wed, 24 Jun 2020 04:27:11 -0700 (PDT) From: Szymon Lukasz To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] chardev: add support for notifying about terminal resizes Date: Wed, 24 Jun 2020 13:26:37 +0200 Message-Id: <20200624112640.82673-4-noh4hss@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200624112640.82673-1-noh4hss@gmail.com> References: <20200624112640.82673-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::241; envelope-from=noh4hss@gmail.com; helo=mail-lj1-x241.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-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" Add a new chardev event, CHR_EVENT_RESIZE, which a backend should trigger if detects the size of the connected terminal changed. Signed-off-by: Szymon Lukasz --- backends/cryptodev-vhost-user.c | 1 + chardev/char.c | 1 + hw/block/vhost-user-blk.c | 1 + hw/char/terminal3270.c | 1 + hw/char/virtio-console.c | 1 + hw/ipmi/ipmi_bmc_extern.c | 1 + hw/usb/ccid-card-passthru.c | 1 + hw/usb/dev-serial.c | 1 + hw/usb/redirect.c | 1 + include/chardev/char.h | 1 + monitor/hmp.c | 1 + monitor/qmp.c | 1 + net/vhost-user.c | 1 + 13 files changed, 13 insertions(+) diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-use= r.c index 8b8cbc4223..bbf8ad426a 100644 --- a/backends/cryptodev-vhost-user.c +++ b/backends/cryptodev-vhost-user.c @@ -174,6 +174,7 @@ static void cryptodev_vhost_user_event(void *opaque, QE= MUChrEvent event) case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/chardev/char.c b/chardev/char.c index e3051295ac..904f8bf6e3 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -74,6 +74,7 @@ void qemu_chr_be_event(Chardev *s, QEMUChrEvent event) case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index a00b854736..1a656a27c3 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -403,6 +403,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrE= vent event) case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c index 2c47ebf007..eadccbb617 100644 --- a/hw/char/terminal3270.c +++ b/hw/char/terminal3270.c @@ -169,6 +169,7 @@ static void chr_event(void *opaque, QEMUChrEvent event) case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c index 4f46753ea3..97b9240ef5 100644 --- a/hw/char/virtio-console.c +++ b/hw/char/virtio-console.c @@ -165,6 +165,7 @@ static void chr_event(void *opaque, QEMUChrEvent event) case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c index f9a13e0a44..9562584309 100644 --- a/hw/ipmi/ipmi_bmc_extern.c +++ b/hw/ipmi/ipmi_bmc_extern.c @@ -439,6 +439,7 @@ static void chr_event(void *opaque, QEMUChrEvent event) case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index bb325dbc4a..3c26b16ed0 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -321,6 +321,7 @@ static void ccid_card_vscard_event(void *opaque, QEMUCh= rEvent event) case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: case CHR_EVENT_CLOSED: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c index 7e50e3ba47..e8e960d0e6 100644 --- a/hw/usb/dev-serial.c +++ b/hw/usb/dev-serial.c @@ -507,6 +507,7 @@ static void usb_serial_event(void *opaque, QEMUChrEvent= event) break; case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 417a60a2e6..b716c4fdd7 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -1383,6 +1383,7 @@ static void usbredir_chardev_event(void *opaque, QEMU= ChrEvent event) case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/include/chardev/char.h b/include/chardev/char.h index fb20707917..c3d108ce82 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -22,6 +22,7 @@ typedef enum { CHR_EVENT_OPENED, /* new connection established */ CHR_EVENT_MUX_IN, /* mux-focus was set to this terminal */ CHR_EVENT_MUX_OUT, /* mux-focus will move on */ + CHR_EVENT_RESIZE, /* the terminal size of the chardev changed */ CHR_EVENT_CLOSED /* connection closed. NOTE: currently this event * is only bound to the read port of the chardev. * Normally the read port and write port of a diff --git a/monitor/hmp.c b/monitor/hmp.c index d598dd02bb..020be03d61 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1373,6 +1373,7 @@ static void monitor_event(void *opaque, QEMUChrEvent = event) break; =20 case CHR_EVENT_BREAK: + case CHR_EVENT_RESIZE: /* Ignored */ break; } diff --git a/monitor/qmp.c b/monitor/qmp.c index d433ceae5b..58aecb475b 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -371,6 +371,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEven= t event) case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } diff --git a/net/vhost-user.c b/net/vhost-user.c index 17532daaf3..e30cbe74bd 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -297,6 +297,7 @@ static void net_vhost_user_event(void *opaque, QEMUChrE= vent event) case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_OUT: + case CHR_EVENT_RESIZE: /* Ignore */ break; } --=20 2.27.0 From nobody Mon Apr 29 10:43:45 2024 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=1592998161; cv=none; d=zohomail.com; s=zohoarc; b=Cgq+jhIXJHj3Y1hepDa2/CWpGENGwcmOFxAai9kLulgWHkZn1Tgnb+XBmLBYfaGe3NOpCBv+kMZ/YMZmCk29C8MDlF6295Yz0iyGT9eGC1wkOlWq7gSIjbMLWu7zPOPNompXaZ4uLlvjrWdJhITF4HMU3O7tdDkNES2pO1qx1BQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592998161; 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=BAeSGl1wtUV2bgf5JPD0BJDHcmlodz8SVwPxsOzMRHc=; b=JFzDXLj8JIefeIr82WeQLx5vrKpryo0QMnrvdq2hkCRPoBuOS+HndgmIWLqXZXSxLwv8PF6yAbbgs/fAdLl3Nl/5PJoB4Fh5Ki6XmQ/PhFmO7TX7I7+1dn0BnLxpHWwdDcq1ZLFv8O05fhqEZJ0EF08G5oiLhUyPw9ieJqfKoHo= 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 1592998161972324.07501471993044; Wed, 24 Jun 2020 04:29:21 -0700 (PDT) Received: from localhost ([::1]:36146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo3ai-0001fQ-Dg for importer@patchew.org; Wed, 24 Jun 2020 07:29:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo3Yi-0006jC-6t for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:16 -0400 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]:33864) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo3Yg-000769-FC for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:15 -0400 Received: by mail-lf1-x141.google.com with SMTP id u25so1092578lfm.1 for ; Wed, 24 Jun 2020 04:27:14 -0700 (PDT) Received: from localhost.localdomain (193-239-39-51.ksi-system.net. [193.239.39.51]) by smtp.gmail.com with ESMTPSA id d6sm1202635lja.77.2020.06.24.04.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 04:27:12 -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=BAeSGl1wtUV2bgf5JPD0BJDHcmlodz8SVwPxsOzMRHc=; b=jehXDHGHMq11GHr2PO+lTcoZv9Q56gkk82ZMxNx1YtrDQ8niyHFuFkBfF6zx9Mywra dTk0wvasfo3IH+VDl5nOJ4uiq8ip3oCKPDuwCBzvBSfCauxL1o5TusErG+LA6WUaPZSG MPaQUEnDYXW71f/BvhUrwIqF2VZ2k5gk7APcBs9yU3a3orF6hfg6pzXgmYGfJxzHPmWn 876MFClASv5gQgnVeenOZvn6m76/0pSESDCNW8hkgsaXUVtwziIVZg8E2RySAztjF7Fn NFTdV13u0Ri/f08fubdkmHlWRWeKEbs+TdbaXIEdpEg6WR6wKjq0TSfmVLZKE1QeXi1F UX1Q== 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=BAeSGl1wtUV2bgf5JPD0BJDHcmlodz8SVwPxsOzMRHc=; b=mxhKMp83VWiVyQ7+T+jaqi8WAyvb40Ch9mqlIdiK1UOTlmn86M/ovvitIIPMbmoZH3 i7/73AQjUBY5LArNqAR5hJ90ebcu/byflQ8RrD08wwcdz7PNdYGaZh1Ex/YlqzafnVJj Woq46BrySjV9oZxbVeLzc66nYYZBtYVIJlUWtSL/fiwJ2SCNh0J/Y0XBLRF+pDh0F+31 GCXsqmFLEA4WPnr50q/f3N2Q0RoGGGdq4AV0vkVkMRW6EJ2H8cuzQx+gWRrstYoIJvXR OCIDB+qbSCObpbNfKo3GV6WmPjahj1aYc7P7QuRRwdkE23tpBfOVMWi1GZT+OXfGbGaY Rr0g== X-Gm-Message-State: AOAM533ej00ShWMD52Aiph0mgnso9SL7I0gKGoRgZF2KJKm0g8UAg3xi ft/BXcSTK7OfswlOIcqWLhBvGBRcc3Q6Ug== X-Google-Smtp-Source: ABdhPJyEGOW1mTkWeQRXEHGuDLsa348Ai+v6YelZ67o7zBE1JBKscm/49RtMq8LP+wL/egMpNSqdjQ== X-Received: by 2002:ac2:5691:: with SMTP id 17mr6961101lfr.209.1592998032680; Wed, 24 Jun 2020 04:27:12 -0700 (PDT) From: Szymon Lukasz To: qemu-devel@nongnu.org Subject: [PATCH v2 4/6] char-stdio: add support for the terminal size Date: Wed, 24 Jun 2020 13:26:38 +0200 Message-Id: <20200624112640.82673-5-noh4hss@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200624112640.82673-1-noh4hss@gmail.com> References: <20200624112640.82673-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::141; envelope-from=noh4hss@gmail.com; helo=mail-lf1-x141.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-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" Implement chr_get_winsize for the stdio backend and trigger CHR_EVENT_RESIZE upon SIGWINCH delivery. Signed-off-by: Szymon Lukasz --- chardev/char-stdio.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index 82eaebc1db..1edc82fc6e 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -34,7 +34,9 @@ #include "chardev/char-win-stdio.h" #else #include +#include #include "chardev/char-fd.h" +#include "qemu/main-loop.h" #endif =20 #ifndef _WIN32 @@ -45,6 +47,13 @@ static bool stdio_in_use; static bool stdio_allow_signal; static bool stdio_echo_state; =20 +typedef struct { + FDChardev parent; + Notifier resize_notifier; +} StdioChardev; + +#define STDIO_CHARDEV(obj) OBJECT_CHECK(StdioChardev, (obj), TYPE_CHARDEV_= STDIO) + static void term_exit(void) { if (stdio_in_use) { @@ -82,11 +91,32 @@ static void term_stdio_handler(int sig) qemu_chr_set_echo_stdio(NULL, stdio_echo_state); } =20 +static int qemu_chr_get_winsize_stdio(Chardev *chr, uint16_t *cols, + uint16_t *rows) +{ + struct winsize ws; + + if (ioctl(1, TIOCGWINSZ, &ws) < 0) { + return -1; + } + + *cols =3D ws.ws_col; + *rows =3D ws.ws_row; + return 0; +} + +static void term_resize_notify(Notifier *n, void *data) +{ + StdioChardev *s =3D container_of(n, StdioChardev, resize_notifier); + qemu_chr_be_event(CHARDEV(s), CHR_EVENT_RESIZE); +} + static void qemu_chr_open_stdio(Chardev *chr, ChardevBackend *backend, bool *be_opened, Error **errp) { + StdioChardev *s =3D STDIO_CHARDEV(chr); ChardevStdio *opts =3D backend->u.stdio.data; struct sigaction act; =20 @@ -116,6 +146,9 @@ static void qemu_chr_open_stdio(Chardev *chr, stdio_allow_signal =3D opts->signal; } qemu_chr_set_echo_stdio(chr, false); + + s->resize_notifier.notify =3D term_resize_notify; + sigwinch_add_notifier(&s->resize_notifier); } #endif =20 @@ -139,6 +172,7 @@ static void char_stdio_class_init(ObjectClass *oc, void= *data) #ifndef _WIN32 cc->open =3D qemu_chr_open_stdio; cc->chr_set_echo =3D qemu_chr_set_echo_stdio; + cc->chr_get_winsize =3D qemu_chr_get_winsize_stdio; #endif } =20 @@ -155,6 +189,7 @@ static const TypeInfo char_stdio_type_info =3D { .parent =3D TYPE_CHARDEV_WIN_STDIO, #else .parent =3D TYPE_CHARDEV_FD, + .instance_size =3D sizeof(StdioChardev), #endif .instance_finalize =3D char_stdio_finalize, .class_init =3D char_stdio_class_init, --=20 2.27.0 From nobody Mon Apr 29 10:43:45 2024 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=1592998494; cv=none; d=zohomail.com; s=zohoarc; b=Q15dmrjMDwjA1BZLsQ1t37HKt1s7/xmDHwpXBa3psloVFBsZEB2VupcNQEhbGKcW7QYeTusJ26MLx9624PPaqK9Ol4rsoNjSTl+uu+VW0PwFiDAHu9Pd83+NIZEBM1Ytz3KERjxfKt2gt1PJsfkHWMw+5NSobmKocdf50sTtEjQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592998494; 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=9gdYmHKQollDgqMy022aRxiAZpeq1ES9ZENq0OBDOxo=; b=J+DeT9BPuHAKvmdhN11yT0T18bacDcOqWeuxyqMJ2ZRaQZZApo7R/nBpLj6dDANTyblksxqaAWb7EvgezEBDM4EN031CHDAG377TT3z23ZnweTh13XBWuihbkwn3MBbnUPXqMn4BG6AoJQNBYkjtmImD+YmV+tyLiUTuikNl+5c= 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 1592998494122672.2873812000192; Wed, 24 Jun 2020 04:34:54 -0700 (PDT) Received: from localhost ([::1]:55006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo3g4-0002Pw-Px for importer@patchew.org; Wed, 24 Jun 2020 07:34:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo3Yo-0006wk-Ct for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:22 -0400 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:46242) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo3Ym-00077R-Gj for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:22 -0400 Received: by mail-lj1-x243.google.com with SMTP id h19so2089270ljg.13 for ; Wed, 24 Jun 2020 04:27:20 -0700 (PDT) Received: from localhost.localdomain (193-239-39-51.ksi-system.net. [193.239.39.51]) by smtp.gmail.com with ESMTPSA id d6sm1202635lja.77.2020.06.24.04.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 04:27:13 -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=9gdYmHKQollDgqMy022aRxiAZpeq1ES9ZENq0OBDOxo=; b=dtwXG4ml3afbwCJkZEmuWBn6Mny+IhgGCUvQA9X/iqL8dsZSGQ72aojqJryX3DY6hP ZpOyQZfoPXH3jeIt6sSiFvIWlO1kFnao2U5vaW3elWKB8oORBeFrsTKwExGWq4wQkW62 NiV8v6MxuF9pf4/CrbFnhoXd142k6s8Hz3WFeyaU0DYvjshby78Xpb6K6uHEE2l8p9F9 XgKTmM4/hVXv/gppYDBjhZIZxb7TSRz7DmvCVK9q9g2kJLKJtjh19g5ZKXmVsSTMnXcc EtS1Ex8FdNhyhsaatI2AFMoWYgrQSF1EV9lkTAKZSwxrWwR1UdzE7CX0v611IIraEXCw kR3w== 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=9gdYmHKQollDgqMy022aRxiAZpeq1ES9ZENq0OBDOxo=; b=TiiILNEhtq3rAvARX1zvyubxbdWFxg6y84izdOHA+/q+mA9xeEYxcBSRjYBTB9rQZi ES0Zjg/ttkBqXKpRYwDhtJVHDJsSO9VeAkwAviCxBugY2ENuLcDvDI/ud4LtJzLRqWW4 oLEyyumjkqwCFJL63bySO3eDKv+yZlL7BXLCkODySxSadgv/OTpHQXm+9ej+r0/Fp2zU aWSFIEhU6uDweUIIoAvn8xFZLJprIpRJzk0ay7QIg26sYwE+YdDlfEYTi+WVOUgKVAh9 2V3gXc5+46ME4uQL//Jd4kZSSHIX6BFS1ZcB56vADsS12trlSgjIuXrhtdEfC0Kfgq6r LBng== X-Gm-Message-State: AOAM532Ow93WYkiIMqaZ5wXP4r03lLgHDbVj37I4pKbJQ4LG33fURjCH WJkaevK2aFNn98B9WxTY/xN07JrK1ys9yw== X-Google-Smtp-Source: ABdhPJzw8tOKy2PfYDye0AyRmpS8qZeka+0KUMEXYj/XEQ3q3zQDCrrTq2epymhElEFi2E6nvbelXA== X-Received: by 2002:a2e:958c:: with SMTP id w12mr10268851ljh.457.1592998033681; Wed, 24 Jun 2020 04:27:13 -0700 (PDT) From: Szymon Lukasz To: qemu-devel@nongnu.org Subject: [PATCH v2 5/6] virtio-serial-bus: add terminal resize messages Date: Wed, 24 Jun 2020 13:26:39 +0200 Message-Id: <20200624112640.82673-6-noh4hss@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200624112640.82673-1-noh4hss@gmail.com> References: <20200624112640.82673-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::243; envelope-from=noh4hss@gmail.com; helo=mail-lj1-x243.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-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" Implement the part of the virtio spec that allows to notify the virtio driver about terminal resizes. The virtio spec contains two methods to achieve that: For legacy drivers, we have only one port and we put the terminal size in the config space and inject the config changed interrupt. For multiport devices, we use the control virtqueue to send a packet containing the terminal size. Note that the Linux kernel expects the fields indicating the number of rows and columns in a packet to be in a different order than the one specified in the current version of the virtio spec. We follow the Linux implementation, so hopefully there is no implementation of this functionality conforming to the spec. Signed-off-by: Szymon Lukasz Reviewed-by: Michael S. Tsirkin --- hw/char/trace-events | 1 + hw/char/virtio-serial-bus.c | 42 +++++++++++++++++++++++++++++-- hw/core/machine.c | 1 + include/hw/virtio/virtio-serial.h | 5 ++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/hw/char/trace-events b/hw/char/trace-events index d20eafd56f..be40df47ea 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -10,6 +10,7 @@ serial_ioport_write(uint16_t addr, uint8_t value) "write = addr 0x%02x val 0x%02x" =20 # virtio-serial-bus.c virtio_serial_send_control_event(unsigned int port, uint16_t event, uint16= _t value) "port %u, event %u, value %u" +virtio_serial_send_console_resize(unsigned int port, uint16_t cols, uint16= _t rows) "port %u, cols %u, rows %u" virtio_serial_throttle_port(unsigned int port, bool throttle) "port %u, th= rottle %d" virtio_serial_handle_control_message(uint16_t event, uint16_t value) "even= t %u, value %u" virtio_serial_handle_control_message_port(unsigned int port) "port %u" diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 262089c0c9..6d9e94a64e 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -261,6 +261,42 @@ static size_t send_control_event(VirtIOSerial *vser, u= int32_t port_id, return send_control_msg(vser, &cpkt, sizeof(cpkt)); } =20 +/* + * This struct should be added to the Linux kernel uapi headers + * and later imported to standard-headers/linux/virtio_console.h + */ +struct virtio_console_resize { + __virtio16 rows; + __virtio16 cols; +}; + +void virtio_serial_send_console_resize(VirtIOSerialPort *port, + uint16_t cols, uint16_t rows) +{ + VirtIOSerial *vser =3D port->vser; + VirtIODevice *vdev =3D VIRTIO_DEVICE(vser); + + if (virtio_vdev_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) { + struct { + struct virtio_console_control control; + struct virtio_console_resize resize; + } buffer; + + virtio_stl_p(vdev, &buffer.control.id, port->id); + virtio_stw_p(vdev, &buffer.control.event, VIRTIO_CONSOLE_RESIZE); + virtio_stw_p(vdev, &buffer.resize.cols, cols); + virtio_stw_p(vdev, &buffer.resize.rows, rows); + + trace_virtio_serial_send_console_resize(port->id, cols, rows); + send_control_msg(vser, &buffer, sizeof(buffer)); + + } else if (virtio_vdev_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) { + vser->port0_cols =3D cols; + vser->port0_rows =3D rows; + virtio_notify_config(vdev); + } +} + /* Functions for use inside qemu to open and read from/write to ports */ int virtio_serial_open(VirtIOSerialPort *port) { @@ -572,8 +608,8 @@ static void get_config(VirtIODevice *vdev, uint8_t *con= fig_data) struct virtio_console_config *config =3D (struct virtio_console_config *)config_data; =20 - config->cols =3D 0; - config->rows =3D 0; + config->cols =3D virtio_tswap16(vdev, vser->port0_cols); + config->rows =3D virtio_tswap16(vdev, vser->port0_rows); config->max_nr_ports =3D virtio_tswap32(vdev, vser->serial.max_virtserial_port= s); } @@ -1168,6 +1204,8 @@ static Property virtio_serial_properties[] =3D { 31), DEFINE_PROP_BIT64("emergency-write", VirtIOSerial, host_features, VIRTIO_CONSOLE_F_EMERG_WRITE, true), + DEFINE_PROP_BIT64("console-size", VirtIOSerial, host_features, + VIRTIO_CONSOLE_F_SIZE, true), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/core/machine.c b/hw/core/machine.c index 1d80ab0e1d..c370c220f0 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -30,6 +30,7 @@ =20 GlobalProperty hw_compat_5_0[] =3D { { "virtio-balloon-device", "page-poison", "false" }, + { "virtio-serial-device", "console-size", "off" }, }; const size_t hw_compat_5_0_len =3D G_N_ELEMENTS(hw_compat_5_0); =20 diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-s= erial.h index ed3e916b68..1d6436c0b1 100644 --- a/include/hw/virtio/virtio-serial.h +++ b/include/hw/virtio/virtio-serial.h @@ -188,6 +188,8 @@ struct VirtIOSerial { virtio_serial_conf serial; =20 uint64_t host_features; + + uint16_t port0_cols, port0_rows; }; =20 /* Interface to the virtio-serial bus */ @@ -222,6 +224,9 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port= ); */ void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle); =20 +void virtio_serial_send_console_resize(VirtIOSerialPort *port, + uint16_t cols, uint16_t rows); + #define TYPE_VIRTIO_SERIAL "virtio-serial-device" #define VIRTIO_SERIAL(obj) \ OBJECT_CHECK(VirtIOSerial, (obj), TYPE_VIRTIO_SERIAL) --=20 2.27.0 From nobody Mon Apr 29 10:43:45 2024 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=1592998355; cv=none; d=zohomail.com; s=zohoarc; b=gVjxHrwLbyproEjgAgKArGF9FzYLfsjRrwqhFtbvqCguaBePwFLScfDvY2sPol3rlD+CKsLFoZ9LlTgJ5Aj859TrPeaQIyjjNtmtffl/mv+ir6pRfq91G8dvS9Pirw/F/iIxL8EIKqjLO9nRKUpJY+VFobNebcc7tOBVLCbVRmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592998355; 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=U24VPFWdLiH9zJdH5m+tYQqpxCOq7+mouQ2KuCIWI1knYCD0y6/8ItjK49AwHZ6SypL28qEy1Y+HJ9Avd2zNpWSwSHMZK/eb/8MfdDFMGBMTHxenWnVAK79KOEd6V4vcUYI8ARnvBhWO4KbrLbJ16eZ/Bu8tEJt9AuOI1sas9qk= 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 1592998355984875.6687396085013; Wed, 24 Jun 2020 04:32:35 -0700 (PDT) Received: from localhost ([::1]:46304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo3dq-0006Lp-Ox for importer@patchew.org; Wed, 24 Jun 2020 07:32:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo3Yk-0006nS-8x for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:18 -0400 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]:42223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo3Yi-00076T-EV for qemu-devel@nongnu.org; Wed, 24 Jun 2020 07:27:17 -0400 Received: by mail-lj1-x241.google.com with SMTP id y11so2112935ljm.9 for ; Wed, 24 Jun 2020 04:27:16 -0700 (PDT) Received: from localhost.localdomain (193-239-39-51.ksi-system.net. [193.239.39.51]) by smtp.gmail.com with ESMTPSA id d6sm1202635lja.77.2020.06.24.04.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 04:27:14 -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=F/8SQUKOwFLmPTSJVnnnyo8l52w/byacFfuuF5736V0G2PCprDnikDatI05vxiQ3Ss HOBhau7VQk3jAWoHVSs1g47/y3EQBx7R1Ac8GM6tobredp7mSg9Whx1hy89f+pCRFNiy bUPSk36MVu1Z3zqqSZxyo+9FjSfrWcL8o/NfIwrOotbh00EKqr3Y2wrfvPt17ShIOM2+ uu5aZTbJbjYqPyHFzXNmH217RjG+7ZpijNY6BkQj9HbEQDCrwVP63rNKn4yd1fxhNE78 s+bOl+v9rFD46VRdJxxgo0magdIyxTkE0POPWHj+yrDfrJawff5Fqt3Bv9Kslrwa41qH 0JTg== 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=AkW7VDs1/uAvx5giNuoYc/5N6qFN5kDoXhIqZIhX3dxRMEEgJSYgIWrAG7MW4g7IyW rrwhP7sKs7hXmotUC84dC3c1i4QvLKia78KZvDslz6P6Idt5NLBmOez80VJ9I3IDk5EI VJEHBP9quqdRlV+uFMd4wiXQjFQhuIFeul5hq4ezxh7spIMDDVwC8jFkeIMGUP4mXjEA uK7+eUte6zP5WUd4dn9OYZQWoMGpwNKQnwbYGI2Tmsjep3Wm3vVy5RL/VklhYPIXdhQl 1ffdL3xJxNK+fDjlAqtifgjUKFSbKJdDkWqqhPQNmOFCAHIKAXCrTLwUdDSl4DSkWPGt eJ3w== X-Gm-Message-State: AOAM530NAW863Om7WH1er1+hRq/s+s3WqOw5lPwXW6snnR7DuPocrv7/ Skk3rkepeZxIkEz04v3Z2iJdHZaiiApQSA== X-Google-Smtp-Source: ABdhPJzUUqHN1jh793be478v7hGfc2gyUpDwMksAGfaMMy1pc6vmeVaSaTPTCkdGduwCVxtIU5kErg== X-Received: by 2002:a2e:b0c3:: with SMTP id g3mr13067145ljl.31.1592998034596; Wed, 24 Jun 2020 04:27:14 -0700 (PDT) From: Szymon Lukasz To: qemu-devel@nongnu.org Subject: [PATCH v2 6/6] virtio-console: notify the guest about terminal resizes Date: Wed, 24 Jun 2020 13:26:40 +0200 Message-Id: <20200624112640.82673-7-noh4hss@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200624112640.82673-1-noh4hss@gmail.com> References: <20200624112640.82673-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::241; envelope-from=noh4hss@gmail.com; helo=mail-lj1-x241.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-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