summaryrefslogtreecommitdiff
path: root/tests/btrfs/049
blob: dd07c94a14a746521b4a66565b8f70e20ea2519d (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2021 SUSE Linux Products GmbH.  All Rights Reserved.
#
# FS QA Test 049
#
# Ensure that it's possible to add a device when we have a paused balance
# and the filesystem is mounted with skip_balance. The issue is fixed by a patch
# titled "btrfs: allow device add if balance is paused"
#
. ./common/preamble
_begin_fstest quick balance auto

_supported_fs btrfs
_require_scratch_swapfile
_require_scratch_dev_pool 3

_scratch_dev_pool_get 2
_spare_dev_get

swapfile="$SCRATCH_MNT/swap"
_scratch_pool_mkfs >/dev/null
_scratch_mount
_format_swapfile "$swapfile" $(($(_get_page_size) * 10)) >/dev/null

check_exclusive_ops()
{
	$BTRFS_UTIL_PROG device remove 2 $SCRATCH_MNT &>/dev/null
	[ $? -ne 0 ] || _fail "Successfully removed device"
	$BTRFS_UTIL_PROG filesystem resize -5m $SCRATCH_MNT &> /dev/null
	[ $? -ne 0 ] || _fail "Successfully resized filesystem"
	$BTRFS_UTIL_PROG replace start -B 2 $SPARE_DEV $SCRATCH_MNT &> /dev/null
	[ $? -ne 0 ] || _fail "Successfully replaced device"
	swapon "$swapfile" &> /dev/null
	[ $? -ne 0 ] || _fail "Successfully enabled a swap file"
}

# Create some files on the so that balance doesn't complete instantly
args=`_scale_fsstress_args -z \
	-f write=10 -f creat=10 \
	-n 1000 -p 2 -d $SCRATCH_MNT/stress_dir`
echo "Run fsstress $args" >>$seqres.full
$FSSTRESS_PROG $args >>$seqres.full

# Start and pause balance to ensure it will be restored on remount
echo "Start balance" >>$seqres.full
_run_btrfs_balance_start --bg "$SCRATCH_MNT"
$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT"
$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused
[ $? -eq 0 ] || _fail "Balance not paused"

# Exclusive ops should be blocked on manual pause of balance
check_exclusive_ops

# Balance is now placed in paused state during mount
_scratch_cycle_mount "skip_balance"

# Exclusive ops should be blocked on balance pause due to 'skip_balance'
check_exclusive_ops

# Device add is the only allowed operation
$BTRFS_UTIL_PROG device add -K -f $SPARE_DEV "$SCRATCH_MNT"

# Exclusive ops should still be blocked on account that balance is still paused
check_exclusive_ops

# Should be possible to resume balance after device add
$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null
[ $? -eq 0 ] || _fail "Couldn't resume balance after device add"

# Add more files so that new balance won't fish immediately
$FSSTRESS_PROG $args >/dev/null 2>&1

# Now pause->resume balance. This ensures balance paused is properly set in
# the kernel and won't trigger an assertion failure.
echo "Start balance" >>$seqres.full
_run_btrfs_balance_start --bg "$SCRATCH_MNT"
$BTRFS_UTIL_PROG balance pause "$SCRATCH_MNT"
$BTRFS_UTIL_PROG balance status "$SCRATCH_MNT" | grep -q paused
[ $? -eq 0 ] || _fail "Balance not paused"
$BTRFS_UTIL_PROG balance resume "$SCRATCH_MNT" &>/dev/null
[ $? -eq 0 ] || _fail "Balance can't be resumed via IOCTL"

_spare_dev_put
_scratch_dev_pool_put
echo "Silence is golden"
status=0
exit