[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH QEMU-XEN v3 2/8] xen: Switch to libxengnttab interface for compat shims.



On Wed, 7 Oct 2015, Ian Campbell wrote:
> In Xen 4.7 we are refactoring parts libxenctrl into a number of
> separate libraries which will provide backward and forward API and ABI
> compatiblity.
> 
> One such library will be libxengnttab which provides access to grant
> tables.
> 
> In preparation for this switch the compatibility layer in xen_common.h
> (which support building with older versions of Xen) to use what will
> be the new library API. This means that the gnttab shim will disappear
> for versions of Xen which include libxengnttab.
> 
> To simplify things for the <= 4.0.0 support we wrap the int fd in a
> malloc(sizeof int) such that the handle is always a pointer. This
> leads to less typedef headaches and the need for
> XC_HANDLER_INITIAL_VALUE etc for these interfaces.
> 
> Build tested with 4.0 and 4.5.
> 
> Note that this patch does not add any support for actually using
> libxengnttab, it just adjusts the existing shims.
> 
> Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

[...]

> diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h
> index 5700c1b..3955d86 100644
> --- a/include/hw/xen/xen_common.h
> +++ b/include/hw/xen/xen_common.h
> @@ -40,7 +40,7 @@ static inline void *xc_map_foreign_bulk(int xc_handle, 
> uint32_t dom, int prot,
>  
>  typedef int XenXC;
>  typedef int xenevtchn_handle;
> -typedef int XenGnttab;
> +typedef int xengnttab_handle;
>  
>  #  define XC_INTERFACE_FMT "%i"
>  #  define XC_HANDLER_INITIAL_VALUE    -1
> @@ -71,11 +71,29 @@ static inline int xenevtchn_close(xenevtchn_handle *h)
>  #define xenevtchn_unmask(h,p) xc_evtchn_unmask(*h,p)
>  #define xenevtchn_unbind(h,p) xc_evtchn_unmask(*h,p)
>  
> -static inline XenGnttab xen_xc_gnttab_open(void *logger,
> -                                           unsigned int open_flags)
> +static inline xengnttab_handle *xengnttab_open(void *logger,
> +                                            unsigned int open_flags)
>  {
> -    return xc_gnttab_open();
> +    int *h = malloc(sizeof h);
                       ^
                       sizeof (*h)

> +    if (!h)
> +     return NULL;

indentation


> +    *h = xc_gnttab_open();
> +    if (*h == -1) {
> +      free(h);
> +         h = NULL;
> +    }
> +    return h;
>  }
> +static inline int xengnttab_close(xengnttab_handle *h)
> +{
> +    int rc = xc_gnttab_close(*h);
> +    free(h);
> +    return rc;
> +}
> +#define xengnttab_set_max_grants(h,n) xc_gnttab_set_max_grants(*h, n)
> +#define xengnttab_map_grant_ref(h,d,r,p) xc_gnttab_map_grant_ref(*h,d,r,p)
> +#define xengnttab_map_grant_refs(h,c,d,r,p) 
> xc_gnttab_map_grant_refs(*h,c,d,r,p)
> +#define xengnttab_munmap(h,a,n) xc_gnttab_munmap(*h,a,n)
>  
>  static inline XenXC xen_xc_interface_open(void *logger, void 
> *dombuild_logger,
>                                            unsigned int open_flags)
> @@ -129,7 +147,7 @@ static inline void xs_close(struct xs_handle *xsh)
>  
>  typedef xc_interface *XenXC;
>  typedef xc_evtchn xenevtchn_handle;
> -typedef xc_gnttab *XenGnttab;
> +typedef xc_gnttab xengnttab_handle;
>  
>  #  define XC_INTERFACE_FMT "%p"
>  #  define XC_HANDLER_INITIAL_VALUE    NULL
> @@ -143,11 +161,12 @@ typedef xc_gnttab *XenGnttab;
>  #define xenevtchn_unmask(h,p) xc_evtchn_unmask(h,p)
>  #define xenevtchn_unbind(h,p) xc_evtchn_unbind(h,p)
>  
> -static inline XenGnttab xen_xc_gnttab_open(void *logger,
> -                                           unsigned int open_flags)
> -{
> -    return xc_gnttab_open(logger, open_flags);
> -}
> +#define xengnttab_open(l,f) xc_gnttab_open(l,f)
> +#define xengnttab_close(h) xc_gnttab_close(h)
> +#define xengnttab_set_max_grants(h,n) xc_gnttab_set_max_grants(h, n)
> +#define xengnttab_map_grant_ref(h,d,r,p) xc_gnttab_map_grant_ref(h,d,r,p)
> +#define xengnttab_munmap(h,a,n) xc_gnttab_munmap(h,a,n)
> +#define xengnttab_map_grant_refs(h,c,d,r,p) 
> xc_gnttab_map_grant_refs(h,c,d,r,p)
>  
>  static inline XenXC xen_xc_interface_open(void *logger, void 
> *dombuild_logger,
>                                            unsigned int open_flags)
> -- 
> 2.1.4
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.