From 3b99cd0ad843074e3bfc62bf1618e6404ec1b541 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Sun, 27 Oct 2013 17:11:11 +0800 Subject: [PATCH] mds: fix readdir end check If the last item in the directory is a remote link and the corresponding inode is not in cache, the readir reply will not contain the last item. But iterator 'it' is equal to dir->end() in this case, it causes the 'end' flag of the readdir reply be set to true. Signed-off-by: Yan, Zheng --- src/mds/Server.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 0c500cdfe63f..6bb3aef7b97f 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -2785,11 +2785,6 @@ void Server::handle_client_readdir(MDRequest *mdr) assert(snapid == CEPH_NOSNAP || snaps->count(snapid)); // just checkin'! } - // build dir contents - bufferlist dnbl; - - CDir::map_t::iterator it = dir->begin(); - unsigned max = req->head.args.readdir.max_entries; if (!max) max = dir->get_num_any(); // whatever, something big. @@ -2807,8 +2802,13 @@ void Server::handle_client_readdir(MDRequest *mdr) int bytes_left = max_bytes - front_bytes; bytes_left -= realm->get_snap_trace().length(); + // build dir contents + bufferlist dnbl; __u32 numfiles = 0; - while (it != dir->end() && numfiles < max) { + __u8 end = (dir->begin() == dir->end()); + for (CDir::map_t::iterator it = dir->begin(); + !end && numfiles < max; + end = (it == dir->end())) { CDentry *dn = it->second; ++it; @@ -2897,7 +2897,6 @@ void Server::handle_client_readdir(MDRequest *mdr) mdcache->lru.lru_touch(dn); } - __u8 end = (it == dir->end()); __u8 complete = (end && offset_str.empty()); // FIXME: what purpose does this serve // finish final blob -- 2.47.3