summaryrefslogtreecommitdiff
path: root/cmds-subvolume.c
diff options
context:
space:
mode:
authorMisono, Tomohiro <misono.tomohiro@jp.fujitsu.com>2017-10-06 10:05:08 +0900
committerDavid Sterba <dsterba@suse.com>2017-11-14 15:59:00 +0100
commit4a5b95abb620175ca6eb356ff8a7d698891fa8ab (patch)
tree064a6f191eee6e7f43142aa8f19ba3d16e9511ad /cmds-subvolume.c
parentc56d61883c6f093ac905c49f76a99be5e8e09332 (diff)
btrfs-progs: subvol: change set-default to also accept path
This patch changes "subvol set-default" to also accept the subvolume path for convenience. If there are two args, they are assumed as subvol id and path to the fs (the same as current behavior), and if there is only one arg, it is assumed as the path to the subvolume. subvol id is resolved by test_issubvolume() + lookup_path_rootid(). The empty subvol (ino == 2) will get error on test_issubvolume() which checks whether inode num is 256 or not. Issue: #35 Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> [ update documentation, use the new multi-line command scheme ] Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r--cmds-subvolume.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index e7caa05a..dc626a64 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -858,8 +858,11 @@ out:
}
static const char * const cmd_subvol_set_default_usage[] = {
+ "btrfs subvolume set-default <subvolume>\n"
"btrfs subvolume set-default <subvolid> <path>",
- "Set the default subvolume of a filesystem",
+ "Set the default subvolume of the filesystem mounted as default.",
+ "The subvolume can be specified by its path,",
+ "or the pair of subvolume id and path to the filesystem.",
NULL
};
@@ -873,17 +876,43 @@ static int cmd_subvol_set_default(int argc, char **argv)
clean_args_no_options(argc, argv, cmd_subvol_set_default_usage);
- if (check_argc_exact(argc - optind, 2))
+ if (check_argc_min(argc - optind, 1) ||
+ check_argc_max(argc - optind, 2))
usage(cmd_subvol_set_default_usage);
- subvolid = argv[optind];
- path = argv[optind + 1];
+ if (argc - optind == 1) {
+ /* path to the subvolume is specified */
+ path = argv[optind];
- objectid = arg_strtou64(subvolid);
+ ret = test_issubvolume(path);
+ if (ret < 0) {
+ error("stat error: %s", strerror(-ret));
+ return 1;
+ } else if (!ret) {
+ error("'%s' is not a subvolume", path);
+ return 1;
+ }
- fd = btrfs_open_dir(path, &dirstream, 1);
- if (fd < 0)
- return 1;
+ fd = btrfs_open_dir(path, &dirstream, 1);
+ if (fd < 0)
+ return 1;
+
+ ret = lookup_path_rootid(fd, &objectid);
+ if (ret) {
+ error("unable to get subvol id: %s", strerror(-ret));
+ close_file_or_dir(fd, dirstream);
+ return 1;
+ }
+ } else {
+ /* subvol id and path to the filesystem are specified */
+ subvolid = argv[optind];
+ path = argv[optind + 1];
+ objectid = arg_strtou64(subvolid);
+
+ fd = btrfs_open_dir(path, &dirstream, 1);
+ if (fd < 0)
+ return 1;
+ }
ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
e = errno;