From patchwork Fri May 19 12:47:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9737143 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 C27886034C for ; Fri, 19 May 2017 12:52:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B628C28929 for ; Fri, 19 May 2017 12:52:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA0FA28930; Fri, 19 May 2017 12:52:11 +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 322BA28929 for ; Fri, 19 May 2017 12:52:11 +0000 (UTC) Received: from localhost ([::1]:58638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBhO6-0002u8-CG for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 May 2017 08:52:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBhK1-0000cZ-4x for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBhK0-0004KE-4h for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:57 -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 1dBhJz-0004AG-Ss for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:56 -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=Sl4C1hZQAn/zQ9rVhK9K6y4XaDW7T2AAfzjR5s1CP08=; b=CdZj6BfT43HG+Nxj4nJY+nJ3sSmZMgKMjRYYvJlluFh8H4lWnHt790T1s7Tplj92wSWOuNXSAniP+NgFq2bW2T9AaNWLlShYLEmUmrtgqB9S6JzaHBY3zY9f/Q7BVlnnwSkq9jm4BvBgV5xXuADMayYS9/605c3Pg2Do6MAKGIw= 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:52 +0000 From: Anton Nefedov To: Date: Fri, 19 May 2017 15:47:19 +0300 Message-ID: <1495198042-124203-7-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: 922d8cf3-5395-41aa-e0ae-08d49eb543ae X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:DB6PR0801MB1989; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 3:iNsilysDZs8A10i0WKjIS8EUhO+LJSuiRVN6p24BttMIHpBgW/ia5xMdVK9JqoS+DGR2X2QqJZmXq9lJ3OpbSx1l3Ouapyj/SrdRzo/jL8X9YtNmpYnNz4SbOHVk31gIficfmH/aXqIH2Iy+JtnAhMY94+ETR9PGaD6zbnUcDaIbo8J9e43tjsqPmb7LAY2M+SUdpvExCzWDEepFA1US93jHpPDnCv7H7Nan2T60Sb6H04SQt3veMTol2ZKyUi8hHIHSzcAVS3x4mMjR/qOGJX734lJDqzXRYhpoJSfW3t7MscuerLc8sZKuo6hsLGAgEQGJrQnhBcVGZDjAhD8gJQ==; 25:UkPTt0Hf+/BuN1JoVUoV7sRc/1ByTkY1pEZr8AsaDv59suAOW+66ttH3EAMBVEOc77BzjukbQlUptgZLA172W5FCWwx7VuSTlvwfqA8BiR8R0X2e5JN4iNV9ZKeOcR2bGzE41wfOW6y+s29aGgIO/3Rt3NmhoQ3Xq2EOQHATVah6GYs/aP5zS5FrNZF243S53mNyTSrBrUFe+QV9dyOgveoIS6Jsi3SBxjiO0p53Zs25MFvXXo7oYqdqkjOb6P0krBFU7dd6kibjdX2yYm4mD6gIQHMiVzsKR8fYQdGghMKSuiHRezZjQeaOoQTwh7wBMnlD9KIvQYksgUR8Uhmy7xHSXPW10uQ/55sK1oRbwFWIefyS5dtxTyQbNYOsiergETm/FcNmAaq7RaNLT9DyvyPSLYVAylX3kLT5SvFL6W4YukIK+Du3YC7h8nI6jlMo+DlUvmCncvBLoBYqbjly9erW7IuoPdRox3TEYQ2PKNQ= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 31:4tiHhp24sN+ektGZW/LdlcuzoxWGy6Me/F7dA9Ym4z1Iw+CsaVRoc2F+OxFSRhEWMLjIDgMGIvbbaXayYgwzf7fMGBxNJcDdxvyrZpc8ux+J0RHAuymmjRqZIN+jc+MjWAeg+ey8YhahBvLYyNIsTp6qyhbIzwU6/BHzw0hGT0XeoZjM5wj+1zmSFFgM3TSaYese5GA4/fwHby2Fhigd52SpWrMc5qYG7ZcDob+3LgOxNImJ16xsWMb5UfQXlh5wkYRTJkVv9LJaDJCagFYAjQ==; 20:UMdDgfgJnn/Ou0Au3CZZNHOCflapj2Q+ub5QORaWI2DsKTYpM8i90ZMj6xv6+RPTippva9gGBcfrO/KBxtCSeLdtsOVFST5R/yyhjBQUIvvvHMYyMUCkl59b7wkH+njaw86p5FhmCSythULczjOPe285e468EMFWJuKgSjZ48VGDxLIIL4Q8tuN6aCP113ofsgfst/QE6XIlIf12Ezm7TpucDvSu/hrykcE2UapiXcfMopMrJvWQH9/0xbw7AF1nrMDollLhNy9fpdLF4C/PtAnQCGLVemvL8X40kP56Epjk3f/Nj+IP2CjyEtvxoZSub2DPlzW7dLsds2HVh8Yz9TZZEtVLQsvhMDLl34Bh2YoKH+16rL/VI5k2d2tGvgowLA6Xg52lnsne0P04qBNl8yh0h1TKv36CydcXkOmZORk= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; 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:ku/YHSRSKIVQbRXi78LfIhDS2ju8OJYO/LSkaRmqvuWANEaaWCVh8V4+jKVuuDTM795rq+oYWkr/on0jAFw8vxZk1Ww/7B5yBGlNQZukShJ1n4h4LByZyLNHJEQpNvS+4cdlTYXYZmRLgkAzCgMuyLm+tL7ugKmceAUGP27iIPHZIQCnay2NbLFUDbrfwbBg+dYKBgMJP9p3USquqp8NlMdQ6A4ngiM3M8C+kRbAkwCK3DjNuQuV/VjZgtM+X9vnymFXVAiriWKy2a3lNly4vYNz21tqV4k8qBVB/y8J66FFWy0wNBIbR8A9csXFWXQhsy8216HPDfyGw6MpKfinBC/cZ8Lf9rYLHG0fAQ/MANFSH+wOB4H7ibd7anamatjrKnmm2iEICGA9dkbs5MpZxRYtuTtQV4pG3u+TeTtcaIx9facBOqAckP6lAFl2IYsvneKjYWzuISTsV8UwxmXzoyatlqxlR/CAH/PZECHYbrXxWmx3ULOFEellmCIcUOr+STL9/BCBcBGa8Sskjc99goz+oVzDKySpEmjYAeL/+fd97m4nxzPpRGFgDPTDo87HcxJaWuUTVX8YMRRyALND1cL9VlLI5XMBJjhnPxfPsvNwgXDDMdkPhxkEIP3+8HAdG/ZH8NFR1FP00YRslK6uA9c3rSsUiRla/ssv8j2iHI9xGpnRMDyyN+tn9EyfojSpNQ1caXg97EgAXIYv2Z77PA== 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)(4326008)(110136004)(5660300001)(36756003)(7736002)(6916009)(2950100002)(305945005)(6666003)(66066001)(2906002)(189998001)(50226002)(50466002)(54906002)(508600001)(86362001)(6512007)(81166006)(8676002)(50986999)(53416004)(3846002)(76176999)(42186005); 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:uvDw2FGmc5r71+UgyVX0FvrcZisLmKLTFGa2oHt?= =?us-ascii?Q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Y?= =?us-ascii?Q?oJCc852TaZnb6PMPBZ5JFPRKznzuQn/awEhnV1onj0A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 6:jT/cHaUMWYUMUxwG6lSvreIJuDL69uKH2C9VHJh+u6g/ltddyXApzmKIbxqFwG40Tb877co8Lnue/rDqtawJiM/no1tzn7AFW1by5AWra6v7x/Wz0flbrdqhUlf0yQi98UkxrDPLyQXWMIGyhTYb0yT8i6QkdgDDoxq33eC9VyjWnGsQk+/71XPEbezPF4Q+6agcF9ybdGimKI2Y3y6cWZpSOHtsLt+C//vyuSn0OHIxOlqWrO5DpDAUek1KCif1n5xAUh3jjE2fjatyUgkpWrVNDEYbJv59KiIbjK5zt9gEzgK80s886KSNjkdga/FcnHO9Zw2zJjeUp6ppWQLZHobWiM11weutibOgN2aZBigmNHGuRF4/X6mQvnvIAMB8YCrRkzCkFOOOOCVQ0dpgytgTigeGDTMGO8EgB4Qd3RwkdQU79bLzJ2j9Dd+cAqEs2dqw539OnEYWpZsSLong+gJmIsmqjgR6EpRl9VH7dqaQyYOhd0LprPbQMXORlOYUQRVk/nMVxt6ciE7gCAL2mA==; 5:4P9oxCzoh+ZDJBh+JzF5nTREM+jaAWAdulIwjCk1H7w7gotqCMFIo6B8P2uQznzJ8Xg20TS1AbbeXCDOLW7rP9lpsUyN4uGbZJtUOK3of59TUw1aw4uIukCs5b/jlhstdo3JFsqSSFCJRiyTMtHtTw==; 24:2g3lGENU1w+6pOJC3Ud71uBZeY5+HkSaX5Phm+geBXVX0AR6RLv6R1HiJCyewBcCi18GyJUdgl/WBBBeF5um/RpkrX8su7rIFvkt5qXjmik= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 7:V2pSM3kZEyCRGs9OyAAHm54hiaTx8ToNk71jKw7OIdLb63B6zwZG8zrMH2cPufFWeelUpFW/Y/chylm0pxijlYs5nPwEd0CvEft7jUOcdb+ULF13NbDUunBz8kNyehVv6UdKlEI76nEz0/EY0OddBRlFAAbrq8W9UFhS2FJYmQ0sxXUiNlEiYa+xMG9QkqXtBCrTFDKvZpynVlvlivxBTsh10qrVItyQhDbRU5+kP/73m1ByZ8xCGu6PC+qwDDuIXTjNN8cviiWbw0LEvQZznSsFpHncBW42mqC6qTtPHUwKsy6OY15+UXPdKL7Cx3mkryGPKyW4WegUzJQZgmynZQ==; 20:IRjE0G8hEy2bRpZZDGwz6vOwILBokNepE6AwR5IJjiziOw60gmw8q+2eXrIFALQ6obweD4ZCZgMDhC+hocrjpI64WeHGxEPE2pu8E2j+v+gKmO3TJBJVl8MwSdg1dYl8YGnbv9xdYUgRLfJDmN9lJCGr6F1lQG6YMOtYS6GUuwY= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2017 12:47:52.2731 (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 6/9] virtio-console: chardev hotswap support 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, Amit Shah , 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 Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy CC: Amit Shah --- hw/char/virtio-console.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c index cf7331d..bd74669 100644 --- a/hw/char/virtio-console.c +++ b/hw/char/virtio-console.c @@ -49,7 +49,7 @@ static ssize_t flush_buf(VirtIOSerialPort *port, VirtConsole *vcon = VIRTIO_CONSOLE(port); ssize_t ret; - if (!qemu_chr_fe_get_driver(&vcon->chr)) { + if (!qemu_chr_fe_backend_connected(&vcon->chr)) { /* If there's no backend, we can just say we consumed all data. */ return len; } @@ -163,12 +163,35 @@ static void chr_event(void *opaque, int event) } } +static int chr_be_change(void *opaque) +{ + VirtConsole *vcon = opaque; + VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(vcon); + VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port); + + if (k->is_console) { + qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read, + NULL, chr_be_change, vcon, NULL, true); + } else { + qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read, + chr_event, chr_be_change, vcon, NULL, false); + } + + if (vcon->watch) { + g_source_remove(vcon->watch); + vcon->watch = qemu_chr_fe_add_watch(&vcon->chr, + G_IO_OUT | G_IO_HUP, + chr_write_unblocked, vcon); + } + + return 0; +} + static void virtconsole_realize(DeviceState *dev, Error **errp) { VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev); VirtConsole *vcon = VIRTIO_CONSOLE(dev); VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(dev); - Chardev *chr = qemu_chr_fe_get_driver(&vcon->chr); if (port->id == 0 && !k->is_console) { error_setg(errp, "Port number 0 on virtio-serial devices reserved " @@ -176,7 +199,7 @@ static void virtconsole_realize(DeviceState *dev, Error **errp) return; } - if (chr) { + if (qemu_chr_fe_backend_connected(&vcon->chr)) { /* * For consoles we don't block guest data transfer just * because nothing is connected - we'll just let it go @@ -188,11 +211,13 @@ 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, NULL, vcon, NULL, true); + NULL, chr_be_change, + vcon, NULL, true); virtio_serial_open(port); } else { qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read, - chr_event, NULL, vcon, NULL, false); + chr_event, chr_be_change, + vcon, NULL, false); } } }