From patchwork Thu Jan 30 15:23:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Heift X-Patchwork-Id: 3557781 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 D09A09F39A for ; Thu, 30 Jan 2014 15:24:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 359F9201C0 for ; Thu, 30 Jan 2014 15:24:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2592C2016C for ; Thu, 30 Jan 2014 15:24:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753367AbaA3PYO (ORCPT ); Thu, 30 Jan 2014 10:24:14 -0500 Received: from mail-ea0-f169.google.com ([209.85.215.169]:62164 "EHLO mail-ea0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752636AbaA3PYN (ORCPT ); Thu, 30 Jan 2014 10:24:13 -0500 Received: by mail-ea0-f169.google.com with SMTP id h10so1724914eak.14 for ; Thu, 30 Jan 2014 07:24:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ntwyn8Pbob4ADYMRRJoSK4Qkxjg7MBTXpl+CA3nQOLQ=; b=ZB1td0pxKlcSWmxxU7YqZFdv/ycDybL1mBD7BSCnrCC0slg6KrVltq2eb09WfDYBoe HRu2XV0sz5UaXIvmuB4O0n9zFBxRfkAuvZ01nQfNxwuh/VHCYP/8Z4Dgbn+seNOyAiWd oq614Zl54oFM7tPSAw29p5mDKMKKCcgu064C3EhhulLnLgPxug6AV9Zf75UbkJ45+7b9 NnYlMboDHI0xQqsE9mT5XRrxIQze7dKGZ3TlUHQAzN141YlxfRyVEJHItb5hEUamfWBe 23341qESlL3s5AVyRB/73drOkKsorL67c+i9g/nW1HOFQoQeSkAKxtVaYTwx93vmjwvn Q/zw== X-Gm-Message-State: ALoCoQmwFaN6eXL6WWFcTqCbcbvJ36tKQTH/nfkK8TGlieTkPn2ZG0UVwsldLh5v6KmZlwY1hl4W X-Received: by 10.14.221.4 with SMTP id q4mr17550017eep.47.1391095452021; Thu, 30 Jan 2014 07:24:12 -0800 (PST) Received: from localhost (host-115-115.kawo1.rwth-aachen.de. [134.130.115.115]) by mx.google.com with ESMTPSA id 8sm18302170eef.1.2014.01.30.07.24.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 30 Jan 2014 07:24:11 -0800 (PST) From: Gerhard Heift To: linux-btrfs@vger.kernel.org Subject: [PATCH RFCv4 1/7] btrfs: tree_search: eliminate redundant nr_items check Date: Thu, 30 Jan 2014 16:23:57 +0100 Message-Id: <1391095443-20287-2-git-send-email-Gerhard@Heift.Name> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1391095443-20287-1-git-send-email-Gerhard@Heift.Name> References: <1391095443-20287-1-git-send-email-Gerhard@Heift.Name> 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.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 amount of items reached the given limit of nr_items, we can leave copy_to_sk without updating the key. Also by returning 1 we leave the loop in search_ioctl without rechecking if we reached the given limit. Signed-off-by: Gerhard Heift --- fs/btrfs/ioctl.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 34772cb..b1c5b4f 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1892,7 +1892,7 @@ static noinline int copy_to_sk(struct btrfs_root *root, if (sizeof(sh) + item_len + *sk_offset > BTRFS_SEARCH_ARGS_BUFSIZE) { ret = 1; - goto overflow; + goto out; } sh.objectid = key->objectid; @@ -1914,8 +1914,10 @@ static noinline int copy_to_sk(struct btrfs_root *root, } (*num_found)++; - if (*num_found >= sk->nr_items) - break; + if (*num_found >= sk->nr_items) { + ret = 1; + goto out; + } } advance_key: ret = 0; @@ -1930,7 +1932,7 @@ advance_key: key->objectid++; } else ret = 1; -overflow: +out: return ret; } @@ -1982,7 +1984,7 @@ static noinline int search_ioctl(struct inode *inode, ret = copy_to_sk(root, path, &key, sk, args->buf, &sk_offset, &num_found); btrfs_release_path(path); - if (ret || num_found >= sk->nr_items) + if (ret) break; }