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

bcachefs: bch2_trans_update_get_key_cache()

Factor out a slowpath into a separate function.

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

+42 -29
+42 -29
fs/bcachefs/btree_update.c
··· 466 466 return 0; 467 467 } 468 468 469 + static noinline int bch2_trans_update_get_key_cache(struct btree_trans *trans, 470 + struct btree_iter *iter, 471 + struct btree_path *path) 472 + { 473 + if (!iter->key_cache_path || 474 + !iter->key_cache_path->should_be_locked || 475 + !bpos_eq(iter->key_cache_path->pos, iter->pos)) { 476 + struct bkey_cached *ck; 477 + int ret; 478 + 479 + if (!iter->key_cache_path) 480 + iter->key_cache_path = 481 + bch2_path_get(trans, path->btree_id, path->pos, 1, 0, 482 + BTREE_ITER_INTENT| 483 + BTREE_ITER_CACHED, _THIS_IP_); 484 + 485 + iter->key_cache_path = 486 + bch2_btree_path_set_pos(trans, iter->key_cache_path, path->pos, 487 + iter->flags & BTREE_ITER_INTENT, 488 + _THIS_IP_); 489 + 490 + ret = bch2_btree_path_traverse(trans, iter->key_cache_path, 491 + BTREE_ITER_CACHED); 492 + if (unlikely(ret)) 493 + return ret; 494 + 495 + ck = (void *) iter->key_cache_path->l[0].b; 496 + 497 + if (test_bit(BKEY_CACHED_DIRTY, &ck->flags)) { 498 + trace_and_count(trans->c, trans_restart_key_cache_raced, trans, _RET_IP_); 499 + return btree_trans_restart(trans, BCH_ERR_transaction_restart_key_cache_raced); 500 + } 501 + 502 + btree_path_set_should_be_locked(iter->key_cache_path); 503 + } 504 + 505 + return 0; 506 + } 507 + 469 508 int __must_check bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, 470 509 struct bkey_i *k, enum btree_update_flags flags) 471 510 { 472 511 struct btree_path *path = iter->update_path ?: iter->path; 473 - struct bkey_cached *ck; 474 512 int ret; 475 513 476 514 if (iter->flags & BTREE_ITER_IS_EXTENTS) ··· 532 494 !path->cached && 533 495 !path->level && 534 496 btree_id_cached(trans->c, path->btree_id)) { 535 - if (!iter->key_cache_path || 536 - !iter->key_cache_path->should_be_locked || 537 - !bpos_eq(iter->key_cache_path->pos, k->k.p)) { 538 - if (!iter->key_cache_path) 539 - iter->key_cache_path = 540 - bch2_path_get(trans, path->btree_id, path->pos, 1, 0, 541 - BTREE_ITER_INTENT| 542 - BTREE_ITER_CACHED, _THIS_IP_); 543 - 544 - iter->key_cache_path = 545 - bch2_btree_path_set_pos(trans, iter->key_cache_path, path->pos, 546 - iter->flags & BTREE_ITER_INTENT, 547 - _THIS_IP_); 548 - 549 - ret = bch2_btree_path_traverse(trans, iter->key_cache_path, 550 - BTREE_ITER_CACHED); 551 - if (unlikely(ret)) 552 - return ret; 553 - 554 - ck = (void *) iter->key_cache_path->l[0].b; 555 - 556 - if (test_bit(BKEY_CACHED_DIRTY, &ck->flags)) { 557 - trace_and_count(trans->c, trans_restart_key_cache_raced, trans, _RET_IP_); 558 - return btree_trans_restart(trans, BCH_ERR_transaction_restart_key_cache_raced); 559 - } 560 - 561 - btree_path_set_should_be_locked(iter->key_cache_path); 562 - } 497 + ret = bch2_trans_update_get_key_cache(trans, iter, path); 498 + if (ret) 499 + return ret; 563 500 564 501 path = iter->key_cache_path; 565 502 }