[Ovirt-devel] [PATCH node] Add data partition to ovirt_vol parameter and o-c-storage

Perry Myers pmyers at redhat.com
Mon Jan 19 08:25:53 UTC 2009


data partition size can be specified as follows:
-1 = data partition uses up remaining disk available
 0 = no data partition
 X = positive number indicates exact size for data partition

Signed-off-by: Perry Myers <pmyers at redhat.com>
---
 scripts/ovirt-config-storage |   96 +++++++++++++++++++++++++++++++++--------
 scripts/ovirt-early          |   12 ++++--
 2 files changed, 85 insertions(+), 23 deletions(-)

diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index a8d679e..efe55f5 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 # To automate the partitioning, pass in the specific fields in this order
-# ovirt-config-storage [swap size] [boot size] [root size] [logging size]
+# ovirt-config-storage [swap size] [boot size] [root size] [logging size] [data size]
 #
 # All sizes are in megabytes
 #
@@ -19,6 +19,15 @@ default_boot_size=50
 default_root_size=256
 default_config_size=5
 default_logging_size=256
+# -1 indicates data partition should use remaining disk
+default_data_size=-1
+
+boot_min_size=50
+root_min_size=256
+config_min_size=5
+logging_min_size=5
+data_min_size=5
+swap_min_size=5
 
 get_selected_drive_size()
 {
@@ -33,20 +42,24 @@ get_selected_drive_size()
         size=$(hal-get-property --udi "$udi" --key storage.removable.media_size)
     fi
     SPACE=$(echo "scale=0; $size / (1024 * 1024)" | bc -l)
-    echo "selected device: $DRIVE ($SPACE MB)"
+    echo "Selected Device: $DRIVE ($SPACE MB)"
 }
 
 check_partition_sizes()
 {
     local disk_size need_size
 
+    local min_data_size=$DATA_SIZE
+    if [ "$DATA_SIZE" = -1 ]; then
+        min_data_size=5
+    fi
+
+    printf "\n"
     get_selected_drive_size
     disk_size=$SPACE
     need_size=$(echo "scale=0;" \
                      "$BOOT_SIZE + $SWAP_SIZE + $ROOT_SIZE" \
-                     "+ $CONFIG_SIZE + $LOGGING_SIZE" | bc -l)
-    printf "disk_size=$disk_size\n"
-    printf "need_size=$need_size\n"
+                     "+ $CONFIG_SIZE + $LOGGING_SIZE + $min_data_size" | bc -l)
 
     if [ $need_size -gt $disk_size ]; then
         gap_size=$(echo "scale=0; $need_size-$disk_size;" | bc -l)
@@ -59,6 +72,8 @@ check_partition_sizes()
         printf "You need an addition $gap_size MB of storage.\n"
         printf "\n"
         return 1
+    else
+        printf "Required Space : $need_size MB\n\n"
     fi
 
     return 0
@@ -126,19 +141,40 @@ do_configure()
     DRIVE=$(get_dev_name) || exit 1
     get_selected_drive_size
 
-    for i in boot swap root config logging ; do
+    printf "\n\nPlease configure storage partitions.\n\n"
+    printf "Enter partition sizes in MB.\n"
+    printf "A value of 0 indicates the partition should be disabled.\n"
+    printf "If the partition is enabled, it will have a minimum valid size.\n"
+    printf "For the Data partition, a size of -1 indicates that the\n"
+    printf "partition should use up the remaining space on the disk.\n\n"
+
+    for i in boot swap root config logging data ; do
+        part_regexp="^0$"
+        if [ "$i" = "data" ]; then
+            part_regexp="^\-1|0$"
+        fi
         uc=$(echo $i|tr '[[:lower:]]' '[[:upper:]]')
-        var=${uc}_SIZE
-        eval "size=\$$var"
-        read -ep "Change $i partition size (Currently $size MB)? "
+        size_var=${uc}_SIZE
+        eval "size=\$$size_var"
+        min_size_var=${i}_min_size
+        eval "min_size=\$$min_size_var"
+        read -ep "Change $i partition size. (Current $size MB, Minimum $min_size MB)? "
         r=$REPLY
         test -z "$r" && r=$size
-        if [[ $r =~ ^[0-9]+$ ]] && [[ $r -ge 0 ]]; then
-            eval "$var=$r"
+        if [[ $r =~ ^-*[0-9]+$ ]] && [[ $r -ge $min_size ||
+                    $r =~ $part_regexp ]] ; then
+            eval "$size_var=$r"
         else
             printf "invalid $i size: '$r' retaining $size MB.\n"
         fi
     done
+
+    if ! check_partition_sizes; then
+        printf "Please try partitioning again.\n"
+        DRIVE=
+        return 1
+    fi
+
     # save input variables
     augtool <<EOF
 set /files$OVIRT_DEFAULTS/OVIRT_INIT $DRIVE
@@ -147,6 +183,7 @@ set /files$OVIRT_DEFAULTS/OVIRT_VOL_SWAP_SIZE $SWAP_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_ROOT_SIZE $ROOT_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_CONFIG_SIZE $CONFIG_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_LOGGING_SIZE $LOGGING_SIZE
+set /files$OVIRT_DEFAULTS/OVIRT_VOL_DATA_SIZE $DATA_SIZE
 EOF
 }
 
@@ -157,6 +194,13 @@ do_review()
         return
     fi
 
