Skip to content

Commit a0d11fe

Browse files
author
Kent Overstreet
committed
bcachefs: Don't use commit_do() unnecessarily
Using commit_do() to call alloc_sectors_start_trans() breaks when we're randomly injecting transaction restarts - the restart in the commit causes us to leak the lock that alloc_sectorS_start_trans() takes. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 6bee2a0 commit a0d11fe

21 files changed

+41
-39
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ static void bch2_do_discards_fast_work(struct work_struct *work)
19771977
ca->mi.bucket_size,
19781978
GFP_KERNEL);
19791979

1980-
int ret = bch2_trans_do(c, NULL, NULL,
1980+
int ret = bch2_trans_commit_do(c, NULL, NULL,
19811981
BCH_WATERMARK_btree|
19821982
BCH_TRANS_COMMIT_no_enospc,
19831983
bch2_clear_bucket_needs_discard(trans, POS(ca->dev_idx, bucket)));

fs/bcachefs/alloc_foreground.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ struct open_bucket *bch2_bucket_alloc(struct bch_fs *c, struct bch_dev *ca,
684684
struct bch_dev_usage usage;
685685
struct open_bucket *ob;
686686

687-
bch2_trans_do(c, NULL, NULL, 0,
687+
bch2_trans_do(c,
688688
PTR_ERR_OR_ZERO(ob = bch2_bucket_alloc_trans(trans, ca, watermark,
689689
data_type, cl, false, &usage)));
690690
return ob;

fs/bcachefs/btree_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ static void btree_node_write_work(struct work_struct *work)
18711871

18721872
}
18731873
} else {
1874-
ret = bch2_trans_do(c, NULL, NULL, 0,
1874+
ret = bch2_trans_do(c,
18751875
bch2_btree_node_update_key_get_iter(trans, b, &wbio->key,
18761876
BCH_WATERMARK_interior_updates|
18771877
BCH_TRANS_COMMIT_journal_reclaim|

fs/bcachefs/btree_iter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,8 @@ struct bkey_s_c bch2_btree_iter_peek_and_restart_outlined(struct btree_iter *);
912912
_ret; \
913913
})
914914

915+
#define bch2_trans_do(_c, _do) bch2_trans_run(_c, lockrestart_do(trans, _do))
916+
915917
struct btree_trans *__bch2_trans_get(struct bch_fs *, unsigned);
916918
void bch2_trans_put(struct btree_trans *);
917919

fs/bcachefs/btree_update.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ int bch2_btree_insert(struct bch_fs *c, enum btree_id id, struct bkey_i *k,
668668
struct disk_reservation *disk_res, int flags,
669669
enum btree_iter_update_trigger_flags iter_flags)
670670
{
671-
return bch2_trans_do(c, disk_res, NULL, flags,
671+
return bch2_trans_commit_do(c, disk_res, NULL, flags,
672672
bch2_btree_insert_trans(trans, id, k, iter_flags));
673673
}
674674

@@ -865,7 +865,7 @@ __bch2_fs_log_msg(struct bch_fs *c, unsigned commit_flags, const char *fmt,
865865
memcpy(l->d, buf.buf, buf.pos);
866866
c->journal.early_journal_entries.nr += jset_u64s(u64s);
867867
} else {
868-
ret = bch2_trans_do(c, NULL, NULL,
868+
ret = bch2_trans_commit_do(c, NULL, NULL,
869869
BCH_TRANS_COMMIT_lazy_rw|commit_flags,
870870
__bch2_trans_log_msg(trans, &buf, u64s));
871871
}

fs/bcachefs/btree_update.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static inline int bch2_trans_commit(struct btree_trans *trans,
192192
nested_lockrestart_do(_trans, _do ?: bch2_trans_commit(_trans, (_disk_res),\
193193
(_journal_seq), (_flags)))
194194

195-
#define bch2_trans_do(_c, _disk_res, _journal_seq, _flags, _do) \
195+
#define bch2_trans_commit_do(_c, _disk_res, _journal_seq, _flags, _do) \
196196
bch2_trans_run(_c, commit_do(trans, _disk_res, _journal_seq, _flags, _do))
197197

198198
#define trans_for_each_update(_trans, _i) \

fs/bcachefs/btree_update_interior.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,10 +2239,8 @@ static void async_btree_node_rewrite_work(struct work_struct *work)
22392239
struct async_btree_rewrite *a =
22402240
container_of(work, struct async_btree_rewrite, work);
22412241
struct bch_fs *c = a->c;
2242-
int ret;
22432242

2244-
ret = bch2_trans_do(c, NULL, NULL, 0,
2245-
async_btree_node_rewrite_trans(trans, a));
2243+
int ret = bch2_trans_do(c, async_btree_node_rewrite_trans(trans, a));
22462244
bch_err_fn_ratelimited(c, ret);
22472245
bch2_write_ref_put(c, BCH_WRITE_REF_node_rewrite);
22482246
kfree(a);

fs/bcachefs/disk_accounting.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,10 @@ int bch2_dev_usage_init(struct bch_dev *ca, bool gc)
856856
};
857857
u64 v[3] = { ca->mi.nbuckets - ca->mi.first_bucket, 0, 0 };
858858

859-
int ret = bch2_trans_do(c, NULL, NULL, 0,
860-
bch2_disk_accounting_mod(trans, &acc, v, ARRAY_SIZE(v), gc));
859+
int ret = bch2_trans_do(c, ({
860+
bch2_disk_accounting_mod(trans, &acc, v, ARRAY_SIZE(v), gc) ?:
861+
(!gc ? bch2_trans_commit(trans, NULL, NULL, 0) : 0);
862+
}));
861863
bch_err_fn(c, ret);
862864
return ret;
863865
}

fs/bcachefs/ec.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ static void ec_stripe_delete_work(struct work_struct *work)
11861186
if (!idx)
11871187
break;
11881188

1189-
int ret = bch2_trans_do(c, NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
1189+
int ret = bch2_trans_commit_do(c, NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
11901190
ec_stripe_delete(trans, idx));
11911191
bch_err_fn(c, ret);
11921192
if (ret)
@@ -1519,14 +1519,14 @@ static void ec_stripe_create(struct ec_stripe_new *s)
15191519
goto err;
15201520
}
15211521

1522-
ret = bch2_trans_do(c, &s->res, NULL,
1523-
BCH_TRANS_COMMIT_no_check_rw|
1524-
BCH_TRANS_COMMIT_no_enospc,
1525-
ec_stripe_key_update(trans,
1526-
s->have_existing_stripe
1527-
? bkey_i_to_stripe(&s->existing_stripe.key)
1528-
: NULL,
1529-
bkey_i_to_stripe(&s->new_stripe.key)));
1522+
ret = bch2_trans_commit_do(c, &s->res, NULL,
1523+
BCH_TRANS_COMMIT_no_check_rw|
1524+
BCH_TRANS_COMMIT_no_enospc,
1525+
ec_stripe_key_update(trans,
1526+
s->have_existing_stripe
1527+
? bkey_i_to_stripe(&s->existing_stripe.key)
1528+
: NULL,
1529+
bkey_i_to_stripe(&s->new_stripe.key)));
15301530
bch_err_msg(c, ret, "creating stripe key");
15311531
if (ret) {
15321532
goto err;

fs/bcachefs/fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ static struct dentry *bch2_lookup(struct inode *vdir, struct dentry *dentry,
658658
struct bch_hash_info hash = bch2_hash_info_init(c, &dir->ei_inode);
659659

660660
struct bch_inode_info *inode;
661-
bch2_trans_do(c, NULL, NULL, 0,
661+
bch2_trans_do(c,
662662
PTR_ERR_OR_ZERO(inode = bch2_lookup_trans(trans, inode_inum(dir),
663663
&hash, &dentry->d_name)));
664664
if (IS_ERR(inode))

0 commit comments

Comments
 (0)