direct-io.hg

changeset 7305:5cca372aec05

Echo request and transaction identifiers in xenstored
replies (and set to zero for async watch events).

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Oct 11 12:39:03 2005 +0100 (2005-10-11)
parents e43ffb31de48
children 46bd7564125d
files tools/xenstore/xenstored_core.c
line diff
     1.1 --- a/tools/xenstore/xenstored_core.c	Tue Oct 11 11:59:15 2005 +0100
     1.2 +++ b/tools/xenstore/xenstored_core.c	Tue Oct 11 12:39:03 2005 +0100
     1.3 @@ -539,6 +539,9 @@ static struct buffered_data *new_buffer(
     1.4  	struct buffered_data *data;
     1.5  
     1.6  	data = talloc(ctx, struct buffered_data);
     1.7 +	if (data == NULL)
     1.8 +		return NULL;
     1.9 +	
    1.10  	data->inhdr = true;
    1.11  	data->used = 0;
    1.12  	data->buffer = NULL;
    1.13 @@ -583,15 +586,24 @@ void send_reply(struct connection *conn,
    1.14  {
    1.15  	struct buffered_data *bdata;
    1.16  
    1.17 -	/* When data gets freed, we want list entry is destroyed (so
    1.18 -	 * list entry is a child). */
    1.19 +	/* Message is a child of the connection context for auto-cleanup. */
    1.20  	bdata = new_buffer(conn);
    1.21  	bdata->buffer = talloc_array(bdata, char, len);
    1.22  
    1.23 +	/* Echo request header in reply unless this is an async watch event. */
    1.24 +	if (type != XS_WATCH_EVENT) {
    1.25 +		memcpy(&bdata->hdr.msg, &conn->in->hdr.msg,
    1.26 +		       sizeof(struct xsd_sockmsg));
    1.27 +	} else {
    1.28 +		memset(&bdata->hdr.msg, 0, sizeof(struct xsd_sockmsg));
    1.29 +	}
    1.30 +
    1.31 +	/* Update relevant header fields and fill in the message body. */
    1.32  	bdata->hdr.msg.type = type;
    1.33  	bdata->hdr.msg.len = len;
    1.34  	memcpy(bdata->buffer, data, len);
    1.35  
    1.36 +	/* Queue for later transmission. */
    1.37  	list_add_tail(&bdata->list, &conn->out_list);
    1.38  }
    1.39  
    1.40 @@ -1144,36 +1156,25 @@ static int out_of_mem(void *data)
    1.41  
    1.42  static void consider_message(struct connection *conn)
    1.43  {
    1.44 -	/*
    1.45 -	 * 'volatile' qualifier prevents register allocation which fixes:
    1.46 -	 *   warning: variable 'xxx' might be clobbered by 'longjmp' or 'vfork'
    1.47 -	 */
    1.48 -	struct buffered_data *volatile in = NULL;
    1.49 -	enum xsd_sockmsg_type volatile type = conn->in->hdr.msg.type;
    1.50  	jmp_buf talloc_fail;
    1.51  
    1.52 +	if (verbose)
    1.53 +		xprintf("Got message %s len %i from %p\n",
    1.54 +			sockmsg_string(conn->in->hdr.msg.type),
    1.55 +			conn->in->hdr.msg.len, conn);
    1.56 +
    1.57  	/* For simplicity, we kill the connection on OOM. */
    1.58  	talloc_set_fail_handler(out_of_mem, &talloc_fail);
    1.59  	if (setjmp(talloc_fail)) {
    1.60 -		/* Free in before conn, in case it needs something. */
    1.61 -		talloc_free(in);
    1.62  		talloc_free(conn);
    1.63  		goto end;
    1.64  	}
    1.65  
    1.66 -	if (verbose)
    1.67 -		xprintf("Got message %s len %i from %p\n",
    1.68 -			sockmsg_string(type), conn->in->hdr.msg.len, conn);
    1.69 +	process_message(conn, conn->in);
    1.70  
    1.71 -	/* Careful: process_message may free connection.  We detach
    1.72 -	 * "in" beforehand and allocate the new buffer to avoid
    1.73 -	 * touching conn after process_message.
    1.74 -	 */
    1.75 -	in = talloc_steal(talloc_autofree_context(), conn->in);
    1.76 +	talloc_free(conn->in);
    1.77  	conn->in = new_buffer(conn);
    1.78 -	process_message(conn, in);
    1.79  
    1.80 -	talloc_free(in);
    1.81  end:
    1.82  	talloc_set_fail_handler(NULL, NULL);
    1.83  	if (talloc_total_blocks(NULL)
    1.84 @@ -1242,12 +1243,7 @@ static void handle_output(struct connect
    1.85  
    1.86  struct connection *new_connection(connwritefn_t *write, connreadfn_t *read)
    1.87  {
    1.88 -	/*
    1.89 -	 * 'volatile' qualifier prevents register allocation which fixes:
    1.90 -	 *   warning: variable 'xxx' might be clobbered by 'longjmp' or 'vfork'
    1.91 -	 */
    1.92 -	struct connection *volatile new;
    1.93 -	jmp_buf talloc_fail;
    1.94 +	struct connection *new;
    1.95  
    1.96  	new = talloc(talloc_autofree_context(), struct connection);
    1.97  	if (!new)
    1.98 @@ -1262,13 +1258,11 @@ struct connection *new_connection(connwr
    1.99  	INIT_LIST_HEAD(&new->watches);
   1.100  	INIT_LIST_HEAD(&new->transaction_list);
   1.101  
   1.102 -	talloc_set_fail_handler(out_of_mem, &talloc_fail);
   1.103 -	if (setjmp(talloc_fail)) {
   1.104 +	new->in = new_buffer(new);
   1.105 +	if (new->in == NULL) {
   1.106  		talloc_free(new);
   1.107  		return NULL;
   1.108  	}
   1.109 -	new->in = new_buffer(new);
   1.110 -	talloc_set_fail_handler(NULL, NULL);
   1.111  
   1.112  	list_add_tail(&new->list, &connections);
   1.113  	talloc_set_destructor(new, destroy_conn);