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

[PATCH v3 06/13] tools/xenstore: add current connection to domain_memory_add() parameters



In order to enable switching memory accounting to the generic array
based accounting, add the current connection to the parameters of
domain_memory_add().

This requires to add the connection to some other functions, too.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 tools/xenstore/xenstored_core.c   | 28 ++++++++++++++++------------
 tools/xenstore/xenstored_domain.c |  3 ++-
 tools/xenstore/xenstored_domain.h | 14 +++++++++-----
 tools/xenstore/xenstored_watch.c  | 11 ++++++-----
 4 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 92a40ccf3f..88ae674523 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -246,7 +246,8 @@ static void free_buffered_data(struct buffered_data *out,
                }
        }
 
-       domain_memory_add_nochk(conn->id, -out->hdr.msg.len - sizeof(out->hdr));
+       domain_memory_add_nochk(conn, conn->id,
+                               -out->hdr.msg.len - sizeof(out->hdr));
 
        if (out->hdr.msg.type == XS_WATCH_EVENT) {
                req = out->pend.req;
@@ -631,24 +632,25 @@ int do_tdb_write(struct connection *conn, TDB_DATA *key, 
TDB_DATA *data,
         * nodes to new owners.
         */
        if (old_acc.memory)
-               domain_memory_add_nochk(old_domid,
+               domain_memory_add_nochk(conn, old_domid,
                                        -old_acc.memory - key->dsize);
-       ret = domain_memory_add(new_domid, data->dsize + key->dsize,
-                               no_quota_check);
+       ret = domain_memory_add(conn, new_domid,
+                               data->dsize + key->dsize, no_quota_check);
        if (ret) {
                /* Error path, so no quota check. */
                if (old_acc.memory)
-                       domain_memory_add_nochk(old_domid,
+                       domain_memory_add_nochk(conn, old_domid,
                                                old_acc.memory + key->dsize);
                return ret;
        }
 
        /* TDB should set errno, but doesn't even set ecode AFAICT. */
        if (tdb_store(tdb_ctx, *key, *data, TDB_REPLACE) != 0) {
-               domain_memory_add_nochk(new_domid, -data->dsize - key->dsize);
+               domain_memory_add_nochk(conn, new_domid,
+                                       -data->dsize - key->dsize);
                /* Error path, so no quota check. */
                if (old_acc.memory)
-                       domain_memory_add_nochk(old_domid,
+                       domain_memory_add_nochk(conn, old_domid,
                                                old_acc.memory + key->dsize);
                errno = EIO;
                return errno;
@@ -683,7 +685,7 @@ int do_tdb_delete(struct connection *conn, TDB_DATA *key,
 
        if (acc->memory) {
                domid = get_acc_domid(conn, key, acc->domid);
-               domain_memory_add_nochk(domid, -acc->memory - key->dsize);
+               domain_memory_add_nochk(conn, domid, -acc->memory - key->dsize);
        }
 
        return 0;
@@ -1055,11 +1057,13 @@ void send_reply(struct connection *conn, enum 
xsd_sockmsg_type type,
        if (len <= DEFAULT_BUFFER_SIZE) {
                bdata->buffer = bdata->default_buffer;
                /* Don't check quota, path might be used for returning error. */
-               domain_memory_add_nochk(conn->id, len + sizeof(bdata->hdr));
+               domain_memory_add_nochk(conn, conn->id,
+                                       len + sizeof(bdata->hdr));
        } else {
                bdata->buffer = talloc_array(bdata, char, len);
                if (!bdata->buffer ||
-                   domain_memory_add_chk(conn->id, len + sizeof(bdata->hdr))) {
+                   domain_memory_add_chk(conn, conn->id,
+                                         len + sizeof(bdata->hdr))) {
                        send_error(conn, ENOMEM);
                        return;
                }
@@ -1122,7 +1126,7 @@ void send_event(struct buffered_data *req, struct 
connection *conn,
                }
        }
 
-       if (domain_memory_add_chk(conn->id, len + sizeof(bdata->hdr))) {
+       if (domain_memory_add_chk(conn, conn->id, len + sizeof(bdata->hdr))) {
                talloc_free(bdata);
                return;
        }
@@ -3322,7 +3326,7 @@ static void add_buffered_data(struct buffered_data *bdata,
         * be smaller. So ignore it. The limit will be applied for any resource
         * after the state has been fully restored.
         */
-       domain_memory_add_nochk(conn->id, len + sizeof(bdata->hdr));
+       domain_memory_add_nochk(conn, conn->id, len + sizeof(bdata->hdr));
 }
 
 void read_state_buffered_data(const void *ctx, struct connection *conn,
diff --git a/tools/xenstore/xenstored_domain.c 
b/tools/xenstore/xenstored_domain.c
index 6c4b8d9b32..aab23a2506 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -1235,7 +1235,8 @@ static bool domain_chk_quota(struct domain *domain, int 
mem)
        return false;
 }
 
-int domain_memory_add(unsigned int domid, int mem, bool no_quota_check)
+int domain_memory_add(struct connection *conn, unsigned int domid, int mem,
+                     bool no_quota_check)
 {
        struct domain *domain;
 
diff --git a/tools/xenstore/xenstored_domain.h 
b/tools/xenstore/xenstored_domain.h
index e669f57b80..5cfd730cf6 100644
--- a/tools/xenstore/xenstored_domain.h
+++ b/tools/xenstore/xenstored_domain.h
@@ -80,25 +80,29 @@ int domain_nbentry_inc(struct connection *conn, unsigned 
int domid);
 int domain_nbentry_dec(struct connection *conn, unsigned int domid);
 int domain_nbentry_fix(unsigned int domid, int num, bool update);
 unsigned int domain_nbentry(struct connection *conn);
-int domain_memory_add(unsigned int domid, int mem, bool no_quota_check);
+int domain_memory_add(struct connection *conn, unsigned int domid, int mem,
+                     bool no_quota_check);
 
 /*
  * domain_memory_add_chk(): to be used when memory quota should be checked.
  * Not to be used when specifying a negative mem value, as lowering the used
  * memory should always be allowed.
  */
-static inline int domain_memory_add_chk(unsigned int domid, int mem)
+static inline int domain_memory_add_chk(struct connection *conn,
+                                       unsigned int domid, int mem)
 {
-       return domain_memory_add(domid, mem, false);
+       return domain_memory_add(conn, domid, mem, false);
 }
+
 /*
  * domain_memory_add_nochk(): to be used when memory quota should not be
  * checked, e.g. when lowering memory usage, or in an error case for undoing
  * a previous memory adjustment.
  */
-static inline void domain_memory_add_nochk(unsigned int domid, int mem)
+static inline void domain_memory_add_nochk(struct connection *conn,
+                                          unsigned int domid, int mem)
 {
-       domain_memory_add(domid, mem, true);
+       domain_memory_add(conn, domid, mem, true);
 }
 void domain_watch_inc(struct connection *conn);
 void domain_watch_dec(struct connection *conn);
diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_watch.c
index 8ad0229df6..e30cd89be3 100644
--- a/tools/xenstore/xenstored_watch.c
+++ b/tools/xenstore/xenstored_watch.c
@@ -199,7 +199,7 @@ static struct watch *add_watch(struct connection *conn, 
char *path, char *token,
        watch->token = talloc_strdup(watch, token);
        if (!watch->node || !watch->token)
                goto nomem;
-       if (domain_memory_add(conn->id, strlen(path) + strlen(token),
+       if (domain_memory_add(conn, conn->id, strlen(path) + strlen(token),
                              no_quota_check))
                goto nomem;
 
@@ -274,8 +274,9 @@ int do_unwatch(const void *ctx, struct connection *conn,
        list_for_each_entry(watch, &conn->watches, list) {
                if (streq(watch->node, node) && streq(watch->token, vec[1])) {
                        list_del(&watch->list);
-                       domain_memory_add_nochk(conn->id, -strlen(watch->node) -
-                                                         strlen(watch->token));
+                       domain_memory_add_nochk(conn, conn->id,
+                                               -strlen(watch->node) -
+                                               strlen(watch->token));
                        talloc_free(watch);
                        domain_watch_dec(conn);
                        send_ack(conn, XS_UNWATCH);
@@ -291,8 +292,8 @@ void conn_delete_all_watches(struct connection *conn)
 
        while ((watch = list_top(&conn->watches, struct watch, list))) {
                list_del(&watch->list);
-               domain_memory_add_nochk(conn->id, -strlen(watch->node) -
-                                                 strlen(watch->token));
+               domain_memory_add_nochk(conn, conn->id, -strlen(watch->node) -
+                                                       strlen(watch->token));
                talloc_free(watch);
                domain_watch_dec(conn);
        }
-- 
2.35.3




 


Rackspace

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