Skip to content

Commit b285eb5

Browse files
committed
btrfs: constify pointer parameters where applicable
We can add const to many 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. This patch does not cover all possible conversions. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 1c44d9f commit b285eb5

31 files changed

+99
-100
lines changed

fs/btrfs/btrfs_inode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,12 @@ static inline void btrfs_i_size_write(struct btrfs_inode *inode, u64 size)
413413
inode->disk_i_size = size;
414414
}
415415

416-
static inline bool btrfs_is_free_space_inode(struct btrfs_inode *inode)
416+
static inline bool btrfs_is_free_space_inode(const struct btrfs_inode *inode)
417417
{
418418
return test_bit(BTRFS_INODE_FREE_SPACE_INODE, &inode->runtime_flags);
419419
}
420420

421-
static inline bool is_data_inode(struct inode *inode)
421+
static inline bool is_data_inode(const struct inode *inode)
422422
{
423423
return btrfs_ino(BTRFS_I(inode)) != BTRFS_BTREE_INODE_OBJECTID;
424424
}

fs/btrfs/delalloc-space.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
* making error handling and cleanup easier.
112112
*/
113113

114-
int btrfs_alloc_data_chunk_ondemand(struct btrfs_inode *inode, u64 bytes)
114+
int btrfs_alloc_data_chunk_ondemand(const struct btrfs_inode *inode, u64 bytes)
115115
{
116116
struct btrfs_root *root = inode->root;
117117
struct btrfs_fs_info *fs_info = root->fs_info;

fs/btrfs/delalloc-space.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct extent_changeset;
99
struct btrfs_inode;
1010
struct btrfs_fs_info;
1111

12-
int btrfs_alloc_data_chunk_ondemand(struct btrfs_inode *inode, u64 bytes);
12+
int btrfs_alloc_data_chunk_ondemand(const struct btrfs_inode *inode, u64 bytes);
1313
int btrfs_check_data_free_space(struct btrfs_inode *inode,
1414
struct extent_changeset **reserved, u64 start, u64 len,
1515
bool noflush);

fs/btrfs/delayed-inode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ static void btrfs_release_dir_index_item_space(struct btrfs_trans_handle *trans)
14691469
int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
14701470
const char *name, int name_len,
14711471
struct btrfs_inode *dir,
1472-
struct btrfs_disk_key *disk_key, u8 flags,
1472+
const struct btrfs_disk_key *disk_key, u8 flags,
14731473
u64 index)
14741474
{
14751475
struct btrfs_fs_info *fs_info = trans->fs_info;
@@ -1755,7 +1755,7 @@ void btrfs_readdir_put_delayed_items(struct inode *inode,
17551755
downgrade_write(&inode->i_rwsem);
17561756
}
17571757

1758-
int btrfs_should_delete_dir_index(struct list_head *del_list,
1758+
int btrfs_should_delete_dir_index(const struct list_head *del_list,
17591759
u64 index)
17601760
{
17611761
struct btrfs_delayed_item *curr;
@@ -1776,7 +1776,7 @@ int btrfs_should_delete_dir_index(struct list_head *del_list,
17761776
* Read dir info stored in the delayed tree.
17771777
*/
17781778
int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
1779-
struct list_head *ins_list)
1779+
const struct list_head *ins_list)
17801780
{
17811781
struct btrfs_dir_item *di;
17821782
struct btrfs_delayed_item *curr, *next;

fs/btrfs/delayed-inode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void btrfs_init_delayed_root(struct btrfs_delayed_root *delayed_root);
110110
int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
111111
const char *name, int name_len,
112112
struct btrfs_inode *dir,
113-
struct btrfs_disk_key *disk_key, u8 flags,
113+
const struct btrfs_disk_key *disk_key, u8 flags,
114114
u64 index);
115115

116116
int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
@@ -150,10 +150,10 @@ bool btrfs_readdir_get_delayed_items(struct inode *inode,
150150
void btrfs_readdir_put_delayed_items(struct inode *inode,
151151
struct list_head *ins_list,
152152
struct list_head *del_list);
153-
int btrfs_should_delete_dir_index(struct list_head *del_list,
153+
int btrfs_should_delete_dir_index(const struct list_head *del_list,
154154
u64 index);
155155
int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
156-
struct list_head *ins_list);
156+
const struct list_head *ins_list);
157157

158158
/* Used during directory logging. */
159159
void btrfs_log_get_delayed_items(struct btrfs_inode *inode,

fs/btrfs/dir-item.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static struct btrfs_dir_item *insert_with_overflow(struct btrfs_trans_handle
2222
*trans,
2323
struct btrfs_root *root,
2424
struct btrfs_path *path,
25-
struct btrfs_key *cpu_key,
25+
const struct btrfs_key *cpu_key,
2626
u32 data_size,
2727
const char *name,
2828
int name_len)
@@ -108,7 +108,7 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
108108
*/
109109
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
110110
const struct fscrypt_str *name, struct btrfs_inode *dir,
111-
struct btrfs_key *location, u8 type, u64 index)
111+
const struct btrfs_key *location, u8 type, u64 index)
112112
{
113113
int ret = 0;
114114
int ret2 = 0;
@@ -379,7 +379,7 @@ struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
379379
* for a specific name.
380380
*/
381381
struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_fs_info *fs_info,
382-
struct btrfs_path *path,
382+
const struct btrfs_path *path,
383383
const char *name, int name_len)
384384
{
385385
struct btrfs_dir_item *dir_item;
@@ -417,7 +417,7 @@ struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_fs_info *fs_info,
417417
int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
418418
struct btrfs_root *root,
419419
struct btrfs_path *path,
420-
struct btrfs_dir_item *di)
420+
const struct btrfs_dir_item *di)
421421
{
422422

423423
struct extent_buffer *leaf;

fs/btrfs/dir-item.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
1717
const struct fscrypt_str *name);
1818
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
1919
const struct fscrypt_str *name, struct btrfs_inode *dir,
20-
struct btrfs_key *location, u8 type, u64 index);
20+
const struct btrfs_key *location, u8 type, u64 index);
2121
struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
2222
struct btrfs_root *root,
2323
struct btrfs_path *path, u64 dir,
@@ -33,7 +33,7 @@ struct btrfs_dir_item *btrfs_search_dir_index_item(struct btrfs_root *root,
3333
int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
3434
struct btrfs_root *root,
3535
struct btrfs_path *path,
36-
struct btrfs_dir_item *di);
36+
const struct btrfs_dir_item *di);
3737
int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
3838
struct btrfs_root *root,
3939
struct btrfs_path *path, u64 objectid,
@@ -45,7 +45,7 @@ struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
4545
const char *name, u16 name_len,
4646
int mod);
4747
struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_fs_info *fs_info,
48-
struct btrfs_path *path,
48+
const struct btrfs_path *path,
4949
const char *name,
5050
int name_len);
5151

