From: Ian Campbell Date: Fri, 3 Dec 2010 09:36:47 +0000 (+0000) Subject: libxc: add ability to query OS interface for "fakeness" X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~11050 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=048f6a9497466b39eb6f34eb0a699e632c15929f;p=xen.git libxc: add ability to query OS interface for "fakeness" i.e. not running on a real hypervisor Allows users of the library to adjust behaviour. I don't especially like this violation of the abstraction but both oxenstored and xapi use this to avoid difficult to simulate operations when running on the simulator. Signed-off-by: Ian Campbell Signed-off-by: Ian Jackson --- diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c index 7c62ee375e..a1ed5f450c 100644 --- a/tools/libxc/xc_linux.c +++ b/tools/libxc/xc_linux.c @@ -697,6 +697,7 @@ static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum xc_osdep_ty xc_osdep_info_t xc_osdep_info = { .name = "Linux Native OS interface", .init = &linux_osdep_init, + .fake = 0, }; /* diff --git a/tools/libxc/xc_minios.c b/tools/libxc/xc_minios.c index 2d5b43544c..990f7142ef 100644 --- a/tools/libxc/xc_minios.c +++ b/tools/libxc/xc_minios.c @@ -549,6 +549,7 @@ static struct xc_osdep_ops *minios_osdep_init(xc_interface *xch, enum xc_osdep_t xc_osdep_info_t xc_osdep_info = { .name = "Minios Native OS interface", .init = &minios_osdep_init, + .fake = 0, }; /* diff --git a/tools/libxc/xc_netbsd.c b/tools/libxc/xc_netbsd.c index 47169ee5b4..d3ec9c54e5 100644 --- a/tools/libxc/xc_netbsd.c +++ b/tools/libxc/xc_netbsd.c @@ -373,6 +373,7 @@ static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_t xc_osdep_info_t xc_osdep_info = { .name = "Netbsd Native OS interface", .init = &netbsd_osdep_init, + .fake = 0, }; /* diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c index aaa0d34ce3..69b674dabf 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -122,6 +122,19 @@ static int xc_interface_close_common(xc_interface *xch) return rc; } +int xc_interface_is_fake(void) +{ + xc_osdep_info_t info; + + if ( xc_osdep_get_info(NULL, &info) < 0 ) + return -1; + + /* Have a copy of info so can release the interface now. */ + xc_osdep_put(&info); + + return info.fake; +} + xc_interface *xc_interface_open(xentoollog_logger *logger, xentoollog_logger *dombuild_logger, unsigned open_flags) diff --git a/tools/libxc/xc_solaris.c b/tools/libxc/xc_solaris.c index beec2872d4..71bbbe62a2 100644 --- a/tools/libxc/xc_solaris.c +++ b/tools/libxc/xc_solaris.c @@ -321,6 +321,7 @@ static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum xc_osdep_ xc_osdep_info_t xc_osdep_info = { .name = "Solaris Native OS interface", .init = &solaris_osdep_init, + .fake = 0, }; /* diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 18d778bdb1..4827303b73 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -159,6 +159,15 @@ enum xc_open_flags { */ int xc_interface_close(xc_interface *xch); +/** + * Query the active OS interface (i.e. that which would be returned by + * xc_interface_open) to find out if it is fake (i.e. backends onto + * something other than an actual Xen hypervisor). + * + * @return 0 is "real", >0 if fake, -1 on error. + */ +int xc_interface_is_fake(void); + /* * HYPERCALL SAFE MEMORY BUFFER * diff --git a/tools/libxc/xenctrlosdep.h b/tools/libxc/xenctrlosdep.h index d862fcff85..874fd653b4 100644 --- a/tools/libxc/xenctrlosdep.h +++ b/tools/libxc/xenctrlosdep.h @@ -122,6 +122,9 @@ struct xc_osdep_info /* Returns ops function. */ xc_osdep_init_fn init; + + /* True if this interface backs onto a fake Xen. */ + int fake; }; typedef struct xc_osdep_info xc_osdep_info_t;