Skip to content

Commit

Permalink
ceph: fix race in concurrent readdir
Browse files Browse the repository at this point in the history
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 fi->readdir_cache_idx.
ceph add the last N3 entries to wrong places.

Cc: stable@vger.kernel.org # v4.3+
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
  • Loading branch information
ukernel committed Jul 6, 2017
1 parent e01aa38 commit 6c51866
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fs/ceph/dir.c
Expand Up @@ -271,6 +271,11 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
if (ret < 0)
err = ret;
dput(last);
/* last_name no longer match cache index */
if (fi->readdir_cache_idx >= 0) {
fi->readdir_cache_idx = -1;
fi->dir_release_count = 0;
}
}
return err;
}
Expand Down

0 comments on commit 6c51866

Please sign in to comment.