mbox series

[v2,0/7] btrfs: check: Check and repair invalid free space cahce inode mode

Message ID 20190401055551.6837-1-wqu@suse.com (mailing list archive)
Headers show
Series btrfs: check: Check and repair invalid free space cahce inode mode | expand

Message

Qu Wenruo April 1, 2019, 5:55 a.m. UTC
This patchset can be fetched from github:
https://github.com/adam900710/btrfs-progs/tree/free_space_cache_imode_fix
Which is based on v4.20.2 tag.

There is a minor problem reported in mail list where invalid inode mode
(0) can sneak into free space cache inodes:
        item 9 key (256 INODE_ITEM 0) itemoff 13702 itemsize 160
                generation 30 transid 30 size 65536 nbytes 1507328
                block group 0 mode 0 links 1 uid 0 gid 0 rdev 0
                sequence 23 flags 0x1b(NODATASUM|NODATACOW|NOCOMPRESS|PREALLOC)
                atime 0.0 (1970-01-01 08:00:00)
                ctime 1553491158.189771625 (2019-03-25 13:19:18)
                mtime 0.0 (1970-01-01 08:00:00)
                otime 0.0 (1970-01-01 08:00:00)

Kernel free space cache code doesn't realy care about the inode mode,
but tree-checker inode item checker cares and will report this as big
problem, rejecting the image.

I didn't see any reason to make inode item checker any less strict, as
there is already fuzzed image can break kernel using invalid inode mode.

So here I just enhance btrfs-progs before strict inode item checker
lands.

Next time when users report kernel rejecting previously valid fs, they
should have a way to fix it in btrfs-progs.

Changelog:
v2:
- Minor refactor to make common code more common.

Qu Wenruo (7):
  btrfs-progs: check/lowmem: Add inode mode check
  btrfs-progs: check/original: Add inode mode check
  btrfs-progs: check/lowmem: Repair invalid inode mode in root tree
  btrfs-progs: check/original: Repair invalid inode mode in root tree
  btrfs: check/lowmem: Check and repair free space cache inode mode
  btrfs: check/original: Check and repair free space cache inode item
  btrfs: tests/fsck: Add test image for free space cache mode repair

 check/main.c                                  |  42 ++++++
 check/mode-common.c                           | 129 ++++++++++++++++++
 check/mode-common.h                           |  29 ++++
 check/mode-lowmem.c                           |  22 +++
 check/mode-lowmem.h                           |   3 +
 check/mode-original.h                         |   1 +
 .../test.raw.xz                               | Bin 0 -> 159128 bytes
 7 files changed, 226 insertions(+)
 create mode 100644 tests/fsck-tests/038-bad-free-space-cache-inode-mode/test.raw.xz

Comments

Qu Wenruo April 1, 2019, 5:55 a.m. UTC | #1
The image has one free space cache inode with invalid mode (0).
        item 9 key (256 INODE_ITEM 0) itemoff 13702 itemsize 160
                generation 30 transid 30 size 65536 nbytes 1507328
                block group 0 mode 0 links 1 uid 0 gid 0 rdev 0
                sequence 23 flags 0x1b(NODATASUM|NODATACOW|NOCOMPRESS|PREALLOC)
                atime 0.0 (1970-01-01 08:00:00)
                ctime 1553491158.189771625 (2019-03-25 13:19:18)
                mtime 0.0 (1970-01-01 08:00:00)
                otime 0.0 (1970-01-01 08:00:00)

Both lowmem and original mode should be able to detect and fix it.

The extracted test image is pretty big (1G extracted), as kernel won't
cache small chunks.
Even with SSD, such test may still take some seconds just extracting the
image.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 .../test.raw.xz                                | Bin 0 -> 159128 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/fsck-tests/038-bad-free-space-cache-inode-mode/test.raw.xz

diff --git a/tests/fsck-tests/038-bad-free-space-cache-inode-mode/test.raw.xz b/tests/fsck-tests/038-bad-free-space-cache-inode-mode/test.raw.xz
new file mode 100644
index 0000000000000000000000000000000000000000..c2603c024098992bece235d27187eefa696b3fe0
GIT binary patch
literal 159128
zcmeI5c{JB+*T%_|kTGN`Ny-=vGN%zgWGHizsHl+npiGgu5Q$8cF+#=^DI`;7GNzO$
zgow_MywCHlXRYU5?{m(2b55%FoXg*>)mr<vzx%#E*WUNO=OtbA3`j`G2ix=ZEhFJ2
z<su;=VQA2+TUel9W^tH=#Cm>V;b!5&etD%;wo*qmi^4Vz-t?vVJocK$t3|9*T9%ZM
zbG|wtKuzo>U8j5UKoB3JcE3J*r9;3gr`dul?zEO=efG*`M)73ifu^El?BhqbrsO8(
z72Ab4UpKX6a$Q+}+d+M~;$hPu?LA4Ug(siCc^SH=?FnbgdhTS0{-MTAJBC*rRu3<x
z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