]> xenbits.xensource.com Git - xen.git/commitdiff
xenstore: modify add_change_node() parameter types
authorJuergen Gross <jgross@suse.com>
Mon, 5 Dec 2016 07:48:42 +0000 (08:48 +0100)
committerWei Liu <wei.liu2@citrix.com>
Mon, 5 Dec 2016 11:19:57 +0000 (11:19 +0000)
In order to prepare adding a generation count to each node modify
add_change_node() to take the connection pointer and a node pointer
instead of the transaction pointer and node name as parameters. This
requires moving the call of add_change_node() from do_rm() to
delete_node_single().

While at it correct the comment for the prototype: there is no
longjmp() involved.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
tools/xenstore/xenstored_core.c
tools/xenstore/xenstored_transaction.c
tools/xenstore/xenstored_transaction.h

index 3df977b0c86e85b2d5e45e2acc35736a152c4ae0..de1a9b4e8ac60b5bf06ea86dffe62fc11cd98557 100644 (file)
@@ -822,7 +822,8 @@ static void do_read(struct connection *conn, struct buffered_data *in)
        send_reply(conn, XS_READ, node->data, node->datalen);
 }
 
-static void delete_node_single(struct connection *conn, struct node *node)
+static void delete_node_single(struct connection *conn, struct node *node,
+                              bool changed)
 {
        TDB_DATA key;
 
@@ -833,6 +834,10 @@ static void delete_node_single(struct connection *conn, struct node *node)
                corrupt(conn, "Could not delete '%s'", node->name);
                return;
        }
+
+       if (changed)
+               add_change_node(conn, node, true);
+
        domain_entry_dec(conn, node);
 }
 
@@ -971,7 +976,7 @@ static void do_write(struct connection *conn, struct buffered_data *in)
                }
        }
 
-       add_change_node(conn->transaction, name, false);
+       add_change_node(conn, node, false);
        fire_watches(conn, in, name, false);
        send_ack(conn, XS_WRITE);
 }
@@ -1002,20 +1007,21 @@ static void do_mkdir(struct connection *conn, struct buffered_data *in)
                        send_error(conn, errno);
                        return;
                }
-               add_change_node(conn->transaction, name, false);
+               add_change_node(conn, node, false);
                fire_watches(conn, in, name, false);
        }
        send_ack(conn, XS_MKDIR);
 }
 
-static void delete_node(struct connection *conn, struct node *node)
+static void delete_node(struct connection *conn, struct node *node,
+                       bool changed)
 {
        unsigned int i;
 
        /* Delete self, then delete children.  If we crash, then the worst
           that can happen is the children will continue to take up space, but
           will otherwise be unreachable. */
-       delete_node_single(conn, node);
+       delete_node_single(conn, node, changed);
 
        /* Delete children, too. */
        for (i = 0; i < node->childlen; i += strlen(node->children+i) + 1) {
@@ -1025,7 +1031,7 @@ static void delete_node(struct connection *conn, struct node *node)
                                  talloc_asprintf(node, "%s/%s", node->name,
                                                  node->children + i));
                if (child) {
-                       delete_node(conn, child);
+                       delete_node(conn, child, false);
                }
                else {
                        trace("delete_node: No child '%s/%s' found!\n",
@@ -1084,7 +1090,7 @@ static int _rm(struct connection *conn, struct node *node, const char *name)
                return 0;
        }
 
-       delete_node(conn, node);
+       delete_node(conn, node, true);
        return 1;
 }
 
@@ -1128,7 +1134,6 @@ static void do_rm(struct connection *conn, struct buffered_data *in)
        }
 
        if (_rm(conn, node, name)) {
-               add_change_node(conn->transaction, name, true);
                fire_watches(conn, in, name, true);
                send_ack(conn, XS_RM);
        }
@@ -1204,7 +1209,7 @@ static void do_set_perms(struct connection *conn, struct buffered_data *in)
                return;
        }
 
-       add_change_node(conn->transaction, name, false);
+       add_change_node(conn, node, false);
        fire_watches(conn, in, name, false);
        send_ack(conn, XS_SET_PERMS);
 }
index 84cb0bfac519292e6bdafbb108f11409b3df4fcf..b08b2eb4e67fe112b9e4b6cc6f32724de6da07cf 100644 (file)
@@ -92,18 +92,21 @@ TDB_CONTEXT *tdb_transaction_context(struct transaction *trans)
 
 /* Callers get a change node (which can fail) and only commit after they've
  * finished.  This way they don't have to unwind eg. a write. */
-void add_change_node(struct transaction *trans, const char *node, bool recurse)
+void add_change_node(struct connection *conn, struct node *node, bool recurse)
 {
        struct changed_node *i;
+       struct transaction *trans;
 
-       if (!trans) {
+       if (!conn || !conn->transaction) {
                /* They're changing the global database. */
                generation++;
                return;
        }
 
+       trans = conn->transaction;
+
        list_for_each_entry(i, &trans->changes, list) {
-               if (streq(i->node, node)) {
+               if (streq(i->node, node->name)) {
                        if (recurse)
                                i->recurse = recurse;
                        return;
@@ -111,7 +114,7 @@ void add_change_node(struct transaction *trans, const char *node, bool recurse)
        }
 
        i = talloc(trans, struct changed_node);
-       i->node = talloc_strdup(i, node);
+       i->node = talloc_strdup(i, node->name);
        i->recurse = recurse;
        list_add_tail(&i->list, &trans->changes);
 }
index 0c868ee504ee53e4bf60a4c486019c352e6f287c..7f0a7817923513aae01916e0e26eef2b45bf1da3 100644 (file)
@@ -30,8 +30,8 @@ struct transaction *transaction_lookup(struct connection *conn, uint32_t id);
 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,
+/* This node was changed. */
+void add_change_node(struct connection *conn, struct node *node,
                      bool recurse);
 
 /* Return tdb context to use for this connection. */