xen: Support new libxc calls from xen unstable.

This patch updates the libxenctrl calls in Qemu to use the new interface,
otherwise Qemu wouldn't be able to build against new versions of the
library.

We check libxenctrl version in configure, from Xen 3.3.0 to Xen
unstable.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
Anthony PERARD 2011-02-25 16:20:34 +00:00 committed by Alexander Graf
parent ce6bc29458
commit d5b93ddfef
6 changed files with 164 additions and 32 deletions

67
configure vendored
View File

@ -127,6 +127,7 @@ vnc_jpeg=""
vnc_png="" vnc_png=""
vnc_thread="no" vnc_thread="no"
xen="" xen=""
xen_ctrl_version=""
linux_aio="" linux_aio=""
attr="" attr=""
vhost_net="" vhost_net=""
@ -1180,20 +1181,81 @@ fi
if test "$xen" != "no" ; then if test "$xen" != "no" ; then
xen_libs="-lxenstore -lxenctrl -lxenguest" xen_libs="-lxenstore -lxenctrl -lxenguest"
# Xen unstable
cat > $TMPC <<EOF cat > $TMPC <<EOF
#include <xenctrl.h> #include <xenctrl.h>
#include <xs.h> #include <xs.h>
int main(void) { xs_daemon_open(); xc_interface_open(); return 0; } #include <stdint.h>
#include <xen/hvm/hvm_info_table.h>
#if !defined(HVM_MAX_VCPUS)
# error HVM_MAX_VCPUS not defined
#endif
int main(void) {
xc_interface *xc;
xs_daemon_open();
xc = xc_interface_open(0, 0, 0);
xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
xc_gnttab_open(NULL, 0);
return 0;
}
EOF EOF
if compile_prog "" "$xen_libs" ; then if compile_prog "" "$xen_libs" ; then
xen_ctrl_version=410
xen=yes xen=yes
libs_softmmu="$xen_libs $libs_softmmu"
# Xen 4.0.0
elif (
cat > $TMPC <<EOF
#include <xenctrl.h>
#include <xs.h>
#include <stdint.h>
#include <xen/hvm/hvm_info_table.h>
#if !defined(HVM_MAX_VCPUS)
# error HVM_MAX_VCPUS not defined
#endif
int main(void) {
xs_daemon_open();
xc_interface_open();
xc_gnttab_open();
xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
return 0;
}
EOF
compile_prog "" "$xen_libs"
) ; then
xen_ctrl_version=400
xen=yes
# Xen 3.3.0, 3.4.0
elif (
cat > $TMPC <<EOF
#include <xenctrl.h>
#include <xs.h>
int main(void) {
xs_daemon_open();
xc_interface_open();
xc_gnttab_open();
xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
return 0;
}
EOF
compile_prog "" "$xen_libs"
) ; then
xen_ctrl_version=330
xen=yes
# Xen not found or unsupported
else else
if test "$xen" = "yes" ; then if test "$xen" = "yes" ; then
feature_not_found "xen" feature_not_found "xen"
fi fi
xen=no xen=no
fi fi
if test "$xen" = yes; then
libs_softmmu="$xen_libs $libs_softmmu"
fi
fi fi
########################################## ##########################################
@ -2855,6 +2917,7 @@ if test "$bluez" = "yes" ; then
fi fi
if test "$xen" = "yes" ; then if test "$xen" = "yes" ; then
echo "CONFIG_XEN=y" >> $config_host_mak echo "CONFIG_XEN=y" >> $config_host_mak
echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
fi fi
if test "$io_thread" = "yes" ; then if test "$io_thread" = "yes" ; then
echo "CONFIG_IOTHREAD=y" >> $config_host_mak echo "CONFIG_IOTHREAD=y" >> $config_host_mak

View File

@ -43,7 +43,8 @@
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
/* public */ /* public */
int xen_xc; XenXC xen_xc = XC_HANDLER_INITIAL_VALUE;
XenGnttab xen_xcg = XC_HANDLER_INITIAL_VALUE;
struct xs_handle *xenstore = NULL; struct xs_handle *xenstore = NULL;
const char *xen_protocol; const char *xen_protocol;
@ -214,8 +215,8 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
xendev->debug = debug; xendev->debug = debug;
xendev->local_port = -1; xendev->local_port = -1;
xendev->evtchndev = xc_evtchn_open(); xendev->evtchndev = xen_xc_evtchn_open(NULL, 0);
if (xendev->evtchndev < 0) { if (xendev->evtchndev == XC_HANDLER_INITIAL_VALUE) {
xen_be_printf(NULL, 0, "can't open evtchn device\n"); xen_be_printf(NULL, 0, "can't open evtchn device\n");
qemu_free(xendev); qemu_free(xendev);
return NULL; return NULL;
@ -223,15 +224,15 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
fcntl(xc_evtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC); fcntl(xc_evtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) { if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
xendev->gnttabdev = xc_gnttab_open(); xendev->gnttabdev = xen_xc_gnttab_open(NULL, 0);
if (xendev->gnttabdev < 0) { if (xendev->gnttabdev == XC_HANDLER_INITIAL_VALUE) {
xen_be_printf(NULL, 0, "can't open gnttab device\n"); xen_be_printf(NULL, 0, "can't open gnttab device\n");
xc_evtchn_close(xendev->evtchndev); xc_evtchn_close(xendev->evtchndev);
qemu_free(xendev); qemu_free(xendev);
return NULL; return NULL;
} }
} else { } else {
xendev->gnttabdev = -1; xendev->gnttabdev = XC_HANDLER_INITIAL_VALUE;
} }
QTAILQ_INSERT_TAIL(&xendevs, xendev, next); QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
@ -277,10 +278,10 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
qemu_free(xendev->fe); qemu_free(xendev->fe);
} }
if (xendev->evtchndev >= 0) { if (xendev->evtchndev != XC_HANDLER_INITIAL_VALUE) {
xc_evtchn_close(xendev->evtchndev); xc_evtchn_close(xendev->evtchndev);
} }
if (xendev->gnttabdev >= 0) { if (xendev->gnttabdev != XC_HANDLER_INITIAL_VALUE) {
xc_gnttab_close(xendev->gnttabdev); xc_gnttab_close(xendev->gnttabdev);
} }
@ -664,8 +665,8 @@ int xen_be_init(void)
goto err; goto err;
} }
xen_xc = xc_interface_open(); xen_xc = xen_xc_interface_open(0, 0, 0);
if (xen_xc == -1) { if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
xen_be_printf(NULL, 0, "can't open xen interface\n"); xen_be_printf(NULL, 0, "can't open xen interface\n");
goto err; goto err;
} }

