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

[xen staging] tools/xenstore: add helpers to free struct buffered_data



commit ead062a68a9c201a95488e84750a70a107f7b317
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Tue Sep 13 07:35:07 2022 +0200
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Tue Nov 1 13:05:44 2022 +0000

    tools/xenstore: add helpers to free struct buffered_data
    
    Add two helpers for freeing struct buffered_data: free_buffered_data()
    for freeing one instance and conn_free_buffered_data() for freeing all
    instances for a connection.
    
    This is avoiding duplicated code and will help later when more actions
    are needed when freeing a struct buffered_data.
    
    This is part of XSA-326.
    
    Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
    Reviewed-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 tools/xenstore/xenstored_core.c   | 18 ++++++++++++++++--
 tools/xenstore/xenstored_core.h   |  2 ++
 tools/xenstore/xenstored_domain.c | 15 ++-------------
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index ed742d9dfc..61fc368e8c 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -207,6 +207,21 @@ void reopen_log(void)
        }
 }
 
+static void free_buffered_data(struct buffered_data *out,
+                              struct connection *conn)
+{
+       list_del(&out->list);
+       talloc_free(out);
+}
+
+void conn_free_buffered_data(struct connection *conn)
+{
+       struct buffered_data *out;
+
+       while ((out = list_top(&conn->out_list, struct buffered_data, list)))
+               free_buffered_data(out, conn);
+}
+
 static bool write_messages(struct connection *conn)
 {
        int ret;
@@ -250,8 +265,7 @@ static bool write_messages(struct connection *conn)
 
        trace_io(conn, out, 1);
 
-       list_del(&out->list);
-       talloc_free(out);
+       free_buffered_data(out, conn);
 
        return true;
 }
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index 99a0373944..c9ea796185 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -271,6 +271,8 @@ int remember_string(struct hashtable *hash, const char 
*str);
 
 void set_tdb_key(const char *name, TDB_DATA *key);
 
+void conn_free_buffered_data(struct connection *conn);
+
 const char *dump_state_global(FILE *fp);
 const char *dump_state_buffered_data(FILE *fp, const struct connection *c,
                                     struct xs_state_connection *sc);
diff --git a/tools/xenstore/xenstored_domain.c 
b/tools/xenstore/xenstored_domain.c
index ead4c237d2..de349e2a77 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -411,15 +411,10 @@ static struct domain *find_domain_by_domid(unsigned int 
domid)
 static void domain_conn_reset(struct domain *domain)
 {
        struct connection *conn = domain->conn;
-       struct buffered_data *out;
 
        conn_delete_all_watches(conn);
        conn_delete_all_transactions(conn);
-
-       while ((out = list_top(&conn->out_list, struct buffered_data, list))) {
-               list_del(&out->list);
-               talloc_free(out);
-       }
+       conn_free_buffered_data(conn);
 
        talloc_free(conn->in);
 
@@ -436,8 +431,6 @@ static void domain_conn_reset(struct domain *domain)
  */
 void ignore_connection(struct connection *conn, unsigned int err)
 {
-       struct buffered_data *out, *tmp;
-
        trace("CONN %p ignored, reason %u\n", conn, err);
 
        if (conn->domain && conn->domain->interface)
@@ -446,11 +439,7 @@ void ignore_connection(struct connection *conn, unsigned 
int err)
        conn->is_ignored = true;
        conn_delete_all_watches(conn);
        conn_delete_all_transactions(conn);
-
-       list_for_each_entry_safe(out, tmp, &conn->out_list, list) {
-               list_del(&out->list);
-               talloc_free(out);
-       }
+       conn_free_buffered_data(conn);
 
        talloc_free(conn->in);
        conn->in = NULL;
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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