From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH v2 1/5] libxl: introduce libxl__device_model_xs_path Date: Thu, 19 Mar 2015 17:01:13 +0000 Message-ID: <1426784473.21742.81.camel@citrix.com> References: <1426771086-9026-1-git-send-email-wei.liu2@citrix.com> <1426771086-9026-2-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: <1426771086-9026-2-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: stefano.stabellini@eu.citrix.com, ian.jackson@eu.ctrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Thu, 2015-03-19 at 13:18 +0000, Wei Liu wrote: > Introduce this helper to return xenstore path for device model to avoid > handcoded paths. > > Signed-off-by: Wei Liu > --- > tools/libxl/libxl_internal.c | 22 ++++++++++++++++++++++ > tools/libxl/libxl_internal.h | 3 +++ > 2 files changed, 25 insertions(+) > > diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c > index ddc68ab..8877288 100644 > --- a/tools/libxl/libxl_internal.c > +++ b/tools/libxl/libxl_internal.c > @@ -555,6 +555,28 @@ void libxl__update_domain_configuration(libxl__gc *gc, > dst->b_info.video_memkb = src->b_info.video_memkb; > } > > +char *libxl__device_model_xs_path(libxl__gc *gc, uint32_t dm_domid, > + uint32_t domid, const char *format, ...) > +{ > + char *s, *fmt; > + va_list ap; > + int ret; > + > + fmt = GCSPRINTF("/local/domain/%u/device-model/%u%s", dm_domid, > + domid, format); > + > + va_start(ap, format); > + ret = vsnprintf(NULL, 0, fmt, ap); > + va_end(ap); > + > + s = libxl__zalloc(gc, ret + 1); > + va_start(ap, format); > + ret = vsnprintf(s, ret + 1, fmt, ap); > + va_end(ap); Please could you refactor the existing libxl__sprintf into a libxl__vsprintf (i.e. which takes a va_list, and uses va_copy for the two calls to vsnprintf). Then implement your new helper in terms of the libxl__vsprintf. > + > + return s; > +} > + > /* > * Local variables: > * mode: C > diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h > index 934465a..9ef2ec6 100644 > --- a/tools/libxl/libxl_internal.h > +++ b/tools/libxl/libxl_internal.h > @@ -1794,6 +1794,9 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc_opt, const char *s); > _hidden int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid); > /* Return the system-wide default device model */ > _hidden libxl_device_model_version libxl__default_device_model(libxl__gc *gc); > +_hidden char *libxl__device_model_xs_path(libxl__gc *gc, uint32_t dm_domid, > + uint32_t domid, > + const char *format, ...); > > /* Check how executes hotplug script currently */ > int libxl__hotplug_settings(libxl__gc *gc, xs_transaction_t t);