diff --git a/sheep/store/md.c b/sheep/store/md.c index 7d2748d5e..40673b80e 100644 --- a/sheep/store/md.c +++ b/sheep/store/md.c @@ -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) { @@ -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; diff --git a/tests/functional/114 b/tests/functional/114 new file mode 100755 index 000000000..8b0073d4c --- /dev/null +++ b/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 diff --git a/tests/functional/114.out b/tests/functional/114.out new file mode 100644 index 000000000..50341dca4 --- /dev/null +++ b/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 diff --git a/tests/functional/group b/tests/functional/group index 54a8d0a6b..766f1fec6 100644 --- a/tests/functional/group +++ b/tests/functional/group @@ -121,3 +121,4 @@ 111 auto quick dog 112 auto dog 113 auto dog +114 auto quick dog md