Skip to content

Commit ca283ea

Browse files
committed
btrfs: constify more pointer parameters
Continue adding const to parameters. This is for clarity and minor addition to safety. There are some minor effects, in the assembly code and .ko measured on release config. Signed-off-by: David Sterba <[email protected]>
1 parent 070969f commit ca283ea

19 files changed

+84
-86
lines changed

fs/btrfs/backref.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ static void free_pref(struct prelim_ref *ref)
219219
* A -1 return indicates ref1 is a 'lower' block than ref2, while 1
220220
* indicates a 'higher' block.
221221
*/
222-
static int prelim_ref_compare(struct prelim_ref *ref1,
223-
struct prelim_ref *ref2)
222+
static int prelim_ref_compare(const struct prelim_ref *ref1,
223+
const struct prelim_ref *ref2)
224224
{
225225
if (ref1->level < ref2->level)
226226
return -1;
@@ -251,7 +251,7 @@ static int prelim_ref_compare(struct prelim_ref *ref1,
251251
}
252252

253253
static void update_share_count(struct share_check *sc, int oldcount,
254-
int newcount, struct prelim_ref *newref)
254+
int newcount, const struct prelim_ref *newref)
255255
{
256256
if ((!sc) || (oldcount == 0 && newcount < 1))
257257
return;

fs/btrfs/block-group.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "extent-tree.h"
2424

2525
#ifdef CONFIG_BTRFS_DEBUG
26-
int btrfs_should_fragment_free_space(struct btrfs_block_group *block_group)
26+
int btrfs_should_fragment_free_space(const struct btrfs_block_group *block_group)
2727
{
2828
struct btrfs_fs_info *fs_info = block_group->fs_info;
2929

@@ -40,9 +40,9 @@ int btrfs_should_fragment_free_space(struct btrfs_block_group *block_group)
4040
*
4141
* Should be called with balance_lock held
4242
*/
43-
static u64 get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags)
43+
static u64 get_restripe_target(const struct btrfs_fs_info *fs_info, u64 flags)
4444
{
45-
struct btrfs_balance_control *bctl = fs_info->balance_ctl;
45+
const struct btrfs_balance_control *bctl = fs_info->balance_ctl;
4646
u64 target = 0;
4747

4848
if (!bctl)
@@ -1415,9 +1415,9 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, int force)
14151415
}
14161416

14171417
static bool clean_pinned_extents(struct btrfs_trans_handle *trans,
1418-
struct btrfs_block_group *bg)
1418+
const struct btrfs_block_group *bg)
14191419
{
1420-
struct btrfs_fs_info *fs_info = bg->fs_info;
1420+
struct btrfs_fs_info *fs_info = trans->fs_info;
14211421
struct btrfs_transaction *prev_trans = NULL;
14221422
const u64 start = bg->start;
14231423
const u64 end = start + bg->length - 1;
@@ -1756,14 +1756,14 @@ static int reclaim_bgs_cmp(void *unused, const struct list_head *a,
17561756
return bg1->used > bg2->used;
17571757
}
17581758

1759-
static inline bool btrfs_should_reclaim(struct btrfs_fs_info *fs_info)
1759+
static inline bool btrfs_should_reclaim(const struct btrfs_fs_info *fs_info)
17601760
{
17611761
if (btrfs_is_zoned(fs_info))
17621762
return btrfs_zoned_should_reclaim(fs_info);
17631763
return true;
17641764
}
17651765

1766-
static bool should_reclaim_block_group(struct btrfs_block_group *bg, u64 bytes_freed)
1766+
static bool should_reclaim_block_group(const struct btrfs_block_group *bg, u64 bytes_freed)
17671767
{
17681768
const int thresh_pct = btrfs_calc_reclaim_threshold(bg->space_info);
17691769
u64 thresh_bytes = mult_perc(bg->length, thresh_pct);
@@ -2006,8 +2006,8 @@ void btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg)
20062006
spin_unlock(&fs_info->unused_bgs_lock);
20072007
}
20082008

