From patchwork Tue Aug 23 17:22:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9295989 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 2705260574 for ; Tue, 23 Aug 2016 17:22:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13A8828CCC for ; Tue, 23 Aug 2016 17:22:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 082BA28CD0; Tue, 23 Aug 2016 17:22:16 +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 5F84E28CCC for ; Tue, 23 Aug 2016 17:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753267AbcHWRWM (ORCPT ); Tue, 23 Aug 2016 13:22:12 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:54832 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751640AbcHWRWK (ORCPT ); Tue, 23 Aug 2016 13:22:10 -0400 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u7NHLG0w019374 for ; Tue, 23 Aug 2016 10:22:10 -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 : content-transfer-encoding; s=facebook; bh=88Ezw2jRMFoSoiaQd0FAL7Zh2JqDrYqALzMVR7+aSfU=; b=FFfI3McjQBrrreEgWGt8lPApLTHrpHQF0OyqaS1+mlcrp1u/augvj7QsjsJy6RaeSO7g 83h73ezl7gixRynlPhRk7xNkSUw9pcQFX9qzT0XDYfScsV0a6MM16FxSpWBi2lNaoe0E mKr8YTaBXx3l71nrzR7zsfq/26RvzV2VFBY= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 250tnw044s-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 23 Aug 2016 10:22:10 -0700 Received: from NAM01-SN1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Tue, 23 Aug 2016 13:22:08 -0400 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=aqU/it2wFJMjyK8I5nC1ivGHbdei3IW7/MRmeNVWdmY=; b=LyWjUDfhGq6Xp9BwUVdRuMXiSDzzNdZT5v6JfdgmNZ2LjPQNCKDmk52LvqC/qZnvMHtHkVlkt7uAaWrBpSM5viZuihrSLvglwQtXsnGDgzuBlXVdC0I0sOhRZ3Cpq+Z9jxksWquxm3Yb8wBYt27pe8WKtK2ZADDB4jnKuqbCf8c= Received: from localhost (107.15.72.49) by MWHPR15MB1325.namprd15.prod.outlook.com (10.175.3.139) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Tue, 23 Aug 2016 17:22:06 +0000 From: Josef Bacik To: , Subject: [PATCH] Btrfs: handle pending renames with recycled inodes properly Date: Tue, 23 Aug 2016 13:22:03 -0400 Message-ID: <1471972923-4833-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: CY1PR14CA0046.namprd14.prod.outlook.com (10.164.65.142) To MWHPR15MB1325.namprd15.prod.outlook.com (10.175.3.139) X-MS-Office365-Filtering-Correlation-Id: 1f82eda0-2333-4689-c87b-08d3cb7a019e X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1325; 2:4g4yS21LAA0s259bhsMSO3InTNT0oDYKPkD8Cyjravr4V7lY7cct9KUDrZOyivfHd33q9nILQzXSu3MFrlpJIRJCPAuOuHj3jbUXKOg75XgelYc0fwAYsyVzwyqPMljWFsKgAW5nOu9bahV6n4Pm2IHk1inHcdw08F87cqbbzhoVtf+K2f3KwdnV5ohnJj9p; 3:CpjJLnB9E9sKimwtfVvI0QPR+aUki0R91ITeG4QR5ENDyTMBNJ/lfhintt5bH+Yp9d0zyVD10PUUtIca/omXCjv1cg0seuA5DOCZei9Nf0oBOmfOpRysUJc9Xx76wVSf; 25:zXMUnfTt3CSOAi8WLTzn34VY5XU8C2tgp73dGXKPvgcLFAboalr64LiLRdzCsTpiBqRUnGqM2t5NoJJ4EjHWNOgQLK9xrAzDQEr9AgSpFb62x9YNAXp5EY98IXObPva2tSZn9Wtr6rDQ0he0uOnmxujdVYHNzvEtnfzfJcLWQ8ZHvoQSBro4fTYeb/vwVDQhwU0YW9urbayOuRrPFO5Ee7FErfbCrIYa3RsOQmh5RwBPU4p3RVirW4yPBaMhPdn2up3c+8P0cOn4aLRhj5nic+tK98TqPI3ca2RCn06wsGceDy1DQRDipnBPjTRp79YsZ0dADCbyXNfLrgasU7nWzrwBc4BtXFuc3gh/i2ixT/HD2ALQFdHFAnl99SquzAhaofzRMYCgUH3h6W1YmZFmAGRlBdRi6TX9N/XTe0qEEDA= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:MWHPR15MB1325; X-LD-Processed: 8ae927fe-1255-47a7-a2af-5f3a069daaa2,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1325; 31:HAwVHby0ny8os53BHqVyCX4i/NZPu05k63tbicBjMdbUI9VElCbQoRqk/TNZjwh6jLn/mS33syk53B/p6qopHr+Rcamqj/4PnrSwD0SLZ+WQCQ9CyAiBTI9FL8kLdj+PzhXQDKxiOLR7PqJSK/ewNIZ/vhaUwke1UIf6uJUQfINwOGsNyW4BznBIz5kpGmXWmV9q7M+Y4xtZxjiRsv9j0pAGwQfRQdftgtUNBcbBRTE=; 20:/TmxYHmxdtotvAbAkuWxm7twVOxcK0VQCtLox5J3HQg7IMewj1FlFGeEHBCucV0XzZtoD+BW+EwRNFrUsqm43cUitn3KW0xM6crggcWWdxlwCV1meBHdB6fa6ARQENeClDmKxJ8lyeKfAtB+nppWYfhS4xvjoL9EW9mmUA7asy4=; 4:mkpiNO524VWRWZkYrmJPRKulq1I+ppWUeKdo+xY4qgzlLWObVteZ99GrHZ9yT3oGkAMOFOmaS8KUgDQrKhC5lZkPnL7khwv2PXM6LrCSZAMKLkN6DPkoLIhNiwRSjsKX2vvwT1KGcj+1uugbdaCmY/7cbwBz4zcrb6oGunWgOlJ+Yy8WZp2MXEkG8h9JfvY7YtT4QjhEX3D7vTYwtoqv3Qe7rwxNRigQb3q/Cp4WvrsmOARAnwmJ1W1TZtX7REEw5pWlF0csJkQ+yEDGabs6mC4nCvqFOVoe8tWT3PwP5SJKKPizNCMyIZWIHGXiuMAezDOaFM84Fifbs5v7G1ISQG+L2+y9YyPMFYJgUVrThswx2DK3pFDbJKVMKZf4owXCzb/9rN8ppNHH10GE1tspBtpDkQnR3QFV+Fyp3EP9CeLKvLCDTrV9F0NHPdc/+QEL 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)(5005006)(8121501046)(3002001)(10201501046); SRVR:MWHPR15MB1325; BCL:0; PCL:0; RULEID:; SRVR:MWHPR15MB1325; X-Forefront-PRVS: 004395A01C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(199003)(189002)(19580395003)(97736004)(5001770100001)(189998001)(86362001)(107886002)(105586002)(19580405001)(42186005)(229853001)(305945005)(586003)(23676002)(101416001)(106356001)(66066001)(50986999)(50466002)(33646002)(47776003)(36756003)(76506005)(3846002)(7846002)(7736002)(77096005)(50226002)(68736007)(2906002)(8676002)(81156014)(81166006)(5820100001)(6116002)(2870700001)(92566002)(450100001)(5660300001)(4720700001); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR15MB1325; 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: =?utf-8?B?MTtNV0hQUjE1TUIxMzI1OzIzOi82ODRZOC90cThKRzVObm8rcVB3aXZRS0JQ?= =?utf-8?B?M1dGazJNOVMrenlxYnZDaERFejViRWVXNWhFYmhLR1NSNldVZVlFSGdmeDVX?= =?utf-8?B?T0NENWhrcUI1dElNOTh2MVJnYkJrclQvNGhXT3BwbitnaDhSWjJUR2RlU0xU?= =?utf-8?B?MUYyVXAxTDFBVTVRTXlOVnpyQzNtRjlSaFh4OG5DeU9neHhoZ2QwV2szZ0tM?= =?utf-8?B?djFZYmw3VzUzd3QvajNBV3RScWJkc3ZkVExldTVCTWJBK1RXNlB1OW9aRGds?= =?utf-8?B?dmw3dDdLYWZNaDR0aGpUU3cvWUlrQ2t4dTRSYTc4RnBQbDExMTRCUjRENUFB?= =?utf-8?B?WnNBS1Z5QzhNL0tkQ1FVa0QzTTZiQ0habTF5bjRnT2U3bFljdUd4V2owaGVk?= =?utf-8?B?b25CdUp0dmIrNTlIdkxNVUhoTmZiRFhCM0lQeEk3Z0s4RXIxTHJFekE3SmhL?= =?utf-8?B?UzJJRVRIUElyL2tnMERDTG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VxbhrxFRxTdVULBvCGv60c0insK6F/u/LtPHHOtEz SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR15MB1325; 20:CgE4H0pvi9OglL9tw0OGc8CqA0v06f9iQwOIAOrwZVuiAAuPERoOTHTYSaZbFXYfGa8ubXxCBvlELTo5p7fIHjG1IXUdaQWbJWWIDkFwihgHdiORwsTg4KSgHhfkSAa+81tOLNofSinLW3pSoeLWxjHnEOW0EE1C2SaY+IEpT+o= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2016 17:22:06.0191 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1325 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-08-23_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 Suppose you have the following tree in snap1 on a file system mounted with -o inode_cache so that inode numbers are recycled └── [ 258] a └── [ 257] b and then you remove b, rename a to c, and then re-create b in c so you have the following tree └── [ 258] c └── [ 257] b and then you try to do an incremental send you will hit ASSERT(pending_move == 0); in process_all_refs(). This is because we assume that any recycling of inodes will not have a pending change in our path, which isn't the case. This is the case for the DELETE side, since we want to remove the old file using the old path, but on the create side we could have a pending move and need to do the normal pending rename dance. So remove this ASSERT() and put it after the DELETE phase as it makes sense there, and change the CREATE stage to bail if we have pending_move set. This fixes the ASSERT() and results in the proper send stream. Signed-off-by: Josef Bacik --- fs/btrfs/send.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index b71dd29..2992ff1 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4063,7 +4063,8 @@ out: * generation number, which means that it was deleted and recreated. */ static int process_all_refs(struct send_ctx *sctx, - enum btrfs_compare_tree_result cmd) + enum btrfs_compare_tree_result cmd, + int *pending_move) { int ret; struct btrfs_root *root; @@ -4073,7 +4074,6 @@ static int process_all_refs(struct send_ctx *sctx, struct extent_buffer *eb; int slot; iterate_inode_ref_t cb; - int pending_move = 0; path = alloc_path_for_send(); if (!path) @@ -4126,10 +4126,7 @@ static int process_all_refs(struct send_ctx *sctx, } btrfs_release_path(path); - ret = process_recorded_refs(sctx, &pending_move); - /* Only applicable to an incremental send. */ - ASSERT(pending_move == 0); - + ret = process_recorded_refs(sctx, pending_move); out: btrfs_free_path(path); return ret; @@ -5521,6 +5518,8 @@ static int changed_inode(struct send_ctx *sctx, * deleted and the new one as new. */ if (sctx->cur_inode_new_gen) { + int pending_move = 0; + /* * First, process the inode as if it was deleted. */ @@ -5532,11 +5531,19 @@ static int changed_inode(struct send_ctx *sctx, sctx->cur_inode_mode = btrfs_inode_mode( sctx->right_path->nodes[0], right_ii); ret = process_all_refs(sctx, - BTRFS_COMPARE_TREE_DELETED); + BTRFS_COMPARE_TREE_DELETED, &pending_move); if (ret < 0) goto out; /* + * We are deleting the old inode, which shouldn't have + * pending moves affecting it for the delete phase, as + * the pending stuff doesn't matter until we are talking + * about adding the new inode. + */ + ASSERT(pending_move == 0); + + /* * Now process the inode as if it was new. */ sctx->cur_inode_gen = left_gen; @@ -5551,10 +5558,21 @@ static int changed_inode(struct send_ctx *sctx, ret = send_create_inode_if_needed(sctx); if (ret < 0) goto out; - - ret = process_all_refs(sctx, BTRFS_COMPARE_TREE_NEW); + ret = process_all_refs(sctx, BTRFS_COMPARE_TREE_NEW, &pending_move); if (ret < 0) goto out; + + /* + * This can happen if we have deleted the old inode from + * it's parent directory, moved that parent directory + * somewhere else, and re-created the inode in that same + * parent directory. If this occurs we need to treat + * this like any other new inode that needs pending + * renames processed before we process this inode. + */ + if (pending_move) + goto out; + /* * Advance send_progress now as we did not get into * process_recorded_refs_if_needed in the new_gen case.