From patchwork Wed Oct 12 08:12:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: robbieko X-Patchwork-Id: 9372227 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 CD5C460839 for ; Wed, 12 Oct 2016 08:13:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF23B29D15 for ; Wed, 12 Oct 2016 08:13:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B427829D16; Wed, 12 Oct 2016 08:13:54 +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 518EB29D1F for ; Wed, 12 Oct 2016 08:13:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754623AbcJLINv (ORCPT ); Wed, 12 Oct 2016 04:13:51 -0400 Received: from synology.com ([59.124.61.242]:52715 "EHLO synology.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754363AbcJLINr (ORCPT ); Wed, 12 Oct 2016 04:13:47 -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 2F8351273262; Wed, 12 Oct 2016 16:13:18 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1476259998; bh=uN3Zd28otuilTDCh+u0/RLJRY/zJDygUH8wzs8esrnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RnuobmdYvZjOPvDX/xQ6kE7ktXa7aGq6ZMH3voN6Fu+Ex85IVotI65IMazso2f1c5 A4N8ez87LTdDEEr5KzhSG7O9Axr3A4wu2t51eYcDvi6QcjqldhRt0Y50NbbdxXMX/L aHFXtYef408aKfyCcgwwqLNvi9WP31DGjF3fKhN4= From: robbieko To: linux-btrfs@vger.kernel.org Cc: Robbie Ko Subject: [PATCH 2/5] Btrfs: incremental send, add gen for is_waiting_for_rm when some corner case Date: Wed, 12 Oct 2016 16:12:47 +0800 Message-Id: <1476259970-1866-3-git-send-email-robbieko@synology.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1476259970-1866-1-git-send-email-robbieko@synology.com> References: <1476259970-1866-1-git-send-email-robbieko@synology.com> X-MailScanner-ID: 2F8351273262.A71B5 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 There a one case for old_gen waiting_for_rm, but new_gen use get_cur_path with the same inode. Example: Parent snapshot: |---- dir258/ (ino 258, dir) |--- dir257/ (ino 257, dir) |---- dir259/ (ino 259, dir) Send snapshot: |---- file258 (ino 258, file) |---- new_dir259/ (ino 259, dir) |--- dir257/ (ino 257, 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 dir258 will be delete, but dir257 is waiting for move, so dir258 is waiting for rm, and then file258 be create, and rename it, and then need to truncate it, so use get_cur_path to get path, but is_waiting_for_rm olny check ino, dosen't check gen, match dir258 is waiting for rm, so get error path o258-21-0. therefore, add gen check in is_waiting_for_rm. 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 1862f8a..95d3718 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) { @@ -2293,7 +2293,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; @@ -2900,11 +2900,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, @@ -3167,7 +3167,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)