Skip to content

Commit 3a0c784

Browse files
maharmstoneosandov
andcommitted
btrfs-progs: add option for recursive subvol snapshots
Adds an option -R to btrfs subvolume snapshot, corresponding to the flag BTRFS_UTIL_CREATE_SNAPSHOT_RECURSIVE. This is another resubmission of a missed patch of Omar's from 2018: https://lore.kernel.org/all/e42cdc5d5287269faf4d09e8c9786d0b3adeb658.1516991902.git.osandov@fb.com/ Signed-off-by: Mark Harmstone <[email protected]> Co-authored-by: Omar Sandoval <[email protected]>
1 parent c75b2f2 commit 3a0c784

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Documentation/btrfs-subvolume.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,23 @@ show [options] <path>
252252
-u|--uuid UUID
253253
show details about subvolume with the given *UUID*, looked up in *path*
254254

255-
snapshot [-r] [-i <qgroupid>] <source> <dest>|[<dest>/]<name>
255+
snapshot [-r|-R] [-i <qgroupid>] <source> <dest>|[<dest>/]<name>
256256
Create a snapshot of the subvolume *source* with the
257257
name *name* in the *dest* directory.
258258

259259
If only *dest* is given, the subvolume will be named the basename of *source*.
260260
If *source* is not a subvolume, btrfs returns an error.
261261

262+
If you wish to recursively create a readonly snapshot, you can run
263+
:command:`btrfs property set <path> ro true` on each subvolume after this command completes.
264+
262265
``Options``
263266

264267
-r
265268
Make the new snapshot read only.
269+
-R|--recursive
270+
Recursively snapshot subvolumes beneath the source. This option cannot be
271+
combined with -r.
266272
-i <qgroupid>
267273
Add the newly created subvolume to a qgroup. This option can be given multiple
268274
times.

cmds/subvolume.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ static int cmd_subvolume_delete(const struct cmd_struct *cmd, int argc, char **a
616616
static DEFINE_COMMAND_WITH_FLAGS(subvolume_delete, "delete", CMD_DRY_RUN);
617617

618618
static const char * const cmd_subvolume_snapshot_usage[] = {
619-
"btrfs subvolume snapshot [-r] [-i <qgroupid>] <subvolume> { <subdir>/<name> | <subdir> }",
619+
"btrfs subvolume snapshot [-r|-R] [-i <qgroupid>] <subvolume> { <subdir>/<name> | <subdir> }",
620620
"",
621621
"Create a snapshot of a <subvolume>. Call it <name> and place it in the <subdir>.",
622622
"(<subvolume> will look like a new sub-directory, but is actually a btrfs subvolume",
@@ -625,6 +625,7 @@ static const char * const cmd_subvolume_snapshot_usage[] = {
625625
"When only <subdir> is given, the subvolume will be named the basename of <subvolume>.",
626626
"",
627627
OPTLINE("-r", "make the new snapshot readonly"),
628+
OPTLINE("-R|--recursive", "recursively snapshot subvolumes beneath the source; this option cannot be combined with -r"),
628629
OPTLINE("-i <qgroupid>", "Add the new snapshot to a qgroup (a quota group). This option can be given multiple times."),
629630
HELPINFO_INSERT_GLOBALS,
630631
HELPINFO_INSERT_QUIET,
@@ -642,7 +643,7 @@ static int cmd_subvolume_snapshot(const struct cmd_struct *cmd, int argc, char *
642643

643644
optind = 0;
644645
while (1) {
645-
int c = getopt(argc, argv, "i:r");
646+
int c = getopt(argc, argv, "i:rR");
646647
if (c < 0)
647648
break;
648649

@@ -657,11 +658,21 @@ static int cmd_subvolume_snapshot(const struct cmd_struct *cmd, int argc, char *
657658
case 'r':
658659
flags |= BTRFS_UTIL_CREATE_SNAPSHOT_READ_ONLY;
659660
break;
661+
case 'R':
662+
flags |= BTRFS_UTIL_CREATE_SNAPSHOT_RECURSIVE;
663+
break;
660664
default:
661665
usage_unknown_option(cmd, argv);
662666
}
663667
}
664668

669+
if ((flags & BTRFS_UTIL_CREATE_SNAPSHOT_READ_ONLY) &&
670+
(flags & BTRFS_UTIL_CREATE_SNAPSHOT_RECURSIVE)) {
671+
error("-r and -R cannot be combined");
672+
retval = 1;
673+
goto out;
674+
}
675+
665676
if (check_argc_exact(argc - optind, 2)) {
666677
retval = 1;
667678
goto out;

0 commit comments

Comments
 (0)