[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#347479: Seems to not handle VG creation correctly



On Tuesday 07 February 2006 18:31, you wrote:
> The attached patch adds some basic checks so we do not "just go ahead"

Sorry. Attached the wrong patch. This one is better.

Index: automatically_partition/some_device_lvm/do_option
===================================================================
--- automatically_partition/some_device_lvm/do_option	(revision 34764)
+++ automatically_partition/some_device_lvm/do_option	(working copy)
@@ -5,12 +5,33 @@
 . /lib/partman/lvm_tools.sh
 . /lib/partman/auto-shared.sh
 
+bail_out() {
+    db_input critical partman-auto-lvm/$1 || true
+    db_go || true
+    exit 1
+}
+
+
 dev=$1
 
 [ -f $dev/size ] || exit 1
 free_size=$(cat $dev/size)
 free_size=$(expr 0000000"$free_size" : '0*\(..*\)......$') # convert to megabytes
 
+# be sure the modules are loaded
+modprobe dm-mod >/dev/null 2>&1 || true
+modprobe lvm-mod >/dev/null 2>&1 || true
+
+if type update-dev >/dev/null 2>&1; then
+    log-output -t update-dev update-dev
+fi
+
+# check if the device already contains any physical volumes
+realdev=$(mapdevfs "$(cat $dev/device)")
+if PV_list | grep -q "$realdev" ; then
+    bail_out pv_on_device
+fi
+
 # we need to be sure we can perform the selected receipe and be able to add /boot.
 # virtually remove 200Mb from the free space. Perhaps a reiteration over the recipe
 # would be more accurate, but for now this is more than fine.
@@ -26,9 +47,7 @@
 
 # check if the recipe contains lvmok tags otherwise fail
 if [ -z "$(echo "$scheme" | grep "lvmok")" ]; then
-	db_input critical partman-auto-lvm/unusable_recipe || true
-	db_go || true
-	exit 1
+	bail_out unusable_recipe
 fi
 
 ### situation:
@@ -74,14 +93,6 @@
 
 #### now we have the container! yeppa!!! ####
 
-# be sure the modules are loaded
-modprobe dm-mod >/dev/null 2>&1 || true
-modprobe lvm-mod >/dev/null 2>&1 || true
-
-if type update-dev >/dev/null 2>&1; then
-    log-output -t update-dev update-dev
-fi
-
 # lvm doesn't like devfs paths.
 for pv in $devfspv_devices; do
     realpath="$(mapdevfs "$pv")"
@@ -96,11 +107,17 @@
     db_get partman-auto-lvm/new_vg_name
     VG_name="$RET"
 
-    if VG_create "$VG_name" $pv_devices; then break; fi
-    noninteractive="exit 1"
+    # check if the volume group name is not in use
+    if [ -z "$(VG_list | grep " $VG_name${TAB}")" ]; then break; fi
+    noninteractive="bail_out vg_exists"
+    db_register partman-auto-lvm/new_vg_name_exists partman-auto-lvm/new_vg_name
 done
 
-perform_recipe_by_lvm $VG_name $recipe
+if VG_create "$VG_name" $pv_devices; then
+    perform_recipe_by_lvm $VG_name $recipe
+else
+    bail_out vg_create_error
+fi
 
 # default to accepting the autopartitioning
 menudir_default_choice /lib/partman/choose_partition finish finish || true
Index: debian/partman-auto-lvm.templates
===================================================================
--- debian/partman-auto-lvm.templates	(revision 34764)
+++ debian/partman-auto-lvm.templates	(working copy)
@@ -11,8 +11,35 @@
 Default: Debian
 _Description: Name of the volume group for the new system:
 
+Template: partman-auto-lvm/new_vg_name_exists
+Type: string
+_Description: Name of the volume group for the new system:
+ The name selected for the volume group is already in use on your system.
+ Please enter a different name.
+
 Template: partman-auto-lvm/unusable_recipe
 Type: error
 _Description: Failed to partition the selected disk
  This happened because the selected recipe does not contain any partition
  that can be created on LVM volumes.
+
+Template: partman-auto-lvm/pv_on_device
+Type: error
+_Description: Selected device already contains a physical volume
+ The device you selected already contains one or more physical volumes. It
+ is not possible to automatically partition the device using LVM.
+
+Template: partman-auto-lvm/vg_exists
+Type: error
+_Description: Volume group name already in use
+ The volume group name used to automatically partition using LVM is already
+ in use. It is possible to specify an alternative name by running the
+ installation at medium or low priority.
+
+Template: partman-auto-lvm/vg_create_error
+Type: error
+_Description: Unexpected error while creating volume group
+ Autopartitioning using LVM failed because an error occurred while creating
+ the volume group.
+ .
+ Check /var/log/syslog or see virtual console 4 for the details.
Index: debian/changelog
===================================================================
--- debian/changelog	(revision 34764)
+++ debian/changelog	(working copy)
@@ -1,9 +1,11 @@
 partman-auto-lvm (9) UNRELEASED; urgency=low
 
   * Fix code that checks if a /boot partition is already present in the
-    selected scheme. Closes: #350444. 
+    selected scheme. Closes: #350444.
+  * Improve handling of the VG name question. Thanks to Fabio M. Di Nitto.
+  * Bail out in situations we cannot really deal with currently.
 
- -- Frans Pop <fjp@debian.org>  Sun, 29 Jan 2006 19:27:24 +0100
+ -- Frans Pop <fjp@debian.org>  Tue,  7 Feb 2006 16:51:38 +0100
 
 partman-auto-lvm (8) unstable; urgency=low
 
Index: lvm_tools.sh
===================================================================
--- lvm_tools.sh	(revision 34764)
+++ lvm_tools.sh	(working copy)
@@ -1,6 +1,11 @@
 
 TAB='	'
 
+# Print a list of the names of all physical volumes and the volume groups they contain
+PV_list () {
+	pvs -o pv_name,vg_name --noheadings --sort pv_name,vg_name --separator "${TAB}"
+}
+
 # Print a list of the names of all volume groups and their size in M (including decimals!)
 VG_list () {
 	vgs -o vg_name,vg_size --nosuffix --units M --noheadings --sort vg_name --separator "${TAB}"
@@ -13,7 +18,7 @@
     local vg
     vg="$1"
     shift
-    log-output -t partman-auto-lvm pvcreate -ff -y $*
+    log-output -t partman-auto-lvm pvcreate -ff -y $* || return 1
     log-output -t partman-auto-lvm vgcreate "$vg" $* || return 1
     return 0
 }

Attachment: pgpy6MjV2FJ2E.pgp
Description: PGP signature


Reply to: