Mike Burns
2010-Mar-24 13:03 UTC
[Ovirt-devel] [PATCH node][REPOST 1/2] 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
Mike Burns
2010-Mar-24 13:03 UTC
[Ovirt-devel] [PATCH node][REPOST 2/2] Remove dependencies on /dev/disk/by-label entries
Use findfs LABEL=ABC and mount LABEL=ABC instead.
Signed-off-by: Mike Burns <mburns at redhat.com>
---
scripts/ovirt-config-boot | 29 ++++++++++++++++-------------
scripts/ovirt-config-storage | 2 --
scripts/ovirt-functions | 18 ++++++++++--------
3 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/scripts/ovirt-config-boot b/scripts/ovirt-config-boot
index ac43daa..d545878 100755
--- a/scripts/ovirt-config-boot
+++ b/scripts/ovirt-config-boot
@@ -29,14 +29,21 @@ ovirt_boot_setup() {
local disk2
local partN=-1
log "installing the image."
- if [ -h /dev/disk/by-label/Boot ]; then
+ local found_boot=false
+ if findfs LABEL=Boot 2>&1 >/dev/null ; then
+ found_boot=true
+ grub_dev_label=Boot
+ elif findfs LABEL=Root 2>&1 >/dev/null ; then
+ found_boot=true
+ grub_dev_label=Root
+ fi
+ if $found_boot; then
mount_boot
mountpoint /boot
if [ $? -ne 0 ] ; then
log "Boot partition not available"
return 1
fi
- grub_dev_label="Boot"
# Grab OVIRT_ISCSI VARIABLES from boot partition for upgrading
# file created only if OVIRT_ISCSI_ENABLED=y
if [ -f /boot/ovirt ]; then
@@ -50,7 +57,7 @@ ovirt_boot_setup() {
fi
# check that /boot mounted ok and find partition number for GRUB
- get_part_info $(readlink -f /dev/disk/by-label/$grub_dev_label disk partN
+ get_part_info $(readlink -f $(findfs LABEL=$grub_dev_label 2>/dev/null))
disk partN
rc=$?
if [ $rc -ne 0 -o $partN -lt 0 ]; then
log "unable to determine Root partition"
@@ -67,11 +74,11 @@ ovirt_boot_setup() {
# prepare Root partition update
candidate- if [ -e /dev/disk/by-label/RootBackup ]; then
+ if findfs LABEL=RootBackup 2>&1 >/dev/null; then
candidate=RootBackup
- elif [ -e /dev/disk/by-label/RootUpdate ]; then
+ elif findfs LABEL=RootUpdate 2>&1 >/dev/null; then
candidate=RootUpdate
- elif [ -e /dev/disk/by-label/RootNew ]; then
+ elif findfs LABEL=RootNew 2>&1 >/dev/null; then
candidate=RootNew
fi
if [ -z "$candidate" ]; then
@@ -80,7 +87,7 @@ ovirt_boot_setup() {
umount /liveos
rc=0
else
- candidate_dev=$(readlink -f /dev/disk/by-label/$candidate)
+ candidate_dev=$(findfs LABEL=$candidate 2>/dev/null)
e2label $candidate_dev RootNew
rc=$?
fi
@@ -90,7 +97,7 @@ ovirt_boot_setup() {
return $rc
fi
- mount $candidate_dev /liveos
+ mount $candidate_dev /liveos/
rm -rf /liveos/LiveOS
mkdir -p /liveos/LiveOS
@@ -212,11 +219,7 @@ if [ $rc -eq 0 -a "$doreboot" = "yes"
]; then
ovirt_store_firstboot_config
stop_log
- if [ "$OVIRT_ISCSI_ENABLED" != "y" ]; then
- reboot
- else
- /sbin/reboot
- fi
+ reboot
fi
stop_log
exit $rc
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index c6473a6..93b94b0 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -703,8 +703,6 @@ perform_partitioning()
log "Creating volume group"
vgcreate /dev/HostVG "${partpv}"
- mkdir -p /dev/disk/by-label
-
if [ "$SWAP_SIZE" -gt 0 ]; then
log "Creating swap partition"
lvcreate --name Swap --size ${SWAP_SIZE}M /dev/HostVG
diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions
index b98e31a..482441a 100644
--- a/scripts/ovirt-functions
+++ b/scripts/ovirt-functions
@@ -283,7 +283,7 @@ mount_liveos() {
return 0
fi
mkdir -p /liveos
- mount /dev/disk/by-label/Root /liveos
+ mount LABEL=Root /liveos
}
# mount config partition
@@ -326,7 +326,7 @@ mount_boot() {
return 0
fi
mkdir -p /boot
- mount /dev/disk/by-label/Boot /boot
+ mount LABEL=Root /boot
}
# stop any service which keeps /var/log busy
# keep the list of services
@@ -709,12 +709,14 @@ lvremove() {
# cleanup before reboot
reboot() {
cd /
- # setup new Root if update is prepared
- if [ -e "/dev/disk/by-label/RootUpdate" ]; then
- root_update_dev=$(readlink -f /dev/disk/by-label/RootUpdate)
- root_dev=$(readlink -f /dev/disk/by-label/Root)
- e2label $root_dev RootBackup
- e2label $root_update_dev Root
+ if [ "$OVIRT_ISCSI_ENABLED" = "yes" ]; then
+ # setup new Root if update is prepared
+ if findfs LABEL=RootUpdate 2>&1 >/dev/null; then
+ root_update_dev=$(findfs LABEL=RootUpdate 2>/dev/null)
+ root_dev=$(findfs LABEL=Root 2>/dev/null)
+ e2label $root_dev RootBackup
+ e2label $root_update_dev Root
+ fi
fi
# run post-install hooks
# e.g. to avoid reboot loops using Cobbler PXE only once
--
1.6.6.1
Joey Boggs
2010-Mar-24 15:10 UTC
[Ovirt-devel] [PATCH node][REPOST 1/2] Fix uninstall to detect and cleanup correct partitions
On 03/24/2010 09:03 AM, Mike Burns wrote:> 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 > >ACK
Maybe Matching Threads
- [PATCH node][RFC] Remove dependencies on /dev/disk/by-label entries
- [PATCH node] split root filesystems out of HostVG and onto their own partitions
- [PATCH node] RESEND: fix iscsi installation problems
- [PATCH node] Handle space in storage wwid
- [PATCH node][RFC] Fix uninstall to detect and cleanup correct partitions