Skip to content

Commit fd80d14

Browse files
author
Kent Overstreet
committed
bcachefs: fix scheduling while atomic in break_cycle()
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 6f692b1 commit fd80d14

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

fs/bcachefs/btree_locking.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static noinline int break_cycle(struct lock_graph *g, struct printbuf *cycle)
231231
prt_newline(&buf);
232232
}
233233

234-
bch2_print_string_as_lines(KERN_ERR, buf.buf);
234+
bch2_print_string_as_lines_nonblocking(KERN_ERR, buf.buf);
235235
printbuf_exit(&buf);
236236
BUG();
237237
}

fs/bcachefs/util.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,24 +252,43 @@ void bch2_prt_u64_base2(struct printbuf *out, u64 v)
252252
bch2_prt_u64_base2_nbits(out, v, fls64(v) ?: 1);
253253
}
254254

255-
void bch2_print_string_as_lines(const char *prefix, const char *lines)
255+
static void __bch2_print_string_as_lines(const char *prefix, const char *lines,
256+
bool nonblocking)
256257
{
258+
bool locked = false;
257259
const char *p;
258260

259261
if (!lines) {
260262
printk("%s (null)\n", prefix);
261263
return;
262264
}
263265

264-
console_lock();
266+
if (!nonblocking) {
267+
console_lock();
268+
locked = true;
269+
} else {
270+
locked = console_trylock();
271+
}
272+
265273
while (1) {
266274
p = strchrnul(lines, '\n');
267275
printk("%s%.*s\n", prefix, (int) (p - lines), lines);
268276
if (!*p)
269277
break;
270278
lines = p + 1;
271279
}
272-
console_unlock();
280+
if (locked)
281+
console_unlock();
282+
}
283+
284+
void bch2_print_string_as_lines(const char *prefix, const char *lines)
285+
{
286+
return __bch2_print_string_as_lines(prefix, lines, false);
287+
}
288+
289+
void bch2_print_string_as_lines_nonblocking(const char *prefix, const char *lines)
290+
{
291+
return __bch2_print_string_as_lines(prefix, lines, true);
273292
}
274293

275294
int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *task, unsigned skipnr,

fs/bcachefs/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ void bch2_prt_u64_base2_nbits(struct printbuf *, u64, unsigned);
315315
void bch2_prt_u64_base2(struct printbuf *, u64);
316316

317317
void bch2_print_string_as_lines(const char *prefix, const char *lines);
318+
void bch2_print_string_as_lines_nonblocking(const char *prefix, const char *lines);
318319

319320
typedef DARRAY(unsigned long) bch_stacktrace;
320321
int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *, unsigned, gfp_t);

0 commit comments

Comments
 (0)