aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaarten Vanraes <alien@mageia.org>2016-05-16 19:09:02 +0200
committerMaarten Vanraes <alien@mageia.org>2016-05-16 19:09:02 +0200
commit86fe12c481549fa60cd21eb98741bc2b25da9b6c (patch)
tree01f477e146158fe41846cafcc31a6ad40786e69f
parent8a04da69ddbcbdb0ef1474de72a29183804eb398 (diff)
downloadmanatools-86fe12c481549fa60cd21eb98741bc2b25da9b6c.tar
manatools-86fe12c481549fa60cd21eb98741bc2b25da9b6c.tar.gz
manatools-86fe12c481549fa60cd21eb98741bc2b25da9b6c.tar.bz2
manatools-86fe12c481549fa60cd21eb98741bc2b25da9b6c.tar.xz
manatools-86fe12c481549fa60cd21eb98741bc2b25da9b6c.zip
use devicepath instead of path and id for blockdevice paths
-rw-r--r--lib/ManaTools/Shared/disk_backend/BlockDevice.pm6
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm94
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm55
3 files changed, 115 insertions, 40 deletions
diff --git a/lib/ManaTools/Shared/disk_backend/BlockDevice.pm b/lib/ManaTools/Shared/disk_backend/BlockDevice.pm
index 3221e740..f20c0fda 100644
--- a/lib/ManaTools/Shared/disk_backend/BlockDevice.pm
+++ b/lib/ManaTools/Shared/disk_backend/BlockDevice.pm
@@ -73,11 +73,7 @@ has 'devicemm' => (
has 'devicepath' => (
is => 'ro',
isa => 'Str',
- lazy => 1,
- default => sub {
- my $self = shift;
- return '/dev/'. $self->id();
- }
+ required => 1,
);
#=============================================================
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm
index 9cd81c36..6d12cfe5 100644
--- a/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm
@@ -54,6 +54,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
use Moose;
use File::Basename;
+use ManaTools::Shared::disk_backend::Part;
extends 'ManaTools::Shared::disk_backend::Plugin';
@@ -88,7 +89,16 @@ override ('probe', sub {
}
for my $dfile (glob("/sys/bus/scsi/devices/[0-9]*")) {
for my $bdfile (glob($dfile ."/block/*")) {
- my $io = $self->parent->mkio('Disk', {id => basename($bdfile), path => $bdfile});
+ # try or create child as a disk
+ my $p = $part->trychild(ManaTools::Shared::disk_backend::Part->CurrentState, sub {
+ my $part = shift;
+ my $parameters = shift;
+ return ($part->devicepath() =~ s'^.+/''r eq $parameters->{devicepath} =~ s'^.+/''r);
+ }, 'Disk', {plugin => $self, devicepath => $bdfile, loaded => undef, saved => undef});
+ # trigger the changedpart
+ $p->changedpart(ManaTools::Shared::disk_backend::Part->CurrentState);
+ # create the IO
+ my $io = $self->parent->mkio('Disk', {id => basename($bdfile), devicepath => $bdfile});
if (!defined($io) || !$part->out_add($io)) {
$err = 1;
}
@@ -109,14 +119,10 @@ has '+type' => (
default => 'Disk'
);
-has 'path' => (
- is => 'ro',
- isa => 'Str',
- required => 1,
+has '+devicepath' => (
trigger => sub {
my $self = shift;
my $value = shift;
- $self->prop('path', $value);
$self->prop_from_file('ro', $value .'/ro');
$self->prop_from_file('removable', $value .'/removable');
$self->prop_from_file('size', $value .'/size');
@@ -167,13 +173,77 @@ class_has '+out_restriction' => (
);
override('label', sub {
- my $self = shift;
- my $label = super;
- if ($self->out_length() < 1) {
- return $label;
- }
- return $label .'('. join(',', sort map { $_->id(); } $self->out_list()) .')';
+ my $self = shift;
+ my $label = super;
+ if ($self->out_length() < 1) {
+ return $label;
+ }
+ return $label .'('. join(',', sort map { $_->id(); } $self->out_list()) .')';
});
+package ManaTools::Shared::disk_backend::Part::Disk;
+
+use Moose;
+
+extends 'ManaTools::Shared::disk_backend::Part';
+
+use MooseX::ClassAttribute;
+
+with 'ManaTools::Shared::disk_backend::BlockDevice';
+
+class_has '+type' => (
+ default => 'Disk'
+);
+
+has '+devicepath' => (
+ trigger => sub {
+ my $self = shift;
+ my $value = shift;
+ $self->prop_from_file('ro', $value .'/ro');
+ $self->prop_from_file('removable', $value .'/removable');
+ $self->prop_from_file('size', $value .'/size');
+ $self->prop('present', ($self->prop('removable') == 0 || $self->prop('size') > 0) ? 1 : 0);
+ $self->prop_from_file('dev', $value .'/dev');
+ $self->sync_majorminor();
+
+ # additional data
+ my $dpath = $value =~ s,/[^/]+/[^/]+$,,r;
+ $self->prop_from_file('vendor', $dpath .'/vendor');
+ $self->prop_from_file('model', $dpath .'/model');
+ $self->prop_from_file('type', $dpath .'/type');
+ }
+);
+
+class_has '+order' => (
+ default => sub {
+ sub {
+ my $self = shift;
+ my $part = shift;
+ return ($self->devicepath() =~ s'^.+/''r cmp $part->devicepath() =~ s'^.+/''r);
+ }
+ }
+);
+
+class_has '+restrictions' => (
+ default => sub {
+ return {
+ sibling => sub {
+ my $self = shift;
+ my $part = shift;
+ return $part->isa('ManaTools::Shared::disk_backend::Part::Disk');
+ },
+ previous => sub {
+ my $self = shift;
+ my $part = shift;
+ return $part->isa('ManaTools::Shared::disk_backend::Part::Disk');
+ },
+ next => sub {
+ my $self = shift;
+ my $part = shift;
+ return $part->isa('ManaTools::Shared::disk_backend::Part::Disk');
+ },
+ }
+ }
+);
1;
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm
index b5ee2273..483f024c 100644
--- a/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm
@@ -101,6 +101,7 @@ override ('changedpart', sub {
my $self = shift;
my $part = shift;
my $partstate = shift;
+ $self->D("$self: called changepart for partitions: $part, $partstate");
## LOAD
# read the partition table
@@ -113,7 +114,7 @@ override ('changedpart', sub {
return 1 if (!defined($pt));
# look or make the PartitionTable as a child of the BlockDevice
- my $parttable = $part->trychild($partstate, undef, 'PartitionTable', {probed => undef, saved => undef});
+ my $parttable = $part->trychild($partstate, undef, 'PartitionTable', {plugin => $self, probed => undef, saved => undef});
my @changedparts = ($parttable);
# make the PartitionElement children
@@ -122,8 +123,8 @@ override ('changedpart', sub {
my $child = $parttable->trychild($partstate, sub {
my $self = shift;
my $parameters = shift;
- return ($self->id() eq $parameters->{id});
- },'PartitionElement', {id => $p->{'file'} =~ s'^.+/''r, probed => undef, saved => undef});
+ return ($self->devicepath() =~ s'^.+/''r eq $parameters->{devicepath} =~ s'^.+/''r);
+ },'PartitionElement', {plugin => $self, devicepath => $p->{'file'}, probed => undef, saved => undef});
# set the necessary properties
my @stat = stat($p->{'file'});
@@ -141,8 +142,8 @@ override ('changedpart', sub {
}
# trigger changedpart on all children for other plugins to load further
- for my $part (@changedparts) {
- $part->changedpart($partstate);
+ for my $p (@changedparts) {
+ $p->changedpart($partstate);
}
}
@@ -156,6 +157,7 @@ override ('changedpart', sub {
# only devices that are present
return 1 if ($part->has_prop('present') && !$part->prop('present'));
+ $self->D("$self: called changepart for probing partitiontable on $part: size ". $part->prop('size'));
# only devices with positive size
return 1 if ($part->prop('size') <= 0);
@@ -164,11 +166,11 @@ override ('changedpart', sub {
# since there is none, it'll just recreate the partition table (probably with the loaded state settings) anyway
#
# in any case, if there are no partition entries (in-kernel), we exit early.
- my @devices = glob($part->path(). "/". $part->id() ."*");
+ my @devices = map { $_ =~ s'/size$''r } glob($part->devicepath(). "/*/size");
return 1 if (!scalar(@devices));
# look or make the PartitionTable as a child of the BlockDevice
- my $parttable = $part->trychild($partstate, undef, 'PartitionTable', {loaded => undef, saved => undef});
+ my $parttable = $part->trychild($partstate, undef, 'PartitionTable', {plugin => $self, loaded => undef, saved => undef});
my @changedparts = ($parttable);
# find subdevices in /sys/
@@ -178,25 +180,16 @@ override ('changedpart', sub {
my $child = $parttable->trychild($partstate, sub {
my $self = shift;
my $parameters = shift;
- return ($self->id() eq $parameters->{id});
- },'PartitionElement', {id => $pf =~ s'^.+/''r, loaded => undef, saved => undef});
-
- $child->prop_from_file('sectors', $pf . '/size');
- # sectors are always 512 bytes here!
- $child->prop('size', $child->prop('sectors') * 512);
- $child->prop_from_file('start', $pf . '/start');
- $child->prop_from_file('ro', $pf . '/ro');
- $child->prop_from_file('dev', $pf . '/dev');
- $child->sync_majorminor();
- $child->prop('num', $pf =~ s/^.+([0-9]+)$/$1/r);
+ return ($self->devicepath() =~ s'^.+/''r eq $parameters->{devicepath} =~ s'^.+/''r);
+ },'PartitionElement', {plugin => $self, devicepath => $pf, loaded => undef, saved => undef});
# add the child to the changedparts
push @changedparts, $child;
}
# trigger changedpart on all children for other plugins to load further
- for my $part (@changedparts) {
- $part->changedpart($partstate);
+ for my $p (@changedparts) {
+ $p->changedpart($partstate);
}
}
@@ -310,8 +303,8 @@ override ('probeio', sub {
my $err = 0;
my $partitions = 0;
# find subdevices in /sys/
- for my $pf (glob($io->path(). "/". $io->id() ."*")) {
- my $io = $self->parent->mkio('Partition', {id => $pf =~ s'^.+/''r});
+ for my $pf (glob($io->devicepath(). "/". $io->id() ."*")) {
+ my $io = $self->parent->mkio('Partition', {id => $pf =~ s'^.+/''r, devicepath => $pf});
$io->prop_from_file('sectors', $pf . '/size');
# sectors are always 512 bytes here!
$io->prop('size', $io->prop('sectors') * 512);
@@ -427,11 +420,27 @@ class_has '+order' => (
return sub {
my $self = shift;
my $part = shift;
- return $self->prop('offset') <=> $part->prop('offset');
+ $self->plugin->D("compare for ordering: $self(". join(',', $self->properties()) .") and $part(". join(',', $part->properties()) .")");
+ return $self->prop('start') <=> $part->prop('start');
}
}
);
+has '+devicepath' => (
+ trigger => sub {
+ my $self = shift;
+ my $value = shift;
+ $self->prop_from_file('sectors', $value . '/size');
+ # sectors are always 512 bytes here!
+ $self->prop('size', $self->prop('sectors') * 512);
+ $self->prop_from_file('start', $value . '/start');
+ $self->prop_from_file('ro', $value . '/ro');
+ $self->prop_from_file('dev', $value . '/dev');
+ $self->sync_majorminor();
+ $self->prop('num', $value =~ s/^.+([0-9]+)$/$1/r);
+ }
+);
+
class_has '+restrictions' => (
default => sub {
return {