Commit graph

8 commits

Author SHA1 Message Date
David Sterba 7f396f5ced btrfs-progs: reorder key initializations
Use the objectid, type, offset natural order as it's more readable and
we're used to read keys like that.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-30 21:49:15 +02:00
David Sterba bec6bc8eee btrfs-progs: minor source sync with kernel 6.8-rc3
Sync a few more file on the source level with kernel 6.8-rc3, no
functional changes.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-02-08 09:30:16 +01:00
Johannes Thumshirn dfc866bfef btrfs-progs: remove stride length from on-disk format
The stride length has been removed from kernel code, remove it here as
well.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-06 17:26:56 +02:00
David Sterba 21aa6777b2 btrfs-progs: clean up includes, using include-what-you-use
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:57 +02:00
Boris Burkov 2c729bbe91 btrfs-progs: add squota kernel definitions
Copy over structs, accessors, and constants for simple quotas

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:54 +02:00
Johannes Thumshirn 2eb351210f btrfs-progs: add raid stripe tree definitions
Add the definitions for the on-disk format of the raid stripe tree.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-02 18:41:08 +02:00
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
Josef Bacik c979ffd787 btrfs-progs: sync accessors.[ch] from the kernel
This syncs accessors.[ch] from the kernel.  For the most part
accessors.h will remain the same, there's just some helpers that need to
be adjusted for eb->data instead of eb->pages.  Additionally accessors.c
needed to be completely updated to deal with this as well.

This is a set of files where we will likely only sync the header going
forward, and leave the C file in place as it needs to be specific to
btrfs-progs.

This forced a few "unrelated" changes

- Using btrfs_dir_item_ftype() instead of btrfs_dir_item_type().  This
  is due to the encryption changes, and was simpler to just do in this
  patch.
- Adjusting some of the print tree code to use the actual helpers and
  not the btrfs-progs ones.

A local definition of static_assert is used to avoid compilation
failures on older gcc (< 9) where the 2nd parameter is mandatory.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00