2009-
static int read_bg_from_eb(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
2010-
struct btrfs_path *path)
2009+
static int read_bg_from_eb(struct btrfs_fs_info *fs_info, const struct btrfs_key *key,
2010+
const struct btrfs_path *path)
20112011
{
20122012
struct btrfs_chunk_map *map;
20132013
struct btrfs_block_group_item bg;
@@ -2055,7 +2055,7 @@ static int read_bg_from_eb(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
20552055

20562056
static int find_first_block_group(struct btrfs_fs_info *fs_info,
20572057
struct btrfs_path *path,
2058-
struct btrfs_key *key)
2058+
const struct btrfs_key *key)
20592059
{
20602060
struct btrfs_root *root = btrfs_block_group_root(fs_info);
20612061
int ret;
@@ -2640,8 +2640,8 @@ static int insert_block_group_item(struct btrfs_trans_handle *trans,
26402640
}
26412641

26422642
static int insert_dev_extent(struct btrfs_trans_handle *trans,
2643-
struct btrfs_device *device, u64 chunk_offset,
2644-
u64 start, u64 num_bytes)
2643+
const struct btrfs_device *device, u64 chunk_offset,
2644+
u64 start, u64 num_bytes)
26452645
{
26462646
struct btrfs_fs_info *fs_info = device->fs_info;
26472647
struct btrfs_root *root = fs_info->dev_root;
@@ -2817,7 +2817,7 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans)
28172817
* For extent tree v2 we use the block_group_item->chunk_offset to point at our
28182818
* global root id. For v1 it's always set to BTRFS_FIRST_CHUNK_TREE_OBJECTID.
28192819
*/
2820-
static u64 calculate_global_root_id(struct btrfs_fs_info *fs_info, u64 offset)
2820+
static u64 calculate_global_root_id(const struct btrfs_fs_info *fs_info, u64 offset)
28212821
{
28222822
u64 div = SZ_1G;
28232823
u64 index;
@@ -3842,8 +3842,8 @@ static void force_metadata_allocation(struct btrfs_fs_info *info)
38423842
}
38433843
}
38443844

3845-
static int should_alloc_chunk(struct btrfs_fs_info *fs_info,
3846-
struct btrfs_space_info *sinfo, int force)
3845+
static int should_alloc_chunk(const struct btrfs_fs_info *fs_info,
3846+
const struct btrfs_space_info *sinfo, int force)
38473847
{
38483848
u64 bytes_used = btrfs_space_info_used(sinfo, false);
38493849
u64 thresh;
@@ -4218,7 +4218,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
42184218
return ret;
42194219
}
42204220

4221-
static u64 get_profile_num_devs(struct btrfs_fs_info *fs_info, u64 type)
4221+
static u64 get_profile_num_devs(const struct btrfs_fs_info *fs_info, u64 type)
42224222
{
42234223
u64 num_dev;
42244224

@@ -4622,7 +4622,7 @@ int btrfs_use_block_group_size_class(struct btrfs_block_group *bg,
46224622
return 0;
46234623
}
46244624

4625-
bool btrfs_block_group_should_use_size_class(struct btrfs_block_group *bg)
4625+
bool btrfs_block_group_should_use_size_class(const struct btrfs_block_group *bg)
46264626
{
46274627
if (btrfs_is_zoned(bg->fs_info))
46284628
return false;

fs/btrfs/block-group.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ struct btrfs_block_group {
266266
u64 reclaim_mark;
267267
};
268268

269-
static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group)
269+
static inline u64 btrfs_block_group_end(const struct btrfs_block_group *block_group)
270270
{
271271
return (block_group->start + block_group->length);
272272
}
@@ -278,8 +278,7 @@ static inline bool btrfs_is_block_group_used(const struct btrfs_block_group *bg)
278278
return (bg->used > 0 || bg->reserved > 0 || bg->pinned > 0);
279279
}
280280

