From patchwork Fri Oct 28 01:40:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: robbieko X-Patchwork-Id: 9400741 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 63FF0605EE for ; Fri, 28 Oct 2016 01:41:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53FE02A422 for ; Fri, 28 Oct 2016 01:41:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48D952A42E; Fri, 28 Oct 2016 01:41:37 +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 DE9BD2A422 for ; Fri, 28 Oct 2016 01:41:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965182AbcJ1Blc (ORCPT ); Thu, 27 Oct 2016 21:41:32 -0400 Received: from synology.com ([59.124.61.242]:37107 "EHLO synology.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965126AbcJ1Blb (ORCPT ); Thu, 27 Oct 2016 21:41:31 -0400 Received: from localhost.localdomain (unknown [10.12.12.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: robbieko@synology.com) by synology.com (Postfix) with ESMTPSA id DF5EA13160274; Fri, 28 Oct 2016 09:41:15 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1477618875; bh=Ftrpdgc0Qov6TySbmD1RoMkhMbbh0Pa64hCUU44c3Go=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hbWBw7AQ1CbTIAKIdlktXrvmuq0xU3vx8hmP39vYwc5g3XbCIeHwCQdBqAc5kxdAC nDWPICV2D/meer8xd+h5hbNMahB6FDs1DCtXZU41waW+Rz4h44XFPOTu1EL6d/dnBB PjRUVEcM9hi5flTtxPp9hGcIY3+72HNStl39QQsM= From: robbieko To: linux-btrfs@vger.kernel.org Cc: Robbie Ko Subject: [PATCH v2 2/6] Btrfs: incremental send, add generation check for the inode waiting for rmdir operation. Date: Fri, 28 Oct 2016 09:40:46 +0800 Message-Id: <1477618850-12922-3-git-send-email-robbieko@synology.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477618850-12922-1-git-send-email-robbieko@synology.com> References: <1477618850-12922-1-git-send-email-robbieko@synology.com> X-MailScanner-ID: DF5EA13160274.A6933 X-MailScanner: Found to be clean X-MailScanner-MCPCheck: MCP-Clean, MCP-Checker (score=0, required 80) X-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (not cached, score=-0.891, required 4.5, ALL_TRUSTED -1.00, BAYES_40 -0.00, DKIM_SIGNED 0.10, T_DKIM_INVALID 0.01) X-MailScanner-From: robbieko@synology.com 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 From: Robbie Ko Example scenario: Parent snapshot: |---- dir258/ (ino 258, gen 15, dir) |--- dir257/ (ino 257, gen 15, dir) |---- dir259/ (ino 259, gen 15, dir) Send snapshot: |---- file258 (ino 258, gen 21, file) |---- new_dir259/ (ino 259, gen 21, dir) |--- dir257/ (ino 257, gen 15, dir) utimes mkdir o259-21-0 rename dir258 -> o258-15-0 utimes mkfile o258-21-0 rename o258-21-0 -> file258 utimes truncate o258-21-0 size=0 ERROR: truncate o258-21-0 failed: No such file or directory While computing the send stream the following steps happen: 1) While processing inode 257, we create o259-21-0 and delay dir257 rename operation, because its new parent in the send snapshot, inode 259, was not yet processed and therefore not yet renamed. 2) Later when processing inode 258, we delay rmdir operation for dir258 because it's not empty, and then orphanize it. 3) After we create o258-21-0 and rename it to file258, we get ENOENT on truncate file258. The reason is that the dir258 with inode 258 is waiting for rmdir operation and file258's inode is also 258, then get_current_path called before truncate will return a unique name. Fix this by adding generation check for the inode waiting for rmdir operation. Signed-off-by: Robbie Ko --- fs/btrfs/send.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 2060e75..22eca86 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -311,7 +311,7 @@ static int is_waiting_for_move(struct send_ctx *sctx, u64 ino); static struct waiting_dir_move * get_waiting_dir_move(struct send_ctx *sctx, u64 ino); -static int is_waiting_for_rm(struct send_ctx *sctx, u64 dir_ino); +static int is_waiting_for_rm(struct send_ctx *sctx, u64 dir_ino, u64 dir_gen); static int need_send_hole(struct send_ctx *sctx) { @@ -2292,7 +2292,7 @@ static int get_cur_path(struct send_ctx *sctx, u64 ino, u64 gen, fs_path_reset(name); - if (is_waiting_for_rm(sctx, ino)) { + if (is_waiting_for_rm(sctx, ino, gen)) { ret = gen_unique_name(sctx, ino, gen, name); if (ret < 0) goto out; @@ -2899,11 +2899,11 @@ get_orphan_dir_info(struct send_ctx *sctx, u64 dir_ino) return NULL; } -static int is_waiting_for_rm(struct send_ctx *sctx, u64 dir_ino) +static int is_waiting_for_rm(struct send_ctx *sctx, u64 dir_ino, u64 dir_gen) { struct orphan_dir_info *odi = get_orphan_dir_info(sctx, dir_ino); - return odi != NULL; + return (odi != NULL && odi->gen == dir_gen); } static void free_orphan_dir_info(struct send_ctx *sctx, @@ -3166,7 +3166,7 @@ static int path_loop(struct send_ctx *sctx, struct fs_path *name, while (ino != BTRFS_FIRST_FREE_OBJECTID) { fs_path_reset(name); - if (is_waiting_for_rm(sctx, ino)) + if (is_waiting_for_rm(sctx, ino, gen)) break; if (is_waiting_for_move(sctx, ino)) { if (*ancestor_ino == 0)