Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13130)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13131)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $
+# $Id: Server.pm,v 1.31 2007-05-02 20:53:42 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -1022,5 +1022,4 @@
 }
 
-#  select *, total - used as free, (used / total) * 100 as perused from mount;
 
 sub _get_storage_volume
@@ -1051,5 +1050,6 @@
         if ( $name ) {
             $query = $db->prepare_cached( $sql->get_storage_volume_byname );
-            $rows = $query->execute(0.95, $name);
+            # %free, name, avaiable, allocate
+            $rows = $query->execute(0.95, $name, 1, 1);
             unless ($rows > 0) {
                 $query->finish;
@@ -1063,5 +1063,6 @@
         } else {
             $query = $db->prepare_cached( $sql->get_storage_volume );
-            $rows = $query->execute(0.95);
+            # %free, avaiable, allocate
+            $rows = $query->execute(0.95, 1, 1);
             # there has to be atleast one storage volume
             unless ($rows > 0) {
Index: /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13130)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13131)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $
+# $Id: SQL.pm,v 1.33 2007-05-02 20:53:42 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -161,4 +161,6 @@
             used / total < ?
             AND name = ?
+            AND available = ?
+            AND allocate = ?
         ORDER BY free DESC
         LIMIT 1
@@ -172,4 +174,6 @@
         WHERE
             used / total < ?
+            AND available = ?
+            AND allocate = ?
         ORDER BY free DESC
         LIMIT 1
@@ -177,5 +181,5 @@
     new_volume          => qq{
         INSERT INTO volume (name, path, allocate)
-        VALUES (?, ?, TRUE)
+        VALUES (?, ?, TRUE, TRUE)
     },
     get_volume_by_name => qq{
@@ -304,7 +308,9 @@
     path VARCHAR(255) NOT NULL,
     allocate BOOLEAN DEFAULT FALSE,
+    available BOOLEAN DEFAULT FALSE,
     PRIMARY KEY(vol_id),
     KEY(name(16)),
-    KEY(allocate)
+    KEY(allocate),
+    KEY(available)
 ) ENGINE=innodb;
 
@@ -337,6 +343,7 @@
     DECLARE namevar VARCHAR(255);
     DECLARE pathvar VARCHAR(255);
-    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume
-        WHERE allocate = TRUE;
+    DECLARE allocatevar BOOLEAN;
+    DECLARE availablevar BOOLEAN;
+    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available FROM volume;
     DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
 
@@ -353,5 +360,7 @@
         vol_id INT NOT NULL,
         name VARCHAR(255) NOT NULL,
-        path VARCHAR(255) NOT NULL
+        path VARCHAR(255) NOT NULL,
+        allocate BOOLEAN DEFAULT FALSE,
+        available BOOLEAN DEFAULT FALSE
     ) ENGINE=MEMORY;
 
@@ -363,8 +372,8 @@
 
     myloop: LOOP
-        FETCH cur1 INTO vol_idvar, namevar, pathvar;
+        FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar;
         IF `done` THEN LEAVE myloop; END IF;
         INSERT INTO mountedvol
-            SELECT mountpoint, total, used, vol_idvar, namevar, pathvar
+            SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar
             FROM
                 (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring
Index: /trunk/Nebulous-Server/t/03_server_create_object.t
===================================================================
--- /trunk/Nebulous-Server/t/03_server_create_object.t	(revision 13130)
+++ /trunk/Nebulous-Server/t/03_server_create_object.t	(revision 13131)
@@ -3,10 +3,10 @@
 # Copryight (C) 2004-2005  Joshua Hoblitt
 #
-# $Id: 03_server_create_object.t,v 1.14 2007-05-02 20:14:46 jhoblitt Exp $
+# $Id: 03_server_create_object.t,v 1.15 2007-05-02 20:53:42 jhoblitt Exp $
 
 use strict;
 use warnings FATAL => qw( all );
 
-use Test::More tests => 10;
+use Test::More tests => 12;
 
 use lib qw( ./t ./lib );
@@ -59,5 +59,5 @@
     $neb->create_object("foo", 'node03');
 };
-like($@, qr/node03 is not available/, "request volume with allocate = FALSE");
+like($@, qr/node03 is not available/, "request volume this is full");
 
 Test::Nebulous->setup;
