Index: trunk/Nebulous-Server/bin/neb-admin
===================================================================
--- trunk/Nebulous-Server/bin/neb-admin	(revision 20031)
+++ trunk/Nebulous-Server/bin/neb-admin	(revision 20060)
@@ -3,5 +3,5 @@
 # Copyright (C) 2005-2008  Joshua Hoblitt
 #
-# $Id: neb-admin,v 1.11 2008-10-09 23:41:47 jhoblitt Exp $
+# $Id: neb-admin,v 1.12 2008-10-11 02:13:23 jhoblitt Exp $
 
 use strict;
@@ -13,5 +13,5 @@
 use DBI;
 use Nebulous::Client;
-use Nebulous::Server::SQL;
+#use Nebulous::Server::SQL;
 use Net::Server::Daemonize qw( check_pid_file create_pid_file unlink_pid_file );
 use URI;
@@ -67,5 +67,5 @@
 );
 
-my $sql = Nebulous::Server::SQL->new();
+#my $sql = Nebulous::Server::SQL->new();
 
 # so_id, ext_id, instances, available_instances, need_recovery, recoverable
@@ -80,6 +80,38 @@
 }
 
-my $query = $dbh->prepare( $sql->find_objects_with_unavailable_instances
-        . " LIMIT $limit" );
+{
+    my $query = $dbh->prepare("CREATE TEMPORARY TABLE myvolume LIKE volume");
+    $query->execute;
+}
+
+{
+    my $query = $dbh->prepare("INSERT INTO myvolume SELECT * FROM volume");
+    $query->execute;
+}
+
+my $query = $dbh->prepare(
+"        SELECT
+            storage_object.so_id,
+            ext_id,
+            count(ins_id) as instances,
+            myvolume.name as volume_name,
+            myvolume.host as volume_host,
+            count(mymountedvol.vol_id) as available_instances,
+            count(mymountedvol.vol_id) > 0 as recoverable,
+            storage_object_xattr.value as copies
+        FROM storage_object
+        JOIN instance
+            USING(so_id)
+        JOIN myvolume
+            USING(vol_id)
+        LEFT JOIN storage_object_xattr
+            ON storage_object.so_id = storage_object_xattr.so_id
+        JOIN mymountedvol
+            USING(vol_id)
+        WHERE mymountedvol.available = 1
+--        WHERE storage_object_xattr.name = 'user.copies'
+        GROUP BY so_id
+        HAVING available_instances < instances OR instances < copies
+        LIMIT $limit" );
 $query->execute;
 
