Changeset 13302
- Timestamp:
- May 7, 2007, 4:27:42 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
-
Nebulous-Server/Changes (modified) (1 diff)
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (13 diffs)
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (8 diffs)
-
Nebulous-Server/t/03_server_create_object.t (modified) (8 diffs)
-
Nebulous-Server/t/04_server_replicate_object.t (modified) (6 diffs)
-
Nebulous/Changes (modified) (1 diff)
-
Nebulous/lib/Nebulous/Client.pm (modified) (2 diffs)
-
Nebulous/lib/Nebulous/Server.pm (modified) (13 diffs)
-
Nebulous/lib/Nebulous/Server/SQL.pm (modified) (8 diffs)
-
Nebulous/lib/Nebulous/Util.pm (modified) (4 diffs)
-
Nebulous/t/03_server_create_object.t (modified) (8 diffs)
-
Nebulous/t/04_server_replicate_object.t (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r13279 r13302 2 2 3 3 0.05 4 - make filesystem xattr support optional & disabled by default 4 5 - generate instance filenames that leave the "key" at the end so as to not 5 6 break a pplications that expect a certain "extension" on the filename -
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r13278 r13302 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.4 0 2007-05-05 02:59:31jhoblitt Exp $3 # $Id: Server.pm,v 1.41 2007-05-08 02:27:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 13 13 14 14 use DBI; 15 use File::ExtAttr qw( setfattr ); 15 16 use Log::Log4perl; 16 17 use Nebulous::Server::Config; … … 124 125 my $self = shift; 125 126 126 my ($key, $vol ume) = validate_pos(@_,127 my ($key, $vol_name) = validate_pos(@_, 127 128 { 128 129 type => SCALAR, … … 143 144 144 145 $log->debug( "entered - @_" ); 145 146 # Find the storage volume to use. We are doing this first as there's no147 # point in creating a new storage object if we can't allocate a new148 # instance. ->_get_storage_volume() throws an exception on failure.149 my ($vol_id, $vol_path);150 eval {151 ($vol_id, $vol_path) = $self->_get_storage_volume($volume);152 };153 if ($@) {154 $log->logdie($@);155 }156 146 157 147 my $ins_id; … … 206 196 # actual on disk file name we can't try to create the file until after 207 197 # we've create both a new storage_storage object and instance. 208 my $filename = $key;209 # mange '/'s into ':'210 $filename =~ s|/|:|g;211 my $uri = URI::file->new("$vol_path/$ins_id.$filename");212 $log->debug("generated uri $uri");213 198 214 199 # TODO add some stuff here to retry if unsucessful 215 eval { 216 _create_empty_file($uri->file, $key); 200 my ($uri, $vol_id); 201 eval { 202 ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name); 217 203 }; 218 204 if ($@) { … … 220 206 $log->logdie($@); 221 207 } 208 209 $log->debug("created $uri on volume ID: $vol_id"); 222 210 223 211 eval { … … 225 213 my $query = $db->prepare_cached( $sql->update_instance_uri ); 226 214 # vol_id, uri, ins_id 227 $query->execute($vol_id, $uri, $ins_id);215 $query->execute($vol_id, "$uri", $ins_id); 228 216 } 229 217 230 218 $db->commit; 219 $log->debug("commit"); 231 220 }; 232 221 if ($@) { … … 315 304 316 305 $log->debug("entered - @_"); 317 318 my ($vol_id, $vol_path);319 eval {320 ($vol_id, $vol_path) = $self->_get_storage_volume($vol_name);321 };322 if ($@) {323 $log->logdie($@);324 }325 306 326 307 my $ins_id; … … 361 342 } 362 343 363 my $filename = $key; 364 # mange '/'s into ':' 365 $filename =~ s|/|:|g; 366 my $uri = URI::file->new("$vol_path/$ins_id.$filename"); 367 $log->debug("generated uri $uri"); 344 # Unfortunately, since we want to use the instance row's ID as part of the 345 # actual on disk file name we can't try to create the file until after 346 # we've create both a new storage_storage object and instance. 368 347 369 348 # TODO add some stuff here to retry if unsucessful 370 eval { 371 _create_empty_file($uri->file, $key); 349 my ($uri, $vol_id); 350 eval { 351 ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name); 372 352 }; 373 353 if ($@) { … … 1107 1087 my $name = shift; 1108 1088 1109 my ($vol_id, $vol_path );1089 my ($vol_id, $vol_path, $xattr); 1110 1090 eval { 1111 1091 # TODO cache this? … … 1137 1117 1138 1118 my $free; 1139 ($vol_id, $vol_path, $ free) = $query->fetchrow_array;1119 ($vol_id, $vol_path, $xattr, $free) = $query->fetchrow_array; 1140 1120 $query->finish; 1141 1121 }; … … 1150 1130 $log->debug( "leaving" ); 1151 1131 1152 return ($vol_id, $vol_path );1132 return ($vol_id, $vol_path, $xattr); 1153 1133 } 1154 1134 … … 1210 1190 } 1211 1191 1192 sub _create_empty_instance_file 1193 { 1194 my $self = shift; 1195 1196 my ($key, $ins_id, $volume) = @_; 1197 1198 my $log = $self->log; 1199 my $sql = $self->sql; 1200 my $db =$self->db; 1201 1202 # Find the storage volume to use. 1203 # ->_get_storage_volume() throws an exception on failure. 1204 my ($vol_id, $vol_path, $xattr); 1205 my ($storage_filename); 1206 my ($uri); 1207 eval { 1208 ($vol_id, $vol_path, $xattr) = $self->_get_storage_volume($volume); 1209 $storage_filename = $self->_generate_storage_filename($key, $ins_id); 1210 # XXX put a hook for directory hashing here 1211 $uri = URI::file->new("$vol_path/$storage_filename"); 1212 $log->debug("generated uri $uri"); 1213 $self->_create_empty_file($uri->file); 1214 }; 1215 if ($@) { 1216 $log->logdie($@); 1217 } 1218 1219 if ($xattr) { 1220 my $path = $uri->file; 1221 die "can not set xattr on $path: $!" 1222 unless (setfattr($path, 'user.nebulous_key', $key)); 1223 } 1224 1225 return ($uri, $vol_id); 1226 } 1227 1228 1229 sub _create_empty_file 1230 { 1231 my $self = shift; 1232 1233 my ($path) = @_; 1234 1235 # perl's open() can't do an O_CREAT | O_EXCL 1236 die "file $path already exists" if (-e $path); 1237 1238 my $fh; 1239 die "can not open $path: $!" 1240 unless (open($fh, '>', $path)); 1241 1242 die "can not close $path: $!" 1243 unless (close($fh)); 1244 1245 die "can not chmod $path: $!" 1246 unless (chmod 0664, $path); 1247 1248 return $path; 1249 } 1250 1251 1252 sub _generate_storage_filename 1253 { 1254 my $self = shift; 1255 1256 my ($key, $ins_id) = @_; 1257 1258 my $filename = $key; 1259 # mangle '/'s into ':' 1260 $filename =~ s|/|:|g; 1261 1262 return "$ins_id.$filename" 1263 } 1264 1212 1265 1213 1266 sub DESTROY -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r13251 r13302 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.4 0 2007-05-04 23:36:46jhoblitt Exp $3 # $Id: SQL.pm,v 1.41 2007-05-08 02:27:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 204 204 vol_id, 205 205 path, 206 xattr, 206 207 total - used as free 207 208 FROM mountedvol … … 218 219 vol_id, 219 220 path, 221 xattr, 220 222 total - used as free 221 223 FROM mountedvol … … 228 230 }, 229 231 new_volume => qq{ 230 INSERT INTO volume (name, path, allocate, available )231 VALUES (?, ?, TRUE, TRUE )232 INSERT INTO volume (name, path, allocate, available, xattr) 233 VALUES (?, ?, TRUE, TRUE, FALSE) 232 234 }, 233 235 get_volume_by_name => qq{ … … 359 361 allocate BOOLEAN DEFAULT FALSE, 360 362 available BOOLEAN DEFAULT FALSE, 363 xattr BOOLEAN DEFAULT FALSE, 361 364 PRIMARY KEY(vol_id), 362 365 KEY(name(16)), … … 396 399 allocate BOOLEAN DEFAULT FALSE, 397 400 available BOOLEAN DEFAULT FALSE, 401 xattr BOOLEAN DEFAULT FALSE, 398 402 KEY(vol_id), 399 403 KEY(allocate), … … 411 415 DECLARE allocatevar BOOLEAN; 412 416 DECLARE availablevar BOOLEAN; 417 DECLARE xattrvar BOOLEAN; 413 418 DECLARE trans_level VARCHAR(255); 414 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available FROM volume;419 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available, xattr FROM volume; 415 420 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; 416 421 … … 430 435 431 436 myloop: LOOP 432 FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar ;437 FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar, xattrvar; 433 438 IF `done` THEN LEAVE myloop; END IF; 434 439 INSERT INTO mountedvol 435 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar 440 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar, xattrvar 436 441 FROM 437 442 (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring -
trunk/Nebulous-Server/t/03_server_create_object.t
r13273 r13302 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 03_server_create_object.t,v 1. 19 2007-05-05 02:25:09jhoblitt Exp $5 # $Id: 03_server_create_object.t,v 1.20 2007-05-08 02:27:42 jhoblitt Exp $ 6 6 7 7 use strict; … … 18 18 use Test::URI; 19 19 use URI::Split qw( uri_split ); 20 21 my $test_xattr = undef; 20 22 21 23 my $neb = Nebulous::Server->new( … … 35 37 uri_scheme_ok($uri, 'file'); 36 38 39 SKIP: { 40 skip "requires xattr support", 1 unless $test_xattr; 37 41 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 42 } 38 43 } 39 44 … … 48 53 uri_scheme_ok($uri, 'file'); 49 54 55 SKIP: { 56 skip "requires xattr support", 1 unless $test_xattr; 50 57 is(getfattr($path, 'user.nebulous_key'), '/foo', 'user.nebulous_key xattr'); 58 } 51 59 } 52 60 … … 61 69 uri_scheme_ok($uri, 'file'); 62 70 71 SKIP: { 72 skip "requires xattr support", 1 unless $test_xattr; 63 73 is(getfattr($path, 'user.nebulous_key'), '/foo/', 'user.nebulous_key xattr'); 74 } 64 75 } 65 76 … … 74 85 uri_scheme_ok($uri, 'file'); 75 86 87 SKIP: { 88 skip "requires xattr support", 1 unless $test_xattr; 76 89 is(getfattr($path, 'user.nebulous_key'), 'foo/', 'user.nebulous_key xattr'); 90 } 77 91 } 78 92 … … 87 101 uri_scheme_ok($uri, 'file'); 88 102 103 SKIP: { 104 skip "requires xattr support", 1 unless $test_xattr; 89 105 is(getfattr($path, 'user.nebulous_key'), 'foo/bar', 'user.nebulous_key xattr'); 106 } 90 107 } 91 108 … … 100 117 uri_scheme_ok($uri, 'file'); 101 118 119 SKIP: { 120 skip "requires xattr support", 1 unless $test_xattr; 102 121 is(getfattr($path, 'user.nebulous_key'), '/foo/bar', 'user.nebulous_key xattr'); 122 } 103 123 } 104 124 -
trunk/Nebulous-Server/t/04_server_replicate_object.t
r13273 r13302 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 04_server_replicate_object.t,v 1. 9 2007-05-05 02:25:09jhoblitt Exp $5 # $Id: 04_server_replicate_object.t,v 1.10 2007-05-08 02:27:42 jhoblitt Exp $ 6 6 7 7 use strict; … … 18 18 use Test::URI; 19 19 use URI::Split qw( uri_split ); 20 21 my $test_xattr = undef; 20 22 21 23 my $neb = Nebulous::Server->new( … … 36 38 uri_scheme_ok($uri, 'file'); 37 39 40 SKIP: { 41 skip "requires xattr support", 1 unless $test_xattr; 38 42 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 43 } 39 44 } 40 45 … … 50 55 uri_scheme_ok($uri, 'file'); 51 56 57 SKIP: { 58 skip "requires xattr support", 1 unless $test_xattr; 52 59 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 60 } 53 61 } 54 62 … … 66 74 uri_scheme_ok($uri1, 'file'); 67 75 76 SKIP: { 77 skip "requires xattr support", 1 unless $test_xattr; 68 78 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 79 } 69 80 } 70 81 … … 74 85 uri_scheme_ok($uri2, 'file'); 75 86 87 SKIP: { 88 skip "requires xattr support", 1 unless $test_xattr; 76 89 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 90 } 77 91 } 78 92 } -
trunk/Nebulous/Changes
r13279 r13302 2 2 3 3 0.05 4 - make filesystem xattr support optional & disabled by default 4 5 - generate instance filenames that leave the "key" at the end so as to not 5 6 break a pplications that expect a certain "extension" on the filename -
trunk/Nebulous/lib/Nebulous/Client.pm
r13256 r13302 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Client.pm,v 1.3 4 2007-05-05 00:14:17jhoblitt Exp $3 # $Id: Client.pm,v 1.35 2007-05-08 02:27:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Client; … … 257 257 258 258 $locations = $self->find_instances($key, $vol_name); 259 unless ( scalar @{ $locations }) {259 unless (defined $locations) { 260 260 $log->debug( "no instances" ); 261 261 $log->debug( "leaving" ); -
trunk/Nebulous/lib/Nebulous/Server.pm
r13278 r13302 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.4 0 2007-05-05 02:59:31jhoblitt Exp $3 # $Id: Server.pm,v 1.41 2007-05-08 02:27:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 13 13 14 14 use DBI; 15 use File::ExtAttr qw( setfattr ); 15 16 use Log::Log4perl; 16 17 use Nebulous::Server::Config; … … 124 125 my $self = shift; 125 126 126 my ($key, $vol ume) = validate_pos(@_,127 my ($key, $vol_name) = validate_pos(@_, 127 128 { 128 129 type => SCALAR, … … 143 144 144 145 $log->debug( "entered - @_" ); 145 146 # Find the storage volume to use. We are doing this first as there's no147 # point in creating a new storage object if we can't allocate a new148 # instance. ->_get_storage_volume() throws an exception on failure.149 my ($vol_id, $vol_path);150 eval {151 ($vol_id, $vol_path) = $self->_get_storage_volume($volume);152 };153 if ($@) {154 $log->logdie($@);155 }156 146 157 147 my $ins_id; … … 206 196 # actual on disk file name we can't try to create the file until after 207 197 # we've create both a new storage_storage object and instance. 208 my $filename = $key;209 # mange '/'s into ':'210 $filename =~ s|/|:|g;211 my $uri = URI::file->new("$vol_path/$ins_id.$filename");212 $log->debug("generated uri $uri");213 198 214 199 # TODO add some stuff here to retry if unsucessful 215 eval { 216 _create_empty_file($uri->file, $key); 200 my ($uri, $vol_id); 201 eval { 202 ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name); 217 203 }; 218 204 if ($@) { … … 220 206 $log->logdie($@); 221 207 } 208 209 $log->debug("created $uri on volume ID: $vol_id"); 222 210 223 211 eval { … … 225 213 my $query = $db->prepare_cached( $sql->update_instance_uri ); 226 214 # vol_id, uri, ins_id 227 $query->execute($vol_id, $uri, $ins_id);215 $query->execute($vol_id, "$uri", $ins_id); 228 216 } 229 217 230 218 $db->commit; 219 $log->debug("commit"); 231 220 }; 232 221 if ($@) { … … 315 304 316 305 $log->debug("entered - @_"); 317 318 my ($vol_id, $vol_path);319 eval {320 ($vol_id, $vol_path) = $self->_get_storage_volume($vol_name);321 };322 if ($@) {323 $log->logdie($@);324 }325 306 326 307 my $ins_id; … … 361 342 } 362 343 363 my $filename = $key; 364 # mange '/'s into ':' 365 $filename =~ s|/|:|g; 366 my $uri = URI::file->new("$vol_path/$ins_id.$filename"); 367 $log->debug("generated uri $uri"); 344 # Unfortunately, since we want to use the instance row's ID as part of the 345 # actual on disk file name we can't try to create the file until after 346 # we've create both a new storage_storage object and instance. 368 347 369 348 # TODO add some stuff here to retry if unsucessful 370 eval { 371 _create_empty_file($uri->file, $key); 349 my ($uri, $vol_id); 350 eval { 351 ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name); 372 352 }; 373 353 if ($@) { … … 1107 1087 my $name = shift; 1108 1088 1109 my ($vol_id, $vol_path );1089 my ($vol_id, $vol_path, $xattr); 1110 1090 eval { 1111 1091 # TODO cache this? … … 1137 1117 1138 1118 my $free; 1139 ($vol_id, $vol_path, $ free) = $query->fetchrow_array;1119 ($vol_id, $vol_path, $xattr, $free) = $query->fetchrow_array; 1140 1120 $query->finish; 1141 1121 }; … … 1150 1130 $log->debug( "leaving" ); 1151 1131 1152 return ($vol_id, $vol_path );1132 return ($vol_id, $vol_path, $xattr); 1153 1133 } 1154 1134 … … 1210 1190 } 1211 1191 1192 sub _create_empty_instance_file 1193 { 1194 my $self = shift; 1195 1196 my ($key, $ins_id, $volume) = @_; 1197 1198 my $log = $self->log; 1199 my $sql = $self->sql; 1200 my $db =$self->db; 1201 1202 # Find the storage volume to use. 1203 # ->_get_storage_volume() throws an exception on failure. 1204 my ($vol_id, $vol_path, $xattr); 1205 my ($storage_filename); 1206 my ($uri); 1207 eval { 1208 ($vol_id, $vol_path, $xattr) = $self->_get_storage_volume($volume); 1209 $storage_filename = $self->_generate_storage_filename($key, $ins_id); 1210 # XXX put a hook for directory hashing here 1211 $uri = URI::file->new("$vol_path/$storage_filename"); 1212 $log->debug("generated uri $uri"); 1213 $self->_create_empty_file($uri->file); 1214 }; 1215 if ($@) { 1216 $log->logdie($@); 1217 } 1218 1219 if ($xattr) { 1220 my $path = $uri->file; 1221 die "can not set xattr on $path: $!" 1222 unless (setfattr($path, 'user.nebulous_key', $key)); 1223 } 1224 1225 return ($uri, $vol_id); 1226 } 1227 1228 1229 sub _create_empty_file 1230 { 1231 my $self = shift; 1232 1233 my ($path) = @_; 1234 1235 # perl's open() can't do an O_CREAT | O_EXCL 1236 die "file $path already exists" if (-e $path); 1237 1238 my $fh; 1239 die "can not open $path: $!" 1240 unless (open($fh, '>', $path)); 1241 1242 die "can not close $path: $!" 1243 unless (close($fh)); 1244 1245 die "can not chmod $path: $!" 1246 unless (chmod 0664, $path); 1247 1248 return $path; 1249 } 1250 1251 1252 sub _generate_storage_filename 1253 { 1254 my $self = shift; 1255 1256 my ($key, $ins_id) = @_; 1257 1258 my $filename = $key; 1259 # mangle '/'s into ':' 1260 $filename =~ s|/|:|g; 1261 1262 return "$ins_id.$filename" 1263 } 1264 1212 1265 1213 1266 sub DESTROY -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r13251 r13302 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.4 0 2007-05-04 23:36:46jhoblitt Exp $3 # $Id: SQL.pm,v 1.41 2007-05-08 02:27:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 204 204 vol_id, 205 205 path, 206 xattr, 206 207 total - used as free 207 208 FROM mountedvol … … 218 219 vol_id, 219 220 path, 221 xattr, 220 222 total - used as free 221 223 FROM mountedvol … … 228 230 }, 229 231 new_volume => qq{ 230 INSERT INTO volume (name, path, allocate, available )231 VALUES (?, ?, TRUE, TRUE )232 INSERT INTO volume (name, path, allocate, available, xattr) 233 VALUES (?, ?, TRUE, TRUE, FALSE) 232 234 }, 233 235 get_volume_by_name => qq{ … … 359 361 allocate BOOLEAN DEFAULT FALSE, 360 362 available BOOLEAN DEFAULT FALSE, 363 xattr BOOLEAN DEFAULT FALSE, 361 364 PRIMARY KEY(vol_id), 362 365 KEY(name(16)), … … 396 399 allocate BOOLEAN DEFAULT FALSE, 397 400 available BOOLEAN DEFAULT FALSE, 401 xattr BOOLEAN DEFAULT FALSE, 398 402 KEY(vol_id), 399 403 KEY(allocate), … … 411 415 DECLARE allocatevar BOOLEAN; 412 416 DECLARE availablevar BOOLEAN; 417 DECLARE xattrvar BOOLEAN; 413 418 DECLARE trans_level VARCHAR(255); 414 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available FROM volume;419 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available, xattr FROM volume; 415 420 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; 416 421 … … 430 435 431 436 myloop: LOOP 432 FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar ;437 FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar, xattrvar; 433 438 IF `done` THEN LEAVE myloop; END IF; 434 439 INSERT INTO mountedvol 435 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar 440 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar, xattrvar 436 441 FROM 437 442 (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring -
trunk/Nebulous/lib/Nebulous/Util.pm
r13277 r13302 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Util.pm,v 1. 6 2007-05-05 02:54:52 jhoblitt Exp $3 # $Id: Util.pm,v 1.7 2007-05-08 02:27:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Util; … … 12 12 use base qw( Exporter ); 13 13 14 use File::ExtAttr qw( setfattr );15 14 use Log::Log4perl qw( :levels ); 16 15 use URI::file; … … 23 22 _get_filehandle 24 23 _open_uri 25 _create_empty_file26 24 ); 27 25 … … 80 78 } 81 79 82 sub _create_empty_file83 {84 my ($path, $key) = @_;85 86 # perl's open() can't do an O_CREAT | O_EXCL87 die "file $path already exists" if (-e $path);88 89 my $fh;90 die "can not open $path: $!"91 unless (open($fh, '>', $path));92 93 die "can not close $path: $!"94 unless (close($fh));95 96 die "can not chmod $path: $!"97 unless (chmod 0664, $path);98 99 die "can not set xattr on $path: $!"100 unless (setfattr($path, 'user.nebulous_key', $key));101 102 return $path;103 }104 105 80 1; 106 81 -
trunk/Nebulous/t/03_server_create_object.t
r13273 r13302 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 03_server_create_object.t,v 1. 19 2007-05-05 02:25:09jhoblitt Exp $5 # $Id: 03_server_create_object.t,v 1.20 2007-05-08 02:27:42 jhoblitt Exp $ 6 6 7 7 use strict; … … 18 18 use Test::URI; 19 19 use URI::Split qw( uri_split ); 20 21 my $test_xattr = undef; 20 22 21 23 my $neb = Nebulous::Server->new( … … 35 37 uri_scheme_ok($uri, 'file'); 36 38 39 SKIP: { 40 skip "requires xattr support", 1 unless $test_xattr; 37 41 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 42 } 38 43 } 39 44 … … 48 53 uri_scheme_ok($uri, 'file'); 49 54 55 SKIP: { 56 skip "requires xattr support", 1 unless $test_xattr; 50 57 is(getfattr($path, 'user.nebulous_key'), '/foo', 'user.nebulous_key xattr'); 58 } 51 59 } 52 60 … … 61 69 uri_scheme_ok($uri, 'file'); 62 70 71 SKIP: { 72 skip "requires xattr support", 1 unless $test_xattr; 63 73 is(getfattr($path, 'user.nebulous_key'), '/foo/', 'user.nebulous_key xattr'); 74 } 64 75 } 65 76 … … 74 85 uri_scheme_ok($uri, 'file'); 75 86 87 SKIP: { 88 skip "requires xattr support", 1 unless $test_xattr; 76 89 is(getfattr($path, 'user.nebulous_key'), 'foo/', 'user.nebulous_key xattr'); 90 } 77 91 } 78 92 … … 87 101 uri_scheme_ok($uri, 'file'); 88 102 103 SKIP: { 104 skip "requires xattr support", 1 unless $test_xattr; 89 105 is(getfattr($path, 'user.nebulous_key'), 'foo/bar', 'user.nebulous_key xattr'); 106 } 90 107 } 91 108 … … 100 117 uri_scheme_ok($uri, 'file'); 101 118 119 SKIP: { 120 skip "requires xattr support", 1 unless $test_xattr; 102 121 is(getfattr($path, 'user.nebulous_key'), '/foo/bar', 'user.nebulous_key xattr'); 122 } 103 123 } 104 124 -
trunk/Nebulous/t/04_server_replicate_object.t
r13273 r13302 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 04_server_replicate_object.t,v 1. 9 2007-05-05 02:25:09jhoblitt Exp $5 # $Id: 04_server_replicate_object.t,v 1.10 2007-05-08 02:27:42 jhoblitt Exp $ 6 6 7 7 use strict; … … 18 18 use Test::URI; 19 19 use URI::Split qw( uri_split ); 20 21 my $test_xattr = undef; 20 22 21 23 my $neb = Nebulous::Server->new( … … 36 38 uri_scheme_ok($uri, 'file'); 37 39 40 SKIP: { 41 skip "requires xattr support", 1 unless $test_xattr; 38 42 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 43 } 39 44 } 40 45 … … 50 55 uri_scheme_ok($uri, 'file'); 51 56 57 SKIP: { 58 skip "requires xattr support", 1 unless $test_xattr; 52 59 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 60 } 53 61 } 54 62 … … 66 74 uri_scheme_ok($uri1, 'file'); 67 75 76 SKIP: { 77 skip "requires xattr support", 1 unless $test_xattr; 68 78 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 79 } 69 80 } 70 81 … … 74 85 uri_scheme_ok($uri2, 'file'); 75 86 87 SKIP: { 88 skip "requires xattr support", 1 unless $test_xattr; 76 89 is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr'); 90 } 77 91 } 78 92 }
Note:
See TracChangeset
for help on using the changeset viewer.
