Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13114)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13115)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.28 2007-05-01 02:52:04 jhoblitt Exp $
+# $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -120,5 +120,6 @@
 }
 
-sub create_object {
+sub create_object
+{
     my $self = shift;
 
@@ -143,24 +144,29 @@
     $log->debug( "entered - @_" );
 
-    $volume = $self->_get_storage_volume( $volume );
-
-    my $object_id;
+    # Find the storage volume to use.  We are doing this first as there's no
+    # point in creating a new storage object if we can't allocate a new
+    # instance. ->_get_storage_volume() throws an exception on failure.
+    my ($vol_id, $vol_path);
+    eval {
+        ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
+    };
+    if ($@) {
+        $log->logdie($@);
+    }
+
     my $ins_id;
-
     eval {
         {
             # create storage_object
-            # XXX prepare_cached() was causing test failures
-            my $query = $db->prepare( $sql->new_object ); 
-            $query->execute( 'NULL', $key );
-        }
-
+            my $query = $db->prepare_cached( $sql->new_object ); 
+            $query->execute('NULL', $key);
+        }
+
+        my $object_id;
         {
             # get object ID
-            my $query = $db->prepare_cached( $sql->last_insert_id );
+            my $query = $db->prepare( $sql->last_insert_id );
             $query->execute;
-            ( $object_id ) = $query->fetchrow_array;
-
-            $query->finish;
+            ($object_id) = $query->fetchrow_array;
         }
 
@@ -168,5 +174,5 @@
             # create storage_object_attr
             my $query = $db->prepare_cached( $sql->new_object_attr ); 
-            $query->execute( $object_id );
+            $query->execute($object_id);
         }
 
@@ -179,19 +185,19 @@
         {
             # get instance ID
-            my $query = $db->prepare_cached( $sql->last_insert_id );
+            my $query = $db->prepare( $sql->last_insert_id );
             $query->execute;
-            ( $ins_id ) = $query->fetchrow_array;
-
-            $query->finish;
-        }
-    };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( "database error: $@" );
-    }
-
-    my $uri = URI::file->new("$volume/$key.$ins_id");
-
-    $log->debug( "generated uri $uri");
+            ($ins_id) = $query->fetchrow_array;
+        }
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    # Unfortunately, since we want to use the instance row's ID as part of the
+    # actual on disk file name we can't try to create the file until after
+    # we've create both a new storage_storage object and instance.
+    my $uri = URI::file->new("$vol_path/$key.$ins_id");
+    $log->debug("generated uri $uri");
 
     # TODO add some stuff here to retry if unsucessful
@@ -199,7 +205,7 @@
         _create_empty_file($uri->file);
     };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( $@ );
+    if ($@) {
+        $db->rollback;
+        $log->logdie($@);
     }
 
@@ -207,33 +213,38 @@
         {
             my $query = $db->prepare_cached( $sql->update_instance_uri );
-            $query->execute( $uri, $ins_id );
+            # vol_id, uri, ins_id
+            $query->execute($vol_id, $uri, $ins_id);
         }
 
         $db->commit;
     };
-    $log->logdie( "database error: $@" ) if $@;
-
-    $log->debug( "leaving" );
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    $log->debug("leaving");
 
     return "$uri";
 }
 
