[Ovirt-devel] [PATCH] Added an error message for when partitioning fails.

Darryl L. Pierce dpierce at redhat.com
Fri Jan 16 19:47:03 UTC 2009


NOTE: This supercedes the patch just sent. I had not rebased against
      next and found there were changes to o-c-storage that affected
      this patch. So I rebased, fixed and am resubmitting this update.

Each call to create an LVM is checked to see if it completed
successfully. If it fails, a message is shown to the user and the
partition stops with a failure.

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 scripts/ovirt-config-storage |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index 3b1b947..851cf3a 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -8,9 +8,18 @@
 
 . /etc/init.d/ovirt-functions
 
+PARTITION_LOG=/var/log/ovirt-partition.log
+
 ME=$(basename "$0")
 warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
 die() { warn "$*"; exit 1; }
+fail()
+{
+    printf "\nFailed while creating the $1 partition.\n";
+    printf "Please see $PARTITION_LOG for more information.\n";
+    exit 1;
+}
+
 
 default_boot_size=50
 default_root_size=256
@@ -177,13 +186,9 @@ perform_partitioning()
 
     printf "Preparing local storage. Please wait..."
 
-    LOG=/var/log/ovirt-partition.log
     {
     wipe_lvm_on_disk
 
-    # Exit upon any failure.
-    set -e
-
     # FIXME: save a backup copy, just in case?
     dd if=/dev/zero of=$DRIVE bs=1024K count=1
     blockdev --rereadpt $DRIVE
@@ -216,40 +221,35 @@ perform_partitioning()
     ln -snf "${DRIVE}1" /dev/disk/by-label/BOOT
 
     if [ "$SWAP_SIZE" -gt 0 ]; then
-        lvcreate --name Swap    --size ${SWAP_SIZE}M    /dev/HostVG
+        lvcreate --name Swap --size ${SWAP_SIZE}M /dev/HostVG && test $? == 0 || fail "swap"
         mkswap -L "SWAP" /dev/HostVG/Swap
         echo "/dev/HostVG/Swap swap swap defaults 0 0" >> /etc/fstab
     fi
     if [ "$ROOT_SIZE" -gt 0 ]; then
-        lvcreate --name Root    --size ${ROOT_SIZE}M    /dev/HostVG
+        test lvcreate --name Root --size ${ROOT_SIZE}M /dev/HostVG || fail "root"
         mke2fs -T ext3 /dev/HostVG/Root    -L "ROOT"
         tune2fs -c 0 -i 0 /dev/HostVG/Root
     fi
     if [ "$CONFIG_SIZE" -gt 0 ]; then
-        lvcreate --name Config  --size ${CONFIG_SIZE}M  /dev/HostVG
+        lvcreate --name Config --size ${CONFIG_SIZE}M /dev/HostVG && test $? == 0|| fail "config"
         mke2fs -T ext3 /dev/HostVG/Config  -L "CONFIG"
         tune2fs -c 0 -i 0 /dev/HostVG/Config
     fi
     if [ "$LOGGING_SIZE" -gt 0 ]; then
-        lvcreate --name Logging --size ${LOGGING_SIZE}M /dev/HostVG
+        lvcreate --name Logging --size ${LOGGING_SIZE}M /dev/HostVG && test $? == 0|| fail "logging"
         mke2fs -T ext3 /dev/HostVG/Logging -L "LOGGING"
         tune2fs -c 0 -i 0 /dev/HostVG/Logging
         echo "/dev/HostVG/Logging /var/log ext3 defaults 0 0" >> /etc/fstab
     fi
-    lvcreate --name Data    -l 100%FREE             /dev/HostVG
+    lvcreate --name Data -l 100%FREE /dev/HostVG && test $? == 0 || fail "data"
     mke2fs -T ext3 /dev/HostVG/Data    -L "DATA"
     tune2fs -c 0 -i 0 /dev/HostVG/Data
+
     echo "/dev/HostVG/Data /data ext3 defaults 0 0" >> /etc/fstab
     if mount_config; then
         ovirt_store_config /etc/fstab
     fi
-    } 2>&1 | tee $LOG
-
-    if [ $? -eq 0 ]; then
-        printf "Completed!\n\n"
-    else
-        printf "FAILED! See $LOG\n\n"
-    fi
+    } 2>&1 | tee $PARTITION_LOG
 }
 
 do_confirm()
-- 
1.6.0.6




More information about the ovirt-devel mailing list