btrfs-progs/kernel-shared
Qu Wenruo af6f301834 btrfs-progs: fix accessors for big endian systems
[BUG]
There is a bug report that on s390x big endian systems, mkfs.btrfs just
fails:

  $ mkfs.btrfs  -f ~/test.img
  btrfs-progs v6.3.1
  Invalid mapping for 1081344-1097728, got 17592186044416-17592190238720
  Couldn't map the block 1081344
  ERROR: cannot read chunk root
  ERROR: open ctree failed

[CAUSE]
The error is caused by wrong endian conversion. The s390x is a big
endian architecture:

  $ lscpu
  Byte Order:            Big Endian

While checking the offending @disk_key and @key inside
btrfs_read_sys_array(), we got:

  2301		while (cur_offset < array_size) {
  (gdb)
  2304			if (cur_offset + len > array_size)
  (gdb)
  2307			btrfs_disk_key_to_cpu(&key, disk_key);
  (gdb)
  2310			sb_array_offset += len;
  (gdb) print *disk_key
  $2 = {objectid = 281474976710656, type = 228 '\344', offset = 17592186044416}
  (gdb) print key
  $3 = {objectid = 281474976710656, type = 228 '\344', offset = 17592186044416}
  (gdb)

Now we can see, @disk_key is indeed in the little endian, but @key is
not converted to the CPU native endian.

Furthermore, if we step into the help btrfs_disk_key_to_cpu(), it shows
we're using little endian version:

  (gdb) step
  btrfs_disk_key_to_cpu (disk_key=0x109fcdb, cpu_key=0x3ffffff847f)
      at ./kernel-shared/accessors.h:592
  592		memcpy(cpu_key, disk_key, sizeof(struct btrfs_key));

[FIX]
The kernel accessors.h checks if __LITTLE_ENDIAN is defined or not, but
that only works inside kernel.

In user space, __LITTLE_ENDIAN and __BIG_ENDIAN are both provided by
kerncompat.h that should have been included already.

Instead we should check __BYTE_ORDER against __LITTLE_ENDIAN to
determine our endianness.

With this change, s390x build works as expected now.

Issue: #639
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-06-15 12:24:09 +02:00
..
uapi btrfs-progs: tune: rework the main idea of csum change 2023-05-26 18:02:32 +02:00
README.md btrfs-progs: add README to kernel-shared tracking the progress 2023-05-26 18:02:32 +02:00
accessors.c btrfs-progs: sync accessors.[ch] from the kernel 2023-05-26 18:02:28 +02:00
accessors.h btrfs-progs: fix accessors for big endian systems 2023-06-15 12:24:09 +02:00
async-thread.c btrfs-progs: sync async-thread.[ch] from the kernel 2023-05-26 18:02:29 +02:00
async-thread.h btrfs-progs: sync async-thread.[ch] from the kernel 2023-05-26 18:02:29 +02:00
backref.c btrfs-progs: update read_tree_block to match the kernel definition 2023-05-26 18:02:30 +02:00
backref.h btrfs-progs: move extent_io.c to kernel-shared/ 2020-08-31 17:01:04 +02:00
compression.h btrfs-progs: sync compression.h from kernel 2023-05-26 18:02:31 +02:00
ctree.c btrfs-progs: tune: rework the main idea of csum change 2023-05-26 18:02:32 +02:00
ctree.h btrfs-progs: tune: rework the main idea of csum change 2023-05-26 18:02:32 +02:00
delayed-ref.c btrfs-progs: sync messages.[ch] from the kernel 2023-05-26 18:02:28 +02:00
delayed-ref.h btrfs-progs: unify GPL header comments 2021-09-07 13:58:44 +02:00
dir-item.c btrfs-progs: sync accessors.[ch] from the kernel 2023-05-26 18:02:28 +02:00
disk-io.c btrfs-progs: tune: rework the main idea of csum change 2023-05-26 18:02:32 +02:00
disk-io.h btrfs-progs: replace write_and_map_eb() by write_data_to_disk() 2023-05-26 18:02:31 +02:00
extent-io-tree.c btrfs-progs: sync extent-io-tree.[ch] from kernel 2023-05-26 18:02:31 +02:00
extent-io-tree.h btrfs-progs: sync extent-io-tree.[ch] from kernel 2023-05-26 18:02:31 +02:00
extent-tree.c btrfs-progs: add an atomic parameter to btrfs_buffer_uptodate 2023-05-26 18:02:30 +02:00
extent_io.c btrfs-progs: constify the buffer pointer for write functions 2023-05-26 18:02:31 +02:00
extent_io.h btrfs-progs: constify the buffer pointer for write functions 2023-05-26 18:02:31 +02:00
file-item.c btrfs-progs: tune: add the ability to generate new data checksums 2023-05-26 18:02:32 +02:00
file-item.h btrfs-progs: tune: add the ability to generate new data checksums 2023-05-26 18:02:32 +02:00
file.c btrfs-progs: sync file-item.h into progs 2023-05-26 18:02:29 +02:00
free-space-cache.c btrfs-progs: remove root argument from free_extent and inc_extent_ref 2023-05-26 18:02:30 +02:00
free-space-cache.h btrfs-progs: check: batch v1 space cache inodes when clearing 2021-07-22 16:26:05 +02:00
free-space-tree.c btrfs-progs: sync messages.[ch] from the kernel 2023-05-26 18:02:28 +02:00
free-space-tree.h btrfs-progs: properly initialize block group thresholds 2022-05-20 15:54:20 +02:00
inode-item.c btrfs-progs: remove the _nr from the item helpers 2022-03-09 15:13:13 +01:00
inode.c btrfs-progs: sync accessors.[ch] from the kernel 2023-05-26 18:02:28 +02:00
locking.c btrfs-progs: sync locking.h and stub out all the helpers 2023-05-26 18:02:29 +02:00
locking.h btrfs-progs: sync locking.h and stub out all the helpers 2023-05-26 18:02:29 +02:00
messages.c btrfs-progs: add musl compatibility for printf format %pV 2023-05-26 18:02:28 +02:00
messages.h btrfs-progs: sync messages.[ch] from the kernel 2023-05-26 18:02:28 +02:00
misc.h btrfs-progs: sync extent-io-tree.[ch] and misc.h from the kernel 2023-05-26 18:02:29 +02:00
print-tree.c btrfs-progs: add CHANGING_FSID_V2 to print-tree 2023-06-01 01:42:00 +02:00
print-tree.h btrfs-progs: dump-tree: add options to dump checksums 2021-06-19 22:07:49 +02:00
root-tree.c btrfs-progs: remove the _nr from the item helpers 2022-03-09 15:13:13 +01:00
send.h btrfs-progs: sync send.h from kernel 2023-05-26 18:02:32 +02:00
transaction.c btrfs-progs: partial sync of transaction.h from kernel 2023-05-26 18:02:32 +02:00
transaction.h btrfs-progs: partial sync of transaction.h from kernel 2023-05-26 18:02:32 +02:00
tree-checker.c btrfs-progs: tune: add the ability to generate new data checksums 2023-05-26 18:02:32 +02:00
tree-checker.h btrfs-progs: sync tree-checker.[ch] from kernel 2023-05-26 18:02:30 +02: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: sync ulist.[ch] from kernel 2023-05-26 18:02:32 +02:00
ulist.h btrfs-progs: sync ulist.[ch] from kernel 2023-05-26 18:02:32 +02:00
uuid-tree.c btrfs-progs: remove the _nr from the item helpers 2022-03-09 15:13:13 +01:00
volumes.c btrfs-progs: sync tree-checker.[ch] from kernel 2023-05-26 18:02:30 +02:00
volumes.h btrfs-progs: sync tree-checker.[ch] from kernel 2023-05-26 18:02:30 +02:00
zoned.c btrfs-progs: fix -Wmissing-prototypes warnings 2023-05-26 18:02:31 +02:00
zoned.h btrfs-progs: sync messages.[ch] from the kernel 2023-05-26 18:02:28 +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
  • volumes.c - todo, local changes
  • volumes.h - todo, local changes
  • zoned.c - todo
  • zoned.h - todo