fs/btrfs/disk-io.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb,
213213
* structure for details.
214214
*/
215215
int btrfs_read_extent_buffer(struct extent_buffer *eb,
216-
struct btrfs_tree_parent_check *check)
216+
const struct btrfs_tree_parent_check *check)
217217
{
218218
struct btrfs_fs_info *fs_info = eb->fs_info;
219219
int failed = 0;
@@ -358,7 +358,7 @@ static bool check_tree_block_fsid(struct extent_buffer *eb)
358358

359359
/* Do basic extent buffer checks at read time */
360360
int btrfs_validate_extent_buffer(struct extent_buffer *eb,
361-
struct btrfs_tree_parent_check *check)
361+
const struct btrfs_tree_parent_check *check)
362362
{
363363
struct btrfs_fs_info *fs_info = eb->fs_info;
364364
u64 found_start;
@@ -425,7 +425,7 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,
425425
goto out;
426426
}
427427
if (check->has_first_key) {
428-
struct btrfs_key *expect_key = &check->first_key;
428+
const struct btrfs_key *expect_key = &check->first_key;
429429
struct btrfs_key found_key;
430430

431431
if (found_level)
@@ -1025,7 +1025,7 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
10251025

10261026
static struct btrfs_root *read_tree_root_path(struct btrfs_root *tree_root,
10271027
struct btrfs_path *path,
1028-
struct btrfs_key *key)
1028+
const struct btrfs_key *key)
10291029
{
10301030
struct btrfs_root *root;
10311031
struct btrfs_tree_parent_check check = { 0 };
@@ -1087,7 +1087,7 @@ static struct btrfs_root *read_tree_root_path(struct btrfs_root *tree_root,
10871087
}
10881088

10891089
struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
1090-
struct btrfs_key *key)
1090+
const struct btrfs_key *key)
10911091
{
10921092
struct btrfs_root *root;
10931093
struct btrfs_path *path;
@@ -1222,7 +1222,7 @@ int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info,
12221222
return ret;
12231223
}
12241224

