From patchwork Fri Jun 20 20:55:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 32298 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7E78F203F4 for ; Fri, 20 Jun 2014 20:56:01 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id y10sf13457731pdj.9 for ; Fri, 20 Jun 2014 13:56:00 -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:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=riGXkJE04jYzfgmlWHrC5xDs5rVI4d0j8lZLcDjY2IY=; b=ML36Ae3ArxnLWbPaXad6ixBMln6uLqHqxx7FdeepvnP7f3MExNozReQf3w/+tcBok4 iECf74b2fAU4V3v+UfLskp46umhBJnyakIRIcfMWqSzTnL/OfoKmFSE7o7ZFh5pSsQrC NaB3hvWQo2dcPLf8oOAG0W0RjlSQ8/HECB3MYIH7yAwdn6eUgPEOMhrmsc4QBaI4dPQp vKA46A5ReICX9J8W7h2YNBA6eiMMBn2QnNORiBKDvsYvPz33jM0dIbgZBd/H/CmPPT38 aTqr824L4aYP6A3ZAu7xBE/zGuyE8F9PedbP54vmDqdHeSDCIujnlKoize8aWD0Cnf9C IW5A== X-Gm-Message-State: ALoCoQmn7nf2LQi70CYf2CGm5GzuS4vBH0hI+HeuXphRls4JI0vVXHYwJ7djHWS8XLFHk64i9Rye X-Received: by 10.66.142.9 with SMTP id rs9mr2492830pab.47.1403297760711; Fri, 20 Jun 2014 13:56:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.16.107 with SMTP id 98ls1128721qga.80.gmail; Fri, 20 Jun 2014 13:56:00 -0700 (PDT) X-Received: by 10.221.44.73 with SMTP id uf9mr4985430vcb.9.1403297760548; Fri, 20 Jun 2014 13:56:00 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id w15si4771281vcq.9.2014.06.20.13.56.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 13:56:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id oy12so4070734veb.13 for ; Fri, 20 Jun 2014 13:56:00 -0700 (PDT) X-Received: by 10.220.166.9 with SMTP id k9mr4949917vcy.20.1403297760409; Fri, 20 Jun 2014 13:56:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp50036vcb; Fri, 20 Jun 2014 13:55:59 -0700 (PDT) X-Received: by 10.180.198.44 with SMTP id iz12mr6838264wic.49.1403297759512; Fri, 20 Jun 2014 13:55:59 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id dc5si4087477wib.85.2014.06.20.13.55.59 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 20 Jun 2014 13:55:59 -0700 (PDT) Received-SPF: none (google.com: pm215@archaic.org.uk does not designate permitted sender hosts) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Wy5qh-0002hs-C4; Fri, 20 Jun 2014 21:55:51 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Luiz Capitulino , Michael Roth , Anthony Liguori , Paolo Bonzini Subject: [PATCH] qemu-char: Convert socket char backend to parse/kind Date: Fri, 20 Jun 2014 21:55:51 +0100 Message-Id: <1403297751-10379-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 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.128.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- I'm not 100% sure I have this correct -- review from somebody who understands the char backends appreciated! Notes: * I haven't tested this terribly much... * The old qemu_chr_open_socket() has an "if (!is_waitconnect) qemu_set_nonblock(fd); which the QMP char-open codepath has never had. Does this matter? Which of the two code paths was correct? (I needed this because I wanted to be able to programmatically create a char backend and not have it spew the error message to stderr if the port was in use...) qemu-char.c | 113 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index b3bd3b5..39c7b9c 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2923,61 +2923,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 */ @@ -3384,6 +3329,61 @@ 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->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 */ @@ -4064,7 +4064,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);