Skip to content

Commit 0138f46

Browse files
adam900710gregkh
authored andcommitted
btrfs: rename btrfs_folio_(set|start|end)_writer_lock()
[ Upstream commit 0f71202 ] Since there is no user of reader locks, rename the writer locks into a more generic name, by removing the "_writer" part from the name. And also rename btrfs_subpage::writer into btrfs_subpage::locked. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]> Stable-dep-of: 8bf334b ("btrfs: fix double accounting race when extent_writepage_io() failed") Signed-off-by: Sasha Levin <[email protected]>
1 parent e092298 commit 0138f46

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

fs/btrfs/compression.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
545545
* subpage::readers and to unlock the page.
546546
*/
547547
if (fs_info->sectorsize < PAGE_SIZE)
548-
btrfs_folio_set_writer_lock(fs_info, folio, cur, add_size);
548+
btrfs_folio_set_lock(fs_info, folio, cur, add_size);
549549
folio_put(folio);
550550
cur += add_size;
551551
}

fs/btrfs/extent_io.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static void process_one_folio(struct btrfs_fs_info *fs_info,
190190
btrfs_folio_clamp_clear_writeback(fs_info, folio, start, len);
191191

192192
if (folio != locked_folio && (page_ops & PAGE_UNLOCK))
193-
btrfs_folio_end_writer_lock(fs_info, folio, start, len);
193+
btrfs_folio_end_lock(fs_info, folio, start, len);
194194
}
195195

196196
static void __process_folios_contig(struct address_space *mapping,
@@ -276,7 +276,7 @@ static noinline int lock_delalloc_folios(struct inode *inode,
276276
range_start = max_t(u64, folio_pos(folio), start);
277277
range_len = min_t(u64, folio_pos(folio) + folio_size(folio),
278278
end + 1) - range_start;
279-
btrfs_folio_set_writer_lock(fs_info, folio, range_start, range_len);
279+
btrfs_folio_set_lock(fs_info, folio, range_start, range_len);
280280

281281
processed_end = range_start + range_len - 1;
282282
}
@@ -438,7 +438,7 @@ static void end_folio_read(struct folio *folio, bool uptodate, u64 start, u32 le
438438
if (!btrfs_is_subpage(fs_info, folio->mapping))
439439
folio_unlock(folio);
440440
else
441-
btrfs_folio_end_writer_lock(fs_info, folio, start, len);
441+
btrfs_folio_end_lock(fs_info, folio, start, len);
442442
}
443443

444444
/*
@@ -495,7 +495,7 @@ static void begin_folio_read(struct btrfs_fs_info *fs_info, struct folio *folio)
495495
return;
496496

497497
ASSERT(folio_test_private(folio));
498-
btrfs_folio_set_writer_lock(fs_info, folio, folio_pos(folio), PAGE_SIZE);
498+
btrfs_folio_set_lock(fs_info, folio, folio_pos(folio), PAGE_SIZE);
499499
}
500500

501501
/*
@@ -1187,7 +1187,7 @@ static noinline_for_stack int writepage_delalloc(struct btrfs_inode *inode,
11871187
for_each_set_bit(bit, &bio_ctrl->submit_bitmap, fs_info->sectors_per_page) {
11881188
u64 start = page_start + (bit << fs_info->sectorsize_bits);
11891189

1190-
btrfs_folio_set_writer_lock(fs_info, folio, start, fs_info->sectorsize);
1190+
btrfs_folio_set_lock(fs_info, folio, start, fs_info->sectorsize);
11911191
}
11921192

11931193
/* Lock all (subpage) delalloc ranges inside the folio first. */
@@ -1523,7 +1523,7 @@ static int extent_writepage(struct folio *folio, struct btrfs_bio_ctrl *bio_ctrl
15231523
* Only unlock ranges that are submitted. As there can be some async
15241524
* submitted ranges inside the folio.
15251525
*/
1526-
btrfs_folio_end_writer_lock_bitmap(fs_info, folio, bio_ctrl->submit_bitmap);
1526+
btrfs_folio_end_lock_bitmap(fs_info, folio, bio_ctrl->submit_bitmap);
15271527
ASSERT(ret <= 0);
15281528
return ret;
15291529
}
@@ -2280,7 +2280,7 @@ void extent_write_locked_range(struct inode *inode, const struct folio *locked_f
22802280
cur, cur_len, !ret);
22812281
mapping_set_error(mapping, ret);
22822282
}
2283-
btrfs_folio_end_writer_lock(fs_info, folio, cur, cur_len);
2283+
btrfs_folio_end_lock(fs_info, folio, cur, cur_len);
22842284
if (ret < 0)
22852285
found_error = true;
22862286
next_page:

