Skip to content

Commit 9180ad2

Browse files
author
Kent Overstreet
committed
bcachefs: Kill btree_iter.trans
This was planned to be done ages ago, now finally completed; there are places where we have quite a few btree_trans objects on the stack, so this reduces stack usage somewhat. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 1c8f458 commit 9180ad2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+405
-402
lines changed

fs/bcachefs/acl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ struct posix_acl *bch2_get_acl(struct inode *vinode, int type, bool rcu)
273273
struct bch_fs *c = inode->v.i_sb->s_fs_info;
274274
struct bch_hash_info hash = bch2_hash_info_init(c, &inode->ei_inode);
275275
struct xattr_search_key search = X_SEARCH(acl_to_xattr_type(type), "", 0);
276-
struct btree_iter iter = { NULL };
276+
struct btree_iter iter = {};
277277
struct posix_acl *acl = NULL;
278278

279279
if (rcu)
@@ -344,7 +344,7 @@ int bch2_set_acl(struct mnt_idmap *idmap,
344344
{
345345
struct bch_inode_info *inode = to_bch_ei(dentry->d_inode);
346346
struct bch_fs *c = inode->v.i_sb->s_fs_info;
347-
struct btree_iter inode_iter = { NULL };
347+
struct btree_iter inode_iter = {};
348348
struct bch_inode_unpacked inode_u;
349349
struct posix_acl *acl;
350350
umode_t mode;

fs/bcachefs/alloc_background.c

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ int bch2_alloc_read(struct bch_fs *c)
610610
* bch2_check_alloc_key() which runs later:
611611
*/
612612
if (!ca) {
613-
bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode + 1, 0));
613+
bch2_btree_iter_set_pos(trans, &iter, POS(k.k->p.inode + 1, 0));
614614
continue;
615615
}
616616

@@ -631,17 +631,17 @@ int bch2_alloc_read(struct bch_fs *c)
631631
* bch2_check_alloc_key() which runs later:
632632
*/
633633
if (!ca) {
634-
bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode + 1, 0));
634+
bch2_btree_iter_set_pos(trans, &iter, POS(k.k->p.inode + 1, 0));
635635
continue;
636636
}
637637

638638
if (k.k->p.offset < ca->mi.first_bucket) {
639-
bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode, ca->mi.first_bucket));
639+
bch2_btree_iter_set_pos(trans, &iter, POS(k.k->p.inode, ca->mi.first_bucket));
640640
continue;
641641
}
642642

643643
if (k.k->p.offset >= ca->mi.nbuckets) {
644-
bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode + 1, 0));
644+
bch2_btree_iter_set_pos(trans, &iter, POS(k.k->p.inode + 1, 0));
645645
continue;
646646
}
647647

