John Levon
2006-May-23 17:34 UTC
[Xen-devel] [PATCH] Make use of /proc/xen/xsd_{port, kva} private to the Linux implementation.
# HG changeset patch # User john.levon@sun.com # Node ID 645e109ef777618564dd40839263da9527bab87b # Parent 13d6d993d79724d86a0c9ac556a7f884baed98ae Make use of /proc/xen/xsd_{port,kva} private to the Linux implementation. Signed-off-by: John Levon <john.levon@sun.com> diff -r 13d6d993d797 -r 645e109ef777 tools/libxc/xc_linux.c --- a/tools/libxc/xc_linux.c Mon May 22 17:30:25 2006 +0100 +++ b/tools/libxc/xc_linux.c Tue May 23 01:50:39 2006 -0700 @@ -13,6 +13,9 @@ #include <xen/memory.h> #include <xen/sys/evtchn.h> + +#define XENSTORED_PROC_KVA "/proc/xen/xsd_kva" +#define XENSTORED_PROC_PORT "/proc/xen/xsd_port" int xc_interface_open(void) { @@ -103,6 +106,51 @@ int do_xen_hypercall(int xc_handle, priv (unsigned long)hypercall); } +evtchn_port_t xc_xenbus_evtchn(int xc_handle) +{ + int fd; + int rc; + evtchn_port_t port; + char str[20]; + + fd = open(XENSTORED_PROC_PORT, O_RDONLY); + if ( fd == -1 ) + return -1; + + rc = read(fd, str, sizeof(str)); + if ( rc == -1 ) + { + int err = errno; + close(fd); + errno = err; + return -1; + } + + str[rc] = ''\0''; + port = strtoul(str, NULL, 0); + + close(fd); + return port; +} + +void *xc_xenbus_map(int xc_handle) +{ + int fd; + void *addr; + + fd = open(XENSTORED_PROC_KVA, O_RDWR); + if ( fd == -1 ) + return NULL; + + addr = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if ( addr == MAP_FAILED ) + addr = NULL; + + close(fd); + + return addr; +} + /* * Local variables: * mode: C diff -r 13d6d993d797 -r 645e109ef777 tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h Mon May 22 17:30:25 2006 +0100 +++ b/tools/libxc/xenctrl.h Tue May 23 01:50:39 2006 -0700 @@ -596,4 +596,15 @@ int xc_finish_mmu_updates(int xc_handle, int xc_acm_op(int xc_handle, int cmd, void *arg, size_t arg_size); +/** + * Return the event channel for communication with the kernel''s xenbus device. + * Returns -1 on failure. + */ +evtchn_port_t xc_xenbus_evtchn(int xc_handle); + +/** + * Map xenstore page from the kernel''s xenbus device. Returns NULL on failure. + */ +void *xc_xenbus_map(int xc_handle); + #endif diff -r 13d6d993d797 -r 645e109ef777 tools/xenstore/xenstored_domain.c --- a/tools/xenstore/xenstored_domain.c Mon May 22 17:30:25 2006 +0100 +++ b/tools/xenstore/xenstored_domain.c Tue May 23 01:50:39 2006 -0700 @@ -33,7 +33,6 @@ #include "talloc.h" #include "xenstored_core.h" #include "xenstored_domain.h" -#include "xenstored_proc.h" #include "xenstored_watch.h" #include "xenstored_test.h" @@ -476,44 +475,26 @@ void restore_existing_connections(void) static int dom0_init(void) { - int rc, fd; - evtchn_port_t port; - char str[20]; - struct domain *dom0; - - fd = open(XENSTORED_PROC_PORT, O_RDONLY); - if (fd == -1) + evtchn_port_t port; + struct domain *dom0; + + port = xc_xenbus_evtchn(*xc_handle); + + if (port == -1) return -1; - rc = read(fd, str, sizeof(str)); - if (rc == -1) - goto outfd; - str[rc] = ''\0''; - port = strtoul(str, NULL, 0); - - close(fd); - dom0 = new_domain(NULL, 0, port); - fd = open(XENSTORED_PROC_KVA, O_RDWR); - if (fd == -1) + dom0->interface = xc_xenbus_map(*xc_handle); + + if (dom0->interface == NULL) return -1; - dom0->interface = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, - MAP_SHARED, fd, 0); - if (dom0->interface == MAP_FAILED) - goto outfd; - - close(fd); - talloc_steal(dom0->conn, dom0); evtchn_notify(dom0->port); return 0; -outfd: - close(fd); - return -1; } diff -r 13d6d993d797 -r 645e109ef777 tools/xenstore/xenstored_proc.h --- a/tools/xenstore/xenstored_proc.h Mon May 22 17:30:25 2006 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - Copyright (C) 2005 XenSource Ltd - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ - -#ifndef _XENSTORED_PROC_H -#define _XENSTORED_PROC_H - -#define XENSTORED_PROC_KVA "/proc/xen/xsd_kva" -#define XENSTORED_PROC_PORT "/proc/xen/xsd_port" - - -#endif /* _XENSTORED_PROC_H */ _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2006-May-23 21:17 UTC
Re: [Xen-devel] [PATCH] Make use of /proc/xen/xsd_{port, kva} private to the Linux implementation.
On 23 May 2006, at 18:34, John Levon wrote:> Make use of /proc/xen/xsd_{port,kva} private to the Linux > implementation. > > Signed-off-by: John Levon <john.levon@sun.com>Although there is a good argument for everything else you have moved into libxc, this code really is very specific to libxenstore. I''d rather have OS-specific code in libxenstore, and maybe some ifdefs, than create extra bogus interfaces in libxc. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2006-May-23 21:41 UTC
Re: [Xen-devel] [PATCH] Make use of /proc/xen/xsd_{port, kva} private to the Linux implementation.
On 23 May 2006, at 22:42, John Levon wrote:>> Although there is a good argument for everything else you have moved >> into libxc, this code really is very specific to libxenstore. > > I guess I don''t really understand what the boundary of libxc is (it''s > all control tools after all). I can make an xs_linux.c, sure.Stuff that would be useful to more than one other tools component. So moving event-channel stuff was fine, for instance. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
John Levon
2006-May-23 21:42 UTC
Re: [Xen-devel] [PATCH] Make use of /proc/xen/xsd_{port, kva} private to the Linux implementation.
On Tue, May 23, 2006 at 10:17:42PM +0100, Keir Fraser wrote:> >Make use of /proc/xen/xsd_{port,kva} private to the Linux > >implementation. > > > >Signed-off-by: John Levon <john.levon@sun.com> > > Although there is a good argument for everything else you have moved > into libxc, this code really is very specific to libxenstore.I guess I don''t really understand what the boundary of libxc is (it''s all control tools after all). I can make an xs_linux.c, sure. regards john _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
John Levon
2006-May-23 23:20 UTC
Re: [Xen-devel] [PATCH] Make use of /proc/xen/xsd_{port, kva} private to the Linux implementation.
On Tue, May 23, 2006 at 10:42:08PM +0100, John Levon wrote:> I guess I don''t really understand what the boundary of libxc is (it''s > all control tools after all). I can make an xs_linux.c, sure.Here''s a new patch. thanks john # HG changeset patch # User john.levon@sun.com # Node ID ae80562f67a6fa40880720adedf650a9e415969f # Parent 13d6d993d79724d86a0c9ac556a7f884baed98ae Make use of /proc/xen/xsd_{port,kva} private to the Linux implementation. Signed-off-by: John Levon <john.levon@sun.com> diff -r 13d6d993d797 -r ae80562f67a6 tools/xenstore/Makefile --- a/tools/xenstore/Makefile Mon May 22 17:30:25 2006 +0100 +++ b/tools/xenstore/Makefile Tue May 23 07:37:01 2006 -0700 @@ -27,6 +27,12 @@ CLIENTS += xenstore-write CLIENTS += xenstore-write CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS)) +XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o + +XENSTORED_Linux = xenstored_linux.o + +XENSTORED_OBJS += $(XENSTORED_$(OS)) + .PHONY: all all: libxenstore.so xenstored $(CLIENTS) xs_tdb_dump xenstore-control xenstore-ls @@ -36,7 +42,7 @@ test_interleaved_transactions: test_inte .PHONY: testcode testcode: xs_test xenstored_test xs_random -xenstored: xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o +xenstored: $(XENSTORED_OBJS) $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@ $(CLIENTS): xenstore-%: xenstore_%.o libxenstore.so diff -r 13d6d993d797 -r ae80562f67a6 tools/xenstore/xenstored_core.h --- a/tools/xenstore/xenstored_core.h Mon May 22 17:30:25 2006 +0100 +++ b/tools/xenstore/xenstored_core.h Tue May 23 07:37:01 2006 -0700 @@ -19,6 +19,8 @@ #ifndef _XENSTORED_CORE_H #define _XENSTORED_CORE_H + +#include <xenctrl.h> #include <sys/types.h> #include <dirent.h> @@ -163,6 +165,12 @@ void trace(const char *fmt, ...); extern int event_fd; +/* Map the kernel''s xenstore page. */ +void *xenbus_map(void); + +/* Return the event channel used by xenbus. */ +evtchn_port_t xenbus_evtchn(void); + #endif /* _XENSTORED_CORE_H */ /* diff -r 13d6d993d797 -r ae80562f67a6 tools/xenstore/xenstored_domain.c --- a/tools/xenstore/xenstored_domain.c Mon May 22 17:30:25 2006 +0100 +++ b/tools/xenstore/xenstored_domain.c Tue May 23 07:37:01 2006 -0700 @@ -33,12 +33,11 @@ #include "talloc.h" #include "xenstored_core.h" #include "xenstored_domain.h" -#include "xenstored_proc.h" #include "xenstored_watch.h" #include "xenstored_test.h" #include <xenctrl.h> -#include <xen/linux/evtchn.h> +#include <xen/sys/evtchn.h> static int *xc_handle; static evtchn_port_t virq_port; @@ -476,44 +475,26 @@ void restore_existing_connections(void) static int dom0_init(void) { - int rc, fd; - evtchn_port_t port; - char str[20]; - struct domain *dom0; - - fd = open(XENSTORED_PROC_PORT, O_RDONLY); - if (fd == -1) + evtchn_port_t port; + struct domain *dom0; + + port = xenbus_evtchn(); + + if (port == -1) return -1; - rc = read(fd, str, sizeof(str)); - if (rc == -1) - goto outfd; - str[rc] = ''\0''; - port = strtoul(str, NULL, 0); - - close(fd); - dom0 = new_domain(NULL, 0, port); - fd = open(XENSTORED_PROC_KVA, O_RDWR); - if (fd == -1) + dom0->interface = xenbus_map(); + + if (dom0->interface == NULL) return -1; - dom0->interface = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, - MAP_SHARED, fd, 0); - if (dom0->interface == MAP_FAILED) - goto outfd; - - close(fd); - talloc_steal(dom0->conn, dom0); evtchn_notify(dom0->port); return 0; -outfd: - close(fd); - return -1; } diff -r 13d6d993d797 -r ae80562f67a6 tools/xenstore/xenstored_linux.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/xenstore/xenstored_linux.c Tue May 23 07:37:01 2006 -0700 @@ -0,0 +1,69 @@ +/****************************************************************************** + * + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Copyright (C) 2005 Rusty Russell IBM Corporation + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2 of the + * License. + */ + +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/mman.h> + +#include "xenstored_core.h" + +#define XENSTORED_PROC_KVA "/proc/xen/xsd_kva" +#define XENSTORED_PROC_PORT "/proc/xen/xsd_port" + +evtchn_port_t xenbus_evtchn(void) +{ + int fd; + int rc; + evtchn_port_t port; + char str[20]; + + fd = open(XENSTORED_PROC_PORT, O_RDONLY); + if (fd == -1) + return -1; + + rc = read(fd, str, sizeof(str)); + if (rc == -1) + { + int err = errno; + close(fd); + errno = err; + return -1; + } + + str[rc] = ''\0''; + port = strtoul(str, NULL, 0); + + close(fd); + return port; +} + +void *xenbus_map(void) +{ + int fd; + void *addr; + + fd = open(XENSTORED_PROC_KVA, O_RDWR); + if (fd == -1) + return NULL; + + addr = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, + MAP_SHARED, fd, 0); + + if (addr == MAP_FAILED) + addr = NULL; + + close(fd); + + return addr; +} diff -r 13d6d993d797 -r ae80562f67a6 tools/xenstore/xenstored_proc.h --- a/tools/xenstore/xenstored_proc.h Mon May 22 17:30:25 2006 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - Copyright (C) 2005 XenSource Ltd - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ - -#ifndef _XENSTORED_PROC_H -#define _XENSTORED_PROC_H - -#define XENSTORED_PROC_KVA "/proc/xen/xsd_kva" -#define XENSTORED_PROC_PORT "/proc/xen/xsd_port" - - -#endif /* _XENSTORED_PROC_H */ _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel