All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 21/24] [xen-unstable.hg] utility for accessing xenstore stubdom console which doesn't use xenstore
@ 2009-03-23 15:21 Alex Zeffertt
  2009-06-10 15:22 ` Alex Zeffertt
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Zeffertt @ 2009-03-23 15:21 UTC (permalink / raw)
  To: xen-devel@lists.xensource.com

[-- Attachment #1: Type: text/plain, Size: 2 bytes --]




[-- Attachment #2: xenconsole_dump --]
[-- Type: text/plain, Size: 4405 bytes --]

This is a very dumb xenconsole backend that does not use xenstore.

Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
---

diff -r 07fb7525c9ce .hgignore
--- a/.hgignore	Thu Mar 19 17:19:07 2009 +0000
+++ b/.hgignore	Fri Mar 20 15:45:44 2009 +0000
@@ -179,6 +179,7 @@
 ^tools/misc/xc_shadow$
 ^tools/misc/xen_cpuperf$
 ^tools/misc/xen-detect$
+^tools/misc/xenconsole_dump$
 ^tools/misc/xenperf$
 ^tools/misc/xenpm$
 ^tools/pygrub/build/.*$
diff -r 07fb7525c9ce tools/misc/Makefile
--- a/tools/misc/Makefile	Thu Mar 19 17:19:07 2009 +0000
+++ b/tools/misc/Makefile	Fri Mar 20 15:45:44 2009 +0000
@@ -10,7 +10,7 @@
 
 HDRS     = $(wildcard *.h)
 
-TARGETS-y := xenperf xenpm
+TARGETS-y := xenperf xenpm xenconsole_dump
 TARGETS-$(CONFIG_X86) += xen-detect
 TARGETS := $(TARGETS-y)
 
@@ -18,7 +18,7 @@
 SUBDIRS-$(CONFIG_MINITERM) += miniterm
 SUBDIRS := $(SUBDIRS-y)
 
-INSTALL_BIN-y := xencons
+INSTALL_BIN-y := xencons xenconsole_dump
 INSTALL_BIN-$(CONFIG_X86) += xen-detect
 INSTALL_BIN := $(INSTALL_BIN-y)
 
@@ -56,4 +56,7 @@
 xenperf xenpm: %: %.o Makefile
 	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDFLAGS_libxenctrl)
 
+xenconsole_dump: %: %.o Makefile
+	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDFLAGS_libxenctrl)
+
 -include $(DEPS)
diff -r 07fb7525c9ce tools/misc/xenconsole_dump.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/misc/xenconsole_dump.c	Fri Mar 20 15:45:44 2009 +0000
@@ -0,0 +1,143 @@
+/*
+ * This is a very dumb xenconsole backend that does not use xenstore.
+ *
+ * Copyright 2008, Diego Ongaro <diego.ongaro@citrix.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License.  See the file "COPYING" in the main directory of
+ * this archive for more details.
+ */
+
+#include <getopt.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/select.h>
+
+#include <xenctrl.h>
+#include <xen/grant_table.h>
+#include <xen/io/console.h>
+
+
+#define DIE() \
+do { \
+	fprintf(stderr, "DIE in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
+	exit(1); \
+} while (0)
+#define DIE_ON(cond) \
+do { \
+	if ((cond)) \
+		DIE(); \
+} while (0)
+
+
+static domid_t domid = -1;
+static evtchn_port_or_error_t remote_port = -1;
+static evtchn_port_or_error_t local_port = -1;
+static struct xencons_interface *intf;
+
+static int xce_handle;
+static int xcg_handle;
+
+static void
+try_dump(void)
+{
+	static char buffer[sizeof(intf->out)];
+	XENCONS_RING_IDX cons, prod, size;
+	int i = 0;
+
+	cons = intf->out_cons;
+	prod = intf->out_prod;
+	xen_mb();
+
+	size = prod - cons;
+	if ((size == 0) || (size > sizeof(intf->out)))
+		return;
+
+	while (cons != prod)
+		buffer[i++] = intf->out[MASK_XENCONS_IDX(cons++, intf->out)];
+
+	xen_mb();
+	intf->out_cons = cons;
+	xc_evtchn_notify(xce_handle, local_port);
+
+	DIE_ON(write(1, buffer, i) != i);
+}
+
+static void
+dump_ring(void)
+{
+	while (1) {
+		DIE_ON(xc_evtchn_pending(xce_handle) == -1);
+		try_dump();
+		DIE_ON(xc_evtchn_unmask(xce_handle, local_port) == -1);
+	}
+}
+
+static void
+setup(void)
+{
+	xce_handle = xc_evtchn_open();
+	DIE_ON(xce_handle == -1);
+
+	xcg_handle = xc_gnttab_open();
+	DIE_ON(xcg_handle == -1);
+
+	intf = xc_gnttab_map_grant_ref(xcg_handle,
+	                               domid,
+	                               GNTTAB_RESERVED_CONSOLE,
+	                               PROT_READ|PROT_WRITE);
+	DIE_ON(intf == NULL);
+
+	local_port = xc_evtchn_bind_interdomain(xce_handle, domid, remote_port);
+	DIE_ON(local_port == -1);
+
+}
+
+static void
+usage(char *name)
+{
+	printf("Usage: %s [-h] --domid=DOMID --remote-port=PORT\n", name);
+}
+
+int
+main(int argc, char **argv)
+{
+	const char *sopts = "h";
+	struct option lopts[] = {
+		{ "help", 0, 0, 'h' },
+		{ "domid", 1, 0, 'D'},
+		{ "remote-port", 1, 0, 'P'},
+		{ 0 },
+	};
+	int ch;
+	int opt_ind = 0;
+
+	while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
+		switch (ch) {
+		case 'h':
+			usage(argv[0]);
+			exit(0);
+		case 'D':
+			domid = (domid_t) atoi(optarg);
+			break;
+		case 'P':
+			remote_port = (evtchn_port_or_error_t) atoi(optarg);
+			break;
+		}
+	}
+
+	if (domid <= 0 || remote_port < 0) {
+		usage(argv[0]);
+		exit(1);
+	}
+
+	setup();
+	dump_ring();
+
+	return 0;
+}



[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 21/24] [xen-unstable.hg] utility for accessing xenstore stubdom console which doesn't use xenstore
  2009-03-23 15:21 [PATCH 21/24] [xen-unstable.hg] utility for accessing xenstore stubdom console which doesn't use xenstore Alex Zeffertt
@ 2009-06-10 15:22 ` Alex Zeffertt
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Zeffertt @ 2009-06-10 15:22 UTC (permalink / raw)
  To: Alex Zeffertt; +Cc: xen-devel@lists.xensource.com

