diff -r c1fafdcdb19a tools/xenstore/xenstored_domain.c --- a/tools/xenstore/xenstored_domain.c Tue May 01 22:24:01 2007 +0100 +++ b/tools/xenstore/xenstored_domain.c Wed May 02 11:30:53 2007 +0100 @@ -35,6 +35,7 @@ #include static int *xc_handle; +static int *xcg_handle; static evtchn_port_t virq_port; int xce_handle = -1; @@ -175,7 +176,7 @@ static int destroy_domain(void *_domain) } if (domain->interface) - munmap(domain->interface, getpagesize()); + xc_gnttab_munmap(*xcg_handle, domain->interface, 1); return 0; } @@ -345,9 +346,8 @@ void do_introduce(struct connection *con domain = find_domain_by_domid(domid); if (domain == NULL) { - interface = xc_map_foreign_range( - *xc_handle, domid, - getpagesize(), PROT_READ|PROT_WRITE, mfn); + interface = xc_gnttab_map_grant_ref(*xcg_handle, domid, 0, + PROT_READ|PROT_WRITE); if (!interface) { send_error(conn, errno); return; @@ -355,7 +355,7 @@ void do_introduce(struct connection *con /* Hang domain off "in" until we're finished. */ domain = new_domain(in, domid, port); if (!domain) { - munmap(interface, getpagesize()); + xc_gnttab_munmap(*xcg_handle, interface, 1); send_error(conn, errno); return; } @@ -501,6 +501,12 @@ static int close_xc_handle(void *_handle return 0; } +static int close_xcg_handle(void *_handle) +{ + xc_gnttab_close(*(int *)_handle); + return 0; +} + /* Returns the implicit path of a connection (only domains have this) */ const char *get_implicit_path(const struct connection *conn) { @@ -543,6 +549,7 @@ int domain_init(void) { int rc; + /* Open the hypervisor interface. */ xc_handle = talloc(talloc_autofree_context(), int); if (!xc_handle) barf_perror("Failed to allocate domain handle"); @@ -553,6 +560,18 @@ int domain_init(void) talloc_set_destructor(xc_handle, close_xc_handle); + /* Open the gntdev interface. */ + xcg_handle = talloc(talloc_autofree_context(), int); + if (!xc_handle) + barf_perror("Failed to allocate domain handle"); + + *xcg_handle = xc_gnttab_open(); + if (*xcg_handle < 0) + barf_perror("Failed to open connection to gntdev"); + + talloc_set_destructor(xcg_handle, close_xcg_handle); + + /* Open the evtchn interface. */ xce_handle = xc_evtchn_open(); if (xce_handle < 0)