From: Radoslaw Zarzynski Date: Mon, 29 Apr 2019 18:49:23 +0000 (+0200) Subject: crimson/os: implement bits needed for basic write path. X-Git-Tag: v15.1.0~2730^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b53956e10f3b4744de4ec4e8171b15c5cc497cce;p=ceph.git crimson/os: implement bits needed for basic write path. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/crimson/os/cyan_store.cc b/src/crimson/os/cyan_store.cc index 493b4a8da61f..64e7637d9489 100644 --- a/src/crimson/os/cyan_store.cc +++ b/src/crimson/os/cyan_store.cc @@ -217,6 +217,13 @@ seastar::future<> CyanStore::do_transaction(CollectionRef ch, switch (op->op) { case Transaction::OP_NOP: break; + case Transaction::OP_TOUCH: + { + coll_t cid = i.get_cid(op->cid); + ghobject_t oid = i.get_oid(op->oid); + r = _touch(cid, oid); + } + break; case Transaction::OP_WRITE: { coll_t cid = i.get_cid(op->cid); @@ -229,6 +236,26 @@ seastar::future<> CyanStore::do_transaction(CollectionRef ch, r = _write(cid, oid, off, len, bl, fadvise_flags); } break; + case Transaction::OP_TRUNCATE: + { + coll_t cid = i.get_cid(op->cid); + ghobject_t oid = i.get_oid(op->oid); + uint64_t off = op->off; + r = _truncate(cid, oid, off); + } + break; + case Transaction::OP_SETATTR: + { + coll_t cid = i.get_cid(op->cid); + ghobject_t oid = i.get_oid(op->oid); + string name = i.decode_string(); + bufferlist bl; + i.decode_bl(bl); + map to_set; + to_set[name] = bufferptr(bl.c_str(), bl.length()); + r = _setattrs(cid, oid, to_set); + } + break; case Transaction::OP_MKCOLL: { coll_t cid = i.get_cid(op->cid); @@ -246,9 +273,21 @@ seastar::future<> CyanStore::do_transaction(CollectionRef ch, return seastar::now(); } +int CyanStore::_touch(const coll_t& cid, const ghobject_t& oid) +{ + logger().debug("{} cid={} oid={}", + __func__, cid, oid); + auto c = open_collection(cid); + if (!c) + return -ENOENT; + + c->get_or_create_object(oid); + return 0; +} + int CyanStore::_write(const coll_t& cid, const ghobject_t& oid, - uint64_t offset, size_t len, const bufferlist& bl, - uint32_t fadvise_flags) + uint64_t offset, size_t len, const bufferlist& bl, + uint32_t fadvise_flags) { logger().debug("{} {} {} {} ~ {}", __func__, cid, oid, offset, len); @@ -268,6 +307,40 @@ int CyanStore::_write(const coll_t& cid, const ghobject_t& oid, return 0; } +int CyanStore::_truncate(const coll_t& cid, const ghobject_t& oid, uint64_t size) +{ + logger().debug("{} cid={} oid={} size={}", + __func__, cid, oid, size); + auto c = open_collection(cid); + if (!c) + return -ENOENT; + + ObjectRef o = c->get_object(oid); + if (!o) + return -ENOENT; + const ssize_t old_size = o->get_size(); + int r = o->truncate(size); + used_bytes += (o->get_size() - old_size); + return r; +} + +int CyanStore::_setattrs(const coll_t& cid, const ghobject_t& oid, + map& aset) +{ + logger().debug("{} cid={} oid={}", + __func__, cid, oid); + auto c = open_collection(cid); + if (!c) + return -ENOENT; + + ObjectRef o = c->get_object(oid); + if (!o) + return -ENOENT; + for (map::const_iterator p = aset.begin(); p != aset.end(); ++p) + o->xattr[p->first] = p->second; + return 0; +} + int CyanStore::_create_collection(const coll_t& cid, int bits) { auto result = coll_map.insert(std::make_pair(cid, CollectionRef())); diff --git a/src/crimson/os/cyan_store.h b/src/crimson/os/cyan_store.h index 56ab6d9abb75..455de1092fdd 100644 --- a/src/crimson/os/cyan_store.h +++ b/src/crimson/os/cyan_store.h @@ -91,9 +91,13 @@ public: uuid_d get_fsid() const; private: + int _touch(const coll_t& cid, const ghobject_t& oid); int _write(const coll_t& cid, const ghobject_t& oid, uint64_t offset, size_t len, const bufferlist& bl, uint32_t fadvise_flags); + int _truncate(const coll_t& cid, const ghobject_t& oid, uint64_t size); + int _setattrs(const coll_t& cid, const ghobject_t& oid, + map& aset); int _create_collection(const coll_t& cid, int bits); }; diff --git a/src/crimson/osd/pg_backend.h b/src/crimson/osd/pg_backend.h index 3d0b298ae0b5..69a55be25612 100644 --- a/src/crimson/osd/pg_backend.h +++ b/src/crimson/osd/pg_backend.h @@ -41,7 +41,7 @@ public: size_t truncate_size, uint32_t truncate_seq, uint32_t flags); - seastar::future<> write( + seastar::future<> writefull( const ObjectState& os, const OSDOp& osd_op, ceph::os::Transaction& trans);