summaryrefslogtreecommitdiffstats
path: root/tests/basic/open-behind/open-behind.t
blob: 5e865d602e2b6a218b186eeaf19dd46e4438b07f (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash

WD="$(dirname "${0}")"

. ${WD}/../../include.rc
. ${WD}/../../volume.rc

function assign() {
    local _assign_var="${1}"
    local _assign_value="${2}"

    printf -v "${_assign_var}" "%s" "${_assign_value}"
}

function pipe_create() {
    local _pipe_create_var="${1}"
    local _pipe_create_name
    local _pipe_create_fd

    _pipe_create_name="$(mktemp -u)"
    mkfifo "${_pipe_create_name}"
    exec {_pipe_create_fd}<>"${_pipe_create_name}"
    rm "${_pipe_create_name}"

    assign "${_pipe_create_var}" "${_pipe_create_fd}"
}

function pipe_close() {
    local _pipe_close_fd="${!1}"

    exec {_pipe_close_fd}>&-
}

function tester_start() {
    declare -ag tester
    local tester_in
    local tester_out

    pipe_create tester_in
    pipe_create tester_out

    ${WD}/tester <&${tester_in} >&${tester_out} &

    tester=("$!" "${tester_in}" "${tester_out}")
}

function tester_send() {
    declare -ag tester
    local tester_res
    local tester_extra

    echo "${*}" >&${tester[1]}

    read -t 3 -u ${tester[2]} tester_res tester_extra
    echo "${tester_res} ${tester_extra}"
    if [[ "${tester_res}" == "OK" ]]; then
        return 0
    fi

    return 1
}

function tester_stop() {
    declare -ag tester
    local tester_res

    tester_send "quit"

    tester_res=0
    if ! wait ${tester[0]}; then
        tester_res=$?
    fi

    unset tester

    return ${tester_res}
}

function count_open() {
    local file="$(realpath "${B0}/${V0}/${1}")"
    local count="0"
    local inode
    local ref

    inode="$(stat -c %i "${file}")"

    for fd in /proc/${BRICK_PID}/fd/*; do
        ref="$(readlink "${fd}")"
        if [[ "${ref}" == "${B0}/${V0}/"* ]]; then
            if [[ "$(stat -c %i "${ref}")" == "${inode}" ]]; then
                count="$((${count} + 1))"
            fi
        fi
    done

    echo "${count}"
}

cleanup

TEST build_tester ${WD}/tester.c ${WD}/tester-fd.c

TEST glusterd
TEST pidof glusterd
TEST ${CLI} volume create ${V0} ${H0}:${B0}/${V0}
TEST ${CLI} volume set ${V0} flush-behind off
TEST ${CLI} volume set ${V0} write-behind off
TEST ${CLI} volume set ${V0} quick-read off
TEST ${CLI} volume set ${V0} stat-prefetch on
TEST ${CLI} volume set ${V0} io-cache off
TEST ${CLI} volume set ${V0} open-behind on
TEST ${CLI} volume set ${V0} lazy-open off
TEST ${CLI} volume set ${V0} read-after-open off
TEST ${CLI} volume start ${V0}

TEST ${GFS} --volfile-id=/${V0} --volfile-server=${H0} ${M0};

BRICK_PID="$(get_brick_pid ${V0} ${H0} ${B0}/${V0})"

TEST touch "${M0}/test"

EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
TEST ${GFS} --volfile-id=/${V0} --volfile-server=${H0} ${M0};

TEST tester_start

TEST tester_send fd open 0 "${M0}/test"
EXPECT_WITHIN 5 "1" count_open "/test"
TEST tester_send fd close 0
EXPECT_WITHIN 5 "0" count_open "/test"

EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
TEST ${CLI} volume set ${V0} lazy-open on
TEST ${GFS} --volfile-id=/${V0} --volfile-server=${H0} ${M0};

TEST tester_send fd open 0 "${M0}/test"
sleep 2
EXPECT "0" count_open "/test"
TEST tester_send fd write 0 "test"
EXPECT "1" count_open "/test"
TEST tester_send fd close 0
EXPECT_WITHIN 5 "0" count_open "/test"

EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
TEST ${GFS} --volfile-id=/${V0} --volfile-server=${H0} ${M0};

TEST tester_send fd open 0 "${M0}/test"
EXPECT "0" count_open "/test"
EXPECT "test" tester_send fd read 0 64
# Even though read-after-open is disabled, use-anonymous-fd is also disabled,
# so reads need to open the file first.
EXPECT "1" count_open "/test"
TEST tester_send fd close 0
EXPECT "0" count_open "/test"

EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
TEST ${GFS} --volfile-id=/${V0} --volfile-server=${H0} ${M0};

TEST tester_send fd open 0 "${M0}/test"
EXPECT "0" count_open "/test"
TEST tester_send fd open 1 "${M0}/test"
EXPECT "2" count_open "/test"
TEST tester_send fd close 0
EXPECT_WITHIN 5 "1" count_open "/test"
TEST tester_send fd close 1
EXPECT_WITHIN 5 "0" count_open "/test"

EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
TEST ${CLI} volume set ${V0} read-after-open on
TEST ${GFS} --volfile-id=/${V0} --volfile-server=${H0} ${M0};

TEST tester_send fd open 0 "${M0}/test"
EXPECT "0" count_open "/test"
EXPECT "test" tester_send fd read 0 64
EXPECT "1" count_open "/test"
TEST tester_send fd close 0
EXPECT_WITHIN 5 "0" count_open "/test"

EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0

TEST tester_stop

cleanup