Skip to content

Instantly share code, notes, and snippets.

@0xIslamTaha
Last active June 6, 2018 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xIslamTaha/a29a42fc66b2fbc433430508528db896 to your computer and use it in GitHub Desktop.
Save 0xIslamTaha/a29a42fc66b2fbc433430508528db896 to your computer and use it in GitHub Desktop.

0-db Block Driver Testing

Here is a steps to test a 0-db block driver.

Scenario #1:

  • Option: Deploy an ubuntu vm
  • Build qemu from our repo
apt-get update
apt-get install -y git python build-essential gcc pkg-config glib-2.0 libglib2.0-dev libsdl1.2-dev libaio-dev libcap-dev libattr1-dev libpixman-1-dev libhiredis-dev virt-manager virt-viewer libvirt-bin
mkdir -p /opt/code/github && cd /opt/code/github
git clone https://github.com/gigforks/qemu qemu-zdb
cd /opt/code/github/qemu-zdb
git submodule update --init
./configure --target-list="x86_64-softmmu" --enable-kvm
make -j 5
ln -sf /opt/code/github/qemu-zdb/x86_64-softmmu/qemu-system-x86_64 /bin/qemu-system-x86_64
  • Start a ZDB server. By default it is running on 127.0.0.1:9900
cd /opt/code/github/
git clone https://github.com/rivine/0-db.git
make
ln -sf /opt/code/github/0-db/bin/zdb /bin/zdb
mkdir /opt/code/zdb
zdb
  • Create a zdb namespace. Here is an example
╭─root@xtrem-x ~  
╰─# redis-cli -h 10.101.107.102 -p 9900 
10.101.107.102:9900> PING
PONG
10.101.107.102:9900> NSNEW blockdriver1
OK
10.101.107.102:9900> NSNEW blockdriver2
OK
10.101.107.102:9900> 
  • Get a linux image or kernerl. Here is an ubuntu image
wget http://releases.ubuntu.com/16.04/ubuntu-16.04.4-desktop-amd64.iso
  • Start an ubuntu vm with this namespace
qemu-system-x86_64 -boot d -vnc :0 -display none -m 5120 -enable-kvm -cpu host -cdrom ubuntu-16.04.4-desktop-amd64.iso -serial null -serial mon:stdio -drive driver=zdb,port=9900,namespace=blockdriver1
  • Connect to this vm using the vnc client.
  • Mount the 0-db driver and write data then umount. Here is an example:
fdisk -l # Get the 0-db disk ex. /dev/sda
fdisk /dev/sda 
# Craete a partion
mkfs.ext4 /dev/sda1
mkdir sda1
mount /dev/sda1 sda1
cd sda1
echo "TESTING" > hello.txt
cd ..
umount sda1
  • Stop the vm.
  • Restart an ubuntu vm and mount /dev/sda1
  • cat hello.txt, You should get TESTING

Scenario #2:

Testing Thin-provisioning option

  • Start an ubutnu vm with namespace blockdriver1
qemu-system-x86_64 -boot d -vnc :0 -display none -m 5120 -enable-kvm -cpu host -cdrom ubuntu-16.04.4-desktop-amd64.iso -serial null -serial mon:stdio -drive driver=zdb,port=9900,size=20G,blocksize=8k,namespace=blockdriver1
  • Mount the 0-db driver and do echo "TEST" > TEST.txt then umount.
  • Stop the VM.
  • Start an ubuntu vm with namespace blockdriver2 and blockdriver1 as a thin-provisioning
qemu-system-x86_64 -boot d -vnc :0 -display none -m 5120 -enable-kvm -cpu host -cdrom /opt/code/ubuntu-16.04.4-desktop-amd64.iso -serial null -serial mon:stdio -drive driver=zdb,port=9900,size=20G,blocksize=8k,namespace=blockdriver2,host=127.0.0.1,thin-host=127.0.0.1,thin-namespace=blockdriver1
  • Mound the 0-db driver.
  • cat TEST.txt shoule print TEST

Scenario #3:

Testing Active-Active backup option

  • Start an ubuntu vm with source namespace source and back-up namespace backup as a 'Active-Active backup`
qemu-system-x86_64 -boot d -vnc :0 -display none -m 5120 -enable-kvm -cpu host -cdrom /opt/code/ubuntu-16.04.4-desktop-amd64.iso -serial null -serial mon:stdio -drive driver=zdb,port=9900,size=20G,blocksize=8k,namespace=source,host=127.0.0.1,backup-host=127.0.0.1,backup-namespace=backup
  • Mount the 0-db driver and do echo "TEST" > TEST.txt then umount.
  • Stop the VM.
  • Start an ubuntu vm with source namespace source only
qemu-system-x86_64 -boot d -vnc :0 -display none -m 5120 -enable-kvm -cpu host -cdrom /opt/code/ubuntu-16.04.4-desktop-amd64.iso -serial null -serial mon:stdio -drive driver=zdb,port=9900,size=20G,blocksize=8k,namespace=source,host=127.0.0.1
  • Mound the 0-db driver.
  • cat TEST.txt shoule print TEST
  • Stop the VM.
  • Start an ubuntu vm with backup namespace backup only
qemu-system-x86_64 -boot d -vnc :0 -display none -m 5120 -enable-kvm -cpu host -cdrom /opt/code/ubuntu-16.04.4-desktop-amd64.iso -serial null -serial mon:stdio -drive driver=zdb,port=9900,size=20G,blocksize=8k,namespace=backup,host=127.0.0.1
  • Mound the 0-db driver.
  • cat TEST.txt shoule print TEST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment