[Ovirt-devel] [PATCH node] Fixes when a removable media is removed. bz#507455
Darryl L. Pierce
dpierce at redhat.com
Wed Jul 1 16:31:26 UTC 2009
If a device is a removeable media device, then o-c-storage will now
check if there's media present before attempting to get the storage size
for the device.
Any device found must also have a storage amount greater than 0 megs.
Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
scripts/ovirt-config-storage | 173 +++++++++++++++++++++++++++++++-----------
1 files changed, 129 insertions(+), 44 deletions(-)
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index 0fcc0bc..65663dc 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -11,6 +11,7 @@
ME=$(basename "$0")
warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
die() { warn "$*"; exit 1; }
+debug() { if $debugging; then printf "[DEBUG] %s\n" "$*"; fi }
trap '__st=$?; stop_log; exit $__st' 0
trap 'exit $?' 1 2 13 15
@@ -36,8 +37,12 @@ logging_min_size=5
data_min_size=5
swap_min_size=5
+# Gets the drive's size and sets the supplied variable.
+# $1 - the drive
+# $2 - the variable
get_drive_size()
{
+ debug "get_drive_size: start"
local drive=$1
local space_var=$2
@@ -62,16 +67,44 @@ get_drive_size()
size=$(hal-get-property --udi "$udi" --key storage.size)
if [[ "${size}" == "0" ]]; then
# disk is probably hot-swappable, use different HAL key
- size=$(hal-get-property --udi "$udi" --key storage.removable.media_size)
+ # but first check that it is removeable media and that media is present
+ if [[ "true" == "$(hal-get-property --udi "$udi" --key storage.removable.media_available)" ]]; then
+ size=$(hal-get-property --udi "$udi" --key storage.removable.media_size)
+ fi
fi
fi
size=$(echo "scale=0; $size / (1024 * 1024)" | bc -l)
- echo "$drive ($size MB)"
+ eval $space_var=$size
+
+ debug "::size=$size"
+
+ debug "get_drive_size: exit"
+}
+
+print_drive_size ()
+{
+ debug "print_drive_size: start"
+ local drive=$1
+ local udi=${2-}
+
+ if [ -z "$udi" ]; then
+ for this_udi in $(hal-find-by-capability --capability storage); do
+ if [[ "$(hal-get-property --udi $this_udi --key block.device)" = "$drive" ]]; then
+ udi=$this_udi
+ fi
+ done
+ fi
+ get_drive_size $drive SIZE
+ debug "::drive=$drive"
+ debug "::SIZE=$SIZE"
+ echo "$drive ($SIZE MB)"
echo "Disk Identifier: $(basename "$udi")"
if [ -n "$space_var" ]; then
eval $space_var=$size
fi
+
+ debug "print_drive_size: end"
}
check_partition_sizes()
@@ -127,73 +160,112 @@ check_partition_sizes()
return $rc
}
-# Find a usable/selected storage device.
-# If there are none, give a diagnostic and return nonzero.
-# If there is just one, e.g., /dev/sda, treat it as selected (see below).
-# and return 0. If there are two or more, make the user select one
-# or decline. Upon decline, return nonzero. Otherwise, print the
-# selected name, then return 0.
-# Sample output: /dev/sda
-get_dev_name()
+# Ensures the device is acceptable
+# $1 - the device
+check_if_device_is_good ()
+{
+ debug "check_if_device_is_good: start"
+ local device=$1
+ local result=1
+
+ # Must start with a '/'.
+ case $device in
+ *' '*)
+ # we use space as separator
+ warn "block device name '$device' contains space; skipping";
+ continue;;
+ /*)
+ local SIZE
+ get_drive_size $device SIZE
+ debug "::SIZE=$SIZE"
+ if [ $SIZE -gt 0 ]; then result=0; fi
+ ;;
+ *) warn "block device name $device doesn't start with '/';" \
+ " skipping"; continue;;
+ esac
+
+ debug "check_if_device_is_good: end (result=$result)"
+ return $result
+}
+
+get_drive_list ()
{
+ debug "get_drive_list: start"
+ local list_var=$1
+
local udi_list=$(hal-find-by-capability --capability storage)
+ debug "list_var=$list_var"
+
if test -z "$udi_list"; then
warn "ERROR: no usable storage devices detected"
return 1
fi
local d devices sizes
+
for d in $udi_list; do
+ debug "Examining $d"
local drive_type=$(hal-get-property --udi "$d" --key storage.drive_type)
+ debug "::drive_type=$drive_type"
test "X$drive_type" = Xdisk || continue
local block_dev=$(hal-get-property --udi "$d" --key block.device)
- # Must start with a '/'.
- case $block_dev in
- *' '*)
- # we use space as separator
- warn "block device name '$block_dev' contains space; skipping";
- continue;;
- /*) ;;
- *) warn "block device name $block_dev doesn't start with '/';" \
- " skipping"; continue;;
- esac
- test -z "$devices" \
- && devices="$block_dev" \
- || devices="$devices $block_dev"
+ debug "::block_dev=$block_dev"
+ check_if_device_is_good $block_dev
+ rc=$?
+ if [ $rc = 0 ]; then
+ debug "::Acceptable device: $block_dev"
+ test -z "$devices" \
+ && devices="$block_dev" \
+ || devices="$devices $block_dev"
+ fi
done
# FIXME: workaround for detecting virtio block devices
devices="$devices $(ls /dev/vd? 2> /dev/null | xargs)"
devices=$(echo $devices | tr ' ' '\n' | sort -u | xargs)
- local num_devices=$(echo "$devices" | wc -w)
- # If there's only one device, use it.
- case $num_devices in
- 0) warn "ERROR: found no usable block device"; return 1;;
- 1) echo "$devices"; return 0;;
- *) ;; # found more than one
+ if [ -n "$devices" ]; then
+ eval $list_var='"$devices"'
+ fi
+
+ debug "get_drive_list: end"
+}
+
+select_a_drive ()
+{
+ local DRIVE_VAR=$1
+ local choices
+
+ get_drive_list choices
+ case $(echo "$choices" | wc -w) in
+ 0) die "ERROR: there are no usable block devices" ;;
+ 1) echo "$choices"; return 0;;
+ *) ;; # continue to selection
esac
- # There are two or more; make the user choose.
- # display description for each disk
- for d in $devices; do
- get_drive_size $d >&2
+ for choice in $choices; do
+ print_drive_size $choice
done
- local choices="$devices Abort"
- select device in $choices
- do
- test "$device" = Abort && return 1
- test -z "$device" && continue
- echo "$device"
- return 0
+
+ while true; do
+ select device in $choices Abort
+ do
+ case $device in
+ "Abort") return 1;;
+ *) eval $DRIVE_VAR=$device; return 0;;
+ esac
+ done
done
}
do_configure()
{
local name_and_size
- DRIVE=$(get_dev_name) || return 0
- get_drive_size $DRIVE SPACE
+ select_a_drive DRIVE
+ debug "DRIVE=$DRIVE"
+ test -z "$DRIVE" && return 0
+
+ print_drive_size $DRIVE SPACE
printf "\n\nPlease configure storage partitions.\n\n"
printf "* Enter partition sizes in MB.\n"
@@ -285,7 +357,7 @@ do_review()
The local disk will be repartitioned as follows:
================================================
- Physical Hard Disk: $(get_drive_size $DRIVE)
+ Physical Hard Disk: $(print_drive_size $DRIVE)
Boot partition size: $BOOT_SIZE MB
Swap partition size: $SWAP_SIZE MB
Installation partition size: $ROOT_SIZE * 2 MB
@@ -522,7 +594,7 @@ DATA_SIZE=${OVIRT_VOL_DATA_SIZE:-$default_data_size}
if [ -n "$OVIRT_INIT" ]; then
# if present, use the drive selected with 'ovirt_init' boot parameter
DRIVE=$OVIRT_INIT
- get_drive_size $DRIVE SPACE
+ print_drive_size $DRIVE SPACE
fi
# if the node is Fedora then use GPT, otherwise use MBR
@@ -551,6 +623,19 @@ if [ "$1" == "AUTO" ]; then
log "Missing device parameter: unable to partition any disk"
fi
else
+ # check commandline options
+ debugging=false
+
+ while getopts dv c; do
+ case $c in
+ d) debugging=true;;
+ v) set -v;;
+ '?') die "invalid option \`-$OPTARG'";;
+ :) die "missing argument to \`-$OPTARG' option";;
+ *) die "internal error";;
+ esac
+ done
+
OPTIONS="\"Configure\" \"Review\" \"Commit Changes And Quit\" \"Return To Menu\""
eval set $OPTIONS
PS3="Choose an option: "
--
1.6.2.5
More information about the ovirt-devel
mailing list