From: Patrick Donnelly Date: Sat, 9 Mar 2019 19:46:44 +0000 (-0800) Subject: mds: convert iterator loop to generic loop X-Git-Tag: v15.0.0~204^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4cf04ca57f3c4fce7a3a5d699627d0760347fd11;p=ceph.git mds: convert iterator loop to generic loop To pave the way to use vectors. Signed-off-by: Patrick Donnelly --- diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index c929e937db0c..d24ff0b80e68 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -1562,11 +1562,12 @@ void CInode::encode_lock_state(int type, bufferlist& bl) set myfrags; list dfls; get_dirfrags(dfls); - for (list::iterator p = dfls.begin(); p != dfls.end(); ++p) - if ((*p)->is_auth()) { - frag_t fg = (*p)->get_frag(); + for (const auto& dir : dfls) { + if (dir->is_auth()) { + frag_t fg = dir->get_frag(); myfrags.insert(fg); } + } encode(myfrags, bl); } break; diff --git a/src/mds/MDBalancer.cc b/src/mds/MDBalancer.cc index abdca46e657f..aed00b4c36f6 100644 --- a/src/mds/MDBalancer.cc +++ b/src/mds/MDBalancer.cc @@ -1031,10 +1031,7 @@ void MDBalancer::find_exports(CDir *dir, in->get_nested_dirfrags(dfls); size_t num_idle_frags = 0; - for (list::iterator p = dfls.begin(); - p != dfls.end(); - ++p) { - CDir *subdir = *p; + for (const auto& subdir : dfls) { if (already_exporting.count(subdir)) continue; @@ -1094,11 +1091,9 @@ void MDBalancer::find_exports(CDir *dir, } // apprently not enough; drill deeper into the hierarchy (if non-replicated) - for (list::iterator it = bigger_unrep.begin(); - it != bigger_unrep.end(); - ++it) { - dout(15) << " descending into " << **it << dendl; - find_exports(*it, amount, exports, have, already_exporting); + for (const auto& dir : bigger_unrep) { + dout(15) << " descending into " << *dir << dendl; + find_exports(dir, amount, exports, have, already_exporting); if (have > needmin) return; } @@ -1117,11 +1112,9 @@ void MDBalancer::find_exports(CDir *dir, } // ok fine, drill into replicated dirs - for (list::iterator it = bigger_rep.begin(); - it != bigger_rep.end(); - ++it) { - dout(7) << " descending into replicated " << **it << dendl; - find_exports(*it, amount, exports, have, already_exporting); + for (const auto& dir : bigger_rep) { + dout(7) << " descending into replicated " << *dir << dendl; + find_exports(dir, amount, exports, have, already_exporting); if (have > needmin) return; } diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index b57fe15f899e..390a9e53ee85 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -1392,8 +1392,7 @@ void MDCache::adjust_subtree_after_rename(CInode *diri, CDir *olddir, bool pop) tomove.push_back(bound); } } - for (list::iterator p = tomove.begin(); p != tomove.end(); ++p) { - CDir *bound = *p; + for (const auto& bound : tomove) { dout(10) << "moving bound " << *bound << " from " << *oldparent << " to " << *newparent << dendl; subtrees[oldparent].erase(bound); subtrees[newparent].insert(bound); @@ -2309,11 +2308,8 @@ void MDCache::predirty_journal_parents(MutationRef mut, EMetaBlob *blob, ceph_assert(parent->is_auth()); blob->add_dir_context(parent); blob->add_dir(parent, true); - for (list::iterator p = lsi.begin(); - p != lsi.end(); - ++p) { - CInode *cur = *p; - journal_dirty_inode(mut.get(), blob, cur); + for (const auto& in : lsi) { + journal_dirty_inode(mut.get(), blob, in); } } @@ -2512,19 +2508,13 @@ ESubtreeMap *MDCache::create_subtree_map() } // apply projected renames - for (map > >::iterator p = projected_subtree_renames.begin(); - p != projected_subtree_renames.end(); - ++p) { - for (list >::iterator q = p->second.begin(); q != p->second.end(); ++q) { - CInode *diri = p->first; - CDir *olddir = q->first; - CDir *newdir = q->second; + for (const auto& [diri, renames] : projected_subtree_renames) { + for (const auto& [olddir, newdir] : renames) { dout(10) << " adjusting for projected rename of " << *diri << " to " << *newdir << dendl; list dfls; diri->get_dirfrags(dfls); - for (list::iterator p = dfls.begin(); p != dfls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : dfls) { dout(10) << "dirfrag " << dir->dirfrag() << " " << *dir << dendl; CDir *oldparent = get_projected_subtree_root(olddir); dout(10) << " old parent " << oldparent->dirfrag() << " " << *oldparent << dendl; @@ -3072,10 +3062,7 @@ void MDCache::handle_mds_recovery(mds_rank_t who) // recurse? list ls; dnl->get_inode()->get_dirfrags(ls); - for (list::iterator p = ls.begin(); - p != ls.end(); - ++p) { - CDir *subdir = *p; + for (const auto& subdir : ls) { if (!subdir->is_subtree_root()) q.push_back(subdir); } @@ -3444,11 +3431,11 @@ void MDCache::finish_uncommitted_slave_update(metareqid_t reqid, mds_rank_t mast uncommitted_slave_rename_olddir.erase(it); list ls; diri->get_dirfrags(ls); - for (list::iterator q = ls.begin(); q != ls.end(); ++q) { - CDir *root = get_subtree_root(*q); + for (const auto& dir : ls) { + CDir *root = get_subtree_root(dir); if (root->get_dir_auth() == CDIR_AUTH_UNDEF) { try_trim_non_auth_subtree(root); - if (*q != root) + if (dir != root) break; } } @@ -3720,8 +3707,9 @@ void MDCache::trim_unlinked_inodes() q.push_back(in); } } - for (list::iterator p = q.begin(); p != q.end(); ++p) - remove_inode_recursive(*p); + for (auto& in : q) { + remove_inode_recursive(in); + } } /** recalc_auth_bits() @@ -4245,10 +4233,9 @@ void MDCache::rejoin_walk(CDir *dir, const MMDSCacheRejoin::ref &rejoin) } // recurse into nested dirs - for (list::iterator p = nested.begin(); - p != nested.end(); - ++p) - rejoin_walk(*p, rejoin); + for (const auto& dir : nested) { + rejoin_walk(dir, rejoin); + } } @@ -4540,10 +4527,7 @@ void MDCache::rejoin_scour_survivor_replicas(mds_rank_t from, const MMDSCacheRej list dfs; in->get_dirfrags(dfs); - for (list::iterator p = dfs.begin(); - p != dfs.end(); - ++p) { - CDir *dir = *p; + for (const auto& dir : dfs) { if (!dir->is_auth()) continue; @@ -4997,16 +4981,14 @@ void MDCache::handle_cache_rejoin_ack(const MMDSCacheRejoin::const_ref &ack) } } - for (set::iterator p = refragged_inodes.begin(); - p != refragged_inodes.end(); - ++p) { + for (const auto& in : refragged_inodes) { list ls; - (*p)->get_nested_dirfrags(ls); - for (list::iterator q = ls.begin(); q != ls.end(); ++q) { - if ((*q)->is_auth() || ack->strong_dirfrags.count((*q)->dirfrag())) + in->get_nested_dirfrags(ls); + for (const auto& dir : ls) { + if (dir->is_auth() || ack->strong_dirfrags.count(dir->dirfrag())) continue; - ceph_assert((*q)->get_num_any() == 0); - (*p)->close_dirfrag((*q)->get_frag()); + ceph_assert(dir->get_num_any() == 0); + in->close_dirfrag(dir->get_frag()); } } @@ -5169,10 +5151,7 @@ void MDCache::rejoin_trim_undef_inodes() if (in->is_dir()) { list dfls; in->get_dirfrags(dfls); - for (list::iterator p = dfls.begin(); - p != dfls.end(); - ++p) { - CDir *dir = *p; + for (const auto& dir : dfls) { dir->clear_replica_map(); for (auto &p : dir->items) { @@ -5940,8 +5919,9 @@ void MDCache::opened_undef_inode(CInode *in) { in->force_dirfrags(); list ls; in->get_dirfrags(ls); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) - rejoin_undef_dirfrags.insert(*p); + for (const auto& dir : ls) { + rejoin_undef_dirfrags.insert(dir); + } } } } @@ -6626,8 +6606,7 @@ std::pair MDCache::trim(uint64_t count) if (mds->is_stopping() && root) { list ls; root->get_dirfrags(ls); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : ls) { if (dir->get_num_ref() == 1) { // subtree pin trim_dirfrag(dir, 0, expiremap); ++trimmed; @@ -6868,8 +6847,7 @@ bool MDCache::trim_inode(CDentry *dn, CInode *in, CDir *con, expiremap& expirema // DIR list dfls; in->get_dirfrags(dfls); - for (list::iterator p = dfls.begin(); p != dfls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : dfls) { ceph_assert(!dir->is_subtree_root()); trim_dirfrag(dir, con ? con:dir, expiremap); // if no container (e.g. root dirfrag), use *p } @@ -6989,8 +6967,7 @@ void MDCache::trim_non_auth() dout(10) << " removing " << *in << dendl; list ls; in->get_dirfrags(ls); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *subdir = *p; + for (const auto& subdir : ls) { ceph_assert(!subdir->is_subtree_root()); in->close_dirfrag(subdir->dirfrag().frag); } @@ -7011,7 +6988,7 @@ void MDCache::trim_non_auth() } } - for (auto dn : auth_list) { + for (const auto& dn : auth_list) { if (dn->state_test(CDentry::STATE_BOTTOMLRU)) bottom_lru.lru_insert_mid(dn); else @@ -7037,13 +7014,11 @@ void MDCache::trim_non_auth() if (!in->is_auth()) { list ls; in->get_dirfrags(ls); - for (list::iterator p = ls.begin(); - p != ls.end(); - ++p) { - dout(10) << " removing " << **p << dendl; - ceph_assert((*p)->get_num_ref() == 1); // SUBTREE - remove_subtree((*p)); - in->close_dirfrag((*p)->dirfrag().frag); + for (const auto& dir : ls) { + dout(10) << " removing " << *dir << dendl; + ceph_assert(dir->get_num_ref() == 1); // SUBTREE + remove_subtree(dir); + in->close_dirfrag(dir->dirfrag().frag); } dout(10) << " removing " << *in << dendl; ceph_assert(!in->get_parent_dn()); @@ -7082,17 +7057,15 @@ bool MDCache::trim_non_auth_subtree(CDir *dir) if (in->is_dir()) { list subdirs; in->get_dirfrags(subdirs); - for (list::iterator subdir = subdirs.begin(); - subdir != subdirs.end(); - ++subdir) { - if ((*subdir)->is_subtree_root()) { + for (const auto& subdir : subdirs) { + if (subdir->is_subtree_root()) { keep_inode = true; - dout(10) << "trim_non_auth_subtree(" << dir << ") keeping " << **subdir << dendl; + dout(10) << "trim_non_auth_subtree(" << dir << ") keeping " << *subdir << dendl; } else { - if (trim_non_auth_subtree(*subdir)) + if (trim_non_auth_subtree(subdir)) keep_inode = true; else { - in->close_dirfrag((*subdir)->get_frag()); + in->close_dirfrag(subdir->get_frag()); dir->state_clear(CDir::STATE_COMPLETE); // now incomplete! } } @@ -7332,8 +7305,8 @@ void MDCache::handle_cache_expire(const MCacheExpire::const_ref &m) diri->get_nested_dirfrags(ls); dout(7) << " dir expire on dirfrag " << q.first << " from mds." << from << " while rejoining, inode isn't replicated" << dendl; - for (list::iterator q = ls.begin(); q != ls.end(); ++q) { - dir = *q; + for (const auto& d : ls) { + dir = d; if (dir->is_replica(from)) { dout(7) << " dir expire on " << *dir << " from mds." << from << dendl; dir->remove_replica(from); @@ -7643,8 +7616,7 @@ bool MDCache::shutdown_pass() } migrator->clear_export_queue(); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : ls) { mds_rank_t dest = dir->get_inode()->authority().first; if (dest > 0 && !mds->mdsmap->is_active(dest)) dest = 0; @@ -9693,8 +9665,7 @@ void MDCache::scan_stray_dir(dirfrag_t next) strays[i]->get_dirfrags(ls); } - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : ls) { if (dir->dirfrag() < next) continue; if (!dir->is_complete()) { @@ -10897,20 +10868,17 @@ void MDCache::adjust_dir_fragments(CInode *diri, // did i change the subtree map? if (dir->is_subtree_root()) { // new frags are now separate subtrees - for (list::iterator p = resultfrags.begin(); - p != resultfrags.end(); - ++p) - subtrees[*p].clear(); // new frag is now its own subtree + for (const auto& dir : resultfrags) { + subtrees[dir].clear(); // new frag is now its own subtree + } // was i a bound? if (parent_subtree) { ceph_assert(subtrees[parent_subtree].count(dir)); subtrees[parent_subtree].erase(dir); - for (list::iterator p = resultfrags.begin(); - p != resultfrags.end(); - ++p) { - ceph_assert((*p)->is_subtree_root()); - subtrees[parent_subtree].insert(*p); + for (const auto& dir : resultfrags) { + ceph_assert(dir->is_subtree_root()); + subtrees[parent_subtree].insert(dir); } } @@ -11025,8 +10993,7 @@ bool MDCache::can_fragment(CInode *diri, list& dirs) return false; } - for (list::iterator p = dirs.begin(); p != dirs.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : dirs) { if (dir->state_test(CDir::STATE_FRAGMENTING)) { dout(7) << "can_fragment: already fragmenting " << *dir << dendl; return false; @@ -11174,11 +11141,7 @@ void MDCache::fragment_mark_and_complete(MDRequestRef& mdr) MDSGatherBuilder gather(g_ceph_context); - for (list::iterator p = info.dirs.begin(); - p != info.dirs.end(); - ++p) { - CDir *dir = *p; - + for (const auto& dir : info.dirs) { bool ready = true; if (!dir->is_complete()) { dout(15) << " fetching incomplete " << *dir << dendl; @@ -11222,10 +11185,7 @@ void MDCache::fragment_mark_and_complete(MDRequestRef& mdr) return; } - for (list::iterator p = info.dirs.begin(); - p != info.dirs.end(); - ++p) { - CDir *dir = *p; + for (const auto& dir : info.dirs) { if (!dir->is_frozen_dir()) { ceph_assert(dir->is_freezing_dir()); dir->add_waiter(CDir::WAIT_FROZEN, gather.new_sub()); @@ -11245,8 +11205,7 @@ void MDCache::fragment_mark_and_complete(MDRequestRef& mdr) void MDCache::fragment_unmark_unfreeze_dirs(list& dirs) { dout(10) << "fragment_unmark_unfreeze_dirs " << dirs << dendl; - for (list::iterator p = dirs.begin(); p != dirs.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : dirs) { dout(10) << " frag " << *dir << dendl; ceph_assert(dir->state_test(CDir::STATE_FRAGMENTING)); @@ -11314,10 +11273,8 @@ void MDCache::find_stale_fragment_freeze() continue; CDir *dir; int total_auth_pins = 0; - for (list::iterator q = info.dirs.begin(); - q != info.dirs.end(); - ++q) { - dir = *q; + for (const auto& d : info.dirs) { + dir = d; if (!dir->state_test(CDir::STATE_DNPINNEDFRAG)) { total_auth_pins = -1; break; @@ -11455,8 +11412,7 @@ void MDCache::dispatch_fragment_dir(MDRequestRef& mdr) EFragment *le = new EFragment(mds->mdlog, EFragment::OP_PREPARE, basedirfrag, info.bits); mds->mdlog->start_entry(le); - for (list::iterator p = info.dirs.begin(); p != info.dirs.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : info.dirs) { dirfrag_rollback rollback; rollback.fnode = dir->fnode; le->add_orig_frag(dir->get_frag(), &rollback); @@ -11474,14 +11430,12 @@ void MDCache::dispatch_fragment_dir(MDRequestRef& mdr) ceph_assert(!diri->dirfragtree.is_leaf(fg)); le->metablob.add_dir_context(*info.resultfrags.begin()); - for (list::iterator p = info.resultfrags.begin(); - p != info.resultfrags.end(); - ++p) { + for (const auto& dir : info.resultfrags) { if (diri->is_auth()) { - le->metablob.add_fragmented_dir(*p, false, false); + le->metablob.add_fragmented_dir(dir, false, false); } else { - (*p)->state_set(CDir::STATE_DIRTYDFT); - le->metablob.add_fragmented_dir(*p, false, true); + dir->state_set(CDir::STATE_DIRTYDFT); + le->metablob.add_fragmented_dir(dir, false, true); } } @@ -11533,10 +11487,7 @@ void MDCache::_fragment_logged(MDRequestRef& mdr) // store resulting frags MDSGatherBuilder gather(g_ceph_context, new C_MDC_FragmentStore(this, mdr)); - for (list::iterator p = info.resultfrags.begin(); - p != info.resultfrags.end(); - ++p) { - CDir *dir = *p; + for (const auto& dir : info.resultfrags) { dout(10) << " storing result frag " << *dir << dendl; // freeze and store them too @@ -11593,10 +11544,9 @@ void MDCache::_fragment_stored(MDRequestRef& mdr) } // freshly replicate new dirs to peers - for (list::iterator q = info.resultfrags.begin(); - q != info.resultfrags.end(); - ++q) - replicate_dir(*q, p.first, notify->basebl); + for (const auto& dir : info.resultfrags) { + replicate_dir(dir, p.first, notify->basebl); + } mds->send_message_mds(notify, p.first); } @@ -11607,10 +11557,7 @@ void MDCache::_fragment_stored(MDRequestRef& mdr) // unfreeze resulting frags - for (list::iterator p = info.resultfrags.begin(); - p != info.resultfrags.end(); - ++p) { - CDir *dir = *p; + for (const auto& dir : info.resultfrags) { dout(10) << " result frag " << *dir << dendl; for (auto &p : dir->items) { @@ -11780,8 +11727,9 @@ void MDCache::handle_fragment_notify(const MMDSFragmentNotify::const_ref ¬ify if (g_conf()->mds_debug_frag) diri->verify_dirfrags(); - for (list::iterator p = resultfrags.begin(); p != resultfrags.end(); ++p) - diri->take_dir_waiting((*p)->get_frag(), waiters); + for (const auto& dir : resultfrags) { + diri->take_dir_waiting(dir->get_frag(), waiters); + } // add new replica dirs values auto p = notify->basebl.cbegin(); @@ -11996,8 +11944,9 @@ void MDCache::show_subtrees(int dbl) set seen; // calc max depth - for (list::iterator p = basefrags.begin(); p != basefrags.end(); ++p) - q.push_back(pair(*p, 0)); + for (const auto& dir : basefrags) { + q.emplace_back(dir, 0); + } set subtrees_seen; @@ -12032,8 +11981,9 @@ void MDCache::show_subtrees(int dbl) // print tree - for (list::iterator p = basefrags.begin(); p != basefrags.end(); ++p) - q.push_back(pair(*p, 0)); + for (const auto& dir : basefrags) { + q.emplace_back(dir, 0); + } while (!q.empty()) { CDir *dir = q.front().first; @@ -12115,8 +12065,7 @@ void MDCache::show_cache() // dirfrags? list dfs; in->get_dirfrags(dfs); - for (list::iterator p = dfs.begin(); p != dfs.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : dfs) { dout(7) << " dirfrag " << *dir << dendl; for (auto &p : dir->items) { diff --git a/src/mds/MDSAuthCaps.cc b/src/mds/MDSAuthCaps.cc index 949ac62c0c43..adafa0279533 100644 --- a/src/mds/MDSAuthCaps.cc +++ b/src/mds/MDSAuthCaps.cc @@ -214,27 +214,25 @@ bool MDSAuthCaps::is_capable(std::string_view inode_path, << " new " << new_uid << ":" << new_gid << " cap: " << *this << dendl; - for (std::vector::const_iterator i = grants.begin(); - i != grants.end(); - ++i) { - if (i->network.size() && - (!i->network_valid || - !network_contains(i->network_parsed, - i->network_prefix, + for (const auto& grant : grants) { + if (grant.network.size() && + (!grant.network_valid || + !network_contains(grant.network_parsed, + grant.network_prefix, addr))) { continue; } - if (i->match.match(inode_path, caller_uid, caller_gid, caller_gid_list) && - i->spec.allows(mask & (MAY_READ|MAY_EXECUTE), mask & MAY_WRITE)) { + if (grant.match.match(inode_path, caller_uid, caller_gid, caller_gid_list) && + grant.spec.allows(mask & (MAY_READ|MAY_EXECUTE), mask & MAY_WRITE)) { // we have a match; narrow down GIDs to those specifically allowed here vector gids; - if (std::find(i->match.gids.begin(), i->match.gids.end(), caller_gid) != - i->match.gids.end()) { + if (std::find(grant.match.gids.begin(), grant.match.gids.end(), caller_gid) != + grant.match.gids.end()) { gids.push_back(caller_gid); } if (caller_gid_list) { - std::set_intersection(i->match.gids.begin(), i->match.gids.end(), + std::set_intersection(grant.match.gids.begin(), grant.match.gids.end(), caller_gid_list->begin(), caller_gid_list->end(), std::back_inserter(gids)); std::sort(gids.begin(), gids.end()); @@ -243,19 +241,19 @@ bool MDSAuthCaps::is_capable(std::string_view inode_path, // Spec is non-allowing if caller asked for set pool but spec forbids it if (mask & MAY_SET_VXATTR) { - if (!i->spec.allow_set_vxattr()) { + if (!grant.spec.allow_set_vxattr()) { continue; } } if (mask & MAY_SNAPSHOT) { - if (!i->spec.allow_snapshot()) { + if (!grant.spec.allow_snapshot()) { continue; } } // check unix permissions? - if (i->match.uid == MDSCapMatch::MDS_AUTH_UID_ANY) { + if (grant.match.uid == MDSCapMatch::MDS_AUTH_UID_ANY) { return true; } @@ -345,8 +343,8 @@ bool MDSAuthCaps::parse(CephContext *c, std::string_view str, ostream *err) bool MDSAuthCaps::allow_all() const { - for (std::vector::const_iterator i = grants.begin(); i != grants.end(); ++i) { - if (i->match.is_match_all() && i->spec.allow_all()) { + for (const auto& grant : grants) { + if (grant.match.is_match_all() && grant.spec.allow_all()) { return true; } } @@ -367,12 +365,12 @@ ostream &operator<<(ostream &out, const MDSCapMatch &match) out << "uid=" << match.uid; if (!match.gids.empty()) { out << " gids="; - for (std::vector::const_iterator p = match.gids.begin(); - p != match.gids.end(); - ++p) { - if (p != match.gids.begin()) + bool first = true; + for (const auto& gid : match.gids) { + if (!first) out << ','; - out << *p; + out << gid; + first = false; } } } diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index 847e2e0d47e1..6a1a431e1457 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -1783,8 +1783,7 @@ uint64_t Migrator::encode_export_dir(bufferlist& exportbl, // directory? list dfs; in->get_dirfrags(dfs); - for (list::iterator p = dfs.begin(); p != dfs.end(); ++p) { - CDir *t = *p; + for (const auto& t : dfs) { if (!t->state_test(CDir::STATE_EXPORTBOUND)) { // include nested dirfrag ceph_assert(t->get_dir_auth().first == CDIR_AUTH_PARENT); @@ -1846,8 +1845,9 @@ void Migrator::finish_export_dir(CDir *dir, mds_rank_t peer, } // subdirs - for (list::iterator it = subdirs.begin(); it != subdirs.end(); ++it) - finish_export_dir(*it, peer, peer_imported, finished, num_dentries); + for (const auto& dir : subdirs) { + finish_export_dir(dir, peer, peer_imported, finished, num_dentries); + } } class C_MDS_ExportFinishLogged : public MigratorLogContext { @@ -2827,9 +2827,10 @@ void Migrator::import_reverse(CDir *dir) // non-bounding dir? list dfs; in->get_dirfrags(dfs); - for (list::iterator p = dfs.begin(); p != dfs.end(); ++p) - if (bounds.count(*p) == 0) - q.push_back(*p); + for (const auto& dir : dfs) { + if (bounds.count(dir) == 0) + q.push_back(dir); + } } cache->touch_dentry_bottom(dn); // move dentry to tail of LRU diff --git a/src/mds/Mutation.cc b/src/mds/Mutation.cc index 78f0e8cbb712..a5436257ee35 100644 --- a/src/mds/Mutation.cc +++ b/src/mds/Mutation.cc @@ -199,19 +199,16 @@ void MutationImpl::apply() pop_and_dirty_projected_inodes(); pop_and_dirty_projected_fnodes(); - for (list::iterator p = dirty_cow_inodes.begin(); - p != dirty_cow_inodes.end(); - ++p) - (*p)->_mark_dirty(ls); - for (list >::iterator p = dirty_cow_dentries.begin(); - p != dirty_cow_dentries.end(); - ++p) - p->first->mark_dirty(p->second, ls); + for (const auto& in : dirty_cow_inodes) { + in->_mark_dirty(ls); + } + for (const auto& [dentry, v] : dirty_cow_dentries) { + dentry->mark_dirty(v, ls); + } - for (list::iterator p = updated_locks.begin(); - p != updated_locks.end(); - ++p) - (*p)->mark_dirty(); + for (const auto& lock : updated_locks) { + lock->mark_dirty(); + } } void MutationImpl::cleanup() diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 92a9fdd9eb3c..c55ce145689c 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -2742,29 +2742,27 @@ void Server::handle_slave_auth_pin(MDRequestRef& mdr) // can we auth pin them? if (!fail) { - for (list::iterator p = objects.begin(); - p != objects.end(); - ++p) { - if (!(*p)->is_auth()) { - dout(10) << " not auth for " << **p << dendl; + for (const auto& obj : objects) { + if (!obj->is_auth()) { + dout(10) << " not auth for " << *obj << dendl; fail = true; break; } - if (mdr->is_auth_pinned(*p)) + if (mdr->is_auth_pinned(obj)) continue; - if (!mdr->can_auth_pin(*p)) { + if (!mdr->can_auth_pin(obj)) { if (mdr->slave_request->is_nonblock()) { - dout(10) << " can't auth_pin (freezing?) " << **p << " nonblocking" << dendl; + dout(10) << " can't auth_pin (freezing?) " << *obj << " nonblocking" << dendl; fail = true; wouldblock = true; break; } // wait - dout(10) << " waiting for authpinnable on " << **p << dendl; - (*p)->add_waiter(CDir::WAIT_UNFREEZE, new C_MDS_RetryRequest(mdcache, mdr)); + dout(10) << " waiting for authpinnable on " << *obj << dendl; + obj->add_waiter(CDir::WAIT_UNFREEZE, new C_MDS_RetryRequest(mdcache, mdr)); mdr->drop_local_auth_pins(); - mds->locker->notify_freeze_waiter(*p); + mds->locker->notify_freeze_waiter(obj); return; } } @@ -2795,11 +2793,9 @@ void Server::handle_slave_auth_pin(MDRequestRef& mdr) return; } } - for (list::iterator p = objects.begin(); - p != objects.end(); - ++p) { - dout(10) << "auth_pinning " << **p << dendl; - mdr->auth_pin(*p); + for (const auto& obj : objects) { + dout(10) << "auth_pinning " << *obj << dendl; + mdr->auth_pin(obj); } } @@ -7229,8 +7225,7 @@ bool Server::_dir_is_nonempty_unlocked(MDRequestRef& mdr, CInode *in) list ls; in->get_dirfrags(ls); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : ls) { // is the frag obviously non-empty? if (dir->is_auth()) { if (dir->get_projected_fnode()->fragstat.size()) { @@ -7255,8 +7250,7 @@ bool Server::_dir_is_nonempty(MDRequestRef& mdr, CInode *in) list ls; in->get_dirfrags(ls); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : ls) { const fnode_t *pf = dir->get_projected_fnode(); if (pf->fragstat.size()) { dout(10) << "dir_is_nonempty dirstat has " @@ -8027,8 +8021,7 @@ void Server::_rename_prepare(MDRequestRef& mdr, if (srci->is_dir()) { list ls; srci->get_dirfrags(ls); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : ls) { if (!dir->is_auth()) metablob->renamed_dir_frags.push_back(dir->get_frag()); } @@ -8206,8 +8199,7 @@ void Server::_rename_prepare(MDRequestRef& mdr, // journal new subtrees root dirfrags list ls; srci->get_dirfrags(ls); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : ls) { if (dir->is_auth()) metablob->add_dir(dir, true); } @@ -8743,8 +8735,9 @@ void Server::_logged_slave_rename(MDRequestRef& mdr, list bounds; if (srcdnl->get_inode()->is_dir()) { srcdnl->get_inode()->get_dirfrags(bounds); - for (list::iterator p = bounds.begin(); p != bounds.end(); ++p) - (*p)->state_set(CDir::STATE_EXPORTBOUND); + for (const auto& bound : bounds) { + bound->state_set(CDir::STATE_EXPORTBOUND); + } } map exported_client_map; @@ -8754,8 +8747,9 @@ void Server::_logged_slave_rename(MDRequestRef& mdr, exported_client_map, exported_client_metadata_map); - for (list::iterator p = bounds.begin(); p != bounds.end(); ++p) - (*p)->state_clear(CDir::STATE_EXPORTBOUND); + for (const auto& bound : bounds) { + bound->state_clear(CDir::STATE_EXPORTBOUND); + } encode(exported_client_map, reply->inode_export, mds->mdsmap->get_up_features()); encode(exported_client_metadata_map, reply->inode_export); @@ -9225,8 +9219,7 @@ void Server::do_rename_rollback(bufferlist &rbl, mds_rank_t master, MDRequestRef if (srcdn->authority().first == whoami) { list ls; in->get_dirfrags(ls); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : ls) { if (!dir->is_auth()) le->commit.renamed_dir_frags.push_back(dir->get_frag()); } diff --git a/src/mds/SnapServer.cc b/src/mds/SnapServer.cc index fc1c59b15312..4cd9dea89913 100644 --- a/src/mds/SnapServer.cc +++ b/src/mds/SnapServer.cc @@ -424,8 +424,9 @@ void SnapServer::generate_test_instances(std::list& ls) list snapinfo_instances; SnapInfo::generate_test_instances(snapinfo_instances); SnapInfo populated_snapinfo = *(snapinfo_instances.back()); - for (list::iterator i = snapinfo_instances.begin(); i != snapinfo_instances.end(); ++i) { - delete *i; + for (auto& info : snapinfo_instances) { + delete info; + info = nullptr; } SnapServer *blank = new SnapServer(); diff --git a/src/mds/journal.cc b/src/mds/journal.cc index c428781dd191..93b5ff20cff1 100644 --- a/src/mds/journal.cc +++ b/src/mds/journal.cc @@ -362,9 +362,9 @@ void EMetaBlob::add_dir_context(CDir *dir, int mode) parents.splice(parents.begin(), maybe); dout(20) << "EMetaBlob::add_dir_context final: " << parents << dendl; - for (list::iterator p = parents.begin(); p != parents.end(); ++p) { - ceph_assert((*p)->get_projected_linkage()->is_primary()); - add_dentry(*p, false); + for (const auto& dentry : parents) { + ceph_assert(dentry->get_projected_linkage()->is_primary()); + add_dentry(dentry, false); } } @@ -534,8 +534,7 @@ void EMetaBlob::fullbit::update_inode(MDSRank *mds, CInode *in) if (in->has_dirfrags() && in->authority() == CDIR_AUTH_UNDEF) { list ls; in->get_nested_dirfrags(ls); - for (list::iterator p = ls.begin(); p != ls.end(); ++p) { - CDir *dir = *p; + for (const auto& dir : ls) { if (dir->get_num_any() == 0 && mds->mdcache->can_trim_non_auth_dirfrag(dir)) { dout(10) << " closing empty non-auth dirfrag " << *dir << dendl;