From patchwork Wed Nov 16 14:13:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9431679 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 4E4C26021C for ; Wed, 16 Nov 2016 14:13:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C966201F5 for ; Wed, 16 Nov 2016 14:13:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F9BD28ED2; Wed, 16 Nov 2016 14:13:56 +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 6761A201F5 for ; Wed, 16 Nov 2016 14:13:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932119AbcKPONv (ORCPT ); Wed, 16 Nov 2016 09:13:51 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:47506 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752029AbcKPONu (ORCPT ); Wed, 16 Nov 2016 09:13:50 -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 uAGE8wng001202 for ; Wed, 16 Nov 2016 06:13:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=IEDEXsbAq8X5eLsNGQ4UaOCoHrK4u5SwwIQUpU4R7UM=; b=NFyT85VfGW5NM0ku6/MZ1WugqT+jdQPhcbgGEqddoLN+r/5l4xR+wokQuQnwsNHQtVgq ni3qloqYfzZw01VejpVxafoIzQR18W9FIXFbrqXXli+Oj/KoHenPZIjb58GYUYhGSzfI 78E+TqS1Ow6lW3yjhuVsqtSKlMOwi3T96Lg= Received: from mail.thefacebook.com ([199.201.64.23]) by m0089730.ppops.net with ESMTP id 26rhxe9ygx-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 16 Nov 2016 06:13:49 -0800 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.15) with Microsoft SMTP Server (TLS) id 14.3.294.0; Wed, 16 Nov 2016 06:13:48 -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=///0F++C0QtNC5Dq3u55jIRGkpEoSyzLWU3XIwktNsM=; b=Hs4GO9AuDvDmUUerEe4gLmHKNzipllxuyLVUkl5jZIcxr04QPEMJFkLOHXwt4hbPqGAyFC+yaEr2Rzi+O26LoZW3RzYVTLnj0Oa7n4Rxg4XAeXFUbHI0KYZFlaFjFDMmx1ag0llj2zMyYcYvhD7T5+BUIhMrLQqjYivK7C3he40= Received: from localhost (2606:a000:4381:1201:225:22ff:feb3:e51a) by MWHPR15MB1326.namprd15.prod.outlook.com (10.175.3.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.721.10; Wed, 16 Nov 2016 14:13:44 +0000 From: Josef Bacik To: , Subject: [PATCH 1/2][V2] Btrfs: fix file extent corruption Date: Wed, 16 Nov 2016 09:13:39 -0500 Message-ID: <1479305619-1667-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479150382-19273-1-git-send-email-jbacik@fb.com> References: <1479150382-19273-1-git-send-email-jbacik@fb.com> MIME-Version: 1.0 X-Originating-IP: [2606:a000:4381:1201:225:22ff:feb3:e51a] X-ClientProxiedBy: DM5PR17CA0011.namprd17.prod.outlook.com (10.168.112.149) To MWHPR15MB1326.namprd15.prod.outlook.com (10.175.3.140) X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1326; 2:C3Bojg20AIAfcIrwZEPOUAJKbAncTA7NKKnWeg2H2Czhwzh1J6tN/XkMYBlGyRPZAA+N9f6G2XRylDb0up8fDP8GKPYGrZ58Ua5byNuS4gUx9RPPMXUrfTcaHB8vNIuQXw6egmkPTq/JsaPclMSEe/TBVvafr9y0qjraTMGfDHQ=; 3:cCXReDeLVO2I+N1QdCqb5Q8XTCKQi2liSe5GhyEW2KU4U6oCfhx7GxBbkSwFkrIubSppgN/Pbbp6hi2YCiWyuG1NhmVFf6E/y1e+epvG6If0E/4c6+L9h++6sX33LLJjqZZTcdT1TGrqm5iWNaq1eVGiFqQhwsfqrmafp+Lgclg=; 25:vQjVSmb4KnUHaHt2CzfUddZqaIAfqeEcXEGO880DQ2bZj2MoBUBM2f941EhiKiaa4BdBCnuHIwQG77qN4rKCxlA3PN3J8nLzV5FWPvU/MIKDYQBnwjfUha97kUefgnd/2TjmjmuMNOZ4H+nYAI9BY/IsliqgqaOwLQAEQVxjbJk6inDGaxoa9I7sn4o0eudcIAZ3y41w5QP77bcOOUk+NnXGVrHFOJ9wRpwe1PcMHPMjq3CyB1BNH9+hAeqk04dFnG3siE/6aWMN7FI9cAxETRhrfBgu0wwSC0cVSfYBc0EuhyVqkwhyCewNbaC+2PBdkPCJ5I8//1rrRSKDnSAg2pHRRQwY3ynbcntVDEvspsGTRq7j8o5G3vaQGFlQlfll7pQG4WeNss5PS0L4ac3T9rAa7xkAjSjX0Rs0YugxEUKi8YXVxfXPRRLd4vPs9raqp/qPMZfUpmjg2Z18Yj+TuQ== X-MS-Office365-Filtering-Correlation-Id: 0fba431d-6a59-408d-15e6-08d40e2ac66d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:MWHPR15MB1326; X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1326; 31:iRY9hnppY6YbDU4qUw+7xaKDNJoJbLyOqw9p+y7h4kbrbQqme0wLzPwC+JuslG0lbhoplDHpTNyFrWG6UfvKI5oRcIxOP2kb+g8rLCdwZqJQI7F9zZSA95nYisRPSavMXJ4ptHgMhn7KckqonNf0YeCibCTyyK0H6PycdohENQq6pvGL/GpRCKqqF1xnPix91b7xsxdQpObOzPTmGlGmJuEQo4jwdyUQxGmokIvZaF3r457EE968E32hwu9Z/8x1YHTrSLMEacAhcSfWJ0fNRQ==; 20:amxN6nqPzyIS3BvLShDQqrsW4n+MkaaIulqUXKPS+9QlAtTr4MZVX0oG5KRF2RVhMfPJEuf8KVrQ0wTFvvKwUEfYQCxyHZxkiT/+TCXRA3EsySPz48kp0Ict296mA5/8L3TYi82dpOcXw0PfMDbUNAKIy67RME2h4yAHTPOlhs27mA0I1LOmZCU71tapYPr5HF4+fiBLtZgzHqKRdM7bRL5aLf88wsfy6PnkOcD5FKY8b5L8vl8jERgQ2bnbdqis X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6060326)(6040281)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041223)(6061324); SRVR:MWHPR15MB1326; BCL:0; PCL:0; RULEID:; SRVR:MWHPR15MB1326; X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1326; 4:MwuCdo0DFIT04HeMPOFqVl43iAr629acGVqc0sfPk7weL/LTue8oV9a86aj5n6PBO1ZBYuXNYYu7KEvRthskYFrPCKxquS4V3JbMXVFgbrgMmqrmxpY5xqU3nHHHX5YOn85yBeEyYDECMGj1RdVH2jSQi4l9WPverufxYeoIXQf0VQRuPUouKx2GXVYxssIws6JGeHqkFnpDcVosa7uRH7XfVbZYC3YbAj4hlZI5AzkvvPSEBhgnuTC3uNgI3MUENGIVVljaVwzXYonMwDPAwmQxRPxei+Awo+sLFoTKL+t/lIzLA3uT2lng7mGfE/GTG//auiqvWjElkmohckmVqHUkH5MT6eL/Dqz0luxSn7c2xHoNF9RcjLrmoB1QelBvZ1CRbXAnUkW+u3KDLfp4Lpvz1txVhRgEAUHbQ4mK2jfv3y/pScUJA6fBhqNT3DCECaHylqDj9A2oorvqsKkqGMgzrox785NvTtIyxUs6RoA/faRHpIDxUxzQVdMC1oPq X-Forefront-PRVS: 01283822F8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(199003)(189002)(86362001)(50986999)(76176999)(76506005)(33646002)(105586002)(5001770100001)(97736004)(36756003)(6116002)(106356001)(92566002)(5003940100001)(450100001)(2950100002)(6636002)(47776003)(42186005)(77096005)(101416001)(81156014)(305945005)(6666003)(8676002)(81166006)(7846002)(5660300001)(107886002)(50466002)(48376002)(50226002)(68736007)(7736002)(189998001)(2906002); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR15MB1326; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; MWHPR15MB1326; 23:GxBukvGdcc4kaq6mIB/ZphA3NRcKMsQuLBr7lu0a1?= =?us-ascii?Q?YqhsNoINxX6t9rEB/i9cgHI4+L5swjDbUYyBTILIRAKJsGAnKnKxiaL6ntr3?= =?us-ascii?Q?JwKe5c33LlvnO6xSynCQVYOmJMjU7VkwYoVa7GuBh617wUt1DdUBc+M/v4gk?= =?us-ascii?Q?gdULAGBvRsvijv1oZdTqMSs0gv5HqAECGSex6PQVtDZgXw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microsoft-Exchange-Diagnostics: 1; MWHPR15MB1326; 6:wHwK4qOJlkmnbkEpUgEB/APFI3nGY+aroffDcvH16ZmCQmkhdxAS1hNl7qwbvUVpjlRwFigDx9NwLIbcvldQiegVBazVuwyK0y8MSO7GwO4appxS0uzl4HjwReIlG4iT2qcyfw2Ul9xPUW5rU+gQZQdDosCMNqSQBinDgQbV99bC58z8EeszB+mECA0c7CmcBVLs0bWFiR87TA3l95XZtsEOntbPDW3U2NS7i5hex2YscIJCiITLN6XerbKvWOG3X/DynZ0YL1HoWuVzmGAXipDgtA56bPtabzzVk57r2lYhnbIEgOopuA6fi5s2OGv39P3fzg/Lty+wqsoA+qNhk2si7azL8EEJSyp7A+3f+po=; 5:UAtwjVjayytlEJJm45K9ynhY5z1uQa24iaDBvyDrz5RE/vHJrd9F/gR0L9IcOn1JGYkPii3XWgWz3kFsY0KT9EygQbBogUNjxsDUE3Me6X5/TB8y6U/KEDQilIX4gP3eDgm66/SlzQDwwLKwmoEiVi0v1d0zFLGQfTVqAzB8XuM=; 24:S/O+cIVVclWJexiY8IIS3EQOcUxS/zFIA/ZwW4APiryNV30LI94BQaBn+E8VNzqqwmrQqQSzb4TmXZpxXAPllAhNJU6+c3kkin8wL+umHcU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1326; 7:/jh9tZK/Mn178WCau/la36dBETUDEt4EEq4ZDlR9fhq1ju1gdMFwr7HTrl87hRTCywrwb/NkhKzT0BZ0eQto39L6VxkSqbA5hyxX3hThTQgXj5DcBCaIWpIA6eryD2GFUPnMBeXO5DKkgdbb7SMBFJ97VIedXx+DanPhb+2+AEO3saEe2IhnGTPeoYqVOMizp5Lm81c8FcNMnPpF9/a/Afg+k6TGDKToRW5xnjgOyF5uVCbLS7N6uJXlGC+Qw+9z8r5C9KTrvX/pIwNRO5+UdcwTDm3meIrsiR8xCFWjon9FIo95dqcDbdQyn0gAJo549PKQ48lhg84itVMXTnSqOpylyFk/Zot/NWBJzVNvVj4=; 20:Y76cOyVyvS7m7rslQSmsUlTrZGA3NUZjXKsr8hWfvNXkw6coPJg2JBtHExmieXc7rEW5jYoJ+uTZf8Fkx3KHycz5hCdWHvdEXecPRfGWWx+JB0h4/3y3arB9E+R0Y9qIGWMY/bu6MSxwq0749oSVSmZQkQ0BQwoofvz4u4ALtsQ= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2016 14:13:44.4143 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1326 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-16_06:, , 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 --- V1->V2: - don't call fill_holes if our drop_end is == start. fs/btrfs/file.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index cbefdc8..23859e7 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 = start; 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; } @@ -2526,7 +2535,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) trans->block_rsv = &root->fs_info->trans_block_rsv; - if (cur_offset < ino_size) { + if (cur_offset < drop_end && cur_offset < ino_size) { ret = fill_holes(trans, inode, path, cur_offset, drop_end); if (ret) {