From patchwork Fri May 27 17:08:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9138777 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 648C86075A for ; Fri, 27 May 2016 17:08:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 577D1280A3 for ; Fri, 27 May 2016 17:08:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C35528160; Fri, 27 May 2016 17:08:57 +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 C3256280A3 for ; Fri, 27 May 2016 17:08:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756374AbcE0RIw (ORCPT ); Fri, 27 May 2016 13:08:52 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:19285 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756222AbcE0RIv (ORCPT ); Fri, 27 May 2016 13:08:51 -0400 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u4RH2U2S027743 for ; Fri, 27 May 2016 10:08:51 -0700 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=YHCkg5VEVj97M0xdZ2rWPxuSMjPOxXv4UKjBgzVW8vs=; b=NZHPdVYtRPrfhHhNe1G0pIsd8nKZj2O1NNe9TJ81f7GY49q4yxXAoUr/JuaxGjHf2ARh PJuzc+DamzRq2uL9dflVMBNTh6Retav94vq6NPorC44JlXjn05s4amrtM46Noas/xYzm Gs+VeyOkacs1rtUBYiTzbtx6FiqkZINkh08= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 236qsnh5d8-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 27 May 2016 10:08:51 -0700 Received: from na01-bn1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.30) with Microsoft SMTP Server (TLS) id 14.3.294.0; Fri, 27 May 2016 13:08:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DwMHTvppBh0Gu550oGUBk/bFlpE8ekKMAMET/7NRRGc=; b=OPHGtCyaMa6JO+FxrZ4GPJjljKxOvaxrqCZavlZuUvZ/B8wiJmmeHRMcJFFyypYoYBpp/vAB6slZ2JQpkAwtEt8d8rCuFcjZVOTkWx9XC+GFn/757naJAZaL6m4rkX5ZD49Dh6jcKCBUeLrwKMdZSMKtiK/XcX6uHN7F2BgR24A= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=fb.com; Received: from localhost (107.15.72.49) by BY2PR15MB0837.namprd15.prod.outlook.com (10.164.171.25) with Microsoft SMTP Server (TLS) id 15.1.506.9; Fri, 27 May 2016 17:08:33 +0000 From: Josef Bacik To: , Subject: [PATCH] Btrfs: fill relocation block rsv after allocation Date: Fri, 27 May 2016 13:08:26 -0400 Message-ID: <1464368906-4316-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [107.15.72.49] X-ClientProxiedBy: CY1PR20CA0013.namprd20.prod.outlook.com (10.161.165.151) To BY2PR15MB0837.namprd15.prod.outlook.com (10.164.171.25) X-MS-Office365-Filtering-Correlation-Id: 6f649296-1e0e-4a7d-6571-08d3865188c5 X-Microsoft-Exchange-Diagnostics: 1; BY2PR15MB0837; 2:MJEokbctUdtt/eeob3+BHTh7fjW6e3uVUtNx944QQ6MiYlGf9GJ98Z1U/Db7AqXd9gm8lwwnjztVqYScR0bcSAZbKoIfO+RMBSooLGd+mHCiezZseErmwOgy0WiiLwuzS0n3N1+f2n0Le0k0qilfrpbz0Leul9cx0qaj851v8KOow07ea1cDSIXzTsz7J5RB; 3:SdyPYdNfoEkzKX1SJ2f5JSdksC296RAkydeBiEm2h3cZ5UKQipFPjdFAssEbbtlqaLub9yHG2gl/FAQ8xnQi320Y+N3B5akTr1e4lWMyKax7hiSYmIGCzKYc3lz83BvO; 25:vsBjCMX8v0VzJhH2uHP1KVrkq3zVrc2iVLZ6e3juuTRcyOHzRNKO9B+8anLoadEaZQ9VHFXE0dRAmJ3lMHVY0CzWHw5SbF5vDGl68ppMuXkYuzM/wtA0AFxqXRUxgP2N2tN9ayu/ElrMm5KiKjXcUk4F0DZeqAmQuLL/yLbWZbK9xUkb7/m+Xt44QzTLvnIjU9p8SqUwRkJYqpXQMFMHjy2M1ux6PTZARQVewsbEb1zGT2bYl9NpUPtzqDybld0iq1dlSRRdq8Nw1om0xO7yy5MPWU5MlyCWa5DWYpJ+B5bLDQAGHh2rpTVIw6alWcf1AeFOGm43hMVcP0y4enu34XXBKb3aMKfBcB0yGpaYVsGJryO0CaijmtocZtGUvVuA+sIRR7p56NGtzGXDx1aeljtDarX8RltlyIML0l6kCis=; 20:PDQSuSyg1TU0s4NGrKMBis8TPLrD+0Tq2ahgkhxIXW2nXwxqP6IV/XPy+HS4DmeSCDM3IBOeSdZYdqayJkHODaU0rLF2sjevwEkJz3goF6WRoHw4BiixW7O80lxJMpNpvLeWdYj60nwvqY16D1wUrf1Ceh3rFB122KV6kB3y1Z8= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR15MB0837; X-LD-Processed: 8ae927fe-1255-47a7-a2af-5f3a069daaa2,ExtAddr X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BY2PR15MB0837; BCL:0; PCL:0; RULEID:; SRVR:BY2PR15MB0837; X-Microsoft-Exchange-Diagnostics: 1; BY2PR15MB0837; 4:Jp3PS76kJuPUeA0eo7klBOxiRUabsKuJ2VUFJeN9zcUUkz4gAEc5L5JHeHEbn7WXchMMw9COouoYyDNbaRGWh7z1XIcPlXzkvyyKoez0+ugHIa0t+lUyAQOXbby6Rgmwk3M8pq3ItC8i2jH8BCD1q5DN+rl4N8vRCkx/f7dmAGudh8UqT3E38pXjOs/tEuNeqDCQl3xf6qs7CTF9fR2EsxmMvwPaa21pmOswKRZp1K255GOihwBbcYqDDidOGANEObK1NSo8OyYu6AglSwVIBA+GNVHysgq65eJ3oJXfza87HDPy0b3YPdzJfUNcHN7wmAJSDccpHAcs6HAfxwM5M9c3nZRQRaI32+EUZL/vpBfEkLE6lo0D6smuaP/127EU0AvYx4Jqcyf7l5BhmpLZc0p0fhuP24uv6lvpGiPmO4A= X-Forefront-PRVS: 09555FB1AD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(42186005)(50226002)(50986999)(76506005)(33646002)(2906002)(92566002)(229853001)(450100001)(50466002)(5001770100001)(6116002)(81166006)(8676002)(3846002)(5004730100002)(586003)(19580395003)(47776003)(5003940100001)(19580405001)(66066001)(48376002)(5008740100001)(77096005)(189998001)(107886002)(86362001)(36756003)(4720700001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR15MB0837; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2PR15MB0837; 23:VmOKdtmhLaRKq6pboafP0dpdXiFGou3WrkAMWQbR8epQXvwRkRKWaWKmIs3aKmezpce9LueX2JgIQa1SrgvC6IFAemxYxfX0sWGl7V08CUFTZt+Ni5K6sNiOWyY/7hun6DwqXSjcFd6yIHJSpuW82M8p8djrrWMpNSmplltostOwUE2+J6LXw0dVtT2HO9mQld3aD5BLtC6o12Chy6w0oAxtqwOGAwcn7geY9P5W4A4lgD8JNOA5yWEa7p3T+Teuc4ILQFPh+eNk70FBv4o5uH6uVAam9zcHB85KpFMn/uDzo+yv4/hLV4wNiIRtf3sbYUY21lB38XLUF71G9/B9A4v1OvPW8AE45I7WlXXOZsT9Ejm0/BNG2pO79dfDu67XQBlMPfn4HzZingy1iVD8ynJqdKnSVh4vD20dZ+bhFoan65Q/TdW8yLmishsUfVGxleg7Fu12qXd1TSgpomWLBol+RNrlAytF2lo4g1MFGEioYONiIN5cgW12Cy+i4SYezOlKquEpmj71cvly68EhuVO8cQhgO/AveawpCG87Hxu+sxgguMavdsox+HJpLfxusGhV4HUDDYVgZDzIro9uB0oHt2raP64UoB3xZnhhIQPesYc5LA8wPSghNIg+aPUuT8+wxV6Il65jTS5FuVK/p1HCPtVy+sKLD3wJb8olh6PLzuxktv4pGxCLshB18c6WCrGoa7eShdiwRUR9Xb4bAulM8YEU1nd1JxWsr6Bg8zy7be81WSVc/3k6sm7EQ4bb8+iHdt4Zo/Ilj5odrFpoZd5yILqb67B/srShtNFekDk4/LdY2ABYXPY+zl7sKnxtGUWVCFigHr4KpYLGuqa9OuHNU2hG6cykC2W4fjAlsYlNd6IQQIVO41HGAXkUmn1XWBFDLASC4VUhKMbPqkcZKmbHOFEgefkwIFvblYUGK z4= X-Microsoft-Exchange-Diagnostics: 1; BY2PR15MB0837; 5:RMKbYEI8DvCRDmA1UnxxZsM1Mn4Q50ShsjWXR3320hmQqxWGZOjXfV48d3A5qBDM7lUoREAEE+nbIVe0CbJUPFIGGCHQ642oywddQnpzm7f9gdBR48bpn8SeIPzkcVkWZvUOaCz6YtUfC7uWSep1Wg==; 24:ygo+lw1cBwcqb526aAqJCyDGx+tTjRX/hjZqciFtBVm+FKrLLqqP/JTZ7TPt84FP46mZY2wqqUF5+ueieECpQ3KYH0LUqQuBCytvoNHY0Go=; 7:9vE9NUQj6mGqC8MskSjkes8slZmp6qntDkmb2Rw1xsuWCyPUAUoUvz6e5awhwiH+xNd2JM+xohqVzP2gL05O1wTRQrm3o01pG9whZSidYArL1R0/YC8zQdlyxet5zYpPl7GdDGyRSNjWwSY9KM+TeG083ZSnyUTKG2OMy2OQ9B8KXidfsEjCl7jzFhfVPM82; 20:/ZTDzfV3Rf8RNikky95mIS16AJur6MJDaqyWTYGBYY0lXEPcU1BpWlp0LqOvp06CCjrmyh8yu/U1kIlEmcwVSdhoZH70Aku+tGQH++NFgil5KMgG9HzOha4Krxa1u5NtbDaR2jcqth7haKQcIIeKQ5er/twoEYLH+cSWoyLsD5k= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2016 17:08:33.1826 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR15MB0837 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-05-27_10:, , 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 Since we set the reloc control before we've reserved our space for relocation we could race with a root being dirtied and not actually have space to do our init reloc root. So once we've allocated it and set it up go ahead and make our reservation before setting the relocate control, that way anybody who tries to do the reloc root init has space to use. Thanks, Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 61efa5f..959cb4e 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3870,6 +3870,7 @@ static noinline_for_stack int prepare_to_relocate(struct reloc_control *rc) { struct btrfs_trans_handle *trans; + int ret; rc->block_rsv = btrfs_alloc_block_rsv(rc->extent_root, BTRFS_BLOCK_RSV_TEMP); @@ -3884,6 +3885,11 @@ int prepare_to_relocate(struct reloc_control *rc) rc->reserved_bytes = 0; rc->block_rsv->size = rc->extent_root->nodesize * RELOCATION_RESERVED_NODES; + ret = btrfs_block_rsv_refill(rc->extent_root, + rc->block_rsv, rc->block_rsv->size, + BTRFS_RESERVE_FLUSH_ALL); + if (ret) + return ret; rc->create_reloc_tree = 1; set_reloc_control(rc);