From patchwork Thu May 19 08:44:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9124901 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D0D089FCE6 for ; Thu, 19 May 2016 08:44:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 06CF120211 for ; Thu, 19 May 2016 08:44:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D14C20219 for ; Thu, 19 May 2016 08:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754057AbcESIou (ORCPT ); Thu, 19 May 2016 04:44:50 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:27912 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753864AbcESIor (ORCPT ); Thu, 19 May 2016 04:44:47 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="491405" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 19 May 2016 16:44:41 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id D31904056401; Thu, 19 May 2016 16:44:36 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Cc: jbacik@fb.com Subject: [PATCH] btrfs-progs: Enhance tree block check by checking empty leaf or node Date: Thu, 19 May 2016 16:44:35 +0800 Message-Id: <1463647475-22102-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.8.2 MIME-Version: 1.0 X-yoursite-MailScanner-ID: D31904056401.AAB3A X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For btrfs, it's possible to have empty leaf, but empty node is not possible. Add check for empty node for tree blocks. Suggested-by: Josef Bacik Signed-off-by: Qu Wenruo --- disk-io.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/disk-io.c b/disk-io.c index 86abdeb..b4f185f 100644 --- a/disk-io.c +++ b/disk-io.c @@ -67,6 +67,11 @@ static int check_tree_block(struct btrfs_fs_info *fs_info, nodesize)) return BTRFS_BAD_NRITEMS; + /* Only leaf can be empty */ + if (btrfs_header_nritems(buf) == 0 && + btrfs_header_level(buf) != 0) + return BTRFS_BAD_NRITEMS; + fs_devices = fs_info->fs_devices; while (fs_devices) { if (fs_info->ignore_fsid_mismatch ||