ia64/xen-unstable

changeset 17499:78d0a147216f

console: Provide option to stall the inter-domain console ring rather
than discard characters in the console daemon buffers.

New option: -o, --overflow-data=discard|keep

This option changes the behaviour when dealing with data that overflow
the max capacity of the buffer. If overflow-data is set to discard
(the default), the current behaviour is used: we discard some data in
the middle of the buffer.

If overflow-data is set to keep, we stop listening to the ring until
we free some space in the buffer. This can cause the ring to fill up
and the guest kernel internal buffer to fill up as well. When this
happens the guest kernel stops reading characters from the console
device so the application generating data hangs. When xenconsoled
resumes reading from the ring, the guest kernel will be able to resume
reading from the console device as well. At that point the guest
application will be allowed to continue.

The risk of making this behaviour the default is that existing kernel
drivers may assume they can rely on timely ring updates by the console
daemon and thus themselves block on the ring being emptied.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 22 10:34:55 2008 +0100 (2008-04-22)
parents 5e3baace443f
children fec632d30571
files tools/console/daemon/io.c tools/console/daemon/main.c
line diff
     1.1 --- a/tools/console/daemon/io.c	Tue Apr 22 10:29:32 2008 +0100
     1.2 +++ b/tools/console/daemon/io.c	Tue Apr 22 10:34:55 2008 +0100
     1.3 @@ -63,6 +63,7 @@ extern int log_hv;
     1.4  extern int log_time_hv;
     1.5  extern int log_time_guest;
     1.6  extern char *log_dir;
     1.7 +extern int discard_overflowed_data;
     1.8  
     1.9  static int log_time_hv_needts = 1;
    1.10  static int log_time_guest_needts = 1;
    1.11 @@ -201,7 +202,7 @@ static void buffer_append(struct domain 
    1.12  			      dom->domid, errno, strerror(errno));
    1.13  	}
    1.14  
    1.15 -	if (buffer->max_capacity &&
    1.16 +	if (discard_overflowed_data && buffer->max_capacity &&
    1.17  	    buffer->size > buffer->max_capacity) {
    1.18  		/* Discard the middle of the data. */
    1.19  
    1.20 @@ -228,6 +229,11 @@ static void buffer_advance(struct buffer
    1.21  	if (buffer->consumed == buffer->size) {
    1.22  		buffer->consumed = 0;
    1.23  		buffer->size = 0;
    1.24 +		if (buffer->max_capacity &&
    1.25 +		    buffer->capacity > buffer->max_capacity) {
    1.26 +			buffer->data = realloc(buffer->data, buffer->max_capacity);
    1.27 +			buffer->capacity = buffer->max_capacity;
    1.28 +		}
    1.29  	}
    1.30  }
    1.31  
    1.32 @@ -1005,9 +1011,13 @@ void handle_io(void)
    1.33  				    d->next_period < next_timeout)
    1.34  					next_timeout = d->next_period;
    1.35  			} else if (d->xce_handle != -1) {
    1.36 -				int evtchn_fd = xc_evtchn_fd(d->xce_handle);
    1.37 -				FD_SET(evtchn_fd, &readfds);
    1.38 -				max_fd = MAX(evtchn_fd, max_fd);
    1.39 +				if (discard_overflowed_data ||
    1.40 +				    !d->buffer.max_capacity ||
    1.41 +				    d->buffer.size < d->buffer.max_capacity) {
    1.42 +					int evtchn_fd = xc_evtchn_fd(d->xce_handle);
    1.43 +					FD_SET(evtchn_fd, &readfds);
    1.44 +					max_fd = MAX(evtchn_fd, max_fd);
    1.45 +				}
    1.46  			}
    1.47  
    1.48  			if (d->master_fd != -1) {
     2.1 --- a/tools/console/daemon/main.c	Tue Apr 22 10:29:32 2008 +0100
     2.2 +++ b/tools/console/daemon/main.c	Tue Apr 22 10:34:55 2008 +0100
     2.3 @@ -38,6 +38,7 @@ int log_hv = 0;
     2.4  int log_time_hv = 0;
     2.5  int log_time_guest = 0;
     2.6  char *log_dir = NULL;
     2.7 +int discard_overflowed_data = 1;
     2.8  
     2.9  static void handle_hup(int sig)
    2.10  {
    2.11 @@ -46,7 +47,7 @@ static void handle_hup(int sig)
    2.12  
    2.13  static void usage(char *name)
    2.14  {
    2.15 -	printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all] [--log-dir=DIR] [--pid-file=PATH] [-t, --timestamp=none|guest|hv|all]\n", name);
    2.16 +	printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all] [--log-dir=DIR] [--pid-file=PATH] [-t, --timestamp=none|guest|hv|all] [-o, --overflow-data=discard|keep]\n", name);
    2.17  }
    2.18  
    2.19  static void version(char *name)
    2.20 @@ -56,7 +57,7 @@ static void version(char *name)
    2.21  
    2.22  int main(int argc, char **argv)
    2.23  {
    2.24 -	const char *sopts = "hVvit:";
    2.25 +	const char *sopts = "hVvit:o:";
    2.26  	struct option lopts[] = {
    2.27  		{ "help", 0, 0, 'h' },
    2.28  		{ "version", 0, 0, 'V' },
    2.29 @@ -66,6 +67,7 @@ int main(int argc, char **argv)
    2.30  		{ "log-dir", 1, 0, 'r' },
    2.31  		{ "pid-file", 1, 0, 'p' },
    2.32  		{ "timestamp", 1, 0, 't' },
    2.33 +		{ "overflow-data", 1, 0, 'o'},
    2.34  		{ 0 },
    2.35  	};
    2.36  	bool is_interactive = false;
    2.37 @@ -119,6 +121,13 @@ int main(int argc, char **argv)
    2.38  				log_time_hv = 0;
    2.39  			}
    2.40  			break;
    2.41 +		case 'o':
    2.42 +			if (!strcmp(optarg, "keep")) {
    2.43 +				discard_overflowed_data = 0;
    2.44 +			} else if (!strcmp(optarg, "discard")) {
    2.45 +				discard_overflowed_data = 1;
    2.46 +			}
    2.47 +			break;
    2.48  		case '?':
    2.49  			fprintf(stderr,
    2.50  				"Try `%s --help' for more information\n",