Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 16264)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 16265)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.50 2008-01-26 02:04:46 jhoblitt Exp $
+# $Id: Server.pm,v 1.51 2008-01-31 02:26:33 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -161,13 +161,15 @@
         my $volume;
         ($volume, $key) = parse_neb_key($key);
-        if (defined $volume) {
-            die "$volume is not a valid volume name"
-                unless $self->_is_valid_volume_name($volume);
-        }
+        # vol_name overrides the key implied volume
         $vol_name ||= $volume;
-
-    }
-
-    my ($uri, $vol_id);
+    }
+
+    if (defined $vol_name and !$self->_is_valid_volume_name($vol_name)) {
+        die "$vol_name is not a valid volume name"
+    }
+        
+    my ($vol_id, $vol_path, $vol_xattr) = $self->_get_storage_volume($vol_name);
+
+    my $uri;
     eval {
         {
@@ -177,10 +179,10 @@
         }
 
-        my $object_id;
+        my $so_id;
         {
             # get object ID
             my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute;
-            ($object_id) = $query->fetchrow_array;
+            ($so_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
@@ -192,5 +194,5 @@
             # create storage_object_attr
             my $query = $db->prepare_cached( $sql->new_object_attr ); 
-            $query->execute($object_id);
+            $query->execute($so_id);
         }
 
@@ -198,5 +200,5 @@
             # create instance with no URI
             my $query = $db->prepare_cached( $sql->new_object_instance );
-            $query->execute;
+            $query->execute($vol_id);
         }
 
@@ -218,5 +220,5 @@
 
         # TODO add some stuff here to retry if unsucessful
-        ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
+        $uri = $self->_create_empty_instance_file($key, $so_id, $ins_id, $vol_path, $vol_xattr);
         $log->debug("created $uri on volume ID: $vol_id");
 
@@ -328,12 +330,15 @@
         my $volume;
         ($volume, $key) = parse_neb_key($key);
-        if (defined $volume) {
-            die "$volume is not a valid volume name"
-                unless $self->_is_valid_volume_name($volume);
-        }
+        # vol_name overrides the key implied volume
         $vol_name ||= $volume;
     }
 