1225-
void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info)
1225+
void btrfs_check_leaked_roots(const struct btrfs_fs_info *fs_info)
12261226
{
12271227
#ifdef CONFIG_BTRFS_DEBUG
12281228
struct btrfs_root *root;
@@ -2339,8 +2339,8 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
23392339
* 1, 2 2nd and 3rd backup copy
23402340
* -1 skip bytenr check
23412341
*/
2342-
int btrfs_validate_super(struct btrfs_fs_info *fs_info,
2343-
struct btrfs_super_block *sb, int mirror_num)
2342+
int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
2343+
const struct btrfs_super_block *sb, int mirror_num)
23442344
{
23452345
u64 nodesize = btrfs_super_nodesize(sb);
23462346
u64 sectorsize = btrfs_super_sectorsize(sb);
@@ -3192,7 +3192,7 @@ int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount)
31923192
}
31933193

31943194
int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices,
3195-
char *options)
3195+
const char *options)
31963196
{
31973197
u32 sectorsize;
31983198
u32 nodesize;

fs/btrfs/disk-io.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static inline u64 btrfs_sb_offset(int mirror)
4141
return BTRFS_SUPER_INFO_OFFSET;
4242
}
4343

44-
void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info);
44+
void btrfs_check_leaked_roots(const struct btrfs_fs_info *fs_info);
4545
void btrfs_init_fs_info(struct btrfs_fs_info *fs_info);
4646
struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
4747
struct btrfs_tree_parent_check *check);
@@ -52,20 +52,19 @@ struct extent_buffer *btrfs_find_create_tree_block(
5252
int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info);
5353
int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
5454
const struct btrfs_super_block *disk_sb);
55-
int __cold open_ctree(struct super_block *sb,
56-
struct btrfs_fs_devices *fs_devices,
57-
char *options);
55+
int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices,
56+
const char *options);
5857
void __cold close_ctree(struct btrfs_fs_info *fs_info);
59-
int btrfs_validate_super(struct btrfs_fs_info *fs_info,
60-
struct btrfs_super_block *sb, int mirror_num);
58+
int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
59+
const struct btrfs_super_block *sb, int mirror_num);
6160
int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount);
6261
int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors);
6362
struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev);
6463
struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
6564
int copy_num, bool drop_cache);
6665
int btrfs_commit_super(struct btrfs_fs_info *fs_info);
6766
struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
68-
struct btrfs_key *key);
67+
const struct btrfs_key *key);
6968
int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info,
7069
struct btrfs_root *root);
7170
void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info);
@@ -90,7 +89,7 @@ void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info);
9089
void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
9190
struct btrfs_root *root);
9291
int btrfs_validate_extent_buffer(struct extent_buffer *eb,
93-
struct btrfs_tree_parent_check *check);
92+
const struct btrfs_tree_parent_check *check);
9493
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
9594
struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info);
9695
#endif
@@ -117,7 +116,7 @@ void btrfs_mark_buffer_dirty(struct btrfs_trans_handle *trans,
117116
int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
118117
int atomic);
119118
int btrfs_read_extent_buffer(struct extent_buffer *buf,
120-
struct btrfs_tree_parent_check *check);
119+
const struct btrfs_tree_parent_check *check);
121120

122121
blk_status_t btree_csum_one_bio(struct btrfs_bio *bbio);
123122
int btrfs_alloc_log_tree_node(struct btrfs_trans_handle *trans,

fs/btrfs/extent_io.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end)
180180
}
181181

