From patchwork Fri Sep 2 19:40:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9311583 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 40C5C60772 for ; Fri, 2 Sep 2016 19:42:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2ED1A29835 for ; Fri, 2 Sep 2016 19:42:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 238F52984D; Fri, 2 Sep 2016 19:42:17 +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 7EA0D29835 for ; Fri, 2 Sep 2016 19:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932807AbcIBTmN (ORCPT ); Fri, 2 Sep 2016 15:42:13 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:56091 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932780AbcIBTmM (ORCPT ); Fri, 2 Sep 2016 15:42:12 -0400 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u82JYgpY003885 for ; Fri, 2 Sep 2016 12:42:11 -0700 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=MoAPxQhz20a6sMb7asIKrKd81feFqJU+xscEkNb9xxA=; b=TX8htOIQMp7XCygagBz2NLzY3gcZDHAdqBjhqN4oRTj8yE1OLJ5d8mCnON/2u+BILHn+ HBJQ+hmOgFafMuTSyIkosL6w1lhUWgLDQkMsKF9199D203mKnpwUxJ5i8Xjesu//Eh0D U+lyuQwcLIocRo2S+TXtxcUVZTQrzD82A6U= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 257dbc0yj9-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 02 Sep 2016 12:42:11 -0700 Received: from NAM01-SN1-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; Fri, 2 Sep 2016 12:42:10 -0700 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=LGh8FNRX5WffRGw8+VlkwvKrK8ZXRkrCrXr1QtQmcTU=; b=XMP5VsHPBA98ZWViqeLGJFPjEwEpOjk3M9LYTV72m+jhmwLJU5oQRSR9Rp/gdXLA++H57u7UaMR9NMER+sTwT3zQGRMe1bMFLWLL2d2b1Il/1TPvgznW3lulI1/T7sc/gsmG4++76H5OVISUPII92wAhQH6pH+JZZ0oRfO9VFLM= Received: from localhost (107.15.72.49) by MWHPR15MB1327.namprd15.prod.outlook.com (10.175.3.141) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.609.9; Fri, 2 Sep 2016 19:41:49 +0000 From: Josef Bacik To: , Subject: [PATCH 7/7] Btrfs: kill BUG_ON()'s in btrfs_mark_extent_written Date: Fri, 2 Sep 2016 15:40:06 -0400 Message-ID: <1472845206-22870-8-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472845206-22870-1-git-send-email-jbacik@fb.com> References: <1472845206-22870-1-git-send-email-jbacik@fb.com> MIME-Version: 1.0 X-Originating-IP: [107.15.72.49] X-ClientProxiedBy: SN1PR16CA0032.namprd16.prod.outlook.com (10.169.34.42) To MWHPR15MB1327.namprd15.prod.outlook.com (10.175.3.141) X-MS-Office365-Filtering-Correlation-Id: 899f4308-0de8-42ca-7a73-08d3d3692e7e X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1327; 2:b3lGEk0T9pz3FBdklMMa5soMn4z6SitB+fFcCd6VHh22ZTE/G9AGiTFOa5M7PcC2qJBiDZZxXW9j+JZ2r/zBECQAB7TXer9lg2H/gLKQnNdcCY/AS+ie3OZ6li9GKMZp9rIOmWI1rc9dbAZGG34rNM01UKFnIdwUeJUsvyPK02geAyuCsTRy1seLP4fFwcJO; 3:YPLD3bT8uapOi3WNs2T8lprdk7Cp5lwLyyc5D4qMLuI5ka4bP9TR9Gfy7m7QykyZpsXpKfsCjoBfzZYtlOfwVi7Cguxyz7UfCX5na1eDj8Fq9QQ16qLpzaK9P7mruSAF X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:MWHPR15MB1327; X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1327; 25:R5Jq4LJru8szUqFiAbVvRMKqpzbtSDBff0S4qXEDlcmor0Vzs64NZFRvm5IY8qb6F2IgRB3Cbt7Xxq3sPG7gKcK1vsZtasmEDqqn6z+8/Ymxyq4jCmTRVmxEroPNmt3uugWb+cYePvtEe+qH/H0iptz+lwyQUPFippdXrHCfNuq6YSztaPt1oJGlZvmrod5Bc/1InvD0C9c/ECKK722A+3M2uHRZ2O5fm7dY1Gifdw+L8OHv8/nPdcp6/Fh8XW25odXjGJYPMDxrZYdahBLTXO7xeBTS6U2gR7SR7ax4gyJUikLc3Np1tqsPJ2t1AGVZeAWwTeJIgC0GCxvOHw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R1gGcrLC3akZwsQKrHkPdThEKK7He1PX5Y5tEqQc4I/Z5bJwGWI02H0i5qLYoAGd/TbWjJkUk0NQIS2PaOFpKrfa2gNUCPOT5CoISqrdRizNdoaXH5lNdemOV2zbQYKHLNYQFgxX6x9568oQzMMndlOmGL/HcN/uy2Fz3WwWEcSgPrxCXPKeLNr9wHsnqE+daG93coxURZCvAfpaWfMT8IAmnzV1dcUsOn3YAoFJH2daNIODI26GDQ9egVn+jb8T3NLShZHigRrIy3flsK X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:MWHPR15MB1327; BCL:0; PCL:0; RULEID:; SRVR:MWHPR15MB1327; X-Forefront-PRVS: 00531FAC2C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(199003)(189002)(229853001)(3846002)(586003)(5660300001)(92566002)(50226002)(81166006)(81156014)(551934003)(2906002)(42186005)(19580395003)(5001770100001)(68736007)(19580405001)(7736002)(189998001)(7846002)(106356001)(107886002)(97736004)(76506005)(305945005)(105586002)(6116002)(5003940100001)(48376002)(66066001)(50986999)(8676002)(101416001)(450100001)(47776003)(86362001)(50466002)(36756003)(77096005)(33646002)(76176999)(2950100001); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR15MB1327; 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; MWHPR15MB1327; 23:9xGQyPdAv/DCf1uXeoxPNSprquwTgI9E9HOoByLsl?= =?us-ascii?Q?U1ZWHUG0/egNdeO7oXTTeNk0FuhifcEoaXdGlxlWzXThB9zG6UIm3hF8gVos?= =?us-ascii?Q?Jxzziv1LBROFaEOm9D5Yt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JaNzT2v7WDoirKM/MP7yaApfO/3pRKI6Zzrz/A4 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1327; 20:C5KSZ+LeXIz9b7ImB/7Yvum9bexCrqz0d5PvIw+7UFUy0yUdG/LsXxUY+LDz+pqvHQcjU47mDaRfBAoDfa0qcQFR8SFskRyqiWxP2lPFxWiDefGMSUtFH0N2WvHqLJXQjy4OiYldz0o7ehFbHzWIyv3iC02JKcw5SPtBH0iTU30= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2016 19:41:49.2087 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1327 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-09-02_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 No reason to bug on in here, fs corruption could easily cause these things to happen. Signed-off-by: Josef Bacik Reviewed-by: David Sterba --- fs/btrfs/file.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index f060b08..85bf035 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1110,13 +1110,25 @@ again: leaf = path->nodes[0]; btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); - BUG_ON(key.objectid != ino || key.type != BTRFS_EXTENT_DATA_KEY); + if (key.objectid != ino || + key.type != BTRFS_EXTENT_DATA_KEY) { + ret = -EINVAL; + btrfs_abort_transaction(trans, ret); + goto out; + } fi = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); - BUG_ON(btrfs_file_extent_type(leaf, fi) != - BTRFS_FILE_EXTENT_PREALLOC); + if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_PREALLOC) { + ret = -EINVAL; + btrfs_abort_transaction(trans, ret); + goto out; + } extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi); - BUG_ON(key.offset > start || extent_end < end); + if (key.offset > start || extent_end < end) { + ret = -EINVAL; + btrfs_abort_transaction(trans, ret); + goto out; + } bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi); @@ -1213,12 +1225,19 @@ again: ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0, root->root_key.objectid, ino, orig_offset); - BUG_ON(ret); /* -ENOMEM */ + if (ret) { + btrfs_abort_transaction(trans, ret); + goto out; + } if (split == start) { key.offset = start; } else { - BUG_ON(start != key.offset); + if (start != key.offset) { + ret = -EINVAL; + btrfs_abort_transaction(trans, ret); + goto out; + } path->slots[0]--; extent_end = end; } @@ -1240,7 +1259,10 @@ again: ret = btrfs_free_extent(trans, root, bytenr, num_bytes, 0, root->root_key.objectid, ino, orig_offset); - BUG_ON(ret); /* -ENOMEM */ + if (ret) { + btrfs_abort_transaction(trans, ret); + goto out; + } } other_start = 0; other_end = start; @@ -1257,7 +1279,10 @@ again: ret = btrfs_free_extent(trans, root, bytenr, num_bytes, 0, root->root_key.objectid, ino, orig_offset); - BUG_ON(ret); /* -ENOMEM */ + if (ret) { + btrfs_abort_transaction(trans, ret); + goto out; + } } if (del_nr == 0) { fi = btrfs_item_ptr(leaf, path->slots[0],