From patchwork Fri Jan 26 18:41:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10186761 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 B8EE8601D5 for ; Fri, 26 Jan 2018 18:42:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAB7229EC8 for ; Fri, 26 Jan 2018 18:42:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D7C929ED0; Fri, 26 Jan 2018 18:42:15 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 DE9EA29EC8 for ; Fri, 26 Jan 2018 18:42:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752297AbeAZSmL (ORCPT ); Fri, 26 Jan 2018 13:42:11 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:41652 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752084AbeAZSlr (ORCPT ); Fri, 26 Jan 2018 13:41:47 -0500 Received: by mail-pg0-f67.google.com with SMTP id 136so782099pgd.8 for ; Fri, 26 Jan 2018 10:41:47 -0800 (PST) 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 :in-reply-to:references; bh=peCBqb0ky9mk2z1x2omI83Vb5wcKaOvAOGRlyfmluDc=; b=wffEZBbEL4QxXGVdHItUhpystjRTiX+6aVrFuY0GOWIW0p8gbgMdAYEWd6kQHr2Xru lVvvwOkvWajfuow9jatk1RqCJ6PHwV4Ls8z2xryVX5fjetzNG7ok0V2AIUb3CuqOGKuh wF38Ku7GaKFzY6BWlyM/0ynIaBPpBW4CjUTd9Qh56Xw1vrqohM7K+k6Im9g4xMmG2c7D JYhcHi5/vsNfZkkplBZ1QK31iAsMC8JLUunEM47b5DVGpPkW0WX8H4sMpyCWQL+1xRjV ZcAaTRUoM52YKLm7/qdyUcfO8zD7pW2LSu3cxfMdpzPjsPcyJBzXD4EI01p2kxsX0fmE E9VA== 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:in-reply-to:references; bh=peCBqb0ky9mk2z1x2omI83Vb5wcKaOvAOGRlyfmluDc=; b=LQvPBl2YrSUygeMXLPO/0ShyLYDsGPBoGXdrv0IX5PqPMXTlM/9ocEmel0h5yB3j1j S9FRAm5u6NddkZe2KyJN4rZQMbP6vX9Wn50qmTTF5Bbup3+DG4HQ/gT/DKSfLpJmLtAx +5+UnpDKYrbxMNtD+3mljklEKh5aWqBBnEmRtuT7GRzvyBuS4maqRziDqriIDztlOypm X0nPP8T3OnkLrN++r81E0NDHHt/morLAdclML97KFN6lozwSjsYPyWPESFUXMsyCD7t3 nHkTSc+06rT6lZD+Cz0Xuc43i4fEGvaZI0zIsULFflvS+jBlKWu015DTGERUNnea7oRX bpkQ== X-Gm-Message-State: AKwxytdI5tNe6gebsjjlc/acuuEwsc+jDyd3/u4gl00IkpwFySIfy6Jg fAmxGHfGAwMnJYRcVWodbX825lmcFS4= X-Google-Smtp-Source: AH8x227PyaT7X4Ud78KqUSoC2pNBl1bdnKkmPyyewNMveCx62Q/ko+iCPdm4Dx5gJda5ZsLG2Nswng== X-Received: by 2002:a17:902:5a41:: with SMTP id f1-v6mr15238190plm.201.1516992106613; Fri, 26 Jan 2018 10:41:46 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:7f96]) by smtp.gmail.com with ESMTPSA id y29sm19627400pff.24.2018.01.26.10.41.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 10:41:45 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 24/26] btrfs-progs: add recursive snapshot/delete using libbtrfsutil Date: Fri, 26 Jan 2018 10:41:12 -0800 Message-Id: X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: 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 And update the documentation. Signed-off-by: Omar Sandoval --- Documentation/btrfs-subvolume.asciidoc | 14 ++++++++++++-- cmds-subvolume.c | 25 +++++++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Documentation/btrfs-subvolume.asciidoc b/Documentation/btrfs-subvolume.asciidoc index a8c4af4b..7a2ec8d2 100644 --- a/Documentation/btrfs-subvolume.asciidoc +++ b/Documentation/btrfs-subvolume.asciidoc @@ -81,6 +81,12 @@ wait for transaction commit at the end of the operation + -C|--commit-each:::: wait for transaction commit after deleting each subvolume ++ +-R|--recursive:::: +delete subvolumes beneath each subvolume recursively ++ +-v|--verbose:::: +output more verbosely *find-new* :: List the recently modified files in a subvolume, after ID. @@ -157,7 +163,7 @@ The id can be obtained from *btrfs subvolume list*, *btrfs subvolume show* or *show* :: Show information of a given subvolume in the . -*snapshot* [-r] |[/]:: +*snapshot* [-r|-R] |[/]:: Create a snapshot of the subvolume with the name in the directory. + @@ -167,7 +173,11 @@ If is not a subvolume, btrfs returns an error. `Options` + -r:::: -Make the new snapshot read only. +make the new snapshot read-only ++ +-R:::: +recursively snapshot subvolumes beneath the source; this option cannot be +combined with -r *sync* [subvolid...]:: Wait until given subvolume(s) are completely removed from the filesystem after diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 5c75799c..3521e7b7 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -187,6 +187,7 @@ static const char * const cmd_subvol_delete_usage[] = { "", "-c|--commit-after wait for transaction commit at the end of the operation", "-C|--commit-each wait for transaction commit after deleting each subvolume", + "-R|--recursive delete subvolumes beneath each subvolume recursively", "-v|--verbose verbose output of operations", NULL }; @@ -203,6 +204,7 @@ static int cmd_subvol_delete(int argc, char **argv) DIR *dirstream = NULL; int verbose = 0; int commit_mode = 0; + int flags = 0; u8 fsid[BTRFS_FSID_SIZE]; char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; struct seen_fsid *seen_fsid_hash[SEEN_FSID_HASH_SIZE] = { NULL, }; @@ -214,11 +216,12 @@ static int cmd_subvol_delete(int argc, char **argv) static const struct option long_options[] = { {"commit-after", no_argument, NULL, 'c'}, {"commit-each", no_argument, NULL, 'C'}, + {"recursive", no_argument, NULL, 'R'}, {"verbose", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0} }; - c = getopt_long(argc, argv, "cCv", long_options, NULL); + c = getopt_long(argc, argv, "cCRv", long_options, NULL); if (c < 0) break; @@ -229,6 +232,9 @@ static int cmd_subvol_delete(int argc, char **argv) case 'C': commit_mode = COMMIT_EACH; break; + case 'R': + flags |= BTRFS_UTIL_DELETE_SUBVOLUME_RECURSIVE; + break; case 'v': verbose++; break; @@ -281,7 +287,7 @@ again: commit_mode == COMMIT_EACH || (commit_mode == COMMIT_AFTER && cnt + 1 == argc) ? "commit" : "no-commit", dname, vname); - err = btrfs_util_f_delete_subvolume(fd, vname, 0); + err = btrfs_util_f_delete_subvolume(fd, vname, flags); if (err) { error_btrfs_util(err); ret = 1; @@ -571,13 +577,15 @@ out: } static const char * const cmd_subvol_snapshot_usage[] = { - "btrfs subvolume snapshot [-r] [-i ] |[/]", + "btrfs subvolume snapshot [-r|-R] [-i ] |[/]", "Create a snapshot of the subvolume", "Create a writable/readonly snapshot of the subvolume with", "the name in the directory. If only is given,", "the subvolume will be named the basename of .", "", "-r create a readonly snapshot", + "-R recursively snapshot subvolumes beneath the source; this", + " option cannot be combined with -r", "-i add the newly created snapshot to a qgroup. This", " option can be given multiple times.", NULL @@ -591,7 +599,7 @@ static int cmd_subvol_snapshot(int argc, char **argv) int retval = 1; while (1) { - int c = getopt(argc, argv, "i:r"); + int c = getopt(argc, argv, "i:rR"); if (c < 0) break; @@ -603,11 +611,20 @@ static int cmd_subvol_snapshot(int argc, char **argv) case 'r': flags |= BTRFS_UTIL_CREATE_SNAPSHOT_READ_ONLY; break; + case 'R': + flags |= BTRFS_UTIL_CREATE_SNAPSHOT_RECURSIVE; + break; default: usage(cmd_subvol_snapshot_usage); } } + if ((flags & BTRFS_UTIL_CREATE_SNAPSHOT_READ_ONLY) && + (flags & BTRFS_UTIL_CREATE_SNAPSHOT_RECURSIVE)) { + error("-r and -R cannot be combined"); + return 1; + } + if (check_argc_exact(argc - optind, 2)) usage(cmd_subvol_snapshot_usage);