@@ -66,5 +66,19 @@
     $neb->create_object("foo", 'node04');
 };
-like($@, qr/node04 is not available/, "request volume this is full");
+like($@, qr/node04 is not available/, "request volume with allocate = FALSE, available = FALSE");
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->create_object("foo", 'node05');
+};
+like($@, qr/node05 is not available/, "request volume with allocate = FALSE , available = TRUE");
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->create_object("foo", 'node06');
+};
+like($@, qr/node06 is not available/, "request volume with allocate = TRUE, available = FALSE");
 
 Test::Nebulous->setup;
Index: /trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13130)
+++ /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13131)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $
+# $Id: Server.pm,v 1.31 2007-05-02 20:53:42 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -1022,5 +1022,4 @@
 }
 
-#  select *, total - used as free, (used / total) * 100 as perused from mount;
 
 sub _get_storage_volume
@@ -1051,5 +1050,6 @@
         if ( $name ) {
             $query = $db->prepare_cached( $sql->get_storage_volume_byname );
-            $rows = $query->execute(0.95, $name);
+            # %free, name, avaiable, allocate
+            $rows = $query->execute(0.95, $name, 1, 1);
             unless ($rows > 0) {
                 $query->finish;
@@ -1063,5 +1063,6 @@
         } else {
             $query = $db->prepare_cached( $sql->get_storage_volume );
-            $rows = $query->execute(0.95);
+            # %free, avaiable, allocate
+            $rows = $query->execute(0.95, 1, 1);
             # there has to be atleast one storage volume
             unless ($rows > 0) {
Index: /trunk/Nebulous/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13130)
+++ /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13131)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $
+# $Id: SQL.pm,v 1.33 2007-05-02 20:53:42 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -161,4 +161,6 @@
             used / total < ?
             AND name = ?
+            AND available = ?
+            AND allocate = ?
         ORDER BY free DESC
         LIMIT 1
@@ -172,4 +174,6 @@
         WHERE
             used / total < ?
+            AND available = ?
+            AND allocate = ?
         ORDER BY free DESC
         LIMIT 1
@@ -177,5 +181,5 @@
     new_volume          => qq{
         INSERT INTO volume (name, path, allocate)
-        VALUES (?, ?, TRUE)
+        VALUES (?, ?, TRUE, TRUE)
     },
     get_volume_by_name => qq{
@@ -304,7 +308,9 @@
     path VARCHAR(255) NOT NULL,
     allocate BOOLEAN DEFAULT FALSE,
+    available BOOLEAN DEFAULT FALSE,
     PRIMARY KEY(vol_id),
     KEY(name(16)),
-    KEY(allocate)
+    KEY(allocate),
+    KEY(available)
 ) ENGINE=innodb;
 
@@ -337,6 +343,7 @@
     DECLARE namevar VARCHAR(255);
     DECLARE pathvar VARCHAR(255);
-    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume
-        WHERE allocate = TRUE;
+    DECLARE allocatevar BOOLEAN;
+    DECLARE availablevar BOOLEAN;
+    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available FROM volume;
     DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
 
@@ -353,5 +360,7 @@
         vol_id INT NOT NULL,
         name VARCHAR(255) NOT NULL,
-        path VARCHAR(255) NOT NULL
+        path VARCHAR(255) NOT NULL,
+        allocate BOOLEAN DEFAULT FALSE,
+        available BOOLEAN DEFAULT FALSE
     ) ENGINE=MEMORY;
 
@@ -363,8 +372,8 @@
 
     myloop: LOOP
-        FETCH cur1 INTO vol_idvar, namevar, pathvar;
+        FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar;
         IF `done` THEN LEAVE myloop; END IF;
         INSERT INTO mountedvol
-            SELECT mountpoint, total, used, vol_idvar, namevar, pathvar
+            SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar
             FROM
                 (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring
Index: /trunk/Nebulous/t/03_server_create_object.t
===================================================================
--- /trunk/Nebulous/t/03_server_create_object.t	(revision 13130)
+++ /trunk/Nebulous/t/03_server_create_object.t	(revision 13131)
@@ -3,10 +3,10 @@
 # Copryight (C) 2004-2005  Joshua Hoblitt
 #
-# $Id: 03_server_create_object.t,v 1.14 2007-05-02 20:14:46 jhoblitt Exp $
+# $Id: 03_server_create_object.t,v 1.15 2007-05-02 20:53:42 jhoblitt Exp $
 
 use strict;
 use warnings FATAL => qw( all );
 
-use Test::More tests => 10;
+use Test::More tests => 12;
 
 use lib qw( ./t ./lib );
@@ -59,5 +59,5 @@
     $neb->create_object("foo", 'node03');
 };
-like($@, qr/node03 is not available/, "request volume with allocate = FALSE");
+like($@, qr/node03 is not available/, "request volume this is full");
 
 Test::Nebulous->setup;
@@ -66,5 +66,19 @@
     $neb->create_object("foo", 'node04');
 };
-like($@, qr/node04 is not available/, "request volume this is full");
+like($@, qr/node04 is not available/, "request volume with allocate = FALSE, available = FALSE");
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->create_object("foo", 'node05');
+};
+like($@, qr/node05 is not available/, "request volume with allocate = FALSE , available = TRUE");
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->create_object("foo", 'node06');
+};
+like($@, qr/node06 is not available/, "request volume with allocate = TRUE, available = FALSE");
 
 Test::Nebulous->setup;
Index: /trunk/Nebulous/t/Test/Nebulous.pm
===================================================================
--- /trunk/Nebulous/t/Test/Nebulous.pm	(revision 13130)
+++ /trunk/Nebulous/t/Test/Nebulous.pm	(revision 13131)
@@ -1,5 +1,5 @@
 # Copyright (C) 2004  Joshua Hoblitt
 #
-# $Id: Nebulous.pm,v 1.13 2007-05-02 20:14:46 jhoblitt Exp $
+# $Id: Nebulous.pm,v 1.14 2007-05-02 20:53:42 jhoblitt Exp $
 
 package Test::Nebulous;
@@ -24,4 +24,6 @@
 my $dir3 = "";
 my $dir4 = "";
+my $dir5 = "";
+my $dir6 = "";
 
 sub setup {
@@ -35,4 +37,6 @@
     $dir3 = tempdir( CLEANUP => 0 );
     $dir4 = tempdir( CLEANUP => 0 );
+    $dir5 = tempdir( CLEANUP => 0 );
+    $dir6 = tempdir( CLEANUP => 0 );
 
     foreach my $statement (@{ $sql->get_db_schema }) {
@@ -41,17 +45,25 @@
 
     # node01/node02: allocate = TRUE
-    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (1, 'node01', ?, TRUE) }, undef, $dir1);
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (1, 'node01', ?, TRUE, TRUE) }, undef, $dir1);
     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1);
 
-    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (2, 'node02', ?, TRUE) }, undef, $dir2);
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (2, 'node02', ?, TRUE, TRUE) }, undef, $dir2);
     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2);
 
-    # node03: allocate = FALSE
-    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (3, 'node03', ?, FALSE) }, undef, $dir3);
-    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir3);
+    # node03: allocate = TRUE, volume full
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (3, 'node03', ?, TRUE, TRUE) }, undef, $dir3);
+    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir3);
 
-    # node04: allocate = TRUE, volume full
-    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (4, 'node04', ?, TRUE) }, undef, $dir4);
-    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir4);
+    # node04: allocate = FALSE, available = FALSE
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (4, 'node04', ?, FALSE, FALSE) }, undef, $dir4);
+    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir4);
+
+    # node05: allocate = FALSE, available = TRUE
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (5, 'node05', ?, FALSE, TRUE) }, undef, $dir5);
+    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir5);
+
+    # node06: allocate = TRUE, available = FALSE
+    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (6, 'node06', ?, TRUE, FALSE) }, undef, $dir4);
+    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir6);
 }
 
@@ -66,4 +78,6 @@
     rmtree([$dir3], 0, 1) if -e $dir3;
     rmtree([$dir4], 0, 1) if -e $dir4;
+    rmtree([$dir5], 0, 1) if -e $dir5;
+    rmtree([$dir6], 0, 1) if -e $dir6;
 }
 
