From patchwork Sat Jul 20 05:40:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11050779 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA38F138D for ; Sat, 20 Jul 2019 05:40:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7A4628736 for ; Sat, 20 Jul 2019 05:40:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B80D22892A; Sat, 20 Jul 2019 05:40:42 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 A50F8287AA for ; Sat, 20 Jul 2019 05:40:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726104AbfGTFkN (ORCPT ); Sat, 20 Jul 2019 01:40:13 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:33494 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726094AbfGTFkN (ORCPT ); Sat, 20 Jul 2019 01:40:13 -0400 Received: by mail-pf1-f194.google.com with SMTP id g2so15060947pfq.0 for ; Fri, 19 Jul 2019 22:40:12 -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=R3XPN37kWDUeiGuCc8nM3y2u88/tB4DlcnWSI/ymbxc=; b=hwrkOh5cDu5f8XtthdpPPu1vJDoMQh9B4mP2yx2ny6gVNHMfxDaJgSstrkalvs2+Rc nCBgvCG6Tb5uSFkvg6Xs3s57mdJkrrR4f8c0fZN/0TRd0L750+NTbsHStoafXE/wQbKz ZfAACv+jmrdHvo/u2HgWtS9u7/idFqrIFkwfVxGADgtrhwKMQsKVel4zMrg/mAqkLt6J Rt5YOlK1vDZJFREn/7OlHLt52qrr8lClGrsm7peuUt0V7qn4YYwjg/vm9TdI3A47BByA lAazk5ceAsq3fXeYhwZsBjxldbyA1WrIMXDEbmEXo2Ai3OKmKkKGwEkRDFDJSmZCt1gm TyCg== 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=R3XPN37kWDUeiGuCc8nM3y2u88/tB4DlcnWSI/ymbxc=; b=ffkHh+/7oDJSocVWvuo9hYkP0SfD5fbQSFqNwWuP6lxL0PtbN4G9tvY0ECtfLYhEsX 5cRTcBtVmC8N1C+6XpG7t517lRXt2nmzYkXhvOiw8T9tKJ99Ne5j0HTF8Bvu3BVdow3o MtCINmJTEGy6LcVuQ04IEaK9RXfCuexa/bXM3ttJx/pKcDSp+Jow8DDGpIYjOSTTp6qj ff1lUVIaQCRSH88kmHntY5L93dfrWOegqg52Ofwx4dUiXeG86B4xsFW/tDwc3DTNB68P /jd13xhsQiZptnGQ29Usymy5SoOBDvx0dEwcIX4o5BdDYlBOfW/T16GXJuB5m5fkteVz yXvA== X-Gm-Message-State: APjAAAVLRFxHIdZz9y3KbpO2VuvEYrDVfIA6XF1JH7j/S0TLJzEk9l9+ qw7e/brTDjHG4hQZITKokGKWylowpVk= X-Google-Smtp-Source: APXvYqzsgoYulbBJhFraO0zzRIDIUZN/N5EZJ27hy5+pNO/a8OHdNAwB9UbQSbhJ8Rc0I9H0mU88ng== X-Received: by 2002:a17:90a:346c:: with SMTP id o99mr61060468pjb.20.1563601211883; Fri, 19 Jul 2019 22:40:11 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:ba1e]) by smtp.gmail.com with ESMTPSA id w3sm28453762pgl.31.2019.07.19.22.40.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 19 Jul 2019 22:40:11 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, Omar Sandoval Subject: [PATCH 1/2] btrfs-progs: receive: get rid of unnecessary strdup() Date: Fri, 19 Jul 2019 22:40:00 -0700 Message-Id: X-Mailer: git-send-email 2.22.0 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 X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval In process_clone(), we're not checking the return value of strdup(). But, there's no reason to strdup() in the first place: we just pass the path into path_cat_out(). Get rid of the strdup(). Fixes: f1c24cd80dfd ("Btrfs-progs: add btrfs send/receive commands") Signed-off-by: Omar Sandoval Signed-off-by: Omar Sandoval --- cmds/receive.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmds/receive.c b/cmds/receive.c index b97850a7..a3e62985 100644 --- a/cmds/receive.c +++ b/cmds/receive.c @@ -739,7 +739,7 @@ static int process_clone(const char *path, u64 offset, u64 len, struct btrfs_ioctl_clone_range_args clone_args; struct subvol_info *si = NULL; char full_path[PATH_MAX]; - char *subvol_path = NULL; + char *subvol_path; char full_clone_path[PATH_MAX]; int clone_fd = -1; @@ -760,7 +760,7 @@ static int process_clone(const char *path, u64 offset, u64 len, if (memcmp(clone_uuid, rctx->cur_subvol.received_uuid, BTRFS_UUID_SIZE) == 0) { /* TODO check generation of extent */ - subvol_path = strdup(rctx->cur_subvol_path); + subvol_path = rctx->cur_subvol_path; } else { if (!si) ret = -ENOENT; @@ -794,14 +794,14 @@ static int process_clone(const char *path, u64 offset, u64 len, 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); + subvol_path = 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); + subvol_path = si->path; } } @@ -839,7 +839,6 @@ out: free(si->path); free(si); } - free(subvol_path); if (clone_fd != -1) close(clone_fd); return ret; From patchwork Sat Jul 20 05:40:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11050783 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2AB5A1800 for ; Sat, 20 Jul 2019 05:40:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1947328736 for ; Sat, 20 Jul 2019 05:40:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0351D287AA; Sat, 20 Jul 2019 05:40:42 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 C5362287D1 for ; Sat, 20 Jul 2019 05:40:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726114AbfGTFkO (ORCPT ); Sat, 20 Jul 2019 01:40:14 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44049 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726094AbfGTFkN (ORCPT ); Sat, 20 Jul 2019 01:40:13 -0400 Received: by mail-pg1-f196.google.com with SMTP id i18so15346472pgl.11 for ; Fri, 19 Jul 2019 22:40:13 -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=LQQ0cXom3U6A8cVVzlOULbBfO8fEGtMqapA3eGhu7MI=; b=s9wil83ihnhD44OkQBTS2KazGoj11U35oCuJ8O/uOfQcDyx6+pyMAuCJh/QuDiUYjB fd/QxPf+iIygPw220s2JlerKmJbNrEzd2YnFdSsP11iZlkORFqqlumd0YezWiuL1szJE 7BlySEBfcrqBCJPVk37Kl0HRDXFnTYUpQJKdV9asfnfyVguRvLXuWHV/viTnruhbozZn wsC5QhEJ2F8BtRnO3+5DfPJ/MMWIdGPs52v1Gb3TS3TH/rs1farmgCpHxVSawxdy8H6q 0G7kEaSpDWJcYE+7RJXU8ZTHDdjJaNdz3DlLMNG6Ilsvk6Ou0Fc060iLr8117jCsmAwu W47A== 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=LQQ0cXom3U6A8cVVzlOULbBfO8fEGtMqapA3eGhu7MI=; b=bOmw91CXkiNNfM1ewWbrgbYM5oyQ/NqkZMa0Ve54nFAHN7ax6oM9em0fO8UQE3r93Z R1qMrTqpCSpe0GObwk1bjz3yapUIJP1xPIkOeI80QIuPS9nNdUHXWx+t8Dbw/+T5csON vl3MkVcYupr47n7it5KWg8bkPWA+4K4rtDANNoltbjFwROva2jJG+/FDWgWZA7EUM2i8 +jDFn3tsyN02O7Lt435s9d8/rz5MhaVkDG7OJWhgBLriQe2tV6KrVrqsTaqzwRyI6dO7 e1YoLxyMBD1OY1/whIs3VFmSQGoq+Zs4o+Eco+ITms1iIfrp+aj+WOd10InZsI2s/aXM 7FNg== X-Gm-Message-State: APjAAAUk5BWKF4/oEmKAgLc7WtQv04YMtiwktWK9mz9uRTn984g1qj/w tQMlmCxYhVpwuyDyuW4fa6MsUVtMlP8= X-Google-Smtp-Source: APXvYqwH/5j/42hKlPqgyzaTI2ihUOMejSP/Ek+HjPpxP7NZJZAl0599a9UPXkcUdExxDr5MzO8qUg== X-Received: by 2002:a63:6ecf:: with SMTP id j198mr57804208pgc.437.1563601212853; Fri, 19 Jul 2019 22:40:12 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:ba1e]) by smtp.gmail.com with ESMTPSA id w3sm28453762pgl.31.2019.07.19.22.40.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 19 Jul 2019 22:40:12 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 2/2] btrfs-progs: receive: don't lookup clone root for received subvolume Date: Fri, 19 Jul 2019 22:40:01 -0700 Message-Id: <6af59460e12a8120bf643a923f5fa6bd3b135b20.1563600688.git.osandov@fb.com> X-Mailer: git-send-email 2.22.0 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 X-Virus-Scanned: ClamAV using ClamSMTP 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 subvol 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 stream subvol mkdir first second btrfs receive -f stream first btrfs receive -f stream 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. Also, while we're here, get rid of some code that has been commented out since it was added. Fixes: f1c24cd80dfd ("Btrfs-progs: add btrfs send/receive commands") Signed-off-by: Omar Sandoval --- cmds/receive.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/cmds/receive.c b/cmds/receive.c index a3e62985..ed089af2 100644 --- a/cmds/receive.c +++ b/cmds/receive.c @@ -753,15 +753,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 @@ -769,23 +768,6 @@ static int process_clone(const char *path, u64 offset, u64 len, error("clone: did not find source subvol"); 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);