Index: branches/eam_branches/ipp-20121219/Nebulous-Server/bin/nebdiskd
===================================================================
--- branches/eam_branches/ipp-20121219/Nebulous-Server/bin/nebdiskd	(revision 34857)
+++ branches/eam_branches/ipp-20121219/Nebulous-Server/bin/nebdiskd	(revision 35096)
@@ -11,7 +11,5 @@
 use Config::YAML;
 use DBI;
-use File::Mountpoint qw( is_mountpoint );
 use File::Spec;
-use Filesys::Df;
 use Log::Log4perl;
 use Nebulous::Server::SQL;
@@ -22,12 +20,12 @@
 
 my (
-    $debug, 
-    $db, 
-    $dbhost, 
-    $dbuser, 
-    $dbpass, 
-    $pidfile, 
-    $stop, 
-    $restart, 
+    $debug,
+    $db,
+    $dbhost,
+    $dbuser,
+    $dbpass,
+    $pidfile,
+    $stop,
+    $restart,
     $verbose,
     $user,
@@ -111,4 +109,5 @@
     log4perl.appender.SERVERLOGFILE.layout    = Log::Log4perl::Layout::PatternLayout
     log4perl.appender.SERVERLOGFILE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n
+    log4perl.appender.SERVERLOGFILE.size      = 10485760
 
     log4perl.filter.MatchWarn  = Log::Log4perl::Filter::LevelMatch
@@ -143,5 +142,5 @@
 $SIG{TERM} = sub { unlink_pid_file($pidfile); exit(); };
 $SIG{INT}  = $SIG{TERM};
-$SIG{HUP}  = sub { $c = read_rcfile($rcfile) }; 
+$SIG{HUP}  = sub { $c = read_rcfile($rcfile) };
 
 my $date = localtime();
@@ -192,5 +191,4 @@
     eval {
         my $r_query = $dbh->prepare_cached("REPLACE INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, ?, ?,note FROM volume WHERE mountpoint = ?");
-#	my $d_query = $dbh->prepare_cached("UPDATE mountedvol SET allocate = ?, available = ? WHERE mountpoint = ?");
         my $d_query = $dbh->prepare_cached("DELETE FROM mountedvol WHERE mountpoint = ?");
 
@@ -199,6 +197,6 @@
         {
             # there may be multiple vol_ids per mountpoint but we only need to
-            # check each mointpont once
-            my $query = $dbh->prepare_cached("SELECT DISTINCT mountpoint FROM volume");
+            # check each mountpoint once
+            my $query = $dbh->prepare_cached("SELECT DISTINCT host, mountpoint FROM volume");
             $query->execute;
             while (my $row = $query->fetchrow_hashref) {
@@ -207,67 +205,19 @@
             $query->finish;
         }
-        
+
         # determine valid mountpoints
         foreach my $mnt (@$mounts) {
             my $mountpoint = $mnt->{'mountpoint'};
-            $log->debug("checking $mountpoint");
-            # this /SHOULD/ fail if the mount point is handled by the
-            # automounter and it fails to mount
-            my $tries = 0;
-	    my $valid_mountpoint = 1;
-	    unless (exists($host_failure_counts{$mountpoint})) {
-		$host_failure_counts{$mountpoint} = 0;
-	    }
-            TEST: eval {
-                $tries++;
-                unless (is_mountpoint($mountpoint)) {
-		    unless(defined($host_removed{$mountpoint})) {
-			$log->warn("$mountpoint is not a valid mountpoint ($tries $host_failure_counts{$mountpoint})");
-		    }
-		    $valid_mountpoint = 0;
-                }
-            };
-
-            # fetch stats on the mounted device.  this has to be done AFTER
-            # we determine if it's a valid mountpoint incase
-            # is_mountpoint() invokes the automounter
-            my $dev_info = df($mountpoint, 1024);
+            my $alt_mountpoint = $mountpoint;
+            $alt_mountpoint =~ s/data/export/;
+            my $hostname = $mnt->{'host'};
+            my $valid_mountpoint = 1;
+
+            # fetch stats on the device using ssh and df
+            my $dev_info = df_through_ssh($hostname, $alt_mountpoint, 1024);
             unless (defined $dev_info) {
-		$valid_mountpoint = 0;
-            }
-
-            if (!$valid_mountpoint) {
-                # try is_mountpoint() again if $retry > 1
-                if ($tries < $retry) {
-                    $log->warn("retrying test of $mountpoint");
-                    goto TEST; 
-                }
-		$host_failure_counts{$mountpoint}++;
-		
-		if (!(defined($host_removed{$mountpoint})) || !($host_removed{$mountpoint})) {
-		    if (($host_failure_counts{$mountpoint} > $failure_limit)) {
-			$host_removed{$mountpoint} = 1;
-			$log->warn("Removing $mountpoint from the mountedvol table ($host_failure_counts{$mountpoint} > $failure_limit) No further warnings unless state changes.");
-			$d_query->execute($mountpoint);
-		    }
-		    else {
-			$log->warn("Mountpoint $mountpoint has had $host_failure_counts{$mountpoint} failures. Will remove after $failure_limit");
-		    }
-		}
-		next;
-		
-	    }
-	    if ($host_failure_counts{$mountpoint} != 0) {
-		$host_removed{$mountpoint} = 0;
-		$log->warn("Mountpoint $mountpoint failures cleared ($host_failure_counts{$mountpoint})");
-		$host_failure_counts{$mountpoint} = 0;
-	    }
-
-            # fetch stats on the mounted device.  this has to be done AFTER
-            # we determine if it's a valid mountpoint incase
-            # is_mountpoint() invokes the automounter
-            $dev_info = df($mountpoint, 1024);
-            unless (defined $dev_info) {
-                $log->error("can't find device info for $mountpoint");
+                $valid_mountpoint = 0;
+                $log->error("can't find device info for $mountpoint / $alt_mountpoint");
+                $d_query->execute($mountpoint);
                 next;
             }
@@ -278,13 +228,6 @@
 
         }
-
-#        $dbh->do("call getmountedvol()");
-
-#        $dbh->commit;
-#        $log->debug("commited to database");
     };
     if ($@) {
-#        $dbh->rollback;
-#        $log->debug("rolledback transaction");
         $log->logdie($@);
     }
@@ -336,5 +279,5 @@
 #        $dbh->commit;
     };
-    if ($@) { 
+    if ($@) {
 #        $dbh->rollback;
         $log->logdie($@);
@@ -391,7 +334,6 @@
   # this follows BSD syntax ps (BSD's and linux)
   # this will fail on Unix98 syntax ps (Solaris, etc)
-  }elsif( `ps h o pid p $$` =~ /^\s*$$\s*$/ ){ # can I play ps on myself ?
-    $exists = `ps h o pid p $current_pid`;
-
+  } elsif( `ps h o pid p $$` =~ /^\s*$$\s*$/ ){ # can I play ps on myself ?
+      $exists = `ps h o pid p $current_pid`;
   }
 
@@ -412,4 +354,46 @@
 }
 
+sub df_through_ssh {
+    my $hostname = shift;
+    my $mountpoint = shift;
+    my $units = shift;
+    $log->debug("Getting info from mountpoint = [$mountpoint] / unit = [$units] / hostname = [$hostname]");
+    my $df_data = qx/ssh $hostname 'df $mountpoint' | grep -v Filesystem/;
+    $df_data =~ s/\s+/:/g;
+    $log->debug("Received from ssh = [$df_data]");
+    my %df_info = ();
+    $df_info{"blocks"} = 0;
+    $df_info{"used"} = 0;
+    unless ($df_data) {
+        # We cannot connect to the host for some reason However, the
+        # partition can be mounted on some other hosts (in the case of
+        # an original host failure or upgrade for instance) Let's look
+        # for an entry in /etc/autofs/auto.data starting with
+        # <hostname>.[012] If it's in there, return (blocks => 1, used
+        # => 1). The partition is mounted but not available for
+        # replication (since blocks-used = 0 and used/blocks=1=100%).
+        my $partition_name = $mountpoint;
+        $partition_name =~ s/\/export\///;
+        $log->debug("Looking for $partition_name in /etc/autofs/auto.data");
+        open(AUTODATA, "</etc/autofs/auto.data") or die("Can't open /etc/autofs/auto.data");
+        foreach my $line (<AUTODATA>) {
+            if ($line =~ /^$partition_name/) {
+                $log->debug("$partition_name found in /etc/autofs/auto.data");
+                close(AUTODATA);
+                $df_info{"blocks"} = 1;
+                $df_info{"used"} = 1;
+                return \%df_info;
+            }
+        }
+        $log->debug("$partition_name NOT found in /etc/autofs/auto.data");
+        close(AUTODATA);
+        return undef;
+    }
+    my @data = split(/:/, $df_data);
+    $df_info{"blocks"} = $data[1];
+    $df_info{"used"} = $data[2];
+    $log->debug("blocks = " . $df_info{"blocks"} . " / used = " . $df_info{"used"});
+    return \%df_info;
+}
 
 __END__
@@ -525,5 +509,5 @@
 =item * C<NEB_PASS>
 
-Equivalent to --dbpass|-p 
+Equivalent to --dbpass|-p
 
 =back
