IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 6, 2013, 2:34:49 PM (13 years ago)
Author:
eugene
Message:

merging changes from trunk

Location:
branches/eam_branches/ipp-20121219
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20121219

  • branches/eam_branches/ipp-20121219/Nebulous-Server

  • branches/eam_branches/ipp-20121219/Nebulous-Server/bin/nebdiskd

    r28525 r35096  
    1111use Config::YAML;
    1212use DBI;
    13 use File::Mountpoint qw( is_mountpoint );
    1413use File::Spec;
    15 use Filesys::Df;
    1614use Log::Log4perl;
    1715use Nebulous::Server::SQL;
     
    2220
    2321my (
    24     $debug, 
    25     $db, 
    26     $dbhost, 
    27     $dbuser, 
    28     $dbpass, 
    29     $pidfile, 
    30     $stop, 
    31     $restart, 
     22    $debug,
     23    $db,
     24    $dbhost,
     25    $dbuser,
     26    $dbpass,
     27    $pidfile,
     28    $stop,
     29    $restart,
    3230    $verbose,
    3331    $user,
     
    111109    log4perl.appender.SERVERLOGFILE.layout    = Log::Log4perl::Layout::PatternLayout
    112110    log4perl.appender.SERVERLOGFILE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n
     111    log4perl.appender.SERVERLOGFILE.size      = 10485760
    113112
    114113    log4perl.filter.MatchWarn  = Log::Log4perl::Filter::LevelMatch
     
    143142$SIG{TERM} = sub { unlink_pid_file($pidfile); exit(); };
    144143$SIG{INT}  = $SIG{TERM};
    145 $SIG{HUP}  = sub { $c = read_rcfile($rcfile) }; 
     144$SIG{HUP}  = sub { $c = read_rcfile($rcfile) };
    146145
    147146my $date = localtime();
     
    192191    eval {
    193192        my $r_query = $dbh->prepare_cached("REPLACE INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, ?, ?,note FROM volume WHERE mountpoint = ?");
    194 #       my $d_query = $dbh->prepare_cached("UPDATE mountedvol SET allocate = ?, available = ? WHERE mountpoint = ?");
    195193        my $d_query = $dbh->prepare_cached("DELETE FROM mountedvol WHERE mountpoint = ?");
    196194
     
    199197        {
    200198            # there may be multiple vol_ids per mountpoint but we only need to
    201             # check each mointpont once
    202             my $query = $dbh->prepare_cached("SELECT DISTINCT mountpoint FROM volume");
     199            # check each mountpoint once
     200            my $query = $dbh->prepare_cached("SELECT DISTINCT host, mountpoint FROM volume");
    203201            $query->execute;
    204202            while (my $row = $query->fetchrow_hashref) {
     
    207205            $query->finish;
    208206        }
    209        
     207
    210208        # determine valid mountpoints
    211209        foreach my $mnt (@$mounts) {
    212210            my $mountpoint = $mnt->{'mountpoint'};
    213             $log->debug("checking $mountpoint");
    214             # this /SHOULD/ fail if the mount point is handled by the
    215             # automounter and it fails to mount
    216             my $tries = 0;
    217             my $valid_mountpoint = 1;
    218             unless (exists($host_failure_counts{$mountpoint})) {
    219                 $host_failure_counts{$mountpoint} = 0;
    220             }
    221             TEST: eval {
    222                 $tries++;
    223                 unless (is_mountpoint($mountpoint)) {
    224                     unless(defined($host_removed{$mountpoint})) {
    225                         $log->warn("$mountpoint is not a valid mountpoint ($tries $host_failure_counts{$mountpoint})");
    226                     }
    227                     $valid_mountpoint = 0;
    228                 }
    229             };
    230 
    231             # fetch stats on the mounted device.  this has to be done AFTER
    232             # we determine if it's a valid mountpoint incase
    233             # is_mountpoint() invokes the automounter
    234             my $dev_info = df($mountpoint, 1024);
     211            my $alt_mountpoint = $mountpoint;
     212            $alt_mountpoint =~ s/data/export/;
     213            my $hostname = $mnt->{'host'};
     214            my $valid_mountpoint = 1;
     215
     216            # fetch stats on the device using ssh and df
     217            my $dev_info = df_through_ssh($hostname, $alt_mountpoint, 1024);
    235218            unless (defined $dev_info) {
    236                 $valid_mountpoint = 0;
    237             }
    238 
    239             if (!$valid_mountpoint) {
    240                 # try is_mountpoint() again if $retry > 1
    241                 if ($tries < $retry) {
    242                     $log->warn("retrying test of $mountpoint");
    243                     goto TEST;
    244                 }
    245                 $host_failure_counts{$mountpoint}++;
    246                
    247                 if (!(defined($host_removed{$mountpoint})) || !($host_removed{$mountpoint})) {
    248                     if (($host_failure_counts{$mountpoint} > $failure_limit)) {
    249                         $host_removed{$mountpoint} = 1;
    250                         $log->warn("Removing $mountpoint from the mountedvol table ($host_failure_counts{$mountpoint} > $failure_limit) No further warnings unless state changes.");
    251                         $d_query->execute($mountpoint);
    252                     }
    253                     else {
    254                         $log->warn("Mountpoint $mountpoint has had $host_failure_counts{$mountpoint} failures. Will remove after $failure_limit");
    255                     }
    256                 }
    257                 next;
    258                
    259             }
    260             if ($host_failure_counts{$mountpoint} != 0) {
    261                 $host_removed{$mountpoint} = 0;
    262                 $log->warn("Mountpoint $mountpoint failures cleared ($host_failure_counts{$mountpoint})");
    263                 $host_failure_counts{$mountpoint} = 0;
    264             }
    265 
    266             # fetch stats on the mounted device.  this has to be done AFTER
    267             # we determine if it's a valid mountpoint incase
    268             # is_mountpoint() invokes the automounter
    269             $dev_info = df($mountpoint, 1024);
    270             unless (defined $dev_info) {
    271                 $log->error("can't find device info for $mountpoint");
     219                $valid_mountpoint = 0;
     220                $log->error("can't find device info for $mountpoint / $alt_mountpoint");
     221                $d_query->execute($mountpoint);
    272222                next;
    273223            }
     
    278228
    279229        }
    280 
    281 #        $dbh->do("call getmountedvol()");
    282 
    283 #        $dbh->commit;
    284 #        $log->debug("commited to database");
    285230    };
    286231    if ($@) {
    287 #        $dbh->rollback;
    288 #        $log->debug("rolledback transaction");
    289232        $log->logdie($@);
    290233    }
     
    336279#        $dbh->commit;
    337280    };
    338     if ($@) { 
     281    if ($@) {
    339282#        $dbh->rollback;
    340283        $log->logdie($@);
     
    391334  # this follows BSD syntax ps (BSD's and linux)
    392335  # this will fail on Unix98 syntax ps (Solaris, etc)
    393   }elsif( `ps h o pid p $$` =~ /^\s*$$\s*$/ ){ # can I play ps on myself ?
    394     $exists = `ps h o pid p $current_pid`;
    395 
     336  } elsif( `ps h o pid p $$` =~ /^\s*$$\s*$/ ){ # can I play ps on myself ?
     337      $exists = `ps h o pid p $current_pid`;
    396338  }
    397339
     
    412354}
    413355
     356sub df_through_ssh {
     357    my $hostname = shift;
     358    my $mountpoint = shift;
     359    my $units = shift;
     360    $log->debug("Getting info from mountpoint = [$mountpoint] / unit = [$units] / hostname = [$hostname]");
     361    my $df_data = qx/ssh $hostname 'df $mountpoint' | grep -v Filesystem/;
     362    $df_data =~ s/\s+/:/g;
     363    $log->debug("Received from ssh = [$df_data]");
     364    my %df_info = ();
     365    $df_info{"blocks"} = 0;
     366    $df_info{"used"} = 0;
     367    unless ($df_data) {
     368        # We cannot connect to the host for some reason However, the
     369        # partition can be mounted on some other hosts (in the case of
     370        # an original host failure or upgrade for instance) Let's look
     371        # for an entry in /etc/autofs/auto.data starting with
     372        # <hostname>.[012] If it's in there, return (blocks => 1, used
     373        # => 1). The partition is mounted but not available for
     374        # replication (since blocks-used = 0 and used/blocks=1=100%).
     375        my $partition_name = $mountpoint;
     376        $partition_name =~ s/\/export\///;
     377        $log->debug("Looking for $partition_name in /etc/autofs/auto.data");
     378        open(AUTODATA, "</etc/autofs/auto.data") or die("Can't open /etc/autofs/auto.data");
     379        foreach my $line (<AUTODATA>) {
     380            if ($line =~ /^$partition_name/) {
     381                $log->debug("$partition_name found in /etc/autofs/auto.data");
     382                close(AUTODATA);
     383                $df_info{"blocks"} = 1;
     384                $df_info{"used"} = 1;
     385                return \%df_info;
     386            }
     387        }
     388        $log->debug("$partition_name NOT found in /etc/autofs/auto.data");
     389        close(AUTODATA);
     390        return undef;
     391    }
     392    my @data = split(/:/, $df_data);
     393    $df_info{"blocks"} = $data[1];
     394    $df_info{"used"} = $data[2];
     395    $log->debug("blocks = " . $df_info{"blocks"} . " / used = " . $df_info{"used"});
     396    return \%df_info;
     397}
    414398
    415399__END__
     
    525509=item * C<NEB_PASS>
    526510
    527 Equivalent to --dbpass|-p 
     511Equivalent to --dbpass|-p
    528512
    529513=back
Note: See TracChangeset for help on using the changeset viewer.