From patchwork Thu Feb 15 19:05:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10223403 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 27A88602CB for ; Thu, 15 Feb 2018 19:06:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1713C29406 for ; Thu, 15 Feb 2018 19:06:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AF2D29485; Thu, 15 Feb 2018 19:06:01 +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 877C029406 for ; Thu, 15 Feb 2018 19:06:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1167189AbeBOTF6 (ORCPT ); Thu, 15 Feb 2018 14:05:58 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:41353 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161962AbeBOTFz (ORCPT ); Thu, 15 Feb 2018 14:05:55 -0500 Received: by mail-pl0-f65.google.com with SMTP id k8so346917pli.8 for ; Thu, 15 Feb 2018 11:05:55 -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=nOCI7tRE9Q91od+wpnkv2wLWwhHRIk/1awYkhsrYfTs=; b=pk2DVelWwEgxu0AVPEid7iR3pDFywxgGiqjzmzWW8iBuujpHja2KcLkqRLZgygu5EL PrM9khRbLcuyWnODDihG1NXJnVSTvI+rXVBPyTsNAYIFusA6FhEMRuI7r6u4Y4eqvCs+ gJN9DsESQtxwKEOi7OtCk8gXvQNruMX6lQfVu9BM+EY3Iotx9Ud9gw9QP6TpzAyd9gbv wSyzqz8EEqyL++XGfJwzLqpz2iBl5skRwoB81+4BAeRTKfiM+bxVS3RTNgnzhV8gOo39 ugUs0WrJK96dBPs+ElMvShXtoGqOWQLAAHSfPsvwWj4vUy4w2DsOlhgzY28wdLvYtQCo gouA== 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=nOCI7tRE9Q91od+wpnkv2wLWwhHRIk/1awYkhsrYfTs=; b=Um6y1eHGPyMPzb4wGUe4EwDiMpICukZIbaGnNV4wANfvl/5h1gXMRQuMSbD+fNpIqY ny+YSFGuhnHlJIunTgc16avQ528pBQWaIHBPAMdBfcH1eOb9iVKWMQ5OCzPjmHT5vwKh b0QFYb3oBct0eN91GNX9B8aKMUaaKH+iS7uPIbZbh8hLzouuNd6NG1KFcIVoAKapVgoP v+FBOjTpUErTrb58Tam6vDUh7cSzVQqjaZz0yrtQ5bAibLX9QV3CEimCtlupptKo1cHt wx7pWlc9zx2xCYcSjz4JQGj0EgfHT8KCJ20WSbJjvGbKyV0CI9QcbvhEUszoDxId7qq3 tbag== X-Gm-Message-State: APf1xPDkc9FY4Tk6JUosp7jSxm5PgIAThyYOx5RmfywlakmMeq2AYcDi H187+UFQsElanmGnzWAqKtH/bSE/6Xc= X-Google-Smtp-Source: AH8x227+sPGGUNnAS4tag3d3Bu/GexFtl8aPA68GV547c0a5x8lBVhvo7kQgTYbhPU2jCA97OW2/HQ== X-Received: by 2002:a17:902:5501:: with SMTP id f1-v6mr3397238pli.50.1518721554354; Thu, 15 Feb 2018 11:05:54 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:4a19]) by smtp.gmail.com with ESMTPSA id p1sm40467428pgr.44.2018.02.15.11.05.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 11:05:53 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH v2 25/27] btrfs-progs: add recursive snapshot/delete using libbtrfsutil Date: Thu, 15 Feb 2018 11:05:10 -0800 Message-Id: <0c443530936babb4c061c71817aa324da168e116.1518720598.git.osandov@fb.com> 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 43875c96..101ba4ca 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; @@ -280,7 +286,7 @@ again: commit_mode == COMMIT_EACH || (commit_mode == COMMIT_AFTER && cnt + 1 == argc) ? "commit" : "no-commit", dname, vname); - err = btrfs_util_delete_subvolume_fd(fd, vname, 0); + err = btrfs_util_delete_subvolume_fd(fd, vname, flags); if (err) { error_btrfs_util(err); ret = 1; @@ -569,13 +575,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 @@ -589,7 +597,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; @@ -601,11 +609,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);