Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcachefs: Refactor bch2_check_alloc_to_lru_ref()

This code was somewhat convoluted - because originally bch2_lru_set()
could modify the LRU index if there was a collision.

That's no longer the case, so the "create LRU entry" path has no reason
to update the alloc key, so we can separate the handling of the two fsck
errors.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

+25 -29
+25 -29
fs/bcachefs/alloc_background.c
··· 1505 1505 if (a->data_type != BCH_DATA_cached) 1506 1506 return 0; 1507 1507 1508 + if (fsck_err_on(!a->io_time[READ], c, 1509 + alloc_key_cached_but_read_time_zero, 1510 + "cached bucket with read_time 0\n" 1511 + " %s", 1512 + (printbuf_reset(&buf), 1513 + bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) { 1514 + struct bkey_i_alloc_v4 *a_mut = 1515 + bch2_alloc_to_v4_mut(trans, alloc_k); 1516 + ret = PTR_ERR_OR_ZERO(a_mut); 1517 + if (ret) 1518 + goto err; 1519 + 1520 + a_mut->v.io_time[READ] = atomic64_read(&c->io_clock[READ].now); 1521 + ret = bch2_trans_update(trans, alloc_iter, 1522 + &a_mut->k_i, BTREE_TRIGGER_NORUN); 1523 + if (ret) 1524 + goto err; 1525 + 1526 + a = &a_mut->v; 1527 + } 1528 + 1508 1529 lru_k = bch2_bkey_get_iter(trans, &lru_iter, BTREE_ID_lru, 1509 1530 lru_pos(alloc_k.k->p.inode, 1510 1531 bucket_to_u64(alloc_k.k->p), ··· 1534 1513 if (ret) 1535 1514 return ret; 1536 1515 1537 - if (fsck_err_on(!a->io_time[READ], c, 1538 - alloc_key_cached_but_read_time_zero, 1539 - "cached bucket with read_time 0\n" 1540 - " %s", 1541 - (printbuf_reset(&buf), 1542 - bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf)) || 1543 - fsck_err_on(lru_k.k->type != KEY_TYPE_set, c, 1516 + if (fsck_err_on(lru_k.k->type != KEY_TYPE_set, c, 1544 1517 alloc_key_to_missing_lru_entry, 1545 1518 "missing lru entry\n" 1546 1519 " %s", 1547 1520 (printbuf_reset(&buf), 1548 1521 bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) { 1549 - u64 read_time = a->io_time[READ] ?: 1550 - atomic64_read(&c->io_clock[READ].now); 1551 - 1552 1522 ret = bch2_lru_set(trans, 1553 1523 alloc_k.k->p.inode, 1554 1524 bucket_to_u64(alloc_k.k->p), 1555 - read_time); 1525 + a->io_time[READ]); 1556 1526 if (ret) 1557 1527 goto err; 1558 - 1559 - if (a->io_time[READ] != read_time) { 1560 - struct bkey_i_alloc_v4 *a_mut = 1561 - bch2_alloc_to_v4_mut(trans, alloc_k); 1562 - ret = PTR_ERR_OR_ZERO(a_mut); 1563 - if (ret) 1564 - goto err; 1565 - 1566 - a_mut->v.io_time[READ] = read_time; 1567 - ret = bch2_trans_update(trans, alloc_iter, 1568 - &a_mut->k_i, BTREE_TRIGGER_NORUN); 1569 - if (ret) 1570 - goto err; 1571 - } 1572 1528 } 1573 1529 err: 1574 1530 fsck_err: ··· 1558 1560 { 1559 1561 struct btree_iter iter; 1560 1562 struct bkey_s_c k; 1561 - int ret = 0; 1562 1563 1563 - ret = bch2_trans_run(c, 1564 + int ret = bch2_trans_run(c, 1564 1565 for_each_btree_key_commit(trans, iter, BTREE_ID_alloc, 1565 1566 POS_MIN, BTREE_ITER_PREFETCH, k, 1566 1567 NULL, NULL, BCH_TRANS_COMMIT_no_enospc|BCH_TRANS_COMMIT_lazy_rw, 1567 1568 bch2_check_alloc_to_lru_ref(trans, &iter))); 1568 - if (ret) 1569 - bch_err_fn(c, ret); 1569 + bch_err_fn(c, ret); 1570 1570 return ret; 1571 1571 } 1572 1572