Commit 1cbb1f45 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by David Sterba

btrfs: struct-funcs, constify readers

We have reader helpers for most of the on-disk structures that use
an extent_buffer and pointer as offset into the buffer that are
read-only.  We should mark them as const and, in turn, allow consumers
of these interfaces to mark the buffers const as well.

No impact on code, but serves as documentation that a buffer is intended
not to be modified.
Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 23d1f737
This diff is collapsed.
...@@ -5405,9 +5405,8 @@ int read_extent_buffer_pages(struct extent_io_tree *tree, ...@@ -5405,9 +5405,8 @@ int read_extent_buffer_pages(struct extent_io_tree *tree,
return ret; return ret;
} }
void read_extent_buffer(struct extent_buffer *eb, void *dstv, void read_extent_buffer(const struct extent_buffer *eb, void *dstv,
unsigned long start, unsigned long start, unsigned long len)
unsigned long len)
{ {
size_t cur; size_t cur;
size_t offset; size_t offset;
...@@ -5436,9 +5435,9 @@ void read_extent_buffer(struct extent_buffer *eb, void *dstv, ...@@ -5436,9 +5435,9 @@ void read_extent_buffer(struct extent_buffer *eb, void *dstv,
} }
} }
int read_extent_buffer_to_user(struct extent_buffer *eb, void __user *dstv, int read_extent_buffer_to_user(const struct extent_buffer *eb,
unsigned long start, void __user *dstv,
unsigned long len) unsigned long start, unsigned long len)
{ {
size_t cur; size_t cur;
size_t offset; size_t offset;
...@@ -5478,10 +5477,10 @@ int read_extent_buffer_to_user(struct extent_buffer *eb, void __user *dstv, ...@@ -5478,10 +5477,10 @@ int read_extent_buffer_to_user(struct extent_buffer *eb, void __user *dstv,
* return 1 if the item spans two pages. * return 1 if the item spans two pages.
* return -EINVAL otherwise. * return -EINVAL otherwise.
*/ */
int map_private_extent_buffer(struct extent_buffer *eb, unsigned long start, int map_private_extent_buffer(const struct extent_buffer *eb,
unsigned long min_len, char **map, unsigned long start, unsigned long min_len,
unsigned long *map_start, char **map, unsigned long *map_start,
unsigned long *map_len) unsigned long *map_len)
{ {
size_t offset = start & (PAGE_SIZE - 1); size_t offset = start & (PAGE_SIZE - 1);
char *kaddr; char *kaddr;
...@@ -5515,9 +5514,8 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long start, ...@@ -5515,9 +5514,8 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long start,
return 0; return 0;
} }
int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv,
unsigned long start, unsigned long start, unsigned long len)
unsigned long len)
{ {
size_t cur; size_t cur;
size_t offset; size_t offset;
......
...@@ -449,14 +449,13 @@ static inline void extent_buffer_get(struct extent_buffer *eb) ...@@ -449,14 +449,13 @@ static inline void extent_buffer_get(struct extent_buffer *eb)
atomic_inc(&eb->refs); atomic_inc(&eb->refs);
} }
int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv,
unsigned long start, unsigned long start, unsigned long len);
unsigned long len); void read_extent_buffer(const struct extent_buffer *eb, void *dst,
void read_extent_buffer(struct extent_buffer *eb, void *dst,
unsigned long start, unsigned long start,
unsigned long len); unsigned long len);
int read_extent_buffer_to_user(struct extent_buffer *eb, void __user *dst, int read_extent_buffer_to_user(const struct extent_buffer *eb,
unsigned long start, void __user *dst, unsigned long start,
unsigned long len); unsigned long len);
void write_extent_buffer_fsid(struct extent_buffer *eb, const void *src); void write_extent_buffer_fsid(struct extent_buffer *eb, const void *src);
void write_extent_buffer_chunk_tree_uuid(struct extent_buffer *eb, void write_extent_buffer_chunk_tree_uuid(struct extent_buffer *eb,
...@@ -486,10 +485,10 @@ void set_extent_buffer_uptodate(struct extent_buffer *eb); ...@@ -486,10 +485,10 @@ void set_extent_buffer_uptodate(struct extent_buffer *eb);
void clear_extent_buffer_uptodate(struct extent_buffer *eb); void clear_extent_buffer_uptodate(struct extent_buffer *eb);
int extent_buffer_uptodate(struct extent_buffer *eb); int extent_buffer_uptodate(struct extent_buffer *eb);
int extent_buffer_under_io(struct extent_buffer *eb); int extent_buffer_under_io(struct extent_buffer *eb);
int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset, int map_private_extent_buffer(const struct extent_buffer *eb,
unsigned long min_len, char **map, unsigned long offset, unsigned long min_len,
unsigned long *map_start, char **map, unsigned long *map_start,
unsigned long *map_len); unsigned long *map_len);
void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end); void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end);
void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end); void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end);
void extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end, void extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,
......
...@@ -50,8 +50,8 @@ static inline void put_unaligned_le8(u8 val, void *p) ...@@ -50,8 +50,8 @@ static inline void put_unaligned_le8(u8 val, void *p)
*/ */
#define DEFINE_BTRFS_SETGET_BITS(bits) \ #define DEFINE_BTRFS_SETGET_BITS(bits) \
u##bits btrfs_get_token_##bits(struct extent_buffer *eb, void *ptr, \ u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \
unsigned long off, \ const void *ptr, unsigned long off, \
struct btrfs_map_token *token) \ struct btrfs_map_token *token) \
{ \ { \
unsigned long part_offset = (unsigned long)ptr; \ unsigned long part_offset = (unsigned long)ptr; \
...@@ -90,7 +90,8 @@ u##bits btrfs_get_token_##bits(struct extent_buffer *eb, void *ptr, \ ...@@ -90,7 +90,8 @@ u##bits btrfs_get_token_##bits(struct extent_buffer *eb, void *ptr, \
return res; \ return res; \
} \ } \
void btrfs_set_token_##bits(struct extent_buffer *eb, \ void btrfs_set_token_##bits(struct extent_buffer *eb, \
void *ptr, unsigned long off, u##bits val, \ const void *ptr, unsigned long off, \
u##bits val, \
struct btrfs_map_token *token) \ struct btrfs_map_token *token) \
{ \ { \
unsigned long part_offset = (unsigned long)ptr; \ unsigned long part_offset = (unsigned long)ptr; \
...@@ -133,7 +134,7 @@ DEFINE_BTRFS_SETGET_BITS(16) ...@@ -133,7 +134,7 @@ DEFINE_BTRFS_SETGET_BITS(16)
DEFINE_BTRFS_SETGET_BITS(32) DEFINE_BTRFS_SETGET_BITS(32)
DEFINE_BTRFS_SETGET_BITS(64) DEFINE_BTRFS_SETGET_BITS(64)
void btrfs_node_key(struct extent_buffer *eb, void btrfs_node_key(const struct extent_buffer *eb,
struct btrfs_disk_key *disk_key, int nr) struct btrfs_disk_key *disk_key, int nr)
{ {
unsigned long ptr = btrfs_node_key_ptr_offset(nr); unsigned long ptr = btrfs_node_key_ptr_offset(nr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment