From patchwork Wed Feb 22 22:56:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benedikt Morbach X-Patchwork-Id: 9587535 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 EAA67600CA for ; Wed, 22 Feb 2017 22:58:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D83C6286D0 for ; Wed, 22 Feb 2017 22:58:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9BD0286D2; Wed, 22 Feb 2017 22:58:41 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 EA5D7286A7 for ; Wed, 22 Feb 2017 22:58:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934090AbdBVW6c (ORCPT ); Wed, 22 Feb 2017 17:58:32 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:36506 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933823AbdBVW6a (ORCPT ); Wed, 22 Feb 2017 17:58:30 -0500 Received: by mail-wr0-f196.google.com with SMTP id z61so2119329wrc.3 for ; Wed, 22 Feb 2017 14:56:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=esLRigCL3RBCYys9n5t29g3kRX2qSFOduA5+BozgR2E=; b=fJheCbXb5iZDFkBKNMkshPV045M9Oc/Ga5imk+VwxU3QF5YtU26ZyrOPvJihHUsWrf uVXmYylgps6Wt8lsRLnUs/u9CIEkuzh5PZKm1ovkxswa+LBpOOR3ZzeNeZBkd33pf3V1 4FbtGtCbrJfNXFdIg2/+qu8QTLYWBUHN75j/ZWa/x4c8P19rVArKHDhnOo3xNdLBJUwm JXwHrvuRVQyp3aciNv+KGp9kcKZOrs7aAGjYxffamP6+DeHtWtIKS2cMjYiGHPlsC60C P9rvN8zXqqwky3CivFqyWJTS9CZNBfSdauNe/d4QdDUNVelqcjOgdzVyGXuuxWN78lru KzJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=esLRigCL3RBCYys9n5t29g3kRX2qSFOduA5+BozgR2E=; b=GFDYgK3bgWS3bDdgnCEt1wnX+WTgvbq7OEB7d21LIgn6mlHSNCCEdeJz2HkhPaMx6I V9cFnamMONEYa6gq3gtbaZDOMvoo6nqIbQFfRkqegvd8MNP1IhgEqu6t8NQQftipk42b 1x1eWV7HLDhGWLcxvo6SSgRgy4qqsvVOQ21Mfydi9hW3BWIBiGXeDy79c1KWila2YVmb h0q5CIdWzf78FHeGzvJIWU4/ShwCzywKcNMOcIAU7yvMGv719oK9OVR7FBOCxAKKxprS Y5rZjf06oTDb/UfZaWMoh1Ohh6Ba8xa3cLnCLbgGFKepX5BZpfkbSWwH2RrKU2wFKIG+ 4Opg== X-Gm-Message-State: AMke39mZa3sn2IK1m5+ep4c11o/WQjYRtv+QPG+Xw5EpzXDT9TJuDp+2xinKO4TTpClA7A== X-Received: by 10.223.139.148 with SMTP id o20mr24547535wra.113.1487804202760; Wed, 22 Feb 2017 14:56:42 -0800 (PST) Received: from detritus.atuin ([2a02:8071:2985:3e00::133]) by smtp.gmail.com with ESMTPSA id g11sm3455662wrb.63.2017.02.22.14.56.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 14:56:42 -0800 (PST) From: Benedikt Morbach To: linux-btrfs@vger.kernel.org Cc: Benedikt Morbach Subject: [PATCH 2/2] btrfs-progs: receive: handle root subvol path in clone Date: Wed, 22 Feb 2017 23:56:37 +0100 Message-Id: <20170222225637.21858-2-benedikt.morbach@googlemail.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170222225637.21858-1-benedikt.morbach@googlemail.com> References: <20170222225637.21858-1-benedikt.morbach@googlemail.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 testcase: # ro subvol /src/parent # rw subvol /src/foo clone /src/parent/file /src/foo/file subvol snapshot -r /src/foo /src/foo.snap # generates a "clone parent/file -> foo.snap/file" send command send -p /src/parent /src/foo.snap # target fs: # dest/ # |--- parent/... # mounted with -o subvol=dest, such that "parent" is at /parent receive result: ERROR: cannot open dest/parent/file: No such file or directory expected: "dest/" get's stripped from the clone source path to get the actual path in the target fs, if reachable from the mount point/chroot. This is exactly what process_snapshot does, which gets called on _every_ incremental receive and I'm quite certain is correct in doing so Signed-off-by: Benedikt Morbach --- Hi, I first tried fixing this ages ago with [1], which was met with some scepticism. While that patch wasn't 100% correct I believe this is, and as mentioned it does exacly the same thing as process_snapshot because that has the exact same problem. An fstest to reproduce this will be following shortly [1] https://patchwork.kernel.org/patch/9177155/ cmds-receive.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmds-receive.c b/cmds-receive.c index 790218c..01345a4 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -782,7 +782,24 @@ static int process_clone(const char *path, u64 offset, u64 len, r->subvol_parent_name); } }*/ - subvol_path = strdup(si->path); + + /* strip the subvolume that we are receiving to from the start of subvol_path */ + if (rctx->full_root_path) { + size_t root_len = strlen(rctx->full_root_path); + size_t sub_len = strlen(si->path); + + if (sub_len > root_len && + strstr(si->path, rctx->full_root_path) == si->path && + si->path[root_len] == '/') { + subvol_path = strdup(si->path + root_len + 1); + } else { + error("clone: source subvol path %s unreachable from %s", + si->path, rctx->full_root_path); + goto out; + } + } else { + subvol_path = strdup(si->path); + } } ret = path_cat_out(full_clone_path, subvol_path, clone_path);