ia64/xen-unstable

changeset 11852:398ab18ffed1

[SOLARIS] Create kernel-interface implementations for libxc and xenstored.
Additionally, on Solaris, tell the kernel when xenstored is running.

Signed-off-by: John Levon <john.levon@sun.com>
author kfraser@localhost.localdomain
date Tue Oct 17 18:21:25 2006 +0100 (2006-10-17)
parents 0e22ecd169a0
children cbfc2e5c6978
files tools/libxc/Makefile tools/libxc/xc_solaris.c tools/xenstore/Makefile tools/xenstore/xenstored_core.c tools/xenstore/xenstored_core.h tools/xenstore/xenstored_linux.c tools/xenstore/xenstored_solaris.c tools/xenstore/xs_lib.c
line diff
     1.1 --- a/tools/libxc/Makefile	Tue Oct 17 18:17:19 2006 +0100
     1.2 +++ b/tools/libxc/Makefile	Tue Oct 17 18:21:25 2006 +0100
     1.3 @@ -17,6 +17,7 @@ CTRL_SRCS-y       += xc_csched.c
     1.4  CTRL_SRCS-y       += xc_tbuf.c
     1.5  CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
     1.6  CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
     1.7 +CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
     1.8  CTRL_SRCS-$(CONFIG_X86_Linux) += xc_ptrace.c xc_ptrace_core.c
     1.9  
    1.10  GUEST_SRCS-y :=
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/libxc/xc_solaris.c	Tue Oct 17 18:21:25 2006 +0100
     2.3 @@ -0,0 +1,235 @@
     2.4 +/******************************************************************************
     2.5 + *
     2.6 + * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
     2.7 + * Use is subject to license terms.
     2.8 + *
     2.9 + * This program is free software; you can redistribute it and/or
    2.10 + * modify it under the terms of the GNU General Public License as
    2.11 + * published by the Free Software Foundation, version 2 of the
    2.12 + * License.
    2.13 + */
    2.14 +
    2.15 +#include "xc_private.h"
    2.16 +
    2.17 +#include <xen/memory.h>
    2.18 +#include <xen/sys/evtchn.h>
    2.19 +#include <unistd.h>
    2.20 +#include <fcntl.h>
    2.21 +
    2.22 +int xc_interface_open(void)
    2.23 +{
    2.24 +    int flags, saved_errno;
    2.25 +    int fd = open("/dev/xen/privcmd", O_RDWR);
    2.26 +
    2.27 +    if ( fd == -1 )
    2.28 +    {
    2.29 +        PERROR("Could not obtain handle on privileged command interface");
    2.30 +        return -1;
    2.31 +    }
    2.32 +
    2.33 +    /* Although we return the file handle as the 'xc handle' the API
    2.34 +       does not specify / guarentee that this integer is in fact
    2.35 +       a file handle. Thus we must take responsiblity to ensure
    2.36 +       it doesn't propagate (ie leak) outside the process */
    2.37 +    if ( (flags = fcntl(fd, F_GETFD)) < 0 )
    2.38 +    {
    2.39 +        PERROR("Could not get file handle flags");
    2.40 +        goto error;
    2.41 +    }
    2.42 +    flags |= FD_CLOEXEC;
    2.43 +    if ( fcntl(fd, F_SETFD, flags) < 0 )
    2.44 +    {
    2.45 +        PERROR("Could not set file handle flags");
    2.46 +        goto error;
    2.47 +    }
    2.48 +
    2.49 +    return fd;
    2.50 +
    2.51 + error:
    2.52 +    saved_errno = errno;
    2.53 +    close(fd);
    2.54 +    errno = saved_errno;
    2.55 +    return -1;
    2.56 +}
    2.57 +
    2.58 +int xc_interface_close(int xc_handle)
    2.59 +{
    2.60 +    return close(xc_handle);
    2.61 +}
    2.62 +
    2.63 +void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
    2.64 +                           xen_pfn_t *arr, int num)
    2.65 +{
    2.66 +    privcmd_mmapbatch_t ioctlx;
    2.67 +    void *addr;
    2.68 +    addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
    2.69 +    if ( addr == MAP_FAILED )
    2.70 +        return NULL;
    2.71 +
    2.72 +    ioctlx.num=num;
    2.73 +    ioctlx.dom=dom;
    2.74 +    ioctlx.addr=(unsigned long)addr;
    2.75 +    ioctlx.arr=arr;
    2.76 +    if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
    2.77 +    {
    2.78 +        int saved_errno = errno;
    2.79 +        perror("XXXXXXXX");
    2.80 +        (void)munmap(addr, num*PAGE_SIZE);
    2.81 +        errno = saved_errno;
    2.82 +        return NULL;
    2.83 +    }
    2.84 +    return addr;
    2.85 +
    2.86 +}
    2.87 +
    2.88 +void *xc_map_foreign_range(int xc_handle, uint32_t dom,
    2.89 +                           int size, int prot,
    2.90 +                           unsigned long mfn)
    2.91 +{
    2.92 +    privcmd_mmap_t ioctlx;
    2.93 +    privcmd_mmap_entry_t entry;
    2.94 +    void *addr;
    2.95 +    addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
    2.96 +    if ( addr == MAP_FAILED )
    2.97 +        return NULL;
    2.98 +
    2.99 +    ioctlx.num=1;
   2.100 +    ioctlx.dom=dom;
   2.101 +    ioctlx.entry=&entry;
   2.102 +    entry.va=(unsigned long) addr;
   2.103 +    entry.mfn=mfn;
   2.104 +    entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
   2.105 +    if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
   2.106 +    {
   2.107 +        int saved_errno = errno;
   2.108 +        (void)munmap(addr, size);
   2.109 +        errno = saved_errno;
   2.110 +        return NULL;
   2.111 +    }
   2.112 +    return addr;
   2.113 +}
   2.114 +
   2.115 +int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
   2.116 +                          privcmd_mmap_entry_t *entries, int nr)
   2.117 +{
   2.118 +    privcmd_mmap_t ioctlx;
   2.119 +
   2.120 +    ioctlx.num   = nr;
   2.121 +    ioctlx.dom   = dom;
   2.122 +    ioctlx.entry = entries;
   2.123 +
   2.124 +    return ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
   2.125 +}
   2.126 +
   2.127 +static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
   2.128 +{
   2.129 +    return ioctl(xc_handle, cmd, data);
   2.130 +}
   2.131 +
   2.132 +int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
   2.133 +{
   2.134 +    return do_privcmd(xc_handle,
   2.135 +                      IOCTL_PRIVCMD_HYPERCALL,
   2.136 +                      (unsigned long)hypercall);
   2.137 +}
   2.138 +
   2.139 +int xc_evtchn_open(void)
   2.140 +{
   2.141 +    int fd;
   2.142 +
   2.143 +    if ( (fd = open("/dev/xen/evtchn", O_RDWR)) == -1 )
   2.144 +    {
   2.145 +        PERROR("Could not open event channel interface");
   2.146 +        return -1;
   2.147 +    }
   2.148 +
   2.149 +    return fd;
   2.150 +}
   2.151 +
   2.152 +int xc_evtchn_close(int xce_handle)
   2.153 +{
   2.154 +    return close(xce_handle);
   2.155 +}
   2.156 +
   2.157 +int xc_evtchn_fd(int xce_handle)
   2.158 +{
   2.159 +    return xce_handle;
   2.160 +}
   2.161 +
   2.162 +int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
   2.163 +{
   2.164 +    struct ioctl_evtchn_notify notify;
   2.165 +
   2.166 +    notify.port = port;
   2.167 +
   2.168 +    return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
   2.169 +}
   2.170 +
   2.171 +evtchn_port_t xc_evtchn_bind_interdomain(int xce_handle, int domid,
   2.172 +    evtchn_port_t remote_port)
   2.173 +{
   2.174 +    struct ioctl_evtchn_bind_interdomain bind;
   2.175 +
   2.176 +    bind.remote_domain = domid;
   2.177 +    bind.remote_port = remote_port;
   2.178 +
   2.179 +    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
   2.180 +}
   2.181 +
   2.182 +int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
   2.183 +{
   2.184 +    struct ioctl_evtchn_unbind unbind;
   2.185 +
   2.186 +    unbind.port = port;
   2.187 +
   2.188 +    return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
   2.189 +}
   2.190 +
   2.191 +evtchn_port_t xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
   2.192 +{
   2.193 +    struct ioctl_evtchn_bind_virq bind;
   2.194 +
   2.195 +    bind.virq = virq;
   2.196 +
   2.197 +    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
   2.198 +}
   2.199 +
   2.200 +static int dorw(int fd, char *data, size_t size, int do_write)
   2.201 +{
   2.202 +    size_t offset = 0;
   2.203 +    ssize_t len;
   2.204 +
   2.205 +    while ( offset < size )
   2.206 +    {
   2.207 +        if (do_write)
   2.208 +            len = write(fd, data + offset, size - offset);
   2.209 +        else
   2.210 +            len = read(fd, data + offset, size - offset);
   2.211 +
   2.212 +        if ( len == -1 )
   2.213 +        {
   2.214 +             if ( errno == EINTR )
   2.215 +                 continue;
   2.216 +             return -1;
   2.217 +        }
   2.218 +
   2.219 +        offset += len;
   2.220 +    }
   2.221 +
   2.222 +    return 0;
   2.223 +}
   2.224 +
   2.225 +evtchn_port_t xc_evtchn_pending(int xce_handle)
   2.226 +{
   2.227 +    evtchn_port_t port;
   2.228 +
   2.229 +    if ( dorw(xce_handle, (char *)&port, sizeof(port), 0) == -1 )
   2.230 +        return -1;
   2.231 +
   2.232 +    return port;
   2.233 +}
   2.234 +
   2.235 +int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
   2.236 +{
   2.237 +    return dorw(xce_handle, (char *)&port, sizeof(port), 1);
   2.238 +}
     3.1 --- a/tools/xenstore/Makefile	Tue Oct 17 18:17:19 2006 +0100
     3.2 +++ b/tools/xenstore/Makefile	Tue Oct 17 18:21:25 2006 +0100
     3.3 @@ -27,9 +27,10 @@ CLIENTS_OBJS := $(patsubst xenstore-%,xe
     3.4  
     3.5  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
     3.6  
     3.7 -XENSTORED_Linux = xenstored_linux.o
     3.8 +XENSTORED_OBJS_$(CONFIG_Linux) = xenstored_linux.o
     3.9 +XENSTORED_OBJS_$(CONFIG_SunOS) = xenstored_solaris.o
    3.10  
    3.11 -XENSTORED_OBJS += $(XENSTORED_$(XEN_OS))
    3.12 +XENSTORED_OBJS += $(XENSTORED_OBJS_y)
    3.13  
    3.14  .PHONY: all
    3.15  all: libxenstore.so libxenstore.a xenstored $(CLIENTS) xs_tdb_dump xenstore-control xenstore-ls
     4.1 --- a/tools/xenstore/xenstored_core.c	Tue Oct 17 18:17:19 2006 +0100
     4.2 +++ b/tools/xenstore/xenstored_core.c	Tue Oct 17 18:21:25 2006 +0100
     4.3 @@ -1924,6 +1924,9 @@ int main(int argc, char *argv[])
     4.4  	/* Get ready to listen to the tools. */
     4.5  	max = initialize_set(&inset, &outset, *sock, *ro_sock);
     4.6  
     4.7 +	/* Tell the kernel we're up and running. */
     4.8 +	xenbus_notify_running();
     4.9 +
    4.10  	/* Main loop. */
    4.11  	/* FIXME: Rewrite so noone can starve. */
    4.12  	for (;;) {
     5.1 --- a/tools/xenstore/xenstored_core.h	Tue Oct 17 18:17:19 2006 +0100
     5.2 +++ b/tools/xenstore/xenstored_core.h	Tue Oct 17 18:21:25 2006 +0100
     5.3 @@ -172,6 +172,9 @@ void *xenbus_map(void);
     5.4  /* Return the event channel used by xenbus. */
     5.5  evtchn_port_t xenbus_evtchn(void);
     5.6  
     5.7 +/* Tell the kernel xenstored is running. */
     5.8 +void xenbus_notify_running(void);
     5.9 +
    5.10  #endif /* _XENSTORED_CORE_H */
    5.11  
    5.12  /*
     6.1 --- a/tools/xenstore/xenstored_linux.c	Tue Oct 17 18:17:19 2006 +0100
     6.2 +++ b/tools/xenstore/xenstored_linux.c	Tue Oct 17 18:21:25 2006 +0100
     6.3 @@ -67,3 +67,7 @@ void *xenbus_map(void)
     6.4  
     6.5  	return addr;
     6.6  }
     6.7 +
     6.8 +void xenbus_notify_running(void)
     6.9 +{
    6.10 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/xenstore/xenstored_solaris.c	Tue Oct 17 18:21:25 2006 +0100
     7.3 @@ -0,0 +1,66 @@
     7.4 +/******************************************************************************
     7.5 + *
     7.6 + * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
     7.7 + * Use is subject to license terms.
     7.8 + *
     7.9 + * Copyright (C) 2005 Rusty Russell IBM Corporation
    7.10 + *
    7.11 + * This program is free software; you can redistribute it and/or
    7.12 + * modify it under the terms of the GNU General Public License as
    7.13 + * published by the Free Software Foundation, version 2 of the
    7.14 + * License.
    7.15 + */
    7.16 +
    7.17 +#include <fcntl.h>
    7.18 +#include <unistd.h>
    7.19 +#include <stdlib.h>
    7.20 +#include <sys/mman.h>
    7.21 +#include <xen/sys/xenbus.h>
    7.22 +
    7.23 +#include "xenstored_core.h"
    7.24 +
    7.25 +evtchn_port_t xenbus_evtchn(void)
    7.26 +{
    7.27 +	int fd;
    7.28 +	evtchn_port_t port; 
    7.29 +
    7.30 +	fd = open("/dev/xen/xenbus", O_RDONLY); 
    7.31 +	if (fd == -1)
    7.32 +		return -1;
    7.33 +
    7.34 +	port = ioctl(fd, IOCTL_XENBUS_XENSTORE_EVTCHN);
    7.35 +
    7.36 +	close(fd); 
    7.37 +	return port;
    7.38 +}
    7.39 +
    7.40 +void *xenbus_map(void)
    7.41 +{
    7.42 +	int fd;
    7.43 +	void *addr;
    7.44 +
    7.45 +	fd = open("/dev/xen/xenbus", O_RDWR);
    7.46 +	if (fd == -1)
    7.47 +		return NULL;
    7.48 +
    7.49 +	addr = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
    7.50 +		MAP_SHARED, fd, 0);
    7.51 +
    7.52 +	if (addr == MAP_FAILED)
    7.53 +		addr = NULL;
    7.54 +
    7.55 +	close(fd);
    7.56 +
    7.57 +	return addr;
    7.58 +}
    7.59 +
    7.60 +void xenbus_notify_running(void)
    7.61 +{
    7.62 +	int fd;
    7.63 +
    7.64 +	fd = open("/dev/xen/xenbus", O_RDONLY);
    7.65 +
    7.66 +	(void) ioctl(fd, IOCTL_XENBUS_NOTIFY_UP);
    7.67 +
    7.68 +	close(fd);
    7.69 +}
     8.1 --- a/tools/xenstore/xs_lib.c	Tue Oct 17 18:17:19 2006 +0100
     8.2 +++ b/tools/xenstore/xs_lib.c	Tue Oct 17 18:21:25 2006 +0100
     8.3 @@ -76,7 +76,14 @@ const char *xs_daemon_socket_ro(void)
     8.4  const char *xs_domain_dev(void)
     8.5  {
     8.6  	char *s = getenv("XENSTORED_PATH");
     8.7 -	return (s ? s : "/proc/xen/xenbus");
     8.8 +	if (s)
     8.9 +		return s;
    8.10 +
    8.11 +#ifdef __linux__
    8.12 +	return "/proc/xen/xenbus";
    8.13 +#else
    8.14 +	return "/dev/xen/xenbus";
    8.15 +#endif
    8.16  }
    8.17  
    8.18  /* Simple routines for writing to sockets, etc. */