Merge pull request #14401 from dillaman/wip-rbd-import-fixes

rbd: correct issues with image importing

Reviewed-by: Mykola Golub <mgolub@mirantis.com>
This commit is contained in:
Mykola Golub 2017-04-10 22:23:53 +03:00 committed by GitHub
commit 712e7e9677
3 changed files with 27 additions and 82 deletions

View File

@ -145,24 +145,19 @@ if ceph osd dump | grep ^pool | grep "'rbd'" | grep tier; then
fi
# create specifically sparse files
# 1 1M block of sparse, 1 1M block of random, 1 1M block of zero, 1 1M block of random
# 1 1M block of sparse, 1 1M block of random
dd if=/dev/urandom bs=1M seek=1 count=1 of=${TMPDIR}/sparse1
dd if=/dev/zero bs=1M seek=2 count=1 of=${TMPDIR}/sparse1
dd if=/dev/urandom bs=1M seek=3 count=1 of=${TMPDIR}/sparse1
# 1 1M block of random, 1 1M block of sparse, 1 1M block of zero, 1 1M block of sparse
dd if=/dev/urandom bs=1M count=1 of=${TMPDIR}/sparse2;
dd if=/dev/zero bs=1M seek=2 count=1 of=${TMPDIR}/sparse2; truncate ${TMPDIR}/sparse2 -s 4M
# 1 1M block of random, 1 1M block of sparse
dd if=/dev/urandom bs=1M count=1 of=${TMPDIR}/sparse2; truncate ${TMPDIR}/sparse2 -s 2M
# 1M-block images; validate resulting blocks
# 1M sparse, 1M data, 1M zero, 1M data, with 4K sparse-size
rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 4K ${TMPDIR}/sparse1
rbd ls -l | grep sparse1 | grep -i '4096k'
rbd du sparse1 | grep '4096k 4096k'
rbd diff sparse1 | grep '1048576 1048576 data'
rbd diff sparse1 | grep '3145728 1048576 data'
[ $tiered -eq 1 -o "$(objects sparse1)" = '1 3' ]
# 1M sparse, 1M data
rbd rm sparse1 || true
rbd import $RBD_CREATE_ARGS --order 20 ${TMPDIR}/sparse1
rbd ls -l | grep sparse1 | grep -i '2048k'
[ $tiered -eq 1 -o "$(objects sparse1)" = '1' ]
# export, compare contents and on-disk size
rbd export sparse1 ${TMPDIR}/sparse1.out
@ -170,36 +165,10 @@ compare_files_and_ondisk_sizes ${TMPDIR}/sparse1 ${TMPDIR}/sparse1.out
rm ${TMPDIR}/sparse1.out
rbd rm sparse1
# 1M sparse, 1M data, 1M zero, 1M data, with 2M sparse-size
rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 2M ${TMPDIR}/sparse1
rbd ls -l | grep sparse1 | grep -i '4096k'
rbd du sparse1 | grep '4096k 4096k'
rbd diff sparse1 | grep '0 2097152 data'
rbd diff sparse1 | grep '2097152 2097152 data'
[ $tiered -eq 1 -o "$(objects sparse1)" = '1 3' ]
# export, compare contents and on-disk size
rbd export sparse1 ${TMPDIR}/sparse1.out
compare_files_and_ondisk_sizes ${TMPDIR}/sparse1 ${TMPDIR}/sparse1.out
rm ${TMPDIR}/sparse1.out
rbd rm sparse1
# 1M data, 1M sparse, 1M zero, 1M sparse, with 4K sparse-size
rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 4K ${TMPDIR}/sparse2
rbd ls -l | grep sparse2 | grep -i '4096k'
rbd du sparse2 | grep '4096k 2048k'
rbd diff sparse2 | grep '0 1048576 data'
[ $tiered -eq 1 -o "$(objects sparse2)" = '0' ]
rbd export sparse2 ${TMPDIR}/sparse2.out
compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out
rm ${TMPDIR}/sparse2.out
rbd rm sparse2
# 1M data, 1M sparse, 1M zero, 1M sparse, with 2M sparse-size
rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 2M ${TMPDIR}/sparse2
rbd ls -l | grep sparse2 | grep -i '4096k'
rbd du sparse2 | grep '4096k 2048k'
rbd diff sparse2 | grep '0 2097152 data'
# 1M data, 1M sparse
rbd rm sparse2 || true
rbd import $RBD_CREATE_ARGS --order 20 ${TMPDIR}/sparse2
rbd ls -l | grep sparse2 | grep -i '2048k'
[ $tiered -eq 1 -o "$(objects sparse2)" = '0' ]
rbd export sparse2 ${TMPDIR}/sparse2.out
compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out
@ -209,48 +178,20 @@ rbd rm sparse2
# extend sparse1 to 10 1M blocks, sparse at the end
truncate ${TMPDIR}/sparse1 -s 10M
# import from stdin just for fun, verify still sparse
rbd import $RBD_CREATE_ARGS --order 21 - sparse1 < ${TMPDIR}/sparse1
rbd import $RBD_CREATE_ARGS --order 20 - sparse1 < ${TMPDIR}/sparse1
rbd ls -l | grep sparse1 | grep -i '10240k'
rbd du sparse1 | grep '10240k 4096k'
rbd diff sparse1 | grep '1048576 1048576 data'
rbd diff sparse1 | grep '3145728 1048576 data'
[ $tiered -eq 1 -o "$(objects sparse1)" = '1 3' ]
rbd export sparse1 ${TMPDIR}/sparse1.out
compare_files_and_ondisk_sizes ${TMPDIR}/sparse1 ${TMPDIR}/sparse1.out
rm ${TMPDIR}/sparse1.out
rbd rm sparse1
# import from stdin just for fun, verify still sparse
rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 2M - sparse1 < ${TMPDIR}/sparse1
rbd ls -l | grep sparse1 | grep -i '10240k'
rbd du sparse1 | grep '10240k 4096k'
rbd diff sparse1 | grep '0 2097152 data'
rbd diff sparse1 | grep '2097152 2097152 data'
[ $tiered -eq 1 -o "$(objects sparse1)" = '1 3' ]
[ $tiered -eq 1 -o "$(objects sparse1)" = '1' ]
rbd export sparse1 ${TMPDIR}/sparse1.out
compare_files_and_ondisk_sizes ${TMPDIR}/sparse1 ${TMPDIR}/sparse1.out
rm ${TMPDIR}/sparse1.out
rbd rm sparse1
# extend sparse2 to 6M total with two more nonsparse megs
# extend sparse2 to 4M total with two more nonsparse megs
dd if=/dev/urandom bs=2M count=1 of=${TMPDIR}/sparse2 oflag=append conv=notrunc
# again from stding
rbd import $RBD_CREATE_ARGS --order 21 - sparse2 < ${TMPDIR}/sparse2
rbd ls -l | grep sparse2 | grep -i '6144k'
rbd du sparse2 | grep '6144k 4096k'
rbd diff sparse2 | grep '0 1048576 data'
rbd diff sparse2 | grep '4194304 2097152 data'
[ $tiered -eq 1 -o "$(objects sparse2)" = '0 4 5' ]
rbd export sparse2 ${TMPDIR}/sparse2.out
compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out
rm ${TMPDIR}/sparse2.out
rbd rm sparse2
# again from stding
rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 2M - sparse2 < ${TMPDIR}/sparse2
rbd ls -l | grep sparse2 | grep -i '6144k'
rbd du sparse2 | grep '6144k 4096k'
rbd diff sparse2 | grep '0 2097152 data'
rbd diff sparse2 | grep '4194304 2097152 data'
[ $tiered -eq 1 -o "$(objects sparse2)" = '0 4 5' ]
rbd import $RBD_CREATE_ARGS --order 20 - sparse2 < ${TMPDIR}/sparse2
rbd ls -l | grep sparse2 | grep -i '4096k'
[ $tiered -eq 1 -o "$(objects sparse2)" = '0 2 3' ]
rbd export sparse2 ${TMPDIR}/sparse2.out
compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out
rm ${TMPDIR}/sparse2.out
@ -262,7 +203,7 @@ rbd rm sparse2
echo "partially-sparse file imports to partially-sparse image"
rbd import $RBD_CREATE_ARGS --order 20 ${TMPDIR}/sparse1 sparse
[ $tiered -eq 1 -o "$(objects sparse)" = '1 3' ]
[ $tiered -eq 1 -o "$(objects sparse)" = '1' ]
rbd rm sparse
echo "zeros import through stdin to sparse image"

