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