Bug#462396: Multiple disks support for partman-auto-lvm
Le mercredi 30 juillet 2008 01:48, Jérémy Bobbio a écrit :
> > Some minor refactoring was needed when writing the code, so why not doing
> > it while it's still hot ? However I can submit two separate patches if
> > it's clearer.
>
> I'm already asking quite some work, but if you have the energy, it would
> be lovely.
Here is the patch concerning the refactoring part. I moved the definition of
dev_to_partman outside of partman-auto-raid and replaced it by the
appropriate include, but couldn't see the function used anywhere. As I have
no time / resources to test this I chose to do it this way, but if someone
knows for sure the function is not needed I can remove the inclusion.
I also added the definition of some function used in the second part of the
patch. The envelope creation is now a separate function as it is called
twice. I think the functional changes patch will be ready this week end
(2008-08-03) for review, after all required tests on my side.
Cheers,
Grégory
Index: partman-auto-raid/display.d/initial_auto_raid
===================================================================
--- partman-auto-raid/display.d/initial_auto_raid (révision 54731)
+++ partman-auto-raid/display.d/initial_auto_raid (copie de travail)
@@ -5,25 +5,8 @@
. /lib/partman/lib/base.sh
. /lib/partman/lib/commit.sh
+. /lib/partman/lib/auto-shared.sh
-dev_to_partman () {
- local dev_name="$1"
-
- local mapped_dev_name="$(mapdevfs $dev_name)"
- if [ -n "$mapped_dev_name" ]; then
- dev_name="$mapped_dev_name"
- fi
-
- for dev in $DEVICES/*; do
- # mapdevfs both to allow for different ways to refer to the
- # same device using devfs, and to allow user input in
- # non-devfs form
- if [ "$(mapdevfs $(cat $dev/device))" = "$dev_name" ]; then
- echo $dev
- fi
- done
-}
-
# See if we are supposed to run and only run once
db_get partman-auto/method
if [ "$RET" != raid ] || \
Index: partman-auto-lvm/lib/auto-lvm.sh
===================================================================
--- partman-auto-lvm/lib/auto-lvm.sh (révision 54731)
+++ partman-auto-lvm/lib/auto-lvm.sh (copie de travail)
@@ -10,6 +10,55 @@
exit 1
}
+# Creates, if needed, the envelope to hold LVM VGs.
+#
+# We need to create the envelope only if one is not defined. This is the case
+# when :
+# - the default device is not part of a PV declaration in the scheme (a PV
+# is declared when there's a method{ lvm } or method{ crypto } attribute) ;
+# *AND*
+# - the recipe contains a PV declaration *without* device.
+#
+# For this case the physical device used will be the default one.
+#
+# First arg : the scheme to add the envelope to
+# Second arg : the physical device (ie /dev/hda)
+# Third arg : the method to use (lvm or crypto)
+# Returns : the scheme with the envelope if needed
+#
+auto_lvm_create_envelope {
+ local scheme physdev method
+ scheme="$1"
+ physdev=$2
+ method=$3
+
+ if ! echo "$scheme" | grep -E "method\{ (lvm|crypto) \}" | grep -q "device{ $physdev[[:digit:]]* }" && \
+ ! echo "$scheme" | grep -E "method\{ (lvm|crypto) \}" | grep -q -v "device{"; then
+ scheme="$scheme${NL}100 1000 1000000000 ext3 \$primary{ } method{ $method }"
+ fi
+
+ echo "$scheme"
+}
+
+# This function depends on the existence of $scheme and $devfspv_devices in scope
+#
+# It will create the partitions needed by a recipe / scheme to hold all PVs
+#
+# First arg : the path to the partman directory for the device
+#
+auto_lvm_create_partitions() {
+ local dev free_size
+ dev=$1
+
+ get_disk_infos $dev;
+ free_size=$(expr 0000000"$free_size" : '0*\(..*\)......$') # convert to megabytes
+
+ expand_scheme
+
+ create_primary_partitions
+ create_partitions
+}
+
auto_lvm_prepare() {
local dev method size free_size normalscheme target
dev=$1
Index: partman-auto/display.d/initial_auto
===================================================================
--- partman-auto/display.d/initial_auto (révision 54731)
+++ partman-auto/display.d/initial_auto (copie de travail)
@@ -9,26 +9,6 @@
. /lib/partman/lib/auto-shared.sh
-dev_to_partman () {
- local dev_name="$1"
-
- local mapped_dev_name="$(mapdevfs $dev_name)"
- if [ -n "$mapped_dev_name" ]; then
- dev_name="$mapped_dev_name"
- fi
-
- for dev in $DEVICES/*; do
- [ -d "$dev" ] || continue
-
- # mapdevfs both to allow for different ways to refer to the
- # same device using devfs, and to allow user input in
- # non-devfs form
- if [ "$(mapdevfs $(cat $dev/device))" = "$dev_name" ]; then
- echo $dev
- fi
- done
-}
-
# Skip if no disks detected and don't run on S/390
if [ -z "$(get_auto_disks)" ] || \
[ "$(udpkg --print-architecture)" = s390 ]; then
Index: partman-auto/lib/auto-shared.sh
===================================================================
--- partman-auto/lib/auto-shared.sh (révision 54731)
+++ partman-auto/lib/auto-shared.sh (copie de travail)
@@ -8,6 +8,13 @@
. /lib/partman/lib/disk-label.sh
create_new_label "$dev" no || return 1
+ get_disk_infos $dev
+}
+
+get_disk_infos() {
+ local dev
+ dev=$1
+
cd $dev
free_space=''
@@ -213,3 +220,25 @@
# TODO: Add a select_auto_disks() function
# Note: This needs a debconf_multiselect equiv.
+
+# Maps a devfs name to a partman directory
+dev_to_partman () {
+ local dev_name="$1"
+
+ local mapped_dev_name="$(mapdevfs $dev_name)"
+ if [ -n "$mapped_dev_name" ]; then
+ dev_name="$mapped_dev_name"
+ fi
+
+ for dev in $DEVICES/*; do
+ [ -d "$dev" ] || continue
+
+ # mapdevfs both to allow for different ways to refer to the
+ # same device using devfs, and to allow user input in
+ # non-devfs form
+ if [ "$(mapdevfs $(cat $dev/device))" = "$dev_name" ]; then
+ echo $dev
+ fi
+ done
+}
+
Reply to: