ia64/xen-unstable

changeset 6690:b7c7cb88f0ba

Create /dev/xen/evtchn if it doesn't exist.

Signed-off-by: Steven Hand <steven@xensource.com>
author shand@ubuntu.eng.hq.xensource.com
date Wed Sep 07 12:30:00 2005 -0800 (2005-09-07)
parents 7d0fb56b4a91
children 7bc32f4c67fb
files tools/xenstore/xenstored_domain.c
line diff
     1.1 --- a/tools/xenstore/xenstored_domain.c	Wed Sep 07 19:01:31 2005 +0000
     1.2 +++ b/tools/xenstore/xenstored_domain.c	Wed Sep 07 12:30:00 2005 -0800
     1.3 @@ -433,33 +433,57 @@ void restore_existing_connections(void)
     1.4  {
     1.5  }
     1.6  
     1.7 +#define EVTCHN_DEV_NAME  "/dev/xen/evtchn"
     1.8 +#define EVTCHN_DEV_MAJOR 10
     1.9 +#define EVTCHN_DEV_MINOR 201
    1.10 +
    1.11  /* Returns the event channel handle. */
    1.12  int domain_init(void)
    1.13  {
    1.14 -	/* The size of the ringbuffer: half a page minus head structure. */
    1.15 -	ringbuf_datasize = getpagesize() / 2 - sizeof(struct ringbuf_head);
    1.16 +    /* The size of the ringbuffer: half a page minus head structure. */
    1.17 +    ringbuf_datasize = getpagesize() / 2 - sizeof(struct ringbuf_head);
    1.18 +    
    1.19 +    xc_handle = talloc(talloc_autofree_context(), int);
    1.20 +    if (!xc_handle)
    1.21 +        barf_perror("Failed to allocate domain handle");
    1.22  
    1.23 -	xc_handle = talloc(talloc_autofree_context(), int);
    1.24 -	if (!xc_handle)
    1.25 -		barf_perror("Failed to allocate domain handle");
    1.26 -	*xc_handle = xc_interface_open();
    1.27 -	if (*xc_handle < 0)
    1.28 -		barf_perror("Failed to open connection to hypervisor");
    1.29 -	talloc_set_destructor(xc_handle, close_xc_handle);
    1.30 +    *xc_handle = xc_interface_open();
    1.31 +    if (*xc_handle < 0)
    1.32 +        barf_perror("Failed to open connection to hypervisor (privcmd)");
    1.33  
    1.34 +    talloc_set_destructor(xc_handle, close_xc_handle);
    1.35 +    
    1.36  #ifdef TESTING
    1.37 -	eventchn_fd = fake_open_eventchn();
    1.38 +    eventchn_fd = fake_open_eventchn();
    1.39  #else
    1.40 -	eventchn_fd = open("/dev/xen/evtchn", O_RDWR);
    1.41 +    {
    1.42 +        struct stat st;
    1.43 +        
    1.44 +        /* Make sure any existing device file links to correct device. */
    1.45 +        if ( (lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
    1.46 +             (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)) )
    1.47 +            (void)unlink(EVTCHN_DEV_NAME);
    1.48 +        
    1.49 +      reopen:
    1.50 +        eventchn_fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
    1.51 +        if (eventchn_fd == -1) {
    1.52 +            if ((errno == ENOENT) && (
    1.53 +                    (mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) 
    1.54 +                && (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600,
    1.55 +                          makedev(EVTCHN_DEV_MAJOR,EVTCHN_DEV_MINOR)) == 0))
    1.56 +                goto reopen;
    1.57 +            return -errno;
    1.58 +        }
    1.59 +    }
    1.60  #endif
    1.61 -	if (eventchn_fd < 0)
    1.62 -		barf_perror("Failed to open connection to hypervisor");
    1.63 -
    1.64 -	if (xc_evtchn_bind_virq(*xc_handle, VIRQ_DOM_EXC, &virq_port))
    1.65 -		barf_perror("Failed to bind to domain exception virq");
    1.66 -
    1.67 -	if (ioctl(eventchn_fd, EVENTCHN_BIND, virq_port) != 0)
    1.68 -		barf_perror("Failed to bind to domain exception virq port");
    1.69 -
    1.70 -	return eventchn_fd;
    1.71 +    if (eventchn_fd < 0)
    1.72 +        barf_perror("Failed to open connection to hypervisor (evtchn)");
    1.73 +    
    1.74 +    if (xc_evtchn_bind_virq(*xc_handle, VIRQ_DOM_EXC, &virq_port))
    1.75 +        barf_perror("Failed to bind to domain exception virq");
    1.76 +    
    1.77 +    if (ioctl(eventchn_fd, EVENTCHN_BIND, virq_port) != 0)
    1.78 +        barf_perror("Failed to bind to domain exception virq port");
    1.79 +    
    1.80 +    return eventchn_fd;
    1.81  }