Adopt vchan to xen-libs-4.1.0 API.
Add #ifdefs to support new and old API
This commit is contained in:
parent
ba07c11237
commit
3f310e5f3e
@ -4,8 +4,13 @@
|
||||
struct xen_sysctl_physinfo xphysinfo;
|
||||
main()
|
||||
{
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xc_interface *handle = xc_interface_open(NULL, NULL, 0);
|
||||
if (!handle) {
|
||||
#else
|
||||
int handle = xc_interface_open();
|
||||
if (handle == -1) {
|
||||
#endif
|
||||
perror("xc_interface_open");
|
||||
exit(1);
|
||||
}
|
||||
|
@ -83,7 +83,11 @@ int buffer_space_vchan_ext()
|
||||
// if the remote domain is destroyed, we get no notification
|
||||
// thus, we check for the status periodically
|
||||
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
static xc_interface *xc_handle = NULL;
|
||||
#else
|
||||
static int xc_handle = -1;
|
||||
#endif
|
||||
void slow_check_for_libvchan_is_eof(struct libvchan *ctrl)
|
||||
{
|
||||
struct evtchn_status evst;
|
||||
@ -198,8 +202,13 @@ char *peer_client_init(int dom, int port)
|
||||
// now client init should succeed; "while" is redundant
|
||||
while (!(ctrl = libvchan_client_init(dom, port)));
|
||||
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xc_handle = xc_interface_open(NULL, 0, 0);
|
||||
if (!xc_handle) {
|
||||
#else
|
||||
xc_handle = xc_interface_open();
|
||||
if (xc_handle < 0) {
|
||||
#endif
|
||||
perror("xc_interface_open");
|
||||
exit(1);
|
||||
}
|
||||
|
42
vchan/init.c
42
vchan/init.c
@ -65,15 +65,25 @@ static int server_interface_init(struct libvchan *ctrl, int devno)
|
||||
struct xs_handle *xs;
|
||||
char buf[64];
|
||||
char ref[16];
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xc_evtchn *evfd;
|
||||
#else
|
||||
int evfd;
|
||||
#endif
|
||||
evtchn_port_or_error_t port;
|
||||
xs = xs_domain_open();
|
||||
if (!xs) {
|
||||
return ret;
|
||||
}
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
evfd = xc_evtchn_open(NULL, 0);
|
||||
if (!evfd)
|
||||
goto fail;
|
||||
#else
|
||||
evfd = xc_evtchn_open();
|
||||
if (evfd < 0)
|
||||
goto fail;
|
||||
#endif
|
||||
ctrl->evfd = evfd;
|
||||
// the following hardcoded 0 is the peer domain id
|
||||
port = xc_evtchn_bind_unbound_port(evfd, 0);
|
||||
@ -98,7 +108,11 @@ static int server_interface_init(struct libvchan *ctrl, int devno)
|
||||
ret = 0;
|
||||
fail2:
|
||||
if (ret)
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xc_evtchn_close(evfd);
|
||||
#else
|
||||
close(evfd);
|
||||
#endif
|
||||
fail:
|
||||
xs_daemon_close(xs);
|
||||
return ret;
|
||||
@ -152,10 +166,18 @@ static int client_interface_init(struct libvchan *ctrl, int domain, int devno)
|
||||
int ret = -1;
|
||||
unsigned int len;
|
||||
struct xs_handle *xs;
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xc_interface *xcfd;
|
||||
#else
|
||||
int xcfd;
|
||||
#endif
|
||||
char buf[64];
|
||||
char *ref;
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xc_evtchn *evfd;
|
||||
#else
|
||||
int evfd;
|
||||
#endif
|
||||
int remote_port;
|
||||
xs = xs_daemon_open();
|
||||
if (!xs) {
|
||||
@ -181,23 +203,43 @@ static int client_interface_init(struct libvchan *ctrl, int domain, int devno)
|
||||
if (!remote_port)
|
||||
goto fail;
|
||||
free(ref);
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xcfd = xc_interface_open(NULL, NULL, 0);
|
||||
if (!xcfd)
|
||||
goto fail;
|
||||
#else
|
||||
xcfd = xc_interface_open();
|
||||
if (xcfd < 0)
|
||||
goto fail;
|
||||
#endif
|
||||
ctrl->ring = (struct vchan_interface *)
|
||||
xc_map_foreign_range(xcfd, domain, 4096,
|
||||
PROT_READ | PROT_WRITE, ctrl->ring_ref);
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xc_interface_close(xcfd);
|
||||
#else
|
||||
close(xcfd);
|
||||
#endif
|
||||
if (ctrl->ring == 0 || ctrl->ring == MAP_FAILED)
|
||||
goto fail;
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
evfd = xc_evtchn_open(NULL, 0);
|
||||
if (!evfd)
|
||||
goto fail;
|
||||
#else
|
||||
evfd = xc_evtchn_open();
|
||||
if (evfd < 0)
|
||||
goto fail;
|
||||
#endif
|
||||
ctrl->evfd = evfd;
|
||||
ctrl->evport =
|
||||
xc_evtchn_bind_interdomain(evfd, domain, remote_port);
|
||||
if (ctrl->evport < 0 || xc_evtchn_notify(evfd, ctrl->evport))
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xc_evtchn_close(evfd);
|
||||
#else
|
||||
close(evfd);
|
||||
#endif
|
||||
else
|
||||
ret = 0;
|
||||
fail:
|
||||
|
@ -149,7 +149,7 @@ int libvchan_close(struct libvchan *ctrl)
|
||||
/// The fd to use for select() set
|
||||
int libvchan_fd_for_select(struct libvchan *ctrl)
|
||||
{
|
||||
return ctrl->evfd;
|
||||
return xc_evtchn_fd(ctrl->evfd);
|
||||
}
|
||||
|
||||
/// Unmasks event channel; must be called before calling select(), and only then
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <xenctrl.h>
|
||||
typedef uint32_t VCHAN_RING_IDX;
|
||||
|
||||
/// struct vchan_interface is placed in memory shared between domains
|
||||
@ -37,7 +38,11 @@ struct libvchan {
|
||||
struct vchan_interface *ring;
|
||||
uint32_t ring_ref;
|
||||
/// descriptor to event channel interface
|
||||
#ifdef XENCTRL_HAS_XC_INTERFACE
|
||||
xc_evtchn *evfd;
|
||||
#else
|
||||
int evfd;
|
||||
#endif
|
||||
int evport;
|
||||
VCHAN_RING_IDX *wr_cons, *wr_prod, *rd_cons, *rd_prod;
|
||||
char *rd_ring, *wr_ring;
|
||||
|
Loading…
Reference in New Issue
Block a user