From: Yan, Zheng Date: Fri, 27 Apr 2018 01:13:51 +0000 (+0800) Subject: client: fix race in concurrent readdir X-Git-Tag: v14.0.0~192^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=01e23c178d068a3983c58cf115d57f6e1cc06255;p=ceph-ci.git client: fix race in concurrent readdir For a large directory, program needs to issue multiple readdir syscalls to get all dentries. When there are multiple programs read the directory concurrently. Following sequence of events can happen. - program calls readdir with pos = 2. ceph sends readdir request to mds. The reply contains N1 entries. ceph adds these N1 entries to readdir cache. - program calls readdir with pos = N1+2. The readdir is satisfied by the readdir cache, N2 entries are returned. (Other program calls readdir in the middle, which fills the cache) - program calls readdir with pos = N1+N2+2. ceph sends readdir request to mds. The reply contains N3 entries and it reaches directory end. ceph adds these N3 entries to the readdir cache and marks directory complete. The second readdir call does not update dirp->cache_index. ceph adds the last N3 entries to wrong places. Signed-off-by: "Yan, Zheng" Fixes: http://tracker.ceph.com/issues/23894 --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 131f80ce451..9991d578fac 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7717,6 +7717,7 @@ int Client::_readdir_cache_cb(dir_result_t *dirp, add_dirent_cb_t cb, void *p, else dirp->next_offset = dirp->offset_low(); dirp->last_name = dn_name; // we successfully returned this one; update! + dirp->release_count = 0; // last_name no longer match cache index if (r > 0) return r; }