From patchwork Thu Jan 5 08:24:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: robbieko X-Patchwork-Id: 9498663 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 BD12760235 for ; Thu, 5 Jan 2017 08:44:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B644A27D13 for ; Thu, 5 Jan 2017 08:44:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA5FB27E71; Thu, 5 Jan 2017 08:44:55 +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 D037E27D13 for ; Thu, 5 Jan 2017 08:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161069AbdAEI1h (ORCPT ); Thu, 5 Jan 2017 03:27:37 -0500 Received: from synology.com ([59.124.61.242]:40429 "EHLO synology.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033231AbdAEI0e (ORCPT ); Thu, 5 Jan 2017 03:26:34 -0500 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 4E3D76BA911; Thu, 5 Jan 2017 16:25:21 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1483604721; bh=BDMI6a4TgNlMwoqO/GSEB9T1e+4OXZ/rPDXZESkVhu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IoitZY6EhC4shhVOjXpu4x7FQlC/FSN8QHsvhLBD24dK+irQdCM7YsDVaxQe1+ghy 7/KJ3xNcm1q9M0owTOLy6FtPNdEQvRmR0t+cJZBMnXYN4yq1J1ik1NRKHKZlRZsPpn cCzK7esFW1wbXk2JjF8nkl2G1+ZTt7VFqqA87oOI= From: robbieko To: linux-btrfs@vger.kernel.org Cc: Robbie Ko Subject: [PATCH v3 2/6] Btrfs: incremental send, fix invalid path for truncate operations Date: Thu, 5 Jan 2017 16:24:56 +0800 Message-Id: <1483604700-21017-3-git-send-email-robbieko@synology.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483604700-21017-1-git-send-email-robbieko@synology.com> References: <1483604700-21017-1-git-send-email-robbieko@synology.com> X-MailScanner-ID: 4E3D76BA911.ABFB9 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.889, required 4.5, ALL_TRUSTED -1.00, DKIM_SIGNED 0.10, T_DKIM_INVALID 0.01, URIBL_BLOCKED 0.00) 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 Under certain situations, an incremental send operation can a truncate operation that will make the receiving end fail when attempting to execute it, because the path is not exist. 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 --- V3: improve the change log 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)