* [Qemu-devel] [PATCH v2] xen_console: support the new extended xenstore protocol
@ 2011-06-28 14:55 stefano.stabellini
2011-06-28 15:02 ` Peter Maydell
0 siblings, 1 reply; 4+ messages in thread
From: stefano.stabellini @ 2011-06-28 14:55 UTC (permalink / raw)
To: qemu-devel
Cc: anthony.perard, peter.maydell, xen-devel, agraf,
Stefano Stabellini
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Since CS 21994 on xen-unstable.hg and CS
466608f3a32e1f9808acdf832a5843af37e5fcec on qemu-xen-unstable.git, few
changes have been introduced to the PV console xenstore protocol, as
described by the document docs/misc/console.txt under xen-unstable.hg.
>From the Qemu point of view, very few modifications are needed to
correctly support the protocol: read from xenstore the "output" node
that tell us what the output of the PV console is going to be.
In case the output is a tty, write to xenstore the device name.
Changes in v2:
- fix error paths: free malloc'ed strings and close the xenstore
connection before returning;
- remove useless snprintf in xenstore_store_pv_console_info if i == 0.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
hw/xen.h | 1 +
hw/xen_console.c | 16 +++++++++-----
xen-all.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/hw/xen.h b/hw/xen.h
index d435ca0..dad0ca0 100644
--- a/hw/xen.h
+++ b/hw/xen.h
@@ -50,6 +50,7 @@ qemu_irq *xen_interrupt_controller_init(void);
int xen_init(void);
int xen_hvm_init(void);
void xen_vcpu_init(void);
+void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
#if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size);
diff --git a/hw/xen_console.c b/hw/xen_console.c
index 519d5f5..e81afcd 100644
--- a/hw/xen_console.c
+++ b/hw/xen_console.c
@@ -179,8 +179,9 @@ static void xencons_send(struct XenConsole *con)
static int con_init(struct XenDevice *xendev)
{
struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
- char *type, *dom;
+ char *type, *dom, label[32];
int ret = 0;
+ const char *output;
/* setup */
dom = xs_get_domain_path(xenstore, con->xendev.dom);
@@ -194,11 +195,14 @@ static int con_init(struct XenDevice *xendev)
goto out;
}
- if (!serial_hds[con->xendev.dev])
- xen_be_printf(xendev, 1, "WARNING: serial line %d not configured\n",
- con->xendev.dev);
- else
- con->chr = serial_hds[con->xendev.dev];
+ output = xenstore_read_str(con->console, "output");
+ /* output is a pty by default */
+ if (output == NULL) {
+ output = "pty";
+ }
+ snprintf(label, sizeof(label), "xencons%d", con->xendev.dev);
+ con->chr = qemu_chr_open(label, output, NULL);
+ xenstore_store_pv_console_info(con->xendev.dev, con->chr);
out:
qemu_free(type);
diff --git a/xen-all.c b/xen-all.c
index 6099bff..3f8aadb 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -737,6 +737,66 @@ static void cpu_handle_ioreq(void *opaque)
}
}
+static int store_dev_info(int domid, CharDriverState *cs, const char *string)
+{
+ struct xs_handle *xs = NULL;
+ char *path = NULL;
+ char *newpath = NULL;
+ char *pts = NULL;
+ int ret = -1;
+
+ /* Only continue if we're talking to a pty. */
+ if (strncmp(cs->filename, "pty:", 4)) {
+ return 0;
+ }
+ pts = cs->filename + 4;
+
+ /* We now have everything we need to set the xenstore entry. */
+ xs = xs_daemon_open();
+ if (xs == NULL) {
+ fprintf(stderr, "Could not contact XenStore\n");
+ goto out;
+ }
+
+ path = xs_get_domain_path(xs, domid);
+ if (path == NULL) {
+ fprintf(stderr, "xs_get_domain_path() error\n");
+ goto out;
+ }
+ newpath = realloc(path, (strlen(path) + strlen(string) +
+ strlen("/tty") + 1));
+ if (newpath == NULL) {
+ fprintf(stderr, "realloc error\n");
+ goto out;
+ }
+ path = newpath;
+
+ strcat(path, string);
+ strcat(path, "/tty");
+ if (!xs_write(xs, XBT_NULL, path, pts, strlen(pts))) {
+ fprintf(stderr, "xs_write for '%s' fail", string);
+ goto out;
+ }
+ ret = 0;
+
+out:
+ free(path);
+ xs_daemon_close(xs);
+
+ return ret;
+}
+
+void xenstore_store_pv_console_info(int i, CharDriverState *chr)
+{
+ if (i == 0) {
+ store_dev_info(xen_domid, chr, "/console");
+ } else {
+ char buf[32];
+ snprintf(buf, sizeof(buf), "/device/console/%d", i);
+ store_dev_info(xen_domid, chr, buf);
+ }
+}
+
static void xenstore_record_dm_state(XenIOState *s, const char *state)
{
char path[50];
--
1.7.2.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] xen_console: support the new extended xenstore protocol
2011-06-28 14:55 [Qemu-devel] [PATCH v2] xen_console: support the new extended xenstore protocol stefano.stabellini
@ 2011-06-28 15:02 ` Peter Maydell
2011-06-28 15:06 ` [Qemu-devel] [Xen-devel] " Ian Campbell
0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2011-06-28 15:02 UTC (permalink / raw)
To: stefano.stabellini; +Cc: anthony.perard, xen-devel, qemu-devel, agraf
On 28 June 2011 15:55, <stefano.stabellini@eu.citrix.com> wrote:
> + xs = xs_daemon_open();
> + if (xs == NULL) {
> + fprintf(stderr, "Could not contact XenStore\n");
> + goto out;
> + }
> +out:
> + free(path);
> + xs_daemon_close(xs);
Google suggests xs_daemon_close(NULL) will crash...
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [Xen-devel] Re: [PATCH v2] xen_console: support the new extended xenstore protocol
2011-06-28 15:02 ` Peter Maydell
@ 2011-06-28 15:06 ` Ian Campbell
2011-06-28 15:15 ` Stefano Stabellini
0 siblings, 1 reply; 4+ messages in thread
From: Ian Campbell @ 2011-06-28 15:06 UTC (permalink / raw)
To: Peter Maydell
Cc: Anthony Perard, agraf@suse.de, xen-devel@lists.xensource.com,
qemu-devel@nongnu.org, Stefano Stabellini
On Tue, 2011-06-28 at 16:02 +0100, Peter Maydell wrote:
> On 28 June 2011 15:55, <stefano.stabellini@eu.citrix.com> wrote:
> > + xs = xs_daemon_open();
> > + if (xs == NULL) {
> > + fprintf(stderr, "Could not contact XenStore\n");
> > + goto out;
> > + }
>
> > +out:
> > + free(path);
> > + xs_daemon_close(xs);
>
> Google suggests xs_daemon_close(NULL) will crash...
Also the preferred interface these days is just xs_open/close. The other
variants are deprecated.
Ian.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [Xen-devel] Re: [PATCH v2] xen_console: support the new extended xenstore protocol
2011-06-28 15:06 ` [Qemu-devel] [Xen-devel] " Ian Campbell
@ 2011-06-28 15:15 ` Stefano Stabellini
0 siblings, 0 replies; 4+ messages in thread
From: Stefano Stabellini @ 2011-06-28 15:15 UTC (permalink / raw)
To: Ian Campbell
Cc: Peter Maydell, xen-devel@lists.xensource.com, Stefano Stabellini,
agraf@suse.de, qemu-devel@nongnu.org, Anthony Perard
On Tue, 28 Jun 2011, Ian Campbell wrote:
> On Tue, 2011-06-28 at 16:02 +0100, Peter Maydell wrote:
> > On 28 June 2011 15:55, <stefano.stabellini@eu.citrix.com> wrote:
> > > + xs = xs_daemon_open();
> > > + if (xs == NULL) {
> > > + fprintf(stderr, "Could not contact XenStore\n");
> > > + goto out;
> > > + }
> >
> > > +out:
> > > + free(path);
> > > + xs_daemon_close(xs);
> >
> > Google suggests xs_daemon_close(NULL) will crash...
>
> Also the preferred interface these days is just xs_open/close. The other
> variants are deprecated.
And xs_close doesn't crash if the parameter is NULL, so it will kill two
birds with one stone.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-06-28 15:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-28 14:55 [Qemu-devel] [PATCH v2] xen_console: support the new extended xenstore protocol stefano.stabellini
2011-06-28 15:02 ` Peter Maydell
2011-06-28 15:06 ` [Qemu-devel] [Xen-devel] " Ian Campbell
2011-06-28 15:15 ` Stefano Stabellini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).