View File

@ -36,7 +36,7 @@ static const std::string RBD_DIFF_BANNER ("rbd diff v1\n");
static const size_t RBD_DEFAULT_SPARSE_SIZE = 4096;
static const std::string RBD_IMAGE_BANNER_V2 ("rbd image v2\n");
static const std::string RBD_IMAGE_DIFFS_BANNER_V2 ("rbd image diffss v2\n");
static const std::string RBD_IMAGE_DIFFS_BANNER_V2 ("rbd image diffs v2\n");
static const std::string RBD_DIFF_BANNER_V2 ("rbd diff v2\n");
#define RBD_DIFF_FROM_SNAP 'f'

View File

@ -220,7 +220,6 @@ static int do_image_io(ImportDiffContext *idiffctx, bool discard, size_t sparse_
::decode(off, p);
::decode(len, p);
bufferlist data;
if (!discard) {
bufferptr bp = buffer::create(len);
r = safe_read_exact(idiffctx->fd, bp.c_str(), len);
@ -242,7 +241,11 @@ static int do_image_io(ImportDiffContext *idiffctx, bool discard, size_t sparse_
bufferptr write_ptr(bp, write_offset, write_length);
bufferlist write_bl;
write_bl.push_back(write_ptr);
C_ImportDiff *ctx = new C_ImportDiff(idiffctx, data, off, len, discard);
assert(write_bl.length() == write_length);
C_ImportDiff *ctx = new C_ImportDiff(idiffctx, write_bl,
off + write_offset, write_length,
false);
r = ctx->send();
if (r < 0) {
@ -254,7 +257,8 @@ static int do_image_io(ImportDiffContext *idiffctx, bool discard, size_t sparse_
}
}
} else {
C_ImportDiff *ctx = new C_ImportDiff(idiffctx, data, off, len, discard);
bufferlist data;
C_ImportDiff *ctx = new C_ImportDiff(idiffctx, data, off, len, true);
return ctx->send();
}
return r;