tools/xenstore: move the call of setup_structure() to dom0 introduction
authorJuergen Gross <jgross@suse.com>
Tue, 13 Sep 2022 05:35:09 +0000 (07:35 +0200)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 1 Nov 2022 14:07:24 +0000 (14:07 +0000)
Setting up the basic structure when introducing dom0 has the advantage
to be able to add proper node memory accounting for the added nodes
later.

This makes it possible to do proper node accounting, too.

An additional requirement to make that work fine is to correct the
owner of the created nodes to be dom0_domid instead of domid 0.

This is part of XSA-326.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
(cherry picked from commit 60e2f6020dea7f616857b8fc1141b1c085d88761)

tools/xenstore/xenstored_core.c
tools/xenstore/xenstored_core.h
tools/xenstore/xenstored_domain.c

index f835aa1b2f1f3e5675c0a6b5c2d3b37d1fa0e7f0..5171d34c947e00e7545ead4700ea785e4655a49c 100644 (file)
@@ -2039,7 +2039,8 @@ static int tdb_flags;
 static void manual_node(const char *name, const char *child)
 {
        struct node *node;
-       struct xs_permissions perms = { .id = 0, .perms = XS_PERM_NONE };
+       struct xs_permissions perms = { .id = dom0_domid,
+                                       .perms = XS_PERM_NONE };
 
        node = talloc_zero(NULL, struct node);
        if (!node)
@@ -2078,7 +2079,7 @@ static void tdb_logger(TDB_CONTEXT *tdb, int level, const char * fmt, ...)
        }
 }
 
-static void setup_structure(bool live_update)
+void setup_structure(bool live_update)
 {
        char *tdbname;
 
@@ -2101,6 +2102,7 @@ static void setup_structure(bool live_update)
                manual_node("/", "tool");
                manual_node("/tool", "xenstored");
                manual_node("/tool/xenstored", NULL);
+               domain_entry_fix(dom0_domid, 3, true);
        }
 
        check_store();
@@ -2614,9 +2616,6 @@ int main(int argc, char *argv[])
 
        init_pipe(reopen_log_pipe);
 
-       /* Setup the database */
-       setup_structure(live_update);
-
        /* Listen to hypervisor. */
        if (!no_domain_init && !live_update) {
                domain_init(-1);
index 245f9258235fd6a9c56b3c859e5bbe37729c85af..2c77ec7ee0f47f210d3e9027deccb14608766e1b 100644 (file)
@@ -231,6 +231,7 @@ int write_node_raw(struct connection *conn, TDB_DATA *key, struct node *node,
 struct node *read_node(struct connection *conn, const void *ctx,
                       const char *name);
 
+void setup_structure(bool live_update);
 struct connection *new_connection(const struct interface_funcs *funcs);
 struct connection *get_connection_by_id(unsigned int conn_id);
 void ignore_connection(struct connection *conn);
index 260952e090965c17f4baa9363debecf4d5ac3054..f04b7aae8a323953f74c31d19cb7303e6cf37288 100644 (file)
@@ -470,6 +470,9 @@ static struct domain *introduce_domain(const void *ctx,
                }
                domain->interface = interface;
 
+               if (is_master_domain)
+                       setup_structure(restore);
+
                /* Now domain belongs to its connection. */
                talloc_steal(domain->conn, domain);