From patchwork Fri May 19 12:47:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9737135 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 D5B006034C for ; Fri, 19 May 2017 12:50:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B7128929 for ; Fri, 19 May 2017 12:50:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB7E328933; Fri, 19 May 2017 12:50:55 +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 1AFD228929 for ; Fri, 19 May 2017 12:50:54 +0000 (UTC) Received: from localhost ([::1]:58629 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBhMs-0001pa-6a for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 May 2017 08:50:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBhJy-0000Xz-9B for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBhJw-0004FK-4B for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:54 -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 1dBhJv-0004AG-Ov for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:52 -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=UhvU1apdCfYfMNo5O6Zj2jij02xMqhWYjidx+HySIgA=; b=CJtKnZMwACGnj48Ox2njvL8PoJl5lcfprFU8MYT9TZh8bK6/tCf8DTHeBs6T9/fxl4npfy8xjgj8l5rpOQa7W2Ze16DAThrE4GDvF571emR+E4NYrdcHL6mczCOKKVJt6zRciwlTWsNXZgtq0f+AETmrpaOFu/mm7T6ShCWydL0= 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:45 +0000 From: Anton Nefedov To: Date: Fri, 19 May 2017 15:47:14 +0300 Message-ID: <1495198042-124203-2-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: 6335d026-3fce-4dc9-c0f3-08d49eb53f67 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:DB6PR0801MB1989; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 3:XNS8Srsao2BCZThDnSxmKyjkjqLzDpbHf1uVLUalLHVcvRPN6tj54rqA9ziZza6yO0EHnNldFvr67NEgTwSefjlyO1aPewj4waXKrsor4woz+bYBqBGREhNHeRACnnXjcb/0QGuS5FxZTQtoSii+eBcULXFs1X4Y0zVdA+f6MjTelLrBaGN204sdXkahitP8ZXX/U0P7u1wDPqTx/8rgsBGe3f6A6Hv3SfTmwCZwBkCIcAABTe8kfzPOo0FfEGQFfy4+3PZ4xUG00Jvm0lbb/sihoKaWECfS6uV2j+FNon4NvhQx3cDVSSZvBRdKupHVKOfOu9fmoyOlbe02z6+dnQ==; 25:D8ShdVXTx+JJfkRIUs/weIL3o+G3KHp8E8kJN+aAN8exizyna02CzaWVPmOLzmtwACMDlHbVxInhv2shSPrWhRPWrnqUrraRqVXoCMgGef24LjPu7AA1mTpro9lf3utUVTFel1bfFpK/4iN8FLwVVdbBlVsXS497WOCB5Zr7sdtVgY+zydEt7+/IigNmflMPCabktBWd9Oz9Drudvw6J61trJCsLK1leFq8BMtkFZiXj67jVZxGmkNqhBuYreYJ+ac7PiGyjlb/yAKR5JTiIV4m/mAFOdQW6w0HXEb/T7zOFBMJUJaqEngb0X7+MPpUuB03PFdFPOUHfAKScs6nm+tWN3adgce+4EwvS6JAJtKeWWHkA+ppO5DROf2HTUS4zOAluBUFvo5/DXHwPUtg748C8VU8pa1SfDEDmpA75bBrZ1KDvveZdTz8aozaB325hwYgbC/XlYTLOxy+ZKD0wqmAesfe/o7VrixaIQPHLP4g= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 31:EjLwNsCiW1yVC99vvvFhxcgrK/J9pF3UP/UeMNrqtwxxWa62Z29qYDXYD+KPxE/bWY+2x4VJBtGj2IWELcSWRVhpVjso7qS81ROyKDh9SkxQeFX1gF+uXLRHd2DGStB6x2Qxl2FGfdNvCQ0K5QYadleuw93ePQbpJK+RKRBedsL++0DIki3Qjh3O5tczUUfapkRbVVqkwKSfKjeFeUZ2sPMQXVnIczWuYn17XxcMpqc=; 20:+lp3BiuR0fJ+xdV/O6HTR727PUZ7xvSlnc+SoTkbcH47GNfclMjHVZnG2Ww0v2EKJrhfWugjO/wK31UCNh/UZ3PdM+K8NNms0Sn9XIBkQyjenNPwmiZwoJj8vNc34PXXVsTlm3yN9Gk1rTpEr5upCoQ/HA7RlNln2QM+zJGhjSkOQQfseBsWvn7yHfx018JtzLox+kw06tA/tV/PtT/89QV0LwSS/KatnRrbu+DnY34W23I4FU/a8XyFVYIfXmy5e7w5X3ATcoX7Unohffyos0/sFm6lYr8DcgRpc8hTCDoqsnk85m32byPKMsl9p/xjaT7k4er5SQWIiY0wn/odsKiA6peS8yM3rS+4xn/WieOyNpGD8NkJqJ6LFAlgYaHXOa3Zi1FmxTzCMSqJZo6ld8oaQ9L4bJdzbINNTlJFs0M= 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:arWOlsCLEj1X+UZLBfv0fgu0KoEXygCXH7KgFhdwGb/QL6BaUS32aCt8FsKio6GSVHLdW5uQ2BfU8kS98gUk63jY+lhmvJhTF6nxrbvyVTBMljuEQV1QHu9psw4Ydaz0piHZ3H3aCmH2W8SXZwaNm9UfmEy6t/3evBLCSdQAEPhNmgH2sLZz9bbS1AH/r2ZF+ChBUDK+kRGDviMqb2ScdlVgkK3CKdtAKtlaGXQP3YsdSU1jAewyGLN76eKMkmd3QKN56pqmiboDEKBCyl/ubDNEfIi29aeLYBYZq40oUPObrPSzFP0Wo4domVkIhNRcOpqnSrG3s9uy2kqN3YW9hwAXSshbAvUvJuvcp+qwefEklitUd/xcygfnnYl0lXvuDl9jGHuA5CXcaN0Qsrkqeta39WCnBHHMOn1LxKUog1isOIPnx4Tgp35gxSt1Fa7QhVe0jM9YQAiqXe0bBIsRJVE6DefPq5Po72vb1kBnYuBEk+oQ/2u+Y7YSSfDaJVzMdn9FhCAeQL/rBPTdTyLZmM3ocv4usSUOtEDsTBdB78xyAzEjdkISzWBC7oHWn881xsCHaebSo1c4414/l9ZOwFncgPItZ/t9xFH0zUyT7C63FQvwiZO7rHlq1vuxd8GSOEC7yQRGLZjh9GeZCwaDnKCx677kMGhAjEKJGhe1cFJizjCNOnWjJV4qsFiidfUnR7Hsni/yOzX+vmj7dpoaqA== 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)(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:X9fVBLwKXfMdjdsR/HHkDNuA/Oi3siL5vjOQHQS?= =?us-ascii?Q?9gd4vL4oyAiAy7uI2t/gYIQkfVzukCwEzhVracZK0CcjRrKr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wlXKH68f855ilFaHKqROQzbv483MX2fo6VFk1zZp1C?= =?us-ascii?Q?/mco=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 6:i8WHNi30Ev6qxCAKKDS98vBbWYuHcNdN1R2vxFCgKpXrUdrgQ1sCdl4w2gAzsiM0qifSTbpQa8DVLqp3y5w6ZfW3qjR1U98KbuxKik0CQ+eptYOcLrfk02bvLBOIkY88HY6iKO4On2TPhsV/hUfYKcKJ/k43C1Y6+F24Iwvn7IAWrX5UcrcrKfUDfz8/LH4+1i6G40kOa/xyZ0F2qHMvh/Fc0XDrfFfmH6JoYOaXqEWS89SgIwenEiAQhTruRvAzlAJWFcJ9wBRkBEkr2AEc+CsE7AxaII3ij8qZYEcVAIHgyx8/CZGOXQlw0I9f3IrpwlfPV3HW2ecwq7izRoXGrzYYH1y3THRcz8BtGqXmjElU6QYxiCT9a9NKJu7UjWYts7C3vC6kWoti4FMARBq4xKdH7j5Py+nAqlN6lYjekFHX0XH6Iy7xv98BfN6IqFHZpECRTmOR0JCPE81ZeKpA0GI/wI767bB7jxvE/FI+H+tWjE+i2UARCm8WVt+KQnr/NBWVvw9pCRFdrj1qa46IgA==; 5:RAeJ9/lUoCpoTN6M5/ichrELIyRqYOX0AuLNYoiYGoHUPK5F0XX2OKgwI8a9qxXovWUpkz3CJPe95m8wER/mEJtf7Az+ohKcrQiFQxETQLdMexB5sYaeW2PRmPzMr3sllHRo7ShANfft3dKJeujCOg==; 24:dLqUIUKBFKN866Uv4r5KcrdQOEEQj9vj5UFSIq5YaNbm2dXgnXvR+RnOzgENOeYRBLgV5JTl1YwQzTaNN9otewpE0JxUm939WHuop6X92Oc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 7:8c4M/N52SgtzhxEmE5LETl6iiqLCXS4J4lcdmJvUm4W/TRt1ewIYDyT791G3OI1Ebt3Y2/YLu+vSIk4XxCC5BgadzDNe4fVUmiB/CBeBfULjuJDzdIsLZ5l6ijUjNj/ZE8YtxkymYNGtqhC8Od0DYuC6PIKbvyAabucihPGUOQb3NMYj4DOAXspRxZf7x+eN9Cj8fkO1Yx/zHoPMdlybZdiUK25pN6Rn9nwvK5NAi5gdh7WbaY2lUbkxGIMbhZ3pwMGqCWFMLAxbVnxt3G9A+hwH+a0tYSVO+jFFi9jj5AM87+er7GzU1gqju8FI2SAcrJHDZFAs0/sAU9d3DV86VA==; 20:laWZuzHtWHO7bpNno6GJNMCLa/41cKpnLb4PBy5Vso4qgj4WqdDmY/WWCpPjRA6MZkQdYFXWHgkcFnZKNUTOyp6Jp6f8CDbUD5I1USiaKKuXOYCOqGu6cjbPv3PzovNarzM0Ca8MojWThw6zd5i1fzFnt7rmqljFd48u+NRGTqA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2017 12:47:45.1592 (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 1/9] char: move QemuOpts->ChardevBackend translation to a separate func 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 Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy --- chardev/char.c | 72 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index 4e24dc3..684cccd 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -854,17 +854,14 @@ help_string_append(const char *name, void *opaque) g_string_append_printf(str, "\n%s", name); } -Chardev *qemu_chr_new_from_opts(QemuOpts *opts, - Error **errp) +static ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, + Error **errp) { Error *local_err = NULL; const ChardevClass *cc; - Chardev *chr; int i; ChardevBackend *backend = NULL; const char *name = qemu_opt_get(opts, "backend"); - const char *id = qemu_opts_id(opts); - char *bid = NULL; if (name == NULL) { error_setg(errp, "chardev: \"%s\" missing backend", @@ -872,21 +869,6 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, return NULL; } - if (is_help_option(name)) { - GString *str = g_string_new(""); - - chardev_name_foreach(help_string_append, str); - - error_report("Available chardev backend types: %s", str->str); - g_string_free(str, true); - exit(0); - } - - if (id == NULL) { - error_setg(errp, "chardev: no id specified"); - return NULL; - } - for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) { if (g_strcmp0(chardev_alias_table[i].alias, name) == 0) { name = chardev_alias_table[i].typename; @@ -902,16 +884,12 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, backend = g_new0(ChardevBackend, 1); backend->type = CHARDEV_BACKEND_KIND_NULL; - if (qemu_opt_get_bool(opts, "mux", 0)) { - bid = g_strdup_printf("%s-base", id); - } - - chr = NULL; if (cc->parse) { cc->parse(opts, backend, &local_err); if (local_err) { error_propagate(errp, local_err); - goto out; + qapi_free_ChardevBackend(backend); + return NULL; } } else { ChardevCommon *ccom = g_new0(ChardevCommon, 1); @@ -919,6 +897,48 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, backend->u.null.data = ccom; /* Any ChardevCommon member would work */ } + return backend; +} + +Chardev *qemu_chr_new_from_opts(QemuOpts *opts, + Error **errp) +{ + const ChardevClass *cc; + Chardev *chr = NULL; + ChardevBackend *backend = NULL; + const char *name = qemu_opt_get(opts, "backend"); + const char *id = qemu_opts_id(opts); + char *bid = NULL; + + if (name && is_help_option(name)) { + GString *str = g_string_new(""); + + chardev_name_foreach(help_string_append, str); + + error_report("Available chardev backend types: %s", str->str); + g_string_free(str, true); + exit(0); + } + + if (id == NULL) { + error_setg(errp, "chardev: no id specified"); + return NULL; + } + + backend = qemu_chr_parse_opts(opts, errp); + if (backend == NULL) { + return NULL; + } + + cc = char_get_class(name, errp); + if (cc == NULL) { + goto out; + } + + if (qemu_opt_get_bool(opts, "mux", 0)) { + bid = g_strdup_printf("%s-base", id); + } + chr = qemu_chardev_new(bid ? bid : id, object_class_get_name(OBJECT_CLASS(cc)), backend, errp);