From patchwork Thu Feb 18 05:42:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8346161 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 ECCAA9F38B for ; Thu, 18 Feb 2016 05:49:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2110F202A1 for ; Thu, 18 Feb 2016 05:49:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B1A620279 for ; Thu, 18 Feb 2016 05:49:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425174AbcBRFqN (ORCPT ); Thu, 18 Feb 2016 00:46:13 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:41093 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1425111AbcBRFpj (ORCPT ); Thu, 18 Feb 2016 00:45:39 -0500 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="327643" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 18 Feb 2016 13:45:11 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id F1B894056413; Thu, 18 Feb 2016 13:45:07 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, clm@fb.com Cc: Wang Xiaoguang Subject: [PATCH v7 20/20] btrfs: dedup: Fix a bug when running inband dedup with balance Date: Thu, 18 Feb 2016 13:42:58 +0800 Message-Id: <1455774178-3595-21-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1455774178-3595-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1455774178-3595-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: F1B894056413.AB120 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com X-Spam-Status: No, score=-6.9 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 From: Wang Xiaoguang When running inband dedup with balance, it's possible that inband dedup still increase ref on extents which are in RO chunk. This may cause either find_data_references() gives warning, or make run_delayed_refs() return -EIO and cause trans abort. The cause is, normal dedup_del() is only called at run_delayed_ref() time, which is too late for balance case. This patch fixes this bug by calling dedup_del() at extent searching time of balance. Signed-off-by: Wang Xiaoguang --- fs/btrfs/relocation.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 2bd0011..913a7b1 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -31,6 +31,7 @@ #include "async-thread.h" #include "free-space-cache.h" #include "inode-map.h" +#include "dedup.h" /* * backref_node, mapping_node and tree_block start with this @@ -3909,6 +3910,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) struct btrfs_trans_handle *trans = NULL; struct btrfs_path *path; struct btrfs_extent_item *ei; + struct btrfs_fs_info *fs_info = rc->extent_root->fs_info; u64 flags; u32 item_size; int ret; @@ -4039,6 +4041,17 @@ restart: if (rc->stage == MOVE_DATA_EXTENTS && (flags & BTRFS_EXTENT_FLAG_DATA)) { rc->found_file_extent = 1; + /* + * This data extent will be replaced, but normal + * dedup_del() will only happen at run_delayed_ref() + * time, which is too late, so delete dedup hash early + * to prevent its ref get increased. + */ + ret = btrfs_dedup_del(trans, fs_info, key.objectid); + if (ret < 0) { + err = ret; + break; + } ret = relocate_data_extent(rc->data_inode, &key, &rc->cluster); if (ret < 0) {