]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: fix readdir end check 775/head
authorYan, Zheng <zheng.z.yan@intel.com>
Sun, 27 Oct 2013 09:11:11 +0000 (17:11 +0800)
committerYan, Zheng <zheng.z.yan@intel.com>
Tue, 29 Oct 2013 01:48:25 +0000 (09:48 +0800)
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 <zheng.z.yan@intel.com>
src/mds/Server.cc

index 0c500cdfe63f76fa813a3c7ff367d3f2946cd01a..6bb3aef7b97f7b8ff79cdb6ccb2be06628175c12 100644 (file)
@@ -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