From patchwork Mon Jan 25 19:42:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Anasal | BDSU X-Patchwork-Id: 12044213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CC8AC433DB for ; Mon, 25 Jan 2021 19:45:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51D3B2251F for ; Mon, 25 Jan 2021 19:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731960AbhAYTpR (ORCPT ); Mon, 25 Jan 2021 14:45:17 -0500 Received: from mail-eopbgr80055.outbound.protection.outlook.com ([40.107.8.55]:23525 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731712AbhAYTn3 (ORCPT ); Mon, 25 Jan 2021 14:43:29 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lBAQqDdMoABw0dJht23SQIW1Szlu40rStuhLOdzKvQipxeoe0OrHHxu4nZ5wHtuerbetQchhbyEdivM03UKkoMnNYblUVDF6a08TLNh8JBTHG+1SDNAMpNdV/CAE6aP9yHrOFU7779Br+1xU20u4ipK0WKQifCaTpYMoMoDndy6Tc5aUY82wRaBrg1uXi4jy9Au19BGc/Bv+hJQFbYHYrwKTTUne6bRFJ0sVdSIi+2gL0ZnupVH+CsqmuiToLjbPYohoig3kEkueYSmbE31cDUhaenaY14dhhPgaCD4b2iG3HxDjRpto0NgSQwiHmiORz1HwVxW7ZVHRTJmwrWCVhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UK2iktAAOit4/I2hlMILUBVJrLgJsN5Jn27Jwuibsr4=; b=ofS2hTAe2a8Ldu3yEiizk3jYEIcx0brzVBYvqGYkwvlifrp/tZPaQj86zmz28Jf7Mdm41DV/mpn+BkAuzStd2CZzJXqngCDRWSVIXfvMfnNFBWzHZndhC97731dYNXMnLTTGtp0bw16vhbbxkJuQo/sSl1EIfFkRC4sxBh6rZKCebL0Q82OxP/jZnjiC8dhRPRgFjfjnqcZ1j9GiGC3Sv0d5iohG/f6Ku3m70GRUHdf8NqWd1CG16uB6pIn2O2udnxNLjnF0Ez3/dsTqzbaqLHOKJKmMh7v/b80pOozii9GOiq8oKkULDb+G9xQ0R3Haz4DIl7cmQRT7CdKc3TNOQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bdsu.de; dmarc=pass action=none header.from=bdsu.de; dkim=pass header.d=bdsu.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bdsu.de; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UK2iktAAOit4/I2hlMILUBVJrLgJsN5Jn27Jwuibsr4=; b=mZhijh5uTKz4id8agq/X0fswnqs12APzst5PeocZKpsPPJz/7OGujxDmDNqJrlfngcTjyL1EtFDnhMqOc7GqMK/PR7PlWSjirUubnHfqM+o+jvNod4BMC9k3O4prM/nLhSgWA7wbY5K3d1TbeJCnry6edq39qLQGccjx20FkUJSvnyQbVfRZyO7H3CiguQKViHQD25xqtyfAHr7O77T30CX9wz0S9E+yIvyK1DG7mwD6Ez2wjSW+u/giO1299alJ0tBh+iPrQ7z7oBCQTM8piuGeYNVrIdu34BspAFyCnSPXROWT19ob6o8IG+yfJJOmF89EOjHCvMgJ7ELoeEVfbg== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=bdsu.de; Received: from DB7PR03MB4297.eurprd03.prod.outlook.com (2603:10a6:10:17::30) by DB8PR03MB5962.eurprd03.prod.outlook.com (2603:10a6:10:e9::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Mon, 25 Jan 2021 19:42:06 +0000 Received: from DB7PR03MB4297.eurprd03.prod.outlook.com ([fe80::b53d:bd77:c4ae:93d]) by DB7PR03MB4297.eurprd03.prod.outlook.com ([fe80::b53d:bd77:c4ae:93d%6]) with mapi id 15.20.3784.016; Mon, 25 Jan 2021 19:42:06 +0000 From: Roman Anasal To: linux-btrfs@vger.kernel.org Cc: Roman Anasal Subject: [PATCH v2 1/4] btrfs: send: rename send_ctx.cur_inode_new_gen to cur_inode_recreated Date: Mon, 25 Jan 2021 20:42:07 +0100 Message-Id: <20210125194210.24071-2-roman.anasal@bdsu.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125194210.24071-1-roman.anasal@bdsu.de> References: <20210125194210.24071-1-roman.anasal@bdsu.de> X-Originating-IP: [2001:a61:3aef:4c01:503:a276:cbe0:8dc0] X-ClientProxiedBy: AM0PR05CA0081.eurprd05.prod.outlook.com (2603:10a6:208:136::21) To DB7PR03MB4297.eurprd03.prod.outlook.com (2603:10a6:10:17::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from nebukadnezar.fritz.box (2001:a61:3aef:4c01:503:a276:cbe0:8dc0) by AM0PR05CA0081.eurprd05.prod.outlook.com (2603:10a6:208:136::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Mon, 25 Jan 2021 19:42:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fd405c04-ec57-4ef6-3bfe-08d8c1694bd1 X-MS-TrafficTypeDiagnostic: DB8PR03MB5962: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nB3VmRjAv+IWW0gWyPNR1bswmfSh1Je5Emm4EMkC1Cr/kjTXd2typdH8IzeShcDj4/bgWG6Lg9xwpCxamchA9nxy/+vmBn6icpuir8n22AYW5zLlTNyLf/MoHwdnOz3ZszwFf9JWK8oT5LvHwPLkJp8q0CYIXzVusFG16/yVDVMzEWAv32637kMg7+GNwDoDrp5MyJHKmfHRsTahl3tsZ1rGmJoU1yEIimWKVZ7RX72iG+A0KhZUdGQUIVfODHA9xZsVM7nGulq2TyysY9BJL7w8JMzN1B0ZrqoBYmw/VMrKfOh3BIHRB7FGSfsLw3v1dcsqydlouB54EsNOaPhJFAZ3vnM8EOByuo+zJ0XDCm2gGzjyMqc2Fm1K3YDJzF84ncmrEpqNfJtNFb1zZ4R4OA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR03MB4297.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(376002)(136003)(39830400003)(396003)(346002)(86362001)(8936002)(2616005)(5660300002)(8676002)(107886003)(66476007)(66946007)(66556008)(83380400001)(52116002)(36756003)(44832011)(1076003)(16526019)(478600001)(6506007)(2906002)(786003)(316002)(4326008)(6916009)(186003)(6486002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: WjgZr79D4ianS6YqT5mmmFkaX3I6cZnTXiln0d80lGalex3k+ARzptDd2zxpvsen+3W2Z7J0pdT0PJQx375tKsnMEd3Q7gjfpnbLMjQHkK0+f5ts3CRK7kvT++eMDSXIRV4kdh1B0dUXDhBPUoijildgfVZs0iZJgJBzuP2kS8EP9cihqW1W9GyyVa4O+dLhem7/OTmBr7yW+A6eeoKzkmbDgwJrlH7jWhOQcdQ1odRhFRoXJkKuJmh4QgW3IuarKmDoJOMif4A9SqzMj3jL6wCB0nDZIwmMdvNwNSN9gx+xc2I8NbsrBcZdPtkdpRnH0UoNNODwszqT8WBtyjn8NW979iXBuFafKM+EWVsDUJ+yc6FnNbZHeovB0YdalWL3cBIOTpRAZOFJKt/QjTCOBAzGHeL5oK8W+/+Sim3mcQR5XR2Ry0ZMlqWI++y4ZM6gRQaTYNwwHEAkf3/AydXWPUcAP7/bhHLVq8qdtliS1Yt7pYFkHjlBlR96TQji7iR5W4vpNbBDKNvutzvtJIYFFkWFy0Kz49KN0PnapcYq18lE63IPjI4BDm1oqoZuTNSNlV+SfTS4ZAM7Ag3uoUhZeJlW75MKKPzG6Eup+exBHaneHi68RioVuj/Jz9Mc2ANJ3huKJSnR0u72LT6C8hsZVW+0WXGZkeo18B0J+Yz+p+vKqsjmPzPfUwWB29zlc8ivRhFnVB0bC6wEnRhdYtXxUOX6WJ69HllZhaeDYarP5SwoMmaxKZ1AhjEF/RmSZfv8MN/ve3lKudTukhCAmaeM18WcqcN8lUkHx2WYQ09cL3WDWj8leAb/URZlMwshYmzMRsg4hXr/HoDAxWhRu2mJL5iVLLlOEzJa2mPVHu4VDRUAPYqcuqa2Y7pKu8r6UUcrPB+z/P460z9Q14rfXZ5SayprH51OVE/f3gymrdkp9GqZccc2sg9GcsO2jT26BKjiFfe+QzE9msWN407sl9ivKEro+kgD1r0mLBXF9YqUurVJb0yT+Wtd7xkQhplo5J7JViVs46ro3xyTuPsKDiEodO1PsSquHR4G85+jlnTjw0schWLBXMKqFzyvn6r2a30m14Dj1xZ/i+jrktklogahCj2Hi0Nb5zEaWJ7Chp5qn0qCbwE56ko3++TXQkVWRm84 X-OriginatorOrg: bdsu.de X-MS-Exchange-CrossTenant-Network-Message-Id: fd405c04-ec57-4ef6-3bfe-08d8c1694bd1 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4297.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2021 19:42:06.3404 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8c0670a1-eeed-4da2-a08a-128fe03f692a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CrxyZtb4raycEkI0w9kYmVcxnO0R8swuD7nDgNbYjXAWqESd9EjMrYa2yt9iXOOsiyn4xEDscpJv8bqFrhEewg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR03MB5962 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org cur_inode_new_gen is used to detect whether an inode was/has to be recreated which is - currently (!) - only based on whether a changed inode as differing generations. To allow additional checks for recreating an inode (see following patch) and still have a sane naming this change was made. Signed-off-by: Roman Anasal --- fs/btrfs/send.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index fee15c4d3..ca78f66a0 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -102,7 +102,7 @@ struct send_ctx { u64 cur_ino; u64 cur_inode_gen; int cur_inode_new; - int cur_inode_new_gen; + int cur_inode_recreated; int cur_inode_deleted; u64 cur_inode_size; u64 cur_inode_mode; @@ -322,7 +322,7 @@ static int is_waiting_for_rm(struct send_ctx *sctx, u64 dir_ino, u64 gen); static int need_send_hole(struct send_ctx *sctx) { return (sctx->parent_root && !sctx->cur_inode_new && - !sctx->cur_inode_new_gen && !sctx->cur_inode_deleted && + !sctx->cur_inode_recreated && !sctx->cur_inode_deleted && S_ISREG(sctx->cur_inode_mode)); } @@ -6265,7 +6265,7 @@ static int changed_inode(struct send_ctx *sctx, u64 right_gen = 0; sctx->cur_ino = key->objectid; - sctx->cur_inode_new_gen = 0; + sctx->cur_inode_recreated = 0; sctx->cur_inode_last_extent = (u64)-1; sctx->cur_inode_next_write_offset = 0; sctx->ignore_cur_inode = false; @@ -6306,7 +6306,7 @@ static int changed_inode(struct send_ctx *sctx, */ if (left_gen != right_gen && sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) - sctx->cur_inode_new_gen = 1; + sctx->cur_inode_recreated = 1; } /* @@ -6364,7 +6364,7 @@ static int changed_inode(struct send_ctx *sctx, * reused the same inum. So we have to treat the old inode as * deleted and the new one as new. */ - if (sctx->cur_inode_new_gen) { + if (sctx->cur_inode_recreated) { /* * First, process the inode as if it was deleted. */ @@ -6401,7 +6401,8 @@ static int changed_inode(struct send_ctx *sctx, goto out; /* * Advance send_progress now as we did not get into - * process_recorded_refs_if_needed in the new_gen case. + * process_recorded_refs_if_needed in the + * cur_inode_recreated case. */ sctx->send_progress = sctx->cur_ino + 1; @@ -6418,7 +6419,7 @@ static int changed_inode(struct send_ctx *sctx, } else { sctx->cur_inode_gen = left_gen; sctx->cur_inode_new = 0; - sctx->cur_inode_new_gen = 0; + sctx->cur_inode_recreated = 0; sctx->cur_inode_deleted = 0; sctx->cur_inode_size = btrfs_inode_size( sctx->left_path->nodes[0], left_ii); @@ -6435,7 +6436,7 @@ static int changed_inode(struct send_ctx *sctx, * We have to process new refs before deleted refs, but compare_trees gives us * the new and deleted refs mixed. To fix this, we record the new/deleted refs * first and later process them in process_recorded_refs. - * For the cur_inode_new_gen case, we skip recording completely because + * For the cur_inode_recreated case, we skip recording completely because * changed_inode did already initiate processing of refs. The reason for this is * that in this case, compare_tree actually compares the refs of 2 different * inodes. To fix this, process_all_refs is used in changed_inode to handle all @@ -6451,7 +6452,7 @@ static int changed_ref(struct send_ctx *sctx, return -EIO; } - if (!sctx->cur_inode_new_gen && + if (!sctx->cur_inode_recreated && sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) { if (result == BTRFS_COMPARE_TREE_NEW) ret = record_new_ref(sctx); @@ -6466,8 +6467,8 @@ static int changed_ref(struct send_ctx *sctx, /* * Process new/deleted/changed xattrs. We skip processing in the - * cur_inode_new_gen case because changed_inode did already initiate processing - * of xattrs. The reason is the same as in changed_ref + * cur_inode_recreated case because changed_inode did already initiate + * processing of xattrs. The reason is the same as in changed_ref */ static int changed_xattr(struct send_ctx *sctx, enum btrfs_compare_tree_result result) @@ -6479,7 +6480,7 @@ static int changed_xattr(struct send_ctx *sctx, return -EIO; } - if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { + if (!sctx->cur_inode_recreated && !sctx->cur_inode_deleted) { if (result == BTRFS_COMPARE_TREE_NEW) ret = process_new_xattr(sctx); else if (result == BTRFS_COMPARE_TREE_DELETED) @@ -6493,8 +6494,8 @@ static int changed_xattr(struct send_ctx *sctx, /* * Process new/deleted/changed extents. We skip processing in the - * cur_inode_new_gen case because changed_inode did already initiate processing - * of extents. The reason is the same as in changed_ref + * cur_inode_recreated case because changed_inode did already initiate + * processing of extents. The reason is the same as in changed_ref */ static int changed_extent(struct send_ctx *sctx, enum btrfs_compare_tree_result result) @@ -6517,7 +6518,7 @@ static int changed_extent(struct send_ctx *sctx, if (sctx->cur_ino != sctx->cmp_key->objectid) return 0; - if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { + if (!sctx->cur_inode_recreated && !sctx->cur_inode_deleted) { if (result != BTRFS_COMPARE_TREE_DELETED) ret = process_extent(sctx, sctx->left_path, sctx->cmp_key); From patchwork Mon Jan 25 19:42:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Anasal | BDSU X-Patchwork-Id: 12045043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FD7CC433DB for ; Tue, 26 Jan 2021 01:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 164D423105 for ; Tue, 26 Jan 2021 01:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731515AbhAZBZF (ORCPT ); Mon, 25 Jan 2021 20:25:05 -0500 Received: from mail-eopbgr80048.outbound.protection.outlook.com ([40.107.8.48]:62438 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731604AbhAYTn1 (ORCPT ); Mon, 25 Jan 2021 14:43:27 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I6MJxg8W+462bnngIGd3IhEDQLRez+900L+a3DPGqsVaA6Puk81bJqr0X197+wMqcEz+IA4/oRbvsrg+utIWXLDGq+6vC0TrVtqoZASoAw/kCRx7kYkOePa+4Z11pogWhVQEZ8tJXI9HClEJtyJJpRXaY75zqjwQnBZOc3A2Jx6zOG9U+e7gcpCAfogxl7A0g4fEdsC8f/QgK74mvMkuzA29PEn/qlI6wBttVnIolFK2h5arfsk0fpJ7oCM8POMOjJYa9icGj05M+uaQcZD/ZFx4F6FuRRxJTqZEt+MdEYICIE5FWOlYPDee9+CIG2aDsRRAsvJo0AHklzrW15v9+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5KTtiqyhFapbU643JQbGUL1KEa2DwXAt5OOq3Gb7jmw=; b=JcjWpkbeExjFiVI0xWcjymnZWv4Ieva3FjelXA/wAxpBLEPiOKsSE8N6krSL7yUjTZUxHPY4JSpSVLfZ0Jl8VhDxMgiUB2kfUK4B0DffmyKR2T5SGAN0FujORuJARZGs3njM57yWhuRnTTNiunxBg0ejexsz8CS1EFJPyYxaAGNclnqwdiJw1XIM7eWuv8HLxmoHPLdHPbQRRSrNYspTiNFbJci426xoE1HbjGWxxLZy7zkcIYLEJEOB3nOve5Ey7jE/LMIEjst4E1oJbPYFEwfmGi1S0ak210v2XtJCDwap05UvBsc+GvfXtAsJ129MmbDtZMDFDOJQXii6yXTAXw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bdsu.de; dmarc=pass action=none header.from=bdsu.de; dkim=pass header.d=bdsu.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bdsu.de; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5KTtiqyhFapbU643JQbGUL1KEa2DwXAt5OOq3Gb7jmw=; b=c01tzxCoryoxjeBqD07uEDl0FYJs8tbJclOYtSpWnkfn16NMUpGFnulIeh9CK6lJv35OchBqM0cGnw2/TCJrC7MrUrvqbnWOwWs0kehldRi66wLJpLZQyxzlgl1mmeUBj+nWcIC+Ko+FEvlIT1NWD/ec3JUJr5tqiy+GX2XbLGpihlbnvPG3nKsicZ5kKu27zuo2mZn2YNF/3s6nsw6FQS7arq8usfX0vjJY0pkStq8AQUbvjuolxgKlu2LW0OLrmU+vERHfHlYuqg/oAVbKG6X/aOecfcO6QmunRsxJd13AYNITei05g8QnB7XpRcBAZdypU6Fli3SnR7RKUXxPhA== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=bdsu.de; Received: from DB7PR03MB4297.eurprd03.prod.outlook.com (2603:10a6:10:17::30) by DB8PR03MB5962.eurprd03.prod.outlook.com (2603:10a6:10:e9::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Mon, 25 Jan 2021 19:42:08 +0000 Received: from DB7PR03MB4297.eurprd03.prod.outlook.com ([fe80::b53d:bd77:c4ae:93d]) by DB7PR03MB4297.eurprd03.prod.outlook.com ([fe80::b53d:bd77:c4ae:93d%6]) with mapi id 15.20.3784.016; Mon, 25 Jan 2021 19:42:07 +0000 From: Roman Anasal To: linux-btrfs@vger.kernel.org Cc: Roman Anasal Subject: [PATCH v2 2/4] btrfs: send: fix invalid commands for inodes with changed type but same gen Date: Mon, 25 Jan 2021 20:42:08 +0100 Message-Id: <20210125194210.24071-3-roman.anasal@bdsu.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125194210.24071-1-roman.anasal@bdsu.de> References: <20210125194210.24071-1-roman.anasal@bdsu.de> X-Originating-IP: [2001:a61:3aef:4c01:503:a276:cbe0:8dc0] X-ClientProxiedBy: AM0PR05CA0081.eurprd05.prod.outlook.com (2603:10a6:208:136::21) To DB7PR03MB4297.eurprd03.prod.outlook.com (2603:10a6:10:17::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from nebukadnezar.fritz.box (2001:a61:3aef:4c01:503:a276:cbe0:8dc0) by AM0PR05CA0081.eurprd05.prod.outlook.com (2603:10a6:208:136::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Mon, 25 Jan 2021 19:42:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b2a24080-3e3f-4386-1d60-08d8c1694cca X-MS-TrafficTypeDiagnostic: DB8PR03MB5962: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WEeAZL29qN8viiiAF/DZ1mW7k/HyEAnaDkrdWBTa3qmZndQn2zOFESWqK+DTyn8ZNkA9+jSkuk4rBwgHhr5wGZwxPvXl7xJo6/jzhVkaKqgHpwrk//5HaVaWOhY4/UGlbIpXwTsrVLJBJNNNmUsgyjfFmV6Q+cGFyN6Onw6KFAUPRoRNcL+Qxr0e9gPRDnwDSTrFILTRkf0AjqaPrYsvdSZyq9yRvXtFupydJna4Bwcl+EEbfBf4qOGnd94mvlqb+1TXnarqHaVWqxL2Jl/t/z/e3JRrAT79JvWixU7oatLc+hFafs6OlJBK1dX7qy7rK2wyOBCCiy5pAreJYsVGIhGaJiC7Lgr4LENUp+yknAuO2mXpWnRFNDM4GiPRNLbf/KzCaGrxchEAUOS7Z+AsCQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR03MB4297.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(376002)(136003)(39830400003)(396003)(346002)(86362001)(8936002)(2616005)(5660300002)(8676002)(107886003)(66476007)(66946007)(66556008)(83380400001)(52116002)(36756003)(44832011)(1076003)(16526019)(478600001)(6506007)(2906002)(786003)(316002)(4326008)(6916009)(186003)(6486002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: wsoTXVjIKBC+mPmFGrPWTnCto0t4HdF1UdhhLPPz3UjhbgBltK+XcR6prT48D+Ncta2M7McbH2HJ914az/bNb70Zb8TzQS+/AgdfFUFA3Yg0Ww63no1Uwusu9Dui8mfxMx9kwIFNMsgO3qW7kFcaPQh/ZpuRifbFMeJHHU6Tl8QsrIiWvBf4iLel831v+XWxhXsMA1bN8p11epy69L+1C6Dd4c06JMUeKN/gsvkdxtSLYGf/3HIl0kYPNmJPQbYYqt2v7a22gE1Ew9sxnNL4iPlmLo5RfXu9ZwHr2K2rYIgeskGMlKol3iDADsuWuyrYYznuaXRLI7ZTOcMSi4vvYqdcLn9OdzVMlKPE9d2oL1CevbIa2bwHsBzACVG/EHDjMo27e0twyR7FF26QXZxmBFlPGQOXNl2QZFrvqAJblPn3wsDxF80TElQZyz6lw1YU61G62tc5ASrXDxMj/XmA6AdCgTcSvFOz2lxrj3E94s8VtF3PTKltR/YC9MIXNKcacx8W174Ffr7PMTB26FPLQukGlQX+SPqT2OH1c04awKhCT0yFy5I5RwMbGZ7PFSOAb6fH76UCxkdLO6XSwjdWhCZ+qfr1OcdWIztiwyoU/PGAs8TOvrNhp+EOH/MBE8TzLT1dniGvgJ5NizUp1T/H+fcW+1wTud5UvG90XMaXW+6849sNYAhDhTGns8N+1dH1WSfbPzlGWFcMPixPde8kJFsCda6Nv4SWJBaslMOliJVv8EeUjeG7dj8bsSoPp8rYNt5muSPkOIRqnY29KnDFt0yRN/GhTiwOAvDll+X69sXOa7yEichaAU/5j4j2VCwyRHZtn/WdbprNFeFX7unhQ2AcBwKrUw3/O/bcqjJcZc2e7MlR2p2jI/eOm1kBjmtKxhD0lRMMHyxBIUVwnP4xjsyUnQC21MLAYYhbfPkkleEr9QQkaM7OHAPt27dBB/IiC/hYTmBYsH49mqywqSSBYc0yCFaZnq29RqnaKvK0QYdjRSntg6hh6eulmTILuUKuJje2FL2+ilYOGajBzft/qU7zbfbvM9pswzamjam28fkYWMLTm4pgeNk3j+lLW9/r4v7bQPsanTMQjPxEeSOvvEwTyxL0IwXPSm/V/5+lWwLcTzohiFgfPOTpvZ8r2xzL X-OriginatorOrg: bdsu.de X-MS-Exchange-CrossTenant-Network-Message-Id: b2a24080-3e3f-4386-1d60-08d8c1694cca X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4297.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2021 19:42:07.9144 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8c0670a1-eeed-4da2-a08a-128fe03f692a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KOSPwivzpduGKQbqGX3cTv3JeOgvJlHyZAgA3Ig8yJrBS5ngXkb0tFL82ynOF/RUDvOJlQRr+h9cCtrlPsc0Mw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR03MB5962 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When doing a send, if a new inode has the same number as an inode in the parent subvolume it will only be detected as to be recreated when the genrations differ. But with inodes in the same generation the emitted commands will cause the receiver to fail. This case does not happen when doing incremental sends with snapshots that are kept read-only by the user all the time, but it may happen if - a snapshot was modified after it was created - the subvol used as parent was created independently from the sent subvol Example reproducers: # case 1: same ino at same path btrfs subvolume create subvol1 btrfs subvolume create subvol2 mkdir subvol1/a touch subvol2/a btrfs property set subvol1 ro true btrfs property set subvol2 ro true btrfs send -p subvol1 subvol2 | btrfs receive --dump The produced tree state here is: |-- subvol1 | `-- a/ (ino 257) | `-- subvol2 `-- a (ino 257) Where subvol1/a/ is a directory and subvol2/a is a file with the same inode number and same generation. Example output of the receive command: At subvol subvol2 snapshot ./subvol2 uuid=19d2be0a-5af1-fa44-9b3f-f21815178d00 transid=9 parent_uuid=1bac8b12-ddb2-6441-8551-700456991785 parent_transid=9 utimes ./subvol2/ atime=2021-01-11T13:41:36+0000 mtime=2021-01-11T13:41:36+0000 ctime=2021-01-11T13:41:36+0000 link ./subvol2/a dest=a unlink ./subvol2/a utimes ./subvol2/ atime=2021-01-11T13:41:36+0000 mtime=2021-01-11T13:41:36+0000 ctime=2021-01-11T13:41:36+0000 chmod ./subvol2/a mode=644 utimes ./subvol2/a atime=2021-01-11T13:41:36+0000 mtime=2021-01-11T13:41:36+0000 ctime=2021-01-11T13:41:36+0000 => the `link` command causes the receiver to fail with: ERROR: link a -> a failed: File exists Second example: # case 2: same ino at different path btrfs subvolume create subvol1 btrfs subvolume create subvol2 mkdir subvol1/a touch subvol2/b btrfs property set subvol1 ro true btrfs property set subvol2 ro true btrfs send -p subvol1 subvol2 | btrfs receive --dump The produced tree state here is: |-- subvol1 | `-- a/ (ino 257) | `-- subvol2 `-- b (ino 257) Where subvol1/a/ is a directory and subvol2/b is a file with the same inode number and same generation. Example output of the receive command: At subvol subvol2 snapshot ./subvol2 uuid=ea93c47a-5f47-724f-8a43-e15ce745aef0 transid=20 parent_uuid=f03578ef-5bca-1445-a480-3df63677fddf parent_transid=20 utimes ./subvol2/ atime=2021-01-11T13:58:00+0000 mtime=2021-01-11T13:58:00+0000 ctime=2021-01-11T13:58:00+0000 link ./subvol2/b dest=a unlink ./subvol2/a utimes ./subvol2/ atime=2021-01-11T13:58:00+0000 mtime=2021-01-11T13:58:00+0000 ctime=2021-01-11T13:58:00+0000 chmod ./subvol2/b mode=644 utimes ./subvol2/b atime=2021-01-11T13:58:00+0000 mtime=2021-01-11T13:58:00+0000 ctime=2021-01-11T13:58:00+0000 => the `link` command causes the receiver to fail with: ERROR: link b -> a failed: Operation not permitted Signed-off-by: Roman Anasal --- v2: - move declarations to the top --- fs/btrfs/send.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index ca78f66a0..c8b1f441f 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -6263,6 +6263,7 @@ static int changed_inode(struct send_ctx *sctx, struct btrfs_inode_item *right_ii = NULL; u64 left_gen = 0; u64 right_gen = 0; + u64 left_type, right_type; sctx->cur_ino = key->objectid; sctx->cur_inode_recreated = 0; @@ -6299,12 +6300,17 @@ static int changed_inode(struct send_ctx *sctx, right_gen = btrfs_inode_generation(sctx->right_path->nodes[0], right_ii); + left_type = S_IFMT & btrfs_inode_mode( + sctx->left_path->nodes[0], left_ii); + right_type = S_IFMT & btrfs_inode_mode( + sctx->right_path->nodes[0], right_ii); + /* * The cur_ino = root dir case is special here. We can't treat * the inode as deleted+reused because it would generate a * stream that tries to delete/mkdir the root dir. */ - if (left_gen != right_gen && + if ((left_gen != right_gen || left_type != right_type) && sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) sctx->cur_inode_recreated = 1; } @@ -6359,10 +6365,10 @@ static int changed_inode(struct send_ctx *sctx, } else if (result == BTRFS_COMPARE_TREE_CHANGED) { /* * We need to do some special handling in case the inode was - * reported as changed with a changed generation number. This - * means that the original inode was deleted and new inode - * reused the same inum. So we have to treat the old inode as - * deleted and the new one as new. + * reported as changed with a changed generation number or + * changed inode type. This means that the original inode was + * deleted and new inode reused the same inum. So we have to + * treat the old inode as deleted and the new one as new. */ if (sctx->cur_inode_recreated) { /* From patchwork Mon Jan 25 19:42:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Anasal | BDSU X-Patchwork-Id: 12044215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DAE7C433E0 for ; Mon, 25 Jan 2021 19:46:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3A112251F for ; Mon, 25 Jan 2021 19:46:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732060AbhAYTpm (ORCPT ); Mon, 25 Jan 2021 14:45:42 -0500 Received: from mail-eopbgr80048.outbound.protection.outlook.com ([40.107.8.48]:62438 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732080AbhAYTn5 (ORCPT ); Mon, 25 Jan 2021 14:43:57 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HY45OepgjEFaPZXYZ+X5ydJrMnrQa9RfuSUDs/B5A3KeN3hBdGwt1gV0u9qI+geWTm8dmwRFAkjuoK1sLA5BBTks0D+NMWlaRe4mIdtR6tSm+6BleFfQZF71Pvef7QiF1oEcfBNGy3Ob9KrOmciJnKjgwzeskF1rY5a0yTSIUtedvczc+YrvwNjpxrk9YG9mIBKVwgsCzus76rP0CKWrss8/nOqVwpWstObJu3CeaRiOP2Um0pRt3i+W8rYhwGbtgnfvouTVqH7qB4fUxtn6mC2vMR8CrfbjofzOrV3GmZschcrHghjdlYTu9eNc7rHO7YXr29c2WQ8Sgx8ii3Wh8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F6z5UFG0TkCEPw/dudiFKMVK1rl9HIDGKoFW0X2z8LI=; b=YgLntgTcibboVbE7jT7hT16k8VVqPzEuXZzylzwrwI1t6UygUjKp2i0PuMRXdJRiMlG6PfWsqM4wf8zLkmtH6XmQQitBVmpnFQ0FX99/IvnXk8kMpZOFstryBzul94K3XEUoOBGfDkaC39itqRQmhjKuPe/k1tDwWx9WfIpetEPJP844WEMBpw0ZvnPAXuxhDx3pCx34/HLOSVz3KHIeM+2bKjcU8RoR+38mehaIApB69wZ8gkXog57pKCpDwFpdYysqLE47i+DVWtC8sCJnZhejTksjgZbrvnb3qDT6ZUZnqkqk/tM4D0YlsMpYYAQyDaU1Y/LbuYrlw8OJsLrl1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bdsu.de; dmarc=pass action=none header.from=bdsu.de; dkim=pass header.d=bdsu.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bdsu.de; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F6z5UFG0TkCEPw/dudiFKMVK1rl9HIDGKoFW0X2z8LI=; b=DcSekaQMBKOPRZPtDZ6olEqWCK1h1QKK2mI+NhrseRj4r9+wB+nEKwc9h/vVsqEyojmu9pC+eEGgpAZjhQacmeTUZSEMADvzYm2cGBCPO1aw4gv27WvS4fBjPFlQZDRMU0+FHfHNM24/jTvrqSWNrlbytAYpYqMT6o54UjJL8y7AplO3OPhwRCOneLF6p3LAelhAfNBVyVu54lNI5Z72Jb0s2scPSWc8dyDQCCczZWBzsssWJP4qqS9qVgK0+LlUnLjYHAEJMv4jbEHvBiefkOacKC6VBvtLqX9CmslEsODgwxhDU3EyVO7oHa3b3veO3uc3JSu+91NIXZn0dziThA== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=bdsu.de; Received: from DB7PR03MB4297.eurprd03.prod.outlook.com (2603:10a6:10:17::30) by DB8PR03MB5962.eurprd03.prod.outlook.com (2603:10a6:10:e9::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Mon, 25 Jan 2021 19:42:09 +0000 Received: from DB7PR03MB4297.eurprd03.prod.outlook.com ([fe80::b53d:bd77:c4ae:93d]) by DB7PR03MB4297.eurprd03.prod.outlook.com ([fe80::b53d:bd77:c4ae:93d%6]) with mapi id 15.20.3784.016; Mon, 25 Jan 2021 19:42:09 +0000 From: Roman Anasal To: linux-btrfs@vger.kernel.org Cc: Roman Anasal Subject: [PATCH v2 3/4] btrfs: send: fix invalid commands for inodes with changed rdev but same gen Date: Mon, 25 Jan 2021 20:42:09 +0100 Message-Id: <20210125194210.24071-4-roman.anasal@bdsu.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125194210.24071-1-roman.anasal@bdsu.de> References: <20210125194210.24071-1-roman.anasal@bdsu.de> X-Originating-IP: [2001:a61:3aef:4c01:503:a276:cbe0:8dc0] X-ClientProxiedBy: AM0PR05CA0081.eurprd05.prod.outlook.com (2603:10a6:208:136::21) To DB7PR03MB4297.eurprd03.prod.outlook.com (2603:10a6:10:17::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from nebukadnezar.fritz.box (2001:a61:3aef:4c01:503:a276:cbe0:8dc0) by AM0PR05CA0081.eurprd05.prod.outlook.com (2603:10a6:208:136::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Mon, 25 Jan 2021 19:42:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 77d087bc-9e8a-41ee-e2a0-08d8c1694de0 X-MS-TrafficTypeDiagnostic: DB8PR03MB5962: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uXOYSKt4FLrojYekJEA8nYOHDCogTbs1XWU74Xk3RToD0JVBMs5S080toIdh1340u8k06OxNLCuJS4yM9/bD+USKPxlbFaR1c5n/p8Fej2JZqbfIWqEcHz4LrU9u42DWPL4RWzgK/++ggnKa5YgPqiG6KmXeOwP0Z3m+e19GEilOYrqJuehomf3fZkKS7L/FBLyqe0UDzUlxRtxp3T0aX7mHqL6GjlF7xxNsprZgJWvhlxQbUhJPURyBJSPpHdIzqHeqGwTVLXe05zeLf9gF8yye9XWLEfExiVyPv38UF6hvxcQQuejNmU+sCWhnQdtWDOmTY58Vvf+GYDKXnL41q+manGw6kRtqxfiUFyE+c0ulWxAnfsIrAOgr6tMfenApr2UPBcAmgp/4ONzY2w5yJA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR03MB4297.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(376002)(136003)(39830400003)(396003)(346002)(86362001)(8936002)(2616005)(5660300002)(8676002)(107886003)(66476007)(66946007)(66556008)(83380400001)(52116002)(36756003)(44832011)(1076003)(16526019)(478600001)(6506007)(2906002)(786003)(316002)(4326008)(6916009)(186003)(6486002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: /ANWlDfdJPzLr/nNLr/RfiBuurPOcF3prFe1JnYz2jQHYGU/Xtg3XBdnMrb2iduLMFfGuNDMOy/C9MbSGkTrtGF6ZvhZx0J7fEC6PyXGyMjeu4LaZGRZnfK1FcE4Cx/z4rIGRr05OcIDzQ+A6wNL1799GY2HKHqKFWvb8XG8PMpKaN5HDmihMEvwUh+BstyI9w6Py7HqbaU2ssva3aqkwYN2jfb7leefsUa7Yk7BgrMUodZzlwjkD5oVo1AUARyPDe5q/OCmo8Q/PPThvZOFX6Zc2rCWmuEzDCLJ2rPESK2fEaR/+4jwh7iR2jsd0VAxYo5dI9vfoeGDZYengT2z4MJSeBKG4nOO7Z7eyXpn0/gvRLT3oPBdgcfABBq4nWyb343MNV7CCKXQXuLu6tVGPMPkFIInCNHE3VK9bZ2TCyXGXYUbkLy9qs6l0ix1pAMUMlurPz2hl3L2CqT3RSWCte9alebta7dLTNEt+yfoLHyJkYQKKHJF3prs01ciUhbE89/kAxI4acf642ywQguT26UeWXtRZ4fnqEzE2+WaTB94QGAyOD9YS1v/EZN2at4EJVYrQ6QocFMErXIms0TD+ivLteNy5mhWOYUlXbR93DUzpE9rMhWfmeNyIl8XUOZu1r0DVLQBqGQWo7Wtgk/R8xB1pRzva94DUnA+6ancNM+T0e5RVwwuYZgQVBok9o/K6NwnBBFtWK4J1qfI5u5GiA8Hln09ipt38cBEBrwmf9BVx1Ay45TphqLAvHkQPVm5pPwPRP6bR6Jw9GAUzVCMG1cOtsdpxGAKwGgEH2RoFjKfbT+OiYpqglfY/01A2gWxxZZkM7BTO/LnC4RxHj5IBmcS4OVFIuwahiS7mxjSyiWe9Hb9BT6rf3/SPg+doyVRFOeeNsRIILkqhSaRqF4MVr3R3lj+X9G6k3HNbCjd6yEKnyrixLeJl1aa5oFuTrmmWEJxB9t2PNjKnFASZt3j6BqwSCbdPZyYRFSIiEsGXqAxvuK2kE67Eu8s9dXSBxULF4Ug2GrrTWv8rEtI0ugqjYp/L3FSIfYlKET2Qliv6XYAJshBBVXbWyyY3RKTKR72FGonhXEjHPt7qRSQzFITAHd8kLsPcCjwcNjde8tiqX7TCW8ffSwPMVj/Ypgp0ZAW X-OriginatorOrg: bdsu.de X-MS-Exchange-CrossTenant-Network-Message-Id: 77d087bc-9e8a-41ee-e2a0-08d8c1694de0 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4297.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2021 19:42:09.6764 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8c0670a1-eeed-4da2-a08a-128fe03f692a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qHS5in64SZtOtqyJgD5RLgH1RXTySJpuwLN5rIO52WatdodVNzNebfUSQT5OZmx9K9B9O1K1hBMH90HDPO+VZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR03MB5962 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is analogous to the preceding patch ("btrfs: send: fix invalid commands for inodes with changed type but same gen") but for changed rdev: When doing an incremental send, if a new inode has the same number as an inode in the parent subvolume, was created with the same generation but has differing rdev it will not be detected as changed and thus not recreated. This will lead to incorrect results on the receiver where the inode will keep the rdev of the inode in the parent subvolume or even fail when also the ref is unchanged. This case does not happen when doing incremental sends with snapshots that are kept read-only by the user all the time, but it may happen if - a snapshot was modified in the same transaction as its parent after it was created - the subvol used as parent was created independently from the sent subvol Example reproducers: # case 1: same ino at same path btrfs subvolume create subvol1 btrfs subvolume create subvol2 mknod subvol1/a c 1 3 mknod subvol2/a c 1 5 btrfs property set subvol1 ro true btrfs property set subvol2 ro true btrfs send -p subvol1 subvol2 | btrfs receive --dump The produced tree state here is: |-- subvol1 | `-- a (ino 257, c 1,3) | `-- subvol2 `-- a (ino 257, c 1,5) Where subvol1/a and subvol2/a are character devices with differing minor numbers but same inode number and same generation. Example output of the receive command: At subvol subvol2 snapshot ./subvol2 uuid=7513941c-4ef7-f847-b05e-4fdfe003af7b transid=9 parent_uuid=b66f015b-c226-2548-9e39-048c7fdbec99 parent_transid=9 utimes ./subvol2/ atime=2021-01-25T17:14:36+0000 mtime=2021-01-25T17:14:36+0000 ctime=2021-01-25T17:14:36+0000 link ./subvol2/a dest=a unlink ./subvol2/a utimes ./subvol2/ atime=2021-01-25T17:14:36+0000 mtime=2021-01-25T17:14:36+0000 ctime=2021-01-25T17:14:36+0000 utimes ./subvol2/a atime=2021-01-25T17:14:36+0000 mtime=2021-01-25T17:14:36+0000 ctime=2021-01-25T17:14:36+0000 => the `link` command causes the receiver to fail with: ERROR: link a -> a failed: File exists Second example: # case 2: same ino at different path btrfs subvolume create subvol1 btrfs subvolume create subvol2 mknod subvol1/a c 1 3 mknod subvol2/b c 1 5 btrfs property set subvol1 ro true btrfs property set subvol2 ro true btrfs send -p subvol1 subvol2 | btrfs receive --dump The produced tree state here is: |-- subvol1 | `-- a (ino 257, c 1,3) | `-- subvol2 `-- b (ino 257, c 1,5) Where subvol1/a and subvol2/b are character devices with differing minor numbers but same inode number and same generation. Example output of the receive command: At subvol subvol2 snapshot ./subvol2 uuid=1c175819-8b97-0046-a20e-5f95e37cbd40 transid=13 parent_uuid=bad4a908-21b4-6f40-9a08-6b0768346725 parent_transid=13 utimes ./subvol2/ atime=2021-01-25T17:18:46+0000 mtime=2021-01-25T17:18:46+0000 ctime=2021-01-25T17:18:46+0000 link ./subvol2/b dest=a unlink ./subvol2/a utimes ./subvol2/ atime=2021-01-25T17:18:46+0000 mtime=2021-01-25T17:18:46+0000 ctime=2021-01-25T17:18:46+0000 utimes ./subvol2/b atime=2021-01-25T17:18:46+0000 mtime=2021-01-25T17:18:46+0000 ctime=2021-01-25T17:18:46+0000 => subvol1/a is renamed to subvol2/b instead of recreated to updated rdev which results in received subvol2/b having the wrong minor number: 257 crw-r--r--. 1 root root 1, 3 Jan 25 17:18 subvol2/b Signed-off-by: Roman Anasal --- v2: - add this patch to also handle changed rdev --- fs/btrfs/send.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index c8b1f441f..ef544525f 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -6263,6 +6263,7 @@ static int changed_inode(struct send_ctx *sctx, struct btrfs_inode_item *right_ii = NULL; u64 left_gen = 0; u64 right_gen = 0; + u64 left_rdev, right_rdev; u64 left_type, right_type; sctx->cur_ino = key->objectid; @@ -6285,6 +6286,8 @@ static int changed_inode(struct send_ctx *sctx, struct btrfs_inode_item); left_gen = btrfs_inode_generation(sctx->left_path->nodes[0], left_ii); + left_rdev = btrfs_inode_rdev(sctx->left_path->nodes[0], + left_ii); } else { right_ii = btrfs_item_ptr(sctx->right_path->nodes[0], sctx->right_path->slots[0], @@ -6300,6 +6303,9 @@ static int changed_inode(struct send_ctx *sctx, right_gen = btrfs_inode_generation(sctx->right_path->nodes[0], right_ii); + right_rdev = btrfs_inode_rdev(sctx->right_path->nodes[0], + right_ii); + left_type = S_IFMT & btrfs_inode_mode( sctx->left_path->nodes[0], left_ii); right_type = S_IFMT & btrfs_inode_mode( @@ -6310,7 +6316,8 @@ static int changed_inode(struct send_ctx *sctx, * the inode as deleted+reused because it would generate a * stream that tries to delete/mkdir the root dir. */ - if ((left_gen != right_gen || left_type != right_type) && + if ((left_gen != right_gen || left_type != right_type || + left_rdev != right_rdev) && sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) sctx->cur_inode_recreated = 1; } @@ -6350,8 +6357,7 @@ static int changed_inode(struct send_ctx *sctx, sctx->left_path->nodes[0], left_ii); sctx->cur_inode_mode = btrfs_inode_mode( sctx->left_path->nodes[0], left_ii); - sctx->cur_inode_rdev = btrfs_inode_rdev( - sctx->left_path->nodes[0], left_ii); + sctx->cur_inode_rdev = left_rdev; if (sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) ret = send_create_inode_if_needed(sctx); } else if (result == BTRFS_COMPARE_TREE_DELETED) { @@ -6396,8 +6402,7 @@ static int changed_inode(struct send_ctx *sctx, sctx->left_path->nodes[0], left_ii); sctx->cur_inode_mode = btrfs_inode_mode( sctx->left_path->nodes[0], left_ii); - sctx->cur_inode_rdev = btrfs_inode_rdev( - sctx->left_path->nodes[0], left_ii); + sctx->cur_inode_rdev = left_rdev; ret = send_create_inode_if_needed(sctx); if (ret < 0) goto out; From patchwork Mon Jan 25 19:42:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Anasal | BDSU X-Patchwork-Id: 12044965 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E28CC43381 for ; Tue, 26 Jan 2021 00:08:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F505229C4 for ; Tue, 26 Jan 2021 00:08:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732051AbhAYX6i (ORCPT ); Mon, 25 Jan 2021 18:58:38 -0500 Received: from mail-eopbgr80055.outbound.protection.outlook.com ([40.107.8.55]:23525 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732081AbhAYTnz (ORCPT ); Mon, 25 Jan 2021 14:43:55 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YHQU/Y8KNMknxF/iw1RoLN9V0hUo3YP/rbnZN0bYZFXmwgh18P5HEB/FtRFpNtWzyhy66he8AWfKQoTAbcVEGxFsjXzEK0N5CBCDuznmDSVMLe0cEcWDSoYVtBLRhANOBW/3mw4cqj57Mx9VNEUIXqo/soNzhfIXQuAPOmImy+h97spitrrI78O4Vggs9TbaD2r5Mnywiw/ulmNMIpAdvgaazeJhXjaD3E+V5mzPI7kk2oJ+8FwAVWHvUq3x5oYPSgaxnTakZtuqTbnkAIeLIHdivgwvmxfGBdz91wpqp56bOHREcwz4/3iRiJf1BQgARgcI21FAXW2ayxZmwKD5KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BR22kljIC6t7FuEDHJVejagCLDpNch30HZDv0D+oCaI=; b=mbN0kRsyCWIszuFTzMA+UmUIZtH4xQwaLqguB1C5F+7xjeorx+uOD0pK5EHkRuLfpPmUMb3Mrph1lGqVO0BytAqYWFUn+XxdjLj7REnMwG+6qBBtf3y8aGbwrBgq+p0r38gta3lQRSAZ7kC/w5II7/Ldh/r6Ko2eTYAESqT16sIBYOixxXN0cqEPCXVHZV/IywtsWy5BbxPuqJvZG+obVcurQnu4h4i3SOVKPpOA0283aIs8epIol+4OwErQ4Iv4prXKQsHMi6OeWiBsfEsoOAyYuqHGA3Z6psr0OBueimV1e+NXrOK/SWEgPS5kbGiLJQWVq03sEOUMiVVdJGVBUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bdsu.de; dmarc=pass action=none header.from=bdsu.de; dkim=pass header.d=bdsu.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bdsu.de; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BR22kljIC6t7FuEDHJVejagCLDpNch30HZDv0D+oCaI=; b=D2d8nXI9O7dGe3U0T851CN5al9mjW2odsfZxuMMbzz1zEuElvWOjqjz9KzKBBvqCSg+tWT7lqTVFMUUv++/AxiY6URS1L3AlI8C0BAVI3pFP/Pu+rosyzmlcto1FHJ+UogcMsy0Laa7p7UBSsFF44vhJEqla1KQqCJbYyA2Tvuwa9d4f1Mt1kjDw7pGMbHYvBui5nrUGbvJnpTTwQ4YJ7YLNpv+r7COD+1zSF/ul5E/wXh1Eya1OKyUEWkq/rlbf/aY9TLnM/DN8mQ5cqtoUhHYWYnKBek4jdxOLjy39DS0pqWtC799QZbbYkJQvEJZ00IFVznDkU1b4qRV7ipRQBw== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=bdsu.de; Received: from DB7PR03MB4297.eurprd03.prod.outlook.com (2603:10a6:10:17::30) by DB8PR03MB5962.eurprd03.prod.outlook.com (2603:10a6:10:e9::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Mon, 25 Jan 2021 19:42:12 +0000 Received: from DB7PR03MB4297.eurprd03.prod.outlook.com ([fe80::b53d:bd77:c4ae:93d]) by DB7PR03MB4297.eurprd03.prod.outlook.com ([fe80::b53d:bd77:c4ae:93d%6]) with mapi id 15.20.3784.016; Mon, 25 Jan 2021 19:42:12 +0000 From: Roman Anasal To: linux-btrfs@vger.kernel.org Cc: Roman Anasal Subject: [PATCH v2 4/4] btrfs: send: fix invalid commands for inodes in disconnected roots Date: Mon, 25 Jan 2021 20:42:10 +0100 Message-Id: <20210125194210.24071-5-roman.anasal@bdsu.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125194210.24071-1-roman.anasal@bdsu.de> References: <20210125194210.24071-1-roman.anasal@bdsu.de> X-Originating-IP: [2001:a61:3aef:4c01:503:a276:cbe0:8dc0] X-ClientProxiedBy: AM0PR05CA0081.eurprd05.prod.outlook.com (2603:10a6:208:136::21) To DB7PR03MB4297.eurprd03.prod.outlook.com (2603:10a6:10:17::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from nebukadnezar.fritz.box (2001:a61:3aef:4c01:503:a276:cbe0:8dc0) by AM0PR05CA0081.eurprd05.prod.outlook.com (2603:10a6:208:136::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Mon, 25 Jan 2021 19:42:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c2c18c6e-8702-4cca-688f-08d8c1694f96 X-MS-TrafficTypeDiagnostic: DB8PR03MB5962: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oqBkIqG8MU1l2wpUQyv62TZqFCxMhz/Rpb0Quprgnwut1rLUmYoXYAho2HqYF0Qn8TRy5SseRB8cTAJ6AI5X35fvFMtSW56lt50hFw6XwZSLdLr5/xmqBIc9dTiznleiidurEctgFoNy646wEyT0/MoyA1hsJAUArpLL4C1Y+kbGRtdn4qcxg6uH9Xkiyr7F2OV77hJAFNvqMi/1aM8N4f4iizoAQ8kJ9tVRa2tn5WIxiFo2BpnJhEFGeAlOd/h2YT2A6XsPDOVReZ0gKb80L6HDNnppPN9qoCyi25bLy35Jtv0KlsdBcJox6GxTol1fpETsuY19xWpinRPd8Oc2i6J9fm4Np4HD74siX/S+n76bc2Up/XZFkNil6evhx2n9g6/x+EcRkmi7QxVRtwQ0VxYSBFcdooAhLTO2uR7Jf1zN2lCYM/kc1Tni0KUc+ldT8SvjwruR09z1monquyw84Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR03MB4297.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(376002)(136003)(39830400003)(396003)(346002)(86362001)(8936002)(2616005)(5660300002)(8676002)(107886003)(66476007)(66946007)(66556008)(83380400001)(52116002)(36756003)(44832011)(1076003)(966005)(16526019)(478600001)(6506007)(2906002)(786003)(316002)(4326008)(6916009)(186003)(6486002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: G+bQNkv4JbH1uzkUWN1uVevLb4WSo63OY2F2dIK7Zj2d/aRQbIQxv8g3tumDYJUPbBPuDCB/4KODdPmvr4WWTFZgunwdfQEYwf9jVPOVWq7kuJ+v693yo1eMZmg9ZHS9eBaSGHqhcgebjI6Qj9bhPT2OxGA4EIpJ1eE2sLpMuFNuxZp1/8V1/52hml28SlGzdMGK2aN/UNRCU96OOisiOLr+a9m4mQyOJMCA1c9+AP3jGKWllW9F3k8sScafsYZ/XwdBNuS4WwvVYRFlv9bWLGJTz5pEwbPOkhfj0sK0epe2Y9W4fnEiXLPe5iat5jzaoxPDKfSchsi9iAvWO5+FbgMi/vv38Kk/MDVqIxtMdTCtqfSc3t0Q1qqULzCOUfYb9PMRQpoAb2wNXjjOyicSx5uaUefQ79/dlZ/eNvgsIWuRJ1oosarVgJLBdLera75Fjr8cy0qmjDyq+aCl5/AdWQ5oh+biYN8rV5K5SFnZ06HsJxKv98S/lnB/z7QWuMY4EuF7OP8pt74xNsgGfKpVK8kuk9K08AUOz+9q2PNzRecP3ujI0OuPontoTH2NvqtpjOf/+IgRCvM4VQDNixy2eAKU4onvrOXqU18IjkxBAP4jl4GSGvZ6BE+1S2vFLAz1yxFuo+Qn8+ugtv/dvK7fVOF4wvUrsQwWFea7OGhPQfW1YwWQvM/4QSOrSg1ESfLZbn8YFkAViqYAaxwOb/fUjlAc6VGKZeFCID2rlaroY7JDDF/3IYcsmLEBX04l9omOXTeWxkLKX2ApVRp6q5bWUjTlNy14m3mz4a81PyCf1yDiByc3OVMNSMPdQ3YdU26yPXei77LmwJJkirLPyynCXqeAwZlXQE4ocbfL/4eJgAUjheEEwjH0DND6MHypP7hP6ob41QDfIFqC37okA4W6ScXpcYlt1C59WDeHwS5+xU2R0sUkFBFOh5JSo0nloRfhyXdKUOtrJPukhGgI8fKYQXq1bbABlY0OJlJcHi9RiMFhmmzd7GAfaRG2D8b2jjue3JZ328X5J1Eqlf4DWp4645LyUarAPOiU+s64DiOlCSlbZOJI0mv87dVMSl+00pfR/yu1t5BTvi7NqKhPKUFskyaNIaEHrzaSSdgHQKclIsiCeC3TqOEY3EpI3VJzn5/i X-OriginatorOrg: bdsu.de X-MS-Exchange-CrossTenant-Network-Message-Id: c2c18c6e-8702-4cca-688f-08d8c1694f96 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4297.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2021 19:42:12.5178 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8c0670a1-eeed-4da2-a08a-128fe03f692a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JYttLQ6CXTLex38Kv39LqXHQKo0vSq+j5Lgd+vTI2wKjjE76vq+5pekwNSWK44zUoV8Tt0mrvtz3SfX5ytYR1A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR03MB5962 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When doing an inceremental send using an independently created subvolume as the send parent compare_refs will falsely report changed refs for inodes with the same inode number, same generation and same ref name. This is due to dir_changed returning true if the generations of the parent directory differ in the subvolume and the send parent. Normally this situation would cause the parent directory to be recreated and the contained inodes would need to be moved (e.g. by link/unlink). In the case of the root directory (ino BTRFS_FIRST_FREE_OBJECTID) though changed_inode will not try to recreated it since this would produce a stream trying to remove and recreate the subvolume itself. For independently created subvolumes the generation will always be different since create_subvol() commits the transaction after createing a new subvolume. By handling this case in dir_changed as well the produced commands are correct again. Summarizing the conditions for this: - inode has same number, type/rdev, ref and generation in subvolume and send parent - ref is a child of the subvolume root directory - root directory has the same inode number - which is always BTRFS_FIRST_FREE_OBJECTID - root directory has different generation in subvolume and send parent which is always true for independent subvolumes, i.e. if they're not snapshots (of snapshots) of one another Example reproducer: btrfs subvolume create subvol1 btrfs subvolume create subvol2 touch subvol1/a subvol2/a btrfs property set subvol1 ro true btrfs property set subvol2 ro true btrfs send -p subvol1 subvol2 | btrfs receive --dump The produced tree state here is (starting at gen 6): |-- subvol1 (ino 256, gen 6) | `-- a (ino 257, gen 8) | `-- subvol2 (ino 256, gen 7) `-- a (ino 257, gen 8) subvol1/a and subvol2/a are files with the same inode number, generation and path name. The subvolume root directories have the same inode number but different generations. Example output of the receive command: At subvol subvol2 snapshot ./subvol2 uuid=e783948d-4fd5-0d47-9777-43036e468170 transid=8 parent_uuid=7b0cefdb-738d-e342-a903-501df1877b01 parent_transid=8 utimes ./subvol2/ atime=2021-01-25T18:07:42+0000 mtime=2021-01-25T18:07:42+0000 ctime=2021-01-25T18:07:42+0000 link ./subvol2/a dest=a unlink ./subvol2/a utimes ./subvol2/ atime=2021-01-25T18:07:42+0000 mtime=2021-01-25T18:07:42+0000 ctime=2021-01-25T18:07:42+0000 utimes ./subvol2/a atime=2021-01-25T18:07:42+0000 mtime=2021-01-25T18:07:42+0000 ctime=2021-01-25T18:07:42+0000 => the `link` command causes the receiver to fail with: ERROR: link a -> a failed: File exists Signed-off-by: Roman Anasal --- v2: - add this patch based on feedback in https://lore.kernel.org/linux-btrfs/9e177865-0408-c321-951e-ce0f3ff33389@gmail.com/ --- fs/btrfs/send.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index ef544525f..3114770be 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -6543,6 +6543,15 @@ static int dir_changed(struct send_ctx *sctx, u64 dir) u64 orig_gen, new_gen; int ret; + /* + * Treat the root dir case special here: changed_inode will never + * produce a stream that tries to delete/rmdir/rename the root dir. + * So we must assume the root always as unchanged here to not produce + * incorrect link/rename commands for contained refs. + */ + if (dir == BTRFS_FIRST_FREE_OBJECTID) + return 0; + ret = get_inode_info(sctx->send_root, dir, NULL, &new_gen, NULL, NULL, NULL, NULL); if (ret)