Skip to content

Commit 064a4a5

Browse files
committed
Merge tag 'bcachefs-2024-01-26' of https://evilpiepirate.org/git/bcachefs
Pull bcachefs fixes from Kent Overstreet: - fix for REQ_OP_FLUSH usage; this fixes filesystems going read only with -EOPNOTSUPP from the block layer. (this really should have gone in with the block layer patch causing the -EOPNOTSUPP, or should have gone in before). - fix an allocation in non-sleepable context - fix one source of srcu lock latency, on devices with terrible discard latency - fix a reattach_inode() issue in fsck * tag 'bcachefs-2024-01-26' of https://evilpiepirate.org/git/bcachefs: bcachefs: __lookup_dirent() works in snapshot, not subvol bcachefs: discard path uses unlock_long() bcachefs: fix incorrect usage of REQ_OP_FLUSH bcachefs: Add gfp flags param to bch2_prt_task_backtrace()
2 parents 8c6f6a7 + d2fda30 commit 064a4a5

File tree

10 files changed

+42
-32
lines changed

10 files changed

+42
-32
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ static int bch2_discard_one_bucket(struct btree_trans *trans,
17151715
* This works without any other locks because this is the only
17161716
* thread that removes items from the need_discard tree
17171717
*/
1718-
bch2_trans_unlock(trans);
1718+
bch2_trans_unlock_long(trans);
17191719
blkdev_issue_discard(ca->disk_sb.bdev,
17201720
k.k->p.offset * ca->mi.bucket_size,
17211721
ca->mi.bucket_size,

fs/bcachefs/btree_locking.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static noinline void print_cycle(struct printbuf *out, struct lock_graph *g)
9292
continue;
9393

9494
bch2_btree_trans_to_text(out, i->trans);
95-
bch2_prt_task_backtrace(out, task, i == g->g ? 5 : 1);
95+
bch2_prt_task_backtrace(out, task, i == g->g ? 5 : 1, GFP_NOWAIT);
9696
}
9797
}
9898

@@ -227,7 +227,7 @@ static noinline int break_cycle(struct lock_graph *g, struct printbuf *cycle)
227227
prt_printf(&buf, "backtrace:");
228228
prt_newline(&buf);
229229
printbuf_indent_add(&buf, 2);
230-
bch2_prt_task_backtrace(&buf, trans->locking_wait.task, 2);
230+
bch2_prt_task_backtrace(&buf, trans->locking_wait.task, 2, GFP_NOWAIT);
231231
printbuf_indent_sub(&buf, 2);
232232
prt_newline(&buf);
233233
}

