From patchwork Fri Oct 28 01:40:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: robbieko X-Patchwork-Id: 9400745 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 1D260605EE for ; Fri, 28 Oct 2016 01:41:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E7352A422 for ; Fri, 28 Oct 2016 01:41:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 036662A427; Fri, 28 Oct 2016 01:41:45 +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 9B3102A422 for ; Fri, 28 Oct 2016 01:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030468AbcJ1Bll (ORCPT ); Thu, 27 Oct 2016 21:41:41 -0400 Received: from synology.com ([59.124.61.242]:37743 "EHLO synology.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964894AbcJ1Blj (ORCPT ); Thu, 27 Oct 2016 21:41:39 -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 F0D781316028B; Fri, 28 Oct 2016 09:41:16 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1477618877; bh=XOpQSsMjwQMDf+wNFhBm6j2l8rFXz7gI+G7IjCodN3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HldqoZ8DWt6ZDxcoMYBNm1aHUvPokfvaNfa51WDLOlvtWoxgRqePLlBoD1QI9uypc J/KJcDGXuw0rEvWBh8P+8Dykx2M7EY/hwTOHG6NxbyR0JbbaMjw4gjQSxIMXpyadXX OoDE8IL3x6VeEm1/yNuZNNP4r+ztv6wYR2An/hUU= From: robbieko To: linux-btrfs@vger.kernel.org Cc: Robbie Ko Subject: [PATCH v2 4/6] Btrfs: incremental send, skip check overwritten if parents' generation are different Date: Fri, 28 Oct 2016 09:40:48 +0800 Message-Id: <1477618850-12922-5-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: F0D781316028B.A456B 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: |---- d259_old/ (ino 259, gen 96) |---- d1/ (ino 258, gen 96) |---- f (ino 257, gen 96) Send snapshot: |---- d258/ (ino 258, gen 98) |---- d259/ (ino 259, gen 98) |---- d1/ (ino 257, gen 98) unlink f mkdir o257-98-0 mkdir o259-98-0 chown o257-98-0 - uid=0, gid=0 chmod o257-98-0 - mode=0755 rmdir o258-96-0 ERROR: rmdir o258-96-0 failed: No such file or directory While computing the send stream the following steps happen: 1) While processing inode 257 we create o257-98-0 and o259-98-0, then delay o257-98-0 rename operation because its new parent in the send snapshot, inode 259, was not yet processed and therefore not yet renamed; 2) Later we want to delete d1 (ino 258, gen 96) while processing inode 258. In order to get its path for delete, we need to check if it is overwritten in the send snapshot. And we find it is overwritten so we delete it via unique name , which leads to error. The reason is we will find out d1 is under parent directory (inode 259) in the send snapshot, and for this case, because d1(inode 257, gen 98) is not same as d1 (inode 258, gen 96), we conclude d1 has been overwritten. Fix this by adding generation check for the parent directory. Because both parent directory are not identical, we can just skip the overwrite check. In addition, inode 256 should not check for this since it is a subvolume. Signed-off-by: Robbie Ko --- fs/btrfs/send.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index eaf1c92..139f492 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -1938,6 +1938,19 @@ static int did_overwrite_ref(struct send_ctx *sctx, if (ret <= 0) goto out; + if (dir != BTRFS_FIRST_FREE_OBJECTID) { + ret = get_inode_info(sctx->send_root, dir, NULL, &gen, NULL, + NULL, NULL, NULL); + if (ret < 0 && ret != -ENOENT) + goto out; + if (ret) { + ret = 0; + goto out; + } + if (gen != dir_gen) + goto out; + } + /* check if the ref was overwritten by another ref */ ret = lookup_dir_item_inode(sctx->send_root, dir, name, name_len, &ow_inode, &other_type);