View File

@ -45,8 +45,8 @@ struct XenDevice {
int remote_port; int remote_port;
int local_port; int local_port;
int evtchndev; XenEvtchn evtchndev;
int gnttabdev; XenGnttab gnttabdev;
struct XenDevOps *ops; struct XenDevOps *ops;
QTAILQ_ENTRY(XenDevice) next; QTAILQ_ENTRY(XenDevice) next;
@ -55,7 +55,7 @@ struct XenDevice {
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
/* variables */ /* variables */
extern int xen_xc; extern XenXC xen_xc;
extern struct xs_handle *xenstore; extern struct xs_handle *xenstore;
extern const char *xen_protocol; extern const char *xen_protocol;

View File

@ -1,6 +1,8 @@
#ifndef QEMU_HW_XEN_COMMON_H #ifndef QEMU_HW_XEN_COMMON_H
#define QEMU_HW_XEN_COMMON_H 1 #define QEMU_HW_XEN_COMMON_H 1
#include "config-host.h"
#include <stddef.h> #include <stddef.h>
#include <inttypes.h> #include <inttypes.h>
@ -13,22 +15,87 @@
#include "qemu-queue.h" #include "qemu-queue.h"
/* /*
* tweaks needed to build with different xen versions * We don't support Xen prior to 3.3.0.
* 0x00030205 -> 3.1.0
* 0x00030207 -> 3.2.0
* 0x00030208 -> unstable
*/ */
#include <xen/xen-compat.h>
#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030205 /* Xen before 4.0 */
# define evtchn_port_or_error_t int #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
xen_pfn_t *arr, int *err,
unsigned int num)
{
return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
}
#endif #endif
#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030207
# define xc_map_foreign_pages xc_map_foreign_batch
#endif /* Xen before 4.1 */
#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030208 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
# define xen_mb() mb()
# define xen_rmb() rmb() typedef int XenXC;
# define xen_wmb() wmb() typedef int XenEvtchn;
typedef int XenGnttab;
# define XC_INTERFACE_FMT "%i"
# define XC_HANDLER_INITIAL_VALUE -1
static inline XenEvtchn xen_xc_evtchn_open(void *logger,
unsigned int open_flags)
{
return xc_evtchn_open();
}
static inline XenGnttab xen_xc_gnttab_open(void *logger,
unsigned int open_flags)
{
return xc_gnttab_open();
}
static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
unsigned int open_flags)
{
return xc_interface_open();
}
static inline int xc_fd(int xen_xc)
{
return xen_xc;
}
/* Xen 4.1 */
#else
typedef xc_interface *XenXC;
typedef xc_evtchn *XenEvtchn;
typedef xc_gnttab *XenGnttab;
# define XC_INTERFACE_FMT "%p"
# define XC_HANDLER_INITIAL_VALUE NULL
static inline XenEvtchn xen_xc_evtchn_open(void *logger,
unsigned int open_flags)
{
return xc_evtchn_open(logger, open_flags);
}
static inline XenGnttab xen_xc_gnttab_open(void *logger,
unsigned int open_flags)
{
return xc_gnttab_open(logger, open_flags);
}
static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
unsigned int open_flags)
{
return xc_interface_open(logger, dombuild_logger, open_flags);
}
/* FIXME There is now way to have the xen fd */
static inline int xc_fd(xc_interface *xen_xc)
{
return -1;
}
#endif #endif
#endif /* QEMU_HW_XEN_COMMON_H */ #endif /* QEMU_HW_XEN_COMMON_H */

View File

@ -242,7 +242,7 @@ err:
static void ioreq_unmap(struct ioreq *ioreq) static void ioreq_unmap(struct ioreq *ioreq)
{ {
int gnt = ioreq->blkdev->xendev.gnttabdev; XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
int i; int i;
if (ioreq->v.niov == 0) { if (ioreq->v.niov == 0) {
@ -275,7 +275,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
static int ioreq_map(struct ioreq *ioreq) static int ioreq_map(struct ioreq *ioreq)
{ {
int gnt = ioreq->blkdev->xendev.gnttabdev; XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
int i; int i;
if (ioreq->v.niov == 0) { if (ioreq->v.niov == 0) {

View File

@ -175,8 +175,9 @@ static int xen_domain_watcher(void)
for (i = 3; i < n; i++) { for (i = 3; i < n; i++) {
if (i == fd[0]) if (i == fd[0])
continue; continue;
if (i == xen_xc) if (i == xc_fd(xen_xc)) {
continue; continue;
}
close(i); close(i);
} }