From patchwork Fri Aug 8 17:07:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 35150 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 843092118A for ; Fri, 8 Aug 2014 17:10:45 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id g18sf23809182oah.6 for ; Fri, 08 Aug 2014 10:10:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=3sOoemwTP+j9qvPN6zvHsl87NMFsMZsYjqfkk290tBw=; b=GGfbC0dCACe9vffQbuhJDrcVvczOm/9VMj1BTjYcfw4d8Pl0GCkejhnFoZQR/xMY+m t+FnAWSlcY+LKb0QeYZrhQCwgRSAybaEFJgEyPCgBIxu2KwdJrrgusWnzRknrsEb+KJL Y/trZMS/WnOkJAXX0osOPe82mBPGgTBl4rZAtIU8WGhzpgnny1khEMEZK+F6LKzf532s CM32HV/pWqeM77BvcZQiPJCszpDCPInLytFZpisSHdEDfEEiI58fCKsJKbaGEyszXGaV hFDIlhSmLiX/AD/bI3s3ucw+6N0mj2CiBMW5zcsXjMI4BxJPGasg78o12yeGldrgXkc8 YA7g== X-Gm-Message-State: ALoCoQkAlO/sahJAAe5oDIBZ90K3y+RECvy4i7PMxcUItOHxNty4kNkjLmQRIqzHKNDAD/kNqtfb X-Received: by 10.182.130.168 with SMTP id of8mr4193921obb.27.1407517845146; Fri, 08 Aug 2014 10:10:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.87.9 with SMTP id q9ls586099qgd.5.gmail; Fri, 08 Aug 2014 10:10:45 -0700 (PDT) X-Received: by 10.52.97.233 with SMTP id ed9mr7688676vdb.16.1407517845042; Fri, 08 Aug 2014 10:10:45 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id xs2si3091843vdc.22.2014.08.08.10.10.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 08 Aug 2014 10:10:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so8811798vcb.33 for ; Fri, 08 Aug 2014 10:10:45 -0700 (PDT) X-Received: by 10.52.127.5 with SMTP id nc5mr1538021vdb.59.1407517844958; Fri, 08 Aug 2014 10:10:44 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp140071vcb; Fri, 8 Aug 2014 10:10:44 -0700 (PDT) X-Received: by 10.140.81.134 with SMTP id f6mr24911323qgd.60.1407517844493; Fri, 08 Aug 2014 10:10:44 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j8si11023405qab.100.2014.08.08.10.10.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 08 Aug 2014 10:10:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:52060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFngh-0005jV-QM for patch@linaro.org; Fri, 08 Aug 2014 13:10:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFnfn-0004mQ-67 for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:09:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFnfl-0004SB-Rg for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:09:47 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48947) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFnfl-0004S7-Hf for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:09:45 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1XFndZ-0002w5-HE; Fri, 08 Aug 2014 18:07:29 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 8 Aug 2014 18:07:26 +0100 Message-Id: <1407517649-11257-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1407517649-11257-1-git-send-email-peter.maydell@linaro.org> References: <1407517649-11257-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: Paolo Bonzini , Gerd Hoffmann , Markus Armbruster Subject: [Qemu-devel] [PATCH 1/4] qemu-char: Convert socket char backend to parse/kind X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Convert the socket char backend to the new style QAPI framework; this allows it to return an Error ** to callers who might not want it to print directly about socket failures. Signed-off-by: Peter Maydell --- qemu-char.c | 114 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 58 insertions(+), 56 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 6964a2d..cac7edb 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2983,61 +2983,6 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay, return chr; } -static CharDriverState *qemu_chr_open_socket(QemuOpts *opts) -{ - CharDriverState *chr = NULL; - Error *local_err = NULL; - int fd = -1; - - bool is_listen = qemu_opt_get_bool(opts, "server", false); - bool is_waitconnect = is_listen && qemu_opt_get_bool(opts, "wait", true); - bool is_telnet = qemu_opt_get_bool(opts, "telnet", false); - bool do_nodelay = !qemu_opt_get_bool(opts, "delay", true); - bool is_unix = qemu_opt_get(opts, "path") != NULL; - - if (is_unix) { - if (is_listen) { - fd = unix_listen_opts(opts, &local_err); - } else { - fd = unix_connect_opts(opts, &local_err, NULL, NULL); - } - } else { - if (is_listen) { - fd = inet_listen_opts(opts, 0, &local_err); - } else { - fd = inet_connect_opts(opts, &local_err, NULL, NULL); - } - } - if (fd < 0) { - goto fail; - } - - if (!is_waitconnect) - qemu_set_nonblock(fd); - - chr = qemu_chr_open_socket_fd(fd, do_nodelay, is_listen, is_telnet, - is_waitconnect, &local_err); - if (local_err) { - goto fail; - } - return chr; - - - fail: - if (local_err) { - qerror_report_err(local_err); - error_free(local_err); - } - if (fd >= 0) { - closesocket(fd); - } - if (chr) { - g_free(chr->opaque); - g_free(chr); - } - return NULL; -} - /*********************************************************/ /* Ring buffer chardev */ @@ -3448,6 +3393,62 @@ static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend, backend->mux->chardev = g_strdup(chardev); } +static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, + Error **errp) +{ + bool is_listen = qemu_opt_get_bool(opts, "server", false); + bool is_waitconnect = is_listen && qemu_opt_get_bool(opts, "wait", true); + bool is_telnet = qemu_opt_get_bool(opts, "telnet", false); + bool do_nodelay = !qemu_opt_get_bool(opts, "delay", true); + const char *path = qemu_opt_get(opts, "path"); + const char *host = qemu_opt_get(opts, "host"); + const char *port = qemu_opt_get(opts, "port"); + SocketAddress *addr; + + if (!path) { + if (!host) { + error_setg(errp, "chardev: socket: no host given"); + return; + } + if (!port) { + error_setg(errp, "chardev: socket: no port given"); + return; + } + } + + backend->socket = g_new0(ChardevSocket, 1); + + backend->socket->has_nodelay = true; + backend->socket->nodelay = do_nodelay; + backend->socket->has_server = true; + backend->socket->server = is_listen; + backend->socket->has_telnet = true; + backend->socket->telnet = is_telnet; + backend->socket->has_wait = true; + backend->socket->wait = is_waitconnect; + + addr = g_new0(SocketAddress, 1); + if (path) { + addr->kind = SOCKET_ADDRESS_KIND_UNIX; + addr->q_unix = g_new0(UnixSocketAddress, 1); + addr->q_unix->path = g_strdup(path); + } else { + addr->kind = SOCKET_ADDRESS_KIND_INET; + addr->inet = g_new0(InetSocketAddress, 1); + addr->inet->host = g_strdup(host); + addr->inet->port = g_strdup(port); + addr->inet->to = qemu_opt_get_number(opts, "to", 0); + addr->inet->has_to = true; + if (qemu_opt_get_bool(opts, "ipv4", 0)) { + addr->inet->has_ipv4 = addr->inet->ipv4 = true; + } + if (qemu_opt_get_bool(opts, "ipv6", 0)) { + addr->inet->has_ipv6 = addr->inet->ipv6 = true; + } + } + backend->socket->addr = addr; +} + typedef struct CharDriver { const char *name; /* old, pre qapi */ @@ -4136,7 +4137,8 @@ void qmp_chardev_remove(const char *id, Error **errp) static void register_types(void) { register_char_driver_qapi("null", CHARDEV_BACKEND_KIND_NULL, NULL); - register_char_driver("socket", qemu_chr_open_socket); + register_char_driver_qapi("socket", CHARDEV_BACKEND_KIND_SOCKET, + qemu_chr_parse_socket); register_char_driver("udp", qemu_chr_open_udp); register_char_driver_qapi("ringbuf", CHARDEV_BACKEND_KIND_RINGBUF, qemu_chr_parse_ringbuf);