Skip to content

Commit 533c87e

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add test for UBLK_F_QUIESCE
Add test generic_11 for covering new control command of UBLK_U_CMD_QUIESCE_DEV. Add 'quiesce -n dev_id' sub-command on ublk utility for transitioning device state to quiesce states, then verify the feature via generic_10 by doing quiesce and recovery. Cc: Yoav Cohen <[email protected]> Link: https://lore.kernel.org/linux-block/DM4PR12MB632807AB7CDCE77D1E5AB7D0A9B92@DM4PR12MB6328.namprd12.prod.outlook.com/ Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent b465ae7 commit 533c87e

File tree

6 files changed

+115
-5
lines changed

6 files changed

+115
-5
lines changed

tools/testing/selftests/ublk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TEST_PROGS += test_generic_07.sh
1818
TEST_PROGS += test_generic_08.sh
1919
TEST_PROGS += test_generic_09.sh
2020
TEST_PROGS += test_generic_10.sh
21+
TEST_PROGS += test_generic_11.sh
2122

2223
TEST_PROGS += test_null_01.sh
2324
TEST_PROGS += test_null_02.sh

tools/testing/selftests/ublk/kublk.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ static int ublk_ctrl_update_size(struct ublk_dev *dev,
228228
return __ublk_ctrl_cmd(dev, &data);
229229
}
230230

231+
static int ublk_ctrl_quiesce_dev(struct ublk_dev *dev,
232+
unsigned int timeout_ms)
233+
{
234+
struct ublk_ctrl_cmd_data data = {
235+
.cmd_op = UBLK_U_CMD_QUIESCE_DEV,
236+
.flags = CTRL_CMD_HAS_DATA,
237+
};
238+
239+
data.data[0] = timeout_ms;
240+
return __ublk_ctrl_cmd(dev, &data);
241+
}
242+
231243
static const char *ublk_dev_state_desc(struct ublk_dev *dev)
232244
{
233245
switch (dev->dev_info.state) {
@@ -1053,6 +1065,9 @@ static int __cmd_dev_add(const struct dev_ctx *ctx)
10531065
info->nr_hw_queues = nr_queues;
10541066
info->queue_depth = depth;
10551067
info->flags = ctx->flags;
1068+
if ((features & UBLK_F_QUIESCE) &&
1069+
(info->flags & UBLK_F_USER_RECOVERY))
1070+
info->flags |= UBLK_F_QUIESCE;
10561071
dev->tgt.ops = ops;
10571072
dev->tgt.sq_depth = depth;
10581073
dev->tgt.cq_depth = depth;
@@ -1250,6 +1265,7 @@ static int cmd_dev_get_features(void)
12501265
[const_ilog2(UBLK_F_USER_RECOVERY_FAIL_IO)] = "RECOVERY_FAIL_IO",
12511266
[const_ilog2(UBLK_F_UPDATE_SIZE)] = "UPDATE_SIZE",
12521267
[const_ilog2(UBLK_F_AUTO_BUF_REG)] = "AUTO_BUF_REG",
1268+
[const_ilog2(UBLK_F_QUIESCE)] = "QUIESCE",
12531269
};
12541270
struct ublk_dev *dev;
12551271
__u64 features = 0;
@@ -1316,6 +1332,26 @@ static int cmd_dev_update_size(struct dev_ctx *ctx)
13161332
return ret;
13171333
}
13181334

1335+
static int cmd_dev_quiesce(struct dev_ctx *ctx)
1336+
{
1337+
struct ublk_dev *dev = ublk_ctrl_init();
1338+
int ret = -EINVAL;
1339+
1340+
if (!dev)
1341+
return -ENODEV;
1342+
1343+
if (ctx->dev_id < 0) {
1344+
fprintf(stderr, "device id isn't provided for quiesce\n");
1345+
goto out;
1346+
}
1347+
dev->dev_info.dev_id = ctx->dev_id;
1348+
ret = ublk_ctrl_quiesce_dev(dev, 10000);
1349+
1350+
out:
1351+
ublk_ctrl_deinit(dev);
1352+
return ret;
1353+
}
1354+
13191355
static void __cmd_create_help(char *exe, bool recovery)
13201356
{
13211357
int i;
@@ -1359,6 +1395,7 @@ static int cmd_dev_help(char *exe)
13591395
printf("\t -a list all devices, -n list specified device, default -a \n\n");
13601396
printf("%s features\n", exe);
13611397
printf("%s update_size -n dev_id -s|--size size_in_bytes \n", exe);
1398+
printf("%s quiesce -n dev_id\n", exe);
13621399
return 0;
13631400
}
13641401

