From owner-freebsd-current@FreeBSD.ORG Tue Dec 24 15:51:05 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1FF3499A; Tue, 24 Dec 2013 15:51:05 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E76281AC7; Tue, 24 Dec 2013 15:51:04 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id DB435B968; Tue, 24 Dec 2013 10:51:03 -0500 (EST) From: John Baldwin To: Roger Pau Monne Subject: Re: [PATCH v7 03/19] xen: add and enable Xen console for PVH guests Date: Tue, 24 Dec 2013 10:07:11 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <1387479296-33389-1-git-send-email-roger.pau@citrix.com> <1387479296-33389-4-git-send-email-roger.pau@citrix.com> In-Reply-To: <1387479296-33389-4-git-send-email-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Message-Id: <201312241007.11898.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 24 Dec 2013 10:51:04 -0500 (EST) Cc: xen-devel@lists.xen.org, julien.grall@citrix.com, freebsd-xen@freebsd.org, freebsd-current@freebsd.org, kib@freebsd.org, gibbs@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Dec 2013 15:51:05 -0000 On Thursday, December 19, 2013 1:54:40 pm Roger Pau Monne wrote: > diff --git a/sys/dev/xen/console/console.c b/sys/dev/xen/console/console.c > index 23eaee2..e8079da 100644 > --- a/sys/dev/xen/console/console.c > +++ b/sys/dev/xen/console/console.c > @@ -69,11 +69,14 @@ struct mtx cn_mtx; > static char wbuf[WBUF_SIZE]; > static char rbuf[RBUF_SIZE]; > static int rc, rp; > -static unsigned int cnsl_evt_reg; > +unsigned int cnsl_evt_reg; > static unsigned int wc, wp; /* write_cons, write_prod */ > xen_intr_handle_t xen_intr_handle; > device_t xencons_dev; > =20 > +/* Virt address of the shared console page */ Tiny nit: I would expand "Virt" to "Virtual" > +char *console_page; > + > #ifdef KDB > static int xc_altbrk; > #endif > @@ -110,9 +113,28 @@ static struct ttydevsw xc_ttydevsw =3D { > .tsw_outwakeup =3D xcoutwakeup, > }; > =20 > +/*----------------------------- Debug function -------------------------= =2D-----*/ > +#define XC_PRINTF_BUFSIZE 1024 > +void > +xc_printf(const char *fmt, ...) > +{ > + __va_list ap; > + int retval; > + static char buf[XC_PRINTF_BUFSIZE]; > + > + va_start(ap, fmt); > + retval =3D vsnprintf(buf, XC_PRINTF_BUFSIZE - 1, fmt, ap); > + va_end(ap); > + buf[retval] =3D 0; > + HYPERVISOR_console_write(buf, retval); > +} > + vsnprintf() always nul-terminates, so you can simplify this slightly to: retval =3D vsnprintf(buf, sizeof(buf), fmt, ap); OTOH, you can't actually use 'retval' from vsnprintf as it returns the number of characters that would have been output if the buffer were infinitely long, not the number of characters output into the string. =46rom printf(3): These functions return the number of characters printed (not including the trailing `\0' used to end output to strings) or a negative value if an output error occurs, except for snprintf() and vsnprintf(), which return the number of characters that would have been printed if the si= ze were unlimited (again, not including the final `\0'). So I think what you actually want is this: void xc_printf(const char *fmt, ...) { static char buf[XC_PRINTF_BUFSIZE]; __va_list ap; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); HYPERVISOR_console_write(buf, strlen(buf)); } (And I realize this is an old bug, you were just moving an existing functio= n) > =20 > -static void > -xc_identify(driver_t *driver, device_t parent) > -{ > - device_t child; > - child =3D BUS_ADD_CHILD(parent, 0, driver_name, 0); > - device_set_driver(child, driver); > - device_set_desc(child, "Xen Console"); > -} > - Hmm, how does the device get created without an identify routine? =2D-=20 John Baldwin