]> xenbits.xensource.com Git - xen.git/commitdiff
tools/xenstore: allow live update only with no transaction active
authorJuergen Gross <jgross@suse.com>
Wed, 13 Jan 2021 13:00:18 +0000 (14:00 +0100)
committerJuergen Gross <jgross@suse.com>
Thu, 21 Jan 2021 16:31:02 +0000 (17:31 +0100)
In order to simplify live update state dumping only allow live update
to happen when no transaction is active.

A timeout is used to detect guests which have a transaction active for
longer periods of time. In case such a guest is detected when trying
to do a live update it will be reported and the update will fail.

The admin can then either use a longer timeout, or use the force flag
to just ignore the transactions of such a guest, or kill the guest
before retrying.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Wei Liu <wl@xen.org>
tools/xenstore/xenstored_control.c
tools/xenstore/xenstored_core.h
tools/xenstore/xenstored_transaction.c

index d3da6b8111068234450b00f9a73459c412f9b65d..52fbf313673ca40447b51651874bfff13f25ba73 100644 (file)
@@ -312,12 +312,37 @@ static const char *lu_arch(const void *ctx, struct connection *conn,
 
 static bool lu_check_lu_allowed(void)
 {
-       return true;
+       struct connection *conn;
+       time_t now = time(NULL);
+       unsigned int ta_total = 0, ta_long = 0;
+
+       list_for_each_entry(conn, &connections, list) {
+               if (conn->ta_start_time) {
+                       ta_total++;
+                       if (conn->ta_start_time - now >= lu_status->timeout)
+                               ta_long++;
+               }
+       }
+
+       return ta_total ? (lu_status->force && ta_long == ta_total) : true;
 }
 
 static const char *lu_reject_reason(const void *ctx)
 {
-       return "BUSY";
+       char *ret = NULL;
+       struct connection *conn;
+       time_t now = time(NULL);
+
+       list_for_each_entry(conn, &connections, list) {
+               if (conn->ta_start_time - now >= lu_status->timeout) {
+                       ret = talloc_asprintf(ctx, "%s\nDomain %u: %ld s",
+                                             ret ? : "Domains with long running transactions:",
+                                             conn->id,
+                                             conn->ta_start_time - now);
+               }
+       }
+
+       return ret ? (const char *)ret : "Overlapping transactions";
 }
 
 static const char *lu_dump_state(const void *ctx, struct connection *conn)
index d5cdf171600224649140b2c1697e10922e5ca0be..db70f61f0deeeac86735cef4d8f67dbec83edd6f 100644 (file)
@@ -107,6 +107,7 @@ struct connection
        struct list_head transaction_list;
        uint32_t next_transaction_id;
        unsigned int transaction_started;
+       time_t ta_start_time;
 
        /* List of delayed requests. */
        struct list_head delayed;
index 52355f4ed8212361b5c102dab9b6edab1dcca949..cd07fb0f218bd9721b0af3249607df46efe7c7ac 100644 (file)
@@ -473,6 +473,8 @@ int do_transaction_start(struct connection *conn, struct buffered_data *in)
        list_add_tail(&trans->list, &conn->transaction_list);
        talloc_steal(conn, trans);
        talloc_set_destructor(trans, destroy_transaction);
+       if (!conn->transaction_started)
+               conn->ta_start_time = time(NULL);
        conn->transaction_started++;
        wrl_ntransactions++;
 
@@ -511,6 +513,8 @@ int do_transaction_end(struct connection *conn, struct buffered_data *in)
        conn->transaction = NULL;
        list_del(&trans->list);
        conn->transaction_started--;
+       if (!conn->transaction_started)
+               conn->ta_start_time = 0;
 
        /* Attach transaction to in for auto-cleanup */
        talloc_steal(in, trans);
@@ -589,6 +593,7 @@ void conn_delete_all_transactions(struct connection *conn)
        assert(conn->transaction == NULL);
 
        conn->transaction_started = 0;
+       conn->ta_start_time = 0;
 }
 
 int check_transactions(struct hashtable *hash)