From patchwork Mon Oct 8 12:30:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10630603 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DF52933 for ; Mon, 8 Oct 2018 12:31:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 761B228F69 for ; Mon, 8 Oct 2018 12:31:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73D4428F54; Mon, 8 Oct 2018 12:31:01 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 1C52128F3F for ; Mon, 8 Oct 2018 12:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726582AbeJHTm3 (ORCPT ); Mon, 8 Oct 2018 15:42:29 -0400 Received: from mx2.suse.de ([195.135.220.15]:60272 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726056AbeJHTm3 (ORCPT ); Mon, 8 Oct 2018 15:42:29 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A462FAFDB for ; Mon, 8 Oct 2018 12:30:58 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v3 4/6] btrfs-progs: lowmem check: Add dev_item check for used bytes and total bytes Date: Mon, 8 Oct 2018 20:30:42 +0800 Message-Id: <20181008123044.13413-5-wqu@suse.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181008123044.13413-1-wqu@suse.com> References: <20181008123044.13413-1-wqu@suse.com> MIME-Version: 1.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 Obviously, used bytes can't be larger than total bytes. Signed-off-by: Qu Wenruo --- check/mode-lowmem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index 07c03cad77af..1173b963b8f3 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -4074,6 +4074,11 @@ static int check_dev_item(struct btrfs_fs_info *fs_info, used = btrfs_device_bytes_used(eb, dev_item); total_bytes = btrfs_device_total_bytes(eb, dev_item); + if (used > total_bytes) { + error("device %llu has incorrect used bytes %llu > total bytes %llu", + dev_id, used, total_bytes); + return ACCOUNTING_MISMATCH; + } key.objectid = dev_id; key.type = BTRFS_DEV_EXTENT_KEY; key.offset = 0;