tools/xenstore: activate new binary for live update
authorJuergen Gross <jgross@suse.com>
Wed, 13 Jan 2021 13:00:21 +0000 (14:00 +0100)
committerJuergen Gross <jgross@suse.com>
Thu, 21 Jan 2021 16:31:55 +0000 (17:31 +0100)
Add activation of the new binary for live update. The daemon case is
handled completely, while for stubdom we only add stubs.

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

index 3c212cc4d4baf64d94846438fda1e151b9da69e2..1f733e0a04a60789f49c2b2b4b172ddaee129b2f 100644 (file)
@@ -16,6 +16,7 @@ Interactive commands for Xen Store Daemon.
     along with this program; If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <ctype.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -335,6 +336,11 @@ static void lu_get_dump_state(struct lu_dump_state *state)
 static void lu_close_dump_state(struct lu_dump_state *state)
 {
 }
+
+static char *lu_exec(const void *ctx, int argc, char **argv)
+{
+       return "NYI";
+}
 #else
 static const char *lu_binary(const void *ctx, struct connection *conn,
                             const char *filename)
@@ -434,6 +440,14 @@ static void lu_close_dump_state(struct lu_dump_state *state)
        unlink(filename);
        talloc_free(filename);
 }
+
+static char *lu_exec(const void *ctx, int argc, char **argv)
+{
+       argv[0] = lu_status->filename;
+       execvp(argv[0], argv);
+
+       return "Error activating new binary.";
+}
 #endif
 
 static bool lu_check_lu_allowed(void)
@@ -572,7 +586,52 @@ void lu_read_state(void)
 
 static const char *lu_activate_binary(const void *ctx)
 {
-       return "Not yet implemented.";
+       int argc;
+       char **argv;
+       unsigned int i;
+
+       if (lu_status->cmdline) {
+               argc = 4;   /* At least one arg + progname + "-U" + NULL. */
+               for (i = 0; lu_status->cmdline[i]; i++)
+                       if (isspace(lu_status->cmdline[i]))
+                               argc++;
+               argv = talloc_array(ctx, char *, argc);
+               if (!argv)
+                       return "Allocation failure.";
+
+               i = 0;
+               argc = 1;
+               argv[1] = strtok(lu_status->cmdline, " \t");
+               while (argv[argc]) {
+                       if (!strcmp(argv[argc], "-U"))
+                               i = 1;
+                       argc++;
+                       argv[argc] = strtok(NULL, " \t");
+               }
+
+               if (!i) {
+                       argv[argc++] = "-U";
+                       argv[argc] = NULL;
+               }
+       } else {
+               for (i = 0; i < orig_argc; i++)
+                       if (!strcmp(orig_argv[i], "-U"))
+                               break;
+
+               argc = orig_argc;
+               argv = talloc_array(ctx, char *, orig_argc + 2);
+               if (!argv)
+                       return "Allocation failure.";
+
+               memcpy(argv, orig_argv, orig_argc * sizeof(*argv));
+               if (i == orig_argc)
+                       argv[argc++] = "-U";
+               argv[argc] = NULL;
+       }
+
+       domain_deinit();
+
+       return lu_exec(ctx, argc, argv);
 }
 
 static bool do_lu_start(struct delayed_request *req)
index a5c1a56c6c02e92a690d187ef5b0765f2a655245..65ecdd05685c99a479996373c4cd00e2f26e1016 100644 (file)
@@ -73,6 +73,9 @@ static unsigned int delayed_requests;
 
 static int sock = -1;
 
+int orig_argc;
+char **orig_argv;
+
 static bool verbose = false;
 LIST_HEAD(connections);
 int tracefd = -1;
@@ -2077,6 +2080,8 @@ int main(int argc, char *argv[])
        const char *pidfile = NULL;
        int timeout;
 
+       orig_argc = argc;
+       orig_argv = argv;
 
        while ((opt = getopt_long(argc, argv, "DE:F:HNPS:t:A:M:T:RVW:U", options,
                                  NULL)) != -1) {
index 6ac5a6fbfadbef82d74e42ad8fdeeff1ea2524a6..589699e8336555a7113048f41b9a3cfa472cfe81 100644 (file)
@@ -222,6 +222,9 @@ void dtrace_io(const struct connection *conn, const struct buffered_data *data,
 void reopen_log(void);
 void close_log(void);
 
+extern int orig_argc;
+extern char **orig_argv;
+
 extern char *tracefile;
 extern int tracefd;
 
index cbeb2a309c8f663fe6c4043f4752d89bbe42366d..3d4d0649a2435808902f901806901e42912b1f2e 100644 (file)
@@ -783,6 +783,12 @@ void domain_init(int evtfd)
        virq_port = rc;
 }
 
+void domain_deinit(void)
+{
+       if (virq_port)
+               xenevtchn_unbind(xce_handle, virq_port);
+}
+
 void domain_entry_inc(struct connection *conn, struct node *node)
 {
        struct domain *d;
index 1cc1c03ed893f99e50d7fdf93884d4b2c528a6b4..dc975917131738b47b9c34384b014629ab127db5 100644 (file)
@@ -46,6 +46,7 @@ int do_reset_watches(struct connection *conn, struct buffered_data *in);
 
 void domain_init(int evtfd);
 void dom0_init(void);
+void domain_deinit(void);
 
 /* Returns the implicit path of a connection (only domains have this) */
 const char *get_implicit_path(const struct connection *conn);