Commit 2701509c authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Support multiple disks

Attach all the instance's disks to the helper VM.
parent 26f902a6
......@@ -795,6 +795,20 @@ detect_image_properties() {
done
}
encode_array() {
local array_name cnt tmp
array_name="$1"
cnt=0
tmp="${array_name}[@]"
for i in "${!tmp}"; do
declare -g ${array_name}_$cnt=$i
: $((cnt++))
done
declare -g ${array_name}_COUNT=$count
}
cleanup() {
# if something fails here, it shouldn't call cleanup again...
trap - EXIT
......
......@@ -67,6 +67,21 @@ else
log_error "$RULES_DEV does not contain \`rules\' file"
fi
# Export SNF_IMAGE_DEV. This is an array and exporting arrays is not supported
# in bash. We need to encode it's values to multiple variables
encode_array SNF_IMAGE_DEV
for ((i = 0; i < SNF_IMAGE_DEV_COUNT; i++)); do
export "SNF_IMAGE_DEV_$i"
done
export SNF_IMAGE_DEV_COUNT
# For backwards compatibility set the value of the SNF_IMAGE_DEV variable to
# the first value of the array
unset SNF_IMAGE_DEV
export SNF_IMAGE_DEV=${SNF_IMAGE_DEV_0}
if [ -f "$rules/unattend.xml" ]; then
export SNF_IMAGE_UNATTEND="$rules/unattend.xml"
fi
......
#!/bin/bash
# Copyright (C) 2011-2014 GRNET S.A.
# Copyright (C) 2011-2015 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -206,11 +206,11 @@ if [ -n "$IMG_PERSONALITY" ]; then
snf_export_PERSONALITY="$IMG_PERSONALITY"
fi
snf_export_DEV=$(get_img_dev)
assign_disk_devices_to snf_export_DEV
create_floppy "$floppy"
launch_helper "$blockdev" "$floppy"
launch_helper "$floppy"
report_info "Image customization finished successfully."
......
# Copyright (C) 2013 GRNET S.A.
# Copyright (C) 2013-2015 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -15,15 +15,23 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
get_img_dev() {
echo /dev/vdb
assign_disk_devices_to() {
local varname
varname="$1"
eval $varname=\(\)
set -- b c d e f g h e j k l m n
for ((i = 0; i < DISK_COUNT; i++)); do
eval $varname+=\(\"/dev/vd$1\"\); shift
done
}
launch_helper() {
local result_file result snapshot rc floppy blockdev
local result_file result snapshot rc floppy i disk_path disks
blockdev="$1"
floppy="$2"
floppy="$1"
result_file=$(mktemp result.XXXXXX)
add_cleanup rm "$result_file"
......@@ -31,12 +39,19 @@ launch_helper() {
report_info "Starting customization VM..."
echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM START" >&2
disks=""
for ((i=0; i < DISK_COUNT; i++)); do
eval disk_path=\"\$DISK_${i}_PATH\"
disks+=" -drive file=$disk_path,format=raw,if=virtio,cache=none"
done
set +e
$TIMEOUT -k "$HELPER_HARD_TIMEOUT" "$HELPER_SOFT_TIMEOUT" \
$KVM -runas "$HELPER_USER" -drive file="$HELPER_DIR/image",format=raw,if=virtio,readonly \
-drive file="$blockdev",format=raw,if=virtio,cache=none -m "$HELPER_MEMORY" \
-boot c -serial stdio -serial "file:$(printf "%q" "$result_file")" \
$KVM -runas "$HELPER_USER" \
-drive file="$HELPER_DIR/image",format=raw,if=virtio,readonly \
$disks -m "$HELPER_MEMORY" -boot c -serial stdio \
-serial "file:$(printf "%q" "$result_file")" \
-serial file:>(./helper-monitor.py ${MONITOR_FD}) \
-drive file="$floppy",if=floppy -vga none -nographic -parallel none -monitor null \
-kernel "$HELPER_DIR/kernel" -initrd "$HELPER_DIR/initrd" \
......
# Copyright (C) 2013 GRNET S.A.
# Copyright (C) 2013-2015 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -15,29 +15,58 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
get_img_dev() {
echo /dev/xvdb
assign_disk_devices_to() {
local varname
varname="$1"
eval $varname=\(\)
set -- c d e f g h e j k l m n o p q r
for ((i = 0; i < DISK_COUNT; i++)); do
eval $varname+=\(\"/dev/xvd$1\"\); shift
done
}
launch_helper() {
local name helperid rc blockdev floppy
local name helperid rc floppy disks disk_path xen_dev ftype
blockdev="$1"
floppy="$2"
floppy="$1"
name="snf-image-helper-$instance-$RANDOM"
report_info "Starting customization VM..."
echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM START" >&2
set -- c d e f g h i j k l m n o p q r
for ((i = 0; i < DISK_COUNT; i++)); do
eval disk_path=\"\$DISK_${i}_PATH\"
case $(stat -L -c %F "$disk_path") in
"regular file")
ftype=file
;;
"block special file")
ftype=phy
;;
*)
log_error "Disk: $disk_path is not a block device or a regular file"
report_error "Disk: $disk_path is not a block device or a regular file"
exit 1
esac
xen_dev="xvd$1"; shift
disks+=" disk=$ftype:$disk_path,$xen_dev,w"
done
xm create /dev/null \
kernel="$HELPER_DIR/kernel" ramdisk="$HELPER_DIR/initrd" \
root="/dev/xvda" memory="$HELPER_MEMORY" boot="c" vcpus=1 name="$name" \
extra="console=hvc0 hypervisor=$HYPERVISOR snf_image_activate_helper \
ipv6.disable=1 rules_dev=/dev/xvdc ro boot=local helper_ip=10.0.0.1 \
ipv6.disable=1 rules_dev=/dev/xvdb ro boot=local helper_ip=10.0.0.1 \
monitor_port=48888 init=/usr/bin/snf-image-helper" \
disk="file:$HELPER_DIR/image,xvda,r" disk="phy:$blockdev,xvdb,w" \
disk="file:$floppy,xvdc,r" vif="script=${XEN_SCRIPTS_DIR}/vif-snf-image"
disk="file:$HELPER_DIR/image,xvda,r" disk="file:$floppy,xvdb,r" $disks \
vif="script=${XEN_SCRIPTS_DIR}/vif-snf-image"
add_cleanup suppress_errors xm destroy "$name"
if ! xenstore-exists snf-image-helper; then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment