[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#335230: More stub code



I've been able to setup an almost-working evms box (at least evms_query
reports useful data).

I tried following Erik's suggestions and also implemented part of the
init() method and reworked some of Marco's code.
Some parts are still to be finished, but I'd like some feedback
expecially on evms_query commands and the expected content of some
EvmsDev properties.

The init() function will try to discover all the evms devices,
starting from `evms_query volumes` it will build an array of EvmsTab-s
reporting the devno string as reported by evms_query info
("$major:$minor"), the volume name and a list of disks.
I'm currently interested in understanding which information we need to
gather, the tryEvms can be fixed later (it'll probably need to loop on
the EvmsDev->devices array as the tryRaid does).
Am I on the right way?

I'll add also the plugins support shortly.

So far you can end up having something like the following (manually written,
can't test now as the evms PC is at my workplace):

           +-- Evms Volume Name
          /                      +-- Evms Device Number
         /                      /               +-- Evms Disks
 [      /                      /               /
   { path=>'/dev/evms/root', devno=>'0:0', ('/dev/hda','/dev/hdb')}
   { path=>'/dev/evms/home', devno=>'0:1', ...}
   { path=>'/dev/evms/usr',  devno=>'1:0', ...}
   ...
 ]

(I'm attaching the two Evms{Tab,Dev}.pm and a diff against
(svn://svn.debian.org/kernel/dists/trunk/utils/yaird) of the rest.
Code is untested, I'll try it out tomorrow.

-- 
mattia
:wq!
#!perl -w
#
# Evms -- encapsulate evms_gather 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;
package Evms;
use base 'Obj';

sub fill {
	my $self = shift;
	$self->SUPER::fill();
	$self->takeArgs ('path', 'devno', 'disks', 'plugins');
}

sub path { return $_[0]->{path}; }
sub devno  { return $_[0]->{devno}; }
sub disks  { return $_[0]->{disks}; }
sub plugins  { return $_[0]->{plugins}; } # not implemented yet


sub string {
	my $self = shift;
	my $path = $self->path;
	my $devno = $self->devno;
	my $disks = join (',', @{$self->disks});
	my $plugins = join (',', @{$self->plugins});
	return "$path($devno) = $plugins on $disks";
}

1;
#!perl -w
#
# Evms -- encapsulate evms_gather 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 EvmsDev;
package EvmsTab;

my $evmsTab = undef;
my $evmsVersion = undef;

sub init () {
	if (defined ($evmsTab)) {
		return;
	}

	$evmsTab = [];
	my $in;
	#
	# $ evms_query volumes
	# /dev/evms/e3
	# /dev/evms/e1
	# /dev/evms/e2
	# /dev/evms/e4
	#
	if (! open ($in, "-|", "/usr/sbin/evms_query volumes")) {
		Base::fatal ("Can't read 'evms_query volumes' output");
	}
	my @lines = <$in>;
	if (! close ($in)) {
		Base::fatal ("Could not read 'evms_query volumes' output");
	}

	#
	# foreach volume read extended info
	# 
	my $evmsVolName;
	my $evmsDevno;
	my @evmsDevices;

	for my $line (@lines) {

		chomp $line;

		# $ evms_query info /dev/evms/e3
		# Name: /dev/evms/e3
		# Type: Volume
		# Device Number: 0:0
		# Size (sectors): 19531006
		#
		if (! open ($in, "-|", "/usr/sbin/evms_query info $line")) {
			Base::fatal ("Can't read 'evms_query info' output");
		}
		my @infoLines = <$in>;
		if (! close ($in)) {
			Base::fatal ("Could not read 'evms_query info' output");
		}
		for my $infoLine (@infoLines) {
			chomp $infoLine;
			$evmsVolName = $1 if ($infoLine =~ /^Name: (.*)/);
			$evmsDevno = $1 if ($infoLine =~ /^Device Number: (.*)/);
		}
		if (! defined($evmsVolName)) {
			Base::fatal ("Missing 'Name' attribute in 'evms_query info' output");
		}
		if (! defined($evmsDevno)) {
			Base::fatal ("Missing 'Device Number' attribute in 'evms_query info' output");
		}
		
		# $ evms_query disks /dev/evms/e3
		# hda
		# hdb
		# ...
		if (! open ($in, "-|", "/usr/sbin/evms_query disks $evmsVolName")) {
			Base::fatal ("Can't read 'evms_query disks' output");
		}
		@evmsDevices = <$in>;
		if (! close ($in)) {
			Base::fatal ("Could not read 'evms_query disks' output");
		}
		if (scalar(@evmsDevices) == 0) {
			Base::fatal ("Unable to detect $evmsVolName devices in 'evms_query disks' output");
		}

		my $descr = EvmsDev->new (
				path => $evmsVolName,
				devno => $evmsDevno,
				devices => map { chomp; "/dev/$_" } @evmsDevices
				);
		push @{$evmsTab}, $descr;
	}

	# evmsVersion:
	#
	# $ evms_query info
	# EVMS Version: 2.5.3
	# EVMS Engine API Version: 10.1.0
	if (! open ($in, "-|", "/usr/sbin/evms_query info")) {
		Base::fatal ("Can't read evms_query output");
	}
	@lines = <$in>;
	if (! close ($in)) {
		Base::fatal ("Could not read evms_query output");
	}
	for my $line (@lines) {
		chomp $line;
		$evmsVersion = $1 if ($line =~ /^EVMS Version: (.*)/);
	}
}

sub all () {
	init;
	return $evmsTab;
}

sub findDisksByName ($) {
	init;
	# TODO
}

sub findDisksDevNo ($) {
	init;
	# TODO
}

sub findVersion () {
	init;
	return $evmsVersion;
}

1;
Index: perl/Plan.pm
===================================================================
--- perl/Plan.pm	(revision 4603)
+++ perl/Plan.pm	(working copy)
@@ -1,7 +1,7 @@
 #!perl -w
 #
 # Plan -- high-level stuff
-#   Copyright (C) 2005  Erik van Konijnenburg
+#   Copyright (C) 2005  Erik van Konijnenburg, 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
@@ -28,6 +28,7 @@
 use Hardware;
 use ModProbe;
 use RaidTab;
+use EvmsTab;
 use Image;
 use ActionList;
 use CryptTab;
@@ -84,6 +85,7 @@
 
 	my $ok = 0;
 	$ok || ($ok = tryParent ($actions,$device,[$device,@{$working}]));
+	$ok || ($ok = tryEvms ($actions,$device,[$device,@{$working}]));
 	$ok || ($ok = tryDmCrypt ($actions,$device,[$device,@{$working}]));
 	$ok || ($ok = tryLvm ($actions,$device,[$device,@{$working}]));
 	$ok || ($ok = tryRaid ($actions,$device,[$device,@{$working}]));
@@ -396,7 +398,33 @@
 	return 1;
 }
 
+#
+# tryEvms -- 
+#
+sub tryEvms ($$$) {
+	my ($actions, $device, $working) = @_;
 
+	my $name = $device->name; # If name is like /dev/evms/root, if is like dm-3 I'm lost
+	if ($name !~ /^dm-\d+$/) {
+		return 0;
+	}
+
+	for my $evmsDisk (@{Evms::findDisksByName($name)}) 
+	{
+		my $pdev = ActiveBlockDevTab::findByPath ($evmsDisk);
+		my $rc = tryHardware ($actions, $pdev, $working);
+		if ($rc !~ 1) {
+			# Base::fatal ("Can't find EVMS info for $name");
+			return 0;
+		}
+	}
+	my $version = Evms::findVersion ();
+	ModProbe::addModules ($actions, [ "dm-mod" ]);
+	$actions->add ("evms_activate", $version);
+
+	return 1;
+}
+
 #
 # tryHardware -- for devices that just want some modules loaded.
 #
Index: perl/TestSet.pm
===================================================================
--- perl/TestSet.pm	(revision 4603)
+++ perl/TestSet.pm	(working copy)
@@ -131,6 +131,14 @@
 	}
 }
 
+sub testEvms () {
+	print "Evms devices:\n";
+	for my $ev (@{EvmsTab::all()}) {
+		my $str = $ev->string;
+		print "\t$str\n";
+	}
+}
+
 sub testInput () {
 	print "Input devices:\n";
 	for my $inp (@{InputTab::all()}) {

Reply to: