summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2002-08-11 17:04:06 +0000
committerPascal Rigaux <pixel@mandriva.com>2002-08-11 17:04:06 +0000
commit2e7a857a435d34c9da3f7f05e7b762f91935f80c (patch)
tree1435ea8b1429603456c62c365ec9f156d7c8999f
parentc2e3c2a0ca9dcd04d555cc6ae0bca2cc58bbd6d8 (diff)
downloaddrakx-2e7a857a435d34c9da3f7f05e7b762f91935f80c.tar
drakx-2e7a857a435d34c9da3f7f05e7b762f91935f80c.tar.gz
drakx-2e7a857a435d34c9da3f7f05e7b762f91935f80c.tar.bz2
drakx-2e7a857a435d34c9da3f7f05e7b762f91935f80c.tar.xz
drakx-2e7a857a435d34c9da3f7f05e7b762f91935f80c.zip
- vg_add: do not vgremove the old_name anymore, this is dangerous and should not happen
- lv_create: fix bug when {primary}{normal} didn't exist - use run_program::get_stdout instead of `` - create and use run() and run_or_die() which takes care of running vgscan again when needed - rename LVMname to VG_name
-rw-r--r--perl-install/lvm.pm58
1 files changed, 34 insertions, 24 deletions
diff --git a/perl-install/lvm.pm b/perl-install/lvm.pm
index 327e07fe2..01e8e55a6 100644
--- a/perl-install/lvm.pm
+++ b/perl-install/lvm.pm
@@ -30,6 +30,22 @@ sub init {
run_program::run('vgchange', '-a', 'y');
}
+sub run {
+ if (my $r = run_program::run(@_)) {
+ $r;
+ } else {
+ $? >> 8 == 98 or return;
+
+ #- sometimes, it needs running vgscan again, doing so:
+ run_program::run('vgscan');
+ run_program::run(@_);
+ }
+}
+sub run_or_die {
+ my ($prog, @para) = @_;
+ run($prog, @para) or die "$prog failed\n";
+}
+
sub check {
my ($in) = @_;
@@ -43,51 +59,45 @@ sub check {
sub get_vg {
my ($part) = @_;
my $dev = expand_symlinks(devices::make($part->{device}));
- install_any::check_prog ("pvdisplay") if $::isInstall;
- (split(':', `pvdisplay -c $dev`))[1];
+ (split(':', run_program::get_stdout('pvdisplay', '-c', $dev)))[1];
}
sub update_size {
my ($lvm) = @_;
- install_any::check_prog ("vgdisplay") if $::isInstall;
- my @l = split(':', `vgdisplay -c -D $lvm->{LVMname}`);
+ my @l = split(':', run_program::get_stdout('vgdisplay', '-c', '-D', $lvm->{VG_name}));
$lvm->{totalsectors} = ($lvm->{PE_size} = $l[12]) * $l[13];
}
sub get_lvs {
my ($lvm) = @_;
- install_any::check_prog ("vgdisplay") if $::isInstall;
- my @l = `vgdisplay -v -D $lvm->{LVMname}`;
- install_any::check_prog ("lvdisplay") if $::isInstall;
+ my @l = run_program::get_stdout('vgdisplay', '-v', '-D', $lvm->{VG_name});
$lvm->{primary}{normal} =
[
map {
my $type = -e "/dev/$_" && fsedit::typeOfPart("/dev/$_");
+ my $info = run_program::get_stdout('lvdisplay', '-D', '-c', "/dev/$_");
+
{ device => $_,
type => $type || 0x83,
- size => (split(':', `lvdisplay -D -c /dev/$_`))[6] }
- } map { m|^LV Name\s+/dev/(\S+)| ? $1 : () } @l
+ size => (split(':', $info))[6] }
+ } map { if_(m|^LV Name\s+/dev/(\S+)|, $1) } @l
];
}
sub vg_add {
my ($part) = @_;
- if (my $old_name = get_vg($part)) {
- run_program::run('vgchange', '-a', 'n', $old_name);
- run_program::run('vgremove', $old_name);
- }
my $dev = expand_symlinks(devices::make($part->{device}));
- run_program::run_or_die('pvcreate', '-y', '-ff', $dev);
- my $prog = run_program::run('vgdisplay', $part->{lvm}) ? 'vgextend' : 'vgcreate';
- run_program::run_or_die($prog, $part->{lvm}, $dev);
+ run_or_die('pvcreate', '-y', '-ff', $dev);
+ my $prog = run('vgdisplay', $part->{lvm}) ? 'vgextend' : 'vgcreate';
+ run_or_die($prog, $part->{lvm}, $dev);
}
sub vg_destroy {
my ($lvm) = @_;
is_empty_array_ref($lvm->{primary}{normal}) or die _("Remove the logical volumes first\n");
- run_program::run('vgchange', '-a', 'n', $lvm->{LVMname});
- run_program::run_or_die('vgremove', $lvm->{LVMname});
+ run('vgchange', '-a', 'n', $lvm->{VG_name});
+ run_or_die('vgremove', $lvm->{VG_name});
foreach (@{$lvm->{disks}}) {
delete $_->{lvm};
$_->{isFormatted} = 0;
@@ -98,7 +108,7 @@ sub vg_destroy {
sub lv_delete {
my ($lvm, $lv) = @_;
- run_program::run_or_die('lvremove', '-f', "/dev/$lv->{device}");
+ run_or_die('lvremove', '-f', "/dev/$lv->{device}");
my $list = $lvm->{primary}{normal};
@$list = grep { $_ != $lv } @$list;
@@ -106,10 +116,10 @@ sub lv_delete {
sub lv_create {
my ($lvm, $lv) = @_;
- my $list = $lvm->{primary}{normal};
+ my $list = $lvm->{primary}{normal} ||= [];
my $nb = 1 + max(map { basename($_->{device}) } @$list);
- $lv->{device} = "$lvm->{LVMname}/$nb";
- run_program::run_or_die('lvcreate', '--size', int($lv->{size} / 2) . 'k', '-n', $nb, $lvm->{LVMname});
+ $lv->{device} = "$lvm->{VG_name}/$nb";
+ run_or_die('lvcreate', '--size', int($lv->{size} / 2) . 'k', '-n', $nb, $lvm->{VG_name});
$lv->{notFormatted} = 1;
$lv->{isFormatted} = 0;
push @$list, $lv;
@@ -117,8 +127,8 @@ sub lv_create {
sub lv_resize {
my ($lv, $oldsize) = @_;
- run_program::run_or_die($oldsize > $lv->{size} ? ('lvreduce', '-f') : 'lvextend',
- '--size', int($lv->{size} / 2) . 'k', "/dev/$lv->{device}");
+ run_or_die($oldsize > $lv->{size} ? ('lvreduce', '-f') : 'lvextend',
+ '--size', int($lv->{size} / 2) . 'k', "/dev/$lv->{device}");
}
1;