Fix xenstore entry accounting
PATCH 1/1 Fix xenstore entry accounting
# HG changeset patch
# User [email protected]
# Date 1180453350 25200
# Node ID 169ed8c1e7c79bd55d07110d9e784945b60da561 # Parent d39ebf946dff51d436f1d8393a9abf97f9654bf9 Fix xenstore entry accounting
xenstored is incorrectly accounting domain nodes when transactions fail. Store pending count changes in the transaction structure, and apply at transaction completion, instead of directly applying the changes.
Signed-off-by Max Zhen <[email protected]>
tools/xenstore/xenstored_domain.c +45 -11
@@ -605,12 +605,21 @@ void domain_entry_inc(struct connectionreturn ;if (node->perms && node->perms[0 ].id != conn->id) { - d =find_domain_by_domid (node->perms[0 ].id); -if (d) - d->nbentry++; - } -else if (conn->domain) { - conn->domain->nbentry++; +if (conn->transaction) { +transaction_entry_inc (conn->transaction, + node->perms[0 ].id); + }else { + d =find_domain_by_domid (node->perms[0 ].id); +if (d) + d->nbentry++; + } + }else if (conn->domain) { +if (conn->transaction) { +transaction_entry_inc (conn->transaction, + conn->domain->domid); + }else { + conn->domain->nbentry++; + } } }
@@ -622,11 +631,36 @@ void domain_entry_dec(struct connectionreturn ;if (node->perms && node->perms[0 ].id != conn->id) { - d =find_domain_by_domid (node->perms[0 ].id); -if (d && d->nbentry) - d->nbentry--; - }else if (conn->domain && conn->domain->nbentry) - conn->domain->nbentry--; +if (conn->transaction) { +transaction_entry_dec (conn->transaction, + node->perms[0 ].id); + }else { + d =find_domain_by_domid (node->perms[0 ].id); +if (d && d->nbentry) + d->nbentry--; + } + }else if (conn->domain && conn->domain->nbentry) { +if (conn->transaction) { +transaction_entry_dec (conn->transaction, + conn->domain->domid); + }else { + conn->domain->nbentry--; + } + } +} + +void domain_entry_fix (unsigned int domid,int num) +{ +struct domain *d; + + d =find_domain_by_domid (domid); +if (d) { +if ((d->nbentry += num) <0 ) { +eprintf ("invalid domain entry number %d" , + d->nbentry); + d->nbentry =0 ; + } + } }int domain_entry (struct connection *conn)
tools/xenstore/xenstored_domain.h +1 -0
@@ -55,6 +55,7 @@ bool domain_is_unprivileged(struct conne/* Quota manipulation */ void domain_entry_inc (struct connection *conn,struct node *);void domain_entry_dec (struct connection *conn,struct node *); +void domain_entry_fix (unsigned int domid,int num);int domain_entry (struct connection *conn);void domain_watch_inc (struct connection *conn);void domain_watch_dec (struct connection *conn);
tools/xenstore/xenstored_transaction.c +60 -0
102 lines not on this page · raw message
tools/xenstore/xenstored_transaction.h +4 -0
@@ -27,6 +27,10 @@ void do_transaction_end(struct connectiostruct transaction *transaction_lookup (struct connection *conn,uint32_t id); +/* inc/dec entry number local to trans while changing a node */ +void transaction_entry_inc (struct transaction *trans,unsigned int domid); +void transaction_entry_dec (struct transaction *trans,unsigned int domid); +/* This node was changed: can fail and longjmp. */ void add_change_node (struct transaction *trans,const char *node,bool recurse);