Do not reimplement libxc routines if HAVE_LIBXC is defined.
If we're compiling for a platform that has a libxc then use it
rather than reimplementing the code in xenstored.
This saves us from having to port these low level routines from
linux to mini-OS in order to run xenstored in a stub domain.
Signed-off-by: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
diff -r 7a4f8a26f48d libs/eventchn/eventchn_stubs.c
--- a/libs/eventchn/eventchn_stubs.c Wed Mar 25 15:11:31 2009 +0000
+++ b/libs/eventchn/eventchn_stubs.c Thu Apr 16 14:19:43 2009 +0100
@@ -27,11 +27,15 @@
#include <xen/sysctl.h>
-#if XEN_SYSCTL_INTERFACE_VERSION < 4
-#include <xen/linux/evtchn.h>
+#ifdef HAVE_LIBXC
+# include <xenctrl.h>
#else
-#include <xen/xen.h>
-#include <xen/sys/evtchn.h>
+# if XEN_SYSCTL_INTERFACE_VERSION < 4
+# include <xen/linux/evtchn.h>
+# else
+# include <xen/xen.h>
+# include <xen/sys/evtchn.h>
+# endif
#endif
#include <xenctrl.h>
@@ -53,6 +57,7 @@
return ioctl(handle, cmd, arg);
}
+#ifndef HAVE_LIBXC
static int do_read_port(int handle, evtchn_port_t *port)
{
return (read(handle, port, sizeof(evtchn_port_t)) !=
sizeof(evtchn_port_t));
@@ -62,9 +67,13 @@
{
return (write(handle, &port, sizeof(evtchn_port_t)) !=
sizeof(evtchn_port_t));
}
+#endif
int eventchn_do_open(void)
{
+#ifdef HAVE_LIBXC
+ return xc_evtchn_open();
+#else
int fd;
fd = open(EVENTCHN_PATH, O_RDWR);
@@ -74,6 +83,7 @@
fd = open(EVENTCHN_PATH, O_RDWR);
}
return fd;
+#endif
}
CAMLprim value stub_eventchn_init(value unit)
@@ -88,14 +98,16 @@
CAMLprim value stub_eventchn_notify(value fd, value port)
{
CAMLparam2(fd, port);
+ int rc;
+#ifdef HAVE_LIBXC
+ rc = xc_evtchn_notify(Int_val(fd), Int_val(port));
+#else
struct ioctl_evtchn_notify notify;
- int rc;
-
notify.port = Int_val(port);
rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_NOTIFY, ¬ify);
+#endif
if (rc == -1)
caml_failwith("ioctl notify failed");
-
CAMLreturn(Val_unit);
}
@@ -104,12 +116,15 @@
{
CAMLparam3(fd, domid, remote_port);
CAMLlocal1(port);
+ int rc;
+#ifdef HAVE_LIBXC
+ rc = xc_evtchn_bind_interdomain(Int_val(fd), Int_val(domid),
Int_val(remote_port));
+#else
struct ioctl_evtchn_bind_interdomain bind;
- int 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);
+#endif
if (rc == -1)
caml_failwith("ioctl bind_interdomain failed");
port = Val_int(rc);
@@ -121,11 +136,14 @@
{
CAMLparam1(fd);
CAMLlocal1(port);
+ int rc;
+#ifdef HAVE_LIBXC
+ rc = xc_evtchn_bind_virq(Int_val(fd), VIRQ_DOM_EXC);
+#else
struct ioctl_evtchn_bind_virq bind;
- int rc;
-
bind.virq = VIRQ_DOM_EXC;
rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_BIND_VIRQ, &bind);
+#endif
if (rc == -1)
caml_failwith("ioctl bind_virq failed");
port = Val_int(rc);
@@ -136,11 +154,14 @@
CAMLprim value stub_eventchn_unbind(value fd, value port)
{
CAMLparam2(fd, port);
+ int rc;
+#ifdef HAVE_LIBXC
+ rc = xc_evtchn_unbind(Int_val(fd), Int_val(port));
+#else
struct ioctl_evtchn_unbind unbind;
- int rc;
-
unbind.port = Int_val(port);
rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_UNBIND, &unbind);
+#endif
if (rc == -1)
caml_failwith("ioctl unbind failed");
@@ -153,8 +174,13 @@
CAMLlocal1(result);
evtchn_port_t port;
+#ifdef HAVE_LIBXC
+ if ((port = xc_evtchn_pending(Int_val(fd))) == -1)
+ caml_failwith("xc_evtchn_pending failed");
+#else
if (do_read_port(Int_val(fd), &port))
caml_failwith("read port failed");
+#endif
result = Val_int(port);
CAMLreturn(result);
@@ -166,7 +192,12 @@
evtchn_port_t port;
port = Int_val(_port);
+#ifdef HAVE_LIBXC
+ if (xc_evtchn_unmask(Int_val(fd), port) == -1)
+ caml_failwith("xc_evtchn_unmask failed");
+#else
if (do_write_port(Int_val(fd), port))
caml_failwith("write port failed");
+#endif
CAMLreturn(Val_unit);
}
diff -r 7a4f8a26f48d libs/xc/xc.h
--- a/libs/xc/xc.h Wed Mar 25 15:11:31 2009 +0000
+++ b/libs/xc/xc.h Thu Apr 16 14:19:43 2009 +0100
@@ -22,11 +22,6 @@
#include <xen/domctl.h>
#include <xen/sched.h>
#include <xen/sysctl.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>
@@ -39,15 +34,21 @@
int xc_using_injection(void);
+#ifdef HAVE_LIBXC
+#include <xenctrl.h>
+#else
+# if XEN_SYSCTL_INTERFACE_VERSION < 4
+# include <xen/linux/privcmd.h>
+# else
+# include <xen/sys/privcmd.h>
+# endif
int xc_interface_open(void);
int xc_interface_close(int handle);
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);
-
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);
+#endif /* HAVE_LIBXC */
diff -r 7a4f8a26f48d libs/xc/xc_lib.c
--- a/libs/xc/xc_lib.c Wed Mar 25 15:11:31 2009 +0000
+++ b/libs/xc/xc_lib.c Thu Apr 16 14:19:43 2009 +0100
@@ -28,10 +28,6 @@
#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))
@@ -68,6 +64,7 @@
return __error_str;
}
+#ifndef HAVE_LIBXC
static void xc_error_set(const char *fmt, ...)
{
va_list ap;
@@ -93,6 +90,7 @@
" failed: %s", xc_error_get());
memcpy(__error_str, __errordup, ERROR_STRLEN);
}
+#endif /* HAVE_LIBXC */
void xc_error_clear(void)
{
@@ -116,6 +114,7 @@
return 0;
}
+#ifndef HAVE_LIBXC
/*---- Trivia ----*/
int xc_interface_open(void)
{
@@ -221,25 +220,9 @@
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;
-}
+#define PAGE_SHIFT 12
+#define PAGE_SIZE (1UL << PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE-1))
void *xc_map_foreign_range(int handle, unsigned int domid,
int size, int prot, unsigned long mfn)
@@ -291,3 +274,4 @@
}
return ret;
}
+#endif /* HAVE_LIBXC */
diff -r 7a4f8a26f48d libs/xc/xc_stubs.c
--- a/libs/xc/xc_stubs.c Wed Mar 25 15:11:31 2009 +0000
+++ b/libs/xc/xc_stubs.c Thu Apr 16 14:19:43 2009 +0100
@@ -119,8 +119,8 @@
xc_domaininfo_t info;
int ret;
- ret = xc_domain_getinfo(_H(xc_handle), _D(domid), &info);
- if (ret != 0)
+ ret = xc_domain_getinfolist(_H(xc_handle), _D(domid), 1, &info);
+ if (ret != 1 || info.domain != _D(domid))
failwith_xc();
result = alloc_domaininfo(&info);
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|