From patchwork Thu Sep 18 04:22:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 4928901 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5307BBEEA6 for ; Thu, 18 Sep 2014 04:22:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EDCF20179 for ; Thu, 18 Sep 2014 04:22:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CDFD201E4 for ; Thu, 18 Sep 2014 04:22:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751378AbaIREWX (ORCPT ); Thu, 18 Sep 2014 00:22:23 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:49483 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751223AbaIREWW (ORCPT ); Thu, 18 Sep 2014 00:22:22 -0400 X-IronPort-AV: E=Sophos;i="5.04,544,1406563200"; d="scan'208";a="36113079" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 18 Sep 2014 12:19:21 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s8I4MRtP012947 for ; Thu, 18 Sep 2014 12:22:27 +0800 Received: from adam-work.lan (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 18 Sep 2014 12:22:20 +0800 From: Qu Wenruo To: Subject: [PATCH 3/3] btrfs: Add btrfsck support for nocow compressed prealloc write. Date: Thu, 18 Sep 2014 12:22:18 +0800 Message-ID: <1411014138-20124-3-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1411014138-20124-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1411014138-20124-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] 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.6 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 Add support for nocow compressed write into preallocated range. The main change is the following: 1) use disk_bytenr + data_offset to search csum 2) use offset + num_bytes - data_offset to judge if this is a valid file extent. 3) add file extent item size check, Since now regular file extent has 2 sizes(one with appended members and the old one), Signed-off-by: Qu Wenruo --- cmds-check.c | 19 ++++++++++++++++--- ctree.h | 1 - 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index 268e588..7a18ad4 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -1175,12 +1175,17 @@ static int process_file_extent(struct btrfs_root *root, num_bytes = (num_bytes + mask) & ~mask; } else if (extent_type == BTRFS_FILE_EXTENT_REG || extent_type == BTRFS_FILE_EXTENT_PREALLOC) { + u32 item_size = btrfs_item_size_nr(eb, slot); num_bytes = btrfs_file_extent_num_bytes(eb, fi); - disk_bytenr = btrfs_file_extent_disk_bytenr(eb, fi); + /* data_offset will fallback to 0 on normal extent */ + disk_bytenr = btrfs_file_extent_disk_bytenr(eb, fi) + + btrfs_ondemand_file_extent_data_offset(eb, + slot, fi); extent_offset = btrfs_file_extent_offset(eb, fi); if (num_bytes == 0 || (num_bytes & mask)) rec->errors |= I_ERR_BAD_FILE_EXTENT; - if (num_bytes + extent_offset > + if (num_bytes + extent_offset - + btrfs_ondemand_file_extent_data_offset(eb, slot, fi) > btrfs_file_extent_ram_bytes(eb, fi)) rec->errors |= I_ERR_BAD_FILE_EXTENT; if (extent_type == BTRFS_FILE_EXTENT_PREALLOC && @@ -1190,6 +1195,13 @@ static int process_file_extent(struct btrfs_root *root, rec->errors |= I_ERR_BAD_FILE_EXTENT; if (disk_bytenr > 0) rec->found_size += num_bytes; + if (item_size != BTRFS_FILE_EXTENT_SIZE_NORMAL && + item_size != BTRFS_FILE_EXTENT_SIZE_MAX) + rec->errors |= I_ERR_BAD_FILE_EXTENT; + if (!btrfs_fs_incompat(root->fs_info, + BTRFS_FEATURE_INCOMPAT_COMPPREALLOC) && + (item_size == BTRFS_FILE_EXTENT_SIZE_MAX)) + rec->errors |= I_ERR_BAD_FILE_EXTENT; } else { rec->errors |= I_ERR_BAD_FILE_EXTENT; } @@ -1198,7 +1210,8 @@ static int process_file_extent(struct btrfs_root *root, if (disk_bytenr > 0) { u64 found; if (btrfs_file_extent_compression(eb, fi)) - num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi); + num_bytes = btrfs_ondemand_file_extent_data_len(eb, + slot, fi); else disk_bytenr += extent_offset; diff --git a/ctree.h b/ctree.h index ab87133..e11e4d8 100644 --- a/ctree.h +++ b/ctree.h @@ -834,7 +834,6 @@ struct __compprealloc_data { __le64 data_len; } __attribute__ ((__packed__)); - #define BTRFS_FILE_EXTENT_SIZE_NORMAL (sizeof(struct btrfs_file_extent_item)) #define BTRFS_FILE_EXTENT_SIZE_MAX (sizeof(struct btrfs_file_extent_item) + \ sizeof(struct __compprealloc_data))