summaryrefslogtreecommitdiffstats
path: root/perl-install/fs/dmraid.pm
blob: 6916ab324014e2bdc91154ce49f0149ff54fbb6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package fs::dmraid; # $Id$

use diagnostics;
use strict;

#-######################################################################################
#- misc imports
#-######################################################################################
use common;
use modules;
use devices;
use fs::type;
use fs::wild_device;
use run_program;


init() or log::l("dmraid::init failed");

sub init() {
    eval { modules::load('dm-mirror') };
    devices::init_device_mapper();
    if ($::isInstall) {
	run_program::run('dmraid', '-ay');
    }
    1;
}

sub check {
    my ($in) = @_;

    $in->do_pkgs->ensure_binary_is_installed('dmraid', 'dmraid') or return;
    init();
    1;
}

sub pvs_and_vgs() {
    map {
	my @l = split(':');
	{ pv => $l[0], format => $l[1], vg => $l[2], level => $l[3], status => $l[4] };
    } run_program::get_stdout('dmraid', '-rcc');
}

sub vgs() {
    my @l = pvs_and_vgs();
    my %vg2pv; push @{$vg2pv{$_->{vg}}}, $_->{pv} foreach @l;
    map {
	my $dev = "mapper/$_->{vg}";
	my $vg = fs::wild_device::to_subpart("/dev/$dev");
	add2hash($vg, { media_type => 'hd', prefix => $dev, bus => "dm_$_->{format}", disks => $vg2pv{$_->{vg}} });

	#- device should exist, created by dmraid(8) using libdevmapper
	#- if it doesn't, we suppose it's not in use
	if_(-e "/dev/$dev", $vg); 

    } grep { $_->{status} eq 'ok' } uniq_ { $_->{vg} } @l;
}

1;