From f9cc138e250945543ab33acd2bfaf999ab6c2dba Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 6 Jan 2015 11:20:24 -0800 Subject: [PATCH] osd: change coll_t::is_pg() and is_temp() to take a pointer; drop snap The snap arg isn't used anymore. The spg_t should be a pointer (not ref) since it is an output argument. Signed-off-by: Sage Weil --- src/os/FileStore.cc | 5 ++--- src/os/HashIndex.cc | 2 +- src/os/LFNIndex.cc | 4 ++-- src/osd/OSD.cc | 19 +++++------------ src/osd/PG.cc | 5 +---- src/osd/osd_types.cc | 22 +++++++------------ src/osd/osd_types.h | 16 ++++++++------ src/tools/ceph_objectstore_tool.cc | 34 +++++++++--------------------- 8 files changed, 38 insertions(+), 69 deletions(-) diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 70b8525daceaa..c921d47b9a4a9 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -4725,11 +4725,10 @@ int FileStore::collection_list_partial(coll_t c, ghobject_t start, shard_id_t shard; { spg_t pgid; - snapid_t snap; - if (c.is_temp(pgid)) { + if (c.is_temp(&pgid)) { pool = -2 - pgid.pool(); shard = pgid.shard; - } else if (c.is_pg(pgid, snap)) { + } else if (c.is_pg(&pgid)) { pool = pgid.pool(); shard = pgid.shard; } else if (c.is_meta()) { diff --git a/src/os/HashIndex.cc b/src/os/HashIndex.cc index 4324d38b51e95..96a0a5af35d98 100644 --- a/src/os/HashIndex.cc +++ b/src/os/HashIndex.cc @@ -382,7 +382,7 @@ int HashIndex::pre_split_folder(uint32_t pg_num, uint64_t expected_num_objs) return 0; spg_t spgid; - if (!c.is_pg_prefix(spgid)) + if (!c.is_pg_prefix(&spgid)) return -EINVAL; const ps_t ps = spgid.pgid.ps(); diff --git a/src/os/LFNIndex.cc b/src/os/LFNIndex.cc index 5d6bd7b9d8d7c..0711c2d08b2ed 100644 --- a/src/os/LFNIndex.cc +++ b/src/os/LFNIndex.cc @@ -1025,7 +1025,7 @@ bool LFNIndex::lfn_parse_object_name_keyless(const string &long_name, ghobject_t bool r = parse_object(long_name.c_str(), *out); int64_t pool = -1; spg_t pg; - if (coll().is_pg_prefix(pg)) + if (coll().is_pg_prefix(&pg)) pool = (int64_t)pg.pgid.pool(); out->hobj.pool = pool; if (!r) return r; @@ -1118,7 +1118,7 @@ bool LFNIndex::lfn_parse_object_name_poolless(const string &long_name, int64_t pool = -1; spg_t pg; - if (coll().is_pg_prefix(pg)) + if (coll().is_pg_prefix(&pg)) pool = (int64_t)pg.pgid.pool(); (*out) = ghobject_t(hobject_t(name, key, snap, hash, pool, "")); return true; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index c00c48352b625..70769407d2a2c 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -2767,26 +2767,17 @@ void OSD::load_pgs() it != ls.end(); ++it) { spg_t pgid; - snapid_t snap; - - if (it->is_temp(pgid) || + if (it->is_temp(&pgid) || it->is_removal(&pgid) || - (it->is_pg(pgid, snap) && - PG::_has_removal_flag(store, pgid))) { + (it->is_pg(&pgid) && PG::_has_removal_flag(store, pgid))) { dout(10) << "load_pgs " << *it << " clearing temp" << dendl; recursive_remove_collection(store, pgid, *it); continue; } - if (it->is_pg(pgid, snap)) { - if (snap != CEPH_NOSNAP) { - dout(10) << "load_pgs skipping snapped dir " << *it - << " (pg " << pgid << " snap " << snap << ")" << dendl; - pgs[pgid].insert(snap); - } else { - pgs[pgid]; - head_pgs.insert(pgid); - } + if (it->is_pg(&pgid)) { + pgs[pgid]; + head_pgs.insert(pgid); continue; } diff --git a/src/osd/PG.cc b/src/osd/PG.cc index 7f12808654d11..767f607ec322d 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -2738,10 +2738,7 @@ epoch_t PG::peek_map_epoch(ObjectStore *store, assert(bl); { // validate collection name - spg_t pgid_temp; - snapid_t snap; - bool ok = coll.is_pg(pgid_temp, snap); - assert(ok); + assert(coll.is_pg()); } // try for v8 diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 74f64f83bd3d6..f6037691a195c 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -556,10 +556,10 @@ bool coll_t::is_temp() const return false; } -bool coll_t::is_temp(spg_t& pgid) const +bool coll_t::is_temp(spg_t *pgid) const { const char *cstr(str.c_str()); - if (!pgid.parse(cstr)) + if (!pgid->parse(cstr)) return false; const char *tmp_start = strchr(cstr, '_'); if (!tmp_start) @@ -569,31 +569,25 @@ bool coll_t::is_temp(spg_t& pgid) const return false; } -bool coll_t::is_pg(spg_t& pgid, snapid_t& snap) const +bool coll_t::is_pg(spg_t *pgid) const { const char *cstr(str.c_str()); - if (!pgid.parse(cstr)) + if (!pgid->parse(cstr)) return false; const char *snap_start = strchr(cstr, '_'); if (!snap_start) return false; - if (strncmp(snap_start, "_head", 5) == 0) { - snap = CEPH_NOSNAP; - } else { - errno = 0; - snap = strtoull(snap_start+1, 0, 16); - if (errno) - return false; - } + if (strncmp(snap_start, "_head", 5) != 0) + return false; return true; } -bool coll_t::is_pg_prefix(spg_t& pgid) const +bool coll_t::is_pg_prefix(spg_t *pgid) const { const char *cstr(str.c_str()); - if (!pgid.parse(cstr)) + if (!pgid->parse(cstr)) return false; const char *snap_start = strchr(cstr, '_'); if (!snap_start) diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 42565bac92f9c..0d0145fe52fdf 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -523,9 +523,13 @@ public: bool is_meta() const { return str == string("meta"); } - bool is_pg_prefix(spg_t& pgid) const; - bool is_pg(spg_t& pgid, snapid_t& snap) const; - bool is_temp(spg_t& pgid) const; + bool is_pg_prefix(spg_t *pgid) const; + bool is_pg(spg_t *pgid) const; + bool is_pg() const { + spg_t pgid; + return is_pg(&pgid); + } + bool is_temp(spg_t *pgid) const; bool is_temp() const; bool is_removal(spg_t *pgid) const; void encode(bufferlist& bl) const; @@ -541,10 +545,8 @@ public: // which we presume is a pg collection. coll_t get_temp() { spg_t pgid; - snapid_t snap; - bool foo = is_pg(pgid, snap); - assert(foo); - assert(snap == CEPH_NOSNAP); + bool valid = is_pg(&pgid); + assert(valid); return coll_t(str.substr(0, str.length() - 4) + "TEMP"); } diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 4c831b81485a5..c363089dcb3ac 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -142,10 +142,7 @@ int action_on_all_objects_in_pg(ObjectStore *store, string pgidstr, action_on_ob i != candidates.end(); ++i) { spg_t cand_pgid; - snapid_t snap; - if (!i->is_pg(cand_pgid, snap)) - continue; - if (snap != CEPH_NOSNAP) + if (!i->is_pg(&cand_pgid)) continue; // If an exact match or treat no shard as any shard @@ -192,9 +189,7 @@ int _action_on_all_objects(ObjectStore *store, action_on_object_t &action, bool for (vector::iterator i = candidates.begin(); i != candidates.end(); ++i) { - spg_t pgid; - snapid_t snap; - if (i->is_pg(pgid, snap)) { + if (i->is_pg()) { colls_to_check.push_back(*i); } } @@ -400,7 +395,7 @@ void dump_log(Formatter *formatter, ostream &out, pg_log_t &log, void remove_coll(ObjectStore *store, const coll_t &coll) { spg_t pg; - coll.is_pg_prefix(pg); + coll.is_pg_prefix(&pg); OSDriver driver( store, coll_t(), @@ -459,11 +454,10 @@ int finish_remove_pgs(ObjectStore *store) it != ls.end(); ++it) { spg_t pgid; - snapid_t snap; - if (it->is_temp(pgid) || + if (it->is_temp(&pgid) || it->is_removal(&pgid) || - (it->is_pg(pgid, snap) && PG::_has_removal_flag(store, pgid))) { + (it->is_pg(&pgid) && PG::_has_removal_flag(store, pgid))) { cout << "finish_remove_pgs " << *it << " removing " << pgid << std::endl; OSD::recursive_remove_collection(store, pgid, *it); continue; @@ -880,7 +874,7 @@ int ObjectStoreTool::get_object(ObjectStore *store, coll_t coll, coll_t(), OSD::make_snapmapper_oid()); spg_t pg; - coll.is_pg_prefix(pg); + coll.is_pg_prefix(&pg); SnapMapper mapper(&driver, 0, 0, 0, pg.shard); assert(g_ceph_context); @@ -891,8 +885,7 @@ int ObjectStoreTool::get_object(ObjectStore *store, coll_t coll, pg_t pgid = curmap.raw_pg_to_pg(raw_pgid); spg_t coll_pgid; - snapid_t coll_snap; - if (coll.is_pg(coll_pgid, coll_snap) == false) { + if (coll.is_pg(&coll_pgid) == false) { cerr << "INTERNAL ERROR: Bad collection during import" << std::endl; return -EFAULT; } @@ -1388,7 +1381,7 @@ int do_list(ObjectStore *store, string pgidstr, string object, Formatter *format int do_remove_object(ObjectStore *store, coll_t coll, ghobject_t &ghobj) { spg_t pg; - coll.is_pg_prefix(pg); + coll.is_pg_prefix(&pg); OSDriver driver( store, coll_t(), @@ -2367,26 +2360,19 @@ int main(int argc, char **argv) // Find pg for (it = ls.begin(); it != ls.end(); ++it) { - snapid_t snap; spg_t tmppgid; - if (!it->is_pg(tmppgid, snap)) { + if (!it->is_pg(&tmppgid)) { continue; } - if (it->is_temp(tmppgid)) { + if (it->is_temp(&tmppgid)) { continue; } if (op != "list-pgs" && tmppgid != pgid) { continue; } - if (snap != CEPH_NOSNAP) { - if (debug) - cerr << "skipping snapped dir " << *it - << " (pg " << pgid << " snap " << snap << ")" << std::endl; - continue; - } if (op != "list-pgs") { //Found! -- 2.39.5