From patchwork Thu Nov 10 15:01:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 9421171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B24E7601C0 for ; Thu, 10 Nov 2016 15:02:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4F8729760 for ; Thu, 10 Nov 2016 15:02:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 994E029762; Thu, 10 Nov 2016 15:02:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25CE929760 for ; Thu, 10 Nov 2016 15:02:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933941AbcKJPB4 (ORCPT ); Thu, 10 Nov 2016 10:01:56 -0500 Received: from mx2.suse.de ([195.135.220.15]:38184 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933808AbcKJPBz (ORCPT ); Thu, 10 Nov 2016 10:01:55 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AA299ACB2 for ; Thu, 10 Nov 2016 15:01:54 +0000 (UTC) From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [PATCH] Return best entry, if it is the first one Date: Thu, 10 Nov 2016 09:01:46 -0600 Message-Id: <20161110150147.19766-1-rgoldwyn@suse.de> X-Mailer: git-send-email 2.10.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The find_most_right_entry() tends to miss on the best entry if it is the first one on the list and there are only two entries in the list. So, we assign both prev and best to entry. To do this, the selection process (rather the rejection) has to be performed earlier to skip on broken==count. Signed-off-by: Goldwyn Rodrigues --- cmds-check.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index 368c1c5..779870a 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -8184,11 +8184,6 @@ static struct extent_entry *find_most_right_entry(struct list_head *entries) struct extent_entry *entry, *best = NULL, *prev = NULL; list_for_each_entry(entry, entries, list) { - if (!prev) { - prev = entry; - continue; - } - /* * If there are as many broken entries as entries then we know * not to trust this particular entry. @@ -8196,6 +8191,12 @@ static struct extent_entry *find_most_right_entry(struct list_head *entries) if (entry->broken == entry->count) continue; + if (!prev) { + best = entry; + prev = entry; + continue; + } + /* * If our current entry == best then we can't be sure our best * is really the best, so we need to keep searching.