[Yaird-devel] minor dmraid fixes, now should be really harmless.

Marco Amadori marco.amadori at gmail.com
Sun Dec 4 20:48:51 UTC 2005


=== added file 'perl/DmRaidDev.pm'
--- /dev/null
+++ perl/DmRaidDev.pm
@@ -0,0 +1,48 @@
+#!perl -w
+#
+# DmRaidDev -- Base dm-raid Volume information
+#   Copyright (C) 2005  Erik van Konijnenburg, Marco Amadori
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+#
+
+use strict;
+use warnings;
+use Base;
+package DmRaidDev;
+use base 'Obj';
+
+sub fill {
+	my $self = shift;
+	$self->SUPER::fill();
+	$self->takeArgs ('path', 'devno', 'dmformat',  'devices');
+}
+
+sub path     { return $_[0]->{path};     }
+sub devno    { return $_[0]->{devno};    }
+sub dmformat { return $_[0]->{dmformat}; }
+sub devices  { return $_[0]->{devices};  }
+
+sub string {
+	my $self = shift;
+	my $path = $self->path;
+	my $devno = $self->devno;
+	my $dmformat = $self->dmformat;
+	my $devices = join (',', @{$self->devices});
+	
+	return "$path($devno) = $dmformat at $devices";
+}
+
+1;

=== added file 'perl/DmRaidTab.pm'
--- /dev/null
+++ perl/DmRaidTab.pm
@@ -0,0 +1,143 @@
+#!perl -w
+#
+# DmRaidTab -- encapsulate dmraid --raid_devices output
+#   Copyright (C) 2005  Erik van Konijnenburg, Marco Amadori, Mattia Dongili
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+#
+use strict;
+use warnings;
+use Base;
+use Conf;
+use DmRaidDev;
+use ActiveBlockDevTab;
+
+package DmRaidTab;
+
+my $dmraidTab = undef;
+
+sub init () {
+	if (defined ($dmraidTab)) {
+		return;
+	}
+
+	$dmraidTab = [];
+	
+	# examples:
+	# # dmraid --raid_devices
+	# /dev/sda: nvidia, "nvidia_jbdaccab", mirror, ok, 160086526 sectors, data@ 
0
+	# /dev/sdb: nvidia, "nvidia_jbdaccab", mirror, ok, 160086526 sectors, data@ 
0
+	#
+	# # dmraid -s -c
+	# nvidia_jbdaccab
+	#
+	# # ls /dev/mapper/nvidia_jbdaccab*
+	# /dev/mapper/nvidia_jbdaccab  /dev/mapper/nvidia_jbdaccab1  
+	# /dev/mapper/nvidia_jbdaccab5 /dev/mapper/nvidia_jbdaccab6
+	# /dev/mapper/nvidia_jbdaccab7 
+
+	my ($rc, $lines) = Base::runCmd (
+		missingOk => 1,
+		cmd => ['/sbin/dmraid', '-s', '-c']);
+	if (! defined ($lines) || ( @{$lines}[0] =~ m!^No RAID disks$! ) ) {
+		return;
+	}	
+	for my $line (@{$lines}) {
+		
+		my $devname = $line;
+		my @splitstr = split(/_/, $line);
+		my $dmformat = $splitstr[0];
+			
+		# # dmraid --raid_devices --format nvidia -cpath
+		# /dev/sda
+		# /dev/sdb
+
+		my @devices = ();
+		my ($rc2, $lines2) = Base::runCmd (
+			missingOk => 1,
+			cmd => ['/sbin/dmraid', '--raid_devices', '--format', $dmformat , 
'-cpath']);
+		if (! defined ($lines2)) {
+			return;
+		}
+		for my $line2 (@{$lines2}) {
+			my $dmraidDevno = Base::devno ($line2);
+			push @devices, $dmraidDevno;
+		}
+		
+		my $basepath = "/dev/mapper/";
+		my $path = $basepath . $devname;
+		my $devno = Base::devno ($path);
+
+		my $descr = DmRaidDev->new (
+				path => $path,
+				devno => $devno,
+				dmformat => $dmformat,
+				devices =>  [ @devices ]
+				);
+		push @{$dmraidTab}, $descr;
+
+		# dmraid does not have a good sysfs interface, so 
+		#  Plan::tryParent will fail; hence we duplicate the
+		#  parent partition stuff here. When dmraid will support sys/block more
+		#  we should remove this code
+		# Put all infos in here now:
+
+		my ($rc3, $partitions) = Base::runCmd (
+			missingOk => 1,
+			cmd => ['/usr/bin/find',  $basepath , '-name', $devname . '?*' ]);
+		if (! defined ($partitions)) {
+			return;
+		}
+		for my $partition (@{$partitions}) {
+			my $pdevno = Base::devno ($partition);
+			my $pdescr = DmRaidDev->new (
+				path => $partition,
+				devno => , $pdevno,
+				dmformat => $dmformat,
+				devices =>  [ @devices ]
+				);
+			push @{$dmraidTab}, $pdescr;	
+		}
+		
+	}
+}
+
+sub all () {
+	init;
+	return $dmraidTab;
+}
+
+sub findFormatByDevno ($) {
+	my ($devno) = @_;
+	for my $ed (@{all()}) {
+		if ($ed->devno() eq $devno) {
+			return $ed->dmformat();
+		}
+	}
+	return undef;
+}	
+
+
+sub findByDevno ($) {
+	my ($devno) = @_;
+	for my $ed (@{all()}) {
+		if ($ed->devno() eq $devno) {
+			return $ed;
+		}
+	}
+	return undef;
+}
+
+1;