[-- Attachment #1: Type: text/plain, Size: 447 bytes --]

Hi,

I've attached an updated version of this patch which fixes a bug.

xenconsole_dump was sending a notification on the console evtchn after reading 
from the console shared page, but this causes crashes in minios VMs such as the 
xenstore stubdomain.

Removing the unnecessary xc_evtchn_notify() call in xenconsole_dump makes it 
possible to run "/etc/init.d/xenstored console" without crashing the xenstore 
stubdom.

Alex Zeffertt wrote:
> 


[-- Attachment #2: xenconsole_dump --]
[-- Type: text/plain, Size: 4417 bytes --]

This is a very dumb xenconsole backend that does not use xenstore.

Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
---

diff -r 3d1e54a046d3 .hgignore
--- a/.hgignore	Mon Jun 08 14:13:00 2009 +0100
+++ b/.hgignore	Wed Jun 10 16:11:09 2009 +0100
@@ -196,6 +196,7 @@
 ^tools/misc/xen-tmem-list-parse$
 ^tools/misc/xenperf$
 ^tools/misc/xenpm$
+^tools/misc/xenconsole_dump$
 ^tools/pygrub/build/.*$
 ^tools/python/build/.*$
 ^tools/python/xen/util/path\.py$
diff -r 3d1e54a046d3 tools/misc/Makefile
--- a/tools/misc/Makefile	Mon Jun 08 14:13:00 2009 +0100
+++ b/tools/misc/Makefile	Wed Jun 10 16:11:09 2009 +0100
@@ -10,7 +10,7 @@
 
 HDRS     = $(wildcard *.h)
 
-TARGETS-y := xenperf xenpm xen-tmem-list-parse
+TARGETS-y := xenperf xenpm xen-tmem-list-parse xenconsole_dump
 TARGETS-$(CONFIG_X86) += xen-detect
 TARGETS := $(TARGETS-y)
 
@@ -18,7 +18,7 @@
 SUBDIRS-$(CONFIG_MINITERM) += miniterm
 SUBDIRS := $(SUBDIRS-y)
 
-INSTALL_BIN-y := xencons
+INSTALL_BIN-y := xencons xenconsole_dump
 INSTALL_BIN-$(CONFIG_X86) += xen-detect
 INSTALL_BIN := $(INSTALL_BIN-y)
 
@@ -56,4 +56,7 @@
 xenperf xenpm: %: %.o Makefile
 	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDFLAGS_libxenctrl)
 
+xenconsole_dump: %: %.o Makefile
+	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDFLAGS_libxenctrl)
+
 -include $(DEPS)
