[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 04/18] tools/xenstore: rename do_tdb_delete() and change parameter type



Rename do_tdb_delete() to db_delete() and replace the key parameter
with db_name specifying the name of the node in the data base.

This is in preparation to replace TDB with a more simple data storage.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
V2:
- remove unrelated change (Julien Grall)
---
 tools/xenstore/xenstored_core.c        | 31 ++++++++++++--------------
 tools/xenstore/xenstored_core.h        |  5 +++--
 tools/xenstore/xenstored_transaction.c | 16 +++++--------
 3 files changed, 23 insertions(+), 29 deletions(-)

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 6d7f002b54..5e83c412ad 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -658,28 +658,31 @@ int do_tdb_write(struct connection *conn, TDB_DATA *key, 
TDB_DATA *data,
        return 0;
 }
 
-int do_tdb_delete(struct connection *conn, TDB_DATA *key,
-                 struct node_account_data *acc)
+int db_delete(struct connection *conn, const char *name,
+             struct node_account_data *acc)
 {
        struct node_account_data tmp_acc;
        unsigned int domid;
+       TDB_DATA key;
+
+       set_tdb_key(name, &key);
 
        if (!acc) {
                acc = &tmp_acc;
                acc->memory = -1;
        }
 
-       get_acc_data(key, acc);
+       get_acc_data(&key, acc);
 
-       if (tdb_delete(tdb_ctx, *key)) {
+       if (tdb_delete(tdb_ctx, key)) {
                errno = EIO;
                return errno;
        }
-       trace_tdb("delete %s\n", key->dptr);
+       trace_tdb("delete %s\n", name);
 
        if (acc->memory) {
-               domid = get_acc_domid(conn, key, acc->domid);
-               domain_memory_add_nochk(conn, domid, -acc->memory - key->dsize);
+               domid = get_acc_domid(conn, &key, acc->domid);
+               domain_memory_add_nochk(conn, domid, -acc->memory - key.dsize);
        }
 
        return 0;
@@ -1450,13 +1453,10 @@ nomem:
 
 static void destroy_node_rm(struct connection *conn, struct node *node)
 {
-       TDB_DATA key;
-
        if (streq(node->name, "/"))
                corrupt(NULL, "Destroying root node!");
 
-       set_tdb_key(node->db_name, &key);
-       do_tdb_delete(conn, &key, &node->acc);
+       db_delete(conn, node->db_name, &node->acc);
 }
 
 static int destroy_node(struct connection *conn, struct node *node)
@@ -1647,7 +1647,6 @@ static int delnode_sub(const void *ctx, struct connection 
*conn,
        bool watch_exact;
        int ret;
        const char *db_name;
-       TDB_DATA key;
 
        /* Any error here will probably be repeated for all following calls. */
        ret = access_node(conn, node, NODE_ACCESS_DELETE, &db_name);
@@ -1658,8 +1657,7 @@ static int delnode_sub(const void *ctx, struct connection 
*conn,
                return WALK_TREE_ERROR_STOP;
 
        /* In case of error stop the walk. */
-       set_tdb_key(db_name, &key);
-       if (!ret && do_tdb_delete(conn, &key, &node->acc))
+       if (!ret && db_delete(conn, db_name, &node->acc))
                return WALK_TREE_ERROR_STOP;
 
        /*
@@ -2484,9 +2482,8 @@ static int clean_store_(TDB_CONTEXT *tdb, TDB_DATA key, 
TDB_DATA val,
        }
        if (!hashtable_search(reachable, name)) {
                log("clean_store: '%s' is orphaned!", name);
-               if (recovery) {
-                       do_tdb_delete(NULL, &key, NULL);
-               }
+               if (recovery)
+                       db_delete(NULL, name, NULL);
        }
 
        talloc_free(name);
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index 2cfc01f200..7bc1f68532 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -361,12 +361,13 @@ extern xengnttab_handle **xgt_handle;
 
 int remember_string(struct hashtable *hash, const char *str);
 
+/* Data base access functions. */
 void set_tdb_key(const char *name, TDB_DATA *key);
 int do_tdb_write(struct connection *conn, TDB_DATA *key, TDB_DATA *data,
                 struct node_account_data *acc, enum write_node_mode mode,
                 bool no_quota_check);
-int do_tdb_delete(struct connection *conn, TDB_DATA *key,
-                 struct node_account_data *acc);
+int db_delete(struct connection *conn, const char *name,
+             struct node_account_data *acc);
 
 void conn_free_buffered_data(struct connection *conn);
 
diff --git a/tools/xenstore/xenstored_transaction.c 
b/tools/xenstore/xenstored_transaction.c
index 1646c07040..a4f9d40e9a 100644
--- a/tools/xenstore/xenstored_transaction.c
+++ b/tools/xenstore/xenstored_transaction.c
@@ -385,8 +385,7 @@ static int finalize_transaction(struct connection *conn,
                /* Entries for unmodified nodes can be removed early. */
                if (!i->modified) {
                        if (i->ta_node) {
-                               set_tdb_key(i->trans_name, &ta_key);
-                               if (do_tdb_delete(conn, &ta_key, NULL))
+                               if (db_delete(conn, i->trans_name, NULL))
                                        return EIO;
                        }
                        list_del(&i->list);
@@ -395,7 +394,6 @@ static int finalize_transaction(struct connection *conn,
        }
 
        while ((i = list_top(&trans->accessed, struct accessed_node, list))) {
-               set_tdb_key(i->node, &key);
                if (i->ta_node) {
                        set_tdb_key(i->trans_name, &ta_key);
                        data = tdb_fetch(tdb_ctx, ta_key);
@@ -406,10 +404,11 @@ static int finalize_transaction(struct connection *conn,
                                hdr->generation = ++generation;
                                flag = (i->generation == NO_GENERATION)
                                       ? NODE_CREATE : NODE_MODIFY;
+                               set_tdb_key(i->node, &key);
                                *is_corrupt |= do_tdb_write(conn, &key, &data,
                                                            NULL, flag, true);
                                talloc_free(data.dptr);
-                               if (do_tdb_delete(conn, &ta_key, NULL))
+                               if (db_delete(conn, i->trans_name, NULL))
                                        *is_corrupt = true;
                        } else {
                                *is_corrupt = true;
@@ -422,7 +421,7 @@ static int finalize_transaction(struct connection *conn,
                         */
                        *is_corrupt |= (i->generation == NO_GENERATION)
                                       ? false
-                                      : do_tdb_delete(conn, &key, NULL);
+                                      : db_delete(conn, i->node, NULL);
                }
                if (i->fire_watch)
                        fire_watches(conn, trans, i->node, NULL, i->watch_exact,
@@ -439,15 +438,12 @@ static int destroy_transaction(void *_transaction)
 {
        struct transaction *trans = _transaction;
        struct accessed_node *i;
-       TDB_DATA key;
 
        wrl_ntransactions--;
        trace_destroy(trans, "transaction");
        while ((i = list_top(&trans->accessed, struct accessed_node, list))) {
-               if (i->ta_node) {
-                       set_tdb_key(i->trans_name, &key);
-                       do_tdb_delete(trans->conn, &key, NULL);
-               }
+               if (i->ta_node)
+                       db_delete(trans->conn, i->trans_name, NULL);
                list_del(&i->list);
                talloc_free(i);
        }
-- 
2.35.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.