ia64/xen-unstable

changeset 10169:041127f2c687

[XENSTORE] Make use of /proc/xen/xsd_{port,kva} private to the Linux implementation.
Signed-off-by: John Levon <john.levon@sun.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed May 24 14:24:57 2006 +0100 (2006-05-24)
parents ed696467fe64
children 2436cc71de50
files tools/xenstore/Makefile tools/xenstore/xenstored_core.h tools/xenstore/xenstored_domain.c tools/xenstore/xenstored_linux.c
line diff
     1.1 --- a/tools/xenstore/Makefile	Wed May 24 14:12:40 2006 +0100
     1.2 +++ b/tools/xenstore/Makefile	Wed May 24 14:24:57 2006 +0100
     1.3 @@ -27,6 +27,12 @@ CLIENTS := xenstore-exists xenstore-list
     1.4  CLIENTS += xenstore-write
     1.5  CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS))
     1.6  
     1.7 +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
     1.8 +
     1.9 +XENSTORED_Linux = xenstored_linux.o
    1.10 +
    1.11 +XENSTORED_OBJS += $(XENSTORED_$(OS))
    1.12 +
    1.13  .PHONY: all
    1.14  all: libxenstore.so xenstored $(CLIENTS) xs_tdb_dump xenstore-control xenstore-ls
    1.15  
    1.16 @@ -36,7 +42,7 @@ test_interleaved_transactions: test_inte
    1.17  .PHONY: testcode
    1.18  testcode: xs_test xenstored_test xs_random
    1.19  
    1.20 -xenstored: xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o
    1.21 +xenstored: $(XENSTORED_OBJS)
    1.22  	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@
    1.23  
    1.24  $(CLIENTS): xenstore-%: xenstore_%.o libxenstore.so
     2.1 --- a/tools/xenstore/xenstored_core.h	Wed May 24 14:12:40 2006 +0100
     2.2 +++ b/tools/xenstore/xenstored_core.h	Wed May 24 14:24:57 2006 +0100
     2.3 @@ -20,6 +20,8 @@
     2.4  #ifndef _XENSTORED_CORE_H
     2.5  #define _XENSTORED_CORE_H
     2.6  
     2.7 +#include <xenctrl.h>
     2.8 +
     2.9  #include <sys/types.h>
    2.10  #include <dirent.h>
    2.11  #include <stdbool.h>
    2.12 @@ -163,6 +165,12 @@ void trace(const char *fmt, ...);
    2.13  
    2.14  extern int event_fd;
    2.15  
    2.16 +/* Map the kernel's xenstore page. */
    2.17 +void *xenbus_map(void);
    2.18 +
    2.19 +/* Return the event channel used by xenbus. */
    2.20 +evtchn_port_t xenbus_evtchn(void);
    2.21 +
    2.22  #endif /* _XENSTORED_CORE_H */
    2.23  
    2.24  /*
     3.1 --- a/tools/xenstore/xenstored_domain.c	Wed May 24 14:12:40 2006 +0100
     3.2 +++ b/tools/xenstore/xenstored_domain.c	Wed May 24 14:24:57 2006 +0100
     3.3 @@ -33,12 +33,11 @@
     3.4  #include "talloc.h"
     3.5  #include "xenstored_core.h"
     3.6  #include "xenstored_domain.h"
     3.7 -#include "xenstored_proc.h"
     3.8  #include "xenstored_watch.h"
     3.9  #include "xenstored_test.h"
    3.10  
    3.11  #include <xenctrl.h>
    3.12 -#include <xen/linux/evtchn.h>
    3.13 +#include <xen/sys/evtchn.h>
    3.14  
    3.15  static int *xc_handle;
    3.16  static evtchn_port_t virq_port;
    3.17 @@ -476,44 +475,24 @@ void restore_existing_connections(void)
    3.18  
    3.19  static int dom0_init(void) 
    3.20  { 
    3.21 -	int rc, fd;
    3.22 -	evtchn_port_t port; 
    3.23 -	char str[20]; 
    3.24 -	struct domain *dom0; 
    3.25 +	evtchn_port_t port;
    3.26 +	struct domain *dom0;
    3.27  
    3.28 -	fd = open(XENSTORED_PROC_PORT, O_RDONLY); 
    3.29 -	if (fd == -1)
    3.30 +	port = xenbus_evtchn();
    3.31 +	if (port == -1)
    3.32  		return -1;
    3.33  
    3.34 -	rc = read(fd, str, sizeof(str)); 
    3.35 -	if (rc == -1)
    3.36 -		goto outfd;
    3.37 -	str[rc] = '\0'; 
    3.38 -	port = strtoul(str, NULL, 0); 
    3.39 -
    3.40 -	close(fd); 
    3.41 -
    3.42  	dom0 = new_domain(NULL, 0, port); 
    3.43  
    3.44 -	fd = open(XENSTORED_PROC_KVA, O_RDWR);
    3.45 -	if (fd == -1)
    3.46 +	dom0->interface = xenbus_map();
    3.47 +	if (dom0->interface == NULL)
    3.48  		return -1;
    3.49  
    3.50 -	dom0->interface = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
    3.51 -			       MAP_SHARED, fd, 0);
    3.52 -	if (dom0->interface == MAP_FAILED)
    3.53 -		goto outfd;
    3.54 -
    3.55 -	close(fd);
    3.56 -
    3.57  	talloc_steal(dom0->conn, dom0); 
    3.58  
    3.59  	evtchn_notify(dom0->port); 
    3.60  
    3.61  	return 0; 
    3.62 -outfd:
    3.63 -	close(fd);
    3.64 -	return -1;
    3.65  }
    3.66  
    3.67  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/xenstore/xenstored_linux.c	Wed May 24 14:24:57 2006 +0100
     4.3 @@ -0,0 +1,69 @@
     4.4 +/******************************************************************************
     4.5 + *
     4.6 + * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
     4.7 + * Use is subject to license terms.
     4.8 + *
     4.9 + * Copyright (C) 2005 Rusty Russell IBM Corporation
    4.10 + *
    4.11 + * This program is free software; you can redistribute it and/or
    4.12 + * modify it under the terms of the GNU General Public License as
    4.13 + * published by the Free Software Foundation, version 2 of the
    4.14 + * License.
    4.15 + */
    4.16 +
    4.17 +#include <fcntl.h>
    4.18 +#include <unistd.h>
    4.19 +#include <stdlib.h>
    4.20 +#include <sys/mman.h>
    4.21 +
    4.22 +#include "xenstored_core.h"
    4.23 +
    4.24 +#define XENSTORED_PROC_KVA  "/proc/xen/xsd_kva"
    4.25 +#define XENSTORED_PROC_PORT "/proc/xen/xsd_port"
    4.26 +
    4.27 +evtchn_port_t xenbus_evtchn(void)
    4.28 +{
    4.29 +	int fd;
    4.30 +	int rc;
    4.31 +	evtchn_port_t port; 
    4.32 +	char str[20]; 
    4.33 +
    4.34 +	fd = open(XENSTORED_PROC_PORT, O_RDONLY); 
    4.35 +	if (fd == -1)
    4.36 +		return -1;
    4.37 +
    4.38 +	rc = read(fd, str, sizeof(str)); 
    4.39 +	if (rc == -1)
    4.40 +	{
    4.41 +		int err = errno;
    4.42 +		close(fd);
    4.43 +		errno = err;
    4.44 +		return -1;
    4.45 +	}
    4.46 +
    4.47 +	str[rc] = '\0'; 
    4.48 +	port = strtoul(str, NULL, 0); 
    4.49 +
    4.50 +	close(fd); 
    4.51 +	return port;
    4.52 +}
    4.53 +
    4.54 +void *xenbus_map(void)
    4.55 +{
    4.56 +	int fd;
    4.57 +	void *addr;
    4.58 +
    4.59 +	fd = open(XENSTORED_PROC_KVA, O_RDWR);
    4.60 +	if (fd == -1)
    4.61 +		return NULL;
    4.62 +
    4.63 +	addr = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
    4.64 +		MAP_SHARED, fd, 0);
    4.65 +
    4.66 +	if (addr == MAP_FAILED)
    4.67 +		addr = NULL;
    4.68 +
    4.69 +	close(fd);
    4.70 +
    4.71 +	return addr;
    4.72 +}
     5.1 --- a/tools/xenstore/xenstored_proc.h	Wed May 24 14:12:40 2006 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,27 +0,0 @@
     5.4 -/* 
     5.5 -    Copyright (C) 2005 XenSource Ltd
     5.6 -
     5.7 -    This program is free software; you can redistribute it and/or modify
     5.8 -    it under the terms of the GNU General Public License as published by
     5.9 -    the Free Software Foundation; either version 2 of the License, or
    5.10 -    (at your option) any later version.
    5.11 -
    5.12 -    This program is distributed in the hope that it will be useful,
    5.13 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 -    GNU General Public License for more details.
    5.16 -
    5.17 -    You should have received a copy of the GNU General Public License
    5.18 -    along with this program; if not, write to the Free Software
    5.19 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.20 -
    5.21 -*/
    5.22 -
    5.23 -#ifndef _XENSTORED_PROC_H
    5.24 -#define _XENSTORED_PROC_H
    5.25 -
    5.26 -#define XENSTORED_PROC_KVA  "/proc/xen/xsd_kva"
    5.27 -#define XENSTORED_PROC_PORT "/proc/xen/xsd_port"
    5.28 -
    5.29 -
    5.30 -#endif /* _XENSTORED_PROC_H */