From patchwork Sun Nov 16 16:05:34 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 8991 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id B3ADFDDDE0 for ; Mon, 17 Nov 2008 03:23:44 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753513AbYKPQXn (ORCPT ); Sun, 16 Nov 2008 11:23:43 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753531AbYKPQXn (ORCPT ); Sun, 16 Nov 2008 11:23:43 -0500 Received: from www.church-of-our-saviour.ORG ([69.25.196.31]:59004 "EHLO thunker.thunk.org" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753513AbYKPQXi (ORCPT ); Sun, 16 Nov 2008 11:23:38 -0500 Received: from root (helo=closure.thunk.org) by thunker.thunk.org with local-esmtp (Exim 4.50 #1 (Debian)) id 1L1kPR-0000h3-CB; Sun, 16 Nov 2008 11:23:37 -0500 Received: from tytso by closure.thunk.org with local (Exim 4.69) (envelope-from ) id 1L1k84-00029c-Jt; Sun, 16 Nov 2008 11:05:40 -0500 From: Theodore Ts'o To: stable@kernel.org Cc: Ext4 Developers List , Theodore Ts'o Subject: [FOR-STABLE 14/20] ext4: Fix duplicate entries returned from getdents() system call Date: Sun, 16 Nov 2008 11:05:34 -0500 Message-Id: <1226851540-8032-15-git-send-email-tytso@mit.edu> X-Mailer: git-send-email 1.6.0.4.8.g36f27.dirty In-Reply-To: <1226851540-8032-14-git-send-email-tytso@mit.edu> References: <1226851540-8032-1-git-send-email-tytso@mit.edu> <1226851540-8032-2-git-send-email-tytso@mit.edu> <1226851540-8032-3-git-send-email-tytso@mit.edu> <1226851540-8032-4-git-send-email-tytso@mit.edu> <1226851540-8032-5-git-send-email-tytso@mit.edu> <1226851540-8032-6-git-send-email-tytso@mit.edu> <1226851540-8032-7-git-send-email-tytso@mit.edu> <1226851540-8032-8-git-send-email-tytso@mit.edu> <1226851540-8032-9-git-send-email-tytso@mit.edu> <1226851540-8032-10-git-send-email-tytso@mit.edu> <1226851540-8032-11-git-send-email-tytso@mit.edu> <1226851540-8032-12-git-send-email-tytso@mit.edu> <1226851540-8032-13-git-send-email-tytso@mit.edu> <1226851540-8032-14-git-send-email-tytso@mit.edu> X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@mit.edu X-SA-Exim-Scanned: No (on thunker.thunk.org); SAEximRunCond expanded to false Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Fix a regression caused by commit d0156417, "ext4: fix ext4_dx_readdir hash collision handling", where deleting files in a large directory (requiring more than one getdents system call), results in some filenames being returned twice. This was caused by a failure to update info->curr_hash and info->curr_minor_hash, so that if the directory had gotten modified since the last getdents() system call (as would be the case if the user is running "rm -r" or "git clean"), a directory entry would get returned twice to the userspace. Signed-off-by: "Theodore Ts'o" This patch fixes the bug reported by Markus Trippelsdorf at: http://bugzilla.kernel.org/show_bug.cgi?id=11844 Signed-off-by: "Theodore Ts'o" Tested-by: Markus Trippelsdorf (cherry picked from commit 3c37fc86d20fe35be656f070997d62f75c2e4874) --- fs/ext4/dir.c | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index ec8e33b..0f2bbda 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -453,17 +453,8 @@ static int ext4_dx_readdir(struct file * filp, if (info->extra_fname) { if (call_filldir(filp, dirent, filldir, info->extra_fname)) goto finished; - info->extra_fname = NULL; - info->curr_node = rb_next(info->curr_node); - if (!info->curr_node) { - if (info->next_hash == ~0) { - filp->f_pos = EXT4_HTREE_EOF; - goto finished; - } - info->curr_hash = info->next_hash; - info->curr_minor_hash = 0; - } + goto next_node; } else if (!info->curr_node) info->curr_node = rb_first(&info->root); @@ -495,9 +486,14 @@ static int ext4_dx_readdir(struct file * filp, info->curr_minor_hash = fname->minor_hash; if (call_filldir(filp, dirent, filldir, fname)) break; - + next_node: info->curr_node = rb_next(info->curr_node); - if (!info->curr_node) { + if (info->curr_node) { + fname = rb_entry(info->curr_node, struct fname, + rb_hash); + info->curr_hash = fname->hash; + info->curr_minor_hash = fname->minor_hash; + } else { if (info->next_hash == ~0) { filp->f_pos = EXT4_HTREE_EOF; break;