From patchwork Sat Mar 22 17:15:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 3877811 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 0C0D2BF540 for ; Sat, 22 Mar 2014 17:16:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 25FCF202B8 for ; Sat, 22 Mar 2014 17:16:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4A6BF202B4 for ; Sat, 22 Mar 2014 17:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751400AbaCVRPj (ORCPT ); Sat, 22 Mar 2014 13:15:39 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:45164 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751167AbaCVRPi (ORCPT ); Sat, 22 Mar 2014 13:15:38 -0400 Received: by mail-wi0-f178.google.com with SMTP id bs8so1339492wib.5 for ; Sat, 22 Mar 2014 10:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ozkNutxxVVSaHXRaGj3mZzFHLA8X8KbP7gYbacckH80=; b=HoPp5lvgbYoXutaxV+7qLDDK9PlTQl0QbzHbHssjNA35H0rO2YPcLsT2m6qhTMUE4s 57Od//k0jQWCwAbSoOqpyenf+Kx8KyiukCA/vppHHdv4lKpp4wKdTp9PQdF5rzp0MK7c J/SzzB+30uZfmjBGNRSC3d0FP1PQqz1ElogQdi3s2I3P+NLaRrPtH0RxEJx2QyWYVdwY HMeC5OCd/H2rfBZxtmEvk7uRfFTMNYaMuMOO8rAeQI3mLsGugo26BDwyhyxpNXsqQIFi tGqaAp0JY2l0Rjelh49NXphsYm4ULubGm0lmy3+1nrrJUpUpwas9E+vdHJiUHH7D6BLw Jr3A== X-Received: by 10.180.101.166 with SMTP id fh6mr4561900wib.2.1395508537033; Sat, 22 Mar 2014 10:15:37 -0700 (PDT) Received: from debian-vm3.lan (bl13-154-103.dsl.telepac.pt. [85.246.154.103]) by mx.google.com with ESMTPSA id bm8sm18716483wjc.12.2014.03.22.10.15.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Mar 2014 10:15:35 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH v2] Btrfs: send, account for orphan directories when building path strings Date: Sat, 22 Mar 2014 17:15:24 +0000 Message-Id: <1395508524-19016-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1395405939-8488-1-git-send-email-fdmanana@gmail.com> References: <1395405939-8488-1-git-send-email-fdmanana@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 If we have directories with a pending move/rename operation, we must take into account any orphan directories that got created before executing the pending move/rename. Those orphan directories are directories with an inode number higher then the current send progress and that don't exist in the parent snapshot, they are created before current progress reaches their inode number, with a generated name of the form oN-M-I and at the root of the filesystem tree, and later when progress matches their inode number, moved/renamed to their final location. Reproducer: $ mkfs.btrfs -f /dev/sdd $ mount /dev/sdd /mnt $ mkdir -p /mnt/a/b/c/d $ mkdir /mnt/a/b/e $ mv /mnt/a/b/c /mnt/a/b/e/CC $ mkdir /mnt/a/b/e/CC/d/f $ mkdir /mnt/a/g $ btrfs subvolume snapshot -r /mnt /mnt/snap1 $ btrfs send /mnt/snap1 -f /tmp/base.send $ mkdir /mnt/a/g/h $ mv /mnt/a/b/e /mnt/a/g/h/EE $ mv /mnt/a/g/h/EE/CC/d /mnt/a/g/h/EE/DD $ btrfs subvolume snapshot -r /mnt /mnt/snap2 $ btrfs send -p /mnt/snap1 /mnt/snap2 -f /tmp/incremental.send The second receive command failed with the following error: ERROR: rename a/b/e/CC/d -> o264-7-0/EE/DD failed. No such file or directory A test case for xfstests follows soon. Signed-off-by: Filipe David Borba Manana --- V2: Simpler version, removed more no longer needed code. fs/btrfs/send.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 143fed3..a08ceca 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -3028,33 +3028,18 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm) if (ret < 0) goto out; - if (parent_ino == sctx->cur_ino) { - /* child only renamed, not moved */ - ASSERT(parent_gen == sctx->cur_inode_gen); - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, - from_path); - if (ret < 0) - goto out; - ret = fs_path_add_path(from_path, name); - if (ret < 0) - goto out; - } else { - /* child moved and maybe renamed too */ - sctx->send_progress = pm->ino; - ret = get_cur_path(sctx, pm->ino, pm->gen, from_path); - if (ret < 0) - goto out; - } + ret = get_cur_path(sctx, parent_ino, parent_gen, + from_path); + if (ret < 0) + goto out; + ret = fs_path_add_path(from_path, name); + if (ret < 0) + goto out; - fs_path_free(name); + fs_path_reset(name); + to_path = name; name = NULL; - to_path = fs_path_alloc(); - if (!to_path) { - ret = -ENOMEM; - goto out; - } - sctx->send_progress = sctx->cur_ino + 1; ret = get_cur_path(sctx, pm->ino, pm->gen, to_path); if (ret < 0)