From ada3dd05b588fdaf0723a40c3a7e1834c5f8fe48 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 11 Mar 2019 21:40:42 +0800 Subject: [PATCH] crimson/os: implement CyanStore::get_attr() it is used for retrieving object_info and snapset attributes. Signed-off-by: Kefu Chai --- src/crimson/os/cyan_store.cc | 30 ++++++++++++++++++++++++++++++ src/crimson/os/cyan_store.h | 5 +++++ 2 files changed, 35 insertions(+) diff --git a/src/crimson/os/cyan_store.cc b/src/crimson/os/cyan_store.cc index adebd41e74b..d395c863109 100644 --- a/src/crimson/os/cyan_store.cc +++ b/src/crimson/os/cyan_store.cc @@ -152,6 +152,36 @@ seastar::future CyanStore::read(CollectionRef c, return seastar::make_ready_future(std::move(bl)); } +seastar::future CyanStore::get_attr(CollectionRef c, + const ghobject_t& oid, + std::string_view name) +{ + logger().info("{} {} {}", + __func__, c->cid, oid); + auto o = c->get_object(oid); + if (!o) { + throw std::runtime_error(fmt::format("object does not exist: {}", oid)); + } + if (auto found = o->xattr.find(name); found != o->xattr.end()) { + return seastar::make_ready_future(found->second); + } else { + throw std::runtime_error(fmt::format("attr does not exist: {}/{}", + oid, name)); + } +} + +seastar::future CyanStore::get_attrs(CollectionRef c, + const ghobject_t& oid) +{ + logger().info("{} {} {}", + __func__, c->cid, oid); + auto o = c->get_object(oid); + if (!o) { + throw std::runtime_error(fmt::format("object does not exist: {}", oid)); + } + return seastar::make_ready_future(o->xattr); +} + seastar::future CyanStore::omap_get_values(CollectionRef c, const ghobject_t& oid, diff --git a/src/crimson/os/cyan_store.h b/src/crimson/os/cyan_store.h index 0b7f3d871e4..2a9c58989f7 100644 --- a/src/crimson/os/cyan_store.h +++ b/src/crimson/os/cyan_store.h @@ -37,6 +37,11 @@ public: uint64_t offset, size_t len, uint32_t op_flags = 0); + seastar::future get_attr(CollectionRef c, + const ghobject_t& oid, + std::string_view name); + using attrs_t = std::map>; + seastar::future get_attrs(CollectionRef c, const ghobject_t& oid); using omap_values_t = std::map>; seastar::future omap_get_values( CollectionRef c, -- 2.39.5