From patchwork Sat Jan 11 21:28:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 3470391 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 63BE69F2E9 for ; Sat, 11 Jan 2014 21:29:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A371E20103 for ; Sat, 11 Jan 2014 21:29:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9BF7200F2 for ; Sat, 11 Jan 2014 21:29:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750876AbaAKV3M (ORCPT ); Sat, 11 Jan 2014 16:29:12 -0500 Received: from mail-wg0-f53.google.com ([74.125.82.53]:48594 "EHLO mail-wg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800AbaAKV3L (ORCPT ); Sat, 11 Jan 2014 16:29:11 -0500 Received: by mail-wg0-f53.google.com with SMTP id k14so5404723wgh.32 for ; Sat, 11 Jan 2014 13:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=tSyGaVuHBBpKINtSVIrxIbnr+MA16uAwuq+p6N83KcA=; b=HFFGSYgC0zJBCZ30ZU2KQilIfSQvvD4SFm7Bgv0J/aKpuVOIkyG9OA+id4RcrX/6b/ m9/N9JEAIFLEw5K+A+d3BdEtnpnVgfvb0BdhwMF1eLg1uh3u8CAVZOzFedJX8IwHIHCV JhLudku3gItsbnV6D1nhweIrs8zvhE+lMZ91b0BFqgQS59UWgZ+hXlAp9XZVs+EfJjJi GsKqnd96Pd9HQoY3hhRs5bHCL8xlWf3Jll93FdsmidMHo3MVRa+fchTfGKWAFo6oFd5R ill0t49RgtJWhdXPs+iN1D6U8vdXzC0+WJOs1GD4atTnPnuGSAMxmGeS0g5D3M1bym2O Vdvg== X-Received: by 10.180.86.198 with SMTP id r6mr8405713wiz.27.1389475750165; Sat, 11 Jan 2014 13:29:10 -0800 (PST) Received: from storm-desktop.lan (bl10-142-79.dsl.telepac.pt. [85.243.142.79]) by mx.google.com with ESMTPSA id pk8sm9470228wic.6.2014.01.11.13.29.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 11 Jan 2014 13:29:09 -0800 (PST) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs: fix btrfs_search_slot_for_read backwards iteration Date: Sat, 11 Jan 2014 21:28:54 +0000 Message-Id: <1389475734-19236-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the current path's leaf slot is 0, we do search for the previous leaf (via btrfs_prev_leaf) and set the new path's leaf slot to a value corresponding to the number of items - 1 of the former leaf. Fix this by using the slot set by btrfs_prev_leaf, decrementing it by 1 if it's equal to the leaf's number of items. Use of btrfs_search_slot_for_read() for backward iteration is used in particular by the send feature, which could miss items when the input leaf has less items than its previous leaf. This could be reproduced by running btrfs/007 from xfstests in a loop. Signed-off-by: Filipe David Borba Manana --- fs/btrfs/ctree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 9e9de68..7f4fe10 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -3142,7 +3142,9 @@ again: if (ret < 0) return ret; if (!ret) { - p->slots[0] = btrfs_header_nritems(leaf) - 1; + leaf = p->nodes[0]; + if (p->slots[0] == btrfs_header_nritems(leaf)) + p->slots[0]--; return 0; } if (!return_any)