summaryrefslogtreecommitdiff
path: root/tests/btrfs/303
blob: b9d6c61d17cc03ca56457a5f53784392b702bae0 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test 303
#
# A regression test to make sure snapshot creation won't cause transaction
# abort if there is already an existing qgroup.
#
. ./common/preamble
_begin_fstest auto quick snapshot subvol qgroup

. ./common/filter

_supported_fs btrfs
_require_scratch

_fixed_by_kernel_commit xxxxxxxxxxxx \
	"btrfs: do not abort transaction if there is already an existing qgroup"

_scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
_scratch_mount

# Create the first subvolume and get its id.
# This subvolume id should not change no matter if there is an existing
# qgroup for it.
$BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" >> $seqres.full
$BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/subvol" \
	"$SCRATCH_MNT/snapshot">> $seqres.full

init_subvolid=$(_btrfs_get_subvolid "$SCRATCH_MNT" "snapshot")

if [ -z "$init_subvolid" ]; then
	_fail "Unable to get the subvolid of the first snapshot"
fi

echo "Subvolumeid: ${init_subvolid}" >> $seqres.full

_scratch_unmount

# Re-create the fs, as btrfs won't reuse the subvolume id.
_scratch_mkfs >> $seqres.full 2>&1 || _fail "2nd mkfs failed"
_scratch_mount

$BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" >> $seqres.full
$BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" >> $seqres.full

# Create a qgroup for the first subvolume, this would make the later
# subvolume creation to find an existing qgroup, and abort transaction.
$BTRFS_UTIL_PROG qgroup create 0/"$init_subvolid" "$SCRATCH_MNT" >> $seqres.full

# Now create the first snapshot, which should have the same subvolid no matter
# if the quota is enabled.
$BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" >> $seqres.full
$BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/subvol" \
	"$SCRATCH_MNT/snapshot" >> $seqres.full

# Either the snapshot create failed and transaction is aborted thus no
# snapshot here, or we should be able to create the snapshot.
new_subvolid=$(_btrfs_get_subvolid "$SCRATCH_MNT" "snapshot")

echo "Subvolumeid: ${new_subvolid}" >> $seqres.full

if [ -z "$new_subvolid" ]; then
	_fail "Unable to get the subvolid of the first snapshot"
fi

# Make sure the subvolumeid for the first snapshot didn't change.
if [ "$new_subvolid" -ne "$init_subvolid" ]; then
	_fail "Subvolumeid for the first snapshot changed, has ${new_subvolid} expect ${init_subvolid}"
fi

echo "Silence is golden"

# success, all done
status=0
exit