From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: Re: [PATCH V4 22/24] xl: update domain configuration when we hotplug a device Date: Tue, 6 May 2014 17:57:34 +0100 Message-ID: <5369147E.4060602@citrix.com> References: <1398949101-23320-1-git-send-email-wei.liu2@citrix.com> <1398949101-23320-23-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: <1398949101-23320-23-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 , xen-devel@lists.xen.org Cc: ian.jackson@eu.citrix.com, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org On 01/05/14 13:58, Wei Liu wrote: > A convenient macro is written to accomplish following tasks: > > 1. load domain configuration > 2. allocate a new device structure NEW > 3. copy the parsed device strcture PARSED to NEW > 4. call libxl_device_TYPE_add(PARSED) > 5. pull from PARSED any fields that might be touched by libxl to NEW > 6. store domain configuration > > Signed-off-by: Wei Liu > --- > tools/libxl/xl_cmdimpl.c | 85 +++++++++++++++++++++++++++++++++++++--------- > 1 file changed, 69 insertions(+), 16 deletions(-) > > diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c > index 83f058e..91172c5 100644 > --- a/tools/libxl/xl_cmdimpl.c > +++ b/tools/libxl/xl_cmdimpl.c > @@ -381,6 +381,36 @@ static void *xrealloc(void *ptr, size_t sz) { > &(array)[array_extend_old_count]; \ > }) > > +#define ARRAY_EXTEND_INIT_NODEVID(array,count,initfn) \ > + ({ \ > + typeof((count)) array_extend_old_count = (count); \ > + (count)++; \ > + (array) = xrealloc((array), sizeof(*array) * (count)); \ > + (initfn)(&(array)[array_extend_old_count]); \ > + &(array)[array_extend_old_count]; \ > + }) > + > +/* Add a device and update the stored configuration */ > +#define ADD_DEVICE(devtype,domid,dev,d_config,ptr,allocate,maybe_fixup) \ > + do { \ > + libxl_domain_config_init((d_config)); \ > + load_domain_config((domid), (d_config)); \ > + \ > + allocate; \ > + \ > + libxl_device_ ## devtype ## _copy(ctx,(ptr),&(dev)); \ > + \ > + if (libxl_device_ ## devtype ## _add(ctx,(domid),&(dev), 0)) { \ > + fprintf(stderr, "libxl_device_%s_add failed.\n", #devtype); \ > + exit(1); \ > + } \ > + \ > + maybe_fixup; \ > + \ > + store_domain_config((domid), (d_config)); \ > + libxl_domain_config_dispose((d_config)); \ > + } while (0) > + Is there a better way of doing this without these obtuse macros? Is libxl lacking is a proper device abstraction layer? David