Bug#375491: patch suggestion

2006-08-23 Thread Ronny Aasen


The basic algorithm looks OK, but you should probably try to use the 
general functions already available in lvm_tools.sh (part of the 
partman-lvm package) instead of the direct calls to pvs and vgs.
  

I begin at the end, since that was the easy part.
Attached is a patch doing the same, but using the functions from 
lvm_tools.sh
I might give a shot at the other issues too, but since i am mostly 
fumbeling around it may take quite some time.


Ronny Aasen


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Bug#375491: patch suggestion

2006-08-23 Thread Ronny Aasen

patch
Index: autopartition-lvm
===
--- autopartition-lvm   (revision 40105)
+++ autopartition-lvm   (working copy)
@@ -26,10 +26,50 @@
log-output -t update-dev update-dev
 fi
 
+
 # Check if the device already contains any physical volumes
 realdev=$(mapdevfs "$(cat $dev/device)")
 if pv_on_device "$realdev"; then
-   bail_out pv_on_device
+   # If we are beeing preseeded with partman-auto-lv/disk, then try to 
make sure lv's 
+   # and vg's are removed from the disk in question.
+   targetvg=
+   db_get partman-auto-lvm/disk
+   diskseed=$(mapdevfs $RET)
+   if [ "$diskseed" = "$realdev" ] ;then
+   #what volume groups is on any of the the disk partitions.
+   all_volume_groups=$(vg_list)
+   #we only care about vg's on the preseeded disk
+   for vg in $all_volume_groups
+   do  
+   if [ "$(vg_list_pvs "$vg" | grep -c "$realdev")" != "0" 
] ; then
+   targetvg=${targetvg}" $vg"
+   fi
+   done
+   for vgroup in $targetvg
+   do
+   #make sure the volume groups on the target disk don't 
span any other disks.
+   if [ "$(lvm_get_info vgs pv_count "$vgroup")" != "1" ] 
; then
+   log-output -t partman-auto-lvs vgs
+   bail_out pv_on_device
+   fi
+   done
+   
+   #it should now be safe to remove the vg's on the target disks
+
+   #remove lv's  from the target vg's.
+   for vgroup in $targetvg
+   do
+   for lv in $(vg_list_lvs $vgroup)
+   do
+   #remove the logical volumes on the volume group
+   lv_delete $vgroup $lv
+   done
+   #remove the volume group
+   vg_delete $vgroup
+   done
+   else
+   bail_out pv_on_device
+   fi
 fi
 
 choose_recipe "$free_size" lvm || exit $?


Bug#375491: patch suggestion

2006-08-21 Thread David Härdeman

On Mon, Aug 21, 2006 at 09:47:59PM +0200, Frans Pop wrote:

On Monday 21 August 2006 20:55, Ronny Aasen wrote:

if it finds that the vg is isolated to the disk, preseeded to be
erased, it removes all Logicalvolumes, and VolumeGroups on that disk.


The basic algorithm looks OK, but you should probably try to use the 
general functions already available in lvm_tools.sh (part of the 
partman-lvm package) instead of the direct calls to pvs and vgs.


I think it would be a good idea to separate out the functionality to a 
lvm_purge_from_disk function in lvm_tools.sh.


Then it can be used both for partman-lvm and partman-auto-lvm, and in 
addition it would be trivial to use this if partman-auto-lvm gains 
support for multiple disks later.


Regards,
David


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Bug#375491: patch suggestion

2006-08-21 Thread Ronny Aasen

patch attached instead

Ronny Aasen




Index: autopartition-lvm
===
--- autopartition-lvm   (revision 40105)
+++ autopartition-lvm   (working copy)
@@ -26,10 +26,42 @@
log-output -t update-dev update-dev
 fi
 
+
 # Check if the device already contains any physical volumes
 realdev=$(mapdevfs "$(cat $dev/device)")
 if pv_on_device "$realdev"; then
-   bail_out pv_on_device
+   # If we are beeing preseeded with partman-auto-lv/disk, then try to 
make sure lv's 
+   # and vg's are removed from the disk in question.
+   db_get partman-auto-lvm/disk
+   diskseed=$(mapdevfs $RET)
+   if [ "$diskseed" = "$realdev" ] ;then
+   #what volume groups is on any of the the target disk partitions.
+   targetvolumegroups=`pvs --noheading --separator=";" | grep 
$realdev | cut -d";" -f2`
+   for vgroup in $targetvolumegroups
+   do
+   #make sure the volume groups on the target disk don't 
span any other disks.
+   if [ "1" -ne `vgs --noheading --separator=";"| grep 
$vgroup | cut -d";" -f2` ] ;then
+   log-output -t partman-auto-lvs vgs 
+   bail_out pv_on_device
+   fi
+   done
+   
+   #it should now be safe to remove the vg's on the target disks
+
+   #remove lv's  from the target vg's.
+   for vgroup in $targetvolumegroups
+   do
+   for lv in `vgs --noheadings -o lv_name $vgroup`
+   do
+   #remove the logical volumes on the volume group
+   log-output -t partman-auto-lvm lvremove 
/dev/$vgroup/$lv
+   done
+   #remove the volume group
+   log-output -t partman-auto-lvm vgremove $vgroup
+   done
+   else
+   bail_out pv_on_device
+   fi
 fi
 
 choose_recipe "$free_size" lvm || exit $?


