IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19791


Ignore:
Timestamp:
Sep 30, 2008, 2:30:53 PM (18 years ago)
Author:
jhoblitt
Message:

rework nebdiskd to only record data on volumes it is supposed to be monitoring and then only for paths that actually have volumes mounted on them

Location:
trunk/Nebulous-Server
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Build.PL

    r19623 r19791  
    1616        'Digest::SHA1'          => 0,
    1717        'File::ExtAttr'         => '1.03',
     18        'File::Mountpoint'      => '0.01',
    1819        'File::Path'            => '1.08',
    1920        'File::Spec'            => 0,
  • trunk/Nebulous-Server/Changes

    r19790 r19791  
    55    - rename neb-addvol -> neb-voladd
    66    - add a pid file to neb-admin so only one instance can be run at a time
     7    - rework nebdiskd to only record data on volumes it is supposed to be
     8      monitoring and then only for paths that actually have volumes mounted on
     9      them
    710
    8110.15 Thu Sep 11 13:00:59 HST 2008
  • trunk/Nebulous-Server/bin/nebdiskd

    r18416 r19791  
    33# Copyright (C) 2007  Joshua Hoblitt
    44#
    5 # $Id: nebdiskd,v 1.6 2008-07-03 22:01:03 jhoblitt Exp $
     5# $Id: nebdiskd,v 1.7 2008-10-01 00:30:53 jhoblitt Exp $
    66
    77use strict;
     
    99
    1010use vars qw( $VERSION );
    11 $VERSION = '0.02';
     11$VERSION = '0.03';
    1212
    1313use Config::YAML;
    1414use DBI;
     15use File::Mountpoint qw( is_mountpoint );
    1516use File::Spec;
    1617use Nebulous::Server::SQL;
     
    7475$SIG{HUP}  = sub { $c = read_rcfile($rcfile) };
    7576
    76 my $dbh = setup_db(
    77         db      => $db,
    78         dbhost  => $dbhost,
    79         dbuser  => $dbuser,
    80         dbpass  => $dbpass,
    81     );
    8277
    8378poll_mounts(
    84         dbh             => $dbh,
     79        db              => $db,
     80        dbhost          => $dbhost,
     81        dbuser          => $dbuser,
     82        dbpass          => $dbpass,
    8583        poll_interval   => $poll_interval,
    8684        debug           => $debug,
    87     ) or die "poll_mounts() should not have returned";
     85) or die "poll_mounts() should not have returned";
    8886
    8987sub poll_mounts
     
    9189    my %p = @_;
    9290
    93     my $dbh             = $p{dbh} or return;
     91    my $db              = $p{db} or return;
     92    my $dbhost          = $p{dbhost} or return;
     93    my $dbuser          = $p{dbuser} or return;
     94    my $dbpass          = $p{dbpass} or return;
    9495    my $poll_interval   = $p{poll_interval} || 60;
    9596    my $debug           = $p{debug} || 0;
     
    9899
    99100    while (1) {
    100         # list of mount points to stat so that the automounter will mount these
    101         # volumes if they have been unmounted.
    102         stat_dirs($mounts);
     101        # setup the db on every pass incase the database died on us
     102        my $dbh = setup_db(
     103            db      => $db,
     104            dbhost  => $dbhost,
     105            dbuser  => $dbuser,
     106            dbpass  => $dbpass,
     107        );
    103108
    104109        eval {
     110            my @valid_mounts;
     111
     112            # determine valid mountpoints
     113            foreach my $mnt (@$mounts) {
     114                print "checking $mnt\n" if $debug;
     115                # this /SHOULD/ fail if the mount point is handled by the
     116                # automounter and it fails to mount
     117                eval {
     118                    unless (is_mountpoint($mnt)) {
     119                        print "$mnt is not a valid mountpoint\n" if $debug;
     120                        next;
     121                    }
     122                };
     123                if ($@) {
     124                    print "$mnt is not a valid mountpoint\n" if $debug;
     125                    next;
     126                }
     127                push @valid_mounts, $mnt;
     128            }
     129            # empty the mount table
     130            $dbh->do("DELETE FROM mount");
     131            print "flushed mount table\n" if $debug;
     132
     133            # repopulate the mount table with all valid mounts that we are
     134            # supposed to be watching
    105135            my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)");
    106             $dbh->do("DELETE FROM mount");
    107 
    108             print "flushed mount table\n" if $debug;
    109 
     136            # get stats on all currently mounted volumes
     137            # this has to be done AFTER we determine what the valid mountpoints
     138            # are incase is_mountpoint() invokes the automounter
    110139            my $stats = $lxs->get;
    111             foreach my $dev (keys %$stats) {
    112                 my $mnt = $stats->{$dev};
    113                 my %mount;
    114                 $query->execute(@$mnt{qw( mountpoint total usage )});
    115                 print "adding $mnt->{mountpoint} to db\n" if $debug;
     140            $stats = fix_disk_stats($stats);
     141
     142            foreach my $mnt (@valid_mounts) {
     143                my $dev_info = $stats->{$mnt};
     144                unless (defined $dev_info) {
     145                    print "can't find device info for $mnt\n"
     146                        if $debug;
     147                    next;
     148                }
     149                $query->execute(@$dev_info{qw( mountpoint total usage )});
     150                print "adding $dev_info->{mountpoint} to db\n" if $debug;
    116151            }
    117152
     
    119154
    120155            $dbh->commit;
     156            print "commited to database\n" if $debug;
    121157        };
    122158        if ($@) {
    123             $db->rollback;
     159            $dbh->rollback;
     160            print "rolledback transaction\n" if $debug;
    124161            warn $@;
    125162        }
     
    158195    my $sql = Nebulous::Server::SQL->new;
    159196
    160     my $dbh = DBI->connect(
     197    my $dbh = DBI->connect_cached(
    161198        "DBI:mysql:database=$p{db}:host=$p{dbhost}",
    162199        $p{dbuser},
     
    247284        }
    248285    }
     286}
     287
     288
     289sub fix_disk_stats
     290{
     291    my $stats = shift;
     292
     293    # take the hash returned by Sys::Statistics::Linux::DiskUsage->new->get and
     294    # replace the keynames with those of the mountpoint for each device
     295    my %new_stats;
     296    foreach my $key (keys %$stats) {
     297        my $disk = $stats->{$key};
     298        $new_stats{$disk->{mountpoint}} = $disk;
     299    }
     300
     301    return \%new_stats;
    249302}
    250303
Note: See TracChangeset for help on using the changeset viewer.