From patchwork Wed Feb 22 22:56:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benedikt Morbach X-Patchwork-Id: 9587537 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 0CEE660578 for ; Wed, 22 Feb 2017 22:58:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F156A286A7 for ; Wed, 22 Feb 2017 22:58:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E56CF286D6; 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 16B05286B4 for ; Wed, 22 Feb 2017 22:58:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934071AbdBVW6e (ORCPT ); Wed, 22 Feb 2017 17:58:34 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36498 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932924AbdBVW6a (ORCPT ); Wed, 22 Feb 2017 17:58:30 -0500 Received: by mail-wr0-f194.google.com with SMTP id z61so2119266wrc.3 for ; Wed, 22 Feb 2017 14:56:41 -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; bh=j37WFYz0IFNLYwJgj84JD4wSXy6Oby+G6FN3yij0ilI=; b=oQ714sY6l/6qOTZ3OKqCuiJAwLrk1hKyK7m5VkI5oDNJSUdg9Gxp46s2NwbzRSdhE5 Jlbfj3WKz3QYTC24XHh6bg4PJM/xVOT7A7OxQDY0aUhrGTLau+Cad0Ios0PJVanJRTPF Jhz+ixS0EQQPug8FDGCOQbmyHl8fLKQFyc4pWxpk16v15CUEeBlkzr34nP6RA2/+yaK7 /g5imk79a1l0fiULuqX7Ss5irT7mEeE2KEZVTW/S+U6sj/Xs6YrUFeAtd8E8VvuQCn3n b8M/vsXFB/s8kkHOvdHT/TO6wYHnTV2fQHNkW8jnukGgPNZt7skdNw43UKoXEE07fkBu XTyw== 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; bh=j37WFYz0IFNLYwJgj84JD4wSXy6Oby+G6FN3yij0ilI=; b=OmSxkn3Bo3LIae9oN+tdxPlhkbQ2x1tYU3g27AFGztIFDo11gYaS531basKFRMJ3RI 9Eiy03xIPaHflCEB5FgukIoZLHXYASBxVbXFlHLWL93eTJKu5YUjV/GjUUgoOUcCGSB4 PctPSEZN8OFw6n51ddyoKEoAZKyyc/P3jIPP+vQDcXMSrjlZ2fsxynM3hV5eYdJnt86+ zfsbnC6tO57l9WniEjbVcx0v/9ojEDKlD2gSPnjZDWtM/aOx+oIs7hcrg4nnzbpvVTHL 1u9jqGKM2OX2n60jjnPqwlXAr/3OkSYYLVdbrrxBLxCNbmgzoQsOSpRvTXVUdunORz+e An0g== X-Gm-Message-State: AMke39m/X2QHVxLO7Jj0S8CzD/8Ojppm6KZbOB01QDwAgIlflnqU5TZQCjqnEGUaEzQaSA== X-Received: by 10.223.162.133 with SMTP id s5mr28546544wra.157.1487804200597; Wed, 22 Feb 2017 14:56:40 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 14:56:40 -0800 (PST) From: Benedikt Morbach To: linux-btrfs@vger.kernel.org Cc: Benedikt Morbach Subject: [PATCH 1/2] btrfs-progs: receive: better error reporting for snapshots Date: Wed, 22 Feb 2017 23:56:36 +0100 Message-Id: <20170222225637.21858-1-benedikt.morbach@googlemail.com> X-Mailer: git-send-email 2.11.1 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 Two fixes: 1) Check that the parent subvol actually is reachable via our root path. The previous code wouldn't catch parent subvol: foo/bar root path: bar (i.e. mounted with -o subvol=bar) where the parent isn't reachable from the root path. (but the original "strstr(parent, root_path) == NULL" check still doesn't hold) Also check for the slash after "root_path", i.e. throw an error on parent subvol: foobar root path: foo 2) If the parent subvol is the one that is mounted we obviously can't receive into it, as it has to be read-only by definition. We'd get a rather cryptic: At subvol /tmp/test/dest.snap At snapshot dest.snap ERROR: creating snapshot / -> dest.snap failed: Invalid cross-device link (not sure what it says if "/" isn't even a btrfs) But with this we get At subvol /tmp/test/dest.snap At snapshot dest.snap ERROR: creating snapshot . -> dest.snap failed: Read-only file system which is both more helpful and more correct. Signed-off-by: Benedikt Morbach --- cmds-receive.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmds-receive.c b/cmds-receive.c index 166d37d..790218c 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -314,8 +314,8 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid, sub_len = strlen(parent_subvol->path); /* First make sure the parent subvol is actually in our path */ - if (sub_len < root_len || - strstr(parent_subvol->path, rctx->full_root_path) == NULL) { + if (strstr(parent_subvol->path, rctx->full_root_path) != parent_subvol->path || + sub_len > root_len && parent_subvol->path[root_len] != '/') { error( "parent subvol is not reachable from inside the root subvol"); ret = -ENOENT; @@ -323,7 +323,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid, } if (sub_len == root_len) { - parent_subvol->path[0] = '/'; + parent_subvol->path[0] = '.'; parent_subvol->path[1] = '\0'; } else { /*