Skip to content

Commit

Permalink
fs: rename buffer trylock
Browse files Browse the repository at this point in the history
Like the page lock change, this also requires name change, so convert the
raw test_and_set bitop to a trylock.

Signed-off-by: Nick Piggin <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Nick Piggin authored and torvalds committed Aug 5, 2008
1 parent 529ae9a commit ca5de40
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions fs/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ static int __block_write_full_page(struct inode *inode, struct page *page,
*/
if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) {
lock_buffer(bh);
} else if (test_set_buffer_locked(bh)) {
} else if (!trylock_buffer(bh)) {
redirty_page_for_writepage(wbc, page);
continue;
}
Expand Down Expand Up @@ -3000,7 +3000,7 @@ void ll_rw_block(int rw, int nr, struct buffer_head *bhs[])

if (rw == SWRITE || rw == SWRITE_SYNC)
lock_buffer(bh);
else if (test_set_buffer_locked(bh))
else if (!trylock_buffer(bh))
continue;

if (rw == WRITE || rw == SWRITE || rw == SWRITE_SYNC) {
Expand Down
2 changes: 1 addition & 1 deletion fs/jbd/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static int journal_submit_data_buffers(journal_t *journal,
* blocking lock_buffer().
*/
if (buffer_dirty(bh)) {
if (test_set_buffer_locked(bh)) {
if (!trylock_buffer(bh)) {
BUFFER_TRACE(bh, "needs blocking lock");
spin_unlock(&journal->j_list_lock);
/* Write out all data to prevent deadlocks */
Expand Down
2 changes: 1 addition & 1 deletion fs/ntfs/aops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ static int ntfs_write_mst_block(struct page *page,
tbh = bhs[i];
if (!tbh)
continue;
if (unlikely(test_set_buffer_locked(tbh)))
if (!trylock_buffer(tbh))
BUG();
/* The buffer dirty state is now irrelevant, just clean it. */
clear_buffer_dirty(tbh);
Expand Down
2 changes: 1 addition & 1 deletion fs/ntfs/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ int ntfs_read_compressed_block(struct page *page)
for (i = 0; i < nr_bhs; i++) {
struct buffer_head *tbh = bhs[i];

if (unlikely(test_set_buffer_locked(tbh)))
if (!trylock_buffer(tbh))
continue;
if (unlikely(buffer_uptodate(tbh))) {
unlock_buffer(tbh);
Expand Down
4 changes: 2 additions & 2 deletions fs/ntfs/mft.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ int ntfs_sync_mft_mirror(ntfs_volume *vol, const unsigned long mft_no,
for (i_bhs = 0; i_bhs < nr_bhs; i_bhs++) {
struct buffer_head *tbh = bhs[i_bhs];

if (unlikely(test_set_buffer_locked(tbh)))
if (!trylock_buffer(tbh))
BUG();
BUG_ON(!buffer_uptodate(tbh));
clear_buffer_dirty(tbh);
Expand Down Expand Up @@ -779,7 +779,7 @@ int write_mft_record_nolock(ntfs_inode *ni, MFT_RECORD *m, int sync)
for (i_bhs = 0; i_bhs < nr_bhs; i_bhs++) {
struct buffer_head *tbh = bhs[i_bhs];

if (unlikely(test_set_buffer_locked(tbh)))
if (!trylock_buffer(tbh))
BUG();
BUG_ON(!buffer_uptodate(tbh));
clear_buffer_dirty(tbh);
Expand Down
2 changes: 1 addition & 1 deletion fs/reiserfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2435,7 +2435,7 @@ static int reiserfs_write_full_page(struct page *page,
if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) {
lock_buffer(bh);
} else {
if (test_set_buffer_locked(bh)) {
if (!trylock_buffer(bh)) {
redirty_page_for_writepage(wbc, page);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions fs/reiserfs/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ static int write_ordered_buffers(spinlock_t * lock,
jh = JH_ENTRY(list->next);
bh = jh->bh;
get_bh(bh);
if (test_set_buffer_locked(bh)) {
if (!trylock_buffer(bh)) {
if (!buffer_dirty(bh)) {
list_move(&jh->list, &tmp);
goto loop_next;
Expand Down Expand Up @@ -3871,7 +3871,7 @@ int reiserfs_prepare_for_journal(struct super_block *p_s_sb,
{
PROC_INFO_INC(p_s_sb, journal.prepare);

if (test_set_buffer_locked(bh)) {
if (!trylock_buffer(bh)) {
if (!wait)
return 0;
lock_buffer(bh);
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/linux-2.6/xfs_aops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ xfs_page_state_convert(
* that we are writing into for the first time.
*/
type = IOMAP_NEW;
if (!test_and_set_bit(BH_Lock, &bh->b_state)) {
if (trylock_buffer(bh)) {
ASSERT(buffer_mapped(bh));
if (iomap_valid)
all_bh = 1;
Expand Down
8 changes: 6 additions & 2 deletions include/linux/buffer_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ BUFFER_FNS(Uptodate, uptodate)
BUFFER_FNS(Dirty, dirty)
TAS_BUFFER_FNS(Dirty, dirty)
BUFFER_FNS(Lock, locked)
TAS_BUFFER_FNS(Lock, locked)
BUFFER_FNS(Req, req)
TAS_BUFFER_FNS(Req, req)
BUFFER_FNS(Mapped, mapped)
Expand Down Expand Up @@ -321,10 +320,15 @@ static inline void wait_on_buffer(struct buffer_head *bh)
__wait_on_buffer(bh);
}

static inline int trylock_buffer(struct buffer_head *bh)
{
return likely(!test_and_set_bit(BH_Lock, &bh->b_state));
}

static inline void lock_buffer(struct buffer_head *bh)
{
might_sleep();
if (test_set_buffer_locked(bh))
if (!trylock_buffer(bh))
__lock_buffer(bh);
}

Expand Down

0 comments on commit ca5de40

Please sign in to comment.