IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20167


Ignore:
Timestamp:
Oct 14, 2008, 5:01:19 PM (18 years ago)
Author:
jhoblitt
Message:

make nebdiskd more crash resistent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/bin/nebdiskd

    r20134 r20167  
    33# Copyright (C) 2007  Joshua Hoblitt
    44#
    5 # $Id: nebdiskd,v 1.12 2008-10-14 02:56:30 jhoblitt Exp $
     5# $Id: nebdiskd,v 1.13 2008-10-15 03:01:19 jhoblitt Exp $
    66
    77use strict;
     
    9393$SIG{HUP}  = sub { $c = read_rcfile($rcfile) };
    9494
    95 
    96 poll_mounts(
    97         db              => $db,
    98         dbhost          => $dbhost,
    99         dbuser          => $dbuser,
    100         dbpass          => $dbpass,
    101         poll_interval   => $poll_interval,
    102         debug           => $debug,
    103 ) or die "poll_mounts() should not have returned";
     95while (1) {
     96    eval {
     97        poll_mounts(
     98                db              => $db,
     99                dbhost          => $dbhost,
     100                dbuser          => $dbuser,
     101                dbpass          => $dbpass,
     102                poll_interval   => $poll_interval,
     103                debug           => $debug,
     104        ) or die "poll_mounts() should not have returned";
     105    };
     106    if ($!) {
     107        warn $@;
     108    }
     109
     110    sleep $poll_interval;
     111}
     112
     113die "poll loop exited -- THIS SHOULD NOT HAPPEN";
     114
    104115
    105116sub poll_mounts
     
    114125    my $debug           = $p{debug} || 0;
    115126
    116     while (1) {
    117         # setup the db on every pass incase the database died on us
    118         my $dbh = setup_db(
    119             db      => $db,
    120             dbhost  => $dbhost,
    121             dbuser  => $dbuser,
    122             dbpass  => $dbpass,
    123         );
    124 
    125         eval {
    126             my $r_query = $dbh->prepare_cached("REPLACE INTO mount VALUES(?, ?, ?)");
    127             my $d_query = $dbh->prepare_cached("DELETE FROM mount WHERE mountpoint = ?");
    128 
    129             # determine valid mountpoints
    130             foreach my $mnt (@$mounts) {
    131                 print "checking $mnt\n" if $debug;
    132                 # this /SHOULD/ fail if the mount point is handled by the
    133                 # automounter and it fails to mount
    134                 eval {
    135                     unless (is_mountpoint($mnt)) {
    136                         die "$mnt is not a valid mountpoint\n";
    137                     }
    138                 };
    139                 if ($@) {
    140                     print $@ if $debug;
    141                     $d_query->execute($mnt);
    142                     next;
     127    # setup the db on every pass incase the database died on us
     128    my $dbh = setup_db(
     129        db      => $db,
     130        dbhost  => $dbhost,
     131        dbuser  => $dbuser,
     132        dbpass  => $dbpass,
     133    );
     134
     135    eval {
     136        my $r_query = $dbh->prepare_cached("REPLACE INTO mount VALUES(?, ?, ?)");
     137        my $d_query = $dbh->prepare_cached("DELETE FROM mount WHERE mountpoint = ?");
     138
     139        # determine valid mountpoints
     140        foreach my $mnt (@$mounts) {
     141            print "checking $mnt\n" if $debug;
     142            # this /SHOULD/ fail if the mount point is handled by the
     143            # automounter and it fails to mount
     144            eval {
     145                unless (is_mountpoint($mnt)) {
     146                    die "$mnt is not a valid mountpoint\n";
    143147                }
    144 
    145                 # fetch stats on the mounted device.  this has to be done AFTER
    146                 # we determine if it's a valid mountpoint incase
    147                 # is_mountpoint() invokes the automounter
    148                 my $dev_info = df($mnt, 1024);
    149                 unless (defined $dev_info) {
    150                     print "can't find device info for $mnt\n" if $debug;
    151                     next;
    152                 }
    153 
    154                 $r_query->execute($mnt, @$dev_info{qw( blocks used )});
    155                 print "adding $mnt to db\n" if $debug;
    156 
     148            };
     149            if ($@) {
     150                print $@ if $debug;
     151                $d_query->execute($mnt);
     152                next;
    157153            }
    158154
    159             $dbh->do("call getmountedvol()");
    160 
    161             $dbh->commit;
    162             print "commited to database\n" if $debug;
    163         };
    164         if ($@) {
    165             $dbh->rollback;
    166             print "rolledback transaction\n" if $debug;
    167             warn $@;
     155            # fetch stats on the mounted device.  this has to be done AFTER
     156            # we determine if it's a valid mountpoint incase
     157            # is_mountpoint() invokes the automounter
     158            my $dev_info = df($mnt, 1024);
     159            unless (defined $dev_info) {
     160                print "can't find device info for $mnt\n" if $debug;
     161                next;
     162            }
     163
     164            $r_query->execute($mnt, @$dev_info{qw( blocks used )});
     165            print "adding $mnt to db\n" if $debug;
     166
    168167        }
    169168
    170         sleep $poll_interval;
     169        $dbh->do("call getmountedvol()");
     170
     171        $dbh->commit;
     172        print "commited to database\n" if $debug;
     173    };
     174    if ($@) {
     175        $dbh->rollback;
     176        print "rolledback transaction\n" if $debug;
     177        warn $@;
    171178    }
    172179}
Note: See TracChangeset for help on using the changeset viewer.