Changeset 34907
- Timestamp:
- Jan 10, 2013, 3:38:41 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous-Server/bin/nebdiskd (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/bin/nebdiskd
r28525 r34907 11 11 use Config::YAML; 12 12 use DBI; 13 use File::Mountpoint qw( is_mountpoint );14 13 use File::Spec; 15 use Filesys::Df;16 14 use Log::Log4perl; 17 15 use Nebulous::Server::SQL; … … 192 190 eval { 193 191 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 = ?");195 192 my $d_query = $dbh->prepare_cached("DELETE FROM mountedvol WHERE mountpoint = ?"); 196 193 … … 199 196 { 200 197 # there may be multiple vol_ids per mountpoint but we only need to 201 # check each mo intpont once202 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"); 203 200 $query->execute; 204 201 while (my $row = $query->fetchrow_hashref) { … … 211 208 foreach my $mnt (@$mounts) { 212 209 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); 235 215 unless (defined $dev_info) { 236 216 $valid_mountpoint = 0; 237 }238 239 if (!$valid_mountpoint) {240 # try is_mountpoint() again if $retry > 1241 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 AFTER267 # we determine if it's a valid mountpoint incase268 # is_mountpoint() invokes the automounter269 $dev_info = df($mountpoint, 1024);270 unless (defined $dev_info) {271 217 $log->error("can't find device info for $mountpoint"); 218 $d_query->execute($mountpoint); 272 219 next; 273 220 } … … 278 225 279 226 } 280 281 # $dbh->do("call getmountedvol()");282 283 # $dbh->commit;284 # $log->debug("commited to database");285 227 }; 286 228 if ($@) { 287 # $dbh->rollback;288 # $log->debug("rolledback transaction");289 229 $log->logdie($@); 290 230 } … … 391 331 # this follows BSD syntax ps (BSD's and linux) 392 332 # 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`; 396 335 } 397 336 … … 412 351 } 413 352 353 sub 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 } 414 371 415 372 __END__
Note:
See TracChangeset
for help on using the changeset viewer.
