ia64/xen-unstable

changeset 15650:68260372b6da

xenstore: Small cleanups and fixes.
1. readfd/writefd account for EINTR/EAGAIN errno returns.
2. Handle zero return from ->read() and ->write() handlers
symmetrically.
3. Fix some indentation issues (use hard tabs).
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Tue Jul 24 18:28:48 2007 +0100 (2007-07-24)
parents 207582c8d88b
children 3ec3e2840a29
files tools/xenstore/xenstored_core.c tools/xenstore/xenstored_domain.c tools/xenstore/xenstored_watch.c
line diff
     1.1 --- a/tools/xenstore/xenstored_core.c	Tue Jul 24 18:05:04 2007 +0100
     1.2 +++ b/tools/xenstore/xenstored_core.c	Tue Jul 24 18:28:48 2007 +0100
     1.3 @@ -1266,7 +1266,7 @@ static void handle_input(struct connecti
     1.4  	if (in->inhdr) {
     1.5  		bytes = conn->read(conn, in->hdr.raw + in->used,
     1.6  				   sizeof(in->hdr) - in->used);
     1.7 -		if (bytes <= 0)
     1.8 +		if (bytes < 0)
     1.9  			goto bad_client;
    1.10  		in->used += bytes;
    1.11  		if (in->used != sizeof(in->hdr))
    1.12 @@ -1288,7 +1288,7 @@ static void handle_input(struct connecti
    1.13  
    1.14  	bytes = conn->read(conn, in->buffer + in->used,
    1.15  			   in->hdr.msg.len - in->used);
    1.16 -	if (bytes <= 0)
    1.17 +	if (bytes < 0)
    1.18  		goto bad_client;
    1.19  
    1.20  	in->used += bytes;
    1.21 @@ -1341,12 +1341,34 @@ struct connection *new_connection(connwr
    1.22  
    1.23  static int writefd(struct connection *conn, const void *data, unsigned int len)
    1.24  {
    1.25 -	return write(conn->fd, data, len);
    1.26 +	int rc;
    1.27 +
    1.28 +	while ((rc = write(conn->fd, data, len)) < 0) {
    1.29 +		if (errno == EAGAIN) {
    1.30 +			rc = 0;
    1.31 +			break;
    1.32 +		}
    1.33 +		if (errno != EINTR)
    1.34 +			break;
    1.35 +	}
    1.36 +
    1.37 +	return rc;
    1.38  }
    1.39  
    1.40  static int readfd(struct connection *conn, void *data, unsigned int len)
    1.41  {
    1.42 -	return read(conn->fd, data, len);
    1.43 +	int rc;
    1.44 +
    1.45 +	while ((rc = read(conn->fd, data, len)) < 0) {
    1.46 +		if (errno == EAGAIN) {
    1.47 +			rc = 0;
    1.48 +			break;
    1.49 +		}
    1.50 +		if (errno != EINTR)
    1.51 +			break;
    1.52 +	}
    1.53 +
    1.54 +	return rc;
    1.55  }
    1.56  
    1.57  static void accept_connection(int sock, bool canwrite)
    1.58 @@ -1439,13 +1461,13 @@ static void setup_structure(void)
    1.59  static unsigned int hash_from_key_fn(void *k)
    1.60  {
    1.61  	char *str = k;
    1.62 -        unsigned int hash = 5381;
    1.63 -        char c;
    1.64 +	unsigned int hash = 5381;
    1.65 +	char c;
    1.66  
    1.67 -        while ((c = *str++))
    1.68 +	while ((c = *str++))
    1.69  		hash = ((hash << 5) + hash) + (unsigned int)c;
    1.70  
    1.71 -        return hash;
    1.72 +	return hash;
    1.73  }
    1.74  
    1.75  
     2.1 --- a/tools/xenstore/xenstored_domain.c	Tue Jul 24 18:05:04 2007 +0100
     2.2 +++ b/tools/xenstore/xenstored_domain.c	Tue Jul 24 18:28:48 2007 +0100
     2.3 @@ -76,7 +76,6 @@ struct domain
     2.4  
     2.5  static LIST_HEAD(domains);
     2.6  
     2.7 -/* FIXME: Mark connection as broken (close it?) when this happens. */
     2.8  static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod)
     2.9  {
    2.10  	return ((prod - cons) <= XENSTORE_RING_SIZE);
    2.11 @@ -102,7 +101,8 @@ static const void *get_input_chunk(XENST
    2.12  	return buf + MASK_XENSTORE_IDX(cons);
    2.13  }
    2.14  
    2.15 -static int writechn(struct connection *conn, const void *data, unsigned int len)
    2.16 +static int writechn(struct connection *conn,
    2.17 +		    const void *data, unsigned int len)
    2.18  {
    2.19  	uint32_t avail;
    2.20  	void *dest;
    2.21 @@ -113,6 +113,7 @@ static int writechn(struct connection *c
    2.22  	cons = intf->rsp_cons;
    2.23  	prod = intf->rsp_prod;
    2.24  	mb();
    2.25 +
    2.26  	if (!check_indexes(cons, prod)) {
    2.27  		errno = EIO;
    2.28  		return -1;
     3.1 --- a/tools/xenstore/xenstored_watch.c	Tue Jul 24 18:05:04 2007 +0100
     3.2 +++ b/tools/xenstore/xenstored_watch.c	Tue Jul 24 18:28:48 2007 +0100
     3.3 @@ -73,11 +73,10 @@ static void add_event(struct connection 
     3.4  	data = talloc_array(watch, char, len);
     3.5  	strcpy(data, name);
     3.6  	strcpy(data + strlen(name) + 1, watch->token);
     3.7 -        send_reply(conn, XS_WATCH_EVENT, data, len);
     3.8 +	send_reply(conn, XS_WATCH_EVENT, data, len);
     3.9  	talloc_free(data);
    3.10  }
    3.11  
    3.12 -/* FIXME: we fail to fire on out of memory.  Should drop connections. */
    3.13  void fire_watches(struct connection *conn, const char *name, bool recurse)
    3.14  {
    3.15  	struct connection *i;
    3.16 @@ -130,7 +129,7 @@ void do_watch(struct connection *conn, s
    3.17  	/* Check for duplicates. */
    3.18  	list_for_each_entry(watch, &conn->watches, list) {
    3.19  		if (streq(watch->node, vec[0]) &&
    3.20 -                    streq(watch->token, vec[1])) {
    3.21 +		    streq(watch->token, vec[1])) {
    3.22  			send_error(conn, EEXIST);
    3.23  			return;
    3.24  		}