fs/btrfs/subpage.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ struct btrfs_subpage *btrfs_alloc_subpage(const struct btrfs_fs_info *fs_info,
143143
if (type == BTRFS_SUBPAGE_METADATA)
144144
atomic_set(&ret->eb_refs, 0);
145145
else
146-
atomic_set(&ret->writers, 0);
146+
atomic_set(&ret->nr_locked, 0);
147147
return ret;
148148
}
149149

@@ -237,8 +237,8 @@ static void btrfs_subpage_clamp_range(struct folio *folio, u64 *start, u32 *len)
237237
orig_start + orig_len) - *start;
238238
}
239239

240-
static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_info,
241-
struct folio *folio, u64 start, u32 len)
240+
static bool btrfs_subpage_end_and_test_lock(const struct btrfs_fs_info *fs_info,
241+
struct folio *folio, u64 start, u32 len)
242242
{
243243
struct btrfs_subpage *subpage = folio_get_private(folio);
244244
const int start_bit = subpage_calc_start_bit(fs_info, folio, locked, start, len);
@@ -256,9 +256,9 @@ static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_inf
256256
* extent_clear_unlock_delalloc() for compression path.
257257
*
258258
* This @locked_page is locked by plain lock_page(), thus its
259-
* subpage::writers is 0. Handle them in a special way.
259+
* subpage::locked is 0. Handle them in a special way.
260260
*/
261-
if (atomic_read(&subpage->writers) == 0) {
261+
if (atomic_read(&subpage->nr_locked) == 0) {
262262
spin_unlock_irqrestore(&subpage->lock, flags);
263263
return true;
264264
}
@@ -267,8 +267,8 @@ static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_inf
267267
clear_bit(bit, subpage->bitmaps);
268268
cleared++;
269269
}
270-
ASSERT(atomic_read(&subpage->writers) >= cleared);
271-
last = atomic_sub_and_test(cleared, &subpage->writers);
270+
ASSERT(atomic_read(&subpage->nr_locked) >= cleared);
271+
last = atomic_sub_and_test(cleared, &subpage->nr_locked);
272272
spin_unlock_irqrestore(&subpage->lock, flags);
273273
return last;
274274
}
@@ -289,8 +289,8 @@ static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_inf
289289
* bitmap, reduce the writer lock number, and unlock the page if that's
290290
* the last locked range.
291291
*/
292-
void btrfs_folio_end_writer_lock(const struct btrfs_fs_info *fs_info,
293-
struct folio *folio, u64 start, u32 len)
292+
void btrfs_folio_end_lock(const struct btrfs_fs_info *fs_info,
293+
struct folio *folio, u64 start, u32 len)
294294
{
295295
struct btrfs_subpage *subpage = folio_get_private(folio);
296296

@@ -303,24 +303,24 @@ void btrfs_folio_end_writer_lock(const struct btrfs_fs_info *fs_info,
303303

304304
/*
305305
* For subpage case, there are two types of locked page. With or
306-
* without writers number.
306+
* without locked number.
307307
*
308-
* Since we own the page lock, no one else could touch subpage::writers
308+
* Since we own the page lock, no one else could touch subpage::locked
309309
* and we are safe to do several atomic operations without spinlock.
310310
*/
311-
if (atomic_read(&subpage->writers) == 0) {
312-
/* No writers, locked by plain lock_page(). */
311+
if (atomic_read(&subpage->nr_locked) == 0) {
312+
/* No subpage lock, locked by plain lock_page(). */
313313
folio_unlock(folio);
314314
return;
315315
}
316316

317317
btrfs_subpage_clamp_range(folio, &start, &len);
318-
if (btrfs_subpage_end_and_test_writer(fs_info, folio, start, len))
318+
if (btrfs_subpage_end_and_test_lock(fs_info, folio, start, len))
319319
folio_unlock(folio);
320320
}
321321

322-
void btrfs_folio_end_writer_lock_bitmap(const struct btrfs_fs_info *fs_info,
323-
struct folio *folio, unsigned long bitmap)
322+
void btrfs_folio_end_lock_bitmap(const struct btrfs_fs_info *fs_info,
323+
struct folio *folio, unsigned long bitmap)
324324
{
325325
struct btrfs_subpage *subpage = folio_get_private(folio);
326326
const int start_bit = fs_info->sectors_per_page * btrfs_bitmap_nr_locked;
@@ -334,8 +334,8 @@ void btrfs_folio_end_writer_lock_bitmap(const struct btrfs_fs_info *fs_info,
334334
return;
335335
}
336336

337-
if (atomic_read(&subpage->writers) == 0) {
338-
/* No writers, locked by plain lock_page(). */
337+
if (atomic_read(&subpage->nr_locked) == 0) {
338+
/* No subpage lock, locked by plain lock_page(). */
339339
folio_unlock(folio);
340340
return;
341341
}
@@ -345,8 +345,8 @@ void btrfs_folio_end_writer_lock_bitmap(const struct btrfs_fs_info *fs_info,
345345
if (test_and_clear_bit(bit + start_bit, subpage->bitmaps))
346346
cleared++;
347347
}
348-
ASSERT(atomic_read(&subpage->writers) >= cleared);
349-
last = atomic_sub_and_test(cleared, &subpage->writers);
348+
ASSERT(atomic_read(&subpage->nr_locked) >= cleared);
349+
last = atomic_sub_and_test(cleared, &subpage->nr_locked);
350350
spin_unlock_irqrestore(&subpage->lock, flags);
351351
if (last)
352352
folio_unlock(folio);
@@ -671,8 +671,8 @@ void btrfs_folio_assert_not_dirty(const struct btrfs_fs_info *fs_info,
671671
* This populates the involved subpage ranges so that subpage helpers can
672672
* properly unlock them.
673673
*/
674-
void btrfs_folio_set_writer_lock(const struct btrfs_fs_info *fs_info,
675-
struct folio *folio, u64 start, u32 len)
674+
void btrfs_folio_set_lock(const struct btrfs_fs_info *fs_info,
675+
struct folio *folio, u64 start, u32 len)
676676
{
677677
struct btrfs_subpage *subpage;
678678
unsigned long flags;
@@ -691,7 +691,7 @@ void btrfs_folio_set_writer_lock(const struct btrfs_fs_info *fs_info,
691691
/* Target range should not yet be locked. */
692692
ASSERT(bitmap_test_range_all_zero(subpage->bitmaps, start_bit, nbits));
693693
bitmap_set(subpage->bitmaps, start_bit, nbits);
694-
ret = atomic_add_return(nbits, &subpage->writers);
694+
ret = atomic_add_return(nbits, &subpage->nr_locked);
695695
ASSERT(ret <= fs_info->sectors_per_page);
696696
spin_unlock_irqrestore(&subpage->lock, flags);
697697
}

fs/btrfs/subpage.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ struct btrfs_subpage {
5454
*/
5555
atomic_t eb_refs;
5656

57-
/* Structures only used by data */
58-
atomic_t writers;
57+
/*
58+
* Structures only used by data,
59+
*
60+
* How many sectors inside the page is locked.
61+
*/
62+
atomic_t nr_locked;
5963
};
6064
unsigned long bitmaps[];
6165
};
@@ -87,12 +91,12 @@ void btrfs_free_subpage(struct btrfs_subpage *subpage);
8791
void btrfs_folio_inc_eb_refs(const struct btrfs_fs_info *fs_info, struct folio *folio);
8892
void btrfs_folio_dec_eb_refs(const struct btrfs_fs_info *fs_info, struct folio *folio);
8993

90-
void btrfs_folio_end_writer_lock(const struct btrfs_fs_info *fs_info,
91-
struct folio *folio, u64 start, u32 len);
92-
void btrfs_folio_set_writer_lock(const struct btrfs_fs_info *fs_info,
93-
struct folio *folio, u64 start, u32 len);
94-
void btrfs_folio_end_writer_lock_bitmap(const struct btrfs_fs_info *fs_info,
95-
struct folio *folio, unsigned long bitmap);
94+
void btrfs_folio_end_lock(const struct btrfs_fs_info *fs_info,
95+
struct folio *folio, u64 start, u32 len);
96+
void btrfs_folio_set_lock(const struct btrfs_fs_info *fs_info,
97+
struct folio *folio, u64 start, u32 len);
98+
void btrfs_folio_end_lock_bitmap(const struct btrfs_fs_info *fs_info,
99+
struct folio *folio, unsigned long bitmap);
96100
/*
97101
* Template for subpage related operations.
98102
*

0 commit comments

Comments
 (0)