WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Fix xenstore entry accounting

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Fix xenstore entry accounting
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 04 Jun 2007 03:16:03 -0700
Delivery-date: Mon, 04 Jun 2007 03:17:55 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1180515863 -3600
# Node ID 1bad5a932df591a891855d8369c3f4c676e64c56
# Parent  33242afccb3261b438e51cd1ce73381e4595acfa
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 <max.zhen@xxxxxxx>
---
 tools/xenstore/xenstored_domain.c      |   56 ++++++++++++++++++++++++++-------
 tools/xenstore/xenstored_domain.h      |    1 
 tools/xenstore/xenstored_transaction.c |   54 +++++++++++++++++++++++++++++++
 tools/xenstore/xenstored_transaction.h |    4 ++
 4 files changed, 104 insertions(+), 11 deletions(-)

diff -r 33242afccb32 -r 1bad5a932df5 tools/xenstore/xenstored_domain.c
--- a/tools/xenstore/xenstored_domain.c Wed May 30 09:59:09 2007 +0100
+++ b/tools/xenstore/xenstored_domain.c Wed May 30 10:04:23 2007 +0100
@@ -576,12 +576,21 @@ void domain_entry_inc(struct connection 
                return;
 
        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++;
+               }
        }
 }
 
@@ -593,11 +602,36 @@ void domain_entry_dec(struct connection 
                return;
 
        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)
diff -r 33242afccb32 -r 1bad5a932df5 tools/xenstore/xenstored_domain.h
--- a/tools/xenstore/xenstored_domain.h Wed May 30 09:59:09 2007 +0100
+++ b/tools/xenstore/xenstored_domain.h Wed May 30 10:04:23 2007 +0100
@@ -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);
diff -r 33242afccb32 -r 1bad5a932df5 tools/xenstore/xenstored_transaction.c
--- a/tools/xenstore/xenstored_transaction.c    Wed May 30 09:59:09 2007 +0100
+++ b/tools/xenstore/xenstored_transaction.c    Wed May 30 10:04:23 2007 +0100
@@ -32,6 +32,7 @@
 #include "list.h"
 #include "xenstored_transaction.h"
 #include "xenstored_watch.h"
+#include "xenstored_domain.h"
 #include "xs_lib.h"
 #include "utils.h"
 #include "xenstored_test.h"
@@ -48,6 +49,18 @@ struct changed_node
        bool recurse;
 };
 
+struct changed_domain
+{
+       /* List of all changed domains in the context of this transaction. */
+       struct list_head list;
+
+       /* Identifier of the changed domain. */
+       unsigned int domid;
+
+       /* Amount by which this domain's nbentry field has changed. */
+       int nbentry;
+};
+
 struct transaction
 {
        /* List of all transactions active on this connection. */
@@ -65,6 +78,9 @@ struct transaction
 
        /* List of changed nodes. */
        struct list_head changes;
+
+       /* List of changed domains - to record the changed domain entry number 
*/
+       struct list_head changed_domains;
 };
 
 extern int quota_max_transaction;
@@ -142,6 +158,7 @@ void do_transaction_start(struct connect
        /* Attach transaction to input for autofree until it's complete */
        trans = talloc(in, struct transaction);
        INIT_LIST_HEAD(&trans->changes);
+       INIT_LIST_HEAD(&trans->changed_domains);
        trans->generation = generation;
        trans->tdb_name = talloc_asprintf(trans, "%s.%p",
                                          xs_daemon_tdb(), trans);
@@ -172,6 +189,7 @@ void do_transaction_end(struct connectio
 void do_transaction_end(struct connection *conn, const char *arg)
 {
        struct changed_node *i;
+       struct changed_domain *d;
        struct transaction *trans;
 
        if (!arg || (!streq(arg, "T") && !streq(arg, "F"))) {
@@ -204,12 +222,48 @@ void do_transaction_end(struct connectio
                /* Don't close this: we won! */
                trans->tdb = NULL;
 
+               /* fix domain entry for each changed domain */
+               list_for_each_entry(d, &trans->changed_domains, list)
+                       domain_entry_fix(d->domid, d->nbentry);
+
                /* Fire off the watches for everything that changed. */
                list_for_each_entry(i, &trans->changes, list)
                        fire_watches(conn, i->node, i->recurse);
                generation++;
        }
        send_ack(conn, XS_TRANSACTION_END);
+}
+
+void transaction_entry_inc(struct transaction *trans, unsigned int domid)
+{
+       struct changed_domain *d;
+
+       list_for_each_entry(d, &trans->changed_domains, list)
+               if (d->domid == domid) {
+                       d->nbentry++;
+                       return;
+               }
+
+       d = talloc(trans, struct changed_domain);
+       d->domid = domid;
+       d->nbentry = 1;
+       list_add_tail(&d->list, &trans->changed_domains);
+}
+
+void transaction_entry_dec(struct transaction *trans, unsigned int domid)
+{
+       struct changed_domain *d;
+
+       list_for_each_entry(d, &trans->changed_domains, list)
+               if (d->domid == domid) {
+                       d->nbentry--;
+                       return;
+               }
+
+       d = talloc(trans, struct changed_domain);
+       d->domid = domid;
+       d->nbentry = -1;
+       list_add_tail(&d->list, &trans->changed_domains);
 }
 
 void conn_delete_all_transactions(struct connection *conn)
diff -r 33242afccb32 -r 1bad5a932df5 tools/xenstore/xenstored_transaction.h
--- a/tools/xenstore/xenstored_transaction.h    Wed May 30 09:59:09 2007 +0100
+++ b/tools/xenstore/xenstored_transaction.h    Wed May 30 10:04:23 2007 +0100
@@ -27,6 +27,10 @@ void do_transaction_end(struct connectio
 
 struct 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);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Fix xenstore entry accounting, Xen patchbot-unstable <=