IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34907


Ignore:
Timestamp:
Jan 10, 2013, 3:38:41 PM (14 years ago)
Author:
Serge CHASTEL
Message:

nebdiskd / Merged tag into trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/bin/nebdiskd

    r28525 r34907  
    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;
     
    192190    eval {
    193191        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 = ?");
    195192        my $d_query = $dbh->prepare_cached("DELETE FROM mountedvol WHERE mountpoint = ?");
    196193
     
    199196        {
    200197            # 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");
     198            # check each mountpoint once
     199            my $query = $dbh->prepare_cached("SELECT DISTINCT host, mountpoint FROM volume");
    203200            $query->execute;
    204201            while (my $row = $query->fetchrow_hashref) {
     
    211208        foreach my $mnt (@$mounts) {
    212209            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);
     210            my $hostname = $mnt->{'host'};
     211            my $valid_mountpoint = 1;
     212
     213            # fetch stats on the device using ssh and df
     214            my $dev_info = df_through_ssh($hostname, $mountpoint, 1024);
    235215            unless (defined $dev_info) {
    236216                $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) {
    271217                $log->error("can't find device info for $mountpoint");
     218                $d_query->execute($mountpoint);
    272219                next;
    273220            }
     
    278225
    279226        }
    280 
    281 #        $dbh->do("call getmountedvol()");
    282 
    283 #        $dbh->commit;
    284 #        $log->debug("commited to database");
    285227    };
    286228    if ($@) {
    287 #        $dbh->rollback;
    288 #        $log->debug("rolledback transaction");
    289229        $log->logdie($@);
    290230    }
     
    391331  # this follows BSD syntax ps (BSD's and linux)
    392332  # 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 
     333  } elsif( `ps h o pid p $$` =~ /^\s*$$\s*$/ ){ # can I play ps on myself ?
     334      $exists = `ps h o pid p $current_pid`;
    396335  }
    397336
     
    412351}
    413352
     353sub df_through_ssh {
     354    my $hostname = shift;
     355    my $mountpoint = shift;
     356    my $units = shift;
     357    $log->debug("Getting info from mountpoint = [$mountpoint] / unit = [$units] / hostname = [$hostname]");
     358    my $df_data = qx/ssh $hostname 'df $mountpoint' | grep -v Filesystem/;
     359    $df_data =~ s/\s+/:/g;
     360    $log->debug("Received from ssh = [$df_data]");
     361    unless ($df_data) {
     362        return undef;
     363    }
     364    my @data = split(/:/, $df_data);
     365    my %df_info = ();
     366    $df_info{"blocks"} = $data[1];
     367    $df_info{"used"} = $data[2];
     368    $log->debug("blocks = " . $df_info{"blocks"} . " / used = " . $df_info{"used"});
     369    return \%df_info;
     370}
    414371
    415372__END__
Note: See TracChangeset for help on using the changeset viewer.