Commit 766fd6a4 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Nikos Skalkotos

Support userspace-only disks

Commits e147e00 and c4f1bff in Ganeti add support for userspace-only
disks. That means that we could have an instance without a local
block device (e.g. using the embedded support in QEMU for rbd by
passing -drive file=rbd:pool/image_name without the need of a
/dev/rdbX device).

This patch does the following:

Introduce a find_disk() helper method that first checks the
DISK_IDX_PATH and if it is not exported then it returns
DISK_IDX_URI.

Introduce a losetup_disk() helper method that is used during
export/import and in case we have an ntfsdump/extdump image type.
Signed-off-by: default avatarDimitris Aragiorgis <dimitris.aragiorgis@gmail.com>
parent 95597305
......@@ -102,7 +102,7 @@ get_api10_arguments() {
esac
instance=$INSTANCE_NAME
if [ $DISK_COUNT -lt 1 -o -z "$DISK_0_PATH" ]; then
if [ $DISK_COUNT -lt 1 ]; then
log_error "At least one disk is needed"
exit 1
fi
......@@ -111,15 +111,15 @@ get_api10_arguments() {
log_error "Missing OS API Variable: \`EXPORT_DEVICE'"
exit 1
fi
blockdev=$EXPORT_DEVICE
export_disk=$EXPORT_DEVICE
elif [ "$SCRIPT_NAME" = "import" ]; then
if [ -z "$IMPORT_DEVICE" ]; then
log_error "Missing OS API Variable: \`IMPORT_DEVICE'"
exit 1
fi
blockdev=$IMPORT_DEVICE
import_disk=$IMPORT_DEVICE
else
blockdev=$DISK_0_PATH
disk0=$(find_disk 0)
fi
if [ "$SCRIPT_NAME" = "rename" -a -z "$OLD_INSTANCE_NAME" ]; then
log_error "Missing OS API Variable: \`OLD_INSTANCE_NAME'"
......@@ -213,6 +213,47 @@ format_disk0() {
EOF
}
# This is used for export/import and in case we have an fsdump image type.
# If the give disk is a block device this is a no-op.
losetup_disk() {
local disk bdev
disk="$1"
if [ -b "$disk" ]; then
echo "$disk"
elif [ -f "$disk" ] ; then
bdev=$($LOSETUP --show -f "$disk")
add_cleanup $LOSETUP -d "$bdev"
echo $bdev
else
log_error "Cannot losetup $disk: not a regular file"
report_error "Could not use disk provided by Ganeti"
exit 1
fi
}
find_disk() {
local idx path uri
idx=$1
eval path=\$DISK_${idx}_PATH
eval uri=\$DISK_${idx}_URI
# Here we check if we have a valid disk path (block device or regular file)
if [ -b "$path" -o -f "$path" ]; then
echo $path
# Otherwise we choose the userspace URI and
# hope that snf-image can handle it
elif [ -n "$uri" ]; then
echo $uri
else
log_error "Disk information not exported by Ganeti"
exit 1
fi
}
create_floppy() {
local img target IFS index name tm
......
......@@ -133,17 +133,12 @@ case $BACKEND_TYPE in
;;
esac
# If the target device is not a real block device we'll first losetup it.
# This is needed for file disks.
if [ ! -b "$blockdev" ]; then
original_blockdev="$blockdev"
blockdev=$($LOSETUP --show -f "$blockdev")
add_cleanup $LOSETUP -d "$blockdev"
fi
case "$IMAGE_TYPE" in
ntfsdump|extdump)
# Create partitions
# Create a corresponding blockdev if required
blockdev=$(losetup_disk "$disk0")
# Create partitions on blockdev
format_disk0 "$blockdev" "$IMAGE_TYPE"
# Install a new MBR
......@@ -159,7 +154,7 @@ case "$IMAGE_TYPE" in
fi
;;
diskdump)
target="$blockdev"
target="$disk0"
;;
*)
log_error "Unknown Image format: \`$IMAGE_TYPE'"
......
......@@ -26,11 +26,7 @@ ganeti_os_main
# If the device we will export from, is not a real block device,
# we'll first losetup it. This is needed for file disks.
if [ ! -b "$blockdev" ]; then
original_blockdev="$blockdev"
blockdev=$($LOSETUP --show -f "$blockdev")
add_cleanup $LOSETUP -d "$blockdev"
fi
blockdev=$(losetup_disk "$export_disk")
# Export disk's predicted size to Ganeti.
# Used to provide a time estimate of the export process to the user.
......
......@@ -26,11 +26,7 @@ ganeti_os_main
# If the device we will import to, is not a real block device,
# we'll first losetup it. This is needed for file disks.
if [ ! -b "$blockdev" ]; then
original_blockdev="$blockdev"
blockdev=$($LOSETUP --show -f "$blockdev")
add_cleanup $LOSETUP -d "$blockdev"
fi
blockdev=$(losetup_disk "$import_disk")
$DD of="$blockdev" bs=4M
......
# Copyright (C) 2013-2015 GRNET S.A. and individual contributors
# Copyright (C) 2013-2016 GRNET S.A. and individual contributors
#
# 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
......@@ -29,7 +29,7 @@ assign_disk_devices_to() {
}
launch_helper() {
local result_file result snapshot rc floppy i disk_path disks
local result_file result snapshot rc floppy i disks
floppy="$1"
......@@ -41,8 +41,7 @@ launch_helper() {
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"
disks+=" -drive file=$(find_disk $i),format=raw,if=virtio,cache=none"
done
set +e
......
......@@ -40,7 +40,7 @@ launch_helper() {
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\"
disk_path="$(find_disk $i)"
case $(stat -L -c %F "$disk_path") in
"regular file")
ftype=file
......
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