All of lore.kernel.org
 help / color / mirror / Atom feed
* XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1)
@ 2010-11-18 10:49 Ian Campbell
  2010-11-18 10:50 ` [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Ian Campbell
       [not found] ` <1290077348.31507.5282.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  0 siblings, 2 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:49 UTC (permalink / raw)
  To: xen-devel, xen-api

The following series against xen-api-libs.hg, xen-api.hg and
xen-unstable.hg (to be posted as replies to this mail shortly) lays some
groundwork to allow XCP to be used against xen-unstable (and therefore
eventually the 4.1 release).

I have very much glossed over (i.e. hacked up the bare minimum of) the
actual toolstack port to xen-unstable, since my primary aim was simply
to do the groundwork to allow the use of the in-tree bindings in order
to ensure that Xen 4.1.0 is released with something with a baseline
level of usefulness to XCP. However I did do enough to allow
installation and starting of a PV guest and a successful "quicktest
-all" run (100% pass, FWIW).

I have arranged that the xen-api-libs.hg and xen-api.hg patches which
can be applied now without compromising the existing Xen 3.4 based XCP
platform are at the head of the relevant series and that the stuff which
depends on the transition to Xen 4.1 comes afterwards and have the
REBASE-4.1 prefix (followed by my hacks and other bits and pieces,
marked with HACK, they are just for reference and should be applied
to /dev/null only). The intention is that the xen-unstable bits can be
applied before Xen 4.1 in order that the infrastructure is in place when
XCP comes to rebase.

For my testing I have been using the build-xapi-toolstack.sh script from
http://xenbits.xen.org/xapi/install.html so in actual fact some of the
patches right at the start of the xen-api-libs.hg and xen-api.hg series
as well as the entire xen-dist-ocaml.hg series are actually fixes for
issues I encountered when using that script and doing RPM builds
outside /usr/src hopefully it is obvious what is what.

While doing this work I started to wonder if using the xb, xs, xc, xl
etc names at the toplevel of the ocaml module namespace was wise/polite?
I'm not sure what support ocaml has for module namepacing but perhaps we
should move the in-tree bindings to e.g. xen.lowlevel.{xb,xs,xc,xl} (to
arbitrarily pick up the convention used in the python bindings)?

I also wonder about maintaining non-Xen specific support libraries (such
as uuid, log and mmap) in the xen source tree. Perhaps these could be
pushed further down into the ocaml ecosystem and become prerequisites of
Xen? (assuming there is nothing similar already in the wider ocaml
world). Some of the modules have grown slightly different interfaces in
xen-api-libs.hg vs xen-unstable.hg, in some cases (e.g. uuid module)
resynchronising is simple, in others (e.g. log module) it is not so
trivial. This would be partially solved by namespacing the two sets of
modules I guess but that seems non-optimal in terms of number of module
to maintain.

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg
  2010-11-18 10:49 XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) Ian Campbell
@ 2010-11-18 10:50 ` Ian Campbell
       [not found]   ` <patchbomb.1290077407-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50   ` [PATCH 3 of 3] Install additional packages Ian Campbell
       [not found] ` <1290077348.31507.5282.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  1 sibling, 2 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

The following short series of patches makes xen-dist-ocaml.hg easier to use
from build-xapi-toolstack.sh.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1 of 3] Query rpm to find build directories
       [not found]   ` <patchbomb.1290077407-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 10:50     ` Ian Campbell
  2010-11-18 10:50     ` [PATCH 2 of 3] Define $(RPM) for use in Makefile Ian Campbell
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290004675 18000
# Node ID 01cface0904c7c5d18703ad3f11909ab2f50471c
# Parent  c8f620542215cbb770e5f56e62eb43559e4a52d8
Query rpm to find build directories.

Allows user with ~/.rpmmacros to build e.g.
$ cat ~/.rpmmacros
%_topdir	/data/rpmbuild
%_tmppath	/data/tmp

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r c8f620542215 -r 01cface0904c Makefile
--- a/Makefile	Tue Oct 05 16:50:18 2010 +0000
+++ b/Makefile	Wed Nov 17 09:37:55 2010 -0500
@@ -8,10 +8,10 @@ MY_OUTPUT_DIR ?= $(CURDIR)/output
 MY_OBJ_DIR ?= $(CURDIR)/obj
 REPO ?= $(CURDIR)
 
-RPM_SPECSDIR?=/usr/src/redhat/SPECS
-RPM_SRPMSDIR?=/usr/src/redhat/SRPMS
-RPM_RPMSDIR?=/usr/src/redhat/RPMS
-RPM_SOURCESDIR?=/usr/src/redhat/SOURCES
+RPM_SPECSDIR?=$(shell rpm --eval='%_specdir')
+RPM_SRPMSDIR?=$(shell rpm --eval='%_srcrpmdir')
+RPM_RPMSDIR?=$(shell rpm --eval='%_rpmdir')
+RPM_SOURCESDIR?=$(shell rpm --eval='%_sourcedir')
 RPMBUILD?=rpmbuild
 
 DIST?=/data

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 2 of 3] Define $(RPM) for use in Makefile
       [not found]   ` <patchbomb.1290077407-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50     ` [PATCH 1 of 3] Query rpm to find build directories Ian Campbell
@ 2010-11-18 10:50     ` Ian Campbell
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290004675 18000
# Node ID cf457090b419139cf5a67382e4ce8a44f03c4539
# Parent  01cface0904c7c5d18703ad3f11909ab2f50471c
Define $(RPM) for use in Makefile

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 01cface0904c -r cf457090b419 Makefile
--- a/Makefile	Wed Nov 17 09:37:55 2010 -0500
+++ b/Makefile	Wed Nov 17 09:37:55 2010 -0500
@@ -8,6 +8,7 @@ MY_OUTPUT_DIR ?= $(CURDIR)/output
 MY_OBJ_DIR ?= $(CURDIR)/obj
 REPO ?= $(CURDIR)
 
+RPM?=rpm
 RPM_SPECSDIR?=$(shell rpm --eval='%_specdir')
 RPM_SRPMSDIR?=$(shell rpm --eval='%_srcrpmdir')
 RPM_RPMSDIR?=$(shell rpm --eval='%_rpmdir')

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 3 of 3] Install additional packages
  2010-11-18 10:50 ` [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Ian Campbell
       [not found]   ` <patchbomb.1290077407-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 10:50   ` Ian Campbell
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290004675 18000
# Node ID 56f040418b89013cc5773c8a4da3644a59e91a6a
# Parent  cf457090b419139cf5a67382e4ce8a44f03c4539
Install additional packages

These were built but not installed but were used by something down the build
chain.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r cf457090b419 -r 56f040418b89 Makefile
--- a/Makefile	Wed Nov 17 09:37:55 2010 -0500
+++ b/Makefile	Wed Nov 17 09:37:55 2010 -0500
@@ -46,6 +46,10 @@ build: srpm $(MY_SOURCES)/MANIFEST
 	$(RPMBUILD) --target $(DOMAIN0_ARCH_OPTIMIZED) -bb $(RPM_SPECSDIR)/omake.spec
 	$(RPM) -ihv $(RPM_BINDIR)/omake* || echo omake is already installed
 	$(RPMBUILD) --target $(DOMAIN0_ARCH_OPTIMIZED) -bb $(RPM_SPECSDIR)/xmlm.spec $(RPM_SPECSDIR)/getopt.spec $(RPM_SPECSDIR)/type-conv.spec
+	$(RPM) -ivh $(RPM_BINDIR)/ocaml-xmlm*.rpm || echo ocaml-xmlm is already installed
+	$(RPM) -ivh $(RPM_BINDIR)/ocaml-getopt*.rpm || echo ocaml-getopt is already installed
+	$(RPM) -ivh $(RPM_BINDIR)/ocaml-type-conv*.rpm || echo ocaml-type-conv is already installed
+
 
 .PHONY: srpm
 srpm:

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 0 of 4] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg
       [not found] ` <1290077348.31507.5282.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 10:50   ` Ian Campbell
       [not found]     ` <patchbomb.1290077414-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
                       ` (2 more replies)
  2010-11-18 10:50   ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
                     ` (2 subsequent siblings)
  3 siblings, 3 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

The following series of patches lays some ground work to enable XCP to move, at
some point in the future, to the in-tree ocaml bindings which will come with
Xen 4.1.

This is the xen-api-libs.hg portion.

Only the first three patches are for immediate consideration, the others all
depend on actually moving to Xen 4.1.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1 of 4] Query rpm to find build directories
       [not found]     ` <patchbomb.1290077414-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 10:50       ` Ian Campbell
  2010-11-18 10:50       ` [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module Ian Campbell
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290004595 18000
# Node ID cdd93d37eb6036e9901ecc0cd1f949901ff1aea4
# Parent  3be1829b46b70a8ae4b2013fc20b71a76f3b55ee
Query rpm to find build directories.

Allows user with ~/.rpmmacros to build e.g.
$ cat ~/.rpmmacros
%_topdir        /data/rpmbuild
%_tmppath       /data/tmp

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 3be1829b46b7 -r cdd93d37eb60 Makefile.in
--- a/Makefile.in	Tue Oct 12 12:15:54 2010 +0100
+++ b/Makefile.in	Wed Nov 17 09:36:35 2010 -0500
@@ -211,8 +211,8 @@ cleanxen:
 	$(MAKE) -C xsrpc clean
 	$(MAKE) -C eventchn clean
 
-RPM_SPECSDIR=/usr/src/redhat/SPECS
-RPM_SOURCEDIR=/usr/src/redhat/SOURCES
+RPM_SPECSDIR=$(shell rpm --eval='%_specdir')
+RPM_SOURCEDIR=$(shell rpm --eval='%_sourcedir')
 XEN_RELEASE=xcp0.2
 
 $(RPM_SPECSDIR)/xapi-libs.spec: xapi.spec.in
diff -r 3be1829b46b7 -r cdd93d37eb60 Makefile.xcp
--- a/Makefile.xcp	Tue Oct 12 12:15:54 2010 +0100
+++ b/Makefile.xcp	Wed Nov 17 09:36:35 2010 -0500
@@ -6,9 +6,9 @@ MY_OUTPUT_DIR ?= $(CURDIR)/output
 MY_OBJ_DIR ?= $(CURDIR)/obj
 REPO ?= $(CURDIR)
 
-RPM_SPECSDIR?=/usr/src/redhat/SPECS
-RPM_SRPMSDIR?=/usr/src/redhat/SRPMS
-RPM_SOURCEDIR?=/usr/src/redhat/SOURCES
+RPM_SPECSDIR?=$(shell rpm --eval='%_specdir')
+RPM_SRPMSDIR?=$(shell rpm --eval='%_srcrpmdir')
+RPM_SOURCEDIR?=$(shell rpm --eval='%_sourcedir')
 XEN_RELEASE?=unknown
 endif
 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module
       [not found]     ` <patchbomb.1290077414-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50       ` [PATCH 1 of 4] Query rpm to find build directories Ian Campbell
@ 2010-11-18 10:50       ` Ian Campbell
  2010-11-18 14:36         ` [Xen-API] " Vincent Hanquez
  1 sibling, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290004595 18000
# Node ID be3de1c0aa0687ef9fa6ad2ac5cfa1a74fb14484
# Parent  cdd93d37eb6036e9901ecc0cd1f949901ff1aea4
xc: split xc non-upstream bindings into xcext module.

move anything which is not provided by upstream libxc and the
associated ocaml bindings in a separate xcext library to ease
replacement of xc library by upstream version.

Some of this functionality could potentially be upstreamed straight
away but other bits rely on stuff from the XCP hypervisor patch queue.

One change of not is that Xcext.hvm_check_pvdriver expects that domid is always
an HVM domain. This matches the existing callsites (and the name) and reduces
cross talk between xc and xcext.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r cdd93d37eb60 -r be3de1c0aa06 Makefile.in
--- a/Makefile.in	Wed Nov 17 09:36:35 2010 -0500
+++ b/Makefile.in	Wed Nov 17 09:36:35 2010 -0500
@@ -41,6 +41,7 @@ ifeq ($(HAVE_XEN),1)
 	$(MAKE) -C xc
 	$(MAKE) -C xb
 	$(MAKE) -C xs
+	$(MAKE) -C xcext
 	$(MAKE) -C xsrpc
 	$(MAKE) -C eventchn
 	$(MAKE) -C cpuid
@@ -81,6 +82,7 @@ ifeq ($(HAVE_XEN),1)
 	$(MAKE) -C xc install
 	$(MAKE) -C xb install
 	$(MAKE) -C xs install
+	$(MAKE) -C xcext install
 	$(MAKE) -C xsrpc install
 	$(MAKE) -C eventchn install
 	$(MAKE) -C cpuid install
@@ -122,6 +124,7 @@ ifeq ($(HAVE_XEN),1)
 	$(MAKE) -C xs uninstall
 	$(MAKE) -C xb uninstall
 	$(MAKE) -C xc uninstall
+	$(MAKE) -C xcext uninstall
 	$(MAKE) -C mmap uninstall
 	$(MAKE) -C cpuid uninstall
 	$(MAKE) -C vhd uninstall
@@ -160,6 +163,7 @@ doc:
 	$(MAKE) -C xb doc
 	$(MAKE) -C xc doc
 	$(MAKE) -C xs doc
+	$(MAKE) -C xcext doc
 	$(MAKE) -C xml-light2 doc
 	$(MAKE) -C rpc-light doc
 	$(MAKE) -C http-svr doc
@@ -208,6 +212,7 @@ cleanxen:
 	$(MAKE) -C xc clean
 	$(MAKE) -C xb clean
 	$(MAKE) -C xs clean
+	$(MAKE) -C xcext clean
 	$(MAKE) -C xsrpc clean
 	$(MAKE) -C eventchn clean
 
diff -r cdd93d37eb60 -r be3de1c0aa06 cpuid/META.in
--- a/cpuid/META.in	Wed Nov 17 09:36:35 2010 -0500
+++ b/cpuid/META.in	Wed Nov 17 09:36:35 2010 -0500
@@ -1,5 +1,5 @@
 version = "@VERSION@"
 description = "Cpuid extension"
-requires = "stdext xc xen-utils"
+requires = "stdext xc xcext xen-utils"
 archive(byte) = "cpuid.cma"
 archive(native) = "cpuid.cmxa"
diff -r cdd93d37eb60 -r be3de1c0aa06 cpuid/Makefile
--- a/cpuid/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/cpuid/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -2,7 +2,7 @@ CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include
 OCAMLC = ocamlc -g
 OCAMLOPT = ocamlopt
-INCLUDES = -I ../stdext -I ../xc -I ../xen-utils
+INCLUDES = -I ../stdext -I ../xc -I ../xcext -I ../xen-utils
 
 LDFLAGS = -cclib -L./
 
@@ -65,7 +65,7 @@ uninstall:
 
 .PHONY: doc
 doc: $(INTF)
-	python ../doc/doc.py $(DOCDIR) "cpuid" "package" "$(OBJS)" "." "stdext xc xen-utils" ""
+	python ../doc/doc.py $(DOCDIR) "cpuid" "package" "$(OBJS)" "." "stdext xc xcext xen-utils" ""
 	
 clean:
 	rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS) *~ *.rej
diff -r cdd93d37eb60 -r be3de1c0aa06 cpuid/cpuid.ml
--- a/cpuid/cpuid.ml	Wed Nov 17 09:36:35 2010 -0500
+++ b/cpuid/cpuid.ml	Wed Nov 17 09:36:35 2010 -0500
@@ -138,7 +138,7 @@ let is_maskable manufacturer family mode
 
 let get_features_from_xen () =
 	let features = 
-	  try Xc.with_intf (fun xc -> Xc.get_boot_cpufeatures xc) 
+	  try Xc.with_intf (fun xc -> Xcext.get_boot_cpufeatures xc) 
 	  with _ -> 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l 
 	in
 	match features with
diff -r cdd93d37eb60 -r be3de1c0aa06 xapi-libs.spec
--- a/xapi-libs.spec	Wed Nov 17 09:36:35 2010 -0500
+++ b/xapi-libs.spec	Wed Nov 17 09:36:35 2010 -0500
@@ -341,6 +341,14 @@ rm -rf $RPM_BUILD_ROOT
    /usr/lib/ocaml/xc/xc.cmi
    /usr/lib/ocaml/xc/xc.cmx
    /usr/lib/ocaml/xc/xc.cmxa
+   /usr/lib/ocaml/xcext/META
+   /usr/lib/ocaml/xcext/dllxcext_stubs.so
+   /usr/lib/ocaml/xcext/libxcext_stubs.a
+   /usr/lib/ocaml/xcext/xcext.a
+   /usr/lib/ocaml/xcext/xcext.cma
+   /usr/lib/ocaml/xcext/xcext.cmi
+   /usr/lib/ocaml/xcext/xcext.cmx
+   /usr/lib/ocaml/xcext/xcext.cmxa
    /usr/lib/ocaml/xs/META
    /usr/lib/ocaml/xs/queueop.cmx
    /usr/lib/ocaml/xs/xs.a
diff -r cdd93d37eb60 -r be3de1c0aa06 xc/xc.h
--- a/xc/xc.h	Wed Nov 17 09:36:35 2010 -0500
+++ b/xc/xc.h	Wed Nov 17 09:36:35 2010 -0500
@@ -31,20 +31,9 @@
 #include <xen/hvm/params.h>
 #include "xc_e820.h"
 
-#ifndef XEN_DOMCTL_get_runstate_info
-#warning "runstate info is missing"
-typedef struct {
-	int32_t state;
-	uint32_t missed_changes;
-	uint64_t state_entry_time;
-	uint64_t time[6];
-} xen_domctl_runstate_info_t;
-#endif
-
 typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
 typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
-typedef xen_domctl_runstate_info_t xc_runstate_info_t;
 
 struct xc_core_header {
 	unsigned int xch_magic;
@@ -111,14 +100,11 @@ int xc_domain_memory_populate_physmap(in
                                       unsigned int extent_order,
                                       unsigned int address_bits,
                                       xen_pfn_t *extent_start);
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist);
 int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max);
 int xc_domain_sethandle(int handle, unsigned int domid,
                         xen_domain_handle_t dhandle);
 int xc_vcpu_getinfo(int handle, unsigned int domid, unsigned int vcpu,
                     xc_vcpuinfo_t *info);
-int xc_get_runstate_info(int handle, unsigned int domid,
-			 xc_runstate_info_t *info);
 int xc_domain_ioport_permission(int handle, unsigned int domid,
                                 unsigned int first_port, unsigned int nr_ports,
                                 unsigned int allow_access);
@@ -158,7 +144,6 @@ int xc_shadow_allocation_set(int handle,
 			     uint32_t mb);
 int xc_domain_get_pfn_list(int handle, unsigned int domid,
                            xen_pfn_t *pfn_array, unsigned long max_pfns);
-int xc_hvm_check_pvdriver(int handle, unsigned int domid);
 
 int xc_domain_assign_device(int handle, unsigned int domid,
                             int domain, int bus, int slot, int func);
@@ -177,18 +162,6 @@ int xc_domain_cpuid_set(int xc, unsigned
 int xc_domain_cpuid_apply(int xc, unsigned int domid, int hvm);
 int xc_cpuid_check(uint32_t input, uint32_t optsubinput,
                    char *config[4], char *config_out[4]);
-int xc_domain_suppress_spurious_page_faults(int xc, uint32_t domid);
-
-int xc_domain_send_s3resume(int handle, unsigned int domid);
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align);
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet);
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode);
-int xc_domain_get_acpi_s_state(int handle, unsigned int domid);
-int xc_domain_trigger_power(int handle, unsigned int domid);
-int xc_domain_trigger_sleep(int handle, unsigned int domid);
-
-int xc_get_boot_cpufeatures(int handle, uint32_t *, uint32_t *, uint32_t *,
-	uint32_t *, uint32_t *, uint32_t *, uint32_t *, uint32_t *);
 
 #if XEN_SYSCTL_INTERFACE_VERSION >= 6
 #define SAFEDIV(a, b)					(((b) >= 0) ? (a) / (b) : (a))
diff -r cdd93d37eb60 -r be3de1c0aa06 xc/xc.ml
--- a/xc/xc.ml	Wed Nov 17 09:36:35 2010 -0500
+++ b/xc/xc.ml	Wed Nov 17 09:36:35 2010 -0500
@@ -26,18 +26,6 @@ type vcpuinfo =
 	cpumap: int32;
 }
 
-type runstateinfo = {
-  state : int32;
-  missed_changes: int32;
-  state_entry_time : int64;
-  time0 : int64;
-  time1 : int64;
-  time2 : int64;
-  time3 : int64;
-  time4 : int64;
-  time5 : int64;
-}
-
 type domaininfo =
 {
 	domid             : domid;
@@ -138,9 +126,6 @@ external _domain_sethandle: handle -> do
 let domain_sethandle handle n uuid =
 	_domain_sethandle handle n (Uuid.int_array_of_uuid uuid)
 
-external domain_setvmxassist: handle -> domid -> bool -> unit
-       = "stub_xc_domain_setvmxassist"
-
 external domain_max_vcpus: handle -> domid -> int -> unit
        = "stub_xc_domain_max_vcpus"
 
@@ -168,8 +153,6 @@ external domain_getinfo: handle -> domid
 
 external domain_get_vcpuinfo: handle -> int -> int -> vcpuinfo
        = "stub_xc_vcpu_getinfo"
-external domain_get_runstate_info : handle -> int -> runstateinfo
-  = "stub_xc_get_runstate_info"
 
 external domain_ioport_permission: handle -> domid -> int -> int -> bool -> unit
        = "stub_xc_domain_ioport_permission"
@@ -243,23 +226,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_suppress_spurious_page_faults: handle -> domid -> unit
-       = "stub_xc_domain_suppress_spurious_page_faults"
-
-external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit = "stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
-
-external domain_trigger_power: handle -> domid -> unit = "stub_xc_domain_trigger_power"
-external domain_trigger_sleep: handle -> domid -> unit = "stub_xc_domain_trigger_sleep"
-
-(** check if some hvm domain got pv driver or not *)
-external hvm_check_pvdriver: handle -> domid -> bool
-       = "stub_xc_hvm_check_pvdriver"
-
 external version: handle -> version = "stub_xc_version_version"
 external version_compile_info: handle -> compile_info
        = "stub_xc_version_compile_info"
@@ -270,9 +236,6 @@ external version_capabilities: handle ->
 external watchdog : handle -> int -> int32 -> int
   = "stub_xc_watchdog"
 
-external get_boot_cpufeatures: handle ->
-	(int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xc_get_boot_cpufeatures"
-
 (* core dump structure *)
 type core_magic = Magic_hvm | Magic_pv
 
diff -r cdd93d37eb60 -r be3de1c0aa06 xc/xc.mli
--- a/xc/xc.mli	Wed Nov 17 09:36:35 2010 -0500
+++ b/xc/xc.mli	Wed Nov 17 09:36:35 2010 -0500
@@ -19,17 +19,6 @@ type vcpuinfo = {
   cputime : int64;
   cpumap : int32;
 }
-type runstateinfo = {
-  state : int32;
-  missed_changes: int32;
-  state_entry_time : int64;
-  time0 : int64;
-  time1 : int64;
-  time2 : int64;
-  time3 : int64;
-  time4 : int64;
-  time5 : int64;
-}
 type domaininfo = {
   domid : domid;
   dying : bool;
@@ -89,8 +78,6 @@ val domain_create : handle -> int32 -> d
 external _domain_sethandle : handle -> domid -> int array -> unit
   = "stub_xc_domain_sethandle"
 val domain_sethandle : handle -> domid -> 'a Uuid.t -> unit
-external domain_setvmxassist: handle -> domid -> bool -> unit
-  = "stub_xc_domain_setvmxassist"
 external domain_max_vcpus : handle -> domid -> int -> unit
   = "stub_xc_domain_max_vcpus"
 external domain_pause : handle -> domid -> unit = "stub_xc_domain_pause"
@@ -107,8 +94,6 @@ external domain_getinfo : handle -> domi
   = "stub_xc_domain_getinfo"
 external domain_get_vcpuinfo : handle -> int -> int -> vcpuinfo
   = "stub_xc_vcpu_getinfo"
-external domain_get_runstate_info : handle -> int -> runstateinfo
-  = "stub_xc_get_runstate_info"
 external domain_ioport_permission: handle -> domid -> int -> int -> bool -> unit
        = "stub_xc_domain_ioport_permission"
 external domain_iomem_permission: handle -> domid -> nativeint -> nativeint -> bool -> unit
@@ -158,21 +143,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit
-  = "stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
-
-external domain_trigger_power: handle -> domid -> unit
-  = "stub_xc_domain_trigger_power"
-external domain_trigger_sleep: handle -> domid -> unit
-  = "stub_xc_domain_trigger_sleep"
-
-external hvm_check_pvdriver : handle -> domid -> bool
-  = "stub_xc_hvm_check_pvdriver"
 external version : handle -> version = "stub_xc_version_version"
 external version_compile_info : handle -> compile_info
   = "stub_xc_version_compile_info"
@@ -201,9 +171,6 @@ external domain_set_machine_address_size
 external domain_get_machine_address_size: handle -> domid -> int
        = "stub_xc_domain_get_machine_address_size"
 
-external domain_suppress_spurious_page_faults: handle -> domid -> unit
-       = "stub_xc_domain_suppress_spurious_page_faults"
-
 external domain_cpuid_set: handle -> domid -> bool -> (int64 * (int64 option))
                         -> string option array
                         -> string option array
@@ -212,7 +179,3 @@ external domain_cpuid_apply: handle -> d
        = "stub_xc_domain_cpuid_apply"
 external cpuid_check: (int64 * (int64 option)) -> string option array -> (bool * string option array)
        = "stub_xc_cpuid_check"
-
-external get_boot_cpufeatures: handle ->
-	(int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xc_get_boot_cpufeatures"
-
diff -r cdd93d37eb60 -r be3de1c0aa06 xc/xc_lib.c
--- a/xc/xc_lib.c	Wed Nov 17 09:36:35 2010 -0500
+++ b/xc/xc_lib.c	Wed Nov 17 09:36:35 2010 -0500
@@ -319,29 +319,6 @@ int xc_get_hvm_param(int handle, unsigne
 	return ret;
 }
 
-static int xc_set_hvm_param(int handle, unsigned int domid,
-                            int param, unsigned long value)
-{
-	struct xen_hvm_param arg = {
-		.domid = domid,
-		.index = param,
-		.value = value,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_set_param, (unsigned long) &arg);
-	int ret;
-
-	if (mlock(&arg, sizeof(arg)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-	munlock(&arg, sizeof(arg));
-	return ret;
-}
-
 /*---- XC API ----*/
 int xc_domain_create(int handle, unsigned int ssidref,
                      xen_domain_handle_t dhandle,
@@ -384,29 +361,6 @@ int xc_domain_unpause(int handle, unsign
 	return ret;
 }
 
-/* return 1 if hvm domain got pv driver, 0 if not. -1 is error occurs */
-int xc_hvm_check_pvdriver(int handle, unsigned int domid)
-{
-	int ret;
-	unsigned long irq = 0;
-	xc_domaininfo_t info;
-
-	ret = xc_domain_getinfolist(handle, domid, 1, &info);
-	if (ret != 1) {
-		xc_error_set("domain getinfo failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "hvm_check_pvdriver");
-		return -1;
-	}
-
-	if (!info.flags & XEN_DOMINF_hvm_guest) {
-		xc_error_set("domain is not hvm");
-		xc_error_dom_set(domid, "hvm_check_pvdriver");
-		return -1;
-	}
-	xc_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
-	return irq;
-}
-
 static int modify_returncode_register(int handle, unsigned int domid)
 {
 	int ret;
@@ -769,21 +723,6 @@ int xc_domain_memory_populate_physmap(in
 	return 0;
 }
 
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist)
-{
-	int ret = 0;
-#ifdef XEN_DOMCTL_setvmxassist
-	DECLARE_DOMCTL(XEN_DOMCTL_setvmxassist, domid);
-	domctl.u.setvmxassist.use_vmxassist = use_vmxassist;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "setting vmxassist to %d",
-				 use_vmxassist);
-#endif
-	return ret;
-}
-
 int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max)
 {
 	int ret;
@@ -825,22 +764,6 @@ int xc_vcpu_getinfo(int handle, unsigned
 	return ret;
 }
 
-int xc_get_runstate_info(int handle, unsigned int domid,
-			 xc_runstate_info_t *info)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_get_runstate_info
-	DECLARE_DOMCTL(XEN_DOMCTL_get_runstate_info, domid);
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0) {
-		xc_error_dom_set(domid, "get runstate info");
-		return ret;
-	}
-	memcpy(info, &domctl.u.domain_runstate, sizeof(*info));
-#endif
-	return ret;
-}
-
 int xc_domain_ioport_permission(int handle, unsigned int domid,
                                 unsigned int first_port, unsigned int nr_ports,
                                 unsigned int allow_access)
@@ -1515,119 +1438,6 @@ out:
 	return ret;
 }
 
-#ifndef HVM_PARAM_HPET_ENABLED
-#define HVM_PARAM_HPET_ENABLED 11
-#endif
-
-#ifndef HVM_PARAM_ACPI_S_STATE
-#define HVM_PARAM_ACPI_S_STATE 14
-#endif
-
-#ifndef HVM_PARAM_VPT_ALIGN
-#define HVM_PARAM_VPT_ALIGN 16
-#endif
-
-int xc_domain_send_s3resume(int handle, unsigned int domid)
-{
-	#define HVM_PARAM_ACPI_S_STATE 14
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 0);
-}
-
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode)
-{
-	return xc_set_hvm_param(handle, domid,
-	                        HVM_PARAM_TIMER_MODE, (unsigned long) mode);
-}
-
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) hpet);
-}
-
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) vpt_align);
-}
-
-int xc_domain_get_acpi_s_state(int handle, unsigned int domid)
-{
-	int ret;
-	unsigned long value;
-
-	ret = xc_get_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, &value);
-	if (ret != 0)
-		xc_error_dom_set(domid, "get acpi s-state");
-	return value;
-}
-
-int xc_domain_suppress_spurious_page_faults(int xc, uint32_t domid)
-{
-	int rc = 0;
-#ifdef XEN_DOMCTL_suppress_spurious_page_faults
-	DECLARE_DOMCTL(XEN_DOMCTL_suppress_spurious_page_faults, domid);
-
-	rc = do_domctl(xc, &domctl);
-	if (rc != 0)
-		xc_error_dom_set(domid, "suppress spurious page faults");
-#endif
-	return rc;
-}
-
-int xc_domain_trigger_power(int handle, unsigned int domid)
-{
-    int ret;
-
-    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
-    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_POWER;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_set("power button failed: %s", xc_error_get());
-    return ret;
-}
-
-int xc_domain_trigger_sleep(int handle, unsigned int domid)
-{
-    int ret;
-
-    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
-    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_SLEEP;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_set("sleep button failed: %s", xc_error_get());
-    return ret;
-}
-
-int xc_get_boot_cpufeatures(int handle,
-                            uint32_t *base_ecx, uint32_t *base_edx,
-                            uint32_t *ext_ecx, uint32_t *ext_edx,
-                            uint32_t *masked_base_ecx, 
-                            uint32_t *masked_base_edx,
-                            uint32_t *masked_ext_ecx, 
-                            uint32_t *masked_ext_edx)
-{
-	int ret = -EINVAL;
-#ifdef XENPF_get_cpu_features 
-	DECLARE_PLATFORM(XENPF_get_cpu_features);
-
-	ret = do_platform(handle, &platform);
-	if (ret != 0)
-		xc_error_set("getting boot cpu features failed: %s", xc_error_get());
-	else {
-		*base_ecx = platform.u.cpu_features.base_ecx;
-		*base_edx = platform.u.cpu_features.base_edx;
-		*ext_ecx = platform.u.cpu_features.ext_ecx;
-		*ext_edx = platform.u.cpu_features.ext_edx;
-		*masked_base_ecx = platform.u.cpu_features.masked_base_ecx;
-		*masked_base_edx = platform.u.cpu_features.masked_base_edx;
-		*masked_ext_ecx = platform.u.cpu_features.masked_ext_ecx;
-		*masked_ext_edx = platform.u.cpu_features.masked_ext_edx;
-	}
-#endif
-	return ret;
-}
-
 /*
  * Local variables:
  *  indent-tabs-mode: t
diff -r cdd93d37eb60 -r be3de1c0aa06 xc/xc_stubs.c
--- a/xc/xc_stubs.c	Wed Nov 17 09:36:35 2010 -0500
+++ b/xc/xc_stubs.c	Wed Nov 17 09:36:35 2010 -0500
@@ -174,20 +174,6 @@ CAMLprim value stub_xc_domain_create(val
 	CAMLreturn(Val_int(domid));
 }
 
-CAMLprim value stub_xc_domain_setvmxassist(value xc_handle, value domid,
-					    value use_vmxassist)
-{
-	CAMLparam3(xc_handle, domid, use_vmxassist);
-	int r;
-
-	r = xc_domain_setvmxassist(_H(xc_handle), _D(domid),
-				   Bool_val(use_vmxassist));
-	if (r)
-		failwith_xc();
-
-	CAMLreturn(Val_unit);
-}
-
 CAMLprim value stub_xc_domain_max_vcpus(value xc_handle, value domid,
                                         value max_vcpus)
 {
@@ -387,41 +373,6 @@ CAMLprim value stub_xc_vcpu_getinfo(valu
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_get_runstate_info(value xc_handle, value domid) 
-{
-	CAMLparam2(xc_handle, domid);
-	CAMLlocal1(result);
-	xc_runstate_info_t info;
-	int retval;
-	
-	int c_xc_handle = _H(xc_handle);
-	uint32_t c_domid = _D(domid);
-	retval = xc_get_runstate_info(c_xc_handle, c_domid, &info);
-	if (retval < 0)
-		failwith_xc();
-
-	/* Store 
-	   0 : state (int32)
-	   1 : missed_changes (int32)
-	   2 : state_entry_time (int64)
-	   3-8 : times (int64s)
-	*/
-	result = caml_alloc_tuple(9);
-	Store_field(result, 0, caml_copy_int32(info.state));
-	Store_field(result, 1, caml_copy_int32(info.missed_changes));
-	Store_field(result, 2, caml_copy_int64(info.state_entry_time));
-	Store_field(result, 3, caml_copy_int64(info.time[0]));
-	Store_field(result, 4, caml_copy_int64(info.time[1]));
-	Store_field(result, 5, caml_copy_int64(info.time[2]));
-	Store_field(result, 6, caml_copy_int64(info.time[3]));
-	Store_field(result, 7, caml_copy_int64(info.time[4]));
-	Store_field(result, 8, caml_copy_int64(info.time[5]));
-
-	CAMLreturn(result);
-}
-
-
-
 CAMLprim value stub_xc_vcpu_context_get(value xc_handle, value domid,
                                         value cpu)
 {
@@ -697,19 +648,6 @@ CAMLprim value stub_xc_domain_get_machin
 	CAMLreturn(Val_int(retval));
 }
 
-CAMLprim value stub_xc_domain_suppress_spurious_page_faults(value xc_handle,
-						       value domid)
-{
-	CAMLparam2(xc_handle, domid);
-	int c_xc_handle = _H(xc_handle);
-	uint32_t c_domid = _D(domid);
-
-	int retval = xc_domain_suppress_spurious_page_faults(c_xc_handle, c_domid);
-	if (retval)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
 CAMLprim value stub_xc_domain_cpuid_set(value xc_handle, value domid,
                                         value is_hvm, value input,
                                         value config)
@@ -1080,17 +1018,6 @@ CAMLprim value stub_xc_domain_irq_permis
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_hvm_check_pvdriver(value xc_handle, value domid)
-{
-	CAMLparam2(xc_handle, domid);
-	int ret;
-
-	ret = xc_hvm_check_pvdriver(_H(xc_handle), _D(domid));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_bool(ret));
-}
-
 CAMLprim value stub_xc_domain_test_assign_device(value xc_handle, value domid, value desc)
 {
 	CAMLparam3(xc_handle, domid, desc);
@@ -1156,97 +1083,6 @@ CAMLprim value stub_xc_watchdog(value ha
 	CAMLreturn(Val_int(ret));
 }
 
-CAMLprim value stub_xc_domain_get_acpi_s_state(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	int ret;
-
-	ret = xc_domain_get_acpi_s_state(_H(handle), _D(domid));
-	if (ret < 0)
-		failwith_xc();
-
-	CAMLreturn(Val_int(ret));
-}
-
-CAMLprim value stub_xc_domain_send_s3resume(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	xc_domain_send_s3resume(_H(handle), _D(domid));
-	CAMLreturn(Val_unit);
-}
-
-
-CAMLprim value stub_xc_domain_set_timer_mode(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_timer_mode(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_hpet(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_hpet(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_vpt_align(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_vpt_align(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_trigger_power(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	xc_domain_trigger_power(_H(handle), _D(domid));
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_trigger_sleep(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	xc_domain_trigger_sleep(_H(handle), _D(domid));
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_get_boot_cpufeatures(value handle)
-{
-	CAMLparam1(handle);
-	CAMLlocal1(v);
-	uint32_t a, b, c, d, e, f, g, h;
-	int ret;
-
-	ret = xc_get_boot_cpufeatures(_H(handle), &a, &b, &c, &d, &e, &f, &g, &h);
-	if (ret < 0)
-		failwith_xc();
-	
-	v = caml_alloc_tuple(8);
-	Store_field(v, 0, caml_copy_int32(a));
-	Store_field(v, 1, caml_copy_int32(b));
-	Store_field(v, 2, caml_copy_int32(c));
-	Store_field(v, 3, caml_copy_int32(d));
-	Store_field(v, 4, caml_copy_int32(e));
-	Store_field(v, 5, caml_copy_int32(f));
-	Store_field(v, 6, caml_copy_int32(g));
-	Store_field(v, 7, caml_copy_int32(h));
-
-	CAMLreturn(v);
-}
-
 /*
  * Local variables:
  *  indent-tabs-mode: t
diff -r cdd93d37eb60 -r be3de1c0aa06 xcext/META.in
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/META.in	Wed Nov 17 09:36:35 2010 -0500
@@ -0,0 +1,5 @@
+version = "@VERSION@"
+description = "Xen Control Interface (extensions)"
+requires = "mmap,uuid,xc"
+archive(byte) = "xcext.cma"
+archive(native) = "xcext.cmxa"
diff -r cdd93d37eb60 -r be3de1c0aa06 xcext/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -0,0 +1,71 @@
+CC = gcc
+CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap -I./
+OCAMLC = ocamlc -g -I ../mmap -I ../uuid -I ../xc
+OCAMLOPT = ocamlopt
+OCAMLOPTFLAGS = -g -dtypes -I ../mmap -I ../uuid -I ../xc
+
+LDFLAGS = -cclib -L./
+
+VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0)
+
+OCAMLABI := $(shell ocamlc -version)
+OCAMLLIBDIR := $(shell ocamlc -where)
+OCAMLDESTDIR ?= $(OCAMLLIBDIR)
+
+OBJS = xcext
+INTF = xcext.cmi
+LIBS = xcext.cma xcext.cmxa
+
+DOCDIR = /myrepos/xen-api-libs.hg/doc
+
+all: $(INTF) $(LIBS) $(PROGRAMS)
+
+bins: $(PROGRAMS)
+
+libs: $(LIBS)
+
+xcext.cmxa: libxcext_stubs.a $(foreach obj,$(OBJS),$(obj).cmx)
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ -cclib -lxcext_stubs $(foreach obj,$(OBJS),$(obj).cmx)
+
+xcext.cma: $(foreach obj,$(OBJS),$(obj).cmo)
+	$(OCAMLC) -a -dllib dllxcext_stubs.so -cclib -lxcext_stubs -o $@ $(foreach obj,$(OBJS),$(obj).cmo)
+
+xcext_stubs.a: xcext_lib.o xcext_stubs.o
+	ocamlmklib -o xcext_stubs $+
+
+libxcext_stubs.a: xcext_lib.o xcext_stubs.o
+	ar rcs $@ $+
+	ocamlmklib -o xcext_stubs $+
+
+%.cmo: %.ml
+	$(OCAMLC) -c -o $@ $<
+
+%.cmi: %.mli
+	$(OCAMLC) -c -o $@ $<
+
+%.cmx: %.ml
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c -o $@ $<
+
+%.o: %.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+META: META.in
+	sed 's/@VERSION@/$(VERSION)/g' < $< > $@
+
+.PHONY: install
+install: path = $(DESTDIR)$(shell ocamlfind printconf destdir)
+install: $(LIBS) META
+	mkdir -p $(path)
+	ocamlfind install -destdir $(path) -ldconf ignore xcext META $(INTF) $(LIBS) *.a *.so *.cmx
+
+.PHONY: uninstall
+uninstall:
+	ocamlfind remove xcext
+
+.PHONY: doc
+doc: $(INTF)
+	python ../doc/doc.py $(DOCDIR) "xcext" "package" "$(OBJS)" "." "mmap,uuid" ""
+	
+clean:
+	rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS) $(INTF) *~ *.rej *.orig
+
diff -r cdd93d37eb60 -r be3de1c0aa06 xcext/xcext.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext.h	Wed Nov 17 09:36:35 2010 -0500
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#define __XEN_TOOLS__
+
+#include <xen/xen.h>
+#include <xen/memory.h>
+#include <xen/sysctl.h>
+#include <xen/domctl.h>
+#include <xen/sched.h>
+#include <xen/platform.h>
+#if XEN_SYSCTL_INTERFACE_VERSION < 4
+#include <xen/linux/privcmd.h>
+#else
+#include <xen/sys/privcmd.h>
+#endif
+#include <xen/version.h>
+#include <xen/foreign/x86_32.h>
+#include <xen/foreign/x86_64.h>
+#include <xen/hvm/params.h>
+
+#ifndef XEN_DOMCTL_get_runstate_info
+#warning "runstate info is missing"
+typedef struct {
+	int32_t state;
+	uint32_t missed_changes;
+	uint64_t state_entry_time;
+	uint64_t time[6];
+} xen_domctl_runstate_info_t;
+#endif
+
+typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
+typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
+typedef xen_sysctl_physinfo_t xc_physinfo_t;
+typedef xen_domctl_runstate_info_t xc_runstate_info_t;
+
+char * xcext_error_get(void);
+void xcext_error_clear(void);
+
+int xcext_using_injection(void);
+
+int xcext_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist);
+int xcext_get_runstate_info(int handle, unsigned int domid,
+			 xc_runstate_info_t *info);
+
+int xcext_hvm_check_pvdriver(int handle, unsigned int domid);
+
+int xcext_domain_suppress_spurious_page_faults(int xc, uint32_t domid);
+
+int xcext_domain_send_s3resume(int handle, unsigned int domid);
+int xcext_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align);
+int xcext_domain_set_hpet(int handle, unsigned int domid, int hpet);
+int xcext_domain_set_timer_mode(int handle, unsigned int domid, int mode);
+int xcext_domain_get_acpi_s_state(int handle, unsigned int domid);
+int xcext_domain_trigger_power(int handle, unsigned int domid);
+int xcext_domain_trigger_sleep(int handle, unsigned int domid);
+
+int xcext_get_boot_cpufeatures(int handle, uint32_t *, uint32_t *, uint32_t *,
+	uint32_t *, uint32_t *, uint32_t *, uint32_t *, uint32_t *);
diff -r cdd93d37eb60 -r be3de1c0aa06 xcext/xcext.ml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext.ml	Wed Nov 17 09:36:35 2010 -0500
@@ -0,0 +1,52 @@
+(*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+type runstateinfo = {
+  state : int32;
+  missed_changes: int32;
+  state_entry_time : int64;
+  time0 : int64;
+  time1 : int64;
+  time2 : int64;
+  time3 : int64;
+  time4 : int64;
+  time5 : int64;
+}
+
+
+external domain_setvmxassist: Xc.handle -> Xc.domid -> bool -> unit
+       = "stub_xcext_domain_setvmxassist"
+
+external domain_get_runstate_info : Xc.handle -> int -> runstateinfo
+       = "stub_xcext_get_runstate_info"
+ 
+external domain_suppress_spurious_page_faults: Xc.handle -> Xc.domid -> unit
+       = "stub_xcext_domain_suppress_spurious_page_faults"
+
+external domain_set_timer_mode: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_timer_mode"
+external domain_set_hpet: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_hpet"
+external domain_set_vpt_align: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_vpt_align"
+
+external domain_send_s3resume: Xc.handle -> Xc.domid -> unit = "stub_xcext_domain_send_s3resume"
+external domain_get_acpi_s_state: Xc.handle -> Xc.domid -> int = "stub_xcext_domain_get_acpi_s_state"
+
+external domain_trigger_power: Xc.handle -> Xc.domid -> unit = "stub_xcext_domain_trigger_power"
+external domain_trigger_sleep: Xc.handle -> Xc.domid -> unit = "stub_xcext_domain_trigger_sleep"
+
+(** check if some hvm domain got pv driver or not *)
+external hvm_check_pvdriver: Xc.handle -> Xc.domid -> bool
+       = "stub_xcext_hvm_check_pvdriver"
+
+external get_boot_cpufeatures: Xc.handle ->
+	(int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xcext_get_boot_cpufeatures"
diff -r cdd93d37eb60 -r be3de1c0aa06 xcext/xcext.mli
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext.mli	Wed Nov 17 09:36:35 2010 -0500
@@ -0,0 +1,55 @@
+(*
+ * Copyright (C) 2006-2010 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+type runstateinfo = {
+  state : int32;
+  missed_changes: int32;
+  state_entry_time : int64;
+  time0 : int64;
+  time1 : int64;
+  time2 : int64;
+  time3 : int64;
+  time4 : int64;
+  time5 : int64;
+}
+
+external domain_setvmxassist: Xc.handle -> Xc.domid -> bool -> unit
+  = "stub_xcext_domain_setvmxassist"
+
+external domain_get_runstate_info : Xc.handle -> int -> runstateinfo
+  = "stub_xcext_get_runstate_info"
+
+external domain_set_timer_mode: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_timer_mode"
+external domain_set_hpet: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_hpet"
+external domain_set_vpt_align: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_vpt_align"
+
+external domain_send_s3resume: Xc.handle -> Xc.domid -> unit
+  = "stub_xcext_domain_send_s3resume"
+external domain_get_acpi_s_state: Xc.handle -> Xc.domid -> int
+  = "stub_xcext_domain_get_acpi_s_state"
+
+external domain_trigger_power: Xc.handle -> Xc.domid -> unit
+  = "stub_xcext_domain_trigger_power"
+external domain_trigger_sleep: Xc.handle -> Xc.domid -> unit
+  = "stub_xcext_domain_trigger_sleep"
+
+external hvm_check_pvdriver : Xc.handle -> Xc.domid -> bool
+  = "stub_xcext_hvm_check_pvdriver"
+
+external domain_suppress_spurious_page_faults: Xc.handle -> Xc.domid -> unit
+       = "stub_xcext_domain_suppress_spurious_page_faults"
+
+external get_boot_cpufeatures: Xc.handle ->
+	(int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xcext_get_boot_cpufeatures"
+
diff -r cdd93d37eb60 -r be3de1c0aa06 xcext/xcext_lib.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext_lib.c	Wed Nov 17 09:36:35 2010 -0500
@@ -0,0 +1,372 @@
+/*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include <stdint.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "xcext.h"
+
+#define PAGE_SHIFT		12
+#define PAGE_SIZE               (1UL << PAGE_SHIFT)
+#define PAGE_MASK               (~(PAGE_SIZE-1))
+
+#define MIN(a, b) 		(((a) < (b)) ? (a) : (b))
+
+#define DECLARE_DOMCTL(_cmd, _domain)	\
+	struct xen_domctl domctl = {    \
+		.cmd = _cmd,		\
+		.domain = _domain,	\
+		.interface_version = XEN_DOMCTL_INTERFACE_VERSION, \
+	}
+
+#define DECLARE_PLATFORM(_cmd)		\
+	struct xen_platform_op platform = { \
+		.cmd = _cmd,		\
+		.interface_version = XENPF_INTERFACE_VERSION, \
+	}
+
+#define DECLARE_HYPERCALL2(_cmd, _arg0, _arg1)	\
+	privcmd_hypercall_t hypercall = {	\
+		.op = _cmd,			\
+		.arg[0] = (unsigned long) _arg0,\
+		.arg[1] = (unsigned long) _arg1,\
+	}
+#define DECLARE_HYPERCALL0(_cmd)	DECLARE_HYPERCALL2(_cmd, 0, 0);
+#define DECLARE_HYPERCALL1(_cmd, _arg0)	DECLARE_HYPERCALL2(_cmd, _arg0, 0);
+
+/*---- Errors handlings ----*/
+#ifndef WITHOUT_GOOD_ERROR
+#define ERROR_STRLEN 256
+
+static char __error_str[ERROR_STRLEN];
+
+char * xcext_error_get(void)
+{
+	return __error_str;
+}
+
+static void xcext_error_set(const char *fmt, ...)
+{
+	va_list ap;
+	char __errordup[ERROR_STRLEN];
+
+	va_start(ap, fmt);
+	vsnprintf(__errordup, ERROR_STRLEN, fmt, ap);
+	va_end(ap);
+	memcpy(__error_str, __errordup, ERROR_STRLEN);
+}
+
+static void xcext_error_dom_set(unsigned int domid, const char *fmt, ...)
+{
+	va_list ap;
+	char __errordup[ERROR_STRLEN];
+	int i;
+
+	i = snprintf(__errordup, ERROR_STRLEN, "domain %u - ", domid);
+	va_start(ap, fmt);
+	i += vsnprintf(__errordup + i, ERROR_STRLEN - i, fmt, ap);
+	va_end(ap);
+	snprintf(__errordup + i, ERROR_STRLEN - i,
+	         " failed: %s", xcext_error_get());
+	memcpy(__error_str, __errordup, ERROR_STRLEN);
+}
+
+void xcext_error_clear(void)
+{
+	memset(__error_str, '\0', ERROR_STRLEN);
+}
+#else
+char * xcext_error_get(void)
+{
+	return "";
+}
+#define xcext_error_set(fmt, ...) do {} while (0)
+#define xcext_error_dom_set(id, fmt, ...) do {} while (0)
+#define xcext_error_clear() do {} while (0)
+#endif
+
+#define xcext_error_hypercall(_h, _r) \
+	xcext_error_set("hypercall %lld fail: %d: %s (ret %d)", _h.op, errno, errno ? strerror(errno) : strerror(-_r), _r)
+
+#define WITH_INJECTION_CAPABILITY
+#include "../xc/xc_lib_injection.c"
+
+
+/*---- Low private operations ----*/
+static int do_xen_hypercall(int handle, privcmd_hypercall_t *hypercall)
+{
+	pre_xen_hypercall(handle, hypercall);
+	return ioctl(handle, IOCTL_PRIVCMD_HYPERCALL, (unsigned long) hypercall);
+}
+
+static int do_domctl(int handle, struct xen_domctl *domctl)
+{
+	int ret;
+	DECLARE_HYPERCALL1(__HYPERVISOR_domctl, domctl);
+
+	if (mlock(domctl, sizeof(*domctl)) != 0) {
+		xcext_error_set("mlock failed: %s", strerror(errno));
+		return -1;
+	}
+
+	ret = do_xen_hypercall(handle, &hypercall);
+	if (ret < 0)
+		xcext_error_hypercall(hypercall, ret);
+
+	munlock(domctl, sizeof(*domctl));
+	return ret;
+}
+
+static int do_platform(int handle, struct xen_platform_op *platform)
+{
+	int ret;
+	DECLARE_HYPERCALL1(__HYPERVISOR_platform_op, platform);
+
+	if (mlock(platform, sizeof(*platform)) != 0) {
+		xcext_error_set("mlock failed: %s", strerror(errno));
+		return -1;
+	}
+
+	ret = do_xen_hypercall(handle, &hypercall);
+	if (ret < 0)
+		xcext_error_hypercall(hypercall, ret);
+
+	munlock(platform, sizeof(*platform));
+	return ret;
+}
+
+int xcext_get_hvm_param(int handle, unsigned int domid,
+                     int param, unsigned long *value)
+{
+	struct xen_hvm_param arg = {
+		.domid = domid,
+		.index = param,
+	};
+	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_get_param,
+	                   (unsigned long) &arg);
+	int ret;
+
+	if (mlock(&arg, sizeof(arg)) == -1) {
+		xcext_error_set("mlock failed: %s", strerror(errno));
+		return -1;
+	}
+
+	ret = do_xen_hypercall(handle, &hypercall);
+	if (ret)
+		xcext_error_hypercall(hypercall, ret);
+	*value = arg.value;
+	munlock(&arg, sizeof(arg));
+	return ret;
+}
+
+/* return 1 if hvm domain got pv driver, 0 if not. -1 is error occurs */
+int xcext_hvm_check_pvdriver(int handle, unsigned int domid)
+{
+	int ret;
+	unsigned long irq = 0;
+
+	ret = xcext_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
+	if (!ret) {
+		xcext_error_dom_set(domid, "hvm_check_pvdriver");
+		return -1;
+	}
+	return irq;
+}
+
+int xcext_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist)
+{
+	int ret = 0;
+#ifdef XEN_DOMCTL_setvmxassist
+	DECLARE_DOMCTL(XEN_DOMCTL_setvmxassist, domid);
+	domctl.u.setvmxassist.use_vmxassist = use_vmxassist;
+
+	ret = do_domctl(handle, &domctl);
+	if (ret)
+		xcext_error_dom_set(domid, "setting vmxassist to %d",
+				 use_vmxassist);
+#endif
+	return ret;
+}
+
+
+int xcext_get_runstate_info(int handle, unsigned int domid,
+			 xc_runstate_info_t *info)
+{
+	int ret = -EBADF;
+#ifdef XEN_DOMCTL_get_runstate_info
+	DECLARE_DOMCTL(XEN_DOMCTL_get_runstate_info, domid);
+	ret = do_domctl(handle, &domctl);
+	if (ret < 0) {
+		xcext_error_dom_set(domid, "get runstate info");
+		return ret;
+	}
+	memcpy(info, &domctl.u.domain_runstate, sizeof(*info));
+#endif
+	return ret;
+}
+
+
+#ifndef HVM_PARAM_HPET_ENABLED
+#define HVM_PARAM_HPET_ENABLED 11
+#endif
+
+#ifndef HVM_PARAM_ACPI_S_STATE
+#define HVM_PARAM_ACPI_S_STATE 14
+#endif
+
+#ifndef HVM_PARAM_VPT_ALIGN
+#define HVM_PARAM_VPT_ALIGN 16
+#endif
+
+static int xcext_set_hvm_param(int handle, unsigned int domid,
+			       int param, unsigned long value)
+{
+	struct xen_hvm_param arg = {
+		.domid = domid,
+		.index = param,
+		.value = value,
+	};
+	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_set_param, (unsigned long) &arg);
+	int ret;
+
+	if (mlock(&arg, sizeof(arg)) == -1) {
+		xcext_error_set("mlock failed: %s", strerror(errno));
+		return -1;
+	}
+
+	ret = do_xen_hypercall(handle, &hypercall);
+	if (ret)
+		xcext_error_hypercall(hypercall, ret);
+	munlock(&arg, sizeof(arg));
+	return ret;
+}
+
+int xcext_domain_send_s3resume(int handle, unsigned int domid)
+{
+	#define HVM_PARAM_ACPI_S_STATE 14
+	return xcext_set_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 0);
+}
+
+int xcext_domain_set_timer_mode(int handle, unsigned int domid, int mode)
+{
+	return xcext_set_hvm_param(handle, domid,
+	                        HVM_PARAM_TIMER_MODE, (unsigned long) mode);
+}
+
+int xcext_domain_set_hpet(int handle, unsigned int domid, int hpet)
+{
+	return xcext_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) hpet);
+}
+
+int xcext_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align)
+{
+	return xcext_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) vpt_align);
+}
+
+int xcext_domain_get_acpi_s_state(int handle, unsigned int domid)
+{
+	int ret;
+	unsigned long value;
+
+	ret = xcext_get_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, &value);
+	if (ret != 0)
+		xcext_error_dom_set(domid, "get acpi s-state");
+	return value;
+}
+
+int xcext_domain_suppress_spurious_page_faults(int xc, uint32_t domid)
+{
+	int rc = 0;
+#ifdef XEN_DOMCTL_suppress_spurious_page_faults
+	DECLARE_DOMCTL(XEN_DOMCTL_suppress_spurious_page_faults, domid);
+
+	rc = do_domctl(xc, &domctl);
+	if (rc != 0)
+		xcext_error_dom_set(domid, "suppress spurious page faults");
+#endif
+	return rc;
+}
+
+int xcext_domain_trigger_power(int handle, unsigned int domid)
+{
+    int ret;
+
+    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
+    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_POWER;
+
+	ret = do_domctl(handle, &domctl);
+	if (ret != 0)
+		xcext_error_set("power button failed: %s", xcext_error_get());
+    return ret;
+}
+
+int xcext_domain_trigger_sleep(int handle, unsigned int domid)
+{
+    int ret;
+
+    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
+    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_SLEEP;
+
+	ret = do_domctl(handle, &domctl);
+	if (ret != 0)
+		xcext_error_set("sleep button failed: %s", xcext_error_get());
+    return ret;
+}
+
+int xcext_get_boot_cpufeatures(int handle,
+                            uint32_t *base_ecx, uint32_t *base_edx,
+                            uint32_t *ext_ecx, uint32_t *ext_edx,
+                            uint32_t *masked_base_ecx, 
+                            uint32_t *masked_base_edx,
+                            uint32_t *masked_ext_ecx, 
+                            uint32_t *masked_ext_edx)
+{
+	int ret = -EINVAL;
+#ifdef XENPF_get_cpu_features 
+	DECLARE_PLATFORM(XENPF_get_cpu_features);
+
+	ret = do_platform(handle, &platform);
+	if (ret != 0)
+		xcext_error_set("getting boot cpu features failed: %s", xcext_error_get());
+	else {
+		*base_ecx = platform.u.cpu_features.base_ecx;
+		*base_edx = platform.u.cpu_features.base_edx;
+		*ext_ecx = platform.u.cpu_features.ext_ecx;
+		*ext_edx = platform.u.cpu_features.ext_edx;
+		*masked_base_ecx = platform.u.cpu_features.masked_base_ecx;
+		*masked_base_edx = platform.u.cpu_features.masked_base_edx;
+		*masked_ext_ecx = platform.u.cpu_features.masked_ext_ecx;
+		*masked_ext_edx = platform.u.cpu_features.masked_ext_edx;
+	}
+#endif
+	return ret;
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: t
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */
diff -r cdd93d37eb60 -r be3de1c0aa06 xcext/xcext_stubs.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext_stubs.c	Wed Nov 17 09:36:35 2010 -0500
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2006-2010 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#define _XOPEN_SOURCE 600
+#include <stdlib.h>
+
+#define CAML_NAME_SPACE
+#include <caml/alloc.h>
+#include <caml/memory.h>
+#include <caml/signals.h>
+#include <caml/fail.h>
+#include <caml/callback.h>
+
+#include <sys/mman.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "xcext.h"
+
+#define _H(__h) (Int_val(__h))
+#define _D(__d) ((uint32_t)Int_val(__d))
+
+void failwith_xcext(void)
+{
+	caml_raise_with_string(*caml_named_value("xc.error"), xcext_error_get());
+}
+
+CAMLprim value stub_xcext_domain_setvmxassist(value xc_handle, value domid,
+					    value use_vmxassist)
+{
+	CAMLparam3(xc_handle, domid, use_vmxassist);
+	int r;
+
+	r = xcext_domain_setvmxassist(_H(xc_handle), _D(domid),
+				   Bool_val(use_vmxassist));
+	if (r)
+		failwith_xcext();
+
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_get_runstate_info(value xc_handle, value domid) {
+
+	CAMLparam2(xc_handle, domid);
+	CAMLlocal1(result);
+	xc_runstate_info_t info;
+	int retval;
+
+	int c_xc_handle = _H(xc_handle);
+	uint32_t c_domid = _D(domid);
+	retval = xcext_get_runstate_info(c_xc_handle, c_domid, &info);
+	if (retval < 0)
+	        failwith_xcext();
+
+	/* Store
+	   0 : state (int32)
+	   1 : missed_changes (int32)
+	   2 : state_entry_time (int64)
+	   3-8 : times (int64s)
+	*/
+	result = caml_alloc_tuple(9);
+	Store_field(result, 0, caml_copy_int32(info.state));
+	Store_field(result, 1, caml_copy_int32(info.missed_changes));
+	Store_field(result, 2, caml_copy_int64(info.state_entry_time));
+	Store_field(result, 3, caml_copy_int64(info.time[0]));
+	Store_field(result, 4, caml_copy_int64(info.time[1]));
+	Store_field(result, 5, caml_copy_int64(info.time[2]));
+	Store_field(result, 6, caml_copy_int64(info.time[3]));
+	Store_field(result, 7, caml_copy_int64(info.time[4]));
+	Store_field(result, 8, caml_copy_int64(info.time[5]));
+
+	CAMLreturn(result);
+}
+
+CAMLprim value stub_xcext_domain_suppress_spurious_page_faults(value xc_handle,
+						       value domid)
+{
+	CAMLparam2(xc_handle, domid);
+	int c_xc_handle = _H(xc_handle);
+	uint32_t c_domid = _D(domid);
+
+	int retval = xcext_domain_suppress_spurious_page_faults(c_xc_handle, c_domid);
+	if (retval)
+		failwith_xcext();
+	CAMLreturn(Val_unit);
+}
+
+
+CAMLprim value stub_xcext_hvm_check_pvdriver(value xc_handle, value domid)
+{
+	CAMLparam2(xc_handle, domid);
+	int ret;
+
+	ret = xcext_hvm_check_pvdriver(_H(xc_handle), _D(domid));
+	if (ret < 0)
+		failwith_xcext();
+	CAMLreturn(Val_bool(ret));
+}
+
+
+CAMLprim value stub_xcext_domain_get_acpi_s_state(value handle, value domid)
+{
+	CAMLparam2(handle, domid);
+	int ret;
+
+	ret = xcext_domain_get_acpi_s_state(_H(handle), _D(domid));
+	if (ret < 0)
+		failwith_xc();
+
+	CAMLreturn(Val_int(ret));
+}
+
+
+CAMLprim value stub_xcext_domain_send_s3resume(value handle, value domid)
+{
+	CAMLparam2(handle, domid);
+	xcext_domain_send_s3resume(_H(handle), _D(domid));
+	CAMLreturn(Val_unit);
+}
+
+
+CAMLprim value stub_xcext_domain_set_timer_mode(value handle, value id, value mode)
+{
+	CAMLparam3(handle, id, mode);
+	int ret;
+
+	ret = xcext_domain_set_timer_mode(_H(handle), _D(id), Int_val(mode));
+	if (ret < 0)
+		failwith_xcext();
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_set_hpet(value handle, value id, value mode)
+{
+	CAMLparam3(handle, id, mode);
+	int ret;
+
+	ret = xcext_domain_set_hpet(_H(handle), _D(id), Int_val(mode));
+	if (ret < 0)
+		failwith_xcext();
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_set_vpt_align(value handle, value id, value mode)
+{
+	CAMLparam3(handle, id, mode);
+	int ret;
+
+	ret = xcext_domain_set_vpt_align(_H(handle), _D(id), Int_val(mode));
+	if (ret < 0)
+		failwith_xcext();
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_trigger_power(value handle, value domid)
+{
+	CAMLparam2(handle, domid);
+	xcext_domain_trigger_power(_H(handle), _D(domid));
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_trigger_sleep(value handle, value domid)
+{
+	CAMLparam2(handle, domid);
+	xcext_domain_trigger_sleep(_H(handle), _D(domid));
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_get_boot_cpufeatures(value handle)
+{
+	CAMLparam1(handle);
+	CAMLlocal1(v);
+	uint32_t a, b, c, d, e, f, g, h;
+	int ret;
+
+	ret = xcext_get_boot_cpufeatures(_H(handle), &a, &b, &c, &d, &e, &f, &g, &h);
+	if (ret < 0)
+		failwith_xcext();
+
+	v = caml_alloc_tuple(8);
+	Store_field(v, 0, caml_copy_int32(a));
+	Store_field(v, 1, caml_copy_int32(b));
+	Store_field(v, 2, caml_copy_int32(c));
+	Store_field(v, 3, caml_copy_int32(d));
+	Store_field(v, 4, caml_copy_int32(e));
+	Store_field(v, 5, caml_copy_int32(f));
+	Store_field(v, 6, caml_copy_int32(g));
+	Store_field(v, 7, caml_copy_int32(h));
+
+	CAMLreturn(v);
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: t
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 3 of 4] add configure-time option to use system installed Xen library bindings
  2010-11-18 10:50   ` [PATCH 0 of 4] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
       [not found]     ` <patchbomb.1290077414-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 10:50     ` Ian Campbell
  2010-11-18 10:50     ` [PATCH 4 of 4] REBASE-4.1: default to using system installed bindings if Xen is available Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290004595 18000
# Node ID 83a3a9308e561806013a111a58f65991d37b9c17
# Parent  be3de1c0aa0687ef9fa6ad2ac5cfa1a74fb14484
add configure-time option to use system installed Xen library bindings.

Could be made to auto detect the Xen version but for now requires the user to
explicitly opt in.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r be3de1c0aa06 -r 83a3a9308e56 Makefile.in
--- a/Makefile.in	Wed Nov 17 09:36:35 2010 -0500
+++ b/Makefile.in	Wed Nov 17 09:36:35 2010 -0500
@@ -5,9 +5,13 @@ HAVE_LINUX_CDROM = @LINUX_CDROM@
 HAVE_XMLM = @OCAML_PKG_xmlm@
 HAVE_TYPECONV = @OCAML_PKG_type_conv@
 
+include config.mk
+
 .PHONY: all
 all:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid
+endif
 ifeq ($(HAVE_TYPECONV),type-conv)
 	$(MAKE) -C rpc-light
 endif
@@ -36,21 +40,29 @@ endif
 .PHONY: allxen
 allxen:
 ifeq ($(HAVE_XEN),1)
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap
+endif
 	$(MAKE) -C netdev
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xc
 	$(MAKE) -C xb
 	$(MAKE) -C xs
+endif
 	$(MAKE) -C xcext
 	$(MAKE) -C xsrpc
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn
+endif
 	$(MAKE) -C cpuid
 	$(MAKE) -C vhd
 	$(MAKE) -C tapctl
 endif
 
 install:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid install
+endif
 	$(MAKE) -C stdext install
 	$(MAKE) -C log install
 	$(MAKE) -C stunnel install
@@ -77,21 +89,29 @@ endif
 
 installxen:
 ifeq ($(HAVE_XEN),1)
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap install
+endif
 	$(MAKE) -C netdev install
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xc install
 	$(MAKE) -C xb install
 	$(MAKE) -C xs install
+endif
 	$(MAKE) -C xcext install
 	$(MAKE) -C xsrpc install
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn install
+endif
 	$(MAKE) -C cpuid install
 	$(MAKE) -C vhd install
 	$(MAKE) -C tapctl install
 endif
 
 uninstall:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid uninstall
+endif
 	$(MAKE) -C stdext uninstall
 	$(MAKE) -C log uninstall
 	$(MAKE) -C stunnel uninstall
@@ -118,14 +138,20 @@ endif
 
 uninstallxen:
 ifeq ($(HAVE_XEN),1)
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn uninstall
+endif
 	$(MAKE) -C xsrpc uninstall
 	$(MAKE) -C netdev uninstall
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xs uninstall
 	$(MAKE) -C xb uninstall
 	$(MAKE) -C xc uninstall
+endif
 	$(MAKE) -C xcext uninstall
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap uninstall
+endif
 	$(MAKE) -C cpuid uninstall
 	$(MAKE) -C vhd uninstall
 	$(MAKE) -C tapctl uninstall
@@ -156,25 +182,33 @@ binuninstall:
 
 .PHONY: doc
 doc:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid doc
+endif
 	$(MAKE) -C stdext doc
 	$(MAKE) -C sexpr doc
 	$(MAKE) -C log doc
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xb doc
 	$(MAKE) -C xc doc
 	$(MAKE) -C xs doc
+endif
 	$(MAKE) -C xcext doc
 	$(MAKE) -C xml-light2 doc
 	$(MAKE) -C rpc-light doc
 	$(MAKE) -C http-svr doc
 	$(MAKE) -C camldm doc
 	$(MAKE) -C cdrom doc
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn doc
+endif
 	$(MAKE) -C pciutil doc
 	$(MAKE) -C rss doc
 	$(MAKE) -C stunnel doc
 	$(MAKE) -C xsrpc doc
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap doc
+endif
 	$(MAKE) -C netdev doc
 	$(MAKE) -C forking_executioner doc
 	$(MAKE) -C mlvm doc
@@ -185,7 +219,9 @@ doc:
 
 .PHONY: clean
 clean:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid clean
+endif
 	$(MAKE) -C camldm clean
 	$(MAKE) -C stdext clean
 	$(MAKE) -C log clean
@@ -207,14 +243,20 @@ clean:
 	$(MAKE) -C xen-utils clean
 
 cleanxen:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap clean
+endif
 	$(MAKE) -C netdev clean
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xc clean
 	$(MAKE) -C xb clean
 	$(MAKE) -C xs clean
+endif
 	$(MAKE) -C xcext clean
 	$(MAKE) -C xsrpc clean
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn clean
+endif
 
 RPM_SPECSDIR=$(shell rpm --eval='%_specdir')
 RPM_SOURCEDIR=$(shell rpm --eval='%_sourcedir')
diff -r be3de1c0aa06 -r 83a3a9308e56 camldm/Makefile
--- a/camldm/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/camldm/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 cdrom/Makefile
--- a/cdrom/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/cdrom/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 close-and-exec/Makefile
--- a/close-and-exec/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/close-and-exec/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
@@ -29,7 +31,7 @@ bins: $(PROGRAMS)
 libs: $(LIBS)
 
 closeandexec: closeandexec.cmxa closeandexec_main.cmx all
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -I ../stdext -I ../uuid uuid.cmxa unix.cmxa threads.cmxa stdext.cmxa closeandexec.cmxa closeandexec_main.cmx -o $@ 
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -I ../stdext $(OCAML_UUID_INC) uuid.cmxa unix.cmxa threads.cmxa stdext.cmxa closeandexec.cmxa closeandexec_main.cmx -o $@ 
 
 closeandexec.cmxa: $(foreach obj,$(OBJS),$(obj).cmx)
 	$(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ $(foreach obj,$(OBJS),$(obj).cmx)
diff -r be3de1c0aa06 -r 83a3a9308e56 configure.ac
--- a/configure.ac	Wed Nov 17 09:36:35 2010 -0500
+++ b/configure.ac	Wed Nov 17 09:36:35 2010 -0500
@@ -30,6 +30,11 @@ AC_CHECK_HEADERS([xen/xen.h],[XEN=1],[XE
 AC_CHECK_HEADERS([libdevmapper.h], [DEVICE_MAPPER=1], [DEVICE_MAPPER=0])
 AC_CHECK_HEADERS([linux/cdrom.h], [LINUX_CDROM=1], [LINUX_CDROM=0])
 
+HAVE_XEN_SYSTEM_BINDINGS=0 # could do more intelligent detection here... 
+AC_ARG_WITH(xen-system-bindings, AS_HELP_STRING([--without-xen-system-bindings],[do not use the system installed xen bindings]),
+	[if test "x$withval" = "xno"; then WITH_XEN_SYSTEM_BINDINGS=0; else WITH_XEN_SYSTEM_BINDINGS=1; fi],
+	[WITH_XEN_SYSTEM_BINDINGS=$HAVE_XEN_SYSTEM_BINDINGS])
+
 # Checks for typedefs, structures, and compiler characteristics.
 AC_CHECK_DECLS([XS_RESTRICT],[],[],[
 [
@@ -54,8 +59,9 @@ fi
 AC_CHECK_OCAML_PKG([xmlm])
 AC_CHECK_OCAML_PKG([type-conv])
 
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile config.mk])
 AC_SUBST([XEN])
+AC_SUBST([WITH_XEN_SYSTEM_BINDINGS])
 AC_SUBST([DEVICE_MAPPER])
 AC_SUBST([LINUX_CDROM])
 AC_SUBST([OCAML_PKG_xmlm])
diff -r be3de1c0aa06 -r 83a3a9308e56 cpuid/Makefile
--- a/cpuid/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/cpuid/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,8 +1,10 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include
 OCAMLC = ocamlc -g
 OCAMLOPT = ocamlopt
-INCLUDES = -I ../stdext -I ../xc -I ../xcext -I ../xen-utils
+INCLUDES = -I ../stdext $(OCAML_XC_INC) -I ../xcext -I ../xen-utils
 
 LDFLAGS = -cclib -L./
 
diff -r be3de1c0aa06 -r 83a3a9308e56 doc/Makefile
--- a/doc/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/doc/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 .PHONY: clean
 clean:
 	rm -rf components.js content
diff -r be3de1c0aa06 -r 83a3a9308e56 eventchn/Makefile
--- a/eventchn/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/eventchn/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 forking_executioner/Makefile
--- a/forking_executioner/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/forking_executioner/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
@@ -31,19 +33,19 @@ bins: $(PROGRAMS)
 libs: $(LIBS)
 
 test_forker: test_forker.cmx
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../uuid -I ../stdext uuid.cmxa rpc.cmx jsonrpc.cmx -I ../log unix.cmxa stdext.cmxa  test_forker.cmx -o $@
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light $(OCAML_UUID_INC) -I ../stdext uuid.cmxa rpc.cmx jsonrpc.cmx -I ../log unix.cmxa stdext.cmxa  test_forker.cmx -o $@
 
 fe: fe_debug.cmx child.cmx fe_main.cmx
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../stdext -I ../uuid -I ../log log.cmxa uuid.cmxa unix.cmxa rpc.cmx jsonrpc.cmx stdext.cmxa fe_debug.cmx child.cmx fe_main.cmx -o $@ 
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../stdext $(OCAML_UUID_INC) -I ../log log.cmxa uuid.cmxa unix.cmxa rpc.cmx jsonrpc.cmx stdext.cmxa fe_debug.cmx child.cmx fe_main.cmx -o $@ 
 
 %.cmo: %.ml
-	$(OCAMLC) -c -I ../log -I ../uuid -I ../stdext -thread -o $@  $<
+	$(OCAMLC) -c -I ../log $(OCAML_UUID_INC) -I ../stdext -thread -o $@  $<
 
 %.cmi: %.mli
-	$(OCAMLC) -c -I ../log -I ../uuid -I ../stdext -o $@  $<
+	$(OCAMLC) -c -I ../log $(OCAML_UUID_INC) -I ../stdext -o $@  $<
 
 %.cmx: %.ml
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../log -I ../uuid -c -I ../stdext -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../log $(OCAML_UUID_INC) -c -I ../stdext -o $@ $<
 
 META: META.in
 	sed 's/@VERSION@/$(VERSION)/g' < $< > $@
diff -r be3de1c0aa06 -r 83a3a9308e56 http-svr/Makefile
--- a/http-svr/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/http-svr/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 log/Makefile
--- a/log/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/log/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 OCAMLLOC := $(shell ocamlc -where)
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml -I$(OCAMLLOC)
diff -r be3de1c0aa06 -r 83a3a9308e56 mk/Makefile
--- a/mk/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/mk/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 ifdef B_BASE
 include $(B_BASE)/common.mk
 include $(B_BASE)/rpmbuild.mk
diff -r be3de1c0aa06 -r 83a3a9308e56 mlvm/Makefile
--- a/mlvm/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/mlvm/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,4 @@
+include ../config.mk
 
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
@@ -18,7 +19,7 @@ INTF = $(foreach obj, $(LIBOBJS),$(obj).
 CMDOBJS = messages.cmx mlvm.cmx
 OCAMLC = ocamlfind ocamlc -g
 OCAMLOPT = ocamlfind ocamlopt 
-COMPFLAG = -dtypes -g -I ../stdext -I ../camldm -I ../uuid -for-pack Lvm -pp '${PP}' -I ../rpc-light
+COMPFLAG = -dtypes -g -I ../stdext -I ../camldm $(OCAML_UUID_INC) -for-pack Lvm -pp '${PP}' -I ../rpc-light
 
 LIBS = lvm.cma lvm.cmxa
 
@@ -27,7 +28,7 @@ DOCDIR = /myrepos/xen-api-libs.hg/doc
 default : $(LIBS)
 
 test_allocator: default
-	$(OCAMLOPT) -package kaputt -linkpkg -dtypes -g  -I ../stdext -I ../camldm -I ../uuid -I +kaputt unix.cmxa ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx ../camldm/camldm.cmxa ../uuid/uuid.cmxa ../stdext/stdext.cmxa ./lvm.cmxa test_allocator.ml -o $@
+	$(OCAMLOPT) -package kaputt -linkpkg -dtypes -g  -I ../stdext -I ../camldm $(OCAML_UUID_INC) -I +kaputt unix.cmxa ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx ../camldm/camldm.cmxa $(OCAML_UUID_DIR)/uuid.cmxa ../stdext/stdext.cmxa ./lvm.cmxa test_allocator.ml -o $@
 
 lvm.cmx: $(foreach obj,$(LIBOBJS),$(obj).cmx)
 	$(OCAMLOPT) -pack -g -o $@ $(foreach obj,$(LIBOBJS),$(obj).cmx)
diff -r be3de1c0aa06 -r 83a3a9308e56 mmap/Makefile
--- a/mmap/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/mmap/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 netdev/Makefile
--- a/netdev/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/netdev/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 pciutil/Makefile
--- a/pciutil/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/pciutil/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
@@ -29,7 +31,7 @@ bins: $(PROGRAMS)
 libs: $(LIBS)
 
 pciutil: pciutil_main.cmx
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ./ -I ../stdext -I ../uuid unix.cmxa uuid.cmxa stdext.cmxa pciutil.cmx -o $@ $^
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ./ -I ../stdext $(OCAML_UUID_INC) unix.cmxa uuid.cmxa stdext.cmxa pciutil.cmx -o $@ $^
 
 pciutil.cmxa: $(foreach obj,$(OBJS),$(obj).cmx)
 	$(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ $(foreach obj,$(OBJS),$(obj).cmx)
diff -r be3de1c0aa06 -r 83a3a9308e56 rpc-light/Makefile
--- a/rpc-light/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/rpc-light/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 OCAMLC = ocamlfind ocamlc
 OCAMLOPT = ocamlfind ocamlopt
 OCAMLFLAGS = -annot -g
diff -r be3de1c0aa06 -r 83a3a9308e56 rss/Makefile
--- a/rss/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/rss/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 sexpr/Makefile
--- a/sexpr/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/sexpr/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
diff -r be3de1c0aa06 -r 83a3a9308e56 stdext/Makefile
--- a/stdext/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/stdext/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 OCAMLLOC := $(shell ocamlc -where)
@@ -17,6 +19,9 @@ OCAMLDESTDIR ?= $(OCAMLLIBDIR)
 
 FEPP = camlp4o -I ../rpc-light -I $(shell ocamlfind query type-conv) pa_type_conv.cmo pa_rpc.cma
 
+OCAML_UUID_INC = -I $(OCAML_UUID_DIR)
+OCAML_UUID_LIB = $(OCAML_UUID_DIR)/uuid.cmxa
+
 OCAML_TEST_INC = -I $(shell ocamlfind query oUnit)
 OCAML_TEST_LIB = $(shell ocamlfind query oUnit)/oUnit.cmxa
 
@@ -75,10 +80,10 @@ base64pp: base64_main.ml all libstdext_s
 	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) stdext.cmxa -linkpkg -o $@ $< -ccopt -L.
 
 fe_cli: fe_cli.ml all libstdext_stubs.a
-	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa ../uuid/uuid.cmxa ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx stdext.cmxa -linkpkg -o $@ $< -ccopt -L.
+	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa $(OCAML_UUID_LIB) ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx stdext.cmxa -linkpkg -o $@ $< -ccopt -L.
 
 fe_test: fe_test.ml all libstdext_stubs.a
-	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa ../uuid/uuid.cmxa ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx stdext.cmxa -linkpkg -I ../uuid -o $@ $< -ccopt -L.
+	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa $(OCAML_UUID_LIB) ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx stdext.cmxa -linkpkg $(OCAML_UUID_INC) -o $@ $< -ccopt -L.
 
 extentlistset_test: extentlistset_test.ml all libstdext_stubs.a
 	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa stdext.cmxa -linkpkg -o $@ $< -ccopt -L.
@@ -111,10 +116,10 @@ fe.cmo: fe.ml
 	$(OCAMLC) -pp '$(FEPP)' -I ../jsonrpc -I ../rpc-light -c -o $@ $<
 
 forkhelpers.cmo: forkhelpers.ml forkhelpers.cmi
-	$(OCAMLC) -thread -I ../uuid -c -o $@ $<
+	$(OCAMLC) -thread $(OCAML_UUID_INC) -c -o $@ $<
 
 filenameext.cmo: filenameext.ml filenameext.cmi
-	$(OCAMLC) -c -I ../uuid -o $@ $<
+	$(OCAMLC) -c $(OCAML_UUID_INC) -o $@ $<
 
 %.cmo: %.ml %.cmi
 	$(OCAMLC) -c -o $@ $<
@@ -126,7 +131,7 @@ forkhelpers.cmi: forkhelpers.mli
 	$(OCAMLC) -thread -c -o $@ $<
 
 filenameext.cmi: filenameext.mli
-	$(OCAMLC) -c -I ../uuid -o $@ $<
+	$(OCAMLC) -c $(OCAML_UUID_INC) -o $@ $<
 
 fe.cmi: fe.cmo
 	$(OCAMLC) -pp '$(FEPP)' -c -o $@ $<
@@ -144,13 +149,13 @@ fecomms.cmx : fecomms.ml
 	$(OCAMLOPT) -I ../rpc-light -c -o $@ $<
 
 forkhelpers.cmx: forkhelpers.ml forkhelpers.cmi
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../uuid -thread -c -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAML_UUID_INC) -thread -c -o $@ $<
 
 filenameext.cmx: filenameext.ml filenameext.cmi
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -c -I ../uuid -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -c $(OCAML_UUID_INC) -o $@ $<
 
 %.cmx: %.ml %.cmi
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../uuid -c -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAML_UUID_INC) -c -o $@ $<
 
 %.o: %.c
 	$(CC) $(CFLAGS) -c -o $@ $<
diff -r be3de1c0aa06 -r 83a3a9308e56 stunnel/Makefile
--- a/stunnel/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/stunnel/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
 OCAMLC = ocamlc -g
@@ -31,13 +33,13 @@ stunnel.cma: $(foreach obj,$(OBJS),$(obj
 	$(OCAMLC) -a -o $@ $(foreach obj,$(OBJS),$(obj).cmo)
 
 %.cmo: %.ml
-	$(OCAMLC) -c -I ../stdext -I ../uuid -I ../log -o $@ $<
+	$(OCAMLC) -c -I ../stdext $(OCAML_UUID_INC) -I ../log -o $@ $<
 
 %.cmi: %.mli
-	$(OCAMLC) -c -I ../stdext -I ../uuid -o $@ $<
+	$(OCAMLC) -c -I ../stdext $(OCAML_UUID_INC) -o $@ $<
 
 %.cmx: %.ml
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c -I ../stdext -I ../uuid -I ../log -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c -I ../stdext $(OCAML_UUID_INC) -I ../log -o $@ $<
 
 %.o: %.c
 	$(CC) $(CFLAGS) -c -o $@ $<
diff -r be3de1c0aa06 -r 83a3a9308e56 tapctl/Makefile
--- a/tapctl/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/tapctl/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 tests/Makefile
--- a/tests/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/tests/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 OCAMLC = ocamlfind ocamlc -g -package "unix,stdext,xc,xb,xs,mmap"
 OCAMLOPT = ocamlfind ocamlopt -package "unix,stdext,xc,xb,xs,mmap"
 
diff -r be3de1c0aa06 -r 83a3a9308e56 uuid/Makefile
--- a/uuid/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/uuid/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 vhd/Makefile
--- a/vhd/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/vhd/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,4 @@
+include ../config.mk
 
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -fno-strict-aliasing -D_FILE_OFFSET_BITS=64
diff -r be3de1c0aa06 -r 83a3a9308e56 xb/Makefile
--- a/xb/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/xb/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap
 OCAMLC = ocamlc -g -I ../mmap
diff -r be3de1c0aa06 -r 83a3a9308e56 xc/Makefile
--- a/xc/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/xc/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,8 +1,10 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap -I./
-OCAMLC = ocamlc -g -I ../mmap -I ../uuid
+OCAMLC = ocamlc -g -I ../mmap $(OCAML_UUID_INC)
 OCAMLOPT = ocamlopt
-OCAMLOPTFLAGS = -g -dtypes -I ../mmap -I ../uuid
+OCAMLOPTFLAGS = -g -dtypes -I ../mmap $(OCAML_UUID_INC)
 
 LDFLAGS = -cclib -L./
 
diff -r be3de1c0aa06 -r 83a3a9308e56 xcext/Makefile
--- a/xcext/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/xcext/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,8 +1,10 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap -I./
-OCAMLC = ocamlc -g -I ../mmap -I ../uuid -I ../xc
+OCAMLC = ocamlc -g -I ../mmap -I ../uuid $(OCAML_XC_INC)
 OCAMLOPT = ocamlopt
-OCAMLOPTFLAGS = -g -dtypes -I ../mmap -I ../uuid -I ../xc
+OCAMLOPTFLAGS = -g -dtypes -I ../mmap -I ../uuid $(OCAML_XC_INC)
 
 LDFLAGS = -cclib -L./
 
diff -r be3de1c0aa06 -r 83a3a9308e56 xen-utils/Makefile
--- a/xen-utils/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/xen-utils/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml -I$(XEN_ROOT)/usr/include
 OCAMLC = ocamlc -g
diff -r be3de1c0aa06 -r 83a3a9308e56 xml-light2/Makefile
--- a/xml-light2/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/xml-light2/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 OCAMLPACKS = xmlm
 
diff -r be3de1c0aa06 -r 83a3a9308e56 xs/Makefile
--- a/xs/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/xs/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,12 +1,14 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
-OCAMLC = ocamlc -g -I ../xb/
+OCAMLC = ocamlc -g $(OCAML_XB_INC)
 OCAMLOPT = ocamlopt
 
 LDFLAGS = -cclib -L./
 
 VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0)
-OCAMLOPTFLAGS = -g -dtypes -I ../xb/
+OCAMLOPTFLAGS = -g -dtypes $(OCAML_XB_INC)
 
 OCAMLABI := $(shell ocamlc -version)
 OCAMLLIBDIR := $(shell ocamlc -where)
diff -r be3de1c0aa06 -r 83a3a9308e56 xsrpc/Makefile
--- a/xsrpc/Makefile	Wed Nov 17 09:36:35 2010 -0500
+++ b/xsrpc/Makefile	Wed Nov 17 09:36:35 2010 -0500
@@ -1,12 +1,14 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
-OCAMLC = ocamlc -g -I ../xb/ -I ../xs/
+OCAMLC = ocamlc -g $(OCAML_XB_INC) $(OCAML_XS_INC)
 OCAMLOPT = ocamlopt
 
 LDFLAGS = -cclib -L./
 
 VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0)
-OCAMLOPTFLAGS = -g -dtypes -I ../xb/ -I ../xs/
+OCAMLOPTFLAGS = -g -dtypes $(OCAML_XB_INC) $(OCAML_XS_INC)
 
 OCAMLABI := $(shell ocamlc -version)
 OCAMLLIBDIR := $(shell ocamlc -where)

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 4 of 4] REBASE-4.1: default to using system installed bindings if Xen is available
  2010-11-18 10:50   ` [PATCH 0 of 4] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
       [not found]     ` <patchbomb.1290077414-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50     ` [PATCH 3 of 4] add configure-time option to use system installed Xen library bindings Ian Campbell
@ 2010-11-18 10:50     ` Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290076585 18000
# Node ID e0b110816450f9eb6cbd5275aa1f96762f736155
# Parent  83a3a9308e561806013a111a58f65991d37b9c17
REBASE-4.1: default to using system installed bindings if Xen is available

(depends on global rebase to Xen 4.1)

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 83a3a9308e56 -r e0b110816450 configure.ac
--- a/configure.ac	Wed Nov 17 09:36:35 2010 -0500
+++ b/configure.ac	Thu Nov 18 05:36:25 2010 -0500
@@ -30,7 +30,7 @@ AC_CHECK_HEADERS([xen/xen.h],[XEN=1],[XE
 AC_CHECK_HEADERS([libdevmapper.h], [DEVICE_MAPPER=1], [DEVICE_MAPPER=0])
 AC_CHECK_HEADERS([linux/cdrom.h], [LINUX_CDROM=1], [LINUX_CDROM=0])
 
-HAVE_XEN_SYSTEM_BINDINGS=0 # could do more intelligent detection here... 
+HAVE_XEN_SYSTEM_BINDINGS=$XEN # could do more intelligent detection here... 
 AC_ARG_WITH(xen-system-bindings, AS_HELP_STRING([--without-xen-system-bindings],[do not use the system installed xen bindings]),
 	[if test "x$withval" = "xno"; then WITH_XEN_SYSTEM_BINDINGS=0; else WITH_XEN_SYSTEM_BINDINGS=1; fi],
 	[WITH_XEN_SYSTEM_BINDINGS=$HAVE_XEN_SYSTEM_BINDINGS])

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg
       [not found] ` <1290077348.31507.5282.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50   ` [PATCH 0 of 4] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
@ 2010-11-18 10:50   ` Ian Campbell
  2010-11-18 10:50     ` [PATCH 1 of 6] Query rpm to find build directories Ian Campbell
                       ` (4 more replies)
  2010-11-18 10:50   ` [PATCH 0 of 7] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
  2010-12-07 14:30   ` [Xen-devel] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) Ian Campbell
  3 siblings, 5 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

The following series of patches lays some ground work to enable XCP to move, at
some point in the future, to the in-tree ocaml bindings which will come with
Xen 4.1

This is the xen-api.hg portion.

Only the first two patches are for immediate consideration, the others all
depend on actually moving to Xen 4.1

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1 of 6] Query rpm to find build directories
  2010-11-18 10:50   ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
@ 2010-11-18 10:50     ` Ian Campbell
  2010-11-18 10:50     ` [PATCH 2 of 6] xc: use Xcext library rather than Xc where appropriate Ian Campbell
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290076616 18000
# Node ID 819ce8194667bb673138ad12e781432cebf2028a
# Parent  7438d990fed8255bba2d592f767de133bd45863a
Query rpm to find build directories.

Allows user with ~/.rpmmacros to build e.g.
$ cat ~/.rpmmacros
%_topdir        /data/rpmbuild
%_tmppath       /data/tmp

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 7438d990fed8 -r 819ce8194667 Makefile
--- a/Makefile	Tue Oct 12 12:02:18 2010 +0100
+++ b/Makefile	Thu Nov 18 05:36:56 2010 -0500
@@ -107,9 +107,9 @@ MY_OUTPUT_DIR ?= $(CURDIR)/output
 MY_OBJ_DIR ?= $(CURDIR)/obj
 REPO ?= $(CURDIR)
 
-RPM_SPECSDIR?=/usr/src/redhat/SPECS
-RPM_SRPMSDIR?=/usr/src/redhat/SRPMS
-RPM_SOURCESDIR?=/usr/src/redhat/SOURCES
+RPM_SPECSDIR?=$(shell rpm --eval='%_specdir')
+RPM_SRPMSDIR?=$(shell rpm --eval='%_srcrpmdir')
+RPM_SOURCESDIR?=$(shell rpm --eval='%_sourcedir')
 RPMBUILD?=rpmbuild
 XEN_RELEASE?=unknown
 endif

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 2 of 6] xc: use Xcext library rather than Xc where appropriate
  2010-11-18 10:50   ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
  2010-11-18 10:50     ` [PATCH 1 of 6] Query rpm to find build directories Ian Campbell
@ 2010-11-18 10:50     ` Ian Campbell
       [not found]     ` <patchbomb.1290077422-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290076616 18000
# Node ID 4b9c3e5d05b045b4b93afa12e78afbef41ca7aa1
# Parent  819ce8194667bb673138ad12e781432cebf2028a
xc: use Xcext library rather than Xc where appropriate.

The xc bindings have been split into xc and xcext with the latter
containing bits of xc functionality which are not present in the
upstream xen tree..

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 819ce8194667 -r 4b9c3e5d05b0 ocaml/xapi/monitor.ml
--- a/ocaml/xapi/monitor.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xapi/monitor.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -92,14 +92,14 @@ let update_vcpus xc doms =
     (* Runstate info is per-domain rather than per-vcpu *)
     let dss = 
       try
-	let ri = Xc.domain_get_runstate_info xc domid in 
-	(VM uuid, ds_make ~name:"runstate_entry_time" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.state_entry_time) /. 1.0e9)) ~description:"" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_fullrun" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time0) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are running" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_full_contention" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time1) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are runnable (i.e., waiting for CPU)" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_concurrency_hazard" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time2) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are running and some are runnable" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_blocked" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time3) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are blocked or offline" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_partial_run" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time4) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are running, and some are blocked" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_partial_contention" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time5) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are runnable and some are blocked" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::dss 
+	let ri = Xcext.domain_get_runstate_info xc domid in 
+	(VM uuid, ds_make ~name:"runstate_entry_time" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.state_entry_time) /. 1.0e9)) ~description:"" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_fullrun" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time0) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are running" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_full_contention" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time1) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are runnable (i.e., waiting for CPU)" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_concurrency_hazard" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time2) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are running and some are runnable" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_blocked" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time3) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are blocked or offline" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_partial_run" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time4) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are running, and some are blocked" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_partial_contention" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time5) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are runnable and some are blocked" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::dss 
       with e -> 
 	dss 
     in
diff -r 819ce8194667 -r 4b9c3e5d05b0 ocaml/xenops-ts/OMakefile
--- a/ocaml/xenops-ts/OMakefile	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops-ts/OMakefile	Thu Nov 18 05:36:56 2010 -0500
@@ -3,6 +3,6 @@ OCAML_LIBS       = ../util/stats ../xeno
 OCAML_CLIBS      += $(XEN_OCAML_CLIBS)
 OCAML_LINK_FLAGS += $(XEN_OCAML_LINK_FLAGS)
 CFLAGS           += $(XEN_CFLAGS)
-OCAMLPACKS	     = xc xs stdext log cdrom netdev
+OCAMLPACKS	     = xc xcext xs stdext log cdrom netdev
 
 OCamlProgram(runtest, runtest test ../xenops/xenvmlib)
diff -r 819ce8194667 -r 4b9c3e5d05b0 ocaml/xenops/OMakefile
--- a/ocaml/xenops/OMakefile	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/OMakefile	Thu Nov 18 05:36:56 2010 -0500
@@ -4,7 +4,7 @@ OCAML_CLIBS     += $(XEN_OCAML_CLIBS)
 OCAML_LINK_FLAGS+= $(XEN_OCAML_LINK_FLAGS)
 CFLAGS          += $(XEN_CFLAGS)
 
-OCAMLPACKS     = threads xc xs stdext log cdrom netdev
+OCAMLPACKS     = threads xc xcext xs stdext log cdrom netdev
 OCAMLFLAGS    += -thread
 
 LIBFILES = xenops_helpers xenbus balloon xenguestHelper domain hotplug device io statdev xal netman memory watch device_common squeeze squeeze_xen squeezed_rpc squeezed_state squeezed_rpc
diff -r 819ce8194667 -r 4b9c3e5d05b0 ocaml/xenops/domain.ml
--- a/ocaml/xenops/domain.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/domain.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -242,7 +242,7 @@ let shutdown_wait_for_ack ?(timeout=60.)
   let di = Xc.domain_getinfo xc domid in
 
   if di.Xc.hvm_guest then begin
-	if Xc.hvm_check_pvdriver xc domid
+	if Xcext.hvm_check_pvdriver xc domid
 	then debug "HVM guest with PV drivers: not expecting any acknowledgement"
 	else Xc.domain_shutdown xc domid (shutdown_to_xc_shutdown req)
   end else begin
@@ -409,11 +409,11 @@ let build_pre ~xc ~xs ~vcpus ~xen_max_mi
           maybe (fun opt -> try f opt with exn -> warn "exception setting %s: %s" name (Printexc.to_string exn)) opt
         in
 
-	maybe_exn_ign "timer mode" (fun mode -> Xc.domain_set_timer_mode xc domid mode) timer_mode;
-        maybe_exn_ign "hpet" (fun hpet -> Xc.domain_set_hpet xc domid hpet) hpet;
-        maybe_exn_ign "vpt align" (fun vpt_align -> Xc.domain_set_vpt_align xc domid vpt_align) vpt_align;
+	maybe_exn_ign "timer mode" (fun mode -> Xcext.domain_set_timer_mode xc domid mode) timer_mode;
+        maybe_exn_ign "hpet" (fun hpet -> Xcext.domain_set_hpet xc domid hpet) hpet;
+        maybe_exn_ign "vpt align" (fun vpt_align -> Xcext.domain_set_vpt_align xc domid vpt_align) vpt_align;
 
-	Xc.domain_setvmxassist xc domid use_vmxassist;
+	Xcext.domain_setvmxassist xc domid use_vmxassist;
 	Xc.domain_max_vcpus xc domid vcpus;
 	Xc.domain_setmaxmem xc domid (Memory.kib_of_mib xen_max_mib);
 	Xc.domain_set_memmap_limit xc domid (Memory.kib_of_mib xen_max_mib);
@@ -822,10 +822,10 @@ let suspend ~xc ~xs ~hvm domid fd flags 
 	);
 	debug "Suspend for domid %d finished" domid
 
-let send_s3resume ~xc domid = Xc.domain_send_s3resume xc domid
+let send_s3resume ~xc domid = Xcext.domain_send_s3resume xc domid
 
-let trigger_power ~xc domid = Xc.domain_trigger_power xc domid
-let trigger_sleep ~xc domid = Xc.domain_trigger_sleep xc domid
+let trigger_power ~xc domid = Xcext.domain_trigger_power xc domid
+let trigger_sleep ~xc domid = Xcext.domain_trigger_sleep xc domid
 
 let vcpu_affinity_set ~xc domid vcpu cpumap =
 	let bitmap = ref Int64.zero in
@@ -901,7 +901,7 @@ let set_machine_address_size ~xc domid w
 
 let suppress_spurious_page_faults ~xc domid =
   debug "suppress spurious page faults for dom%d" domid;
-  Xc.domain_suppress_spurious_page_faults xc domid
+  Xcext.domain_suppress_spurious_page_faults xc domid
 
 type cpuid_reg = Eax | Ebx | Ecx | Edx
 type cpuid_rtype = Clear | Set | Default | Same | Keep

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 3 of 6] REBASE-4.1: vmops: apply CPUID to all domains
       [not found]     ` <patchbomb.1290077422-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 10:50       ` Ian Campbell
  2010-11-18 10:50       ` [PATCH 5 of 6] HACK/PoC: adjust for minor differences in upstream Xc bindings Ian Campbell
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290076616 18000
# Node ID 810786855fe641b7db0074cfcb2b2a3a4dfd34a0
# Parent  4b9c3e5d05b045b4b93afa12e78afbef41ca7aa1
REBASE-4.1: vmops: apply CPUID to all domains.

Not just when xenclient is enabled.

I think the indentation was confusing here and the PCI passthrough bit wasn't
actually guarded by Xapi_globs.xenclient_enabled.

Required on newer hypervisor otherwise guest sees all cpuid leafs == 0.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 4b9c3e5d05b0 -r 810786855fe6 ocaml/xapi/vmops.ml
--- a/ocaml/xapi/vmops.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xapi/vmops.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -1052,11 +1052,10 @@ let start_paused ?(progress_cb = fun _ -
 
 		      let hvm = Helpers.is_hvm snapshot in			
 
-		      if Xapi_globs.xenclient_enabled then 
-			Domain.cpuid_apply ~xc ~hvm domid;
+		      Domain.cpuid_apply ~xc ~hvm domid;
 
-			  (* XXX: PCI passthrough needs a lot of work *)
-			  let pcidevs = (match pcidevs with Some x -> x | None -> pcidevs_of_vm ~__context ~vm) in
+		      (* XXX: PCI passthrough needs a lot of work *)
+		      let pcidevs = (match pcidevs with Some x -> x | None -> pcidevs_of_vm ~__context ~vm) in
 
 		      (* Don't attempt to attach empty VBDs to PV guests: they can't handle them *)
 		      let vbds = 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 4 of 6] REBASE-4.1: xenops: update PV console path in xenstore
  2010-11-18 10:50   ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
                       ` (2 preceding siblings ...)
       [not found]     ` <patchbomb.1290077422-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 10:50     ` Ian Campbell
  2010-11-18 10:50     ` [PATCH 6 of 6] HACK: xenguest updates for Xen 4.0/4.1 Ian Campbell
  4 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290076616 18000
# Node ID 2e6a1485047a2e91c2e90d8ffdbf6c9a9814588c
# Parent  810786855fe641b7db0074cfcb2b2a3a4dfd34a0
REBASE-4.1: xenops: update PV console path in xenstore.

This was changed in more recent xenconsoled in order to better support multiple
consoles.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 810786855fe6 -r 2e6a1485047a ocaml/xenops/device.ml
--- a/ocaml/xenops/device.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/device.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -845,11 +845,11 @@ module PV_Vnc = struct
 
 let vncterm_wrapper = "/opt/xensource/libexec/vncterm-wrapper"
 
-let vnc_port_path domid = sprintf "/local/domain/%d/serial/0/vnc-port" domid
+let vnc_port_path domid = sprintf "/local/domain/%d/console/vnc-port" domid
 
 let pid ~xs domid =
 	try
-		let pid = xs.Xs.read (sprintf "/local/domain/%d/serial/0/vncterm-pid" domid) in
+		let pid = xs.Xs.read (sprintf "/local/domain/%d/console/vncterm-pid" domid) in
 		Some (int_of_string pid)
 	with _ ->
 		None
@@ -896,7 +896,7 @@ let save ~xs domid =
 let start ?statefile ~xs domid =
 	let l = [ string_of_int domid; (* absorbed by vncterm-wrapper *)
 		  (* everything else goes straight through to vncterm-wrapper: *)
-		  "-x"; sprintf "/local/domain/%d/serial/0" domid;
+		  "-x"; sprintf "/local/domain/%d/console" domid;
 		] @ load_args statefile in
 	(* Now add the close fds wrapper *)
 	let pid = Forkhelpers.safe_close_and_exec None None None [] vncterm_wrapper l in
diff -r 810786855fe6 -r 2e6a1485047a scripts/vncterm-wrapper
--- a/scripts/vncterm-wrapper	Thu Nov 18 05:36:56 2010 -0500
+++ b/scripts/vncterm-wrapper	Thu Nov 18 05:36:56 2010 -0500
@@ -39,9 +39,9 @@ else
 fi
 
 echo vncterm-wrapper:
-xenstore-write -s /local/domain/$DOMID/serial/0/vncterm-pid $$
+xenstore-write -s /local/domain/$DOMID/console/vncterm-pid $$
 if [ -z "${XIU}" ]; then
 	exec /usr/lib/xen/bin/vncterm $VNCTERM_LISTEN $VNCVIEWER $* > /dev/null 2>&1
 else
-	exec xenstore-write -s /local/domain/$DOMID/serial/0/vnc-port 0
+	exec xenstore-write -s /local/domain/$DOMID/console/vnc-port 0
 fi

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 5 of 6] HACK/PoC: adjust for minor differences in upstream Xc bindings
       [not found]     ` <patchbomb.1290077422-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50       ` [PATCH 3 of 6] REBASE-4.1: vmops: apply CPUID to all domains Ian Campbell
@ 2010-11-18 10:50       ` Ian Campbell
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290076616 18000
# Node ID 13460a457762df182fec2b1f4860d640934f73ad
# Parent  2e6a1485047a2e91c2e90d8ffdbf6c9a9814588c
HACK/PoC: adjust for minor differences in upstream Xc bindings

Just a PoC at this stage. It might be better to push the interface differences
to xen-api-libs.hg now to reduce the churn when rebasing to 4.1

Not-Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 2e6a1485047a -r 13460a457762 ocaml/xenops/domain.ml
--- a/ocaml/xenops/domain.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/domain.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -837,7 +837,9 @@ let vcpu_affinity_set ~xc domid vcpu cpu
 	Array.iteri (fun i has_affinity ->
 		if has_affinity then bitmap := bit_set !bitmap i
 		) cpumap;
-	Xc.vcpu_affinity_set xc domid vcpu !bitmap
+	(*Xc.vcpu_affinity_set xc domid vcpu !bitmap*)
+	Xc.vcpu_affinity_set xc domid vcpu cpumap
+
 
 let vcpu_affinity_get ~xc domid vcpu =
 	let bitmap = Xc.vcpu_affinity_get xc domid vcpu in
@@ -845,8 +847,9 @@ let vcpu_affinity_get ~xc domid vcpu =
 	let bit_isset bitmap n =
 		(Int64.logand bitmap (Int64.shift_left 1L n)) > 0L in
 	(* set bit in the array that are set in the bitmap *)
-	for i = 0 to 63 do cpumap.(i) <- bit_isset bitmap i done;
-	cpumap
+	(*for i = 0 to 63 do cpumap.(i) <- bit_isset bitmap i done;*)
+	(*cpumap*)
+	bitmap
 
 let get_uuid ~xc domid =
 	Uuid.uuid_of_int_array (Xc.domain_getinfo xc domid).Xc.handle
@@ -961,19 +964,20 @@ let cpuid_set ~xc ~hvm domid cfg =
 	let tmp = Array.create 4 None in
 	let cfgout = List.map (fun (node, constr) ->
 		cpuid_cfg_to_xc_cpuid_cfg tmp constr;
-		let ret = Xc.domain_cpuid_set xc domid hvm node tmp in
+		let ret = Xc.domain_cpuid_set xc domid (*hvm*) node tmp in
 		let ret = cpuid_cfg_of_xc_cpuid_cfg ret in
 		(node, ret)
 	) cfg in
 	cfgout
 
 let cpuid_apply ~xc ~hvm domid =
-	Xc.domain_cpuid_apply xc domid hvm
+	(*Xc.domain_cpuid_apply xc domid hvm*)
+	Xc.domain_cpuid_apply_policy xc domid
 
-let cpuid_check cfg =
+let cpuid_check ~xc cfg =
 	let tmp = Array.create 4 None in
 	List.map (fun (node, constr) ->
 		cpuid_cfg_to_xc_cpuid_cfg tmp constr;
-		let (success, cfgout) = Xc.cpuid_check node tmp in
+		let (success, cfgout) = Xc.cpuid_check xc node tmp in
 		(success, (node, (cpuid_cfg_of_xc_cpuid_cfg cfgout)))
 	) cfg
diff -r 2e6a1485047a -r 13460a457762 ocaml/xenops/domain.mli
--- a/ocaml/xenops/domain.mli	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/domain.mli	Thu Nov 18 05:36:56 2010 -0500
@@ -206,4 +206,4 @@ val cpuid_rtype_of_char : char -> cpuid_
 
 val cpuid_set : xc: Xc.handle -> hvm: bool -> domid -> cpuid_config -> cpuid_config
 val cpuid_apply : xc: Xc.handle -> hvm: bool -> domid -> unit
-val cpuid_check : cpuid_config -> (bool * ((int64 * int64 option) * (cpuid_reg * cpuid_rtype array) list)) list
+val cpuid_check : xc: Xc.handle -> cpuid_config -> (bool * ((int64 * int64 option) * (cpuid_reg * cpuid_rtype array) list)) list

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 6 of 6] HACK: xenguest updates for Xen 4.0/4.1
  2010-11-18 10:50   ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
                       ` (3 preceding siblings ...)
  2010-11-18 10:50     ` [PATCH 4 of 6] REBASE-4.1: xenops: update PV console path in xenstore Ian Campbell
@ 2010-11-18 10:50     ` Ian Campbell
  4 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290076616 18000
# Node ID 1b166fb9629c50be802c5cfc9c2722db80ec8a0e
# Parent  13460a457762df182fec2b1f4860d640934f73ad
HACK: xenguest updates for Xen 4.0/4.1

Totally incomplete but enough to start a PV guest.

Not-signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 13460a457762 -r 1b166fb9629c ocaml/xenguest/save_helpers.c
--- a/ocaml/xenguest/save_helpers.c	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenguest/save_helpers.c	Thu Nov 18 05:36:56 2010 -0500
@@ -22,150 +22,19 @@
  * Modifications (c) Citrix Systems Inc
  */
 
-#include <err.h>
 #include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <grp.h>
 
 #include <xs.h>
 #include <xenctrl.h>
 #include <xenguest.h>
 
-static char *qemu_active_path;
-static char *qemu_next_active_path;
-static int qemu_shmid = -1;
-static struct xs_handle *xs;
-
-
-/* Mark the shared-memory segment for destruction */
-static void qemu_destroy_buffer(void)
-{
-    if (qemu_shmid != -1)
-        shmctl(qemu_shmid, IPC_RMID, NULL);
-    qemu_shmid = -1;
+int switch_qemu_logdirty(int domid, unsigned enable, void *data)
+{	
+	return 1; /* XXX actually do something! */
 }
 
-/* Get qemu to change buffers. */
-void qemu_flip_buffer(int domid, int next_active)
+int do_domain_suspend(void* data)
 {
-    char digit = '0' + next_active;
-    unsigned int len;
-    char *active_str, **watch;
-    struct timeval tv;
-    fd_set fdset;
-    int rc;
-
-    /* Tell qemu that we want it to start writing log-dirty bits to the
-     * other buffer */
-    if (!xs_write(xs, XBT_NULL, qemu_next_active_path, &digit, 1)) {
-        errx(1, "can't write next-active to store path (%s)\n",
-              qemu_next_active_path);
-        exit(1);
-    }
-
-    /* Wait a while for qemu to signal that it has switched to the new
-     * active buffer */
- read_again:
-    tv.tv_sec = 60;
-    tv.tv_usec = 0;
-    FD_ZERO(&fdset);
-    FD_SET(xs_fileno(xs), &fdset);
-    rc = select(xs_fileno(xs) + 1, &fdset, NULL, NULL, &tv);
-    if (rc == 0)
-        errx(1, "timed out waiting for qemu to switch buffers\n");
-    else if (rc < 0) {
-        if (errno == EINTR) 
-            goto read_again;
-        err(1, "error waiting for qemu to switch buffers");
-    }
-    watch = xs_read_watch(xs, &len);
-    free(watch);
-
-    active_str = xs_read(xs, XBT_NULL, qemu_active_path, &len);
-    if (active_str == NULL || active_str[0] - '0' != next_active)
-        /* Watch fired but value is not yet right */
-        goto read_again;
+	return 1; /* XXX actually do something! */
 }
 
-void * init_qemu_maps(int domid, unsigned int bitmap_size)
-{
-    key_t key;
-    char key_ascii[17] = {0,};
-    void *seg;
-    char *path, *p;
-    struct shmid_ds ds_buf;
-    struct group *gr;
-
-    /* Make a shared-memory segment */
-    do {
-        key = rand(); /* No security, just a sequence of numbers */
-        qemu_shmid = shmget(key, 2 * bitmap_size, 
-                       IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
-        if (qemu_shmid == -1 && errno != EEXIST)
-            errx(1, "can't get shmem to talk to qemu-dm");
-    } while (qemu_shmid == -1);
-
-    /* Remember to tidy up after ourselves */
-    atexit(qemu_destroy_buffer);
-
-    /* Change owner so that qemu can map it. */
-    gr = getgrnam("qemu_base");
-    if (!gr)
-        err(1, "can't get qemu gid");
-    if (shmctl(qemu_shmid, IPC_STAT, &ds_buf) < 0)
-        err(1, "can't get status of shm area");
-    ds_buf.shm_perm.gid = gr->gr_gid + (unsigned short)domid;
-    if (shmctl(qemu_shmid, IPC_SET, &ds_buf) < 0)
-        err(1, "can't change gid of shm area");
-
-    /* Map it into our address space */
-    seg = shmat(qemu_shmid, NULL, 0);
-    if (seg == (void *) -1)
-        errx(1, "can't map shmem to talk to qemu-dm");
-    memset(seg, 0, 2 * bitmap_size);
-
-    /* Write the size of it into the first 32 bits */
-    *(uint32_t *)seg = bitmap_size;
-
-    /* Tell qemu about it */
-    if ((xs = xs_daemon_open()) == NULL)
-        errx(1, "Couldn't contact xenstore");
-    if (!(path = xs_get_domain_path(xs, domid)))
-        errx(1, "can't get domain path in store");
-    if (!(path = realloc(path, strlen(path)
-                         + strlen("/logdirty/next-active") + 1)))
-        errx(1, "no memory for constructing xenstore path");
-    strcat(path, "/logdirty/");
-    p = path + strlen(path);
-
-    strcpy(p, "key");
-    snprintf(key_ascii, 17, "%16.16llx", (unsigned long long) key);
-    if (!xs_write(xs, XBT_NULL, path, key_ascii, 16))
-        errx(1, "can't write key (%s) to store path (%s)\n", key_ascii, path);
-
-    /* Watch for qemu's indication of the active buffer, and request it
-     * to start writing to buffer 0 */
-    strcpy(p, "active");
-    if (!xs_watch(xs, path, "qemu-active-buffer"))
-        errx(1, "can't set watch in store (%s)\n", path);
-    if (!(qemu_active_path = strdup(path)))
-        errx(1, "no memory for copying xenstore path");
-
-    strcpy(p, "next-active");
-    if (!(qemu_next_active_path = strdup(path)))
-        errx(1, "no memory for copying xenstore path");
-
-    qemu_flip_buffer(domid, 0);
-
-    free(path);
-    return seg;
-}
-
-/***********************************************************************/
diff -r 13460a457762 -r 1b166fb9629c ocaml/xenguest/xenguest_stubs.c
--- a/ocaml/xenguest/xenguest_stubs.c	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenguest/xenguest_stubs.c	Thu Nov 18 05:36:56 2010 -0500
@@ -34,7 +34,7 @@
 #include <caml/signals.h>
 #include <caml/fail.h>
 
-#define _H(__h) (Int_val(__h))
+#define _H(__h) ((xc_interface *)(__h))
 #define _D(__d) ((uint32_t)Int_val(__d))
 
 #define None_val (Val_int(0))
@@ -138,17 +138,17 @@ get_flags(struct flags *f, int domid)
 }
 
 
-static void failwith_oss_xc(char *fct)
+static void failwith_oss_xc(xc_interface *xch, char *fct)
 {
 	char buf[80];
 	const xc_error *error;
 
-	error = xc_get_last_error();
+	error = xc_get_last_error(xch);
 	if (error->code == XC_ERROR_NONE)
 		snprintf(buf, 80, "%s: [%d] %s", fct, errno, strerror(errno));
 	else
 		snprintf(buf, 80, "%s: [%d] %s", fct, error->code, error->message);
-	xc_clear_last_error();
+	xc_clear_last_error(xch);
 	caml_failwith(buf);
 }
 
@@ -172,41 +172,55 @@ static int suspend_flag_list[] = {
 
 CAMLprim value stub_xenguest_init()
 {
-	int handle;
+	xc_interface *xch;
 
-	handle = xc_interface_open();
-	if (handle == -1)
-		failwith_oss_xc("xc_interface_open");
-	return Val_int(handle);
+	xch = xc_interface_open(NULL, NULL, 0);
+	if (xch == NULL)
+		failwith_oss_xc(NULL, "xc_interface_open");
+	return (value)xch;
 }
 
 CAMLprim value stub_xenguest_close(value xenguest_handle)
 {
 	CAMLparam1(xenguest_handle);
-	xc_interface_close(Int_val(xenguest_handle));
+	xc_interface_close(_H(xenguest_handle));
 	CAMLreturn(Val_unit);
 }
 
-extern struct xc_dom_image *xc_dom_allocate(const char *cmdline, const char *features);
+extern struct xc_dom_image *xc_dom_allocate(xc_interface *xch, const char *cmdline, const char *features);
 
-static void configure_vcpus(int handle, int domid, struct flags f){
+static void configure_vcpus(xc_interface *xch, int domid, struct flags f){
   struct xen_domctl_sched_credit sdom;
   int i, r;
   if (f.vcpu_affinity != 0L){ /* 0L means unset */
+    xc_cpumap_t cpumap = xc_cpumap_alloc(xch);
+    if (cpumap == NULL)
+      failwith_oss_xc(xch, "xc_cpumap_alloc");
+
+    for (i=0; i<64; i++) {
+      if (f.vcpu_affinity & 1<<i)
+        cpumap[i/8] |= i << (i&7);
+    }
+
     for (i=0; i<f.vcpus; i++){
-      r = xc_vcpu_setaffinity(handle, domid, i, f.vcpu_affinity);
-      if (r)
-	failwith_oss_xc("xc_vcpu_setaffinity");
+      r = xc_vcpu_setaffinity(xch, domid, i, cpumap);
+      if (r) {
+        free(cpumap);
+	failwith_oss_xc(xch, "xc_vcpu_setaffinity");
+      }
     }
-  };
-  r = xc_sched_credit_domain_get(handle, domid, &sdom);
+
+    free(cpumap);
+  }
+
+  r = xc_sched_credit_domain_get(xch, domid, &sdom);
   if (r)
-    failwith_oss_xc("xc_sched_credit_domain_get");
+    failwith_oss_xc(xch, "xc_sched_credit_domain_get");
   if (f.vcpu_weight != 0L) sdom.weight = f.vcpu_weight;
   if (f.vcpu_cap != 0L) sdom.cap = f.vcpu_cap;
-  r = xc_sched_credit_domain_set(handle, domid, &sdom);
+  r = xc_sched_credit_domain_set(xch, domid, &sdom);
   if (r)
-    failwith_oss_xc("xc_sched_credit_domain_set");
+    failwith_oss_xc(xch, "xc_sched_credit_domain_set");
 }
 
 CAMLprim value stub_xc_linux_build_native(value xc_handle, value domid,
@@ -228,7 +242,7 @@ CAMLprim value stub_xc_linux_build_nativ
 	char c_protocol[64];
 
 	/* Copy the ocaml values into c-land before dropping the mutex */
-	int c_xc_handle = _H(xc_handle);
+	xc_interface *xch = _H(xc_handle);
 	unsigned int c_mem_start_mib = Int_val(mem_start_mib);
 	uint32_t c_domid = _D(domid);
 	char *c_image_name = strdup(String_val(image_name));
@@ -241,14 +255,14 @@ CAMLprim value stub_xc_linux_build_nativ
 	get_flags(&f,c_domid);
 
 	xc_dom_loginit();
-	dom = xc_dom_allocate(String_val(cmdline), String_val(features));
+	dom = xc_dom_allocate(xch, String_val(cmdline), String_val(features));
 	if (!dom)
-		failwith_oss_xc("xc_dom_allocate");
+		failwith_oss_xc(xch, "xc_dom_allocate");
 
-	configure_vcpus(c_xc_handle, c_domid, f);
+	configure_vcpus(xch, c_domid, f);
 
 	caml_enter_blocking_section();
-	r = xc_dom_linux_build(c_xc_handle, dom, c_domid, c_mem_start_mib,
+	r = xc_dom_linux_build(xch, dom, c_domid, c_mem_start_mib,
 	                       c_image_name, c_ramdisk_name, c_flags,
 	                       c_store_evtchn, &store_mfn,
 	                       c_console_evtchn, &console_mfn);
@@ -264,7 +278,7 @@ CAMLprim value stub_xc_linux_build_nativ
 	xc_dom_release(dom);
 
 	if (r != 0)
-		failwith_oss_xc("xc_dom_linux_build");
+		failwith_oss_xc(xch, "xc_dom_linux_build");
 
 	result = caml_alloc_tuple(3);
 	Store_field(result, 0, caml_copy_nativeint(store_mfn));
@@ -282,7 +296,7 @@ CAMLprim value stub_xc_linux_build_bytec
 	                                  argv[8], argv[9], argv[10]);
 }
 
-static int hvm_build_set_params(int handle, int domid,
+static int hvm_build_set_params(xc_interface *xch, int domid,
                                 int store_evtchn, unsigned long *store_mfn,
 				struct flags f)
 {
@@ -290,7 +304,7 @@ static int hvm_build_set_params(int hand
 	uint8_t *va_map, sum;
 	int i;
 
-	va_map = xc_map_foreign_range(handle, domid,
+	va_map = xc_map_foreign_range(xch, domid,
 			    XC_PAGE_SIZE, PROT_READ | PROT_WRITE,
 			    HVM_INFO_PFN);
 	if (va_map == NULL)
@@ -300,22 +314,24 @@ static int hvm_build_set_params(int hand
 	va_hvm->acpi_enabled = f.acpi;
 	va_hvm->apic_mode = f.apic;
 	va_hvm->nr_vcpus = f.vcpus;
+#if 0
         va_hvm->s4_enabled = f.acpi_s4;
         va_hvm->s3_enabled = f.acpi_s3;
+#endif
 	va_hvm->checksum = 0;
 	for (i = 0, sum = 0; i < va_hvm->length; i++)
 		sum += ((uint8_t *) va_hvm)[i];
 	va_hvm->checksum = -sum;
 	munmap(va_map, XC_PAGE_SIZE);
 
-	xc_get_hvm_param(handle, domid, HVM_PARAM_STORE_PFN, store_mfn);
-	xc_set_hvm_param(handle, domid, HVM_PARAM_PAE_ENABLED, f.pae);
+	xc_get_hvm_param(xch, domid, HVM_PARAM_STORE_PFN, store_mfn);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_PAE_ENABLED, f.pae);
 #ifdef HVM_PARAM_VIRIDIAN
-	xc_set_hvm_param(handle, domid, HVM_PARAM_VIRIDIAN, f.viridian);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_VIRIDIAN, f.viridian);
 #endif
-	xc_set_hvm_param(handle, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn);
 #ifndef XEN_UNSTABLE
-	xc_set_hvm_param(handle, domid, HVM_PARAM_NX_ENABLED, f.nx);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_NX_ENABLED, f.nx);
 #endif
 	return 0;
 }
@@ -330,16 +346,18 @@ CAMLprim value stub_xc_hvm_build_native(
 	CAMLlocal1(ret);
 	char *image_name_c = strdup(String_val(image_name));
 	char *error[256];
+	xc_interface *xch;
 
 	unsigned long store_mfn=0;
 	int r;
 	struct flags f;
 	get_flags(&f, _D(domid));
 
-	configure_vcpus(_H(xc_handle), _D(domid), f);
+	xch = _H(xc_handle);
+	configure_vcpus(xch, _D(domid), f);
 
 	caml_enter_blocking_section ();
-	r = xc_hvm_build_target_mem(_H(xc_handle), _D(domid),
+	r = xc_hvm_build_target_mem(xch, _D(domid),
 	                            Int_val(mem_max_mib),
 	                            Int_val(mem_start_mib),
 	                            image_name_c);
@@ -348,13 +366,13 @@ CAMLprim value stub_xc_hvm_build_native(
 	free(image_name_c);
 
 	if (r)
-		failwith_oss_xc("hvm_build");
+		failwith_oss_xc(xch, "hvm_build");
 
 
-	r = hvm_build_set_params(_H(xc_handle), _D(domid),
+	r = hvm_build_set_params(xch, _D(domid),
 				 Int_val(store_evtchn), &store_mfn, f);
 	if (r)
-		failwith_oss_xc("hvm_build_params");
+		failwith_oss_xc(xch, "hvm_build_params");
 
 	ret = caml_copy_nativeint(store_mfn);
 	CAMLreturn(ret);
@@ -366,8 +384,8 @@ CAMLprim value stub_xc_hvm_build_bytecod
 	                                argv[4], argv[5]);
 }
 
-extern void qemu_flip_buffer(int domid, int next_active);
-extern void * init_qemu_maps(int domid, unsigned int bitmap_size);
+extern int switch_qemu_logdirty(int domid, unsigned enable, void *data);
+extern int do_domain_suspend(void* data);
 
 CAMLprim value stub_xc_domain_save(value handle, value fd, value domid,
                                    value max_iters, value max_factors,
@@ -375,24 +393,23 @@ CAMLprim value stub_xc_domain_save(value
 {
 	CAMLparam5(handle, fd, domid, max_iters, max_factors);
 	CAMLxparam2(flags, hvm);
-	void *(*init_maps)(int, unsigned);
-	void (*flip_buffer)(int, int);
+	struct save_callbacks callbacks;
 	uint32_t c_flags;
 	int r;
 
-	init_maps = (Bool_val(hvm)) ? init_qemu_maps : NULL;
-	flip_buffer = (Bool_val(hvm)) ? qemu_flip_buffer : NULL;
+	c_flags = caml_convert_flag_list(flags, suspend_flag_list);
 
-	c_flags = caml_convert_flag_list(flags, suspend_flag_list);
+	memset(&callbacks, 0, sizeof(callbacks));
+	callbacks.suspend = &do_domain_suspend;	
+	callbacks.switch_qemu_logdirty = &switch_qemu_logdirty;
 
 	caml_enter_blocking_section();
 	r = xc_domain_save(_H(handle), Int_val(fd), _D(domid),
 	                   Int_val(max_iters), Int_val(max_factors),
-	                   c_flags, dispatch_suspend,
-	                   Bool_val(hvm), init_maps, flip_buffer);
+	                   c_flags, &callbacks, Bool_val(hvm));
 	caml_leave_blocking_section();
 	if (r)
-		failwith_oss_xc("xc_domain_save");
+		failwith_oss_xc(_H(handle), "xc_domain_save");
 
 	CAMLreturn(Val_unit);
 }
@@ -413,7 +430,7 @@ CAMLprim value stub_xc_domain_resume_slo
 	/* hard code fast to 0, we only want to expose the slow version here */
 	r = xc_domain_resume(_H(handle), _D(domid), 0);
 	if (r)
-		failwith_oss_xc("xc_domain_resume");
+		failwith_oss_xc(_H(handle), "xc_domain_resume");
 	CAMLreturn(Val_unit);
 }
 
@@ -444,10 +461,10 @@ CAMLprim value stub_xc_domain_restore(va
 	r = xc_domain_restore(_H(handle), Int_val(fd), _D(domid),
 	                      c_store_evtchn, &store_mfn,
 	                      c_console_evtchn, &console_mfn,
-			      Bool_val(hvm), f.pae);
+			      Bool_val(hvm), f.pae, 0 /*superpages*/);
 	caml_leave_blocking_section();
 	if (r)
-		failwith_oss_xc("xc_domain_restore");
+		failwith_oss_xc(_H(handle), "xc_domain_restore");
 
 	result = caml_alloc_tuple(2);
 	Store_field(result, 0, caml_copy_nativeint(store_mfn));
@@ -469,6 +486,6 @@ CAMLprim value stub_xc_domain_dumpcore(v
 
 	r = xc_domain_dumpcore(_H(handle), _D(domid), String_val(file));
 	if (r)
-		failwith_oss_xc("xc_domain_dumpcore");
+		failwith_oss_xc(_H(handle), "xc_domain_dumpcore");
 	CAMLreturn(Val_unit);
 }
diff -r 13460a457762 -r 1b166fb9629c ocaml/xenops/xenops.ml
--- a/ocaml/xenops/xenops.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/xenops.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -29,8 +29,8 @@ let print_xen_physinfo ~xc =
 	printf "nr_cpus = %d\n" physinfo.Xc.nr_cpus;
 	printf "threads_per_core = %d\n" physinfo.Xc.threads_per_core;
 	printf "cores_per_socket = %d\n" physinfo.Xc.cores_per_socket;
-	printf "sockets_per_node = %d\n" physinfo.Xc.sockets_per_node;
-	printf "nr_nodes = %d\n" physinfo.Xc.nr_nodes;
+	(*printf "sockets_per_node = %d\n" physinfo.Xc.sockets_per_node;*)
+	(*printf "nr_nodes = %d\n" physinfo.Xc.nr_nodes;*)
 	printf "cpu_khz = %d\n" physinfo.Xc.cpu_khz;
 	printf "total_pages = %s (%Ld Mb)\n" (Nativeint.to_string physinfo.Xc.total_pages) totalmib;
 	printf "free_pages = %s (%Ld Mb)\n" (Nativeint.to_string physinfo.Xc.free_pages) freemib;

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 0 of 7] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg
       [not found] ` <1290077348.31507.5282.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50   ` [PATCH 0 of 4] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
  2010-11-18 10:50   ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
@ 2010-11-18 10:50   ` Ian Campbell
       [not found]     ` <patchbomb.1290077432-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
                       ` (3 more replies)
  2010-12-07 14:30   ` [Xen-devel] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) Ian Campbell
  3 siblings, 4 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

The following series of patches lays some ground work to enable XCP to move, at
some point in the future, to the in-tree ocaml bindings which will come with
Xen 4.1

This is the xen-unstable.hg portion.

All but the last patch are intended for immediate consideration.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1 of 7] libxc: rename safe_strerror to _xc_safestrerror and pass XC handle
       [not found]     ` <patchbomb.1290077432-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 10:50       ` Ian Campbell
  2010-11-18 10:50       ` [PATCH 4 of 7] ocaml: resynchronise uuid library with xen-api-libs.hg Ian Campbell
                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290077186 18000
# Node ID 61797efad6c24b6b63b03ac0a4532671a1a9a40a
# Parent  a15b0a2dc276ae8eb8cff4cc58d5563848a39b9b
libxc: rename safe_strerror to _xc_safestrerror and pass XC handle.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r a15b0a2dc276 -r 61797efad6c2 tools/libxc/ia64/xc_ia64_linux_save.c
--- a/tools/libxc/ia64/xc_ia64_linux_save.c	Tue Nov 09 20:37:46 2010 +0000
+++ b/tools/libxc/ia64/xc_ia64_linux_save.c	Thu Nov 18 05:46:26 2010 -0500
@@ -660,7 +660,7 @@ xc_domain_save(xc_interface *xch, int io
                        FIXME: to be tracked.  */
                     fprintf(stderr, "cannot map mfn page %lx gpfn %lx: %s\n",
                             xc_ia64_p2m_mfn(&p2m_table, N),
-                            N, safe_strerror(errno));
+                            N, _xc_strerror(xch, errno));
                     goto out;
                 }
 
diff -r a15b0a2dc276 -r 61797efad6c2 tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c	Tue Nov 09 20:37:46 2010 +0000
+++ b/tools/libxc/xc_private.c	Thu Nov 18 05:46:26 2010 -0500
@@ -544,7 +544,7 @@ _xc_init_errbuf(void)
     pthread_key_create(&errbuf_pkey, _xc_clean_errbuf);
 }
 
-char *safe_strerror(int errcode)
+char *_xc_strerror(xc_interface *xch, int errcode)
 {
 #define XS_BUFSIZE 32
     char *errbuf;
diff -r a15b0a2dc276 -r 61797efad6c2 tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h	Tue Nov 09 20:37:46 2010 +0000
+++ b/tools/libxc/xc_private.h	Thu Nov 18 05:46:26 2010 -0500
@@ -74,7 +74,7 @@ struct xc_interface {
     const char *currently_progress_reporting;
 };
 
-char *safe_strerror(int errcode);
+char *_xc_strerror(xc_interface *xch, int errcode);
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...);
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
                 int code, const char *fmt, va_list args)
@@ -96,7 +96,7 @@ void xc_report_progress_step(xc_interfac
 
 #define ERROR(_m, _a...)  xc_report_error(xch,XC_INTERNAL_ERROR,_m , ## _a )
 #define PERROR(_m, _a...) xc_report_error(xch,XC_INTERNAL_ERROR,_m \
-                  " (%d = %s)", ## _a , errno, safe_strerror(errno))
+                  " (%d = %s)", ## _a , errno, _xc_strerror(xch, errno))
 
 /*
  * HYPERCALL ARGUMENT BUFFERS

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 2 of 7] libxc: allow caller to specify no re-entrancy protection when opening the interface
  2010-11-18 10:50   ` [PATCH 0 of 7] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
       [not found]     ` <patchbomb.1290077432-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 10:50     ` Ian Campbell
  2010-11-18 10:50     ` [PATCH 3 of 7] ocaml: install built modules Ian Campbell
  2010-11-18 10:50     ` [PATCH 5 of 7] ocaml: add dependency to module metadata Ian Campbell
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290077186 18000
# Node ID 3de336d9c113359203885ca6cf6360e5250dfe82
# Parent  61797efad6c24b6b63b03ac0a4532671a1a9a40a
libxc: allow caller to specify no re-entrancy protection when opening the interface

Used by language bindings which provide their own re-entrancy which conflicts
with pthreads.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 61797efad6c2 -r 3de336d9c113 tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/libxc/xc_private.c	Thu Nov 18 05:46:26 2010 -0500
@@ -32,6 +32,7 @@ xc_interface *xc_interface_open(xentooll
                                 unsigned open_flags) {
     xc_interface xch_buf, *xch = &xch_buf;
 
+    xch->flags = open_flags;
     xch->fd = -1;
     xch->dombuild_logger_file = 0;
     xc_clear_last_error(xch);
@@ -546,30 +547,37 @@ _xc_init_errbuf(void)
 
 char *_xc_strerror(xc_interface *xch, int errcode)
 {
+    if ( xch->flags & XC_OPENFLAG_NON_REENTRANT )
+    {
+        return strerror(errcode);
+    }
+    else
+    {
 #define XS_BUFSIZE 32
-    char *errbuf;
-    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-    char *strerror_str;
+        char *errbuf;
+        static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+        char *strerror_str;
 
-    pthread_once(&errbuf_pkey_once, _xc_init_errbuf);
+        pthread_once(&errbuf_pkey_once, _xc_init_errbuf);
 
-    errbuf = pthread_getspecific(errbuf_pkey);
-    if (errbuf == NULL) {
-        errbuf = malloc(XS_BUFSIZE);
-        pthread_setspecific(errbuf_pkey, errbuf);
+        errbuf = pthread_getspecific(errbuf_pkey);
+        if (errbuf == NULL) {
+            errbuf = malloc(XS_BUFSIZE);
+            pthread_setspecific(errbuf_pkey, errbuf);
+        }
+
+        /*
+         * Thread-unsafe strerror() is protected by a local mutex. We copy the
+         * string to a thread-private buffer before releasing the mutex.
+         */
+        pthread_mutex_lock(&mutex);
+        strerror_str = strerror(errcode);
+        strncpy(errbuf, strerror_str, XS_BUFSIZE);
+        errbuf[XS_BUFSIZE-1] = '\0';
+        pthread_mutex_unlock(&mutex);
+
+        return errbuf;
     }
-
-    /*
-     * Thread-unsafe strerror() is protected by a local mutex. We copy
-     * the string to a thread-private buffer before releasing the mutex.
-     */
-    pthread_mutex_lock(&mutex);
-    strerror_str = strerror(errcode);
-    strncpy(errbuf, strerror_str, XS_BUFSIZE);
-    errbuf[XS_BUFSIZE-1] = '\0';
-    pthread_mutex_unlock(&mutex);
-
-    return errbuf;
 }
 
 void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits)
diff -r 61797efad6c2 -r 3de336d9c113 tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/libxc/xc_private.h	Thu Nov 18 05:46:26 2010 -0500
@@ -67,6 +67,7 @@
 
 struct xc_interface {
     int fd;
+    int flags;
     xentoollog_logger *error_handler,   *error_handler_tofree;
     xentoollog_logger *dombuild_logger, *dombuild_logger_tofree;
     struct xc_error last_error; /* for xc_get_last_error */
diff -r 61797efad6c2 -r 3de336d9c113 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/libxc/xenctrl.h	Thu Nov 18 05:46:26 2010 -0500
@@ -132,8 +132,17 @@ xc_interface *xc_interface_open(xentooll
    * if dombuild_logger=NULL, will log to a file
    */
 
+/*
+ * Note: if XC_OPENFLAG_NON_REENTRANT is passed then libxc must not be
+ * called reentrantly and the calling application is responsible for
+ * providing mutual exclusion surrounding all libxc calls itself.
+ *
+ * In particular xc_{get,clear}_last_error only remain valid for the
+ * duration of the critical section containing the call which failed.
+ */
 enum xc_open_flags {
-    XC_OPENFLAG_DUMMY =  01, /* do not actually open a xenctrl interface */
+    XC_OPENFLAG_DUMMY =  1<<0, /* do not actually open a xenctrl interface */
+    XC_OPENFLAG_NON_REENTRANT = 1<<1, /* assume library is only every called from a single thread */
 };
 
 /**

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 3 of 7] ocaml: install built modules
  2010-11-18 10:50   ` [PATCH 0 of 7] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
       [not found]     ` <patchbomb.1290077432-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50     ` [PATCH 2 of 7] libxc: allow caller to specify no re-entrancy protection when opening the interface Ian Campbell
@ 2010-11-18 10:50     ` Ian Campbell
  2010-11-18 10:50     ` [PATCH 5 of 7] ocaml: add dependency to module metadata Ian Campbell
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290077186 18000
# Node ID 11cc3e6d573937508df213c0127c1dbbbd61af30
# Parent  3de336d9c113359203885ca6cf6360e5250dfe82
ocaml: install built modules

Previously the install target was having no effect because it ended up
calling the default target in the subdir Makefile instead of the
install target.

Resolve this by tying the tools/ocaml Makefiles into the generic
handling done by tools/Rules.mk.

Other changes arising in one way or another from this:
- Add libs/xl/META.in
- Update .hgignore for META files
- Create leading directories
- Remove existing module before installation in install targer
  (worksaround what appears to be a quirk of "ocamlfind install")
- Use the globally defined $(DESTDIR)
- Move "ocamlfind printfconf destdir" to a common variable,
  repurposing exising unused OCAMLDESTDIR, incorporating $(DESTDIR) at
  the same time.
- Drop a few unused variable definitions (mainly to avoid deciding if
  $(DESTDIR) made sense for them or not.
- Pass -destdir to ocamlfind in uninstall target for symmetry with
  install target.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 3de336d9c113 -r 11cc3e6d5739 .hgignore
--- a/.hgignore	Thu Nov 18 05:46:26 2010 -0500
+++ b/.hgignore	Thu Nov 18 05:46:26 2010 -0500
@@ -292,6 +292,7 @@
 ^tools/ioemu-dir$
 ^tools/ocaml/.*/.*\.annot$
 ^tools/ocaml/.*/.*\.cmx?a$
+^tools/ocaml/.*/META$
 ^tools/ocaml/.*/\.ocamldep\.make$
 ^tools/ocaml/xenstored/oxenstored$
 ^xen/\.banner.*$
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/Makefile
--- a/tools/ocaml/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -1,43 +1,19 @@
 XEN_ROOT = ../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-SUBDIRS_LIBS = \
-	libs/uuid libs/mmap \
-	libs/log libs/xc libs/eventchn \
-	libs/xb libs/xs libs/xl
-
 SUBDIRS_PROGRAMS = xenstored
 
-SUBDIRS = $(SUBDIRS_LIBS) $(SUBDIRS_PROGRAMS)
+SUBDIRS = libs $(SUBDIRS_PROGRAMS)
 
 .NOTPARALLEL:
 # targets here must be run in order, otherwise we can try
 # to build programs before the libraries are done
 
 .PHONY: all
-all: build
+all: subdirs-all
 
-.PHONY: build
-build: SUBDIRS
-
-.PHONY: SUBDIRS SUBDIRS_PROGRAMS SUBDIRS_LIBS
-SUBDIRS SUBDIRS_PROGRAMS SUBDIRS_LIBS:
-	@set -e; for d in $($@); do			\
-		echo " === building $$d";		\
-		$(MAKE) --no-print-directory -C $$d;	\
-	done
-
-.PHONY: install install-libs install-program
-install: install-libs install-program
-
-install-program: SUBDIRS_PROGRAMS
-	$(INSTALL_DIR) $(DESTDIR)$(SBINDIR)
-	$(INSTALL_PROG) xenstored/oxenstored $(DESTDIR)$(SBINDIR)
-
-install-libs: SUBDIRS_LIBS
+.PHONY: install
+install: subdirs-install
 
 .PHONY: clean
-clean:
-	@for dir in $(SUBDIRS); do \
-		$(MAKE) --no-print-directory -C $$dir clean; \
-	done
+clean: subdirs-clean
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/common.make
--- a/tools/ocaml/common.make	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/common.make	Thu Nov 18 05:46:26 2010 -0500
@@ -17,13 +17,8 @@ OCAMLOPTFLAG_G := $(shell $(OCAMLOPT) -h
 OCAMLOPTFLAGS = $(OCAMLOPTFLAG_G) -ccopt "$(LDFLAGS)" -dtypes $(OCAMLINCLUDE) -cc $(CC) -w F -warn-error F
 OCAMLCFLAGS += -g $(OCAMLINCLUDE) -w F -warn-error F
 
-#LDFLAGS = -cclib -L./
-
-DESTDIR ?= /
 VERSION := 4.1
 
-OCAMLABI = $(shell $(OCAMLC) -version)
-OCAMLLIBDIR = $(shell $(OCAMLC) -where)
-OCAMLDESTDIR ?= $(OCAMLLIBDIR)
+OCAMLDESTDIR ?= $(DESTDIR)$(shell ocamlfind printconf destdir)
 
 o= >$@.new && mv -f $@.new $@
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/ocaml/libs/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -0,0 +1,16 @@
+XEN_ROOT = ../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SUBDIRS= \
+	uuid mmap \
+	log xc eventchn \
+	xb xs xl
+
+.PHONY: all
+all: subdirs-all
+
+.PHONY: install
+install: subdirs-install
+
+.PHONY: clean
+clean: subdirs-clean
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/eventchn/Makefile
--- a/tools/ocaml/libs/eventchn/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/eventchn/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -19,11 +19,13 @@ OCAML_LIBRARY = eventchn
 
 .PHONY: install
 install: $(LIBS) META
-	ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore eventchn META $(INTF) $(LIBS) *.a *.so *.cmx
+	mkdir -p $(OCAMLDESTDIR)
+	ocamlfind remove -destdir $(OCAMLDESTDIR) eventchn
+	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore eventchn META $(INTF) $(LIBS) *.a *.so *.cmx
 
 .PHONY: uninstall
 uninstall:
-	ocamlfind remove eventchn
+	ocamlfind remove -destdir $(OCAMLDESTDIR) eventchn
 
 include $(TOPLEVEL)/Makefile.rules
 
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/log/Makefile
--- a/tools/ocaml/libs/log/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/log/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -32,11 +32,13 @@ syslog.mli : syslog.ml
 
 .PHONY: install
 install: $(LIBS) META
-	ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore log META $(INTF) $(LIBS) *.a *.so *.cmx
+	mkdir -p $(OCAMLDESTDIR)
+	ocamlfind remove -destdir $(OCAMLDESTDIR) log
+	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore log META $(INTF) $(LIBS) *.a *.so *.cmx
 
 .PHONY: uninstall
 uninstall:
-	ocamlfind remove log
+	ocamlfind remove -destdir $(OCAMLDESTDIR) log
 
 include $(TOPLEVEL)/Makefile.rules
 
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/mmap/Makefile
--- a/tools/ocaml/libs/mmap/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/mmap/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -18,11 +18,13 @@ OCAML_LIBRARY = mmap
 
 .PHONY: install
 install: $(LIBS) META
-	ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore mmap META $(INTF) $(LIBS) *.a *.so *.cmx
+	mkdir -p $(OCAMLDESTDIR)
+	ocamlfind remove -destdir $(OCAMLDESTDIR) mmap
+	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore mmap META $(INTF) $(LIBS) *.a *.so *.cmx
 
 .PHONY: uninstall
 uninstall:
-	ocamlfind remove mmap
+	ocamlfind remove -destdir $(OCAMLDESTDIR) mmap
 
 include $(TOPLEVEL)/Makefile.rules
 
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/uuid/Makefile
--- a/tools/ocaml/libs/uuid/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/uuid/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -17,11 +17,13 @@ OCAML_NOC_LIBRARY = uuid
 
 .PHONY: install
 install: $(LIBS) META
-	ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore uuid META $(INTF) $(LIBS) *.a *.cmx
+	mkdir -p $(OCAMLDESTDIR)
+	ocamlfind remove -destdir $(OCAMLDESTDIR) uuid
+	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore uuid META $(INTF) $(LIBS) *.a *.cmx
 
 .PHONY: uninstall
 uninstall:
-	ocamlfind remove uuid
+	ocamlfind remove -destdir $(OCAMLDESTDIR) uuid
 
 include $(TOPLEVEL)/Makefile.rules
 
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/xb/Makefile
--- a/tools/ocaml/libs/xb/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xb/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -33,10 +33,12 @@ OCAML_LIBRARY = xb
 
 .PHONY: install
 install: $(LIBS) META
-	ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore xb META $(INTF) $(LIBS) *.a *.so *.cmx
+	mkdir -p $(OCAMLDESTDIR)
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xb
+	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore xb META $(INTF) $(LIBS) *.a *.so *.cmx
 
 .PHONY: uninstall
 uninstall:
-	ocamlfind remove xb
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xb
 
 include $(TOPLEVEL)/Makefile.rules
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/xc/Makefile
--- a/tools/ocaml/libs/xc/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xc/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -20,10 +20,12 @@ libs: $(LIBS)
 
 .PHONY: install
 install: $(LIBS) META
-	ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore xc META $(INTF) $(LIBS) *.a *.so *.cmx
+	mkdir -p $(OCAMLDESTDIR)
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xc
+	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore xc META $(INTF) $(LIBS) *.a *.so *.cmx
 
 .PHONY: uninstall
 uninstall:
-	ocamlfind remove xc
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xc
 
 include $(TOPLEVEL)/Makefile.rules
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/xl/META.in
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/ocaml/libs/xl/META.in	Thu Nov 18 05:46:26 2010 -0500
@@ -0,0 +1,4 @@
+version = "@VERSION@"
+description = "Xen Toolstack Library"
+archive(byte) = "xl.cma"
+archive(native) = "xl.cmxa"
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/xl/Makefile
--- a/tools/ocaml/libs/xl/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xl/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -17,10 +17,12 @@ libs: $(LIBS)
 
 .PHONY: install
 install: $(LIBS) META
-	ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore xl META $(INTF) $(LIBS) *.a *.so *.cmx
+	mkdir -p $(OCAMLDESTDIR)
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xl
+	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore xl META $(INTF) $(LIBS) *.a *.so *.cmx
 
 .PHONY: uninstall
 uninstall:
-	ocamlfind remove xl
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xl
 
 include $(TOPLEVEL)/Makefile.rules
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/libs/xs/Makefile
--- a/tools/ocaml/libs/xs/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xs/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -33,11 +33,13 @@ OCAML_NOC_LIBRARY = xs
 
 .PHONY: install
 install: $(LIBS) META
-	ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore xs META $(INTF) xs.mli xst.mli xsraw.mli $(LIBS) *.a *.cmx
+	mkdir -p $(OCAMLDESTDIR)
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xs
+	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore xs META $(INTF) xs.mli xst.mli xsraw.mli $(LIBS) *.a *.cmx
 
 .PHONY: uninstall
 uninstall:
-	ocamlfind remove xs
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xs
 
 include $(TOPLEVEL)/Makefile.rules
 
diff -r 3de336d9c113 -r 11cc3e6d5739 tools/ocaml/xenstored/Makefile
--- a/tools/ocaml/xenstored/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/xenstored/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -52,4 +52,8 @@ all: $(INTF) $(PROGRAMS)
 
 bins: $(PROGRAMS)
 
+install: all
+	$(INSTALL_DIR) $(DESTDIR)$(SBINDIR)
+	$(INSTALL_PROG) oxenstored $(DESTDIR)$(SBINDIR)
+
 include $(OCAML_TOPLEVEL)/Makefile.rules

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 4 of 7] ocaml: resynchronise uuid library with xen-api-libs.hg
       [not found]     ` <patchbomb.1290077432-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50       ` [PATCH 1 of 7] libxc: rename safe_strerror to _xc_safestrerror and pass XC handle Ian Campbell
@ 2010-11-18 10:50       ` Ian Campbell
  2010-11-18 11:32         ` Gianni Tedesco
  2010-11-18 10:50       ` [PATCH 6 of 7] ocaml: xc bindings: use libxenctrl and libxenguest Ian Campbell
  2010-11-18 10:50       ` [PATCH 7 of 7] HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same Ian Campbell
  3 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290077186 18000
# Node ID 05cf9251ac48e7abeabdcf3c5a164b276bf393e9
# Parent  11cc3e6d573937508df213c0127c1dbbbd61af30
ocaml: resynchronise uuid library with xen-api-libs.hg

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 11cc3e6d5739 -r 05cf9251ac48 tools/ocaml/libs/uuid/uuid.ml
--- a/tools/ocaml/libs/uuid/uuid.ml	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/uuid/uuid.ml	Thu Nov 18 05:46:26 2010 -0500
@@ -1,7 +1,5 @@
 (*
- * Copyright (C) 2006-2007 XenSource Ltd.
- * Copyright (C) 2008      Citrix Ltd.
- * Author Vincent Hanquez <vincent.hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published
@@ -14,9 +12,7 @@
  * GNU Lesser General Public License for more details.
  *)
 
-(** Type-safe UUIDs. *)
-
-(** Internally, a UUID is simply a string. *)
+(* Internally, a UUID is simply a string. *)
 type 'a t = string
 
 type cookie = string
@@ -24,6 +20,8 @@ type cookie = string
 let of_string s = s
 let to_string s = s
 
+let null = ""
+
 (* deprecated: we don't need to duplicate the uuid prefix/suffix *)
 let uuid_of_string = of_string
 let string_of_uuid = to_string
@@ -32,12 +30,34 @@ let string_of_cookie s = s
 
 let cookie_of_string s = s
 
-(** FIXME: using /dev/random is too slow but using /dev/urandom is too
-    deterministic. *)
-let dev_random = "/dev/urandom"
+let dev_random = "/dev/random"
+let dev_urandom = "/dev/urandom"
 
-let read_random n = 
-  let ic = open_in_bin dev_random in
+let rnd_array n =
+	let fstbyte i = 0xff land i in
+	let sndbyte i = fstbyte (i lsr 8) in
+	let thdbyte i = sndbyte (i lsr 8) in
+	let rec rnd_list n acc = match n with
+		| 0 -> acc
+		| 1 ->
+			let b = fstbyte (Random.bits ()) in
+			b :: acc
+		| 2 ->
+			let r = Random.bits () in
+			let b1 = fstbyte r in
+			let b2 = sndbyte r in
+			b1 :: b2 :: acc
+		| n -> 
+			let r = Random.bits () in
+			let b1 = fstbyte r in
+			let b2 = sndbyte r in
+			let b3 = thdbyte r in
+			rnd_list (n - 3) (b1 :: b2 :: b3 :: acc)
+	in
+	Array.of_list (rnd_list n [])
+
+let read_array dev n = 
+  let ic = open_in_bin dev in
   try
     let result = Array.init n (fun _ -> input_byte ic) in
     close_in ic;
@@ -52,30 +72,14 @@ let uuid_of_int_array uuid =
     uuid.(6) uuid.(7) uuid.(8) uuid.(9) uuid.(10) uuid.(11)
     uuid.(12) uuid.(13) uuid.(14) uuid.(15)
 
-(** Return a new random UUID *)
-let make_uuid() = uuid_of_int_array (read_random 16)
+let make_uuid_prng () = uuid_of_int_array (rnd_array 16)
+let make_uuid_urnd () = uuid_of_int_array (read_array dev_urandom 16)
+let make_uuid_rnd () = uuid_of_int_array (read_array dev_random 16)
+let make_uuid = make_uuid_urnd
 
-(** Return a new random, big UUID (hopefully big and random enough to be
-    unguessable) *)
 let make_cookie() =
-  let bytes = Array.to_list (read_random 64) in
+  let bytes = Array.to_list (read_array dev_urandom 64) in
   String.concat "" (List.map (Printf.sprintf "%1x") bytes)
-(*
-  let hexencode x = 
-    let nibble x =
-      char_of_int (if x < 10 
-		   then int_of_char '0' + x
-		   else int_of_char 'a' + (x - 10)) in
-    let result = String.make (String.length x * 2) ' ' in
-    for i = 0 to String.length x - 1 do
-      let byte = int_of_char x.[i] in
-      result.[i * 2 + 0] <- nibble((byte lsr 4) land 15);
-      result.[i * 2 + 1] <- nibble((byte lsr 0) land 15);
-    done;
-    result in
-  let n = 64 in
-  hexencode (String.concat "" (List.map (fun x -> String.make 1 (char_of_int x)) (Array.to_list (read_n_random_bytes n))))
-*)
 
 let int_array_of_uuid s =
   try
@@ -86,3 +90,10 @@ let int_array_of_uuid s =
              a10; a11; a12; a13; a14; a15; ]);
     Array.of_list !l
   with _ -> invalid_arg "Uuid.int_array_of_uuid"
+
+let is_uuid str =
+	try
+		Scanf.sscanf str
+			"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
+			(fun _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ -> true)
+	with _ -> false
diff -r 11cc3e6d5739 -r 05cf9251ac48 tools/ocaml/libs/uuid/uuid.mli
--- a/tools/ocaml/libs/uuid/uuid.mli	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/uuid/uuid.mli	Thu Nov 18 05:46:26 2010 -0500
@@ -1,7 +1,5 @@
 (*
- * Copyright (C) 2006-2007 XenSource Ltd.
- * Copyright (C) 2008      Citrix Ltd.
- * Author Vincent Hanquez <vincent.hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published
@@ -13,41 +11,56 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  *)
-
 (** Type-safe UUIDs.
     Probably need to refactor this; UUIDs are used in two places:
-    1. to uniquely name things across the cluster
-    2. as secure session IDs
+    + to uniquely name things across the cluster
+    + as secure session IDs
+
     There is the additional constraint that current Xen tools use 
     a particular format of UUID (the 16 byte variety generated by fresh ())
+
+	Also, cookies aren't UUIDs and should be put somewhere else.
 *)
 
-(** A 128-bit UUID referencing a value of type 'a. *)
+(** A 128-bit UUID.  Using phantom types ('a) to achieve the requires type-safety. *)
 type 'a t
 
-(** A 512-bit UUID. *)
+(** Create a fresh UUID *)
+val make_uuid : unit -> 'a t
+val make_uuid_prng : unit -> 'a t
+val make_uuid_urnd : unit -> 'a t
+val make_uuid_rnd : unit -> 'a t
+
+(** Create a UUID from a string. *)
+val of_string : string -> 'a t
+
+(** Marshal a UUID to a string. *)
+val to_string : 'a t -> string
+
+(** A null UUID, as if such a thing actually existed.  It turns out to be
+ * useful though. *)
+val null : 'a t
+
+(** Deprecated alias for {! Uuid.of_string} *)
+val uuid_of_string : string -> 'a t
+
+(** Deprecated alias for {! Uuid.to_string} *)
+val string_of_uuid : 'a t -> string
+
+(** Convert an array to a UUID. *)
+val uuid_of_int_array : int array -> 'a t
+
+(** Convert a UUID to an array. *)
+val int_array_of_uuid : 'a t -> int array
+
+(** Check whether a string is a UUID. *)
+val is_uuid : string -> bool
+
+(** A 512-bit cookie. *)
 type cookie
 
-(** Create a fresh (unique!) UUID *)
-val make_uuid : unit -> 'a t
-
-(** Create a fresh secure (bigger and hopefully unguessable) UUID *)
 val make_cookie : unit -> cookie
 
-(** Create a type-safe UUID. *)
-val of_string : string -> 'a t
-
-(** Marshal a UUID to a (type-unsafe) string. *)
-val to_string : 'a t -> string
-
-(* deprecated alias for previous one *)
-val uuid_of_string : string -> 'a t
-val string_of_uuid : 'a t -> string
-
 val cookie_of_string : string -> cookie
 
 val string_of_cookie : cookie -> string
-
-val uuid_of_int_array : int array -> 'a t
-
-val int_array_of_uuid : 'a t -> int array

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 5 of 7] ocaml: add dependency to module metadata
  2010-11-18 10:50   ` [PATCH 0 of 7] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
                       ` (2 preceding siblings ...)
  2010-11-18 10:50     ` [PATCH 3 of 7] ocaml: install built modules Ian Campbell
@ 2010-11-18 10:50     ` Ian Campbell
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290077186 18000
# Node ID ac5b6ac9ec0d6fafed037d89a9802c542a77b5ce
# Parent  05cf9251ac48e7abeabdcf3c5a164b276bf393e9
ocaml: add dependency to module metadata.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 05cf9251ac48 -r ac5b6ac9ec0d tools/ocaml/libs/eventchn/META.in
--- a/tools/ocaml/libs/eventchn/META.in	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/eventchn/META.in	Thu Nov 18 05:46:26 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "Eventchn interface extension"
+requires = "unix"
 archive(byte) = "eventchn.cma"
 archive(native) = "eventchn.cmxa"
diff -r 05cf9251ac48 -r ac5b6ac9ec0d tools/ocaml/libs/log/META.in
--- a/tools/ocaml/libs/log/META.in	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/log/META.in	Thu Nov 18 05:46:26 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "Log - logging library"
+requires = "unix"
 archive(byte) = "log.cma"
 archive(native) = "log.cmxa"
diff -r 05cf9251ac48 -r ac5b6ac9ec0d tools/ocaml/libs/xb/META.in
--- a/tools/ocaml/libs/xb/META.in	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xb/META.in	Thu Nov 18 05:46:26 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "XenBus Interface"
+requires = "unix,mmap"
 archive(byte) = "xb.cma"
 archive(native) = "xb.cmxa"
diff -r 05cf9251ac48 -r ac5b6ac9ec0d tools/ocaml/libs/xc/META.in
--- a/tools/ocaml/libs/xc/META.in	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xc/META.in	Thu Nov 18 05:46:26 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "Xen Control Interface"
+requires = "mmap,uuid"
 archive(byte) = "xc.cma"
 archive(native) = "xc.cmxa"
diff -r 05cf9251ac48 -r ac5b6ac9ec0d tools/ocaml/libs/xs/META.in
--- a/tools/ocaml/libs/xs/META.in	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xs/META.in	Thu Nov 18 05:46:26 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "XenStore Interface"
+requires = "unix,xb"
 archive(byte) = "xs.cma"
 archive(native) = "xs.cmxa"

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 6 of 7] ocaml: xc bindings: use libxenctrl and libxenguest
       [not found]     ` <patchbomb.1290077432-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-18 10:50       ` [PATCH 1 of 7] libxc: rename safe_strerror to _xc_safestrerror and pass XC handle Ian Campbell
  2010-11-18 10:50       ` [PATCH 4 of 7] ocaml: resynchronise uuid library with xen-api-libs.hg Ian Campbell
@ 2010-11-18 10:50       ` Ian Campbell
  2010-11-18 10:50       ` [PATCH 7 of 7] HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same Ian Campbell
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290077186 18000
# Node ID 4e6556dc40d36822bddf8ebb55294762e3279f33
# Parent  ac5b6ac9ec0d6fafed037d89a9802c542a77b5ce
ocaml: xc bindings: use libxenctrl and libxenguest

Now that tools/libxc is licensed under LGPL I don't think there is any need for
an LGPL reimplementation under tools/ocaml.

For the most part the conversion to the up-to-date libxc API (xc_lib.c
essentially implemented the same interface as an older libxc) was pretty
automatic. There are some functions which appear to no longer exist in libxc
which I therefore simply removed the bindings for and a small number of
interfaces which had changed.

Many of the functions bound by the stubs have no in-tree users (which I think
is fine for a language binding) so I have no way to confirm correctness other
than by eye. I was however able to confirm that oxenstored still worked and to
build a XCP toolstack which could successfully start a PV guest.

Uses the new XC_OPENFLAG_NON_REENTRANT option to avoid potential conflicts
between pthreads and the ocaml runtime.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
Cc: Vincent Hanquez <Vincent.Hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>

diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/Makefile.rules
--- a/tools/ocaml/Makefile.rules	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/Makefile.rules	Thu Nov 18 05:46:26 2010 -0500
@@ -54,18 +54,18 @@ mk-caml-lib-bytecode = $(call quiet-comm
 
 mk-caml-stubs = $(call quiet-command, $(OCAMLMKLIB) -o `basename $1 .a` $2,MKLIB,$1)
 mk-caml-lib-stubs = \
-	$(call quiet-command, $(AR) rcs $1 $2 && $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $2,MKLIB,$1)
+	$(call quiet-command, $(AR) rcs $1 $2 && $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $3 $2,MKLIB,$1)
 
 # define a library target <name>.cmxa and <name>.cma
 define OCAML_LIBRARY_template
  $(1).cmxa: lib$(1)_stubs.a $(foreach obj,$($(1)_OBJS),$(obj).cmx)
-	$(call mk-caml-lib-native,$$@, -cclib -l$(1)_stubs, $(foreach obj,$($(1)_OBJS),$(obj).cmx))
+	$(call mk-caml-lib-native,$$@, -cclib -l$(1)_stubs $(foreach lib,$(LIBS_$(1)),-cclib $(lib)), $(foreach obj,$($(1)_OBJS),$(obj).cmx))
  $(1).cma: $(foreach obj,$($(1)_OBJS),$(obj).cmo)
 	$(call mk-caml-lib-bytecode,$$@, -dllib dll$(1)_stubs.so -cclib -l$(1)_stubs, $$+)
  $(1)_stubs.a: $(foreach obj,$$($(1)_C_OBJS),$(obj).o)
 	$(call mk-caml-stubs,$$@, $$+)
  lib$(1)_stubs.a: $(foreach obj,$($(1)_C_OBJS),$(obj).o)
-	$(call mk-caml-lib-stubs,$$@, $$+)
+	$(call mk-caml-lib-stubs,$$@, $$+, $(LIBS_$(1)))
 endef
 
 define OCAML_NOC_LIBRARY_template
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/libs/xc/Makefile
--- a/tools/ocaml/libs/xc/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xc/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -2,15 +2,17 @@ TOPLEVEL=../..
 XEN_ROOT=$(TOPLEVEL)/../..
 include $(TOPLEVEL)/common.make
 
-CFLAGS += -I../mmap -I./
-OCAMLINCLUDE += -I ../mmap -I ../uuid
+CFLAGS += -I../mmap -I./ -I$(XEN_ROOT)/tools/libxc
+OCAMLINCLUDE += -I ../mmap -I ../uuid -I $(XEN_ROOT)/tools/libxc
 
 OBJS = xc
 INTF = xc.cmi
 LIBS = xc.cma xc.cmxa
 
+LIBS_xc = -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
+
 xc_OBJS = $(OBJS)
-xc_C_OBJS = xc_lib xc_stubs
+xc_C_OBJS = xc_stubs
 
 OCAML_LIBRARY = xc
 
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/libs/xc/xc.h
--- a/tools/ocaml/libs/xc/xc.h	Thu Nov 18 05:46:26 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2006-2007 XenSource Ltd.
- * Copyright (C) 2008      Citrix Ltd.
- * Author Vincent Hanquez <vincent.hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; version 2.1 only. with the special
- * exception on linking described in file LICENSE.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- */
-
-#include <xen/xen.h>
-#include <xen/memory.h>
-#include <xen/sysctl.h>
-#include <xen/domctl.h>
-#include <xen/sched.h>
-#include <xen/sysctl.h>
-#include <xen/sys/privcmd.h>
-#include <xen/version.h>
-#include <xen/foreign/x86_32.h>
-#include <xen/foreign/x86_64.h>
-#include <xen/hvm/params.h>
-#include "xc_e820.h"
-
-typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
-typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
-typedef xen_sysctl_physinfo_t xc_physinfo_t;
-
-struct xc_core_header {
-	unsigned int xch_magic;
-	unsigned int xch_nr_vcpus;
-	unsigned int xch_nr_pages;
-	unsigned int xch_ctxt_offset;
-	unsigned int xch_index_offset;
-	unsigned int xch_pages_offset;
-};
-
-typedef union {
-#if defined(__i386__) || defined(__x86_64__)
-	vcpu_guest_context_x86_64_t x64;
-	vcpu_guest_context_x86_32_t x32;
-#endif
-	vcpu_guest_context_t c;
-} vcpu_guest_context_any_t;
-
-char * xc_error_get(void);
-void xc_error_clear(void);
-
-int xc_using_injection(void);
-
-int xc_interface_open(void);
-int xc_interface_close(int handle);
-
-int xc_domain_create(int handle, unsigned int ssidref,
-                     xen_domain_handle_t dhandle,
-                     unsigned int flags, unsigned int *pdomid);
-int xc_domain_pause(int handle, unsigned int domid);
-int xc_domain_unpause(int handle, unsigned int domid);
-int xc_domain_resume_fast(int handle, unsigned int domid);
-int xc_domain_destroy(int handle, unsigned int domid);
-int xc_domain_shutdown(int handle, int domid, int reason);
-
-int xc_vcpu_setaffinity(int handle, unsigned int domid, int vcpu,
-                        uint64_t cpumap);
-int xc_vcpu_getaffinity(int handle, unsigned int domid, int vcpu,
-                        uint64_t *cpumap);
-
-int xc_domain_getinfolist(int handle, unsigned int first_domain,
-                          unsigned int max_domains, xc_domaininfo_t *info);
-int xc_domain_getinfo(int handle, unsigned int first_domain,
-                      xc_domaininfo_t *info);
-
-int xc_domain_setmaxmem(int handle, unsigned int domid, unsigned int max_memkb);
-int xc_domain_set_memmap_limit(int handle, unsigned int domid,
-                               unsigned long map_limitkb);
-
-int xc_domain_set_time_offset(int handle, unsigned int domid, int time_offset);
-
-int xc_domain_memory_increase_reservation(int handle, unsigned int domid,
-                                          unsigned long nr_extents,
-                                          unsigned int extent_order,
-                                          unsigned int address_bits,
-                                          xen_pfn_t *extent_start);
-int xc_domain_memory_decrease_reservation(int handle, unsigned int domid,
-                                          unsigned long nr_extents,
-                                          unsigned int extent_order,
-                                          unsigned int address_bits,
-                                          xen_pfn_t *extent_start);
-int xc_domain_memory_populate_physmap(int handle, unsigned int domid,
-                                      unsigned long nr_extents,
-                                      unsigned int extent_order,
-                                      unsigned int address_bits,
-                                      xen_pfn_t *extent_start);
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist);
-int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max);
-int xc_domain_sethandle(int handle, unsigned int domid,
-                        xen_domain_handle_t dhandle);
-int xc_vcpu_getinfo(int handle, unsigned int domid, unsigned int vcpu,
-                    xc_vcpuinfo_t *info);
-int xc_domain_ioport_permission(int handle, unsigned int domid,
-                                unsigned int first_port, unsigned int nr_ports,
-                                unsigned int allow_access);
-int xc_vcpu_setcontext(int handle, unsigned int domid,
-                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt);
-int xc_vcpu_getcontext(int handle, unsigned int domid,
-                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt);
-int xc_domain_irq_permission(int handle, unsigned int domid,
-                             unsigned char pirq, unsigned char allow_access);
-int xc_domain_iomem_permission(int handle, unsigned int domid,
-                               unsigned long first_mfn, unsigned long nr_mfns,
-                               unsigned char allow_access);
-long long xc_domain_get_cpu_usage(int handle, unsigned int domid,
-                                  unsigned int vcpu);
-void *xc_map_foreign_range(int handle, unsigned int domid,
-                           int size, int prot, unsigned long mfn);
-int xc_map_foreign_ranges(int handle, unsigned int domid,
-                          privcmd_mmap_entry_t *entries, int nr);
-int xc_readconsolering(int handle, char **pbuffer,
-                       unsigned int *pnr_chars, int clear);
-int xc_send_debug_keys(int handle, char *keys);
-int xc_physinfo(int handle, xc_physinfo_t *put_info);
-int xc_pcpu_info(
-	int handle, int max_cpus, xen_sysctl_cpuinfo_t *info, int *nr_cpus);
-int xc_sched_id(int handle, int *sched_id);
-int xc_version(int handle, int cmd, void *arg);
-int xc_evtchn_alloc_unbound(int handle, unsigned int domid,
-                            unsigned int remote_domid);
-int xc_evtchn_reset(int handle, unsigned int domid);
-
-int xc_sched_credit_domain_set(int handle, unsigned int domid,
-                               struct xen_domctl_sched_credit *sdom);
-int xc_sched_credit_domain_get(int handle, unsigned int domid,
-                               struct xen_domctl_sched_credit *sdom);
-int xc_shadow_allocation_get(int handle, unsigned int domid,
-			     uint32_t *mb);
-int xc_shadow_allocation_set(int handle, unsigned int domid,
-			     uint32_t mb);
-int xc_domain_get_pfn_list(int handle, unsigned int domid,
-                           uint64_t *pfn_array, unsigned long max_pfns);
-int xc_hvm_check_pvdriver(int handle, unsigned int domid);
-
-int xc_domain_assign_device(int handle, unsigned int domid,
-                            int domain, int bus, int slot, int func);
-int xc_domain_deassign_device(int handle, unsigned int domid,
-                              int domain, int bus, int slot, int func);
-int xc_domain_test_assign_device(int handle, unsigned int domid,
-                                 int domain, int bus, int slot, int func);
-int xc_domain_watchdog(int handle, int id, uint32_t timeout);
-int xc_domain_set_machine_address_size(int xc, uint32_t domid, unsigned int width);
-int xc_domain_get_machine_address_size(int xc, uint32_t domid);
-
-int xc_domain_cpuid_set(int xc, unsigned int domid, int hvm,
-                        uint32_t input, uint32_t oinput,
-                        char *config[4], char *config_out[4]);
-int xc_domain_cpuid_apply(int xc, unsigned int domid, int hvm);
-int xc_cpuid_check(uint32_t input, uint32_t optsubinput,
-                   char *config[4], char *config_out[4]);
-
-int xc_domain_send_s3resume(int handle, unsigned int domid);
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align);
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet);
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode);
-int xc_domain_get_acpi_s_state(int handle, unsigned int domid);
-
-#if XEN_SYSCTL_INTERFACE_VERSION >= 6
-#define SAFEDIV(a, b)					(((b) > 0) ? (a) / (b) : (a))
-#define COMPAT_FIELD_physinfo_get_nr_cpus(p)		(p).nr_cpus
-#define COMPAT_FIELD_physinfo_get_sockets_per_node(p)	\
-	SAFEDIV((p).nr_cpus, ((p).threads_per_core * (p).cores_per_socket * (p).nr_nodes))
-#else
-#define COMPAT_FIELD_physinfo_get_nr_cpus(p)		\
-	((p).threads_per_core * (p).sockets_per_node *	\
-	 (p).cores_per_socket * (p).threads_per_core)
-#define COMPAT_FIELD_physinfo_get_sockets_per_node(p)	(p).sockets_per_node
-#endif
-
-#if __XEN_LATEST_INTERFACE_VERSION__ >= 0x00030209
-#define COMPAT_FIELD_ADDRESS_BITS		mem_flags
-#else
-#define COMPAT_FIELD_ADDRESS_BITS		address_bits
-#endif
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/libs/xc/xc.ml
--- a/tools/ocaml/libs/xc/xc.ml	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xc/xc.ml	Thu Nov 18 05:46:26 2010 -0500
@@ -127,9 +127,6 @@ external _domain_sethandle: handle -> do
 let domain_sethandle handle n uuid =
 	_domain_sethandle handle n (Uuid.int_array_of_uuid uuid)
 
-external domain_setvmxassist: handle -> domid -> bool -> unit
-       = "stub_xc_domain_setvmxassist"
-
 external domain_max_vcpus: handle -> domid -> int -> unit
        = "stub_xc_domain_max_vcpus"
 
@@ -165,9 +162,9 @@ external domain_iomem_permission: handle
 external domain_irq_permission: handle -> domid -> int -> bool -> unit
        = "stub_xc_domain_irq_permission"
 
-external vcpu_affinity_set: handle -> domid -> int -> int64 -> unit
+external vcpu_affinity_set: handle -> domid -> int -> bool array -> unit
        = "stub_xc_vcpu_setaffinity"
-external vcpu_affinity_get: handle -> domid -> int -> int64
+external vcpu_affinity_get: handle -> domid -> int -> bool array
        = "stub_xc_vcpu_getaffinity"
 
 external vcpu_context_get: handle -> domid -> int -> string
@@ -207,13 +204,13 @@ external domain_set_machine_address_size
 external domain_get_machine_address_size: handle -> domid -> int
        = "stub_xc_domain_get_machine_address_size"
 
-external domain_cpuid_set: handle -> domid -> bool -> (int64 * (int64 option))
+external domain_cpuid_set: handle -> domid -> (int64 * (int64 option))
                         -> string option array
                         -> string option array
        = "stub_xc_domain_cpuid_set"
-external domain_cpuid_apply: handle -> domid -> bool -> unit
-       = "stub_xc_domain_cpuid_apply"
-external cpuid_check: (int64 * (int64 option)) -> string option array -> (bool * string option array)
+external domain_cpuid_apply_policy: handle -> domid -> unit
+       = "stub_xc_domain_cpuid_apply_policy"
+external cpuid_check: handle -> (int64 * (int64 option)) -> string option array -> (bool * string option array)
        = "stub_xc_cpuid_check"
 
 external map_foreign_range: handle -> domid -> int
@@ -230,17 +227,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit = "stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
-
-(** check if some hvm domain got pv driver or not *)
-external hvm_check_pvdriver: handle -> domid -> bool
-       = "stub_xc_hvm_check_pvdriver"
-
 external version: handle -> version = "stub_xc_version_version"
 external version_compile_info: handle -> compile_info
        = "stub_xc_version_compile_info"
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/libs/xc/xc.mli
--- a/tools/ocaml/libs/xc/xc.mli	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xc/xc.mli	Thu Nov 18 05:46:26 2010 -0500
@@ -80,8 +80,6 @@ val domain_create : handle -> int32 -> d
 external _domain_sethandle : handle -> domid -> int array -> unit
   = "stub_xc_domain_sethandle"
 val domain_sethandle : handle -> domid -> 'a Uuid.t -> unit
-external domain_setvmxassist: handle -> domid -> bool -> unit
-  = "stub_xc_domain_setvmxassist"
 external domain_max_vcpus : handle -> domid -> int -> unit
   = "stub_xc_domain_max_vcpus"
 external domain_pause : handle -> domid -> unit = "stub_xc_domain_pause"
@@ -104,9 +102,9 @@ external domain_iomem_permission: handle
        = "stub_xc_domain_iomem_permission"
 external domain_irq_permission: handle -> domid -> int -> bool -> unit
        = "stub_xc_domain_irq_permission"
-external vcpu_affinity_set : handle -> domid -> int -> int64 -> unit
+external vcpu_affinity_set : handle -> domid -> int -> bool array -> unit
   = "stub_xc_vcpu_setaffinity"
-external vcpu_affinity_get : handle -> domid -> int -> int64
+external vcpu_affinity_get : handle -> domid -> int -> bool array
   = "stub_xc_vcpu_getaffinity"
 external vcpu_context_get : handle -> domid -> int -> string
   = "stub_xc_vcpu_context_get"
@@ -147,16 +145,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit
-  = "stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
-
-external hvm_check_pvdriver : handle -> domid -> bool
-  = "stub_xc_hvm_check_pvdriver"
 external version : handle -> version = "stub_xc_version_version"
 external version_compile_info : handle -> compile_info
   = "stub_xc_version_compile_info"
@@ -185,12 +173,12 @@ external domain_set_machine_address_size
 external domain_get_machine_address_size: handle -> domid -> int
        = "stub_xc_domain_get_machine_address_size"
 
-external domain_cpuid_set: handle -> domid -> bool -> (int64 * (int64 option))
+external domain_cpuid_set: handle -> domid -> (int64 * (int64 option))
                         -> string option array
                         -> string option array
        = "stub_xc_domain_cpuid_set"
-external domain_cpuid_apply: handle -> domid -> bool -> unit
-       = "stub_xc_domain_cpuid_apply"
-external cpuid_check: (int64 * (int64 option)) -> string option array -> (bool * string option array)
+external domain_cpuid_apply_policy: handle -> domid -> unit
+       = "stub_xc_domain_cpuid_apply_policy"
+external cpuid_check: handle -> (int64 * (int64 option)) -> string option array -> (bool * string option array)
        = "stub_xc_cpuid_check"
 
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/libs/xc/xc_cpufeature.h
--- a/tools/ocaml/libs/xc/xc_cpufeature.h	Thu Nov 18 05:46:26 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-#ifndef __LIBXC_CPUFEATURE_H
-#define __LIBXC_CPUFEATURE_H
-
-/* Intel-defined CPU features, CPUID level 0x00000001 (edx), word 0 */
-#define X86_FEATURE_FPU		(0*32+ 0) /* Onboard FPU */
-#define X86_FEATURE_VME		(0*32+ 1) /* Virtual Mode Extensions */
-#define X86_FEATURE_DE		(0*32+ 2) /* Debugging Extensions */
-#define X86_FEATURE_PSE 	(0*32+ 3) /* Page Size Extensions */
-#define X86_FEATURE_TSC		(0*32+ 4) /* Time Stamp Counter */
-#define X86_FEATURE_MSR		(0*32+ 5) /* Model-Specific Registers, RDMSR, WRMSR */
-#define X86_FEATURE_PAE		(0*32+ 6) /* Physical Address Extensions */
-#define X86_FEATURE_MCE		(0*32+ 7) /* Machine Check Architecture */
-#define X86_FEATURE_CX8		(0*32+ 8) /* CMPXCHG8 instruction */
-#define X86_FEATURE_APIC	(0*32+ 9) /* Onboard APIC */
-#define X86_FEATURE_SEP		(0*32+11) /* SYSENTER/SYSEXIT */
-#define X86_FEATURE_MTRR	(0*32+12) /* Memory Type Range Registers */
-#define X86_FEATURE_PGE		(0*32+13) /* Page Global Enable */
-#define X86_FEATURE_MCA		(0*32+14) /* Machine Check Architecture */
-#define X86_FEATURE_CMOV	(0*32+15) /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
-#define X86_FEATURE_PAT		(0*32+16) /* Page Attribute Table */
-#define X86_FEATURE_PSE36	(0*32+17) /* 36-bit PSEs */
-#define X86_FEATURE_PN		(0*32+18) /* Processor serial number */
-#define X86_FEATURE_CLFLSH	(0*32+19) /* Supports the CLFLUSH instruction */
-#define X86_FEATURE_DS		(0*32+21) /* Debug Store */
-#define X86_FEATURE_ACPI	(0*32+22) /* ACPI via MSR */
-#define X86_FEATURE_MMX		(0*32+23) /* Multimedia Extensions */
-#define X86_FEATURE_FXSR	(0*32+24) /* FXSAVE and FXRSTOR instructions (fast save and restore */
-				          /* of FPU context), and CR4.OSFXSR available */
-#define X86_FEATURE_XMM		(0*32+25) /* Streaming SIMD Extensions */
-#define X86_FEATURE_XMM2	(0*32+26) /* Streaming SIMD Extensions-2 */
-#define X86_FEATURE_SELFSNOOP	(0*32+27) /* CPU self snoop */
-#define X86_FEATURE_HT		(0*32+28) /* Hyper-Threading */
-#define X86_FEATURE_ACC		(0*32+29) /* Automatic clock control */
-#define X86_FEATURE_IA64	(0*32+30) /* IA-64 processor */
-#define X86_FEATURE_PBE		(0*32+31) /* Pending Break Enable */
-
-/* AMD-defined CPU features, CPUID level 0x80000001, word 1 */
-/* Don't duplicate feature flags which are redundant with Intel! */
-#define X86_FEATURE_SYSCALL	(1*32+11) /* SYSCALL/SYSRET */
-#define X86_FEATURE_MP		(1*32+19) /* MP Capable. */
-#define X86_FEATURE_NX		(1*32+20) /* Execute Disable */
-#define X86_FEATURE_MMXEXT	(1*32+22) /* AMD MMX extensions */
-#define X86_FEATURE_FFXSR       (1*32+25) /* FFXSR instruction optimizations */
-#define X86_FEATURE_PAGE1GB	(1*32+26) /* 1Gb large page support */
-#define X86_FEATURE_RDTSCP	(1*32+27) /* RDTSCP */
-#define X86_FEATURE_LM		(1*32+29) /* Long Mode (x86-64) */
-#define X86_FEATURE_3DNOWEXT	(1*32+30) /* AMD 3DNow! extensions */
-#define X86_FEATURE_3DNOW	(1*32+31) /* 3DNow! */
-
-/* Transmeta-defined CPU features, CPUID level 0x80860001, word 2 */
-#define X86_FEATURE_RECOVERY	(2*32+ 0) /* CPU in recovery mode */
-#define X86_FEATURE_LONGRUN	(2*32+ 1) /* Longrun power control */
-#define X86_FEATURE_LRTI	(2*32+ 3) /* LongRun table interface */
-
-/* Other features, Linux-defined mapping, word 3 */
-/* This range is used for feature bits which conflict or are synthesized */
-#define X86_FEATURE_CXMMX	(3*32+ 0) /* Cyrix MMX extensions */
-#define X86_FEATURE_K6_MTRR	(3*32+ 1) /* AMD K6 nonstandard MTRRs */
-#define X86_FEATURE_CYRIX_ARR	(3*32+ 2) /* Cyrix ARRs (= MTRRs) */
-#define X86_FEATURE_CENTAUR_MCR	(3*32+ 3) /* Centaur MCRs (= MTRRs) */
-/* cpu types for specific tunings: */
-#define X86_FEATURE_K8		(3*32+ 4) /* Opteron, Athlon64 */
-#define X86_FEATURE_K7		(3*32+ 5) /* Athlon */
-#define X86_FEATURE_P3		(3*32+ 6) /* P3 */
-#define X86_FEATURE_P4		(3*32+ 7) /* P4 */
-#define X86_FEATURE_CONSTANT_TSC (3*32+ 8) /* TSC ticks at a constant rate */
-
-/* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
-#define X86_FEATURE_XMM3	(4*32+ 0) /* Streaming SIMD Extensions-3 */
-#define X86_FEATURE_DTES64	(4*32+ 2) /* 64-bit Debug Store */
-#define X86_FEATURE_MWAIT	(4*32+ 3) /* Monitor/Mwait support */
-#define X86_FEATURE_DSCPL	(4*32+ 4) /* CPL Qualified Debug Store */
-#define X86_FEATURE_VMXE	(4*32+ 5) /* Virtual Machine Extensions */
-#define X86_FEATURE_SMXE	(4*32+ 6) /* Safer Mode Extensions */
-#define X86_FEATURE_EST		(4*32+ 7) /* Enhanced SpeedStep */
-#define X86_FEATURE_TM2		(4*32+ 8) /* Thermal Monitor 2 */
-#define X86_FEATURE_SSSE3	(4*32+ 9) /* Supplemental Streaming SIMD Extensions-3 */
-#define X86_FEATURE_CID		(4*32+10) /* Context ID */
-#define X86_FEATURE_CX16        (4*32+13) /* CMPXCHG16B */
-#define X86_FEATURE_XTPR	(4*32+14) /* Send Task Priority Messages */
-#define X86_FEATURE_PDCM	(4*32+15) /* Perf/Debug Capability MSR */
-#define X86_FEATURE_DCA		(4*32+18) /* Direct Cache Access */
-#define X86_FEATURE_SSE4_1	(4*32+19) /* Streaming SIMD Extensions 4.1 */
-#define X86_FEATURE_SSE4_2	(4*32+20) /* Streaming SIMD Extensions 4.2 */
-#define X86_FEATURE_POPCNT	(4*32+23) /* POPCNT instruction */
-#define X86_FEATURE_HYPERVISOR	(4*32+31) /* Running under some hypervisor */
-
-/* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 */
-#define X86_FEATURE_XSTORE	(5*32+ 2) /* on-CPU RNG present (xstore insn) */
-#define X86_FEATURE_XSTORE_EN	(5*32+ 3) /* on-CPU RNG enabled */
-#define X86_FEATURE_XCRYPT	(5*32+ 6) /* on-CPU crypto (xcrypt insn) */
-#define X86_FEATURE_XCRYPT_EN	(5*32+ 7) /* on-CPU crypto enabled */
-#define X86_FEATURE_ACE2	(5*32+ 8) /* Advanced Cryptography Engine v2 */
-#define X86_FEATURE_ACE2_EN	(5*32+ 9) /* ACE v2 enabled */
-#define X86_FEATURE_PHE		(5*32+ 10) /* PadLock Hash Engine */
-#define X86_FEATURE_PHE_EN	(5*32+ 11) /* PHE enabled */
-#define X86_FEATURE_PMM		(5*32+ 12) /* PadLock Montgomery Multiplier */
-#define X86_FEATURE_PMM_EN	(5*32+ 13) /* PMM enabled */
-
-/* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */
-#define X86_FEATURE_LAHF_LM	(6*32+ 0) /* LAHF/SAHF in long mode */
-#define X86_FEATURE_CMP_LEGACY	(6*32+ 1) /* If yes HyperThreading not valid */
-#define X86_FEATURE_SVME        (6*32+ 2) /* Secure Virtual Machine */
-#define X86_FEATURE_EXTAPICSPACE (6*32+ 3) /* Extended APIC space */
-#define X86_FEATURE_ALTMOVCR	(6*32+ 4) /* LOCK MOV CR accesses CR+8 */
-#define X86_FEATURE_ABM		(6*32+ 5) /* Advanced Bit Manipulation */
-#define X86_FEATURE_SSE4A	(6*32+ 6) /* AMD Streaming SIMD Extensions-4a */
-#define X86_FEATURE_MISALIGNSSE	(6*32+ 7) /* Misaligned SSE Access */
-#define X86_FEATURE_3DNOWPF	(6*32+ 8) /* 3DNow! Prefetch */
-#define X86_FEATURE_OSVW	(6*32+ 9) /* OS Visible Workaround */
-#define X86_FEATURE_IBS		(6*32+ 10) /* Instruction Based Sampling */
-#define X86_FEATURE_SSE5	(6*32+ 11) /* AMD Streaming SIMD Extensions-5 */
-#define X86_FEATURE_SKINIT	(6*32+ 12) /* SKINIT, STGI/CLGI, DEV */
-#define X86_FEATURE_WDT		(6*32+ 13) /* Watchdog Timer */
-
-#endif /* __LIBXC_CPUFEATURE_H */
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/libs/xc/xc_cpuid.h
--- a/tools/ocaml/libs/xc/xc_cpuid.h	Thu Nov 18 05:46:26 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,285 +0,0 @@
-#ifndef XC_CPUID_H
-#define XC_CPUID_H
-
-#ifdef XEN_DOMCTL_set_cpuid
-
-#include "xc_cpufeature.h"
-
-#define bitmaskof(idx)      (1u << ((idx) & 31))
-#define clear_bit(idx, dst) ((dst) &= ~(1u << ((idx) & 31)))
-#define set_bit(idx, dst)   ((dst) |= (1u << ((idx) & 31)))
-
-#define DEF_MAX_BASE 0x00000004u
-#define DEF_MAX_EXT  0x80000008u
-
-static void xc_cpuid(uint32_t eax, uint32_t ecx, uint32_t regs[4])
-{
-	unsigned int realecx = (ecx == XEN_CPUID_INPUT_UNUSED) ? 0 : ecx;
-	asm (
-#ifdef __i386__
-	     "push %%ebx; cpuid; mov %%ebx,%1; pop %%ebx"
-#else
-	     "push %%rbx; cpuid; mov %%ebx,%1; pop %%rbx"
-#endif
-	    : "=a" (regs[0]), "=r" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
-	    : "0" (eax), "2" (realecx));
-}
-
-enum { CPU_BRAND_INTEL, CPU_BRAND_AMD, CPU_BRAND_UNKNOWN };
-
-static int xc_cpuid_brand_get(void)
-{
-	uint32_t regs[4];
-	char str[13];
-	uint32_t *istr = (uint32_t *) str;
-
-	xc_cpuid(0, 0, regs);
-	istr[0] = regs[1];
-	istr[1] = regs[3];
-	istr[2] = regs[2];
-	str[12] = '\0';
-	if      (strcmp(str, "AuthenticAMD") == 0) {
-		return CPU_BRAND_AMD;
-	} else if (strcmp(str, "GenuineIntel") == 0) {
-		return CPU_BRAND_INTEL;
-	} else
-		return CPU_BRAND_UNKNOWN;
-}
-
-static int hypervisor_is_64bit(int xc)
-{
-	xen_capabilities_info_t xen_caps;
-	return ((xc_version(xc, XENVER_capabilities, &xen_caps) == 0) &&
-	        (strstr(xen_caps, "x86_64") != NULL));
-}
-
-static void do_hvm_cpuid_policy(int xc, int domid, uint32_t input, uint32_t regs[4])
-{
-	unsigned long is_pae;
-	int brand;
-
-	/* pae ? */
-	xc_get_hvm_param(xc, domid, HVM_PARAM_PAE_ENABLED, &is_pae);
-	is_pae = !!is_pae;
-
-	switch (input) {
-	case 0x00000000:
-		if (regs[0] > DEF_MAX_BASE)
-			regs[0] = DEF_MAX_BASE;
-		break;
-	case 0x00000001:
-		regs[2] &= (bitmaskof(X86_FEATURE_XMM3) |
-				bitmaskof(X86_FEATURE_SSSE3) |
-				bitmaskof(X86_FEATURE_CX16) |
-				bitmaskof(X86_FEATURE_SSE4_1) |
-				bitmaskof(X86_FEATURE_SSE4_2) |
-				bitmaskof(X86_FEATURE_POPCNT));
-
-                regs[2] |= bitmaskof(X86_FEATURE_HYPERVISOR);
-
-		regs[3] &= (bitmaskof(X86_FEATURE_FPU) |
-				bitmaskof(X86_FEATURE_VME) |
-				bitmaskof(X86_FEATURE_DE) |
-				bitmaskof(X86_FEATURE_PSE) |
-				bitmaskof(X86_FEATURE_TSC) |
-				bitmaskof(X86_FEATURE_MSR) |
-				bitmaskof(X86_FEATURE_PAE) |
-				bitmaskof(X86_FEATURE_MCE) |
-				bitmaskof(X86_FEATURE_CX8) |
-				bitmaskof(X86_FEATURE_APIC) |
-				bitmaskof(X86_FEATURE_SEP) |
-				bitmaskof(X86_FEATURE_MTRR) |
-				bitmaskof(X86_FEATURE_PGE) |
-				bitmaskof(X86_FEATURE_MCA) |
-				bitmaskof(X86_FEATURE_CMOV) |
-				bitmaskof(X86_FEATURE_PAT) |
-				bitmaskof(X86_FEATURE_CLFLSH) |
-				bitmaskof(X86_FEATURE_MMX) |
-				bitmaskof(X86_FEATURE_FXSR) |
-				bitmaskof(X86_FEATURE_XMM) |
-				bitmaskof(X86_FEATURE_XMM2));
-		/* We always support MTRR MSRs. */
-		regs[3] |= bitmaskof(X86_FEATURE_MTRR);
-
-		if (!is_pae)
-			clear_bit(X86_FEATURE_PAE, regs[3]);
-		break;
-	case 0x80000000:
-		if (regs[0] > DEF_MAX_EXT)
-			regs[0] = DEF_MAX_EXT;
-		break;
-	case 0x80000001:
-		if (!is_pae)
-			clear_bit(X86_FEATURE_NX, regs[3]);
-		break;
-	case 0x80000008:
-		regs[0] &= 0x0000ffffu;
-		regs[1] = regs[2] = regs[3] = 0;
-		break;
-	case 0x00000002: /* Intel cache info (dumped by AMD policy) */
-	case 0x00000004: /* Intel cache info (dumped by AMD policy) */
-	case 0x80000002: /* Processor name string */
-	case 0x80000003: /* ... continued         */
-	case 0x80000004: /* ... continued         */
-	case 0x80000005: /* AMD L1 cache/TLB info (dumped by Intel policy) */
-	case 0x80000006: /* AMD L2/3 cache/TLB info ; Intel L2 cache features */
-		break;
-	default:
-		regs[0] = regs[1] = regs[2] = regs[3] = 0;
-		break;
-	}
-	
-	brand = xc_cpuid_brand_get();
-	if (brand == CPU_BRAND_AMD) {
-		switch (input) {
-		case 0x00000001:
-			/* Mask Intel-only features. */
-			regs[2] &= ~(bitmaskof(X86_FEATURE_SSSE3) |
-					bitmaskof(X86_FEATURE_SSE4_1) |
-					bitmaskof(X86_FEATURE_SSE4_2));
-			break;
-
-		case 0x00000002:
-		case 0x00000004:
-			regs[0] = regs[1] = regs[2] = 0;
-			break;
-
-		case 0x80000001: {
-			int is_64bit = hypervisor_is_64bit(xc) && is_pae;
-
-			if (!is_pae)
-				 clear_bit(X86_FEATURE_PAE, regs[3]);
-			clear_bit(X86_FEATURE_PSE36, regs[3]);
-
-			/* Filter all other features according to a whitelist. */
-			regs[2] &= ((is_64bit ? bitmaskof(X86_FEATURE_LAHF_LM) : 0) |
-					 bitmaskof(X86_FEATURE_ALTMOVCR) |
-					 bitmaskof(X86_FEATURE_ABM) |
-					 bitmaskof(X86_FEATURE_SSE4A) |
-					 bitmaskof(X86_FEATURE_MISALIGNSSE) |
-					 bitmaskof(X86_FEATURE_3DNOWPF));
-			regs[3] &= (0x0183f3ff | /* features shared with 0x00000001:EDX */
-					 (is_pae ? bitmaskof(X86_FEATURE_NX) : 0) |
-					 (is_64bit ? bitmaskof(X86_FEATURE_LM) : 0) |
-					 bitmaskof(X86_FEATURE_SYSCALL) |
-					 bitmaskof(X86_FEATURE_MP) |
-					 bitmaskof(X86_FEATURE_MMXEXT) |
-					 bitmaskof(X86_FEATURE_FFXSR) |
-					 bitmaskof(X86_FEATURE_3DNOW) |
-					 bitmaskof(X86_FEATURE_3DNOWEXT));
-			break;
-			}
-		}
-	} else if (brand == CPU_BRAND_INTEL) {
-		switch (input) {
-		case 0x00000001:
-			/* Mask AMD-only features. */
-			regs[2] &= ~(bitmaskof(X86_FEATURE_POPCNT));
-			break;
-
-		case 0x00000004:
-			regs[0] &= 0x3FF;
-			regs[3] &= 0x3FF;
-			break;
-
-		case 0x80000001:
-			{
-			int is_64bit = hypervisor_is_64bit(xc) && is_pae;
-
-			/* Only a few features are advertised in Intel's 0x80000001. */
-			regs[2] &= (is_64bit ? bitmaskof(X86_FEATURE_LAHF_LM) : 0);
-			regs[3] &= ((is_pae ? bitmaskof(X86_FEATURE_NX) : 0) |
-					(is_64bit ? bitmaskof(X86_FEATURE_LM) : 0) |
-					(is_64bit ? bitmaskof(X86_FEATURE_SYSCALL) : 0));
-			break;
-			}
-		case 0x80000005:
-			{
-			regs[0] = regs[1] = regs[2] = 0;
-			break;
-			}
-		}
-	}
-}
-
-static void do_pv_cpuid_policy(int xc, int domid, uint32_t input, uint32_t regs[4])
-{
-	int brand;
-	int guest_64_bits, xen_64_bits;
-	int ret;
-	
-	ret = xc_domain_get_machine_address_size(xc, domid);
-	if (ret < 0)
-		return;
-	guest_64_bits = (ret == 64);
-	xen_64_bits = hypervisor_is_64bit(xc);
-	brand = xc_cpuid_brand_get();
-
-	if ((input & 0x7fffffff) == 1) {
-		clear_bit(X86_FEATURE_VME, regs[3]);
-		clear_bit(X86_FEATURE_PSE, regs[3]);
-		clear_bit(X86_FEATURE_PGE, regs[3]);
-		clear_bit(X86_FEATURE_MCE, regs[3]);
-		clear_bit(X86_FEATURE_MCA, regs[3]);
-		clear_bit(X86_FEATURE_MTRR, regs[3]);
-		clear_bit(X86_FEATURE_PSE36, regs[3]);
-	}
-
-	switch (input) {
-	case 1:
-		if (!xen_64_bits || brand == CPU_BRAND_AMD)
-			clear_bit(X86_FEATURE_SEP, regs[3]);
-		clear_bit(X86_FEATURE_DS, regs[3]);
-		clear_bit(X86_FEATURE_ACC, regs[3]);
-		clear_bit(X86_FEATURE_PBE, regs[3]);
-
-		clear_bit(X86_FEATURE_DTES64, regs[2]);
-		clear_bit(X86_FEATURE_MWAIT, regs[2]);
-		clear_bit(X86_FEATURE_DSCPL, regs[2]);
-		clear_bit(X86_FEATURE_VMXE, regs[2]);
-		clear_bit(X86_FEATURE_SMXE, regs[2]);
-		clear_bit(X86_FEATURE_EST, regs[2]);
-		clear_bit(X86_FEATURE_TM2, regs[2]);
-		if (!guest_64_bits)
-			clear_bit(X86_FEATURE_CX16, regs[2]);
-		clear_bit(X86_FEATURE_XTPR, regs[2]);
-		clear_bit(X86_FEATURE_PDCM, regs[2]);
-		clear_bit(X86_FEATURE_DCA, regs[2]);
-		break;
-	case 0x80000001:
-		if (!guest_64_bits) {
-			clear_bit(X86_FEATURE_LM, regs[3]);
-			clear_bit(X86_FEATURE_LAHF_LM, regs[2]);
-			if (brand != CPU_BRAND_AMD)
-				clear_bit(X86_FEATURE_SYSCALL, regs[3]);
-		} else
-			set_bit(X86_FEATURE_SYSCALL, regs[3]);
-		clear_bit(X86_FEATURE_PAGE1GB, regs[3]);
-		clear_bit(X86_FEATURE_RDTSCP, regs[3]);
-
-		clear_bit(X86_FEATURE_SVME, regs[2]);
-		clear_bit(X86_FEATURE_OSVW, regs[2]);
-		clear_bit(X86_FEATURE_IBS, regs[2]);
-		clear_bit(X86_FEATURE_SKINIT, regs[2]);
-		clear_bit(X86_FEATURE_WDT, regs[2]);
-		break;
-	case 5: /* MONITOR/MWAIT */
-	case 0xa: /* Architectural Performance Monitor Features */
-	case 0x8000000a: /* SVM revision and features */
-	case 0x8000001b: /* Instruction Based Sampling */
-		regs[0] = regs[1] = regs[2] = regs[3] = 0;
-		break;
-	}
-}
-
-static void do_cpuid_policy(int xc, int domid, int hvm, uint32_t input, uint32_t regs[4])
-{
-	if (hvm)
-		do_hvm_cpuid_policy(xc, domid, input, regs);
-	else
-		do_pv_cpuid_policy(xc, domid, input, regs);
-}
-
-#endif
-
-#endif
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/libs/xc/xc_e820.h
--- a/tools/ocaml/libs/xc/xc_e820.h	Thu Nov 18 05:46:26 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#ifndef __XC_E820_H__
-#define __XC_E820_H__
-
-#include <xen/hvm/e820.h>
-
-/*
- * PC BIOS standard E820 types and structure.
- */
-#define E820_RAM          1
-#define E820_RESERVED     2
-#define E820_ACPI         3
-#define E820_NVS          4
-
-struct e820entry {
-    uint64_t addr;
-    uint64_t size;
-    uint32_t type;
-} __attribute__((packed));
-
-#endif /* __XC_E820_H__ */
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/libs/xc/xc_lib.c
--- a/tools/ocaml/libs/xc/xc_lib.c	Thu Nov 18 05:46:26 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1537 +0,0 @@
-/*
- * Copyright (C) 2006-2007 XenSource Ltd.
- * Copyright (C) 2008      Citrix Ltd.
- * Author Vincent Hanquez <vincent.hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; version 2.1 only. with the special
- * exception on linking described in file LICENSE.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- */
-
-#include <stdint.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-#include "xc.h"
-
-#define PAGE_SHIFT		12
-#define PAGE_SIZE               (1UL << PAGE_SHIFT)
-#define PAGE_MASK               (~(PAGE_SIZE-1))
-
-#define MIN(a, b) 		(((a) < (b)) ? (a) : (b))
-
-#define DECLARE_DOMCTL(_cmd, _domain)	\
-	struct xen_domctl domctl = {    \
-		.cmd = _cmd,		\
-		.domain = _domain,	\
-		.interface_version = XEN_DOMCTL_INTERFACE_VERSION, \
-	}
-
-#define DECLARE_SYSCTL(_cmd)		\
-	struct xen_sysctl sysctl = {	\
-		.cmd = _cmd,		\
-		.interface_version = XEN_SYSCTL_INTERFACE_VERSION, \
-	}
-
-#define DECLARE_HYPERCALL2(_cmd, _arg0, _arg1)	\
-	privcmd_hypercall_t hypercall = {	\
-		.op = _cmd,			\
-		.arg[0] = (unsigned long) _arg0,\
-		.arg[1] = (unsigned long) _arg1,\
-	}
-#define DECLARE_HYPERCALL0(_cmd)	DECLARE_HYPERCALL2(_cmd, 0, 0);
-#define DECLARE_HYPERCALL1(_cmd, _arg0)	DECLARE_HYPERCALL2(_cmd, _arg0, 0);
-
-/*---- Errors handlings ----*/
-#ifndef WITHOUT_GOOD_ERROR
-#define ERROR_STRLEN 256
-
-static char __error_str[ERROR_STRLEN];
-
-char * xc_error_get(void)
-{
-	return __error_str;
-}
-
-static void xc_error_set(const char *fmt, ...)
-{
-	va_list ap;
-	char __errordup[ERROR_STRLEN];
-
-	va_start(ap, fmt);
-	vsnprintf(__errordup, ERROR_STRLEN, fmt, ap);
-	va_end(ap);
-	memcpy(__error_str, __errordup, ERROR_STRLEN);
-}
-
-static void xc_error_dom_set(unsigned int domid, const char *fmt, ...)
-{
-	va_list ap;
-	char __errordup[ERROR_STRLEN];
-	int i;
-
-	i = snprintf(__errordup, ERROR_STRLEN, "domain %u - ", domid);
-	va_start(ap, fmt);
-	i += vsnprintf(__errordup + i, ERROR_STRLEN - i, fmt, ap);
-	va_end(ap);
-	snprintf(__errordup + i, ERROR_STRLEN - i,
-	         " failed: %s", xc_error_get());
-	memcpy(__error_str, __errordup, ERROR_STRLEN);
-}
-
-void xc_error_clear(void)
-{
-	memset(__error_str, '\0', ERROR_STRLEN);
-}
-#else
-char * xc_error_get(void)
-{
-	return "";
-}
-#define xc_error_set(fmt, ...) do {} while (0)
-#define xc_error_dom_set(id, fmt, ...) do {} while (0)
-#define xc_error_clear() do {} while (0)
-#endif
-
-#define xc_error_hypercall(_h, _r) \
-	xc_error_set("hypercall %lld fail: %d: %s (ret %d)", _h.op, errno, errno ? strerror(errno) : strerror(-_r), _r)
-
-int xc_using_injection(void)
-{
-	return 0;
-}
-
-/*---- Trivia ----*/
-int xc_interface_open(void)
-{
-	int fd, ret;
-
-	fd = open("/proc/xen/privcmd", O_RDWR);
-	if (fd == -1) {
-		xc_error_set("open /proc/xen/privcmd failed: %s",
-		             strerror(errno));
-		return -1;
-	}
-
-	ret = fcntl(fd, F_GETFD);
-	if (ret < 0) {
-		xc_error_set("cannot get handle flags: %s",
-		             strerror(errno));
-		goto out;
-	}
-
-	ret = fcntl(fd, F_SETFD, ret | FD_CLOEXEC);
-	if (ret < 0) {
-		xc_error_set("cannot set handle flags: %s",
-		             strerror(errno));
-		goto out;
-	}
-
-	return fd;
-out:
-	close(fd);
-	return -1;
-}
-
-int xc_interface_close(int handle)
-{
-	int ret;
-
-	ret = close(handle);
-	if (ret != 0)
-		xc_error_set("close xc failed: %s", strerror(errno));
-	return ret;
-}
-
-/*---- Low private operations ----*/
-static int do_xen_hypercall(int handle, privcmd_hypercall_t *hypercall)
-{
-	return ioctl(handle, IOCTL_PRIVCMD_HYPERCALL, (unsigned long) hypercall);
-}
-
-static int do_domctl(int handle, struct xen_domctl *domctl)
-{
-	int ret;
-	DECLARE_HYPERCALL1(__HYPERVISOR_domctl, domctl);
-
-	if (mlock(domctl, sizeof(*domctl)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0)
-		xc_error_hypercall(hypercall, ret);
-
-	munlock(domctl, sizeof(*domctl));
-	return ret;
-}
-
-static int do_sysctl(int handle, struct xen_sysctl *sysctl)
-{
-	int ret;
-	DECLARE_HYPERCALL1(__HYPERVISOR_sysctl, sysctl);
-
-	if (mlock(sysctl, sizeof(*sysctl)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0)
-		xc_error_hypercall(hypercall, ret);
-
-	munlock(sysctl, sizeof(*sysctl));
-	return ret;
-}
-
-static int do_evtchnctl(int handle, int cmd, void *arg, size_t arg_size)
-{
-	DECLARE_HYPERCALL2(__HYPERVISOR_event_channel_op, cmd, arg);
-	int ret;
-
-	if (mlock(arg, arg_size) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0)
-		xc_error_hypercall(hypercall, ret);
-	munlock(arg, arg_size);
-	return ret;
-}
-
-static int do_memctl_reservation(int handle, int cmd,
-                                 struct xen_memory_reservation *reservation)
-{
-	int ret;
-	DECLARE_HYPERCALL2(__HYPERVISOR_memory_op, cmd, reservation);
-	xen_pfn_t *extent_start;
-
-	if (cmd != XENMEM_increase_reservation &&
-	    cmd != XENMEM_decrease_reservation &&
-	    cmd != XENMEM_populate_physmap) {
-		xc_error_set("do_memctl_reservation: unknown cmd %d", cmd);
-		return -EINVAL;
-	}
-
-	if (mlock(reservation, sizeof(*reservation)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -ENOMEM;
-	}
-	get_xen_guest_handle(extent_start, reservation->extent_start);
-	if (extent_start && mlock(extent_start, reservation->nr_extents
-	                                      * sizeof(xen_pfn_t)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		munlock(reservation, sizeof(*reservation));
-		return -3;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-	munlock(extent_start, reservation->nr_extents * sizeof(xen_pfn_t));
-	get_xen_guest_handle(extent_start, reservation->extent_start);
-	munlock(reservation, sizeof(*reservation));
-	return ret;
-}
-
-static int do_ioctl(int handle, int cmd, void *arg)
-{
-	return ioctl(handle, cmd, arg);
-}
-
-static void * do_mmap(void *start, size_t length, int prot, int flags,
-                      int fd, off_t offset)
-{
-	return mmap(start, length, prot, flags, fd, offset);
-}
-
-int xc_get_hvm_param(int handle, unsigned int domid,
-                     int param, unsigned long *value)
-{
-	struct xen_hvm_param arg = {
-		.domid = domid,
-		.index = param,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_get_param,
-	                   (unsigned long) &arg);
-	int ret;
-
-	if (mlock(&arg, sizeof(arg)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-	*value = arg.value;
-	munlock(&arg, sizeof(arg));
-	return ret;
-}
-
-static int xc_set_hvm_param(int handle, unsigned int domid,
-                            int param, unsigned long value)
-{
-	struct xen_hvm_param arg = {
-		.domid = domid,
-		.index = param,
-		.value = value,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_set_param, (unsigned long) &arg);
-	int ret;
-
-	if (mlock(&arg, sizeof(arg)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-	munlock(&arg, sizeof(arg));
-	return ret;
-}
-
-
-/*---- XC API ----*/
-int xc_domain_create(int handle, unsigned int ssidref,
-                     xen_domain_handle_t dhandle,
-                     unsigned int flags, unsigned int *pdomid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_createdomain, *pdomid);
-	domctl.u.createdomain.ssidref = ssidref;
-	domctl.u.createdomain.flags = flags;
-	memcpy(domctl.u.createdomain.handle, dhandle, sizeof(xen_domain_handle_t));
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0) {
-		xc_error_set("creating domain failed: %s", xc_error_get());
-		return ret;
-	}
-	*pdomid = domctl.domain;
-	return 0;
-}
-
-int xc_domain_pause(int handle, unsigned int domid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_pausedomain, domid);
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_dom_set(domid, "pause");
-	return ret;
-}
-
-int xc_domain_unpause(int handle, unsigned int domid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_unpausedomain, domid);
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_dom_set(domid, "unpause");
-	return ret;
-}
-
-/* return 1 if hvm domain got pv driver, 0 if not. -1 is error occurs */
-int xc_hvm_check_pvdriver(int handle, unsigned int domid)
-{
-	int ret;
-	unsigned long irq = 0;
-	xc_domaininfo_t info;
-
-	ret = xc_domain_getinfolist(handle, domid, 1, &info);
-	if (ret != 1) {
-		xc_error_set("domain getinfo failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "hvm_check_pvdriver");
-		return -1;
-	}
-
-	if (!(info.flags & XEN_DOMINF_hvm_guest)) {
-		xc_error_set("domain is not hvm");
-		xc_error_dom_set(domid, "hvm_check_pvdriver");
-		return -1;
-	}
-	xc_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
-	return irq;
-}
-
-static int modify_returncode_register(int handle, unsigned int domid)
-{
-	int ret;
-	xc_domaininfo_t info;
-	xen_capabilities_info_t caps;
-	vcpu_guest_context_any_t context;
-
-	ret = xc_domain_getinfolist(handle, domid, 1, &info);
-	if (ret != 1) {
-		xc_error_set("domain getinfo failed: %s", strerror(errno));
-		return -1;
-	}
-
-	/* HVM guests without PV drivers do not have a return code to modify */
-	if (info.flags & XEN_DOMINF_hvm_guest) {
-		unsigned long irq = 0;
-		xc_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
-		if (!irq)
-			return 0;
-	}
-
-	ret = xc_version(handle, XENVER_capabilities, &caps);
-	if (ret) {
-		xc_error_set("could not get Xen capabilities");
-		return ret;
-	}
-
-	ret = xc_vcpu_getcontext(handle, domid, 0, &context);
-	if (ret) {
-		xc_error_set("could not get vcpu 0 context");
-		return ret;
-	}
-
-	if (!(info.flags & XEN_DOMINF_hvm_guest))
-		context.c.user_regs.eax = 1;
-	else if (strstr(caps, "x86_64"))
-		context.x64.user_regs.eax = 1;
-	else
-		context.x32.user_regs.eax = 1;
-
-	ret = xc_vcpu_setcontext(handle, domid, 0, &context);
-	if (ret) {
-		xc_error_set("could not set vcpu 0 context");
-		return ret;
-	}
-	return 0;
-}
-
-int xc_domain_resume_fast(int handle, unsigned int domid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_resumedomain, domid);
-
-	ret = modify_returncode_register(handle, domid);
-	if (ret != 0) {
-		xc_error_dom_set(domid, "resume_fast");
-		return ret;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_dom_set(domid, "resume_fast");
-	return ret;
-}
-
-int xc_domain_destroy(int handle, unsigned int domid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_destroydomain, domid);
-
-	do {
-		ret = do_domctl(handle, &domctl);
-	} while (ret && (errno == EAGAIN));
-	if (ret != 0)
-		xc_error_dom_set(domid, "destroy");
-	return ret;
-}
-
-int xc_domain_shutdown(int handle, int domid, int reason)
-{
-	sched_remote_shutdown_t arg = {
-		.domain_id = domid,
-		.reason = reason,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_sched_op, SCHEDOP_remote_shutdown, &arg);
-	int ret;
-
-	if (mlock(&arg, sizeof(arg)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "shutdown %d", reason);
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0) {
-		xc_error_hypercall(hypercall, ret);
-		xc_error_dom_set(domid, "shutdown %d", reason);
-	}
-	munlock(&arg, sizeof(arg));
-	return ret;
-}
-
-static void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits)
-{
-    uint64_t l;
-    int i, j, b;
-
-    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
-        l = lp[i];
-        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
-            bp[b+j] = l;
-            l >>= 8;
-            nbits -= 8;
-        }
-    }
-}
-
-static void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits)
-{
-    uint64_t l;
-    int i, j, b;
-
-    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
-        l = 0;
-        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
-            l |= (uint64_t)bp[b+j] << (j*8);
-            nbits -= 8;
-        }
-        lp[i] = l;
-    }
-}
-
-int xc_vcpu_setaffinity(int handle, unsigned int domid, int vcpu,
-                        uint64_t cpumap)
-{
-	int ret;
-	uint8_t local[sizeof(cpumap)];
-	DECLARE_DOMCTL(XEN_DOMCTL_setvcpuaffinity, domid);
-	domctl.u.vcpuaffinity.vcpu = vcpu;
-	domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
-
-	bitmap_64_to_byte(local, &cpumap, sizeof(cpumap)*8);
-	set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
-
-	if (mlock(&cpumap, sizeof(cpumap)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "vcpu %d set affinity", vcpu);
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "vcpu %d set affinity", vcpu);
-	munlock(&cpumap, sizeof(cpumap));
-	return ret;
-}
-
-int xc_vcpu_getaffinity(int handle, unsigned int domid, int vcpu,
-                        uint64_t *cpumap)
-{
-	int ret;
-	uint8_t local[sizeof(*cpumap)];
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpuaffinity, domid);
-	domctl.u.vcpuaffinity.vcpu = vcpu;
-	domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
-
-	set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
-
-	if (mlock(cpumap, sizeof(*cpumap)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "vcpu %d get affinity", vcpu);
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "vcpu %d get affinity", vcpu);
-	munlock(cpumap, sizeof(*cpumap));
-	bitmap_byte_to_64(cpumap, local, sizeof(*cpumap) * 8);
-	return ret;
-}
-
-int xc_vcpu_context_get(int handle, unsigned int domid, unsigned short vcpu,
-                        struct vcpu_guest_context *ctxt)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpucontext, domid);
-	domctl.u.vcpucontext.vcpu = vcpu;
-
-	set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
-
-	if (mlock(ctxt, sizeof(struct vcpu_guest_context)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "vcpu %d get context", vcpu);
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "vcpu %d get context", vcpu);
-	munlock(ctxt, sizeof(struct vcpu_guest_context));
-
-	return ret;
-}
-
-int xc_domain_getinfolist(int handle, unsigned int first_domain,
-                          unsigned int max_domains, xc_domaininfo_t *info)
-{
-	int ret;
-	DECLARE_SYSCTL(XEN_SYSCTL_getdomaininfolist);
-	sysctl.u.getdomaininfolist.first_domain = first_domain;
-	sysctl.u.getdomaininfolist.max_domains = max_domains;
-	set_xen_guest_handle(sysctl.u.getdomaininfolist.buffer, info);
-
-	if (mlock(info, max_domains * sizeof(xc_domaininfo_t)) != 0) {
-		xc_error_set("getinfolist(%d, %u, %u, %x (%d)) failed: mlock failed: %s",
-			     handle, first_domain, max_domains, info, sizeof(xc_domaininfo_t),
-		             strerror(errno));
-		return -1;
-	}
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret < 0)
-		xc_error_set("getinfolist(%d, %u, %u, %x (%d)) failed: %s", 
-			     handle, first_domain, max_domains, info, sizeof(xc_domaininfo_t),
-			     xc_error_get());
-	else
-		ret = sysctl.u.getdomaininfolist.num_domains;
-
-	munlock(info, max_domains * sizeof(xc_domaininfo_t));
-	return ret;
-}
-
-int xc_domain_getinfo(int handle, unsigned int domid, xc_domaininfo_t *info)
-{
-	int ret;
-	ret = xc_domain_getinfolist(handle, domid, 1, info);
-	if (ret != 1) {
-		xc_error_set("getinfo failed: domain %d: %s", domid, xc_error_get());
-		return -1;
-	}
-
-	/* If the requested domain didn't exist but there exists one with a 
-	   higher domain ID, this will be returned. We consider this an error since
-	   we only wanted info about a specific domain. */
-	if (info->domain != domid) {
-		xc_error_set("getinfo failed: domain %d nolonger exists", domid);
-		return -1;
-	}
-
-	return 0;
-}
-
-int xc_domain_setmaxmem(int handle, unsigned int domid, unsigned int max_memkb)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_max_mem, domid);
-	domctl.u.max_mem.max_memkb = max_memkb;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "set max memory to %u", max_memkb);
-	return ret;
-}
-
-int xc_domain_set_memmap_limit(int handle, unsigned int domid,
-                               unsigned long map_limitkb)
-{
-	int ret;
-	struct xen_foreign_memory_map fmap = {
-		.domid = domid,
-		.map = { .nr_entries = 1 }
-	};
-	struct e820entry e820 = {
-		.addr = 0,
-		.size = (uint64_t)map_limitkb << 10,
-		.type = E820_RAM
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_memory_op, XENMEM_set_memory_map, &fmap);
-
-	set_xen_guest_handle(fmap.map.buffer, &e820);
-
-	if (mlock(&fmap, sizeof(fmap)) != 0) {
-		xc_error_set("set_memmap_limit failed: mlock failed: %s",
-		             strerror(errno));
-		return -1;
-	}
-
-	if (mlock(&e820, sizeof(e820)) != 0) {
-		xc_error_set("set_memmap_limit failed: mlock failed: %s",
-		             strerror(errno));
-		munlock(&fmap, sizeof(fmap));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-
-	munlock(&e820, sizeof(e820));
-	munlock(&fmap, sizeof(fmap));
-	return ret;
-}
-
-int xc_domain_set_time_offset(int handle, unsigned int domid, int time_offset)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_settimeoffset, domid);
-	domctl.u.settimeoffset.time_offset_seconds = time_offset;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "set time offset %d", time_offset);
-	return ret;
-}
-
-int xc_domain_memory_increase_reservation(int handle, unsigned int domid,
-                                          unsigned long nr_extents,
-                                          unsigned int extent_order,
-                                          unsigned int address_bits,
-                                          xen_pfn_t *extent_start)
-{
-	int ret;
-	struct xen_memory_reservation reservation = {
-		.nr_extents   = nr_extents,
-		.extent_order = extent_order,
-		.COMPAT_FIELD_ADDRESS_BITS = address_bits,
-		.domid        = domid
-	};
-
-	set_xen_guest_handle(reservation.extent_start, extent_start);
-
-	ret = do_memctl_reservation(handle, XENMEM_increase_reservation,
-	                            &reservation);
-	if (ret != nr_extents) {
-		xc_error_dom_set(domid, "increase reservation to %lu",
-		                 nr_extents);
-		return (ret >= 0) ? -1 : ret;
-	}
-	return 0;
-}
-
-int xc_domain_memory_decrease_reservation(int handle, unsigned int domid,
-                                          unsigned long nr_extents,
-                                          unsigned int extent_order,
-                                          unsigned int address_bits,
-                                          xen_pfn_t *extent_start)
-{
-	int ret;
-	struct xen_memory_reservation reservation = {
-		.nr_extents   = nr_extents,
-		.extent_order = extent_order,
-		.COMPAT_FIELD_ADDRESS_BITS = 0,
-		.domid        = domid
-	};
-
-	set_xen_guest_handle(reservation.extent_start, extent_start);
-	if (!extent_start) {
-		xc_error_set("decrease reservation: extent start is NULL");
-		return -EINVAL;
-	}
-
-	ret = do_memctl_reservation(handle, XENMEM_decrease_reservation,
-	                            &reservation);
-	if (ret < nr_extents) {
-		xc_error_dom_set(domid, "decrease reservation to %lu",
-		                 nr_extents);
-		return (ret >= 0) ? -1 : ret;
-	}
-	return 0;
-}
-
-int xc_domain_memory_populate_physmap(int handle, unsigned int domid,
-                                      unsigned long nr_extents,
-                                      unsigned int extent_order,
-                                      unsigned int address_bits,
-                                      xen_pfn_t *extent_start)
-{
-	int ret;
-	struct xen_memory_reservation reservation = {
-		.nr_extents   = nr_extents,
-		.extent_order = extent_order,
-		.COMPAT_FIELD_ADDRESS_BITS = address_bits,
-		.domid        = domid
-	};
-
-	set_xen_guest_handle(reservation.extent_start, extent_start);
-	ret = do_memctl_reservation(handle, XENMEM_populate_physmap,
-	                            &reservation);
-	if (ret < nr_extents) {
-		xc_error_dom_set(domid, "populate physmap");
-		return (ret >= 0) ? -1 : ret;
-	}
-	return 0;
-}
-
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist)
-{
-	int ret = 0;
-#ifdef XEN_DOMCTL_setvmxassist
-	DECLARE_DOMCTL(XEN_DOMCTL_setvmxassist, domid);
-	domctl.u.setvmxassist.use_vmxassist = use_vmxassist;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "setting vmxassist to %d",
-				 use_vmxassist);
-#endif
-	return ret;
-}
-
-int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_max_vcpus, domid);
-	domctl.u.max_vcpus.max = max;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "setting max vcpus to %d", max);
-	return ret;
-}
-
-int xc_domain_sethandle(int handle, unsigned int domid,
-                        xen_domain_handle_t dhandle)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_setdomainhandle, domid);
-	memcpy(domctl.u.setdomainhandle.handle, dhandle, sizeof(xen_domain_handle_t));
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "set handle");
-	return ret;
-}
-
-int xc_vcpu_getinfo(int handle, unsigned int domid, unsigned int vcpu,
-                    xc_vcpuinfo_t *info)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpuinfo, domid);
-	domctl.u.getvcpuinfo.vcpu = vcpu;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0) {
-		xc_error_dom_set(domid, "vcpu %u getinfo", vcpu);
-		return ret;
-	}
-	memcpy(info, &domctl.u.getvcpuinfo, sizeof(*info));
-	return ret;
-}
-
-int xc_domain_ioport_permission(int handle, unsigned int domid,
-                                unsigned int first_port, unsigned int nr_ports,
-                                unsigned int allow_access)
-{
-	DECLARE_DOMCTL(XEN_DOMCTL_ioport_permission, domid);
-	domctl.u.ioport_permission.first_port = first_port;
-	domctl.u.ioport_permission.nr_ports = nr_ports;
-	domctl.u.ioport_permission.allow_access = allow_access;
-
-	return do_domctl(handle, &domctl);
-}
-
-int xc_vcpu_getcontext(int handle, unsigned int domid,
-                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpucontext, domid);
-	domctl.u.vcpucontext.vcpu = vcpu;
-	set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt->c);
-
-	if (mlock(ctxt, sizeof(*ctxt)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "vcpu %u getcontext", vcpu);
-	munlock(ctxt, sizeof(*ctxt));
-	return ret;
-}
-
-int xc_vcpu_setcontext(int handle, unsigned int domid,
-                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_setvcpucontext, domid);
-	domctl.u.vcpucontext.vcpu = vcpu;
-	set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt->c);
-
-	if (mlock(ctxt, sizeof(*ctxt)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "vcpu %u setcontext", vcpu);
-
-	munlock(ctxt, sizeof(*ctxt));
-	return ret;
-}
-
-int xc_domain_irq_permission(int handle, unsigned int domid,
-                             unsigned char pirq, unsigned char allow_access)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_irq_permission, domid);
-	domctl.u.irq_permission.pirq = pirq;
-	domctl.u.irq_permission.allow_access = allow_access;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "irq permission %u to %u",
-		                 pirq, allow_access);
-	return ret;
-}
-
-int xc_domain_iomem_permission(int handle, unsigned int domid,
-                               unsigned long first_mfn, unsigned long nr_mfns,
-                               unsigned char allow_access)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_iomem_permission, domid);
-	domctl.u.iomem_permission.first_mfn = first_mfn;
-	domctl.u.iomem_permission.nr_mfns = nr_mfns;
-	domctl.u.iomem_permission.allow_access = allow_access;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "iomem permission [%lu, %lu] to %u",
-		                 first_mfn, first_mfn + nr_mfns, allow_access);
-	return ret;
-}
-
-long long xc_domain_get_cpu_usage(int handle, unsigned int domid,
-                                  unsigned int vcpu)
-{
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpuinfo, domid);
-	domctl.u.getvcpuinfo.vcpu = vcpu;
-
-	if (do_domctl(handle, &domctl) < 0) {
-		xc_error_dom_set(domid, "get cpu %d usage", vcpu);
-		return -1;
-	}
-	return domctl.u.getvcpuinfo.cpu_time;
-}
-
-void *xc_map_foreign_range(int handle, unsigned int domid,
-                           int size, int prot, unsigned long mfn)
-{
-	privcmd_mmap_entry_t entry = {
-		.mfn = mfn,
-		.npages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT,
-	};
-	privcmd_mmap_t ioctlx = {
-		.num = 1,
-		.dom = domid,
-		.entry = &entry,
-	};
-	void *addr;
-
-	addr = do_mmap(NULL, size, prot, MAP_SHARED, handle, 0);
-	if (addr == MAP_FAILED) {
-		xc_error_set("mmap failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "map foreign range [%lx,%lx] prot %u",
-		                 mfn, mfn + size, prot);
-		return NULL;
-	}
-	entry.va = (unsigned long) addr;
-	if (do_ioctl(handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0) {
-		xc_error_set("ioctl failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "map foreign range [%lx,%lx] prot %u",
-		                 mfn, mfn + size, prot);
-		munmap(addr, size);
-		return NULL;
-	}
-	return addr;
-}
-
-int xc_map_foreign_ranges(int handle, unsigned int domid,
-                          privcmd_mmap_entry_t *entries, int nr)
-{
-	privcmd_mmap_t ioctlx = {
-		.num = nr,
-		.dom = domid,
-		.entry = entries,
-	};
-	int ret;
-
-	ret = do_ioctl(handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
-	if (ret < 0) {
-		xc_error_set("ioctl failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "map foreign ranges");
-		return -1;
-	}
-	return ret;
-}
-
-int xc_readconsolering(int handle, char **pbuffer,
-                       unsigned int *pnr_chars, int clear)
-{
-	int ret;
-	DECLARE_SYSCTL(XEN_SYSCTL_readconsole);
-	char *buffer = *pbuffer;
-	unsigned int nr_chars = *pnr_chars;
-
-	set_xen_guest_handle(sysctl.u.readconsole.buffer, buffer);
-	sysctl.u.readconsole.count = nr_chars;
-	sysctl.u.readconsole.clear = clear;
-
-	if (mlock(buffer, nr_chars) != 0) {
-		xc_error_set("read console ring: mlock failed: %s",
-		             strerror(errno));
-		return -1;
-	}
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret != 0)
-		xc_error_set("read console ring failed: %s", xc_error_get());
-	else
-		*pnr_chars = sysctl.u.readconsole.count;
-
-	munlock(buffer, nr_chars);
-	return ret;
-}
-
-int xc_send_debug_keys(int handle, char *keys)
-{
-	int ret;
-	DECLARE_SYSCTL(XEN_SYSCTL_debug_keys);
-
-	set_xen_guest_handle(sysctl.u.debug_keys.keys, keys);
-	sysctl.u.debug_keys.nr_keys = strlen(keys);
-
-	if (mlock(keys, sysctl.u.debug_keys.nr_keys) != 0) {
-		xc_error_set("send debug keys: mlock failed: %s",
-		             strerror(errno));
-		return -1;
-	}
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret != 0)
-		xc_error_set("send debug keys: %s", xc_error_get());
-
-	munlock(keys, sysctl.u.debug_keys.nr_keys);
-	return ret;
-}
-
-int xc_physinfo(int handle, xc_physinfo_t *put_info)
-{
-	DECLARE_SYSCTL(XEN_SYSCTL_physinfo);
-	int ret;
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret) {
-		xc_error_set("physinfo failed: %s", xc_error_get());
-		return ret;
-	}
-	memcpy(put_info, &sysctl.u.physinfo, sizeof(*put_info));
-	return 0;
-}
-
-int xc_pcpu_info(
-	int handle, int max_cpus, xen_sysctl_cpuinfo_t *info, int *nr_cpus)
-{
-	DECLARE_SYSCTL(XEN_SYSCTL_getcpuinfo);
-	int ret;
-
-	sysctl.u.getcpuinfo.max_cpus = max_cpus;
-	set_xen_guest_handle(sysctl.u.getcpuinfo.info, info);
-
-	if (mlock(info, sizeof(*info) * max_cpus) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret)
-		xc_error_set("pcpu info failed: %s", xc_error_get());
-	else if (ret == 0 && nr_cpus)
-		*nr_cpus = sysctl.u.getcpuinfo.nr_cpus;
-	munlock(info, sizeof(*info) * max_cpus);
-	return ret;
-}
-
-int xc_sched_id(int handle, int *sched_id)
-{
-	DECLARE_SYSCTL(XEN_SYSCTL_sched_id);
-	int ret;
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret) {
-		xc_error_set("sched id failed: %s", xc_error_get());
-		return ret;
-	}
-	*sched_id = sysctl.u.sched_id.sched_id;
-	return 0;
-}
-
-int xc_version(int handle, int cmd, void *arg)
-{
-	int argsize;
-	int ret;
-	DECLARE_HYPERCALL2(__HYPERVISOR_xen_version, cmd, arg);
-
-	switch (cmd) {
-	case XENVER_extraversion:
-		argsize = sizeof(xen_extraversion_t); break;
-	case XENVER_compile_info:
-		argsize = sizeof(xen_compile_info_t); break;
-	case XENVER_capabilities:
-		argsize = sizeof(xen_capabilities_info_t); break;
-	case XENVER_changeset:
-		argsize = sizeof(xen_changeset_info_t); break;
-	case XENVER_platform_parameters:
-		argsize = sizeof(xen_platform_parameters_t); break;
-	case XENVER_version:
-		argsize = 0; break;
-	default:
-		xc_error_set("version: unknown command");
-		return -1;
-	}
-	if (argsize && mlock(arg, argsize) == -1) {
-		xc_error_set("version: mlock failed: %s", strerror(errno));
-		return -ENOMEM;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-
-	if (argsize)
-		munlock(arg, argsize);
-	return ret;
-}
-
-int xc_evtchn_alloc_unbound(int handle, unsigned int domid,
-                            unsigned int remote_domid)
-{
-	struct evtchn_alloc_unbound arg = {
-		.dom = domid,
-		.remote_dom = remote_domid,
-	};
-	int ret;
-
-	ret = do_evtchnctl(handle, EVTCHNOP_alloc_unbound, &arg, sizeof(arg));
-	if (ret) {
-		xc_error_dom_set(domid, "alloc unbound evtchn to %d",
-		                 remote_domid);
-		return ret;
-	}
-	return arg.port;
-}
-
-int xc_evtchn_reset(int handle, unsigned int domid)
-{
-	struct evtchn_reset arg = {
-		.dom = domid,
-	};
-	int ret;
-
-	ret = do_evtchnctl(handle, EVTCHNOP_reset, &arg, sizeof(arg));
-	if (ret)
-		xc_error_dom_set(domid, "reset evtchn of %d", domid);
-	return ret;
-}
-
-int xc_sched_credit_domain_set(int handle, unsigned int domid,
-                               struct xen_domctl_sched_credit *sdom)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_scheduler_op, domid);
-	domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT;
-	domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
-	domctl.u.scheduler_op.u.credit = *sdom;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "credit scheduler domain set");
-	return ret;
-}
-
-int xc_sched_credit_domain_get(int handle, unsigned int domid,
-                               struct xen_domctl_sched_credit *sdom)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_scheduler_op, domid);
-
-	domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT;
-	domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "credit scheduler domain get");
-	else
-		*sdom = domctl.u.scheduler_op.u.credit;
-	return ret;
-}
-
-int xc_shadow_allocation_get(int handle, unsigned int domid, uint32_t *mb)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_shadow_op, domid);
-
-	domctl.u.shadow_op.op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "shadow allocation get");
-	else
-		*mb = domctl.u.shadow_op.mb;
-	return ret;
-}
-
-int xc_shadow_allocation_set(int handle, unsigned int domid, uint32_t mb)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_shadow_op, domid);
-
-	domctl.u.shadow_op.op = XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION;
-	domctl.u.shadow_op.mb = mb;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "shadow allocation set");
-	return ret;
-}
-
-int xc_domain_get_pfn_list(int handle, unsigned int domid,
-                           uint64_t *pfn_array, unsigned long max_pfns)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_getmemlist, domid);
-
-	domctl.u.getmemlist.max_pfns = max_pfns;
-	set_xen_guest_handle(domctl.u.getmemlist.buffer, pfn_array);
-
-	if (mlock(pfn_array, max_pfns * sizeof(xen_pfn_t)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "get pfn list");
-
-	munlock(pfn_array, max_pfns * sizeof(xen_pfn_t));
-	return (ret < 0) ? ret : domctl.u.getmemlist.num_pfns;
-}
-
-#define MARSHALL_BDF(d,b,s,f) \
-	(((b) & 0xff) << 16 | ((s) & 0x1f) << 11 | ((f) & 0x7) << 8)
-
-int xc_domain_assign_device(int handle, unsigned int domid,
-                            int domain, int bus, int slot, int func)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_assign_device
-	DECLARE_DOMCTL(XEN_DOMCTL_assign_device, domid);
-
-	domctl.u.assign_device.machine_bdf = MARSHALL_BDF(domain, bus, slot, func);
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "assign device");
-#endif
-	return ret;
-}
-
-int xc_domain_deassign_device(int handle, unsigned int domid,
-                              int domain, int bus, int slot, int func)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_deassign_device
-	DECLARE_DOMCTL(XEN_DOMCTL_deassign_device, domid);
-
-	domctl.u.assign_device.machine_bdf = MARSHALL_BDF(domain, bus, slot, func);
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "deassign device");
-#endif
-	return ret;
-}
-
-int xc_domain_test_assign_device(int handle, unsigned int domid,
-                                 int domain, int bus, int slot, int func)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_test_assign_device
-	DECLARE_DOMCTL(XEN_DOMCTL_test_assign_device, domid);
-	domctl.u.assign_device.machine_bdf = MARSHALL_BDF(domain, bus, slot, func);
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "test assign device");
-#endif
-	return ret;
-}
-
-int xc_domain_watchdog(int handle, int id, uint32_t timeout)
-{
-	int ret = -EBADF;
-#ifdef SCHEDOP_watchdog
-	sched_watchdog_t arg = {
-		.id = (uint32_t) id,
-		.timeout = timeout,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_sched_op, SCHEDOP_watchdog, &arg);
-
-	if (mlock(&arg, sizeof(arg)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0) {
-		xc_error_hypercall(hypercall, ret);
-	}
-	munlock(&arg, sizeof(arg));
-#endif
-	return ret;
-}
-
-int xc_domain_set_machine_address_size(int xc, uint32_t domid, unsigned int width)
-{
-	DECLARE_DOMCTL(XEN_DOMCTL_set_machine_address_size, domid);
-	int rc;
-
-	domctl.u.address_size.size = width;
-	rc = do_domctl(xc, &domctl);
-	if (rc != 0)
-		xc_error_dom_set(domid, "set machine address size");
-
-	return rc;
-}
-
-int xc_domain_get_machine_address_size(int xc, uint32_t domid)
-{
-	DECLARE_DOMCTL(XEN_DOMCTL_get_machine_address_size, domid);
-	int rc;
-
-	rc = do_domctl(xc, &domctl);
-	if (rc != 0)
-		xc_error_dom_set(domid, "get machine address size");
-	return rc == 0 ? domctl.u.address_size.size : rc;
-}
-
-#include "xc_cpuid.h"
-int xc_domain_cpuid_set(int xc, unsigned int domid, int hvm,
-                        uint32_t input, uint32_t oinput,
-                        char *config[4], char *config_out[4])
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_set_cpuid
-	DECLARE_DOMCTL(XEN_DOMCTL_set_cpuid, domid);
-	uint32_t regs[4], polregs[4];
-	int i, j;
-
-	xc_cpuid(input, oinput, regs);
-	memcpy(polregs, regs, sizeof(regs));
-	do_cpuid_policy(xc, domid, hvm, input, polregs);
-
-	for (i = 0; i < 4; i++) {
-		if (!config[i]) {
-			regs[i] = polregs[i];
-			continue;
-		}
-		
-		for (j = 0; j < 32; j++) {
-			unsigned char val, polval;
-
-			val = !!((regs[i] & (1U << (31 - j))));
-			polval = !!((regs[i] & (1U << (31 - j))));
-
-			switch (config[i][j]) {
-			case '1': val = 1; break; /* force to true */
-			case '0': val = 0; break; /* force to false */
-			case 'x': val = polval; break;
-			case 'k': case 's': break;
-			default:
-				xc_error_dom_set(domid, "domain cpuid set: invalid config");
-				ret = -EINVAL;
-				goto out;
-			}
-
-			if (val)
-				set_bit(31 - j, regs[i]);
-			else
-				clear_bit(31 - j, regs[i]);
-
-			if (config_out && config_out[i]) {
-				config_out[i][j] = (config[i][j] == 's')
-				                   ? '0' + val
-						   : config[i][j];
-			}
-		}
-	}
-
-	domctl.u.cpuid.input[0] = input;
-	domctl.u.cpuid.input[1] = oinput;
-	domctl.u.cpuid.eax = regs[0];
-	domctl.u.cpuid.ebx = regs[1];
-	domctl.u.cpuid.ecx = regs[2];
-	domctl.u.cpuid.edx = regs[3];
-	ret = do_domctl(xc, &domctl);
-	if (ret) {
-		xc_error_dom_set(domid, "cpuid set");
-		goto out;
-	}
-out:
-#endif
-	return ret;
-}
-
-int xc_domain_cpuid_apply(int xc, unsigned int domid, int hvm)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_set_cpuid
-	uint32_t regs[4], base_max, ext_max, eax, ecx;
-
-	/* determinate cpuid range */
-	xc_cpuid(0, 0, regs);
-	base_max = MIN(regs[0], DEF_MAX_BASE);
-	xc_cpuid(0x80000000, 0, regs);
-	ext_max = MIN(regs[0], DEF_MAX_EXT);
-
-	eax = ecx = 0;
-	while (!(eax & 0x80000000) || (eax <= ext_max)) {
-		xc_cpuid(eax, ecx, regs);
-
-		do_cpuid_policy(xc, domid, hvm, eax, regs);
-		
-		if (regs[0] || regs[1] || regs[2] || regs[3]) {
-			DECLARE_DOMCTL(XEN_DOMCTL_set_cpuid, domid);
-			
-			domctl.u.cpuid.input[0] = eax;
-			domctl.u.cpuid.input[1] = (eax == 4) ? ecx : XEN_CPUID_INPUT_UNUSED;
-			domctl.u.cpuid.eax = regs[0];
-			domctl.u.cpuid.ebx = regs[1];
-			domctl.u.cpuid.ecx = regs[2];
-			domctl.u.cpuid.edx = regs[3];
-
-			ret = do_domctl(xc, &domctl);
-			if (ret) {
-				xc_error_dom_set(domid, "cpuid apply");
-				goto out;
-			}
-
-			/* we repeat when doing node 4 (cache descriptor leaves) increasing ecx 
-			 * until the cpuid eax value masked is 0 */
-			if (eax == 4) {
-				ecx++;
-				if ((regs[0] & 0x1f) != 0)
-					continue;
-				ecx = 0;
-			}
-		}
-
-		eax++;
-		if (!(eax & 0x80000000) && (eax > base_max))
-			eax = 0x80000000;
-	}
-	ret = 0;
-out:
-#endif
-	return ret;
-}
-
-/*
- * return 1 on checking success 
- *        0 on checking failure
- *        -EINVAL if the config contains unknown character
- */
-int xc_cpuid_check(uint32_t input, uint32_t optsubinput,
-                   char *config[4], char *config_out[4])
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_set_cpuid
-	uint32_t regs[4];
-	int i, j;
-
-	xc_cpuid(input, optsubinput, regs);
-
-	ret = 1;
-	for (i = 0; i < 4; i++) {
-		if (!config[i])
-			continue;
-		for (j = 0; j < 32; j++) {
-			unsigned char val;
-
-			val = !!((regs[i] & (1U << (31 - j))));
-
-			switch (config[i][j]) {
-			case '1': if (!val) { ret = 0; goto out; }; break;
-			case '0': if (val) { ret = 0; goto out; }; break;
-			case 'x': case 's': break;
-			default:
-				xc_error_set("cpuid check: invalid config");
-				ret = -EINVAL;
-				goto out;
-			}
-
-			if (config_out && config_out[i]) {
-				config_out[i][j] = (config[i][j] == 's')
-				                   ? '0' + val
-						   : config[i][j];
-			}
-		}
-	} 
-out:
-#endif
-	return ret;
-}
-
-#ifndef HVM_PARAM_HPET_ENABLED
-#define HVM_PARAM_HPET_ENABLED 11
-#endif
-
-#ifndef HVM_PARAM_ACPI_S_STATE
-#define HVM_PARAM_ACPI_S_STATE 14
-#endif
-
-#ifndef HVM_PARAM_VPT_ALIGN
-#define HVM_PARAM_VPT_ALIGN 16
-#endif
-
-int xc_domain_send_s3resume(int handle, unsigned int domid)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 0);
-}
-
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode)
-{
-	return xc_set_hvm_param(handle, domid,
-	                        HVM_PARAM_TIMER_MODE, (unsigned long) mode);
-}
-
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) hpet);
-}
-
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) vpt_align);
-}
-
-int xc_domain_get_acpi_s_state(int handle, unsigned int domid)
-{
-	int ret;
-	unsigned long value;
-
-	ret = xc_get_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, &value);
-	if (ret != 0)
-		xc_error_dom_set(domid, "get acpi s-state");
-	return value;
-}
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/libs/xc/xc_stubs.c
--- a/tools/ocaml/libs/xc/xc_stubs.c	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/xc/xc_stubs.c	Thu Nov 18 05:46:26 2010 -0500
@@ -16,6 +16,7 @@
 
 #define _XOPEN_SOURCE 600
 #include <stdlib.h>
+#include <errno.h>
 
 #define CAML_NAME_SPACE
 #include <caml/alloc.h>
@@ -28,7 +29,7 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "xc.h"
+#include <xenctrl.h>
 
 #include "mmap_stubs.h"
 
@@ -36,7 +37,7 @@
 #define PAGE_SIZE               (1UL << PAGE_SHIFT)
 #define PAGE_MASK               (~(PAGE_SIZE-1))
 
-#define _H(__h) (Int_val(__h))
+#define _H(__h) ((xc_interface *)(__h))
 #define _D(__d) ((uint32_t)Int_val(__d))
 
 #define Val_none (Val_int(0))
@@ -50,12 +51,23 @@
 	i1 = (uint32_t) Int64_val(Field(input, 0)); \
 	i2 = ((Field(input, 1) == Val_none) ? 0xffffffff : (uint32_t) Int64_val(Field(Field(input, 1), 0)));
 
-/**
- * Convert the given number of pages to an amount in MiB, rounded up.
- */
-void failwith_xc(void)
+#define ERROR_STRLEN 1024
+void failwith_xc(xc_interface *xch)
 {
-	caml_raise_with_string(*caml_named_value("xc.error"), xc_error_get());
+	static char error_str[ERROR_STRLEN];
+	if (xch) {
+		const xc_error *error = xc_get_last_error(xch);
+		if (error->code == XC_ERROR_NONE)
+                	snprintf(error_str, ERROR_STRLEN, "%d: %s", errno, strerror(errno));
+		else
+			snprintf(error_str, ERROR_STRLEN, "%d: %s: %s",
+				 error->code,
+				 xc_error_code_to_desc(error->code),
+				 error->message);
+	} else {
+		snprintf(error_str, ERROR_STRLEN, "Unable to open XC interface");
+	}
+	caml_raise_with_string(*caml_named_value("xc.error"), error_str);
 }
 
 CAMLprim value stub_sizeof_core_header(value unit)
@@ -101,11 +113,11 @@ CAMLprim value stub_marshall_core_header
 
 CAMLprim value stub_xc_interface_open(void)
 {
-        int handle;
-        handle = xc_interface_open();
-        if (handle == -1)
-		failwith_xc();
-        return Val_int(handle);
+        xc_interface *xch;
+        xch = xc_interface_open(NULL, NULL, XC_OPENFLAG_NON_REENTRANT);
+        if (xch == NULL)
+		failwith_xc(NULL);
+        return (value)xch;
 }
 
 
@@ -116,20 +128,15 @@ CAMLprim value stub_xc_interface_open_fa
 
 CAMLprim value stub_xc_using_injection(void)
 {
-	if (xc_using_injection ()){
-		return Val_int(1);
-	} else {
-		return Val_int(0);
-	}
+	return Val_int(0);
 }
 
-CAMLprim value stub_xc_interface_close(value xc_handle)
+CAMLprim value stub_xc_interface_close(value xch)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 
-	int handle = _H(xc_handle);
 	// caml_enter_blocking_section();
-	xc_interface_close(handle);
+	xc_interface_close(_H(xch));
 	// caml_leave_blocking_section();
 
 	CAMLreturn(Val_unit);
@@ -140,16 +147,15 @@ static int domain_create_flag_table[] = 
 	XEN_DOMCTL_CDF_hap,
 };
 
-CAMLprim value stub_xc_domain_create(value xc_handle, value ssidref,
+CAMLprim value stub_xc_domain_create(value xch, value ssidref,
                                      value flags, value handle)
 {
-	CAMLparam4(xc_handle, ssidref, flags, handle);
+	CAMLparam4(xch, ssidref, flags, handle);
 
 	uint32_t domid = 0;
 	xen_domain_handle_t h = { 0 };
 	int result;
 	int i;
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_ssidref = Int32_val(ssidref);
 	unsigned int c_flags = 0;
 	value l;
@@ -167,46 +173,32 @@ CAMLprim value stub_xc_domain_create(val
 	}
 
 	// caml_enter_blocking_section();
-	result = xc_domain_create(c_xc_handle, c_ssidref, h, c_flags, &domid);
+	result = xc_domain_create(_H(xch), c_ssidref, h, c_flags, &domid);
 	// caml_leave_blocking_section();
 
 	if (result < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_int(domid));
 }
 
-CAMLprim value stub_xc_domain_setvmxassist(value xc_handle, value domid,
-					    value use_vmxassist)
+CAMLprim value stub_xc_domain_max_vcpus(value xch, value domid,
+                                        value max_vcpus)
 {
-	CAMLparam3(xc_handle, domid, use_vmxassist);
+	CAMLparam3(xch, domid, max_vcpus);
 	int r;
 
-	r = xc_domain_setvmxassist(_H(xc_handle), _D(domid),
-				   Bool_val(use_vmxassist));
+	r = xc_domain_max_vcpus(_H(xch), _D(domid), Int_val(max_vcpus));
 	if (r)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_max_vcpus(value xc_handle, value domid,
-                                        value max_vcpus)
+
+value stub_xc_domain_sethandle(value xch, value domid, value handle)
 {
-	CAMLparam3(xc_handle, domid, max_vcpus);
-	int r;
-
-	r = xc_domain_max_vcpus(_H(xc_handle), _D(domid), Int_val(max_vcpus));
-	if (r)
-		failwith_xc();
-
-	CAMLreturn(Val_unit);
-}
-
-
-value stub_xc_domain_sethandle(value xc_handle, value domid, value handle)
-{
-	CAMLparam3(xc_handle, domid, handle);
+	CAMLparam3(xch, domid, handle);
 	xen_domain_handle_t h = { 0 };
 	int i;
 
@@ -217,57 +209,65 @@ value stub_xc_domain_sethandle(value xc_
 		h[i] = Int_val(Field(handle, i)) & 0xff;
 	}
 
-	i = xc_domain_sethandle(_H(xc_handle), _D(domid), h);
+	i = xc_domain_sethandle(_H(xch), _D(domid), h);
 	if (i)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-static value dom_op(value xc_handle, value domid, int (*fn)(int, uint32_t))
+static value dom_op(value xch, value domid, int (*fn)(xc_interface *, uint32_t))
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_domid = _D(domid);
 
 	// caml_enter_blocking_section();
-	int result = fn(c_xc_handle, c_domid);
+	int result = fn(_H(xch), c_domid);
 	// caml_leave_blocking_section();
         if (result)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_pause(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_pause(value xch, value domid)
 {
-	return dom_op(xc_handle, domid, xc_domain_pause);
+	return dom_op(xch, domid, xc_domain_pause);
 }
 
 
-CAMLprim value stub_xc_domain_unpause(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_unpause(value xch, value domid)
 {
-	return dom_op(xc_handle, domid, xc_domain_unpause);
+	return dom_op(xch, domid, xc_domain_unpause);
 }
 
-CAMLprim value stub_xc_domain_destroy(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_destroy(value xch, value domid)
 {
-	return dom_op(xc_handle, domid, xc_domain_destroy);
+	return dom_op(xch, domid, xc_domain_destroy);
 }
 
-CAMLprim value stub_xc_domain_resume_fast(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_resume_fast(value xch, value domid)
 {
-	return dom_op(xc_handle, domid, xc_domain_resume_fast);
+	CAMLparam2(xch, domid);
+
+	uint32_t c_domid = _D(domid);
+
+	// caml_enter_blocking_section();
+	int result = xc_domain_resume(_H(xch), c_domid, 1);
+	// caml_leave_blocking_section();
+        if (result)
+		failwith_xc(_H(xch));
+	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_shutdown(value handle, value domid, value reason)
+CAMLprim value stub_xc_domain_shutdown(value xch, value domid, value reason)
 {
-	CAMLparam3(handle, domid, reason);
+	CAMLparam3(xch, domid, reason);
 	int ret;
 
-	ret = xc_domain_shutdown(_H(handle), _D(domid), Int_val(reason));
+	ret = xc_domain_shutdown(_H(xch), _D(domid), Int_val(reason));
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
@@ -307,12 +307,12 @@ static value alloc_domaininfo(xc_domaini
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_domain_getinfolist(value xc_handle, value first_domain, value nb)
+CAMLprim value stub_xc_domain_getinfolist(value xch, value first_domain, value nb)
 {
-	CAMLparam3(xc_handle, first_domain, nb);
+	CAMLparam3(xch, first_domain, nb);
 	CAMLlocal2(result, temp);
 	xc_domaininfo_t * info;
-	int i, ret, toalloc, c_xc_handle, retval;
+	int i, ret, toalloc, retval;
 	unsigned int c_max_domains;
 	uint32_t c_first_domain;
 
@@ -324,17 +324,16 @@ CAMLprim value stub_xc_domain_getinfolis
 
 	result = temp = Val_emptylist;
 
-	c_xc_handle = _H(xc_handle);
 	c_first_domain = _D(first_domain);
 	c_max_domains = Int_val(nb);
 	// caml_enter_blocking_section();
-	retval = xc_domain_getinfolist(c_xc_handle, c_first_domain,
+	retval = xc_domain_getinfolist(_H(xch), c_first_domain,
 				       c_max_domains, info);
 	// caml_leave_blocking_section();
 
 	if (retval < 0) {
 		free(info);
-		failwith_xc();
+		failwith_xc(_H(xch));
 	}
 	for (i = 0; i < retval; i++) {
 		result = caml_alloc_small(2, Tag_cons);
@@ -349,37 +348,38 @@ CAMLprim value stub_xc_domain_getinfolis
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_domain_getinfo(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_getinfo(value xch, value domid)
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 	CAMLlocal1(result);
 	xc_domaininfo_t info;
 	int ret;
 
-	ret = xc_domain_getinfo(_H(xc_handle), _D(domid), &info);
-	if (ret != 0)
-		failwith_xc();
+	ret = xc_domain_getinfolist(_H(xch), _D(domid), 1, &info);
+	if (ret != 1)
+		failwith_xc(_H(xch));
+	if (info.domain != _D(domid))
+		failwith_xc(_H(xch));
 
 	result = alloc_domaininfo(&info);
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_vcpu_getinfo(value xc_handle, value domid, value vcpu)
+CAMLprim value stub_xc_vcpu_getinfo(value xch, value domid, value vcpu)
 {
-	CAMLparam3(xc_handle, domid, vcpu);
+	CAMLparam3(xch, domid, vcpu);
 	CAMLlocal1(result);
 	xc_vcpuinfo_t info;
 	int retval;
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_domid = _D(domid);
 	uint32_t c_vcpu = Int_val(vcpu);
 	// caml_enter_blocking_section();
-	retval = xc_vcpu_getinfo(c_xc_handle, c_domid,
+	retval = xc_vcpu_getinfo(_H(xch), c_domid,
 	                         c_vcpu, &info);
 	// caml_leave_blocking_section();
 	if (retval < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	result = caml_alloc_tuple(5);
 	Store_field(result, 0, Val_bool(info.online));
@@ -391,15 +391,15 @@ CAMLprim value stub_xc_vcpu_getinfo(valu
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_vcpu_context_get(value xc_handle, value domid,
+CAMLprim value stub_xc_vcpu_context_get(value xch, value domid,
                                         value cpu)
 {
-	CAMLparam3(xc_handle, domid, cpu);
+	CAMLparam3(xch, domid, cpu);
 	CAMLlocal1(context);
 	int ret;
 	vcpu_guest_context_any_t ctxt;
 
-	ret = xc_vcpu_getcontext(_H(xc_handle), _D(domid), Int_val(cpu), &ctxt);
+	ret = xc_vcpu_getcontext(_H(xch), _D(domid), Int_val(cpu), &ctxt);
 
 	context = caml_alloc_string(sizeof(ctxt));
 	memcpy(String_val(context), (char *) &ctxt.c, sizeof(ctxt.c));
@@ -407,75 +407,115 @@ CAMLprim value stub_xc_vcpu_context_get(
 	CAMLreturn(context);
 }
 
-CAMLprim value stub_xc_vcpu_setaffinity(value xc_handle, value domid,
+static int get_cpumap_len(value xch, value cpumap)
+{
+	int ml_len = Wosize_val(cpumap);
+	int xc_len = xc_get_max_cpus(_H(xch));
+
+	if (ml_len < xc_len)
+		return ml_len;
+	else
+		return xc_len;
+}
+
+CAMLprim value stub_xc_vcpu_setaffinity(value xch, value domid,
                                         value vcpu, value cpumap)
 {
-	CAMLparam4(xc_handle, domid, vcpu, cpumap);
-	uint64_t c_cpumap;
+	CAMLparam4(xch, domid, vcpu, cpumap);
+	int i, len = get_cpumap_len(xch, cpumap);
+	xc_cpumap_t c_cpumap;
 	int retval;
 
-	c_cpumap = Int64_val(cpumap);
-	retval = xc_vcpu_setaffinity(_H(xc_handle), _D(domid),
+	c_cpumap = xc_cpumap_alloc(_H(xch));
+	if (c_cpumap == NULL)
+		failwith_xc(_H(xch));
+
+	for (i=0; i<len; i++) {
+		if (Bool_val(Field(cpumap, i)))
+			c_cpumap[i/8] |= i << (i&7);
+	}
+	retval = xc_vcpu_setaffinity(_H(xch), _D(domid),
 	                             Int_val(vcpu), c_cpumap);
+	free(c_cpumap);
+
 	if (retval < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_vcpu_getaffinity(value xc_handle, value domid,
+CAMLprim value stub_xc_vcpu_getaffinity(value xch, value domid,
                                         value vcpu)
 {
-	CAMLparam3(xc_handle, domid, vcpu);
+	CAMLparam3(xch, domid, vcpu);
 	CAMLlocal1(ret);
-	uint64_t cpumap;
+	xc_cpumap_t c_cpumap;
+	int i, len = xc_get_max_cpus(_H(xch));
 	int retval;
 
-	retval = xc_vcpu_getaffinity(_H(xc_handle), _D(domid),
-	                             Int_val(vcpu), &cpumap);
-	if (retval < 0)
-		failwith_xc();
-	ret = caml_copy_int64(cpumap);
+	c_cpumap = xc_cpumap_alloc(_H(xch));
+	if (c_cpumap == NULL)
+		failwith_xc(_H(xch));
+
+	retval = xc_vcpu_getaffinity(_H(xch), _D(domid),
+	                             Int_val(vcpu), c_cpumap);
+	free(c_cpumap);
+
+	if (retval < 0) {
+		free(c_cpumap);
+		failwith_xc(_H(xch));
+	}
+
+	ret = caml_alloc(len, 0);
+
+	for (i=0; i<len; i++) {
+		if (c_cpumap[i%8] & 1 << (i&7))
+			Store_field(ret, i, Val_true);
+		else
+			Store_field(ret, i, Val_false);
+	}
+
+	free(c_cpumap);
+
 	CAMLreturn(ret);
 }
 
-CAMLprim value stub_xc_sched_id(value xc_handle)
+CAMLprim value stub_xc_sched_id(value xch)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	int sched_id;
 
-	if (xc_sched_id(_H(xc_handle), &sched_id))
-		failwith_xc();
+	if (xc_sched_id(_H(xch), &sched_id))
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_int(sched_id));
 }
 
-CAMLprim value stub_xc_evtchn_alloc_unbound(value xc_handle,
+CAMLprim value stub_xc_evtchn_alloc_unbound(value xch,
                                             value local_domid,
                                             value remote_domid)
 {
-	CAMLparam3(xc_handle, local_domid, remote_domid);
+	CAMLparam3(xch, local_domid, remote_domid);
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_local_domid = _D(local_domid);
 	uint32_t c_remote_domid = _D(remote_domid);
 
 	// caml_enter_blocking_section();
-	int result = xc_evtchn_alloc_unbound(c_xc_handle, c_local_domid,
+	int result = xc_evtchn_alloc_unbound(_H(xch), c_local_domid,
 	                                     c_remote_domid);
 	// caml_leave_blocking_section();
 
 	if (result < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_int(result));
 }
 
-CAMLprim value stub_xc_evtchn_reset(value handle, value domid)
+CAMLprim value stub_xc_evtchn_reset(value xch, value domid)
 {
-	CAMLparam2(handle, domid);
+	CAMLparam2(xch, domid);
 	int r;
 
-	r = xc_evtchn_reset(_H(handle), _D(domid));
+	r = xc_evtchn_reset(_H(xch), _D(domid));
 	if (r < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
@@ -483,48 +523,47 @@ CAMLprim value stub_xc_evtchn_reset(valu
 #define RING_SIZE 32768
 static char ring[RING_SIZE];
 
-CAMLprim value stub_xc_readconsolering(value xc_handle)
+CAMLprim value stub_xc_readconsolering(value xch)
 {
 	unsigned int size = RING_SIZE;
 	char *ring_ptr = ring;
 
-	CAMLparam1(xc_handle);
-	int c_xc_handle = _H(xc_handle);
+	CAMLparam1(xch);
 
 	// caml_enter_blocking_section();
-	int retval = xc_readconsolering(c_xc_handle, &ring_ptr, &size, 0);
+	int retval = xc_readconsolering(_H(xch), ring_ptr, &size, 0, 0, NULL);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	ring[size] = '\0';
 	CAMLreturn(caml_copy_string(ring));
 }
 
-CAMLprim value stub_xc_send_debug_keys(value xc_handle, value keys)
+CAMLprim value stub_xc_send_debug_keys(value xch, value keys)
 {
-	CAMLparam2(xc_handle, keys);
+	CAMLparam2(xch, keys);
 	int r;
 
-	r = xc_send_debug_keys(_H(xc_handle), String_val(keys));
+	r = xc_send_debug_keys(_H(xch), String_val(keys));
 	if (r)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_physinfo(value xc_handle)
+CAMLprim value stub_xc_physinfo(value xch)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	CAMLlocal3(physinfo, cap_list, tmp);
 	xc_physinfo_t c_physinfo;
 	int r;
 
 	// caml_enter_blocking_section();
-	r = xc_physinfo(_H(xc_handle), &c_physinfo);
+	r = xc_physinfo(_H(xch), &c_physinfo);
 	// caml_leave_blocking_section();
 
 	if (r)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	tmp = cap_list = Val_emptylist;
 	for (r = 0; r < 2; r++) {
@@ -550,11 +589,11 @@ CAMLprim value stub_xc_physinfo(value xc
 	CAMLreturn(physinfo);
 }
 
-CAMLprim value stub_xc_pcpu_info(value xc_handle, value nr_cpus)
+CAMLprim value stub_xc_pcpu_info(value xch, value nr_cpus)
 {
-	CAMLparam2(xc_handle, nr_cpus);
+	CAMLparam2(xch, nr_cpus);
 	CAMLlocal2(pcpus, v);
-	xen_sysctl_cpuinfo_t *info;
+	xc_cpuinfo_t *info;
 	int r, size;
 
 	if (Int_val(nr_cpus) < 1)
@@ -565,12 +604,12 @@ CAMLprim value stub_xc_pcpu_info(value x
 		caml_raise_out_of_memory();
 
 	// caml_enter_blocking_section();
-	r = xc_pcpu_info(_H(xc_handle), Int_val(nr_cpus), info, &size);
+	r = xc_getcpuinfo(_H(xch), Int_val(nr_cpus), info, &size);
 	// caml_leave_blocking_section();
 
 	if (r) {
 		free(info);
-		failwith_xc();
+		failwith_xc(_H(xch));
 	}
 
 	if (size > 0) {
@@ -586,101 +625,98 @@ CAMLprim value stub_xc_pcpu_info(value x
 	CAMLreturn(pcpus);
 }
 
-CAMLprim value stub_xc_domain_setmaxmem(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_setmaxmem(value xch, value domid,
                                         value max_memkb)
 {
-	CAMLparam3(xc_handle, domid, max_memkb);
+	CAMLparam3(xch, domid, max_memkb);
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_domid = _D(domid);
 	unsigned int c_max_memkb = Int64_val(max_memkb);
 	// caml_enter_blocking_section();
-	int retval = xc_domain_setmaxmem(c_xc_handle, c_domid,
+	int retval = xc_domain_setmaxmem(_H(xch), c_domid,
 	                                 c_max_memkb);
 	// caml_leave_blocking_section();
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_set_memmap_limit(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_set_memmap_limit(value xch, value domid,
                                                value map_limitkb)
 {
-	CAMLparam3(xc_handle, domid, map_limitkb);
+	CAMLparam3(xch, domid, map_limitkb);
 	unsigned long v;
 	int retval;
 
 	v = Int64_val(map_limitkb);
-	retval = xc_domain_set_memmap_limit(_H(xc_handle), _D(domid), v);
+	retval = xc_domain_set_memmap_limit(_H(xch), _D(domid), v);
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_memory_increase_reservation(value xc_handle,
+CAMLprim value stub_xc_domain_memory_increase_reservation(value xch,
                                                           value domid,
                                                           value mem_kb)
 {
-	CAMLparam3(xc_handle, domid, mem_kb);
+	CAMLparam3(xch, domid, mem_kb);
 
 	unsigned long nr_extents = ((unsigned long)(Int64_val(mem_kb))) >> (PAGE_SHIFT - 10);
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_domid = _D(domid);
 	// caml_enter_blocking_section();
-	int retval = xc_domain_memory_increase_reservation(c_xc_handle, c_domid,
-	                                                   nr_extents, 0, 0, NULL);
+	int retval = xc_domain_increase_reservation_exact(_H(xch), c_domid,
+							  nr_extents, 0, 0, NULL);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_set_machine_address_size(value xc_handle,
+CAMLprim value stub_xc_domain_set_machine_address_size(value xch,
 						       value domid,
 						       value width)
 {
-	CAMLparam3(xc_handle, domid, width);
-	int c_xc_handle = _H(xc_handle);
+	CAMLparam3(xch, domid, width);
 	uint32_t c_domid = _D(domid);
 	int c_width = Int_val(width);
 
-	int retval = xc_domain_set_machine_address_size(c_xc_handle, c_domid, c_width);
+	int retval = xc_domain_set_machine_address_size(_H(xch), c_domid, c_width);
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_get_machine_address_size(value xc_handle,
+CAMLprim value stub_xc_domain_get_machine_address_size(value xch,
                                                        value domid)
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 	int retval;
 
-	retval = xc_domain_get_machine_address_size(_H(xc_handle), _D(domid));
+	retval = xc_domain_get_machine_address_size(_H(xch), _D(domid));
 	if (retval < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_int(retval));
 }
 
-CAMLprim value stub_xc_domain_cpuid_set(value xc_handle, value domid,
-                                        value is_hvm, value input,
+CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
+                                        value input,
                                         value config)
 {
-	CAMLparam5(xc_handle, domid, is_hvm, input, config);
+	CAMLparam4(xch, domid, input, config);
 	CAMLlocal2(array, tmp);
 	int r;
+	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];
-	uint32_t c_input, c_oinput;
 
 	c_config[0] = string_of_option_array(config, 0);
 	c_config[1] = string_of_option_array(config, 1);
 	c_config[2] = string_of_option_array(config, 2);
 	c_config[3] = string_of_option_array(config, 3);
 
-	cpuid_input_of_val(c_input, c_oinput, input);
+	cpuid_input_of_val(c_input[0], c_input[1], input);
 
 	array = caml_alloc(4, 0);
 	for (r = 0; r < 4; r++) {
@@ -695,29 +731,30 @@ CAMLprim value stub_xc_domain_cpuid_set(
 	for (r = 0; r < 4; r++)
 		out_config[r] = (c_config[r]) ? String_val(Field(Field(array, r), 0)) : NULL;
 
-	r = xc_domain_cpuid_set(_H(xc_handle), _D(domid), Bool_val(is_hvm),
-	                        c_input, c_oinput, c_config, out_config);
+	r = xc_cpuid_set(_H(xch), _D(domid),
+			 c_input, (const char **)c_config, out_config);
 	if (r < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(array);
 }
 
-CAMLprim value stub_xc_domain_cpuid_apply(value xc_handle, value domid, value is_hvm)
+CAMLprim value stub_xc_domain_cpuid_apply_policy(value xch, value domid)
 {
-	CAMLparam3(xc_handle, domid, is_hvm);
+	CAMLparam2(xch, domid);
 	int r;
-	r = xc_domain_cpuid_apply(_H(xc_handle), _D(domid), Bool_val(is_hvm));
+
+	r = xc_cpuid_apply_policy(_H(xch), _D(domid));
 	if (r < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_cpuid_check(value input, value config)
+CAMLprim value stub_xc_cpuid_check(value xch, value input, value config)
 {
-	CAMLparam2(input, config);
+	CAMLparam3(xch, input, config);
 	CAMLlocal3(ret, array, tmp);
 	int r;
-	uint32_t c_input, c_oinput;
+	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];
 
 	c_config[0] = string_of_option_array(config, 0);
@@ -725,7 +762,7 @@ CAMLprim value stub_xc_cpuid_check(value
 	c_config[2] = string_of_option_array(config, 2);
 	c_config[3] = string_of_option_array(config, 3);
 
-	cpuid_input_of_val(c_input, c_oinput, input);
+	cpuid_input_of_val(c_input[0], c_input[1], input);
 
 	array = caml_alloc(4, 0);
 	for (r = 0; r < 4; r++) {
@@ -740,9 +777,9 @@ CAMLprim value stub_xc_cpuid_check(value
 	for (r = 0; r < 4; r++)
 		out_config[r] = (c_config[r]) ? String_val(Field(Field(array, r), 0)) : NULL;
 
-	r = xc_cpuid_check(c_input, c_oinput, c_config, out_config);
+	r = xc_cpuid_check(_H(xch), c_input, (const char **)c_config, out_config);
 	if (r < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	ret = caml_alloc_tuple(2);
 	Store_field(ret, 0, Val_bool(r));
@@ -751,22 +788,21 @@ CAMLprim value stub_xc_cpuid_check(value
 	CAMLreturn(ret);
 }
 
-CAMLprim value stub_xc_version_version(value xc_handle)
+CAMLprim value stub_xc_version_version(value xch)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	CAMLlocal1(result);
 	xen_extraversion_t extra;
 	long packed;
 	int retval;
 
-	int c_xc_handle = _H(xc_handle);
 	// caml_enter_blocking_section();
-	packed = xc_version(c_xc_handle, XENVER_version, NULL);
-	retval = xc_version(c_xc_handle, XENVER_extraversion, &extra);
+	packed = xc_version(_H(xch), XENVER_version, NULL);
+	retval = xc_version(_H(xch), XENVER_extraversion, &extra);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	result = caml_alloc_tuple(3);
 
@@ -778,20 +814,19 @@ CAMLprim value stub_xc_version_version(v
 }
 
 
-CAMLprim value stub_xc_version_compile_info(value xc_handle)
+CAMLprim value stub_xc_version_compile_info(value xch)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	CAMLlocal1(result);
 	xen_compile_info_t ci;
 	int retval;
 
-	int c_xc_handle = _H(xc_handle);
 	// caml_enter_blocking_section();
-	retval = xc_version(c_xc_handle, XENVER_compile_info, &ci);
+	retval = xc_version(_H(xch), XENVER_compile_info, &ci);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	result = caml_alloc_tuple(4);
 
@@ -804,36 +839,35 @@ CAMLprim value stub_xc_version_compile_i
 }
 
 
-static value xc_version_single_string(value xc_handle, int code, void *info)
+static value xc_version_single_string(value xch, int code, void *info)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	int retval;
 
-	int c_xc_handle = _H(xc_handle);
 	// caml_enter_blocking_section();
-	retval = xc_version(c_xc_handle, code, info);
+	retval = xc_version(_H(xch), code, info);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(caml_copy_string((char *)info));
 }
 
 
-CAMLprim value stub_xc_version_changeset(value xc_handle)
+CAMLprim value stub_xc_version_changeset(value xch)
 {
 	xen_changeset_info_t ci;
 
-	return xc_version_single_string(xc_handle, XENVER_changeset, &ci);
+	return xc_version_single_string(xch, XENVER_changeset, &ci);
 }
 
 
-CAMLprim value stub_xc_version_capabilities(value xc_handle)
+CAMLprim value stub_xc_version_capabilities(value xch)
 {
 	xen_capabilities_info_t ci;
 
-	return xc_version_single_string(xc_handle, XENVER_capabilities, &ci);
+	return xc_version_single_string(xch, XENVER_capabilities, &ci);
 }
 
 
@@ -845,13 +879,12 @@ CAMLprim value stub_pages_to_kib(value p
 }
 
 
-CAMLprim value stub_map_foreign_range(value xc_handle, value dom,
+CAMLprim value stub_map_foreign_range(value xch, value dom,
                                       value size, value mfn)
 {
-	CAMLparam4(xc_handle, dom, size, mfn);
+	CAMLparam4(xch, dom, size, mfn);
 	CAMLlocal1(result);
 	struct mmap_interface *intf;
-	int c_xc_handle;
 	uint32_t c_dom;
 	unsigned long c_mfn;
 
@@ -860,11 +893,10 @@ CAMLprim value stub_map_foreign_range(va
 
 	intf->len = Int_val(size);
 
-	c_xc_handle = _H(xc_handle);
 	c_dom = _D(dom);
 	c_mfn = Nativeint_val(mfn);
 	// caml_enter_blocking_section();
-	intf->addr = xc_map_foreign_range(c_xc_handle, c_dom,
+	intf->addr = xc_map_foreign_range(_H(xch), c_dom,
 	                                  intf->len, PROT_READ|PROT_WRITE,
 	                                  c_mfn);
 	// caml_leave_blocking_section();
@@ -873,18 +905,18 @@ CAMLprim value stub_map_foreign_range(va
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_sched_credit_domain_get(value xc_handle, value domid)
+CAMLprim value stub_sched_credit_domain_get(value xch, value domid)
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 	CAMLlocal1(sdom);
 	struct xen_domctl_sched_credit c_sdom;
 	int ret;
 
 	// caml_enter_blocking_section();
-	ret = xc_sched_credit_domain_get(_H(xc_handle), _D(domid), &c_sdom);
+	ret = xc_sched_credit_domain_get(_H(xch), _D(domid), &c_sdom);
 	// caml_leave_blocking_section();
 	if (ret != 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	sdom = caml_alloc_tuple(2);
 	Store_field(sdom, 0, Val_int(c_sdom.weight));
@@ -893,62 +925,66 @@ CAMLprim value stub_sched_credit_domain_
 	CAMLreturn(sdom);
 }
 
-CAMLprim value stub_sched_credit_domain_set(value xc_handle, value domid,
+CAMLprim value stub_sched_credit_domain_set(value xch, value domid,
                                             value sdom)
 {
-	CAMLparam3(xc_handle, domid, sdom);
+	CAMLparam3(xch, domid, sdom);
 	struct xen_domctl_sched_credit c_sdom;
 	int ret;
 
 	c_sdom.weight = Int_val(Field(sdom, 0));
 	c_sdom.cap = Int_val(Field(sdom, 1));
 	// caml_enter_blocking_section();
-	ret = xc_sched_credit_domain_set(_H(xc_handle), _D(domid), &c_sdom);
+	ret = xc_sched_credit_domain_set(_H(xch), _D(domid), &c_sdom);
 	// caml_leave_blocking_section();
 	if (ret != 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_shadow_allocation_get(value xc_handle, value domid)
+CAMLprim value stub_shadow_allocation_get(value xch, value domid)
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 	CAMLlocal1(mb);
-	uint32_t c_mb;
+	unsigned long c_mb;
 	int ret;
 
 	// caml_enter_blocking_section();
-	ret = xc_shadow_allocation_get(_H(xc_handle), _D(domid), &c_mb);
+	ret = xc_shadow_control(_H(xch), _D(domid),
+				XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION,
+				NULL, 0, &c_mb, 0, NULL);
 	// caml_leave_blocking_section();
 	if (ret != 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	mb = Val_int(c_mb);
 	CAMLreturn(mb);
 }
 
-CAMLprim value stub_shadow_allocation_set(value xc_handle, value domid,
+CAMLprim value stub_shadow_allocation_set(value xch, value domid,
 					  value mb)
 {
-	CAMLparam3(xc_handle, domid, mb);
-	uint32_t c_mb;
+	CAMLparam3(xch, domid, mb);
+	unsigned long c_mb;
 	int ret;
 
 	c_mb = Int_val(mb);
 	// caml_enter_blocking_section();
-	ret = xc_shadow_allocation_set(_H(xc_handle), _D(domid), c_mb);
+	ret = xc_shadow_control(_H(xch), _D(domid),
+				XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION,
+				NULL, 0, &c_mb, 0, NULL);
 	// caml_leave_blocking_section();
 	if (ret != 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_get_pfn_list(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_get_pfn_list(value xch, value domid,
                                            value nr_pfns)
 {
-	CAMLparam3(xc_handle, domid, nr_pfns);
+	CAMLparam3(xch, domid, nr_pfns);
 	CAMLlocal2(array, v);
 	unsigned long c_nr_pfns;
 	long ret, i;
@@ -960,11 +996,11 @@ CAMLprim value stub_xc_domain_get_pfn_li
 	if (!c_array)
 		caml_raise_out_of_memory();
 
-	ret = xc_domain_get_pfn_list(_H(xc_handle), _D(domid),
-	                             c_array, c_nr_pfns);
+	ret = xc_get_pfn_list(_H(xch), _D(domid),
+			      c_array, c_nr_pfns);
 	if (ret < 0) {
 		free(c_array);
-		failwith_xc();
+		failwith_xc(_H(xch));
 	}
 
 	array = caml_alloc(ret, 0);
@@ -977,11 +1013,11 @@ CAMLprim value stub_xc_domain_get_pfn_li
 	CAMLreturn(array);
 }
 
-CAMLprim value stub_xc_domain_ioport_permission(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_ioport_permission(value xch, value domid,
 					       value start_port, value nr_ports,
 					       value allow)
 {
-	CAMLparam5(xc_handle, domid, start_port, nr_ports, allow);
+	CAMLparam5(xch, domid, start_port, nr_ports, allow);
 	uint32_t c_start_port, c_nr_ports;
 	uint8_t c_allow;
 	int ret;
@@ -990,19 +1026,19 @@ CAMLprim value stub_xc_domain_ioport_per
 	c_nr_ports = Int_val(nr_ports);
 	c_allow = Bool_val(allow);
 
-	ret = xc_domain_ioport_permission(_H(xc_handle), _D(domid),
+	ret = xc_domain_ioport_permission(_H(xch), _D(domid),
 					 c_start_port, c_nr_ports, c_allow);
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_iomem_permission(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_iomem_permission(value xch, value domid,
 					       value start_pfn, value nr_pfns,
 					       value allow)
 {
-	CAMLparam5(xc_handle, domid, start_pfn, nr_pfns, allow);
+	CAMLparam5(xch, domid, start_pfn, nr_pfns, allow);
 	unsigned long c_start_pfn, c_nr_pfns;
 	uint8_t c_allow;
 	int ret;
@@ -1011,18 +1047,18 @@ CAMLprim value stub_xc_domain_iomem_perm
 	c_nr_pfns = Nativeint_val(nr_pfns);
 	c_allow = Bool_val(allow);
 
-	ret = xc_domain_iomem_permission(_H(xc_handle), _D(domid),
+	ret = xc_domain_iomem_permission(_H(xch), _D(domid),
 					 c_start_pfn, c_nr_pfns, c_allow);
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_irq_permission(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_irq_permission(value xch, value domid,
 					     value pirq, value allow)
 {
-	CAMLparam4(xc_handle, domid, pirq, allow);
+	CAMLparam4(xch, domid, pirq, allow);
 	uint8_t c_pirq;
 	uint8_t c_allow;
 	int ret;
@@ -1030,138 +1066,90 @@ CAMLprim value stub_xc_domain_irq_permis
 	c_pirq = Int_val(pirq);
 	c_allow = Bool_val(allow);
 
-	ret = xc_domain_irq_permission(_H(xc_handle), _D(domid),
+	ret = xc_domain_irq_permission(_H(xch), _D(domid),
 				       c_pirq, c_allow);
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_hvm_check_pvdriver(value xc_handle, value domid)
+static uint32_t pci_dev_to_bdf(int domain, int bus, int slot, int func)
 {
-	CAMLparam2(xc_handle, domid);
-	int ret;
-
-	ret = xc_hvm_check_pvdriver(_H(xc_handle), _D(domid));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_bool(ret));
+	uint32_t bdf = 0;
+	bdf |= (bus & 0xff) << 16;
+	bdf |= (slot & 0x1f) << 11;
+	bdf |= (func & 0x7) << 8;
+	return bdf;
 }
 
-CAMLprim value stub_xc_domain_test_assign_device(value xc_handle, value domid, value desc)
+CAMLprim value stub_xc_domain_test_assign_device(value xch, value domid, value desc)
 {
-	CAMLparam3(xc_handle, domid, desc);
+	CAMLparam3(xch, domid, desc);
 	int ret;
 	int domain, bus, slot, func;
+	uint32_t bdf;
 
 	domain = Int_val(Field(desc, 0));
 	bus = Int_val(Field(desc, 1));
 	slot = Int_val(Field(desc, 2));
 	func = Int_val(Field(desc, 3));
+	bdf = pci_dev_to_bdf(domain, bus, slot, func);
 
-	ret = xc_domain_test_assign_device(_H(xc_handle), _D(domid),
-	                                   domain, bus, slot, func);
+	ret = xc_test_assign_device(_H(xch), _D(domid), bdf);
+
 	CAMLreturn(Val_bool(ret == 0));
 }
 
-CAMLprim value stub_xc_domain_assign_device(value xc_handle, value domid, value desc)
+CAMLprim value stub_xc_domain_assign_device(value xch, value domid, value desc)
 {
-	CAMLparam3(xc_handle, domid, desc);
+	CAMLparam3(xch, domid, desc);
 	int ret;
 	int domain, bus, slot, func;
+	uint32_t bdf;
 
 	domain = Int_val(Field(desc, 0));
 	bus = Int_val(Field(desc, 1));
 	slot = Int_val(Field(desc, 2));
 	func = Int_val(Field(desc, 3));
+	bdf = pci_dev_to_bdf(domain, bus, slot, func);
 
-	ret = xc_domain_assign_device(_H(xc_handle), _D(domid),
-	                              domain, bus, slot, func);
+	ret = xc_assign_device(_H(xch), _D(domid), bdf);
+
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_deassign_device(value xc_handle, value domid, value desc)
+CAMLprim value stub_xc_domain_deassign_device(value xch, value domid, value desc)
 {
-	CAMLparam3(xc_handle, domid, desc);
+	CAMLparam3(xch, domid, desc);
 	int ret;
 	int domain, bus, slot, func;
+	uint32_t bdf;
 
 	domain = Int_val(Field(desc, 0));
 	bus = Int_val(Field(desc, 1));
 	slot = Int_val(Field(desc, 2));
 	func = Int_val(Field(desc, 3));
+	bdf = pci_dev_to_bdf(domain, bus, slot, func);
 
-	ret = xc_domain_deassign_device(_H(xc_handle), _D(domid),
-	                                domain, bus, slot, func);
+	ret = xc_deassign_device(_H(xch), _D(domid), bdf);
+
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_set_timer_mode(value handle, value id, value mode)
+CAMLprim value stub_xc_watchdog(value xch, value domid, value timeout)
 {
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_timer_mode(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_hpet(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_hpet(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_vpt_align(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_vpt_align(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_watchdog(value handle, value domid, value timeout)
-{
-	CAMLparam3(handle, domid, timeout);
+	CAMLparam3(xch, domid, timeout);
 	int ret;
 	unsigned int c_timeout = Int32_val(timeout);
 
-	ret = xc_domain_watchdog(_H(handle), _D(domid), c_timeout);
+	ret = xc_watchdog(_H(xch), _D(domid), c_timeout);
 	if (ret < 0)
-		failwith_xc();
-
-	CAMLreturn(Val_int(ret));
-}
-
-CAMLprim value stub_xc_domain_send_s3resume(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	xc_domain_send_s3resume(_H(handle), _D(domid));
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_get_acpi_s_state(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	int ret;
-
-	ret = xc_domain_get_acpi_s_state(_H(handle), _D(domid));
-	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_int(ret));
 }
diff -r ac5b6ac9ec0d -r 4e6556dc40d3 tools/ocaml/xenstored/Makefile
--- a/tools/ocaml/xenstored/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/xenstored/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -39,7 +39,8 @@ XENSTOREDLIBS = \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/log $(OCAML_TOPLEVEL)/libs/log/log.cmxa \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/eventchn/eventchn.cmxa \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xc.cmxa \
-	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xb.cmxa
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xb.cmxa \
+	-ccopt -L -ccopt $(XEN_ROOT)/tools/libxc
 
 PROGRAMS = oxenstored
 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 7 of 7] HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same
       [not found]     ` <patchbomb.1290077432-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
                         ` (2 preceding siblings ...)
  2010-11-18 10:50       ` [PATCH 6 of 7] ocaml: xc bindings: use libxenctrl and libxenguest Ian Campbell
@ 2010-11-18 10:50       ` Ian Campbell
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 10:50 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290077186 18000
# Node ID 74b174ffed0167d7c1c5fe709176c43770cc9e13
# Parent  4e6556dc40d36822bddf8ebb55294762e3279f33
HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same.

blktap issue is resolved by proper XCP packaging of the hypervisor tools rather
than my rather ad-hoc approach.

ocaml namespacing issues need some more thought, as mentioned in the overall
introductory email.

Not-Signed-of-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 4e6556dc40d3 -r 74b174ffed01 tools/Makefile
--- a/tools/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -21,8 +21,8 @@ SUBDIRS-$(VTPM_TOOLS) += vtpm
 SUBDIRS-y += xenstat
 SUBDIRS-$(CONFIG_Linux) += libaio
 SUBDIRS-$(CONFIG_Linux) += memshr 
-SUBDIRS-$(CONFIG_Linux) += blktap
-SUBDIRS-$(CONFIG_Linux) += blktap2
+#SUBDIRS-$(CONFIG_Linux) += blktap
+#SUBDIRS-$(CONFIG_Linux) += blktap2
 SUBDIRS-$(CONFIG_NetBSD) += libaio
 SUBDIRS-$(CONFIG_NetBSD) += blktap2
 SUBDIRS-$(CONFIG_NetBSD) += xenbackendd
@@ -46,7 +46,7 @@ SUBDIRS-$(CONFIG_X86) += debugger/kdd
 # These don't cross-compile
 ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
 SUBDIRS-$(PYTHON_TOOLS) += python
-SUBDIRS-$(PYTHON_TOOLS) += pygrub
+#SUBDIRS-$(PYTHON_TOOLS) += pygrub
 SUBDIRS-$(OCAML_TOOLS) += ocaml
 endif
 
diff -r 4e6556dc40d3 -r 74b174ffed01 tools/blktap2/vhd/lib/Makefile
--- a/tools/blktap2/vhd/lib/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/blktap2/vhd/lib/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -63,9 +63,9 @@ libvhd.a: $(LIB-OBJS)
 
 install: all
 	$(INSTALL_DIR) -p $(DESTDIR)$(INST-DIR)
-	$(INSTALL_DATA) $(LIBVHD) $(DESTDIR)$(INST-DIR)
-	ln -sf libvhd.so.$(LIBVHD-MAJOR).$(LIBVHD-MINOR) $(DESTDIR)$(INST-DIR)/libvhd.so.$(LIBVHD-MAJOR)
-	ln -sf libvhd.so.$(LIBVHD-MAJOR) $(DESTDIR)$(INST-DIR)/libvhd.so
+	#$(INSTALL_DATA) $(LIBVHD) $(DESTDIR)$(INST-DIR)
+	#ln -sf libvhd.so.$(LIBVHD-MAJOR).$(LIBVHD-MINOR) $(DESTDIR)$(INST-DIR)/libvhd.so.$(LIBVHD-MAJOR)
+	#ln -sf libvhd.so.$(LIBVHD-MAJOR) $(DESTDIR)$(INST-DIR)/libvhd.so
 
 clean:
 	rm -rf *.a *.so* *.o *~ $(DEPS) $(LIBVHD)
diff -r 4e6556dc40d3 -r 74b174ffed01 tools/ocaml/libs/log/Makefile
--- a/tools/ocaml/libs/log/Makefile	Thu Nov 18 05:46:26 2010 -0500
+++ b/tools/ocaml/libs/log/Makefile	Thu Nov 18 05:46:26 2010 -0500
@@ -32,9 +32,10 @@ syslog.mli : syslog.ml
 
 .PHONY: install
 install: $(LIBS) META
-	mkdir -p $(OCAMLDESTDIR)
-	ocamlfind remove -destdir $(OCAMLDESTDIR) log
-	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore log META $(INTF) $(LIBS) *.a *.so *.cmx
+### XXX need resyncing with xen-api-libs
+#	mkdir -p $(OCAMLDESTDIR)
+#	ocamlfind remove -destdir $(OCAMLDESTDIR) log
+#	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore log META $(INTF) $(LIBS) *.a *.so *.cmx
 
 .PHONY: uninstall
 uninstall:

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 4 of 7] ocaml: resynchronise uuid library with xen-api-libs.hg
  2010-11-18 10:50       ` [PATCH 4 of 7] ocaml: resynchronise uuid library with xen-api-libs.hg Ian Campbell
@ 2010-11-18 11:32         ` Gianni Tedesco
  2010-11-18 12:27           ` Ian Campbell
  0 siblings, 1 reply; 66+ messages in thread
From: Gianni Tedesco @ 2010-11-18 11:32 UTC (permalink / raw)
  To: Ian Campbell; +Cc: Ian Campbell, xen-devel, xen-api

On Thu, 2010-11-18 at 10:50 +0000, Ian Campbell wrote:
> # HG changeset patch
> # User root@localhost.localdomain
> # Date 1290077186 18000
> # Node ID 05cf9251ac48e7abeabdcf3c5a164b276bf393e9
> # Parent  11cc3e6d573937508df213c0127c1dbbbd61af30
> ocaml: resynchronise uuid library with xen-api-libs.hg
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> 
> diff -r 11cc3e6d5739 -r 05cf9251ac48 tools/ocaml/libs/uuid/uuid.ml
> --- a/tools/ocaml/libs/uuid/uuid.ml	Thu Nov 18 05:46:26 2010 -0500
> +++ b/tools/ocaml/libs/uuid/uuid.ml	Thu Nov 18 05:46:26 2010 -0500
> @@ -1,7 +1,5 @@
>  (*
> - * Copyright (C) 2006-2007 XenSource Ltd.
> - * Copyright (C) 2008      Citrix Ltd.
> - * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
> + * Copyright (C) 2006-2009 Citrix Systems Inc.
>   *

Hmm, I can understand folding in the redundant copyright claims but what
is the deal with assertion of authorship?

Gianni

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 4 of 7] ocaml: resynchronise uuid library with xen-api-libs.hg
  2010-11-18 11:32         ` Gianni Tedesco
@ 2010-11-18 12:27           ` Ian Campbell
       [not found]             ` <1290083222.31507.5290.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 12:27 UTC (permalink / raw)
  To: Gianni Tedesco; +Cc: xen-devel, xen-api

On Thu, 2010-11-18 at 11:32 +0000, Gianni Tedesco wrote:
> On Thu, 2010-11-18 at 10:50 +0000, Ian Campbell wrote:
> > # HG changeset patch
> > # User root@localhost.localdomain
> > # Date 1290077186 18000
> > # Node ID 05cf9251ac48e7abeabdcf3c5a164b276bf393e9
> > # Parent  11cc3e6d573937508df213c0127c1dbbbd61af30
> > ocaml: resynchronise uuid library with xen-api-libs.hg
> > 
> > Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> > 
> > diff -r 11cc3e6d5739 -r 05cf9251ac48 tools/ocaml/libs/uuid/uuid.ml
> > --- a/tools/ocaml/libs/uuid/uuid.ml	Thu Nov 18 05:46:26 2010 -0500
> > +++ b/tools/ocaml/libs/uuid/uuid.ml	Thu Nov 18 05:46:26 2010 -0500
> > @@ -1,7 +1,5 @@
> >  (*
> > - * Copyright (C) 2006-2007 XenSource Ltd.
> > - * Copyright (C) 2008      Citrix Ltd.
> > - * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
> > + * Copyright (C) 2006-2009 Citrix Systems Inc.
> >   *
> 
> Hmm, I can understand folding in the redundant copyright claims but what
> is the deal with assertion of authorship?

I literally did a cp from xen-api-libs.hg. AIUI the two modules have a
shared ancestry with the xen-unstable version being imported from a
snapshot of xen-api-libs at some point. It looks like the copyright
headers were added to both trees independently after (or as part of) the
import and so the two versions have diverged.

I'll redo this as a less automated import and retain the authorship
statements in xen-unstable.hg -- doing otherwise was unintentional but
still impolite, sorry about that Vincent.

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [Xen-API] [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module
  2010-11-18 10:50       ` [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module Ian Campbell
@ 2010-11-18 14:36         ` Vincent Hanquez
  2010-11-18 15:35           ` Ian Campbell
  2010-11-19 13:42           ` Re: [Xen-API] " Gianni Tedesco
  0 siblings, 2 replies; 66+ messages in thread
From: Vincent Hanquez @ 2010-11-18 14:36 UTC (permalink / raw)
  To: xen-api; +Cc: xen-devel, Ian Campbell

On 18/11/10 10:50, Ian Campbell wrote:
> # HG changeset patch
> # User root@localhost.localdomain
> # Date 1290004595 18000
> # Node ID be3de1c0aa0687ef9fa6ad2ac5cfa1a74fb14484
> # Parent  cdd93d37eb6036e9901ecc0cd1f949901ff1aea4
> xc: split xc non-upstream bindings into xcext module.
>
> move anything which is not provided by upstream libxc and the
> associated ocaml bindings in a separate xcext library to ease
> replacement of xc library by upstream version.
>
> Some of this functionality could potentially be upstreamed straight
> away but other bits rely on stuff from the XCP hypervisor patch queue.
>
> One change of not is that Xcext.hvm_check_pvdriver expects that domid is always
> an HVM domain. This matches the existing callsites (and the name) and reduces
> cross talk between xc and xcext.
>    

This is breaking xiu. as i said before the xc C library in XCP is 
different than the one in opensource;
There's an injection layer that give the ability to catch stuff and 
redirect them to userspace, where
we can simulate lots of things. Last time i checked this was still used 
by a bunch of people for testing.

-- 
Vincent

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [Xen-devel] [PATCH 4 of 7] ocaml: resynchronise uuid library with xen-api-libs.hg
       [not found]             ` <1290083222.31507.5290.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-18 14:44               ` Vincent Hanquez
  0 siblings, 0 replies; 66+ messages in thread
From: Vincent Hanquez @ 2010-11-18 14:44 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell, xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR

On 18/11/10 12:27, Ian Campbell wrote:
> I literally did a cp from xen-api-libs.hg. AIUI the two modules have a
> shared ancestry with the xen-unstable version being imported from a
> snapshot of xen-api-libs at some point. It looks like the copyright
> headers were added to both trees independently after (or as part of) the
> import and so the two versions have diverged.
>
> I'll redo this as a less automated import and retain the authorship
> statements in xen-unstable.hg -- doing otherwise was unintentional but
> still impolite, sorry about that Vincent.
>    

no worries no offenses taken, there's multiples versions of the same 
file, with different headers unfortunately.

authorship is mostly advisory: could be useful to track the author when 
wondering about a piece of code, or a design decision. Otherwise it's 
not bound to anything useful legally AFAIK.

-- 
Vincent

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [Xen-API] [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module
  2010-11-18 14:36         ` [Xen-API] " Vincent Hanquez
@ 2010-11-18 15:35           ` Ian Campbell
  2010-11-19 11:43             ` Vincent Hanquez
       [not found]             ` <1290094550.31507.5391.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-11-19 13:42           ` Re: [Xen-API] " Gianni Tedesco
  1 sibling, 2 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-18 15:35 UTC (permalink / raw)
  To: Vincent Hanquez; +Cc: xen-devel, xen-api

On Thu, 2010-11-18 at 14:36 +0000, Vincent Hanquez wrote:
> On 18/11/10 10:50, Ian Campbell wrote:
> > # HG changeset patch
> > # User root@localhost.localdomain
> > # Date 1290004595 18000
> > # Node ID be3de1c0aa0687ef9fa6ad2ac5cfa1a74fb14484
> > # Parent  cdd93d37eb6036e9901ecc0cd1f949901ff1aea4
> > xc: split xc non-upstream bindings into xcext module.
> >
> > move anything which is not provided by upstream libxc and the
> > associated ocaml bindings in a separate xcext library to ease
> > replacement of xc library by upstream version.
> >
> > Some of this functionality could potentially be upstreamed straight
> > away but other bits rely on stuff from the XCP hypervisor patch queue.
> >
> > One change of not is that Xcext.hvm_check_pvdriver expects that domid is always
> > an HVM domain. This matches the existing callsites (and the name) and reduces
> > cross talk between xc and xcext.
> >    
> 
> This is breaking xiu. as i said before the xc C library in XCP is 
> different than the one in opensource;

That would be fine (or at least I'd have no grounds to complain ;-)) for
out-of-tree bindings but I don't think it is acceptable for in tree
bindings to duplicate infrastructure libraries in this way.

> There's an injection layer that give the ability to catch stuff and 
> redirect them to userspace, where
> we can simulate lots of things. Last time i checked this was still used 
> by a bunch of people for testing.

Absolutely, I think the XIU stuff is really very useful indeed. I think
it even has the potential for wider usefulness than just XCP.

Addressing this is next on my list so my plan is only half baked (if
that!) but I think the hooks necessary to support an injection
infrastructure of this type could be integrated into libxc without too
much pain. Doing this would allow xl, libvirt etc to also use the XIU
functionality for testing which I think would be really cool.

I've several possible approaches in mind:

      * Just whack the hooks and injection layer into libxc itself,
        there aren't really that many hook points or that much code in
        the injection layer...
      * Turn xc_injection_lib.c into a LD_PRELOAD'able library. Requires
        moving various, do_{domctl,ioctl,etc} stuff out of line in the
        library -- which I think is a good idea anyway.
      * Add functionality to libxc to allow it to dlopen a backend (e.g.
        pointed to by an envvar) containing the hook implementation with
        explicit calls to the layer as necessary.

Probably the second two are pretty much equivalent modulo the name of
the environment variable being either LD_PRELOAD or something else.

Initially I think I prefer the dynamic loading approaches to dropping
the injection stuff directly into libxc. In particular the dynamic
options allow the injection layer and XIU backend to live together
whereas the first option effectively has the injection layer in
xen-unstable.hg and the XIU backend possibly somewhere else which
doesn't seem helpful.

The dynamic solution also allows for other injection layers and backends
but I'm not sure how useful that actually is. Perhaps a valgrind
friendly backend or something like that, dunno.

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [Xen-API] [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module
  2010-11-18 15:35           ` Ian Campbell
@ 2010-11-19 11:43             ` Vincent Hanquez
       [not found]               ` <4CE662D9.6030808-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
       [not found]             ` <1290094550.31507.5391.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  1 sibling, 1 reply; 66+ messages in thread
From: Vincent Hanquez @ 2010-11-19 11:43 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel, xen-api

On 18/11/10 15:35, Ian Campbell wrote:
> Absolutely, I think the XIU stuff is really very useful indeed. I think
> it even has the potential for wider usefulness than just XCP.
>
> Addressing this is next on my list so my plan is only half baked (if
> that!) but I think the hooks necessary to support an injection
> infrastructure of this type could be integrated into libxc without too
> much pain. Doing this would allow xl, libvirt etc to also use the XIU
> functionality for testing which I think would be really cool.
>
> I've several possible approaches in mind:
>
>        * Just whack the hooks and injection layer into libxc itself,
>          there aren't really that many hook points or that much code in
>          the injection layer...
>        * Turn xc_injection_lib.c into a LD_PRELOAD'able library. Requires
>          moving various, do_{domctl,ioctl,etc} stuff out of line in the
>          library -- which I think is a good idea anyway.
>        * Add functionality to libxc to allow it to dlopen a backend (e.g.
>          pointed to by an envvar) containing the hook implementation with
>          explicit calls to the layer as necessary.
>
> Probably the second two are pretty much equivalent modulo the name of
> the environment variable being either LD_PRELOAD or something else.
>
> Initially I think I prefer the dynamic loading approaches to dropping
> the injection stuff directly into libxc. In particular the dynamic
> options allow the injection layer and XIU backend to live together
> whereas the first option effectively has the injection layer in
> xen-unstable.hg and the XIU backend possibly somewhere else which
> doesn't seem helpful.
>
> The dynamic solution also allows for other injection layers and backends
> but I'm not sure how useful that actually is. Perhaps a valgrind
> friendly backend or something like that, dunno
I pretty much agree with you, however just a bit of comments.

option 1 is more dynamic than option 2. you can mix and match backend 
just setting/unsetting
your XIU environment before any XC call technically. this isn't possible 
with LD_PRELOAD, since
it's one shot during the start of your program.

3 is pretty much equivalent to 1 and best technically IMO. it's just a 
bit more efforts to do, hence why option 1 is the one available now.

-- 
Vincent

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module
       [not found]               ` <4CE662D9.6030808-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
@ 2010-11-19 13:32                 ` Ian Campbell
  0 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-19 13:32 UTC (permalink / raw)
  To: Vincent Hanquez; +Cc: xen-devel, xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR

On Fri, 2010-11-19 at 11:43 +0000, Vincent Hanquez wrote:
> option 1 is more dynamic than option 2. you can mix and match backend 
> just setting/unsetting your XIU environment before any XC call technically.
> this isn't possible  with LD_PRELOAD, since it's one shot during the 
> start of your program.

True, I hadn't thought of it that way.

> 3 is pretty much equivalent to 1 and best technically IMO.

Agreed.

> it's just a bit more efforts to do,

It turns out to have been a mornings work to implement the hooks support
in libxc plus a simple "ENOSYS stub". I'm hoping it will be an
afternoons work to port xc_lib_injection.c over, but perhaps I'm over
ambitious ;-)

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: Re: [Xen-API] [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module
  2010-11-18 14:36         ` [Xen-API] " Vincent Hanquez
  2010-11-18 15:35           ` Ian Campbell
@ 2010-11-19 13:42           ` Gianni Tedesco
  1 sibling, 0 replies; 66+ messages in thread
From: Gianni Tedesco @ 2010-11-19 13:42 UTC (permalink / raw)
  To: Vincent Hanquez; +Cc: Ian Campbell, xen-devel, xen-api

On Thu, 2010-11-18 at 14:36 +0000, Vincent Hanquez wrote:
> On 18/11/10 10:50, Ian Campbell wrote:
> > # HG changeset patch
> > # User root@localhost.localdomain
> > # Date 1290004595 18000
> > # Node ID be3de1c0aa0687ef9fa6ad2ac5cfa1a74fb14484
> > # Parent  cdd93d37eb6036e9901ecc0cd1f949901ff1aea4
> > xc: split xc non-upstream bindings into xcext module.
> >
> > move anything which is not provided by upstream libxc and the
> > associated ocaml bindings in a separate xcext library to ease
> > replacement of xc library by upstream version.
> >
> > Some of this functionality could potentially be upstreamed straight
> > away but other bits rely on stuff from the XCP hypervisor patch queue.
> >
> > One change of not is that Xcext.hvm_check_pvdriver expects that domid is always
> > an HVM domain. This matches the existing callsites (and the name) and reduces
> > cross talk between xc and xcext.
> >    
> 
> This is breaking xiu. as i said before the xc C library in XCP is 
> different than the one in opensource;
> There's an injection layer that give the ability to catch stuff and 
> redirect them to userspace, where
> we can simulate lots of things. Last time i checked this was still used 
> by a bunch of people for testing.

Is this not suitable for upstreaming?

Gianni

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [Xen-devel] Re: [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module
       [not found]             ` <1290094550.31507.5391.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-11-19 17:43               ` Ian Jackson
       [not found]                 ` <19686.46942.593712.651242-msK/Ju9w1zmnROeE8kUsYhEHtJm+Wo+I@public.gmane.org>
       [not found]                 ` <m2n.s.1PKW6s-0019ae@chiark.greenend.org.uk>
  0 siblings, 2 replies; 66+ messages in thread
From: Ian Jackson @ 2010-11-19 17:43 UTC (permalink / raw)
  To: Ian Campbell
  Cc: xen-devel, Vincent Hanquez, xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR

Ian Campbell writes ("[Xen-devel] Re: [Xen-API] [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module"):
>       * Add functionality to libxc to allow it to dlopen a backend (e.g.
>         pointed to by an envvar) containing the hook implementation with
>         explicit calls to the layer as necessary.

I think this is the best approach.  You could put the hook function
pointers in the xc handle struct.

> Probably the second two are pretty much equivalent modulo the name of
> the environment variable being either LD_PRELOAD or something else.

LD_PRELOAD is a sledgehammer to crack a nut for this, I think.  Also,
I generally think that the existence of LD_PRELOAD should not be used
as an excuse for not providing a properly-supported interface.

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [Xen-devel] Re: [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module
       [not found]                 ` <19686.46942.593712.651242-msK/Ju9w1zmnROeE8kUsYhEHtJm+Wo+I@public.gmane.org>
@ 2010-11-22 13:05                   ` Ian Campbell
  0 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-11-22 13:05 UTC (permalink / raw)
  To: Ian Jackson
  Cc: xen-devel, Vincent Hanquez, xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR

On Fri, 2010-11-19 at 17:43 +0000, Ian Jackson wrote:
> Ian Campbell writes ("[Xen-devel] Re: [Xen-API] [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module"):
> >       * Add functionality to libxc to allow it to dlopen a backend (e.g.
> >         pointed to by an envvar) containing the hook implementation with
> >         explicit calls to the layer as necessary.
> 
> I think this is the best approach.  You could put the hook function
> pointers in the xc handle struct.

I've currently made them global (and it works ok for the cases I've
tried) but I think adding them to the xc_handle would indeed be better.

Next I need to decide what to do with the event channel interfaces in
libxenctrl which also need this treatment but which currently use a
straight integer as the handle.

I shall probably convert the evtchn interfaces to use an xc_interface
style opaque pointer as a handle, possibly/probably even reusing the
existing xc_handle type in some way since it already contains broadly
the right set of stuff.

> > Probably the second two are pretty much equivalent modulo the name of
> > the environment variable being either LD_PRELOAD or something else.
> 
> LD_PRELOAD is a sledgehammer to crack a nut for this, I think.  Also,
> I generally think that the existence of LD_PRELOAD should not be used
> as an excuse for not providing a properly-supported interface.

Agreed.

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [Xen-devel] Re: [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module
       [not found]                   ` <m2n.s.1PKW6s-0019ae-QGMSyCZBOSwv4zxTlrOuLwNdhmdF6hFW@public.gmane.org>
@ 2010-11-23 18:02                     ` Ian Jackson
  0 siblings, 0 replies; 66+ messages in thread
From: Ian Jackson @ 2010-11-23 18:02 UTC (permalink / raw)
  To: Ian Campbell
  Cc: xen-devel, Vincent Hanquez, xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR

Ian Campbell writes ("Re: [Xen-devel] Re: [Xen-API] [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module"):
> I shall probably convert the evtchn interfaces to use an xc_interface
> style opaque pointer as a handle, possibly/probably even reusing the
> existing xc_handle type in some way since it already contains broadly
> the right set of stuff.

Have fun with that.  I ducked that one when I was doing the xc_handle
type change ...

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [Xen-devel] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1)
       [not found] ` <1290077348.31507.5282.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
                     ` (2 preceding siblings ...)
  2010-11-18 10:50   ` [PATCH 0 of 7] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
@ 2010-12-07 14:30   ` Ian Campbell
  2010-12-07 14:32     ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
       [not found]     ` <1291732233.13966.3198.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  3 siblings, 2 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:30 UTC (permalink / raw)
  To: xen-devel; +Cc: xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR

A second version of each of these patch queues will follow shortly.

The major change is to make use of the proposed hooks in upstream
libxenctrl to reenable the XIU functionality. This allows xenstored and
xapi to run in an SDK VM. This depends on my "libxc: dom0 OS integration
cleanup+abstraction." series against xen-unstable.hg sent to xen-devel
last week.

I've not had any feedback on the module namespace issue so I haven't
done anything about that.

Ian.

On Thu, 2010-11-18 at 10:49 +0000, Ian Campbell wrote: 
> The following series against xen-api-libs.hg, xen-api.hg and
> xen-unstable.hg (to be posted as replies to this mail shortly) lays some
> groundwork to allow XCP to be used against xen-unstable (and therefore
> eventually the 4.1 release).
> 
> I have very much glossed over (i.e. hacked up the bare minimum of) the
> actual toolstack port to xen-unstable, since my primary aim was simply
> to do the groundwork to allow the use of the in-tree bindings in order
> to ensure that Xen 4.1.0 is released with something with a baseline
> level of usefulness to XCP. However I did do enough to allow
> installation and starting of a PV guest and a successful "quicktest
> -all" run (100% pass, FWIW).
> 
> I have arranged that the xen-api-libs.hg and xen-api.hg patches which
> can be applied now without compromising the existing Xen 3.4 based XCP
> platform are at the head of the relevant series and that the stuff which
> depends on the transition to Xen 4.1 comes afterwards and have the
> REBASE-4.1 prefix (followed by my hacks and other bits and pieces,
> marked with HACK, they are just for reference and should be applied
> to /dev/null only). The intention is that the xen-unstable bits can be
> applied before Xen 4.1 in order that the infrastructure is in place when
> XCP comes to rebase.
> 
> For my testing I have been using the build-xapi-toolstack.sh script from
> http://xenbits.xen.org/xapi/install.html so in actual fact some of the
> patches right at the start of the xen-api-libs.hg and xen-api.hg series
> as well as the entire xen-dist-ocaml.hg series are actually fixes for
> issues I encountered when using that script and doing RPM builds
> outside /usr/src hopefully it is obvious what is what.
> 
> While doing this work I started to wonder if using the xb, xs, xc, xl
> etc names at the toplevel of the ocaml module namespace was wise/polite?
> I'm not sure what support ocaml has for module namepacing but perhaps we
> should move the in-tree bindings to e.g. xen.lowlevel.{xb,xs,xc,xl} (to
> arbitrarily pick up the convention used in the python bindings)?
> 
> I also wonder about maintaining non-Xen specific support libraries (such
> as uuid, log and mmap) in the xen source tree. Perhaps these could be
> pushed further down into the ocaml ecosystem and become prerequisites of
> Xen? (assuming there is nothing similar already in the wider ocaml
> world). Some of the modules have grown slightly different interfaces in
> xen-api-libs.hg vs xen-unstable.hg, in some cases (e.g. uuid module)
> resynchronising is simple, in others (e.g. log module) it is not so
> trivial. This would be partially solved by namespacing the two sets of
> modules I guess but that seems non-optimal in terms of number of module
> to maintain.
> 
> Ian.
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR@public.gmane.org
> http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg
       [not found]     ` <1291732233.13966.3198.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-12-07 14:32       ` Ian Campbell
       [not found]         ` <patchbomb.1291732364-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
                           ` (2 more replies)
  2010-12-07 14:32       ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
  2010-12-07 14:33       ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
  2 siblings, 3 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

The following short series of patches makes xen-dist-ocaml.hg easier to use
from build-xapi-toolstack.sh.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1 of 3] Query rpm to find build directories
       [not found]         ` <patchbomb.1291732364-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-12-07 14:32           ` Ian Campbell
  2010-12-07 14:32           ` [PATCH 3 of 3] Install additional packages Ian Campbell
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290004675 18000
# Node ID 01cface0904c7c5d18703ad3f11909ab2f50471c
# Parent  c8f620542215cbb770e5f56e62eb43559e4a52d8
Query rpm to find build directories.

Allows user with ~/.rpmmacros to build e.g.
$ cat ~/.rpmmacros
%_topdir	/data/rpmbuild
%_tmppath	/data/tmp

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r c8f620542215 -r 01cface0904c Makefile
--- a/Makefile	Tue Oct 05 16:50:18 2010 +0000
+++ b/Makefile	Wed Nov 17 09:37:55 2010 -0500
@@ -8,10 +8,10 @@ MY_OUTPUT_DIR ?= $(CURDIR)/output
 MY_OBJ_DIR ?= $(CURDIR)/obj
 REPO ?= $(CURDIR)
 
-RPM_SPECSDIR?=/usr/src/redhat/SPECS
-RPM_SRPMSDIR?=/usr/src/redhat/SRPMS
-RPM_RPMSDIR?=/usr/src/redhat/RPMS
-RPM_SOURCESDIR?=/usr/src/redhat/SOURCES
+RPM_SPECSDIR?=$(shell rpm --eval='%_specdir')
+RPM_SRPMSDIR?=$(shell rpm --eval='%_srcrpmdir')
+RPM_RPMSDIR?=$(shell rpm --eval='%_rpmdir')
+RPM_SOURCESDIR?=$(shell rpm --eval='%_sourcedir')
 RPMBUILD?=rpmbuild
 
 DIST?=/data

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 2 of 3] Define $(RPM) for use in Makefile
  2010-12-07 14:32       ` [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Ian Campbell
       [not found]         ` <patchbomb.1291732364-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-12-07 14:32         ` Ian Campbell
  2010-12-08 18:19         ` [Xen-API] [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Dave Scott
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290004675 18000
# Node ID cf457090b419139cf5a67382e4ce8a44f03c4539
# Parent  01cface0904c7c5d18703ad3f11909ab2f50471c
Define $(RPM) for use in Makefile

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 01cface0904c -r cf457090b419 Makefile
--- a/Makefile	Wed Nov 17 09:37:55 2010 -0500
+++ b/Makefile	Wed Nov 17 09:37:55 2010 -0500
@@ -8,6 +8,7 @@ MY_OUTPUT_DIR ?= $(CURDIR)/output
 MY_OBJ_DIR ?= $(CURDIR)/obj
 REPO ?= $(CURDIR)
 
+RPM?=rpm
 RPM_SPECSDIR?=$(shell rpm --eval='%_specdir')
 RPM_SRPMSDIR?=$(shell rpm --eval='%_srcrpmdir')
 RPM_RPMSDIR?=$(shell rpm --eval='%_rpmdir')

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 3 of 3] Install additional packages
       [not found]         ` <patchbomb.1291732364-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:32           ` [PATCH 1 of 3] Query rpm to find build directories Ian Campbell
@ 2010-12-07 14:32           ` Ian Campbell
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290004675 18000
# Node ID 56f040418b89013cc5773c8a4da3644a59e91a6a
# Parent  cf457090b419139cf5a67382e4ce8a44f03c4539
Install additional packages

These were built but not installed but were used by something down the build
chain.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r cf457090b419 -r 56f040418b89 Makefile
--- a/Makefile	Wed Nov 17 09:37:55 2010 -0500
+++ b/Makefile	Wed Nov 17 09:37:55 2010 -0500
@@ -46,6 +46,10 @@ build: srpm $(MY_SOURCES)/MANIFEST
 	$(RPMBUILD) --target $(DOMAIN0_ARCH_OPTIMIZED) -bb $(RPM_SPECSDIR)/omake.spec
 	$(RPM) -ihv $(RPM_BINDIR)/omake* || echo omake is already installed
 	$(RPMBUILD) --target $(DOMAIN0_ARCH_OPTIMIZED) -bb $(RPM_SPECSDIR)/xmlm.spec $(RPM_SPECSDIR)/getopt.spec $(RPM_SPECSDIR)/type-conv.spec
+	$(RPM) -ivh $(RPM_BINDIR)/ocaml-xmlm*.rpm || echo ocaml-xmlm is already installed
+	$(RPM) -ivh $(RPM_BINDIR)/ocaml-getopt*.rpm || echo ocaml-getopt is already installed
+	$(RPM) -ivh $(RPM_BINDIR)/ocaml-type-conv*.rpm || echo ocaml-type-conv is already installed
+
 
 .PHONY: srpm
 srpm:

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg
  2010-12-07 14:30   ` [Xen-devel] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) Ian Campbell
@ 2010-12-07 14:32     ` Ian Campbell
       [not found]       ` <patchbomb.1291732371-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
                         ` (4 more replies)
       [not found]     ` <1291732233.13966.3198.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  1 sibling, 5 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

The following series of patches lays some ground work to enable XCP to move, at
some point in the future, to the in-tree ocaml bindings which will come with
Xen 4.1

This is the xen-unstable.hg portion.

All but the last patch are intended for immediate consideration.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg
       [not found]       ` <patchbomb.1291732371-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-12-07 14:32         ` Ian Campbell
  2010-12-07 14:32         ` [PATCH 2 of 5] ocaml: add dependency to module metadata Ian Campbell
  2010-12-07 14:32         ` [PATCH 4 of 5] ocaml: evtchn+xc bindings: use libxenctrl and libxenguest Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1291307719 18000
# Node ID 21d9d889ec30f6ac55267c745a1cae56c768f63b
# Parent  8ecbddf6cad3a2fbb63b273658b9f67429754d3d
ocaml: resynchronise uuid library with xen-api-libs.hg

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 8ecbddf6cad3 -r 21d9d889ec30 tools/ocaml/libs/uuid/uuid.ml
--- a/tools/ocaml/libs/uuid/uuid.ml	Thu Dec 02 10:09:24 2010 -0500
+++ b/tools/ocaml/libs/uuid/uuid.ml	Thu Dec 02 11:35:19 2010 -0500
@@ -1,6 +1,5 @@
 (*
- * Copyright (C) 2006-2007 XenSource Ltd.
- * Copyright (C) 2008      Citrix Ltd.
+ * Copyright (C) 2006-2010 Citrix Systems Inc.
  * Author Vincent Hanquez <vincent.hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -14,9 +13,7 @@
  * GNU Lesser General Public License for more details.
  *)
 
-(** Type-safe UUIDs. *)
-
-(** Internally, a UUID is simply a string. *)
+(* Internally, a UUID is simply a string. *)
 type 'a t = string
 
 type cookie = string
@@ -24,6 +21,8 @@ type cookie = string
 let of_string s = s
 let to_string s = s
 
+let null = ""
+
 (* deprecated: we don't need to duplicate the uuid prefix/suffix *)
 let uuid_of_string = of_string
 let string_of_uuid = to_string
@@ -32,12 +31,34 @@ let string_of_cookie s = s
 
 let cookie_of_string s = s
 
-(** FIXME: using /dev/random is too slow but using /dev/urandom is too
-    deterministic. *)
-let dev_random = "/dev/urandom"
+let dev_random = "/dev/random"
+let dev_urandom = "/dev/urandom"
 
-let read_random n = 
-  let ic = open_in_bin dev_random in
+let rnd_array n =
+	let fstbyte i = 0xff land i in
+	let sndbyte i = fstbyte (i lsr 8) in
+	let thdbyte i = sndbyte (i lsr 8) in
+	let rec rnd_list n acc = match n with
+		| 0 -> acc
+		| 1 ->
+			let b = fstbyte (Random.bits ()) in
+			b :: acc
+		| 2 ->
+			let r = Random.bits () in
+			let b1 = fstbyte r in
+			let b2 = sndbyte r in
+			b1 :: b2 :: acc
+		| n -> 
+			let r = Random.bits () in
+			let b1 = fstbyte r in
+			let b2 = sndbyte r in
+			let b3 = thdbyte r in
+			rnd_list (n - 3) (b1 :: b2 :: b3 :: acc)
+	in
+	Array.of_list (rnd_list n [])
+
+let read_array dev n = 
+  let ic = open_in_bin dev in
   try
     let result = Array.init n (fun _ -> input_byte ic) in
     close_in ic;
@@ -52,30 +73,14 @@ let uuid_of_int_array uuid =
     uuid.(6) uuid.(7) uuid.(8) uuid.(9) uuid.(10) uuid.(11)
     uuid.(12) uuid.(13) uuid.(14) uuid.(15)
 
-(** Return a new random UUID *)
-let make_uuid() = uuid_of_int_array (read_random 16)
+let make_uuid_prng () = uuid_of_int_array (rnd_array 16)
+let make_uuid_urnd () = uuid_of_int_array (read_array dev_urandom 16)
+let make_uuid_rnd () = uuid_of_int_array (read_array dev_random 16)
+let make_uuid = make_uuid_urnd
 
-(** Return a new random, big UUID (hopefully big and random enough to be
-    unguessable) *)
 let make_cookie() =
-  let bytes = Array.to_list (read_random 64) in
+  let bytes = Array.to_list (read_array dev_urandom 64) in
   String.concat "" (List.map (Printf.sprintf "%1x") bytes)
-(*
-  let hexencode x = 
-    let nibble x =
-      char_of_int (if x < 10 
-		   then int_of_char '0' + x
-		   else int_of_char 'a' + (x - 10)) in
-    let result = String.make (String.length x * 2) ' ' in
-    for i = 0 to String.length x - 1 do
-      let byte = int_of_char x.[i] in
-      result.[i * 2 + 0] <- nibble((byte lsr 4) land 15);
-      result.[i * 2 + 1] <- nibble((byte lsr 0) land 15);
-    done;
-    result in
-  let n = 64 in
-  hexencode (String.concat "" (List.map (fun x -> String.make 1 (char_of_int x)) (Array.to_list (read_n_random_bytes n))))
-*)
 
 let int_array_of_uuid s =
   try
@@ -86,3 +91,10 @@ let int_array_of_uuid s =
              a10; a11; a12; a13; a14; a15; ]);
     Array.of_list !l
   with _ -> invalid_arg "Uuid.int_array_of_uuid"
+
+let is_uuid str =
+	try
+		Scanf.sscanf str
+			"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
+			(fun _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ -> true)
+	with _ -> false
diff -r 8ecbddf6cad3 -r 21d9d889ec30 tools/ocaml/libs/uuid/uuid.mli
--- a/tools/ocaml/libs/uuid/uuid.mli	Thu Dec 02 10:09:24 2010 -0500
+++ b/tools/ocaml/libs/uuid/uuid.mli	Thu Dec 02 11:35:19 2010 -0500
@@ -1,6 +1,5 @@
 (*
- * Copyright (C) 2006-2007 XenSource Ltd.
- * Copyright (C) 2008      Citrix Ltd.
+ * Copyright (C) 2006-2010 Citrix Systems Inc.
  * Author Vincent Hanquez <vincent.hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -13,41 +12,56 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  *)
-
 (** Type-safe UUIDs.
     Probably need to refactor this; UUIDs are used in two places:
-    1. to uniquely name things across the cluster
-    2. as secure session IDs
+    + to uniquely name things across the cluster
+    + as secure session IDs
+
     There is the additional constraint that current Xen tools use 
     a particular format of UUID (the 16 byte variety generated by fresh ())
+
+	Also, cookies aren't UUIDs and should be put somewhere else.
 *)
 
-(** A 128-bit UUID referencing a value of type 'a. *)
+(** A 128-bit UUID.  Using phantom types ('a) to achieve the requires type-safety. *)
 type 'a t
 
-(** A 512-bit UUID. *)
+(** Create a fresh UUID *)
+val make_uuid : unit -> 'a t
+val make_uuid_prng : unit -> 'a t
+val make_uuid_urnd : unit -> 'a t
+val make_uuid_rnd : unit -> 'a t
+
+(** Create a UUID from a string. *)
+val of_string : string -> 'a t
+
+(** Marshal a UUID to a string. *)
+val to_string : 'a t -> string
+
+(** A null UUID, as if such a thing actually existed.  It turns out to be
+ * useful though. *)
+val null : 'a t
+
+(** Deprecated alias for {! Uuid.of_string} *)
+val uuid_of_string : string -> 'a t
+
+(** Deprecated alias for {! Uuid.to_string} *)
+val string_of_uuid : 'a t -> string
+
+(** Convert an array to a UUID. *)
+val uuid_of_int_array : int array -> 'a t
+
+(** Convert a UUID to an array. *)
+val int_array_of_uuid : 'a t -> int array
+
+(** Check whether a string is a UUID. *)
+val is_uuid : string -> bool
+
+(** A 512-bit cookie. *)
 type cookie
 
-(** Create a fresh (unique!) UUID *)
-val make_uuid : unit -> 'a t
-
-(** Create a fresh secure (bigger and hopefully unguessable) UUID *)
 val make_cookie : unit -> cookie
 
-(** Create a type-safe UUID. *)
-val of_string : string -> 'a t
-
-(** Marshal a UUID to a (type-unsafe) string. *)
-val to_string : 'a t -> string
-
-(* deprecated alias for previous one *)
-val uuid_of_string : string -> 'a t
-val string_of_uuid : 'a t -> string
-
 val cookie_of_string : string -> cookie
 
 val string_of_cookie : cookie -> string
-
-val uuid_of_int_array : int array -> 'a t
-
-val int_array_of_uuid : 'a t -> int array

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 2 of 5] ocaml: add dependency to module metadata
       [not found]       ` <patchbomb.1291732371-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:32         ` [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg Ian Campbell
@ 2010-12-07 14:32         ` Ian Campbell
  2010-12-07 14:32         ` [PATCH 4 of 5] ocaml: evtchn+xc bindings: use libxenctrl and libxenguest Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1291307719 18000
# Node ID e147f32b385cdebc568992fae9ceb71d958bb169
# Parent  21d9d889ec30f6ac55267c745a1cae56c768f63b
ocaml: add dependency to module metadata.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 21d9d889ec30 -r e147f32b385c tools/ocaml/libs/eventchn/META.in
--- a/tools/ocaml/libs/eventchn/META.in	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/eventchn/META.in	Thu Dec 02 11:35:19 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "Eventchn interface extension"
+requires = "unix"
 archive(byte) = "eventchn.cma"
 archive(native) = "eventchn.cmxa"
diff -r 21d9d889ec30 -r e147f32b385c tools/ocaml/libs/log/META.in
--- a/tools/ocaml/libs/log/META.in	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/log/META.in	Thu Dec 02 11:35:19 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "Log - logging library"
+requires = "unix"
 archive(byte) = "log.cma"
 archive(native) = "log.cmxa"
diff -r 21d9d889ec30 -r e147f32b385c tools/ocaml/libs/xb/META.in
--- a/tools/ocaml/libs/xb/META.in	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/xb/META.in	Thu Dec 02 11:35:19 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "XenBus Interface"
+requires = "unix,mmap"
 archive(byte) = "xb.cma"
 archive(native) = "xb.cmxa"
diff -r 21d9d889ec30 -r e147f32b385c tools/ocaml/libs/xc/META.in
--- a/tools/ocaml/libs/xc/META.in	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/xc/META.in	Thu Dec 02 11:35:19 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "Xen Control Interface"
+requires = "mmap,uuid"
 archive(byte) = "xc.cma"
 archive(native) = "xc.cmxa"
diff -r 21d9d889ec30 -r e147f32b385c tools/ocaml/libs/xs/META.in
--- a/tools/ocaml/libs/xs/META.in	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/xs/META.in	Thu Dec 02 11:35:19 2010 -0500
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "XenStore Interface"
+requires = "unix,xb"
 archive(byte) = "xs.cma"
 archive(native) = "xs.cmxa"

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 3 of 5] ocaml: rename Evtchn.bind_virq as Evtchn.bind_dom_exc_virq
  2010-12-07 14:32     ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
       [not found]       ` <patchbomb.1291732371-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-12-07 14:32       ` Ian Campbell
  2010-12-07 14:32       ` [PATCH 5 of 5] HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same Ian Campbell
                         ` (2 subsequent siblings)
  4 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1291307719 18000
# Node ID 9ca2fdb9072dceac4f37c9e14d41fdcdcc9be7a9
# Parent  e147f32b385cdebc568992fae9ceb71d958bb169
ocaml: rename Evtchn.bind_virq as Evtchn.bind_dom_exc_virq
to reflect it actual behaviour.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r e147f32b385c -r 9ca2fdb9072d tools/ocaml/libs/eventchn/eventchn.ml
--- a/tools/ocaml/libs/eventchn/eventchn.ml	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/eventchn/eventchn.ml	Thu Dec 02 11:35:19 2010 -0500
@@ -19,7 +19,7 @@ exception Error of string
 external init: unit -> Unix.file_descr = "stub_eventchn_init"
 external notify: Unix.file_descr -> int -> unit = "stub_eventchn_notify"
 external bind_interdomain: Unix.file_descr -> int -> int -> int = "stub_eventchn_bind_interdomain"
-external bind_virq: Unix.file_descr -> int = "stub_eventchn_bind_virq"
+external bind_dom_exc_virq: Unix.file_descr -> int = "stub_eventchn_bind_dom_exc_virq"
 external unbind: Unix.file_descr -> int -> unit = "stub_eventchn_unbind"
 external read_port: Unix.file_descr -> int = "stub_eventchn_read_port"
 external write_port: Unix.file_descr -> int -> unit = "stub_eventchn_write_port"
diff -r e147f32b385c -r 9ca2fdb9072d tools/ocaml/libs/eventchn/eventchn.mli
--- a/tools/ocaml/libs/eventchn/eventchn.mli	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/eventchn/eventchn.mli	Thu Dec 02 11:35:19 2010 -0500
@@ -19,7 +19,7 @@ external init : unit -> Unix.file_descr 
 external notify : Unix.file_descr -> int -> unit = "stub_eventchn_notify"
 external bind_interdomain : Unix.file_descr -> int -> int -> int
   = "stub_eventchn_bind_interdomain"
-external bind_virq : Unix.file_descr -> int = "stub_eventchn_bind_virq"
+external bind_dom_exc_virq : Unix.file_descr -> int = "stub_eventchn_bind_dom_exc_virq"
 external unbind : Unix.file_descr -> int -> unit = "stub_eventchn_unbind"
 external read_port : Unix.file_descr -> int = "stub_eventchn_read_port"
 external write_port : Unix.file_descr -> int -> unit
diff -r e147f32b385c -r 9ca2fdb9072d tools/ocaml/libs/eventchn/eventchn_stubs.c
--- a/tools/ocaml/libs/eventchn/eventchn_stubs.c	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/eventchn/eventchn_stubs.c	Thu Dec 02 11:35:19 2010 -0500
@@ -97,7 +97,7 @@ CAMLprim value stub_eventchn_bind_interd
 	CAMLreturn(port);
 }
 
-CAMLprim value stub_eventchn_bind_virq(value fd)
+CAMLprim value stub_eventchn_bind_dom_exc_virq(value fd)
 {
 	CAMLparam1(fd);
 	CAMLlocal1(port);
diff -r e147f32b385c -r 9ca2fdb9072d tools/ocaml/xenstored/event.ml
--- a/tools/ocaml/xenstored/event.ml	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/xenstored/event.ml	Thu Dec 02 11:35:19 2010 -0500
@@ -21,7 +21,7 @@ type t = {
 }
 
 let init () = { fd = Eventchn.init (); virq_port = -1; }
-let bind_virq eventchn = eventchn.virq_port <- Eventchn.bind_virq eventchn.fd
+let bind_dom_exc_virq eventchn = eventchn.virq_port <- Eventchn.bind_dom_exc_virq eventchn.fd
 let bind_interdomain eventchn domid port = Eventchn.bind_interdomain eventchn.fd domid port
 let unbind eventchn port = Eventchn.unbind eventchn.fd port
 let notify eventchn port = Eventchn.notify eventchn.fd port
diff -r e147f32b385c -r 9ca2fdb9072d tools/ocaml/xenstored/xenstored.ml
--- a/tools/ocaml/xenstored/xenstored.ml	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/xenstored/xenstored.ml	Thu Dec 02 11:35:19 2010 -0500
@@ -270,7 +270,7 @@ let _ =
 
 	if cf.restart then (
 		DB.from_file store domains cons "/var/run/xenstored/db";
-		Event.bind_virq eventchn
+		Event.bind_dom_exc_virq eventchn
 	) else (
 		if !Disk.enable then (
 			info "reading store from disk";
@@ -284,7 +284,7 @@ let _ =
 		if cf.domain_init then (
 			let usingxiu = Xc.using_injection () in
 			Connections.add_domain cons (Domains.create0 usingxiu domains);
-			Event.bind_virq eventchn
+			Event.bind_dom_exc_virq eventchn
 		);
 	);

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 4 of 5] ocaml: evtchn+xc bindings: use libxenctrl and libxenguest
       [not found]       ` <patchbomb.1291732371-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:32         ` [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg Ian Campbell
  2010-12-07 14:32         ` [PATCH 2 of 5] ocaml: add dependency to module metadata Ian Campbell
@ 2010-12-07 14:32         ` Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1291307719 18000
# Node ID 5aca7dd0284714d086b62b3504a39b67e23b65e2
# Parent  9ca2fdb9072dceac4f37c9e14d41fdcdcc9be7a9
ocaml: evtchn+xc bindings: use libxenctrl and libxenguest

Now that tools/libxc is licensed under LGPL I don't think there is any need for
an LGPL reimplementation under tools/ocaml.

For the most part the conversion to the up-to-date libxc API (xc_lib.c
essentially implemented the same interface as an older libxc) was pretty
automatic. There are some functions which appear to no longer exist in libxc
which I therefore simply removed the bindings for and a small number of
interfaces which had changed.

Many of the functions bound by the stubs have no in-tree users (which I think
is fine for a language binding) so I have no way to confirm correctness other
than by eye. I was however able to confirm that oxenstored still worked and to
build a XCP toolstack which could successfully start a PV guest.

Uses the new XC_OPENFLAG_NON_REENTRANT option to avoid potential conflicts
between pthreads and the ocaml runtime.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
Cc: Vincent Hanquez <Vincent.Hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>

diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/Makefile.rules
--- a/tools/ocaml/Makefile.rules	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/Makefile.rules	Thu Dec 02 11:35:19 2010 -0500
@@ -54,18 +54,18 @@ mk-caml-lib-bytecode = $(call quiet-comm
 
 mk-caml-stubs = $(call quiet-command, $(OCAMLMKLIB) -o `basename $1 .a` $2,MKLIB,$1)
 mk-caml-lib-stubs = \
-	$(call quiet-command, $(AR) rcs $1 $2 && $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $2,MKLIB,$1)
+	$(call quiet-command, $(AR) rcs $1 $2 && $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $3 $2,MKLIB,$1)
 
 # define a library target <name>.cmxa and <name>.cma
 define OCAML_LIBRARY_template
  $(1).cmxa: lib$(1)_stubs.a $(foreach obj,$($(1)_OBJS),$(obj).cmx)
-	$(call mk-caml-lib-native,$$@, -cclib -l$(1)_stubs, $(foreach obj,$($(1)_OBJS),$(obj).cmx))
+	$(call mk-caml-lib-native,$$@, -cclib -l$(1)_stubs $(foreach lib,$(LIBS_$(1)),-cclib $(lib)), $(foreach obj,$($(1)_OBJS),$(obj).cmx))
  $(1).cma: $(foreach obj,$($(1)_OBJS),$(obj).cmo)
 	$(call mk-caml-lib-bytecode,$$@, -dllib dll$(1)_stubs.so -cclib -l$(1)_stubs, $$+)
  $(1)_stubs.a: $(foreach obj,$$($(1)_C_OBJS),$(obj).o)
 	$(call mk-caml-stubs,$$@, $$+)
  lib$(1)_stubs.a: $(foreach obj,$($(1)_C_OBJS),$(obj).o)
-	$(call mk-caml-lib-stubs,$$@, $$+)
+	$(call mk-caml-lib-stubs,$$@, $$+, $(LIBS_$(1)))
 endef
 
 define OCAML_NOC_LIBRARY_template
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/eventchn/eventchn.ml
--- a/tools/ocaml/libs/eventchn/eventchn.ml	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/eventchn/eventchn.ml	Thu Dec 02 11:35:19 2010 -0500
@@ -16,12 +16,15 @@
 
 exception Error of string
 
-external init: unit -> Unix.file_descr = "stub_eventchn_init"
-external notify: Unix.file_descr -> int -> unit = "stub_eventchn_notify"
-external bind_interdomain: Unix.file_descr -> int -> int -> int = "stub_eventchn_bind_interdomain"
-external bind_dom_exc_virq: Unix.file_descr -> int = "stub_eventchn_bind_dom_exc_virq"
-external unbind: Unix.file_descr -> int -> unit = "stub_eventchn_unbind"
-external read_port: Unix.file_descr -> int = "stub_eventchn_read_port"
-external write_port: Unix.file_descr -> int -> unit = "stub_eventchn_write_port"
+type handle
+
+external init: unit -> handle = "stub_eventchn_init"
+external fd: handle -> Unix.file_descr = "stub_eventchn_fd"
+external notify: handle -> int -> unit = "stub_eventchn_notify"
+external bind_interdomain: handle -> int -> int -> int = "stub_eventchn_bind_interdomain"
+external bind_dom_exc_virq: handle -> int = "stub_eventchn_bind_dom_exc_virq"
+external unbind: handle -> int -> unit = "stub_eventchn_unbind"
+external pending: handle -> int = "stub_eventchn_pending"
+external unmask: handle -> int -> unit = "stub_eventchn_unmask"
 
 let _ = Callback.register_exception "eventchn.error" (Error "register_callback")
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/eventchn/eventchn.mli
--- a/tools/ocaml/libs/eventchn/eventchn.mli	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/eventchn/eventchn.mli	Thu Dec 02 11:35:19 2010 -0500
@@ -15,12 +15,17 @@
  *)
 
 exception Error of string
-external init : unit -> Unix.file_descr = "stub_eventchn_init"
-external notify : Unix.file_descr -> int -> unit = "stub_eventchn_notify"
-external bind_interdomain : Unix.file_descr -> int -> int -> int
+
+type handle
+
+external init : unit -> handle = "stub_eventchn_init"
+external fd: handle -> Unix.file_descr = "stub_eventchn_fd"
+
+external notify : handle -> int -> unit = "stub_eventchn_notify"
+external bind_interdomain : handle -> int -> int -> int
   = "stub_eventchn_bind_interdomain"
-external bind_dom_exc_virq : Unix.file_descr -> int = "stub_eventchn_bind_dom_exc_virq"
-external unbind : Unix.file_descr -> int -> unit = "stub_eventchn_unbind"
-external read_port : Unix.file_descr -> int = "stub_eventchn_read_port"
-external write_port : Unix.file_descr -> int -> unit
-  = "stub_eventchn_write_port"
+external bind_dom_exc_virq : handle -> int = "stub_eventchn_bind_dom_exc_virq"
+external unbind : handle -> int -> unit = "stub_eventchn_unbind"
+external pending : handle -> int = "stub_eventchn_pending"
+external unmask : handle -> int -> unit
+  = "stub_eventchn_unmask"
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/eventchn/eventchn_stubs.c
--- a/tools/ocaml/libs/eventchn/eventchn_stubs.c	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/eventchn/eventchn_stubs.c	Thu Dec 02 11:35:19 2010 -0500
@@ -34,119 +34,110 @@
 #include <caml/callback.h>
 #include <caml/fail.h>
 
-#define EVENTCHN_PATH "/dev/xen/evtchn"
+#define _H(__h) ((xc_interface *)(__h))
 
-static int do_ioctl(int handle, int cmd, void *arg)
+CAMLprim value stub_eventchn_init(void)
 {
-	return ioctl(handle, cmd, arg);
+	CAMLparam0();
+	CAMLlocal1(result);
+
+	xc_interface *xce = xc_evtchn_open(NULL, XC_OPENFLAG_NON_REENTRANT);
+	if (xce == NULL)
+		caml_failwith("open failed");
+
+	result = (value)xce;
+	CAMLreturn(result);
 }
 
-static int do_read_port(int handle, evtchn_port_t *port)
+CAMLprim value stub_eventchn_fd(value xce)
 {
-	return (read(handle, port, sizeof(evtchn_port_t)) != sizeof(evtchn_port_t));
+	CAMLparam1(xce);
+	CAMLlocal1(result);
+	int fd;
+
+	fd = xc_evtchn_fd(_H(xce));
+	if (fd == -1)
+		caml_failwith("evtchn fd failed");
+
+	result = Val_int(fd);
+
+	CAMLreturn(result);
 }
 
-static int do_write_port(int handle, evtchn_port_t port)
+CAMLprim value stub_eventchn_notify(value xce, value port)
 {
-	return (write(handle, &port, sizeof(evtchn_port_t)) != sizeof(evtchn_port_t));
-}
-
-int eventchn_do_open(void)
-{
-	return open(EVENTCHN_PATH, O_RDWR);
-}
-
-CAMLprim value stub_eventchn_init(value unit)
-{
-	CAMLparam1(unit);
-	int fd = eventchn_do_open();
-	if (fd == -1)
-		caml_failwith("open failed");
-	CAMLreturn(Val_int(fd));
-}
-
-CAMLprim value stub_eventchn_notify(value fd, value port)
-{
-	CAMLparam2(fd, port);
-	struct ioctl_evtchn_notify notify;
+	CAMLparam2(xce, port);
 	int rc;
 
-	notify.port = Int_val(port);
-	rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_NOTIFY, &notify);
+	rc = xc_evtchn_notify(_H(xce), Int_val(port));
 	if (rc == -1)
-		caml_failwith("ioctl notify failed");
+		caml_failwith("evtchn notify failed");
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_eventchn_bind_interdomain(value fd, value domid,
+CAMLprim value stub_eventchn_bind_interdomain(value xce, value domid,
                                               value remote_port)
 {
-	CAMLparam3(fd, domid, remote_port);
+	CAMLparam3(xce, domid, remote_port);
 	CAMLlocal1(port);
-	struct ioctl_evtchn_bind_interdomain bind;
-	int rc;
+	evtchn_port_or_error_t rc;
 
-	bind.remote_domain = Int_val(domid);
-	bind.remote_port = Int_val(remote_port);
-	rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+	rc = xc_evtchn_bind_interdomain(_H(xce), Int_val(domid), Int_val(remote_port));
 	if (rc == -1)
-		caml_failwith("ioctl bind_interdomain failed");
+		caml_failwith("evtchn bind_interdomain failed");
 	port = Val_int(rc);
 
 	CAMLreturn(port);
 }
 
-CAMLprim value stub_eventchn_bind_dom_exc_virq(value fd)
+CAMLprim value stub_eventchn_bind_dom_exc_virq(value xce)
 {
-	CAMLparam1(fd);
+	CAMLparam1(xce);
 	CAMLlocal1(port);
-	struct ioctl_evtchn_bind_virq bind;
-	int rc;
+	evtchn_port_or_error_t rc;
 
-	bind.virq = VIRQ_DOM_EXC;
-	rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_BIND_VIRQ, &bind);
+	rc = xc_evtchn_bind_virq(_H(xce), VIRQ_DOM_EXC);
 	if (rc == -1)
-		caml_failwith("ioctl bind_virq failed");
+		caml_failwith("evtchn bind_dom_exc_virq failed");
 	port = Val_int(rc);
 
 	CAMLreturn(port);
 }
 
-CAMLprim value stub_eventchn_unbind(value fd, value port)
+CAMLprim value stub_eventchn_unbind(value xce, value port)
 {
-	CAMLparam2(fd, port);
-	struct ioctl_evtchn_unbind unbind;
+	CAMLparam2(xce, port);
 	int rc;
 
-	unbind.port = Int_val(port);
-	rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_UNBIND, &unbind);
+	rc = xc_evtchn_unbind(_H(xce), Int_val(port));
 	if (rc == -1)
-		caml_failwith("ioctl unbind failed");
+		caml_failwith("evtchn unbind failed");
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_eventchn_read_port(value fd)
+CAMLprim value stub_eventchn_pending(value xce)
 {
-	CAMLparam1(fd);
+	CAMLparam1(xce);
 	CAMLlocal1(result);
-	evtchn_port_t port;
+	evtchn_port_or_error_t port;
 
-	if (do_read_port(Int_val(fd), &port))
-		caml_failwith("read port failed");
+	port = xc_evtchn_pending(_H(xce));
+	if (port == -1)
+		caml_failwith("evtchn pending failed");
 	result = Val_int(port);
 
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_eventchn_write_port(value fd, value _port)
+CAMLprim value stub_eventchn_unmask(value xce, value _port)
 {
-	CAMLparam2(fd, _port);
+	CAMLparam2(xce, _port);
 	evtchn_port_t port;
 
 	port = Int_val(_port);
-	if (do_write_port(Int_val(fd), port))
-		caml_failwith("write port failed");
+	if (xc_evtchn_unmask(_H(xce), port))
+		caml_failwith("evtchn unmask failed");
 	CAMLreturn(Val_unit);
 }
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/xc/Makefile
--- a/tools/ocaml/libs/xc/Makefile	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/xc/Makefile	Thu Dec 02 11:35:19 2010 -0500
@@ -2,15 +2,17 @@ TOPLEVEL=../..
 XEN_ROOT=$(TOPLEVEL)/../..
 include $(TOPLEVEL)/common.make
 
-CFLAGS += -I../mmap -I./
-OCAMLINCLUDE += -I ../mmap -I ../uuid
+CFLAGS += -I../mmap -I./ -I$(XEN_ROOT)/tools/libxc
+OCAMLINCLUDE += -I ../mmap -I ../uuid -I $(XEN_ROOT)/tools/libxc
 
 OBJS = xc
 INTF = xc.cmi
 LIBS = xc.cma xc.cmxa
 
+LIBS_xc = -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
+
 xc_OBJS = $(OBJS)
-xc_C_OBJS = xc_lib xc_stubs
+xc_C_OBJS = xc_stubs
 
 OCAML_LIBRARY = xc
 
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/xc/xc.h
--- a/tools/ocaml/libs/xc/xc.h	Thu Dec 02 11:35:19 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2006-2007 XenSource Ltd.
- * Copyright (C) 2008      Citrix Ltd.
- * Author Vincent Hanquez <vincent.hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; version 2.1 only. with the special
- * exception on linking described in file LICENSE.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- */
-
-#include <xen/xen.h>
-#include <xen/memory.h>
-#include <xen/sysctl.h>
-#include <xen/domctl.h>
-#include <xen/sched.h>
-#include <xen/sysctl.h>
-#include <xen/sys/privcmd.h>
-#include <xen/version.h>
-#include <xen/foreign/x86_32.h>
-#include <xen/foreign/x86_64.h>
-#include <xen/hvm/params.h>
-#include "xc_e820.h"
-
-typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
-typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
-typedef xen_sysctl_physinfo_t xc_physinfo_t;
-
-struct xc_core_header {
-	unsigned int xch_magic;
-	unsigned int xch_nr_vcpus;
-	unsigned int xch_nr_pages;
-	unsigned int xch_ctxt_offset;
-	unsigned int xch_index_offset;
-	unsigned int xch_pages_offset;
-};
-
-typedef union {
-#if defined(__i386__) || defined(__x86_64__)
-	vcpu_guest_context_x86_64_t x64;
-	vcpu_guest_context_x86_32_t x32;
-#endif
-	vcpu_guest_context_t c;
-} vcpu_guest_context_any_t;
-
-char * xc_error_get(void);
-void xc_error_clear(void);
-
-int xc_using_injection(void);
-
-int xc_interface_open(void);
-int xc_interface_close(int handle);
-
-int xc_domain_create(int handle, unsigned int ssidref,
-                     xen_domain_handle_t dhandle,
-                     unsigned int flags, unsigned int *pdomid);
-int xc_domain_pause(int handle, unsigned int domid);
-int xc_domain_unpause(int handle, unsigned int domid);
-int xc_domain_resume_fast(int handle, unsigned int domid);
-int xc_domain_destroy(int handle, unsigned int domid);
-int xc_domain_shutdown(int handle, int domid, int reason);
-
-int xc_vcpu_setaffinity(int handle, unsigned int domid, int vcpu,
-                        uint64_t cpumap);
-int xc_vcpu_getaffinity(int handle, unsigned int domid, int vcpu,
-                        uint64_t *cpumap);
-
-int xc_domain_getinfolist(int handle, unsigned int first_domain,
-                          unsigned int max_domains, xc_domaininfo_t *info);
-int xc_domain_getinfo(int handle, unsigned int first_domain,
-                      xc_domaininfo_t *info);
-
-int xc_domain_setmaxmem(int handle, unsigned int domid, unsigned int max_memkb);
-int xc_domain_set_memmap_limit(int handle, unsigned int domid,
-                               unsigned long map_limitkb);
-
-int xc_domain_set_time_offset(int handle, unsigned int domid, int time_offset);
-
-int xc_domain_memory_increase_reservation(int handle, unsigned int domid,
-                                          unsigned long nr_extents,
-                                          unsigned int extent_order,
-                                          unsigned int address_bits,
-                                          xen_pfn_t *extent_start);
-int xc_domain_memory_decrease_reservation(int handle, unsigned int domid,
-                                          unsigned long nr_extents,
-                                          unsigned int extent_order,
-                                          unsigned int address_bits,
-                                          xen_pfn_t *extent_start);
-int xc_domain_memory_populate_physmap(int handle, unsigned int domid,
-                                      unsigned long nr_extents,
-                                      unsigned int extent_order,
-                                      unsigned int address_bits,
-                                      xen_pfn_t *extent_start);
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist);
-int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max);
-int xc_domain_sethandle(int handle, unsigned int domid,
-                        xen_domain_handle_t dhandle);
-int xc_vcpu_getinfo(int handle, unsigned int domid, unsigned int vcpu,
-                    xc_vcpuinfo_t *info);
-int xc_domain_ioport_permission(int handle, unsigned int domid,
-                                unsigned int first_port, unsigned int nr_ports,
-                                unsigned int allow_access);
-int xc_vcpu_setcontext(int handle, unsigned int domid,
-                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt);
-int xc_vcpu_getcontext(int handle, unsigned int domid,
-                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt);
-int xc_domain_irq_permission(int handle, unsigned int domid,
-                             unsigned char pirq, unsigned char allow_access);
-int xc_domain_iomem_permission(int handle, unsigned int domid,
-                               unsigned long first_mfn, unsigned long nr_mfns,
-                               unsigned char allow_access);
-long long xc_domain_get_cpu_usage(int handle, unsigned int domid,
-                                  unsigned int vcpu);
-void *xc_map_foreign_range(int handle, unsigned int domid,
-                           int size, int prot, unsigned long mfn);
-int xc_map_foreign_ranges(int handle, unsigned int domid,
-                          privcmd_mmap_entry_t *entries, int nr);
-int xc_readconsolering(int handle, char **pbuffer,
-                       unsigned int *pnr_chars, int clear);
-int xc_send_debug_keys(int handle, char *keys);
-int xc_physinfo(int handle, xc_physinfo_t *put_info);
-int xc_pcpu_info(
-	int handle, int max_cpus, xen_sysctl_cpuinfo_t *info, int *nr_cpus);
-int xc_sched_id(int handle, int *sched_id);
-int xc_version(int handle, int cmd, void *arg);
-int xc_evtchn_alloc_unbound(int handle, unsigned int domid,
-                            unsigned int remote_domid);
-int xc_evtchn_reset(int handle, unsigned int domid);
-
-int xc_sched_credit_domain_set(int handle, unsigned int domid,
-                               struct xen_domctl_sched_credit *sdom);
-int xc_sched_credit_domain_get(int handle, unsigned int domid,
-                               struct xen_domctl_sched_credit *sdom);
-int xc_shadow_allocation_get(int handle, unsigned int domid,
-			     uint32_t *mb);
-int xc_shadow_allocation_set(int handle, unsigned int domid,
-			     uint32_t mb);
-int xc_domain_get_pfn_list(int handle, unsigned int domid,
-                           uint64_t *pfn_array, unsigned long max_pfns);
-int xc_hvm_check_pvdriver(int handle, unsigned int domid);
-
-int xc_domain_assign_device(int handle, unsigned int domid,
-                            int domain, int bus, int slot, int func);
-int xc_domain_deassign_device(int handle, unsigned int domid,
-                              int domain, int bus, int slot, int func);
-int xc_domain_test_assign_device(int handle, unsigned int domid,
-                                 int domain, int bus, int slot, int func);
-int xc_domain_watchdog(int handle, int id, uint32_t timeout);
-int xc_domain_set_machine_address_size(int xc, uint32_t domid, unsigned int width);
-int xc_domain_get_machine_address_size(int xc, uint32_t domid);
-
-int xc_domain_cpuid_set(int xc, unsigned int domid, int hvm,
-                        uint32_t input, uint32_t oinput,
-                        char *config[4], char *config_out[4]);
-int xc_domain_cpuid_apply(int xc, unsigned int domid, int hvm);
-int xc_cpuid_check(uint32_t input, uint32_t optsubinput,
-                   char *config[4], char *config_out[4]);
-
-int xc_domain_send_s3resume(int handle, unsigned int domid);
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align);
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet);
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode);
-int xc_domain_get_acpi_s_state(int handle, unsigned int domid);
-
-#if XEN_SYSCTL_INTERFACE_VERSION >= 6
-#define SAFEDIV(a, b)					(((b) > 0) ? (a) / (b) : (a))
-#define COMPAT_FIELD_physinfo_get_nr_cpus(p)		(p).nr_cpus
-#define COMPAT_FIELD_physinfo_get_sockets_per_node(p)	\
-	SAFEDIV((p).nr_cpus, ((p).threads_per_core * (p).cores_per_socket * (p).nr_nodes))
-#else
-#define COMPAT_FIELD_physinfo_get_nr_cpus(p)		\
-	((p).threads_per_core * (p).sockets_per_node *	\
-	 (p).cores_per_socket * (p).threads_per_core)
-#define COMPAT_FIELD_physinfo_get_sockets_per_node(p)	(p).sockets_per_node
-#endif
-
-#if __XEN_LATEST_INTERFACE_VERSION__ >= 0x00030209
-#define COMPAT_FIELD_ADDRESS_BITS		mem_flags
-#else
-#define COMPAT_FIELD_ADDRESS_BITS		address_bits
-#endif
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/xc/xc.ml
--- a/tools/ocaml/libs/xc/xc.ml	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/xc/xc.ml	Thu Dec 02 11:35:19 2010 -0500
@@ -107,7 +107,7 @@ external sizeof_xen_pfn: unit -> int = "
 external interface_open: unit -> handle = "stub_xc_interface_open"
 external interface_close: handle -> unit = "stub_xc_interface_close"
 
-external using_injection: unit -> bool = "stub_xc_using_injection"
+external is_fake: unit -> bool = "stub_xc_interface_is_fake"
 
 let with_intf f =
 	let xc = interface_open () in
@@ -127,9 +127,6 @@ external _domain_sethandle: handle -> do
 let domain_sethandle handle n uuid =
 	_domain_sethandle handle n (Uuid.int_array_of_uuid uuid)
 
-external domain_setvmxassist: handle -> domid -> bool -> unit
-       = "stub_xc_domain_setvmxassist"
-
 external domain_max_vcpus: handle -> domid -> int -> unit
        = "stub_xc_domain_max_vcpus"
 
@@ -165,9 +162,9 @@ external domain_iomem_permission: handle
 external domain_irq_permission: handle -> domid -> int -> bool -> unit
        = "stub_xc_domain_irq_permission"
 
-external vcpu_affinity_set: handle -> domid -> int -> int64 -> unit
+external vcpu_affinity_set: handle -> domid -> int -> bool array -> unit
        = "stub_xc_vcpu_setaffinity"
-external vcpu_affinity_get: handle -> domid -> int -> int64
+external vcpu_affinity_get: handle -> domid -> int -> bool array
        = "stub_xc_vcpu_getaffinity"
 
 external vcpu_context_get: handle -> domid -> int -> string
@@ -207,13 +204,13 @@ external domain_set_machine_address_size
 external domain_get_machine_address_size: handle -> domid -> int
        = "stub_xc_domain_get_machine_address_size"
 
-external domain_cpuid_set: handle -> domid -> bool -> (int64 * (int64 option))
+external domain_cpuid_set: handle -> domid -> (int64 * (int64 option))
                         -> string option array
                         -> string option array
        = "stub_xc_domain_cpuid_set"
-external domain_cpuid_apply: handle -> domid -> bool -> unit
-       = "stub_xc_domain_cpuid_apply"
-external cpuid_check: (int64 * (int64 option)) -> string option array -> (bool * string option array)
+external domain_cpuid_apply_policy: handle -> domid -> unit
+       = "stub_xc_domain_cpuid_apply_policy"
+external cpuid_check: handle -> (int64 * (int64 option)) -> string option array -> (bool * string option array)
        = "stub_xc_cpuid_check"
 
 external map_foreign_range: handle -> domid -> int
@@ -230,17 +227,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit = "stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
-
-(** check if some hvm domain got pv driver or not *)
-external hvm_check_pvdriver: handle -> domid -> bool
-       = "stub_xc_hvm_check_pvdriver"
-
 external version: handle -> version = "stub_xc_version_version"
 external version_compile_info: handle -> compile_info
        = "stub_xc_version_compile_info"
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/xc/xc.mli
--- a/tools/ocaml/libs/xc/xc.mli	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/xc/xc.mli	Thu Dec 02 11:35:19 2010 -0500
@@ -71,7 +71,7 @@ external sizeof_vcpu_guest_context : uni
   = "stub_sizeof_vcpu_guest_context"
 external sizeof_xen_pfn : unit -> int = "stub_sizeof_xen_pfn"
 external interface_open : unit -> handle = "stub_xc_interface_open"
-external using_injection : unit -> bool = "stub_xc_using_injection"
+external is_fake : unit -> bool = "stub_xc_interface_is_fake"
 external interface_close : handle -> unit = "stub_xc_interface_close"
 val with_intf : (handle -> 'a) -> 'a
 external _domain_create : handle -> int32 -> domain_create_flag list -> int array -> domid
@@ -80,8 +80,6 @@ val domain_create : handle -> int32 -> d
 external _domain_sethandle : handle -> domid -> int array -> unit
   = "stub_xc_domain_sethandle"
 val domain_sethandle : handle -> domid -> 'a Uuid.t -> unit
-external domain_setvmxassist: handle -> domid -> bool -> unit
-  = "stub_xc_domain_setvmxassist"
 external domain_max_vcpus : handle -> domid -> int -> unit
   = "stub_xc_domain_max_vcpus"
 external domain_pause : handle -> domid -> unit = "stub_xc_domain_pause"
@@ -104,9 +102,9 @@ external domain_iomem_permission: handle
        = "stub_xc_domain_iomem_permission"
 external domain_irq_permission: handle -> domid -> int -> bool -> unit
        = "stub_xc_domain_irq_permission"
-external vcpu_affinity_set : handle -> domid -> int -> int64 -> unit
+external vcpu_affinity_set : handle -> domid -> int -> bool array -> unit
   = "stub_xc_vcpu_setaffinity"
-external vcpu_affinity_get : handle -> domid -> int -> int64
+external vcpu_affinity_get : handle -> domid -> int -> bool array
   = "stub_xc_vcpu_getaffinity"
 external vcpu_context_get : handle -> domid -> int -> string
   = "stub_xc_vcpu_context_get"
@@ -147,16 +145,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit
-  = "stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
-
-external hvm_check_pvdriver : handle -> domid -> bool
-  = "stub_xc_hvm_check_pvdriver"
 external version : handle -> version = "stub_xc_version_version"
 external version_compile_info : handle -> compile_info
   = "stub_xc_version_compile_info"
@@ -185,12 +173,12 @@ external domain_set_machine_address_size
 external domain_get_machine_address_size: handle -> domid -> int
        = "stub_xc_domain_get_machine_address_size"
 
-external domain_cpuid_set: handle -> domid -> bool -> (int64 * (int64 option))
+external domain_cpuid_set: handle -> domid -> (int64 * (int64 option))
                         -> string option array
                         -> string option array
        = "stub_xc_domain_cpuid_set"
-external domain_cpuid_apply: handle -> domid -> bool -> unit
-       = "stub_xc_domain_cpuid_apply"
-external cpuid_check: (int64 * (int64 option)) -> string option array -> (bool * string option array)
+external domain_cpuid_apply_policy: handle -> domid -> unit
+       = "stub_xc_domain_cpuid_apply_policy"
+external cpuid_check: handle -> (int64 * (int64 option)) -> string option array -> (bool * string option array)
        = "stub_xc_cpuid_check"
 
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/xc/xc_cpufeature.h
--- a/tools/ocaml/libs/xc/xc_cpufeature.h	Thu Dec 02 11:35:19 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-#ifndef __LIBXC_CPUFEATURE_H
-#define __LIBXC_CPUFEATURE_H
-
-/* Intel-defined CPU features, CPUID level 0x00000001 (edx), word 0 */
-#define X86_FEATURE_FPU		(0*32+ 0) /* Onboard FPU */
-#define X86_FEATURE_VME		(0*32+ 1) /* Virtual Mode Extensions */
-#define X86_FEATURE_DE		(0*32+ 2) /* Debugging Extensions */
-#define X86_FEATURE_PSE 	(0*32+ 3) /* Page Size Extensions */
-#define X86_FEATURE_TSC		(0*32+ 4) /* Time Stamp Counter */
-#define X86_FEATURE_MSR		(0*32+ 5) /* Model-Specific Registers, RDMSR, WRMSR */
-#define X86_FEATURE_PAE		(0*32+ 6) /* Physical Address Extensions */
-#define X86_FEATURE_MCE		(0*32+ 7) /* Machine Check Architecture */
-#define X86_FEATURE_CX8		(0*32+ 8) /* CMPXCHG8 instruction */
-#define X86_FEATURE_APIC	(0*32+ 9) /* Onboard APIC */
-#define X86_FEATURE_SEP		(0*32+11) /* SYSENTER/SYSEXIT */
-#define X86_FEATURE_MTRR	(0*32+12) /* Memory Type Range Registers */
-#define X86_FEATURE_PGE		(0*32+13) /* Page Global Enable */
-#define X86_FEATURE_MCA		(0*32+14) /* Machine Check Architecture */
-#define X86_FEATURE_CMOV	(0*32+15) /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
-#define X86_FEATURE_PAT		(0*32+16) /* Page Attribute Table */
-#define X86_FEATURE_PSE36	(0*32+17) /* 36-bit PSEs */
-#define X86_FEATURE_PN		(0*32+18) /* Processor serial number */
-#define X86_FEATURE_CLFLSH	(0*32+19) /* Supports the CLFLUSH instruction */
-#define X86_FEATURE_DS		(0*32+21) /* Debug Store */
-#define X86_FEATURE_ACPI	(0*32+22) /* ACPI via MSR */
-#define X86_FEATURE_MMX		(0*32+23) /* Multimedia Extensions */
-#define X86_FEATURE_FXSR	(0*32+24) /* FXSAVE and FXRSTOR instructions (fast save and restore */
-				          /* of FPU context), and CR4.OSFXSR available */
-#define X86_FEATURE_XMM		(0*32+25) /* Streaming SIMD Extensions */
-#define X86_FEATURE_XMM2	(0*32+26) /* Streaming SIMD Extensions-2 */
-#define X86_FEATURE_SELFSNOOP	(0*32+27) /* CPU self snoop */
-#define X86_FEATURE_HT		(0*32+28) /* Hyper-Threading */
-#define X86_FEATURE_ACC		(0*32+29) /* Automatic clock control */
-#define X86_FEATURE_IA64	(0*32+30) /* IA-64 processor */
-#define X86_FEATURE_PBE		(0*32+31) /* Pending Break Enable */
-
-/* AMD-defined CPU features, CPUID level 0x80000001, word 1 */
-/* Don't duplicate feature flags which are redundant with Intel! */
-#define X86_FEATURE_SYSCALL	(1*32+11) /* SYSCALL/SYSRET */
-#define X86_FEATURE_MP		(1*32+19) /* MP Capable. */
-#define X86_FEATURE_NX		(1*32+20) /* Execute Disable */
-#define X86_FEATURE_MMXEXT	(1*32+22) /* AMD MMX extensions */
-#define X86_FEATURE_FFXSR       (1*32+25) /* FFXSR instruction optimizations */
-#define X86_FEATURE_PAGE1GB	(1*32+26) /* 1Gb large page support */
-#define X86_FEATURE_RDTSCP	(1*32+27) /* RDTSCP */
-#define X86_FEATURE_LM		(1*32+29) /* Long Mode (x86-64) */
-#define X86_FEATURE_3DNOWEXT	(1*32+30) /* AMD 3DNow! extensions */
-#define X86_FEATURE_3DNOW	(1*32+31) /* 3DNow! */
-
-/* Transmeta-defined CPU features, CPUID level 0x80860001, word 2 */
-#define X86_FEATURE_RECOVERY	(2*32+ 0) /* CPU in recovery mode */
-#define X86_FEATURE_LONGRUN	(2*32+ 1) /* Longrun power control */
-#define X86_FEATURE_LRTI	(2*32+ 3) /* LongRun table interface */
-
-/* Other features, Linux-defined mapping, word 3 */
-/* This range is used for feature bits which conflict or are synthesized */
-#define X86_FEATURE_CXMMX	(3*32+ 0) /* Cyrix MMX extensions */
-#define X86_FEATURE_K6_MTRR	(3*32+ 1) /* AMD K6 nonstandard MTRRs */
-#define X86_FEATURE_CYRIX_ARR	(3*32+ 2) /* Cyrix ARRs (= MTRRs) */
-#define X86_FEATURE_CENTAUR_MCR	(3*32+ 3) /* Centaur MCRs (= MTRRs) */
-/* cpu types for specific tunings: */
-#define X86_FEATURE_K8		(3*32+ 4) /* Opteron, Athlon64 */
-#define X86_FEATURE_K7		(3*32+ 5) /* Athlon */
-#define X86_FEATURE_P3		(3*32+ 6) /* P3 */
-#define X86_FEATURE_P4		(3*32+ 7) /* P4 */
-#define X86_FEATURE_CONSTANT_TSC (3*32+ 8) /* TSC ticks at a constant rate */
-
-/* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
-#define X86_FEATURE_XMM3	(4*32+ 0) /* Streaming SIMD Extensions-3 */
-#define X86_FEATURE_DTES64	(4*32+ 2) /* 64-bit Debug Store */
-#define X86_FEATURE_MWAIT	(4*32+ 3) /* Monitor/Mwait support */
-#define X86_FEATURE_DSCPL	(4*32+ 4) /* CPL Qualified Debug Store */
-#define X86_FEATURE_VMXE	(4*32+ 5) /* Virtual Machine Extensions */
-#define X86_FEATURE_SMXE	(4*32+ 6) /* Safer Mode Extensions */
-#define X86_FEATURE_EST		(4*32+ 7) /* Enhanced SpeedStep */
-#define X86_FEATURE_TM2		(4*32+ 8) /* Thermal Monitor 2 */
-#define X86_FEATURE_SSSE3	(4*32+ 9) /* Supplemental Streaming SIMD Extensions-3 */
-#define X86_FEATURE_CID		(4*32+10) /* Context ID */
-#define X86_FEATURE_CX16        (4*32+13) /* CMPXCHG16B */
-#define X86_FEATURE_XTPR	(4*32+14) /* Send Task Priority Messages */
-#define X86_FEATURE_PDCM	(4*32+15) /* Perf/Debug Capability MSR */
-#define X86_FEATURE_DCA		(4*32+18) /* Direct Cache Access */
-#define X86_FEATURE_SSE4_1	(4*32+19) /* Streaming SIMD Extensions 4.1 */
-#define X86_FEATURE_SSE4_2	(4*32+20) /* Streaming SIMD Extensions 4.2 */
-#define X86_FEATURE_POPCNT	(4*32+23) /* POPCNT instruction */
-#define X86_FEATURE_HYPERVISOR	(4*32+31) /* Running under some hypervisor */
-
-/* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 */
-#define X86_FEATURE_XSTORE	(5*32+ 2) /* on-CPU RNG present (xstore insn) */
-#define X86_FEATURE_XSTORE_EN	(5*32+ 3) /* on-CPU RNG enabled */
-#define X86_FEATURE_XCRYPT	(5*32+ 6) /* on-CPU crypto (xcrypt insn) */
-#define X86_FEATURE_XCRYPT_EN	(5*32+ 7) /* on-CPU crypto enabled */
-#define X86_FEATURE_ACE2	(5*32+ 8) /* Advanced Cryptography Engine v2 */
-#define X86_FEATURE_ACE2_EN	(5*32+ 9) /* ACE v2 enabled */
-#define X86_FEATURE_PHE		(5*32+ 10) /* PadLock Hash Engine */
-#define X86_FEATURE_PHE_EN	(5*32+ 11) /* PHE enabled */
-#define X86_FEATURE_PMM		(5*32+ 12) /* PadLock Montgomery Multiplier */
-#define X86_FEATURE_PMM_EN	(5*32+ 13) /* PMM enabled */
-
-/* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */
-#define X86_FEATURE_LAHF_LM	(6*32+ 0) /* LAHF/SAHF in long mode */
-#define X86_FEATURE_CMP_LEGACY	(6*32+ 1) /* If yes HyperThreading not valid */
-#define X86_FEATURE_SVME        (6*32+ 2) /* Secure Virtual Machine */
-#define X86_FEATURE_EXTAPICSPACE (6*32+ 3) /* Extended APIC space */
-#define X86_FEATURE_ALTMOVCR	(6*32+ 4) /* LOCK MOV CR accesses CR+8 */
-#define X86_FEATURE_ABM		(6*32+ 5) /* Advanced Bit Manipulation */
-#define X86_FEATURE_SSE4A	(6*32+ 6) /* AMD Streaming SIMD Extensions-4a */
-#define X86_FEATURE_MISALIGNSSE	(6*32+ 7) /* Misaligned SSE Access */
-#define X86_FEATURE_3DNOWPF	(6*32+ 8) /* 3DNow! Prefetch */
-#define X86_FEATURE_OSVW	(6*32+ 9) /* OS Visible Workaround */
-#define X86_FEATURE_IBS		(6*32+ 10) /* Instruction Based Sampling */
-#define X86_FEATURE_SSE5	(6*32+ 11) /* AMD Streaming SIMD Extensions-5 */
-#define X86_FEATURE_SKINIT	(6*32+ 12) /* SKINIT, STGI/CLGI, DEV */
-#define X86_FEATURE_WDT		(6*32+ 13) /* Watchdog Timer */
-
-#endif /* __LIBXC_CPUFEATURE_H */
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/xc/xc_cpuid.h
--- a/tools/ocaml/libs/xc/xc_cpuid.h	Thu Dec 02 11:35:19 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,285 +0,0 @@
-#ifndef XC_CPUID_H
-#define XC_CPUID_H
-
-#ifdef XEN_DOMCTL_set_cpuid
-
-#include "xc_cpufeature.h"
-
-#define bitmaskof(idx)      (1u << ((idx) & 31))
-#define clear_bit(idx, dst) ((dst) &= ~(1u << ((idx) & 31)))
-#define set_bit(idx, dst)   ((dst) |= (1u << ((idx) & 31)))
-
-#define DEF_MAX_BASE 0x00000004u
-#define DEF_MAX_EXT  0x80000008u
-
-static void xc_cpuid(uint32_t eax, uint32_t ecx, uint32_t regs[4])
-{
-	unsigned int realecx = (ecx == XEN_CPUID_INPUT_UNUSED) ? 0 : ecx;
-	asm (
-#ifdef __i386__
-	     "push %%ebx; cpuid; mov %%ebx,%1; pop %%ebx"
-#else
-	     "push %%rbx; cpuid; mov %%ebx,%1; pop %%rbx"
-#endif
-	    : "=a" (regs[0]), "=r" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
-	    : "0" (eax), "2" (realecx));
-}
-
-enum { CPU_BRAND_INTEL, CPU_BRAND_AMD, CPU_BRAND_UNKNOWN };
-
-static int xc_cpuid_brand_get(void)
-{
-	uint32_t regs[4];
-	char str[13];
-	uint32_t *istr = (uint32_t *) str;
-
-	xc_cpuid(0, 0, regs);
-	istr[0] = regs[1];
-	istr[1] = regs[3];
-	istr[2] = regs[2];
-	str[12] = '\0';
-	if      (strcmp(str, "AuthenticAMD") == 0) {
-		return CPU_BRAND_AMD;
-	} else if (strcmp(str, "GenuineIntel") == 0) {
-		return CPU_BRAND_INTEL;
-	} else
-		return CPU_BRAND_UNKNOWN;
-}
-
-static int hypervisor_is_64bit(int xc)
-{
-	xen_capabilities_info_t xen_caps;
-	return ((xc_version(xc, XENVER_capabilities, &xen_caps) == 0) &&
-	        (strstr(xen_caps, "x86_64") != NULL));
-}
-
-static void do_hvm_cpuid_policy(int xc, int domid, uint32_t input, uint32_t regs[4])
-{
-	unsigned long is_pae;
-	int brand;
-
-	/* pae ? */
-	xc_get_hvm_param(xc, domid, HVM_PARAM_PAE_ENABLED, &is_pae);
-	is_pae = !!is_pae;
-
-	switch (input) {
-	case 0x00000000:
-		if (regs[0] > DEF_MAX_BASE)
-			regs[0] = DEF_MAX_BASE;
-		break;
-	case 0x00000001:
-		regs[2] &= (bitmaskof(X86_FEATURE_XMM3) |
-				bitmaskof(X86_FEATURE_SSSE3) |
-				bitmaskof(X86_FEATURE_CX16) |
-				bitmaskof(X86_FEATURE_SSE4_1) |
-				bitmaskof(X86_FEATURE_SSE4_2) |
-				bitmaskof(X86_FEATURE_POPCNT));
-
-                regs[2] |= bitmaskof(X86_FEATURE_HYPERVISOR);
-
-		regs[3] &= (bitmaskof(X86_FEATURE_FPU) |
-				bitmaskof(X86_FEATURE_VME) |
-				bitmaskof(X86_FEATURE_DE) |
-				bitmaskof(X86_FEATURE_PSE) |
-				bitmaskof(X86_FEATURE_TSC) |
-				bitmaskof(X86_FEATURE_MSR) |
-				bitmaskof(X86_FEATURE_PAE) |
-				bitmaskof(X86_FEATURE_MCE) |
-				bitmaskof(X86_FEATURE_CX8) |
-				bitmaskof(X86_FEATURE_APIC) |
-				bitmaskof(X86_FEATURE_SEP) |
-				bitmaskof(X86_FEATURE_MTRR) |
-				bitmaskof(X86_FEATURE_PGE) |
-				bitmaskof(X86_FEATURE_MCA) |
-				bitmaskof(X86_FEATURE_CMOV) |
-				bitmaskof(X86_FEATURE_PAT) |
-				bitmaskof(X86_FEATURE_CLFLSH) |
-				bitmaskof(X86_FEATURE_MMX) |
-				bitmaskof(X86_FEATURE_FXSR) |
-				bitmaskof(X86_FEATURE_XMM) |
-				bitmaskof(X86_FEATURE_XMM2));
-		/* We always support MTRR MSRs. */
-		regs[3] |= bitmaskof(X86_FEATURE_MTRR);
-
-		if (!is_pae)
-			clear_bit(X86_FEATURE_PAE, regs[3]);
-		break;
-	case 0x80000000:
-		if (regs[0] > DEF_MAX_EXT)
-			regs[0] = DEF_MAX_EXT;
-		break;
-	case 0x80000001:
-		if (!is_pae)
-			clear_bit(X86_FEATURE_NX, regs[3]);
-		break;
-	case 0x80000008:
-		regs[0] &= 0x0000ffffu;
-		regs[1] = regs[2] = regs[3] = 0;
-		break;
-	case 0x00000002: /* Intel cache info (dumped by AMD policy) */
-	case 0x00000004: /* Intel cache info (dumped by AMD policy) */
-	case 0x80000002: /* Processor name string */
-	case 0x80000003: /* ... continued         */
-	case 0x80000004: /* ... continued         */
-	case 0x80000005: /* AMD L1 cache/TLB info (dumped by Intel policy) */
-	case 0x80000006: /* AMD L2/3 cache/TLB info ; Intel L2 cache features */
-		break;
-	default:
-		regs[0] = regs[1] = regs[2] = regs[3] = 0;
-		break;
-	}
-	
-	brand = xc_cpuid_brand_get();
-	if (brand == CPU_BRAND_AMD) {
-		switch (input) {
-		case 0x00000001:
-			/* Mask Intel-only features. */
-			regs[2] &= ~(bitmaskof(X86_FEATURE_SSSE3) |
-					bitmaskof(X86_FEATURE_SSE4_1) |
-					bitmaskof(X86_FEATURE_SSE4_2));
-			break;
-
-		case 0x00000002:
-		case 0x00000004:
-			regs[0] = regs[1] = regs[2] = 0;
-			break;
-
-		case 0x80000001: {
-			int is_64bit = hypervisor_is_64bit(xc) && is_pae;
-
-			if (!is_pae)
-				 clear_bit(X86_FEATURE_PAE, regs[3]);
-			clear_bit(X86_FEATURE_PSE36, regs[3]);
-
-			/* Filter all other features according to a whitelist. */
-			regs[2] &= ((is_64bit ? bitmaskof(X86_FEATURE_LAHF_LM) : 0) |
-					 bitmaskof(X86_FEATURE_ALTMOVCR) |
-					 bitmaskof(X86_FEATURE_ABM) |
-					 bitmaskof(X86_FEATURE_SSE4A) |
-					 bitmaskof(X86_FEATURE_MISALIGNSSE) |
-					 bitmaskof(X86_FEATURE_3DNOWPF));
-			regs[3] &= (0x0183f3ff | /* features shared with 0x00000001:EDX */
-					 (is_pae ? bitmaskof(X86_FEATURE_NX) : 0) |
-					 (is_64bit ? bitmaskof(X86_FEATURE_LM) : 0) |
-					 bitmaskof(X86_FEATURE_SYSCALL) |
-					 bitmaskof(X86_FEATURE_MP) |
-					 bitmaskof(X86_FEATURE_MMXEXT) |
-					 bitmaskof(X86_FEATURE_FFXSR) |
-					 bitmaskof(X86_FEATURE_3DNOW) |
-					 bitmaskof(X86_FEATURE_3DNOWEXT));
-			break;
-			}
-		}
-	} else if (brand == CPU_BRAND_INTEL) {
-		switch (input) {
-		case 0x00000001:
-			/* Mask AMD-only features. */
-			regs[2] &= ~(bitmaskof(X86_FEATURE_POPCNT));
-			break;
-
-		case 0x00000004:
-			regs[0] &= 0x3FF;
-			regs[3] &= 0x3FF;
-			break;
-
-		case 0x80000001:
-			{
-			int is_64bit = hypervisor_is_64bit(xc) && is_pae;
-
-			/* Only a few features are advertised in Intel's 0x80000001. */
-			regs[2] &= (is_64bit ? bitmaskof(X86_FEATURE_LAHF_LM) : 0);
-			regs[3] &= ((is_pae ? bitmaskof(X86_FEATURE_NX) : 0) |
-					(is_64bit ? bitmaskof(X86_FEATURE_LM) : 0) |
-					(is_64bit ? bitmaskof(X86_FEATURE_SYSCALL) : 0));
-			break;
-			}
-		case 0x80000005:
-			{
-			regs[0] = regs[1] = regs[2] = 0;
-			break;
-			}
-		}
-	}
-}
-
-static void do_pv_cpuid_policy(int xc, int domid, uint32_t input, uint32_t regs[4])
-{
-	int brand;
-	int guest_64_bits, xen_64_bits;
-	int ret;
-	
-	ret = xc_domain_get_machine_address_size(xc, domid);
-	if (ret < 0)
-		return;
-	guest_64_bits = (ret == 64);
-	xen_64_bits = hypervisor_is_64bit(xc);
-	brand = xc_cpuid_brand_get();
-
-	if ((input & 0x7fffffff) == 1) {
-		clear_bit(X86_FEATURE_VME, regs[3]);
-		clear_bit(X86_FEATURE_PSE, regs[3]);
-		clear_bit(X86_FEATURE_PGE, regs[3]);
-		clear_bit(X86_FEATURE_MCE, regs[3]);
-		clear_bit(X86_FEATURE_MCA, regs[3]);
-		clear_bit(X86_FEATURE_MTRR, regs[3]);
-		clear_bit(X86_FEATURE_PSE36, regs[3]);
-	}
-
-	switch (input) {
-	case 1:
-		if (!xen_64_bits || brand == CPU_BRAND_AMD)
-			clear_bit(X86_FEATURE_SEP, regs[3]);
-		clear_bit(X86_FEATURE_DS, regs[3]);
-		clear_bit(X86_FEATURE_ACC, regs[3]);
-		clear_bit(X86_FEATURE_PBE, regs[3]);
-
-		clear_bit(X86_FEATURE_DTES64, regs[2]);
-		clear_bit(X86_FEATURE_MWAIT, regs[2]);
-		clear_bit(X86_FEATURE_DSCPL, regs[2]);
-		clear_bit(X86_FEATURE_VMXE, regs[2]);
-		clear_bit(X86_FEATURE_SMXE, regs[2]);
-		clear_bit(X86_FEATURE_EST, regs[2]);
-		clear_bit(X86_FEATURE_TM2, regs[2]);
-		if (!guest_64_bits)
-			clear_bit(X86_FEATURE_CX16, regs[2]);
-		clear_bit(X86_FEATURE_XTPR, regs[2]);
-		clear_bit(X86_FEATURE_PDCM, regs[2]);
-		clear_bit(X86_FEATURE_DCA, regs[2]);
-		break;
-	case 0x80000001:
-		if (!guest_64_bits) {
-			clear_bit(X86_FEATURE_LM, regs[3]);
-			clear_bit(X86_FEATURE_LAHF_LM, regs[2]);
-			if (brand != CPU_BRAND_AMD)
-				clear_bit(X86_FEATURE_SYSCALL, regs[3]);
-		} else
-			set_bit(X86_FEATURE_SYSCALL, regs[3]);
-		clear_bit(X86_FEATURE_PAGE1GB, regs[3]);
-		clear_bit(X86_FEATURE_RDTSCP, regs[3]);
-
-		clear_bit(X86_FEATURE_SVME, regs[2]);
-		clear_bit(X86_FEATURE_OSVW, regs[2]);
-		clear_bit(X86_FEATURE_IBS, regs[2]);
-		clear_bit(X86_FEATURE_SKINIT, regs[2]);
-		clear_bit(X86_FEATURE_WDT, regs[2]);
-		break;
-	case 5: /* MONITOR/MWAIT */
-	case 0xa: /* Architectural Performance Monitor Features */
-	case 0x8000000a: /* SVM revision and features */
-	case 0x8000001b: /* Instruction Based Sampling */
-		regs[0] = regs[1] = regs[2] = regs[3] = 0;
-		break;
-	}
-}
-
-static void do_cpuid_policy(int xc, int domid, int hvm, uint32_t input, uint32_t regs[4])
-{
-	if (hvm)
-		do_hvm_cpuid_policy(xc, domid, input, regs);
-	else
-		do_pv_cpuid_policy(xc, domid, input, regs);
-}
-
-#endif
-
-#endif
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/xc/xc_e820.h
--- a/tools/ocaml/libs/xc/xc_e820.h	Thu Dec 02 11:35:19 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#ifndef __XC_E820_H__
-#define __XC_E820_H__
-
-#include <xen/hvm/e820.h>
-
-/*
- * PC BIOS standard E820 types and structure.
- */
-#define E820_RAM          1
-#define E820_RESERVED     2
-#define E820_ACPI         3
-#define E820_NVS          4
-
-struct e820entry {
-    uint64_t addr;
-    uint64_t size;
-    uint32_t type;
-} __attribute__((packed));
-
-#endif /* __XC_E820_H__ */
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/xc/xc_lib.c
--- a/tools/ocaml/libs/xc/xc_lib.c	Thu Dec 02 11:35:19 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1537 +0,0 @@
-/*
- * Copyright (C) 2006-2007 XenSource Ltd.
- * Copyright (C) 2008      Citrix Ltd.
- * Author Vincent Hanquez <vincent.hanquez-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; version 2.1 only. with the special
- * exception on linking described in file LICENSE.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- */
-
-#include <stdint.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-#include "xc.h"
-
-#define PAGE_SHIFT		12
-#define PAGE_SIZE               (1UL << PAGE_SHIFT)
-#define PAGE_MASK               (~(PAGE_SIZE-1))
-
-#define MIN(a, b) 		(((a) < (b)) ? (a) : (b))
-
-#define DECLARE_DOMCTL(_cmd, _domain)	\
-	struct xen_domctl domctl = {    \
-		.cmd = _cmd,		\
-		.domain = _domain,	\
-		.interface_version = XEN_DOMCTL_INTERFACE_VERSION, \
-	}
-
-#define DECLARE_SYSCTL(_cmd)		\
-	struct xen_sysctl sysctl = {	\
-		.cmd = _cmd,		\
-		.interface_version = XEN_SYSCTL_INTERFACE_VERSION, \
-	}
-
-#define DECLARE_HYPERCALL2(_cmd, _arg0, _arg1)	\
-	privcmd_hypercall_t hypercall = {	\
-		.op = _cmd,			\
-		.arg[0] = (unsigned long) _arg0,\
-		.arg[1] = (unsigned long) _arg1,\
-	}
-#define DECLARE_HYPERCALL0(_cmd)	DECLARE_HYPERCALL2(_cmd, 0, 0);
-#define DECLARE_HYPERCALL1(_cmd, _arg0)	DECLARE_HYPERCALL2(_cmd, _arg0, 0);
-
-/*---- Errors handlings ----*/
-#ifndef WITHOUT_GOOD_ERROR
-#define ERROR_STRLEN 256
-
-static char __error_str[ERROR_STRLEN];
-
-char * xc_error_get(void)
-{
-	return __error_str;
-}
-
-static void xc_error_set(const char *fmt, ...)
-{
-	va_list ap;
-	char __errordup[ERROR_STRLEN];
-
-	va_start(ap, fmt);
-	vsnprintf(__errordup, ERROR_STRLEN, fmt, ap);
-	va_end(ap);
-	memcpy(__error_str, __errordup, ERROR_STRLEN);
-}
-
-static void xc_error_dom_set(unsigned int domid, const char *fmt, ...)
-{
-	va_list ap;
-	char __errordup[ERROR_STRLEN];
-	int i;
-
-	i = snprintf(__errordup, ERROR_STRLEN, "domain %u - ", domid);
-	va_start(ap, fmt);
-	i += vsnprintf(__errordup + i, ERROR_STRLEN - i, fmt, ap);
-	va_end(ap);
-	snprintf(__errordup + i, ERROR_STRLEN - i,
-	         " failed: %s", xc_error_get());
-	memcpy(__error_str, __errordup, ERROR_STRLEN);
-}
-
-void xc_error_clear(void)
-{
-	memset(__error_str, '\0', ERROR_STRLEN);
-}
-#else
-char * xc_error_get(void)
-{
-	return "";
-}
-#define xc_error_set(fmt, ...) do {} while (0)
-#define xc_error_dom_set(id, fmt, ...) do {} while (0)
-#define xc_error_clear() do {} while (0)
-#endif
-
-#define xc_error_hypercall(_h, _r) \
-	xc_error_set("hypercall %lld fail: %d: %s (ret %d)", _h.op, errno, errno ? strerror(errno) : strerror(-_r), _r)
-
-int xc_using_injection(void)
-{
-	return 0;
-}
-
-/*---- Trivia ----*/
-int xc_interface_open(void)
-{
-	int fd, ret;
-
-	fd = open("/proc/xen/privcmd", O_RDWR);
-	if (fd == -1) {
-		xc_error_set("open /proc/xen/privcmd failed: %s",
-		             strerror(errno));
-		return -1;
-	}
-
-	ret = fcntl(fd, F_GETFD);
-	if (ret < 0) {
-		xc_error_set("cannot get handle flags: %s",
-		             strerror(errno));
-		goto out;
-	}
-
-	ret = fcntl(fd, F_SETFD, ret | FD_CLOEXEC);
-	if (ret < 0) {
-		xc_error_set("cannot set handle flags: %s",
-		             strerror(errno));
-		goto out;
-	}
-
-	return fd;
-out:
-	close(fd);
-	return -1;
-}
-
-int xc_interface_close(int handle)
-{
-	int ret;
-
-	ret = close(handle);
-	if (ret != 0)
-		xc_error_set("close xc failed: %s", strerror(errno));
-	return ret;
-}
-
-/*---- Low private operations ----*/
-static int do_xen_hypercall(int handle, privcmd_hypercall_t *hypercall)
-{
-	return ioctl(handle, IOCTL_PRIVCMD_HYPERCALL, (unsigned long) hypercall);
-}
-
-static int do_domctl(int handle, struct xen_domctl *domctl)
-{
-	int ret;
-	DECLARE_HYPERCALL1(__HYPERVISOR_domctl, domctl);
-
-	if (mlock(domctl, sizeof(*domctl)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0)
-		xc_error_hypercall(hypercall, ret);
-
-	munlock(domctl, sizeof(*domctl));
-	return ret;
-}
-
-static int do_sysctl(int handle, struct xen_sysctl *sysctl)
-{
-	int ret;
-	DECLARE_HYPERCALL1(__HYPERVISOR_sysctl, sysctl);
-
-	if (mlock(sysctl, sizeof(*sysctl)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0)
-		xc_error_hypercall(hypercall, ret);
-
-	munlock(sysctl, sizeof(*sysctl));
-	return ret;
-}
-
-static int do_evtchnctl(int handle, int cmd, void *arg, size_t arg_size)
-{
-	DECLARE_HYPERCALL2(__HYPERVISOR_event_channel_op, cmd, arg);
-	int ret;
-
-	if (mlock(arg, arg_size) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0)
-		xc_error_hypercall(hypercall, ret);
-	munlock(arg, arg_size);
-	return ret;
-}
-
-static int do_memctl_reservation(int handle, int cmd,
-                                 struct xen_memory_reservation *reservation)
-{
-	int ret;
-	DECLARE_HYPERCALL2(__HYPERVISOR_memory_op, cmd, reservation);
-	xen_pfn_t *extent_start;
-
-	if (cmd != XENMEM_increase_reservation &&
-	    cmd != XENMEM_decrease_reservation &&
-	    cmd != XENMEM_populate_physmap) {
-		xc_error_set("do_memctl_reservation: unknown cmd %d", cmd);
-		return -EINVAL;
-	}
-
-	if (mlock(reservation, sizeof(*reservation)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -ENOMEM;
-	}
-	get_xen_guest_handle(extent_start, reservation->extent_start);
-	if (extent_start && mlock(extent_start, reservation->nr_extents
-	                                      * sizeof(xen_pfn_t)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		munlock(reservation, sizeof(*reservation));
-		return -3;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-	munlock(extent_start, reservation->nr_extents * sizeof(xen_pfn_t));
-	get_xen_guest_handle(extent_start, reservation->extent_start);
-	munlock(reservation, sizeof(*reservation));
-	return ret;
-}
-
-static int do_ioctl(int handle, int cmd, void *arg)
-{
-	return ioctl(handle, cmd, arg);
-}
-
-static void * do_mmap(void *start, size_t length, int prot, int flags,
-                      int fd, off_t offset)
-{
-	return mmap(start, length, prot, flags, fd, offset);
-}
-
-int xc_get_hvm_param(int handle, unsigned int domid,
-                     int param, unsigned long *value)
-{
-	struct xen_hvm_param arg = {
-		.domid = domid,
-		.index = param,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_get_param,
-	                   (unsigned long) &arg);
-	int ret;
-
-	if (mlock(&arg, sizeof(arg)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-	*value = arg.value;
-	munlock(&arg, sizeof(arg));
-	return ret;
-}
-
-static int xc_set_hvm_param(int handle, unsigned int domid,
-                            int param, unsigned long value)
-{
-	struct xen_hvm_param arg = {
-		.domid = domid,
-		.index = param,
-		.value = value,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_set_param, (unsigned long) &arg);
-	int ret;
-
-	if (mlock(&arg, sizeof(arg)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-	munlock(&arg, sizeof(arg));
-	return ret;
-}
-
-
-/*---- XC API ----*/
-int xc_domain_create(int handle, unsigned int ssidref,
-                     xen_domain_handle_t dhandle,
-                     unsigned int flags, unsigned int *pdomid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_createdomain, *pdomid);
-	domctl.u.createdomain.ssidref = ssidref;
-	domctl.u.createdomain.flags = flags;
-	memcpy(domctl.u.createdomain.handle, dhandle, sizeof(xen_domain_handle_t));
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0) {
-		xc_error_set("creating domain failed: %s", xc_error_get());
-		return ret;
-	}
-	*pdomid = domctl.domain;
-	return 0;
-}
-
-int xc_domain_pause(int handle, unsigned int domid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_pausedomain, domid);
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_dom_set(domid, "pause");
-	return ret;
-}
-
-int xc_domain_unpause(int handle, unsigned int domid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_unpausedomain, domid);
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_dom_set(domid, "unpause");
-	return ret;
-}
-
-/* return 1 if hvm domain got pv driver, 0 if not. -1 is error occurs */
-int xc_hvm_check_pvdriver(int handle, unsigned int domid)
-{
-	int ret;
-	unsigned long irq = 0;
-	xc_domaininfo_t info;
-
-	ret = xc_domain_getinfolist(handle, domid, 1, &info);
-	if (ret != 1) {
-		xc_error_set("domain getinfo failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "hvm_check_pvdriver");
-		return -1;
-	}
-
-	if (!(info.flags & XEN_DOMINF_hvm_guest)) {
-		xc_error_set("domain is not hvm");
-		xc_error_dom_set(domid, "hvm_check_pvdriver");
-		return -1;
-	}
-	xc_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
-	return irq;
-}
-
-static int modify_returncode_register(int handle, unsigned int domid)
-{
-	int ret;
-	xc_domaininfo_t info;
-	xen_capabilities_info_t caps;
-	vcpu_guest_context_any_t context;
-
-	ret = xc_domain_getinfolist(handle, domid, 1, &info);
-	if (ret != 1) {
-		xc_error_set("domain getinfo failed: %s", strerror(errno));
-		return -1;
-	}
-
-	/* HVM guests without PV drivers do not have a return code to modify */
-	if (info.flags & XEN_DOMINF_hvm_guest) {
-		unsigned long irq = 0;
-		xc_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
-		if (!irq)
-			return 0;
-	}
-
-	ret = xc_version(handle, XENVER_capabilities, &caps);
-	if (ret) {
-		xc_error_set("could not get Xen capabilities");
-		return ret;
-	}
-
-	ret = xc_vcpu_getcontext(handle, domid, 0, &context);
-	if (ret) {
-		xc_error_set("could not get vcpu 0 context");
-		return ret;
-	}
-
-	if (!(info.flags & XEN_DOMINF_hvm_guest))
-		context.c.user_regs.eax = 1;
-	else if (strstr(caps, "x86_64"))
-		context.x64.user_regs.eax = 1;
-	else
-		context.x32.user_regs.eax = 1;
-
-	ret = xc_vcpu_setcontext(handle, domid, 0, &context);
-	if (ret) {
-		xc_error_set("could not set vcpu 0 context");
-		return ret;
-	}
-	return 0;
-}
-
-int xc_domain_resume_fast(int handle, unsigned int domid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_resumedomain, domid);
-
-	ret = modify_returncode_register(handle, domid);
-	if (ret != 0) {
-		xc_error_dom_set(domid, "resume_fast");
-		return ret;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_dom_set(domid, "resume_fast");
-	return ret;
-}
-
-int xc_domain_destroy(int handle, unsigned int domid)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_destroydomain, domid);
-
-	do {
-		ret = do_domctl(handle, &domctl);
-	} while (ret && (errno == EAGAIN));
-	if (ret != 0)
-		xc_error_dom_set(domid, "destroy");
-	return ret;
-}
-
-int xc_domain_shutdown(int handle, int domid, int reason)
-{
-	sched_remote_shutdown_t arg = {
-		.domain_id = domid,
-		.reason = reason,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_sched_op, SCHEDOP_remote_shutdown, &arg);
-	int ret;
-
-	if (mlock(&arg, sizeof(arg)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "shutdown %d", reason);
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0) {
-		xc_error_hypercall(hypercall, ret);
-		xc_error_dom_set(domid, "shutdown %d", reason);
-	}
-	munlock(&arg, sizeof(arg));
-	return ret;
-}
-
-static void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits)
-{
-    uint64_t l;
-    int i, j, b;
-
-    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
-        l = lp[i];
-        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
-            bp[b+j] = l;
-            l >>= 8;
-            nbits -= 8;
-        }
-    }
-}
-
-static void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits)
-{
-    uint64_t l;
-    int i, j, b;
-
-    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
-        l = 0;
-        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
-            l |= (uint64_t)bp[b+j] << (j*8);
-            nbits -= 8;
-        }
-        lp[i] = l;
-    }
-}
-
-int xc_vcpu_setaffinity(int handle, unsigned int domid, int vcpu,
-                        uint64_t cpumap)
-{
-	int ret;
-	uint8_t local[sizeof(cpumap)];
-	DECLARE_DOMCTL(XEN_DOMCTL_setvcpuaffinity, domid);
-	domctl.u.vcpuaffinity.vcpu = vcpu;
-	domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
-
-	bitmap_64_to_byte(local, &cpumap, sizeof(cpumap)*8);
-	set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
-
-	if (mlock(&cpumap, sizeof(cpumap)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "vcpu %d set affinity", vcpu);
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "vcpu %d set affinity", vcpu);
-	munlock(&cpumap, sizeof(cpumap));
-	return ret;
-}
-
-int xc_vcpu_getaffinity(int handle, unsigned int domid, int vcpu,
-                        uint64_t *cpumap)
-{
-	int ret;
-	uint8_t local[sizeof(*cpumap)];
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpuaffinity, domid);
-	domctl.u.vcpuaffinity.vcpu = vcpu;
-	domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
-
-	set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
-
-	if (mlock(cpumap, sizeof(*cpumap)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "vcpu %d get affinity", vcpu);
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "vcpu %d get affinity", vcpu);
-	munlock(cpumap, sizeof(*cpumap));
-	bitmap_byte_to_64(cpumap, local, sizeof(*cpumap) * 8);
-	return ret;
-}
-
-int xc_vcpu_context_get(int handle, unsigned int domid, unsigned short vcpu,
-                        struct vcpu_guest_context *ctxt)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpucontext, domid);
-	domctl.u.vcpucontext.vcpu = vcpu;
-
-	set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
-
-	if (mlock(ctxt, sizeof(struct vcpu_guest_context)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "vcpu %d get context", vcpu);
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "vcpu %d get context", vcpu);
-	munlock(ctxt, sizeof(struct vcpu_guest_context));
-
-	return ret;
-}
-
-int xc_domain_getinfolist(int handle, unsigned int first_domain,
-                          unsigned int max_domains, xc_domaininfo_t *info)
-{
-	int ret;
-	DECLARE_SYSCTL(XEN_SYSCTL_getdomaininfolist);
-	sysctl.u.getdomaininfolist.first_domain = first_domain;
-	sysctl.u.getdomaininfolist.max_domains = max_domains;
-	set_xen_guest_handle(sysctl.u.getdomaininfolist.buffer, info);
-
-	if (mlock(info, max_domains * sizeof(xc_domaininfo_t)) != 0) {
-		xc_error_set("getinfolist(%d, %u, %u, %x (%d)) failed: mlock failed: %s",
-			     handle, first_domain, max_domains, info, sizeof(xc_domaininfo_t),
-		             strerror(errno));
-		return -1;
-	}
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret < 0)
-		xc_error_set("getinfolist(%d, %u, %u, %x (%d)) failed: %s", 
-			     handle, first_domain, max_domains, info, sizeof(xc_domaininfo_t),
-			     xc_error_get());
-	else
-		ret = sysctl.u.getdomaininfolist.num_domains;
-
-	munlock(info, max_domains * sizeof(xc_domaininfo_t));
-	return ret;
-}
-
-int xc_domain_getinfo(int handle, unsigned int domid, xc_domaininfo_t *info)
-{
-	int ret;
-	ret = xc_domain_getinfolist(handle, domid, 1, info);
-	if (ret != 1) {
-		xc_error_set("getinfo failed: domain %d: %s", domid, xc_error_get());
-		return -1;
-	}
-
-	/* If the requested domain didn't exist but there exists one with a 
-	   higher domain ID, this will be returned. We consider this an error since
-	   we only wanted info about a specific domain. */
-	if (info->domain != domid) {
-		xc_error_set("getinfo failed: domain %d nolonger exists", domid);
-		return -1;
-	}
-
-	return 0;
-}
-
-int xc_domain_setmaxmem(int handle, unsigned int domid, unsigned int max_memkb)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_max_mem, domid);
-	domctl.u.max_mem.max_memkb = max_memkb;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "set max memory to %u", max_memkb);
-	return ret;
-}
-
-int xc_domain_set_memmap_limit(int handle, unsigned int domid,
-                               unsigned long map_limitkb)
-{
-	int ret;
-	struct xen_foreign_memory_map fmap = {
-		.domid = domid,
-		.map = { .nr_entries = 1 }
-	};
-	struct e820entry e820 = {
-		.addr = 0,
-		.size = (uint64_t)map_limitkb << 10,
-		.type = E820_RAM
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_memory_op, XENMEM_set_memory_map, &fmap);
-
-	set_xen_guest_handle(fmap.map.buffer, &e820);
-
-	if (mlock(&fmap, sizeof(fmap)) != 0) {
-		xc_error_set("set_memmap_limit failed: mlock failed: %s",
-		             strerror(errno));
-		return -1;
-	}
-
-	if (mlock(&e820, sizeof(e820)) != 0) {
-		xc_error_set("set_memmap_limit failed: mlock failed: %s",
-		             strerror(errno));
-		munlock(&fmap, sizeof(fmap));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-
-	munlock(&e820, sizeof(e820));
-	munlock(&fmap, sizeof(fmap));
-	return ret;
-}
-
-int xc_domain_set_time_offset(int handle, unsigned int domid, int time_offset)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_settimeoffset, domid);
-	domctl.u.settimeoffset.time_offset_seconds = time_offset;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "set time offset %d", time_offset);
-	return ret;
-}
-
-int xc_domain_memory_increase_reservation(int handle, unsigned int domid,
-                                          unsigned long nr_extents,
-                                          unsigned int extent_order,
-                                          unsigned int address_bits,
-                                          xen_pfn_t *extent_start)
-{
-	int ret;
-	struct xen_memory_reservation reservation = {
-		.nr_extents   = nr_extents,
-		.extent_order = extent_order,
-		.COMPAT_FIELD_ADDRESS_BITS = address_bits,
-		.domid        = domid
-	};
-
-	set_xen_guest_handle(reservation.extent_start, extent_start);
-
-	ret = do_memctl_reservation(handle, XENMEM_increase_reservation,
-	                            &reservation);
-	if (ret != nr_extents) {
-		xc_error_dom_set(domid, "increase reservation to %lu",
-		                 nr_extents);
-		return (ret >= 0) ? -1 : ret;
-	}
-	return 0;
-}
-
-int xc_domain_memory_decrease_reservation(int handle, unsigned int domid,
-                                          unsigned long nr_extents,
-                                          unsigned int extent_order,
-                                          unsigned int address_bits,
-                                          xen_pfn_t *extent_start)
-{
-	int ret;
-	struct xen_memory_reservation reservation = {
-		.nr_extents   = nr_extents,
-		.extent_order = extent_order,
-		.COMPAT_FIELD_ADDRESS_BITS = 0,
-		.domid        = domid
-	};
-
-	set_xen_guest_handle(reservation.extent_start, extent_start);
-	if (!extent_start) {
-		xc_error_set("decrease reservation: extent start is NULL");
-		return -EINVAL;
-	}
-
-	ret = do_memctl_reservation(handle, XENMEM_decrease_reservation,
-	                            &reservation);
-	if (ret < nr_extents) {
-		xc_error_dom_set(domid, "decrease reservation to %lu",
-		                 nr_extents);
-		return (ret >= 0) ? -1 : ret;
-	}
-	return 0;
-}
-
-int xc_domain_memory_populate_physmap(int handle, unsigned int domid,
-                                      unsigned long nr_extents,
-                                      unsigned int extent_order,
-                                      unsigned int address_bits,
-                                      xen_pfn_t *extent_start)
-{
-	int ret;
-	struct xen_memory_reservation reservation = {
-		.nr_extents   = nr_extents,
-		.extent_order = extent_order,
-		.COMPAT_FIELD_ADDRESS_BITS = address_bits,
-		.domid        = domid
-	};
-
-	set_xen_guest_handle(reservation.extent_start, extent_start);
-	ret = do_memctl_reservation(handle, XENMEM_populate_physmap,
-	                            &reservation);
-	if (ret < nr_extents) {
-		xc_error_dom_set(domid, "populate physmap");
-		return (ret >= 0) ? -1 : ret;
-	}
-	return 0;
-}
-
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist)
-{
-	int ret = 0;
-#ifdef XEN_DOMCTL_setvmxassist
-	DECLARE_DOMCTL(XEN_DOMCTL_setvmxassist, domid);
-	domctl.u.setvmxassist.use_vmxassist = use_vmxassist;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "setting vmxassist to %d",
-				 use_vmxassist);
-#endif
-	return ret;
-}
-
-int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_max_vcpus, domid);
-	domctl.u.max_vcpus.max = max;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "setting max vcpus to %d", max);
-	return ret;
-}
-
-int xc_domain_sethandle(int handle, unsigned int domid,
-                        xen_domain_handle_t dhandle)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_setdomainhandle, domid);
-	memcpy(domctl.u.setdomainhandle.handle, dhandle, sizeof(xen_domain_handle_t));
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "set handle");
-	return ret;
-}
-
-int xc_vcpu_getinfo(int handle, unsigned int domid, unsigned int vcpu,
-                    xc_vcpuinfo_t *info)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpuinfo, domid);
-	domctl.u.getvcpuinfo.vcpu = vcpu;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0) {
-		xc_error_dom_set(domid, "vcpu %u getinfo", vcpu);
-		return ret;
-	}
-	memcpy(info, &domctl.u.getvcpuinfo, sizeof(*info));
-	return ret;
-}
-
-int xc_domain_ioport_permission(int handle, unsigned int domid,
-                                unsigned int first_port, unsigned int nr_ports,
-                                unsigned int allow_access)
-{
-	DECLARE_DOMCTL(XEN_DOMCTL_ioport_permission, domid);
-	domctl.u.ioport_permission.first_port = first_port;
-	domctl.u.ioport_permission.nr_ports = nr_ports;
-	domctl.u.ioport_permission.allow_access = allow_access;
-
-	return do_domctl(handle, &domctl);
-}
-
-int xc_vcpu_getcontext(int handle, unsigned int domid,
-                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpucontext, domid);
-	domctl.u.vcpucontext.vcpu = vcpu;
-	set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt->c);
-
-	if (mlock(ctxt, sizeof(*ctxt)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "vcpu %u getcontext", vcpu);
-	munlock(ctxt, sizeof(*ctxt));
-	return ret;
-}
-
-int xc_vcpu_setcontext(int handle, unsigned int domid,
-                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_setvcpucontext, domid);
-	domctl.u.vcpucontext.vcpu = vcpu;
-	set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt->c);
-
-	if (mlock(ctxt, sizeof(*ctxt)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "vcpu %u setcontext", vcpu);
-
-	munlock(ctxt, sizeof(*ctxt));
-	return ret;
-}
-
-int xc_domain_irq_permission(int handle, unsigned int domid,
-                             unsigned char pirq, unsigned char allow_access)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_irq_permission, domid);
-	domctl.u.irq_permission.pirq = pirq;
-	domctl.u.irq_permission.allow_access = allow_access;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "irq permission %u to %u",
-		                 pirq, allow_access);
-	return ret;
-}
-
-int xc_domain_iomem_permission(int handle, unsigned int domid,
-                               unsigned long first_mfn, unsigned long nr_mfns,
-                               unsigned char allow_access)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_iomem_permission, domid);
-	domctl.u.iomem_permission.first_mfn = first_mfn;
-	domctl.u.iomem_permission.nr_mfns = nr_mfns;
-	domctl.u.iomem_permission.allow_access = allow_access;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "iomem permission [%lu, %lu] to %u",
-		                 first_mfn, first_mfn + nr_mfns, allow_access);
-	return ret;
-}
-
-long long xc_domain_get_cpu_usage(int handle, unsigned int domid,
-                                  unsigned int vcpu)
-{
-	DECLARE_DOMCTL(XEN_DOMCTL_getvcpuinfo, domid);
-	domctl.u.getvcpuinfo.vcpu = vcpu;
-
-	if (do_domctl(handle, &domctl) < 0) {
-		xc_error_dom_set(domid, "get cpu %d usage", vcpu);
-		return -1;
-	}
-	return domctl.u.getvcpuinfo.cpu_time;
-}
-
-void *xc_map_foreign_range(int handle, unsigned int domid,
-                           int size, int prot, unsigned long mfn)
-{
-	privcmd_mmap_entry_t entry = {
-		.mfn = mfn,
-		.npages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT,
-	};
-	privcmd_mmap_t ioctlx = {
-		.num = 1,
-		.dom = domid,
-		.entry = &entry,
-	};
-	void *addr;
-
-	addr = do_mmap(NULL, size, prot, MAP_SHARED, handle, 0);
-	if (addr == MAP_FAILED) {
-		xc_error_set("mmap failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "map foreign range [%lx,%lx] prot %u",
-		                 mfn, mfn + size, prot);
-		return NULL;
-	}
-	entry.va = (unsigned long) addr;
-	if (do_ioctl(handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0) {
-		xc_error_set("ioctl failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "map foreign range [%lx,%lx] prot %u",
-		                 mfn, mfn + size, prot);
-		munmap(addr, size);
-		return NULL;
-	}
-	return addr;
-}
-
-int xc_map_foreign_ranges(int handle, unsigned int domid,
-                          privcmd_mmap_entry_t *entries, int nr)
-{
-	privcmd_mmap_t ioctlx = {
-		.num = nr,
-		.dom = domid,
-		.entry = entries,
-	};
-	int ret;
-
-	ret = do_ioctl(handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
-	if (ret < 0) {
-		xc_error_set("ioctl failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "map foreign ranges");
-		return -1;
-	}
-	return ret;
-}
-
-int xc_readconsolering(int handle, char **pbuffer,
-                       unsigned int *pnr_chars, int clear)
-{
-	int ret;
-	DECLARE_SYSCTL(XEN_SYSCTL_readconsole);
-	char *buffer = *pbuffer;
-	unsigned int nr_chars = *pnr_chars;
-
-	set_xen_guest_handle(sysctl.u.readconsole.buffer, buffer);
-	sysctl.u.readconsole.count = nr_chars;
-	sysctl.u.readconsole.clear = clear;
-
-	if (mlock(buffer, nr_chars) != 0) {
-		xc_error_set("read console ring: mlock failed: %s",
-		             strerror(errno));
-		return -1;
-	}
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret != 0)
-		xc_error_set("read console ring failed: %s", xc_error_get());
-	else
-		*pnr_chars = sysctl.u.readconsole.count;
-
-	munlock(buffer, nr_chars);
-	return ret;
-}
-
-int xc_send_debug_keys(int handle, char *keys)
-{
-	int ret;
-	DECLARE_SYSCTL(XEN_SYSCTL_debug_keys);
-
-	set_xen_guest_handle(sysctl.u.debug_keys.keys, keys);
-	sysctl.u.debug_keys.nr_keys = strlen(keys);
-
-	if (mlock(keys, sysctl.u.debug_keys.nr_keys) != 0) {
-		xc_error_set("send debug keys: mlock failed: %s",
-		             strerror(errno));
-		return -1;
-	}
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret != 0)
-		xc_error_set("send debug keys: %s", xc_error_get());
-
-	munlock(keys, sysctl.u.debug_keys.nr_keys);
-	return ret;
-}
-
-int xc_physinfo(int handle, xc_physinfo_t *put_info)
-{
-	DECLARE_SYSCTL(XEN_SYSCTL_physinfo);
-	int ret;
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret) {
-		xc_error_set("physinfo failed: %s", xc_error_get());
-		return ret;
-	}
-	memcpy(put_info, &sysctl.u.physinfo, sizeof(*put_info));
-	return 0;
-}
-
-int xc_pcpu_info(
-	int handle, int max_cpus, xen_sysctl_cpuinfo_t *info, int *nr_cpus)
-{
-	DECLARE_SYSCTL(XEN_SYSCTL_getcpuinfo);
-	int ret;
-
-	sysctl.u.getcpuinfo.max_cpus = max_cpus;
-	set_xen_guest_handle(sysctl.u.getcpuinfo.info, info);
-
-	if (mlock(info, sizeof(*info) * max_cpus) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret)
-		xc_error_set("pcpu info failed: %s", xc_error_get());
-	else if (ret == 0 && nr_cpus)
-		*nr_cpus = sysctl.u.getcpuinfo.nr_cpus;
-	munlock(info, sizeof(*info) * max_cpus);
-	return ret;
-}
-
-int xc_sched_id(int handle, int *sched_id)
-{
-	DECLARE_SYSCTL(XEN_SYSCTL_sched_id);
-	int ret;
-
-	ret = do_sysctl(handle, &sysctl);
-	if (ret) {
-		xc_error_set("sched id failed: %s", xc_error_get());
-		return ret;
-	}
-	*sched_id = sysctl.u.sched_id.sched_id;
-	return 0;
-}
-
-int xc_version(int handle, int cmd, void *arg)
-{
-	int argsize;
-	int ret;
-	DECLARE_HYPERCALL2(__HYPERVISOR_xen_version, cmd, arg);
-
-	switch (cmd) {
-	case XENVER_extraversion:
-		argsize = sizeof(xen_extraversion_t); break;
-	case XENVER_compile_info:
-		argsize = sizeof(xen_compile_info_t); break;
-	case XENVER_capabilities:
-		argsize = sizeof(xen_capabilities_info_t); break;
-	case XENVER_changeset:
-		argsize = sizeof(xen_changeset_info_t); break;
-	case XENVER_platform_parameters:
-		argsize = sizeof(xen_platform_parameters_t); break;
-	case XENVER_version:
-		argsize = 0; break;
-	default:
-		xc_error_set("version: unknown command");
-		return -1;
-	}
-	if (argsize && mlock(arg, argsize) == -1) {
-		xc_error_set("version: mlock failed: %s", strerror(errno));
-		return -ENOMEM;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-
-	if (argsize)
-		munlock(arg, argsize);
-	return ret;
-}
-
-int xc_evtchn_alloc_unbound(int handle, unsigned int domid,
-                            unsigned int remote_domid)
-{
-	struct evtchn_alloc_unbound arg = {
-		.dom = domid,
-		.remote_dom = remote_domid,
-	};
-	int ret;
-
-	ret = do_evtchnctl(handle, EVTCHNOP_alloc_unbound, &arg, sizeof(arg));
-	if (ret) {
-		xc_error_dom_set(domid, "alloc unbound evtchn to %d",
-		                 remote_domid);
-		return ret;
-	}
-	return arg.port;
-}
-
-int xc_evtchn_reset(int handle, unsigned int domid)
-{
-	struct evtchn_reset arg = {
-		.dom = domid,
-	};
-	int ret;
-
-	ret = do_evtchnctl(handle, EVTCHNOP_reset, &arg, sizeof(arg));
-	if (ret)
-		xc_error_dom_set(domid, "reset evtchn of %d", domid);
-	return ret;
-}
-
-int xc_sched_credit_domain_set(int handle, unsigned int domid,
-                               struct xen_domctl_sched_credit *sdom)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_scheduler_op, domid);
-	domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT;
-	domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
-	domctl.u.scheduler_op.u.credit = *sdom;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "credit scheduler domain set");
-	return ret;
-}
-
-int xc_sched_credit_domain_get(int handle, unsigned int domid,
-                               struct xen_domctl_sched_credit *sdom)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_scheduler_op, domid);
-
-	domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT;
-	domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "credit scheduler domain get");
-	else
-		*sdom = domctl.u.scheduler_op.u.credit;
-	return ret;
-}
-
-int xc_shadow_allocation_get(int handle, unsigned int domid, uint32_t *mb)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_shadow_op, domid);
-
-	domctl.u.shadow_op.op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "shadow allocation get");
-	else
-		*mb = domctl.u.shadow_op.mb;
-	return ret;
-}
-
-int xc_shadow_allocation_set(int handle, unsigned int domid, uint32_t mb)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_shadow_op, domid);
-
-	domctl.u.shadow_op.op = XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION;
-	domctl.u.shadow_op.mb = mb;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "shadow allocation set");
-	return ret;
-}
-
-int xc_domain_get_pfn_list(int handle, unsigned int domid,
-                           uint64_t *pfn_array, unsigned long max_pfns)
-{
-	int ret;
-	DECLARE_DOMCTL(XEN_DOMCTL_getmemlist, domid);
-
-	domctl.u.getmemlist.max_pfns = max_pfns;
-	set_xen_guest_handle(domctl.u.getmemlist.buffer, pfn_array);
-
-	if (mlock(pfn_array, max_pfns * sizeof(xen_pfn_t)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "get pfn list");
-
-	munlock(pfn_array, max_pfns * sizeof(xen_pfn_t));
-	return (ret < 0) ? ret : domctl.u.getmemlist.num_pfns;
-}
-
-#define MARSHALL_BDF(d,b,s,f) \
-	(((b) & 0xff) << 16 | ((s) & 0x1f) << 11 | ((f) & 0x7) << 8)
-
-int xc_domain_assign_device(int handle, unsigned int domid,
-                            int domain, int bus, int slot, int func)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_assign_device
-	DECLARE_DOMCTL(XEN_DOMCTL_assign_device, domid);
-
-	domctl.u.assign_device.machine_bdf = MARSHALL_BDF(domain, bus, slot, func);
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "assign device");
-#endif
-	return ret;
-}
-
-int xc_domain_deassign_device(int handle, unsigned int domid,
-                              int domain, int bus, int slot, int func)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_deassign_device
-	DECLARE_DOMCTL(XEN_DOMCTL_deassign_device, domid);
-
-	domctl.u.assign_device.machine_bdf = MARSHALL_BDF(domain, bus, slot, func);
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "deassign device");
-#endif
-	return ret;
-}
-
-int xc_domain_test_assign_device(int handle, unsigned int domid,
-                                 int domain, int bus, int slot, int func)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_test_assign_device
-	DECLARE_DOMCTL(XEN_DOMCTL_test_assign_device, domid);
-	domctl.u.assign_device.machine_bdf = MARSHALL_BDF(domain, bus, slot, func);
-
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0)
-		xc_error_dom_set(domid, "test assign device");
-#endif
-	return ret;
-}
-
-int xc_domain_watchdog(int handle, int id, uint32_t timeout)
-{
-	int ret = -EBADF;
-#ifdef SCHEDOP_watchdog
-	sched_watchdog_t arg = {
-		.id = (uint32_t) id,
-		.timeout = timeout,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_sched_op, SCHEDOP_watchdog, &arg);
-
-	if (mlock(&arg, sizeof(arg)) != 0) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret < 0) {
-		xc_error_hypercall(hypercall, ret);
-	}
-	munlock(&arg, sizeof(arg));
-#endif
-	return ret;
-}
-
-int xc_domain_set_machine_address_size(int xc, uint32_t domid, unsigned int width)
-{
-	DECLARE_DOMCTL(XEN_DOMCTL_set_machine_address_size, domid);
-	int rc;
-
-	domctl.u.address_size.size = width;
-	rc = do_domctl(xc, &domctl);
-	if (rc != 0)
-		xc_error_dom_set(domid, "set machine address size");
-
-	return rc;
-}
-
-int xc_domain_get_machine_address_size(int xc, uint32_t domid)
-{
-	DECLARE_DOMCTL(XEN_DOMCTL_get_machine_address_size, domid);
-	int rc;
-
-	rc = do_domctl(xc, &domctl);
-	if (rc != 0)
-		xc_error_dom_set(domid, "get machine address size");
-	return rc == 0 ? domctl.u.address_size.size : rc;
-}
-
-#include "xc_cpuid.h"
-int xc_domain_cpuid_set(int xc, unsigned int domid, int hvm,
-                        uint32_t input, uint32_t oinput,
-                        char *config[4], char *config_out[4])
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_set_cpuid
-	DECLARE_DOMCTL(XEN_DOMCTL_set_cpuid, domid);
-	uint32_t regs[4], polregs[4];
-	int i, j;
-
-	xc_cpuid(input, oinput, regs);
-	memcpy(polregs, regs, sizeof(regs));
-	do_cpuid_policy(xc, domid, hvm, input, polregs);
-
-	for (i = 0; i < 4; i++) {
-		if (!config[i]) {
-			regs[i] = polregs[i];
-			continue;
-		}
-		
-		for (j = 0; j < 32; j++) {
-			unsigned char val, polval;
-
-			val = !!((regs[i] & (1U << (31 - j))));
-			polval = !!((regs[i] & (1U << (31 - j))));
-
-			switch (config[i][j]) {
-			case '1': val = 1; break; /* force to true */
-			case '0': val = 0; break; /* force to false */
-			case 'x': val = polval; break;
-			case 'k': case 's': break;
-			default:
-				xc_error_dom_set(domid, "domain cpuid set: invalid config");
-				ret = -EINVAL;
-				goto out;
-			}
-
-			if (val)
-				set_bit(31 - j, regs[i]);
-			else
-				clear_bit(31 - j, regs[i]);
-
-			if (config_out && config_out[i]) {
-				config_out[i][j] = (config[i][j] == 's')
-				                   ? '0' + val
-						   : config[i][j];
-			}
-		}
-	}
-
-	domctl.u.cpuid.input[0] = input;
-	domctl.u.cpuid.input[1] = oinput;
-	domctl.u.cpuid.eax = regs[0];
-	domctl.u.cpuid.ebx = regs[1];
-	domctl.u.cpuid.ecx = regs[2];
-	domctl.u.cpuid.edx = regs[3];
-	ret = do_domctl(xc, &domctl);
-	if (ret) {
-		xc_error_dom_set(domid, "cpuid set");
-		goto out;
-	}
-out:
-#endif
-	return ret;
-}
-
-int xc_domain_cpuid_apply(int xc, unsigned int domid, int hvm)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_set_cpuid
-	uint32_t regs[4], base_max, ext_max, eax, ecx;
-
-	/* determinate cpuid range */
-	xc_cpuid(0, 0, regs);
-	base_max = MIN(regs[0], DEF_MAX_BASE);
-	xc_cpuid(0x80000000, 0, regs);
-	ext_max = MIN(regs[0], DEF_MAX_EXT);
-
-	eax = ecx = 0;
-	while (!(eax & 0x80000000) || (eax <= ext_max)) {
-		xc_cpuid(eax, ecx, regs);
-
-		do_cpuid_policy(xc, domid, hvm, eax, regs);
-		
-		if (regs[0] || regs[1] || regs[2] || regs[3]) {
-			DECLARE_DOMCTL(XEN_DOMCTL_set_cpuid, domid);
-			
-			domctl.u.cpuid.input[0] = eax;
-			domctl.u.cpuid.input[1] = (eax == 4) ? ecx : XEN_CPUID_INPUT_UNUSED;
-			domctl.u.cpuid.eax = regs[0];
-			domctl.u.cpuid.ebx = regs[1];
-			domctl.u.cpuid.ecx = regs[2];
-			domctl.u.cpuid.edx = regs[3];
-
-			ret = do_domctl(xc, &domctl);
-			if (ret) {
-				xc_error_dom_set(domid, "cpuid apply");
-				goto out;
-			}
-
-			/* we repeat when doing node 4 (cache descriptor leaves) increasing ecx 
-			 * until the cpuid eax value masked is 0 */
-			if (eax == 4) {
-				ecx++;
-				if ((regs[0] & 0x1f) != 0)
-					continue;
-				ecx = 0;
-			}
-		}
-
-		eax++;
-		if (!(eax & 0x80000000) && (eax > base_max))
-			eax = 0x80000000;
-	}
-	ret = 0;
-out:
-#endif
-	return ret;
-}
-
-/*
- * return 1 on checking success 
- *        0 on checking failure
- *        -EINVAL if the config contains unknown character
- */
-int xc_cpuid_check(uint32_t input, uint32_t optsubinput,
-                   char *config[4], char *config_out[4])
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_set_cpuid
-	uint32_t regs[4];
-	int i, j;
-
-	xc_cpuid(input, optsubinput, regs);
-
-	ret = 1;
-	for (i = 0; i < 4; i++) {
-		if (!config[i])
-			continue;
-		for (j = 0; j < 32; j++) {
-			unsigned char val;
-
-			val = !!((regs[i] & (1U << (31 - j))));
-
-			switch (config[i][j]) {
-			case '1': if (!val) { ret = 0; goto out; }; break;
-			case '0': if (val) { ret = 0; goto out; }; break;
-			case 'x': case 's': break;
-			default:
-				xc_error_set("cpuid check: invalid config");
-				ret = -EINVAL;
-				goto out;
-			}
-
-			if (config_out && config_out[i]) {
-				config_out[i][j] = (config[i][j] == 's')
-				                   ? '0' + val
-						   : config[i][j];
-			}
-		}
-	} 
-out:
-#endif
-	return ret;
-}
-
-#ifndef HVM_PARAM_HPET_ENABLED
-#define HVM_PARAM_HPET_ENABLED 11
-#endif
-
-#ifndef HVM_PARAM_ACPI_S_STATE
-#define HVM_PARAM_ACPI_S_STATE 14
-#endif
-
-#ifndef HVM_PARAM_VPT_ALIGN
-#define HVM_PARAM_VPT_ALIGN 16
-#endif
-
-int xc_domain_send_s3resume(int handle, unsigned int domid)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 0);
-}
-
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode)
-{
-	return xc_set_hvm_param(handle, domid,
-	                        HVM_PARAM_TIMER_MODE, (unsigned long) mode);
-}
-
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) hpet);
-}
-
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) vpt_align);
-}
-
-int xc_domain_get_acpi_s_state(int handle, unsigned int domid)
-{
-	int ret;
-	unsigned long value;
-
-	ret = xc_get_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, &value);
-	if (ret != 0)
-		xc_error_dom_set(domid, "get acpi s-state");
-	return value;
-}
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/libs/xc/xc_stubs.c
--- a/tools/ocaml/libs/xc/xc_stubs.c	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/xc/xc_stubs.c	Thu Dec 02 11:35:19 2010 -0500
@@ -16,6 +16,7 @@
 
 #define _XOPEN_SOURCE 600
 #include <stdlib.h>
+#include <errno.h>
 
 #define CAML_NAME_SPACE
 #include <caml/alloc.h>
@@ -28,7 +29,7 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "xc.h"
+#include <xenctrl.h>
 
 #include "mmap_stubs.h"
 
@@ -36,7 +37,7 @@
 #define PAGE_SIZE               (1UL << PAGE_SHIFT)
 #define PAGE_MASK               (~(PAGE_SIZE-1))
 
-#define _H(__h) (Int_val(__h))
+#define _H(__h) ((xc_interface *)(__h))
 #define _D(__d) ((uint32_t)Int_val(__d))
 
 #define Val_none (Val_int(0))
@@ -50,12 +51,23 @@
 	i1 = (uint32_t) Int64_val(Field(input, 0)); \
 	i2 = ((Field(input, 1) == Val_none) ? 0xffffffff : (uint32_t) Int64_val(Field(Field(input, 1), 0)));
 
-/**
- * Convert the given number of pages to an amount in MiB, rounded up.
- */
-void failwith_xc(void)
+#define ERROR_STRLEN 1024
+void failwith_xc(xc_interface *xch)
 {
-	caml_raise_with_string(*caml_named_value("xc.error"), xc_error_get());
+	static char error_str[ERROR_STRLEN];
+	if (xch) {
+		const xc_error *error = xc_get_last_error(xch);
+		if (error->code == XC_ERROR_NONE)
+                	snprintf(error_str, ERROR_STRLEN, "%d: %s", errno, strerror(errno));
+		else
+			snprintf(error_str, ERROR_STRLEN, "%d: %s: %s",
+				 error->code,
+				 xc_error_code_to_desc(error->code),
+				 error->message);
+	} else {
+		snprintf(error_str, ERROR_STRLEN, "Unable to open XC interface");
+	}
+	caml_raise_with_string(*caml_named_value("xc.error"), error_str);
 }
 
 CAMLprim value stub_sizeof_core_header(value unit)
@@ -101,35 +113,28 @@ CAMLprim value stub_marshall_core_header
 
 CAMLprim value stub_xc_interface_open(void)
 {
-        int handle;
-        handle = xc_interface_open();
-        if (handle == -1)
-		failwith_xc();
-        return Val_int(handle);
+	CAMLparam0();
+        xc_interface *xch;
+        xch = xc_interface_open(NULL, NULL, XC_OPENFLAG_NON_REENTRANT);
+        if (xch == NULL)
+		failwith_xc(NULL);
+        CAMLreturn((value)xch);
 }
 
 
-CAMLprim value stub_xc_interface_open_fake(void)
+CAMLprim value stub_xc_interface_is_fake(void)
 {
-	return Val_int(-1);
+	CAMLparam0();
+	int is_fake = xc_interface_is_fake();
+	CAMLreturn(Val_int(is_fake));
 }
 
-CAMLprim value stub_xc_using_injection(void)
+CAMLprim value stub_xc_interface_close(value xch)
 {
-	if (xc_using_injection ()){
-		return Val_int(1);
-	} else {
-		return Val_int(0);
-	}
-}
+	CAMLparam1(xch);
 
-CAMLprim value stub_xc_interface_close(value xc_handle)
-{
-	CAMLparam1(xc_handle);
-
-	int handle = _H(xc_handle);
 	// caml_enter_blocking_section();
-	xc_interface_close(handle);
+	xc_interface_close(_H(xch));
 	// caml_leave_blocking_section();
 
 	CAMLreturn(Val_unit);
@@ -140,16 +145,15 @@ static int domain_create_flag_table[] = 
 	XEN_DOMCTL_CDF_hap,
 };
 
-CAMLprim value stub_xc_domain_create(value xc_handle, value ssidref,
+CAMLprim value stub_xc_domain_create(value xch, value ssidref,
                                      value flags, value handle)
 {
-	CAMLparam4(xc_handle, ssidref, flags, handle);
+	CAMLparam4(xch, ssidref, flags, handle);
 
 	uint32_t domid = 0;
 	xen_domain_handle_t h = { 0 };
 	int result;
 	int i;
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_ssidref = Int32_val(ssidref);
 	unsigned int c_flags = 0;
 	value l;
@@ -167,46 +171,32 @@ CAMLprim value stub_xc_domain_create(val
 	}
 
 	// caml_enter_blocking_section();
-	result = xc_domain_create(c_xc_handle, c_ssidref, h, c_flags, &domid);
+	result = xc_domain_create(_H(xch), c_ssidref, h, c_flags, &domid);
 	// caml_leave_blocking_section();
 
 	if (result < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_int(domid));
 }
 
-CAMLprim value stub_xc_domain_setvmxassist(value xc_handle, value domid,
-					    value use_vmxassist)
+CAMLprim value stub_xc_domain_max_vcpus(value xch, value domid,
+                                        value max_vcpus)
 {
-	CAMLparam3(xc_handle, domid, use_vmxassist);
+	CAMLparam3(xch, domid, max_vcpus);
 	int r;
 
-	r = xc_domain_setvmxassist(_H(xc_handle), _D(domid),
-				   Bool_val(use_vmxassist));
+	r = xc_domain_max_vcpus(_H(xch), _D(domid), Int_val(max_vcpus));
 	if (r)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_max_vcpus(value xc_handle, value domid,
-                                        value max_vcpus)
+
+value stub_xc_domain_sethandle(value xch, value domid, value handle)
 {
-	CAMLparam3(xc_handle, domid, max_vcpus);
-	int r;
-
-	r = xc_domain_max_vcpus(_H(xc_handle), _D(domid), Int_val(max_vcpus));
-	if (r)
-		failwith_xc();
-
-	CAMLreturn(Val_unit);
-}
-
-
-value stub_xc_domain_sethandle(value xc_handle, value domid, value handle)
-{
-	CAMLparam3(xc_handle, domid, handle);
+	CAMLparam3(xch, domid, handle);
 	xen_domain_handle_t h = { 0 };
 	int i;
 
@@ -217,57 +207,65 @@ value stub_xc_domain_sethandle(value xc_
 		h[i] = Int_val(Field(handle, i)) & 0xff;
 	}
 
-	i = xc_domain_sethandle(_H(xc_handle), _D(domid), h);
+	i = xc_domain_sethandle(_H(xch), _D(domid), h);
 	if (i)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-static value dom_op(value xc_handle, value domid, int (*fn)(int, uint32_t))
+static value dom_op(value xch, value domid, int (*fn)(xc_interface *, uint32_t))
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_domid = _D(domid);
 
 	// caml_enter_blocking_section();
-	int result = fn(c_xc_handle, c_domid);
+	int result = fn(_H(xch), c_domid);
 	// caml_leave_blocking_section();
         if (result)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_pause(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_pause(value xch, value domid)
 {
-	return dom_op(xc_handle, domid, xc_domain_pause);
+	return dom_op(xch, domid, xc_domain_pause);
 }
 
 
-CAMLprim value stub_xc_domain_unpause(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_unpause(value xch, value domid)
 {
-	return dom_op(xc_handle, domid, xc_domain_unpause);
+	return dom_op(xch, domid, xc_domain_unpause);
 }
 
-CAMLprim value stub_xc_domain_destroy(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_destroy(value xch, value domid)
 {
-	return dom_op(xc_handle, domid, xc_domain_destroy);
+	return dom_op(xch, domid, xc_domain_destroy);
 }
 
-CAMLprim value stub_xc_domain_resume_fast(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_resume_fast(value xch, value domid)
 {
-	return dom_op(xc_handle, domid, xc_domain_resume_fast);
+	CAMLparam2(xch, domid);
+
+	uint32_t c_domid = _D(domid);
+
+	// caml_enter_blocking_section();
+	int result = xc_domain_resume(_H(xch), c_domid, 1);
+	// caml_leave_blocking_section();
+        if (result)
+		failwith_xc(_H(xch));
+	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_shutdown(value handle, value domid, value reason)
+CAMLprim value stub_xc_domain_shutdown(value xch, value domid, value reason)
 {
-	CAMLparam3(handle, domid, reason);
+	CAMLparam3(xch, domid, reason);
 	int ret;
 
-	ret = xc_domain_shutdown(_H(handle), _D(domid), Int_val(reason));
+	ret = xc_domain_shutdown(_H(xch), _D(domid), Int_val(reason));
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
@@ -307,12 +305,12 @@ static value alloc_domaininfo(xc_domaini
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_domain_getinfolist(value xc_handle, value first_domain, value nb)
+CAMLprim value stub_xc_domain_getinfolist(value xch, value first_domain, value nb)
 {
-	CAMLparam3(xc_handle, first_domain, nb);
+	CAMLparam3(xch, first_domain, nb);
 	CAMLlocal2(result, temp);
 	xc_domaininfo_t * info;
-	int i, ret, toalloc, c_xc_handle, retval;
+	int i, ret, toalloc, retval;
 	unsigned int c_max_domains;
 	uint32_t c_first_domain;
 
@@ -324,17 +322,16 @@ CAMLprim value stub_xc_domain_getinfolis
 
 	result = temp = Val_emptylist;
 
-	c_xc_handle = _H(xc_handle);
 	c_first_domain = _D(first_domain);
 	c_max_domains = Int_val(nb);
 	// caml_enter_blocking_section();
-	retval = xc_domain_getinfolist(c_xc_handle, c_first_domain,
+	retval = xc_domain_getinfolist(_H(xch), c_first_domain,
 				       c_max_domains, info);
 	// caml_leave_blocking_section();
 
 	if (retval < 0) {
 		free(info);
-		failwith_xc();
+		failwith_xc(_H(xch));
 	}
 	for (i = 0; i < retval; i++) {
 		result = caml_alloc_small(2, Tag_cons);
@@ -349,37 +346,38 @@ CAMLprim value stub_xc_domain_getinfolis
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_domain_getinfo(value xc_handle, value domid)
+CAMLprim value stub_xc_domain_getinfo(value xch, value domid)
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 	CAMLlocal1(result);
 	xc_domaininfo_t info;
 	int ret;
 
-	ret = xc_domain_getinfo(_H(xc_handle), _D(domid), &info);
-	if (ret != 0)
-		failwith_xc();
+	ret = xc_domain_getinfolist(_H(xch), _D(domid), 1, &info);
+	if (ret != 1)
+		failwith_xc(_H(xch));
+	if (info.domain != _D(domid))
+		failwith_xc(_H(xch));
 
 	result = alloc_domaininfo(&info);
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_vcpu_getinfo(value xc_handle, value domid, value vcpu)
+CAMLprim value stub_xc_vcpu_getinfo(value xch, value domid, value vcpu)
 {
-	CAMLparam3(xc_handle, domid, vcpu);
+	CAMLparam3(xch, domid, vcpu);
 	CAMLlocal1(result);
 	xc_vcpuinfo_t info;
 	int retval;
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_domid = _D(domid);
 	uint32_t c_vcpu = Int_val(vcpu);
 	// caml_enter_blocking_section();
-	retval = xc_vcpu_getinfo(c_xc_handle, c_domid,
+	retval = xc_vcpu_getinfo(_H(xch), c_domid,
 	                         c_vcpu, &info);
 	// caml_leave_blocking_section();
 	if (retval < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	result = caml_alloc_tuple(5);
 	Store_field(result, 0, Val_bool(info.online));
@@ -391,15 +389,15 @@ CAMLprim value stub_xc_vcpu_getinfo(valu
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_vcpu_context_get(value xc_handle, value domid,
+CAMLprim value stub_xc_vcpu_context_get(value xch, value domid,
                                         value cpu)
 {
-	CAMLparam3(xc_handle, domid, cpu);
+	CAMLparam3(xch, domid, cpu);
 	CAMLlocal1(context);
 	int ret;
 	vcpu_guest_context_any_t ctxt;
 
-	ret = xc_vcpu_getcontext(_H(xc_handle), _D(domid), Int_val(cpu), &ctxt);
+	ret = xc_vcpu_getcontext(_H(xch), _D(domid), Int_val(cpu), &ctxt);
 
 	context = caml_alloc_string(sizeof(ctxt));
 	memcpy(String_val(context), (char *) &ctxt.c, sizeof(ctxt.c));
@@ -407,75 +405,115 @@ CAMLprim value stub_xc_vcpu_context_get(
 	CAMLreturn(context);
 }
 
-CAMLprim value stub_xc_vcpu_setaffinity(value xc_handle, value domid,
+static int get_cpumap_len(value xch, value cpumap)
+{
+	int ml_len = Wosize_val(cpumap);
+	int xc_len = xc_get_max_cpus(_H(xch));
+
+	if (ml_len < xc_len)
+		return ml_len;
+	else
+		return xc_len;
+}
+
+CAMLprim value stub_xc_vcpu_setaffinity(value xch, value domid,
                                         value vcpu, value cpumap)
 {
-	CAMLparam4(xc_handle, domid, vcpu, cpumap);
-	uint64_t c_cpumap;
+	CAMLparam4(xch, domid, vcpu, cpumap);
+	int i, len = get_cpumap_len(xch, cpumap);
+	xc_cpumap_t c_cpumap;
 	int retval;
 
-	c_cpumap = Int64_val(cpumap);
-	retval = xc_vcpu_setaffinity(_H(xc_handle), _D(domid),
+	c_cpumap = xc_cpumap_alloc(_H(xch));
+	if (c_cpumap == NULL)
+		failwith_xc(_H(xch));
+
+	for (i=0; i<len; i++) {
+		if (Bool_val(Field(cpumap, i)))
+			c_cpumap[i/8] |= i << (i&7);
+	}
+	retval = xc_vcpu_setaffinity(_H(xch), _D(domid),
 	                             Int_val(vcpu), c_cpumap);
+	free(c_cpumap);
+
 	if (retval < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_vcpu_getaffinity(value xc_handle, value domid,
+CAMLprim value stub_xc_vcpu_getaffinity(value xch, value domid,
                                         value vcpu)
 {
-	CAMLparam3(xc_handle, domid, vcpu);
+	CAMLparam3(xch, domid, vcpu);
 	CAMLlocal1(ret);
-	uint64_t cpumap;
+	xc_cpumap_t c_cpumap;
+	int i, len = xc_get_max_cpus(_H(xch));
 	int retval;
 
-	retval = xc_vcpu_getaffinity(_H(xc_handle), _D(domid),
-	                             Int_val(vcpu), &cpumap);
-	if (retval < 0)
-		failwith_xc();
-	ret = caml_copy_int64(cpumap);
+	c_cpumap = xc_cpumap_alloc(_H(xch));
+	if (c_cpumap == NULL)
+		failwith_xc(_H(xch));
+
+	retval = xc_vcpu_getaffinity(_H(xch), _D(domid),
+	                             Int_val(vcpu), c_cpumap);
+	free(c_cpumap);
+
+	if (retval < 0) {
+		free(c_cpumap);
+		failwith_xc(_H(xch));
+	}
+
+	ret = caml_alloc(len, 0);
+
+	for (i=0; i<len; i++) {
+		if (c_cpumap[i%8] & 1 << (i&7))
+			Store_field(ret, i, Val_true);
+		else
+			Store_field(ret, i, Val_false);
+	}
+
+	free(c_cpumap);
+
 	CAMLreturn(ret);
 }
 
-CAMLprim value stub_xc_sched_id(value xc_handle)
+CAMLprim value stub_xc_sched_id(value xch)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	int sched_id;
 
-	if (xc_sched_id(_H(xc_handle), &sched_id))
-		failwith_xc();
+	if (xc_sched_id(_H(xch), &sched_id))
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_int(sched_id));
 }
 
-CAMLprim value stub_xc_evtchn_alloc_unbound(value xc_handle,
+CAMLprim value stub_xc_evtchn_alloc_unbound(value xch,
                                             value local_domid,
                                             value remote_domid)
 {
-	CAMLparam3(xc_handle, local_domid, remote_domid);
+	CAMLparam3(xch, local_domid, remote_domid);
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_local_domid = _D(local_domid);
 	uint32_t c_remote_domid = _D(remote_domid);
 
 	// caml_enter_blocking_section();
-	int result = xc_evtchn_alloc_unbound(c_xc_handle, c_local_domid,
+	int result = xc_evtchn_alloc_unbound(_H(xch), c_local_domid,
 	                                     c_remote_domid);
 	// caml_leave_blocking_section();
 
 	if (result < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_int(result));
 }
 
-CAMLprim value stub_xc_evtchn_reset(value handle, value domid)
+CAMLprim value stub_xc_evtchn_reset(value xch, value domid)
 {
-	CAMLparam2(handle, domid);
+	CAMLparam2(xch, domid);
 	int r;
 
-	r = xc_evtchn_reset(_H(handle), _D(domid));
+	r = xc_evtchn_reset(_H(xch), _D(domid));
 	if (r < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
@@ -483,48 +521,47 @@ CAMLprim value stub_xc_evtchn_reset(valu
 #define RING_SIZE 32768
 static char ring[RING_SIZE];
 
-CAMLprim value stub_xc_readconsolering(value xc_handle)
+CAMLprim value stub_xc_readconsolering(value xch)
 {
 	unsigned int size = RING_SIZE;
 	char *ring_ptr = ring;
 
-	CAMLparam1(xc_handle);
-	int c_xc_handle = _H(xc_handle);
+	CAMLparam1(xch);
 
 	// caml_enter_blocking_section();
-	int retval = xc_readconsolering(c_xc_handle, &ring_ptr, &size, 0);
+	int retval = xc_readconsolering(_H(xch), ring_ptr, &size, 0, 0, NULL);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	ring[size] = '\0';
 	CAMLreturn(caml_copy_string(ring));
 }
 
-CAMLprim value stub_xc_send_debug_keys(value xc_handle, value keys)
+CAMLprim value stub_xc_send_debug_keys(value xch, value keys)
 {
-	CAMLparam2(xc_handle, keys);
+	CAMLparam2(xch, keys);
 	int r;
 
-	r = xc_send_debug_keys(_H(xc_handle), String_val(keys));
+	r = xc_send_debug_keys(_H(xch), String_val(keys));
 	if (r)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_physinfo(value xc_handle)
+CAMLprim value stub_xc_physinfo(value xch)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	CAMLlocal3(physinfo, cap_list, tmp);
 	xc_physinfo_t c_physinfo;
 	int r;
 
 	// caml_enter_blocking_section();
-	r = xc_physinfo(_H(xc_handle), &c_physinfo);
+	r = xc_physinfo(_H(xch), &c_physinfo);
 	// caml_leave_blocking_section();
 
 	if (r)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	tmp = cap_list = Val_emptylist;
 	for (r = 0; r < 2; r++) {
@@ -550,11 +587,11 @@ CAMLprim value stub_xc_physinfo(value xc
 	CAMLreturn(physinfo);
 }
 
-CAMLprim value stub_xc_pcpu_info(value xc_handle, value nr_cpus)
+CAMLprim value stub_xc_pcpu_info(value xch, value nr_cpus)
 {
-	CAMLparam2(xc_handle, nr_cpus);
+	CAMLparam2(xch, nr_cpus);
 	CAMLlocal2(pcpus, v);
-	xen_sysctl_cpuinfo_t *info;
+	xc_cpuinfo_t *info;
 	int r, size;
 
 	if (Int_val(nr_cpus) < 1)
@@ -565,12 +602,12 @@ CAMLprim value stub_xc_pcpu_info(value x
 		caml_raise_out_of_memory();
 
 	// caml_enter_blocking_section();
-	r = xc_pcpu_info(_H(xc_handle), Int_val(nr_cpus), info, &size);
+	r = xc_getcpuinfo(_H(xch), Int_val(nr_cpus), info, &size);
 	// caml_leave_blocking_section();
 
 	if (r) {
 		free(info);
-		failwith_xc();
+		failwith_xc(_H(xch));
 	}
 
 	if (size > 0) {
@@ -586,101 +623,98 @@ CAMLprim value stub_xc_pcpu_info(value x
 	CAMLreturn(pcpus);
 }
 
-CAMLprim value stub_xc_domain_setmaxmem(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_setmaxmem(value xch, value domid,
                                         value max_memkb)
 {
-	CAMLparam3(xc_handle, domid, max_memkb);
+	CAMLparam3(xch, domid, max_memkb);
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_domid = _D(domid);
 	unsigned int c_max_memkb = Int64_val(max_memkb);
 	// caml_enter_blocking_section();
-	int retval = xc_domain_setmaxmem(c_xc_handle, c_domid,
+	int retval = xc_domain_setmaxmem(_H(xch), c_domid,
 	                                 c_max_memkb);
 	// caml_leave_blocking_section();
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_set_memmap_limit(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_set_memmap_limit(value xch, value domid,
                                                value map_limitkb)
 {
-	CAMLparam3(xc_handle, domid, map_limitkb);
+	CAMLparam3(xch, domid, map_limitkb);
 	unsigned long v;
 	int retval;
 
 	v = Int64_val(map_limitkb);
-	retval = xc_domain_set_memmap_limit(_H(xc_handle), _D(domid), v);
+	retval = xc_domain_set_memmap_limit(_H(xch), _D(domid), v);
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_memory_increase_reservation(value xc_handle,
+CAMLprim value stub_xc_domain_memory_increase_reservation(value xch,
                                                           value domid,
                                                           value mem_kb)
 {
-	CAMLparam3(xc_handle, domid, mem_kb);
+	CAMLparam3(xch, domid, mem_kb);
 
 	unsigned long nr_extents = ((unsigned long)(Int64_val(mem_kb))) >> (PAGE_SHIFT - 10);
 
-	int c_xc_handle = _H(xc_handle);
 	uint32_t c_domid = _D(domid);
 	// caml_enter_blocking_section();
-	int retval = xc_domain_memory_increase_reservation(c_xc_handle, c_domid,
-	                                                   nr_extents, 0, 0, NULL);
+	int retval = xc_domain_increase_reservation_exact(_H(xch), c_domid,
+							  nr_extents, 0, 0, NULL);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_set_machine_address_size(value xc_handle,
+CAMLprim value stub_xc_domain_set_machine_address_size(value xch,
 						       value domid,
 						       value width)
 {
-	CAMLparam3(xc_handle, domid, width);
-	int c_xc_handle = _H(xc_handle);
+	CAMLparam3(xch, domid, width);
 	uint32_t c_domid = _D(domid);
 	int c_width = Int_val(width);
 
-	int retval = xc_domain_set_machine_address_size(c_xc_handle, c_domid, c_width);
+	int retval = xc_domain_set_machine_address_size(_H(xch), c_domid, c_width);
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_get_machine_address_size(value xc_handle,
+CAMLprim value stub_xc_domain_get_machine_address_size(value xch,
                                                        value domid)
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 	int retval;
 
-	retval = xc_domain_get_machine_address_size(_H(xc_handle), _D(domid));
+	retval = xc_domain_get_machine_address_size(_H(xch), _D(domid));
 	if (retval < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_int(retval));
 }
 
-CAMLprim value stub_xc_domain_cpuid_set(value xc_handle, value domid,
-                                        value is_hvm, value input,
+CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
+                                        value input,
                                         value config)
 {
-	CAMLparam5(xc_handle, domid, is_hvm, input, config);
+	CAMLparam4(xch, domid, input, config);
 	CAMLlocal2(array, tmp);
 	int r;
+	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];
-	uint32_t c_input, c_oinput;
 
 	c_config[0] = string_of_option_array(config, 0);
 	c_config[1] = string_of_option_array(config, 1);
 	c_config[2] = string_of_option_array(config, 2);
 	c_config[3] = string_of_option_array(config, 3);
 
-	cpuid_input_of_val(c_input, c_oinput, input);
+	cpuid_input_of_val(c_input[0], c_input[1], input);
 
 	array = caml_alloc(4, 0);
 	for (r = 0; r < 4; r++) {
@@ -695,29 +729,30 @@ CAMLprim value stub_xc_domain_cpuid_set(
 	for (r = 0; r < 4; r++)
 		out_config[r] = (c_config[r]) ? String_val(Field(Field(array, r), 0)) : NULL;
 
-	r = xc_domain_cpuid_set(_H(xc_handle), _D(domid), Bool_val(is_hvm),
-	                        c_input, c_oinput, c_config, out_config);
+	r = xc_cpuid_set(_H(xch), _D(domid),
+			 c_input, (const char **)c_config, out_config);
 	if (r < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(array);
 }
 
-CAMLprim value stub_xc_domain_cpuid_apply(value xc_handle, value domid, value is_hvm)
+CAMLprim value stub_xc_domain_cpuid_apply_policy(value xch, value domid)
 {
-	CAMLparam3(xc_handle, domid, is_hvm);
+	CAMLparam2(xch, domid);
 	int r;
-	r = xc_domain_cpuid_apply(_H(xc_handle), _D(domid), Bool_val(is_hvm));
+
+	r = xc_cpuid_apply_policy(_H(xch), _D(domid));
 	if (r < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_cpuid_check(value input, value config)
+CAMLprim value stub_xc_cpuid_check(value xch, value input, value config)
 {
-	CAMLparam2(input, config);
+	CAMLparam3(xch, input, config);
 	CAMLlocal3(ret, array, tmp);
 	int r;
-	uint32_t c_input, c_oinput;
+	unsigned int c_input[2];
 	char *c_config[4], *out_config[4];
 
 	c_config[0] = string_of_option_array(config, 0);
@@ -725,7 +760,7 @@ CAMLprim value stub_xc_cpuid_check(value
 	c_config[2] = string_of_option_array(config, 2);
 	c_config[3] = string_of_option_array(config, 3);
 
-	cpuid_input_of_val(c_input, c_oinput, input);
+	cpuid_input_of_val(c_input[0], c_input[1], input);
 
 	array = caml_alloc(4, 0);
 	for (r = 0; r < 4; r++) {
@@ -740,9 +775,9 @@ CAMLprim value stub_xc_cpuid_check(value
 	for (r = 0; r < 4; r++)
 		out_config[r] = (c_config[r]) ? String_val(Field(Field(array, r), 0)) : NULL;
 
-	r = xc_cpuid_check(c_input, c_oinput, c_config, out_config);
+	r = xc_cpuid_check(_H(xch), c_input, (const char **)c_config, out_config);
 	if (r < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	ret = caml_alloc_tuple(2);
 	Store_field(ret, 0, Val_bool(r));
@@ -751,22 +786,21 @@ CAMLprim value stub_xc_cpuid_check(value
 	CAMLreturn(ret);
 }
 
-CAMLprim value stub_xc_version_version(value xc_handle)
+CAMLprim value stub_xc_version_version(value xch)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	CAMLlocal1(result);
 	xen_extraversion_t extra;
 	long packed;
 	int retval;
 
-	int c_xc_handle = _H(xc_handle);
 	// caml_enter_blocking_section();
-	packed = xc_version(c_xc_handle, XENVER_version, NULL);
-	retval = xc_version(c_xc_handle, XENVER_extraversion, &extra);
+	packed = xc_version(_H(xch), XENVER_version, NULL);
+	retval = xc_version(_H(xch), XENVER_extraversion, &extra);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	result = caml_alloc_tuple(3);
 
@@ -778,20 +812,19 @@ CAMLprim value stub_xc_version_version(v
 }
 
 
-CAMLprim value stub_xc_version_compile_info(value xc_handle)
+CAMLprim value stub_xc_version_compile_info(value xch)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	CAMLlocal1(result);
 	xen_compile_info_t ci;
 	int retval;
 
-	int c_xc_handle = _H(xc_handle);
 	// caml_enter_blocking_section();
-	retval = xc_version(c_xc_handle, XENVER_compile_info, &ci);
+	retval = xc_version(_H(xch), XENVER_compile_info, &ci);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	result = caml_alloc_tuple(4);
 
@@ -804,36 +837,35 @@ CAMLprim value stub_xc_version_compile_i
 }
 
 
-static value xc_version_single_string(value xc_handle, int code, void *info)
+static value xc_version_single_string(value xch, int code, void *info)
 {
-	CAMLparam1(xc_handle);
+	CAMLparam1(xch);
 	int retval;
 
-	int c_xc_handle = _H(xc_handle);
 	// caml_enter_blocking_section();
-	retval = xc_version(c_xc_handle, code, info);
+	retval = xc_version(_H(xch), code, info);
 	// caml_leave_blocking_section();
 
 	if (retval)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(caml_copy_string((char *)info));
 }
 
 
-CAMLprim value stub_xc_version_changeset(value xc_handle)
+CAMLprim value stub_xc_version_changeset(value xch)
 {
 	xen_changeset_info_t ci;
 
-	return xc_version_single_string(xc_handle, XENVER_changeset, &ci);
+	return xc_version_single_string(xch, XENVER_changeset, &ci);
 }
 
 
-CAMLprim value stub_xc_version_capabilities(value xc_handle)
+CAMLprim value stub_xc_version_capabilities(value xch)
 {
 	xen_capabilities_info_t ci;
 
-	return xc_version_single_string(xc_handle, XENVER_capabilities, &ci);
+	return xc_version_single_string(xch, XENVER_capabilities, &ci);
 }
 
 
@@ -845,13 +877,12 @@ CAMLprim value stub_pages_to_kib(value p
 }
 
 
-CAMLprim value stub_map_foreign_range(value xc_handle, value dom,
+CAMLprim value stub_map_foreign_range(value xch, value dom,
                                       value size, value mfn)
 {
-	CAMLparam4(xc_handle, dom, size, mfn);
+	CAMLparam4(xch, dom, size, mfn);
 	CAMLlocal1(result);
 	struct mmap_interface *intf;
-	int c_xc_handle;
 	uint32_t c_dom;
 	unsigned long c_mfn;
 
@@ -860,11 +891,10 @@ CAMLprim value stub_map_foreign_range(va
 
 	intf->len = Int_val(size);
 
-	c_xc_handle = _H(xc_handle);
 	c_dom = _D(dom);
 	c_mfn = Nativeint_val(mfn);
 	// caml_enter_blocking_section();
-	intf->addr = xc_map_foreign_range(c_xc_handle, c_dom,
+	intf->addr = xc_map_foreign_range(_H(xch), c_dom,
 	                                  intf->len, PROT_READ|PROT_WRITE,
 	                                  c_mfn);
 	// caml_leave_blocking_section();
@@ -873,18 +903,18 @@ CAMLprim value stub_map_foreign_range(va
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_sched_credit_domain_get(value xc_handle, value domid)
+CAMLprim value stub_sched_credit_domain_get(value xch, value domid)
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 	CAMLlocal1(sdom);
 	struct xen_domctl_sched_credit c_sdom;
 	int ret;
 
 	// caml_enter_blocking_section();
-	ret = xc_sched_credit_domain_get(_H(xc_handle), _D(domid), &c_sdom);
+	ret = xc_sched_credit_domain_get(_H(xch), _D(domid), &c_sdom);
 	// caml_leave_blocking_section();
 	if (ret != 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	sdom = caml_alloc_tuple(2);
 	Store_field(sdom, 0, Val_int(c_sdom.weight));
@@ -893,62 +923,66 @@ CAMLprim value stub_sched_credit_domain_
 	CAMLreturn(sdom);
 }
 
-CAMLprim value stub_sched_credit_domain_set(value xc_handle, value domid,
+CAMLprim value stub_sched_credit_domain_set(value xch, value domid,
                                             value sdom)
 {
-	CAMLparam3(xc_handle, domid, sdom);
+	CAMLparam3(xch, domid, sdom);
 	struct xen_domctl_sched_credit c_sdom;
 	int ret;
 
 	c_sdom.weight = Int_val(Field(sdom, 0));
 	c_sdom.cap = Int_val(Field(sdom, 1));
 	// caml_enter_blocking_section();
-	ret = xc_sched_credit_domain_set(_H(xc_handle), _D(domid), &c_sdom);
+	ret = xc_sched_credit_domain_set(_H(xch), _D(domid), &c_sdom);
 	// caml_leave_blocking_section();
 	if (ret != 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_shadow_allocation_get(value xc_handle, value domid)
+CAMLprim value stub_shadow_allocation_get(value xch, value domid)
 {
-	CAMLparam2(xc_handle, domid);
+	CAMLparam2(xch, domid);
 	CAMLlocal1(mb);
-	uint32_t c_mb;
+	unsigned long c_mb;
 	int ret;
 
 	// caml_enter_blocking_section();
-	ret = xc_shadow_allocation_get(_H(xc_handle), _D(domid), &c_mb);
+	ret = xc_shadow_control(_H(xch), _D(domid),
+				XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION,
+				NULL, 0, &c_mb, 0, NULL);
 	// caml_leave_blocking_section();
 	if (ret != 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	mb = Val_int(c_mb);
 	CAMLreturn(mb);
 }
 
-CAMLprim value stub_shadow_allocation_set(value xc_handle, value domid,
+CAMLprim value stub_shadow_allocation_set(value xch, value domid,
 					  value mb)
 {
-	CAMLparam3(xc_handle, domid, mb);
-	uint32_t c_mb;
+	CAMLparam3(xch, domid, mb);
+	unsigned long c_mb;
 	int ret;
 
 	c_mb = Int_val(mb);
 	// caml_enter_blocking_section();
-	ret = xc_shadow_allocation_set(_H(xc_handle), _D(domid), c_mb);
+	ret = xc_shadow_control(_H(xch), _D(domid),
+				XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION,
+				NULL, 0, &c_mb, 0, NULL);
 	// caml_leave_blocking_section();
 	if (ret != 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_get_pfn_list(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_get_pfn_list(value xch, value domid,
                                            value nr_pfns)
 {
-	CAMLparam3(xc_handle, domid, nr_pfns);
+	CAMLparam3(xch, domid, nr_pfns);
 	CAMLlocal2(array, v);
 	unsigned long c_nr_pfns;
 	long ret, i;
@@ -960,11 +994,11 @@ CAMLprim value stub_xc_domain_get_pfn_li
 	if (!c_array)
 		caml_raise_out_of_memory();
 
-	ret = xc_domain_get_pfn_list(_H(xc_handle), _D(domid),
-	                             c_array, c_nr_pfns);
+	ret = xc_get_pfn_list(_H(xch), _D(domid),
+			      c_array, c_nr_pfns);
 	if (ret < 0) {
 		free(c_array);
-		failwith_xc();
+		failwith_xc(_H(xch));
 	}
 
 	array = caml_alloc(ret, 0);
@@ -977,11 +1011,11 @@ CAMLprim value stub_xc_domain_get_pfn_li
 	CAMLreturn(array);
 }
 
-CAMLprim value stub_xc_domain_ioport_permission(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_ioport_permission(value xch, value domid,
 					       value start_port, value nr_ports,
 					       value allow)
 {
-	CAMLparam5(xc_handle, domid, start_port, nr_ports, allow);
+	CAMLparam5(xch, domid, start_port, nr_ports, allow);
 	uint32_t c_start_port, c_nr_ports;
 	uint8_t c_allow;
 	int ret;
@@ -990,19 +1024,19 @@ CAMLprim value stub_xc_domain_ioport_per
 	c_nr_ports = Int_val(nr_ports);
 	c_allow = Bool_val(allow);
 
-	ret = xc_domain_ioport_permission(_H(xc_handle), _D(domid),
+	ret = xc_domain_ioport_permission(_H(xch), _D(domid),
 					 c_start_port, c_nr_ports, c_allow);
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_iomem_permission(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_iomem_permission(value xch, value domid,
 					       value start_pfn, value nr_pfns,
 					       value allow)
 {
-	CAMLparam5(xc_handle, domid, start_pfn, nr_pfns, allow);
+	CAMLparam5(xch, domid, start_pfn, nr_pfns, allow);
 	unsigned long c_start_pfn, c_nr_pfns;
 	uint8_t c_allow;
 	int ret;
@@ -1011,18 +1045,18 @@ CAMLprim value stub_xc_domain_iomem_perm
 	c_nr_pfns = Nativeint_val(nr_pfns);
 	c_allow = Bool_val(allow);
 
-	ret = xc_domain_iomem_permission(_H(xc_handle), _D(domid),
+	ret = xc_domain_iomem_permission(_H(xch), _D(domid),
 					 c_start_pfn, c_nr_pfns, c_allow);
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_irq_permission(value xc_handle, value domid,
+CAMLprim value stub_xc_domain_irq_permission(value xch, value domid,
 					     value pirq, value allow)
 {
-	CAMLparam4(xc_handle, domid, pirq, allow);
+	CAMLparam4(xch, domid, pirq, allow);
 	uint8_t c_pirq;
 	uint8_t c_allow;
 	int ret;
@@ -1030,138 +1064,90 @@ CAMLprim value stub_xc_domain_irq_permis
 	c_pirq = Int_val(pirq);
 	c_allow = Bool_val(allow);
 
-	ret = xc_domain_irq_permission(_H(xc_handle), _D(domid),
+	ret = xc_domain_irq_permission(_H(xch), _D(domid),
 				       c_pirq, c_allow);
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_hvm_check_pvdriver(value xc_handle, value domid)
+static uint32_t pci_dev_to_bdf(int domain, int bus, int slot, int func)
 {
-	CAMLparam2(xc_handle, domid);
-	int ret;
-
-	ret = xc_hvm_check_pvdriver(_H(xc_handle), _D(domid));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_bool(ret));
+	uint32_t bdf = 0;
+	bdf |= (bus & 0xff) << 16;
+	bdf |= (slot & 0x1f) << 11;
+	bdf |= (func & 0x7) << 8;
+	return bdf;
 }
 
-CAMLprim value stub_xc_domain_test_assign_device(value xc_handle, value domid, value desc)
+CAMLprim value stub_xc_domain_test_assign_device(value xch, value domid, value desc)
 {
-	CAMLparam3(xc_handle, domid, desc);
+	CAMLparam3(xch, domid, desc);
 	int ret;
 	int domain, bus, slot, func;
+	uint32_t bdf;
 
 	domain = Int_val(Field(desc, 0));
 	bus = Int_val(Field(desc, 1));
 	slot = Int_val(Field(desc, 2));
 	func = Int_val(Field(desc, 3));
+	bdf = pci_dev_to_bdf(domain, bus, slot, func);
 
-	ret = xc_domain_test_assign_device(_H(xc_handle), _D(domid),
-	                                   domain, bus, slot, func);
+	ret = xc_test_assign_device(_H(xch), _D(domid), bdf);
+
 	CAMLreturn(Val_bool(ret == 0));
 }
 
-CAMLprim value stub_xc_domain_assign_device(value xc_handle, value domid, value desc)
+CAMLprim value stub_xc_domain_assign_device(value xch, value domid, value desc)
 {
-	CAMLparam3(xc_handle, domid, desc);
+	CAMLparam3(xch, domid, desc);
 	int ret;
 	int domain, bus, slot, func;
+	uint32_t bdf;
 
 	domain = Int_val(Field(desc, 0));
 	bus = Int_val(Field(desc, 1));
 	slot = Int_val(Field(desc, 2));
 	func = Int_val(Field(desc, 3));
+	bdf = pci_dev_to_bdf(domain, bus, slot, func);
 
-	ret = xc_domain_assign_device(_H(xc_handle), _D(domid),
-	                              domain, bus, slot, func);
+	ret = xc_assign_device(_H(xch), _D(domid), bdf);
+
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_deassign_device(value xc_handle, value domid, value desc)
+CAMLprim value stub_xc_domain_deassign_device(value xch, value domid, value desc)
 {
-	CAMLparam3(xc_handle, domid, desc);
+	CAMLparam3(xch, domid, desc);
 	int ret;
 	int domain, bus, slot, func;
+	uint32_t bdf;
 
 	domain = Int_val(Field(desc, 0));
 	bus = Int_val(Field(desc, 1));
 	slot = Int_val(Field(desc, 2));
 	func = Int_val(Field(desc, 3));
+	bdf = pci_dev_to_bdf(domain, bus, slot, func);
 
-	ret = xc_domain_deassign_device(_H(xc_handle), _D(domid),
-	                                domain, bus, slot, func);
+	ret = xc_deassign_device(_H(xch), _D(domid), bdf);
+
 	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_domain_set_timer_mode(value handle, value id, value mode)
+CAMLprim value stub_xc_watchdog(value xch, value domid, value timeout)
 {
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_timer_mode(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_hpet(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_hpet(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_vpt_align(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_vpt_align(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_watchdog(value handle, value domid, value timeout)
-{
-	CAMLparam3(handle, domid, timeout);
+	CAMLparam3(xch, domid, timeout);
 	int ret;
 	unsigned int c_timeout = Int32_val(timeout);
 
-	ret = xc_domain_watchdog(_H(handle), _D(domid), c_timeout);
+	ret = xc_watchdog(_H(xch), _D(domid), c_timeout);
 	if (ret < 0)
-		failwith_xc();
-
-	CAMLreturn(Val_int(ret));
-}
-
-CAMLprim value stub_xc_domain_send_s3resume(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	xc_domain_send_s3resume(_H(handle), _D(domid));
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_get_acpi_s_state(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	int ret;
-
-	ret = xc_domain_get_acpi_s_state(_H(handle), _D(domid));
-	if (ret < 0)
-		failwith_xc();
+		failwith_xc(_H(xch));
 
 	CAMLreturn(Val_int(ret));
 }
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/xenstored/Makefile
--- a/tools/ocaml/xenstored/Makefile	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/xenstored/Makefile	Thu Dec 02 11:35:19 2010 -0500
@@ -39,7 +39,8 @@ XENSTOREDLIBS = \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/log $(OCAML_TOPLEVEL)/libs/log/log.cmxa \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/eventchn/eventchn.cmxa \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xc.cmxa \
-	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xb.cmxa
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xb.cmxa \
+	-ccopt -L -ccopt $(XEN_ROOT)/tools/libxc
 
 PROGRAMS = oxenstored
 
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/xenstored/event.ml
--- a/tools/ocaml/xenstored/event.ml	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/xenstored/event.ml	Thu Dec 02 11:35:19 2010 -0500
@@ -16,14 +16,15 @@
 
 (**************** high level binding ****************)
 type t = {
-	fd: Unix.file_descr;
+	handle: Eventchn.handle;
 	mutable virq_port: int;
 }
 
-let init () = { fd = Eventchn.init (); virq_port = -1; }
-let bind_dom_exc_virq eventchn = eventchn.virq_port <- Eventchn.bind_dom_exc_virq eventchn.fd
-let bind_interdomain eventchn domid port = Eventchn.bind_interdomain eventchn.fd domid port
-let unbind eventchn port = Eventchn.unbind eventchn.fd port
-let notify eventchn port = Eventchn.notify eventchn.fd port
-let read_port eventchn = Eventchn.read_port eventchn.fd
-let write_port eventchn port = Eventchn.write_port eventchn.fd port
+let init () = { handle = Eventchn.init (); virq_port = -1; }
+let fd eventchn = Eventchn.fd eventchn.handle
+let bind_dom_exc_virq eventchn = eventchn.virq_port <- Eventchn.bind_dom_exc_virq eventchn.handle
+let bind_interdomain eventchn domid port = Eventchn.bind_interdomain eventchn.handle domid port
+let unbind eventchn port = Eventchn.unbind eventchn.handle port
+let notify eventchn port = Eventchn.notify eventchn.handle port
+let pending eventchn = Eventchn.pending eventchn.handle
+let unmask eventchn port = Eventchn.unmask eventchn.handle port
diff -r 9ca2fdb9072d -r 5aca7dd02847 tools/ocaml/xenstored/xenstored.ml
--- a/tools/ocaml/xenstored/xenstored.ml	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/xenstored/xenstored.ml	Thu Dec 02 11:35:19 2010 -0500
@@ -282,7 +282,7 @@ let _ =
 			Store.mkdir store (Perms.Connection.create 0) localpath;
 
 		if cf.domain_init then (
-			let usingxiu = Xc.using_injection () in
+			let usingxiu = Xc.is_fake () in
 			Connections.add_domain cons (Domains.create0 usingxiu domains);
 			Event.bind_dom_exc_virq eventchn
 		);
@@ -298,7 +298,7 @@ let _ =
 	let spec_fds =
 		(match rw_sock with None -> [] | Some x -> [ x ]) @
 		(match ro_sock with None -> [] | Some x -> [ x ]) @
-		(if cf.domain_init then [ eventchn.Event.fd ] else [])
+		(if cf.domain_init then [ Event.fd eventchn ] else [])
 		in
 
 	let xc = Xc.interface_open () in
@@ -309,7 +309,7 @@ let _ =
 			debug "new connection through socket";
 			Connections.add_anonymous cons cfd can_write
 		and handle_eventchn fd =
-			let port = Event.read_port eventchn in
+			let port = Event.pending eventchn in
 			finally (fun () ->
 				if port = eventchn.Event.virq_port then (
 					let (notify, deaddom) = Domains.cleanup xc domains in
@@ -317,14 +317,14 @@ let _ =
 					if deaddom <> [] || notify then
 						Connections.fire_spec_watches cons "@releaseDomain"
 				)
-			) (fun () -> Event.write_port eventchn port);
+			) (fun () -> Event.unmask eventchn port);
 		and do_if_set fd set fct =
 			if List.mem fd set then
 				fct fd in
 
 		maybe (fun fd -> do_if_set fd rset (accept_connection true)) rw_sock;
 		maybe (fun fd -> do_if_set fd rset (accept_connection false)) ro_sock;
-		do_if_set eventchn.Event.fd rset (handle_eventchn)
+		do_if_set (Event.fd eventchn) rset (handle_eventchn)
 		in
 
 	let last_stat_time = ref 0. in

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 5 of 5] HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same
  2010-12-07 14:32     ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
       [not found]       ` <patchbomb.1291732371-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:32       ` [PATCH 3 of 5] ocaml: rename Evtchn.bind_virq as Evtchn.bind_dom_exc_virq Ian Campbell
@ 2010-12-07 14:32       ` Ian Campbell
  2010-12-13 17:23       ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Stefano Stabellini
       [not found]       ` <m2n.s.1PPykG-000YDj@chiark.greenend.org.uk>
  4 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1291307719 18000
# Node ID 4030d0d9eb3cdf1f75965190805cf97e1a477602
# Parent  5aca7dd0284714d086b62b3504a39b67e23b65e2
HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same.

blktap issue is resolved by proper XCP packaging of the hypervisor tools rather
than my rather ad-hoc approach.

ocaml namespacing issues need some more thought, as mentioned in the overall
introductory email.

Not-Signed-of-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 5aca7dd02847 -r 4030d0d9eb3c tools/Makefile
--- a/tools/Makefile	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/Makefile	Thu Dec 02 11:35:19 2010 -0500
@@ -21,8 +21,8 @@ SUBDIRS-$(VTPM_TOOLS) += vtpm
 SUBDIRS-y += xenstat
 SUBDIRS-$(CONFIG_Linux) += libaio
 SUBDIRS-$(CONFIG_Linux) += memshr 
-SUBDIRS-$(CONFIG_Linux) += blktap
-SUBDIRS-$(CONFIG_Linux) += blktap2
+#SUBDIRS-$(CONFIG_Linux) += blktap
+#SUBDIRS-$(CONFIG_Linux) += blktap2
 SUBDIRS-$(CONFIG_NetBSD) += libaio
 SUBDIRS-$(CONFIG_NetBSD) += blktap2
 SUBDIRS-$(CONFIG_NetBSD) += xenbackendd
@@ -46,7 +46,7 @@ SUBDIRS-$(CONFIG_X86) += debugger/kdd
 # These don't cross-compile
 ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
 SUBDIRS-$(PYTHON_TOOLS) += python
-SUBDIRS-$(PYTHON_TOOLS) += pygrub
+#SUBDIRS-$(PYTHON_TOOLS) += pygrub
 SUBDIRS-$(OCAML_TOOLS) += ocaml
 endif
 
diff -r 5aca7dd02847 -r 4030d0d9eb3c tools/blktap2/vhd/lib/Makefile
--- a/tools/blktap2/vhd/lib/Makefile	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/blktap2/vhd/lib/Makefile	Thu Dec 02 11:35:19 2010 -0500
@@ -63,9 +63,9 @@ libvhd.a: $(LIB-OBJS)
 
 install: all
 	$(INSTALL_DIR) -p $(DESTDIR)$(INST-DIR)
-	$(INSTALL_DATA) $(LIBVHD) $(DESTDIR)$(INST-DIR)
-	ln -sf libvhd.so.$(LIBVHD-MAJOR).$(LIBVHD-MINOR) $(DESTDIR)$(INST-DIR)/libvhd.so.$(LIBVHD-MAJOR)
-	ln -sf libvhd.so.$(LIBVHD-MAJOR) $(DESTDIR)$(INST-DIR)/libvhd.so
+	#$(INSTALL_DATA) $(LIBVHD) $(DESTDIR)$(INST-DIR)
+	#ln -sf libvhd.so.$(LIBVHD-MAJOR).$(LIBVHD-MINOR) $(DESTDIR)$(INST-DIR)/libvhd.so.$(LIBVHD-MAJOR)
+	#ln -sf libvhd.so.$(LIBVHD-MAJOR) $(DESTDIR)$(INST-DIR)/libvhd.so
 
 clean:
 	rm -rf *.a *.so* *.o *~ $(DEPS) $(LIBVHD)
diff -r 5aca7dd02847 -r 4030d0d9eb3c tools/ocaml/libs/log/Makefile
--- a/tools/ocaml/libs/log/Makefile	Thu Dec 02 11:35:19 2010 -0500
+++ b/tools/ocaml/libs/log/Makefile	Thu Dec 02 11:35:19 2010 -0500
@@ -32,9 +32,10 @@ syslog.mli : syslog.ml
 
 .PHONY: install
 install: $(LIBS) META
-	mkdir -p $(OCAMLDESTDIR)
-	ocamlfind remove -destdir $(OCAMLDESTDIR) log
-	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore log META $(INTF) $(LIBS) *.a *.so *.cmx
+### XXX need resyncing with xen-api-libs
+#	mkdir -p $(OCAMLDESTDIR)
+#	ocamlfind remove -destdir $(OCAMLDESTDIR) log
+#	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore log META $(INTF) $(LIBS) *.a *.so *.cmx
 
 .PHONY: uninstall
 uninstall:

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg
       [not found]     ` <1291732233.13966.3198.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:32       ` [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Ian Campbell
@ 2010-12-07 14:32       ` Ian Campbell
  2010-12-07 14:33         ` [PATCH 1 of 5] Query rpm to find build directories Ian Campbell
                           ` (2 more replies)
  2010-12-07 14:33       ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
  2 siblings, 3 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:32 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

The following series of patches lays some ground work to enable XCP to move, at
some point in the future, to the in-tree ocaml bindings which will come with
Xen 4.1.

This is the xen-api-libs.hg portion.

Only the first three patches are for immediate consideration, the others all
depend on actually moving to Xen 4.1.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1 of 5] Query rpm to find build directories
  2010-12-07 14:32       ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
@ 2010-12-07 14:33         ` Ian Campbell
       [not found]         ` <patchbomb.1291732379-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:33         ` [PATCH 4 of 5] REBASE-4.1: default to using system installed bindings if Xen is available Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1291731529 18000
# Node ID b4ef59ed08a9a4c1387fd00cd79aec3398bca3f5
# Parent  3be1829b46b70a8ae4b2013fc20b71a76f3b55ee
Query rpm to find build directories.

Allows user with ~/.rpmmacros to build e.g.
$ cat ~/.rpmmacros
%_topdir        /data/rpmbuild
%_tmppath       /data/tmp

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 3be1829b46b7 -r b4ef59ed08a9 Makefile.in
--- a/Makefile.in	Tue Oct 12 12:15:54 2010 +0100
+++ b/Makefile.in	Tue Dec 07 09:18:49 2010 -0500
@@ -211,8 +211,8 @@ cleanxen:
 	$(MAKE) -C xsrpc clean
 	$(MAKE) -C eventchn clean
 
-RPM_SPECSDIR=/usr/src/redhat/SPECS
-RPM_SOURCEDIR=/usr/src/redhat/SOURCES
+RPM_SPECSDIR=$(shell rpm --eval='%_specdir')
+RPM_SOURCEDIR=$(shell rpm --eval='%_sourcedir')
 XEN_RELEASE=xcp0.2
 
 $(RPM_SPECSDIR)/xapi-libs.spec: xapi.spec.in
diff -r 3be1829b46b7 -r b4ef59ed08a9 Makefile.xcp
--- a/Makefile.xcp	Tue Oct 12 12:15:54 2010 +0100
+++ b/Makefile.xcp	Tue Dec 07 09:18:49 2010 -0500
@@ -6,9 +6,9 @@ MY_OUTPUT_DIR ?= $(CURDIR)/output
 MY_OBJ_DIR ?= $(CURDIR)/obj
 REPO ?= $(CURDIR)
 
-RPM_SPECSDIR?=/usr/src/redhat/SPECS
-RPM_SRPMSDIR?=/usr/src/redhat/SRPMS
-RPM_SOURCEDIR?=/usr/src/redhat/SOURCES
+RPM_SPECSDIR?=$(shell rpm --eval='%_specdir')
+RPM_SRPMSDIR?=$(shell rpm --eval='%_srcrpmdir')
+RPM_SOURCEDIR?=$(shell rpm --eval='%_sourcedir')
 XEN_RELEASE?=unknown
 endif

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 2 of 5] xc: split xc non-upstream bindings into xcext module
       [not found]         ` <patchbomb.1291732379-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-12-07 14:33           ` Ian Campbell
  2010-12-07 14:33           ` [PATCH 3 of 5] add configure-time option to use system installed Xen library bindings Ian Campbell
  2010-12-07 14:33           ` [PATCH 5 of 5] REBASE-4.1: xiu: add xenctrlosdep backend Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1291731529 18000
# Node ID cc5f6f7e18cf39cf8ed9112c52aebb9c1317f8f9
# Parent  b4ef59ed08a9a4c1387fd00cd79aec3398bca3f5
xc: split xc non-upstream bindings into xcext module.

move anything which is not provided by upstream libxc and the
associated ocaml bindings in a separate xcext library to ease
replacement of xc library by upstream version.

Some of this functionality could potentially be upstreamed straight
away but other bits rely on stuff from the XCP hypervisor patch queue.

One change of not is that Xcext.hvm_check_pvdriver expects that domid is always
an HVM domain. This matches the existing callsites (and the name) and reduces
cross talk between xc and xcext.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r b4ef59ed08a9 -r cc5f6f7e18cf Makefile.in
--- a/Makefile.in	Tue Dec 07 09:18:49 2010 -0500
+++ b/Makefile.in	Tue Dec 07 09:18:49 2010 -0500
@@ -41,6 +41,7 @@ ifeq ($(HAVE_XEN),1)
 	$(MAKE) -C xc
 	$(MAKE) -C xb
 	$(MAKE) -C xs
+	$(MAKE) -C xcext
 	$(MAKE) -C xsrpc
 	$(MAKE) -C eventchn
 	$(MAKE) -C cpuid
@@ -81,6 +82,7 @@ ifeq ($(HAVE_XEN),1)
 	$(MAKE) -C xc install
 	$(MAKE) -C xb install
 	$(MAKE) -C xs install
+	$(MAKE) -C xcext install
 	$(MAKE) -C xsrpc install
 	$(MAKE) -C eventchn install
 	$(MAKE) -C cpuid install
@@ -122,6 +124,7 @@ ifeq ($(HAVE_XEN),1)
 	$(MAKE) -C xs uninstall
 	$(MAKE) -C xb uninstall
 	$(MAKE) -C xc uninstall
+	$(MAKE) -C xcext uninstall
 	$(MAKE) -C mmap uninstall
 	$(MAKE) -C cpuid uninstall
 	$(MAKE) -C vhd uninstall
@@ -160,6 +163,7 @@ doc:
 	$(MAKE) -C xb doc
 	$(MAKE) -C xc doc
 	$(MAKE) -C xs doc
+	$(MAKE) -C xcext doc
 	$(MAKE) -C xml-light2 doc
 	$(MAKE) -C rpc-light doc
 	$(MAKE) -C http-svr doc
@@ -208,6 +212,7 @@ cleanxen:
 	$(MAKE) -C xc clean
 	$(MAKE) -C xb clean
 	$(MAKE) -C xs clean
+	$(MAKE) -C xcext clean
 	$(MAKE) -C xsrpc clean
 	$(MAKE) -C eventchn clean
 
diff -r b4ef59ed08a9 -r cc5f6f7e18cf cpuid/META.in
--- a/cpuid/META.in	Tue Dec 07 09:18:49 2010 -0500
+++ b/cpuid/META.in	Tue Dec 07 09:18:49 2010 -0500
@@ -1,5 +1,5 @@
 version = "@VERSION@"
 description = "Cpuid extension"
-requires = "stdext xc xen-utils"
+requires = "stdext xc xcext xen-utils"
 archive(byte) = "cpuid.cma"
 archive(native) = "cpuid.cmxa"
diff -r b4ef59ed08a9 -r cc5f6f7e18cf cpuid/Makefile
--- a/cpuid/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/cpuid/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -2,7 +2,7 @@ CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include
 OCAMLC = ocamlc -g
 OCAMLOPT = ocamlopt
-INCLUDES = -I ../stdext -I ../xc -I ../xen-utils
+INCLUDES = -I ../stdext -I ../xc -I ../xcext -I ../xen-utils
 
 LDFLAGS = -cclib -L./
 
@@ -65,7 +65,7 @@ uninstall:
 
 .PHONY: doc
 doc: $(INTF)
-	python ../doc/doc.py $(DOCDIR) "cpuid" "package" "$(OBJS)" "." "stdext xc xen-utils" ""
+	python ../doc/doc.py $(DOCDIR) "cpuid" "package" "$(OBJS)" "." "stdext xc xcext xen-utils" ""
 	
 clean:
 	rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS) *~ *.rej
diff -r b4ef59ed08a9 -r cc5f6f7e18cf cpuid/cpuid.ml
--- a/cpuid/cpuid.ml	Tue Dec 07 09:18:49 2010 -0500
+++ b/cpuid/cpuid.ml	Tue Dec 07 09:18:49 2010 -0500
@@ -138,7 +138,7 @@ let is_maskable manufacturer family mode
 
 let get_features_from_xen () =
 	let features = 
-	  try Xc.with_intf (fun xc -> Xc.get_boot_cpufeatures xc) 
+	  try Xc.with_intf (fun xc -> Xcext.get_boot_cpufeatures xc) 
 	  with _ -> 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l 
 	in
 	match features with
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xapi-libs.spec
--- a/xapi-libs.spec	Tue Dec 07 09:18:49 2010 -0500
+++ b/xapi-libs.spec	Tue Dec 07 09:18:49 2010 -0500
@@ -341,6 +341,14 @@ rm -rf $RPM_BUILD_ROOT
    /usr/lib/ocaml/xc/xc.cmi
    /usr/lib/ocaml/xc/xc.cmx
    /usr/lib/ocaml/xc/xc.cmxa
+   /usr/lib/ocaml/xcext/META
+   /usr/lib/ocaml/xcext/dllxcext_stubs.so
+   /usr/lib/ocaml/xcext/libxcext_stubs.a
+   /usr/lib/ocaml/xcext/xcext.a
+   /usr/lib/ocaml/xcext/xcext.cma
+   /usr/lib/ocaml/xcext/xcext.cmi
+   /usr/lib/ocaml/xcext/xcext.cmx
+   /usr/lib/ocaml/xcext/xcext.cmxa
    /usr/lib/ocaml/xs/META
    /usr/lib/ocaml/xs/queueop.cmx
    /usr/lib/ocaml/xs/xs.a
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc.h
--- a/xc/xc.h	Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc.h	Tue Dec 07 09:18:49 2010 -0500
@@ -31,20 +31,9 @@
 #include <xen/hvm/params.h>
 #include "xc_e820.h"
 
-#ifndef XEN_DOMCTL_get_runstate_info
-#warning "runstate info is missing"
-typedef struct {
-	int32_t state;
-	uint32_t missed_changes;
-	uint64_t state_entry_time;
-	uint64_t time[6];
-} xen_domctl_runstate_info_t;
-#endif
-
 typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
 typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
-typedef xen_domctl_runstate_info_t xc_runstate_info_t;
 
 struct xc_core_header {
 	unsigned int xch_magic;
@@ -111,14 +100,11 @@ int xc_domain_memory_populate_physmap(in
                                       unsigned int extent_order,
                                       unsigned int address_bits,
                                       xen_pfn_t *extent_start);
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist);
 int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max);
 int xc_domain_sethandle(int handle, unsigned int domid,
                         xen_domain_handle_t dhandle);
 int xc_vcpu_getinfo(int handle, unsigned int domid, unsigned int vcpu,
                     xc_vcpuinfo_t *info);
-int xc_get_runstate_info(int handle, unsigned int domid,
-			 xc_runstate_info_t *info);
 int xc_domain_ioport_permission(int handle, unsigned int domid,
                                 unsigned int first_port, unsigned int nr_ports,
                                 unsigned int allow_access);
@@ -158,7 +144,6 @@ int xc_shadow_allocation_set(int handle,
 			     uint32_t mb);
 int xc_domain_get_pfn_list(int handle, unsigned int domid,
                            xen_pfn_t *pfn_array, unsigned long max_pfns);
-int xc_hvm_check_pvdriver(int handle, unsigned int domid);
 
 int xc_domain_assign_device(int handle, unsigned int domid,
                             int domain, int bus, int slot, int func);
@@ -177,18 +162,6 @@ int xc_domain_cpuid_set(int xc, unsigned
 int xc_domain_cpuid_apply(int xc, unsigned int domid, int hvm);
 int xc_cpuid_check(uint32_t input, uint32_t optsubinput,
                    char *config[4], char *config_out[4]);
-int xc_domain_suppress_spurious_page_faults(int xc, uint32_t domid);
-
-int xc_domain_send_s3resume(int handle, unsigned int domid);
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align);
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet);
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode);
-int xc_domain_get_acpi_s_state(int handle, unsigned int domid);
-int xc_domain_trigger_power(int handle, unsigned int domid);
-int xc_domain_trigger_sleep(int handle, unsigned int domid);
-
-int xc_get_boot_cpufeatures(int handle, uint32_t *, uint32_t *, uint32_t *,
-	uint32_t *, uint32_t *, uint32_t *, uint32_t *, uint32_t *);
 
 #if XEN_SYSCTL_INTERFACE_VERSION >= 6
 #define SAFEDIV(a, b)					(((b) >= 0) ? (a) / (b) : (a))
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc.ml
--- a/xc/xc.ml	Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc.ml	Tue Dec 07 09:18:49 2010 -0500
@@ -26,18 +26,6 @@ type vcpuinfo =
 	cpumap: int32;
 }
 
-type runstateinfo = {
-  state : int32;
-  missed_changes: int32;
-  state_entry_time : int64;
-  time0 : int64;
-  time1 : int64;
-  time2 : int64;
-  time3 : int64;
-  time4 : int64;
-  time5 : int64;
-}
-
 type domaininfo =
 {
 	domid             : domid;
@@ -138,9 +126,6 @@ external _domain_sethandle: handle -> do
 let domain_sethandle handle n uuid =
 	_domain_sethandle handle n (Uuid.int_array_of_uuid uuid)
 
-external domain_setvmxassist: handle -> domid -> bool -> unit
-       = "stub_xc_domain_setvmxassist"
-
 external domain_max_vcpus: handle -> domid -> int -> unit
        = "stub_xc_domain_max_vcpus"
 
@@ -168,8 +153,6 @@ external domain_getinfo: handle -> domid
 
 external domain_get_vcpuinfo: handle -> int -> int -> vcpuinfo
        = "stub_xc_vcpu_getinfo"
-external domain_get_runstate_info : handle -> int -> runstateinfo
-  = "stub_xc_get_runstate_info"
 
 external domain_ioport_permission: handle -> domid -> int -> int -> bool -> unit
        = "stub_xc_domain_ioport_permission"
@@ -243,23 +226,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_suppress_spurious_page_faults: handle -> domid -> unit
-       = "stub_xc_domain_suppress_spurious_page_faults"
-
-external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit = "stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
-
-external domain_trigger_power: handle -> domid -> unit = "stub_xc_domain_trigger_power"
-external domain_trigger_sleep: handle -> domid -> unit = "stub_xc_domain_trigger_sleep"
-
-(** check if some hvm domain got pv driver or not *)
-external hvm_check_pvdriver: handle -> domid -> bool
-       = "stub_xc_hvm_check_pvdriver"
-
 external version: handle -> version = "stub_xc_version_version"
 external version_compile_info: handle -> compile_info
        = "stub_xc_version_compile_info"
@@ -270,9 +236,6 @@ external version_capabilities: handle ->
 external watchdog : handle -> int -> int32 -> int
   = "stub_xc_watchdog"
 
-external get_boot_cpufeatures: handle ->
-	(int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xc_get_boot_cpufeatures"
-
 (* core dump structure *)
 type core_magic = Magic_hvm | Magic_pv
 
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc.mli
--- a/xc/xc.mli	Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc.mli	Tue Dec 07 09:18:49 2010 -0500
@@ -19,17 +19,6 @@ type vcpuinfo = {
   cputime : int64;
   cpumap : int32;
 }
-type runstateinfo = {
-  state : int32;
-  missed_changes: int32;
-  state_entry_time : int64;
-  time0 : int64;
-  time1 : int64;
-  time2 : int64;
-  time3 : int64;
-  time4 : int64;
-  time5 : int64;
-}
 type domaininfo = {
   domid : domid;
   dying : bool;
@@ -89,8 +78,6 @@ val domain_create : handle -> int32 -> d
 external _domain_sethandle : handle -> domid -> int array -> unit
   = "stub_xc_domain_sethandle"
 val domain_sethandle : handle -> domid -> 'a Uuid.t -> unit
-external domain_setvmxassist: handle -> domid -> bool -> unit
-  = "stub_xc_domain_setvmxassist"
 external domain_max_vcpus : handle -> domid -> int -> unit
   = "stub_xc_domain_max_vcpus"
 external domain_pause : handle -> domid -> unit = "stub_xc_domain_pause"
@@ -107,8 +94,6 @@ external domain_getinfo : handle -> domi
   = "stub_xc_domain_getinfo"
 external domain_get_vcpuinfo : handle -> int -> int -> vcpuinfo
   = "stub_xc_vcpu_getinfo"
-external domain_get_runstate_info : handle -> int -> runstateinfo
-  = "stub_xc_get_runstate_info"
 external domain_ioport_permission: handle -> domid -> int -> int -> bool -> unit
        = "stub_xc_domain_ioport_permission"
 external domain_iomem_permission: handle -> domid -> nativeint -> nativeint -> bool -> unit
@@ -158,21 +143,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit
-  = "stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
-
-external domain_trigger_power: handle -> domid -> unit
-  = "stub_xc_domain_trigger_power"
-external domain_trigger_sleep: handle -> domid -> unit
-  = "stub_xc_domain_trigger_sleep"
-
-external hvm_check_pvdriver : handle -> domid -> bool
-  = "stub_xc_hvm_check_pvdriver"
 external version : handle -> version = "stub_xc_version_version"
 external version_compile_info : handle -> compile_info
   = "stub_xc_version_compile_info"
@@ -201,9 +171,6 @@ external domain_set_machine_address_size
 external domain_get_machine_address_size: handle -> domid -> int
        = "stub_xc_domain_get_machine_address_size"
 
-external domain_suppress_spurious_page_faults: handle -> domid -> unit
-       = "stub_xc_domain_suppress_spurious_page_faults"
-
 external domain_cpuid_set: handle -> domid -> bool -> (int64 * (int64 option))
                         -> string option array
                         -> string option array
@@ -212,7 +179,3 @@ external domain_cpuid_apply: handle -> d
        = "stub_xc_domain_cpuid_apply"
 external cpuid_check: (int64 * (int64 option)) -> string option array -> (bool * string option array)
        = "stub_xc_cpuid_check"
-
-external get_boot_cpufeatures: handle ->
-	(int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xc_get_boot_cpufeatures"
-
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc_lib.c
--- a/xc/xc_lib.c	Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc_lib.c	Tue Dec 07 09:18:49 2010 -0500
@@ -319,29 +319,6 @@ int xc_get_hvm_param(int handle, unsigne
 	return ret;
 }
 
-static int xc_set_hvm_param(int handle, unsigned int domid,
-                            int param, unsigned long value)
-{
-	struct xen_hvm_param arg = {
-		.domid = domid,
-		.index = param,
-		.value = value,
-	};
-	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_set_param, (unsigned long) &arg);
-	int ret;
-
-	if (mlock(&arg, sizeof(arg)) == -1) {
-		xc_error_set("mlock failed: %s", strerror(errno));
-		return -1;
-	}
-
-	ret = do_xen_hypercall(handle, &hypercall);
-	if (ret)
-		xc_error_hypercall(hypercall, ret);
-	munlock(&arg, sizeof(arg));
-	return ret;
-}
-
 /*---- XC API ----*/
 int xc_domain_create(int handle, unsigned int ssidref,
                      xen_domain_handle_t dhandle,
@@ -384,29 +361,6 @@ int xc_domain_unpause(int handle, unsign
 	return ret;
 }
 
-/* return 1 if hvm domain got pv driver, 0 if not. -1 is error occurs */
-int xc_hvm_check_pvdriver(int handle, unsigned int domid)
-{
-	int ret;
-	unsigned long irq = 0;
-	xc_domaininfo_t info;
-
-	ret = xc_domain_getinfolist(handle, domid, 1, &info);
-	if (ret != 1) {
-		xc_error_set("domain getinfo failed: %s", strerror(errno));
-		xc_error_dom_set(domid, "hvm_check_pvdriver");
-		return -1;
-	}
-
-	if (!info.flags & XEN_DOMINF_hvm_guest) {
-		xc_error_set("domain is not hvm");
-		xc_error_dom_set(domid, "hvm_check_pvdriver");
-		return -1;
-	}
-	xc_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
-	return irq;
-}
-
 static int modify_returncode_register(int handle, unsigned int domid)
 {
 	int ret;
@@ -769,21 +723,6 @@ int xc_domain_memory_populate_physmap(in
 	return 0;
 }
 
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist)
-{
-	int ret = 0;
-#ifdef XEN_DOMCTL_setvmxassist
-	DECLARE_DOMCTL(XEN_DOMCTL_setvmxassist, domid);
-	domctl.u.setvmxassist.use_vmxassist = use_vmxassist;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret)
-		xc_error_dom_set(domid, "setting vmxassist to %d",
-				 use_vmxassist);
-#endif
-	return ret;
-}
-
 int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max)
 {
 	int ret;
@@ -825,22 +764,6 @@ int xc_vcpu_getinfo(int handle, unsigned
 	return ret;
 }
 
-int xc_get_runstate_info(int handle, unsigned int domid,
-			 xc_runstate_info_t *info)
-{
-	int ret = -EBADF;
-#ifdef XEN_DOMCTL_get_runstate_info
-	DECLARE_DOMCTL(XEN_DOMCTL_get_runstate_info, domid);
-	ret = do_domctl(handle, &domctl);
-	if (ret < 0) {
-		xc_error_dom_set(domid, "get runstate info");
-		return ret;
-	}
-	memcpy(info, &domctl.u.domain_runstate, sizeof(*info));
-#endif
-	return ret;
-}
-
 int xc_domain_ioport_permission(int handle, unsigned int domid,
                                 unsigned int first_port, unsigned int nr_ports,
                                 unsigned int allow_access)
@@ -1515,119 +1438,6 @@ out:
 	return ret;
 }
 
-#ifndef HVM_PARAM_HPET_ENABLED
-#define HVM_PARAM_HPET_ENABLED 11
-#endif
-
-#ifndef HVM_PARAM_ACPI_S_STATE
-#define HVM_PARAM_ACPI_S_STATE 14
-#endif
-
-#ifndef HVM_PARAM_VPT_ALIGN
-#define HVM_PARAM_VPT_ALIGN 16
-#endif
-
-int xc_domain_send_s3resume(int handle, unsigned int domid)
-{
-	#define HVM_PARAM_ACPI_S_STATE 14
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 0);
-}
-
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode)
-{
-	return xc_set_hvm_param(handle, domid,
-	                        HVM_PARAM_TIMER_MODE, (unsigned long) mode);
-}
-
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) hpet);
-}
-
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align)
-{
-	return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) vpt_align);
-}
-
-int xc_domain_get_acpi_s_state(int handle, unsigned int domid)
-{
-	int ret;
-	unsigned long value;
-
-	ret = xc_get_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, &value);
-	if (ret != 0)
-		xc_error_dom_set(domid, "get acpi s-state");
-	return value;
-}
-
-int xc_domain_suppress_spurious_page_faults(int xc, uint32_t domid)
-{
-	int rc = 0;
-#ifdef XEN_DOMCTL_suppress_spurious_page_faults
-	DECLARE_DOMCTL(XEN_DOMCTL_suppress_spurious_page_faults, domid);
-
-	rc = do_domctl(xc, &domctl);
-	if (rc != 0)
-		xc_error_dom_set(domid, "suppress spurious page faults");
-#endif
-	return rc;
-}
-
-int xc_domain_trigger_power(int handle, unsigned int domid)
-{
-    int ret;
-
-    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
-    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_POWER;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_set("power button failed: %s", xc_error_get());
-    return ret;
-}
-
-int xc_domain_trigger_sleep(int handle, unsigned int domid)
-{
-    int ret;
-
-    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
-    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_SLEEP;
-
-	ret = do_domctl(handle, &domctl);
-	if (ret != 0)
-		xc_error_set("sleep button failed: %s", xc_error_get());
-    return ret;
-}
-
-int xc_get_boot_cpufeatures(int handle,
-                            uint32_t *base_ecx, uint32_t *base_edx,
-                            uint32_t *ext_ecx, uint32_t *ext_edx,
-                            uint32_t *masked_base_ecx, 
-                            uint32_t *masked_base_edx,
-                            uint32_t *masked_ext_ecx, 
-                            uint32_t *masked_ext_edx)
-{
-	int ret = -EINVAL;
-#ifdef XENPF_get_cpu_features 
-	DECLARE_PLATFORM(XENPF_get_cpu_features);
-
-	ret = do_platform(handle, &platform);
-	if (ret != 0)
-		xc_error_set("getting boot cpu features failed: %s", xc_error_get());
-	else {
-		*base_ecx = platform.u.cpu_features.base_ecx;
-		*base_edx = platform.u.cpu_features.base_edx;
-		*ext_ecx = platform.u.cpu_features.ext_ecx;
-		*ext_edx = platform.u.cpu_features.ext_edx;
-		*masked_base_ecx = platform.u.cpu_features.masked_base_ecx;
-		*masked_base_edx = platform.u.cpu_features.masked_base_edx;
-		*masked_ext_ecx = platform.u.cpu_features.masked_ext_ecx;
-		*masked_ext_edx = platform.u.cpu_features.masked_ext_edx;
-	}
-#endif
-	return ret;
-}
-
 /*
  * Local variables:
  *  indent-tabs-mode: t
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc_stubs.c
--- a/xc/xc_stubs.c	Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc_stubs.c	Tue Dec 07 09:18:49 2010 -0500
@@ -174,20 +174,6 @@ CAMLprim value stub_xc_domain_create(val
 	CAMLreturn(Val_int(domid));
 }
 
-CAMLprim value stub_xc_domain_setvmxassist(value xc_handle, value domid,
-					    value use_vmxassist)
-{
-	CAMLparam3(xc_handle, domid, use_vmxassist);
-	int r;
-
-	r = xc_domain_setvmxassist(_H(xc_handle), _D(domid),
-				   Bool_val(use_vmxassist));
-	if (r)
-		failwith_xc();
-
-	CAMLreturn(Val_unit);
-}
-
 CAMLprim value stub_xc_domain_max_vcpus(value xc_handle, value domid,
                                         value max_vcpus)
 {
@@ -387,41 +373,6 @@ CAMLprim value stub_xc_vcpu_getinfo(valu
 	CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_get_runstate_info(value xc_handle, value domid) 
-{
-	CAMLparam2(xc_handle, domid);
-	CAMLlocal1(result);
-	xc_runstate_info_t info;
-	int retval;
-	
-	int c_xc_handle = _H(xc_handle);
-	uint32_t c_domid = _D(domid);
-	retval = xc_get_runstate_info(c_xc_handle, c_domid, &info);
-	if (retval < 0)
-		failwith_xc();
-
-	/* Store 
-	   0 : state (int32)
-	   1 : missed_changes (int32)
-	   2 : state_entry_time (int64)
-	   3-8 : times (int64s)
-	*/
-	result = caml_alloc_tuple(9);
-	Store_field(result, 0, caml_copy_int32(info.state));
-	Store_field(result, 1, caml_copy_int32(info.missed_changes));
-	Store_field(result, 2, caml_copy_int64(info.state_entry_time));
-	Store_field(result, 3, caml_copy_int64(info.time[0]));
-	Store_field(result, 4, caml_copy_int64(info.time[1]));
-	Store_field(result, 5, caml_copy_int64(info.time[2]));
-	Store_field(result, 6, caml_copy_int64(info.time[3]));
-	Store_field(result, 7, caml_copy_int64(info.time[4]));
-	Store_field(result, 8, caml_copy_int64(info.time[5]));
-
-	CAMLreturn(result);
-}
-
-
-
 CAMLprim value stub_xc_vcpu_context_get(value xc_handle, value domid,
                                         value cpu)
 {
@@ -697,19 +648,6 @@ CAMLprim value stub_xc_domain_get_machin
 	CAMLreturn(Val_int(retval));
 }
 
-CAMLprim value stub_xc_domain_suppress_spurious_page_faults(value xc_handle,
-						       value domid)
-{
-	CAMLparam2(xc_handle, domid);
-	int c_xc_handle = _H(xc_handle);
-	uint32_t c_domid = _D(domid);
-
-	int retval = xc_domain_suppress_spurious_page_faults(c_xc_handle, c_domid);
-	if (retval)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
 CAMLprim value stub_xc_domain_cpuid_set(value xc_handle, value domid,
                                         value is_hvm, value input,
                                         value config)
@@ -1080,17 +1018,6 @@ CAMLprim value stub_xc_domain_irq_permis
 	CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_hvm_check_pvdriver(value xc_handle, value domid)
-{
-	CAMLparam2(xc_handle, domid);
-	int ret;
-
-	ret = xc_hvm_check_pvdriver(_H(xc_handle), _D(domid));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_bool(ret));
-}
-
 CAMLprim value stub_xc_domain_test_assign_device(value xc_handle, value domid, value desc)
 {
 	CAMLparam3(xc_handle, domid, desc);
@@ -1156,97 +1083,6 @@ CAMLprim value stub_xc_watchdog(value ha
 	CAMLreturn(Val_int(ret));
 }
 
-CAMLprim value stub_xc_domain_get_acpi_s_state(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	int ret;
-
-	ret = xc_domain_get_acpi_s_state(_H(handle), _D(domid));
-	if (ret < 0)
-		failwith_xc();
-
-	CAMLreturn(Val_int(ret));
-}
-
-CAMLprim value stub_xc_domain_send_s3resume(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	xc_domain_send_s3resume(_H(handle), _D(domid));
-	CAMLreturn(Val_unit);
-}
-
-
-CAMLprim value stub_xc_domain_set_timer_mode(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_timer_mode(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_hpet(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_hpet(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_vpt_align(value handle, value id, value mode)
-{
-	CAMLparam3(handle, id, mode);
-	int ret;
-
-	ret = xc_domain_set_vpt_align(_H(handle), _D(id), Int_val(mode));
-	if (ret < 0)
-		failwith_xc();
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_trigger_power(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	xc_domain_trigger_power(_H(handle), _D(domid));
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_trigger_sleep(value handle, value domid)
-{
-	CAMLparam2(handle, domid);
-	xc_domain_trigger_sleep(_H(handle), _D(domid));
-	CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_get_boot_cpufeatures(value handle)
-{
-	CAMLparam1(handle);
-	CAMLlocal1(v);
-	uint32_t a, b, c, d, e, f, g, h;
-	int ret;
-
-	ret = xc_get_boot_cpufeatures(_H(handle), &a, &b, &c, &d, &e, &f, &g, &h);
-	if (ret < 0)
-		failwith_xc();
-	
-	v = caml_alloc_tuple(8);
-	Store_field(v, 0, caml_copy_int32(a));
-	Store_field(v, 1, caml_copy_int32(b));
-	Store_field(v, 2, caml_copy_int32(c));
-	Store_field(v, 3, caml_copy_int32(d));
-	Store_field(v, 4, caml_copy_int32(e));
-	Store_field(v, 5, caml_copy_int32(f));
-	Store_field(v, 6, caml_copy_int32(g));
-	Store_field(v, 7, caml_copy_int32(h));
-
-	CAMLreturn(v);
-}
-
 /*
  * Local variables:
  *  indent-tabs-mode: t
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/META.in
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/META.in	Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,5 @@
+version = "@VERSION@"
+description = "Xen Control Interface (extensions)"
+requires = "mmap,uuid,xc"
+archive(byte) = "xcext.cma"
+archive(native) = "xcext.cmxa"
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,71 @@
+CC = gcc
+CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap -I./
+OCAMLC = ocamlc -g -I ../mmap -I ../uuid -I ../xc
+OCAMLOPT = ocamlopt
+OCAMLOPTFLAGS = -g -dtypes -I ../mmap -I ../uuid -I ../xc
+
+LDFLAGS = -cclib -L./
+
+VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0)
+
+OCAMLABI := $(shell ocamlc -version)
+OCAMLLIBDIR := $(shell ocamlc -where)
+OCAMLDESTDIR ?= $(OCAMLLIBDIR)
+
+OBJS = xcext
+INTF = xcext.cmi
+LIBS = xcext.cma xcext.cmxa
+
+DOCDIR = /myrepos/xen-api-libs.hg/doc
+
+all: $(INTF) $(LIBS) $(PROGRAMS)
+
+bins: $(PROGRAMS)
+
+libs: $(LIBS)
+
+xcext.cmxa: libxcext_stubs.a $(foreach obj,$(OBJS),$(obj).cmx)
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ -cclib -lxcext_stubs $(foreach obj,$(OBJS),$(obj).cmx)
+
+xcext.cma: $(foreach obj,$(OBJS),$(obj).cmo)
+	$(OCAMLC) -a -dllib dllxcext_stubs.so -cclib -lxcext_stubs -o $@ $(foreach obj,$(OBJS),$(obj).cmo)
+
+xcext_stubs.a: xcext_lib.o xcext_stubs.o
+	ocamlmklib -o xcext_stubs $+
+
+libxcext_stubs.a: xcext_lib.o xcext_stubs.o
+	ar rcs $@ $+
+	ocamlmklib -o xcext_stubs $+
+
+%.cmo: %.ml
+	$(OCAMLC) -c -o $@ $<
+
+%.cmi: %.mli
+	$(OCAMLC) -c -o $@ $<
+
+%.cmx: %.ml
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c -o $@ $<
+
+%.o: %.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+META: META.in
+	sed 's/@VERSION@/$(VERSION)/g' < $< > $@
+
+.PHONY: install
+install: path = $(DESTDIR)$(shell ocamlfind printconf destdir)
+install: $(LIBS) META
+	mkdir -p $(path)
+	ocamlfind install -destdir $(path) -ldconf ignore xcext META $(INTF) $(LIBS) *.a *.so *.cmx
+
+.PHONY: uninstall
+uninstall:
+	ocamlfind remove xcext
+
+.PHONY: doc
+doc: $(INTF)
+	python ../doc/doc.py $(DOCDIR) "xcext" "package" "$(OBJS)" "." "mmap,uuid" ""
+	
+clean:
+	rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS) $(INTF) *~ *.rej *.orig
+
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext.h	Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#define __XEN_TOOLS__
+
+#include <xen/xen.h>
+#include <xen/memory.h>
+#include <xen/sysctl.h>
+#include <xen/domctl.h>
+#include <xen/sched.h>
+#include <xen/platform.h>
+#if XEN_SYSCTL_INTERFACE_VERSION < 4
+#include <xen/linux/privcmd.h>
+#else
+#include <xen/sys/privcmd.h>
+#endif
+#include <xen/version.h>
+#include <xen/foreign/x86_32.h>
+#include <xen/foreign/x86_64.h>
+#include <xen/hvm/params.h>
+
+#ifndef XEN_DOMCTL_get_runstate_info
+#warning "runstate info is missing"
+typedef struct {
+	int32_t state;
+	uint32_t missed_changes;
+	uint64_t state_entry_time;
+	uint64_t time[6];
+} xen_domctl_runstate_info_t;
+#endif
+
+typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
+typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
+typedef xen_sysctl_physinfo_t xc_physinfo_t;
+typedef xen_domctl_runstate_info_t xc_runstate_info_t;
+
+char * xcext_error_get(void);
+void xcext_error_clear(void);
+
+int xcext_using_injection(void);
+
+int xcext_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist);
+int xcext_get_runstate_info(int handle, unsigned int domid,
+			 xc_runstate_info_t *info);
+
+int xcext_hvm_check_pvdriver(int handle, unsigned int domid);
+
+int xcext_domain_suppress_spurious_page_faults(int xc, uint32_t domid);
+
+int xcext_domain_send_s3resume(int handle, unsigned int domid);
+int xcext_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align);
+int xcext_domain_set_hpet(int handle, unsigned int domid, int hpet);
+int xcext_domain_set_timer_mode(int handle, unsigned int domid, int mode);
+int xcext_domain_get_acpi_s_state(int handle, unsigned int domid);
+int xcext_domain_trigger_power(int handle, unsigned int domid);
+int xcext_domain_trigger_sleep(int handle, unsigned int domid);
+
+int xcext_get_boot_cpufeatures(int handle, uint32_t *, uint32_t *, uint32_t *,
+	uint32_t *, uint32_t *, uint32_t *, uint32_t *, uint32_t *);
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext.ml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext.ml	Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,52 @@
+(*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+type runstateinfo = {
+  state : int32;
+  missed_changes: int32;
+  state_entry_time : int64;
+  time0 : int64;
+  time1 : int64;
+  time2 : int64;
+  time3 : int64;
+  time4 : int64;
+  time5 : int64;
+}
+
+
+external domain_setvmxassist: Xc.handle -> Xc.domid -> bool -> unit
+       = "stub_xcext_domain_setvmxassist"
+
+external domain_get_runstate_info : Xc.handle -> int -> runstateinfo
+       = "stub_xcext_get_runstate_info"
+ 
+external domain_suppress_spurious_page_faults: Xc.handle -> Xc.domid -> unit
+       = "stub_xcext_domain_suppress_spurious_page_faults"
+
+external domain_set_timer_mode: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_timer_mode"
+external domain_set_hpet: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_hpet"
+external domain_set_vpt_align: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_vpt_align"
+
+external domain_send_s3resume: Xc.handle -> Xc.domid -> unit = "stub_xcext_domain_send_s3resume"
+external domain_get_acpi_s_state: Xc.handle -> Xc.domid -> int = "stub_xcext_domain_get_acpi_s_state"
+
+external domain_trigger_power: Xc.handle -> Xc.domid -> unit = "stub_xcext_domain_trigger_power"
+external domain_trigger_sleep: Xc.handle -> Xc.domid -> unit = "stub_xcext_domain_trigger_sleep"
+
+(** check if some hvm domain got pv driver or not *)
+external hvm_check_pvdriver: Xc.handle -> Xc.domid -> bool
+       = "stub_xcext_hvm_check_pvdriver"
+
+external get_boot_cpufeatures: Xc.handle ->
+	(int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xcext_get_boot_cpufeatures"
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext.mli
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext.mli	Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,55 @@
+(*
+ * Copyright (C) 2006-2010 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+type runstateinfo = {
+  state : int32;
+  missed_changes: int32;
+  state_entry_time : int64;
+  time0 : int64;
+  time1 : int64;
+  time2 : int64;
+  time3 : int64;
+  time4 : int64;
+  time5 : int64;
+}
+
+external domain_setvmxassist: Xc.handle -> Xc.domid -> bool -> unit
+  = "stub_xcext_domain_setvmxassist"
+
+external domain_get_runstate_info : Xc.handle -> int -> runstateinfo
+  = "stub_xcext_get_runstate_info"
+
+external domain_set_timer_mode: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_timer_mode"
+external domain_set_hpet: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_hpet"
+external domain_set_vpt_align: Xc.handle -> Xc.domid -> int -> unit = "stub_xcext_domain_set_vpt_align"
+
+external domain_send_s3resume: Xc.handle -> Xc.domid -> unit
+  = "stub_xcext_domain_send_s3resume"
+external domain_get_acpi_s_state: Xc.handle -> Xc.domid -> int
+  = "stub_xcext_domain_get_acpi_s_state"
+
+external domain_trigger_power: Xc.handle -> Xc.domid -> unit
+  = "stub_xcext_domain_trigger_power"
+external domain_trigger_sleep: Xc.handle -> Xc.domid -> unit
+  = "stub_xcext_domain_trigger_sleep"
+
+external hvm_check_pvdriver : Xc.handle -> Xc.domid -> bool
+  = "stub_xcext_hvm_check_pvdriver"
+
+external domain_suppress_spurious_page_faults: Xc.handle -> Xc.domid -> unit
+       = "stub_xcext_domain_suppress_spurious_page_faults"
+
+external get_boot_cpufeatures: Xc.handle ->
+	(int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xcext_get_boot_cpufeatures"
+
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext_lib.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext_lib.c	Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,372 @@
+/*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include <stdint.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "xcext.h"
+
+#define PAGE_SHIFT		12
+#define PAGE_SIZE               (1UL << PAGE_SHIFT)
+#define PAGE_MASK               (~(PAGE_SIZE-1))
+
+#define MIN(a, b) 		(((a) < (b)) ? (a) : (b))
+
+#define DECLARE_DOMCTL(_cmd, _domain)	\
+	struct xen_domctl domctl = {    \
+		.cmd = _cmd,		\
+		.domain = _domain,	\
+		.interface_version = XEN_DOMCTL_INTERFACE_VERSION, \
+	}
+
+#define DECLARE_PLATFORM(_cmd)		\
+	struct xen_platform_op platform = { \
+		.cmd = _cmd,		\
+		.interface_version = XENPF_INTERFACE_VERSION, \
+	}
+
+#define DECLARE_HYPERCALL2(_cmd, _arg0, _arg1)	\
+	privcmd_hypercall_t hypercall = {	\
+		.op = _cmd,			\
+		.arg[0] = (unsigned long) _arg0,\
+		.arg[1] = (unsigned long) _arg1,\
+	}
+#define DECLARE_HYPERCALL0(_cmd)	DECLARE_HYPERCALL2(_cmd, 0, 0);
+#define DECLARE_HYPERCALL1(_cmd, _arg0)	DECLARE_HYPERCALL2(_cmd, _arg0, 0);
+
+/*---- Errors handlings ----*/
+#ifndef WITHOUT_GOOD_ERROR
+#define ERROR_STRLEN 256
+
+static char __error_str[ERROR_STRLEN];
+
+char * xcext_error_get(void)
+{
+	return __error_str;
+}
+
+static void xcext_error_set(const char *fmt, ...)
+{
+	va_list ap;
+	char __errordup[ERROR_STRLEN];
+
+	va_start(ap, fmt);
+	vsnprintf(__errordup, ERROR_STRLEN, fmt, ap);
+	va_end(ap);
+	memcpy(__error_str, __errordup, ERROR_STRLEN);
+}
+
+static void xcext_error_dom_set(unsigned int domid, const char *fmt, ...)
+{
+	va_list ap;
+	char __errordup[ERROR_STRLEN];
+	int i;
+
+	i = snprintf(__errordup, ERROR_STRLEN, "domain %u - ", domid);
+	va_start(ap, fmt);
+	i += vsnprintf(__errordup + i, ERROR_STRLEN - i, fmt, ap);
+	va_end(ap);
+	snprintf(__errordup + i, ERROR_STRLEN - i,
+	         " failed: %s", xcext_error_get());
+	memcpy(__error_str, __errordup, ERROR_STRLEN);
+}
+
+void xcext_error_clear(void)
+{
+	memset(__error_str, '\0', ERROR_STRLEN);
+}
+#else
+char * xcext_error_get(void)
+{
+	return "";
+}
+#define xcext_error_set(fmt, ...) do {} while (0)
+#define xcext_error_dom_set(id, fmt, ...) do {} while (0)
+#define xcext_error_clear() do {} while (0)
+#endif
+
+#define xcext_error_hypercall(_h, _r) \
+	xcext_error_set("hypercall %lld fail: %d: %s (ret %d)", _h.op, errno, errno ? strerror(errno) : strerror(-_r), _r)
+
+#define WITH_INJECTION_CAPABILITY
+#include "../xc/xc_lib_injection.c"
+
+
+/*---- Low private operations ----*/
+static int do_xen_hypercall(int handle, privcmd_hypercall_t *hypercall)
+{
+	pre_xen_hypercall(handle, hypercall);
+	return ioctl(handle, IOCTL_PRIVCMD_HYPERCALL, (unsigned long) hypercall);
+}
+
+static int do_domctl(int handle, struct xen_domctl *domctl)
+{
+	int ret;
+	DECLARE_HYPERCALL1(__HYPERVISOR_domctl, domctl);
+
+	if (mlock(domctl, sizeof(*domctl)) != 0) {
+		xcext_error_set("mlock failed: %s", strerror(errno));
+		return -1;
+	}
+
+	ret = do_xen_hypercall(handle, &hypercall);
+	if (ret < 0)
+		xcext_error_hypercall(hypercall, ret);
+
+	munlock(domctl, sizeof(*domctl));
+	return ret;
+}
+
+static int do_platform(int handle, struct xen_platform_op *platform)
+{
+	int ret;
+	DECLARE_HYPERCALL1(__HYPERVISOR_platform_op, platform);
+
+	if (mlock(platform, sizeof(*platform)) != 0) {
+		xcext_error_set("mlock failed: %s", strerror(errno));
+		return -1;
+	}
+
+	ret = do_xen_hypercall(handle, &hypercall);
+	if (ret < 0)
+		xcext_error_hypercall(hypercall, ret);
+
+	munlock(platform, sizeof(*platform));
+	return ret;
+}
+
+int xcext_get_hvm_param(int handle, unsigned int domid,
+                     int param, unsigned long *value)
+{
+	struct xen_hvm_param arg = {
+		.domid = domid,
+		.index = param,
+	};
+	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_get_param,
+	                   (unsigned long) &arg);
+	int ret;
+
+	if (mlock(&arg, sizeof(arg)) == -1) {
+		xcext_error_set("mlock failed: %s", strerror(errno));
+		return -1;
+	}
+
+	ret = do_xen_hypercall(handle, &hypercall);
+	if (ret)
+		xcext_error_hypercall(hypercall, ret);
+	*value = arg.value;
+	munlock(&arg, sizeof(arg));
+	return ret;
+}
+
+/* return 1 if hvm domain got pv driver, 0 if not. -1 is error occurs */
+int xcext_hvm_check_pvdriver(int handle, unsigned int domid)
+{
+	int ret;
+	unsigned long irq = 0;
+
+	ret = xcext_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
+	if (!ret) {
+		xcext_error_dom_set(domid, "hvm_check_pvdriver");
+		return -1;
+	}
+	return irq;
+}
+
+int xcext_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist)
+{
+	int ret = 0;
+#ifdef XEN_DOMCTL_setvmxassist
+	DECLARE_DOMCTL(XEN_DOMCTL_setvmxassist, domid);
+	domctl.u.setvmxassist.use_vmxassist = use_vmxassist;
+
+	ret = do_domctl(handle, &domctl);
+	if (ret)
+		xcext_error_dom_set(domid, "setting vmxassist to %d",
+				 use_vmxassist);
+#endif
+	return ret;
+}
+
+
+int xcext_get_runstate_info(int handle, unsigned int domid,
+			 xc_runstate_info_t *info)
+{
+	int ret = -EBADF;
+#ifdef XEN_DOMCTL_get_runstate_info
+	DECLARE_DOMCTL(XEN_DOMCTL_get_runstate_info, domid);
+	ret = do_domctl(handle, &domctl);
+	if (ret < 0) {
+		xcext_error_dom_set(domid, "get runstate info");
+		return ret;
+	}
+	memcpy(info, &domctl.u.domain_runstate, sizeof(*info));
+#endif
+	return ret;
+}
+
+
+#ifndef HVM_PARAM_HPET_ENABLED
+#define HVM_PARAM_HPET_ENABLED 11
+#endif
+
+#ifndef HVM_PARAM_ACPI_S_STATE
+#define HVM_PARAM_ACPI_S_STATE 14
+#endif
+
+#ifndef HVM_PARAM_VPT_ALIGN
+#define HVM_PARAM_VPT_ALIGN 16
+#endif
+
+static int xcext_set_hvm_param(int handle, unsigned int domid,
+			       int param, unsigned long value)
+{
+	struct xen_hvm_param arg = {
+		.domid = domid,
+		.index = param,
+		.value = value,
+	};
+	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_set_param, (unsigned long) &arg);
+	int ret;
+
+	if (mlock(&arg, sizeof(arg)) == -1) {
+		xcext_error_set("mlock failed: %s", strerror(errno));
+		return -1;
+	}
+
+	ret = do_xen_hypercall(handle, &hypercall);
+	if (ret)
+		xcext_error_hypercall(hypercall, ret);
+	munlock(&arg, sizeof(arg));
+	return ret;
+}
+
+int xcext_domain_send_s3resume(int handle, unsigned int domid)
+{
+	#define HVM_PARAM_ACPI_S_STATE 14
+	return xcext_set_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 0);
+}
+
+int xcext_domain_set_timer_mode(int handle, unsigned int domid, int mode)
+{
+	return xcext_set_hvm_param(handle, domid,
+	                        HVM_PARAM_TIMER_MODE, (unsigned long) mode);
+}
+
+int xcext_domain_set_hpet(int handle, unsigned int domid, int hpet)
+{
+	return xcext_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) hpet);
+}
+
+int xcext_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align)
+{
+	return xcext_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) vpt_align);
+}
+
+int xcext_domain_get_acpi_s_state(int handle, unsigned int domid)
+{
+	int ret;
+	unsigned long value;
+
+	ret = xcext_get_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, &value);
+	if (ret != 0)
+		xcext_error_dom_set(domid, "get acpi s-state");
+	return value;
+}
+
+int xcext_domain_suppress_spurious_page_faults(int xc, uint32_t domid)
+{
+	int rc = 0;
+#ifdef XEN_DOMCTL_suppress_spurious_page_faults
+	DECLARE_DOMCTL(XEN_DOMCTL_suppress_spurious_page_faults, domid);
+
+	rc = do_domctl(xc, &domctl);
+	if (rc != 0)
+		xcext_error_dom_set(domid, "suppress spurious page faults");
+#endif
+	return rc;
+}
+
+int xcext_domain_trigger_power(int handle, unsigned int domid)
+{
+    int ret;
+
+    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
+    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_POWER;
+
+	ret = do_domctl(handle, &domctl);
+	if (ret != 0)
+		xcext_error_set("power button failed: %s", xcext_error_get());
+    return ret;
+}
+
+int xcext_domain_trigger_sleep(int handle, unsigned int domid)
+{
+    int ret;
+
+    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
+    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_SLEEP;
+
+	ret = do_domctl(handle, &domctl);
+	if (ret != 0)
+		xcext_error_set("sleep button failed: %s", xcext_error_get());
+    return ret;
+}
+
+int xcext_get_boot_cpufeatures(int handle,
+                            uint32_t *base_ecx, uint32_t *base_edx,
+                            uint32_t *ext_ecx, uint32_t *ext_edx,
+                            uint32_t *masked_base_ecx, 
+                            uint32_t *masked_base_edx,
+                            uint32_t *masked_ext_ecx, 
+                            uint32_t *masked_ext_edx)
+{
+	int ret = -EINVAL;
+#ifdef XENPF_get_cpu_features 
+	DECLARE_PLATFORM(XENPF_get_cpu_features);
+
+	ret = do_platform(handle, &platform);
+	if (ret != 0)
+		xcext_error_set("getting boot cpu features failed: %s", xcext_error_get());
+	else {
+		*base_ecx = platform.u.cpu_features.base_ecx;
+		*base_edx = platform.u.cpu_features.base_edx;
+		*ext_ecx = platform.u.cpu_features.ext_ecx;
+		*ext_edx = platform.u.cpu_features.ext_edx;
+		*masked_base_ecx = platform.u.cpu_features.masked_base_ecx;
+		*masked_base_edx = platform.u.cpu_features.masked_base_edx;
+		*masked_ext_ecx = platform.u.cpu_features.masked_ext_ecx;
+		*masked_ext_edx = platform.u.cpu_features.masked_ext_edx;
+	}
+#endif
+	return ret;
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: t
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext_stubs.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext_stubs.c	Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2006-2010 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#define _XOPEN_SOURCE 600
+#include <stdlib.h>
+
+#define CAML_NAME_SPACE
+#include <caml/alloc.h>
+#include <caml/memory.h>
+#include <caml/signals.h>
+#include <caml/fail.h>
+#include <caml/callback.h>
+
+#include <sys/mman.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "xcext.h"
+
+#define _H(__h) (Int_val(__h))
+#define _D(__d) ((uint32_t)Int_val(__d))
+
+void failwith_xcext(void)
+{
+	caml_raise_with_string(*caml_named_value("xc.error"), xcext_error_get());
+}
+
+CAMLprim value stub_xcext_domain_setvmxassist(value xc_handle, value domid,
+					    value use_vmxassist)
+{
+	CAMLparam3(xc_handle, domid, use_vmxassist);
+	int r;
+
+	r = xcext_domain_setvmxassist(_H(xc_handle), _D(domid),
+				   Bool_val(use_vmxassist));
+	if (r)
+		failwith_xcext();
+
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_get_runstate_info(value xc_handle, value domid) {
+
+	CAMLparam2(xc_handle, domid);
+	CAMLlocal1(result);
+	xc_runstate_info_t info;
+	int retval;
+
+	int c_xc_handle = _H(xc_handle);
+	uint32_t c_domid = _D(domid);
+	retval = xcext_get_runstate_info(c_xc_handle, c_domid, &info);
+	if (retval < 0)
+	        failwith_xcext();
+
+	/* Store
+	   0 : state (int32)
+	   1 : missed_changes (int32)
+	   2 : state_entry_time (int64)
+	   3-8 : times (int64s)
+	*/
+	result = caml_alloc_tuple(9);
+	Store_field(result, 0, caml_copy_int32(info.state));
+	Store_field(result, 1, caml_copy_int32(info.missed_changes));
+	Store_field(result, 2, caml_copy_int64(info.state_entry_time));
+	Store_field(result, 3, caml_copy_int64(info.time[0]));
+	Store_field(result, 4, caml_copy_int64(info.time[1]));
+	Store_field(result, 5, caml_copy_int64(info.time[2]));
+	Store_field(result, 6, caml_copy_int64(info.time[3]));
+	Store_field(result, 7, caml_copy_int64(info.time[4]));
+	Store_field(result, 8, caml_copy_int64(info.time[5]));
+
+	CAMLreturn(result);
+}
+
+CAMLprim value stub_xcext_domain_suppress_spurious_page_faults(value xc_handle,
+						       value domid)
+{
+	CAMLparam2(xc_handle, domid);
+	int c_xc_handle = _H(xc_handle);
+	uint32_t c_domid = _D(domid);
+
+	int retval = xcext_domain_suppress_spurious_page_faults(c_xc_handle, c_domid);
+	if (retval)
+		failwith_xcext();
+	CAMLreturn(Val_unit);
+}
+
+
+CAMLprim value stub_xcext_hvm_check_pvdriver(value xc_handle, value domid)
+{
+	CAMLparam2(xc_handle, domid);
+	int ret;
+
+	ret = xcext_hvm_check_pvdriver(_H(xc_handle), _D(domid));
+	if (ret < 0)
+		failwith_xcext();
+	CAMLreturn(Val_bool(ret));
+}
+
+
+CAMLprim value stub_xcext_domain_get_acpi_s_state(value handle, value domid)
+{
+	CAMLparam2(handle, domid);
+	int ret;
+
+	ret = xcext_domain_get_acpi_s_state(_H(handle), _D(domid));
+	if (ret < 0)
+		failwith_xc();
+
+	CAMLreturn(Val_int(ret));
+}
+
+
+CAMLprim value stub_xcext_domain_send_s3resume(value handle, value domid)
+{
+	CAMLparam2(handle, domid);
+	xcext_domain_send_s3resume(_H(handle), _D(domid));
+	CAMLreturn(Val_unit);
+}
+
+
+CAMLprim value stub_xcext_domain_set_timer_mode(value handle, value id, value mode)
+{
+	CAMLparam3(handle, id, mode);
+	int ret;
+
+	ret = xcext_domain_set_timer_mode(_H(handle), _D(id), Int_val(mode));
+	if (ret < 0)
+		failwith_xcext();
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_set_hpet(value handle, value id, value mode)
+{
+	CAMLparam3(handle, id, mode);
+	int ret;
+
+	ret = xcext_domain_set_hpet(_H(handle), _D(id), Int_val(mode));
+	if (ret < 0)
+		failwith_xcext();
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_set_vpt_align(value handle, value id, value mode)
+{
+	CAMLparam3(handle, id, mode);
+	int ret;
+
+	ret = xcext_domain_set_vpt_align(_H(handle), _D(id), Int_val(mode));
+	if (ret < 0)
+		failwith_xcext();
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_trigger_power(value handle, value domid)
+{
+	CAMLparam2(handle, domid);
+	xcext_domain_trigger_power(_H(handle), _D(domid));
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_trigger_sleep(value handle, value domid)
+{
+	CAMLparam2(handle, domid);
+	xcext_domain_trigger_sleep(_H(handle), _D(domid));
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_get_boot_cpufeatures(value handle)
+{
+	CAMLparam1(handle);
+	CAMLlocal1(v);
+	uint32_t a, b, c, d, e, f, g, h;
+	int ret;
+
+	ret = xcext_get_boot_cpufeatures(_H(handle), &a, &b, &c, &d, &e, &f, &g, &h);
+	if (ret < 0)
+		failwith_xcext();
+
+	v = caml_alloc_tuple(8);
+	Store_field(v, 0, caml_copy_int32(a));
+	Store_field(v, 1, caml_copy_int32(b));
+	Store_field(v, 2, caml_copy_int32(c));
+	Store_field(v, 3, caml_copy_int32(d));
+	Store_field(v, 4, caml_copy_int32(e));
+	Store_field(v, 5, caml_copy_int32(f));
+	Store_field(v, 6, caml_copy_int32(g));
+	Store_field(v, 7, caml_copy_int32(h));
+
+	CAMLreturn(v);
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: t
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 3 of 5] add configure-time option to use system installed Xen library bindings
       [not found]         ` <patchbomb.1291732379-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:33           ` [PATCH 2 of 5] xc: split xc non-upstream bindings into xcext module Ian Campbell
@ 2010-12-07 14:33           ` Ian Campbell
  2010-12-07 14:33           ` [PATCH 5 of 5] REBASE-4.1: xiu: add xenctrlosdep backend Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1291731529 18000
# Node ID 4ddc7e5613c08fc203c13c55bbb84d2935f57c9b
# Parent  cc5f6f7e18cf39cf8ed9112c52aebb9c1317f8f9
add configure-time option to use system installed Xen library bindings.

Could be made to auto detect the Xen version but for now requires the user to
explicitly opt in.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r cc5f6f7e18cf -r 4ddc7e5613c0 Makefile.in
--- a/Makefile.in	Tue Dec 07 09:18:49 2010 -0500
+++ b/Makefile.in	Tue Dec 07 09:18:49 2010 -0500
@@ -5,9 +5,13 @@ HAVE_LINUX_CDROM = @LINUX_CDROM@
 HAVE_XMLM = @OCAML_PKG_xmlm@
 HAVE_TYPECONV = @OCAML_PKG_type_conv@
 
+include config.mk
+
 .PHONY: all
 all:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid
+endif
 ifeq ($(HAVE_TYPECONV),type-conv)
 	$(MAKE) -C rpc-light
 endif
@@ -36,21 +40,29 @@ endif
 .PHONY: allxen
 allxen:
 ifeq ($(HAVE_XEN),1)
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap
+endif
 	$(MAKE) -C netdev
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xc
 	$(MAKE) -C xb
 	$(MAKE) -C xs
+endif
 	$(MAKE) -C xcext
 	$(MAKE) -C xsrpc
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn
+endif
 	$(MAKE) -C cpuid
 	$(MAKE) -C vhd
 	$(MAKE) -C tapctl
 endif
 
 install:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid install
+endif
 	$(MAKE) -C stdext install
 	$(MAKE) -C log install
 	$(MAKE) -C stunnel install
@@ -77,21 +89,29 @@ endif
 
 installxen:
 ifeq ($(HAVE_XEN),1)
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap install
+endif
 	$(MAKE) -C netdev install
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xc install
 	$(MAKE) -C xb install
 	$(MAKE) -C xs install
+endif
 	$(MAKE) -C xcext install
 	$(MAKE) -C xsrpc install
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn install
+endif
 	$(MAKE) -C cpuid install
 	$(MAKE) -C vhd install
 	$(MAKE) -C tapctl install
 endif
 
 uninstall:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid uninstall
+endif
 	$(MAKE) -C stdext uninstall
 	$(MAKE) -C log uninstall
 	$(MAKE) -C stunnel uninstall
@@ -118,14 +138,20 @@ endif
 
 uninstallxen:
 ifeq ($(HAVE_XEN),1)
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn uninstall
+endif
 	$(MAKE) -C xsrpc uninstall
 	$(MAKE) -C netdev uninstall
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xs uninstall
 	$(MAKE) -C xb uninstall
 	$(MAKE) -C xc uninstall
+endif
 	$(MAKE) -C xcext uninstall
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap uninstall
+endif
 	$(MAKE) -C cpuid uninstall
 	$(MAKE) -C vhd uninstall
 	$(MAKE) -C tapctl uninstall
@@ -156,25 +182,33 @@ binuninstall:
 
 .PHONY: doc
 doc:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid doc
+endif
 	$(MAKE) -C stdext doc
 	$(MAKE) -C sexpr doc
 	$(MAKE) -C log doc
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xb doc
 	$(MAKE) -C xc doc
 	$(MAKE) -C xs doc
+endif
 	$(MAKE) -C xcext doc
 	$(MAKE) -C xml-light2 doc
 	$(MAKE) -C rpc-light doc
 	$(MAKE) -C http-svr doc
 	$(MAKE) -C camldm doc
 	$(MAKE) -C cdrom doc
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn doc
+endif
 	$(MAKE) -C pciutil doc
 	$(MAKE) -C rss doc
 	$(MAKE) -C stunnel doc
 	$(MAKE) -C xsrpc doc
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap doc
+endif
 	$(MAKE) -C netdev doc
 	$(MAKE) -C forking_executioner doc
 	$(MAKE) -C mlvm doc
@@ -185,7 +219,9 @@ doc:
 
 .PHONY: clean
 clean:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C uuid clean
+endif
 	$(MAKE) -C camldm clean
 	$(MAKE) -C stdext clean
 	$(MAKE) -C log clean
@@ -207,14 +243,20 @@ clean:
 	$(MAKE) -C xen-utils clean
 
 cleanxen:
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap clean
+endif
 	$(MAKE) -C netdev clean
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C xc clean
 	$(MAKE) -C xb clean
 	$(MAKE) -C xs clean
+endif
 	$(MAKE) -C xcext clean
 	$(MAKE) -C xsrpc clean
+ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C eventchn clean
+endif
 
 RPM_SPECSDIR=$(shell rpm --eval='%_specdir')
 RPM_SOURCEDIR=$(shell rpm --eval='%_sourcedir')
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 camldm/Makefile
--- a/camldm/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/camldm/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 cdrom/Makefile
--- a/cdrom/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/cdrom/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 close-and-exec/Makefile
--- a/close-and-exec/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/close-and-exec/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
@@ -29,7 +31,7 @@ bins: $(PROGRAMS)
 libs: $(LIBS)
 
 closeandexec: closeandexec.cmxa closeandexec_main.cmx all
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -I ../stdext -I ../uuid uuid.cmxa unix.cmxa threads.cmxa stdext.cmxa closeandexec.cmxa closeandexec_main.cmx -o $@ 
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -I ../stdext $(OCAML_UUID_INC) uuid.cmxa unix.cmxa threads.cmxa stdext.cmxa closeandexec.cmxa closeandexec_main.cmx -o $@ 
 
 closeandexec.cmxa: $(foreach obj,$(OBJS),$(obj).cmx)
 	$(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ $(foreach obj,$(OBJS),$(obj).cmx)
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 configure.ac
--- a/configure.ac	Tue Dec 07 09:18:49 2010 -0500
+++ b/configure.ac	Tue Dec 07 09:18:49 2010 -0500
@@ -30,6 +30,11 @@ AC_CHECK_HEADERS([xen/xen.h],[XEN=1],[XE
 AC_CHECK_HEADERS([libdevmapper.h], [DEVICE_MAPPER=1], [DEVICE_MAPPER=0])
 AC_CHECK_HEADERS([linux/cdrom.h], [LINUX_CDROM=1], [LINUX_CDROM=0])
 
+HAVE_XEN_SYSTEM_BINDINGS=0 # could do more intelligent detection here... 
+AC_ARG_WITH(xen-system-bindings, AS_HELP_STRING([--without-xen-system-bindings],[do not use the system installed xen bindings]),
+	[if test "x$withval" = "xno"; then WITH_XEN_SYSTEM_BINDINGS=0; else WITH_XEN_SYSTEM_BINDINGS=1; fi],
+	[WITH_XEN_SYSTEM_BINDINGS=$HAVE_XEN_SYSTEM_BINDINGS])
+
 # Checks for typedefs, structures, and compiler characteristics.
 AC_CHECK_DECLS([XS_RESTRICT],[],[],[
 [
@@ -54,8 +59,9 @@ fi
 AC_CHECK_OCAML_PKG([xmlm])
 AC_CHECK_OCAML_PKG([type-conv])
 
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile config.mk])
 AC_SUBST([XEN])
+AC_SUBST([WITH_XEN_SYSTEM_BINDINGS])
 AC_SUBST([DEVICE_MAPPER])
 AC_SUBST([LINUX_CDROM])
 AC_SUBST([OCAML_PKG_xmlm])
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 cpuid/Makefile
--- a/cpuid/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/cpuid/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,8 +1,10 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include
 OCAMLC = ocamlc -g
 OCAMLOPT = ocamlopt
-INCLUDES = -I ../stdext -I ../xc -I ../xcext -I ../xen-utils
+INCLUDES = -I ../stdext $(OCAML_XC_INC) -I ../xcext -I ../xen-utils
 
 LDFLAGS = -cclib -L./
 
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 doc/Makefile
--- a/doc/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/doc/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 .PHONY: clean
 clean:
 	rm -rf components.js content
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 eventchn/Makefile
--- a/eventchn/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/eventchn/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 forking_executioner/Makefile
--- a/forking_executioner/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/forking_executioner/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
@@ -31,19 +33,19 @@ bins: $(PROGRAMS)
 libs: $(LIBS)
 
 test_forker: test_forker.cmx
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../uuid -I ../stdext uuid.cmxa rpc.cmx jsonrpc.cmx -I ../log unix.cmxa stdext.cmxa  test_forker.cmx -o $@
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light $(OCAML_UUID_INC) -I ../stdext uuid.cmxa rpc.cmx jsonrpc.cmx -I ../log unix.cmxa stdext.cmxa  test_forker.cmx -o $@
 
 fe: fe_debug.cmx child.cmx fe_main.cmx
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../stdext -I ../uuid -I ../log log.cmxa uuid.cmxa unix.cmxa rpc.cmx jsonrpc.cmx stdext.cmxa fe_debug.cmx child.cmx fe_main.cmx -o $@ 
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../stdext $(OCAML_UUID_INC) -I ../log log.cmxa uuid.cmxa unix.cmxa rpc.cmx jsonrpc.cmx stdext.cmxa fe_debug.cmx child.cmx fe_main.cmx -o $@ 
 
 %.cmo: %.ml
-	$(OCAMLC) -c -I ../log -I ../uuid -I ../stdext -thread -o $@  $<
+	$(OCAMLC) -c -I ../log $(OCAML_UUID_INC) -I ../stdext -thread -o $@  $<
 
 %.cmi: %.mli
-	$(OCAMLC) -c -I ../log -I ../uuid -I ../stdext -o $@  $<
+	$(OCAMLC) -c -I ../log $(OCAML_UUID_INC) -I ../stdext -o $@  $<
 
 %.cmx: %.ml
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../log -I ../uuid -c -I ../stdext -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../log $(OCAML_UUID_INC) -c -I ../stdext -o $@ $<
 
 META: META.in
 	sed 's/@VERSION@/$(VERSION)/g' < $< > $@
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 http-svr/Makefile
--- a/http-svr/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/http-svr/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 log/Makefile
--- a/log/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/log/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 OCAMLLOC := $(shell ocamlc -where)
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml -I$(OCAMLLOC)
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 mk/Makefile
--- a/mk/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/mk/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 ifdef B_BASE
 include $(B_BASE)/common.mk
 include $(B_BASE)/rpmbuild.mk
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 mlvm/Makefile
--- a/mlvm/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/mlvm/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,4 @@
+include ../config.mk
 
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
@@ -18,7 +19,7 @@ INTF = $(foreach obj, $(LIBOBJS),$(obj).
 CMDOBJS = messages.cmx mlvm.cmx
 OCAMLC = ocamlfind ocamlc -g
 OCAMLOPT = ocamlfind ocamlopt 
-COMPFLAG = -dtypes -g -I ../stdext -I ../camldm -I ../uuid -for-pack Lvm -pp '${PP}' -I ../rpc-light
+COMPFLAG = -dtypes -g -I ../stdext -I ../camldm $(OCAML_UUID_INC) -for-pack Lvm -pp '${PP}' -I ../rpc-light
 
 LIBS = lvm.cma lvm.cmxa
 
@@ -27,7 +28,7 @@ DOCDIR = /myrepos/xen-api-libs.hg/doc
 default : $(LIBS)
 
 test_allocator: default
-	$(OCAMLOPT) -package kaputt -linkpkg -dtypes -g  -I ../stdext -I ../camldm -I ../uuid -I +kaputt unix.cmxa ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx ../camldm/camldm.cmxa ../uuid/uuid.cmxa ../stdext/stdext.cmxa ./lvm.cmxa test_allocator.ml -o $@
+	$(OCAMLOPT) -package kaputt -linkpkg -dtypes -g  -I ../stdext -I ../camldm $(OCAML_UUID_INC) -I +kaputt unix.cmxa ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx ../camldm/camldm.cmxa $(OCAML_UUID_DIR)/uuid.cmxa ../stdext/stdext.cmxa ./lvm.cmxa test_allocator.ml -o $@
 
 lvm.cmx: $(foreach obj,$(LIBOBJS),$(obj).cmx)
 	$(OCAMLOPT) -pack -g -o $@ $(foreach obj,$(LIBOBJS),$(obj).cmx)
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 mmap/Makefile
--- a/mmap/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/mmap/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 netdev/Makefile
--- a/netdev/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/netdev/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 pciutil/Makefile
--- a/pciutil/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/pciutil/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
@@ -29,7 +31,7 @@ bins: $(PROGRAMS)
 libs: $(LIBS)
 
 pciutil: pciutil_main.cmx
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ./ -I ../stdext -I ../uuid unix.cmxa uuid.cmxa stdext.cmxa pciutil.cmx -o $@ $^
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ./ -I ../stdext $(OCAML_UUID_INC) unix.cmxa uuid.cmxa stdext.cmxa pciutil.cmx -o $@ $^
 
 pciutil.cmxa: $(foreach obj,$(OBJS),$(obj).cmx)
 	$(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ $(foreach obj,$(OBJS),$(obj).cmx)
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 rpc-light/Makefile
--- a/rpc-light/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/rpc-light/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 OCAMLC = ocamlfind ocamlc
 OCAMLOPT = ocamlfind ocamlopt
 OCAMLFLAGS = -annot -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 rss/Makefile
--- a/rss/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/rss/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 sexpr/Makefile
--- a/sexpr/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/sexpr/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 stdext/Makefile
--- a/stdext/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/stdext/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 CC = gcc
 OCAMLLOC := $(shell ocamlc -where)
@@ -17,6 +19,9 @@ OCAMLDESTDIR ?= $(OCAMLLIBDIR)
 
 FEPP = camlp4o -I ../rpc-light -I $(shell ocamlfind query type-conv) pa_type_conv.cmo pa_rpc.cma
 
+OCAML_UUID_INC = -I $(OCAML_UUID_DIR)
+OCAML_UUID_LIB = $(OCAML_UUID_DIR)/uuid.cmxa
+
 OCAML_TEST_INC = -I $(shell ocamlfind query oUnit)
 OCAML_TEST_LIB = $(shell ocamlfind query oUnit)/oUnit.cmxa
 
@@ -75,10 +80,10 @@ base64pp: base64_main.ml all libstdext_s
 	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) stdext.cmxa -linkpkg -o $@ $< -ccopt -L.
 
 fe_cli: fe_cli.ml all libstdext_stubs.a
-	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa ../uuid/uuid.cmxa ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx stdext.cmxa -linkpkg -o $@ $< -ccopt -L.
+	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa $(OCAML_UUID_LIB) ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx stdext.cmxa -linkpkg -o $@ $< -ccopt -L.
 
 fe_test: fe_test.ml all libstdext_stubs.a
-	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa ../uuid/uuid.cmxa ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx stdext.cmxa -linkpkg -I ../uuid -o $@ $< -ccopt -L.
+	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa $(OCAML_UUID_LIB) ../rpc-light/rpc.cmx ../rpc-light/jsonrpc.cmx stdext.cmxa -linkpkg $(OCAML_UUID_INC) -o $@ $< -ccopt -L.
 
 extentlistset_test: extentlistset_test.ml all libstdext_stubs.a
 	ocamlfind $(OCAMLOPT) $(OCAMLOPTFLAGS) unix.cmxa stdext.cmxa -linkpkg -o $@ $< -ccopt -L.
@@ -111,10 +116,10 @@ fe.cmo: fe.ml
 	$(OCAMLC) -pp '$(FEPP)' -I ../jsonrpc -I ../rpc-light -c -o $@ $<
 
 forkhelpers.cmo: forkhelpers.ml forkhelpers.cmi
-	$(OCAMLC) -thread -I ../uuid -c -o $@ $<
+	$(OCAMLC) -thread $(OCAML_UUID_INC) -c -o $@ $<
 
 filenameext.cmo: filenameext.ml filenameext.cmi
-	$(OCAMLC) -c -I ../uuid -o $@ $<
+	$(OCAMLC) -c $(OCAML_UUID_INC) -o $@ $<
 
 %.cmo: %.ml %.cmi
 	$(OCAMLC) -c -o $@ $<
@@ -126,7 +131,7 @@ forkhelpers.cmi: forkhelpers.mli
 	$(OCAMLC) -thread -c -o $@ $<
 
 filenameext.cmi: filenameext.mli
-	$(OCAMLC) -c -I ../uuid -o $@ $<
+	$(OCAMLC) -c $(OCAML_UUID_INC) -o $@ $<
 
 fe.cmi: fe.cmo
 	$(OCAMLC) -pp '$(FEPP)' -c -o $@ $<
@@ -144,13 +149,13 @@ fecomms.cmx : fecomms.ml
 	$(OCAMLOPT) -I ../rpc-light -c -o $@ $<
 
 forkhelpers.cmx: forkhelpers.ml forkhelpers.cmi
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../uuid -thread -c -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAML_UUID_INC) -thread -c -o $@ $<
 
 filenameext.cmx: filenameext.ml filenameext.cmi
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -c -I ../uuid -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -c $(OCAML_UUID_INC) -o $@ $<
 
 %.cmx: %.ml %.cmi
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../uuid -c -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAML_UUID_INC) -c -o $@ $<
 
 %.o: %.c
 	$(CC) $(CFLAGS) -c -o $@ $<
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 stunnel/Makefile
--- a/stunnel/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/stunnel/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
 OCAMLC = ocamlc -g
@@ -31,13 +33,13 @@ stunnel.cma: $(foreach obj,$(OBJS),$(obj
 	$(OCAMLC) -a -o $@ $(foreach obj,$(OBJS),$(obj).cmo)
 
 %.cmo: %.ml
-	$(OCAMLC) -c -I ../stdext -I ../uuid -I ../log -o $@ $<
+	$(OCAMLC) -c -I ../stdext $(OCAML_UUID_INC) -I ../log -o $@ $<
 
 %.cmi: %.mli
-	$(OCAMLC) -c -I ../stdext -I ../uuid -o $@ $<
+	$(OCAMLC) -c -I ../stdext $(OCAML_UUID_INC) -o $@ $<
 
 %.cmx: %.ml
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c -I ../stdext -I ../uuid -I ../log -o $@ $<
+	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c -I ../stdext $(OCAML_UUID_INC) -I ../log -o $@ $<
 
 %.o: %.c
 	$(CC) $(CFLAGS) -c -o $@ $<
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 tapctl/Makefile
--- a/tapctl/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/tapctl/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 tests/Makefile
--- a/tests/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/tests/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 OCAMLC = ocamlfind ocamlc -g -package "unix,stdext,xc,xb,xs,mmap"
 OCAMLOPT = ocamlfind ocamlopt -package "unix,stdext,xc,xb,xs,mmap"
 
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 uuid/Makefile
--- a/uuid/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/uuid/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 vhd/Makefile
--- a/vhd/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/vhd/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,4 @@
+include ../config.mk
 
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -fno-strict-aliasing -D_FILE_OFFSET_BITS=64
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 xb/Makefile
--- a/xb/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/xb/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap
 OCAMLC = ocamlc -g -I ../mmap
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 xc/Makefile
--- a/xc/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,8 +1,10 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap -I./
-OCAMLC = ocamlc -g -I ../mmap -I ../uuid
+OCAMLC = ocamlc -g -I ../mmap $(OCAML_UUID_INC)
 OCAMLOPT = ocamlopt
-OCAMLOPTFLAGS = -g -dtypes -I ../mmap -I ../uuid
+OCAMLOPTFLAGS = -g -dtypes -I ../mmap $(OCAML_UUID_INC)
 
 LDFLAGS = -cclib -L./
 
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 xcext/Makefile
--- a/xcext/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/xcext/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,8 +1,10 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap -I./
-OCAMLC = ocamlc -g -I ../mmap -I ../uuid -I ../xc
+OCAMLC = ocamlc -g -I ../mmap -I ../uuid $(OCAML_XC_INC)
 OCAMLOPT = ocamlopt
-OCAMLOPTFLAGS = -g -dtypes -I ../mmap -I ../uuid -I ../xc
+OCAMLOPTFLAGS = -g -dtypes -I ../mmap -I ../uuid $(OCAML_XC_INC)
 
 LDFLAGS = -cclib -L./
 
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 xen-utils/Makefile
--- a/xen-utils/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/xen-utils/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml -I$(XEN_ROOT)/usr/include
 OCAMLC = ocamlc -g
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 xml-light2/Makefile
--- a/xml-light2/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/xml-light2/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,3 +1,5 @@
+include ../config.mk
+
 IPROG=install -m 755 -o root -g root
 OCAMLPACKS = xmlm
 
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 xs/Makefile
--- a/xs/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/xs/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,12 +1,14 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml
-OCAMLC = ocamlc -g -I ../xb/
+OCAMLC = ocamlc -g $(OCAML_XB_INC)
 OCAMLOPT = ocamlopt
 
 LDFLAGS = -cclib -L./
 
 VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0)
-OCAMLOPTFLAGS = -g -dtypes -I ../xb/
+OCAMLOPTFLAGS = -g -dtypes $(OCAML_XB_INC)
 
 OCAMLABI := $(shell ocamlc -version)
 OCAMLLIBDIR := $(shell ocamlc -where)
diff -r cc5f6f7e18cf -r 4ddc7e5613c0 xsrpc/Makefile
--- a/xsrpc/Makefile	Tue Dec 07 09:18:49 2010 -0500
+++ b/xsrpc/Makefile	Tue Dec 07 09:18:49 2010 -0500
@@ -1,12 +1,14 @@
+include ../config.mk
+
 CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
-OCAMLC = ocamlc -g -I ../xb/ -I ../xs/
+OCAMLC = ocamlc -g $(OCAML_XB_INC) $(OCAML_XS_INC)
 OCAMLOPT = ocamlopt
 
 LDFLAGS = -cclib -L./
 
 VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0)
-OCAMLOPTFLAGS = -g -dtypes -I ../xb/ -I ../xs/
+OCAMLOPTFLAGS = -g -dtypes $(OCAML_XB_INC) $(OCAML_XS_INC)
 
 OCAMLABI := $(shell ocamlc -version)
 OCAMLLIBDIR := $(shell ocamlc -where)

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 4 of 5] REBASE-4.1: default to using system installed bindings if Xen is available
  2010-12-07 14:32       ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
  2010-12-07 14:33         ` [PATCH 1 of 5] Query rpm to find build directories Ian Campbell
       [not found]         ` <patchbomb.1291732379-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-12-07 14:33         ` Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1291731529 18000
# Node ID 791652226f0e89265bf5ba50d0fe17c69a98dee7
# Parent  4ddc7e5613c08fc203c13c55bbb84d2935f57c9b
REBASE-4.1: default to using system installed bindings if Xen is available

(depends on global rebase to Xen 4.1)

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 4ddc7e5613c0 -r 791652226f0e configure.ac
--- a/configure.ac	Tue Dec 07 09:18:49 2010 -0500
+++ b/configure.ac	Tue Dec 07 09:18:49 2010 -0500
@@ -30,7 +30,7 @@ AC_CHECK_HEADERS([xen/xen.h],[XEN=1],[XE
 AC_CHECK_HEADERS([libdevmapper.h], [DEVICE_MAPPER=1], [DEVICE_MAPPER=0])
 AC_CHECK_HEADERS([linux/cdrom.h], [LINUX_CDROM=1], [LINUX_CDROM=0])
 
-HAVE_XEN_SYSTEM_BINDINGS=0 # could do more intelligent detection here... 
+HAVE_XEN_SYSTEM_BINDINGS=$XEN # could do more intelligent detection here... 
 AC_ARG_WITH(xen-system-bindings, AS_HELP_STRING([--without-xen-system-bindings],[do not use the system installed xen bindings]),
 	[if test "x$withval" = "xno"; then WITH_XEN_SYSTEM_BINDINGS=0; else WITH_XEN_SYSTEM_BINDINGS=1; fi],
 	[WITH_XEN_SYSTEM_BINDINGS=$HAVE_XEN_SYSTEM_BINDINGS])

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 5 of 5] REBASE-4.1: xiu: add xenctrlosdep backend
       [not found]         ` <patchbomb.1291732379-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:33           ` [PATCH 2 of 5] xc: split xc non-upstream bindings into xcext module Ian Campbell
  2010-12-07 14:33           ` [PATCH 3 of 5] add configure-time option to use system installed Xen library bindings Ian Campbell
@ 2010-12-07 14:33           ` Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1291731939 18000
# Node ID 6fbe1c0939894dd12e2df5e930fbe9f60d24b3d8
# Parent  791652226f0e89265bf5ba50d0fe17c69a98dee7
REBASE-4.1: xiu: add xenctrlosdep backend.

This interface was recently added to the upstream libxenctrl to allow
interception of the calls to the hypervisor.

Convert eventchn/eventchn_injection.c and xc/xc_lib_injection.c into an XIU
backend for this interface.

(depends on global rebase to Xen 4.1)

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 791652226f0e -r 6fbe1c093989 Makefile.in
--- a/Makefile.in	Tue Dec 07 09:18:49 2010 -0500
+++ b/Makefile.in	Tue Dec 07 09:25:39 2010 -0500
@@ -57,6 +57,7 @@ endif
 	$(MAKE) -C cpuid
 	$(MAKE) -C vhd
 	$(MAKE) -C tapctl
+	$(MAKE) -C fake
 endif
 
 install:
@@ -106,6 +107,7 @@ endif
 	$(MAKE) -C cpuid install
 	$(MAKE) -C vhd install
 	$(MAKE) -C tapctl install
+	$(MAKE) -C fake install
 endif
 
 uninstall:
@@ -155,6 +157,7 @@ endif
 	$(MAKE) -C cpuid uninstall
 	$(MAKE) -C vhd uninstall
 	$(MAKE) -C tapctl uninstall
+	$(MAKE) -C fake uninstall
 endif
 
 bins:
@@ -215,6 +218,7 @@ endif
 	$(MAKE) -C cpuid doc
 	$(MAKE) -C vhd doc
 	$(MAKE) -C tapctl doc
+	$(MAKE) -C fake doc
 	$(MAKE) -C xen-utils doc
 
 .PHONY: clean
@@ -243,6 +247,7 @@ endif
 	$(MAKE) -C xen-utils clean
 
 cleanxen:
+	$(MAKE) -C fake clean
 ifeq ($(WITH_XEN_SYSTEM_BINDINGS),0)
 	$(MAKE) -C mmap clean
 endif
diff -r 791652226f0e -r 6fbe1c093989 fake/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fake/Makefile	Tue Dec 07 09:25:39 2010 -0500
@@ -0,0 +1,27 @@
+CC := gcc
+
+CFLAGS := -O1
+CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -std=gnu99
+CFLAGS += -mno-tls-direct-seg-refs
+CFLAGS += -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -Werror -Wmissing-prototypes
+CFLAGS += -D__XEN_TOOLS__ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_GNU_SOURCE
+
+all: xenctrl_osdep_xiu.so
+	@:
+
+xeninterrcept_xiu.o: xenctrl_osdep_xiu.c
+	$(CC) $(CFLAGS) -c -o xenctrl_osdep_xiu.o xenctrl_osdep_xiu.c
+
+xenctrl_osdep_xiu.so: xenctrl_osdep_xiu.o
+	$(CC) $(CFLAGS) -shared -o xenctrl_osdep_xiu.so xenctrl_osdep_xiu.o -lxenctrl
+
+install: xenctrl_osdep_xiu.so
+	mkdir -p $$(DESTDIR)/opt/xensource/lib/xenctrl/
+	cp xenctrl_osdep_xiu.so $(DESTDIR)/opt/xensource/lib/xenctrl/osdep_xiu.so
+
+clean:
+	rm -f xeninterrcept_xiu.o
+	rm -f xenctrl_osdep_xiu.so
+
+uninstall:
+	rm -f $(DESTDIR)/opt/xensource/lib/xenctrl/osdep_xiu.so
diff -r 791652226f0e -r 6fbe1c093989 fake/xenctrl_osdep_xiu.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fake/xenctrl_osdep_xiu.c	Tue Dec 07 09:25:39 2010 -0500
@@ -0,0 +1,609 @@
+/*
+ * Copyright (C) 2010 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <xenctrl.h>
+#include <xenctrlosdep.h>
+
+#include "marshall.h"
+
+#define IPRINTF(_x, _f, _a...) xc_osdep_log(_x,XTL_INFO,0, _f , ## _a)
+
+#define ERROR(_x, _m, _a...)  xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## _a )
+#define PERROR(_x, _m, _a...) xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m \
+                  " (%d = %s)", ## _a , errno, xc_strerror(xch, errno))
+
+#define HYPCALLcmd "hypcall"
+
+static xc_osdep_handle xiu_privcmd_open(xc_interface *xch)
+{
+    struct sockaddr_un remote;
+    char *s;
+    int fd, len;
+
+    s = getenv("XIU");
+    if (!s)
+    {
+        ERROR(xch, "XIU not found. Set $XIU");
+        return XC_OSDEP_OPEN_ERROR;
+    }
+
+    snprintf(remote.sun_path, 256, "%s-xc", s);
+    remote.sun_family = AF_UNIX;
+    len = strlen(remote.sun_path) + sizeof(remote.sun_family);
+
+    fd = socket(AF_UNIX, SOCK_STREAM, 0);
+    if (fd == -1)
+    {
+        ERROR(xch, "XIU: Cannot open Unix domain socket");
+        return XC_OSDEP_OPEN_ERROR;
+    }
+
+    if (connect(fd, (struct sockaddr *)&remote, len) != 0)
+    {
+        ERROR(xch, "XIU: Cannot connect to Unix domain socket %s.", remote.sun_path);
+        return XC_OSDEP_OPEN_ERROR;
+    }
+
+    return (xc_osdep_handle)fd;
+}
+
+static int xiu_privcmd_close(xc_interface *xch, xc_osdep_handle h)
+{
+    int fd = (int)h;
+    return close(fd);
+}
+
+#define DOMAINHANDLE "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x"
+
+static int fake_xen_domctl(int fd, struct xen_domctl *domctl)
+{
+    #define DOMCTLcmd "domctl"
+    switch (domctl->cmd) {
+    case XEN_DOMCTL_pausedomain:
+    case XEN_DOMCTL_unpausedomain:
+    case XEN_DOMCTL_resumedomain:
+    case XEN_DOMCTL_destroydomain:
+        marshall_command(fd, "%s,%d,%d\n", DOMCTLcmd, domctl->cmd, domctl->domain);
+        return unmarshall_return(fd);
+    case XEN_DOMCTL_createdomain: /* W ssidref */
+        marshall_command(fd, "%s,%d,%d,%d," DOMAINHANDLE "\n", DOMCTLcmd,
+                         domctl->cmd,
+                         (domctl->u.createdomain.flags|XEN_DOMCTL_CDF_hvm_guest)?1:0,
+                         (domctl->u.createdomain.flags|XEN_DOMCTL_CDF_hap)?1:0,
+                         domctl->u.createdomain.handle[0],
+                         domctl->u.createdomain.handle[1],
+                         domctl->u.createdomain.handle[2],
+                         domctl->u.createdomain.handle[3],
+                         domctl->u.createdomain.handle[4],
+                         domctl->u.createdomain.handle[5],
+                         domctl->u.createdomain.handle[6],
+                         domctl->u.createdomain.handle[7],
+                         domctl->u.createdomain.handle[8],
+                         domctl->u.createdomain.handle[9],
+                         domctl->u.createdomain.handle[10],
+                         domctl->u.createdomain.handle[11],
+                         domctl->u.createdomain.handle[12],
+                         domctl->u.createdomain.handle[13],
+                         domctl->u.createdomain.handle[14],
+                         domctl->u.createdomain.handle[15]);
+        domctl->domain = unmarshall_int(fd);
+        return unmarshall_return(fd);
+    case XEN_DOMCTL_max_mem: /* W domid, maxmem */
+        marshall_command(fd, "%s,%d,%d,%d\n", DOMCTLcmd,
+                         domctl->cmd,
+                         domctl->domain, domctl->u.max_mem.max_memkb);
+        return unmarshall_return(fd);
+    case XEN_DOMCTL_settimeoffset: /* W domid, time */
+        marshall_command(fd, "%s,%d,%d,%d\n", DOMCTLcmd,
+                         domctl->cmd,
+                         domctl->domain,
+                         domctl->u.settimeoffset.time_offset_seconds);
+        return unmarshall_return(fd);
+#ifdef XEN_DOMCTL_setvmxassist
+    case XEN_DOMCTL_setvmxassist: /* W domid, use_vmxassist */
+        marshall_command(fd, "%s,%d,%d,%d\n", DOMCTLcmd,
+                         domctl->cmd,
+                         domctl->domain,
+                         domctl->u.setvmxassist.use_vmxassist);
+        return unmarshall_return(fd);
+#endif
+    case XEN_DOMCTL_max_vcpus: /* W domid, max */
+        marshall_command(fd, "%s,%d,%d,%d\n", DOMCTLcmd,
+                         domctl->cmd,
+                         domctl->domain,
+                         domctl->u.max_vcpus.max);
+        return unmarshall_return(fd);
+    case XEN_DOMCTL_setdomainhandle: { /* domid, fd */
+        marshall_command(fd, "%s,%d,%d," DOMAINHANDLE "\n", DOMCTLcmd,
+                         domctl->cmd,
+                         domctl->domain,
+                         domctl->u.setdomainhandle.handle[0],
+                         domctl->u.setdomainhandle.handle[1],
+                         domctl->u.setdomainhandle.handle[2],
+                         domctl->u.setdomainhandle.handle[3],
+                         domctl->u.setdomainhandle.handle[4],
+                         domctl->u.setdomainhandle.handle[5],
+                         domctl->u.setdomainhandle.handle[6],
+                         domctl->u.setdomainhandle.handle[7],
+                         domctl->u.setdomainhandle.handle[8],
+                         domctl->u.setdomainhandle.handle[9],
+                         domctl->u.setdomainhandle.handle[10],
+                         domctl->u.setdomainhandle.handle[11],
+                         domctl->u.setdomainhandle.handle[12],
+                         domctl->u.setdomainhandle.handle[13],
+                         domctl->u.setdomainhandle.handle[14],
+                         domctl->u.setdomainhandle.handle[15]);
+        return unmarshall_return(fd);
+        }
+    /* just returning success : might need init */
+    case XEN_DOMCTL_getvcpucontext:
+    case XEN_DOMCTL_getvcpuaffinity:
+        return 0;
+    /* just returning success */
+    case XEN_DOMCTL_scheduler_op:
+        return 0;
+    case XEN_DOMCTL_shadow_op:
+        /* Only fd set/get allocation at the moment */
+        marshall_command(fd, "%s,%d,%d,%d,%d,%d\n", DOMCTLcmd,
+                 domctl->cmd,
+                 domctl->domain,
+                 domctl->u.shadow_op.op,
+                 domctl->u.shadow_op.mode,
+                 domctl->u.shadow_op.mb);
+        if(domctl->u.shadow_op.op == XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION) 
+            domctl->u.shadow_op.mb = unmarshall_int(fd);
+
+        return unmarshall_return(fd);
+
+    /* just return success */
+    case XEN_DOMCTL_ioport_permission: 
+    case XEN_DOMCTL_irq_permission:
+    case XEN_DOMCTL_iomem_permission:
+    case XEN_DOMCTL_setvcpuaffinity:
+    case XEN_DOMCTL_setvcpucontext:
+    case XEN_DOMCTL_getmemlist:
+    case XEN_DOMCTL_getvcpuinfo:
+#ifdef XEN_DOMCTL_get_runstate_info
+    case XEN_DOMCTL_get_runstate_info:
+#endif
+    case XEN_DOMCTL_set_machine_address_size:
+#ifdef XEN_DOMCTL_suppress_spurious_page_faults
+    case XEN_DOMCTL_suppress_spurious_page_faults:
+#endif
+        return 0;
+    default:
+        return -EINVAL;
+    }
+}
+
+static int fake_xen_sysctl(int fd, struct xen_sysctl *sysctl)
+{
+    #define SYSCTLcmd "sysctl"
+    switch (sysctl->cmd) {
+    case XEN_SYSCTL_getdomaininfolist: {
+        xc_domaininfo_t *info; int num, i;
+
+        get_xen_guest_handle(info, sysctl->u.getdomaininfolist.buffer);
+
+        marshall_command(fd, "%s,%d,%d,%d\n", SYSCTLcmd, sysctl->cmd,
+                         sysctl->u.getdomaininfolist.first_domain,
+                         sysctl->u.getdomaininfolist.max_domains);
+        num = unmarshall_int(fd);
+        for (i = 0; i < num; i++) {
+            int uuid[16], j, flags;
+            char **ret;
+            
+            ret = unmarshall_multiple(fd);
+            if (!ret)
+                return -EBADF;
+
+            /* domid,uuid,flags */
+            info->domain = atoi(ret[0]);
+
+            parse_uuid(ret[1], uuid);
+            for (j = 0; j < 16; j++)
+                info->handle[j] = uuid[j] & 0xff;
+
+            flags = atoi(ret[2]);
+            info->flags = 0;
+            if (flags & 0x1) info->flags |= XEN_DOMINF_dying;
+            if (flags & 0x2) info->flags |= XEN_DOMINF_shutdown;
+            if (flags & 0x4) info->flags |= XEN_DOMINF_paused;
+            if (flags & 0x8) info->flags |= XEN_DOMINF_blocked;
+            if (flags & 0x10) info->flags |= XEN_DOMINF_running;
+            if (flags & 0x20) info->flags |= XEN_DOMINF_hvm_guest;
+            info->flags |= ((flags >> 8) & 0xff) << XEN_DOMINF_shutdownshift;
+
+            info->nr_online_vcpus = atoi(ret[3]);
+            info->max_vcpu_id = atoi(ret[4]);
+
+            info->tot_pages = atoi(ret[5]);
+            info->max_pages = atoi(ret[6]);
+            info->shared_info_frame = atoi(ret[7]);
+            info->cpu_time = atoi(ret[8]);
+            info->ssidref = atoi(ret[9]);
+
+            string_split_free(ret);
+            info++;
+
+        }
+        sysctl->u.getdomaininfolist.num_domains = num;
+        return unmarshall_return(fd);
+        }
+    case XEN_SYSCTL_readconsole:
+    case XEN_SYSCTL_debug_keys:
+        return 0;
+    case XEN_SYSCTL_physinfo: {
+        char **ret;
+        int sockets_per_node;
+
+        marshall_command(fd, "%s,%d\n", SYSCTLcmd, sysctl->cmd);
+        ret = unmarshall_multiple(fd);
+        if (!ret) return -EBADF;
+
+        sockets_per_node = atoi(ret[2]);
+
+        sysctl->u.physinfo.threads_per_core = atoi(ret[0]);
+        sysctl->u.physinfo.cores_per_socket = atoi(ret[1]);
+#if XEN_SYSCTL_INTERFACE_VERSION < 6
+        sysctl->u.physinfo.sockets_per_node = sockets_per_node;
+#endif
+        sysctl->u.physinfo.nr_nodes = atoi(ret[3]);
+#if XEN_SYSCTL_INTERFACE_VERSION >= 6
+        sysctl->u.physinfo.nr_cpus =
+            sysctl->u.physinfo.threads_per_core *
+            sysctl->u.physinfo.cores_per_socket *
+            sockets_per_node *
+            sysctl->u.physinfo.nr_nodes;
+#endif
+        sysctl->u.physinfo.cpu_khz = atoi(ret[4]);
+        sysctl->u.physinfo.total_pages = atoi(ret[5]);
+        sysctl->u.physinfo.free_pages = atoi(ret[6]);
+        sysctl->u.physinfo.scrub_pages = 0;
+
+        string_split_free(ret);
+        return unmarshall_return(fd);
+        }
+    case XEN_SYSCTL_getcpuinfo: {
+        xen_sysctl_cpuinfo_t *info;
+        int num, i;
+
+        get_xen_guest_handle(info, sysctl->u.getcpuinfo.info);
+        marshall_command(fd, "%s,%d,%d\n", SYSCTLcmd, sysctl->cmd, sysctl->u.getcpuinfo.max_cpus);
+        num = unmarshall_int(fd);
+        for (i = 0; i < num; i++) {
+            info[i].idletime = unmarshall_int64(fd);
+        }
+        return unmarshall_return(fd);
+        }
+    case XEN_SYSCTL_sched_id:
+        return 0;
+    default:
+        return -EINVAL;
+    }
+    return 0;
+}
+
+static int fake_xen_eventchn(int fd, unsigned long cmd, unsigned long arg)
+{
+    switch (cmd) {
+    case EVTCHNOP_alloc_unbound:
+    case EVTCHNOP_reset:
+        return 0;
+    default:
+        return -EINVAL;
+    }
+    return 0;
+}
+
+static int fake_xen_memoryop(int fd, unsigned long cmd, struct xen_memory_reservation *reservation)
+{
+    switch (cmd) {
+    case XENMEM_set_memory_map:
+    case XENMEM_increase_reservation:
+    case XENMEM_decrease_reservation:
+    case XENMEM_populate_physmap:
+        return 0;
+    default:
+        return -EINVAL;
+    }
+    return 0;
+}
+
+static int fake_xen_hvmop(int fd, unsigned long cmd, unsigned long arg)
+{
+    switch (cmd) {
+    case HVMOP_get_param:
+        return 0;
+    default:
+        return -EINVAL;
+    }
+    return 0;
+}
+
+static int fake_xen_schedop(int fd, unsigned long cmd, sched_remote_shutdown_t *arg)
+{
+    switch (cmd) {
+    case SCHEDOP_remote_shutdown:
+        marshall_command(fd, "%s,%d,%d,%d\n", HYPCALLcmd,
+                         1, 
+                         arg->domain_id,
+                         arg->reason);
+        return unmarshall_return(fd);
+    default:
+        return -EINVAL;
+    }
+    return 0;
+}
+
+static int fake_xen_versionop(int fd, unsigned long cmd, void * arg)
+{
+    switch (cmd) {
+    case XENVER_extraversion:
+        memset(arg, '\0', sizeof(xen_extraversion_t));
+        memcpy(arg, ".0", 2);
+        return 0;
+    case XENVER_compile_info:
+        memset(arg, '\0', sizeof(xen_compile_info_t));
+        return 0;
+    case XENVER_capabilities:
+        memset(arg, '\0', sizeof(xen_capabilities_info_t));
+        #define CAPA "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64"
+        memcpy(arg, CAPA, strlen(CAPA));
+        #undef CAPA
+        return 0;
+    case XENVER_changeset:
+        memset(arg, '\0', sizeof(xen_changeset_info_t));
+        return 0;
+    case XENVER_platform_parameters:
+        memset(arg, '\0', sizeof(xen_platform_parameters_t));
+        return 0;
+    case XENVER_version:
+        return (((3 << 16) & 0xffff0000) + (1 & 0xffff)); /* 3.1 */
+    default:
+        return -EINVAL;
+    }
+    return 0;
+}
+
+static int xiu_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
+{
+    int fd = (int)h;
+    if (!hypercall) return -EINVAL;
+    switch (hypercall->op) {
+    case __HYPERVISOR_domctl:
+        return fake_xen_domctl(fd, (struct xen_domctl *) (intptr_t)hypercall->arg[0]);
+    case __HYPERVISOR_sysctl:
+        return fake_xen_sysctl(fd, (struct xen_sysctl *) (intptr_t)hypercall->arg[0]);
+    case __HYPERVISOR_event_channel_op:
+        return fake_xen_eventchn(fd, hypercall->arg[0], hypercall->arg[1]);
+    case __HYPERVISOR_memory_op:
+        return fake_xen_memoryop(fd, hypercall->arg[0], (struct xen_memory_reservation *) (intptr_t)hypercall->arg[2]);
+    case __HYPERVISOR_hvm_op:
+        return fake_xen_hvmop(fd, hypercall->arg[0], hypercall->arg[2]);
+    case __HYPERVISOR_sched_op:
+        return fake_xen_schedop(fd, hypercall->arg[0], (sched_remote_shutdown_t *) (intptr_t)hypercall->arg[1]);
+    case __HYPERVISOR_xen_version:
+        return fake_xen_versionop(fd, hypercall->arg[0], (void *) (intptr_t)hypercall->arg[1]);
+    default:
+        return -EINVAL;
+    }
+}
+
+static void *xiu_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
+                                      xen_pfn_t *arr, int num)
+{
+    return mmap(NULL, num << XC_PAGE_SHIFT, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+}
+
+static void *xiu_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
+                                     const xen_pfn_t *arr, int *err, unsigned int num)
+{
+    return mmap(NULL, (unsigned long)num << XC_PAGE_SHIFT, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+}
+
+static void *xiu_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int size, int prot,
+                                      unsigned long mfn)
+{
+    int num = (size + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT;
+    return mmap(NULL, num, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+}
+
+static void *xiu_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h, uint32_t dom, size_t size, int prot,
+                                       size_t chunksize, privcmd_mmap_entry_t entries[],
+                                       int nentries)
+{
+    int num_per_entry;
+    int num;
+
+    num_per_entry = chunksize >> XC_PAGE_SHIFT;
+    num = num_per_entry * nentries;
+    return mmap(NULL, num, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+}
+
+static struct xc_osdep_ops xiu_privcmd_ops =
+{
+    .open      = &xiu_privcmd_open,
+    .close     = &xiu_privcmd_close,
+    .u.privcmd   = {
+        .hypercall = &xiu_privcmd_hypercall,
+
+        .map_foreign_batch = &xiu_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &xiu_privcmd_map_foreign_bulk,
+        .map_foreign_range = &xiu_privcmd_map_foreign_range,
+        .map_foreign_ranges = &xiu_privcmd_map_foreign_ranges,
+    }
+};
+
+static xc_osdep_handle xiu_evtchn_open(xc_evtchn *xce)
+{
+	struct sockaddr_un remote;
+	char *s;
+	int fd, len;
+
+	s = getenv("XIU");
+    if (!s)
+    {
+        ERROR(xce, "XIU not found. Set $XIU");
+        return XC_OSDEP_OPEN_ERROR;
+    }
+	snprintf(remote.sun_path, 256, "%s-ev", s);
+	remote.sun_family = AF_UNIX;
+	len = strlen(remote.sun_path) + sizeof(remote.sun_family);
+
+	fd = socket(AF_UNIX, SOCK_STREAM, 0);
+    if (fd == -1)
+    {
+        ERROR(xce, "XIU: Cannot open Unix domain socket");
+        return XC_OSDEP_OPEN_ERROR;
+    }
+
+    if (connect(fd, (struct sockaddr *)&remote, len) != 0)
+    {
+        ERROR(xce, "XIU: Cannot connect to Unix domain socket %s.", remote.sun_path);
+        return XC_OSDEP_OPEN_ERROR;
+    }
+
+    return (xc_osdep_handle)fd;
+}
+
+static int xiu_evtchn_close(xc_evtchn *xce, xc_osdep_handle h)
+{
+    int fd = (int)h;
+    return close(fd);
+}
+
+static int xiu_evtchn_fd(xc_evtchn *xce, xc_osdep_handle h)
+{
+    return (int)h;
+}
+
+static int xiu_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
+{
+   int fd = (int)h;
+   marshall_command(fd, "ioctl,notify,%d\n", port);
+   return unmarshall_return(fd);
+}
+
+static evtchn_port_or_error_t
+xiu_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid)
+{
+    return -EINVAL;
+}
+
+static evtchn_port_or_error_t
+xiu_evtchn_bind_interdomain(xc_evtchn *xce, xc_osdep_handle h, int domid,
+                              evtchn_port_t remote_port)
+{
+    int fd = (int)h;
+    marshall_command(fd, "ioctl,bind_interdomain,%d,%d\n", domid, remote_port);
+    return unmarshall_return(fd);
+}
+
+static evtchn_port_or_error_t
+xiu_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq)
+{
+    int fd = (int)h;
+    marshall_command(fd, "ioctl,bind_virq,%d\n", virq);
+    return unmarshall_return(fd);
+}
+
+static int xiu_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
+{
+    int fd = (int)h;
+    marshall_command(fd, "ioctl,unbind,%d\n", port);
+    return unmarshall_return(fd);
+}
+
+static evtchn_port_or_error_t xiu_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h)
+{
+    int fd = (int)h;
+    evtchn_port_t port;
+
+	marshall_command(fd, "read\n");
+	port = unmarshall_int(fd);
+    if (unmarshall_return(fd) < 0)
+        return port;
+    else
+        return -1;
+}
+
+static int xiu_evtchn_unmask(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
+{
+    int fd = (int)h;
+	marshall_command(fd, "write,%d\n", port);
+	return unmarshall_return(fd);
+}
+
+static struct xc_osdep_ops xiu_evtchn_ops = {
+    .open = &xiu_evtchn_open,
+    .close = &xiu_evtchn_close,
+
+    .u.evtchn = {
+        .fd = &xiu_evtchn_fd,
+        .notify = &xiu_evtchn_notify,
+        .bind_unbound_port = &xiu_evtchn_bind_unbound_port,
+        .bind_interdomain = &xiu_evtchn_bind_interdomain,
+        .bind_virq = &xiu_evtchn_bind_virq,
+        .unbind = &xiu_evtchn_unbind,
+        .pending = &xiu_evtchn_pending,
+        .unmask = &xiu_evtchn_unmask,
+    },
+};
+
+static struct xc_osdep_ops * xiu_osdep_init(xc_interface *xch, enum xc_osdep_type type)
+{
+    if (getenv("XIU") == NULL)
+    {
+        ERROR(xch, "XIU not found. Set $XIU");
+        return NULL;
+    }
+
+    switch ( type )
+    {
+    case XC_OSDEP_PRIVCMD:
+        return &xiu_privcmd_ops;
+    case XC_OSDEP_EVTCHN:
+        return &xiu_evtchn_ops;
+    case XC_OSDEP_GNTTAB:
+        ERROR(xch, "GNTTAB interface not supported on this platform");
+        return NULL;
+    default:
+        return NULL;
+    }
+}
+
+xc_osdep_info_t xc_osdep_info = {
+    .name = "Xen In Userspace (XIU) Simulator",
+    .init = &xiu_osdep_init,
+    .fake = 1,
+};
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg
       [not found]     ` <1291732233.13966.3198.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:32       ` [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Ian Campbell
  2010-12-07 14:32       ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
@ 2010-12-07 14:33       ` Ian Campbell
       [not found]         ` <patchbomb.1291732388-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
                           ` (2 more replies)
  2 siblings, 3 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

The following series of patches lays some ground work to enable XCP to move, at
some point in the future, to the in-tree ocaml bindings which will come with
Xen 4.1

This is the xen-api.hg portion.

Only the first two patches are for immediate consideration, the others all
depend on actually moving to Xen 4.1

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1 of 6] Query rpm to find build directories
       [not found]         ` <patchbomb.1291732388-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-12-07 14:33           ` Ian Campbell
  2010-12-07 14:33           ` [PATCH 2 of 6] xc: use Xcext library rather than Xc where appropriate Ian Campbell
                             ` (2 subsequent siblings)
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290076616 18000
# Node ID 819ce8194667bb673138ad12e781432cebf2028a
# Parent  7438d990fed8255bba2d592f767de133bd45863a
Query rpm to find build directories.

Allows user with ~/.rpmmacros to build e.g.
$ cat ~/.rpmmacros
%_topdir        /data/rpmbuild
%_tmppath       /data/tmp

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 7438d990fed8 -r 819ce8194667 Makefile
--- a/Makefile	Tue Oct 12 12:02:18 2010 +0100
+++ b/Makefile	Thu Nov 18 05:36:56 2010 -0500
@@ -107,9 +107,9 @@ MY_OUTPUT_DIR ?= $(CURDIR)/output
 MY_OBJ_DIR ?= $(CURDIR)/obj
 REPO ?= $(CURDIR)
 
-RPM_SPECSDIR?=/usr/src/redhat/SPECS
-RPM_SRPMSDIR?=/usr/src/redhat/SRPMS
-RPM_SOURCESDIR?=/usr/src/redhat/SOURCES
+RPM_SPECSDIR?=$(shell rpm --eval='%_specdir')
+RPM_SRPMSDIR?=$(shell rpm --eval='%_srcrpmdir')
+RPM_SOURCESDIR?=$(shell rpm --eval='%_sourcedir')
 RPMBUILD?=rpmbuild
 XEN_RELEASE?=unknown
 endif

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 2 of 6] xc: use Xcext library rather than Xc where appropriate
       [not found]         ` <patchbomb.1291732388-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:33           ` [PATCH 1 of 6] Query rpm to find build directories Ian Campbell
@ 2010-12-07 14:33           ` Ian Campbell
  2010-12-07 14:33           ` [PATCH 4 of 6] REBASE-4.1: xenops: update PV console path in xenstore Ian Campbell
  2010-12-07 14:33           ` [PATCH 6 of 6] HACK: xenguest updates for Xen 4.0/4.1 Ian Campbell
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290076616 18000
# Node ID 4b9c3e5d05b045b4b93afa12e78afbef41ca7aa1
# Parent  819ce8194667bb673138ad12e781432cebf2028a
xc: use Xcext library rather than Xc where appropriate.

The xc bindings have been split into xc and xcext with the latter
containing bits of xc functionality which are not present in the
upstream xen tree..

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 819ce8194667 -r 4b9c3e5d05b0 ocaml/xapi/monitor.ml
--- a/ocaml/xapi/monitor.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xapi/monitor.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -92,14 +92,14 @@ let update_vcpus xc doms =
     (* Runstate info is per-domain rather than per-vcpu *)
     let dss = 
       try
-	let ri = Xc.domain_get_runstate_info xc domid in 
-	(VM uuid, ds_make ~name:"runstate_entry_time" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.state_entry_time) /. 1.0e9)) ~description:"" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_fullrun" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time0) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are running" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_full_contention" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time1) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are runnable (i.e., waiting for CPU)" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_concurrency_hazard" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time2) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are running and some are runnable" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_blocked" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time3) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are blocked or offline" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_partial_run" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time4) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are running, and some are blocked" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
-	  (VM uuid, ds_make ~name:"runstate_partial_contention" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xc.time5) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are runnable and some are blocked" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::dss 
+	let ri = Xcext.domain_get_runstate_info xc domid in 
+	(VM uuid, ds_make ~name:"runstate_entry_time" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.state_entry_time) /. 1.0e9)) ~description:"" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_fullrun" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time0) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are running" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_full_contention" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time1) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are runnable (i.e., waiting for CPU)" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_concurrency_hazard" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time2) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are running and some are runnable" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_blocked" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time3) /. 1.0e9)) ~description:"Fraction of time that all VCPUs are blocked or offline" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_partial_run" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time4) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are running, and some are blocked" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::
+	  (VM uuid, ds_make ~name:"runstate_partial_contention" ~value:(Rrd.VT_Float ((Int64.to_float ri.Xcext.time5) /. 1.0e9)) ~description:"Fraction of time that some VCPUs are runnable and some are blocked" ~ty:Rrd.Derive ~default:false ~min:0.0 ())::dss 
       with e -> 
 	dss 
     in
diff -r 819ce8194667 -r 4b9c3e5d05b0 ocaml/xenops-ts/OMakefile
--- a/ocaml/xenops-ts/OMakefile	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops-ts/OMakefile	Thu Nov 18 05:36:56 2010 -0500
@@ -3,6 +3,6 @@ OCAML_LIBS       = ../util/stats ../xeno
 OCAML_CLIBS      += $(XEN_OCAML_CLIBS)
 OCAML_LINK_FLAGS += $(XEN_OCAML_LINK_FLAGS)
 CFLAGS           += $(XEN_CFLAGS)
-OCAMLPACKS	     = xc xs stdext log cdrom netdev
+OCAMLPACKS	     = xc xcext xs stdext log cdrom netdev
 
 OCamlProgram(runtest, runtest test ../xenops/xenvmlib)
diff -r 819ce8194667 -r 4b9c3e5d05b0 ocaml/xenops/OMakefile
--- a/ocaml/xenops/OMakefile	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/OMakefile	Thu Nov 18 05:36:56 2010 -0500
@@ -4,7 +4,7 @@ OCAML_CLIBS     += $(XEN_OCAML_CLIBS)
 OCAML_LINK_FLAGS+= $(XEN_OCAML_LINK_FLAGS)
 CFLAGS          += $(XEN_CFLAGS)
 
-OCAMLPACKS     = threads xc xs stdext log cdrom netdev
+OCAMLPACKS     = threads xc xcext xs stdext log cdrom netdev
 OCAMLFLAGS    += -thread
 
 LIBFILES = xenops_helpers xenbus balloon xenguestHelper domain hotplug device io statdev xal netman memory watch device_common squeeze squeeze_xen squeezed_rpc squeezed_state squeezed_rpc
diff -r 819ce8194667 -r 4b9c3e5d05b0 ocaml/xenops/domain.ml
--- a/ocaml/xenops/domain.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/domain.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -242,7 +242,7 @@ let shutdown_wait_for_ack ?(timeout=60.)
   let di = Xc.domain_getinfo xc domid in
 
   if di.Xc.hvm_guest then begin
-	if Xc.hvm_check_pvdriver xc domid
+	if Xcext.hvm_check_pvdriver xc domid
 	then debug "HVM guest with PV drivers: not expecting any acknowledgement"
 	else Xc.domain_shutdown xc domid (shutdown_to_xc_shutdown req)
   end else begin
@@ -409,11 +409,11 @@ let build_pre ~xc ~xs ~vcpus ~xen_max_mi
           maybe (fun opt -> try f opt with exn -> warn "exception setting %s: %s" name (Printexc.to_string exn)) opt
         in
 
-	maybe_exn_ign "timer mode" (fun mode -> Xc.domain_set_timer_mode xc domid mode) timer_mode;
-        maybe_exn_ign "hpet" (fun hpet -> Xc.domain_set_hpet xc domid hpet) hpet;
-        maybe_exn_ign "vpt align" (fun vpt_align -> Xc.domain_set_vpt_align xc domid vpt_align) vpt_align;
+	maybe_exn_ign "timer mode" (fun mode -> Xcext.domain_set_timer_mode xc domid mode) timer_mode;
+        maybe_exn_ign "hpet" (fun hpet -> Xcext.domain_set_hpet xc domid hpet) hpet;
+        maybe_exn_ign "vpt align" (fun vpt_align -> Xcext.domain_set_vpt_align xc domid vpt_align) vpt_align;
 
-	Xc.domain_setvmxassist xc domid use_vmxassist;
+	Xcext.domain_setvmxassist xc domid use_vmxassist;
 	Xc.domain_max_vcpus xc domid vcpus;
 	Xc.domain_setmaxmem xc domid (Memory.kib_of_mib xen_max_mib);
 	Xc.domain_set_memmap_limit xc domid (Memory.kib_of_mib xen_max_mib);
@@ -822,10 +822,10 @@ let suspend ~xc ~xs ~hvm domid fd flags 
 	);
 	debug "Suspend for domid %d finished" domid
 
-let send_s3resume ~xc domid = Xc.domain_send_s3resume xc domid
+let send_s3resume ~xc domid = Xcext.domain_send_s3resume xc domid
 
-let trigger_power ~xc domid = Xc.domain_trigger_power xc domid
-let trigger_sleep ~xc domid = Xc.domain_trigger_sleep xc domid
+let trigger_power ~xc domid = Xcext.domain_trigger_power xc domid
+let trigger_sleep ~xc domid = Xcext.domain_trigger_sleep xc domid
 
 let vcpu_affinity_set ~xc domid vcpu cpumap =
 	let bitmap = ref Int64.zero in
@@ -901,7 +901,7 @@ let set_machine_address_size ~xc domid w
 
 let suppress_spurious_page_faults ~xc domid =
   debug "suppress spurious page faults for dom%d" domid;
-  Xc.domain_suppress_spurious_page_faults xc domid
+  Xcext.domain_suppress_spurious_page_faults xc domid
 
 type cpuid_reg = Eax | Ebx | Ecx | Edx
 type cpuid_rtype = Clear | Set | Default | Same | Keep

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 3 of 6] REBASE-4.1: vmops: apply CPUID to all domains
  2010-12-07 14:33       ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
       [not found]         ` <patchbomb.1291732388-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
@ 2010-12-07 14:33         ` Ian Campbell
  2010-12-07 14:33         ` [PATCH 5 of 6] HACK/PoC: adjust for minor differences in upstream Xc bindings Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1290076616 18000
# Node ID 810786855fe641b7db0074cfcb2b2a3a4dfd34a0
# Parent  4b9c3e5d05b045b4b93afa12e78afbef41ca7aa1
REBASE-4.1: vmops: apply CPUID to all domains.

Not just when xenclient is enabled.

I think the indentation was confusing here and the PCI passthrough bit wasn't
actually guarded by Xapi_globs.xenclient_enabled.

Required on newer hypervisor otherwise guest sees all cpuid leafs == 0.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 4b9c3e5d05b0 -r 810786855fe6 ocaml/xapi/vmops.ml
--- a/ocaml/xapi/vmops.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xapi/vmops.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -1052,11 +1052,10 @@ let start_paused ?(progress_cb = fun _ -
 
 		      let hvm = Helpers.is_hvm snapshot in			
 
-		      if Xapi_globs.xenclient_enabled then 
-			Domain.cpuid_apply ~xc ~hvm domid;
+		      Domain.cpuid_apply ~xc ~hvm domid;
 
-			  (* XXX: PCI passthrough needs a lot of work *)
-			  let pcidevs = (match pcidevs with Some x -> x | None -> pcidevs_of_vm ~__context ~vm) in
+		      (* XXX: PCI passthrough needs a lot of work *)
+		      let pcidevs = (match pcidevs with Some x -> x | None -> pcidevs_of_vm ~__context ~vm) in
 
 		      (* Don't attempt to attach empty VBDs to PV guests: they can't handle them *)
 		      let vbds = 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 4 of 6] REBASE-4.1: xenops: update PV console path in xenstore
       [not found]         ` <patchbomb.1291732388-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:33           ` [PATCH 1 of 6] Query rpm to find build directories Ian Campbell
  2010-12-07 14:33           ` [PATCH 2 of 6] xc: use Xcext library rather than Xc where appropriate Ian Campbell
@ 2010-12-07 14:33           ` Ian Campbell
  2010-12-07 14:33           ` [PATCH 6 of 6] HACK: xenguest updates for Xen 4.0/4.1 Ian Campbell
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1290076616 18000
# Node ID 2e6a1485047a2e91c2e90d8ffdbf6c9a9814588c
# Parent  810786855fe641b7db0074cfcb2b2a3a4dfd34a0
REBASE-4.1: xenops: update PV console path in xenstore.

This was changed in more recent xenconsoled in order to better support multiple
consoles.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 810786855fe6 -r 2e6a1485047a ocaml/xenops/device.ml
--- a/ocaml/xenops/device.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/device.ml	Thu Nov 18 05:36:56 2010 -0500
@@ -845,11 +845,11 @@ module PV_Vnc = struct
 
 let vncterm_wrapper = "/opt/xensource/libexec/vncterm-wrapper"
 
-let vnc_port_path domid = sprintf "/local/domain/%d/serial/0/vnc-port" domid
+let vnc_port_path domid = sprintf "/local/domain/%d/console/vnc-port" domid
 
 let pid ~xs domid =
 	try
-		let pid = xs.Xs.read (sprintf "/local/domain/%d/serial/0/vncterm-pid" domid) in
+		let pid = xs.Xs.read (sprintf "/local/domain/%d/console/vncterm-pid" domid) in
 		Some (int_of_string pid)
 	with _ ->
 		None
@@ -896,7 +896,7 @@ let save ~xs domid =
 let start ?statefile ~xs domid =
 	let l = [ string_of_int domid; (* absorbed by vncterm-wrapper *)
 		  (* everything else goes straight through to vncterm-wrapper: *)
-		  "-x"; sprintf "/local/domain/%d/serial/0" domid;
+		  "-x"; sprintf "/local/domain/%d/console" domid;
 		] @ load_args statefile in
 	(* Now add the close fds wrapper *)
 	let pid = Forkhelpers.safe_close_and_exec None None None [] vncterm_wrapper l in
diff -r 810786855fe6 -r 2e6a1485047a scripts/vncterm-wrapper
--- a/scripts/vncterm-wrapper	Thu Nov 18 05:36:56 2010 -0500
+++ b/scripts/vncterm-wrapper	Thu Nov 18 05:36:56 2010 -0500
@@ -39,9 +39,9 @@ else
 fi
 
 echo vncterm-wrapper:
-xenstore-write -s /local/domain/$DOMID/serial/0/vncterm-pid $$
+xenstore-write -s /local/domain/$DOMID/console/vncterm-pid $$
 if [ -z "${XIU}" ]; then
 	exec /usr/lib/xen/bin/vncterm $VNCTERM_LISTEN $VNCVIEWER $* > /dev/null 2>&1
 else
-	exec xenstore-write -s /local/domain/$DOMID/serial/0/vnc-port 0
+	exec xenstore-write -s /local/domain/$DOMID/console/vnc-port 0
 fi

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 5 of 6] HACK/PoC: adjust for minor differences in upstream Xc bindings
  2010-12-07 14:33       ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
       [not found]         ` <patchbomb.1291732388-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:33         ` [PATCH 3 of 6] REBASE-4.1: vmops: apply CPUID to all domains Ian Campbell
@ 2010-12-07 14:33         ` Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

# HG changeset patch
# User root@localhost.localdomain
# Date 1291305003 18000
# Node ID 15700c869b5445ce6d239513c54d6f69f9d62808
# Parent  2e6a1485047a2e91c2e90d8ffdbf6c9a9814588c
HACK/PoC: adjust for minor differences in upstream Xc bindings

Just a PoC at this stage. It might be better to push the interface differences
to xen-api-libs.hg now to reduce the churn when rebasing to 4.1

Not-Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 2e6a1485047a -r 15700c869b54 ocaml/xenops/balloon.ml
--- a/ocaml/xenops/balloon.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/balloon.ml	Thu Dec 02 10:50:03 2010 -0500
@@ -26,7 +26,7 @@ let _low_mem_balloon = "Low-mem balloon"
 let _high_mem_balloon = "High-mem balloon"
 
 (** Indicates whether or not we're running with XIU (Xen-In Userspace) *)
-let on_xiu () = Xc.using_injection ()
+let on_xiu () = Xc.is_fake ()
 
 (** Reads /proc/xen/balloon into a string * int64 option association list *)
 let parse_proc_xen_balloon () =
diff -r 2e6a1485047a -r 15700c869b54 ocaml/xenops/device.ml
--- a/ocaml/xenops/device.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/device.ml	Thu Dec 02 10:50:03 2010 -0500
@@ -749,8 +749,8 @@ let add ~xs ~devid ~netty ~mac ?mtu ?(ra
 	let extra_private_keys = extra_private_keys @
 	  (match mtu with | Some mtu when mtu > 0 -> [ "MTU", string_of_int mtu ] | _ -> []) @
 	  (match netty with
-	     | Netman.Bridge b -> [ "bridge", b; "bridge-MAC", if(Xc.using_injection ()) then "fe:fe:fe:fe:fe:fe" else "fe:ff:ff:ff:ff:ff"; ]
-	     | Netman.Vswitch b -> [ "bridge", b; "bridge-MAC", if(Xc.using_injection ()) then "fe:fe:fe:fe:fe:fe" else "fe:ff:ff:ff:ff:ff"; ]
+	     | Netman.Bridge b -> [ "bridge", b; "bridge-MAC", if(Xc.is_fake ()) then "fe:fe:fe:fe:fe:fe" else "fe:ff:ff:ff:ff:ff"; ]
+	     | Netman.Vswitch b -> [ "bridge", b; "bridge-MAC", if(Xc.is_fake ()) then "fe:fe:fe:fe:fe:fe" else "fe:ff:ff:ff:ff:ff"; ]
 	     | Netman.DriverDomain -> []
 	     | Netman.Nat -> []) @
 	  (match rate with | None -> [] | Some(rate, timeslice) -> [ "rate", Int64.to_string rate; "timeslice", Int64.to_string timeslice ]) in
diff -r 2e6a1485047a -r 15700c869b54 ocaml/xenops/domain.ml
--- a/ocaml/xenops/domain.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/domain.ml	Thu Dec 02 10:50:03 2010 -0500
@@ -837,7 +837,9 @@ let vcpu_affinity_set ~xc domid vcpu cpu
 	Array.iteri (fun i has_affinity ->
 		if has_affinity then bitmap := bit_set !bitmap i
 		) cpumap;
-	Xc.vcpu_affinity_set xc domid vcpu !bitmap
+	(*Xc.vcpu_affinity_set xc domid vcpu !bitmap*)
+	Xc.vcpu_affinity_set xc domid vcpu cpumap
+
 
 let vcpu_affinity_get ~xc domid vcpu =
 	let bitmap = Xc.vcpu_affinity_get xc domid vcpu in
@@ -845,8 +847,9 @@ let vcpu_affinity_get ~xc domid vcpu =
 	let bit_isset bitmap n =
 		(Int64.logand bitmap (Int64.shift_left 1L n)) > 0L in
 	(* set bit in the array that are set in the bitmap *)
-	for i = 0 to 63 do cpumap.(i) <- bit_isset bitmap i done;
-	cpumap
+	(*for i = 0 to 63 do cpumap.(i) <- bit_isset bitmap i done;*)
+	(*cpumap*)
+	bitmap
 
 let get_uuid ~xc domid =
 	Uuid.uuid_of_int_array (Xc.domain_getinfo xc domid).Xc.handle
@@ -961,19 +964,20 @@ let cpuid_set ~xc ~hvm domid cfg =
 	let tmp = Array.create 4 None in
 	let cfgout = List.map (fun (node, constr) ->
 		cpuid_cfg_to_xc_cpuid_cfg tmp constr;
-		let ret = Xc.domain_cpuid_set xc domid hvm node tmp in
+		let ret = Xc.domain_cpuid_set xc domid (*hvm*) node tmp in
 		let ret = cpuid_cfg_of_xc_cpuid_cfg ret in
 		(node, ret)
 	) cfg in
 	cfgout
 
 let cpuid_apply ~xc ~hvm domid =
-	Xc.domain_cpuid_apply xc domid hvm
+	(*Xc.domain_cpuid_apply xc domid hvm*)
+	Xc.domain_cpuid_apply_policy xc domid
 
-let cpuid_check cfg =
+let cpuid_check ~xc cfg =
 	let tmp = Array.create 4 None in
 	List.map (fun (node, constr) ->
 		cpuid_cfg_to_xc_cpuid_cfg tmp constr;
-		let (success, cfgout) = Xc.cpuid_check node tmp in
+		let (success, cfgout) = Xc.cpuid_check xc node tmp in
 		(success, (node, (cpuid_cfg_of_xc_cpuid_cfg cfgout)))
 	) cfg
diff -r 2e6a1485047a -r 15700c869b54 ocaml/xenops/domain.mli
--- a/ocaml/xenops/domain.mli	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/domain.mli	Thu Dec 02 10:50:03 2010 -0500
@@ -206,4 +206,4 @@ val cpuid_rtype_of_char : char -> cpuid_
 
 val cpuid_set : xc: Xc.handle -> hvm: bool -> domid -> cpuid_config -> cpuid_config
 val cpuid_apply : xc: Xc.handle -> hvm: bool -> domid -> unit
-val cpuid_check : cpuid_config -> (bool * ((int64 * int64 option) * (cpuid_reg * cpuid_rtype array) list)) list
+val cpuid_check : xc: Xc.handle -> cpuid_config -> (bool * ((int64 * int64 option) * (cpuid_reg * cpuid_rtype array) list)) list
diff -r 2e6a1485047a -r 15700c869b54 ocaml/xenops/netman.ml
--- a/ocaml/xenops/netman.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/netman.ml	Thu Dec 02 10:50:03 2010 -0500
@@ -27,7 +27,7 @@ let online vif netty =
 		Netdev.Link.arp dev false;
 		Netdev.Link.multicast dev false;
 		Netdev.Link.set_addr dev 
-		 (if(Xc.using_injection ()) then "fe:fe:fe:fe:fe:fe" else "fe:ff:ff:ff:ff:ff");
+		 (if(Xc.is_fake ()) then "fe:fe:fe:fe:fe:fe" else "fe:ff:ff:ff:ff:ff");
 		Netdev.Addr.flush dev
 		in
 	match netty with
diff -r 2e6a1485047a -r 15700c869b54 ocaml/xenops/xenguestHelper.ml
--- a/ocaml/xenops/xenguestHelper.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenops/xenguestHelper.ml	Thu Dec 02 10:50:03 2010 -0500
@@ -41,7 +41,7 @@ let connect (args: string list) (fds: (s
 	(* Need to send commands and receive responses from the
 	   slave process *)
 
-	let using_xiu = Xc.using_injection () in
+	let using_xiu = Xc.is_fake () in
 
 	let last_log_file = "/tmp/xenguest.log" in
 	(try Unix.unlink last_log_file with _ -> ());
diff -r 2e6a1485047a -r 15700c869b54 ocaml/xenstored/event.ml
--- a/ocaml/xenstored/event.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenstored/event.ml	Thu Dec 02 10:50:03 2010 -0500
@@ -13,14 +13,15 @@
  *)
 (**************** high level binding ****************)
 type t = {
-	fd: Unix.file_descr;
+	handle: Eventchn.handle;
 	mutable virq_port: int;
 }
 
-let init () = { fd = Eventchn.init (); virq_port = -1; }
-let bind_virq eventchn = eventchn.virq_port <- Eventchn.bind_virq eventchn.fd
-let bind_interdomain eventchn domid port = Eventchn.bind_interdomain eventchn.fd domid port
-let unbind eventchn port = Eventchn.unbind eventchn.fd port
-let notify eventchn port = Eventchn.notify eventchn.fd port
-let read_port eventchn = Eventchn.read_port eventchn.fd
-let write_port eventchn port = Eventchn.write_port eventchn.fd port
+let init () = { handle = Eventchn.init (); virq_port = -1; }
+let fd eventchn = Eventchn.fd eventchn.handle
+let bind_dom_exc_virq eventchn = eventchn.virq_port <- Eventchn.bind_dom_exc_virq eventchn.handle
+let bind_interdomain eventchn domid port = Eventchn.bind_interdomain eventchn.handle domid port
+let unbind eventchn port = Eventchn.unbind eventchn.handle port
+let notify eventchn port = Eventchn.notify eventchn.handle port
+let pending eventchn = Eventchn.pending eventchn.handle
+let unmask eventchn port = Eventchn.unmask eventchn.handle port
diff -r 2e6a1485047a -r 15700c869b54 ocaml/xenstored/xenstored.ml
--- a/ocaml/xenstored/xenstored.ml	Thu Nov 18 05:36:56 2010 -0500
+++ b/ocaml/xenstored/xenstored.ml	Thu Dec 02 10:50:03 2010 -0500
@@ -249,7 +249,7 @@ let _ =
 
 	if cf.restart then (
 		DB.from_file store domains cons "/var/run/xenstored/db";
-		Event.bind_virq eventchn
+		Event.bind_dom_exc_virq eventchn
 	) else (
 		if !Disk.enable then (
 			info "reading store from disk";
@@ -261,9 +261,9 @@ let _ =
 			Store.mkdir store (Perms.Connection.create 0) localpath;
 
 		if cf.domain_init then (
-			let usingxiu = Xc.using_injection () in
+			let usingxiu = Xc.is_fake () in
 			Connections.add_domain cons (Domains.create0 usingxiu domains);
-			Event.bind_virq eventchn
+			Event.bind_dom_exc_virq eventchn
 		);
 	);
 
@@ -275,7 +275,7 @@ let _ =
 	Logging.init cf.activate_access_log (fun () -> DB.to_file store cons "/var/run/xenstored/db");
 
 	let spec_fds = [ rw_sock; ro_sock ] @
-		       (if cf.domain_init then [ eventchn.Event.fd ] else []) in
+		       (if cf.domain_init then [ Event.fd eventchn ] else []) in
 
 	let xc = Xc.interface_open () in
 
@@ -285,7 +285,7 @@ let _ =
 			debug "new connection through socket";
 			Connections.add_anonymous cons cfd can_write
 		and handle_eventchn fd =
-			let port = Event.read_port eventchn in
+			let port = Event.pending eventchn in
 			finally (fun () ->
 				if port = eventchn.Event.virq_port then (
 					let (notify, deaddom) = Domains.cleanup xc domains in
@@ -293,14 +293,14 @@ let _ =
 					if deaddom <> [] || notify then
 						Connections.fire_spec_watches cons "@releaseDomain"
 				)
-			) (fun () -> Event.write_port eventchn port);
+			) (fun () -> Event.unmask eventchn port);
 		and do_if_set fd set fct =
 			if List.mem fd set then
 				fct fd in
 
 		do_if_set rw_sock rset (accept_connection true);
 		do_if_set ro_sock rset (accept_connection false);
-		do_if_set eventchn.Event.fd rset (handle_eventchn)
+		do_if_set (Event.fd eventchn) rset (handle_eventchn)
 		in
 
 	let last_stat_time = ref 0. in
diff -r 2e6a1485047a -r 15700c869b54 scripts/init.d-squeezed
--- a/scripts/init.d-squeezed	Thu Nov 18 05:36:56 2010 -0500
+++ b/scripts/init.d-squeezed	Thu Dec 02 10:50:03 2010 -0500
@@ -25,6 +25,7 @@ SUBSYS_FILE="/var/lock/subsys/squeezed"
 . /etc/init.d/functions
 
 if [ -e /var/xapi/xiu-xc ]; then
+	export XENCTRL_OSDEP=/opt/xensource/lib/xenctrl/osdep_xiu.so
 	export XIU=/var/xapi/xiu
 fi
 
diff -r 2e6a1485047a -r 15700c869b54 scripts/init.d-xapi
--- a/scripts/init.d-xapi	Thu Nov 18 05:36:56 2010 -0500
+++ b/scripts/init.d-xapi	Thu Dec 02 10:50:03 2010 -0500
@@ -16,6 +16,7 @@ if [ -f /etc/sysconfig/xapi ]; then
 fi
 
 if [ -e /var/xapi/xiu-xc ]; then
+	export XENCTRL_OSDEP=/opt/xensource/lib/xenctrl/osdep_xiu.so
 	export XIU=/var/xapi/xiu
 fi
 
diff -r 2e6a1485047a -r 15700c869b54 scripts/init.d-xenservices
--- a/scripts/init.d-xenservices	Thu Nov 18 05:36:56 2010 -0500
+++ b/scripts/init.d-xenservices	Thu Dec 02 10:50:03 2010 -0500
@@ -36,6 +36,7 @@ start() {
 	    failure $"xiu"
 	    exit 1
 	fi
+	export XENCTRL_OSDEP=/opt/xensource/lib/xenctrl/osdep_xiu.so
 	export XIU=/var/xapi/xiu
     fi
 	echo -n $"Starting xenstored: "	

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 6 of 6] HACK: xenguest updates for Xen 4.0/4.1
       [not found]         ` <patchbomb.1291732388-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
                             ` (2 preceding siblings ...)
  2010-12-07 14:33           ` [PATCH 4 of 6] REBASE-4.1: xenops: update PV console path in xenstore Ian Campbell
@ 2010-12-07 14:33           ` Ian Campbell
  3 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-07 14:33 UTC (permalink / raw)
  To: xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
	xen-api-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
  Cc: Ian Campbell

# HG changeset patch
# User root-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org
# Date 1291305009 18000
# Node ID 45271ebfd9022c7b0a2f962360c4c7a663706865
# Parent  15700c869b5445ce6d239513c54d6f69f9d62808
HACK: xenguest updates for Xen 4.0/4.1

Totally incomplete but enough to start a PV guest.

Not-signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>

diff -r 15700c869b54 -r 45271ebfd902 ocaml/xenguest/save_helpers.c
--- a/ocaml/xenguest/save_helpers.c	Thu Dec 02 10:50:03 2010 -0500
+++ b/ocaml/xenguest/save_helpers.c	Thu Dec 02 10:50:09 2010 -0500
@@ -22,150 +22,19 @@
  * Modifications (c) Citrix Systems Inc
  */
 
-#include <err.h>
 #include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <grp.h>
 
 #include <xs.h>
 #include <xenctrl.h>
 #include <xenguest.h>
 
-static char *qemu_active_path;
-static char *qemu_next_active_path;
-static int qemu_shmid = -1;
-static struct xs_handle *xs;
-
-
-/* Mark the shared-memory segment for destruction */
-static void qemu_destroy_buffer(void)
-{
-    if (qemu_shmid != -1)
-        shmctl(qemu_shmid, IPC_RMID, NULL);
-    qemu_shmid = -1;
+int switch_qemu_logdirty(int domid, unsigned enable, void *data)
+{	
+	return 1; /* XXX actually do something! */
 }
 
-/* Get qemu to change buffers. */
-void qemu_flip_buffer(int domid, int next_active)
+int do_domain_suspend(void* data)
 {
-    char digit = '0' + next_active;
-    unsigned int len;
-    char *active_str, **watch;
-    struct timeval tv;
-    fd_set fdset;
-    int rc;
-
-    /* Tell qemu that we want it to start writing log-dirty bits to the
-     * other buffer */
-    if (!xs_write(xs, XBT_NULL, qemu_next_active_path, &digit, 1)) {
-        errx(1, "can't write next-active to store path (%s)\n",
-              qemu_next_active_path);
-        exit(1);
-    }
-
-    /* Wait a while for qemu to signal that it has switched to the new
-     * active buffer */
- read_again:
-    tv.tv_sec = 60;
-    tv.tv_usec = 0;
-    FD_ZERO(&fdset);
-    FD_SET(xs_fileno(xs), &fdset);
-    rc = select(xs_fileno(xs) + 1, &fdset, NULL, NULL, &tv);
-    if (rc == 0)
-        errx(1, "timed out waiting for qemu to switch buffers\n");
-    else if (rc < 0) {
-        if (errno == EINTR) 
-            goto read_again;
-        err(1, "error waiting for qemu to switch buffers");
-    }
-    watch = xs_read_watch(xs, &len);
-    free(watch);
-
-    active_str = xs_read(xs, XBT_NULL, qemu_active_path, &len);
-    if (active_str == NULL || active_str[0] - '0' != next_active)
-        /* Watch fired but value is not yet right */
-        goto read_again;
+	return 1; /* XXX actually do something! */
 }
 
-void * init_qemu_maps(int domid, unsigned int bitmap_size)
-{
-    key_t key;
-    char key_ascii[17] = {0,};
-    void *seg;
-    char *path, *p;
-    struct shmid_ds ds_buf;
-    struct group *gr;
-
-    /* Make a shared-memory segment */
-    do {
-        key = rand(); /* No security, just a sequence of numbers */
-        qemu_shmid = shmget(key, 2 * bitmap_size, 
-                       IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
-        if (qemu_shmid == -1 && errno != EEXIST)
-            errx(1, "can't get shmem to talk to qemu-dm");
-    } while (qemu_shmid == -1);
-
-    /* Remember to tidy up after ourselves */
-    atexit(qemu_destroy_buffer);
-
-    /* Change owner so that qemu can map it. */
-    gr = getgrnam("qemu_base");
-    if (!gr)
-        err(1, "can't get qemu gid");
-    if (shmctl(qemu_shmid, IPC_STAT, &ds_buf) < 0)
-        err(1, "can't get status of shm area");
-    ds_buf.shm_perm.gid = gr->gr_gid + (unsigned short)domid;
-    if (shmctl(qemu_shmid, IPC_SET, &ds_buf) < 0)
-        err(1, "can't change gid of shm area");
-
-    /* Map it into our address space */
-    seg = shmat(qemu_shmid, NULL, 0);
-    if (seg == (void *) -1)
-        errx(1, "can't map shmem to talk to qemu-dm");
-    memset(seg, 0, 2 * bitmap_size);
-
-    /* Write the size of it into the first 32 bits */
-    *(uint32_t *)seg = bitmap_size;
-
-    /* Tell qemu about it */
-    if ((xs = xs_daemon_open()) == NULL)
-        errx(1, "Couldn't contact xenstore");
-    if (!(path = xs_get_domain_path(xs, domid)))
-        errx(1, "can't get domain path in store");
-    if (!(path = realloc(path, strlen(path)
-                         + strlen("/logdirty/next-active") + 1)))
-        errx(1, "no memory for constructing xenstore path");
-    strcat(path, "/logdirty/");
-    p = path + strlen(path);
-
-    strcpy(p, "key");
-    snprintf(key_ascii, 17, "%16.16llx", (unsigned long long) key);
-    if (!xs_write(xs, XBT_NULL, path, key_ascii, 16))
-        errx(1, "can't write key (%s) to store path (%s)\n", key_ascii, path);
-
-    /* Watch for qemu's indication of the active buffer, and request it
-     * to start writing to buffer 0 */
-    strcpy(p, "active");
-    if (!xs_watch(xs, path, "qemu-active-buffer"))
-        errx(1, "can't set watch in store (%s)\n", path);
-    if (!(qemu_active_path = strdup(path)))
-        errx(1, "no memory for copying xenstore path");
-
-    strcpy(p, "next-active");
-    if (!(qemu_next_active_path = strdup(path)))
-        errx(1, "no memory for copying xenstore path");
-
-    qemu_flip_buffer(domid, 0);
-
-    free(path);
-    return seg;
-}
-
-/***********************************************************************/
diff -r 15700c869b54 -r 45271ebfd902 ocaml/xenguest/xenguest_stubs.c
--- a/ocaml/xenguest/xenguest_stubs.c	Thu Dec 02 10:50:03 2010 -0500
+++ b/ocaml/xenguest/xenguest_stubs.c	Thu Dec 02 10:50:09 2010 -0500
@@ -34,7 +34,7 @@
 #include <caml/signals.h>
 #include <caml/fail.h>
 
-#define _H(__h) (Int_val(__h))
+#define _H(__h) ((xc_interface *)(__h))
 #define _D(__d) ((uint32_t)Int_val(__d))
 
 #define None_val (Val_int(0))
@@ -138,17 +138,17 @@ get_flags(struct flags *f, int domid)
 }
 
 
-static void failwith_oss_xc(char *fct)
+static void failwith_oss_xc(xc_interface *xch, char *fct)
 {
 	char buf[80];
 	const xc_error *error;
 
-	error = xc_get_last_error();
+	error = xc_get_last_error(xch);
 	if (error->code == XC_ERROR_NONE)
 		snprintf(buf, 80, "%s: [%d] %s", fct, errno, strerror(errno));
 	else
 		snprintf(buf, 80, "%s: [%d] %s", fct, error->code, error->message);
-	xc_clear_last_error();
+	xc_clear_last_error(xch);
 	caml_failwith(buf);
 }
 
@@ -172,41 +172,55 @@ static int suspend_flag_list[] = {
 
 CAMLprim value stub_xenguest_init()
 {
-	int handle;
+	xc_interface *xch;
 
-	handle = xc_interface_open();
-	if (handle == -1)
-		failwith_oss_xc("xc_interface_open");
-	return Val_int(handle);
+	xch = xc_interface_open(NULL, NULL, 0);
+	if (xch == NULL)
+		failwith_oss_xc(NULL, "xc_interface_open");
+	return (value)xch;
 }
 
 CAMLprim value stub_xenguest_close(value xenguest_handle)
 {
 	CAMLparam1(xenguest_handle);
-	xc_interface_close(Int_val(xenguest_handle));
+	xc_interface_close(_H(xenguest_handle));
 	CAMLreturn(Val_unit);
 }
 
-extern struct xc_dom_image *xc_dom_allocate(const char *cmdline, const char *features);
+extern struct xc_dom_image *xc_dom_allocate(xc_interface *xch, const char *cmdline, const char *features);
 
-static void configure_vcpus(int handle, int domid, struct flags f){
+static void configure_vcpus(xc_interface *xch, int domid, struct flags f){
   struct xen_domctl_sched_credit sdom;
   int i, r;
   if (f.vcpu_affinity != 0L){ /* 0L means unset */
+    xc_cpumap_t cpumap = xc_cpumap_alloc(xch);
+    if (cpumap == NULL)
+      failwith_oss_xc(xch, "xc_cpumap_alloc");
+
+    for (i=0; i<64; i++) {
+      if (f.vcpu_affinity & 1<<i)
+        cpumap[i/8] |= i << (i&7);
+    }
+
     for (i=0; i<f.vcpus; i++){
-      r = xc_vcpu_setaffinity(handle, domid, i, f.vcpu_affinity);
-      if (r)
-	failwith_oss_xc("xc_vcpu_setaffinity");
+      r = xc_vcpu_setaffinity(xch, domid, i, cpumap);
+      if (r) {
+        free(cpumap);
+	failwith_oss_xc(xch, "xc_vcpu_setaffinity");
+      }
     }
-  };
-  r = xc_sched_credit_domain_get(handle, domid, &sdom);
+
+    free(cpumap);
+  }
+
+  r = xc_sched_credit_domain_get(xch, domid, &sdom);
   if (r)
-    failwith_oss_xc("xc_sched_credit_domain_get");
+    failwith_oss_xc(xch, "xc_sched_credit_domain_get");
   if (f.vcpu_weight != 0L) sdom.weight = f.vcpu_weight;
   if (f.vcpu_cap != 0L) sdom.cap = f.vcpu_cap;
-  r = xc_sched_credit_domain_set(handle, domid, &sdom);
+  r = xc_sched_credit_domain_set(xch, domid, &sdom);
   if (r)
-    failwith_oss_xc("xc_sched_credit_domain_set");
+    failwith_oss_xc(xch, "xc_sched_credit_domain_set");
 }
 
 CAMLprim value stub_xc_linux_build_native(value xc_handle, value domid,
@@ -228,7 +242,7 @@ CAMLprim value stub_xc_linux_build_nativ
 	char c_protocol[64];
 
 	/* Copy the ocaml values into c-land before dropping the mutex */
-	int c_xc_handle = _H(xc_handle);
+	xc_interface *xch = _H(xc_handle);
 	unsigned int c_mem_start_mib = Int_val(mem_start_mib);
 	uint32_t c_domid = _D(domid);
 	char *c_image_name = strdup(String_val(image_name));
@@ -241,14 +255,14 @@ CAMLprim value stub_xc_linux_build_nativ
 	get_flags(&f,c_domid);
 
 	xc_dom_loginit();
-	dom = xc_dom_allocate(String_val(cmdline), String_val(features));
+	dom = xc_dom_allocate(xch, String_val(cmdline), String_val(features));
 	if (!dom)
-		failwith_oss_xc("xc_dom_allocate");
+		failwith_oss_xc(xch, "xc_dom_allocate");
 
-	configure_vcpus(c_xc_handle, c_domid, f);
+	configure_vcpus(xch, c_domid, f);
 
 	caml_enter_blocking_section();
-	r = xc_dom_linux_build(c_xc_handle, dom, c_domid, c_mem_start_mib,
+	r = xc_dom_linux_build(xch, dom, c_domid, c_mem_start_mib,
 	                       c_image_name, c_ramdisk_name, c_flags,
 	                       c_store_evtchn, &store_mfn,
 	                       c_console_evtchn, &console_mfn);
@@ -264,7 +278,7 @@ CAMLprim value stub_xc_linux_build_nativ
 	xc_dom_release(dom);
 
 	if (r != 0)
-		failwith_oss_xc("xc_dom_linux_build");
+		failwith_oss_xc(xch, "xc_dom_linux_build");
 
 	result = caml_alloc_tuple(3);
 	Store_field(result, 0, caml_copy_nativeint(store_mfn));
@@ -282,7 +296,7 @@ CAMLprim value stub_xc_linux_build_bytec
 	                                  argv[8], argv[9], argv[10]);
 }
 
-static int hvm_build_set_params(int handle, int domid,
+static int hvm_build_set_params(xc_interface *xch, int domid,
                                 int store_evtchn, unsigned long *store_mfn,
 				struct flags f)
 {
@@ -290,7 +304,7 @@ static int hvm_build_set_params(int hand
 	uint8_t *va_map, sum;
 	int i;
 
-	va_map = xc_map_foreign_range(handle, domid,
+	va_map = xc_map_foreign_range(xch, domid,
 			    XC_PAGE_SIZE, PROT_READ | PROT_WRITE,
 			    HVM_INFO_PFN);
 	if (va_map == NULL)
@@ -300,22 +314,24 @@ static int hvm_build_set_params(int hand
 	va_hvm->acpi_enabled = f.acpi;
 	va_hvm->apic_mode = f.apic;
 	va_hvm->nr_vcpus = f.vcpus;
+#if 0
         va_hvm->s4_enabled = f.acpi_s4;
         va_hvm->s3_enabled = f.acpi_s3;
+#endif
 	va_hvm->checksum = 0;
 	for (i = 0, sum = 0; i < va_hvm->length; i++)
 		sum += ((uint8_t *) va_hvm)[i];
 	va_hvm->checksum = -sum;
 	munmap(va_map, XC_PAGE_SIZE);
 
-	xc_get_hvm_param(handle, domid, HVM_PARAM_STORE_PFN, store_mfn);
-	xc_set_hvm_param(handle, domid, HVM_PARAM_PAE_ENABLED, f.pae);
+	xc_get_hvm_param(xch, domid, HVM_PARAM_STORE_PFN, store_mfn);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_PAE_ENABLED, f.pae);
 #ifdef HVM_PARAM_VIRIDIAN
-	xc_set_hvm_param(handle, domid, HVM_PARAM_VIRIDIAN, f.viridian);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_VIRIDIAN, f.viridian);
 #endif
-	xc_set_hvm_param(handle, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn);
 #ifndef XEN_UNSTABLE
-	xc_set_hvm_param(handle, domid, HVM_PARAM_NX_ENABLED, f.nx);
+	xc_set_hvm_param(xch, domid, HVM_PARAM_NX_ENABLED, f.nx);
 #endif
 	return 0;
 }
@@ -330,16 +346,18 @@ CAMLprim value stub_xc_hvm_build_native(
 	CAMLlocal1(ret);
 	char *image_name_c = strdup(String_val(image_name));
 	char *error[256];
+	xc_interface *xch;
 
 	unsigned long store_mfn=0;
 	int r;
 	struct flags f;
 	get_flags(&f, _D(domid));
 
-	configure_vcpus(_H(xc_handle), _D(domid), f);
+	xch = _H(xc_handle);
+	configure_vcpus(xch, _D(domid), f);
 
 	caml_enter_blocking_section ();
-	r = xc_hvm_build_target_mem(_H(xc_handle), _D(domid),
+	r = xc_hvm_build_target_mem(xch, _D(domid),
 	                            Int_val(mem_max_mib),
 	                            Int_val(mem_start_mib),
 	                            image_name_c);
@@ -348,13 +366,13 @@ CAMLprim value stub_xc_hvm_build_native(
 	free(image_name_c);
 
 	if (r)
-		failwith_oss_xc("hvm_build");
+		failwith_oss_xc(xch, "hvm_build");
 
 
-	r = hvm_build_set_params(_H(xc_handle), _D(domid),
+	r = hvm_build_set_params(xch, _D(domid),
 				 Int_val(store_evtchn), &store_mfn, f);
 	if (r)
-		failwith_oss_xc("hvm_build_params");
+		failwith_oss_xc(xch, "hvm_build_params");
 
 	ret = caml_copy_nativeint(store_mfn);
 	CAMLreturn(ret);
@@ -366,8 +384,8 @@ CAMLprim value stub_xc_hvm_build_bytecod
 	                                argv[4], argv[5]);
 }
 
-extern void qemu_flip_buffer(int domid, int next_active);
-extern void * init_qemu_maps(int domid, unsigned int bitmap_size);
+extern int switch_qemu_logdirty(int domid, unsigned enable, void *data);
+extern int do_domain_suspend(void* data);
 
 CAMLprim value stub_xc_domain_save(value handle, value fd, value domid,
                                    value max_iters, value max_factors,
@@ -375,24 +393,23 @@ CAMLprim value stub_xc_domain_save(value
 {
 	CAMLparam5(handle, fd, domid, max_iters, max_factors);
 	CAMLxparam2(flags, hvm);
-	void *(*init_maps)(int, unsigned);
-	void (*flip_buffer)(int, int);
+	struct save_callbacks callbacks;
 	uint32_t c_flags;
 	int r;
 
-	init_maps = (Bool_val(hvm)) ? init_qemu_maps : NULL;
-	flip_buffer = (Bool_val(hvm)) ? qemu_flip_buffer : NULL;
+	c_flags = caml_convert_flag_list(flags, suspend_flag_list);
 
-	c_flags = caml_convert_flag_list(flags, suspend_flag_list);
+	memset(&callbacks, 0, sizeof(callbacks));
+	callbacks.suspend = &do_domain_suspend;	
+	callbacks.switch_qemu_logdirty = &switch_qemu_logdirty;
 
 	caml_enter_blocking_section();
 	r = xc_domain_save(_H(handle), Int_val(fd), _D(domid),
 	                   Int_val(max_iters), Int_val(max_factors),
-	                   c_flags, dispatch_suspend,
-	                   Bool_val(hvm), init_maps, flip_buffer);
+	                   c_flags, &callbacks, Bool_val(hvm));
 	caml_leave_blocking_section();
 	if (r)
-		failwith_oss_xc("xc_domain_save");
+		failwith_oss_xc(_H(handle), "xc_domain_save");
 
 	CAMLreturn(Val_unit);
 }
@@ -413,7 +430,7 @@ CAMLprim value stub_xc_domain_resume_slo
 	/* hard code fast to 0, we only want to expose the slow version here */
 	r = xc_domain_resume(_H(handle), _D(domid), 0);
 	if (r)
-		failwith_oss_xc("xc_domain_resume");
+		failwith_oss_xc(_H(handle), "xc_domain_resume");
 	CAMLreturn(Val_unit);
 }
 
@@ -444,10 +461,10 @@ CAMLprim value stub_xc_domain_restore(va
 	r = xc_domain_restore(_H(handle), Int_val(fd), _D(domid),
 	                      c_store_evtchn, &store_mfn,
 	                      c_console_evtchn, &console_mfn,
-			      Bool_val(hvm), f.pae);
+			      Bool_val(hvm), f.pae, 0 /*superpages*/);
 	caml_leave_blocking_section();
 	if (r)
-		failwith_oss_xc("xc_domain_restore");
+		failwith_oss_xc(_H(handle), "xc_domain_restore");
 
 	result = caml_alloc_tuple(2);
 	Store_field(result, 0, caml_copy_nativeint(store_mfn));
@@ -469,6 +486,6 @@ CAMLprim value stub_xc_domain_dumpcore(v
 
 	r = xc_domain_dumpcore(_H(handle), _D(domid), String_val(file));
 	if (r)
-		failwith_oss_xc("xc_domain_dumpcore");
+		failwith_oss_xc(_H(handle), "xc_domain_dumpcore");
 	CAMLreturn(Val_unit);
 }
diff -r 15700c869b54 -r 45271ebfd902 ocaml/xenops/xenops.ml
--- a/ocaml/xenops/xenops.ml	Thu Dec 02 10:50:03 2010 -0500
+++ b/ocaml/xenops/xenops.ml	Thu Dec 02 10:50:09 2010 -0500
@@ -29,8 +29,8 @@ let print_xen_physinfo ~xc =
 	printf "nr_cpus = %d\n" physinfo.Xc.nr_cpus;
 	printf "threads_per_core = %d\n" physinfo.Xc.threads_per_core;
 	printf "cores_per_socket = %d\n" physinfo.Xc.cores_per_socket;
-	printf "sockets_per_node = %d\n" physinfo.Xc.sockets_per_node;
-	printf "nr_nodes = %d\n" physinfo.Xc.nr_nodes;
+	(*printf "sockets_per_node = %d\n" physinfo.Xc.sockets_per_node;*)
+	(*printf "nr_nodes = %d\n" physinfo.Xc.nr_nodes;*)
 	printf "cpu_khz = %d\n" physinfo.Xc.cpu_khz;
 	printf "total_pages = %s (%Ld Mb)\n" (Nativeint.to_string physinfo.Xc.total_pages) totalmib;
 	printf "free_pages = %s (%Ld Mb)\n" (Nativeint.to_string physinfo.Xc.free_pages) freemib;

^ permalink raw reply	[flat|nested] 66+ messages in thread

* RE: [Xen-API] [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg
  2010-12-07 14:32       ` [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Ian Campbell
       [not found]         ` <patchbomb.1291732364-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
  2010-12-07 14:32         ` [PATCH 2 of 3] Define $(RPM) for use in Makefile Ian Campbell
@ 2010-12-08 18:19         ` Dave Scott
  2 siblings, 0 replies; 66+ messages in thread
From: Dave Scott @ 2010-12-08 18:19 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Ian Campbell

> The following short series of patches makes xen-dist-ocaml.hg easier to
> use
> from build-xapi-toolstack.sh.

Thanks for these. I'll push them upstream once we've completed our hg to git conversion (hopefully imminent)... 

Cheers,
Dave

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg
  2010-12-07 14:32     ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
                         ` (2 preceding siblings ...)
  2010-12-07 14:32       ` [PATCH 5 of 5] HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same Ian Campbell
@ 2010-12-13 17:23       ` Stefano Stabellini
  2010-12-15 11:03         ` Vincent Hanquez
       [not found]       ` <m2n.s.1PPykG-000YDj@chiark.greenend.org.uk>
  4 siblings, 1 reply; 66+ messages in thread
From: Stefano Stabellini @ 2010-12-13 17:23 UTC (permalink / raw)
  To: Ian Campbell; +Cc: Ian Campbell, xen-devel, Vincent Hanquez, xen-api

On Tue, 7 Dec 2010, Ian Campbell wrote:
> The following series of patches lays some ground work to enable XCP to move, at
> some point in the future, to the in-tree ocaml bindings which will come with
> Xen 4.1
> 
> This is the xen-unstable.hg portion.
> 
> All but the last patch are intended for immediate consideration.
> 

Vincent, do you have any comments on these?

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg
       [not found]       ` <m2n.s.1PPykG-000YDj@chiark.greenend.org.uk>
@ 2010-12-14 19:22         ` Ian Jackson
  2011-01-06 17:38         ` Ian Jackson
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Jackson @ 2010-12-14 19:22 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel, xen-api

Ian Campbell writes ("[Xen-devel] [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg"):
> ocaml: resynchronise uuid library with xen-api-libs.hg

After I applied 1-4 of this series, I got this compile error:

cc1: warnings being treated as errors
xc_stubs.c: In function 'stub_xc_interface_is_fake':
xc_stubs.c:128: error: implicit declaration of function 'xc_interface_is_fake'
make[7]: *** [xc_stubs.o] Error 1
make[7]: Leaving directory `/u/iwj/work/xen-unstable-tools.hg/tools/ocaml/libs/xc'
make[6]: *** [subdir-install-xc] Error 2
make[6]: Leaving directory `/u/iwj/work/xen-unstable-tools.hg/tools/ocaml/libs'

Perhaps this needs to come after your giant libxc evtchn series ?

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg
  2010-12-13 17:23       ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Stefano Stabellini
@ 2010-12-15 11:03         ` Vincent Hanquez
  2010-12-16  9:56           ` Ian Campbell
  0 siblings, 1 reply; 66+ messages in thread
From: Vincent Hanquez @ 2010-12-15 11:03 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: Ian Campbell, xen-devel, xen-api

On 13/12/10 17:23, Stefano Stabellini wrote:
> Vincent, do you have any comments on these?

Not much. Personally I think it would be better that xcext is folded in 
xc. It just make the moving to upstream module more transparent, and the
convergence quicker.

It's also probably required that libxl knows to use stuff that have been 
left in xcext if XCP/XCI is ever going to use it.

-- 
Vincent

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg
  2010-12-15 11:03         ` Vincent Hanquez
@ 2010-12-16  9:56           ` Ian Campbell
  0 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2010-12-16  9:56 UTC (permalink / raw)
  To: Vincent Hanquez; +Cc: xen-api, xen-devel, Stefano Stabellini

On Wed, 2010-12-15 at 11:03 +0000, Vincent Hanquez wrote:
> On 13/12/10 17:23, Stefano Stabellini wrote:
> > Vincent, do you have any comments on these?
> 
> Not much. Personally I think it would be better that xcext is folded in 
> xc. It just make the moving to upstream module more transparent, and the
> convergence quicker.

> It's also probably required that libxl knows to use stuff that have been 
> left in xcext if XCP/XCI is ever going to use it.

The stuff in xcext depends on features/interfaces which are only in the
XCP hypervisor patch queue and not upstream which is why I didn't add
the support upstream libxc.

When those hypervisor patches get upstreamed then the bindings should be
added to upstream libxc (or possibly libxl in some cases) at that time.
Certainly the intention should be that xcext disappears with time.

In the meantime perhaps it would make sense to add patches to the XCP
patch queue to add those features to libxc there instead of having
xcext.

I think some of xcext might also be obsolete and doesn't do anything on
modern hypervisors but I didn't check that closely.

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg
       [not found]       ` <m2n.s.1PPykG-000YDj@chiark.greenend.org.uk>
  2010-12-14 19:22         ` [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg Ian Jackson
@ 2011-01-06 17:38         ` Ian Jackson
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Jackson @ 2011-01-06 17:38 UTC (permalink / raw)
  To: xen-devel, xen-api; +Cc: Vincent Hanquez

Ian Campbell writes ("[Xen-devel] [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg"):
> ocaml: resynchronise uuid library with xen-api-libs.hg

Thanks, I have applied 1-4 from this series.

Ian.

^ permalink raw reply	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2011-01-06 17:38 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-18 10:49 XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) Ian Campbell
2010-11-18 10:50 ` [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Ian Campbell
     [not found]   ` <patchbomb.1290077407-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-11-18 10:50     ` [PATCH 1 of 3] Query rpm to find build directories Ian Campbell
2010-11-18 10:50     ` [PATCH 2 of 3] Define $(RPM) for use in Makefile Ian Campbell
2010-11-18 10:50   ` [PATCH 3 of 3] Install additional packages Ian Campbell
     [not found] ` <1290077348.31507.5282.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-11-18 10:50   ` [PATCH 0 of 4] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
     [not found]     ` <patchbomb.1290077414-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-11-18 10:50       ` [PATCH 1 of 4] Query rpm to find build directories Ian Campbell
2010-11-18 10:50       ` [PATCH 2 of 4] xc: split xc non-upstream bindings into xcext module Ian Campbell
2010-11-18 14:36         ` [Xen-API] " Vincent Hanquez
2010-11-18 15:35           ` Ian Campbell
2010-11-19 11:43             ` Vincent Hanquez
     [not found]               ` <4CE662D9.6030808-mvvWK6WmYclDPfheJLI6IQ@public.gmane.org>
2010-11-19 13:32                 ` Ian Campbell
     [not found]             ` <1290094550.31507.5391.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-11-19 17:43               ` [Xen-devel] " Ian Jackson
     [not found]                 ` <19686.46942.593712.651242-msK/Ju9w1zmnROeE8kUsYhEHtJm+Wo+I@public.gmane.org>
2010-11-22 13:05                   ` Ian Campbell
     [not found]                 ` <m2n.s.1PKW6s-0019ae@chiark.greenend.org.uk>
     [not found]                   ` <m2n.s.1PKW6s-0019ae-QGMSyCZBOSwv4zxTlrOuLwNdhmdF6hFW@public.gmane.org>
2010-11-23 18:02                     ` Ian Jackson
2010-11-19 13:42           ` Re: [Xen-API] " Gianni Tedesco
2010-11-18 10:50     ` [PATCH 3 of 4] add configure-time option to use system installed Xen library bindings Ian Campbell
2010-11-18 10:50     ` [PATCH 4 of 4] REBASE-4.1: default to using system installed bindings if Xen is available Ian Campbell
2010-11-18 10:50   ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
2010-11-18 10:50     ` [PATCH 1 of 6] Query rpm to find build directories Ian Campbell
2010-11-18 10:50     ` [PATCH 2 of 6] xc: use Xcext library rather than Xc where appropriate Ian Campbell
     [not found]     ` <patchbomb.1290077422-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-11-18 10:50       ` [PATCH 3 of 6] REBASE-4.1: vmops: apply CPUID to all domains Ian Campbell
2010-11-18 10:50       ` [PATCH 5 of 6] HACK/PoC: adjust for minor differences in upstream Xc bindings Ian Campbell
2010-11-18 10:50     ` [PATCH 4 of 6] REBASE-4.1: xenops: update PV console path in xenstore Ian Campbell
2010-11-18 10:50     ` [PATCH 6 of 6] HACK: xenguest updates for Xen 4.0/4.1 Ian Campbell
2010-11-18 10:50   ` [PATCH 0 of 7] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
     [not found]     ` <patchbomb.1290077432-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-11-18 10:50       ` [PATCH 1 of 7] libxc: rename safe_strerror to _xc_safestrerror and pass XC handle Ian Campbell
2010-11-18 10:50       ` [PATCH 4 of 7] ocaml: resynchronise uuid library with xen-api-libs.hg Ian Campbell
2010-11-18 11:32         ` Gianni Tedesco
2010-11-18 12:27           ` Ian Campbell
     [not found]             ` <1290083222.31507.5290.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-11-18 14:44               ` [Xen-devel] " Vincent Hanquez
2010-11-18 10:50       ` [PATCH 6 of 7] ocaml: xc bindings: use libxenctrl and libxenguest Ian Campbell
2010-11-18 10:50       ` [PATCH 7 of 7] HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same Ian Campbell
2010-11-18 10:50     ` [PATCH 2 of 7] libxc: allow caller to specify no re-entrancy protection when opening the interface Ian Campbell
2010-11-18 10:50     ` [PATCH 3 of 7] ocaml: install built modules Ian Campbell
2010-11-18 10:50     ` [PATCH 5 of 7] ocaml: add dependency to module metadata Ian Campbell
2010-12-07 14:30   ` [Xen-devel] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) Ian Campbell
2010-12-07 14:32     ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Ian Campbell
     [not found]       ` <patchbomb.1291732371-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-12-07 14:32         ` [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg Ian Campbell
2010-12-07 14:32         ` [PATCH 2 of 5] ocaml: add dependency to module metadata Ian Campbell
2010-12-07 14:32         ` [PATCH 4 of 5] ocaml: evtchn+xc bindings: use libxenctrl and libxenguest Ian Campbell
2010-12-07 14:32       ` [PATCH 3 of 5] ocaml: rename Evtchn.bind_virq as Evtchn.bind_dom_exc_virq Ian Campbell
2010-12-07 14:32       ` [PATCH 5 of 5] HACK: Do not install some stuff which conflicts with out-off-tree XCP versions of the same Ian Campbell
2010-12-13 17:23       ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-unstable.hg Stefano Stabellini
2010-12-15 11:03         ` Vincent Hanquez
2010-12-16  9:56           ` Ian Campbell
     [not found]       ` <m2n.s.1PPykG-000YDj@chiark.greenend.org.uk>
2010-12-14 19:22         ` [PATCH 1 of 5] ocaml: resynchronise uuid library with xen-api-libs.hg Ian Jackson
2011-01-06 17:38         ` Ian Jackson
     [not found]     ` <1291732233.13966.3198.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-12-07 14:32       ` [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Ian Campbell
     [not found]         ` <patchbomb.1291732364-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-12-07 14:32           ` [PATCH 1 of 3] Query rpm to find build directories Ian Campbell
2010-12-07 14:32           ` [PATCH 3 of 3] Install additional packages Ian Campbell
2010-12-07 14:32         ` [PATCH 2 of 3] Define $(RPM) for use in Makefile Ian Campbell
2010-12-08 18:19         ` [Xen-API] [PATCH 0 of 3] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-dist-ocaml.hg Dave Scott
2010-12-07 14:32       ` [PATCH 0 of 5] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api-libs.hg Ian Campbell
2010-12-07 14:33         ` [PATCH 1 of 5] Query rpm to find build directories Ian Campbell
     [not found]         ` <patchbomb.1291732379-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-12-07 14:33           ` [PATCH 2 of 5] xc: split xc non-upstream bindings into xcext module Ian Campbell
2010-12-07 14:33           ` [PATCH 3 of 5] add configure-time option to use system installed Xen library bindings Ian Campbell
2010-12-07 14:33           ` [PATCH 5 of 5] REBASE-4.1: xiu: add xenctrlosdep backend Ian Campbell
2010-12-07 14:33         ` [PATCH 4 of 5] REBASE-4.1: default to using system installed bindings if Xen is available Ian Campbell
2010-12-07 14:33       ` [PATCH 0 of 6] XCP: Allow XCP to use ocaml library bindings in Xen unstable (which will become Xen 4.1) -- xen-api.hg Ian Campbell
     [not found]         ` <patchbomb.1291732388-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2010-12-07 14:33           ` [PATCH 1 of 6] Query rpm to find build directories Ian Campbell
2010-12-07 14:33           ` [PATCH 2 of 6] xc: use Xcext library rather than Xc where appropriate Ian Campbell
2010-12-07 14:33           ` [PATCH 4 of 6] REBASE-4.1: xenops: update PV console path in xenstore Ian Campbell
2010-12-07 14:33           ` [PATCH 6 of 6] HACK: xenguest updates for Xen 4.0/4.1 Ian Campbell
2010-12-07 14:33         ` [PATCH 3 of 6] REBASE-4.1: vmops: apply CPUID to all domains Ian Campbell
2010-12-07 14:33         ` [PATCH 5 of 6] HACK/PoC: adjust for minor differences in upstream Xc bindings Ian Campbell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.