+    local data_size_display="$DATA_SIZE MB"
+    if [ "$DATA_SIZE" = -1 ]; then
+        local remaining_mb=$(( $SPACE - $BOOT_SIZE - $SWAP_SIZE \
+                - $ROOT_SIZE - $CONFIG_SIZE - $LOGGING_SIZE ))
+        data_size_display="$remaining_mb MB"
+    fi
+
     cat <<EOF
 
 The local disk will be repartitioned as follows:
@@ -168,6 +212,7 @@ The local disk will be repartitioned as follows:
   Installation partition size: $ROOT_SIZE MB
  Configuration partition size: $CONFIG_SIZE MB
        Logging partition size: $LOGGING_SIZE MB
+          Data partition size: $data_size_display
 
 EOF
 }
@@ -277,14 +322,26 @@ perform_partitioning()
         tune2fs -c 0 -i 0 /dev/HostVG/Logging
         echo "/dev/HostVG/Logging /var/log ext3 defaults 0 0" >> /etc/fstab
     fi
-    log "Creating data partition"
-    lvcreate --name Data    -l 100%FREE             /dev/HostVG
-    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
-    echo "/data/images /var/lib/libvirt/images bind bind 0 0" >> /etc/fstab
-    log "Mounting data partition"
-    mount_data
+
+    local use_data=1
+    if [ "$DATA_SIZE" -eq -1 ]; then
+        log "Creating data partition with remaining free space"
+        lvcreate --name Data -l 100%FREE /dev/HostVG
+        use_data=0
+    elif [ "$DATA_SIZE" -gt 0 ]; then
+        log "Creating data partition"
+        lvcreate --name Data --size ${DATA_SIZE}M /dev/HostVG
+        use_data=0
+    fi
+
+    if [ "$use_data" = 0 ]; then
+        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
+        echo "/data/images /var/lib/libvirt/images bind bind 0 0" >> /etc/fstab
+        log "Mounting data partition"
+        mount_data
+    fi
 
     log "Mounting config partition"
     if mount_config; then
@@ -365,6 +422,7 @@ BOOT_SIZE=${OVIRT_VOL_BOOT_SIZE:-$default_boot_size}
 ROOT_SIZE=${OVIRT_VOL_ROOT_SIZE:-$default_root_size}
 CONFIG_SIZE=${OVIRT_VOL_CONFIG_SIZE:-$default_config_size}
 LOGGING_SIZE=${OVIRT_VOL_LOGGING_SIZE:-$default_logging_size}
+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
diff --git a/scripts/ovirt-early b/scripts/ovirt-early
index 6c7b29b..a7cf4dc 100755
--- a/scripts/ovirt-early
+++ b/scripts/ovirt-early
@@ -116,7 +116,7 @@ start() {
     # oVirt boot parameters
     #   BOOTIF=link|eth*|<MAC> (appended by pxelinux)
     #   ovirt_init=usb|scsi[:serial#]
-    #   ovirt_vol=BOOT_MB:SWAP_MB:ROOT_MB:CONFIG_MB:LOGGING_MB
+    #   ovirt_vol=BOOT_MB:SWAP_MB:ROOT_MB:CONFIG_MB:LOGGING_MB:DATA_MB
     #   ovirt_overcommit
     #   ovirt_local_boot
     #   ovirt_standalone
@@ -147,13 +147,17 @@ start() {
     # e.g. ovirt_init=usb:Generic_STORAGE_DEVICE_0000145418-0:0
     init=
 
-    #   ovirt_vol=BOOT_MB:SWAP_MB:ROOT_MB:CONFIG_MB:LOGGING_MB
+    #   ovirt_vol=BOOT_MB:SWAP_MB:ROOT_MB:CONFIG_MB:LOGGING_MB:DATA_MB
     # local partition sizes in MB
     vol_boot_size=
     vol_swap_size=
     vol_root_size=
     vol_config_size=
     vol_logging_size=
+    # data size can be set to 0 to disable data partition, -1 to use
+    # remaining free space after the other above partitions are defined
+    # or a specific positive number in MB
+    vol_data_size=
 
     #   ovirt_local_boot
     # install/update oVirt Node image on the local installation target disk
@@ -250,7 +254,7 @@ start() {
             ;;
             ovirt_vol=*)
             i=${i#ovirt_vol=}
-            eval $(printf $i|awk -F: '{print "vol_boot_size="$1; print "vol_swap_size="$2; print "vol_root_size="$3; print "vol_config_size="$4; print "vol_logging_size="$5;}')
+            eval $(printf $i|awk -F: '{print "vol_boot_size="$1; print "vol_swap_size="$2; print "vol_root_size="$3; print "vol_config_size="$4; print "vol_logging_size="$5; print "vol_data_size="$6;}')
             ;;
             ovirt_local_boot*)
             local_boot=1
@@ -305,7 +309,7 @@ start() {
         ip_gateway=$gateway
     fi
     # save boot parameters as defaults for ovirt-config-*
-    params="bootif init vol_boot_size vol_swap_size vol_root_size vol_config_size vol_logging_size local_boot standalone overcommit ip_address ip_netmask ip_gateway ipv6 dns syslog_server syslog_port collectd_server collectd_port bootparams hostname"
+    params="bootif init vol_boot_size vol_swap_size vol_root_size vol_config_size vol_logging_size vol_data_size local_boot standalone overcommit ip_address ip_netmask ip_gateway ipv6 dns syslog_server syslog_port collectd_server collectd_port bootparams hostname"
     mount_config
     if [ -e $OVIRT_DEFAULTS ]; then
         echo "update ovirt defaults"
-- 
1.6.0.6




More information about the ovirt-devel mailing list