Skip to content

Commit

Permalink
F OpenNebula#4089: Improve map_context.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian González committed Mar 5, 2020
1 parent 2fe17a7 commit df34335
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
45 changes: 28 additions & 17 deletions src/vmm_mad/remotes/lib/firecracker/map_context.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,64 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #

function clean () {
# Clean temporary directories
umount "$MAP_PATH/fs"
rm -rf "$MAP_PATH"
}

# exit when any command fails
set -e
set -eE

MAP_PATH=""
SYSDS_PATH=""
CONTEXT_PATH=""
ROOTFS_ID=""
VM_ID=""

while getopts ":m:s:c:r:v:" opt; do
while getopts ":s:c:r:v:" opt; do
case $opt in
m) MAP_PATH="$OPTARG" ;;
s) SYSDS_PATH="$OPTARG" ;;
c) CONTEXT_PATH="$OPTARG" ;;
c) CONTEXT_ID=$OPTARG ;;
r) ROOTFS_ID="$OPTARG" ;;
v) VM_ID="$OPTARG" ;;
esac
done

shift $(($OPTIND - 1))

if [ -z "$MAP_PATH" ] || [ -z "$SYSDS_PATH" ] || [ -z "$CONTEXT_PATH" ] || [ -z "$ROOTFS_ID" ] || [ -z "$VM_ID" ]; then

if [ -z "$SYSDS_PATH" ] || [ -z "$CONTEXT_ID" ] || [ -z "$ROOTFS_ID" ] || [ -z "$VM_ID" ]; then
exit -1
fi

rgx_num="^[0-9]+$"
if ! [[ $CONTEXT_ID =~ $rgx_num ]] || ! [[ $ROOTFS_ID =~ $rgx_num ]] || ! [[ $VM_ID =~ $rgx_num ]]; then
exit -1
fi

VM_LOCATION="$SYSDS_PATH/$VM_ID"

MAP_PATH="$VM_LOCATION/map_context"
CONTEXT_PATH="$VM_LOCATION/disk.$CONTEXT_ID"
ROOTFS_PATH="$VM_LOCATION/disk.$ROOTFS_ID"

trap clean ERR

# Create temporary directories
mkdir "$MAP_PATH"
mkdir "$MAP_PATH/context"
mkdir "$MAP_PATH/fs"

# Mount rootfs
mount "/$SYSDS_PATH/$VM_ID/disk.$ROOTFS_ID" "$MAP_PATH/fs"

# Mount context disk
mount "$CONTEXT_PATH" "$MAP_PATH/context"
mount "$ROOTFS_PATH" "$MAP_PATH/fs"

# Create /context directory inside rootfs
if [ ! -d "$MAP_PATH/fs/context" ]; then
mkdir "$MAP_PATH/fs/context"
fi

# Copy context information
cp $MAP_PATH/context/* "$MAP_PATH/fs/context"
# Move the context disk info into the microVM fs
bsdtar -xf "$CONTEXT_PATH" -C "$MAP_PATH/fs/context"

# Clean temporary directories
umount "$MAP_PATH/fs"
umount "$MAP_PATH/context"
rm -rf "$MAP_PATH"
clean

exit 0
4 changes: 2 additions & 2 deletions src/vmm_mad/remotes/lib/firecracker/microvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def map_context

return 0 unless context['context'] # return if there is no context

context_location = context['context']['source']
context_id = context['context']['disk_id']

params = "-m #{@map_location} -s #{@one.sysds_path} -c #{context_location} -r #{@one.rootfs_id} -v #{@one.vm_id}"
params = " -s #{@one.sysds_path} -c #{context_id} -r #{@one.rootfs_id} -v #{@one.vm_id}"

cmd = "sudo #{@map_context_sh} #{params}"

Expand Down

0 comments on commit df34335

Please sign in to comment.