281-
static inline bool btrfs_is_block_group_data_only(
282-
struct btrfs_block_group *block_group)
281+
static inline bool btrfs_is_block_group_data_only(const struct btrfs_block_group *block_group)
283282
{
284283
/*
285284
* In mixed mode the fragmentation is expected to be high, lowering the
@@ -290,7 +289,7 @@ static inline bool btrfs_is_block_group_data_only(
290289
}
291290

292291
#ifdef CONFIG_BTRFS_DEBUG
293-
int btrfs_should_fragment_free_space(struct btrfs_block_group *block_group);
292+
int btrfs_should_fragment_free_space(const struct btrfs_block_group *block_group);
294293
#endif
295294

296295
struct btrfs_block_group *btrfs_lookup_first_block_group(
@@ -370,7 +369,7 @@ static inline u64 btrfs_system_alloc_profile(struct btrfs_fs_info *fs_info)
370369
return btrfs_get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_SYSTEM);
371370
}
372371

373-
static inline int btrfs_block_group_done(struct btrfs_block_group *cache)
372+
static inline int btrfs_block_group_done(const struct btrfs_block_group *cache)
374373
{
375374
smp_mb();
376375
return cache->cached == BTRFS_CACHE_FINISHED ||
@@ -387,6 +386,6 @@ enum btrfs_block_group_size_class btrfs_calc_block_group_size_class(u64 size);
387386
int btrfs_use_block_group_size_class(struct btrfs_block_group *bg,
388387
enum btrfs_block_group_size_class size_class,
389388
bool force_wrong_size_class);
390-
bool btrfs_block_group_should_use_size_class(struct btrfs_block_group *bg);
389+
bool btrfs_block_group_should_use_size_class(const struct btrfs_block_group *bg);
391390

392391
#endif /* BTRFS_BLOCK_GROUP_H */

fs/btrfs/block-rsv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans,
553553
return ERR_PTR(ret);
554554
}
555555

