From patchwork Thu May 7 18:53:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: lauri X-Patchwork-Id: 6360551 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F24D2BEEE1 for ; Thu, 7 May 2015 18:54:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 09E61202EB for ; Thu, 7 May 2015 18:54:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D62D7200ED for ; Thu, 7 May 2015 18:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751740AbbEGSyL (ORCPT ); Thu, 7 May 2015 14:54:11 -0400 Received: from mail-la0-f48.google.com ([209.85.215.48]:33262 "EHLO mail-la0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751707AbbEGSyK (ORCPT ); Thu, 7 May 2015 14:54:10 -0400 Received: by layy10 with SMTP id y10so37450783lay.0 for ; Thu, 07 May 2015 11:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=q8XG9gnaWm9dV8TkPqXLKYzGniQ5rfXHH7Abn9oskzk=; b=GgHovD/mJRFzayEpUIxEQX/vzLdZdfGglqzoeG4qj7alvLJnboQ4RqpJ8cPovE+v5R o4CLd2JRDoATUqrZRInuGYtFqc5J4E/YQmsAnvsWz7iugoDOHRShL0r41HpEzOJMmWiA VhlFXT/N9RBlXkaFJ46dxpt9EMfFfezExGgzYUAIOlXycAIO5PemVqlKyUgNpBX+fGbZ DhZOzCyt32DA8BKimUAPKe5Ws/P/RGoWHAhANLsbhge6rSXFTCr1EA+Iwd73eM9PjLp2 AChYAWys36sAK9sWNH39noHg6z9hlBmrBenEDjjivpSiAoYkzhlFHKT7TfRv/1mzotT0 MzdQ== X-Received: by 10.153.8.167 with SMTP id dl7mr44604lad.86.1431024848243; Thu, 07 May 2015 11:54:08 -0700 (PDT) Received: from localhost.localdomain (128-45-71-217.dyn.internet.emt.ee. [217.71.45.128]) by mx.google.com with ESMTPSA id m8sm634717lbs.17.2015.05.07.11.54.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 May 2015 11:54:07 -0700 (PDT) From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= To: linux-btrfs@vger.kernel.org Cc: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Subject: [PATCH v2] btrfs-progs: receive explicit parent support Date: Thu, 7 May 2015 21:53:59 +0300 Message-Id: <1431024839-13693-1-git-send-email-lauri.vosandi@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430043165-20641-1-git-send-email-lauri.vosandi@gmail.com> References: <1430043165-20641-1-git-send-email-lauri.vosandi@gmail.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds command-line flag -p to btrfs receive which makes it possible to disable automatic parent search for incremental snapshots and use explicitly specified path instead. Works also with multiple incremental snapshots. Signed-off-by: Lauri Võsandi --- cmds-receive.c | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/cmds-receive.c b/cmds-receive.c index b7cf3f9..21a6f56 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -61,6 +61,7 @@ struct btrfs_receive char *root_path; char *dest_dir_path; /* relative to root_path */ char *full_subvol_path; + char *explicit_parent_path; int dest_dir_chroot; struct subvol_info *cur_subvol; @@ -152,6 +153,12 @@ static int process_subvol(const char *path, const u8 *uuid, u64 ctransid, if (ret < 0) goto out; + if (r->explicit_parent_path) { + free(r->explicit_parent_path); + r->explicit_parent_path = NULL; + fprintf(stderr, "WARNING: Receiving full snapshot, no need to specify explicit parent!\n"); + } + r->cur_subvol = calloc(1, sizeof(*r->cur_subvol)); if (strlen(r->dest_dir_path) == 0) @@ -220,20 +227,32 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid, fprintf(stderr, "receiving snapshot %s uuid=%s, " "ctransid=%llu ", path, uuid_str, r->cur_subvol->stransid); - uuid_unparse(parent_uuid, uuid_str); - fprintf(stderr, "parent_uuid=%s, parent_ctransid=%llu\n", - uuid_str, parent_ctransid); } memset(&args_v2, 0, sizeof(args_v2)); strncpy_null(args_v2.name, path); - parent_subvol = subvol_uuid_search(&r->sus, 0, parent_uuid, - parent_ctransid, NULL, subvol_search_by_received_uuid); - if (!parent_subvol) { + if (r->explicit_parent_path) { + if (g_verbose) { + fprintf(stderr, "using explicit parent %s\n", + r->explicit_parent_path); + } + parent_subvol = subvol_uuid_search(&r->sus, 0, NULL, + 0, r->explicit_parent_path, subvol_search_by_path); + } else { + if (g_verbose) { + uuid_unparse(parent_uuid, uuid_str); + fprintf(stderr, "parent_uuid=%s, parent_ctransid=%llu\n", + uuid_str, parent_ctransid); + } parent_subvol = subvol_uuid_search(&r->sus, 0, parent_uuid, - parent_ctransid, NULL, subvol_search_by_uuid); + parent_ctransid, NULL, subvol_search_by_received_uuid); + if (!parent_subvol) { + parent_subvol = subvol_uuid_search(&r->sus, 0, parent_uuid, + parent_ctransid, NULL, subvol_search_by_uuid); + } } + if (!parent_subvol) { ret = -ENOENT; fprintf(stderr, "ERROR: could not find parent subvolume\n"); @@ -276,6 +295,12 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid, goto out; } + if (r->explicit_parent_path) { + free(r->explicit_parent_path); + r->explicit_parent_path = strdup(r->cur_subvol->path); + printf("New explicit parent is %s\n", r->explicit_parent_path); + } + out: if (parent_subvol) { free(parent_subvol->path); @@ -922,6 +947,10 @@ out: r->full_subvol_path = NULL; r->dest_dir_path = NULL; free(dest_dir_full_path); + if (r->explicit_parent_path) { + free(r->explicit_parent_path); + r->explicit_parent_path = NULL; + } if (r->cur_subvol) { free(r->cur_subvol->path); free(r->cur_subvol); @@ -962,11 +991,14 @@ int cmd_receive(int argc, char **argv) { NULL, 0, NULL, 0 } }; - c = getopt_long(argc, argv, "Cevf:", long_opts, NULL); + c = getopt_long(argc, argv, "Cevf:p:", long_opts, NULL); if (c < 0) break; switch (c) { + case 'p': + r.explicit_parent_path = strdup(optarg); + break; case 'v': g_verbose++; break; @@ -1028,6 +1060,8 @@ const char * const cmd_receive_usage[] = { " in the data stream. Without this option,", " the receiver terminates only if an error", " is recognized or on EOF.", + "-p Disables the automatic searching for parents", + " if incremental streams are received.", "-C|--chroot confine the process to using chroot", "--max-errors Terminate as soon as N errors happened while", " processing commands from the send stream.",