Mike Burns
2010-Mar-23 22:51 UTC
[Ovirt-devel] [PATCH node] Fix uninstall to detect and cleanup correct partitions
Previous implementation had staticly defined partitions to remove. This would break in the case of split Root and HostVG devices. Signed-off-by: Mike Burns <mburns at redhat.com> --- scripts/ovirt-config-boot | 11 +-------- scripts/ovirt-config-uninstall | 48 ++++++++++++++++++++++++--------------- scripts/ovirt-functions | 33 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 29 deletions(-) diff --git a/scripts/ovirt-config-boot b/scripts/ovirt-config-boot index 28d1572..ac43daa 100755 --- a/scripts/ovirt-config-boot +++ b/scripts/ovirt-config-boot @@ -50,12 +50,7 @@ ovirt_boot_setup() { fi # check that /boot mounted ok and find partition number for GRUB - eval $(readlink -f /dev/disk/by-label/$grub_dev_label|awk {' - print "disk=" substr($1,1,length($1)-1); - print "disk2=" substr($1,1,length($1)-2); - partN=substr($1,length($1),1); partN--; - print "partN=" partN; - }') + get_part_info $(readlink -f /dev/disk/by-label/$grub_dev_label disk partN rc=$? if [ $rc -ne 0 -o $partN -lt 0 ]; then log "unable to determine Root partition" @@ -70,10 +65,6 @@ ovirt_boot_setup() { return 1 fi - if [ ! -e "$disk" ]; then - # e.g. c0d0p1 - disk="$disk2" - fi # prepare Root partition update candidate if [ -e /dev/disk/by-label/RootBackup ]; then diff --git a/scripts/ovirt-config-uninstall b/scripts/ovirt-config-uninstall index 3b7b48d..b6675e7 100755 --- a/scripts/ovirt-config-uninstall +++ b/scripts/ovirt-config-uninstall @@ -37,27 +37,37 @@ if ask_yes_or_no "Do you wish to continue and uninstall this node ([Y]es/[N]o)?" rm -f /var/lib/multipath/bindings unmount_logging unmount_config /etc/default/ovirt + #get partition info + root2="" + if findfs LABEL=RootBackup 2>&1 >/dev/null; then + root2=RootBackup + elif findfs LABEL=RootUpdate 2>&1 >/dev/null; then + root2=RootUpdate + elif findfs LABEL=RootNew 2>&1 >/dev/null; then + root2=RootNew + fi + if ! get_part_info $(findfs LABEL=Root 2>/dev/null) root_dev root_part; then + log "Can't find Root device" + exit 2 + fi + if ! get_part_info $(findfs LABEL=${root2} 2>/dev/null) root2_dev root2_part; then + log "Can't find RootBackup/RootNew/RootUpdate device" + exit 3 + fi + if ! get_part_info $(pvs --noheadings -o pv_name,vg_name | grep HostVG | awk '{print $1}') pv_dev pv_part; then + log "Can't find HostVG device" + exit 4 + fi log "Removing volume group" wipe_volume_group "HostVG" - partition=$(readlink -f $(findfs LABEL=Root)) - if [ -n "$partition" ]; then - log "Removing partitions" - eval $(echo $partition | awk ' { - print "drive=" substr($0,1,length($1)-1); - print "drive2=" substr($0,1,length($1)-2); - }') - if [ ! -e "$drive" ]; then - drive="$drive2" - partpv="$drive}p2" - else - partpv="${drive}2" - fi - parted -s $drive "rm 1" - pvremove ${partpv} - parted -s $drive "rm 2" - parted -s $drive "rm 3" - wipe_partitions $drive - fi + log "Removing partitions" + parted -s $root_dev "rm $root_part" + pvremove ${vg_dev} + parted -s $root2_dev "rm $root2_part" + parted -s $vg_dev "rm $vg_part" + wipe_partitions $pv_dev + wipe_partitions $root_dev + wipe_partitions $root2_dev #restart multipath multipath -F multipath -v3 diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions index c2ef94b..b98e31a 100644 --- a/scripts/ovirt-functions +++ b/scripts/ovirt-functions @@ -851,6 +851,39 @@ get_dm_device () return $rc } +#Function to determine partition and device names +get_part_info() { + local drive_in=$1 + local dev_var=$2 + local part_var=$3 + local devname_1 devname2 part_number + local rc=0 + + eval $(readlink -f $drive_in|awk {' + print "devname_1=" substr($1,1,length($1)-1); + print "devname_2=" substr($1,1,length($1)-2); + part_number=substr($1,length($1),1); + print "part_number=" part_number; + }') + rc=$? + + if [[ "part_number" -lt 1 ]]; then + log "Partition number was invalid" + return 2 + fi + + + if [ -e ${devname_1} ]; then + eval "${dev_var}"="${devname_1}" + elif [ -e ${devname_2} ]; then + eval "${dev_var}"="${devname_2}" + else + return 1 + fi + eval "${part_var}"="${part_number}" + return $rc +} + # execute a function if called as a script, e.g. # ovirt-functions ovirt_store_config /etc/hosts -- 1.6.6.1
Maybe Matching Threads
- [PATCH node][RFC] Fix uninstall to detect and cleanup correct partitions
- [PATCH node][REPOST 1/2] Fix uninstall to detect and cleanup correct partitions
- [PATCH node] fix iscsi installation problems
- [PATCH node] RESEND: fix iscsi installation problems
- [PATCH node] add uninstall module