From patchwork Mon Aug 7 08:53:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 109540 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp2482164obb; Mon, 7 Aug 2017 01:56:06 -0700 (PDT) X-Received: by 10.107.20.215 with SMTP id 206mr11159276iou.163.1502096166027; Mon, 07 Aug 2017 01:56:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502096166; cv=none; d=google.com; s=arc-20160816; b=f1JWd8C7jA7Tj2UFMbtRWCvFEh0TBQmE04eqkXxgAS5zLUCFuIRsav6dIWywCCFZLE YwX2TahOCtJqeAE0sBJSkZlzOk+JkAURdqObVAM/im1flIU/oUsI0385Y81+2Bqn1tNz WLW+VymKsN4oXd/5bwHunrM3K1TKXVg+FpTtQEjdi28BBu8IthQCAeDWGat/X3UXdQKv XtP0oD76hUrSD6DRWRKARNQQNis4T7IJ2LjOxIuDU7qtrpkN2uzkIDt1DCd7C68FkN9q VR9v5QnJCPCZPmbXyoGv1fkoIhcaL9udefuS07uy04v3d/akGxV+fVILWaF6d7OZFMea AInQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=WXsVKFtSEvooh/gQViJFmbABTRKBe0u52bhIWXyD934=; b=Nr5Y9aLYSXWTgYB0/DeJ3BvoqWysdcFefoxPlSIcKSWfuY4n9uAud2gwdT/AD18KQq V4enXhrK18GS6PRW9cYlqrEbKRd99+ijkThyqFlz6Si9eWDdEzsN1OdKCect4MXxJ5du l8RGkIpUtX5kgOqAUl11hZXMrzhcPFPcoZ8oGfNA2X9tkXgu92sV/pN9b/RfmLVVqbMF qdN3ue9c6+00PqTSXD0prIzLWNuIX67cDNNKgh2kX+K1Jfoh5RpZuVdEwN5iXGA4so7y zTsrjTo5qz+RLsGFcXqHSwb0r6zjIXnLPzO4fuDUWzubp5CGo27ky7gmDGDRP1atPjiy 3UsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KICTwXQv; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 71si8197016itf.139.2017.08.07.01.56.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Aug 2017 01:56:06 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KICTwXQv; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dednW-0004Yq-FZ; Mon, 07 Aug 2017 08:54:02 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dednV-0004XE-Df for xen-devel@lists.xenproject.org; Mon, 07 Aug 2017 08:54:01 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id DC/C4-01862-8AA28895; Mon, 07 Aug 2017 08:54:00 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRWlGSWpSXmKPExsXiVRusp7tcqyP S4Od2bYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNaPhxFnmgreeFV2HdjA2MP616WLk4hASmM4o cbfnHAuIwyIwj1niwL/JYI6EQD+rxLTbLYxdjJxATprEmafH2SHsSok5y2+C2UICWhJHT81mh RjVxiSxrfUTcxcjBwebgInErA4JkBoRASWJe6smM4HUMAvMZ5RomtTLBpIQFsiU2Hj3BQuIzS KgKvF/xx8wm1fAR+LN0U4WiGVyEjfPdTKD2JxA8fOX3rBALPaWuH2sj3ECo8ACRoZVjBrFqUV lqUW6RgZ6SUWZ6RkluYmZObqGBsZ6uanFxYnpqTmJScV6yfm5mxiBwVXPwMC4g7H5hN8hRkkO JiVR3vgVbZFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHgTNDsihQSLUtNTK9Iyc4BhDpOW4OBRE uF9oQ6U5i0uSMwtzkyHSJ1iNOaYdGD7FyaOVxP+f2MSYsnLz0uVEufNAZkkAFKaUZoHNwgWf5 cYZaWEeRkZGBiEeApSi3IzS1DlXzGKczAqCfNOApnCk5lXArfvFdApTECnvElsBTmlJBEhJdX AqKJ1/b7I/7fX9FZ5H9GsEFu+VDx+/ZTlL7Tz9+b8EGNdXH3lmq9LubZCwe7J098zLOY+FTq7 qTN+DcNSRW7ppeJrX8qZHZFIy7Z5/T7NokwwQvgi8+7Henelbvicn7y1ITN2Z+Zh09WMlz9bl Ed1u/CuuC0d62mmuytg8qmyjL/HtjqzHeS7rsRSnJFoqMVcVJwIAF0YggK6AgAA X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-3.tower-31.messagelabs.com!1502096038!108865269!1 X-Originating-IP: [74.125.83.46] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29532 invoked from network); 7 Aug 2017 08:53:59 -0000 Received: from mail-pg0-f46.google.com (HELO mail-pg0-f46.google.com) (74.125.83.46) by server-3.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Aug 2017 08:53:59 -0000 Received: by mail-pg0-f46.google.com with SMTP id u5so31662233pgn.0 for ; Mon, 07 Aug 2017 01:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/c87JD9XyWkvHP2iWascyeQ5IUSzbfWQc11J8Ir9N+k=; b=KICTwXQvDR5clzqioWd2gnJw5YModWElm+Fpjhe3DaULDVqw1zbDVRP6478lDsKrRg AZuOQMn92rZaTjV8xV/KsqGvKHOWZphOtnPOml1GGkPjCyFKNyZNM3hniaxLw/JQrgh3 YLdeAlSR+/Wy/8gK7bW5IZgNMyypLoY27RMXE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/c87JD9XyWkvHP2iWascyeQ5IUSzbfWQc11J8Ir9N+k=; b=oy4kx2f06EgAAKlE955x0+MjduhktaC1pIL2jdgZEBHWY7j7SPk5MKJiUKvrLXR5fX rZGSaKgeLF6dnfI3T/aglq37yWa162yZLmM4VxdNiwvuuNx8wgFe8Q33kbjAn2vb6tUd u/iK04yeAUW++9BpSRBo1I5WV/AbfIlnfayr5oHBYElL10uCmXVidRt1YGaDjCOf4M8O 9w9CcDLph/7nAVBfVq0h/doO39PTqM1cP/57bOH9jyTARzajT+dADlzaq91qV/Q0raGc VXDK24RQhPzN/hhgSKzkzZFHUZbGbY0J/VaM6/0aSHS+3knYvW7mSUIpQbkWH775/egs iaMw== X-Gm-Message-State: AIVw112DCowa6it1jkD03FeiWM1w8wk0TQaY1UG9IZ8lrDImOlAdZJw+ wYFg8Gpi+xejiT75+GMR+A== X-Received: by 10.99.42.72 with SMTP id q69mr10895353pgq.449.1502096037782; Mon, 07 Aug 2017 01:53:57 -0700 (PDT) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([103.5.19.18]) by smtp.gmail.com with ESMTPSA id p77sm12604047pfi.153.2017.08.07.01.53.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 01:53:57 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Mon, 7 Aug 2017 14:23:02 +0530 Message-Id: <1502095997-31219-11-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502095997-31219-1-git-send-email-bhupinder.thakur@linaro.org> References: <1502095997-31219-1-git-send-email-bhupinder.thakur@linaro.org> Cc: Wei Liu , Julien Grall , Stefano Stabellini , Ian Jackson Subject: [Xen-devel] [PATCH 10/25 v7] xen/arm: vpl011: Modify xenconsole functions to take console structure as input X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" Xenconsole functions take domain structure as input. These functions shall be modified to take console structure as input since these functions typically perform console specific operations. Also the console specific functions starting with prefix "domain_" shall be modified to "console_" to indicate that these are console specific functions. This patch is in preparation to support multiple consoles to support vuart console. Signed-off-by: Bhupinder Thakur Acked-by: Stefano Stabellini Acked-by: Wei Liu --- CC: Ian Jackson CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall Changes since v3: - The changes in xenconsole have been split into multiple patches. This is the second patch. tools/console/daemon/io.c | 79 +++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 6f5c69c..a2a3496 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -163,10 +163,10 @@ static int write_with_timestamp(int fd, const char *data, size_t sz, return 0; } -static void buffer_append(struct domain *dom) +static void buffer_append(struct console *con) { - struct console *con = &dom->console; struct buffer *buffer = &con->buffer; + struct domain *dom = con->d; XENCONS_RING_IDX cons, prod, size; struct xencons_interface *intf = con->interface; @@ -296,12 +296,13 @@ static int create_hv_log(void) return fd; } -static int create_domain_log(struct domain *dom) +static int create_console_log(struct console *con) { char logfile[PATH_MAX]; char *namepath, *data, *s; int fd; unsigned int len; + struct domain *dom = con->d; namepath = xs_get_domain_path(xs, dom->domid); s = realloc(namepath, strlen(namepath) + 6); @@ -342,10 +343,8 @@ static int create_domain_log(struct domain *dom) return fd; } -static void domain_close_tty(struct domain *dom) +static void console_close_tty(struct console *con) { - struct console *con = &dom->console; - if (con->master_fd != -1) { close(con->master_fd); con->master_fd = -1; @@ -417,7 +416,7 @@ void cfmakeraw(struct termios *termios_p) } #endif /* __sun__ */ -static int domain_create_tty(struct domain *dom) +static int console_create_tty(struct console *con) { const char *slave; char *path; @@ -426,7 +425,7 @@ static int domain_create_tty(struct domain *dom) char *data; unsigned int len; struct termios term; - struct console *con = &dom->console; + struct domain *dom = con->d; assert(con->slave_fd == -1); assert(con->master_fd == -1); @@ -487,7 +486,7 @@ static int domain_create_tty(struct domain *dom) return 1; out: - domain_close_tty(dom); + console_close_tty(con); return 0; } @@ -526,10 +525,8 @@ static int xs_gather(struct xs_handle *xs, const char *dir, ...) return ret; } -static void domain_unmap_interface(struct domain *dom) +static void console_unmap_interface(struct console *con) { - struct console *con = &dom->console; - if (con->interface == NULL) return; if (xgt_handle && con->ring_ref == -1) @@ -540,11 +537,11 @@ static void domain_unmap_interface(struct domain *dom) con->ring_ref = -1; } -static int domain_create_ring(struct domain *dom) +static int console_create_ring(struct console *con) { int err, remote_port, ring_ref, rc; char *type, path[PATH_MAX]; - struct console *con = &dom->console; + struct domain *dom = con->d; err = xs_gather(xs, con->xspath, "ring-ref", "%u", &ring_ref, @@ -563,7 +560,7 @@ static int domain_create_ring(struct domain *dom) /* If using ring_ref and it has changed, remap */ if (ring_ref != con->ring_ref && con->ring_ref != -1) - domain_unmap_interface(dom); + console_unmap_interface(con); if (!con->interface && xgt_handle) { /* Prefer using grant table */ @@ -621,7 +618,7 @@ static int domain_create_ring(struct domain *dom) con->remote_port = remote_port; if (con->master_fd == -1) { - if (!domain_create_tty(dom)) { + if (!console_create_tty(con)) { err = errno; xenevtchn_close(con->xce_handle); con->xce_handle = NULL; @@ -632,7 +629,7 @@ static int domain_create_ring(struct domain *dom) } if (log_guest && (con->log_fd == -1)) - con->log_fd = create_domain_log(dom); + con->log_fd = create_console_log(con); out: return err; @@ -648,7 +645,7 @@ static bool watch_domain(struct domain *dom, bool watch) if (watch) { success = xs_watch(xs, con->xspath, domid_str); if (success) - domain_create_ring(dom); + console_create_ring(con); else xs_unwatch(xs, con->xspath, domid_str); } else { @@ -695,6 +692,7 @@ static struct domain *create_domain(int domid) con->slave_fd = -1; con->log_fd = -1; con->xce_pollfd_idx = -1; + con->d = dom; con->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD; @@ -746,7 +744,7 @@ static void cleanup_domain(struct domain *d) { struct console *con = &d->console; - domain_close_tty(d); + console_close_tty(con); if (con->log_fd != -1) { close(con->log_fd); @@ -768,7 +766,7 @@ static void shutdown_domain(struct domain *d) d->is_dead = true; watch_domain(d, false); - domain_unmap_interface(d); + console_unmap_interface(con); if (con->xce_handle != NULL) xenevtchn_close(con->xce_handle); con->xce_handle = NULL; @@ -799,9 +797,8 @@ static void enum_domains(void) } } -static int ring_free_bytes(struct domain *dom) +static int ring_free_bytes(struct console *con) { - struct console *con = &dom->console; struct xencons_interface *intf = con->interface; XENCONS_RING_IDX cons, prod, space; @@ -816,30 +813,30 @@ static int ring_free_bytes(struct domain *dom) return (sizeof(intf->in) - space); } -static void domain_handle_broken_tty(struct domain *dom, int recreate) +static void console_handle_broken_tty(struct console *con, int recreate) { - domain_close_tty(dom); + console_close_tty(con); if (recreate) { - domain_create_tty(dom); + console_create_tty(con); } else { - shutdown_domain(dom); + shutdown_domain(con->d); } } -static void handle_tty_read(struct domain *dom) +static void handle_tty_read(struct console *con) { ssize_t len = 0; char msg[80]; int i; - struct console *con = &dom->console; struct xencons_interface *intf = con->interface; + struct domain *dom = con->d; XENCONS_RING_IDX prod; if (dom->is_dead) return; - len = ring_free_bytes(dom); + len = ring_free_bytes(con); if (len == 0) return; @@ -853,7 +850,7 @@ static void handle_tty_read(struct domain *dom) * keep the slave open for the duration. */ if (len < 0) { - domain_handle_broken_tty(dom, domain_is_valid(dom->domid)); + console_handle_broken_tty(con, domain_is_valid(dom->domid)); } else if (domain_is_valid(dom->domid)) { prod = intf->in_prod; for (i = 0; i < len; i++) { @@ -864,15 +861,15 @@ static void handle_tty_read(struct domain *dom) intf->in_prod = prod; xenevtchn_notify(con->xce_handle, con->local_port); } else { - domain_close_tty(dom); + console_close_tty(con); shutdown_domain(dom); } } -static void handle_tty_write(struct domain *dom) +static void handle_tty_write(struct console *con) { ssize_t len; - struct console *con = &dom->console; + struct domain *dom = con->d; if (dom->is_dead) return; @@ -882,7 +879,7 @@ static void handle_tty_write(struct domain *dom) if (len < 1) { dolog(LOG_DEBUG, "Write failed on domain %d: %zd, %d\n", dom->domid, len, errno); - domain_handle_broken_tty(dom, domain_is_valid(dom->domid)); + console_handle_broken_tty(con, domain_is_valid(dom->domid)); } else { buffer_advance(&con->buffer, len); } @@ -901,7 +898,7 @@ static void handle_ring_read(struct domain *dom) con->event_count++; - buffer_append(dom); + buffer_append(con); if (con->event_count < RATE_LIMIT_ALLOWANCE) (void)xenevtchn_unmask(con->xce_handle, port); @@ -925,7 +922,7 @@ static void handle_xs(void) /* We may get watches firing for domains that have recently been removed, so dom may be NULL here. */ if (dom && dom->is_dead == false) - domain_create_ring(dom); + console_create_ring(&dom->console); } free(vec); @@ -975,7 +972,7 @@ static void handle_log_reload(void) if (con->log_fd != -1) close(con->log_fd); - con->log_fd = create_domain_log(d); + con->log_fd = create_console_log(con); } } @@ -1121,7 +1118,7 @@ void handle_io(void) if (con->master_fd != -1) { short events = 0; - if (!d->is_dead && ring_free_bytes(d)) + if (!d->is_dead && ring_free_bytes(con)) events |= POLLIN; if (!buffer_empty(&con->buffer)) @@ -1208,15 +1205,15 @@ void handle_io(void) if (con->master_fd != -1 && con->master_pollfd_idx != -1) { if (fds[con->master_pollfd_idx].revents & ~(POLLIN|POLLOUT|POLLPRI)) - domain_handle_broken_tty(d, + console_handle_broken_tty(con, domain_is_valid(d->domid)); else { if (fds[con->master_pollfd_idx].revents & POLLIN) - handle_tty_read(d); + handle_tty_read(con); if (fds[con->master_pollfd_idx].revents & POLLOUT) - handle_tty_write(d); + handle_tty_write(con); } }