-    my ($uri, $vol_id);
+    if (defined $vol_name and !$self->_is_valid_volume_name($vol_name)) {
+        die "$vol_name is not a valid volume name"
+    }
+        
+    my ($vol_id, $vol_path, $vol_xattr) = $self->_get_storage_volume($vol_name);
+
+    my $uri;
     eval {
         my $so_id;
@@ -355,5 +360,5 @@
         {
             my $query = $db->prepare_cached( $sql->new_instance );
-            $query->execute($so_id);
+            $query->execute($so_id, $vol_id);
         }
 
@@ -374,5 +379,5 @@
 
         # TODO add some stuff here to retry if unsucessful
-        ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
+        $uri = $self->_create_empty_instance_file($key, $so_id, $ins_id, $vol_path, $vol_xattr);
 
         {
@@ -1211,17 +1216,13 @@
     my $self = shift;
 
-    my ($key, $ins_id, $volume) = @_;
-
-    my $log = $self->log;
-    my $sql = $self->sql;
-    my $db  =$self->db;
-
-    # Find the storage volume to use. 
-    # ->_get_storage_volume() throws an exception on failure.
-    my ($vol_id, $vol_path, $xattr);
+    my ($key, $so_id, $ins_id, $vol_path, $xattr) =  @_;
+
+    my $log = $self->log;
+    my $sql = $self->sql;
+    my $db  =$self->db;
+
     my ($storage_filename);
     my ($uri);
     eval {
-        ($vol_id, $vol_path, $xattr) = $self->_get_storage_volume($volume);
         $storage_filename = $self->_generate_storage_filename($key, $ins_id);
         # XXX put a hook for directory hashing here
@@ -1240,5 +1241,5 @@
     }
 
-    return ($uri, $vol_id);
+    return $uri;
 }
 
Index: /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 16264)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 16265)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.46 2008-01-30 00:19:06 jhoblitt Exp $
+# $Id: SQL.pm,v 1.47 2008-01-31 02:26:33 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -40,9 +40,9 @@
     new_object_instance => qq{
         INSERT INTO instance 
-        VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL)
+        VALUES (NULL, LAST_INSERT_ID(), ?, 'error', NULL, NULL, NULL, NULL)
     },
     new_instance        => qq{
         INSERT INTO instance
-        VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL)
+        VALUES (NULL, ?, ?, 'error', NULL, NULL, NULL, NULL)
     },
     get_object          => qq{
@@ -253,4 +253,9 @@
             count(mountedvol.vol_id) > 0 as recoverable
         FROM storage_object
+        JOIN storage_object_attr
+            USING(so_id)
+        JOIN storage_object_xattr
+            ON storage_object.so_id = storage_object_xattr.so_id
+            AND storage_object_xattr.name = 'copies'
         JOIN instance
             USING(so_id)
Index: /trunk/Nebulous-Server/t/03_server_create_object.t
===================================================================
--- /trunk/Nebulous-Server/t/03_server_create_object.t	(revision 16264)
+++ /trunk/Nebulous-Server/t/03_server_create_object.t	(revision 16265)
@@ -3,10 +3,10 @@
 # Copryight (C) 2004-2005  Joshua Hoblitt
 #
-# $Id: 03_server_create_object.t,v 1.22 2008-01-25 02:06:08 jhoblitt Exp $
+# $Id: 03_server_create_object.t,v 1.23 2008-01-31 02:26:33 jhoblitt Exp $
 
 use strict;
 use warnings FATAL => qw( all );
 
-use Test::More tests => 65;
+use Test::More tests => 67;
 
 use lib qw( ./t ./lib );
@@ -239,4 +239,17 @@
 Test::Nebulous->setup;
 
+{
+    # volume name override 
+    # OK because the volume arg overrides the key's  implied volume
+    my $uri = $neb->create_object("neb://99/foo", "node01");
+
+    my ($scheme, $auth, $path, $query, $frag) = uri_split($uri);
+    ok(-e $path, "file exists");
+    ok($neb->find_instances("foo"), 'object key exists');
+    uri_scheme_ok($uri, 'file');
+}
+
+Test::Nebulous->setup;
+
 eval {
     $neb->create_object("foo");
@@ -326,12 +339,4 @@
 
 eval {
-    # volume name override
-    $neb->create_object("neb://99/foo", "node01");
-};
-like($@, qr/is not a valid volume name/, "volume name doesn't exist");
-
-Test::Nebulous->setup;
-
-eval {
     $neb->create_object();
 };
Index: /trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 16264)
+++ /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 16265)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.50 2008-01-26 02:04:46 jhoblitt Exp $
+# $Id: Server.pm,v 1.51 2008-01-31 02:26:33 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -161,13 +161,15 @@
         my $volume;
         ($volume, $key) = parse_neb_key($key);
-        if (defined $volume) {
-            die "$volume is not a valid volume name"
-                unless $self->_is_valid_volume_name($volume);
-        }
+        # vol_name overrides the key implied volume
         $vol_name ||= $volume;
-
-    }
-
-    my ($uri, $vol_id);
+    }
+
+    if (defined $vol_name and !$self->_is_valid_volume_name($vol_name)) {
+        die "$vol_name is not a valid volume name"
+    }
+        
+    my ($vol_id, $vol_path, $vol_xattr) = $self->_get_storage_volume($vol_name);
+
+    my $uri;
     eval {
         {
@@ -177,10 +179,10 @@
         }
 
-        my $object_id;
+        my $so_id;
         {
             # get object ID
             my $query = $db->prepare_cached( $sql->last_insert_id );
             $query->execute;
-            ($object_id) = $query->fetchrow_array;
+            ($so_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
@@ -192,5 +194,5 @@
             # create storage_object_attr
             my $query = $db->prepare_cached( $sql->new_object_attr ); 
-            $query->execute($object_id);
+            $query->execute($so_id);
         }
 
@@ -198,5 +200,5 @@
             # create instance with no URI
             my $query = $db->prepare_cached( $sql->new_object_instance );
-            $query->execute;
+            $query->execute($vol_id);
         }
 
@@ -218,5 +220,5 @@
 
         # TODO add some stuff here to retry if unsucessful
-        ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
+        $uri = $self->_create_empty_instance_file($key, $so_id, $ins_id, $vol_path, $vol_xattr);
         $log->debug("created $uri on volume ID: $vol_id");
 
@@ -328,12 +330,15 @@
         my $volume;
         ($volume, $key) = parse_neb_key($key);
-        if (defined $volume) {
-            die "$volume is not a valid volume name"
-                unless $self->_is_valid_volume_name($volume);
-        }
+        # vol_name overrides the key implied volume
         $vol_name ||= $volume;
     }
 
