Changeset 24540
- Timestamp:
- Jun 24, 2009, 12:50:43 PM (17 years ago)
- Location:
- trunk/Nebulous-Server
- Files:
-
- 4 edited
-
Changes (modified) (1 diff)
-
bin/nebdiskd (modified) (22 diffs)
-
lib/Nebulous/Server/SQL.pm (modified) (6 diffs)
-
lib/Test/Nebulous.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r24500 r24540 24 24 - add nebdiskd mountpoint test retyring 25 25 - rework delete_instance() to avoid requiring an index on instance.uri 26 - nebdiskd bug fixes: fix debug mode outpoint going to mail, remove db 27 passwd requirement (not all dbs require a password param) 28 - completely rework how mountedvol is populated, drop mount table 26 29 27 30 0.16 -
trunk/Nebulous-Server/bin/nebdiskd
r24539 r24540 37 37 38 38 GetOptions( 39 'dbhost| h=s' => \$dbhost,39 'dbhost|H=s' => \$dbhost, 40 40 'dbpass|p=s' => \$dbpass, 41 41 'dbuser|u=s' => \$dbuser, … … 47 47 'retry=i' => \$retry, 48 48 'stop|s' => \$stop, 49 'user =s'=> \$user,49 'user|U=s' => \$user, 50 50 'verbose|v' => \$verbose, 51 51 ) || pod2usage( 2 ); … … 61 61 $dbhost ||= $c->get_dbhost || $ENV{'NEB_DBHOST'} || 'localhost'; 62 62 $dbuser ||= $c->get_dbuser || $ENV{'NEB_USER'}; 63 $dbpass ||= $c->get_dbpass || $ENV{'NEB_PASS'} ;63 $dbpass ||= $c->get_dbpass || $ENV{'NEB_PASS'} || undef; 64 64 $pidfile ||= $c->get_pidfile || "/var/tmp/nebdiskd"; 65 65 $user ||= $c->get_user || $<; # user … … 85 85 86 86 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 87 pod2usage( -msg => "Required options: --db -- user --pass", -exitval => 2 )88 unless $db && $dbuser && $dbpass;87 pod2usage( -msg => "Required options: --db --dbuser", -exitval => 2 ) 88 unless $db && $dbuser; 89 89 90 90 # start up logging … … 111 111 log4perl.appender.Mailer.subject = nebdiskd alert 112 112 log4perl.appender.Mailer.buffered = 0 113 log4perl.appender. AppError.Filter= MatchWarn113 log4perl.appender.Mailer.Filter= MatchWarn 114 114 log4perl.appender.Mailer.layout = Log::Log4perl::Layout::PatternLayout 115 115 log4perl.appender.Mailer.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n … … 163 163 my $dbhost = $p{dbhost} or return; 164 164 my $dbuser = $p{dbuser} or return; 165 my $dbpass = $p{dbpass} or return;165 # my $dbpass = $p{dbpass} or return; 166 166 my $poll_interval = $p{poll_interval} || 60; 167 167 my $debug = $p{debug} || 0; … … 177 177 178 178 eval { 179 my $r_query = $dbh->prepare_cached("REPLACE INTO mount VALUES(?, ?, ?)");180 my $d_query = $dbh->prepare_cached("DELETE FROM mount , mountedvol WHERE mountpoint = ?");179 my $r_query = $dbh->prepare_cached("REPLACE INTO mountedvol SELECT *, ?, ? FROM volume WHERE mountpoint = ?"); 180 my $d_query = $dbh->prepare_cached("DELETE FROM mountedvol WHERE mountpoint = ?"); 181 181 182 182 # get list of mount points 183 183 my $mounts = []; 184 184 { 185 my $query = $dbh->prepared_cached("SELECT mountpoint FROM volume"); 185 # there may be multiple vol_ids per mountpoint but we only need to 186 # check each mointpont once 187 my $query = $dbh->prepare_cached("SELECT DISTINCT mountpoint FROM volume"); 186 188 $query->execute; 187 189 while (my $row = $query->fetchrow_hashref) { 188 push @$mounts, $row ->{'mountpoint'};190 push @$mounts, $row; 189 191 } 190 192 $query->finish; … … 193 195 # determine valid mountpoints 194 196 foreach my $mnt (@$mounts) { 195 $log->debug("checking $mnt"); 197 my $mountpoint = $mnt->{'mountpoint'}; 198 $log->debug("checking $mountpoint"); 196 199 # this /SHOULD/ fail if the mount point is handled by the 197 200 # automounter and it fails to mount … … 199 202 TEST: eval { 200 203 $tries++; 201 unless (is_mountpoint($m nt)) {204 unless (is_mountpoint($mountpoint)) { 202 205 $log->warn("$mnt is not a valid mountpoint"); 203 206 } … … 206 209 # try is_mountpoint() again if $retry > 1 207 210 if ($tries < $retry) { 208 $log->warn("retrying test of $m nt");211 $log->warn("retrying test of $mountpoint"); 209 212 goto TEST; 210 213 } 211 214 $log->warn($@); 212 $d_query->execute($m nt);215 $d_query->execute($mountpoint); 213 216 next; 214 217 } … … 217 220 # we determine if it's a valid mountpoint incase 218 221 # is_mountpoint() invokes the automounter 219 my $dev_info = df($m nt, 1024);222 my $dev_info = df($mountpoint, 1024); 220 223 unless (defined $dev_info) { 221 $log->error("can't find device info for $m nt");224 $log->error("can't find device info for $mountpoint"); 222 225 next; 223 226 } 224 227 225 228 # find vol_id(s) for mountpoint 226 $r_query->execute( $mnt, @$dev_info{qw( blocks used )});227 $log->debug("adding $m nt to db");229 $r_query->execute(@$dev_info{qw( blocks used )}, $mountpoint); 230 $log->debug("adding $mountpoint to db"); 228 231 229 232 } 230 233 231 $dbh->do("call getmountedvol()");234 # $dbh->do("call getmountedvol()"); 232 235 233 236 $dbh->commit; … … 263 266 my %p = @_; 264 267 268 # $p{dbpass} may be undef; 269 265 270 return unless defined $p{db} 266 271 and defined $p{dbhost} 267 and defined $p{dbuser} 268 and defined $p{dbpass}; 272 and defined $p{dbuser}; 269 273 270 274 my $sql = Nebulous::Server::SQL->new; … … 372 376 =head1 SYNOPSIS 373 377 374 nebdiskd [--db <db name>] [--user <db username>] [--pass <db password>] [--debug] [--pidfile <filename>] [--stop] [--restart] [--verbose] 378 nebdiskd [--db|-D <db name>] [--dbhost|-H <db hostname> 379 [--dbuser|-u <db username>] [--dbpass|-p <db password>] [--debug|-d] 380 [--user|-U <username>] [--group|-g <groupname>] [--pidfile <filename>] 381 [--retry <n>] [--stop|-s] [--restart|-r] [--verbose|-v] 375 382 376 383 =head1 DESCRIPTION … … 383 390 =over 4 384 391 385 =item * --db|- d<db name>392 =item * --db|-D <db name> 386 393 387 394 Name of database (C<namespace>) to write too. … … 390 397 variable is set. 391 398 392 =item * -- user|-u <dbusername>399 =item * --dbuser|-u <username> 393 400 394 401 Username to authenticate with. … … 397 404 variable is set. 398 405 399 =item * -- pass|-p <dbpassword>406 =item * --dbpass|-p <password> 400 407 401 408 Password to authenticate with. 409 410 Optional if defined in the F<.nebdiskdrc> file or the appropriate environment 411 variable is set or if the database does not require a password. 412 413 =item * --dbhost|-H <hostname> 414 415 Database host to connect to. 402 416 403 417 Optional if defined in the F<.nebdiskdrc> file or the appropriate environment 404 418 variable is set. 405 419 406 =item * --debug 420 =item * --debug|-d 407 421 408 422 This flag prevents the program from "daemonizing" so output can be sent to … … 425 439 instance. 426 440 427 =item * --verbose|-r 441 =item * --retry 442 443 The number of times to test a mountpoint for "mountedness" before giving up on 444 it. 445 446 =item * --verbose|-v 428 447 429 448 Turns on informational/debugging messages to be sent to the … … 431 450 with C<--debug>. 432 451 452 =item * --user|-U 453 454 user account to run daemon as. 455 456 =item * --group|-g 457 458 group to run daemon as. 459 433 460 =back 434 461 … … 443 470 =item * C<NEB_DB> 444 471 445 Equivalent to --db|- d472 Equivalent to --db|-D 446 473 447 474 =item * C<NEB_USER> 448 475 449 Equivalent to -- user|-u476 Equivalent to --dbuser|-u 450 477 451 478 =item * C<NEB_PASS> 452 479 453 Equivalent to -- pass|-p480 Equivalent to --dbpass|-p 454 481 455 482 =back … … 467 494 dbpass: '@neb@' 468 495 dbuser: nebulous 469 mounts:470 - /mnt471 - /tmp472 - /usr473 496 pidfile: /var/tmp/nebdiskd 474 497 poll_interval: 5 … … 480 503 =over 4 481 504 482 =item * C<mounts>483 484 A list of "paths" to C<stat(2)> before mounted volumes are polled. The propose485 of this option is to attempt to keep "automounted" volumes mounted while this486 program is running.487 488 505 This value may be omitted or left blank. 489 506 … … 493 510 494 511 This value may be omitted or left blank. The default value is C<60>s. 512 513 =item * C<retry> 514 515 Same as C<--retry>. 495 516 496 517 =back -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r24539 r24540 396 396 }, 397 397 get_mounted_volumes => qq{ 398 SELECT *FROM mountedvol ORDER BY host, name398 SELECT mountpoint, total, used, vol_id, name, host, path, allocate, available, xattr FROM mountedvol ORDER BY host, name 399 399 }, 400 400 ); … … 423 423 DROP TABLE IF EXISTS lock_record; 424 424 DROP TABLE IF EXISTS volume; 425 DROP TABLE IF EXISTS mount ;425 DROP TABLE IF EXISTS mountedvol; 426 426 DROP TABLE IF EXISTS log; 427 DROP TABLE IF EXISTS mountedvol;428 427 DROP TABLE IF EXISTS directory; 429 428 DROP PROCEDURE IF EXISTS getmountedvol; … … 518 517 host VARCHAR(255) NOT NULL, 519 518 path VARCHAR(255) UNIQUE NOT NULL, 520 mountpoint VARCHAR(255) NOT NULL,521 519 allocate BOOLEAN DEFAULT FALSE, 522 520 available BOOLEAN DEFAULT FALSE, 523 521 xattr BOOLEAN DEFAULT FALSE, 522 mountpoint VARCHAR(255) NOT NULL, 524 523 PRIMARY KEY(vol_id), 525 524 KEY(host(16)), … … 527 526 KEY(allocate), 528 527 KEY(available) 528 ) ENGINE=innodb DEFAULT CHARSET=latin1; 529 530 ### 531 532 CREATE TABLE mountedvol( 533 vol_id INT UNIQUE NOT NULL, 534 FOREIGN KEY(vol_id) REFERENCES volume(vol_id) ON DELETE CASCADE, 535 name VARCHAR(255) NOT NULL, 536 host VARCHAR(255) NOT NULL, 537 path VARCHAR(255) NOT NULL, 538 FOREIGN KEY(path) REFERENCES volume(path) ON DELETE CASCADE, 539 allocate BOOLEAN DEFAULT FALSE, 540 available BOOLEAN DEFAULT FALSE, 541 xattr BOOLEAN DEFAULT FALSE, 542 mountpoint VARCHAR(255) NOT NULL, 543 FOREIGN KEY(mountpoint) REFERENCES volume(mountpoint) ON DELETE CASCADE, 544 total BIGINT NOT NULL, 545 used BIGINT NOT NULL, 546 PRIMARY KEY(vol_id), 547 KEY(name), 548 KEY(host), 549 KEY(path), 550 KEY(allocate), 551 KEY(available), 552 KEY(xattr), 553 KEY(mountpoint(255)) 529 554 ) ENGINE=innodb DEFAULT CHARSET=latin1; 530 555 … … 548 573 ### 549 574 550 CREATE TABLE mount (551 mountpoint VARCHAR(255) NOT NULL,552 total BIGINT NOT NULL,553 used BIGINT NOT NULL,554 PRIMARY KEY(mountpoint)555 ) ENGINE=innodb DEFAULT CHARSET=latin1;556 557 ###558 559 575 CREATE TABLE log ( 560 576 timestamp TIMESTAMP, … … 564 580 message VARCHAR(2048) NOT NULL, 565 581 PRIMARY KEY(timestamp) 566 ) ENGINE=innodb DEFAULT CHARSET=latin1;567 568 ###569 570 CREATE TABLE mountedvol(571 mountpoint VARCHAR(255) NOT NULL,572 FOREIGN KEY(mountpoint) REFERENCES mount(mountpoint) ON DELETE CASCADE,573 total BIGINT NOT NULL,574 used BIGINT NOT NULL,575 vol_id INT NOT NULL,576 FOREIGN KEY(vol_id) REFERENCES volume(vol_id) ON DELETE CASCADE,577 name VARCHAR(255) NOT NULL,578 host VARCHAR(255) NOT NULL,579 path VARCHAR(255) NOT NULL,580 FOREIGN KEY(path) REFERENCES volume(path) ON DELETE CASCADE,581 allocate BOOLEAN DEFAULT FALSE,582 available BOOLEAN DEFAULT FALSE,583 xattr BOOLEAN DEFAULT FALSE,584 PRIMARY KEY(mountpoint),585 KEY(vol_id),586 KEY(name),587 KEY(host),588 KEY(path),589 KEY(allocate),590 KEY(available),591 KEY(xattr)592 582 ) ENGINE=innodb DEFAULT CHARSET=latin1; 593 583 -
trunk/Nebulous-Server/lib/Test/Nebulous.pm
r24372 r24540 55 55 56 56 # node01/node02: allocate = TRUE 57 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (1, 'node01', 'node01', ?, TRUE, TRUE) }, undef, $dir1); 58 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1); 57 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (1, 'node01', 'node01', ?, '/', TRUE, TRUE) }, undef, $dir1); 58 $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 1); 59 # $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1); 59 60 60 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (2, 'node02', 'node02', ?, TRUE, TRUE) }, undef, $dir2); 61 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2); 61 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (2, 'node02', 'node02', ?, '/', TRUE, TRUE) }, undef, $dir2); 62 $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e8 FROM volume WHERE vol_id = ? }, undef, 2); 63 # $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2); 62 64 63 65 # node03: allocate = TRUE 64 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (3, 'node03', 'node03', ?, TRUE, TRUE) }, undef, $dir3); 65 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir3); 66 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (3, 'node03', 'node03', ?, '/', TRUE, TRUE) }, undef, $dir3); 67 $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e8 FROM volume WHERE vol_id = ? }, undef, 3); 68 # $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir3); 66 69 67 70 # node04: allocate = FALSE, available = FALSE 68 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (4, 'node04', 'node04', ?, FALSE, FALSE) }, undef, $dir4); 69 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir4); 71 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (4, 'node04', 'node04', ?, '/', FALSE, FALSE) }, undef, $dir4); 72 $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 4); 73 # $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir4); 70 74 71 75 # node05: allocate = FALSE, available = TRUE 72 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (5, 'node05', 'node05', ?, FALSE, TRUE) }, undef, $dir5); 73 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir5); 76 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (5, 'node05', 'node05', ?, '/', FALSE, TRUE) }, undef, $dir5); 77 $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 5); 78 # $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir5); 74 79 75 80 # node06: allocate = TRUE, available = FALSE 76 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (6, 'node06', 'node06', ?, TRUE, FALSE) }, undef, $dir6); 77 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir6); 81 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (6, 'node06', 'node06', ?, '/', TRUE, FALSE) }, undef, $dir6); 82 $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 6); 83 # $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir6); 78 84 79 85 # node07: full 80 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (7, 'node07', 'node07', ?, TRUE, TRUE) }, undef, $dir7); 81 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir7); 86 $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (7, 'node07', 'node07', ?, '/', TRUE, TRUE) }, undef, $dir7); 87 $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e10 FROM volume WHERE vol_id = ? }, undef, 7); 88 # $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir7); 82 89 83 $dbh->do(qq{ call getmountedvol() });90 # $dbh->do(qq{ call getmountedvol() }); 84 91 } 85 92
Note:
See TracChangeset
for help on using the changeset viewer.