fs/bcachefs/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static ssize_t bch2_btree_transactions_read(struct file *file, char __user *buf,
627627
prt_printf(&i->buf, "backtrace:");
628628
prt_newline(&i->buf);
629629
printbuf_indent_add(&i->buf, 2);
630-
bch2_prt_task_backtrace(&i->buf, task, 0);
630+
bch2_prt_task_backtrace(&i->buf, task, 0, GFP_KERNEL);
631631
printbuf_indent_sub(&i->buf, 2);
632632
prt_newline(&i->buf);
633633

fs/bcachefs/fs-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void bch2_inode_flush_nocow_writes_async(struct bch_fs *c,
7979
continue;
8080

8181
bio = container_of(bio_alloc_bioset(ca->disk_sb.bdev, 0,
82-
REQ_OP_FLUSH,
82+
REQ_OP_WRITE|REQ_PREFLUSH,
8383
GFP_KERNEL,
8484
&c->nocow_flush_bioset),
8585
struct nocow_flush, bio);

fs/bcachefs/fsck.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,19 @@ static int lookup_inode(struct btree_trans *trans, u64 inode_nr,
119119
if (!ret)
120120
*snapshot = iter.pos.snapshot;
121121
err:
122-
bch_err_msg(trans->c, ret, "fetching inode %llu:%u", inode_nr, *snapshot);
123122
bch2_trans_iter_exit(trans, &iter);
124123
return ret;
125124
}
126125

127-
static int __lookup_dirent(struct btree_trans *trans,
126+
static int lookup_dirent_in_snapshot(struct btree_trans *trans,
128127
struct bch_hash_info hash_info,
129128
subvol_inum dir, struct qstr *name,
130-
u64 *target, unsigned *type)
129+
u64 *target, unsigned *type, u32 snapshot)
131130
{
132131
struct btree_iter iter;
133132
struct bkey_s_c_dirent d;
134-
int ret;
135-
136-
ret = bch2_hash_lookup(trans, &iter, bch2_dirent_hash_desc,
137-
&hash_info, dir, name, 0);
133+
int ret = bch2_hash_lookup_in_snapshot(trans, &iter, bch2_dirent_hash_desc,
134+
&hash_info, dir, name, 0, snapshot);
138135
if (ret)
139136
return ret;
140137

@@ -225,15 +222,16 @@ static int lookup_lostfound(struct btree_trans *trans, u32 snapshot,
225222

226223
struct bch_inode_unpacked root_inode;
227224
struct bch_hash_info root_hash_info;
228-
ret = lookup_inode(trans, root_inum.inum, &root_inode, &snapshot);
225+
u32 root_inode_snapshot = snapshot;
226+
ret = lookup_inode(trans, root_inum.inum, &root_inode, &root_inode_snapshot);
229227
bch_err_msg(c, ret, "looking up root inode");
230228
if (ret)
231229
return ret;
232230

233231
root_hash_info = bch2_hash_info_init(c, &root_inode);
234232

235-
ret = __lookup_dirent(trans, root_hash_info, root_inum,
236-
&lostfound_str, &inum, &d_type);
233+
ret = lookup_dirent_in_snapshot(trans, root_hash_info, root_inum,
234+
&lostfound_str, &inum, &d_type, snapshot);
237235
if (bch2_err_matches(ret, ENOENT))
238236
goto create_lostfound;
239237

@@ -250,7 +248,10 @@ static int lookup_lostfound(struct btree_trans *trans, u32 snapshot,
250248
* The bch2_check_dirents pass has already run, dangling dirents
251249
* shouldn't exist here:
252250
*/
253-
return lookup_inode(trans, inum, lostfound, &snapshot);
251+
ret = lookup_inode(trans, inum, lostfound, &snapshot);
252+
bch_err_msg(c, ret, "looking up lost+found %llu:%u in (root inode %llu, snapshot root %u)",
253+
inum, snapshot, root_inum.inum, bch2_snapshot_root(c, snapshot));
254+
return ret;
254255

255256
create_lostfound:
256257
/*

fs/bcachefs/journal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static void __journal_entry_close(struct journal *j, unsigned closed_val, bool t
233233
prt_str(&pbuf, "entry size: ");
234234
prt_human_readable_u64(&pbuf, vstruct_bytes(buf->data));
235235
prt_newline(&pbuf);
236-
bch2_prt_task_backtrace(&pbuf, current, 1);
236+
bch2_prt_task_backtrace(&pbuf, current, 1, GFP_NOWAIT);
237237
trace_journal_entry_close(c, pbuf.buf);
238238
printbuf_exit(&pbuf);
239239
}

fs/bcachefs/journal_io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,8 @@ CLOSURE_CALLBACK(bch2_journal_write)
19881988
percpu_ref_get(&ca->io_ref);
19891989

19901990
bio = ca->journal.bio;
1991-
bio_reset(bio, ca->disk_sb.bdev, REQ_OP_FLUSH);
1991+
bio_reset(bio, ca->disk_sb.bdev,
1992+
REQ_OP_WRITE|REQ_PREFLUSH);
19921993
bio->bi_end_io = journal_write_endio;
19931994
bio->bi_private = ca;
19941995
closure_bio_submit(bio, cl);

fs/bcachefs/str_hash.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,16 @@ static inline bool is_visible_key(struct bch_hash_desc desc, subvol_inum inum, s
160160
}
161161

162162
static __always_inline int
163-
bch2_hash_lookup(struct btree_trans *trans,
163+
bch2_hash_lookup_in_snapshot(struct btree_trans *trans,
164164
struct btree_iter *iter,
165165
const struct bch_hash_desc desc,
166166
const struct bch_hash_info *info,
167167
subvol_inum inum, const void *key,
168-
unsigned flags)
168+
unsigned flags, u32 snapshot)
169169
{
170170
struct bkey_s_c k;
171-
u32 snapshot;
172171
int ret;
173172

174-
ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
175-
if (ret)
176-
return ret;
177-
178173
for_each_btree_key_upto_norestart(trans, *iter, desc.btree_id,
179174
SPOS(inum.inum, desc.hash_key(info, key), snapshot),
180175
POS(inum.inum, U64_MAX),
@@ -194,6 +189,19 @@ bch2_hash_lookup(struct btree_trans *trans,
194189
return ret ?: -BCH_ERR_ENOENT_str_hash_lookup;
195190
}
196191

192+
static __always_inline int
193+
bch2_hash_lookup(struct btree_trans *trans,
194+
struct btree_iter *iter,
195+
const struct bch_hash_desc desc,
196+
const struct bch_hash_info *info,
197+
subvol_inum inum, const void *key,
198+
unsigned flags)
199+
{
200+
u32 snapshot;
201+
return bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot) ?:
202+
bch2_hash_lookup_in_snapshot(trans, iter, desc, info, inum, key, flags, snapshot);
203+
}
204+
197205
static __always_inline int
198206
bch2_hash_hole(struct btree_trans *trans,
199207
struct btree_iter *iter,

fs/bcachefs/util.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@ void bch2_print_string_as_lines(const char *prefix, const char *lines)
272272
console_unlock();
273273
}
274274

275-
int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *task, unsigned skipnr)
275+
int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *task, unsigned skipnr,
276+
gfp_t gfp)
276277
{
277278
#ifdef CONFIG_STACKTRACE
278279
unsigned nr_entries = 0;
279-
int ret = 0;
280280

281281
stack->nr = 0;
282-
ret = darray_make_room(stack, 32);
282+
int ret = darray_make_room_gfp(stack, 32, gfp);
283283
if (ret)
284284
return ret;
285285

@@ -308,10 +308,10 @@ void bch2_prt_backtrace(struct printbuf *out, bch_stacktrace *stack)
308308
}
309309
}
310310

311-
int bch2_prt_task_backtrace(struct printbuf *out, struct task_struct *task, unsigned skipnr)
311+
int bch2_prt_task_backtrace(struct printbuf *out, struct task_struct *task, unsigned skipnr, gfp_t gfp)
312312
{
313313
bch_stacktrace stack = { 0 };
314-
int ret = bch2_save_backtrace(&stack, task, skipnr + 1);
314+
int ret = bch2_save_backtrace(&stack, task, skipnr + 1, gfp);
315315

316316
bch2_prt_backtrace(out, &stack);
317317
darray_exit(&stack);

fs/bcachefs/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ void bch2_prt_u64_base2(struct printbuf *, u64);
348348
void bch2_print_string_as_lines(const char *prefix, const char *lines);
349349

350350
typedef DARRAY(unsigned long) bch_stacktrace;
351-
int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *, unsigned);
351+
int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *, unsigned, gfp_t);
352352
void bch2_prt_backtrace(struct printbuf *, bch_stacktrace *);
353-
int bch2_prt_task_backtrace(struct printbuf *, struct task_struct *, unsigned);
353+
int bch2_prt_task_backtrace(struct printbuf *, struct task_struct *, unsigned, gfp_t);
354354

355355
static inline void prt_bdevname(struct printbuf *out, struct block_device *bdev)
356356
{

0 commit comments

Comments
 (0)