-sub rename_object {
-    my $self = shift;
-
-    my ( $key, $newkey ) = validate_pos( @_,
-        {
-            type        => SCALAR,
-        },
-        {
-            type        => SCALAR,
-        },
-    );
-
-    my $log = $self->log;
-    my $sql = $self->sql;
-    my $db  =$self->db;
-
-    $log->debug( "entered - @_" );
+sub rename_object
+{
+    my $self = shift;
+
+    my ($key, $newkey) = validate_pos(@_,
+        {
+            type        => SCALAR,
+        },
+        {
+            type        => SCALAR,
+        },
+    );
+
+    my $log = $self->log;
+    my $sql = $self->sql;
+    my $db  =$self->db;
+
+    $log->debug("entered - @_");
 
     eval {
@@ -244,30 +255,25 @@
 
         # if we affected more then one row something very bad has happened.
-        unless ( $rows == 1 ) {
-            $log->logdie( "affected row count is $rows instead of 1" );
-        }
-    };
-    if ($@) {
-        $db->rollback;
-        $log->logdie( "database error: $@" );
-    }
-
-    eval { 
+        unless ($rows == 1) {
+            $log->logdie("affected row count is $rows instead of 1");
+        }
+
         $db->commit;
     };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( "database error: $@" );
-    }
-
-    $log->debug( "leaving" );
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    $log->debug("leaving");
 
     return $newkey;
 }
 
