Skip to content

Commit

Permalink
Merge pull request #303 from tmenjo/md-is-sparse-object
Browse files Browse the repository at this point in the history
sheep: Only ledger and inode objects keep sparse when "dog node md plug"
  • Loading branch information
mitake committed Aug 31, 2016
2 parents ba1f39a + 9c8c07e commit dbf83bc
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sheep/store/md.c
Expand Up @@ -651,6 +651,7 @@ static int md_move_object(uint64_t oid, const char *old, const char *new)
struct strbuf buf = STRBUF_INIT;
int fd, ret = -1;
size_t sz = get_store_objsize(oid);
const bool sparse = is_sparse_object(oid);

fd = open(old, O_RDONLY);
if (fd < 0) {
Expand All @@ -665,7 +666,7 @@ static int md_move_object(uint64_t oid, const char *old, const char *new)
goto out_close;
}

if (atomic_create_and_write(new, buf.buf, buf.len, false, true) < 0) {
if (atomic_create_and_write(new, buf.buf, buf.len, false, sparse) < 0) {
if (errno != EEXIST) {
sd_err("failed to create %s", new);
ret = -1;
Expand Down
57 changes: 57 additions & 0 deletions tests/functional/114
@@ -0,0 +1,57 @@
#!/bin/bash

# Test md plug and sparse object

. ./common

MD=true

_need_to_be_root

if [ "$STORE" != "/tmp/sheepdog/114" ]; then
_notrun "This test cannot be run when WD is manually set"
fi

function _listFiles
{
for i in "$@" ; do
stat -c "%n %b %B %s" "$i"/* |\
awk '{print $1,$2*$3,$4;}' |\
sort |\
_filter_store
done
}

function setUp
{
_make_device 0 $((256*1024**2))
_make_device 1 $((256*1024**2))
_make_device 2 $((256*1024**2))
MD_STORE=",$STORE/1"
_start_sheep 0
_wait_for_sheep 1
_cluster_format -c 1
}

function testPlugAndSparse
{
setUp

$DOG node md info | _filter_store

for ((i=0; i<10; ++i)) ; do
$DOG vdi create -P "v$i" 8M
done

_listFiles "$STORE"/1

$DOG node md plug -f "$STORE"/2
_wait_for_sheep_recovery 0

$DOG node md info | _filter_store
_listFiles "$STORE"/{1,2}

_cleanup
}

testPlugAndSparse
67 changes: 67 additions & 0 deletions tests/functional/114.out
@@ -0,0 +1,67 @@
QA output created by 114
using backend plain store
Id Size Used Avail Use% Path
0 229 MB 0.0 MB 229 MB 0% STORE/1
STORE/1/0070839000000000 4194304 4194304
STORE/1/0070839000000001 4194304 4194304
STORE/1/0070854300000000 4194304 4194304
STORE/1/0070854300000001 4194304 4194304
STORE/1/0070912800000000 4194304 4194304
STORE/1/0070912800000001 4194304 4194304
STORE/1/007092db00000000 4194304 4194304
STORE/1/007092db00000001 4194304 4194304
STORE/1/0070948e00000000 4194304 4194304
STORE/1/0070948e00000001 4194304 4194304
STORE/1/0070964100000000 4194304 4194304
STORE/1/0070964100000001 4194304 4194304
STORE/1/007097f400000000 4194304 4194304
STORE/1/007097f400000001 4194304 4194304
STORE/1/007099a700000000 4194304 4194304
STORE/1/007099a700000001 4194304 4194304
STORE/1/00709b5a00000000 4194304 4194304
STORE/1/00709b5a00000001 4194304 4194304
STORE/1/00709d0d00000000 4194304 4194304
STORE/1/00709d0d00000001 4194304 4194304
STORE/1/8070839000000000 6144 12587576
STORE/1/8070854300000000 6144 12587576
STORE/1/8070912800000000 6144 12587576
STORE/1/807092db00000000 6144 12587576
STORE/1/8070948e00000000 6144 12587576
STORE/1/8070964100000000 6144 12587576
STORE/1/807097f400000000 6144 12587576
STORE/1/807099a700000000 6144 12587576
STORE/1/80709b5a00000000 6144 12587576
STORE/1/80709d0d00000000 6144 12587576
Id Size Used Avail Use% Path
0 229 MB 76 MB 153 MB 33% STORE/1
1 229 MB 4.0 MB 225 MB 1% STORE/2
STORE/1/0070839000000000 4194304 4194304
STORE/1/0070839000000001 4194304 4194304
STORE/1/0070854300000000 4194304 4194304
STORE/1/0070854300000001 4194304 4194304
STORE/1/0070912800000000 4194304 4194304
STORE/1/0070912800000001 4194304 4194304
STORE/1/007092db00000000 4194304 4194304
STORE/1/007092db00000001 4194304 4194304
STORE/1/0070948e00000000 4194304 4194304
STORE/1/0070948e00000001 4194304 4194304
STORE/1/0070964100000000 4194304 4194304
STORE/1/0070964100000001 4194304 4194304
STORE/1/007097f400000000 4194304 4194304
STORE/1/007097f400000001 4194304 4194304
STORE/1/007099a700000000 4194304 4194304
STORE/1/007099a700000001 4194304 4194304
STORE/1/00709b5a00000001 4194304 4194304
STORE/1/00709d0d00000000 4194304 4194304
STORE/1/00709d0d00000001 4194304 4194304
STORE/1/8070839000000000 6144 12587576
STORE/1/8070854300000000 6144 12587576
STORE/1/8070912800000000 6144 12587576
STORE/1/807092db00000000 6144 12587576
STORE/1/8070964100000000 6144 12587576
STORE/1/807097f400000000 6144 12587576
STORE/1/807099a700000000 6144 12587576
STORE/1/80709b5a00000000 6144 12587576
STORE/1/80709d0d00000000 6144 12587576
STORE/2/00709b5a00000000 4194304 4194304
STORE/2/8070948e00000000 8192 12587576
1 change: 1 addition & 0 deletions tests/functional/group
Expand Up @@ -121,3 +121,4 @@
111 auto quick dog
112 auto dog
113 auto dog
114 auto quick dog md

0 comments on commit dbf83bc

Please sign in to comment.