From patchwork Mon Feb 2 07:31:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forrest Liu X-Patchwork-Id: 5759601 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D67EDBF440 for ; Mon, 2 Feb 2015 07:32:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0AB9D20218 for ; Mon, 2 Feb 2015 07:32:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2F6E2017D for ; Mon, 2 Feb 2015 07:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932677AbbBBHb4 (ORCPT ); Mon, 2 Feb 2015 02:31:56 -0500 Received: from mail.synology.com ([59.124.41.242]:23057 "EHLO mail.synology.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932594AbbBBHbz (ORCPT ); Mon, 2 Feb 2015 02:31:55 -0500 Received: from localhost.localdomain (unknown [192.168.0.152]) (Authenticated sender: forrestl@synology.com) by mail.synology.com (Postfix) with ESMTPSA id 1901E9D7E9E; Mon, 2 Feb 2015 15:31:52 +0800 (CST) From: Forrest Liu To: linux-btrfs@vger.kernel.org Cc: Forrest Liu Subject: [PATCH] Btrfs: fix find_free_dev_extent() malfunction in case device tree has hole Date: Mon, 2 Feb 2015 15:31:39 +0800 Message-Id: <1422862299-7361-1-git-send-email-forrestl@synology.com> X-Mailer: git-send-email 1.9.1 X-MailScanner-ID: 1901E9D7E9E.AE602 X-MailScanner: Found to be clean X-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (cached, score=0.792, required 8, ALL_TRUSTED -1.00, AWL 0.99, BAYES_00 -1.90, DNS_FROM_AHBL_RHSBL 2.70) X-MailScanner-From: forrestl@synology.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 If device tree has hole, find_free_dev_extent() cannot find available address properly. The example below, has one BIG hole in device tree, and can only allocate just one chunk in a transaction. item 9 key (1 DEV_EXTENT 273841913856) itemoff 15811 itemsize 48 dev extent chunk_tree 3 chunk objectid 256 chunk offset 272759783424 length 1073741824 item 10 key (1 DEV_EXTENT 1071632089088) itemoff 15763 itemsize 48 dev extent chunk_tree 3 chunk objectid 256 chunk offset 1070549958656 length 1073741824 item 11 key (1 DEV_EXTENT 1072705830912) itemoff 15715 itemsize 48 dev extent chunk_tree 3 chunk objectid 256 chunk offset 1071623700480 length Signed-off-by: Forrest Liu Reviewed-by: Liu Bo --- fs/btrfs/volumes.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index da7e0e1..61be789 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1060,6 +1060,7 @@ static int contains_pending_extent(struct btrfs_trans_handle *trans, struct extent_map *em; struct list_head *search_list = &trans->transaction->pending_chunks; int ret = 0; + u64 physical_start = *start; again: list_for_each_entry(em, search_list, list) { @@ -1070,9 +1071,9 @@ again: for (i = 0; i < map->num_stripes; i++) { if (map->stripes[i].dev != device) continue; - if (map->stripes[i].physical >= *start + len || + if (map->stripes[i].physical >= physical_start + len || map->stripes[i].physical + em->orig_block_len <= - *start) + physical_start) continue; *start = map->stripes[i].physical + em->orig_block_len; @@ -1195,8 +1196,14 @@ again: */ if (contains_pending_extent(trans, device, &search_start, - hole_size)) - hole_size = 0; + hole_size)) { + if (key.offset >= search_start) + hole_size = key_offset - search_start; + else { + WARN_ON(1); + hole_size = 0; + } + } if (hole_size > max_hole_size) { max_hole_start = search_start;