]> xenbits.xensource.com Git - xen.git/commitdiff
tools/xenstore: save new binary for live update
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:55 +0000 (17:30 +0100)
Save the new binary name for the daemon case and the new kernel for
stubdom in order to support live update of Xenstore..

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 7854b7f46fea6a1d521c6f124709a6ebae0d1617..95ac1a16482f24212851701aa4b7794fa6ce8ee3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Interactive commands for Xen Store Daemon.
+Interactive commands for Xen Store Daemon.
     Copyright (C) 2017 Juergen Gross, SUSE Linux GmbH
 
     This program is free software; you can redistribute it and/or modify
@@ -22,6 +22,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <syslog.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include "utils.h"
 #include "talloc.h"
 struct live_update {
        /* For verification the correct connection is acting. */
        struct connection *conn;
+
+#ifdef __MINIOS__
+       void *kernel;
+       unsigned int kernel_size;
+       unsigned int kernel_off;
+#else
+       char *filename;
+#endif
 };
 
 static struct live_update *lu_status;
@@ -215,6 +226,13 @@ static const char *lu_binary_alloc(const void *ctx, struct connection *conn,
        if (ret)
                return ret;
 
+       lu_status->kernel = talloc_size(lu_status, size);
+       if (!lu_status->kernel)
+               return "Allocation failure.";
+
+       lu_status->kernel_size = size;
+       lu_status->kernel_off = 0;
+
        return NULL;
 }
 
@@ -224,6 +242,12 @@ static const char *lu_binary_save(const void *ctx, struct connection *conn,
        if (!lu_status || lu_status->conn != conn)
                return "Not in live-update session.";
 
+       if (lu_status->kernel_off + size > lu_status->kernel_size)
+               return "Too much kernel data.";
+
+       memcpy(lu_status->kernel + lu_status->kernel_off, data, size);
+       lu_status->kernel_off += size;
+
        return NULL;
 }
 
@@ -243,13 +267,23 @@ static const char *lu_binary(const void *ctx, struct connection *conn,
                             const char *filename)
 {
        const char *ret;
+       struct stat statbuf;
 
        syslog(LOG_INFO, "live-update: binary %s\n", filename);
 
+       if (stat(filename, &statbuf))
+               return "File not accessible.";
+       if (!(statbuf.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR)))
+               return "File not executable.";
+
        ret = lu_begin(conn);
        if (ret)
                return ret;
 
+       lu_status->filename = talloc_strdup(lu_status, filename);
+       if (!lu_status->filename)
+               return "Allocation failure.";
+
        return NULL;
 }
 
@@ -272,6 +306,11 @@ static const char *lu_start(const void *ctx, struct connection *conn,
        if (!lu_status || lu_status->conn != conn)
                return "Not in live-update session.";
 
+#ifdef __MINIOS__
+       if (lu_status->kernel_size != lu_status->kernel_off)
+               return "Kernel not complete.";
+#endif
+
        /* Will be replaced by real live-update later. */
        talloc_free(lu_status);