Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Dec 2013 10:07:11 -0500
From:      John Baldwin <jhb@freebsd.org>
To:        Roger Pau Monne <roger.pau@citrix.com>
Cc:        xen-devel@lists.xen.org, julien.grall@citrix.com, freebsd-xen@freebsd.org, freebsd-current@freebsd.org, kib@freebsd.org, gibbs@freebsd.org
Subject:   Re: [PATCH v7 03/19] xen: add and enable Xen console for PVH guests
Message-ID:  <201312241007.11898.jhb@freebsd.org>
In-Reply-To: <1387479296-33389-4-git-send-email-roger.pau@citrix.com>
References:  <1387479296-33389-1-git-send-email-roger.pau@citrix.com> <1387479296-33389-4-git-send-email-roger.pau@citrix.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312241007.11898.jhb>