summaryrefslogtreecommitdiff
path: root/tests/bcache/discard.ktest
blob: fd2a7b590601a73671e1b3c6fa6800a1cb8be494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash

. $(dirname $(readlink -e ${BASH_SOURCE[0]}))/bcache-test-libs.sh

require-lib ../../../vm-tests/container_lib.sh
require-container ioctl_test

config-cache 2G
config-bucket-size 512k
config-block-size 2k
config-volume 1400M

config-timeout $(stress_timeout)

mb_to_sec()
{
    local mb=$1
    local sec=$((2*1024*$mb))
    echo "$sec"
}

main()
{
    setup_bcache

    bch_ioctl()
    {
	container_run ioctl_test /dev/bcache_extent0 $@
    }

    cd /root

    echo "-------- READ TEST -------- "

    dd if=/dev/zero of=bar bs=512 count=24
    bch_ioctl read	      1 8     24 | diff -q bar -

    echo "-------- UNIT TEST -------- "

    # this portion specifically tests to make sure discard doesn't
    # touch any surrounding keys

    dd if=/dev/urandom of=foo bs=4096 count=1
    touch bar

    echo "initial state setup ..."
    bch_ioctl write	      1 0     8 < foo
    bch_ioctl write	      1 16    8 < foo
    bch_ioctl write	      1 32    8 < foo

    echo "initial state check ..."
    bch_ioctl count_keys    0 1 0 2 0   |& grep "3 keys found";

    echo "discard ...."
    bch_ioctl discard	      1 8     24

    echo "after discard check ..."
    bch_ioctl list_keys	    0 1 0 2 0	|& grep "2 keys found"

    bch_ioctl read	      1 0     8 | diff -q foo -
    bch_ioctl read	      1 8     24 | diff -q bar -
    bch_ioctl read	      1 32    8 | diff -q foo -
   
    echo "------- FIO TEST -------- "

    run_fio

    bch_ioctl list_keys       1 0 0 100 100
    bch_ioctl count_keys      0 0 0 1 0 |& grep "ENOSPC"

    echo "discard ...."
    bch_ioctl discard	        0 0	"`mb_to_sec 1400`"
    bch_ioctl count_keys      0 0 0 1 0 |& grep "0 keys found"
}