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

[Xen-changelog] [xen master] xenstore: call each xenstored command function with temporary context



commit 31b08f76b78a7db101d151a0b0b912c4e974022c
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Tue Jul 19 13:30:42 2016 +0200
Commit:     Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Tue Jul 19 12:56:58 2016 +0100

    xenstore: call each xenstored command function with temporary context
    
    In order to be able to avoid leaving temporary memory allocated after
    processing of a command in xenstored call all command functions with
    the temporary "in" context. Each function can then make use of that
    temporary context for allocating temporary memory instead of either
    leaving that memory allocated until the connection is dropped (or
    even until end of xenstored) or freeing the memory itself.
    
    This requires to modify the interfaces of the functions taking only
    one argument from the connection by moving the call of onearg() into
    the single functions. Other than that no functional change.
    
    Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
    Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/xenstore/xenstored_core.c        | 39 +++++++++++++++++++---------------
 tools/xenstore/xenstored_core.h        |  3 +++
 tools/xenstore/xenstored_domain.c      | 14 +++++++-----
 tools/xenstore/xenstored_domain.h      | 10 ++++-----
 tools/xenstore/xenstored_transaction.c |  3 ++-
 tools/xenstore/xenstored_transaction.h |  2 +-
 6 files changed, 42 insertions(+), 29 deletions(-)

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 51fb0b3..accca82 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -723,7 +723,7 @@ bool is_valid_nodename(const char *node)
 /* We expect one arg in the input: return NULL otherwise.
  * The payload must contain exactly one nul, at the end.
  */
-static const char *onearg(struct buffered_data *in)
+const char *onearg(struct buffered_data *in)
 {
        if (!in->used || get_string(in, 0) != in->used)
                return NULL;
@@ -771,9 +771,10 @@ bool check_event_node(const char *node)
        return true;
 }
 
-static void send_directory(struct connection *conn, const char *name)
+static void send_directory(struct connection *conn, struct buffered_data *in)
 {
        struct node *node;
+       const char *name = onearg(in);
 
        name = canonicalize(conn, name);
        node = get_node(conn, name, XS_PERM_READ);
@@ -785,9 +786,10 @@ static void send_directory(struct connection *conn, const 
char *name)
        send_reply(conn, XS_DIRECTORY, node->children, node->childlen);
 }
 
-static void do_read(struct connection *conn, const char *name)
+static void do_read(struct connection *conn, struct buffered_data *in)
 {
        struct node *node;
+       const char *name = onearg(in);
 
        name = canonicalize(conn, name);
        node = get_node(conn, name, XS_PERM_READ);
@@ -953,9 +955,10 @@ static void do_write(struct connection *conn, struct 
buffered_data *in)
        send_ack(conn, XS_WRITE);
 }
 
-static void do_mkdir(struct connection *conn, const char *name)
+static void do_mkdir(struct connection *conn, struct buffered_data *in)
 {
        struct node *node;
+       const char *name = onearg(in);
 
        name = canonicalize(conn, name);
        node = get_node(conn, name, XS_PERM_WRITE);
@@ -1070,9 +1073,10 @@ static void internal_rm(const char *name)
 }
 
 
-static void do_rm(struct connection *conn, const char *name)
+static void do_rm(struct connection *conn, struct buffered_data *in)
 {
        struct node *node;
+       const char *name = onearg(in);
 
        name = canonicalize(conn, name);
        node = get_node(conn, name, XS_PERM_WRITE);
@@ -1104,9 +1108,10 @@ static void do_rm(struct connection *conn, const char 
*name)
 }
 
 