-sub replicate_object {
-    my $self = shift;
-
-    my ( $key, $volume ) = validate_pos( @_,
+sub replicate_object
+{
+    my $self = shift;
+
+    my ($key, $volume) = validate_pos(@_,
         {
             type        => SCALAR,
@@ -283,15 +289,17 @@
     my $db  =$self->db;
 
-    $log->debug( "entered - @_" );
-
-    # TODO
-    $volume = $self->_get_storage_volume();
-
-    my $path;
-    my $uri;
-
-    my $so_id;
+    $log->debug("entered - @_");
+
+    my ($vol_id, $vol_path);
+    eval {
+        ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
+    };
+    if ($@) {
+        $log->logdie($@);
+    }
+
     my $ins_id;
     eval {
+        my $so_id;
         {
             my $query = $db->prepare_cached( $sql->get_object_instances );
@@ -310,41 +318,46 @@
         {
             my $query = $db->prepare_cached( $sql->new_instance );
-            $query->execute( $so_id );
-        }
-
-        {
-            my $query = $db->prepare_cached( $sql->last_insert_id );
+            $query->execute($so_id);
+        }
+
+        {
+            my $query = $db->prepare( $sql->last_insert_id );
             $query->execute();
 
-            ( $ins_id ) = $query->fetchrow_array;
-
-            $query->finish;
-        }
-
-        {
-            $uri = URI::file->new("$volume/$key.$ins_id");
-            $log->debug("generated uri $uri");
-
+            ($ins_id) = $query->fetchrow_array;
+        }
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie( "database error: $@" );
+    }
+
+    my $uri = URI::file->new("$vol_path/$key.$ins_id");
+    $log->debug("generated uri $uri");
+
+    # TODO add some stuff here to retry if unsucessful
+    eval {
+        _create_empty_file($uri->file);
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie($@);
+    }
+
+    eval {
+        {
             my $query = $db->prepare_cached( $sql->update_instance_uri );
-            $query->execute( $uri, $ins_id );
-        }
-    };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( "database error: $@" );
-    }
-
-
-    eval {
-        _create_empty_file($uri->file);
-    };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( $@ );
-    }
-
-    $db->commit;
-
-    $log->debug( "leaving" );
+            # vol_id, uri, ins_id
+            $query->execute($vol_id, $uri, $ins_id);
+        }
+
+        $db->commit;
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    $log->debug("leaving");
 
     return "$uri";
@@ -1000,5 +1013,6 @@
 #  select *, total - used as free, (used / total) * 100 as perused from mount;
 
-sub _get_storage_volume {
+sub _get_storage_volume
+{
     my $self = shift;
 
@@ -1013,12 +1027,14 @@
     my $name = shift;
 
-    my $volume;
-    my $query;
-    eval {
-        # ask the db to generate the table of mounted Nebulous volume 
-        $query = $db->prepare_cached("call getmountedvol()");
-        $query->execute();
+    my ($vol_id, $vol_path);
+    eval {
+        {
+            # ask the db to generate the table of mounted Nebulous volume 
+            my $query = $db->prepare_cached("call getmountedvol()");
+            $query->execute();
+        }
 
         # TODO cache this?
+        my $query;
         my $rows;
         if ( $name ) {
@@ -1031,24 +1047,23 @@
 
         # there has to be atleast one storage volume
-        unless ( $rows > 0 ) {
-            $log->logdie( "affected row count is $rows instead of 1" );
-        }
-
-        $volume = $query->fetchrow_hashref->{ 'volume' };
-
+        unless ($rows > 0) {
+            $log->logdie( "affected row count is $rows instead of > 0" );
+        }
+
+        my $free;
+        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
         $query->finish;
-        $db->commit;
-    };
-    if ( $@ ) {
-        $query->finish;
-        $db->rollback;
-        $log->logdie( "database error: $@" ) if $@;
-    }
-
-    $log->logdie( "failed to find a suitable volume" ) unless defined $volume;
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    $log->logdie("failed to find a suitable volume" )
+        unless defined $vol_id and defined $vol_path;
 
     $log->debug( "leaving" );
 
-    return $volume;
+    return ($vol_id, $vol_path);
 }
 
@@ -1060,18 +1075,22 @@
     my $db  =$self->db;
 
-    my $volume;
+    my ($vol_id, $vol_path);
     eval {
         my $query = $db->prepare_cached( $sql->get_volume_by_name ); 
         $query->execute( $vol_name );
-        ( $volume ) = $query->fetchrow_array;
-
+        my $free;
+        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
         $query->finish;
     };
-    if ( $@ ) {
+    if ($@) {
         $db->rollback;
         $log->logdie( "database error: $@" );
     }
 
-    return ( defined $volume ) ? 1 : undef;
+    if (defined $vol_id and defined $vol_path) {
+        return 1;
+    } 
+
+    return;
 }
 
Index: /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13114)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13115)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.30 2007-05-01 02:52:04 jhoblitt Exp $
+# $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -17,5 +17,5 @@
     },
     update_instance_uri => qq{
-        UPDATE instance SET uri = ? WHERE ins_id = ?
+        UPDATE instance SET vol_id = ?, uri = ? WHERE ins_id = ?
     },
     last_insert_id      => qq{
@@ -38,11 +38,11 @@
         WHERE storage_object.so_id = ?
     },
-    new_object_instance  => qq{
+    new_object_instance => qq{
         INSERT INTO instance 
-        VALUES (NULL, LAST_INSERT_ID(), 'error', NULL, NULL, NULL, NULL)
+        VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL)
     },
     new_instance        => qq{
         INSERT INTO instance
-        VALUES (NULL, ?, 'error', NULL,NULL, NULL, NULL)
+        VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL)
     },
     get_object          => qq{
@@ -154,5 +154,6 @@
     get_storage_volume_byname   => qq{
         SELECT
-            path as volume,
+            vol_id,
+            path,
             total - used as free
         FROM mountedvol
@@ -165,5 +166,6 @@
     get_storage_volume          => qq{
         SELECT
-            path as volume,
+            vol_id,
+            path,
             total - used as free
         FROM mountedvol
@@ -210,4 +212,5 @@
 {
     my @clear = split /;/, <<END;
+SET FOREIGN_KEY_CHECKS=0;
 DROP TABLE IF EXISTS storage_object;
 DROP TABLE IF EXISTS storage_object_attr;
@@ -219,5 +222,6 @@
 DROP TABLE IF EXISTS class;
 DROP TABLE IF EXISTS log;
-DROP PROCEDURE IF EXISTS getmountedvol
+DROP PROCEDURE IF EXISTS getmountedvol;
+SET FOREIGN_KEY_CHECKS=1
 END
     $sql{get_db_clear} = \@clear;
@@ -273,4 +277,5 @@
     ins_id BIGINT NOT NULL AUTO_INCREMENT,
     so_id BIGINT NOT NULL,
+    vol_id INT NOT NULL,
     uri VARCHAR(255) NOT NULL,
     sha1sum CHAR(40) ASCII,
Index: /trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13114)
+++ /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13115)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.28 2007-05-01 02:52:04 jhoblitt Exp $
+# $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -120,5 +120,6 @@
 }
 
-sub create_object {
+sub create_object
+{
     my $self = shift;
 
@@ -143,24 +144,29 @@
     $log->debug( "entered - @_" );
 
-    $volume = $self->_get_storage_volume( $volume );
-
-    my $object_id;
+    # Find the storage volume to use.  We are doing this first as there's no
+    # point in creating a new storage object if we can't allocate a new
+    # instance. ->_get_storage_volume() throws an exception on failure.
+    my ($vol_id, $vol_path);
+    eval {
+        ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
+    };
+    if ($@) {
+        $log->logdie($@);
+    }
+
     my $ins_id;
-
     eval {
         {
             # create storage_object
-            # XXX prepare_cached() was causing test failures
-            my $query = $db->prepare( $sql->new_object ); 
-            $query->execute( 'NULL', $key );
-        }
-
+            my $query = $db->prepare_cached( $sql->new_object ); 
+            $query->execute('NULL', $key);
+        }
+
+        my $object_id;
         {
             # get object ID
-            my $query = $db->prepare_cached( $sql->last_insert_id );
+            my $query = $db->prepare( $sql->last_insert_id );
             $query->execute;
-            ( $object_id ) = $query->fetchrow_array;
-
-            $query->finish;
+            ($object_id) = $query->fetchrow_array;
         }
 
@@ -168,5 +174,5 @@
             # create storage_object_attr
             my $query = $db->prepare_cached( $sql->new_object_attr ); 
-            $query->execute( $object_id );
+            $query->execute($object_id);
         }
 
@@ -179,19 +185,19 @@
         {
             # get instance ID
-            my $query = $db->prepare_cached( $sql->last_insert_id );
+            my $query = $db->prepare( $sql->last_insert_id );
             $query->execute;
-            ( $ins_id ) = $query->fetchrow_array;
-
-            $query->finish;
-        }
-    };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( "database error: $@" );
-    }
-
-    my $uri = URI::file->new("$volume/$key.$ins_id");
-
-    $log->debug( "generated uri $uri");
+            ($ins_id) = $query->fetchrow_array;
+        }
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    # Unfortunately, since we want to use the instance row's ID as part of the
+    # actual on disk file name we can't try to create the file until after
+    # we've create both a new storage_storage object and instance.
+    my $uri = URI::file->new("$vol_path/$key.$ins_id");
+    $log->debug("generated uri $uri");
 
     # TODO add some stuff here to retry if unsucessful
@@ -199,7 +205,7 @@
         _create_empty_file($uri->file);
     };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( $@ );
