Skip to content

Commit

Permalink
tools: Add support for loading multiple images during cell creation
Browse files Browse the repository at this point in the history
Augment the power of "jailhouse cell create" by supporting to load
multiple images during cell creation. This allows, e.g., to specify cell
code and data separately.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
jan-kiszka committed Feb 17, 2014
1 parent d85b3c5 commit 95666fd
Showing 1 changed file with 51 additions and 21 deletions.
72 changes: 51 additions & 21 deletions tools/jailhouse.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static void help(const char *progname)
"\nAvailable commands:\n" "\nAvailable commands:\n"
" enable CONFIGFILE\n" " enable CONFIGFILE\n"
" disable\n" " disable\n"
" cell create CONFIGFILE PRELOADIMAGE [-l ADDRESS]\n" " cell create CONFIGFILE IMAGE [-l ADDRESS] "
"[IMAGE [-l ADDRESS] ...]\n"
" cell destroy CONFIGFILE\n", " cell destroy CONFIGFILE\n",
progname); progname);
} }
Expand Down Expand Up @@ -107,47 +108,76 @@ static int enable(int argc, char *argv[])


static int cell_create(int argc, char *argv[]) static int cell_create(int argc, char *argv[])
{ {
struct { struct jailhouse_preload_image *image;
struct jailhouse_new_cell cell; struct jailhouse_new_cell *cell;
struct jailhouse_preload_image image; unsigned int images, arg_num;
} params;
struct jailhouse_new_cell *cell = &params.cell;
struct jailhouse_preload_image *image = params.cell.image;
size_t size; size_t size;
int err, fd; int err, fd;
char *endp; char *endp;


if (argc != 5 && argc != 7) { if (argc < 5) {
help(argv[0]); help(argv[0]);
exit(1); exit(1);
} }


arg_num = 4;
images = 0;
while (arg_num < argc) {
images++;
arg_num++;

if (arg_num < argc && strcmp(argv[arg_num], "-l") == 0) {
if (arg_num + 1 >= argc) {
help(argv[0]);
exit(1);
}
arg_num += 2;
}
}

cell = malloc(sizeof(*cell) + sizeof(*image) * images);
if (!cell) {
fprintf(stderr, "insufficient memory\n");
exit(1);
}

cell->config_address = (unsigned long)read_file(argv[3], &size); cell->config_address = (unsigned long)read_file(argv[3], &size);
cell->config_size = size; cell->config_size = size;
cell->num_preload_images = 1; cell->num_preload_images = images;


image->source_address = (unsigned long)read_file(argv[4], &size); arg_num = 4;
image->size = size; image = cell->image;
image->target_address = 0;

while (images > 0) {
if (argc == 7) { image->source_address =
errno = 0; (unsigned long)read_file(argv[arg_num++], &size);
image->target_address = strtoll(argv[6], &endp, 0); image->size = size;
if (errno != 0 || *endp != 0 || strcmp(argv[5], "-l") != 0) { image->target_address = 0;
help(argv[0]);
exit(1); if (arg_num < argc && strcmp(argv[arg_num], "-l") == 0) {
errno = 0;
image->target_address =
strtoll(argv[arg_num + 1], &endp, 0);
if (errno != 0 || *endp != 0) {
help(argv[0]);
exit(1);
}
arg_num += 2;
} }
image++;
images--;
} }


fd = open_dev(); fd = open_dev();


err = ioctl(fd, JAILHOUSE_CELL_CREATE, &params); err = ioctl(fd, JAILHOUSE_CELL_CREATE, cell);
if (err) if (err)
perror("JAILHOUSE_CELL_CREATE"); perror("JAILHOUSE_CELL_CREATE");


close(fd); close(fd);
free((void *)(unsigned long)cell->config_address); free((void *)(unsigned long)cell->config_address);
free((void *)(unsigned long)image->source_address); free((void *)(unsigned long)image->source_address);
free(cell);


return err; return err;
} }
Expand Down

0 comments on commit 95666fd

Please sign in to comment.