-static void do_get_perms(struct connection *conn, const char *name)
+static void do_get_perms(struct connection *conn, struct buffered_data *in)
 {
        struct node *node;
+       const char *name = onearg(in);
        char *strings;
        unsigned int len;
 
@@ -1220,11 +1225,11 @@ static void process_message(struct connection *conn, 
struct buffered_data *in)
 
        switch (in->hdr.msg.type) {
        case XS_DIRECTORY:
-               send_directory(conn, onearg(in));
+               send_directory(conn, in);
                break;
 
        case XS_READ:
-               do_read(conn, onearg(in));
+               do_read(conn, in);
                break;
 
        case XS_WRITE:
@@ -1232,15 +1237,15 @@ static void process_message(struct connection *conn, 
struct buffered_data *in)
                break;
 
        case XS_MKDIR:
-               do_mkdir(conn, onearg(in));
+               do_mkdir(conn, in);
                break;
 
        case XS_RM:
-               do_rm(conn, onearg(in));
+               do_rm(conn, in);
                break;
 
        case XS_GET_PERMS:
-               do_get_perms(conn, onearg(in));
+               do_get_perms(conn, in);
                break;
 
        case XS_SET_PERMS:
@@ -1264,7 +1269,7 @@ static void process_message(struct connection *conn, 
struct buffered_data *in)
                break;
 
        case XS_TRANSACTION_END:
-               do_transaction_end(conn, onearg(in));
+               do_transaction_end(conn, in);
                break;
 
        case XS_INTRODUCE:
@@ -1272,19 +1277,19 @@ static void process_message(struct connection *conn, 
struct buffered_data *in)
                break;
 
        case XS_IS_DOMAIN_INTRODUCED:
-               do_is_domain_introduced(conn, onearg(in));
+               do_is_domain_introduced(conn, in);
                break;
 
        case XS_RELEASE:
-               do_release(conn, onearg(in));
+               do_release(conn, in);
                break;
 
        case XS_GET_DOMAIN_PATH:
-               do_get_domain_path(conn, onearg(in));
+               do_get_domain_path(conn, in);
                break;
 
        case XS_RESUME:
-               do_resume(conn, onearg(in));
+               do_resume(conn, in);
                break;
 
        case XS_SET_TARGET:
@@ -1292,7 +1297,7 @@ static void process_message(struct connection *conn, 
struct buffered_data *in)
                break;
 
        case XS_RESET_WATCHES:
-               do_reset_watches(conn);
+               do_reset_watches(conn, in);
                break;
 
        default:
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index 3a497f7..5dbf9c8 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -122,6 +122,9 @@ struct node {
        char *children;
 };
 
+/* Return the only argument in the input. */
+const char *onearg(struct buffered_data *in);
+
 /* Break input into vectors, return the number, fill in up to num of them. */
 unsigned int get_strings(struct buffered_data *data,
                         char *vec[], unsigned int num);
diff --git a/tools/xenstore/xenstored_domain.c 
b/tools/xenstore/xenstored_domain.c
index 47b4f03..c66539a 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -453,8 +453,9 @@ void do_set_target(struct connection *conn, struct 
buffered_data *in)
 }
 
 /* domid */
-void do_release(struct connection *conn, const char *domid_str)
+void do_release(struct connection *conn, struct buffered_data *in)
 {
+       const char *domid_str = onearg(in);
        struct domain *domain;
        unsigned int domid;
 
@@ -490,10 +491,11 @@ void do_release(struct connection *conn, const char 
*domid_str)
        send_ack(conn, XS_RELEASE);
 }
 
-void do_resume(struct connection *conn, const char *domid_str)
+void do_resume(struct connection *conn, struct buffered_data *in)
 {
        struct domain *domain;
        unsigned int domid;
+       const char *domid_str = onearg(in);
 
        if (!domid_str) {
                send_error(conn, EINVAL);
@@ -527,9 +529,10 @@ void do_resume(struct connection *conn, const char 
*domid_str)
        send_ack(conn, XS_RESUME);
 }
 
-void do_get_domain_path(struct connection *conn, const char *domid_str)
+void do_get_domain_path(struct connection *conn, struct buffered_data *in)
 {
        char *path;
+       const char *domid_str = onearg(in);
 
        if (!domid_str) {
                send_error(conn, EINVAL);
@@ -543,10 +546,11 @@ void do_get_domain_path(struct connection *conn, const 
char *domid_str)
        talloc_free(path);
 }
 
-void do_is_domain_introduced(struct connection *conn, const char *domid_str)
+void do_is_domain_introduced(struct connection *conn, struct buffered_data *in)
 {
        int result;
        unsigned int domid;
+       const char *domid_str = onearg(in);
 
        if (!domid_str) {
                send_error(conn, EINVAL);
@@ -563,7 +567,7 @@ void do_is_domain_introduced(struct connection *conn, const 
char *domid_str)
 }
 
 /* Allow guest to reset all watches */
-void do_reset_watches(struct connection *conn)
+void do_reset_watches(struct connection *conn, struct buffered_data *in)
 {
        conn_delete_all_watches(conn);
        conn_delete_all_transactions(conn);
diff --git a/tools/xenstore/xenstored_domain.h 
b/tools/xenstore/xenstored_domain.h
index 83488ed..2554423 100644
--- a/tools/xenstore/xenstored_domain.h
+++ b/tools/xenstore/xenstored_domain.h
@@ -25,22 +25,22 @@ void handle_event(void);
 void do_introduce(struct connection *conn, struct buffered_data *in);
 
 /* domid */
-void do_is_domain_introduced(struct connection *conn, const char *domid_str);
+void do_is_domain_introduced(struct connection *conn, struct buffered_data 
*in);
 
 /* domid */
-void do_release(struct connection *conn, const char *domid_str);
+void do_release(struct connection *conn, struct buffered_data *in);
 
 /* domid */
-void do_resume(struct connection *conn, const char *domid_str);
+void do_resume(struct connection *conn, struct buffered_data *in);
 
 /* domid, target */
 void do_set_target(struct connection *conn, struct buffered_data *in);
 
 /* domid */
-void do_get_domain_path(struct connection *conn, const char *domid_str);
+void do_get_domain_path(struct connection *conn, struct buffered_data *in);
 
 /* Allow guest to reset all watches */
-void do_reset_watches(struct connection *conn);
+void do_reset_watches(struct connection *conn, struct buffered_data *in);
 
 void domain_init(void);
 
diff --git a/tools/xenstore/xenstored_transaction.c 
b/tools/xenstore/xenstored_transaction.c
index d0e4739..3cde26e 100644
--- a/tools/xenstore/xenstored_transaction.c
+++ b/tools/xenstore/xenstored_transaction.c
@@ -184,8 +184,9 @@ void do_transaction_start(struct connection *conn, struct 
buffered_data *in)
        send_reply(conn, XS_TRANSACTION_START, id_str, strlen(id_str)+1);
 }
 
-void do_transaction_end(struct connection *conn, const char *arg)
+void do_transaction_end(struct connection *conn, struct buffered_data *in)
 {
+       const char *arg = onearg(in);
        struct changed_node *i;
        struct changed_domain *d;
        struct transaction *trans;
diff --git a/tools/xenstore/xenstored_transaction.h 
b/tools/xenstore/xenstored_transaction.h
index cfeeae1..0c868ee 100644
--- a/tools/xenstore/xenstored_transaction.h
+++ b/tools/xenstore/xenstored_transaction.h
@@ -22,7 +22,7 @@
 struct transaction;
 
 void do_transaction_start(struct connection *conn, struct buffered_data *node);
-void do_transaction_end(struct connection *conn, const char *arg);
+void do_transaction_end(struct connection *conn, struct buffered_data *in);
 
 struct transaction *transaction_lookup(struct connection *conn, uint32_t id);
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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