+    if ($@) {
+        $db->rollback;
+        $log->logdie($@);
     }
 
@@ -207,33 +213,38 @@
         {
             my $query = $db->prepare_cached( $sql->update_instance_uri );
-            $query->execute( $uri, $ins_id );
+            # vol_id, uri, ins_id
+            $query->execute($vol_id, $uri, $ins_id);
         }
 
         $db->commit;
     };
-    $log->logdie( "database error: $@" ) if $@;
-
-    $log->debug( "leaving" );
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    $log->debug("leaving");
 
     return "$uri";
 }
 
-sub rename_object {
-    my $self = shift;
-
-    my ( $key, $newkey ) = validate_pos( @_,
-        {
-            type        => SCALAR,
-        },
-        {
-            type        => SCALAR,
-        },
-    );
-
-    my $log = $self->log;
-    my $sql = $self->sql;
-    my $db  =$self->db;
-
-    $log->debug( "entered - @_" );
+sub rename_object
+{
+    my $self = shift;
+
+    my ($key, $newkey) = validate_pos(@_,
+        {
+            type        => SCALAR,
+        },
+        {
+            type        => SCALAR,
+        },
+    );
+
+    my $log = $self->log;
+    my $sql = $self->sql;
+    my $db  =$self->db;
+
+    $log->debug("entered - @_");
 
     eval {
@@ -244,30 +255,25 @@
 
         # if we affected more then one row something very bad has happened.
-        unless ( $rows == 1 ) {
-            $log->logdie( "affected row count is $rows instead of 1" );
-        }
-    };
-    if ($@) {
-        $db->rollback;
-        $log->logdie( "database error: $@" );
-    }
-
-    eval { 
+        unless ($rows == 1) {
+            $log->logdie("affected row count is $rows instead of 1");
+        }
+
         $db->commit;
     };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( "database error: $@" );
-    }
-
-    $log->debug( "leaving" );
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    $log->debug("leaving");
 
     return $newkey;
 }
 
