From: Yan, Zheng Date: Fri, 9 Aug 2019 08:09:58 +0000 (+0800) Subject: mds: change MDCache::path_traverse()'s 'onfail' argument to flags X-Git-Tag: v15.1.0~766^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e9f94dd4c6f68bb58cd9beea8a53b2d04ff17618;p=ceph.git mds: change MDCache::path_traverse()'s 'onfail' argument to flags Later pathes will introduce more flags Signed-off-by: "Yan, Zheng" --- diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index e7472abdf812..4dd949584591 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -8047,17 +8047,16 @@ void MDCache::dispatch(const cref_t &m) } } -int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, // who - const filepath& path, // what - vector *pdnvec, // result - CInode **pin, - int onfail) +int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, + const filepath& path, int flags, + vector *pdnvec, CInode **pin) { - bool discover = (onfail == MDS_TRAVERSE_DISCOVER); - bool null_okay = (onfail == MDS_TRAVERSE_DISCOVERXLOCK); - bool forward = (onfail == MDS_TRAVERSE_FORWARD); + bool discover = (flags & MDS_TRAVERSE_DISCOVER); + bool forward = !discover; + bool last_xlocked = (flags & MDS_TRAVERSE_LAST_XLOCKED); - ceph_assert(!forward || mdr); // forward requires a request + if (forward) + ceph_assert(mdr); // forward requires a request snapid_t snapid = CEPH_NOSNAP; if (mdr) @@ -8156,7 +8155,7 @@ int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, // who // discover? dout(10) << "traverse: need dirfrag " << fg << ", doing discover from " << *cur << dendl; discover_path(cur, snapid, path.postfixpath(depth), cf.build(), - null_okay); + last_xlocked); if (mds->logger) mds->logger->inc(l_mds_traverse_discover); return 1; } @@ -8193,7 +8192,7 @@ int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, // who CDentry::linkage_t *dnl = dn ? dn->get_projected_linkage() : 0; // null and last_bit and xlocked by me? - if (dnl && dnl->is_null() && null_okay) { + if (dnl && dnl->is_null() && last_xlocked) { dout(10) << "traverse: hit null dentry at tail of traverse, succeeding" << dendl; if (pdnvec) pdnvec->push_back(dn); @@ -8253,7 +8252,7 @@ int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, // who return -EIO; } open_remote_dentry(dn, true, cf.build(), - (null_okay && depth == path.depth() - 1)); + (last_xlocked && depth == path.depth() - 1)); if (mds->logger) mds->logger->inc(l_mds_traverse_remote_ino); return 1; } @@ -8339,10 +8338,10 @@ int MDCache::path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, // who discover = true; } - if ((discover || null_okay)) { + if ((discover)) { dout(7) << "traverse: discover from " << path[depth] << " from " << *curdir << dendl; discover_path(curdir, snapid, path.postfixpath(depth), cf.build(), - null_okay); + last_xlocked); if (mds->logger) mds->logger->inc(l_mds_traverse_discover); return 1; } @@ -9164,7 +9163,7 @@ void MDCache::handle_find_ino_reply(const cref_t &m) vector trace; CF_MDS_RetryMessageFactory cf(mds, m); MDRequestRef null_ref; - int r = path_traverse(null_ref, cf, m->path, &trace, NULL, MDS_TRAVERSE_DISCOVER); + int r = path_traverse(null_ref, cf, m->path, MDS_TRAVERSE_DISCOVER, &trace); if (r > 0) return; dout(0) << "handle_find_ino_reply failed with " << r << " on " << m->path @@ -10721,7 +10720,7 @@ void MDCache::handle_dir_update(const cref_t &m) dout(5) << "trying discover on dir_update for " << path << dendl; CF_MDS_RetryMessageFactory cf(mds, m); MDRequestRef null_ref; - int r = path_traverse(null_ref, cf, path, &trace, &in, MDS_TRAVERSE_DISCOVER); + int r = path_traverse(null_ref, cf, path, MDS_TRAVERSE_DISCOVER, &trace, &in); if (r > 0) return; if (r == 0 && diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index abed6a6d26e3..d416d0fb9cf5 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -110,6 +110,9 @@ enum { l_mdc_last, }; +// flags for path_traverse(); +static const int MDS_TRAVERSE_DISCOVER = (1 << 0); +static const int MDS_TRAVERSE_LAST_XLOCKED = (1 << 1); // flags for predirty_journal_parents() static const int PREDIRTY_PRIMARY = 1; // primary dn, adjust nested accounting @@ -759,19 +762,21 @@ class MDCache { * @param mdr The MDRequest associated with the path. Can be null. * @param cf A MDSContextFactory for waiter building. * @param path The path to traverse to. + * + * @param flags Specifies different lookup behaviors. + * By default, path_traverse() forwards the request to the auth MDS if that + * is appropriate (ie, if it doesn't know the contents of a directory). + * 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). + * * @param pdnvec Data return parameter -- on success, contains a * vector of dentries. On failure, is either empty or contains the * full trace of traversable dentries. * @param pin Data return parameter -- if successful, points to the inode * associated with filepath. If unsuccessful, is null. - * @param onfail Specifies different lookup failure behaviors. If set to - * MDS_TRAVERSE_DISCOVERXLOCK, path_traverse will succeed on null - * dentries (instead of returning -ENOENT). If set to - * MDS_TRAVERSE_FORWARD, it will forward the request to the auth - * MDS if that becomes appropriate (ie, if it doesn't know the contents - * of a directory). If set to MDS_TRAVERSE_DISCOVER, it - * will attempt to look up the path from a different MDS (and bring them - * into its cache as replicas). * * @returns 0 on success, 1 on "not done yet", 2 on "forwarding", -errno otherwise. * If it returns 1, the requester associated with this call has been placed @@ -779,8 +784,9 @@ class MDCache { * If it returns 2 the request has been forwarded, and again the requester * should unwind itself and back out. */ - int path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, const filepath& path, - vector *pdnvec, CInode **pin, int onfail); + int path_traverse(MDRequestRef& mdr, MDSContextFactory& cf, + const filepath& path, int flags, + vector *pdnvec, CInode **pin=nullptr); CInode *cache_traverse(const filepath& path); diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index a9b6b80b7f0c..d717f3b1ddf5 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -2302,7 +2302,7 @@ void Migrator::handle_export_discover(const cref_t &m, bool filepath fpath(m->get_path()); vector trace; MDRequestRef null_ref; - int r = cache->path_traverse(null_ref, cf, fpath, &trace, NULL, MDS_TRAVERSE_DISCOVER); + int r = cache->path_traverse(null_ref, cf, fpath, MDS_TRAVERSE_DISCOVER, &trace); if (r > 0) return; if (r < 0) { dout(7) << "handle_export_discover failed to discover or not dir " << m->get_path() << ", NAK" << dendl; diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 2e50ccbdb7da..ae83a48d53cb 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -3390,7 +3390,7 @@ CDir *Server::traverse_to_auth_dir(MDRequestRef& mdr, vector &trace, f // traverse to parent dir CInode *diri; CF_MDS_MDRContextFactory cf(mdcache, mdr); - int r = mdcache->path_traverse(mdr, cf, refpath, &trace, &diri, MDS_TRAVERSE_FORWARD); + int r = mdcache->path_traverse(mdr, cf, refpath, 0, &trace, &diri); if (r > 0) return 0; // delayed if (r < 0) { if (r == -ESTALE) { @@ -3429,7 +3429,7 @@ CInode* Server::rdlock_path_pin_ref(MDRequestRef& mdr, int n, // traverse CF_MDS_MDRContextFactory cf(mdcache, mdr); - int r = mdcache->path_traverse(mdr, cf, refpath, &mdr->dn[n], &mdr->in[n], MDS_TRAVERSE_FORWARD); + int r = mdcache->path_traverse(mdr, cf, refpath, 0, &mdr->dn[n], &mdr->in[n]); if (r > 0) return NULL; // delayed if (r < 0) { // error @@ -4199,8 +4199,7 @@ void Server::handle_client_openc(MDRequestRef& mdr) if (!excl) { CF_MDS_MDRContextFactory cf(mdcache, mdr); - int r = mdcache->path_traverse(mdr, cf, req->get_filepath(), - &mdr->dn[0], NULL, MDS_TRAVERSE_FORWARD); + int r = mdcache->path_traverse(mdr, cf, req->get_filepath(), 0, &mdr->dn[0]); if (r > 0) return; if (r == 0) { // it existed. @@ -6749,7 +6748,7 @@ void Server::handle_client_unlink(MDRequestRef& mdr) vector trace; CInode *in; CF_MDS_MDRContextFactory cf(mdcache, mdr); - int r = mdcache->path_traverse(mdr, cf, refpath, &trace, &in, MDS_TRAVERSE_FORWARD); + int r = mdcache->path_traverse(mdr, cf, refpath, 0, &trace, &in); if (r > 0) return; if (r < 0) { if (r == -ESTALE) { @@ -7137,7 +7136,9 @@ void Server::handle_slave_rmdir_prep(MDRequestRef& mdr) dout(10) << " src " << srcpath << dendl; CInode *in; CF_MDS_MDRContextFactory cf(mdcache, mdr); - int r = mdcache->path_traverse(mdr, cf, srcpath, &trace, &in, MDS_TRAVERSE_DISCOVERXLOCK); + int r = mdcache->path_traverse(mdr, cf, srcpath, + MDS_TRAVERSE_DISCOVER | MDS_TRAVERSE_LAST_XLOCKED, + &trace, &in); if (r > 0) return; if (r == -ESTALE) { mdcache->find_ino_peers(srcpath.get_ino(), new C_MDS_RetryRequest(mdcache, mdr), @@ -7533,7 +7534,7 @@ void Server::handle_client_rename(MDRequestRef& mdr) ceph_assert(destdir->is_auth()); CF_MDS_MDRContextFactory cf(mdcache, mdr); - int r = mdcache->path_traverse(mdr, cf, srcpath, &srctrace, NULL, MDS_TRAVERSE_DISCOVER); + int r = mdcache->path_traverse(mdr, cf, srcpath, MDS_TRAVERSE_DISCOVER, &srctrace); if (r > 0) return; // delayed if (r < 0) { @@ -8691,7 +8692,9 @@ void Server::handle_slave_rename_prep(MDRequestRef& mdr) dout(10) << " dest " << destpath << dendl; vector trace; CF_MDS_MDRContextFactory cf(mdcache, mdr); - int r = mdcache->path_traverse(mdr, cf, destpath, &trace, NULL, MDS_TRAVERSE_DISCOVERXLOCK); + int r = mdcache->path_traverse(mdr, cf, destpath, + MDS_TRAVERSE_DISCOVER | MDS_TRAVERSE_LAST_XLOCKED, + &trace); if (r > 0) return; if (r == -ESTALE) { mdcache->find_ino_peers(destpath.get_ino(), new C_MDS_RetryRequest(mdcache, mdr), @@ -8709,7 +8712,9 @@ void Server::handle_slave_rename_prep(MDRequestRef& mdr) filepath srcpath(mdr->slave_request->srcdnpath); dout(10) << " src " << srcpath << dendl; CInode *srci = nullptr; - r = mdcache->path_traverse(mdr, cf, srcpath, &trace, &srci, MDS_TRAVERSE_DISCOVERXLOCK); + r = mdcache->path_traverse(mdr, cf, srcpath, + MDS_TRAVERSE_DISCOVER | MDS_TRAVERSE_LAST_XLOCKED, + &trace, &srci); if (r > 0) return; ceph_assert(r == 0); diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 2485b28a27b9..be5da40dc9c3 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -69,11 +69,6 @@ #define MDS_INO_STRAY_OWNER(i) (signed (((unsigned (i)) - MDS_INO_STRAY_OFFSET) / NUM_STRAY)) #define MDS_INO_STRAY_INDEX(i) (((unsigned (i)) - MDS_INO_STRAY_OFFSET) % NUM_STRAY) -#define MDS_TRAVERSE_FORWARD 1 -#define MDS_TRAVERSE_DISCOVER 2 // skips permissions checks etc. -#define MDS_TRAVERSE_DISCOVERXLOCK 3 // succeeds on (foreign?) null, xlocked dentries. - - typedef int32_t mds_rank_t; constexpr mds_rank_t MDS_RANK_NONE = -1;