From: Yan, Zheng Date: Mon, 12 Aug 2019 02:09:02 +0000 (+0800) Subject: mds: explictly specify if MDCache::path_traverse() needs to check null dentry X-Git-Tag: v15.1.0~766^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7b8e289f0c0cf6040b91a670c03288b18b478fc3;p=ceph.git mds: explictly specify if MDCache::path_traverse() needs to check null dentry Signed-off-by: "Yan, Zheng" --- diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index d1333a19fa84..18198b0d8084 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -8054,6 +8054,7 @@ int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, bool discover = (flags & MDS_TRAVERSE_DISCOVER); bool forward = !discover; bool last_xlocked = (flags & MDS_TRAVERSE_LAST_XLOCKED); + bool want_dentry = (flags & MDS_TRAVERSE_WANT_DENTRY); if (forward) ceph_assert(mdr); // forward requires a request @@ -8208,19 +8209,14 @@ int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, CDentry::linkage_t *dnl = dn->get_projected_linkage(); // can we conclude ENOENT? if (dnl->is_null()) { - if (pin) - *pin = nullptr; - + dout(10) << "traverse: null+readable dentry at " << *dn << dendl; if (depth == path.depth() - 1) { - if (last_xlocked) { - dout(10) << "traverse: null+tail+xlocked dentry at " << *dn << dendl; + if (want_dentry) break; - } } else { if (pdnvec) pdnvec->clear(); // do not confuse likes of rdlock_path_pin_ref(); } - dout(10) << "traverse: null+readable dentry at " << *dn << dendl; return -ENOENT; } @@ -8263,6 +8259,8 @@ int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, continue; } + ceph_assert(!dn); + // MISS. dentry doesn't exist. dout(12) << "traverse: miss on dentry " << path[depth] << " in " << *curdir << dendl; @@ -8275,24 +8273,26 @@ int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, // file not found if (pdnvec) { // instantiate a null dn? - if (depth < path.depth()-1){ + if (depth < path.depth() - 1) { dout(20) << " didn't traverse full path; not returning pdnvec" << dendl; - dn = NULL; - } else if (dn) { - ceph_abort(); // should have fallen out in ->is_null() check above - } else if (curdir->is_frozen()) { - dout(20) << " not adding null to frozen dir " << dendl; } else if (snapid < CEPH_MAXSNAP) { dout(20) << " not adding null for snapid " << snapid << dendl; + } else if (curdir->is_frozen()) { + dout(7) << "traverse: " << *curdir << " is frozen, waiting" << dendl; + curdir->add_waiter(CDir::WAIT_UNFREEZE, cf.build()); + return 1; } else { // create a null dentry dn = curdir->add_null_dentry(path[depth]); dout(20) << " added null " << *dn << dendl; } - if (dn) + if (dn) { pdnvec->push_back(dn); - else + if (want_dentry) + break; + } else { pdnvec->clear(); // do not confuse likes of rdlock_path_pin_ref(); + } } return -ENOENT; } else { diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index d416d0fb9cf5..0e3f781d5f31 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -113,6 +113,7 @@ enum { // flags for path_traverse(); static const int MDS_TRAVERSE_DISCOVER = (1 << 0); static const int MDS_TRAVERSE_LAST_XLOCKED = (1 << 1); +static const int MDS_TRAVERSE_WANT_DENTRY = (1 << 2); // flags for predirty_journal_parents() static const int PREDIRTY_PRIMARY = 1; // primary dn, adjust nested accounting @@ -769,8 +770,10 @@ class MDCache { * MDS_TRAVERSE_DISCOVER: Instead of forwarding request, path_traverse() * attempts to look up the path from a different MDS (and bring them into * its cache as replicas). - * MDS_TRAVERSE_LAST_XLOCKED: path_traverse() will succeed on xlocked tail - * dentry (return 0 even it's null). + * MDS_TRAVERSE_LAST_XLOCKED: path_traverse() will procceed when xlocked tail + * dentry is encountered. + * MDS_TRAVERSE_WANT_DENTRY: Caller wants tail dentry. Add a null dentry if + * tail dentry does not exist. return 0 even tail dentry is null. * * @param pdnvec Data return parameter -- on success, contains a * vector of dentries. On failure, is either empty or contains the diff --git a/src/mds/Server.cc b/src/mds/Server.cc index ae83a48d53cb..c2a9c27a4cc1 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -8693,7 +8693,7 @@ void Server::handle_slave_rename_prep(MDRequestRef& mdr) vector trace; CF_MDS_MDRContextFactory cf(mdcache, mdr); int r = mdcache->path_traverse(mdr, cf, destpath, - MDS_TRAVERSE_DISCOVER | MDS_TRAVERSE_LAST_XLOCKED, + MDS_TRAVERSE_DISCOVER | MDS_TRAVERSE_LAST_XLOCKED | MDS_TRAVERSE_WANT_DENTRY, &trace); if (r > 0) return; if (r == -ESTALE) { @@ -8718,9 +8718,6 @@ void Server::handle_slave_rename_prep(MDRequestRef& mdr) if (r > 0) return; ceph_assert(r == 0); - // srcpath must not point to a null dentry - ceph_assert(srci != nullptr); - CDentry *srcdn = trace.back(); CDentry::linkage_t *srcdnl = srcdn->get_projected_linkage(); dout(10) << " srcdn " << *srcdn << dendl;