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

[PATCH 05/11] tools/xenstored: split acc[] array in struct domain



Prepare using per-domain quota by splitting the acc[] array in struct
domain into an array with the current accounting data, and an array
of type struct quota for the per-domain quota and the seen max value
of the domain.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 tools/xenstored/domain.c | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
index 694ae58973..9bd3ac7aca 100644
--- a/tools/xenstored/domain.c
+++ b/tools/xenstored/domain.c
@@ -140,10 +140,8 @@ struct domain
        bool introduced;
 
        /* Accounting data for this domain. */
-       struct acc {
-               unsigned int val;
-               unsigned int max;
-       } acc[ACC_N];
+       unsigned int acc_val[ACC_N];
+       struct quota acc[ACC_N];
 
        /* Memory quota data for this domain. */
        bool soft_quota_reported;
@@ -410,7 +408,7 @@ bool domain_check_quota_add(struct domain *d, enum accitem 
what, int add)
        if (add < 0 || !d)
                return false;
 
-       return domain_check_quota_val(d, what, d->acc[what].val + add);
+       return domain_check_quota_val(d, what, d->acc_val[what] + add);
 }
 
 static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod)
@@ -582,7 +580,7 @@ static int domain_tree_remove_sub(const void *ctx, struct 
connection *conn,
                ret = WALK_TREE_SKIP_CHILDREN;
        }
 
-       return domain->acc[ACC_NODES].val ? ret : WALK_TREE_SUCCESS_STOP;
+       return domain->acc_val[ACC_NODES] ? ret : WALK_TREE_SUCCESS_STOP;
 }
 
 static void domain_tree_remove(struct domain *domain)
@@ -590,7 +588,7 @@ static void domain_tree_remove(struct domain *domain)
        int ret;
        struct walk_funcs walkfuncs = { .enter = domain_tree_remove_sub };
 
-       if (domain->acc[ACC_NODES].val) {
+       if (domain->acc_val[ACC_NODES]) {
                ret = walk_node_tree(domain, NULL, "/", &walkfuncs, domain);
                if (ret == WALK_TREE_ERROR_STOP)
                        syslog(LOG_ERR,
@@ -774,7 +772,7 @@ int domain_get_quota(const void *ctx, struct connection 
*conn,
                        continue;
                resp = talloc_asprintf_append(resp, "%-17s: %8u (max %8u)\n",
                                              quota_adm[i].name,
-                                             d->acc[i].val, d->acc[i].max);
+                                             d->acc_val[i], d->acc[i].max);
                if (!resp)
                        return ENOMEM;
        }
@@ -1637,10 +1635,10 @@ static int domain_acc_add_valid(struct domain *d, enum 
accitem what, int add)
 {
        unsigned int val;
 
-       assert(what < ARRAY_SIZE(d->acc));
+       assert(what < ARRAY_SIZE(d->acc_val));
 
-       if ((add < 0 && -add > d->acc[what].val) ||
-           (add > 0 && (INT_MAX - d->acc[what].val) < add)) {
+       if ((add < 0 && -add > d->acc_val[what]) ||
+           (add > 0 && (INT_MAX - d->acc_val[what]) < add)) {
                /*
                 * In a transaction when a node is being added/removed AND the
                 * same node has been added/removed outside the transaction in
@@ -1651,7 +1649,7 @@ static int domain_acc_add_valid(struct domain *d, enum 
accitem what, int add)
                return (add < 0) ? 0 : INT_MAX;
        }
 
-       val = d->acc[what].val + add;
+       val = d->acc_val[what] + add;
        domain_acc_valid_max(d, what, val);
 
        return val;
@@ -1710,10 +1708,10 @@ static int domain_acc_add(struct connection *conn, 
unsigned int domid,
        }
 
        trace_acc("global change domid %u: what=%u %u add %d\n", domid, what,
-                 d->acc[what].val, add);
-       d->acc[what].val = domain_acc_add_valid(d, what, add);
+                 d->acc_val[what], add);
+       d->acc_val[what] = domain_acc_add_valid(d, what, add);
 
-       return d->acc[what].val;
+       return d->acc_val[what];
 }
 
 void acc_drop(struct connection *conn)
@@ -1757,7 +1755,7 @@ static int domain_reset_global_acc_sub(const void *k, 
void *v, void *arg)
        unsigned int i;
 
        for (i = 0; i < ACC_N; i++)
-               d->acc[i].max = d->acc[i].val;
+               d->acc[i].max = d->acc_val[i];
 
        return 0;
 }
@@ -2193,7 +2191,7 @@ static int domain_check_acc_init_sub(const void *k, void 
*v, void *arg)
         * If everything is correct incrementing the value for each node will
         * result in dom->nodes being 0 at the end.
         */
-       dom->nodes = -d->acc[ACC_NODES].val;
+       dom->nodes = -d->acc_val[ACC_NODES];
 
        if (hashtable_add(domains, &dom->domid, dom)) {
                talloc_free(dom);
@@ -2248,7 +2246,7 @@ static int domain_check_acc_cb(const void *k, void *v, 
void *arg)
        if (!d)
                return 0;
 
-       d->acc[ACC_NODES].val += dom->nodes;
+       d->acc_val[ACC_NODES] += dom->nodes;
 
        return 0;
 }
-- 
2.53.0




 


Rackspace

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