summaryrefslogtreecommitdiff
path: root/cmds-subvolume.c
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2017-07-13 06:47:11 +0800
committerDavid Sterba <dsterba@suse.com>2017-07-20 17:43:43 +0200
commit8714e458f1a21ba159effbc54bc0f6ec6ff0031b (patch)
treed71db5118278aabc22da779121a12acee6c47a92 /cmds-subvolume.c
parent18aed6a623f86f02eb342205d4fc9c7f6928805d (diff)
btrfs-progs: subvol show: add support to search subvolume by rootid or uuid
Unless the top level is mounted there is no way to know the details of all the subvolume. For example: mount -o subvol=sv1/newsv1 /dev/sdb /btrfs btrfs su list /btrfs ID 257 gen 12 top level 5 path sv1 ID 258 gen 9 top level 257 path sv1/snap ID 259 gen 11 top level 257 path sv1/newsv1 You can't subvol show for sv1 and sv1/snap as its paths aren't accessible to the user unless the its top level is mounted. This patch adds two new options to the existing btrfs subvol show cli. They are --rootid/-r or --uuid/-u, with this now the user will be able to look for a subvolume using the rootid OR the uuid. ./btrfs su show -r 257 /btrfs sv1 Name: sv1 UUID: 30129358-c69d-3e4a-a662-29509cc69c95 Parent UUID: - Received UUID: - Creation time: 2017-07-11 20:32:57 +0800 Subvolume ID: 257 Generation: 12 Gen at creation: 7 Parent ID: 5 Top level ID: 5 Flags: - Snapshot(s): sv1/snap Signed-off-by: Anand Jain <anand.jain@oracle.com> [ minor adjustments in the help text ] Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r--cmds-subvolume.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index de6204e..666f6e0 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -891,8 +891,13 @@ static int cmd_subvol_find_new(int argc, char **argv)
}
static const char * const cmd_subvol_show_usage[] = {
- "btrfs subvolume show <subvol-path>",
- "Show more information of the subvolume",
+ "btrfs subvolume show [options] <subvol-path>|<mnt>",
+ "Show more information about the subvolume",
+ "-r|--rootid rootid of the subvolume",
+ "-u|--uuid uuid of the subvolume",
+ "",
+ "If no option is specified, <subvol-path> will be shown, otherwise",
+ "the rootid or uuid are resolved relative to the <mnt> path.",
NULL
};
@@ -907,12 +912,46 @@ static int cmd_subvol_show(int argc, char **argv)
int fd = -1;
int ret = 1;
DIR *dirstream1 = NULL;
+ int by_rootid = 0;
+ int by_uuid = 0;
+ u64 rootid_arg;
+ u8 uuid_arg[BTRFS_UUID_SIZE];
+
+ while (1) {
+ int c;
+ static const struct option long_options[] = {
+ { "rootid", required_argument, NULL, 'r'},
+ { "uuid", required_argument, NULL, 'u'},
+ { NULL, 0, NULL, 0 }
+ };
- clean_args_no_options(argc, argv, cmd_subvol_show_usage);
+ c = getopt_long(argc, argv, "r:u:", long_options, NULL);
+ if (c < 0)
+ break;
+
+ switch (c) {
+ case 'r':
+ rootid_arg = arg_strtou64(optarg);
+ by_rootid = 1;
+ break;
+ case 'u':
+ uuid_parse(optarg, uuid_arg);
+ by_uuid = 1;
+ break;
+ default:
+ usage(cmd_subvol_show_usage);
+ }
+ }
if (check_argc_exact(argc - optind, 1))
usage(cmd_subvol_show_usage);
+ if (by_rootid && by_uuid) {
+ error(
+ "options --rootid and --uuid cannot be used at the same time");
+ usage(cmd_subvol_show_usage);
+ }
+
memset(&get_ri, 0, sizeof(get_ri));
fullpath = realpath(argv[optind], NULL);
if (!fullpath) {
@@ -921,7 +960,14 @@ static int cmd_subvol_show(int argc, char **argv)
goto out;
}
- ret = get_subvol_info(fullpath, &get_ri);
+ if (by_rootid) {
+ ret = get_subvol_info_by_rootid(fullpath, &get_ri, rootid_arg);
+ } else if (by_uuid) {
+ ret = get_subvol_info_by_uuid(fullpath, &get_ri, uuid_arg);
+ } else {
+ ret = get_subvol_info(fullpath, &get_ri);
+ }
+
if (ret) {
if (ret < 0) {
error("Failed to get subvol info %s: %s",