]> rtime.felk.cvut.cz Git - jailhouse.git/blobdiff - tools/jailhouse.c
tools: Add hardware feature check
[jailhouse.git] / tools / jailhouse.c
index 6a3689273bf4806074d202df3704fb992e8c7fe5..ba2af66a666338b4b96da88cee58dc597ebe5062 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013
+ * Copyright (c) Siemens AG, 2013-2016
  *
  * Authors:
  *  Jan Kiszka <jan.kiszka@siemens.com>
@@ -40,8 +40,10 @@ static const struct extension extensions[] = {
        { "cell", "list", "" },
        { "cell", "stats", "{ ID | [--name] NAME }" },
        { "config", "create", "[-h] [-g] [-r ROOT] "
-         "[--mem-inmates MEM_INMATES] [--mem-hv MEM_HV] FILE" },
+         "[--mem-inmates MEM_INMATES]\n"
+         "                 [--mem-hv MEM_HV] FILE" },
        { "config", "collect", "FILE.TAR" },
+       { "hardware", "check", "SYSCONFIG" },
        { NULL }
 };
 
@@ -54,8 +56,9 @@ static void __attribute__((noreturn)) help(char *prog, int exit_status)
               "   enable SYSCONFIG\n"
               "   disable\n"
               "   cell create CELLCONFIG\n"
-              "   cell load { ID | [--name] NAME } IMAGE "
-                       "[ -a | --address ADDRESS] ...\n"
+              "   cell load { ID | [--name] NAME } "
+                               "{ IMAGE | { -s | --string } \"STRING\" }\n"
+              "             [-a | --address ADDRESS] ...\n"
               "   cell start { ID | [--name] NAME }\n"
               "   cell shutdown { ID | [--name] NAME }\n"
               "   cell destroy { ID | [--name] NAME }\n",
@@ -106,6 +109,21 @@ static int open_dev()
        return fd;
 }
 
+static void *read_string(const char *string, size_t *size)
+{
+       void *buffer;
+
+       *size = strlen(string) + 1;
+
+       buffer = strdup(string);
+       if (!buffer) {
+               fprintf(stderr, "insufficient memory\n");
+               exit(1);
+       }
+
+       return buffer;
+}
+
 static void *read_file(const char *name, size_t *size)
 {
        struct stat stat;
@@ -233,12 +251,12 @@ static bool match_opt(const char *argv, const char *short_opt,
 static int cell_shutdown_load(int argc, char *argv[],
                              enum shutdown_load_mode mode)
 {
-       unsigned int images, id_args, arg_num, n;
        struct jailhouse_preload_image *image;
        struct jailhouse_cell_load *cell_load;
        struct jailhouse_cell_id cell_id;
+       int err, fd, id_args, arg_num;
+       unsigned int images, n;
        size_t size;
-       int err, fd;
        char *endp;
 
        id_args = parse_cell_id(&cell_id, argc - 3, &argv[3]);
@@ -249,6 +267,12 @@ static int cell_shutdown_load(int argc, char *argv[],
 
        images = 0;
        while (arg_num < argc) {
+               if (match_opt(argv[arg_num], "-s", "--string")) {
+                       if (arg_num + 1 >= argc)
+                               help(argv[0], 1);
+                       arg_num++;
+               }
+
                images++;
                arg_num++;
 
@@ -271,8 +295,16 @@ static int cell_shutdown_load(int argc, char *argv[],
        arg_num = 3 + id_args;
 
        for (n = 0, image = cell_load->image; n < images; n++, image++) {
-               image->source_address =
-                       (unsigned long)read_file(argv[arg_num++], &size);
+               if (match_opt(argv[arg_num], "-s", "--string")) {
+                       arg_num++;
+                       image->source_address =
+                               (unsigned long)read_string(argv[arg_num++],
+                                                          &size);
+               } else {
+                       image->source_address =
+                               (unsigned long)read_file(argv[arg_num++],
+                                                        &size);
+               }
                image->size = size;
                image->target_address = 0;
 
@@ -368,7 +400,8 @@ int main(int argc, char *argv[])
                close(fd);
        } else if (strcmp(argv[1], "cell") == 0) {
                err = cell_management(argc, argv);
-       } else if (strcmp(argv[1], "config") == 0) {
+       } else if (strcmp(argv[1], "config") == 0 ||
+                  strcmp(argv[1], "hardware") == 0) {
                call_extension_script(argv[1], argc, argv);
                help(argv[0], 1);
        } else if (strcmp(argv[1], "--version") == 0) {