btrfs-progs/kernel-shared
Qu Wenruo bc0995297f btrfs-progs: convert: fix inline extent size for symlink
[BUG]
Sometimes test case btrfs/012 fails randomly, with the failure to read a
symlink:

     QA output created by 012
     Checking converted btrfs against the original one:
    -OK
    +readlink: Structure needs cleaning
     Checking saved ext2 image against the original one:
     OK

Furthermore, this will trigger a kernel error message:

 BTRFS critical (device dm-2): regular/prealloc extent found for non-regular inode 133081

[CAUSE]
For that specific inode 133081, the tree dump looks like this:

        item 127 key (133081 INODE_ITEM 0) itemoff 40984 itemsize 160
                generation 1 transid 1 size 4095 nbytes 4096
                block group 0 mode 120777 links 1 uid 0 gid 0 rdev 0
                sequence 0 flags 0x0(none)
        item 128 key (133081 INODE_REF 133080) itemoff 40972 itemsize 12
                index 2 namelen 2 name: l3
        item 129 key (133081 EXTENT_DATA 0) itemoff 40919 itemsize 53
                generation 4 type 1 (regular)
                extent data disk byte 2147483648 nr 38080512
                extent data offset 37974016 nr 4096 ram 38080512
                extent compression 0 (none)

Note that, the symlink inode size is 4095 at the max size (PATH_MAX,
removing the terminating NUL).
But the nbytes is 4096, exactly matching the sector size of the btrfs.

Thus it results the creation of a regular extent, but for btrfs we do
not accept a symlink with a regular/preallocated extent, thus kernel
rejects such read and failed the readlink call.

The root cause is in the convert code, where for symlinks we always
create a data extent with its size + 1, causing the above problem.

I guess the original code is to handle the terminating NUL, but in btrfs
we never need to store the terminating NUL for inline extents nor
file names.

Thus this pitfall in btrfs-convert leads to the above invalid data
extent and fail the test case.

[FIX]
- Fix the ext2 and reiserfs symbolic link creation code
  To remove the terminating NUL.

- Add extra checks for the size of a symbolic link
  Btrfs has extra limits on the size of a symbolic link, as btrfs must
  store symbolic link targets as inlined extents.

  This means for 4K node sized btrfs, the size limit is smaller than the
  usual PATH_MAX - 1 (only around 4000 bytes instead of 4095).

  So for certain nodesize, some filesystems can not be converted to
  btrfs.
  (this should be rare, because the default nodesize is 16K already)

- Split the symbolic link and inline data extent size checks
  For symbolic links the real limit is PATH_MAX - 1 (removing the
  terminating NUL), but for inline data extents the limit is
  sectorsize - 1, which can be different from 4096 - 1 (e.g. 64K sector
  size).

