From 6b043a7ce7c0ac6b4de38b04911ab6e4e79aa28a Mon Sep 17 00:00:00 2001 From: Matan Breizman Date: Sun, 6 Nov 2022 13:28:27 +0000 Subject: [PATCH] crimson/osd/object_context_loader: Introduce with_clone_obc_only() A with_clone_obc() variant, in PGBackend::rollback() with_locked_obc is locking the head obc used, we should not lock the head object obc again (as in by calling with_head_obc()). Signed-off-by: Matan Breizman --- src/crimson/osd/object_context_loader.cc | 49 +++++++++++++++--------- src/crimson/osd/object_context_loader.h | 8 ++++ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/crimson/osd/object_context_loader.cc b/src/crimson/osd/object_context_loader.cc index 81edc3c74a8eb..2c93a879a5f00 100644 --- a/src/crimson/osd/object_context_loader.cc +++ b/src/crimson/osd/object_context_loader.cc @@ -39,7 +39,7 @@ using crimson::common::local_conf; { assert(!oid.is_head()); return with_head_obc(oid.get_head(), - [oid, func=std::move(func), this](auto head) + [oid, func=std::move(func), this](auto head) mutable -> load_obc_iertr::future<> { if (!head->obs.exists) { logger().error("with_clone_obc: {} head doesn't exist", @@ -48,23 +48,36 @@ using crimson::common::local_conf; crimson::ct_error::enoent::make() }; } - auto coid = resolve_oid(head->get_ro_ss(), oid); - if (!coid) { - logger().error("with_clone_obc: {} clone not found", coid); - return load_obc_iertr::future<>{ - crimson::ct_error::enoent::make() - }; - } - auto [clone, existed] = shard_services.get_cached_obc(*coid); - return clone->template with_lock( - [existed=existed, head=std::move(head), clone=std::move(clone), - func=std::move(func), this]() -> load_obc_iertr::future<> { - auto loaded = get_or_load_obc(clone, existed); - clone->head = head; - return loaded.safe_then_interruptible( - [func = std::move(func)](auto clone) { - return std::move(func)(std::move(clone)); - }); + return this->with_clone_obc_only(head, + oid, + std::move(func)); + }); + } + + template + ObjectContextLoader::load_obc_iertr::future<> + ObjectContextLoader::with_clone_obc_only(ObjectContextRef head, + hobject_t oid, + with_obc_func_t&& func) + { + auto coid = resolve_oid(head->get_ro_ss(), oid); + if (!coid) { + logger().error("with_clone_obc_only: {} clone not found", + coid); + return load_obc_iertr::future<>{ + crimson::ct_error::enoent::make() + }; + } + auto [clone, existed] = shard_services.get_cached_obc(*coid); + return clone->template with_lock( + [existed=existed, clone=std::move(clone), + func=std::move(func), head=std::move(head), this]() + -> load_obc_iertr::future<> { + auto loaded = get_or_load_obc(clone, existed); + clone->head = std::move(head); + return loaded.safe_then_interruptible( + [func = std::move(func)](auto clone) { + return std::move(func)(std::move(clone)); }); }); } diff --git a/src/crimson/osd/object_context_loader.h b/src/crimson/osd/object_context_loader.h index 7c572229ac924..e211fd1159a3a 100644 --- a/src/crimson/osd/object_context_loader.h +++ b/src/crimson/osd/object_context_loader.h @@ -39,6 +39,14 @@ public: load_obc_iertr::future<> with_clone_obc(hobject_t oid, with_obc_func_t&& func); + // Use this variant in the case where the head object + // obc is already locked. Avoid nesting + // with_head_obc() as in using with_clone_obc(). + template + load_obc_iertr::future<> with_clone_obc_only(ObjectContextRef head, + hobject_t oid, + with_obc_func_t&& func); + template load_obc_iertr::future<> with_head_obc(ObjectContextRef obc, bool existed, -- 2.39.5