From patchwork Fri May 19 12:47:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9737155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2365C6034C for ; Fri, 19 May 2017 12:54:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1669628929 for ; Fri, 19 May 2017 12:54:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0997428930; Fri, 19 May 2017 12:54:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C417528929 for ; Fri, 19 May 2017 12:54:28 +0000 (UTC) Received: from localhost ([::1]:58646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBhQK-00059q-31 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 May 2017 08:54:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBhK3-0000eU-TO for qemu-devel@nongnu.org; Fri, 19 May 2017 08:48:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBhK1-0004Mk-P6 for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:59 -0400 Received: from mail-eopbgr00136.outbound.protection.outlook.com ([40.107.0.136]:31167 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBhK1-0004AG-HJ for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=34wDlga/NuUnlvEX9jKUNHa9MMj9ZUX4MMg3zUyNmZo=; b=eRf+xhZk+SZi4QBuSafBF2PIWd7rGqPAnUgV4pVF00P0NawDN+M7MG8+GUm55mGYOSa9RWMD+IDpQG5pN2OUpweJ5Ewk9CPW8ipAMDOemVLF4VtvdptBSSVrqO+BewbyNOH8fbFI07Y0rahs/XEDWUza8rzkFhgea47w+OP+7Ms= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by DB6PR0801MB1989.eurprd08.prod.outlook.com (10.168.85.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Fri, 19 May 2017 12:47:56 +0000 From: Anton Nefedov To: Date: Fri, 19 May 2017 15:47:22 +0300 Message-ID: <1495198042-124203-10-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495198042-124203-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1495198042-124203-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR1001CA0002.EURPRD10.PROD.OUTLOOK.COM (10.171.79.12) To DB6PR0801MB1989.eurprd08.prod.outlook.com (10.168.85.150) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB6PR0801MB1989: X-MS-Office365-Filtering-Correlation-Id: fba0a6a4-7859-436a-c871-08d49eb545ec X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:DB6PR0801MB1989; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 3:L6DzhIw23ug1y8p7gNxLEZLo3V0sp5UPB+NCpFt6lOUpISRbCBaAVv2p1/5YMiPX8eumtvc2GQ6AesnkYFe/9CTXizkE+OIYrYcuWjng1wTo+yNx5ybc7kH2MqCW8jrcGHgpXRwqIePD40yMX8A5eyoPWwLwqYnNykLgjQTgf3MOjKvqspQK7YliNxKicL1DY5u+Si7L0rg5rVS8zY2QZYWfF+VRr9743X2ftWFSnhSXSPHdF3NoUzUwkiJntbSs6SvjOhnyDTUCcat2F52YkYlB5vErXLBMnxlJ/bE5MRX3yjhTub3fgmW72xmhbGpZ4T4U4ZgezpUSczwnt/rV0A==; 25:Xwqcb656aX8XloC/U0n/vhSDR30O8e6KBIJXERLZ8T+34EKFkTvaruUfdtE1mlgZgyXKxmkt03EpP3CT5gRqnVILCmqYDLSC9iMBSvP2xt3RJ30kIqB94ziuhtAPQcbbn4XSQSfu9eMR+J6GOuHqcyJmHRLUFIvi+3XAGTfrVzf40UaK6vX45twmvzHH2RQ8l4iSsinOvfUNVl0gwLEk2sa8PHxNGCybPjjgvjKzFjWDUa7K+TPsk/j3qO1sLjhiRflgsc80DcHnJI31BAU6F+2630AR2Jih7GQIS4xmqnoFErsXQ1Kpdoghg1iGSRTkI2BKVuJqbZhEmQIrsbkhJKbhhbZq+OReI2UfOW0tYN8AiQu4OorJTBIXLae7zQS+mdD9NYzjxvRPk+ScSpx8ecPKYiMLCRC14lGO3AE1FXMInSwN1dyOzX27NwJwNuJXuADoMG08na6NDRP5rbfUl2SEVB4ya3r3IHykSN6pX20= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 31:4XWdO2BKD/QXqthNttEsglOC03Nu1N2YL883iE2rmiJipZlsb1BqZIfL3UOIhgF5yaaR6kPKB5MKEqYi0R4GqS7uXdj0h12Tp7i7pYtWgkVQCgbDCyHUO3JSZIxpqBUqevJT9ZduHiJTd6xaGPZ6TOpVe9kB8QbkHj1RckEC3464CSgVtD6KQIjXqOQDkIIM0vIMV3MKPdAKn7Jw1SJi+uN0awMwWGFtllBFm1haYfE=; 20:801e/IlkwOk9gG4a9MdNi8Nzfok9f5LAgiOWZonMR+0A970419tYTZwMWnf/DeyE5SGDtWBOs/UW/1Pc2ZYw5qR13HIYU4fk4L5PYcGKg6urhxGS/+xQOrn8IP+y8KY5lNgei+orn/WQtgaWWwSaMppSUasgz7gev01P8HqPCUGysrJH+utmtE9ILLbhQ9InZ39vK8K0QzQ+mEf5an4Qp9/+FLzKJ6gfsVF9dblvkRRx6rYPiHnFyJhc1J9Cw20htd7Nh92wQCpzLyE5BhjXr3IsmjTztty1Ztav1In4Y4f1ApmizFUPqnMCUAtwty8HpiytuLciO82biWySY2qFoVFU6iajNNceJwe9nn0ogW6czFEJzfISQJfWEMYSNWE2K/l2XGqKmo246mvXhGbPIltcs/SPU1ZM1fHn8Gq1w8E= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(158342451672863); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(6041248)(20161123560025)(20161123555025)(20161123558100)(20161123562025)(20161123564025)(201703131423075)(201703061421075)(6072148); SRVR:DB6PR0801MB1989; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0801MB1989; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 4:OC1ZDjjo3aUP1B13gsSSFKDy0KenOwtRofkicTT+AtpAJVBAidjmLkNObPGlzlh1SRnQx1f8Kg0yyEWhiL8JrRqoCYF9i0d6YrK3vHq6fGqUx46z3gzYMDfsI7z/tkIhm0YNlV4mcvp/WoqK0/RQCJ2PtkWtK/k/foqevc34HfTYTSJjtMRHOHSMxsxIQ0cOJFVQ1BD2jpPigElIkdLHupyfc4/1Ri4XNp2sOfB9z7yrnBlz+CO/i2E+Li6wJPJFk62K61jMDaStMkjN9vDV8ILE4DFWpayrXiCXXlST1VBeCBlfOW2+Y1wtuMXiYLWi32DLKS5tL32zdlU4/PlgWUndGjvE9UyZkLudWQz2ZpKjMimW6yCCQOsVNKSJhgtGYiWFdNJFO9I3VQAi+eoFIcFQxxmgDU1KQ4yvncmn8eFXM6zlITzxAyeVu2o8L+ucQFGIoLy/VSlTtExRVMfWfiFfdtLeqvOU6ONrPOZIWJcbZg3GQbscYU1zglsxFa+9Tt3n8qOJNrpGffdnd1tQ+Cc3oL/MN4o2QZnQIOCDagxs78z3nzZMloQCrvq6vSDF9+P3RmlA9sj6WE6f0rpsJ/L1E6LZPp3YRSpN/EPir3B8u+IdOcEbL48yXbKo5PjmwwN50+26VrkAdA0koY6OzYNOl8eAMqMVgCLG5ghorDZMUfA11U5zKgjzn7BUunMIIwiVt0fitmDFJCZsbEtwcBYvz3WXb7beBX4YqjVMdYs87gYMpauUWeql5AjoBlbGCCSv95oo49pwd/lRTF8uIA== X-Forefront-PRVS: 031257FE13 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39400400002)(39450400003)(33646002)(48376002)(5003940100001)(53936002)(38730400002)(25786009)(2351001)(6506006)(6486002)(107886003)(4326008)(110136004)(5660300001)(36756003)(7736002)(6916009)(2950100002)(305945005)(6666003)(5890100001)(66066001)(2906002)(189998001)(50226002)(50466002)(54906002)(508600001)(86362001)(6512007)(81166006)(8676002)(50986999)(53416004)(3846002)(76176999)(575784001)(42186005)(21314002); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0801MB1989; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0801MB1989; 23:2GJ+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Xids= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 7:1V1Y7PTGPzlaipwIAW4NaqCpne5IMRAL/xgI8vNJj8ZtR76HA3rtNxsHThKJOTcEshZC/Ll/18jpoj5GfCaZoPGv2c0NK3uYoVYZhIvvfTHTXzmRvTnOWN53i3MC7C3WnOY+m2B61LmPUA5usTRvmilnuh04UeL676HucN7wxA9C9h/fOwxt0XOSw4Qsgd+77voG1sE3giTmRnUKgvszOIaAg1/xcYCMWVdbEPoHNaC9hrRyhROIJLQ/mz2I5AEVQZOavomemeEc77QENixVzfoWD+k7UWU6/EAjnjVRWESqAxHob08tYGAZREzGK3kuwUQHqN9kNSWOCriN7NkoOw==; 20:JvqEZ6Zx6QmscMfYfsAxDzSMoXBz+TU5Ny09pE6GF824lx9sdNLAjVp6wNib7kcneIWhl2spSnQLYTXwwsd6T6jyMTfPfv/gSHuF0gxey87zZIU1j0lMKqD7BYtbMqE4CiQcntXYeVv5FCCH2gGPPaHbvPrUKflm6kyZd5spQao= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2017 12:47:56.1033 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1989 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.0.136 Subject: [Qemu-devel] [PATCH v2 9/9] char: avoid chardevice direct access X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, Anton Nefedov , den@virtuozzo.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP frontends should avoid accessing CharDriver struct where possible Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy --- chardev/char.c | 5 +++++ gdbstub.c | 2 +- hw/arm/strongarm.c | 2 +- hw/char/cadence_uart.c | 2 +- hw/char/debugcon.c | 2 +- hw/char/escc.c | 6 +++--- hw/char/exynos4210_uart.c | 2 +- hw/char/grlib_apbuart.c | 2 +- hw/char/ipoctal232.c | 2 +- hw/char/parallel.c | 2 +- hw/char/sclpconsole-lm.c | 2 +- hw/char/sclpconsole.c | 2 +- hw/char/sh_serial.c | 2 +- hw/char/spapr_vty.c | 2 +- hw/char/terminal3270.c | 2 +- hw/char/xen_console.c | 2 +- hw/ipmi/ipmi_bmc_extern.c | 2 +- hw/misc/ivshmem.c | 4 ++-- hw/usb/ccid-card-passthru.c | 4 ++-- hw/usb/dev-serial.c | 5 ++--- hw/usb/redirect.c | 5 ++--- include/sysemu/char.h | 7 +++++++ net/filter-mirror.c | 2 +- 23 files changed, 39 insertions(+), 29 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index 36d6f36..e43d840 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -494,6 +494,11 @@ bool qemu_chr_fe_backend_connected(CharBackend *be) return !!be->chr; } +bool qemu_chr_fe_backend_open(CharBackend *be) +{ + return be->chr && be->chr->be_open; +} + static bool fe_connect(CharBackend *b, Chardev *s, Error **errp) { int tag = 0; diff --git a/gdbstub.c b/gdbstub.c index 1ac0489..68cbe8a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2001,7 +2001,7 @@ int gdbserver_start(const char *device) NULL, &error_abort); monitor_init(mon_chr, 0); } else { - if (qemu_chr_fe_get_driver(&s->chr)) { + if (qemu_chr_fe_backend_connected(&s->chr)) { object_unparent(OBJECT(qemu_chr_fe_get_driver(&s->chr))); } mon_chr = s->mon_chr; diff --git a/hw/arm/strongarm.c b/hw/arm/strongarm.c index bec093d..9d7cf21 100644 --- a/hw/arm/strongarm.c +++ b/hw/arm/strongarm.c @@ -1105,7 +1105,7 @@ static void strongarm_uart_tx(void *opaque) if (s->utcr3 & UTCR3_LBM) /* loopback */ { strongarm_uart_receive(s, &s->tx_fifo[s->tx_start], 1); - } else if (qemu_chr_fe_get_driver(&s->chr)) { + } else if (qemu_chr_fe_backend_connected(&s->chr)) { /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ qemu_chr_fe_write_all(&s->chr, &s->tx_fifo[s->tx_start], 1); diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c index 71867b3..19636c0 100644 --- a/hw/char/cadence_uart.c +++ b/hw/char/cadence_uart.c @@ -278,7 +278,7 @@ static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond, int ret; /* instant drain the fifo when there's no back-end */ - if (!qemu_chr_fe_get_driver(&s->chr)) { + if (!qemu_chr_fe_backend_connected(&s->chr)) { s->tx_count = 0; return FALSE; } diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c index 6d95297..bd0d4f0 100644 --- a/hw/char/debugcon.c +++ b/hw/char/debugcon.c @@ -87,7 +87,7 @@ static const MemoryRegionOps debugcon_ops = { static void debugcon_realize_core(DebugconState *s, Error **errp) { - if (!qemu_chr_fe_get_driver(&s->chr)) { + if (!qemu_chr_fe_backend_connected(&s->chr)) { error_setg(errp, "Can't create debugcon device, empty char device"); return; } diff --git a/hw/char/escc.c b/hw/char/escc.c index aa882b6..dbbeb4a 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -416,7 +416,7 @@ static void escc_update_parameters(ChannelState *s) int speed, parity, data_bits, stop_bits; QEMUSerialSetParams ssp; - if (!qemu_chr_fe_get_driver(&s->chr) || s->type != ser) + if (!qemu_chr_fe_backend_connected(&s->chr) || s->type != ser) return; if (s->wregs[W_TXCTRL1] & TXCTRL1_PAREN) { @@ -556,7 +556,7 @@ static void escc_mem_write(void *opaque, hwaddr addr, trace_escc_mem_writeb_data(CHN_C(s), val); s->tx = val; if (s->wregs[W_TXCTRL2] & TXCTRL2_TXEN) { // tx enabled - if (qemu_chr_fe_get_driver(&s->chr)) { + if (qemu_chr_fe_backend_connected(&s->chr)) { /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ qemu_chr_fe_write_all(&s->chr, &s->tx, 1); @@ -1012,7 +1012,7 @@ static void escc_realize(DeviceState *dev, Error **errp) ESCC_SIZE << s->it_shift); for (i = 0; i < 2; i++) { - if (qemu_chr_fe_get_driver(&s->chn[i].chr)) { + if (qemu_chr_fe_backend_connected(&s->chn[i].chr)) { s->chn[i].clock = s->frequency / 2; qemu_chr_fe_set_handlers(&s->chn[i].chr, serial_can_receive, serial_receive1, serial_event, NULL, diff --git a/hw/char/exynos4210_uart.c b/hw/char/exynos4210_uart.c index 7ef4ea5..2b0576c 100644 --- a/hw/char/exynos4210_uart.c +++ b/hw/char/exynos4210_uart.c @@ -379,7 +379,7 @@ static void exynos4210_uart_write(void *opaque, hwaddr offset, break; case UTXH: - if (qemu_chr_fe_get_driver(&s->chr)) { + if (qemu_chr_fe_backend_connected(&s->chr)) { s->reg[I_(UTRSTAT)] &= ~(UTRSTAT_TRANSMITTER_EMPTY | UTRSTAT_Tx_BUFFER_EMPTY); ch = (uint8_t)val; diff --git a/hw/char/grlib_apbuart.c b/hw/char/grlib_apbuart.c index 610a317..1cb9026 100644 --- a/hw/char/grlib_apbuart.c +++ b/hw/char/grlib_apbuart.c @@ -201,7 +201,7 @@ static void grlib_apbuart_write(void *opaque, hwaddr addr, case DATA_OFFSET: case DATA_OFFSET + 3: /* When only one byte write */ /* Transmit when character device available and transmitter enabled */ - if (qemu_chr_fe_get_driver(&uart->chr) && + if (qemu_chr_fe_backend_connected(&uart->chr) && (uart->control & UART_TRANSMIT_ENABLE)) { c = value & 0xFF; /* XXX this blocks entire thread. Rewrite to use diff --git a/hw/char/ipoctal232.c b/hw/char/ipoctal232.c index 734e42c..b5ada43 100644 --- a/hw/char/ipoctal232.c +++ b/hw/char/ipoctal232.c @@ -542,7 +542,7 @@ static void ipoctal_realize(DeviceState *dev, Error **errp) ch->ipoctal = s; /* Redirect IP-Octal channels to host character devices */ - if (qemu_chr_fe_get_driver(&ch->dev)) { + if (qemu_chr_fe_backend_connected(&ch->dev)) { qemu_chr_fe_set_handlers(&ch->dev, hostdev_can_receive, hostdev_receive, hostdev_event, NULL, ch, NULL, true); diff --git a/hw/char/parallel.c b/hw/char/parallel.c index c71a4a0..b3ed117 100644 --- a/hw/char/parallel.c +++ b/hw/char/parallel.c @@ -512,7 +512,7 @@ static void parallel_isa_realizefn(DeviceState *dev, Error **errp) int base; uint8_t dummy; - if (!qemu_chr_fe_get_driver(&s->chr)) { + if (!qemu_chr_fe_backend_connected(&s->chr)) { error_setg(errp, "Can't create parallel device, empty char device"); return; } diff --git a/hw/char/sclpconsole-lm.c b/hw/char/sclpconsole-lm.c index ed1e2c5..ff54d19 100644 --- a/hw/char/sclpconsole-lm.c +++ b/hw/char/sclpconsole-lm.c @@ -195,7 +195,7 @@ static int write_console_data(SCLPEvent *event, const uint8_t *buf, int len) { SCLPConsoleLM *scon = SCLPLM_CONSOLE(event); - if (!qemu_chr_fe_get_driver(&scon->chr)) { + if (!qemu_chr_fe_backend_connected(&scon->chr)) { /* If there's no backend, we can just say we consumed all data. */ return len; } diff --git a/hw/char/sclpconsole.c b/hw/char/sclpconsole.c index 9a65010..7e23d09 100644 --- a/hw/char/sclpconsole.c +++ b/hw/char/sclpconsole.c @@ -163,7 +163,7 @@ static ssize_t write_console_data(SCLPEvent *event, const uint8_t *buf, { SCLPConsole *scon = SCLP_CONSOLE(event); - if (!qemu_chr_fe_get_driver(&scon->chr)) { + if (!qemu_chr_fe_backend_connected(&scon->chr)) { /* If there's no backend, we can just say we consumed all data. */ return len; } diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c index c352337..868773f 100644 --- a/hw/char/sh_serial.c +++ b/hw/char/sh_serial.c @@ -110,7 +110,7 @@ static void sh_serial_write(void *opaque, hwaddr offs, } return; case 0x0c: /* FTDR / TDR */ - if (qemu_chr_fe_get_driver(&s->chr)) { + if (qemu_chr_fe_backend_connected(&s->chr)) { ch = val; /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c index 9cdc0e0..6d1ccff 100644 --- a/hw/char/spapr_vty.c +++ b/hw/char/spapr_vty.c @@ -78,7 +78,7 @@ static void spapr_vty_realize(VIOsPAPRDevice *sdev, Error **errp) { VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(sdev); - if (!qemu_chr_fe_get_driver(&dev->chardev)) { + if (!qemu_chr_fe_backend_connected(&dev->chardev)) { error_setg(errp, "chardev property not set"); return; } diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c index 943a0f3..62803e5 100644 --- a/hw/char/terminal3270.c +++ b/hw/char/terminal3270.c @@ -239,7 +239,7 @@ static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd, return 0; } } - if (!qemu_chr_fe_get_driver(&t->chr)) { + if (!qemu_chr_fe_backend_connected(&t->chr)) { /* We just say we consumed all data if there's no backend. */ return count; } diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index cb7975f..b066176 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -150,7 +150,7 @@ static void xencons_send(struct XenConsole *con) ssize_t len, size; size = con->buffer.size - con->buffer.consumed; - if (qemu_chr_fe_get_driver(&con->chr)) { + if (qemu_chr_fe_backend_connected(&con->chr)) { len = qemu_chr_fe_write(&con->chr, con->buffer.data + con->buffer.consumed, size); diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c index 6f2339d..0ca9e92 100644 --- a/hw/ipmi/ipmi_bmc_extern.c +++ b/hw/ipmi/ipmi_bmc_extern.c @@ -447,7 +447,7 @@ static void ipmi_bmc_extern_realize(DeviceState *dev, Error **errp) { IPMIBmcExtern *ibe = IPMI_BMC_EXTERN(dev); - if (!qemu_chr_fe_get_driver(&ibe->chr)) { + if (!qemu_chr_fe_backend_connected(&ibe->chr)) { error_setg(errp, "IPMI external bmc requires chardev attribute"); return; } diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index e2dece8..a1be4bb 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -1130,7 +1130,7 @@ static void ivshmem_doorbell_realize(PCIDevice *dev, Error **errp) { IVShmemState *s = IVSHMEM_COMMON(dev); - if (!qemu_chr_fe_get_driver(&s->server_chr)) { + if (!qemu_chr_fe_backend_connected(&s->server_chr)) { error_setg(errp, "You must specify a 'chardev'"); return; } @@ -1259,7 +1259,7 @@ static void ivshmem_realize(PCIDevice *dev, Error **errp) " or ivshmem-doorbell instead"); } - if (!!qemu_chr_fe_get_driver(&s->server_chr) + !!s->shmobj != 1) { + if (qemu_chr_fe_backend_connected(&s->server_chr) + !!s->shmobj != 1) { error_setg(errp, "You must specify either 'shm' or 'chardev'"); return; } diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 9ace5ac..c0f8acd 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -325,7 +325,7 @@ static void passthru_apdu_from_guest( { PassthruState *card = PASSTHRU_CCID_CARD(base); - if (!qemu_chr_fe_get_driver(&card->cs)) { + if (!qemu_chr_fe_backend_connected(&card->cs)) { printf("ccid-passthru: no chardev, discarding apdu length %d\n", len); return; } @@ -346,7 +346,7 @@ static int passthru_initfn(CCIDCardState *base) card->vscard_in_pos = 0; card->vscard_in_hdr = 0; - if (qemu_chr_fe_get_driver(&card->cs)) { + if (qemu_chr_fe_backend_connected(&card->cs)) { DPRINTF(card, D_INFO, "initing chardev\n"); qemu_chr_fe_set_handlers(&card->cs, ccid_card_vscard_can_read, diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c index e6b2c7c..7aa7290 100644 --- a/hw/usb/dev-serial.c +++ b/hw/usb/dev-serial.c @@ -483,13 +483,12 @@ static void usb_serial_realize(USBDevice *dev, Error **errp) { USBSerialState *s = USB_SERIAL_DEV(dev); Error *local_err = NULL; - Chardev *chr = qemu_chr_fe_get_driver(&s->cs); usb_desc_create_serial(dev); usb_desc_init(dev); dev->auto_attach = 0; - if (!chr) { + if (!qemu_chr_fe_backend_connected(&s->cs)) { error_setg(errp, "Property chardev is required"); return; } @@ -504,7 +503,7 @@ static void usb_serial_realize(USBDevice *dev, Error **errp) usb_serial_event, NULL, s, NULL, true); usb_serial_handle_reset(dev); - if (chr->be_open && !dev->attached) { + if (qemu_chr_fe_backend_open(&s->cs) && !dev->attached) { usb_device_attach(dev, &error_abort); } } diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 1e9bf69..6992d92 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -273,10 +273,9 @@ static gboolean usbredir_write_unblocked(GIOChannel *chan, GIOCondition cond, static int usbredir_write(void *priv, uint8_t *data, int count) { USBRedirDevice *dev = priv; - Chardev *chr = qemu_chr_fe_get_driver(&dev->cs); int r; - if (!chr->be_open) { + if (!qemu_chr_fe_backend_open(&dev->cs)) { return 0; } @@ -1366,7 +1365,7 @@ static void usbredir_realize(USBDevice *udev, Error **errp) USBRedirDevice *dev = USB_REDIRECT(udev); int i; - if (!qemu_chr_fe_get_driver(&dev->cs)) { + if (!qemu_chr_fe_backend_connected(&dev->cs)) { error_setg(errp, QERR_MISSING_PARAMETER, "chardev"); return; } diff --git a/include/sysemu/char.h b/include/sysemu/char.h index fa21535..e1a0e52 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -418,6 +418,13 @@ Chardev *qemu_chr_fe_get_driver(CharBackend *be); bool qemu_chr_fe_backend_connected(CharBackend *be); /** + * @qemu_chr_fe_backend_open: + * + * Returns true if chardevice associated with @be is open. + */ +bool qemu_chr_fe_backend_open(CharBackend *be); + +/** * @qemu_chr_fe_deinit: * * Dissociate the CharBackend from the Chardev. diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 06321d7..72a6077 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -163,7 +163,7 @@ static ssize_t filter_redirector_receive_iov(NetFilterState *nf, MirrorState *s = FILTER_REDIRECTOR(nf); int ret; - if (qemu_chr_fe_get_driver(&s->chr_out)) { + if (qemu_chr_fe_backend_connected(&s->chr_out)) { ret = filter_mirror_send(&s->chr_out, iov, iovcnt); if (ret) { error_report("filter_mirror_send failed(%s)", strerror(-ret));