Pull-request: #884
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-09-17 14:33:22 +02:00
..
uapi btrfs-progs: remove raid stripe encoding 2024-06-24 19:40:18 +02:00
README.md btrfs-progs: move uuid-tree definitions to kernel-shared/uuid-tree.h 2024-07-30 20:01:59 +02:00
accessors.c btrfs-progs: kernel-shared: update const of parameters accessors.h 2024-08-14 23:59:36 +02:00
accessors.h btrfs-progs: kernel-shared: update const of parameters accessors.h 2024-08-14 23:59:36 +02:00
async-thread.c btrfs-progs: pull in the full max/min/clamp implementation from kernel 2023-10-10 19:16:29 +02:00
async-thread.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
backref.c btrfs-progs: error out immediately if an unknown backref type is found 2024-06-05 19:48:04 +02:00
backref.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
compression.h btrfs-progs: minor source sync with kernel 6.8 2024-03-12 21:22:56 +01:00
ctree.c btrfs-progs: kernel-shared: update const of parameters accessors.h 2024-08-14 23:59:36 +02:00
ctree.h btrfs-progs: constify the name parameter of btrfs_add_link() 2024-08-14 23:58:24 +02:00
delayed-ref.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
delayed-ref.h btrfs-progs: minor source sync with kernel 6.8 2024-03-12 21:22:56 +01:00
dir-item.c btrfs-progs: set transid in btrfs_insert_dir_item 2024-07-30 20:01:38 +02:00
disk-io.c btrfs-progs: remove fs_info parameter from btrfs_create_tree() 2024-07-30 19:54:00 +02:00
disk-io.h btrfs-progs: remove fs_info parameter from btrfs_create_tree() 2024-07-30 19:54:00 +02:00
extent-io-tree.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
extent-io-tree.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
extent-tree.c btrfs-progs: reorder key initializations 2024-04-30 21:49:15 +02:00
extent_io.c btrfs-progs: kernel-shared: update const of parameters accessors.h 2024-08-14 23:59:36 +02:00
extent_io.h btrfs-progs: kernel-shared: update const of parameters accessors.h 2024-08-14 23:59:36 +02:00
file-item.c btrfs-progs: convert: fix inline extent size for symlink 2024-09-17 14:33:22 +02:00
file-item.h btrfs-progs: convert: fix inline extent size for symlink 2024-09-17 14:33:22 +02:00
file.c btrfs-progs: reorder key initializations 2024-04-30 21:49:15 +02:00
free-space-cache.c btrfs-progs: reorder key initializations 2024-04-30 21:49:15 +02:00
free-space-cache.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
free-space-tree.c btrfs-progs: remove fs_info parameter from btrfs_create_tree() 2024-07-30 19:54:00 +02:00
free-space-tree.h btrfs-progs: minor source sync with kernel 6.8 2024-03-12 21:22:56 +01:00
inode-item.c btrfs-progs: reorder key initializations 2024-04-30 21:49:15 +02:00
inode.c btrfs-progs: constify the name parameter of btrfs_add_link() 2024-08-14 23:58:24 +02:00
locking.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
locking.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
messages.c btrfs-progs: minor source sync with kernel 6.8 2024-03-12 21:22:56 +01:00
messages.h btrfs-progs: minor source sync with kernel 6.8-rc3 2024-02-08 09:30:16 +01:00
misc.h btrfs-progs: minor source sync with kernel 6.8-rc3 2024-02-08 09:30:16 +01:00
print-tree.c btrfs-progs: dump-tree: escape special characters in paths or xattrs 2024-07-30 19:53:33 +02:00
print-tree.h btrfs-progs: use unsigned types for bit shifts 2024-03-12 22:05:09 +01:00
root-tree.c btrfs-progs: minor source sync with kernel 6.8 2024-03-12 21:22:56 +01:00
send.h btrfs-progs: enable send v3 correctly (use EXPERIMENTAL instead of CONFIG_BTRFS_DEBUG) 2024-03-18 23:19:52 +01:00
transaction.c btrfs-progs: kernel-shared: use kmalloc and kfree 2023-11-03 18:04:37 +01:00
transaction.h btrfs-progs: minor source sync with kernel 6.8-rc3 2024-02-08 09:30:16 +01:00
tree-checker.c btrfs-progs: remove raid stripe encoding 2024-06-24 19:40:18 +02:00
tree-checker.h btrfs-progs: minor source sync with kernel 6.8-rc3 2024-02-08 09:30:16 +01:00
tree-mod-log.h btrfs-progs: sync and stub-out tree-mod-log.h 2023-05-26 18:02:29 +02:00
ulist.c btrfs-progs: minor source sync with kernel 6.8-rc3 2024-02-08 09:30:16 +01:00
ulist.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
uuid-tree.c btrfs-progs: cross-port btrfs_uuid_tree_add() from kernel 2024-07-30 20:02:42 +02:00
uuid-tree.h btrfs-progs: cross-port btrfs_uuid_tree_add() from kernel 2024-07-30 20:02:42 +02:00
volumes.c btrfs-progs: reorder key initializations 2024-04-30 21:49:15 +02:00
volumes.h btrfs-progs: run codespell throughout fixing typos automagically 2024-07-30 19:56:08 +02:00
zoned.c btrfs-progs: support byte length for zone resetting 2024-06-03 21:26:39 +02:00
zoned.h btrfs-progs: support byte length for zone resetting 2024-06-03 21:26:39 +02:00

README.md

Shared sources with kernel

Status and progress of kernel/userspace synchronization.

  • accessors.c - done, local changes
  • accessors.h - done, local changes
  • async-thread.c - done
  • async-thread.h - done
  • backref.c - todo
  • backref.h - todo
  • compression.h - done
  • ctree.c - partial
  • ctree.h - partial
  • delayed-ref.c - partial
  • delayed-ref.h - partial
  • dir-item.c - partial
  • disk-io.c - todo
  • disk-io.h - todo
  • extent_io.c
  • extent_io.h
  • extent-io-tree.c - done, local changes
  • extent-io-tree.h - done, local changes
  • extent-tree.c - todo
  • file.c - todo
  • file-item.c - todo
  • file-item.h - partial
  • free-space-cache.c - not needed
  • free-space-cache.h - not needed
  • free-space-tree.c - partial
  • free-space-tree.h - partial
  • inode.c - todo
  • inode-item.c - partial
  • locking.c - done, local changes
  • locking.h - done, local changes
  • messages.c - done, local changes
  • messages.h - done, local changes
  • misc.h - done
  • print-tree.c - partial, sync to kernel
  • print-tree.h - partial
  • root-tree.c - partial
  • root-tree.h - done
  • send.h - done
  • transaction.c - todo
  • transaction.h - partial, local changes
  • tree-checker.c - partial, local changes
  • tree-checker.h - partial, local changes
  • tree-mod-log.h - done, local changes
  • ulist.c - done
  • ulist.h - done
  • uuid-tree.c - partial
  • uuid-tree.h - partial, local changes
  • volumes.c - todo, local changes
  • volumes.h - todo, local changes
  • zoned.c - todo
  • zoned.h - todo