From patchwork Wed Mar 11 08:17:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11431027 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4BC614B7 for ; Wed, 11 Mar 2020 08:17:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A396B2082E for ; Wed, 11 Mar 2020 08:17:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="wbxAHfru" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728543AbgCKIR1 (ORCPT ); Wed, 11 Mar 2020 04:17:27 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39594 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726097AbgCKIR0 (ORCPT ); Wed, 11 Mar 2020 04:17:26 -0400 Received: by mail-pg1-f194.google.com with SMTP id s2so762647pgv.6 for ; Wed, 11 Mar 2020 01:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tl2qJYqkoq4i0n0WsdxJLNjkYfr/WIVsn6+CVSKBFjI=; b=wbxAHfruQH/vcRRjglHiArYt/WnMn4plu+Wyopb/+KWogNypv7iiA3o9rwQlQ8HQ52 Xex2FKZ+fTCJw5QJ0q0rURxnk+P3tx6mWrGLB3bQ05I3JLcclgS7I81Wjf+akGatQcdU iuNGnppgoI1Q9guRdtgF709KTb2VMLOK0Q+5/NRpdldEY42XftggqfxaBmWgEu8sHUfH GuDf5xd6K9Gevx5OSMG27z3UJ4hK4bwlmc1v6nwAQf7WpRDQEWPZTTYkiHDQnjNQcf0l dSxYjBwAV6XsHh3QsAy+l54OWX/fLFFu9lZIcAVQxwSWb9ovVOFWvFf6oIDmDD1F+79q IHDA== 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:mime-version:content-transfer-encoding; bh=tl2qJYqkoq4i0n0WsdxJLNjkYfr/WIVsn6+CVSKBFjI=; b=aQYGOkDVcGegZzAFRkj4AmTlXFKuywMZEnb6mjmFTiE0ogZ7dX6xK4+IrfYaFhqIB0 MH0/OwGE7tAFtzcEniLKznPOdglhEvmMb5IVgRR0TvReVKVHRl1Wb6AvQbvn0uKaVtsV +Q2p/nu5LGhc/CUu3ldEfBv+iTQGXZYHK5pp/1SK4U6puRGuqCJMWjYnSAB+1c7V5BDu 7QhlEiw0QHBlQhw42dZs6TMAIMOYf66rW1kGflbf3/b4G1Ddavb1FMwpOmA/KQj0MXKu yilgIIc815kl34NeJASftwgFp5KjInr6lo4AkJqpxAFo4A5+STUQQXufjP640E0VbawG e19Q== X-Gm-Message-State: ANhLgQ0lZP0wCfsBkji33fyqJQVgkUDIWOSdF9FT0S7L5n7ygEJRPIml 1FqVX4wfdIgcDIgWRA27skVejnh/Va8= X-Google-Smtp-Source: ADFU+vuuNe4DkelaAWPBqUnLEESrSQpYMdSFW1/ZSdGe/A1SyI9Cx03vfOWrzMTxQY5FVzl6dZbsaQ== X-Received: by 2002:a65:6787:: with SMTP id e7mr1678613pgr.98.1583914643822; Wed, 11 Mar 2020 01:17:23 -0700 (PDT) Received: from vader.hsd1.wa.comcast.net ([2601:602:8b80:8e0::14a2]) by smtp.gmail.com with ESMTPSA id j8sm4692039pjb.4.2020.03.11.01.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 01:17:22 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, Filipe Manana Subject: [PATCH RESEND v2 1/3] btrfs-progs: receive: remove commented out transid checks Date: Wed, 11 Mar 2020 01:17:09 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval The checks for a subvolume being modified after it was received have been commented out since they were added back in commit f1c24cd80dfd ("Btrfs-progs: add btrfs send/receive commands"). Let's just get rid of the noise. Signed-off-by: Omar Sandoval Reviewed-by: Filipe Manana --- cmds/receive.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/cmds/receive.c b/cmds/receive.c index c4827c1d..a4bf8787 100644 --- a/cmds/receive.c +++ b/cmds/receive.c @@ -345,15 +345,6 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid, parent_subvol->path[sub_len - root_len - 1] = '\0'; } } - /*if (rs_args.ctransid > rs_args.rtransid) { - if (!r->force) { - ret = -EINVAL; - fprintf(stderr, "ERROR: subvolume %s was modified after it was received.\n", r->subvol_parent_name); - goto out; - } else { - fprintf(stderr, "WARNING: subvolume %s was modified after it was received.\n", r->subvol_parent_name); - } - }*/ if (*parent_subvol->path == 0) args_v2.fd = dup(rctx->mnt_fd); @@ -771,22 +762,6 @@ static int process_clone(const char *path, u64 offset, u64 len, goto out; } } else { - /*if (rs_args.ctransid > rs_args.rtransid) { - if (!r->force) { - ret = -EINVAL; - fprintf(stderr, "ERROR: subvolume %s was " - "modified after it was " - "received.\n", - r->subvol_parent_name); - goto out; - } else { - fprintf(stderr, "WARNING: subvolume %s was " - "modified after it was " - "received.\n", - r->subvol_parent_name); - } - }*/ - /* 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); From patchwork Wed Mar 11 08:17:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11431029 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F3181800 for ; Wed, 11 Mar 2020 08:17:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0EA6020873 for ; Wed, 11 Mar 2020 08:17:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="sG+z5/+e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728582AbgCKIR2 (ORCPT ); Wed, 11 Mar 2020 04:17:28 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35360 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728544AbgCKIR2 (ORCPT ); Wed, 11 Mar 2020 04:17:28 -0400 Received: by mail-pf1-f195.google.com with SMTP id u68so879030pfb.2 for ; Wed, 11 Mar 2020 01:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lAWYgi3WBUAGspLIIBW0G9rAvZdYdEaHNqj4FetbUPI=; b=sG+z5/+emHBNv394lDQnafAeLlUJJ4Qz2vULEO4wxo19ChDxNW1SZCJDU7q2k9yyhQ sQUvGjgX5y32/gFJHAGHLYLE+KAqqcO1nJ9SXof6ID4r63h94BAahKT9ViM9614oE+OH 7sh9TIEwC1NbW4NUFMMnBhLbhLL3R92lWM2gqnXdYjUfIzQWhJGx2Zos36LBMLmby84F b2wUjrEkIa5DAI5qzqUeGOrK2yAl1IHsv8/LrR32fwI2PflOIwqfbOOHZZ/zp6VxyslV ZyNDTHWtUJnwkoN+Dn67maIUZYP2U1FbLVeXr31GK4xEcpePSS5WsFohZB3S5uBsPzTN gnZg== 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:mime-version:content-transfer-encoding; bh=lAWYgi3WBUAGspLIIBW0G9rAvZdYdEaHNqj4FetbUPI=; b=ugP1Rv1dwo7sDEJPWxiYBixSxDoAYVnuyPPJAnbANPZzgWnmoNKVXIHZ7qDGFyUsdB o2y3+F7sXzkBEDNbZ3vCVBY/ZTBnAZtSW1wb4OQcAN37AY330GJfEaBZ56mzxOcZOdbR aYXjb/XyK121z2hfUZbvYtckEfw2ZBeD2NVNOsiRzxvtHfHSfU8A8X+AUcn1JUqONV2h s3nkrvUJq39tfMfyYQl360L5TYySj1BPNbmU1r0hHU5c/nbt+QZpO4FLtKfDylRju1Cd y4GxEGwxkTqBCm5rmXWSDtqP2MzG71ftZz4YUu1R1YnKIn152+idiQ+hat+OVha18rNQ Upnw== X-Gm-Message-State: ANhLgQ2cRf96TG/9L1j23JH/8V20Vkss/CyhXMn5xvbgwNyAXwQkJ30Y ytS9XUiuKGRAFI8swNIibjOaQSpe+mc= X-Google-Smtp-Source: ADFU+vtbxl5vMAO8Vx75tmIWGNXdg3S4oi9JmlPw5FzliHZgritxVpQkoOu87+p+CjvsZkFRClkpZA== X-Received: by 2002:aa7:824a:: with SMTP id e10mr1753567pfn.54.1583914644951; Wed, 11 Mar 2020 01:17:24 -0700 (PDT) Received: from vader.hsd1.wa.comcast.net ([2601:602:8b80:8e0::14a2]) by smtp.gmail.com with ESMTPSA id j8sm4692039pjb.4.2020.03.11.01.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 01:17:24 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, Filipe Manana , Filipe Manana Subject: [PATCH RESEND v2 2/3] btrfs-progs: receive: don't lookup clone root for received subvolume Date: Wed, 11 Mar 2020 01:17:10 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval When we process a clone request, we look up the source subvolume by UUID, even if the source is the subvolume that we're currently receiving. Usually, this is fine. However, if for some reason we previously received the same subvolume, then this will use paths relative to the previously received subvolume instead of the current one. This is incorrect, since the send stream may use temporary names for the clone source. This can be reproduced as follows: btrfs subvolume create subvol dd if=/dev/urandom of=subvol/foo bs=1M count=1 cp --reflink subvol/foo subvol/bar mkdir subvol/dir mv subvol/foo subvol/dir/ btrfs property set subvol ro true btrfs send -f send.data subvol mkdir first second btrfs receive -f send.data first btrfs receive -f send.data second The second receive results in this error: ERROR: cannot open first/subvol/o259-7-0/foo: No such file or directory Fix it by always cloning from the current subvolume if its UUID matches. This has the nice side effect of avoiding unnecessary UUID tree lookups in that case. Fixes: f1c24cd80dfd ("Btrfs-progs: add btrfs send/receive commands") Reviewed-by: Filipe Manana Signed-off-by: Omar Sandoval --- cmds/receive.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cmds/receive.c b/cmds/receive.c index a4bf8787..74b73f48 100644 --- a/cmds/receive.c +++ b/cmds/receive.c @@ -745,15 +745,14 @@ static int process_clone(const char *path, u64 offset, u64 len, if (ret < 0) goto out; - si = subvol_uuid_search(&rctx->sus, 0, clone_uuid, clone_ctransid, - NULL, - subvol_search_by_received_uuid); - if (IS_ERR_OR_NULL(si)) { - if (memcmp(clone_uuid, rctx->cur_subvol.received_uuid, - BTRFS_UUID_SIZE) == 0) { - /* TODO check generation of extent */ - subvol_path = rctx->cur_subvol_path; - } else { + if (memcmp(clone_uuid, rctx->cur_subvol.received_uuid, + BTRFS_UUID_SIZE) == 0) { + subvol_path = rctx->cur_subvol_path; + } else { + si = subvol_uuid_search(&rctx->sus, 0, clone_uuid, clone_ctransid, + NULL, + subvol_search_by_received_uuid); + if (IS_ERR_OR_NULL(si)) { if (!si) ret = -ENOENT; else @@ -761,7 +760,6 @@ static int process_clone(const char *path, u64 offset, u64 len, error("clone: did not find source subvol"); goto out; } - } else { /* 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); From patchwork Wed Mar 11 08:17:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11431031 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C355C1874 for ; Wed, 11 Mar 2020 08:17:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A35E620873 for ; Wed, 11 Mar 2020 08:17:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="FKla1E9N" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728559AbgCKIR2 (ORCPT ); Wed, 11 Mar 2020 04:17:28 -0400 Received: from mail-pf1-f181.google.com ([209.85.210.181]:36730 "EHLO mail-pf1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726097AbgCKIR1 (ORCPT ); Wed, 11 Mar 2020 04:17:27 -0400 Received: by mail-pf1-f181.google.com with SMTP id i13so878331pfe.3 for ; Wed, 11 Mar 2020 01:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vU/0jV7F8m15JbjAbEfvTnyzaUqHuKYjLpUR2hgj7bY=; b=FKla1E9Nx7fZZ7Sk0VuXgANrHdwX7ZvP3wODzZCNgF33T4t2ZH+IgHBwQn2QUMZsrB 5OhmvZQqx6pIEKcvx4FfcCDe0NOkWZsH0c3Ji/x9rj6UkI5lOLjCwE0a83gHK4ULFkys WrXPls4nwYCIyoz73qrTaEQdNQP14l0T/JoBBGVcJbrRuO9U2nNuidjuHEAog4gC5SD8 WpZ9be938hs9EB/iRwFFcBcHMJquZuCRxLE3lF29sJJWeZoH9mE2vzxojPd+Fh6z46q7 nBqXW1YFeUkVqzx3zcNBUf4c+w9RLVqttwcLPdeU0mczVbkO19QC1v9zSvmmqFv5rR9a KfAQ== 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:mime-version:content-transfer-encoding; bh=vU/0jV7F8m15JbjAbEfvTnyzaUqHuKYjLpUR2hgj7bY=; b=p4F+2s+SBxxWLfmjQ4NPqKT6SdwEFo4F4f11L0eNsI26J8j8fOMyPJY1flnhVIoS3m 51bkPsEetmMGNIkIThSROv/loPpP9iUNfHih2ztbwuYPUh/4NESLq2718DjIU9z+Lme7 pMpxe/ouFBa+lJjvMVPNVXwcmFw8JeO+3DUWiNBQ40K7WFEXKBLksMou/BbuXhkSA8db hOEkuXuSXzGcBMhZYMcFe8ElYihVDMLHRJ/SszL3OTnIDzC/LmrRURdvS2L9e0CRvi0+ t1WKZVEf/nC/nygW1M01zbePmSi4o6swYl56kTXtGp8Vj3jTXqUgH0KsOVDTGpGlWzN3 2frg== X-Gm-Message-State: ANhLgQ1dhlkO+u4ArqLjSgMXr3/4BDu3ySHb+B8iMvj2kb6izKQ5fbkf gMaqsxjbXl9U9v4aqksiRyN319lrVnU= X-Google-Smtp-Source: ADFU+vtsKKluEms5hrRCcFVCofDIEFHcVl5iYV4L2DwGsgsB5gWkNcbYcc3wIg9krSt3u7mKWUpA6w== X-Received: by 2002:a65:458e:: with SMTP id o14mr1744782pgq.323.1583914646308; Wed, 11 Mar 2020 01:17:26 -0700 (PDT) Received: from vader.hsd1.wa.comcast.net ([2601:602:8b80:8e0::14a2]) by smtp.gmail.com with ESMTPSA id j8sm4692039pjb.4.2020.03.11.01.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 01:17:25 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, Filipe Manana , Filipe Manana Subject: [PATCH RESEND v2 3/3] btrfs-progs: tests: add test for receiving clone from duplicate subvolume Date: Wed, 11 Mar 2020 01:17:11 -0700 Message-Id: <999924f436ccad26b30f555ee106a131dff015c9.1583914311.git.osandov@fb.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval This test case is the reproducer for the previous fix. Reviewed-by: Filipe Manana Signed-off-by: Omar Sandoval --- .../test.sh | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 tests/misc-tests/038-receive-clone-from-current-subvolume/test.sh diff --git a/tests/misc-tests/038-receive-clone-from-current-subvolume/test.sh b/tests/misc-tests/038-receive-clone-from-current-subvolume/test.sh new file mode 100755 index 00000000..be648605 --- /dev/null +++ b/tests/misc-tests/038-receive-clone-from-current-subvolume/test.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Test that when receiving a subvolume whose received UUID already exists in +# the filesystem, we clone from the correct source (the subvolume that we are +# receiving, not the existing subvolume). This is a regression test for +# "btrfs-progs: receive: don't lookup clone root for received subvolume". + +source "$TEST_TOP/common" + +check_prereq btrfs +check_prereq mkfs.btrfs + +setup_root_helper + +rm -f disk +run_check truncate -s 1G disk +chmod a+w disk +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f disk +run_check $SUDO_HELPER mount -o loop disk "$TEST_MNT" + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/subvol" +run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_MNT/subvol/foo" \ + bs=1M count=1 status=none +run_check $SUDO_HELPER cp --reflink "$TEST_MNT/subvol/foo" "$TEST_MNT/subvol/bar" +run_check $SUDO_HELPER mkdir "$TEST_MNT/subvol/dir" +run_check $SUDO_HELPER mv "$TEST_MNT/subvol/foo" "$TEST_MNT/subvol/dir" +run_check $SUDO_HELPER "$TOP/btrfs" property set "$TEST_MNT/subvol" ro true +run_check $SUDO_HELPER "$TOP/btrfs" send -f send.data "$TEST_MNT/subvol" + +run_check $SUDO_HELPER mkdir "$TEST_MNT/first" "$TEST_MNT/second" +run_check $SUDO_HELPER "$TOP/btrfs" receive -f send.data "$TEST_MNT/first" +run_check $SUDO_HELPER "$TOP/btrfs" receive -f send.data "$TEST_MNT/second" + +run_check $SUDO_HELPER umount "$TEST_MNT" +rm -f disk send.data