]> xenbits.xensource.com Git - xen.git/commitdiff
tools/xenstore: introduce live update status block
authorJuergen Gross <jgross@suse.com>
Wed, 13 Jan 2021 13:00:17 +0000 (14:00 +0100)
committerJuergen Gross <jgross@suse.com>
Thu, 21 Jan 2021 16:30:52 +0000 (17:30 +0100)
Live update of Xenstore is done in multiple steps. It needs a status
block holding the current state of live update and related data. It
is allocated as child of the connection live update was started over
in order to abort live update in case the connection is closed.

Allocation of the block is done in lu_binary[_alloc](), freeing in
lu_abort() (and for now in lu_start() as long as no real live-update
is happening).

Add tests in all live-update command handlers other than lu_abort()
and lu_binary[_alloc]() for being started via the same connection
as the begin of live-update.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Paul Durrant <paul@xen.org>
Reviewed-by: Julien Grall <jgrall@amazon.com>
Acked-by: Wei Liu <wl@xen.org>
tools/xenstore/xenstored_control.c

index e3f0d345281e15946dd6d9882fff028c6e3ba346..7854b7f46fea6a1d521c6f124709a6ebae0d1617 100644 (file)
 #include "xenstored_core.h"
 #include "xenstored_control.h"
 
+struct live_update {
+       /* For verification the correct connection is acting. */
+       struct connection *conn;
+};
+
+static struct live_update *lu_status;
+
+static int lu_destroy(void *data)
+{
+       lu_status = NULL;
+
+       return 0;
+}
+
+static const char *lu_begin(struct connection *conn)
+{
+       if (lu_status)
+               return "live-update session already active.";
+
+       lu_status = talloc_zero(conn, struct live_update);
+       if (!lu_status)
+               return "Allocation failure.";
+       lu_status->conn = conn;
+       talloc_set_destructor(lu_status, lu_destroy);
+
+       return NULL;
+}
+
 struct cmd_s {
        char *cmd;
        int (*func)(void *, struct connection *, char **, int);
@@ -154,6 +182,13 @@ static int do_control_print(void *ctx, struct connection *conn,
 static const char *lu_abort(const void *ctx, struct connection *conn)
 {
        syslog(LOG_INFO, "live-update: abort\n");
+
+       if (!lu_status)
+               return "No live-update session active.";
+
+       /* Destructor will do the real abort handling. */
+       talloc_free(lu_status);
+
        return NULL;
 }
 
@@ -161,6 +196,10 @@ static const char *lu_cmdline(const void *ctx, struct connection *conn,
                              const char *cmdline)
 {
        syslog(LOG_INFO, "live-update: cmdline %s\n", cmdline);
+
+       if (!lu_status || lu_status->conn != conn)
+               return "Not in live-update session.";
+
        return NULL;
 }
 
@@ -168,13 +207,23 @@ static const char *lu_cmdline(const void *ctx, struct connection *conn,
 static const char *lu_binary_alloc(const void *ctx, struct connection *conn,
                                   unsigned long size)
 {
+       const char *ret;
+
        syslog(LOG_INFO, "live-update: binary size %lu\n", size);
+
+       ret = lu_begin(conn);
+       if (ret)
+               return ret;
+
        return NULL;
 }
 
 static const char *lu_binary_save(const void *ctx, struct connection *conn,
                                  unsigned int size, const char *data)
 {
+       if (!lu_status || lu_status->conn != conn)
+               return "Not in live-update session.";
+
        return NULL;
 }
 
@@ -193,7 +242,14 @@ static const char *lu_arch(const void *ctx, struct connection *conn,
 static const char *lu_binary(const void *ctx, struct connection *conn,
                             const char *filename)
 {
+       const char *ret;
+
        syslog(LOG_INFO, "live-update: binary %s\n", filename);
+
+       ret = lu_begin(conn);
+       if (ret)
+               return ret;
+
        return NULL;
 }
 
@@ -212,6 +268,13 @@ static const char *lu_start(const void *ctx, struct connection *conn,
                            bool force, unsigned int to)
 {
        syslog(LOG_INFO, "live-update: start, force=%d, to=%u\n", force, to);
+
+       if (!lu_status || lu_status->conn != conn)
+               return "Not in live-update session.";
+
+       /* Will be replaced by real live-update later. */
+       talloc_free(lu_status);
+
        return NULL;
 }