From: Sage Weil Date: Mon, 18 Jan 2016 16:05:00 +0000 (-0500) Subject: os/bluestore: implement CollectionHandle based read methods X-Git-Tag: v10.0.4~153^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=765eb9f721591a505fca27ae0c60d79ccee549ab;p=ceph.git os/bluestore: implement CollectionHandle based read methods Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 69ff54c9e070..107c33fc003a 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2337,10 +2337,18 @@ ObjectStore::CollectionHandle BlueStore::open_collection(const coll_t& cid) bool BlueStore::exists(coll_t cid, const ghobject_t& oid) { - dout(10) << __func__ << " " << cid << " " << oid << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return false; + return exists(c, oid); +} + +bool BlueStore::exists(CollectionHandle &c_, const ghobject_t& oid) +{ + Collection *c = static_cast(c_.get()); + dout(10) << __func__ << " " << c->cid << " " << oid << dendl; + if (!c->exists) + return false; RWLock::RLocker l(c->lock); OnodeRef o = c->get_onode(oid, false); if (!o || !o->exists) @@ -2354,10 +2362,22 @@ int BlueStore::stat( struct stat *st, bool allow_eio) { - dout(10) << __func__ << " " << cid << " " << oid << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return -ENOENT; + return stat(c, oid, st, allow_eio); +} + +int BlueStore::stat( + CollectionHandle &c_, + const ghobject_t& oid, + struct stat *st, + bool allow_eio) +{ + Collection *c = static_cast(c_.get()); + if (c->exists) + return -ENOENT; + dout(10) << __func__ << " " << c->get_cid() << " " << oid << dendl; RWLock::RLocker l(c->lock); OnodeRef o = c->get_onode(oid, false); if (!o || !o->exists) @@ -2378,15 +2398,32 @@ int BlueStore::read( uint32_t op_flags, bool allow_eio) { + CollectionHandle c = _get_collection(cid); + if (!c) + return -ENOENT; + return read(c, oid, offset, length, bl, op_flags, allow_eio); +} + +int BlueStore::read( + CollectionHandle &c_, + const ghobject_t& oid, + uint64_t offset, + size_t length, + bufferlist& bl, + uint32_t op_flags, + bool allow_eio) +{ + Collection *c = static_cast(c_.get()); + const coll_t &cid = c->get_cid(); dout(15) << __func__ << " " << cid << " " << oid << " " << offset << "~" << length << dendl; - bl.clear(); - CollectionRef c = _get_collection(cid); - if (!c) + if (!c->exists) return -ENOENT; RWLock::RLocker l(c->lock); + bl.clear(); + int r; OnodeRef o = c->get_onode(oid, false); @@ -2566,10 +2603,23 @@ int BlueStore::fiemap( size_t len, bufferlist& bl) { - interval_set m; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return -ENOENT; + return fiemap(c, oid, offset, len, bl); +} + +int BlueStore::fiemap( + CollectionHandle &c_, + const ghobject_t& oid, + uint64_t offset, + size_t len, + bufferlist& bl) +{ + Collection *c = static_cast(c_.get()); + if (!c->exists) + return -ENOENT; + interval_set m; RWLock::RLocker l(c->lock); OnodeRef o = c->get_onode(oid, false); @@ -2669,10 +2719,22 @@ int BlueStore::getattr( const char *name, bufferptr& value) { - dout(15) << __func__ << " " << cid << " " << oid << " " << name << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return -ENOENT; + return getattr(c, oid, name, value); +} + +int BlueStore::getattr( + CollectionHandle &c_, + const ghobject_t& oid, + const char *name, + bufferptr& value) +{ + Collection *c = static_cast(c_.get()); + dout(15) << __func__ << " " << c->cid << " " << oid << " " << name << dendl; + if (!c->exists) + return -ENOENT; RWLock::RLocker l(c->lock); int r; string k(name); @@ -2690,20 +2752,32 @@ int BlueStore::getattr( value = o->onode.attrs[k]; r = 0; out: - dout(10) << __func__ << " " << cid << " " << oid << " " << name + dout(10) << __func__ << " " << c->cid << " " << oid << " " << name << " = " << r << dendl; return r; } + int BlueStore::getattrs( coll_t cid, const ghobject_t& oid, map& aset) { - dout(15) << __func__ << " " << cid << " " << oid << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return -ENOENT; + return getattrs(c, oid, aset); +} + +int BlueStore::getattrs( + CollectionHandle &c_, + const ghobject_t& oid, + map& aset) +{ + Collection *c = static_cast(c_.get()); + dout(15) << __func__ << " " << c->cid << " " << oid << dendl; + if (!c->exists) + return -ENOENT; RWLock::RLocker l(c->lock); int r; @@ -2715,7 +2789,7 @@ int BlueStore::getattrs( aset = o->onode.attrs; r = 0; out: - dout(10) << __func__ << " " << cid << " " << oid + dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; return r; } @@ -2755,13 +2829,24 @@ int BlueStore::collection_list( bool sort_bitwise, int max, vector *ls, ghobject_t *pnext) { - dout(15) << __func__ << " " << cid + CollectionHandle c = _get_collection(cid); + if (!c) + return -ENOENT; + return collection_list(c, start, end, sort_bitwise, max, ls, pnext); +} + +int BlueStore::collection_list( + CollectionHandle &c_, ghobject_t start, ghobject_t end, + bool sort_bitwise, int max, + vector *ls, ghobject_t *pnext) +{ + Collection *c = static_cast(c_.get()); + dout(15) << __func__ << " " << c->cid << " start " << start << " end " << end << " max " << max << dendl; + if (!c->exists) + return -ENOENT; if (!sort_bitwise) return -EOPNOTSUPP; - CollectionRef c = _get_collection(cid); - if (!c) - return -ENOENT; RWLock::RLocker l(c->lock); int r = 0; KeyValueDB::Iterator it; @@ -2779,7 +2864,7 @@ int BlueStore::collection_list( start.hobj == hobject_t::get_max()) { goto out; } - get_coll_key_range(cid, c->cnode.bits, &temp_start_key, &temp_end_key, + get_coll_key_range(c->cid, c->cnode.bits, &temp_start_key, &temp_end_key, &start_key, &end_key); dout(20) << __func__ << " range " << pretty_binary_string(temp_start_key) @@ -2790,7 +2875,7 @@ int BlueStore::collection_list( it = db->get_iterator(PREFIX_OBJ); if (start == ghobject_t() || start.hobj == hobject_t() || - start == cid.get_min_hobj()) { + start == c->cid.get_min_hobj()) { it->upper_bound(temp_start_key); temp = true; } else { @@ -2865,7 +2950,7 @@ int BlueStore::collection_list( *pnext = ghobject_t::get_max(); } out: - dout(10) << __func__ << " " << cid + dout(10) << __func__ << " " << c->cid << " start " << start << " end " << end << " max " << max << " = " << r << ", ls.size() = " << ls->size() << ", next = " << *pnext << dendl; @@ -2968,10 +3053,23 @@ int BlueStore::omap_get( map *out /// < [out] Key to value map ) { - dout(15) << __func__ << " " << cid << " oid " << oid << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return -ENOENT; + return omap_get(c, oid, header, out); +} + +int BlueStore::omap_get( + CollectionHandle &c_, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + bufferlist *header, ///< [out] omap header + map *out /// < [out] Key to value map + ) +{ + Collection *c = static_cast(c_.get()); + dout(15) << __func__ << " " << c->get_cid() << " oid " << oid << dendl; + if (!c->exists) + return -ENOENT; RWLock::RLocker l(c->lock); int r = 0; OnodeRef o = c->get_onode(oid, false); @@ -3007,7 +3105,8 @@ int BlueStore::omap_get( } } out: - dout(10) << __func__ << " " << cid << " oid " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->get_cid() << " oid " << oid << " = " << r + << dendl; return r; } @@ -3018,10 +3117,23 @@ int BlueStore::omap_get_header( bool allow_eio ///< [in] don't assert on eio ) { - dout(15) << __func__ << " " << cid << " oid " << oid << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return -ENOENT; + return omap_get_header(c, oid, header, allow_eio); +} + +int BlueStore::omap_get_header( + CollectionHandle &c_, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + bufferlist *header, ///< [out] omap header + bool allow_eio ///< [in] don't assert on eio + ) +{ + Collection *c = static_cast(c_.get()); + dout(15) << __func__ << " " << c->get_cid() << " oid " << oid << dendl; + if (!c->exists) + return -ENOENT; RWLock::RLocker l(c->lock); int r = 0; OnodeRef o = c->get_onode(oid, false); @@ -3042,7 +3154,8 @@ int BlueStore::omap_get_header( } } out: - dout(10) << __func__ << " " << cid << " oid " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->get_cid() << " oid " << oid << " = " << r + << dendl; return r; } @@ -3052,10 +3165,22 @@ int BlueStore::omap_get_keys( set *keys ///< [out] Keys defined on oid ) { - dout(15) << __func__ << " " << cid << " oid " << oid << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return -ENOENT; + return omap_get_keys(c, oid, keys); +} + +int BlueStore::omap_get_keys( + CollectionHandle &c_, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + set *keys ///< [out] Keys defined on oid + ) +{ + Collection *c = static_cast(c_.get()); + dout(15) << __func__ << " " << c->get_cid() << " oid " << oid << dendl; + if (!c->exists) + return -ENOENT; RWLock::RLocker l(c->lock); int r = 0; OnodeRef o = c->get_onode(oid, false); @@ -3087,7 +3212,8 @@ int BlueStore::omap_get_keys( } } out: - dout(10) << __func__ << " " << cid << " oid " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->get_cid() << " oid " << oid << " = " << r + << dendl; return r; } @@ -3098,10 +3224,23 @@ int BlueStore::omap_get_values( map *out ///< [out] Returned keys and values ) { - dout(15) << __func__ << " " << cid << " oid " << oid << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return -ENOENT; + return omap_get_values(c, oid, keys, out); +} + +int BlueStore::omap_get_values( + CollectionHandle &c_, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + const set &keys, ///< [in] Keys to get + map *out ///< [out] Returned keys and values + ) +{ + Collection *c = static_cast(c_.get()); + dout(15) << __func__ << " " << c->get_cid() << " oid " << oid << dendl; + if (!c->exists) + return -ENOENT; RWLock::RLocker l(c->lock); int r = 0; OnodeRef o = c->get_onode(oid, false); @@ -3123,7 +3262,8 @@ int BlueStore::omap_get_values( } } out: - dout(10) << __func__ << " " << cid << " oid " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->get_cid() << " oid " << oid << " = " << r + << dendl; return r; } @@ -3134,10 +3274,23 @@ int BlueStore::omap_check_keys( set *out ///< [out] Subset of keys defined on oid ) { - dout(15) << __func__ << " " << cid << " oid " << oid << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) return -ENOENT; + return omap_check_keys(c, oid, keys, out); +} + +int BlueStore::omap_check_keys( + CollectionHandle &c_, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + const set &keys, ///< [in] Keys to check + set *out ///< [out] Subset of keys defined on oid + ) +{ + Collection *c = static_cast(c_.get()); + dout(15) << __func__ << " " << c->get_cid() << " oid " << oid << dendl; + if (!c->exists) + return -ENOENT; RWLock::RLocker l(c->lock); int r = 0; OnodeRef o = c->get_onode(oid, false); @@ -3162,7 +3315,8 @@ int BlueStore::omap_check_keys( } } out: - dout(10) << __func__ << " " << cid << " oid " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->get_cid() << " oid " << oid << " = " << r + << dendl; return r; } @@ -3171,13 +3325,24 @@ ObjectMap::ObjectMapIterator BlueStore::get_omap_iterator( const ghobject_t &oid ///< [in] object ) { - - dout(10) << __func__ << " " << cid << " " << oid << dendl; - CollectionRef c = _get_collection(cid); + CollectionHandle c = _get_collection(cid); if (!c) { dout(10) << __func__ << " " << cid << "doesn't exist" <(c_.get()); + dout(10) << __func__ << " " << c->get_cid() << " " << oid << dendl; + if (!c->exists) { + return ObjectMap::ObjectMapIterator(); + } RWLock::RLocker l(c->lock); OnodeRef o = c->get_onode(oid, false); if (!o) { diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 35b44eab9a8e..3740fdbb05fe 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -622,11 +622,17 @@ public: int statfs(struct statfs *buf); bool exists(coll_t cid, const ghobject_t& oid); + bool exists(CollectionHandle &c, const ghobject_t& oid); int stat( coll_t cid, const ghobject_t& oid, struct stat *st, - bool allow_eio = false); // struct stat? + bool allow_eio = false) override; + int stat( + CollectionHandle &c, + const ghobject_t& oid, + struct stat *st, + bool allow_eio = false) override; int read( coll_t cid, const ghobject_t& oid, @@ -634,7 +640,15 @@ public: size_t len, bufferlist& bl, uint32_t op_flags = 0, - bool allow_eio = false); + bool allow_eio = false) override; + int read( + CollectionHandle &c, + const ghobject_t& oid, + uint64_t offset, + size_t len, + bufferlist& bl, + uint32_t op_flags = 0, + bool allow_eio = false) override; int _do_read( OnodeRef o, uint64_t offset, @@ -642,24 +656,47 @@ public: bufferlist& bl, uint32_t op_flags = 0); - int fiemap(coll_t cid, const ghobject_t& oid, uint64_t offset, size_t len, bufferlist& bl); - int getattr(coll_t cid, const ghobject_t& oid, const char *name, bufferptr& value); - int getattrs(coll_t cid, const ghobject_t& oid, map& aset); + int fiemap(coll_t cid, const ghobject_t& oid, + uint64_t offset, size_t len, bufferlist& bl) override; + int fiemap(CollectionHandle &c, const ghobject_t& oid, + uint64_t offset, size_t len, bufferlist& bl) override; + + int getattr(coll_t cid, const ghobject_t& oid, const char *name, + bufferptr& value) override; + int getattr(CollectionHandle &c, const ghobject_t& oid, const char *name, + bufferptr& value) override; + + int getattrs(coll_t cid, const ghobject_t& oid, + map& aset) override; + int getattrs(CollectionHandle &c, const ghobject_t& oid, + map& aset) override; + + int list_collections(vector& ls) override; + + CollectionHandle open_collection(const coll_t &c) override; - int list_collections(vector& ls); bool collection_exists(coll_t c); bool collection_empty(coll_t c); int collection_list(coll_t cid, ghobject_t start, ghobject_t end, bool sort_bitwise, int max, - vector *ls, ghobject_t *next); + vector *ls, ghobject_t *next) override; + int collection_list(CollectionHandle &c, ghobject_t start, ghobject_t end, + bool sort_bitwise, int max, + vector *ls, ghobject_t *next) override; int omap_get( coll_t cid, ///< [in] Collection containing oid const ghobject_t &oid, ///< [in] Object containing omap bufferlist *header, ///< [out] omap header map *out /// < [out] Key to value map - ); + ) override; + int omap_get( + CollectionHandle &c, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + bufferlist *header, ///< [out] omap header + map *out /// < [out] Key to value map + ) override; /// Get omap header int omap_get_header( @@ -667,13 +704,24 @@ public: const ghobject_t &oid, ///< [in] Object containing omap bufferlist *header, ///< [out] omap header bool allow_eio = false ///< [in] don't assert on eio - ); + ) override; + int omap_get_header( + CollectionHandle &c, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + bufferlist *header, ///< [out] omap header + bool allow_eio = false ///< [in] don't assert on eio + ) override; /// Get keys defined on oid int omap_get_keys( coll_t cid, ///< [in] Collection containing oid const ghobject_t &oid, ///< [in] Object containing omap set *keys ///< [out] Keys defined on oid + ) override; + int omap_get_keys( + CollectionHandle &c, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + set *keys ///< [out] Keys defined on oid ); /// Get key values @@ -682,7 +730,13 @@ public: const ghobject_t &oid, ///< [in] Object containing omap const set &keys, ///< [in] Keys to get map *out ///< [out] Returned keys and values - ); + ) override; + int omap_get_values( + CollectionHandle &c, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + const set &keys, ///< [in] Keys to get + map *out ///< [out] Returned keys and values + ) override; /// Filters keys into out which are defined on oid int omap_check_keys( @@ -690,12 +744,22 @@ public: const ghobject_t &oid, ///< [in] Object containing omap const set &keys, ///< [in] Keys to check set *out ///< [out] Subset of keys defined on oid - ); + ) override; + int omap_check_keys( + CollectionHandle &c, ///< [in] Collection containing oid + const ghobject_t &oid, ///< [in] Object containing omap + const set &keys, ///< [in] Keys to check + set *out ///< [out] Subset of keys defined on oid + ) override; ObjectMap::ObjectMapIterator get_omap_iterator( coll_t cid, ///< [in] collection const ghobject_t &oid ///< [in] object - ); + ) override; + ObjectMap::ObjectMapIterator get_omap_iterator( + CollectionHandle &c, ///< [in] collection + const ghobject_t &oid ///< [in] object + ) override; void set_fsid(uuid_d u) { fsid = u;