@@ -1523,6 +1560,8 @@ int main(int argc, char *argv[])
15231560
ret = cmd_dev_get_features();
15241561
else if (!strcmp(cmd, "update_size"))
15251562
ret = cmd_dev_update_size(&ctx);
1563+
else if (!strcmp(cmd, "quiesce"))
1564+
ret = cmd_dev_quiesce(&ctx);
15261565
else
15271566
cmd_dev_help(argv[0]);
15281567

tools/testing/selftests/ublk/test_common.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,26 @@ _recover_ublk_dev() {
220220
echo "$state"
221221
}
222222

223+
# quiesce device and return ublk device state
224+
__ublk_quiesce_dev()
225+
{
226+
local dev_id=$1
227+
local exp_state=$2
228+
local state
229+
230+
if ! ${UBLK_PROG} quiesce -n "${dev_id}"; then
231+
state=$(_get_ublk_dev_state "${dev_id}")
232+
return "$state"
233+
fi
234+
235+
for ((j=0;j<50;j++)); do
236+
state=$(_get_ublk_dev_state "${dev_id}")
237+
[ "$state" == "$exp_state" ] && break
238+
sleep 1
239+
done
240+
echo "$state"
241+
}
242+
223243
# kill the ublk daemon and return ublk device state
224244
__ublk_kill_daemon()
225245
{
@@ -308,20 +328,26 @@ run_io_and_kill_daemon()
308328

309329
run_io_and_recover()
310330
{
331+
local action=$1
311332
local state
312333
local dev_id
313334

335+
shift 1
314336
dev_id=$(_add_ublk_dev "$@")
315337
_check_add_dev "$TID" $?
316338

317339
fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \
318-
--rw=readwrite --iodepth=256 --size="${size}" --numjobs=4 \
340+
--rw=randread --iodepth=256 --size="${size}" --numjobs=4 \
319341
--runtime=20 --time_based > /dev/null 2>&1 &
320342
sleep 4
321343

322-
state=$(__ublk_kill_daemon "${dev_id}" "QUIESCED")
344+
if [ "$action" == "kill_daemon" ]; then
345+
state=$(__ublk_kill_daemon "${dev_id}" "QUIESCED")
346+
elif [ "$action" == "quiesce_dev" ]; then
347+
state=$(__ublk_quiesce_dev "${dev_id}" "QUIESCED")
348+
fi
323349
if [ "$state" != "QUIESCED" ]; then
324-
echo "device isn't quiesced($state) after killing daemon"
350+
echo "device isn't quiesced($state) after $action"
325351
return 255
326352
fi
327353

tools/testing/selftests/ublk/test_generic_04.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ERR_CODE=0
88

99
ublk_run_recover_test()
1010
{
11-
run_io_and_recover "$@"
11+
run_io_and_recover "kill_daemon" "$@"
1212
ERR_CODE=$?
1313
if [ ${ERR_CODE} -ne 0 ]; then
1414
echo "$TID failure: $*"

tools/testing/selftests/ublk/test_generic_05.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ERR_CODE=0
88

99
ublk_run_recover_test()
1010
{
11-
run_io_and_recover "$@"
11+
run_io_and_recover "kill_daemon" "$@"
1212
ERR_CODE=$?
1313
if [ ${ERR_CODE} -ne 0 ]; then
1414
echo "$TID failure: $*"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5+
6+
TID="generic_11"
7+
ERR_CODE=0
8+
9+
ublk_run_quiesce_recover()
10+
{
11+
run_io_and_recover "quiesce_dev" "$@"
12+
ERR_CODE=$?
13+
if [ ${ERR_CODE} -ne 0 ]; then
14+
echo "$TID failure: $*"
15+
_show_result $TID $ERR_CODE
16+
fi
17+
}
18+
19+
if ! _have_feature "QUIESCE"; then
20+
exit "$UBLK_SKIP_CODE"
21+
fi
22+
23+
if ! _have_program fio; then
24+
exit "$UBLK_SKIP_CODE"
25+
fi
26+
27+
_prep_test "quiesce" "basic quiesce & recover function verification"
28+
29+
_create_backfile 0 256M
30+
_create_backfile 1 128M
31+
_create_backfile 2 128M
32+
33+
ublk_run_quiesce_recover -t null -q 2 -r 1 &
34+
ublk_run_quiesce_recover -t loop -q 2 -r 1 "${UBLK_BACKFILES[0]}" &
35+
ublk_run_quiesce_recover -t stripe -q 2 -r 1 "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
36+
wait
37+
38+
ublk_run_quiesce_recover -t null -q 2 -r 1 -i 1 &
39+
ublk_run_quiesce_recover -t loop -q 2 -r 1 -i 1 "${UBLK_BACKFILES[0]}" &
40+
ublk_run_quiesce_recover -t stripe -q 2 -r 1 -i 1 "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
41+
wait
42+
43+
_cleanup_test "quiesce"
44+
_show_result $TID $ERR_CODE

0 commit comments

Comments
 (0)