summaryrefslogtreecommitdiffstats
path: root/perl-install/lvm.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/lvm.pm')
-rw-r--r--perl-install/lvm.pm55
1 files changed, 51 insertions, 4 deletions
diff --git a/perl-install/lvm.pm b/perl-install/lvm.pm
index 5bca97af9..bf212bd6f 100644
--- a/perl-install/lvm.pm
+++ b/perl-install/lvm.pm
@@ -1,4 +1,4 @@
-package lvm; # $Id: lvm.pm 268652 2010-05-13 17:09:00Z pterjan $
+package lvm;
use diagnostics;
use strict;
@@ -12,6 +12,16 @@ use devices;
use fs::type;
use run_program;
+=head1 SYNOPSYS
+
+Manage LVM (PV, VG, LV)
+
+=head1 Functions
+
+=over 4
+
+=cut
+
#- for partition_table_xxx emulation
sub new {
my ($class, $name) = @_;
@@ -29,19 +39,38 @@ sub cylinder_size {
$hd->{extent_size};
}
+=item detect_durting_install()
+
+Explicitly scan VGs.
+
+=cut
+
sub detect_during_install() {
run_program::run('lvm2', 'vgscan');
run_program::run('lvm2', 'vgchange', '-a', 'y');
}
+=item init()
+
+Loads LVM modules and scan VGs (if in installer, not in standalone tool).
+
+=cut
+
sub init() {
devices::init_device_mapper();
- detect_during_install() if $::isInstall;
+ detect_during_install() if $::isInstall || $::isLiveInstall;
1;
}
init() or log::l("lvm::init failed");
+=item lvm_cmd(...)
+
+Run a LVM command, then rescan VG.
+See run_program::run() for arguments.
+
+=cut
+
sub lvm_cmd {
if (my $r = run_program::run('lvm2', @_)) {
$r;
@@ -54,6 +83,13 @@ sub lvm_cmd {
run_program::run('lvm2', @_);
}
}
+
+=item lvm_cmd_or_die($prog, @para)
+
+Like lvm_cmd() but die if there's an error.
+
+=cut
+
sub lvm_cmd_or_die {
my ($prog, @para) = @_;
my @err;
@@ -112,6 +148,12 @@ sub lv_nb_pvs {
listlength(lv_to_pvs($lv));
}
+=item get_lvs($lvm)
+
+Return list of LVs.
+
+=cut
+
sub get_lvs {
my ($lvm) = @_;
my @l = run_program::get_stdout('lvm2', 'lvs', '--noheadings', '--nosuffix', '--units', 's', '-o', 'lv_name', $lvm->{VG_name}) =~ /(\S+)/g;
@@ -184,14 +226,15 @@ sub suggest_lv_name_from_mnt_point {
$str = "root" if $str eq '/';
$str =~ s!^/!!;
$str =~ s!/!_!g;
- $str;
+ $str =~ s! !_!g;
+ 'lv_' . $str;
}
sub suggest_lv_name {
my ($lvm, $lv) = @_;
my $list = $lvm->{primary}{normal} ||= [];
$lv->{lv_name} ||= suggest_lv_name_from_mnt_point($lv);
- $lv->{lv_name} ||= 1 + max(map { if_($_->{device} =~ /(\d+)$/, $1) } @$list);
+ $lv->{lv_name} ||= "lv_" . (1 + max(map { if_($_->{device} =~ /(\d+)$/, $1) } @$list));
}
sub lv_create {
@@ -241,4 +284,8 @@ sub create_singleton_vg {
add_to_VG($part, $lvm);
}
+=back
+
+=cut
+
1;