From: Ian Campbell Subject: Re: [PATCH V3] xl: create VFB for PV guest when VNC is specified Date: Mon, 16 Dec 2013 17:46:04 +0000 Message-ID: <1387215964.21086.54.camel@kazak.uk.xensource.com> References: <1387215576-17455-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1387215576-17455-1-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu Cc: Ian Jackson , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Mon, 2013-12-16 at 17:39 +0000, Wei Liu wrote: > This replicates a Xend behavior, when you specify: > > vnc=1 > vnclisten=XXXX > vncpasswd=XXXX > > in a PV guest's config file, it creates a VFB for you. > > Fixes bug #25. > http://bugs.xenproject.org/xen/bug/25 > > Reported-by: Konrad Wilk > Signed-off-by: Wei Liu > Cc: Ian Campbell > Cc: Ian Jackson > > --- > Changes in V3: > * ARRAY_EXTEND macro > * make parse_top_level_vnc_options a function > > Changes in V2: > * use macros to reduce code duplication > * vfb=[] take precedence over top level VNC options > --- > tools/libxl/xl_cmdimpl.c | 89 ++++++++++++++++++++++++++++++++++++---------- > 1 file changed, 70 insertions(+), 19 deletions(-) > > diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c > index bd26bcc..6a22e17 100644 > --- a/tools/libxl/xl_cmdimpl.c > +++ b/tools/libxl/xl_cmdimpl.c > @@ -315,6 +315,13 @@ static void *xrealloc(void *ptr, size_t sz) { > return r; > } > > +#define ARRAY_EXTEND(array,count) \ > + do { \ > + (array) = xrealloc((array), \ > + sizeof(typeof(*(array))) * ((count) + 1)); \ sizeof(typeof(*array)) == sizeof(*array), doesn't it? > + (count) = (count) + 1; \ (count++) I suppose in a macro like this it is tricky to arrange to only evaluate the arguments once, since you need to read and write, but I think you can arrange to evaluate array exactly once instead of 3 times and count just once. Perhaps Ian J has some hints. > @@ -1369,13 +1393,13 @@ skip_nic: > char *buf2 = strdup(buf); > char *p, *p2; > > - d_config->vfbs = (libxl_device_vfb *) realloc(d_config->vfbs, sizeof(libxl_device_vfb) * (d_config->num_vfbs + 1)); > - vfb = d_config->vfbs + d_config->num_vfbs; > + ARRAY_EXTEND(d_config->vfbs, d_config->num_vfbs); > + vfb = d_config->vfbs + (d_config->num_vfbs - 1); You should make the macro return the new element like I suggested. Apart from being convenient it avoids having to have this logic, and the potential for an off-by-one error, repeated in every user. > @@ -1608,6 +1630,44 @@ skip_vfb: > > #undef parse_extra_args > > + /* If we've already got vfb=[] for PV guestthen ignore top level "guest then" > + parse_top_level_vnc_options(config, > + &vfb->vnc.enable, This helper can take a libxl_vnc * instead of all of these, individual fields. Pass it &vfb->vnc or &b_Info->u.hvm.vnc as appropriate. Ian.