Changeset 35096 for branches/eam_branches/ipp-20121219/Nebulous-Server
- Timestamp:
- Feb 6, 2013, 2:34:49 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20121219
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
Nebulous-Server (modified) (1 prop)
-
Nebulous-Server/bin/nebdiskd (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20121219
-
branches/eam_branches/ipp-20121219/Nebulous-Server
- Property svn:mergeinfo set to
-
branches/eam_branches/ipp-20121219/Nebulous-Server/bin/nebdiskd
r28525 r35096 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; … … 22 20 23 21 my ( 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, 32 30 $verbose, 33 31 $user, … … 111 109 log4perl.appender.SERVERLOGFILE.layout = Log::Log4perl::Layout::PatternLayout 112 110 log4perl.appender.SERVERLOGFILE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n 111 log4perl.appender.SERVERLOGFILE.size = 10485760 113 112 114 113 log4perl.filter.MatchWarn = Log::Log4perl::Filter::LevelMatch … … 143 142 $SIG{TERM} = sub { unlink_pid_file($pidfile); exit(); }; 144 143 $SIG{INT} = $SIG{TERM}; 145 $SIG{HUP} = sub { $c = read_rcfile($rcfile) }; 144 $SIG{HUP} = sub { $c = read_rcfile($rcfile) }; 146 145 147 146 my $date = localtime(); … … 192 191 eval { 193 192 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 193 my $d_query = $dbh->prepare_cached("DELETE FROM mountedvol WHERE mountpoint = ?"); 196 194 … … 199 197 { 200 198 # 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");199 # check each mountpoint once 200 my $query = $dbh->prepare_cached("SELECT DISTINCT host, mountpoint FROM volume"); 203 201 $query->execute; 204 202 while (my $row = $query->fetchrow_hashref) { … … 207 205 $query->finish; 208 206 } 209 207 210 208 # determine valid mountpoints 211 209 foreach my $mnt (@$mounts) { 212 210 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); 235 218 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); 272 222 next; 273 223 } … … 278 228 279 229 } 280 281 # $dbh->do("call getmountedvol()");282 283 # $dbh->commit;284 # $log->debug("commited to database");285 230 }; 286 231 if ($@) { 287 # $dbh->rollback;288 # $log->debug("rolledback transaction");289 232 $log->logdie($@); 290 233 } … … 336 279 # $dbh->commit; 337 280 }; 338 if ($@) { 281 if ($@) { 339 282 # $dbh->rollback; 340 283 $log->logdie($@); … … 391 334 # this follows BSD syntax ps (BSD's and linux) 392 335 # 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`; 396 338 } 397 339 … … 412 354 } 413 355 356 sub 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 } 414 398 415 399 __END__ … … 525 509 =item * C<NEB_PASS> 526 510 527 Equivalent to --dbpass|-p 511 Equivalent to --dbpass|-p 528 512 529 513 =back
Note:
See TracChangeset
for help on using the changeset viewer.
