ia64/xen-unstable

changeset 14204:3186248a1236

Fully reset the xenstore connection when a domain is (re)introduced to xenstored.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Mar 01 14:51:12 2007 +0000 (2007-03-01)
parents beabac411220
children 10eb93864df5
files tools/xenstore/xenstored_domain.c tools/xenstore/xenstored_transaction.c tools/xenstore/xenstored_transaction.h tools/xenstore/xenstored_watch.c tools/xenstore/xenstored_watch.h
line diff
     1.1 --- a/tools/xenstore/xenstored_domain.c	Thu Mar 01 14:00:05 2007 +0000
     1.2 +++ b/tools/xenstore/xenstored_domain.c	Thu Mar 01 14:51:12 2007 +0000
     1.3 @@ -28,6 +28,7 @@
     1.4  #include "talloc.h"
     1.5  #include "xenstored_core.h"
     1.6  #include "xenstored_domain.h"
     1.7 +#include "xenstored_transaction.h"
     1.8  #include "xenstored_watch.h"
     1.9  #include "xenstored_test.h"
    1.10  
    1.11 @@ -289,6 +290,26 @@ static struct domain *find_domain_by_dom
    1.12  	return NULL;
    1.13  }
    1.14  
    1.15 +static void domain_conn_reset(struct domain *domain)
    1.16 +{
    1.17 +	struct connection *conn = domain->conn;
    1.18 +	struct buffered_data *out;
    1.19 +
    1.20 +	conn_delete_all_watches(conn);
    1.21 +	conn_delete_all_transactions(conn);
    1.22 +
    1.23 +	while ((out = list_top(&conn->out_list, struct buffered_data, list))) {
    1.24 +		list_del(&out->list);
    1.25 +		talloc_free(out);
    1.26 +	}
    1.27 +
    1.28 +	talloc_free(conn->in->buffer);
    1.29 +	memset(conn->in, 0, sizeof(*conn->in));
    1.30 +	conn->in->inhdr = true;
    1.31 +
    1.32 +	domain->interface->req_cons = domain->interface->req_prod = 0;
    1.33 +	domain->interface->rsp_cons = domain->interface->rsp_prod = 0;
    1.34 +}
    1.35  
    1.36  /* domid, mfn, evtchn, path */
    1.37  void do_introduce(struct connection *conn, struct buffered_data *in)
    1.38 @@ -342,7 +363,7 @@ void do_introduce(struct connection *con
    1.39  		talloc_steal(domain->conn, domain);
    1.40  
    1.41  		fire_watches(conn, "@introduceDomain", false);
    1.42 -	} else if (domain->mfn == mfn) {
    1.43 +	} else if ((domain->mfn == mfn) && (domain->conn != conn)) {
    1.44  		/* Use XS_INTRODUCE for recreating the xenbus event-channel. */
    1.45  		if (domain->port)
    1.46  			xc_evtchn_unbind(xce_handle, domain->port);
    1.47 @@ -354,9 +375,7 @@ void do_introduce(struct connection *con
    1.48  		return;
    1.49  	}
    1.50  
    1.51 -	/* Rings must be quiesced. */
    1.52 -	domain->interface->req_cons = domain->interface->req_prod = 0;
    1.53 -	domain->interface->rsp_cons = domain->interface->rsp_prod = 0;
    1.54 +	domain_conn_reset(domain);
    1.55  
    1.56  	send_ack(conn, XS_INTRODUCE);
    1.57  }
     2.1 --- a/tools/xenstore/xenstored_transaction.c	Thu Mar 01 14:00:05 2007 +0000
     2.2 +++ b/tools/xenstore/xenstored_transaction.c	Thu Mar 01 14:51:12 2007 +0000
     2.3 @@ -23,6 +23,7 @@
     2.4  #include <sys/wait.h>
     2.5  #include <sys/time.h>
     2.6  #include <time.h>
     2.7 +#include <assert.h>
     2.8  #include <stdarg.h>
     2.9  #include <stdlib.h>
    2.10  #include <fcntl.h>
    2.11 @@ -211,6 +212,21 @@ void do_transaction_end(struct connectio
    2.12  	send_ack(conn, XS_TRANSACTION_END);
    2.13  }
    2.14  
    2.15 +void conn_delete_all_transactions(struct connection *conn)
    2.16 +{
    2.17 +	struct transaction *trans;
    2.18 +
    2.19 +	while ((trans = list_top(&conn->transaction_list,
    2.20 +				 struct transaction, list))) {
    2.21 +		list_del(&trans->list);
    2.22 +		talloc_free(trans);
    2.23 +	}
    2.24 +
    2.25 +	assert(conn->transaction == NULL);
    2.26 +
    2.27 +	conn->transaction_started = 0;
    2.28 +}
    2.29 +
    2.30  /*
    2.31   * Local variables:
    2.32   *  c-file-style: "linux"
     3.1 --- a/tools/xenstore/xenstored_transaction.h	Thu Mar 01 14:00:05 2007 +0000
     3.2 +++ b/tools/xenstore/xenstored_transaction.h	Thu Mar 01 14:51:12 2007 +0000
     3.3 @@ -33,4 +33,7 @@ void add_change_node(struct transaction 
     3.4  
     3.5  /* Return tdb context to use for this connection. */
     3.6  TDB_CONTEXT *tdb_transaction_context(struct transaction *trans);
     3.7 +
     3.8 +void conn_delete_all_transactions(struct connection *conn);
     3.9 +
    3.10  #endif /* _XENSTORED_TRANSACTION_H */
     4.1 --- a/tools/xenstore/xenstored_watch.c	Thu Mar 01 14:00:05 2007 +0000
     4.2 +++ b/tools/xenstore/xenstored_watch.c	Thu Mar 01 14:51:12 2007 +0000
     4.3 @@ -185,6 +185,17 @@ void do_unwatch(struct connection *conn,
     4.4  	send_error(conn, ENOENT);
     4.5  }
     4.6  
     4.7 +void conn_delete_all_watches(struct connection *conn)
     4.8 +{
     4.9 +	struct watch *watch;
    4.10 +
    4.11 +	while ((watch = list_top(&conn->watches, struct watch, list))) {
    4.12 +		list_del(&watch->list);
    4.13 +		talloc_free(watch);
    4.14 +		domain_watch_dec(conn);
    4.15 +	}
    4.16 +}
    4.17 +
    4.18  #ifdef TESTING
    4.19  void dump_watches(struct connection *conn)
    4.20  {
     5.1 --- a/tools/xenstore/xenstored_watch.h	Thu Mar 01 14:00:05 2007 +0000
     5.2 +++ b/tools/xenstore/xenstored_watch.h	Thu Mar 01 14:51:12 2007 +0000
     5.3 @@ -30,4 +30,6 @@ void fire_watches(struct connection *con
     5.4  
     5.5  void dump_watches(struct connection *conn);
     5.6  
     5.7 +void conn_delete_all_watches(struct connection *conn);
     5.8 +
     5.9  #endif /* _XENSTORED_WATCH_H */