Skip to contentSkip to conversation

Improvements for xenconsoled

PATCH New Andrew Cooper 1 participant 4 messages Jul 22, 2014

lore
Share & tools
lore
#0 lore raw

cover Improvements for xenconsoled

These are three largly independent improvements from xenconsoled when attempting to use it to do Xen console logging.

Andrew Cooper (3):
tools/xenconsoled: Newline on 'Logfile Opened' messages tools/xenconsoled: Possibly perform repeated xc_readconsolering()
hypercalls
tools/xenconsoled: Log Xen boot messages at startup.

 tools/console/daemon/io.c |   36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 tools/xenconsoled: Newline on 'Logfile Opened' messages

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
---
 tools/console/daemon/io.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/console/daemon/io.c +4 -4
index 46719a8..313b256 100644
@@ -276,8 +276,8 @@ static int create_hv_log(void)
 		dolog(LOG_ERR, "Failed to open log %s: %d (%s)",
 		      logfile, errno, strerror(errno));
 	if (fd != -1 && log_time_hv) {
-		if (write_with_timestamp(fd, "Logfile Opened",
-					 strlen("Logfile Opened"),
+		if (write_with_timestamp(fd, "Logfile Opened\n",
+					 strlen("Logfile Opened\n"),
 					 &log_time_hv_needts) < 0) {
 			dolog(LOG_ERR, "Failed to log opening timestamp "
 				       "in %s: %d (%s)", logfile, errno,
@@ -322,8 +322,8 @@ static int create_domain_log(struct domain *dom)
 		dolog(LOG_ERR, "Failed to open log %s: %d (%s)",
 		      logfile, errno, strerror(errno));
 	if (fd != -1 && log_time_guest) {
-		if (write_with_timestamp(fd, "Logfile Opened",
-					 strlen("Logfile Opened"),
+		if (write_with_timestamp(fd, "Logfile Opened\n",
+					 strlen("Logfile Opened\n"),
 					 &log_time_guest_needts) < 0) {
 			dolog(LOG_ERR, "Failed to log opening timestamp "
 				       "in %s: %d (%s)", logfile, errno,
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/3 tools/xenconsoled: Possibly perform repeated xc_readconsolering() hypercalls

In reply to Andrew Cooper

The size of the Xen console ring is runtime configurable, so the statically sized 16k buffer is not necessarily sufficient. Make repeated xc_readconsolering() hypercalls while Xen managed to completely fill the provided buffer.

Also, change the buffer to being static to save on stack space.

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
---
 tools/console/daemon/io.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
tools/console/daemon/io.c +11 -4
index 313b256..b1268fa 100644
@@ -909,17 +909,24 @@ static void handle_xs(void)
 
 static void handle_hv_logs(xc_evtchn *xce_handle)
 {
-	char buffer[1024*16];
+	static char buffer[1024*16];
 	char *bufptr = buffer;
-	unsigned int size = sizeof(buffer);
+	unsigned int size;
 	static uint32_t index = 0;
 	evtchn_port_or_error_t port;
 
 	if ((port = xc_evtchn_pending(xce_handle)) == -1)
 		return;
 
-	if (xc_readconsolering(xc, bufptr, &size, 0, 1, &index) == 0 && size > 0) {
+	do
+	{
 		int logret;
+
+		size = sizeof(buffer);
+		if (xc_readconsolering(xc, bufptr, &size, 0, 1, &index) != 0 ||
+		    size == 0)
+			break;
+
 		if (log_time_hv)
 			logret = write_with_timestamp(log_hv_fd, buffer, size,
 						      &log_time_hv_needts);
@@ -929,7 +936,7 @@ static void handle_hv_logs(xc_evtchn *xce_handle)
 		if (logret < 0)
 			dolog(LOG_ERR, "Failed to write hypervisor log: "
 				       "%d (%s)", errno, strerror(errno));
-	}
+	} while (size == sizeof(buffer));
 
 	(void)xc_evtchn_unmask(xce_handle, port);
 }
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/3 tools/xenconsoled: Log Xen boot messages at startup.

In reply to Andrew Cooper

When xenconsoled starts, there will be log lines in the Xen console ring from boot, even though VIRQ_CON_RING is not yet pending.

Add a force option to handle_hv_logs() which bypasses the event channel check, allowing xenconsoled to drain the Xen boot messages when it starts, rather than at the first subsequent time that VIRQ_CON_RING becomes set.

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
---
 tools/console/daemon/io.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
tools/console/daemon/io.c +8 -5
index b1268fa..ac08b5b 100644
@@ -907,15 +907,15 @@ static void handle_xs(void)
 	free(vec);
 }
 
-static void handle_hv_logs(xc_evtchn *xce_handle)
+static void handle_hv_logs(xc_evtchn *xce_handle, bool force)
 {
 	static char buffer[1024*16];
 	char *bufptr = buffer;
 	unsigned int size;
 	static uint32_t index = 0;
-	evtchn_port_or_error_t port;
+	evtchn_port_or_error_t port = -1;
 
-	if ((port = xc_evtchn_pending(xce_handle)) == -1)
+	if (!force && ((port = xc_evtchn_pending(xce_handle)) == -1))
 		return;
 
 	do
@@ -938,7 +938,8 @@ static void handle_hv_logs(xc_evtchn *xce_handle)
 				       "%d (%s)", errno, strerror(errno));
 	} while (size == sizeof(buffer));
 
-	(void)xc_evtchn_unmask(xce_handle, port);
+	if (port != -1)
+		(void)xc_evtchn_unmask(xce_handle, port);
 }
 
 static void handle_log_reload(void)
@@ -1024,6 +1025,8 @@ void handle_io(void)
 			      "%d (%s)", errno, strerror(errno));
 			goto out;
 		}
+		/* Log the boot dmesg even if VIRQ_CON_RING isn't pending. */
+		handle_hv_logs(xce_handle, true);
 	}
 
 	xcg_handle = xc_gnttab_open(NULL, 0);
@@ -1134,7 +1137,7 @@ void handle_io(void)
 				      errno, strerror(errno));
 				break;
 			} else if (fds[xce_pollfd_idx].revents & POLLIN)
-				handle_hv_logs(xce_handle);
+				handle_hv_logs(xce_handle, false);
 
 			xce_pollfd_idx = -1;
 		}
Signature · 1 line
1.7.10.4