Skip to content

Commit 5642aa8

Browse files
KAGA-KOKOSebastian Andrzej Siewior
authored andcommitted
fs: jbd/jbd2: Make state lock and journal head lock rt safe
bit_spin_locks break under RT. Based on a previous patch from Steven Rostedt <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> -- include/linux/buffer_head.h | 8 ++++++++ include/linux/jbd2.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
1 parent b73aee4 commit 5642aa8

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

include/linux/buffer_head.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ struct buffer_head {
7777
atomic_t b_count; /* users using this buffer_head */
7878
#ifdef CONFIG_PREEMPT_RT_BASE
7979
spinlock_t b_uptodate_lock;
80+
#if IS_ENABLED(CONFIG_JBD2)
81+
spinlock_t b_state_lock;
82+
spinlock_t b_journal_head_lock;
83+
#endif
8084
#endif
8185
};
8286

@@ -108,6 +112,10 @@ static inline void buffer_head_init_locks(struct buffer_head *bh)
108112
{
109113
#ifdef CONFIG_PREEMPT_RT_BASE
110114
spin_lock_init(&bh->b_uptodate_lock);
115+
#if IS_ENABLED(CONFIG_JBD2)
116+
spin_lock_init(&bh->b_state_lock);
117+
spin_lock_init(&bh->b_journal_head_lock);
118+
#endif
111119
#endif
112120
}
113121

include/linux/jbd2.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,32 +347,56 @@ static inline struct journal_head *bh2jh(struct buffer_head *bh)
347347

348348
static inline void jbd_lock_bh_state(struct buffer_head *bh)
349349
{
350+
#ifndef CONFIG_PREEMPT_RT_BASE
350351
bit_spin_lock(BH_State, &bh->b_state);
352+
#else
353+
spin_lock(&bh->b_state_lock);
354+
#endif
351355
}
352356

353357
static inline int jbd_trylock_bh_state(struct buffer_head *bh)
354358
{
359+
#ifndef CONFIG_PREEMPT_RT_BASE
355360
return bit_spin_trylock(BH_State, &bh->b_state);
361+
#else
362+
return spin_trylock(&bh->b_state_lock);
363+
#endif
356364
}
357365

358366
static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
359367
{
368+
#ifndef CONFIG_PREEMPT_RT_BASE
360369
return bit_spin_is_locked(BH_State, &bh->b_state);
370+
#else
371+
return spin_is_locked(&bh->b_state_lock);
372+
#endif
361373
}
362374

363375
static inline void jbd_unlock_bh_state(struct buffer_head *bh)
364376
{
377+
#ifndef CONFIG_PREEMPT_RT_BASE
365378
bit_spin_unlock(BH_State, &bh->b_state);
379+
#else
380+
spin_unlock(&bh->b_state_lock);
381+
#endif
366382
}
367383

368384
static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
369385
{
386+
#ifndef CONFIG_PREEMPT_RT_BASE
370387
bit_spin_lock(BH_JournalHead, &bh->b_state);
388+
#else
389+
spin_lock(&bh->b_journal_head_lock);
390+
#endif
371391
}
372392

373393
static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
374394
{
395+
#ifndef CONFIG_PREEMPT_RT_BASE
375396
bit_spin_unlock(BH_JournalHead, &bh->b_state);
397+
#else
398+
spin_unlock(&bh->b_journal_head_lock);
399+
#endif
376400
}
377401

378402
#define J_ASSERT(assert) BUG_ON(!(assert))

0 commit comments

Comments
 (0)