From patchwork Thu Sep 10 15:02:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 7154731 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 4B1329F314 for ; Thu, 10 Sep 2015 15:04:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C0312088A for ; Thu, 10 Sep 2015 15:04:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6687820876 for ; Thu, 10 Sep 2015 15:04:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751646AbbIJPEB (ORCPT ); Thu, 10 Sep 2015 11:04:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:57410 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970AbbIJPEA (ORCPT ); Thu, 10 Sep 2015 11:04:00 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 64A19AD23; Thu, 10 Sep 2015 15:03:58 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id C5BE0DAB4C; Thu, 10 Sep 2015 17:03:12 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba , Qu Wenruo Subject: [PATCH] btrfs-progs: fix cross stripe boundary check Date: Thu, 10 Sep 2015 17:02:56 +0200 Message-Id: <1441897376-5572-1-git-send-email-dsterba@suse.com> X-Mailer: git-send-email 2.1.3 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Commit 854437ca3c228d8ab3eb24d2efc1c21b5d56a635 ("btrfs-progs: extent-tree: avoid allocating tree block that crosses stripe boundary") does not work for 64k nodesize. Due to an off-by-one error, all queries to check_crossing_stripes will return that all extents cross a stripe and this will lead to a false ENOSPC. This crashes later $ ./mkfs.btrfs -n 64k image ./mkfs.btrfs(btrfs_reserve_extent+0xb77)[0x417f38] ./mkfs.btrfs(btrfs_alloc_free_block+0x57)[0x417fe0] ./mkfs.btrfs(__btrfs_cow_block+0x163)[0x408eb7] ./mkfs.btrfs(btrfs_cow_block+0xd0)[0x4097c4] ./mkfs.btrfs(btrfs_search_slot+0x16f)[0x40be4d] ./mkfs.btrfs(btrfs_insert_empty_items+0xc0)[0x40d5f9] ./mkfs.btrfs(btrfs_insert_item+0x99)[0x40da5f] ./mkfs.btrfs(btrfs_make_block_group+0x4d)[0x41705c] ./mkfs.btrfs(main+0xeef)[0x434b56] CC: Qu Wenruo Signed-off-by: David Sterba Reviewed-by: Qu Wenruo --- volumes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/volumes.h b/volumes.h index f7761311e8ce..4ecb99314a0c 100644 --- a/volumes.h +++ b/volumes.h @@ -156,7 +156,7 @@ struct map_lookup { static inline int check_crossing_stripes(u64 start, u64 len) { return (start / BTRFS_STRIPE_LEN) != - ((start + len) / BTRFS_STRIPE_LEN); + ((start + len - 1) / BTRFS_STRIPE_LEN); } int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,