Skip to content

Commit

Permalink
tools: Add configuration generator
Browse files Browse the repository at this point in the history
Adding a helper script to generate a configuration for the root cell.
The script can also generate another script to collect all the necessary
files on a remote machine.
Both scripts can be accessed through the jailhouse command.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
henning-schild authored and jan-kiszka committed Jul 7, 2014
1 parent f49454b commit 82ee792
Show file tree
Hide file tree
Showing 6 changed files with 578 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,4 +11,5 @@ jailhouse.ko
hypervisor/include/jailhouse/config.h
hypervisor/hypervisor.lds
tools/jailhouse
tools/jailhouse-config-collect
configs/*.cell
28 changes: 27 additions & 1 deletion tools/Makefile
Expand Up @@ -15,8 +15,34 @@ CC = $(CROSS_COMPILE)gcc
CFLAGS = -g -O3 -I.. -I../hypervisor/include \
-Wall -Wmissing-declarations -Wmissing-prototypes

TARGETS := jailhouse

HAS_PYTHON_MAKO := \
$(shell python -c "from mako.template import Template" 2>/dev/null \
&& echo yes)

ifeq ($(strip $(HAS_PYTHON_MAKO)), yes)
TARGETS += jailhouse-config-collect
else
TARGETS += no_python_mako
endif

all: $(TARGETS)

jailhouse: jailhouse.c ../jailhouse.h ../hypervisor/include/jailhouse/cell-config.h
$(CC) $(CFLAGS) -o $@ $<

jailhouse-config-collect: jailhouse-config-create jailhouse-config-collect.tmpl
./$< -g $@
chmod +x $@

.PHONY: clean no_python_mako

clean:
rm -f jailhouse
rm -f $(TARGETS)

no_python_mako:
@echo -ne "WARNING: Could not create the helper script to generate" \
"configurations on remote machines" \
"(\"jailhouse-conf-collect\"). You need Python and the" \
"Mako library for it.\n"
59 changes: 59 additions & 0 deletions tools/jailhouse-config-collect.tmpl
@@ -0,0 +1,59 @@
#!/bin/sh
#
# Jailhouse, a Linux-based partitioning hypervisor
#
# Copyright (c) Siemens AG, 2014
#
# This work is licensed under the terms of the GNU GPL, version 2. See
# the COPYING file in the top-level directory.
#
# This script will collect information needed to generate a Jailhouse
# configuration for hypervisor and root cell (Linux).
#
# Run it like that:
# $ jailhouse-config-collect.sh mytarget.tar
#
# Copying files and directories from /sys and /proc is surprisingly hard
# it would be nice to use just one tool together with the list of files.
# The main problem is that stat does not report the correct file sizes. In
# procfs files seem to have a size of 0 while in sysfs they ofter appear
# bigger than they really are.
# Archivers like tar/cpio etc. can not be used for procfs and sysfs.
# This scripts first gets a temporary copy of all the files we want. After
# copying the files can be archived with tar.

set -e

if test -z "$1"; then
echo "Usage: $0 mytarget.tar" 1>&2
exit 1
fi

filelist="${filelist}"

tmpdir=/tmp/jailhouse-config-collect.$$

rm -rf $tmpdir
mkdir $tmpdir

# copy all the files we need to a temporary directory first
for f in $filelist
do
if [ -f $f ]
then
dstdir=$tmpdir/$(dirname $f)
if [ ! -d $dstdir ]
then
mkdir -p $dstdir
fi
cp -p $f $tmpdir/$f
else
echo "Warning: $f does not exist" 1>&2
fi
done

# now archive it and remove temporary copy
tar -C $tmpdir -cf $1 .
rm -rf $tmpdir

exit 0

0 comments on commit 82ee792

Please sign in to comment.