From patchwork Mon Nov 14 19:06:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9428267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CB5BE602F0 for ; Mon, 14 Nov 2016 19:06:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF03428AAE for ; Mon, 14 Nov 2016 19:06:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B317D28AC1; Mon, 14 Nov 2016 19:06:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1522B28A66 for ; Mon, 14 Nov 2016 19:06:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934010AbcKNTGg (ORCPT ); Mon, 14 Nov 2016 14:06:36 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:43775 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752781AbcKNTGd (ORCPT ); Mon, 14 Nov 2016 14:06:33 -0500 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.17/8.16.0.17) with SMTP id uAEJ427o019718 for ; Mon, 14 Nov 2016 11:06:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : subject : date : message-id : mime-version : content-type; s=facebook; bh=TuEJE2FxzJcZEgrxykaNYRro9HuFyr71pjXlTD9sWjI=; b=C/GwL3GHjTsebI1X8p2pkePthOO418T0uktyA7StLex2OiL6QzG33Qt53xp8gIAJcc3E qfL2k1vaT9QnA8FhmizVnkm7aitmMb8ItAFDrd+6VM4hc3gH3GAXkNMsDFgjOG80Ds55 xRIkIbmn89Hyy9SmKaiFAKS3uHZgcfMRAME= Received: from mail.thefacebook.com ([199.201.64.23]) by m0089730.ppops.net with ESMTP id 26qesj9mb6-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 14 Nov 2016 11:06:33 -0800 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.17) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 14 Nov 2016 11:06:30 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=JpGVap4qX38BcIdbSzWyCkP9FQG8dU3y8+jJOt9amFk=; b=Lu1hJ95fQzd/3DPXbH4IZB140urql2M2snelpMUtdJs5mIMNJd7fdHN38mxw+bRh3GRWpAFTGc25vxvpVwob/SE844zEN+r4MekOy8WCjx3VpZR2CXJRYjN/Qz14QCMBuJeXsYXZI7smO11sjnaT+PgMPNuLVWxDJveukC2+Joc= Received: from localhost (2606:a000:4381:1201:225:22ff:feb3:e51a) by BN6PR15MB1314.namprd15.prod.outlook.com (10.172.206.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.721.10; Mon, 14 Nov 2016 19:06:26 +0000 From: Josef Bacik To: , Subject: [PATCH 1/2] Btrfs: fix file extent corruption Date: Mon, 14 Nov 2016 14:06:21 -0500 Message-ID: <1479150382-19273-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [2606:a000:4381:1201:225:22ff:feb3:e51a] X-ClientProxiedBy: DM5PR17CA0024.namprd17.prod.outlook.com (10.168.112.162) To BN6PR15MB1314.namprd15.prod.outlook.com (10.172.206.140) X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1314; 2:abG/fzSKOi6bfKB1dIbZIxaKbjENkkIJg2pA14y694cOPQhmXmZuCa5oDTaFXOEnRlDihrnO19BNsVRaNJFqnHRGJRtbVyEoWPcw0KwfT7qh8sHEEBn2BAoi3h8ChYZeA2oulTIEEt0HqV5Szwok9/9AfJDByL+2fqSVnnb1b54=; 3:CdjOzNHzmfSYzoUI4YNyuDD3kKIRa2xLCdrMSNJszV5RVDh3yL+F3lcTYUWgquUUqq8mjaG1DUXzm3z8h42PP7EJXjN+gFoS0TSIo6UZ6OkxNATtdokWxtsgvuDTJenRzzSRiJ9KhcruOwy2EyfVrWE1YAlboa674unm2+n8DC0= X-MS-Office365-Filtering-Correlation-Id: 09154eb2-dfef-4ed6-4e33-08d40cc15561 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN6PR15MB1314; X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1314; 25:bA5scZi2A4nP2xH2WumBBBGpYZZgtUIYwUUBddDLNh9+td48SQyETN5JjA8zjv6pERmPA5I1wDAFgxXjHI0qHM0auLAvvFEGPxKsyVjfJvp5TgsCeNmSMaToD9WOd5pyCqp1bnjCltjRJAsXemXYFEBRlNSdzF/1DEopioinOETDLLmnBUbmczKCDKcRTEADUqElWO+Y3e/TvDNvTwHmkGHfyvLfvE0ZKOCZvVOaKBXyXKYmsQEj8Z93vEStZGxIx3qPjcNwG7z87+69kmSjs3RlWEnwSwHfU0LkdZK5HQD+1CtzgJWa60t23r9KMliE/x/DblW7Y7pz+Bbq7u+CFqlhFOykbrGj+ZHmRsAZoIEMByRrALCljTQP22L9AJiOnh1rUd6j7MBIfoJVoFjf4eOb17P6ZD/cmsXazjMq2KrqROCoBOTxP2x7alhPdCCIMoMo9EHPsZpvHNp4K+bwZH+ZjviekmWpe12hw5LnegkyWm8Mk/F8ZLKIcWCXMfiPFjzBkkXnHo37lZlx/UEfg3S65YVMOzBFArLprs/kkFwbKmiAEwYANgrxcT/kx/zDXqVU1vRJyGDXbE6QU0zDAyGSOaHfzcJStn+JzSKpWLJjkUMMpowdkD2znPxrUAI+bdvKrH+nCFfwGy2TqoM9qPHxShPIxJaebXbOQZc9a0uGVRxUc8MgPZY6kgej2R9ne9mxLJ3Kerw/rW9yQeXrH6e90OsqkeemBzVQ79RefOg= X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1314; 31:2LuXRMtmUsDdYMbNyIcBCsalnlfdT4IDJsH+t5TRAu6JOKNPMOkWTsjXAIvNMxkJFZZsxRs8yiNrFDSdhsBDVDSsbVMHmn/kP2wJ/Z2pCbykjkOsG7Cmxuyjg2tGNM1H7Hmad9d9Unhpxllj87IXoHXQhbOnXb8Fk8QkADhhPH0pXsbW4ZJI1WE6uKMeFMDBy0bqnzAy68rfmns01AKlKAqp+7Gs5fHglulyRdU1fedo49tHIPtwe2mhxtpZq8drUYGjMGryTjFT70XhdcUxrg==; 20:NKmKCC6VJrpR4TohHkgKhDebpbGz86bcoEGdhLqdKJrHBc9C0046rB2NP/2Pnb2Y+inku+TmcK7tk7Pt3wSFe+yZRIIhLhP/aTqPwzI/iK4rKj7Du5tUcTd16hvCZoLDXrSblUJljN0V0c1+/skvfpu8TU4xRgA4GwOlbCogojJZp9AhTI+8VMQ3vsWZMm6XQgPqpbtTK08XeW/tIRQjyLJj3QJbUj7uV2TkCoUvYfg4eowaXg6Vb3niiTjKbnLt X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6060326)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6061324); SRVR:BN6PR15MB1314; BCL:0; PCL:0; RULEID:; SRVR:BN6PR15MB1314; X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1314; 4:jOZKoAB2vWzLUCsoTAlDkuyBmHXEuI2Nvv7YMYyBq+NMnPTe1SXuEaRj4JBMW2WQHC5JqAEp63CkZNrZWK8J93uomlJRPnXibCp7Trfli/YCooDtrhP6UjfP/3ty8H/O9DmrOlZq6Zu3BgZVOi5VOlJOKrvhLdu/wIobY0N6qATaYP/uz2pU/frvXtbpkOER8BXMX9kEKBBeffXYHsMYRyEaSwOg6r/los1nJZZMDJnKHYTN2pOf6pjuI4moMh0D9LA5Irqv2uKDTvF9yBoQMgPgA0rKvgs9qc0FlZbow4lwXvtLVAxQuH/07B7HL3uWAsp/sqC/v5CVRZRlqp2cUDY32PsAcXq7IDjyaw8q07+sdrvfBIEjTlNag6Zc+tSOJJKE1AnuPmYAj9/8LU2q5HksVXVe7Z0mlUsvAugD213nJu8DST05gXfr5BEV2EvJVQx6wZQ22BMsYwlpOXGcVg== X-Forefront-PRVS: 0126A32F74 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(7916002)(189002)(199003)(6636002)(36756003)(5003940100001)(6666003)(50226002)(2906002)(86362001)(81166006)(6116002)(305945005)(81156014)(7736002)(8676002)(7846002)(68736007)(5660300001)(33646002)(76506005)(101416001)(105586002)(106356001)(42186005)(77096005)(107886002)(97736004)(5001770100001)(47776003)(48376002)(189998001)(50466002)(50986999)(450100001)(92566002); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR15MB1314; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR15MB1314; 23:ZWK+KW+zqra/mFr36WcsW06voHnIQNqZ35V/myx94?= =?us-ascii?Q?qua0dqd8VXvaAczNz32vruBPfFbA373upuqTPQP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Q?1448KDYy68huEqAOhkaQDvKaMdTY67nFEbNuNQohd3YXyxsQtZmbda/wIkEi?= =?us-ascii?Q?Z31aoSsuhh50mNgMeH2L9gq?= X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1314; 6:ughE34fi/0haeioEvLCXR/WEPkCCj3G/cELhISLRCisyiSXbhus/C///YCz0IEsLIQuszK1ZQ6/j9zf5YhjwWXZu1x6ncwAdqM2jQ8h8eE0+5ckEjj6ir2E4P/imae3/3kQ+MJhqkFfFbTIaydgqk0LETwP/etd9FO2u23X3qr8SseoTeIbGriXJ8W7SfL9FqI/oO541i3zLQOWu1ol+6H3UPghMzTDGuEkKtWX6OZ+C746hVqeZDGi/j8cncsK6t8j6ozSL777JbteAIHohpqVLI0HYvJ7Zs58GyCiwHvRjb031q2fNiMILbypL6eovx16XvlDlTXUaCDf/gWsCMgeiDPdgmyw+INwpRVU5QQo=; 5:L8nWLMkCw2ZD+Q6LVyFcdpYCXroikccADkaCLNiD4IiZovEAikfp/aP9vXhgtVmg+LB+paGQRChNDpoRcNgmZc+hKu44m3bCdBr2URioUnxt18kyIWzHxoqHgh99bJUjL1REt4rCQF1JYxH7IPwtYQ==; 24:SdzNcg9Cu17oBwreCwvo5IXDk6qs0SFcLT7gtSz/wkdkFyGjHq+0CeUu89KxbhsXnPWIbuDvH8yrs7jl9IvjR8K0bUo46PhgFuqForwt9c0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1314; 7:1n2Zp0+dm47Ts4EWX2htV9Cw1zSSyrnf8ZO5ZrCV9GGvcc93Hs3qU8aHEwg1LEryVUcwUCQuk9hwJdyqiRJhgr6nUsmjnojOvKoL6bbewBDLwE7DG7tcaBiKLqrh9AT2fz9FsDYcre3ALtbbU409/2U4nwKoUbhAnBzAFBRayXx5fkHIFlTAHjUnZjaUfSp6dwMBBIarQ9QvZ9G3zU9n/yGRs5u19Dr5scDYI5r1f28yUh7AIGchfeyv4bRlSH9YYFRCGDpEY+3xLLW55psHlFmjrTCa8eV3a45XaTXGdQV5n33vpPJZfbPiTLRFuVMvJqSjZnsnlxIrcU4c2sVNTCIOvFoy33jVA2GHnjTvCeU=; 20:9WB5v07sVLkEwAG+4f7F92P103fLQiMu/ox/D0vrbv/pQ1Tu22HFQ2gI/cOCJHz5/htxc4gt8gACnOO+jFbxHiLFitDmhOY6VCyrYFLLe5W1eezqNGr38ecClqJq8673AGjWEPNGE9o4eRbhQkPCVH2wDGKPe0JCOumNogr65K4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2016 19:06:26.4402 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR15MB1314 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-14_12:, , signatures=0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to do hole punching we have a block reserve to hold the reservation we need to drop the extents in our range. Since we could end up dropping a lot of extents we set rsv->failfast so we can just loop around again and drop the remaining of the range. Unfortunately we unconditionally fill the hole extents in and start from the last extent we encountered, which we may or may not have dropped. So this can result in overlapping file extent entries, which can be tripped over in a variety of ways, either by hitting BUG_ON(!ret) in fill_holes() after the search, or in btrfs_set_item_key_safe() in btrfs_drop_extent() at a later time by an unrelated task. Fix this by only setting drop_end to the last extent we did actually drop. This way our holes are filled in properly for the range that we did drop, and the rest of the range that remains to be dropped is actually dropped. Thanks, Signed-off-by: Josef Bacik --- fs/btrfs/file.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index cbefdc8..1c15a98 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -706,6 +706,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans, u64 num_bytes = 0; u64 extent_offset = 0; u64 extent_end = 0; + u64 last_end = 0; int del_nr = 0; int del_slot = 0; int extent_type; @@ -797,8 +798,10 @@ next_slot: * extent item in the call to setup_items_for_insert() later * in this function. */ - if (extent_end == key.offset && extent_end >= search_start) + if (extent_end == key.offset && extent_end >= search_start) { + last_end = extent_end; goto delete_extent_item; + } if (extent_end <= search_start) { path->slots[0]++; @@ -861,6 +864,12 @@ next_slot: key.offset = start; } /* + * From here on out we will have actually dropped something, so + * last_end can be updated. + */ + last_end = extent_end; + + /* * | ---- range to drop ----- | * | -------- extent -------- | */ @@ -1010,7 +1019,7 @@ delete_extent_item: if (!replace_extent || !(*key_inserted)) btrfs_release_path(path); if (drop_end) - *drop_end = found ? min(end, extent_end) : end; + *drop_end = found ? min(end, last_end) : end; return ret; }