From patchwork Tue Jun 6 10:04:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 103151 Delivered-To: patch@linaro.org Received: by 10.182.29.35 with SMTP id g3csp1186170obh; Tue, 6 Jun 2017 03:06:13 -0700 (PDT) X-Received: by 10.107.170.152 with SMTP id g24mr29438961ioj.101.1496743573542; Tue, 06 Jun 2017 03:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496743573; cv=none; d=google.com; s=arc-20160816; b=xvEjeINeG3k8cSnWqKH++wmXc2//j/KlULIHFkZ9zGCXg8EkL6v/LdUVU8/Zt2bp9f C9VhLCxJmWXUYB/48qFc32Qm28NV9usu48qgKH/6t9Z4Pcp+aCx7Eaep/opRdp6OUIa9 sZnGRqHuqtVZ+aJYYlwZK2EhPuCbVYQelO7fjRLQVyYyw6mSQbnyjRat6Nl+mx0aOY/o NEOiCLRl89vwf8IUabPAWeUlKYKAkYTHwbMaH+lE8M/DMvdVG3rWSJtorLeHaSghWk/D jLzIFjhmTQuaa3hIoAT6iIPHfKGbJRnCX788nO3C2AQldEZmvsC1Dr8t0uF39+EvOe+e tnpQ== 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:message-id:date:to:from:dkim-signature :arc-authentication-results; bh=CodEl+cYH0crgwjNNVQ3wdGamp9z8sRWlVy/2u0GkdY=; b=A7GdU2BEqiExM9ZQJ27rAtGfgV+EwWmUWZi83rGBP20sdisS5GMO7S682INtQMADO1 5Etbafr3KNdGFrZQeLM1c6I3DGWCXfwj3jHpmYHCjGqafJTrDcy09tS7flq7Y+ChI8TB IkD6nCHalsxpU+e1OJnywU4HhTAdRLWS5HcNxcLLGF/+0TpocqC5RIQLyY0gNbjCNKQv tWYiHxptCXdsDvaKrT4pY2JZVGzb9lSSkQsRa/Ei8/WtHs3ZzN/qf034DantjDMbU4bM CaoN9kcE1btRTeJkxepFcO59kcj1ByztrJkIZfVzswhVAMBkTYSVvCixyIAqDonowNAi Cwkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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 y99si8060435ioe.224.2017.06.06.03.06.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jun 2017 03:06:13 -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; 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 1dIBLd-00044S-GA; Tue, 06 Jun 2017 10:04:25 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dIBLc-00043i-3Z for xen-devel@lists.xenproject.org; Tue, 06 Jun 2017 10:04:24 +0000 Received: from [85.158.139.211] by server-16.bemta-5.messagelabs.com id 27/E3-01752-72E76395; Tue, 06 Jun 2017 10:04:23 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42K5GHpgla5anVm kwbepchbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8baHVYF+70qJrWsZm1g3GDbxcjJISQwk1Hi RhtnFyMXB4tAO7PE1wM3GUEcCYF3LBInnpxlBqmSEEiTOHXuLBuEXSFx6uJtVohuLYmjp2azg jQICexlkljVvBGom4ODTcBEYlaHBEiNiICSxL1Vk5lAapgF5jNKNE3qBRskLJApce3RQjCbRU BVYsvhBnYQm1fAW+LonqMsEMvkJG6e62SewMi3gJFhFaNGcWpRWWqRrpGZXlJRZnpGSW5iZo6 uoYGpXm5qcXFiempOYlKxXnJ+7iZGYKDUMzAw7mC8PdnvEKMkB5OSKG9tglmkEF9SfkplRmJx RnxRaU5q8SFGGQ4OJQneSTVAOcGi1PTUirTMHGDIwqQlOHiURHiVK4HSvMUFibnFmekQqVOMx hxXrqz7wsQx5cD2L0xCLHn5ealS4rwctUClAiClGaV5cINgsXSJUVZKmJeRgYFBiKcgtSg3sw RV/hWjOAejkjDvN5B7eDLzSuD2vQI6hQnoFL5LJiCnlCQipKQaGLm0r/TUJty/ta4mXiyQaVv ss0UHN8jtXaerXZYr8LHV9NzVd6syok/ptyffWMrNkt6kkNN8ke0BNyuz4psqloxIJdvnx+V4 PU30WF2aLkT7vLXzXHPub1XBkwd71pmFvD5uabF896W1th4vZS4c+HtL/PmOY70bzH56+G95/ HdeU9LPvjalSCWW4oxEQy3mouJEAEZ5dB+gAgAA X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-6.tower-206.messagelabs.com!1496743460!101846222!1 X-Originating-IP: [209.85.192.170] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 58452 invoked from network); 6 Jun 2017 10:04:21 -0000 Received: from mail-pf0-f170.google.com (HELO mail-pf0-f170.google.com) (209.85.192.170) by server-6.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 6 Jun 2017 10:04:21 -0000 Received: by mail-pf0-f170.google.com with SMTP id l89so21930506pfi.2 for ; Tue, 06 Jun 2017 03:04:21 -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; bh=VI5/9aUElqnH1iVBR8oRu+LuPZTMuBpvW44ozDvLkYI=; b=JCFjVm5p1x2FIwCTKw5uhdWQoL4o4DoPwhnFIx0+X9R8KchbZJUvBy4V7N+ic5doty gZ8CH1UK/shluHUqvHz5u3INNW5mMGDagl59J49TUs2Q0Bsr1U/KTXqkqZ5gULtFbdv9 3vFVk+B1GrdOUlxFT8bVo7acQYGgYQjEGX3M8= 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; bh=VI5/9aUElqnH1iVBR8oRu+LuPZTMuBpvW44ozDvLkYI=; b=l4wy39UQvRdveczSM8M7WZuxYX10C6gogjnfq9ArremWV3O+suUyye/eYRf/Ag0626 /fCNVY4xVTcbDnkEGgvKFM4dKFsMqqKcPK8m33I8rpYWY3ZCQioNsf7f2f98Z4kUAkRy 4Li/0l9e0tpO14OfreD64kfCRklBU4VYpWyqZ3FnGAE2EwTTimOP/IKgZ/OcVQez68o/ s2gws/Z9FPilfOFK+m+3et+vcmVQ6aTBQobThNxq4KXWZSWaPmEAotFTmBVajOVztVEU qnLrMBSlplXzE/68XzYj3fi2S9LvATAkDQ60EmR5M1tAPEHeXYrstINuH3HxtEzVMJpI kbFA== X-Gm-Message-State: AODbwcBS4Gz5xvR8GE0qiNS4h4smFY/5CyE9M9NG+IrdMdEXCoXonGps d5EIaH9sl5AW817VaS3vmw== X-Received: by 10.84.151.99 with SMTP id i90mr1110866pli.81.1496743459363; Tue, 06 Jun 2017 03:04:19 -0700 (PDT) Received: from blr-ubuntu-linaro.wlan.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id y2sm62354114pfa.65.2017.06.06.03.04.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Jun 2017 03:04:18 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Tue, 6 Jun 2017 15:34:13 +0530 Message-Id: <1496743453-15887-1-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 Cc: Wei Liu , Julien Grall , Stefano Stabellini , Ian Jackson Subject: [Xen-devel] [PATCH 09/14 v4] 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 --- Changes since v3: - The changes in xenconsole have been split into four patches. This is the second patch. tools/console/daemon/io.c | 82 +++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 0402ddf..c5dd08d 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->conspath, "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(dom->xce_handle); dom->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->conspath, domid_str); if (success) - domain_create_ring(dom); + console_create_ring(con); else xs_unwatch(xs, con->conspath, domid_str); } else { @@ -694,6 +691,7 @@ static struct domain *create_domain(int domid) con->master_pollfd_idx = -1; con->slave_fd = -1; con->log_fd = -1; + con->d = dom; dom->xce_pollfd_idx = -1; dom->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); @@ -764,9 +762,11 @@ static void cleanup_domain(struct domain *d) static void shutdown_domain(struct domain *d) { + struct console *con = &d->console; + d->is_dead = true; watch_domain(d, false); - domain_unmap_interface(d); + console_unmap_interface(con); if (d->xce_handle != NULL) xenevtchn_close(d->xce_handle); d->xce_handle = NULL; @@ -797,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; @@ -814,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; @@ -851,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++) { @@ -862,15 +861,15 @@ static void handle_tty_read(struct domain *dom) intf->in_prod = prod; xenevtchn_notify(dom->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; @@ -880,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); } @@ -889,6 +888,7 @@ static void handle_tty_write(struct domain *dom) static void handle_ring_read(struct domain *dom) { xenevtchn_port_or_error_t port; + struct console *con = &dom->console; if (dom->is_dead) return; @@ -898,7 +898,7 @@ static void handle_ring_read(struct domain *dom) dom->event_count++; - buffer_append(dom); + buffer_append(con); if (dom->event_count < RATE_LIMIT_ALLOWANCE) (void)xenevtchn_unmask(dom->xce_handle, port); @@ -922,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); @@ -972,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); } } @@ -1118,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)) @@ -1201,15 +1201,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); } }