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
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2018 Red Hat Inc. All Rights Reserved.
#
# FS QA Test No. 490
#
# Test a corruption when the directory structure and the inobt thinks the inode
# is free, but the inode on disk thinks it is still in use.
#
# This case test same bug (upstream linux commit ee457001ed6c) as xfs/132, but
# through different code path.
#
. ./common/preamble
_begin_fstest auto quick
# Import common functions.
. ./common/filter
# real QA test starts here
# Modify as appropriate.
_supported_fs xfs
_require_scratch_nocheck
_require_xfs_mkfs_finobt
# Skip the verifier "xfs_check_agi_freecount()" which verify the number of free
# inodes in the AGI is correct, when XFS_DEBUG is enabled
_require_no_xfs_debug
filter_dmesg()
{
local warn1="Internal error xfs_trans_cancel.*fs/xfs/xfs_trans\.c.*"
sed -e "s#$warn1#Intentional error in xfs_trans_cancel#"
}
# If enable free inode B+tree, this case will fail on xfs_dialloc_ag_update_inobt,
# that's not what we want to test. Due to finobt feature is not necessary for this
# test, so disable it directly.
_scratch_mkfs_xfs -m finobt=0 | _filter_mkfs 2>$tmp.mkfs >> $seqres.full
# On V5 filesystem, this case can't trigger bug because it doesn't read inodes
# we are allocating from disk - it simply overwrites them with new inode
# information. So use ikeep mount option to stop that.
source $tmp.mkfs
mount_opt=""
if [ $_fs_has_crcs -eq 1 ]; then
mount_opt="-o ikeep"
fi
blksz=$(_scratch_xfs_get_sb_field blocksize)
agcount=$(_scratch_xfs_get_sb_field agcount)
_scratch_mount $mount_opt
# Create a directory for later allocation in same AG (AG 0, due to this's an
# empty XFS for now)
mkdir $SCRATCH_MNT/dir
# Allocate 1 block for testfile
$XFS_IO_PROG -fc "pwrite 0 $blksz" -c fsync $SCRATCH_MNT/dir/testfile >> $seqres.full
inum=`stat -c %i $SCRATCH_MNT/dir/testfile`
_scratch_unmount
# Find the AG which contains testfile
agi=`_scratch_xfs_db -c "convert inode $inum agno" | sed -e 's/^.*(\([0-9]*\).*$/\1/g'`
# Due to we only allocate 1 block for testfile, and this's the only one data
# block we use. So we use single level inobt, So the ${agi}->root->recs[1]
# should be the only one record points the chunk which contains testfile's
# inode.
# An exmaple of inode record is as below:
# recs[1] = [startino,freecount,free] 1:[1024,59,0xffffffffffffffe0]
freecount=$(_scratch_xfs_get_metadata_field "recs[1].freecount" \
"agi $agi" "addr root")
fmask=$(_scratch_xfs_get_metadata_field "recs[1].free" "agi $agi" "addr root")
# fmask shift right 1 bit, and freecount++, to mark testfile inode as free in
# inobt. (But the inode itself isn't freed, it still has allocated block)
freecount="$((freecount + 1))"
fmask="$((fmask / 2))"
_scratch_xfs_set_metadata_field "recs[1].freecount" "$freecount" \
"agi $agi" "addr root" >/dev/null
_scratch_xfs_set_metadata_field "recs[1].free" "$fmask" \
"agi $agi" "addr root" >/dev/null
# Mount again and create a new inode cover that inode we just 'freed' from inobt
_scratch_mount $mount_opt
$XFS_IO_PROG -fc "pwrite 0 $blksz" -c fsync $SCRATCH_MNT/dir/newfile 2>&1 | \
grep -i "Structure needs cleaning" | _filter_scratch
# filter a intentional internal errors
_check_dmesg filter_dmesg
# success, all done
status=0
exit
|