Skip to content

Commit 7cb2a78

Browse files
Brian FosterKent Overstreet
authored andcommitted
bcachefs: use swab40 for bch_backpointer.bucket_offset bitfield
The bucket_offset field of bch_backpointer is a 40-bit bitfield, but the bch2_backpointer_swab() helper uses swab32. This leads to inconsistency when an on-disk fs is accessed from an opposite endian machine. As it turns out, we already have an internal swab40() helper that is used from the bch_alloc_v4 swab callback. Lift it into the backpointers header file and use it consistently in both places. Signed-off-by: Brian Foster <bfoster@redhat.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 0996c72 commit 7cb2a78

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

fs/bcachefs/alloc_background.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,6 @@ int bch2_alloc_v4_invalid(struct bch_fs *c, struct bkey_s_c k,
297297
return ret;
298298
}
299299

300-
static inline u64 swab40(u64 x)
301-
{
302-
return (((x & 0x00000000ffULL) << 32)|
303-
((x & 0x000000ff00ULL) << 16)|
304-
((x & 0x0000ff0000ULL) >> 0)|
305-
((x & 0x00ff000000ULL) >> 16)|
306-
((x & 0xff00000000ULL) >> 32));
307-
}
308-
309300
void bch2_alloc_v4_swab(struct bkey_s k)
310301
{
311302
struct bch_alloc_v4 *a = bkey_s_to_alloc_v4(k).v;

fs/bcachefs/backpointers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void bch2_backpointer_swab(struct bkey_s k)
7777
{
7878
struct bkey_s_backpointer bp = bkey_s_to_backpointer(k);
7979

80-
bp.v->bucket_offset = swab32(bp.v->bucket_offset);
80+
bp.v->bucket_offset = swab40(bp.v->bucket_offset);
8181
bp.v->bucket_len = swab32(bp.v->bucket_len);
8282
bch2_bpos_swab(&bp.v->pos);
8383
}

fs/bcachefs/backpointers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
#include "buckets.h"
88
#include "super.h"
99

10+
static inline u64 swab40(u64 x)
11+
{
12+
return (((x & 0x00000000ffULL) << 32)|
13+
((x & 0x000000ff00ULL) << 16)|
14+
((x & 0x0000ff0000ULL) >> 0)|
15+
((x & 0x00ff000000ULL) >> 16)|
16+
((x & 0xff00000000ULL) >> 32));
17+
}
18+
1019
int bch2_backpointer_invalid(struct bch_fs *, struct bkey_s_c k,
1120
enum bkey_invalid_flags, struct printbuf *);
1221
void bch2_backpointer_to_text(struct printbuf *, const struct bch_backpointer *);

0 commit comments

Comments
 (0)