From a6fa7b6568c882cd5b92b65e7326f50f719e70c8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 3 Feb 2017 14:52:46 -0500 Subject: [PATCH] osd/OSDMap: generalize map_to_pg So we can do this without constructing an object_locator_t. Signed-off-by: Sage Weil --- src/osd/OSDMap.cc | 39 +++++++++++++++++++++++++-------------- src/osd/OSDMap.h | 13 +++++++++++-- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 9dcfee1dd01..89bda09f290 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -1484,28 +1484,39 @@ int OSDMap::apply_incremental(const Incremental &inc) } // mapping -int OSDMap::object_locator_to_pg( - const object_t& oid, - const object_locator_t& loc, - pg_t &pg) const +int OSDMap::map_to_pg( + int64_t poolid, + const string& name, + const string& key, + const string& nspace, + pg_t *pg) const { // calculate ps (placement seed) - const pg_pool_t *pool = get_pg_pool(loc.get_pool()); + const pg_pool_t *pool = get_pg_pool(poolid); if (!pool) return -ENOENT; ps_t ps; - if (loc.hash >= 0) { - ps = loc.hash; - } else { - if (!loc.key.empty()) - ps = pool->hash_key(loc.key, loc.nspace); - else - ps = pool->hash_key(oid.name, loc.nspace); - } - pg = pg_t(ps, loc.get_pool(), -1); + if (!key.empty()) + ps = pool->hash_key(key, nspace); + else + ps = pool->hash_key(name, nspace); + *pg = pg_t(ps, poolid); return 0; } +int OSDMap::object_locator_to_pg( + const object_t& oid, const object_locator_t& loc, pg_t &pg) const +{ + if (loc.hash >= 0) { + if (!get_pg_pool(loc.get_pool())) { + return -ENOENT; + } + pg = pg_t(loc.hash, loc.get_pool()); + return 0; + } + return map_to_pg(loc.get_pool(), oid.name, loc.key, loc.nspace, &pg); +} + ceph_object_layout OSDMap::make_object_layout( object_t oid, int pg_pool, string nspace) const { diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index c662bdcea8d..5fc114539ee 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -587,14 +587,23 @@ public: /**** mapping facilities ****/ - int object_locator_to_pg(const object_t& oid, const object_locator_t& loc, pg_t &pg) const; - pg_t object_locator_to_pg(const object_t& oid, const object_locator_t& loc) const { + int map_to_pg( + int64_t pool, + const string& name, + const string& key, + const string& nspace, + pg_t *pg) const; + int object_locator_to_pg(const object_t& oid, const object_locator_t& loc, + pg_t &pg) const; + pg_t object_locator_to_pg(const object_t& oid, + const object_locator_t& loc) const { pg_t pg; int ret = object_locator_to_pg(oid, loc, pg); assert(ret == 0); return pg; } + static object_locator_t file_to_object_locator(const file_layout_t& layout) { return object_locator_t(layout.pool_id, layout.pool_ns); }