]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
driver/tools: Switch to ID/name-based cell addressing
authorJan Kiszka <jan.kiszka@siemens.com>
Sat, 3 May 2014 06:13:38 +0000 (08:13 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Sat, 3 May 2014 12:56:57 +0000 (14:56 +0200)
No longer request to cell config file for destroying a cell. Rather
use its name or its hypervisor-assigned ID. Numerical parameters are
assumed to be IDs unless --name is prepended.

This pattern will be used in all upcoming cell management commands.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
driver.c
jailhouse.h
tools/jailhouse.c

index 77b9d903dbd2efef3cbb407f59f588060bf7dbdd..1244c7e6dc681e911d76a2ea66e4834073772aad 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -215,12 +215,14 @@ static void register_cell(struct cell *cell)
        kobject_uevent(&cell->kobj, KOBJ_ADD);
 }
 
-static struct cell *find_cell(struct jailhouse_cell_desc *cell_desc)
+static struct cell *find_cell(struct jailhouse_cell_id *cell_id)
 {
        struct cell *cell;
 
        list_for_each_entry(cell, &cells, entry)
-               if (strcmp(kobject_name(&cell->kobj), cell_desc->name) == 0)
+               if (cell_id->id == cell->id ||
+                   (cell_id->id == JAILHOUSE_CELL_ID_UNUSED &&
+                    strcmp(kobject_name(&cell->kobj), cell_id->name) == 0))
                        return cell;
        return NULL;
 }
@@ -511,6 +513,7 @@ static int jailhouse_cell_create(struct jailhouse_new_cell __user *arg)
        struct jailhouse_preload_image __user *image = arg->image;
        struct jailhouse_new_cell cell_params;
        struct jailhouse_cell_desc *config;
+       struct jailhouse_cell_id cell_id;
        unsigned int cpu, n;
        struct cell *cell;
        int id, err;
@@ -540,7 +543,9 @@ static int jailhouse_cell_create(struct jailhouse_new_cell __user *arg)
                goto unlock_out;
        }
 
-       if (find_cell(config) != NULL) {
+       cell_id.id = JAILHOUSE_CELL_ID_UNUSED;
+       memcpy(cell_id.name, config->name, sizeof(cell_id.name));
+       if (find_cell(&cell_id) != NULL) {
                err = -EEXIST;
                goto unlock_out;
        }
@@ -605,38 +610,25 @@ error_cell_put:
 
 static int jailhouse_cell_destroy(const char __user *arg)
 {
-       struct jailhouse_cell_desc *config;
-       struct jailhouse_cell cell_params;
+       struct jailhouse_cell_id cell_id;
        struct cell *cell;
        unsigned int cpu;
        int err;
 
-       if (copy_from_user(&cell_params, arg, sizeof(cell_params)))
+       if (copy_from_user(&cell_id, arg, sizeof(cell_id)))
                return -EFAULT;
 
-       config = kmalloc(cell_params.config_size, GFP_KERNEL | GFP_DMA);
-       if (!config)
-               return -ENOMEM;
-
-       if (copy_from_user(config,
-                          (void *)(unsigned long)cell_params.config_address,
-                          cell_params.config_size)) {
-               err = -EFAULT;
-               goto kfree_config_out;
-       }
-       config->name[JAILHOUSE_CELL_NAME_MAXLEN] = 0;
+       cell_id.name[JAILHOUSE_CELL_NAME_MAXLEN] = 0;
 
-       if (mutex_lock_interruptible(&lock) != 0) {
-               err = -EINTR;
-               goto kfree_config_out;
-       }
+       if (mutex_lock_interruptible(&lock) != 0)
+               return -EINTR;
 
        if (!enabled) {
                err = -EINVAL;
                goto unlock_out;
        }
 
-       cell = find_cell(config);
+       cell = find_cell(&cell_id);
        if (!cell) {
                err = -ENOENT;
                goto unlock_out;
@@ -656,16 +648,14 @@ static int jailhouse_cell_destroy(const char __user *arg)
                cpu_set(cpu, root_cell->cpus_assigned);
        }
 
-       delete_cell(cell);
+       pr_info("Destroyed Jailhouse cell \"%s\"\n",
+               kobject_name(&cell->kobj));
 
-       pr_info("Destroyed Jailhouse cell \"%s\"\n", config->name);
+       delete_cell(cell);
 
 unlock_out:
        mutex_unlock(&lock);
 
-kfree_config_out:
-       kfree(config);
-
        return err;
 }
 
index dc6e550e04da41392aec7830005c6409fa6de50a..6975431ba93ecf5d9d6e54b827715f36192bc1f3 100644 (file)
@@ -28,12 +28,15 @@ struct jailhouse_new_cell {
        struct jailhouse_preload_image image[];
 };
 
-struct jailhouse_cell {
-       __u64 config_address;
-       __u32 config_size;
+struct jailhouse_cell_id {
+       __s32 id;
+       __u32 padding;
+       char name[JAILHOUSE_CELL_NAME_MAXLEN+1];
 };
 
+#define JAILHOUSE_CELL_ID_UNUSED       (-1)
+
 #define JAILHOUSE_ENABLE               _IOW(0, 0, struct jailhouse_system)
 #define JAILHOUSE_DISABLE              _IO(0, 1)
 #define JAILHOUSE_CELL_CREATE          _IOW(0, 2, struct jailhouse_new_cell)
-#define JAILHOUSE_CELL_DESTROY         _IOW(0, 3, struct jailhouse_cell)
+#define JAILHOUSE_CELL_DESTROY         _IOW(0, 3, struct jailhouse_cell_id)
index daa75f1ef3bb37eff0c003d1a86e94d5185f1cc6..c290e2fdb70932bb5f2c4c3b607115230b3e53e9 100644 (file)
@@ -10,6 +10,7 @@
  * the COPYING file in the top-level directory.
  */
 
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,7 +32,7 @@ help(const char *progname, int exit_status)
               "   disable\n"
               "   cell create CONFIGFILE IMAGE [-l ADDRESS] "
                        "[IMAGE [-l ADDRESS] ...]\n"
-              "   cell destroy CONFIGFILE\n",
+              "   cell destroy { ID | [--name] NAME }\n",
               progname);
        exit(exit_status);
 }
