Index: trunk/Nebulous-Server/bin/neb-fsck
===================================================================
--- trunk/Nebulous-Server/bin/neb-fsck	(revision 16264)
+++ trunk/Nebulous-Server/bin/neb-fsck	(revision 17072)
@@ -3,5 +3,5 @@
 # Copyright (C) 2005-2008  Joshua Hoblitt
 #
-# $Id: neb-fsck,v 1.1 2008-01-30 00:19:34 jhoblitt Exp $
+# $Id: neb-fsck,v 1.2 2008-03-20 21:12:06 jhoblitt Exp $
 
 use strict;
@@ -59,4 +59,6 @@
 my $sql = Nebulous::Server::SQL->new();
 
+print "Pass 1: Look for objects with inaccessable instances\n";
+
 # so_id, ext_id, instances, available_instances, need_recovery, recoverable
 my $query = $dbh->prepare( $sql->find_objects_with_unavailable_instances );
@@ -70,14 +72,19 @@
 
 foreach my $obj (@rows) {
+#    use Data::Dumper;
+#    print Dumper($obj);
     my $so_id = $obj->{so_id};
     my $key = $obj->{ext_id};
     my $has = $obj->{instances};
-    my $available = $obj->{instances_available};
-    my $need = $obj->{need_recovery};
+    my $available = $obj->{available_instances} || 0;
+    my $need_recovery = $obj->{need_recovery};
     my $recoverable = $obj->{recoverable};
+    # if the copies xattr is unset and the object has 2 or more instances, we
+    # will assume a target of 2 copies
+    my $copies = $obj->{copies} || 2;
 
     # objects with only a single instance that are offline are unrecoverable so
     # we don't need to handle that special case
-    next unless $need;
+    next unless $need_recovery;
     unless ($recoverable) {
         warn "so_id: $so_id key: \'$key\' ",
@@ -86,13 +93,25 @@
     }
 
-    $available ||= 0;
-    next unless $available < 2;
-
-    warn "so_id: $so_id key: \'$key\' ",
-            " has only 1 instance avaiable -- replicating";
-
-    $neb->replicate($obj->{ext_id})
-        or warn "so_id: $so_id key: \'$key\' failed to replicate";
+    my $need = $copies - $available;
+    $need = 0 if $need < 0;
+
+    next unless $need;
+
+    for (; $need > 0; $need--) {
+        warn "so_id: $so_id key: \'$key\' ",
+            "has $available available instances, target $copies -- replicating";
+        $neb->replicate($obj->{ext_id})
+            or warn "so_id: $so_id key: \'$key\' replication failed";
+
+        $available++;
+    }
 }
+
+print "Pass 2: Check volumes for files without an instance\n";
+
+# get a list of volumes and their paths
+# get a list of all instances on a volume
+# get a list of all files under the volumes path
+# compare the two lists
 
 __END__
