From patchwork Sat Feb 1 02:00:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 3564151 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8FB51C02DC for ; Sat, 1 Feb 2014 02:01:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94B5D20260 for ; Sat, 1 Feb 2014 02:01:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE5752022D for ; Sat, 1 Feb 2014 02:01:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754368AbaBACBg (ORCPT ); Fri, 31 Jan 2014 21:01:36 -0500 Received: from mail-we0-f176.google.com ([74.125.82.176]:44667 "EHLO mail-we0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754220AbaBACBf (ORCPT ); Fri, 31 Jan 2014 21:01:35 -0500 Received: by mail-we0-f176.google.com with SMTP id q58so275817wes.7 for ; Fri, 31 Jan 2014 18:01:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=i94EKht/uI2RTOJfFNqH52MeRjgDY7s+1FtrYMiFdM4=; b=XvBqR4bw/Xp2BEqRFNYD+p9uJ5DQvHkQBQ0/clP6fAtc+gv6sD/TC06PJlm0uVq3XZ 7vkK76vSCIcpX7WW7WJlmI4NhQdJca5HNEuS7FkloG0sYa+hJrc5p9AXf5P4Lx+hLvpy 6DegMWd9HrVolu4jDHLuWE0LaF3hlI39N3ejsR+eI2J/dwmuXlB84pZr9ueWE2n7pvPK SKdRJAnyfo8hsLfrRr7g/GVtxaE4NNNg+g6VPxcBJCi7SfbLcDTf8HgWzMckctGZrxVI JsAVFtgJNrWePXJtRH647lyKaGU/2/ikb2jbL898GnnktK4/GB9+C5KZlJP1hqBTCZDH c3oA== X-Received: by 10.194.219.132 with SMTP id po4mr15717536wjc.7.1391220094340; Fri, 31 Jan 2014 18:01:34 -0800 (PST) Received: from storm-desktop.lan (bl10-140-184.dsl.telepac.pt. [85.243.140.184]) by mx.google.com with ESMTPSA id cx3sm7982899wib.0.2014.01.31.18.01.33 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Jan 2014 18:01:33 -0800 (PST) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs: fix send dealing with file renames and directory moves Date: Sat, 1 Feb 2014 02:00:15 +0000 Message-Id: <1391220015-21946-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This fixes a case that the commit titled: Btrfs: fix infinite path build loops in incremental send didn't cover. If the parent-child relationship between 2 directories is inverted, both get renamed, and the former parent has a file that got renamed too (but remains a child of that directory), the incremental send operation would use the file's old path after sending an unlink operation for that old path, causing receive to fail on future operations like changing owner, permissions or utimes of the corresponding inode. This is not a regression from the commit mentioned before, as without that commit we would fall into the issues that commit fixed, so it's just one case that wasn't covered before. Simple steps to reproduce this issue are: $ mkfs.btrfs -f /dev/sdb3 $ mount /dev/sdb3 /mnt/btrfs $ mkdir -p /mnt/btrfs/a/b/c/d $ touch /mnt/btrfs/a/b/c/d/file $ mkdir -p /mnt/btrfs/a/b/x $ btrfs subvol snapshot -r /mnt/btrfs /mnt/btrfs/snap1 $ mv /mnt/btrfs/a/b/x /mnt/btrfs/a/b/c/x2 $ mv /mnt/btrfs/a/b/c/d /mnt/btrfs/a/b/c/x2/d2 $ mv /mnt/btrfs/a/b/c/x2/d2/file /mnt/btrfs/a/b/c/x2/d2/file2 $ btrfs subvol snapshot -r /mnt/btrfs /mnt/btrfs/snap2 $ btrfs send -p /mnt/btrfs/snap1 /mnt/btrfs/snap2 > /tmp/incremental.send A patch to update the test btrfs/030 from xfstests, so that it covers this case, will be submitted soon. Signed-off-by: Filipe David Borba Manana --- fs/btrfs/send.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 7250d86..e0b49f6 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -2121,8 +2121,6 @@ static int get_cur_path(struct send_ctx *sctx, u64 ino, u64 gen, u64 parent_inode = 0; u64 parent_gen = 0; int stop = 0; - u64 start_ino = ino; - u64 start_gen = gen; int skip_name_cache = 0; name = fs_path_alloc(); @@ -2134,7 +2132,6 @@ static int get_cur_path(struct send_ctx *sctx, u64 ino, u64 gen, if (is_waiting_for_move(sctx, ino)) skip_name_cache = 1; -again: dest->reversed = 1; fs_path_reset(dest); @@ -2149,13 +2146,8 @@ again: stop = 1; if (!skip_name_cache && - is_waiting_for_move(sctx, parent_inode)) { - ino = start_ino; - gen = start_gen; - stop = 0; + is_waiting_for_move(sctx, parent_inode)) skip_name_cache = 1; - goto again; - } ret = fs_path_add_path(dest, name); if (ret < 0)