Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Documentation/btrfs-subvolume.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ from normal directories.

SUBCOMMAND
-----------
*create* [-i <qgroupid>] [<dest>]<name>::
*create* [-v] [-i <qgroupid>] [<dest>]<name>::
Create a subvolume <name> in <dest>.
+
If <dest> is not given, subvolume <name> will be created in the currently
Expand All @@ -54,6 +54,9 @@ directory.
-i <qgroupid>::::
Add the newly created subvolume to a qgroup. This option can be given multiple
times.
+
-v::::
be a bit more verbose

*delete* [options] <subvolume> [<subvolume>...]::
Delete the subvolume(s) from the filesystem.
Expand All @@ -74,6 +77,9 @@ wait for transaction commit at the end of the operation
+
-C|--commit-each::::
wait for transaction commit after delet each subvolume
+
-v::::
be a bit more verbose (may be specified more than once)

*find-new* <subvolume> <last_gen>::
List the recently modified files in a subvolume, after <last_gen> ID.
Expand Down Expand Up @@ -145,13 +151,16 @@ command.
*show* <path>::
Show information of a given subvolume in the <path>.

*snapshot* [-r] <source> <dest>|[<dest>/]<name>::
*snapshot* [-v] [-r] <source> <dest>|[<dest>/]<name>::
Create a writable/readonly snapshot of the subvolume <source> with the
name <name> in the <dest> directory.
+
If only <dest> is given, the subvolume will be named the basename of <source>.
If <source> is not a subvolume, btrfs returns an error.
If '-r' is given, the snapshot will be readonly.
+
-v::::
be a bit more verbose

*sync* <path> [subvolid...]::
Wait until given subvolume(s) are completely removed from the filesystem
Expand Down
41 changes: 27 additions & 14 deletions cmds-subvolume.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static const char * const cmd_subvol_create_usage[] = {
static int cmd_subvol_create(int argc, char **argv)
{
int retval, res, len;
int verbose = 0;
int fddst = -1;
char *dupname = NULL;
char *dupdir = NULL;
Expand Down Expand Up @@ -146,6 +147,9 @@ static int cmd_subvol_create(int argc, char **argv)
goto out;
}
break;
case 'v':
verbose++;
break;
default:
usage(cmd_subvol_create_usage);
}
Expand Down Expand Up @@ -185,7 +189,9 @@ static int cmd_subvol_create(int argc, char **argv)
if (fddst < 0)
goto out;

printf("Create subvolume '%s/%s'\n", dstdir, newname);
if (verbose)
printf("Create subvolume '%s/%s'\n", dstdir, newname);

if (inherit) {
struct btrfs_ioctl_vol_args_v2 args;

Expand Down Expand Up @@ -288,7 +294,7 @@ static int cmd_subvol_delete(int argc, char **argv)
{NULL, 0, NULL, 0}
};

c = getopt_long(argc, argv, "cC", long_options, NULL);
c = getopt_long(argc, argv, "cCv", long_options, NULL);
if (c < 0)
break;

Expand All @@ -310,7 +316,7 @@ static int cmd_subvol_delete(int argc, char **argv)
if (check_argc_min(argc - optind, 1))
usage(cmd_subvol_delete_usage);

if (verbose > 0) {
if (verbose > 1) {
printf("Transaction commit: %s\n",
!commit_mode ? "none (default)" :
commit_mode == 1 ? "at the end" : "after each");
Expand Down Expand Up @@ -352,9 +358,10 @@ static int cmd_subvol_delete(int argc, char **argv)
goto out;
}

printf("Delete subvolume (%s): '%s/%s'\n",
commit_mode == 2 || (commit_mode == 1 && cnt + 1 == argc)
? "commit" : "no-commit", dname, vname);
if (verbose)
printf("Delete subvolume (%s): '%s/%s'\n",
commit_mode == 2 || (commit_mode == 1 && cnt + 1 == argc)
? "commit" : "no-commit", dname, vname);
memset(&args, 0, sizeof(args));
strncpy_null(args.name, vname);
res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
Expand Down Expand Up @@ -628,6 +635,7 @@ static int cmd_subvol_snapshot(int argc, char **argv)
int res, retval;
int fd = -1, fddst = -1;
int len, readonly = 0;
int verbose = 0;
char *dupname = NULL;
char *dupdir = NULL;
char *newname;
Expand All @@ -639,7 +647,7 @@ static int cmd_subvol_snapshot(int argc, char **argv)
optind = 1;
memset(&args, 0, sizeof(args));
while (1) {
int c = getopt(argc, argv, "c:i:r");
int c = getopt(argc, argv, "c:i:rv");
if (c < 0)
break;

Expand All @@ -661,6 +669,9 @@ static int cmd_subvol_snapshot(int argc, char **argv)
case 'r':
readonly = 1;
break;
case 'v':
verbose++;
break;
case 'x':
res = qgroup_inherit_add_copy(&inherit, optarg, 1);
if (res) {
Expand Down Expand Up @@ -728,13 +739,15 @@ static int cmd_subvol_snapshot(int argc, char **argv)
if (fd < 0)
goto out;

if (readonly) {
args.flags |= BTRFS_SUBVOL_RDONLY;
printf("Create a readonly snapshot of '%s' in '%s/%s'\n",
subvol, dstdir, newname);
} else {
printf("Create a snapshot of '%s' in '%s/%s'\n",
subvol, dstdir, newname);
if (verbose) {
if (readonly) {
args.flags |= BTRFS_SUBVOL_RDONLY;
printf("Create a readonly snapshot of '%s' in '%s/%s'\n",
subvol, dstdir, newname);
} else {
printf("Create a snapshot of '%s' in '%s/%s'\n",
subvol, dstdir, newname);
}
}

args.fd = fd;
Expand Down