From patchwork Sun Sep 17 19:50:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 9955053 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 77A4B60208 for ; Sun, 17 Sep 2017 19:51:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C87E28329 for ; Sun, 17 Sep 2017 19:51:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 617F628464; Sun, 17 Sep 2017 19:51:03 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 6F686286B3 for ; Sun, 17 Sep 2017 19:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751842AbdIQTuh (ORCPT ); Sun, 17 Sep 2017 15:50:37 -0400 Received: from smtp-16-i6.italiaonline.it ([213.209.14.16]:39832 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751821AbdIQTuf (ORCPT ); Sun, 17 Sep 2017 15:50:35 -0400 Received: from venice.bhome ([94.38.17.243]) by smtp-16.iol.local with SMTP id tfaKdHEzOa91btfaLdAY60; Sun, 17 Sep 2017 21:50:34 +0200 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1505677834; bh=/A8mLG3CPflNl/3IR3kx5jdpRoAyzsCLmHamHU0P6BA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BIYkMYHUcdbDdwgx2WJ3keBLH1+zmMiprURPaOrSXSFQQrkF7Pv8sDSctF72jWdcf 7kjRVkthFsgpk6qzQx/ZObPUHV+hYTpBzt3Bxstk06pkAZS++PxYlUhuOIvcwS+pAy sg85ysy6Cd7P5GM0uSZwNwkWm9w9qwecaUnSWns6iWmk0e9xPIaDVkxrr6ZZY9U12K 7l78D0reeSIyT6So0PpzOk5XymLY7sYaiBd5qimMjU34tzHK2i+EpPLhJe+1vrx/rO LCFyOeStUPHge4enacVhkPAR4bEr4kdyBQEOTJSkzpUD72tDkV3mtUZMzdd0uoo3Rf jxDe/muIn7rqA== X-CNFS-Analysis: v=2.2 cv=TYHmjVYh c=1 sm=1 tr=0 a=Fz84JiIh2tkFF2c4z3Y6CQ==:117 a=Fz84JiIh2tkFF2c4z3Y6CQ==:17 a=F8ThwK_sxisubfsOV6QA:9 From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: David Sterba , Goffredo Baroncelli Subject: [PATCH] load_chunk_info() : wrong search key 'type' Date: Sun, 17 Sep 2017 21:50:28 +0200 Message-Id: <20170917195028.3124-2-kreijack@libero.it> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170917195028.3124-1-kreijack@libero.it> References: <20170917195028.3124-1-kreijack@libero.it> X-CMAE-Envelope: MS4wfKVomEjy40OtxOMaxSHohLXSwLQREVV5DGxLCjlnf4rBgj+ClYg7HMubsArtZ4Dg1Nvmi4+7Q6PoUiXZswu8toDcQk4FEoNjzW0G8D0Qz9Ee8NlNFVFH 9wvRFVV2zu4Tw0rFVi/L6diLs4JzO26jcu6gIxHvclOy5yPxP7sSVhEMNIYeWsCxUN4DoD3YNjIJGXZFYN9+crlqm0gf0dxv/4paGyEgz3yAsaiFMXYdBrpI dq51TvaQtiiK0xyKS0TGuQ== 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 From: Goffredo Baroncelli The function load_chunk_info() doesn't initialize correctly the sk->min/max_type when it calls the TREE_SEARCH ioctl: these keys are swapped. Moreover this function assumes that all the items contained in the tree BTRFS_CHUNK_TREE_OBJECTID are of type BTRFS_CHUNK_ITEM_KEY, however some items are of type DEV_ITEM. Add an if( ) to pick only the right ones. Signed-off-by: G.Baroncelli --- cmds-fi-usage.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c index 6c846c15..52d63524 100644 --- a/cmds-fi-usage.c +++ b/cmds-fi-usage.c @@ -147,8 +147,8 @@ static int load_chunk_info(int fd, struct chunk_info **info_ptr, int *info_count sk->min_objectid = 0; sk->max_objectid = (u64)-1; - sk->max_type = 0; - sk->min_type = (u8)-1; + sk->min_type = 0; + sk->max_type = (u8)-1; sk->min_offset = 0; sk->max_offset = (u64)-1; sk->min_transid = 0; @@ -174,20 +174,21 @@ static int load_chunk_info(int fd, struct chunk_info **info_ptr, int *info_count off = 0; for (i = 0; i < sk->nr_items; i++) { struct btrfs_chunk *item; + u8 type; sh = (struct btrfs_ioctl_search_header *)(args.buf + off); - + type = btrfs_search_header_type(sh); off += sizeof(*sh); - item = (struct btrfs_chunk *)(args.buf + off); - - ret = add_info_to_list(info_ptr, info_count, item); - if (ret) { - *info_ptr = NULL; - return 1; + if (type == BTRFS_CHUNK_ITEM_KEY) { + item = (struct btrfs_chunk *)(args.buf + off); + ret = add_info_to_list(info_ptr, info_count, item); + if (ret) { + *info_ptr = NULL; + return 1; + } } off += btrfs_search_header_len(sh); - sk->min_objectid = btrfs_search_header_objectid(sh); sk->min_type = btrfs_search_header_type(sh); sk->min_offset = btrfs_search_header_offset(sh)+1;