-    my ($uri, $vol_id);
+    if (defined $vol_name and !$self->_is_valid_volume_name($vol_name)) {
+        die "$vol_name is not a valid volume name"
+    }
+        
+    my ($vol_id, $vol_path, $vol_xattr) = $self->_get_storage_volume($vol_name);
+
+    my $uri;
     eval {
         my $so_id;
@@ -355,5 +360,5 @@
         {
             my $query = $db->prepare_cached( $sql->new_instance );
-            $query->execute($so_id);
+            $query->execute($so_id, $vol_id);
         }
 
@@ -374,5 +379,5 @@
 
         # TODO add some stuff here to retry if unsucessful
-        ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
+        $uri = $self->_create_empty_instance_file($key, $so_id, $ins_id, $vol_path, $vol_xattr);
 
         {
@@ -1211,17 +1216,13 @@
     my $self = shift;
 
-    my ($key, $ins_id, $volume) = @_;
-
-    my $log = $self->log;
-    my $sql = $self->sql;
-    my $db  =$self->db;
-
-    # Find the storage volume to use. 
-    # ->_get_storage_volume() throws an exception on failure.
-    my ($vol_id, $vol_path, $xattr);
+    my ($key, $so_id, $ins_id, $vol_path, $xattr) =  @_;
+
+    my $log = $self->log;
+    my $sql = $self->sql;
+    my $db  =$self->db;
+
     my ($storage_filename);
     my ($uri);
     eval {
-        ($vol_id, $vol_path, $xattr) = $self->_get_storage_volume($volume);
         $storage_filename = $self->_generate_storage_filename($key, $ins_id);
         # XXX put a hook for directory hashing here
@@ -1240,5 +1241,5 @@
     }
 
-    return ($uri, $vol_id);
+    return $uri;
 }
 
Index: /trunk/Nebulous/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 16264)
+++ /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 16265)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.46 2008-01-30 00:19:06 jhoblitt Exp $
+# $Id: SQL.pm,v 1.47 2008-01-31 02:26:33 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -40,9 +40,9 @@
     new_object_instance => qq{
         INSERT INTO instance 
-        VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL)
+        VALUES (NULL, LAST_INSERT_ID(), ?, 'error', NULL, NULL, NULL, NULL)
     },
     new_instance        => qq{
         INSERT INTO instance
-        VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL)
+        VALUES (NULL, ?, ?, 'error', NULL, NULL, NULL, NULL)
     },
     get_object          => qq{
@@ -253,4 +253,9 @@
             count(mountedvol.vol_id) > 0 as recoverable
         FROM storage_object
+        JOIN storage_object_attr
+            USING(so_id)
+        JOIN storage_object_xattr
+            ON storage_object.so_id = storage_object_xattr.so_id
+            AND storage_object_xattr.name = 'copies'
         JOIN instance
             USING(so_id)
Index: /trunk/Nebulous/t/03_server_create_object.t
===================================================================
--- /trunk/Nebulous/t/03_server_create_object.t	(revision 16264)
+++ /trunk/Nebulous/t/03_server_create_object.t	(revision 16265)
@@ -3,10 +3,10 @@
 # Copryight (C) 2004-2005  Joshua Hoblitt
 #
-# $Id: 03_server_create_object.t,v 1.22 2008-01-25 02:06:08 jhoblitt Exp $
+# $Id: 03_server_create_object.t,v 1.23 2008-01-31 02:26:33 jhoblitt Exp $
 
 use strict;
 use warnings FATAL => qw( all );
 
-use Test::More tests => 65;
+use Test::More tests => 67;
 
 use lib qw( ./t ./lib );
@@ -239,4 +239,17 @@
 Test::Nebulous->setup;
 
+{
+    # volume name override 
+    # OK because the volume arg overrides the key's  implied volume
+    my $uri = $neb->create_object("neb://99/foo", "node01");
+
+    my ($scheme, $auth, $path, $query, $frag) = uri_split($uri);
+    ok(-e $path, "file exists");
+    ok($neb->find_instances("foo"), 'object key exists');
+    uri_scheme_ok($uri, 'file');
+}
+
+Test::Nebulous->setup;
+
 eval {
     $neb->create_object("foo");
@@ -326,12 +339,4 @@
 
 eval {
-    # volume name override
-    $neb->create_object("neb://99/foo", "node01");
-};
-like($@, qr/is not a valid volume name/, "volume name doesn't exist");
-
-Test::Nebulous->setup;
-
-eval {
     $neb->create_object();
 };