diff -r 3d1e54a046d3 tools/misc/xenconsole_dump.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/misc/xenconsole_dump.c	Wed Jun 10 16:11:09 2009 +0100
@@ -0,0 +1,142 @@
+/*
+ * This is a very dumb xenconsole backend that does not use xenstore.
+ *
+ * Copyright 2008, Diego Ongaro <diego.ongaro@citrix.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License.  See the file "COPYING" in the main directory of
+ * this archive for more details.
+ */
+
+#include <getopt.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/select.h>
+
+#include <xenctrl.h>
+#include <xen/grant_table.h>
+#include <xen/io/console.h>
+
+
+#define DIE() \
+do { \
+	fprintf(stderr, "DIE in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
+	exit(1); \
+} while (0)
+#define DIE_ON(cond) \
+do { \
+	if ((cond)) \
+		DIE(); \
+} while (0)
+
+
+static domid_t domid = -1;
+static evtchn_port_or_error_t remote_port = -1;
+static evtchn_port_or_error_t local_port = -1;
+static struct xencons_interface *intf;
+
+static int xce_handle;
+static int xcg_handle;
+
+static void
+try_dump(void)
+{
+	static char buffer[sizeof(intf->out)];
+	XENCONS_RING_IDX cons, prod, size;
+	int i = 0;
+
+	cons = intf->out_cons;
+	prod = intf->out_prod;
+	xen_mb();
+
+	size = prod - cons;
+	if ((size == 0) || (size > sizeof(intf->out)))
+		return;
+
+	while (cons != prod)
+		buffer[i++] = intf->out[MASK_XENCONS_IDX(cons++, intf->out)];
+
+	xen_mb();
+	intf->out_cons = cons;
+
+	DIE_ON(write(1, buffer, i) != i);
+}
+
+static void
+dump_ring(void)
+{
+	while (1) {
+		DIE_ON(xc_evtchn_pending(xce_handle) == -1);
+		try_dump();
+		DIE_ON(xc_evtchn_unmask(xce_handle, local_port) == -1);
+	}
+}
+
+static void
+setup(void)
+{
+	xce_handle = xc_evtchn_open();
+	DIE_ON(xce_handle == -1);
+
+	xcg_handle = xc_gnttab_open();
+	DIE_ON(xcg_handle == -1);
+
+	intf = xc_gnttab_map_grant_ref(xcg_handle,
+	                               domid,
+	                               GNTTAB_RESERVED_CONSOLE,
+	                               PROT_READ|PROT_WRITE);
+	DIE_ON(intf == NULL);
+
+	local_port = xc_evtchn_bind_interdomain(xce_handle, domid, remote_port);
+	DIE_ON(local_port == -1);
+
+}
+
+static void
+usage(char *name)
+{
+	printf("Usage: %s [-h] --domid=DOMID --remote-port=PORT\n", name);
+}
+
+int
+main(int argc, char **argv)
+{
+	const char *sopts = "h";
+	struct option lopts[] = {
+		{ "help", 0, 0, 'h' },
+		{ "domid", 1, 0, 'D'},
+		{ "remote-port", 1, 0, 'P'},
+		{ 0 },
+	};
+	int ch;
+	int opt_ind = 0;
+
+	while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
+		switch (ch) {
+		case 'h':
+			usage(argv[0]);
+			exit(0);
+		case 'D':
+			domid = (domid_t) atoi(optarg);
+			break;
+		case 'P':
+			remote_port = (evtchn_port_or_error_t) atoi(optarg);
+			break;
+		}
+	}
+
+	if (domid <= 0 || remote_port < 0) {
+		usage(argv[0]);
+		exit(1);
+	}
+
+	setup();
+	dump_ring();
+
+	return 0;
+}

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-06-10 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-23 15:21 [PATCH 21/24] [xen-unstable.hg] utility for accessing xenstore stubdom console which doesn't use xenstore Alex Zeffertt
2009-06-10 15:22 ` Alex Zeffertt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.