diff options
Diffstat (limited to 'perl-install/fs/remote/nfs.pm')
-rw-r--r-- | perl-install/fs/remote/nfs.pm | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/perl-install/fs/remote/nfs.pm b/perl-install/fs/remote/nfs.pm new file mode 100644 index 000000000..f946a4323 --- /dev/null +++ b/perl-install/fs/remote/nfs.pm @@ -0,0 +1,68 @@ +package fs::remote::nfs; # $Id$ + +use strict; +use diagnostics; + +use common; +use fs::remote; +use log; + +our @ISA = 'fs::remote'; + +sub to_fstab_entry { + my ($class, $e) = @_; + $class->to_fstab_entry_raw($e, 'nfs'); +} +sub comment_to_string { + my ($_class, $comment) = @_; + member($comment, qw(* 0.0.0.0/0.0.0.0 (everyone))) ? '' : $comment; +} +sub from_dev { + my ($_class, $dev) = @_; + $dev =~ m|(.*?):(.*)|; +} +sub to_dev_raw { + my ($_class, $server, $name) = @_; + $server . ':' . $name; +} + +sub check { + my ($_class, $in) = @_; + $in->do_pkgs->ensure_binary_is_installed('nfs-utils-clients', 'showmount') or return; + system('/etc/init.d/portmap start') if system('/etc/init.d/portmap status') != 0; + 1; +} + +sub find_servers { + open(my $F2, "rpcinfo-flushed -b mountd 2 |"); + open(my $F3, "rpcinfo-flushed -b mountd 3 |"); + + common::nonblock($F2); + common::nonblock($F3); + my $domain = chomp_(`domainname`); + my ($s, %servers); + my $quit; + while (!$quit) { + $quit = 1; + sleep 1; + while ($s = <$F2> || <$F3>) { + $quit = 0; + my ($ip, $name) = $s =~ /(\S+)\s+(\S+)/ or log::explanations("bad line in rpcinfo output"), next; + $name =~ s/\.$//; + $name =~ s/\Q.$domain\E$//; + $servers{$ip} ||= { ip => $ip, if_($name ne '(unknown)', name => $name) }; + } + } + values %servers; +} + +sub find_exports { + my ($_class, $server) = @_; + + my @l; + run_program::raw({ timeout => 1 }, "showmount", '>', \@l, "--no-headers", "-e", $server->{ip} || $server->{name}); + + map { if_(/(\S+(\s*\S+)*)\s+(\S+)/, { name => $1, comment => $3, server => $server }) } @l; +} + +1; |