@@ -106,6 +107,37 @@ static int enable(int argc, char *argv[])
        return err;
 }
 
+static int parse_cell_id(struct jailhouse_cell_id *cell_id, int argc,
+                        char *argv[])
+{
+       bool use_name = false;
+       int arg_pos = 0;
+       char *endp;
+
+       if (argc < 1)
+               return 0;
+
+       if (strcmp(argv[0], "--name") == 0) {
+               if (argc < 2)
+                       return 0;
+               arg_pos++;
+               use_name = true;
+       } else {
+               errno = 0;
+               cell_id->id = strtoll(argv[0], &endp, 0);
+               if (errno != 0 || *endp != 0 || cell_id->id < 0)
+                       use_name = true;
+       }
+
+       if (use_name) {
+               cell_id->id = JAILHOUSE_CELL_ID_UNUSED;
+               strncpy(cell_id->name, argv[arg_pos], sizeof(cell_id->name));
+               cell_id->name[sizeof(cell_id->name) - 1] = 0;
+       }
+
+       return arg_pos + 1;
+}
+
 static int cell_create(int argc, char *argv[])
 {
        struct jailhouse_preload_image *image;
@@ -177,24 +209,20 @@ static int cell_create(int argc, char *argv[])
 
 static int cell_destroy(int argc, char *argv[])
 {
-       struct jailhouse_cell cell;
-       size_t size;
-       int err, fd;
+       struct jailhouse_cell_id cell_id;
+       int id_args, err, fd;
 
-       if (argc != 4)
+       id_args = parse_cell_id(&cell_id, argc - 3, &argv[3]);
+       if (id_args == 0 || 3 + id_args != argc)
                help(argv[0], 1);
 
-       cell.config_address = (unsigned long)read_file(argv[3], &size);
-       cell.config_size = size;
-
        fd = open_dev();
 
-       err = ioctl(fd, JAILHOUSE_CELL_DESTROY, &cell);
+       err = ioctl(fd, JAILHOUSE_CELL_DESTROY, &cell_id);
        if (err)
                perror("JAILHOUSE_CELL_DESTROY");
 
        close(fd);
-       free((void *)(unsigned long)cell.config_address);
 
        return err;
 }