556-
int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
556+
int btrfs_check_trunc_cache_free_space(const struct btrfs_fs_info *fs_info,
557557
struct btrfs_block_rsv *rsv)
558558
{
559559
u64 needed_bytes;

fs/btrfs/block-rsv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void btrfs_release_global_block_rsv(struct btrfs_fs_info *fs_info);
8989
struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans,
9090
struct btrfs_root *root,
9191
u32 blocksize);
92-
int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
92+
int btrfs_check_trunc_cache_free_space(const struct btrfs_fs_info *fs_info,
9393
struct btrfs_block_rsv *rsv);
9494
static inline void btrfs_unuse_block_rsv(struct btrfs_fs_info *fs_info,
9595
struct btrfs_block_rsv *block_rsv,

fs/btrfs/ctree.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,8 +2564,8 @@ int btrfs_get_next_valid_item(struct btrfs_root *root, struct btrfs_key *key,
25642564
*
25652565
*/
25662566
static void fixup_low_keys(struct btrfs_trans_handle *trans,
2567-
struct btrfs_path *path,
2568-
struct btrfs_disk_key *key, int level)
2567+
const struct btrfs_path *path,
2568+
const struct btrfs_disk_key *key, int level)
25692569
{
25702570
int i;
25712571
struct extent_buffer *t;
@@ -2594,7 +2594,7 @@ static void fixup_low_keys(struct btrfs_trans_handle *trans,
25942594
* that the new key won't break the order
25952595
*/
25962596
void btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
2597-
struct btrfs_path *path,
2597+
const struct btrfs_path *path,
25982598
const struct btrfs_key *new_key)
25992599
{
26002600
struct btrfs_fs_info *fs_info = trans->fs_info;
@@ -2660,8 +2660,8 @@ void btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
26602660
* is correct, we only need to bother the last key of @left and the first
26612661
* key of @right.
26622662
*/
2663-
static bool check_sibling_keys(struct extent_buffer *left,
2664-
struct extent_buffer *right)
2663+
static bool check_sibling_keys(const struct extent_buffer *left,
2664+
const struct extent_buffer *right)
26652665
{
26662666
struct btrfs_key left_last;
26672667
struct btrfs_key right_first;
@@ -2928,8 +2928,8 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans,
29282928
* blocknr is the block the key points to.
29292929
*/
29302930
static int insert_ptr(struct btrfs_trans_handle *trans,
2931-
struct btrfs_path *path,
2932-
struct btrfs_disk_key *key, u64 bytenr,
2931+
const struct btrfs_path *path,
2932+
const struct btrfs_disk_key *key, u64 bytenr,
29332933
int slot, int level)
29342934
{
29352935
struct extent_buffer *lower;
@@ -4019,7 +4019,7 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,
40194019
* the front.
40204020
*/
40214021
void btrfs_truncate_item(struct btrfs_trans_handle *trans,
4022-
struct btrfs_path *path, u32 new_size, int from_end)
4022+
const struct btrfs_path *path, u32 new_size, int from_end)
40234023
{
40244024
int slot;
40254025
struct extent_buffer *leaf;
@@ -4111,7 +4111,7 @@ void btrfs_truncate_item(struct btrfs_trans_handle *trans,
41114111
* make the item pointed to by the path bigger, data_size is the added size.
41124112
*/
41134113
void btrfs_extend_item(struct btrfs_trans_handle *trans,
4114-
struct btrfs_path *path, u32 data_size)
4114+
const struct btrfs_path *path, u32 data_size)
41154115
{
41164116
int slot;
41174117
struct extent_buffer *leaf;

fs/btrfs/ctree.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ int btrfs_previous_item(struct btrfs_root *root,
538538
int btrfs_previous_extent_item(struct btrfs_root *root,
539539
struct btrfs_path *path, u64 min_objectid);
540540
void btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
541-
struct btrfs_path *path,
541+
const struct btrfs_path *path,
542542
const struct btrfs_key *new_key);
543543
struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
544544
int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
@@ -572,9 +572,9 @@ bool btrfs_block_can_be_shared(struct btrfs_trans_handle *trans,
572572
int btrfs_del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root,
573573
struct btrfs_path *path, int level, int slot);
574574
void btrfs_extend_item(struct btrfs_trans_handle *trans,
575-
struct btrfs_path *path, u32 data_size);
575+
const struct btrfs_path *path, u32 data_size);
576576
void btrfs_truncate_item(struct btrfs_trans_handle *trans,
577-
struct btrfs_path *path, u32 new_size, int from_end);
577+
const struct btrfs_path *path, u32 new_size, int from_end);
578578
int btrfs_split_item(struct btrfs_trans_handle *trans,
579579
struct btrfs_root *root,
580580
struct btrfs_path *path,

fs/btrfs/discard.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int discard_minlen[BTRFS_NR_DISCARD_LISTS] = {
6868
};
6969

7070
static struct list_head *get_discard_list(struct btrfs_discard_ctl *discard_ctl,
71-
struct btrfs_block_group *block_group)
71+
const struct btrfs_block_group *block_group)
7272
{
7373
return &discard_ctl->discard_list[block_group->discard_index];
7474
}
@@ -80,7 +80,7 @@ static struct list_head *get_discard_list(struct btrfs_discard_ctl *discard_ctl,
8080
*
8181
* Check if the file system is writeable and BTRFS_FS_DISCARD_RUNNING is set.
8282
*/
83-
static bool btrfs_run_discard_work(struct btrfs_discard_ctl *discard_ctl)
83+
static bool btrfs_run_discard_work(const struct btrfs_discard_ctl *discard_ctl)
8484
{
8585
struct btrfs_fs_info *fs_info = container_of(discard_ctl,
8686
struct btrfs_fs_info,

fs/btrfs/file-item.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static inline u32 max_ordered_sum_bytes(const struct btrfs_fs_info *fs_info)
151151
* Calculate the total size needed to allocate for an ordered sum structure
152152
* spanning @bytes in the file.
153153
*/
154-
static int btrfs_ordered_sum_size(struct btrfs_fs_info *fs_info, unsigned long bytes)
154+
static int btrfs_ordered_sum_size(const struct btrfs_fs_info *fs_info, unsigned long bytes)
155155
{
156156
return sizeof(struct btrfs_ordered_sum) + bytes_to_csum_size(fs_info, bytes);
157157
}
@@ -1272,7 +1272,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
12721272

12731273
void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
12741274
const struct btrfs_path *path,
1275-
struct btrfs_file_extent_item *fi,
1275+
const struct btrfs_file_extent_item *fi,
12761276
struct extent_map *em)
12771277
{
12781278
struct btrfs_fs_info *fs_info = inode->root->fs_info;

fs/btrfs/file-item.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int btrfs_lookup_csums_bitmap(struct btrfs_root *root, struct btrfs_path *path,
7474
unsigned long *csum_bitmap);
7575
void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
7676
const struct btrfs_path *path,
77-
struct btrfs_file_extent_item *fi,
77+
const struct btrfs_file_extent_item *fi,
7878
struct extent_map *em);
7979
int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start,
8080
u64 len);

0 commit comments

Comments
 (0)