-sub replicate_object {
-    my $self = shift;
-
-    my ( $key, $volume ) = validate_pos( @_,
+sub replicate_object
+{
+    my $self = shift;
+
+    my ($key, $volume) = validate_pos(@_,
         {
             type        => SCALAR,
@@ -283,15 +289,17 @@
     my $db  =$self->db;
 
-    $log->debug( "entered - @_" );
-
-    # TODO
-    $volume = $self->_get_storage_volume();
-
-    my $path;
-    my $uri;
-
-    my $so_id;
+    $log->debug("entered - @_");
+
+    my ($vol_id, $vol_path);
+    eval {
+        ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
+    };
+    if ($@) {
+        $log->logdie($@);
+    }
+
     my $ins_id;
     eval {
+        my $so_id;
         {
             my $query = $db->prepare_cached( $sql->get_object_instances );
@@ -310,41 +318,46 @@
         {
             my $query = $db->prepare_cached( $sql->new_instance );
-            $query->execute( $so_id );
-        }
-
-        {
-            my $query = $db->prepare_cached( $sql->last_insert_id );
+            $query->execute($so_id);
+        }
+
+        {
+            my $query = $db->prepare( $sql->last_insert_id );
             $query->execute();
 
-            ( $ins_id ) = $query->fetchrow_array;
-
-            $query->finish;
-        }
-
-        {
-            $uri = URI::file->new("$volume/$key.$ins_id");
-            $log->debug("generated uri $uri");
-
+            ($ins_id) = $query->fetchrow_array;
+        }
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie( "database error: $@" );
+    }
+
+    my $uri = URI::file->new("$vol_path/$key.$ins_id");
+    $log->debug("generated uri $uri");
+
+    # TODO add some stuff here to retry if unsucessful
+    eval {
+        _create_empty_file($uri->file);
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie($@);
+    }
+
+    eval {
+        {
             my $query = $db->prepare_cached( $sql->update_instance_uri );
-            $query->execute( $uri, $ins_id );
-        }
-    };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( "database error: $@" );
-    }
-
-
-    eval {
-        _create_empty_file($uri->file);
-    };
-    if ( $@ ) {
-        $db->rollback;
-        $log->logdie( $@ );
-    }
-
-    $db->commit;
-
-    $log->debug( "leaving" );
+            # vol_id, uri, ins_id
+            $query->execute($vol_id, $uri, $ins_id);
+        }
+
+        $db->commit;
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    $log->debug("leaving");
 
     return "$uri";
@@ -1000,5 +1013,6 @@
 #  select *, total - used as free, (used / total) * 100 as perused from mount;
 
-sub _get_storage_volume {
+sub _get_storage_volume
+{
     my $self = shift;
 
@@ -1013,12 +1027,14 @@
     my $name = shift;
 
-    my $volume;
-    my $query;
-    eval {
-        # ask the db to generate the table of mounted Nebulous volume 
-        $query = $db->prepare_cached("call getmountedvol()");
-        $query->execute();
+    my ($vol_id, $vol_path);
+    eval {
+        {
+            # ask the db to generate the table of mounted Nebulous volume 
+            my $query = $db->prepare_cached("call getmountedvol()");
+            $query->execute();
+        }
 
         # TODO cache this?
+        my $query;
         my $rows;
         if ( $name ) {
@@ -1031,24 +1047,23 @@
 
         # there has to be atleast one storage volume
-        unless ( $rows > 0 ) {
-            $log->logdie( "affected row count is $rows instead of 1" );
-        }
-
-        $volume = $query->fetchrow_hashref->{ 'volume' };
-
+        unless ($rows > 0) {
+            $log->logdie( "affected row count is $rows instead of > 0" );
+        }
+
+        my $free;
+        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
         $query->finish;
-        $db->commit;
-    };
-    if ( $@ ) {
-        $query->finish;
-        $db->rollback;
-        $log->logdie( "database error: $@" ) if $@;
-    }
-
-    $log->logdie( "failed to find a suitable volume" ) unless defined $volume;
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie("database error: $@");
+    }
+
+    $log->logdie("failed to find a suitable volume" )
+        unless defined $vol_id and defined $vol_path;
 
     $log->debug( "leaving" );
 
-    return $volume;
+    return ($vol_id, $vol_path);
 }
 
@@ -1060,18 +1075,22 @@
     my $db  =$self->db;
 
-    my $volume;
+    my ($vol_id, $vol_path);
     eval {
         my $query = $db->prepare_cached( $sql->get_volume_by_name ); 
         $query->execute( $vol_name );
-        ( $volume ) = $query->fetchrow_array;
-
+        my $free;
+        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
         $query->finish;
     };
-    if ( $@ ) {
+    if ($@) {
         $db->rollback;
         $log->logdie( "database error: $@" );
     }
 
-    return ( defined $volume ) ? 1 : undef;
+    if (defined $vol_id and defined $vol_path) {
+        return 1;
+    } 
+
+    return;
 }
 
Index: /trunk/Nebulous/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13114)
+++ /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13115)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.30 2007-05-01 02:52:04 jhoblitt Exp $
+# $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -17,5 +17,5 @@
     },
     update_instance_uri => qq{
-        UPDATE instance SET uri = ? WHERE ins_id = ?
+        UPDATE instance SET vol_id = ?, uri = ? WHERE ins_id = ?
     },
     last_insert_id      => qq{
@@ -38,11 +38,11 @@
         WHERE storage_object.so_id = ?
     },
-    new_object_instance  => qq{
+    new_object_instance => qq{
         INSERT INTO instance 
-        VALUES (NULL, LAST_INSERT_ID(), 'error', NULL, NULL, NULL, NULL)
+        VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL)
     },
     new_instance        => qq{
         INSERT INTO instance
-        VALUES (NULL, ?, 'error', NULL,NULL, NULL, NULL)
+        VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL)
     },
     get_object          => qq{
@@ -154,5 +154,6 @@
     get_storage_volume_byname   => qq{
         SELECT
-            path as volume,
+            vol_id,
+            path,
             total - used as free
         FROM mountedvol
@@ -165,5 +166,6 @@
     get_storage_volume          => qq{
         SELECT
-            path as volume,
+            vol_id,
+            path,
             total - used as free
         FROM mountedvol
@@ -210,4 +212,5 @@
 {
     my @clear = split /;/, <<END;
+SET FOREIGN_KEY_CHECKS=0;
 DROP TABLE IF EXISTS storage_object;
 DROP TABLE IF EXISTS storage_object_attr;
@@ -219,5 +222,6 @@
 DROP TABLE IF EXISTS class;
 DROP TABLE IF EXISTS log;
-DROP PROCEDURE IF EXISTS getmountedvol
+DROP PROCEDURE IF EXISTS getmountedvol;
+SET FOREIGN_KEY_CHECKS=1
 END
     $sql{get_db_clear} = \@clear;
@@ -273,4 +277,5 @@
     ins_id BIGINT NOT NULL AUTO_INCREMENT,
     so_id BIGINT NOT NULL,
+    vol_id INT NOT NULL,
     uri VARCHAR(255) NOT NULL,
     sha1sum CHAR(40) ASCII,