182182
static void process_one_page(struct btrfs_fs_info *fs_info,
183-
struct page *page, struct page *locked_page,
183+
struct page *page, const struct page *locked_page,
184184
unsigned long page_ops, u64 start, u64 end)
185185
{
186186
struct folio *folio = page_folio(page);
@@ -203,7 +203,7 @@ static void process_one_page(struct btrfs_fs_info *fs_info,
203203
}
204204

205205
static void __process_pages_contig(struct address_space *mapping,
206-
struct page *locked_page, u64 start, u64 end,
206+
const struct page *locked_page, u64 start, u64 end,
207207
unsigned long page_ops)
208208
{
209209
struct btrfs_fs_info *fs_info = inode_to_fs_info(mapping->host);
@@ -230,8 +230,8 @@ static void __process_pages_contig(struct address_space *mapping,
230230
}
231231
}
232232

233-
static noinline void __unlock_for_delalloc(struct inode *inode,
234-
struct page *locked_page,
233+
static noinline void __unlock_for_delalloc(const struct inode *inode,
234+
const struct page *locked_page,
235235
u64 start, u64 end)
236236
{
237237
unsigned long index = start >> PAGE_SHIFT;
@@ -246,7 +246,7 @@ static noinline void __unlock_for_delalloc(struct inode *inode,
246246
}
247247

248248
static noinline int lock_delalloc_pages(struct inode *inode,
249-
struct page *locked_page,
249+
const struct page *locked_page,
250250
u64 start,
251251
u64 end)
252252
{
@@ -411,7 +411,7 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode,
411411
}
412412

413413
void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
414-
struct page *locked_page,
414+
const struct page *locked_page,
415415
struct extent_state **cached,
416416
u32 clear_bits, unsigned long page_ops)
417417
{
@@ -1382,7 +1382,7 @@ static noinline_for_stack int writepage_delalloc(struct btrfs_inode *inode,
13821382
* Return the next dirty range in [@start, @end).
13831383
* If no dirty range is found, @start will be page_offset(page) + PAGE_SIZE.
13841384
*/
1385-
static void find_next_dirty_byte(struct btrfs_fs_info *fs_info,
1385+
static void find_next_dirty_byte(const struct btrfs_fs_info *fs_info,
13861386
struct page *page, u64 *start, u64 *end)
13871387
{
13881388
struct folio *folio = page_folio(page);
@@ -1743,7 +1743,7 @@ static void set_btree_ioerr(struct extent_buffer *eb)
17431743
* context.
17441744
*/
17451745
static struct extent_buffer *find_extent_buffer_nolock(
1746-
struct btrfs_fs_info *fs_info, u64 start)
1746+
const struct btrfs_fs_info *fs_info, u64 start)
17471747
{
17481748
struct extent_buffer *eb;
17491749

@@ -2312,7 +2312,7 @@ static int extent_write_cache_pages(struct address_space *mapping,
23122312
* already been ran (aka, ordered extent inserted) and all pages are still
23132313
* locked.
23142314
*/
2315-
void extent_write_locked_range(struct inode *inode, struct page *locked_page,
2315+
void extent_write_locked_range(struct inode *inode, const struct page *locked_page,
23162316
u64 start, u64 end, struct writeback_control *wbc,
23172317
bool pages_dirty)
23182318
{
@@ -2597,7 +2597,7 @@ static bool folio_range_has_eb(struct btrfs_fs_info *fs_info, struct folio *foli
25972597
return false;
25982598
}
25992599

2600-
static void detach_extent_buffer_folio(struct extent_buffer *eb, struct folio *folio)
2600+
static void detach_extent_buffer_folio(const struct extent_buffer *eb, struct folio *folio)
26012601
{
26022602
struct btrfs_fs_info *fs_info = eb->fs_info;
26032603
const bool mapped = !test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags);
@@ -2658,7 +2658,7 @@ static void detach_extent_buffer_folio(struct extent_buffer *eb, struct folio *f
26582658
}
26592659

26602660
/* Release all pages attached to the extent buffer */
2661-
static void btrfs_release_extent_buffer_pages(struct extent_buffer *eb)
2661+
static void btrfs_release_extent_buffer_pages(const struct extent_buffer *eb)
26622662
{
26632663
ASSERT(!extent_buffer_under_io(eb));
26642664

@@ -3573,7 +3573,7 @@ static void end_bbio_meta_read(struct btrfs_bio *bbio)
35733573
}
35743574

35753575
int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num,
3576-
struct btrfs_tree_parent_check *check)
3576+
const struct btrfs_tree_parent_check *check)
35773577
{
35783578
struct btrfs_bio *bbio;
35793579
bool ret;
@@ -4186,7 +4186,7 @@ void memmove_extent_buffer(const struct extent_buffer *dst,
41864186

41874187
#define GANG_LOOKUP_SIZE 16
41884188
static struct extent_buffer *get_next_extent_buffer(
4189-
struct btrfs_fs_info *fs_info, struct page *page, u64 bytenr)
4189+
const struct btrfs_fs_info *fs_info, struct page *page, u64 bytenr)
41904190
{
41914191
struct extent_buffer *gang[GANG_LOOKUP_SIZE];
41924192
struct extent_buffer *found = NULL;

0 commit comments

Comments
 (0)