Skip to content

Commit

Permalink
mds: don't access mds->mdsmap without holding mds_lock
Browse files Browse the repository at this point in the history
Fixes: https://tracker.ceph.com/issues/47786
Signed-off-by: "Yan, Zheng" <[email protected]>
  • Loading branch information
ukernel committed Nov 15, 2020
1 parent 4dc60e9 commit 23d7900
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
29 changes: 16 additions & 13 deletions src/mds/CDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2164,37 +2164,41 @@ class C_IO_Dir_Committed : public CDirIOContext {

class C_IO_Dir_Commit_Ops : public Context {
public:
C_IO_Dir_Commit_Ops(CDir *d, int pr, bufferlist &&bl,
vector<dentry_key_t> &&r, vector<CDir::dentry_commit_item> &&s,
C_IO_Dir_Commit_Ops(CDir *d, int pr,
vector<CDir::dentry_commit_item> &&s, bufferlist &&bl,
vector<dentry_key_t> &&r,
mempool::mds_co::compact_set<mempool::mds_co::string> &&stale) :
dir(d), op_prio(pr) {
metapool = dir->mdcache->mds->mdsmap->get_metadata_pool();
version = dir->get_version();
is_new = dir->is_new();
to_set.swap(s);
dfts.swap(bl);
to_remove.swap(r);
to_set.swap(s);
stale_items.swap(stale);
}

void finish(int r) override {
dir->_omap_commit_ops(r, op_prio, version, is_new, dfts, to_remove, to_set,
stale_items);
dir->_omap_commit_ops(r, op_prio, metapool, version, is_new, to_set, dfts,
to_remove, stale_items);
}

private:
CDir *dir;
version_t version;
int op_prio;
int64_t metapool;
version_t version;
bool is_new;
vector<CDir::dentry_commit_item> to_set;
bufferlist dfts;
vector<dentry_key_t> to_remove;
vector<CDir::dentry_commit_item> to_set;
mempool::mds_co::compact_set<mempool::mds_co::string> stale_items;
};

// This is not locked by mds_lock
void CDir::_omap_commit_ops(int r, int op_prio, version_t version, bool _new, bufferlist &dfts,
vector<dentry_key_t>& to_remove, vector<dentry_commit_item> &to_set,
void CDir::_omap_commit_ops(int r, int op_prio, int64_t metapool, version_t version, bool _new,
vector<dentry_commit_item> &to_set, bufferlist &dfts,
vector<dentry_key_t>& to_remove,
mempool::mds_co::compact_set<mempool::mds_co::string> &stales)
{
dout(10) << __func__ << dendl;
Expand All @@ -2210,7 +2214,7 @@ void CDir::_omap_commit_ops(int r, int op_prio, version_t version, bool _new, bu

SnapContext snapc;
object_t oid = get_ondisk_object();
object_locator_t oloc(mdcache->mds->mdsmap->get_metadata_pool());
object_locator_t oloc(metapool);

map<string, bufferlist> _set;
set<string> _rm;
Expand Down Expand Up @@ -2414,9 +2418,8 @@ void CDir::_omap_commit(int op_prio)
}
}

auto c = new C_IO_Dir_Commit_Ops(this, op_prio, std::move(dfts),
std::move(to_remove), std::move(to_set),
std::move(stale_items));
auto c = new C_IO_Dir_Commit_Ops(this, op_prio, std::move(to_set), std::move(dfts),
std::move(to_remove), std::move(stale_items));
stale_items.clear();
mdcache->mds->finisher->queue(c);
}
Expand Down
5 changes: 3 additions & 2 deletions src/mds/CDir.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,9 @@ class CDir : public MDSCacheObject, public Counter<CDir> {

// -- commit --
void _commit(version_t want, int op_prio);
void _omap_commit_ops(int r, int op_prio, version_t version, bool _new, bufferlist &bl,
vector<dentry_key_t> &to_remove, vector<dentry_commit_item> &to_set,
void _omap_commit_ops(int r, int op_prio, int64_t metapool, version_t version, bool _new,
vector<dentry_commit_item> &to_set, bufferlist &dfts,
vector<dentry_key_t> &to_remove,
mempool::mds_co::compact_set<mempool::mds_co::string> &_stale);
void _omap_commit(int op_prio);
void _parse_dentry(CDentry *dn, dentry_commit_item &item,
Expand Down

0 comments on commit 23d7900

Please sign in to comment.