diff options
author | Maarten Vanraes <alien@mageia.org> | 2016-07-21 16:19:41 +0200 |
---|---|---|
committer | Maarten Vanraes <alien@mageia.org> | 2016-07-21 16:19:41 +0200 |
commit | 1774a5cfb4dc04b5ff1e7be7955536998b1a96e4 (patch) | |
tree | c4afe491c4eff581c756cdb3b82030d1e33ffb18 /lib/ManaTools/Shared/disk_backend/Plugin | |
parent | c41ff5335b1bcf111faa88039ba0189bc4912424 (diff) | |
download | manatools-1774a5cfb4dc04b5ff1e7be7955536998b1a96e4.tar manatools-1774a5cfb4dc04b5ff1e7be7955536998b1a96e4.tar.gz manatools-1774a5cfb4dc04b5ff1e7be7955536998b1a96e4.tar.bz2 manatools-1774a5cfb4dc04b5ff1e7be7955536998b1a96e4.tar.xz manatools-1774a5cfb4dc04b5ff1e7be7955536998b1a96e4.zip |
remove IO subsystem
Diffstat (limited to 'lib/ManaTools/Shared/disk_backend/Plugin')
-rw-r--r-- | lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm | 311 | ||||
-rw-r--r-- | lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm | 70 | ||||
-rw-r--r-- | lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm | 109 | ||||
-rw-r--r-- | lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm | 30 | ||||
-rw-r--r-- | lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm | 195 | ||||
-rw-r--r-- | lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm | 163 | ||||
-rw-r--r-- | lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm | 40 |
7 files changed, 169 insertions, 749 deletions
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm index fa14d995..a7acdd6d 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm @@ -82,48 +82,71 @@ has 'filesystems' => ( default => sub { return {};} ); -sub get_fsdev { +sub create_subvolume { my $self = shift; - my $io = shift; - my $rio = ref($io); - - # if it's a reference, it'll be an object, so return the mm property - return $io->prop('mm') if defined($rio) && $rio; - - my @stat = stat($io); - # if it's not a block device, it's no use - return undef if (($stat[2] >> 12) != 6); - - # find the device - my $dev = $stat[6]; - my $minor = $dev % 256; - my $major = int (($dev - $minor) / 256); - return $major .':'. $minor; -} - -sub get_subvolumes { - my $self = shift; - my $io = shift; - my $path = shift; + my $part = shift; + my $partstate = shift; + my $fields = shift; + my $quotas = shift; + my $subvolumes = shift; + + # look or create part for btrfsvol + my $p = $part->trychild($partstate, sub { + my $self = shift; + my $parameters = shift; + return ($self->uuid() eq $parameters->{uuid}); + }, 'BtrfsVol', {plugin => $self, fs => $part, mountsourcepath => $fields->{path} =~ s'<FS_TREE>''r, uuid => $fields->{uuid}, loaded => undef, saved => undef}); + + # set properties + $p->prop('label', $fields->{path} =~ s'<FS_TREE>/?''r); + $p->prop('uuid', $fields->{uuid}); + $p->prop('parent_uuid', $fields->{parent_uuid}); + $p->prop('subvolid', $fields->{ID}); + $p->prop('gen', $fields->{gen}); + $p->prop('cgen', $fields->{cgen}); + $p->prop('parent', $fields->{parent}); + $p->prop('top_level', $fields->{top_level}); + + # set quota information + if (defined($quotas->{'0/'. $fields->{ID}})) { + my $item = $quotas->{'0/'. $fields->{ID}}; + $p->prop('referred', $item->{rfer}); + $p->prop('exclusive', $item->{excl}); + $p->prop('quota_referred', $item->{max_rfer}); + $p->prop('quota_exclusive', $item->{max_excl}); + } - # get the dev numbering - my $mm = $self->get_fsdev($io); + # trace parenting and fill in subvolumes in all the BtrfsVol Parts + # create missing parents too! - # no device, get out now - return undef if !defined($mm); + $self->D("$self: trigger changepart for BTRFS Volume $p: ". $p->mountsourcepath()); + $p->changedpart($partstate); - my $fs = $self->filesystems(); - # no filesystem, get out now - return undef if !defined($fs->{$mm}); + # if it has a mount point, get readonly state + # find Mount child (for subvolumes, might need to check the parent and base the path from there) + my $path = $p->find_path($partstate); + if (defined($path)) { + # if it's mounted, we can get readonly status with properties + my %fields = $self->tool_fields('btrfs', '=', 'property', 'get', "'$path'"); + $p->prop('readonly', $fields{ro} eq 'true'); + } - # this is the filesystem part - my $btrfs = $fs->{$mm}; + # set up children subvolumes + for my $id (keys %{$fields->{subvolumes}}) { + if (defined($subvolumes->{$id})) { + # TODO: add childvol tag for this one + $p->add_taglink($subvolumes->{$id}, 'childsubvol'); + } + } - my $vols = $btrfs->subvolumes(); + if (defined($subvolumes->{$p->prop('parent')})) { + # add a parent link + $p->add_taglink($subvolumes->{$p->prop('parent')}, 'parentsubvol'); + } - $vols = $btrfs->refresh($path) if scalar(@{$vols}) == 0; + $subvolumes->{$p->prop('subvolid')} = $p; - return $vols; + return $p; } #============================================================= @@ -153,23 +176,6 @@ override ('probe', sub { $part->prop_from_file('used', "$fs/allocation/data/disk_used"); $part->prop_from_file('total', "$fs/allocation/data/disk_total"); $part->prop_from_file('flags', "$fs/allocation/data/flags"); - # create an io for out - my $io = $self->parent->mkio('Btrfs', {id => $fs =~ s'^.+/''r}); - $io->prop('uuid', $fs =~ s'^.+/''r); - $part->out_add($io); - - # TODO: find the in devices (create if needed?) - for my $df (glob("$fs/devices/*")) { - open F, '<'. $df .'/dev'; - my $value = <F>; - close F; - chomp($value); - my @ios = $self->parent->findioprop('dev', $value); - if (scalar(@ios) > 0) { - $part->in_add($ios[0]); - $fss->{$ios[0]->prop('dev')} = $part; - } - } # TODO: find base mount point in order to find volumes # TODO: quotas ...? pathbased? @@ -179,64 +185,6 @@ override ('probe', sub { #============================================================= -=head2 fsprobe - -=head3 INPUT - - $io: ManaTools::Shared::disk_backend::IO | Str - $mount: ManaTools::Shared::disk_backend::Part::Mount - -=head3 OUTPUT - - ManaTools::Shared::disk_backend::IO or undef - -=head3 DESCRIPTION - - this method probes the IO to see if it fits for this - filesystem, if it does, create a new Part with this IO as in. - also create an IO (linked as the out) and return that one. - The resulting one can then be used as an in to eg: a Mount Part. - -=cut - -#============================================================= -sub fsprobe { - my $self = shift; - my $io = shift; - my $mount = shift; - my $vols = $self->get_subvolumes($io, $mount->path()); - # return undef if there are not subvolumes - return undef if !defined($vols); - - for my $vol (@{$vols}) { - # return when we find the one with the correct srcpath - return $vol if ($vol->prop('srcpath') eq $mount->prop('srcdevpath')); - } - return undef; -} - -package ManaTools::Shared::disk_backend::IO::Btrfs; - -use Moose; - -extends 'ManaTools::Shared::disk_backend::IO'; - -has '+type' => ( - default => 'Btrfs' -); - -package ManaTools::Shared::disk_backend::IO::BtrfsVol; - -use Moose; - -extends 'ManaTools::Shared::disk_backend::IO'; - -with 'ManaTools::Shared::disk_backend::IOFS'; - -has '+type' => ( - default => 'BtrfsVol' -); - package ManaTools::Shared::disk_backend::Part::Btrfs; @@ -268,93 +216,6 @@ has 'subvolumes' => ( default => sub { return [];}, ); -class_has '+in_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - if (defined $del && !$del) { - return ($self->in_length() > 0); - } - # multiple device allowed - return $io->does('ManaTools::Shared::disk_backend::BlockDevice'); - }; - } -); - -class_has '+out_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - if (!defined $del) { - $del = 0; - } - if ($del != 0) { - return ($self->in_length() > 0); - } - return ($self->in_length() == 0 && ref($io) eq 'ManaTools::Shared::disk_backend::IO::Btrfs'); - }; - } -); - -sub refresh { - my $self = shift; - my $path = shift; - my $subvols = $self->subvolumes(); - - # first, clean up all Volume stuff - my @parts = $self->db->findpart('BtrfsVol'); - for my $part (@parts) { - $part->unhook(); - } - # loop all BtrfsVol IO and remove safely - for my $vol (@{$subvols}) { - # this should also unhook from any Part - $vol->unhook(); - } - # clear subvols from list - @{$subvols} = (); - - # find the IO::Btrfs - my @outs = $self->get_outs(); - if (scalar(@outs) == 0) { - # make an IO::Btrfs for this one - @outs = ($self->db->mkio('Btrfs', {id => $self->uuid()})); - } - - return $subvols if !defined($path) || !$path; - - # btrfs subvolume list / -agcpuq - # ID 264 gen 1090157 cgen 255 parent 5 top level 5 parent_uuid - uuid ab6d48f8-6d65-6b43-b792-dd31d93018be path <FS_TREE>/backup-@ - my @lines = $self->tool_lines('btrfs', 'subvolume', 'list', "'$path'", '-agcpuq'); - for my $line (@lines) { - # top level is 2 strings, so combine them, so that the fields can be nicely splitted - my %fields = split(/[ \t\r\n]+/, $line =~ s'top level'top_level'r); - # create the volume part - my $part = $self->db->mkpart('BtrfsVol', {fs => $self, uuid => $fields{uuid}, plugin => $self->plugin()}); - # add the IO::Btrfs filesystem - $part->in_add($outs[0]); - # create a IO::BtrfsVol - my $vol = $self->db->mkio('BtrfsVol', {id => $fields{ID}}); - # TODO: trace parenting and fill in subvolumes in all the BtrfsVol Parts - # set properties - $vol->prop('srcpath', $fields{path} =~ s'<FS_TREE>''r); - $vol->prop('uuid', $fields{uuid}); - $vol->prop('parent_uuid', $fields{parent_uuid}); - $vol->prop('gen', $fields{gen}); - $vol->prop('cgen', $fields{cgen}); - $vol->prop('parent', $fields{parent}); - $vol->prop('top_level', $fields{top_level}); - $part->out_add($vol); - push @{$subvols}, $vol; - } - return $subvols; -} - - package ManaTools::Shared::disk_backend::Part::BtrfsVol; use Moose; @@ -391,39 +252,37 @@ has 'subvolumes' => ( default => sub { return [];}, ); -class_has '+in_restriction' => ( +class_has '+restrictions' => ( default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - if (!defined $del) { - $del = 0; - } - if ($del != 0) { - return ($self->in_length() > 0); - } - return ($self->in_length() == 0 && ref($io) eq 'ManaTools::Shared::disk_backend::IO::Btrfs'); - }; + return { + sibling => sub { + my $self = shift; + my $part = shift; + return $part->isa('ManaTools::Shared::disk_backend::Part::BtrfsVol');; + }, + parentsubvol => sub { + my $self = shift; + my $part = shift; + return $part->isa('ManaTools::Shared::disk_backend::Part::BtrfsVol'); + }, + childsubvol => sub { + my $self = shift; + my $part = shift; + return $part->isa('ManaTools::Shared::disk_backend::Part::BtrfsVol'); + }, + parent => sub { + my $self = shift; + my $part = shift; + return $part->isa('ManaTools::Shared::disk_backend::Part::Btrfs'); + }, + child => sub { + my $self = shift; + my $part = shift; + return $part->isa('ManaTools::Shared::disk_backend::Part::Mount'); + }, + } } ); -class_has '+out_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - if (!defined $del) { - $del = 0; - } - if ($del != 0) { - return ($self->in_length() > 0); - } - # multiple device allowed - return (ref($io) eq 'ManaTools::Shared::disk_backend::IO::BtrfsVol'); - }; - } -); 1; diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm index 6d12cfe5..ba47fc63 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm @@ -97,52 +97,11 @@ override ('probe', sub { }, '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; - } } } return $err == 0; }); -package ManaTools::Shared::disk_backend::IO::Disk; - -use Moose; - -extends 'ManaTools::Shared::disk_backend::IO'; - -with 'ManaTools::Shared::disk_backend::BlockDevice'; - -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'); - } -); - -sub file { - my $self = shift; - return '/dev/'. $self->id(); -} - package ManaTools::Shared::disk_backend::Part::Disks; use Moose; @@ -155,20 +114,21 @@ class_has '+type' => ( default => 'Disks' ); -class_has '+in_restriction' => ( - default => sub { - return sub {return 0;}; - } -); - -class_has '+out_restriction' => ( +class_has '+restrictions' => ( default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - return ref($io) eq 'ManaTools::Shared::disk_backend::IO::Disk'; - }; + return { + child => sub { + my $self = shift; + my $part = shift; + return $part->isa('ManaTools::Shared::disk_backend::Part::Disk'); + }, + parent => sub { + return 0; + }, + sibling => sub { + return 0; + }, + } } ); @@ -178,7 +138,7 @@ override('label', sub { if ($self->out_length() < 1) { return $label; } - return $label .'('. join(',', sort map { $_->id(); } $self->out_list()) .')'; + return $label .'('. join(',', sort map { $_->label(); } @children) .')'; }); package ManaTools::Shared::disk_backend::Part::Disk; diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm index 690cb1bd..7087f91a 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm @@ -168,83 +168,6 @@ override ('changedpart', sub { return 1; }); -#============================================================= - -=head2 fsprobe - -=head3 INPUT - - $io: ManaTools::Shared::disk_backend::IO | Str - $mount: ManaTools::Shared::disk_backend::Part::Mount - -=head3 OUTPUT - - ManaTools::Shared::disk_backend::IO or undef - -=head3 DESCRIPTION - - this method probes the IO to see if it fits for this - filesystem, if it does, create a new Part with this IO as in. - also create an IO (linked as the out) and return that one. - The resulting one can then be used as an in to eg: a Mount Part. - -=cut - -#============================================================= -sub fsprobe { - my $self = shift; - my $io = shift; - my $mount = shift; - - # gather fields from dumpe2fs - my %fields = $self->tool_fields('dumpe2fs', ':', '-h', '/dev/'. $io->id()); - - # get uuid - my $uuid = $fields{'Filesystem UUID'}; - - return undef if (!defined $uuid || !$uuid); - - # create part - # TODO: look or create part - my $part = $self->parent->mkpart('Extfs', { uuid => $uuid, plugin => $self}); - $part->prop('label', $fields{'Filesystem volume name'} =~ s'<none>''r); - $part->prop('features', split(' ', $fields{'Filesystem features'})); - $part->prop('options', split(' ', $fields{'Default mount options'})); - $part->prop('state', $fields{'Filesystem state'}); - $part->prop('block_size', $fields{'Block size'}); - $part->prop('block_count', $fields{'Block count'}); - $part->prop('size', $fields{'Block size'} * $fields{'Block count'}); - - # link in the in IO - $part->in_add($io); - - # create the out IO and set properties - my $fs = $self->parent->mkio('Extfs', {id => $uuid}); - $fs->prop('label', $fields{'Filesystem volume name'} =~ s'<none>''r); - $fs->prop('features', split(' ', $fields{'Filesystem features'})); - $fs->prop('options', split(' ', $fields{'Default mount options'})); - $fs->prop('state', $fields{'Filesystem state'}); - $fs->prop('block_size', $fields{'Block size'}); - $fs->prop('block_count', $fields{'Block count'}); - $fs->prop('size', $fields{'Block size'} * $fields{'Block count'}); - $part->out_add($fs); - - # return $fs to be link as an in IO into $mount Part - return $fs; -} - -package ManaTools::Shared::disk_backend::IO::Extfs; - -use Moose; - -extends 'ManaTools::Shared::disk_backend::IO'; - -with 'ManaTools::Shared::disk_backend::IOFS'; - -has '+type' => ( - default => 'Extfs' -); - package ManaTools::Shared::disk_backend::Part::Extfs; use Moose; @@ -270,38 +193,6 @@ has 'uuid' => ( } ); -class_has '+in_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - if (defined $del && !$del) { - return ($self->in_length() > 0); - } - # multiple device allowed - return $io->does('ManaTools::Shared::disk_backend::BlockDevice'); - }; - } -); - -class_has '+out_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - if (!defined $del) { - $del = 0; - } - if ($del != 0) { - return ($self->out_length() > 0); - } - return ($self->out_length() == 0 && ref($io) eq 'ManaTools::Shared::disk_backend::IO::Extfs'); - }; - } -); - class_has '+restrictions' => ( default => sub { return { diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm index 9086ac80..10e37fc0 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm @@ -158,19 +158,6 @@ override ('probe', sub { # TODO: add sibling tags to the other parts # TODO: parent that is filerole? if parent is create, we can do the child/first/last thing - # io stuff - my $io = $self->parent->mkio('Disk', {id => basename($loopfile), path => $bdfile, devicepath => $bdfile}); - if (!defined($io) || !$part->out_add($io)) { - $err = 1; - } - else { - $io->prop('sizelimit', $self->_sanitize_string($fields[2])); - $io->prop('offset', $self->_sanitize_string($fields[3])); - $io->prop('autoclear', $self->_sanitize_string($fields[4])); - $io->prop('back-file', $self->_sanitize_string($fields[6])); - $io->prop('back-dev', $self->_sanitize_string($fields[7])) if (defined $fields[7]); - $io->prop('back-ino', $self->_sanitize_string($fields[8])) if (defined $fields[8]); - } } # trigger changed parts @@ -192,23 +179,6 @@ class_has '+type' => ( default => 'Loops' ); -class_has '+in_restriction' => ( - default => sub { - return sub {return 0;}; - } -); - -class_has '+out_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - return $io->does('ManaTools::Shared::disk_backend::BlockDevice'); - }; - } -); - package ManaTools::Shared::disk_backend::Part::Loop; use Moose; diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm index b0e02e5c..5b3593b4 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm @@ -66,6 +66,74 @@ has '+dependencies' => ( #============================================================= +=head2 _makemount + +=head3 INPUT + + $parent: Part + $partstate: PartState + $fields: ArrayRef + +=head3 OUTPUT + + Part|undef + +=head3 DESCRIPTION + + this function create a mount Part from the parent and set the properties. + +=cut + +#============================================================= +sub _makemount { + my $self = shift; + my $parent = shift; + my $partstate = shift; + my $fields = shift; + + ## from this parent, create the mount point + # look or create the child with id based on the path + my $child = $parent->trychild($partstate, sub { + my $self = shift; + my $parameters = shift; + return ($self->path() eq $parameters->{path}); + },'Mount', {plugin => $self, path => $fields->[4], loaded => undef, saved => undef}); + + $child->prop('options', $fields->[5]); + $child->prop('dev', $fields->[2]); + $child->prop('id', $fields->[0]); + $child->prop('parent', $fields->[1]); + $child->prop('srcdevpath', $fields->[3]); + $child->prop('fstype', $fields->[8]); + $child->prop('srcmount', $fields->[9]); + + # add an unmount action + $child->add_action('unmount', 'Unmount', undef, sub { + my $self = shift; + print STDERR "Unmount is not implemented...\n"; + return 1; + }); + + ## take care of family + # finding parent mount + if ($fields->[1] != $fields->[0]) { + # find parent and put into parentmount field + my @parts = $self->parent->findpartprop('Mount', 'id', $fields->[1]); + $child->parentmount($parts[0]) if scalar(@parts) > 0; + } + + # find missing children Mount Part + my @parts = $self->parent->findpartprop('Mount', 'parent', $fields->[0]); + for my $p (@parts) { + my $pm = $p->parentmount(); + $p->parentmount($child) if (!defined $pm); + } + + return $child; +} + +#============================================================= + =head2 changedpart =head3 INPUT @@ -229,82 +297,11 @@ override ('probe', sub { $fs->prop('fstype', $fields[8]); ## TODO: check filesystem and sourcepath options to select the actual parent - # - ## from this parent, create the mount point - # look or create the child with id based on the path - my $child = $fs->trychild(ManaTools::Shared::disk_backend::Part->CurrentState, sub { - my $self = shift; - my $parameters = shift; - return ($self->path() eq $parameters->{path}); - },'Mount', {plugin => $self, path => $fields[4], loaded => undef, saved => undef}); - - $child->prop('options', $fields[5]); - $child->prop('dev', $fields[2]); - $child->prop('id', $fields[0]); - $child->prop('parent', $fields[1]); - $child->prop('srcdevpath', $fields[3]); - $child->prop('fstype', $fields[8]); - $child->prop('srcmount', $fields[9]); - - # add an unmount action - $child->add_action('unmount', 'Unmount', undef, sub { - my $self = shift; - print STDERR "Unmount is not implemented...\n"; - return 1; - }); - - ## take care of family - # finding parent mount - if ($fields[1] != $fields[0]) { - # find parent and put into parentmount field - my @parts = $self->parent->findpartprop('Mount', 'id', $fields[1]); - $child->parentmount($parts[0]) if scalar(@parts) > 0; - } - # find missing children Mount Part - @parts = $self->parent->findpartprop('Mount', 'parent', $fields[0]); - for my $p (@parts) { - my $pm = $p->parentmount(); - $p->parentmount($child) if (!defined $pm); - } - - ## get the in IO - # first, track down the device - my $in = undef; - my @ios = $self->parent->findioprop('dev', $fields[2]); - if (scalar(@ios) > 0) { - $in = $ios[0]; - } - else { - # if major is 0, it's a non-device mount, try fsprobe with srcmount - if ($fields[2] =~ s':.+$''r eq "0") { - # just pass on the srcmount string and hope with fsprobe - $in = $fields[9]; - } - } - # no need to continue trying to parse this one if we can't have an IO - continue if (!defined $in); - - ## try to insert filesystem in between, look at fstype - # first, check the exact filesystem (if it exists) - my $out = $self->parent->walkplugin(sub { - my $plugin = shift; - my $type = shift; - my $in = shift; - my $mount = shift; - return ($plugin->does('ManaTools::Shared::disk_backend::FileSystem') and $plugin->has_type($type) and $plugin->fsprobe($in, $mount)); - }, $fields[8], $in, $child); - - if (defined $out) { - my $res = $child->in_add($out); - } - else { - $child->in_add($in); - } + my $child = $self->_makemount($fs, ManaTools::Shared::disk_backend::Part->CurrentState, \@fields); # TODO: look up device with this # TODO: find the end of the options, and store them # TODO: also the super options and mount source (may have UUID or whatnot) - # TODO: use the filesystem type to connect to the previous IO } # 3.5 /proc/<pid>/mountinfo - Information about mounts # -------------------------------------------------------- @@ -377,29 +374,6 @@ has 'parentmount' => ( default => undef, ); -class_has '+in_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - my $rio = ref($io); - return 0 if !defined($rio) || !$rio; - if (defined $del && !$del) { - return ($self->in_length() > 0); - } - # only 1 device allowed - return $self->in_length() < 1 && ($io->does('ManaTools::Shared::disk_backend::BlockDevice') || $io->does('ManaTools::Shared::disk_backend::IOFS')); - }; - } -); - -class_has '+out_restriction' => ( - default => sub { - return sub {return 0;}; - } -); - class_has '+restrictions' => ( default => sub { return { @@ -501,36 +475,5 @@ class_has '+restrictions' => ( } ); -#============================================================= - -=head2 fsprobe - -=head3 INPUT - - $io: ManaTools::Shared::disk_backend::IO | Str - $mount: ManaTools::Shared::disk_backend::Part::Mount - -=head3 OUTPUT - - ManaTools::Shared::disk_backend::IO or undef - -=head3 DESCRIPTION - - this method probes the IO to see if it fits for this - filesystem, if it does, create a new Part with this IO as in. - also create an IO (linked as the out) and return that one. - The resulting one can then be used as an in to eg: a Mount Part. - -=cut - -#============================================================= -sub fsprobe { - my $self = shift; - my $io = shift; - my $mount = shift; - - # return $fs to be link as an in IO into $mount Part - return undef; -} 1; diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm index 483f024c..e9a67ab8 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm @@ -206,135 +206,6 @@ override ('changedpart', sub { return 1; }); -#============================================================= - -=head2 load - -=head3 OUTPUT - - 0 if failed, 1 if success or unneeded - -=head3 DESCRIPTION - - this method will load all disks partition tables - -=cut - -#============================================================= -override ('loadio', sub { - my $self = shift; - my $io = shift; - # get the partition table - my $pt = ManaTools::Shared::disk_backend::PartitionTable->new(parted => $self->tool('parted'), disk => $io->file()); - # get partitions and mkio them all - for my $p (values %{$pt->partitions()}) { - my @stat = stat($p->{'file'}); - my $dev = $stat[6]; - my $minor = $dev % 256; - my $major = int (($dev - $minor) / 256); - my $io = $self->parent->mkio('Partition', {id => $p->{'file'} =~ s'^.+/''r}); - $io->prop('dev', $major .':'. $minor); - $io->sync_majorminor(); - $io->prop('start', $p->{'start'}); - $io->prop('size', $p->{'size'}); - $io->prop('num', $p->{'num'}); - # TODO: also create the Part (if it doesn't already exists) and link it - } - return 1; -}); - -#============================================================= - -=head2 probeio - -=head3 OUTPUT - - 0 if failed, 1 if success or unneeded - -=head3 DESCRIPTION - - this method will try to probe the specific disk IO and get partitions - -=cut - -#============================================================= -override ('probeio', sub { - my $self = shift; - my $io = shift; - my $part = undef; - # return if $io is not the correct type - if ($io->type() ne 'Disk') { - return 1; - } - if ($io->prop('present') == 0) { - return 1; - } - # find out if the IO already has a part, if not: make a part - my @parts = $self->parent->findin($io); - if (scalar(@parts) > 0) { - $part = $parts[0]; - } - else { - $part = $self->parent->mkpart('PartitionTable', {plugin => $self}); - if (!defined($part)) { - return 0; - } - # assign this IO to the ins - if (!$part->in_add($io)) { - return 0; - } - # add properties - # TODO: partition table type, size and position, logical alignment, etc... - # default partition is always 1 sector ? - $part->prop('size', 1); - # add an action - $part->add_action('addPartition', 'Add a partition', $part, sub { - my $self = shift; - my $part = $self->item(); - print STDERR "Add partition is not implemented...\n"; - return 1; - }, sub { - my $self = shift; - my $part = $self->item(); - return 1; - }); - } - @parts = $self->parent->findin($io); - my $err = 0; - my $partitions = 0; - # find subdevices in /sys/ - 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); - $io->prop_from_file('start', $pf . '/start'); - $io->prop_from_file('ro', $pf . '/ro'); - $io->prop_from_file('dev', $pf . '/dev'); - $io->sync_majorminor(); - $io->prop('num', $pf =~ s/^.+([0-9]+)$/$1/r); - $partitions = $partitions + 1; - if (!$part->out_add($io)) { - $err = 1; - } - } - $part->prop('partitions', $partitions); - # find out how to differentiate between an empty partition table and no partition table - return $err == 0; -}); - -package ManaTools::Shared::disk_backend::IO::Partition; - -use Moose; - -extends 'ManaTools::Shared::disk_backend::IO'; - -with 'ManaTools::Shared::disk_backend::BlockDevice'; - -has '+type' => ( - default => 'Partition' -); - package ManaTools::Shared::disk_backend::Part::PartitionTable; use Moose; @@ -367,40 +238,6 @@ class_has '+restrictions' => ( } ); -class_has '+in_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - if (!defined $del) { - $del = 0; - } - if ($del != 0) { - return ($self->in_length() > 0); - } - return ($self->in_length() == 0 && ref($io) eq 'ManaTools::Shared::disk_backend::IO::Disk'); - }; - } -); - -class_has '+out_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - if (!defined $del) { - $del = 0; - } - if ($del != 0) { - return ($self->out_length() > 0); - } - return ($self->out_length() < 4 && ref($io) eq 'ManaTools::Shared::disk_backend::IO::Partition'); - }; - } -); - package ManaTools::Shared::disk_backend::Part::PartitionElement; use Moose; diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm index 1f3e08a2..3a96036f 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm @@ -148,25 +148,6 @@ override ('probe', sub { $part->prop('uuid', defined($labelfields{'UUID'}) ? $labelfields{'UUID'} : ''); $part->prop('label', defined($labelfields{'LABEL'}) ? $labelfields{'LABEL'} : ''); - # check first if it's a device, then find the define - my @stat = stat($fields[0]); - # if device: then... - if ($stat[2] >> 12 == 6) { - my $dev = $stat[6]; - my $minor = $dev % 256; - my $major = int (($dev - $minor) / 256); - my @ios = $self->parent->findioprop('dev', $major .':'. $minor); - if (scalar(@ios) > 0) { - $part->in_add($ios[0]); - } - else { - # TODO: create the IO ? try to probe parent? or ??? - # think of XEN where you may have device partition files without an actual disk? - } - } - else { - # TODO the in should be the mount point containing the filename - } } # /proc/swaps: # @@ -195,27 +176,6 @@ has 'path' => ( required => 1 ); -class_has '+in_restriction' => ( - default => sub { - return sub { - my $self = shift; - my $io = shift; - my $del = shift; - if (defined $del && !$del) { - return ($self->in_length() > 0); - } - # only 1 device allowed - return $self->in_length() < 1 && ($io->does('ManaTools::Shared::disk_backend::BlockDevice') || $io->does('ManaTools::Shared::disk_backend::FileRole')); - }; - } -); - -class_has '+out_restriction' => ( - default => sub { - return sub {return 0;}; - } -); - class_has '+order' => ( default => sub { sub { |