direct-io.hg
changeset 9478:2cd44eba4df6
Merged.
author | emellor@leeni.uk.xensource.com |
---|---|
date | Thu Mar 30 11:55:07 2006 +0100 (2006-03-30) |
parents | 7a3f07a33487 7c994d80049c |
children | 85b7a341207e f1014bb3ad6f |
files |
line diff
1.1 --- a/tools/console/daemon/io.c Thu Mar 30 11:54:07 2006 +0100 1.2 +++ b/tools/console/daemon/io.c Thu Mar 30 11:55:07 2006 +0100 1.3 @@ -434,26 +434,37 @@ void enum_domains(void) 1.4 } 1.5 } 1.6 1.7 +static int ring_free_bytes(struct domain *dom) 1.8 +{ 1.9 + struct xencons_interface *intf = dom->interface; 1.10 + XENCONS_RING_IDX cons, prod, space; 1.11 + 1.12 + cons = intf->in_cons; 1.13 + prod = intf->in_prod; 1.14 + mb(); 1.15 + 1.16 + space = prod - cons; 1.17 + if (space > sizeof(intf->in)) 1.18 + return 0; /* ring is screwed: ignore it */ 1.19 + 1.20 + return (sizeof(intf->in) - space); 1.21 +} 1.22 + 1.23 static void handle_tty_read(struct domain *dom) 1.24 { 1.25 ssize_t len = 0; 1.26 char msg[80]; 1.27 int i; 1.28 struct xencons_interface *intf = dom->interface; 1.29 - XENCONS_RING_IDX cons, prod; 1.30 + XENCONS_RING_IDX prod; 1.31 1.32 - cons = intf->in_cons; 1.33 - prod = intf->in_prod; 1.34 - mb(); 1.35 + len = ring_free_bytes(dom); 1.36 + if (len == 0) 1.37 + return; 1.38 1.39 - if (sizeof(intf->in) > (prod - cons)) 1.40 - len = sizeof(intf->in) - (prod - cons); 1.41 if (len > sizeof(msg)) 1.42 len = sizeof(msg); 1.43 1.44 - if (len == 0) 1.45 - return; 1.46 - 1.47 len = read(dom->tty_fd, msg, len); 1.48 if (len < 1) { 1.49 close(dom->tty_fd); 1.50 @@ -465,6 +476,7 @@ static void handle_tty_read(struct domai 1.51 shutdown_domain(dom); 1.52 } 1.53 } else if (domain_is_valid(dom->domid)) { 1.54 + prod = intf->in_prod; 1.55 for (i = 0; i < len; i++) { 1.56 intf->in[MASK_XENCONS_IDX(prod++, intf->in)] = 1.57 msg[i]; 1.58 @@ -514,7 +526,7 @@ static void handle_ring_read(struct doma 1.59 (void)write_sync(dom->evtchn_fd, &v, sizeof(v)); 1.60 } 1.61 1.62 -static void handle_xs(int fd) 1.63 +static void handle_xs(void) 1.64 { 1.65 char **vec; 1.66 int domid; 1.67 @@ -560,7 +572,7 @@ void handle_io(void) 1.68 } 1.69 1.70 if (d->tty_fd != -1) { 1.71 - if (!d->is_dead) 1.72 + if (!d->is_dead && ring_free_bytes(d)) 1.73 FD_SET(d->tty_fd, &readfds); 1.74 1.75 if (!buffer_empty(&d->buffer)) 1.76 @@ -572,7 +584,7 @@ void handle_io(void) 1.77 ret = select(max_fd + 1, &readfds, &writefds, 0, NULL); 1.78 1.79 if (FD_ISSET(xs_fileno(xs), &readfds)) 1.80 - handle_xs(xs_fileno(xs)); 1.81 + handle_xs(); 1.82 1.83 for (d = dom_head; d; d = n) { 1.84 n = d->next;