Index: trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13115)
+++ trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13130)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $
+# $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -166,7 +166,11 @@
         {
             # get object ID
-            my $query = $db->prepare( $sql->last_insert_id );
+            my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute;
             ($object_id) = $query->fetchrow_array;
+            # XXX finish seems to be required when using LAST_INSERT_ID() or we
+            # get a warning about the stmt handling still be active the next
+            # time LAST_INSERT_ID() is invoked
+            $query->finish;
         }
 
@@ -185,7 +189,11 @@
         {
             # get instance ID
-            my $query = $db->prepare( $sql->last_insert_id );
+            my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute;
             ($ins_id) = $query->fetchrow_array;
+            # XXX finish seems to be required when using LAST_INSERT_ID() or we
+            # get a warning about the stmt handling still be active the next
+            # time LAST_INSERT_ID() is invoked
+            $query->finish;
         }
     };
@@ -322,8 +330,11 @@
 
         {
-            my $query = $db->prepare( $sql->last_insert_id );
+            my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute();
-
             ($ins_id) = $query->fetchrow_array;
+            # XXX finish seems to be required when using LAST_INSERT_ID() or we
+            # get a warning about the stmt handling still be active the next
+            # time LAST_INSERT_ID() is invoked
+            $query->finish;
         }
     };
@@ -1041,12 +1052,21 @@
             $query = $db->prepare_cached( $sql->get_storage_volume_byname );
             $rows = $query->execute(0.95, $name);
+            unless ($rows > 0) {
+                $query->finish;
+                $log->logdie("storage volume: $name is not available");
+            }
+            # when matching by name we shouldn't ever match more than once
+            if ($rows > 1) {
+                $query->finish;
+                $log->logdie("affected row count is $rows instead of 1");
+            }
         } else {
             $query = $db->prepare_cached( $sql->get_storage_volume );
             $rows = $query->execute(0.95);
-        }
-
-        # there has to be atleast one storage volume
-        unless ($rows > 0) {
-            $log->logdie( "affected row count is $rows instead of > 0" );
+            # there has to be atleast one storage volume
+            unless ($rows > 0) {
+                $query->finish;
+                $log->logdie("no storage volume is available");
+            }
         }
 
Index: trunk/Nebulous/lib/Nebulous/Server/SQL.pm
===================================================================
--- trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13115)
+++ trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13130)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $
+# $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -176,6 +176,6 @@
     },
     new_volume          => qq{
-        INSERT INTO volume (name, path)
-        VALUES (?, ?)
+        INSERT INTO volume (name, path, allocate)
+        VALUES (?, ?, TRUE)
     },
     get_volume_by_name => qq{
@@ -303,6 +303,8 @@
     name VARCHAR(255) UNIQUE NOT NULL,
     path VARCHAR(255) NOT NULL,
+    allocate BOOLEAN DEFAULT FALSE,
     PRIMARY KEY(vol_id),
-    KEY(name(16))
+    KEY(name(16)),
+    KEY(allocate)
 ) ENGINE=innodb;
 
@@ -335,5 +337,6 @@
     DECLARE namevar VARCHAR(255);
     DECLARE pathvar VARCHAR(255);
-    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume;
+    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume
+        WHERE allocate = TRUE;
     DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
 
