direct-io.hg

changeset 15428:f152e44325a7

xenconsoled: improve robustness of logfile handling

Check the 'log_reload' on every iteration of the select() loop, not just when
select() returns EINTR. This is because the log reload signal may have
iterrupted a syscall other than select & thus without this change we
might miss the reload signal. The second change makes us process the
hypervisor logs on every iteration of the loop, not just upon timeouts.
This is because if a guest VM were consistently sending some log message
and < 1 second period, the select() would never hit the 1 second timeout
and thus never process the HV logs.

Thanks to Markus Armbruster for pointing out both these edge cases

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author Keir Fraser <keir@xensource.com>
date Wed Jun 27 21:05:54 2007 +0100 (2007-06-27)
parents 4ab9e4bbd61b
children b370047d0fa0
files tools/console/daemon/io.c
line diff
     1.1 --- a/tools/console/daemon/io.c	Wed Jun 27 21:01:08 2007 +0100
     1.2 +++ b/tools/console/daemon/io.c	Wed Jun 27 21:05:54 2007 +0100
     1.3 @@ -764,27 +764,31 @@ void handle_io(void)
     1.4  		/* XXX I wish we didn't have to busy wait for hypervisor logs
     1.5  		 * but there's no obvious way to get event channel notifications
     1.6  		 * for new HV log data as we can with guest */
     1.7 -		ret = select(max_fd + 1, &readfds, &writefds, 0, log_hv_fd != -1 ? &timeout : NULL);
     1.8 +		ret = select(max_fd + 1, &readfds, &writefds, 0,
     1.9 +			     log_hv_fd != -1 ? &timeout : NULL);
    1.10  
    1.11 +		if (log_reload) {
    1.12 +			handle_log_reload();
    1.13 +			log_reload = 0;
    1.14 +		}
    1.15 +
    1.16 +		/* Abort if select failed, except for EINTR cases
    1.17 +		   which indicate a possible log reload */
    1.18  		if (ret == -1) {
    1.19 -			if (errno == EINTR) {
    1.20 -				if (log_reload) {
    1.21 -					handle_log_reload();
    1.22 -					log_reload = 0;
    1.23 -				}
    1.24 +			if (errno == EINTR)
    1.25  				continue;
    1.26 -			}
    1.27  			dolog(LOG_ERR, "Failure in select: %d (%s)",
    1.28  			      errno, strerror(errno));
    1.29  			break;
    1.30  		}
    1.31  
    1.32 -		/* Check for timeout */
    1.33 -		if (ret == 0) {
    1.34 -			if (log_hv_fd != -1)
    1.35 -				handle_hv_logs();
    1.36 +		/* Always process HV logs even if not a timeout */
    1.37 +		if (log_hv_fd != -1)
    1.38 +			handle_hv_logs();
    1.39 +
    1.40 +		/* Must not check returned FDSET if it was a timeout */
    1.41 +		if (ret == 0)
    1.42  			continue;
    1.43 -		}
    1.44  
    1.45  		if (FD_ISSET(xs_fileno(xs), &readfds))
    1.46  			handle_xs();
    1.47 @@ -806,10 +810,14 @@ void handle_io(void)
    1.48  		}
    1.49  	}
    1.50  
    1.51 -	if (log_hv_fd != -1)
    1.52 +	if (log_hv_fd != -1) {
    1.53  		close(log_hv_fd);
    1.54 -	if (xc_handle != -1)
    1.55 +		log_hv_fd = -1;
    1.56 +	}
    1.57 +	if (xc_handle != -1) {
    1.58  		xc_interface_close(xc_handle);
    1.59 +		xc_handle = -1;
    1.60 +	}
    1.61  }
    1.62  
    1.63  /*