Skip to content

Commit 7ec20af

Browse files
committed
btrfs: new define for the inline extent data start
Use a common definition for the inline data start so we don't have to open-code it and introduce bugs like "Btrfs: fix wrong max inline data size limit" fixed. Signed-off-by: David Sterba <[email protected]>
1 parent fb85fc9 commit 7ec20af

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

fs/btrfs/ctree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4625,8 +4625,7 @@ void btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path,
46254625
ptr = btrfs_item_ptr_offset(leaf, slot);
46264626
memmove_extent_buffer(leaf, ptr,
46274627
(unsigned long)fi,
4628-
offsetof(struct btrfs_file_extent_item,
4629-
disk_bytenr));
4628+
BTRFS_FILE_EXTENT_INLINE_DATA_START);
46304629
}
46314630
}
46324631

fs/btrfs/ctree.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,11 @@ struct btrfs_header {
385385
sizeof(struct btrfs_key_ptr))
386386
#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
387387
#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize))
388+
#define BTRFS_FILE_EXTENT_INLINE_DATA_START \
389+
(offsetof(struct btrfs_file_extent_item, disk_bytenr))
388390
#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
389391
sizeof(struct btrfs_item) - \
390-
offsetof(struct btrfs_file_extent_item, disk_bytenr))
392+
BTRFS_FILE_EXTENT_INLINE_DATA_START)
391393
#define BTRFS_MAX_XATTR_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
392394
sizeof(struct btrfs_item) -\
393395
sizeof(struct btrfs_dir_item))
@@ -896,6 +898,8 @@ struct btrfs_file_extent_item {
896898
/*
897899
* disk space consumed by the extent, checksum blocks are included
898900
* in these numbers
901+
*
902+
* At this offset in the structure, the inline extent data start.
899903
*/
900904
__le64 disk_bytenr;
901905
__le64 disk_num_bytes;
@@ -3043,14 +3047,12 @@ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression,
30433047
static inline unsigned long
30443048
btrfs_file_extent_inline_start(struct btrfs_file_extent_item *e)
30453049
{
3046-
unsigned long offset = (unsigned long)e;
3047-
offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
3048-
return offset;
3050+
return (unsigned long)e + BTRFS_FILE_EXTENT_INLINE_DATA_START;
30493051
}
30503052

30513053
static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
30523054
{
3053-
return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
3055+
return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize;
30543056
}
30553057

30563058
BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
@@ -3080,9 +3082,7 @@ BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
30803082
static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
30813083
struct btrfs_item *e)
30823084
{
3083-
unsigned long offset;
3084-
offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
3085-
return btrfs_item_size(eb, e) - offset;
3085+
return btrfs_item_size(eb, e) - BTRFS_FILE_EXTENT_INLINE_DATA_START;
30863086
}
30873087

30883088
/* this returns the number of file bytes represented by the inline item.

0 commit comments

Comments
 (0)