From patchwork Mon Jun 9 12:22:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 4321481 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 62EFF9F433 for ; Mon, 9 Jun 2014 11:22:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8740F2018A for ; Mon, 9 Jun 2014 11:22:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F44B2012D for ; Mon, 9 Jun 2014 11:22:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932428AbaFILWw (ORCPT ); Mon, 9 Jun 2014 07:22:52 -0400 Received: from mail-wg0-f47.google.com ([74.125.82.47]:63699 "EHLO mail-wg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932283AbaFILWv (ORCPT ); Mon, 9 Jun 2014 07:22:51 -0400 Received: by mail-wg0-f47.google.com with SMTP id k14so4582444wgh.18 for ; Mon, 09 Jun 2014 04:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=+bYH5Jxkbo4NZ9QbM6UIa5eLtmCP9YiE0MKz0H9fRqk=; b=fyIoJcJjY8Slw9ZIob7E5lhqi3npFUTcFybuSrOLPKqf6sJC76JT1cb7JEgt9HrBah wC03GSUSpyhJNE2z5j/ORZjHOYtRsfvHSgRbrvou4wRBqwy2dPf55ohlBAySGamCAi4q BpAVtplhtkfV2/L1bUmQbqu4fmlwUNroJZca2hgPfpHXrtaSE4DoA5sXVLRLtFDiscDt RBx8CQmhHx4XPMJO9Y4Bro0ToPtujAXO09I1Om1cfYl6G7OfRHCqaS/w5o2bE9YCAeKw zmvWI934QF9RAka5MHNaYtvvSN1Nf54i1Xkl0ZTTUJUGYl4L3/bT66A8dB9L/jCqCXAR HE9g== X-Received: by 10.194.108.5 with SMTP id hg5mr30607857wjb.57.1402312970000; Mon, 09 Jun 2014 04:22:50 -0700 (PDT) Received: from debian-vm3.lan (bl10-253-137.dsl.telepac.pt. [85.243.253.137]) by mx.google.com with ESMTPSA id l5sm14165326wif.22.2014.06.09.04.22.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Jun 2014 04:22:49 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs: ensure btrfs_prev_leaf doesn't miss 1 item Date: Mon, 9 Jun 2014 13:22:13 +0100 Message-Id: <1402316533-18089-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 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 We might have had an item with the previous key in the tree right before we released our path. And after we released our path, that item might have been pushed to the first slot (0) of the leaf we were holding due to a tree balance. Alternatively, an item with the previous key can exist as the only element of a leaf (big fat item). Therefore account for these 2 cases, so that our callers (like btrfs_previous_item) don't miss an existing item with a key matching the previous key we computed above. Signed-off-by: Filipe David Borba Manana --- fs/btrfs/ctree.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index d99d965..4eada52 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -5097,7 +5097,17 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path) return ret; btrfs_item_key(path->nodes[0], &found_key, 0); ret = comp_keys(&found_key, &key); - if (ret < 0) + /* + * We might have had an item with the previous key in the tree right + * before we released our path. And after we released our path, that + * item might have been pushed to the first slot (0) of the leaf we + * were holding due to a tree balance. Alternatively, an item with the + * previous key can exist as the only element of a leaf (big fat item). + * Therefore account for these 2 cases, so that our callers (like + * btrfs_previous_item) don't miss an existing item with a key matching + * the previous key we computed above. + */ + if (ret <= 0) return 0; return 1; }