@@ -1039,9 +1039,10 @@ int bch2_trigger_alloc(struct btree_trans *trans,
10391039
* This synthesizes deleted extents for holes, similar to BTREE_ITER_slots for
10401040
* extents style btrees, but works on non-extents btrees:
10411041
*/
1042-
static struct bkey_s_c bch2_get_key_or_hole(struct btree_iter *iter, struct bpos end, struct bkey *hole)
1042+
static struct bkey_s_c bch2_get_key_or_hole(struct btree_trans *trans, struct btree_iter *iter,
1043+
struct bpos end, struct bkey *hole)
10431044
{
1044-
struct bkey_s_c k = bch2_btree_iter_peek_slot(iter);
1045+
struct bkey_s_c k = bch2_btree_iter_peek_slot(trans, iter);
10451046

10461047
if (bkey_err(k))
10471048
return k;
@@ -1052,9 +1053,9 @@ static struct bkey_s_c bch2_get_key_or_hole(struct btree_iter *iter, struct bpos
10521053
struct btree_iter iter2;
10531054
struct bpos next;
10541055

1055-
bch2_trans_copy_iter(&iter2, iter);
1056+
bch2_trans_copy_iter(trans, &iter2, iter);
10561057

1057-
struct btree_path *path = btree_iter_path(iter->trans, iter);
1058+
struct btree_path *path = btree_iter_path(trans, iter);
10581059
if (!bpos_eq(path->l[0].b->key.k.p, SPOS_MAX))
10591060
end = bkey_min(end, bpos_nosnap_successor(path->l[0].b->key.k.p));
10601061

@@ -1064,9 +1065,9 @@ static struct bkey_s_c bch2_get_key_or_hole(struct btree_iter *iter, struct bpos
10641065
* btree node min/max is a closed interval, upto takes a half
10651066
* open interval:
10661067
*/
1067-
k = bch2_btree_iter_peek_max(&iter2, end);
1068+
k = bch2_btree_iter_peek_max(trans, &iter2, end);
10681069
next = iter2.pos;
1069-
bch2_trans_iter_exit(iter->trans, &iter2);
1070+
bch2_trans_iter_exit(trans, &iter2);
10701071

10711072
BUG_ON(next.offset >= iter->pos.offset + U32_MAX);
10721073

@@ -1107,13 +1108,14 @@ static bool next_bucket(struct bch_fs *c, struct bch_dev **ca, struct bpos *buck
11071108
return *ca != NULL;
11081109
}
11091110

1110-
static struct bkey_s_c bch2_get_key_or_real_bucket_hole(struct btree_iter *iter,
1111-
struct bch_dev **ca, struct bkey *hole)
1111+
static struct bkey_s_c bch2_get_key_or_real_bucket_hole(struct btree_trans *trans,
1112+
struct btree_iter *iter,
1113+
struct bch_dev **ca, struct bkey *hole)
11121114
{
1113-
struct bch_fs *c = iter->trans->c;
1115+
struct bch_fs *c = trans->c;
11141116
struct bkey_s_c k;
11151117
again:
1116-
k = bch2_get_key_or_hole(iter, POS_MAX, hole);
1118+
k = bch2_get_key_or_hole(trans, iter, POS_MAX, hole);
11171119
if (bkey_err(k))
11181120
return k;
11191121

@@ -1126,7 +1128,7 @@ static struct bkey_s_c bch2_get_key_or_real_bucket_hole(struct btree_iter *iter,
11261128
if (!next_bucket(c, ca, &hole_start))
11271129
return bkey_s_c_null;
11281130

1129-
bch2_btree_iter_set_pos(iter, hole_start);
1131+
bch2_btree_iter_set_pos(trans, iter, hole_start);
11301132
goto again;
11311133
}
11321134

@@ -1167,8 +1169,8 @@ int bch2_check_alloc_key(struct btree_trans *trans,
11671169

11681170
a = bch2_alloc_to_v4(alloc_k, &a_convert);
11691171

1170-
bch2_btree_iter_set_pos(discard_iter, alloc_k.k->p);
1171-
k = bch2_btree_iter_peek_slot(discard_iter);
1172+
bch2_btree_iter_set_pos(trans, discard_iter, alloc_k.k->p);
1173+
k = bch2_btree_iter_peek_slot(trans, discard_iter);
11721174
ret = bkey_err(k);
11731175
if (ret)
11741176
goto err;
@@ -1181,8 +1183,8 @@ int bch2_check_alloc_key(struct btree_trans *trans,
11811183
goto err;
11821184
}
11831185

1184-
bch2_btree_iter_set_pos(freespace_iter, alloc_freespace_pos(alloc_k.k->p, *a));
1185-
k = bch2_btree_iter_peek_slot(freespace_iter);
1186+
bch2_btree_iter_set_pos(trans, freespace_iter, alloc_freespace_pos(alloc_k.k->p, *a));
1187+
k = bch2_btree_iter_peek_slot(trans, freespace_iter);
11861188
ret = bkey_err(k);
11871189
if (ret)
11881190
goto err;
@@ -1195,8 +1197,8 @@ int bch2_check_alloc_key(struct btree_trans *trans,
11951197
goto err;
11961198
}
11971199

1198-
bch2_btree_iter_set_pos(bucket_gens_iter, alloc_gens_pos(alloc_k.k->p, &gens_offset));
1199-
k = bch2_btree_iter_peek_slot(bucket_gens_iter);
1200+
bch2_btree_iter_set_pos(trans, bucket_gens_iter, alloc_gens_pos(alloc_k.k->p, &gens_offset));
1201+
k = bch2_btree_iter_peek_slot(trans, bucket_gens_iter);
12001202
ret = bkey_err(k);
12011203
if (ret)
12021204
goto err;
@@ -1249,9 +1251,9 @@ int bch2_check_alloc_hole_freespace(struct btree_trans *trans,
12491251
if (!ca->mi.freespace_initialized)
12501252
return 0;
12511253

1252-
bch2_btree_iter_set_pos(freespace_iter, start);
1254+
bch2_btree_iter_set_pos(trans, freespace_iter, start);
12531255

1254-
k = bch2_btree_iter_peek_slot(freespace_iter);
1256+
k = bch2_btree_iter_peek_slot(trans, freespace_iter);
12551257
ret = bkey_err(k);
12561258
if (ret)
12571259
goto err;
@@ -1300,9 +1302,9 @@ int bch2_check_alloc_hole_bucket_gens(struct btree_trans *trans,
13001302
unsigned i, gens_offset, gens_end_offset;
13011303
int ret;
13021304

1303-
bch2_btree_iter_set_pos(bucket_gens_iter, alloc_gens_pos(start, &gens_offset));
1305+
bch2_btree_iter_set_pos(trans, bucket_gens_iter, alloc_gens_pos(start, &gens_offset));
13041306

1305-
k = bch2_btree_iter_peek_slot(bucket_gens_iter);
1307+
k = bch2_btree_iter_peek_slot(trans, bucket_gens_iter);
13061308
ret = bkey_err(k);
13071309
if (ret)
13081310
goto err;
@@ -1435,7 +1437,7 @@ int bch2_check_discard_freespace_key(struct btree_trans *trans, struct btree_ite
14351437
*gen = a->gen;
14361438
out:
14371439
fsck_err:
1438-
bch2_set_btree_iter_dontneed(&alloc_iter);
1440+
bch2_set_btree_iter_dontneed(trans, &alloc_iter);
14391441
bch2_trans_iter_exit(trans, &alloc_iter);
14401442
printbuf_exit(&buf);
14411443
return ret;
@@ -1572,7 +1574,7 @@ int bch2_check_alloc_info(struct bch_fs *c)
15721574

15731575
bch2_trans_begin(trans);
15741576

1575-
k = bch2_get_key_or_real_bucket_hole(&iter, &ca, &hole);
1577+
k = bch2_get_key_or_real_bucket_hole(trans, &iter, &ca, &hole);
15761578
ret = bkey_err(k);
15771579
if (ret)
15781580
goto bkey_err;
@@ -1610,7 +1612,7 @@ int bch2_check_alloc_info(struct bch_fs *c)
16101612
if (ret)
16111613
goto bkey_err;
16121614

1613-
bch2_btree_iter_set_pos(&iter, next);
1615+
bch2_btree_iter_set_pos(trans, &iter, next);
16141616
bkey_err:
16151617
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
16161618
continue;
@@ -1638,7 +1640,7 @@ int bch2_check_alloc_info(struct bch_fs *c)
16381640
BTREE_ITER_prefetch);
16391641
while (1) {
16401642
bch2_trans_begin(trans);
1641-
k = bch2_btree_iter_peek(&iter);
1643+
k = bch2_btree_iter_peek(trans, &iter);
16421644
if (!k.k)
16431645
break;
16441646

@@ -1657,7 +1659,7 @@ int bch2_check_alloc_info(struct bch_fs *c)
16571659
break;
16581660
}
16591661

1660-
bch2_btree_iter_set_pos(&iter, bpos_nosnap_successor(iter.pos));
1662+
bch2_btree_iter_set_pos(trans, &iter, bpos_nosnap_successor(iter.pos));
16611663
}
16621664
bch2_trans_iter_exit(trans, &iter);
16631665
if (ret)
@@ -1685,7 +1687,7 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
16851687
struct printbuf buf = PRINTBUF;
16861688
int ret;
16871689

1688-
alloc_k = bch2_btree_iter_peek(alloc_iter);
1690+
alloc_k = bch2_btree_iter_peek(trans, alloc_iter);
16891691
if (!alloc_k.k)
16901692
return 0;
16911693

@@ -1826,7 +1828,7 @@ static int bch2_discard_one_bucket(struct btree_trans *trans,
18261828
{
18271829
struct bch_fs *c = trans->c;
18281830
struct bpos pos = need_discard_iter->pos;
1829-
struct btree_iter iter = { NULL };
1831+
struct btree_iter iter = {};
18301832
struct bkey_s_c k;
18311833
struct bkey_i_alloc_v4 *a;
18321834
struct printbuf buf = PRINTBUF;
@@ -2199,9 +2201,9 @@ static struct bkey_s_c next_lru_key(struct btree_trans *trans, struct btree_iter
21992201
{
22002202
struct bkey_s_c k;
22012203
again:
2202-
k = bch2_btree_iter_peek_max(iter, lru_pos(ca->dev_idx, U64_MAX, LRU_TIME_MAX));
2204+
k = bch2_btree_iter_peek_max(trans, iter, lru_pos(ca->dev_idx, U64_MAX, LRU_TIME_MAX));
22032205
if (!k.k && !*wrapped) {
2204-
bch2_btree_iter_set_pos(iter, lru_pos(ca->dev_idx, 0, 0));
2206+
bch2_btree_iter_set_pos(trans, iter, lru_pos(ca->dev_idx, 0, 0));
22052207
*wrapped = true;
22062208
goto again;
22072209
}
@@ -2251,7 +2253,7 @@ static void bch2_do_invalidates_work(struct work_struct *work)
22512253
if (ret)
22522254
break;
22532255

2254-
bch2_btree_iter_advance(&iter);
2256+
bch2_btree_iter_advance(trans, &iter);
22552257
}
22562258
bch2_trans_iter_exit(trans, &iter);
22572259
err:
@@ -2321,7 +2323,7 @@ int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca,
23212323
break;
23222324
}
23232325

2324-
k = bch2_get_key_or_hole(&iter, end, &hole);
2326+
k = bch2_get_key_or_hole(trans, &iter, end, &hole);
23252327
ret = bkey_err(k);
23262328
if (ret)
23272329
goto bkey_err;
@@ -2340,7 +2342,7 @@ int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca,
23402342
if (ret)
23412343
goto bkey_err;
23422344

2343-
bch2_btree_iter_advance(&iter);
2345+
bch2_btree_iter_advance(trans, &iter);
23442346
} else {
23452347
struct bkey_i *freespace;
23462348

@@ -2360,7 +2362,7 @@ int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca,
23602362
if (ret)
23612363
goto bkey_err;
23622364

2363-
bch2_btree_iter_set_pos(&iter, k.k->p);
2365+
bch2_btree_iter_set_pos(trans, &iter, k.k->p);
23642366
}
23652367
bkey_err:
23662368
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))

fs/bcachefs/alloc_foreground.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ bch2_bucket_alloc_early(struct btree_trans *trans,
327327
bucket = sector_to_bucket(ca,
328328
round_up(bucket_to_sector(ca, bucket) + 1,
329329
1ULL << ca->mi.btree_bitmap_shift));
330-
bch2_btree_iter_set_pos(&iter, POS(ca->dev_idx, bucket));
330+
bch2_btree_iter_set_pos(trans, &iter, POS(ca->dev_idx, bucket));
331331
s->buckets_seen++;
332332
s->skipped_mi_btree_bitmap++;
333333
continue;
@@ -355,7 +355,7 @@ bch2_bucket_alloc_early(struct btree_trans *trans,
355355
watermark, s, cl)
356356
: NULL;
357357
next:
358-
bch2_set_btree_iter_dontneed(&citer);
358+
bch2_set_btree_iter_dontneed(trans, &citer);
359359
bch2_trans_iter_exit(trans, &citer);
360360
if (ob)
361361
break;
@@ -417,7 +417,7 @@ static struct open_bucket *bch2_bucket_alloc_freelist(struct btree_trans *trans,
417417
1ULL << ca->mi.btree_bitmap_shift));
418418
alloc_cursor = bucket|(iter.pos.offset & (~0ULL << 56));
419419

420-
bch2_btree_iter_set_pos(&iter, POS(ca->dev_idx, alloc_cursor));
420+
bch2_btree_iter_set_pos(trans, &iter, POS(ca->dev_idx, alloc_cursor));
421421
s->skipped_mi_btree_bitmap++;
422422
goto next;
423423
}
@@ -426,7 +426,7 @@ static struct open_bucket *bch2_bucket_alloc_freelist(struct btree_trans *trans,
426426
if (ob) {
427427
if (!IS_ERR(ob))
428428
*dev_alloc_cursor = iter.pos.offset;
429-
bch2_set_btree_iter_dontneed(&iter);
429+
bch2_set_btree_iter_dontneed(trans, &iter);
430430
break;
431431
}
432432

fs/bcachefs/backpointers.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ struct bkey_s_c bch2_backpointer_get_key(struct btree_trans *trans,
252252
0,
253253
bp.v->level,
254254
iter_flags);
255-
struct bkey_s_c k = bch2_btree_iter_peek_slot(iter);
255+
struct bkey_s_c k = bch2_btree_iter_peek_slot(trans, iter);
256256
if (bkey_err(k)) {
257257
bch2_trans_iter_exit(trans, iter);
258258
return k;
@@ -293,7 +293,7 @@ struct btree *bch2_backpointer_get_node(struct btree_trans *trans,
293293
0,
294294
bp.v->level - 1,
295295
0);
296-
struct btree *b = bch2_btree_iter_peek_node(iter);
296+
struct btree *b = bch2_btree_iter_peek_node(trans, iter);
297297
if (IS_ERR_OR_NULL(b))
298298
goto err;
299299

@@ -321,7 +321,7 @@ static int bch2_check_backpointer_has_valid_bucket(struct btree_trans *trans, st
321321
return 0;
322322

323323
struct bch_fs *c = trans->c;
324-
struct btree_iter alloc_iter = { NULL };
324+
struct btree_iter alloc_iter = {};
325325
struct bkey_s_c alloc_k;
326326
struct printbuf buf = PRINTBUF;
327327
int ret = 0;
@@ -650,7 +650,7 @@ static int check_btree_root_to_backpointers(struct btree_trans *trans,
650650
retry:
651651
bch2_trans_node_iter_init(trans, &iter, btree_id, POS_MIN,
652652
0, bch2_btree_id_root(c, btree_id)->b->c.level, 0);
653-
b = bch2_btree_iter_peek_node(&iter);
653+
b = bch2_btree_iter_peek_node(trans, &iter);
654654
ret = PTR_ERR_OR_ZERO(b);
655655
if (ret)
656656
goto err;
@@ -934,7 +934,7 @@ static int btree_node_get_and_pin(struct btree_trans *trans, struct bkey_i *k,
934934
{
935935
struct btree_iter iter;
936936
bch2_trans_node_iter_init(trans, &iter, btree, k->k.p, 0, level, 0);
937-
struct btree *b = bch2_btree_iter_peek_node(&iter);
937+
struct btree *b = bch2_btree_iter_peek_node(trans, &iter);
938938
int ret = PTR_ERR_OR_ZERO(b);
939939
if (ret)
940940
goto err;

fs/bcachefs/btree_gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static int bch2_gc_btree(struct btree_trans *trans,
691691
struct btree_iter iter;
692692
bch2_trans_node_iter_init(trans, &iter, btree, POS_MIN,
693693
0, bch2_btree_id_root(c, btree)->b->c.level, 0);
694-
struct btree *b = bch2_btree_iter_peek_node(&iter);
694+
struct btree *b = bch2_btree_iter_peek_node(trans, &iter);
695695
ret = PTR_ERR_OR_ZERO(b);
696696
if (ret)
697697
goto err_root;
@@ -1199,7 +1199,7 @@ int bch2_gc_gens(struct bch_fs *c)
11991199
BCH_TRANS_COMMIT_no_enospc, ({
12001200
ca = bch2_dev_iterate(c, ca, k.k->p.inode);
12011201
if (!ca) {
1202-
bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode + 1, 0));
1202+
bch2_btree_iter_set_pos(trans, &iter, POS(k.k->p.inode + 1, 0));
12031203
continue;
12041204
}
12051205
bch2_alloc_write_oldest_gen(trans, ca, &iter, k);

fs/bcachefs/btree_io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,8 @@ static void btree_node_scrub_work(struct work_struct *work)
19091909
scrub->key.k->k.p, 0, scrub->level - 1, 0);
19101910

19111911
struct btree *b;
1912-
int ret = lockrestart_do(trans, PTR_ERR_OR_ZERO(b = bch2_btree_iter_peek_node(&iter)));
1912+
int ret = lockrestart_do(trans,
1913+
PTR_ERR_OR_ZERO(b = bch2_btree_iter_peek_node(trans, &iter)));
19131914
if (ret)
19141915
goto err;
19151916

0 commit comments

Comments
 (0)