Bug#375491: patch suggestion

2006-08-21 Thread Frans Pop
On Monday 21 August 2006 20:55, Ronny Aasen wrote:
> I have written a patch that i hope could help on this issue.
> it can probably be santized, or rewritten in a better way, but it works
> for me as it looks now.

Thanks Ronny.

> what it does is basicaly.
> it checks that it's beeing run preseeded, if not it does nothing.

We really want to do the same when running interactive, but with a message 
to the user what is being deleted. If you feel up to trying that too, 
feel free. If not, someone else probably will when applying this.

Basically this means adding a boolean template with the question to 
confirm and a couple of variables to show the VGs and LVs to be removed 
(examples of similar templates and how to use them available in 
partman-lvm).
We would probably want to have the user preseed this template to "true" if 
he wants to delete without confirmation, so the test if LVM was preseeded 
would no longer be needed.

Again, you don't have to be the person to add this, but that is basically 
what we need for the final solution (at least as I see it).

> if the lvm check finds lvm volumes on the disk, it will check that
> these volume groups are not spanning multiple disks, if they do it will
> fail with the same error as before.

The current error should then probably be rewritten slightly to better 
describe the actual error situation.

> if it finds that the vg is isolated to the disk, preseeded to be
> erased, it removes all Logicalvolumes, and VolumeGroups on that disk.

The basic algorithm looks OK, but you should probably try to use the 
general functions already available in lvm_tools.sh (part of the 
partman-lvm package) instead of the direct calls to pvs and vgs.

Cheers,
FJP


pgpC8TFmYGJQZ.pgp
Description: PGP signature


Bug#375491: patch suggestion

2006-08-21 Thread Ronny Aasen

Hello

I have written a patch that i hope could help on this issue.
it can probably be santized, or rewritten in a better way, but it works 
for me as it looks now.


what it does is basicaly.
it checks that it's beeing run preseeded, if not it does nothing.
if the lvm check finds lvm volumes on the disk, it will check that these 
volume groups are not spanning multiple disks, if they do it will fail 
with the same error as before.
if it finds that the vg is isolated to the disk, preseeded to be erased, 
it removes all Logicalvolumes, and VolumeGroups on that disk.



Ronny Aasen


=== patch 
[EMAIL PROTECTED]:~/svn/partman/partman-auto-lvm$ svn diff
Index: autopartition-lvm
===
--- autopartition-lvm   (revision 40105)
+++ autopartition-lvm   (working copy)
@@ -26,10 +26,42 @@
   log-output -t update-dev update-dev
fi

+
# Check if the device already contains any physical volumes
realdev=$(mapdevfs "$(cat $dev/device)")
if pv_on_device "$realdev"; then
-   bail_out pv_on_device
+   # If we are beeing preseeded with partman-auto-lv/disk, then try 
to make sure lv's

+   # and vg's are removed from the disk in question.
+   db_get partman-auto-lvm/disk
+   diskseed=$(mapdevfs $RET)
+   if [ "$diskseed" = "$realdev" ] ;then
+   #what volume groups is on any of the the target disk 
partitions.
+   targetvolumegroups=`pvs --noheading --separator=";" | 
grep $realdev | cut -d";" -f2`

+   for vgroup in $targetvolumegroups
+   do
+   #make sure the volume groups on the target disk 
don't span any other disks.
+   if [ "1" -ne `vgs --noheading --separator=";"| 
grep $vgroup | cut -d";" -f2` ] ;then

+   log-output -t partman-auto-lvs vgs
+   bail_out pv_on_device
+   fi
+   done
+
+   #it should now be safe to remove the vg's on the target 
disks

+
+   #remove lv's  from the target vg's.
+   for vgroup in $targetvolumegroups
+   do
+   for lv in `vgs --noheadings -o lv_name $vgroup`
+   do
+   #remove the logical volumes on the 
volume group
+   log-output -t partman-auto-lvm lvremove 
/dev/$vgroup/$lv

+   done
+   #remove the volume group
+   log-output -t partman-auto-lvm vgremove $vgroup
+   done
+   else
+   bail_out pv_on_device
+   fi
fi

choose_recipe "$free_size" lvm || exit $?



--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]