#!/bin/bash -ex
. ` dirname $0 ` /common.sh
dd if = /dev/zero of = ./testdata/test_osd1.bin bs = 1024 count = 1 seek = $(( 1024 * 1024 - 1 ))
dd if = /dev/zero of = ./testdata/test_osd2.bin bs = 1024 count = 1 seek = $(( 1024 * 1024 - 1 ))
dd if = /dev/zero of = ./testdata/test_osd3.bin bs = 1024 count = 1 seek = $(( 1024 * 1024 - 1 ))
build/src/vitastor-osd --osd_num 1 --bind_address 127.0.0.1 --etcd_address $ETCD_URL $( node mon/simple-offsets.js --format options --device ./testdata/test_osd1.bin 2>/dev/null) & >./testdata/osd1.log &
OSD1_PID = $!
build/src/vitastor-osd --osd_num 2 --bind_address 127.0.0.1 --etcd_address $ETCD_URL $( node mon/simple-offsets.js --format options --device ./testdata/test_osd2.bin 2>/dev/null) & >./testdata/osd2.log &
OSD2_PID = $!
build/src/vitastor-osd --osd_num 3 --bind_address 127.0.0.1 --etcd_address $ETCD_URL $( node mon/simple-offsets.js --format options --device ./testdata/test_osd3.bin 2>/dev/null) & >./testdata/osd3.log &
OSD3_PID = $!
cd mon
npm install
cd ..
node mon/mon-main.js --etcd_url http://$ETCD_URL --etcd_prefix "/vitastor" & >./testdata/mon.log &
MON_PID = $!
$ETCDCTL put /vitastor/config/pools '{"1":{"name":"testpool","scheme":"xor","pg_size":3,"pg_minsize":2,"parity_chunks":1,"pg_count":1,"failure_domain":"osd"}}'
sleep 2
if ! ( $ETCDCTL get /vitastor/config/pgs --print-value-only | jq -s -e '(. | length) != 0 and (.[0].items["1"]["1"].osd_set | sort) == ["1","2","3"]' ) ; then
format_error "FAILED: 1 PG NOT CONFIGURED"
fi
if ! ( $ETCDCTL get /vitastor/pg/state/1/1 --print-value-only | jq -s -e '(. | length) != 0 and .[0].state == ["active"]' ) ; then
format_error "FAILED: 1 PG NOT UP"
fi
if ! cmp build/src/block-vitastor.so /usr/lib/x86_64-linux-gnu/qemu/block-vitastor.so; then
sudo rm -f /usr/lib/x86_64-linux-gnu/qemu/block-vitastor.so
sudo ln -s " $( realpath .) /build/src/block-vitastor.so " /usr/lib/x86_64-linux-gnu/qemu/block-vitastor.so
fi
# Test basic write and snapshot
$ETCDCTL put /vitastor/config/inode/1/2 '{"name":"testimg","size":' $(( 32 * 1024 * 1024 )) '}'
LD_PRELOAD = libasan.so.5 \
fio -thread -name= test -ioengine= build/src/libfio_vitastor.so -bs= 4M -direct= 1 -iodepth= 1 -fsync= 1 -rw= write \
-etcd= $ETCD_URL -pool= 1 -inode= 2 -size= 32M -cluster_log_level= 10
$ETCDCTL put /vitastor/config/inode/1/2 '{"name":"testimg@0","size":' $(( 32 * 1024 * 1024 )) '}'
$ETCDCTL put /vitastor/config/inode/1/3 '{"parent_id":2,"name":"testimg","size":' $(( 32 * 1024 * 1024 )) '}'
LD_PRELOAD = libasan.so.5 \
fio -thread -name= test -ioengine= build/src/libfio_vitastor.so -bs= 4k -direct= 1 -iodepth= 1 -fsync= 32 -buffer_pattern= 0xdeadface \
-rw= randwrite -etcd= $ETCD_URL -image= testimg -number_ios= 1024
LD_PRELOAD = libasan.so.5 \
fio -thread -name= test -ioengine= build/src/libfio_vitastor.so -bs= 4M -direct= 1 -iodepth= 1 -rw= read -etcd= $ETCD_URL -pool= 1 -inode= 3 -size= 32M
qemu-img convert -S 4096 -p \
-f raw " vitastor:etcd_host=127.0.0.1\: $ETCD_PORT /v3:pool=1:inode=3:size= $(( 32 * 1024 * 1024 )) " \
-O raw ./testdata/merged.bin
qemu-img convert -S 4096 -p \
-f raw " vitastor:etcd_host=127.0.0.1\: $ETCD_PORT /v3:image=testimg@0 " \
-O raw ./testdata/layer0.bin
$ETCDCTL put /vitastor/config/inode/1/3 '{"name":"testimg","size":' $(( 32 * 1024 * 1024 )) '}'
qemu-img convert -S 4096 -p \
-f raw " vitastor:etcd_host=127.0.0.1\: $ETCD_PORT /v3:image=testimg " \
-O raw ./testdata/layer1.bin
node mon/merge.js ./testdata/layer0.bin ./testdata/layer1.bin ./testdata/check.bin
cmp ./testdata/merged.bin ./testdata/check.bin
format_green OK