=== modified file 'perl/ActiveBlockDev.pm'
--- perl/ActiveBlockDev.pm
+++ perl/ActiveBlockDev.pm
@@ -87,10 +87,13 @@
 			if ($p =~ m!^/dev/mapper/([^/]*)$!
 			   	||$p =~ m!^/dev/evms/.*$!)
 			{
-				if (defined ($match)) {
-					Base::fatal ("Don't know how to choose between $match and $p for 
$name");
-				}
-				$match = $p;
+				if (defined ($match) && !($p =~ m!^/dev/evms/\..*$!))
+			        {
+			        	Base::fatal ("Don't know how to choose between $match and $p for 
$name");
+			        } else
+			        {
+			                $match = $p;
+			        }
 			}
 		}
 		if (! defined ($match)) {

=== modified file 'perl/Plan.pm'
--- perl/Plan.pm
+++ perl/Plan.pm
@@ -28,6 +28,7 @@
 use Hardware;
 use ModProbe;
 use RaidTab;
+use DmRaidTab;
 use EvmsTab;
 use Image;
 use ActionList;
@@ -88,6 +89,7 @@
 	$ok || ($ok = tryEvms ($actions,$device,[$device,@{$working}]));
 	$ok || ($ok = tryDmCrypt ($actions,$device,[$device,@{$working}]));
 	$ok || ($ok = tryLvm ($actions,$device,[$device,@{$working}]));
+	$ok || ($ok = tryDmRaid ($actions,$device,[$device,@{$working}]));
 	$ok || ($ok = tryRaid ($actions,$device,[$device,@{$working}]));
 	$ok || ($ok = tryHardware ($actions,$device,[$device,@{$working}]));
 	if (! $ok) {
@@ -443,6 +445,45 @@
 	my $evmsVersion = EvmsTab::findVersion ();
 	$actions->add ("evms_activate", $name, evmsVersion => $evmsVersion);
 	# root device should be active now
+	return 1;
+}
+
+#
+# tryDmRaid -- To start a dm-raid device, start the underlying hardware,
+# load raid module, then do dm-raid -r && dmraid -a y.
+#
+#
+sub tryDmRaid ($$$) {
+	my ($actions, $device, $working) = @_;
+
+	my $name = $device->name;
+	my $devno = $device->devno;
+	if ($name !~ /^dm-\d+$/) {
+		return 0;
+	}
+
+	my $rd = DmRaidTab::findByDevno ($devno);
+	if (! defined ($rd)) {
+		# Nope, it's not a disk known to dm-raid.
+		return 0;
+	}
+
+	for my $d (@{$rd->devices()}) {
+		my $pdev = ActiveBlockDevTab::findByDevno ($d);
+		addDevicePlan ($actions, $pdev, $working);
+	}
+
+	# This one used *always* by dm-raid.
+	ModProbe::addModules ($actions, [ "dm-mod" ]);
+
+	# Adding all raid's km for now, we could scan more to right match needed
+	# kernel modules for 0.13
+
+	ModProbe::addModules ($actions, [ "raid0", "raid1",
+		"raid10", "dm-mirror", "linear"]);
+
+	my $dmformat = DmRaidTab::findFormatByDevno ($devno);
+	$actions->add ("dm_raid" , $name, dmraidFormat => $dmformat);
 	return 1;
 }
 
@@ -721,3 +762,4 @@
 }
 
 1;
+

=== modified file 'perl/TestSet.pm'
--- perl/TestSet.pm
+++ perl/TestSet.pm
@@ -29,6 +29,7 @@
 use LvmTab;
 use Hardware;
 use RaidTab;
+use DmRaidTab;
 use EvmsTab;
 use InputTab;
 use Image;
@@ -127,6 +128,14 @@
 sub testRaidDevices () {
 	print "Raid devices:\n";
 	for my $rd (@{RaidTab::all()}) {
+		my $str = $rd->string;
+		print "\t$str\n";
+	}
+}
+
+sub testDmRaidDevices () {
+	print "Raid devices (dmraid):\n";
+	for my $rd (@{DmRaidTab::all()}) {
 		my $str = $rd->string;
 		print "\t$str\n";
 	}
@@ -229,6 +238,7 @@
 	testActiveBlockDevPartitions ();
 	testEvms ();
 	testLvm ();
+	testDmRaidDevices ();
 	testHardware ();
 	testRaidDevices();
 	testInterpretation ();

=== modified file 'templates/Debian.cfg'
--- templates/Debian.cfg
+++ templates/Debian.cfg
@@ -239,6 +239,8 @@
 		# but everything it encounters.
 		#
 		TREE "/lib/evms/<TMPL_VAR NAME=evmsVersion>"
+		FILE "/sbin/swapon"
+		DIRECTORY "/var/log"
 		FILE "/sbin/evms_activate"
 		FILE "/etc/evms.conf"
 		SCRIPT "/init"
@@ -249,6 +251,23 @@
 			!	/bin/mkdir /dev/evms
 			!fi
 			!/sbin/evms_activate 
+		END SCRIPT
+	END TEMPLATE
+
+
+	TEMPLATE dm_raid
+	BEGIN
+		FILE "/sbin/dmraid"
+		SCRIPT "/init"
+		BEGIN
+			!# activate for <TMPL_VAR NAME=target>
+			!if [ ! -c /dev/mapper/control ]
+			!then
+			!	/bin/mkdir /dev/mapper
+			!	mkcdev /dev/mapper/control misc/device-mapper
+			!fi
+			!dmraid --raid_devices 
+			!dmraid --activate yes --format <TMPL_VAR NAME=dmraidFormat> 
--ignorelocking --verbose
 		END SCRIPT
 	END TEMPLATE
 


-- 
ESC:wq



More information about the Yaird-devel mailing list