From 76576536dad1dae425e96de6da7e1418dd3b6829 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 21 Aug 2020 16:15:08 +0800 Subject: [PATCH] crimson/os/cyanstore: handle OP_RMATTR Signed-off-by: Kefu Chai --- src/crimson/os/cyanstore/cyan_store.cc | 28 ++++++++++++++++++++++++++ src/crimson/os/cyanstore/cyan_store.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/crimson/os/cyanstore/cyan_store.cc b/src/crimson/os/cyanstore/cyan_store.cc index ec1bc5ce4bf..03d59d77cfd 100644 --- a/src/crimson/os/cyanstore/cyan_store.cc +++ b/src/crimson/os/cyanstore/cyan_store.cc @@ -379,6 +379,14 @@ seastar::future<> CyanStore::do_transaction(CollectionRef ch, r = _setattrs(cid, oid, to_set); } break; + case Transaction::OP_RMATTR: + { + coll_t cid = i.get_cid(op->cid); + ghobject_t oid = i.get_oid(op->oid); + std::string name = i.decode_string(); + r = _rm_attr(cid, oid, name); + } + break; case Transaction::OP_MKCOLL: { coll_t cid = i.get_cid(op->cid); @@ -667,6 +675,26 @@ int CyanStore::_setattrs(const coll_t& cid, const ghobject_t& oid, return 0; } +int CyanStore::_rm_attr(const coll_t& cid, const ghobject_t& oid, + std::string_view name) +{ + logger().debug("{} cid={} oid={} name={}", __func__, cid, oid, name); + auto c = _get_collection(cid); + if (!c) { + return -ENOENT; + } + ObjectRef o = c->get_object(oid); + if (!o) { + return -ENOENT; + } + auto i = o->xattr.find(name); + if (i == o->xattr.end()) { + return -ENODATA; + } + o->xattr.erase(i); + return 0; +} + int CyanStore::_create_collection(const coll_t& cid, int bits) { auto result = coll_map.try_emplace(cid); diff --git a/src/crimson/os/cyanstore/cyan_store.h b/src/crimson/os/cyanstore/cyan_store.h index 86678042f30..2c773211af1 100644 --- a/src/crimson/os/cyanstore/cyan_store.h +++ b/src/crimson/os/cyanstore/cyan_store.h @@ -176,6 +176,8 @@ private: int _truncate(const coll_t& cid, const ghobject_t& oid, uint64_t size); int _setattrs(const coll_t& cid, const ghobject_t& oid, std::map& aset); + int _rm_attr(const coll_t& cid, const ghobject_t& oid, + string_view name); int _create_collection(const coll_t& cid, int bits); boost::intrusive_ptr _get_collection(const coll_t& cid); }; -- 2.39.5