From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
To: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: [PATCH 4/24] [xen-unstable.hg] make xenstored use grantref rather than map_foreign_range (which only privileged domains can do)
Date: Mon, 23 Mar 2009 15:20:38 +0000 [thread overview]
Message-ID: <49C7A8C6.50008@eu.citrix.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2 bytes --]
[-- Attachment #2: xenstored_map_grant_ref --]
[-- Type: text/plain, Size: 3206 bytes --]
This patch modifies the xenstore daemon to use xc_gnttab_map_grant_ref
instead of xc_map_foreign_range where available.
TODO: This will probably break linking on Solaris, since they don't have
stubs for the gntmap functions yet.
A previous version of this patch was sent to xen-devel. See
http://lists.xensource.com/archives/html/xen-devel/2008-07/msg00610.html
Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
---
diff -r 289762278873 tools/xenstore/xenstored_domain.c
--- a/tools/xenstore/xenstored_domain.c Fri Aug 01 16:50:27 2008 +0100
+++ b/tools/xenstore/xenstored_domain.c Fri Aug 01 16:50:28 2008 +0100
@@ -31,8 +31,10 @@
#include "xenstored_watch.h"
#include <xenctrl.h>
+#include <xen/grant_table.h>
static int *xc_handle;
+static int *xcg_handle;
static evtchn_port_t virq_port;
int xce_handle = -1;
@@ -173,8 +175,12 @@
eprintf("> Unbinding port %i failed!\n", domain->port);
}
- if (domain->interface)
- munmap(domain->interface, getpagesize());
+ if (domain->interface) {
+ if (*xcg_handle >= 0 && domain->domid != 0)
+ xc_gnttab_munmap(*xcg_handle, domain->interface, 1);
+ else
+ munmap(domain->interface, getpagesize());
+ }
fire_watches(NULL, "@releaseDomain", false);
@@ -343,9 +349,17 @@
domain = find_domain_by_domid(domid);
if (domain == NULL) {
- interface = xc_map_foreign_range(
- *xc_handle, domid,
- getpagesize(), PROT_READ|PROT_WRITE, mfn);
+ if (*xcg_handle >= 0) {
+ /* this is the preferred method */
+ interface = xc_gnttab_map_grant_ref(
+ *xcg_handle, domid,
+ GNTTAB_RESERVED_XENSTORE,
+ PROT_READ|PROT_WRITE);
+ } else {
+ interface = xc_map_foreign_range(
+ *xc_handle, domid,
+ getpagesize(), PROT_READ|PROT_WRITE, mfn);
+ }
if (!interface) {
send_error(conn, errno);
return;
@@ -353,7 +367,10 @@
/* Hang domain off "in" until we're finished. */
domain = new_domain(in, domid, port);
if (!domain) {
- munmap(interface, getpagesize());
+ if (*xcg_handle >= 0)
+ xc_gnttab_munmap(*xcg_handle, interface, 1);
+ else
+ munmap(interface, getpagesize());
send_error(conn, errno);
return;
}
@@ -542,6 +559,12 @@
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)
{
@@ -584,6 +607,7 @@
{
int rc;
+ /* Open the hypervisor interface. */
xc_handle = talloc(talloc_autofree_context(), int);
if (!xc_handle)
barf_perror("Failed to allocate domain handle");
@@ -593,6 +617,17 @@
barf_perror("Failed to open connection to hypervisor");
talloc_set_destructor(xc_handle, close_xc_handle);
+
+ /* Open the gntdev interface. */
+ xcg_handle = talloc(talloc_autofree_context(), int);
+ if (!xcg_handle)
+ barf_perror("Failed to allocate domain gnttab handle");
+
+ *xcg_handle = xc_gnttab_open();
+ if (*xcg_handle < 0)
+ xprintf("WARNING: Failed to open connection to gnttab\n");
+ else
+ talloc_set_destructor(xcg_handle, close_xcg_handle);
xce_handle = xc_evtchn_open();
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
reply other threads:[~2009-03-23 15:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49C7A8C6.50008@eu.citrix.com \
--to=alex.zeffertt@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.