From: Anand Jain <anand.jain@oracle.com> This set of patch will make btrfs su list -s <subvol> to list only snapshot(s) of the given subvol. before: btrfs su list -s /btrfs/sv1 <nothing> btrfs su list -s /btrfs ID 258 gen 6 cgen 6 top level 5 otime 2012-10-18 17:01:56 uuid f648cdda-4efa-6f45-bd6b-041a8ae1538e path ss1 ID 260 gen 8 cgen 8 top level 5 otime 2012-10-18 17:02:20 uuid ea8fdf85-8d3f-8946-b3af-ede510cdcf19 path ss2 ID 261 gen 9 cgen 9 top level 5 otime 2012-10-19 13:37:42 uuid 44560e56-3879-2146-8b24-e9048871892f path ss3 with this patch: btrfs su list -s /btrfs/sv1 ID 258 gen 6 cgen 6 top level 5 otime 2012-10-18 17:01:56 uuid f648cdda-4efa-6f45-bd6b-041a8ae1538e path ss1 ID 261 gen 9 cgen 9 top level 5 otime 2012-10-19 13:37:42 uuid 44560e56-3879-2146-8b24-e9048871892f path ss3 btrfs su list -s /btrfs ID 258 gen 6 cgen 6 top level 5 otime 2012-10-18 17:01:56 uuid f648cdda-4efa-6f45-bd6b-041a8ae1538e path ss1 ID 260 gen 8 cgen 8 top level 5 otime 2012-10-18 17:02:20 uuid ea8fdf85-8d3f-8946-b3af-ede510cdcf19 path ss2 ID 261 gen 9 cgen 9 top level 5 otime 2012-10-19 13:37:42 uuid 44560e56-3879-2146-8b24-e9048871892f path ss3 Anand Jain (4): Btrfs-progs: provide method to check if filter is set Btrfs-progs: fix irrelevant string in the subvol path Btrfs-progs: add method to filter snapshots by parent uuid Btrfs-progs: list only snapshots of the given subvol btrfs-list.c | 17 +++++++++++++++++ btrfs-list.h | 3 +++ cmds-subvolume.c | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand jain
2012-Oct-19 06:23 UTC
[PATCH 1/4] Btrfs-progs: provide method to check if filter is set
From: Anand Jain <anand.jain@oracle.com> Signed-off-by: Anand Jain <anand.jain@oracle.com> --- btrfs-list.c | 11 +++++++++++ btrfs-list.h | 2 ++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index 9cfdb35..462e049 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -1181,6 +1181,17 @@ void btrfs_list_free_filter_set(struct btrfs_list_filter_set *filter_set) free(filter_set); } +int btrfs_list_is_filter_set(struct btrfs_list_filter_set *fset, + enum btrfs_list_filter_enum filter) +{ + int i; + for (i=0; i < fset->nfilters; i++) { + if (fset->filters[i].filter_func == all_filter_funcs[filter]) + return i; + } + return -1; +} + int btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set, enum btrfs_list_filter_enum filter, u64 data) { diff --git a/btrfs-list.h b/btrfs-list.h index fc04f05..64d89e1 100644 --- a/btrfs-list.h +++ b/btrfs-list.h @@ -153,3 +153,5 @@ int btrfs_list_get_default_subvolume(int fd, u64 *default_id); char *btrfs_list_path_for_root(int fd, u64 root); u64 btrfs_list_get_path_rootid(int fd); int btrfs_get_a_subvol(int fd, struct root_info *the_ri); +int btrfs_list_is_filter_set(struct btrfs_list_filter_set *fset, + enum btrfs_list_filter_enum filter); -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand jain
2012-Oct-19 06:23 UTC
[PATCH 2/4] Btrfs-progs: fix irrelevant string in the subvol path
From: Anand Jain <anand.jain@oracle.com> btrfs su list -a /btrfs/sv1 ID 256 gen 6 top level 5 path <FS_TREE>/sv1 ID 258 gen 6 top level 5 path <FS_TREE>/ss1 Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-subvolume.c | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index a33c352..f8beecc 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -306,7 +306,7 @@ static int cmd_subvol_list(int argc, char **argv) u64 top_id; int ret; int c; - char *subvol; + char *subvol, *mnt = NULL; int is_tab_result = 0; int is_list_all = 0; struct option long_options[] = { @@ -398,9 +398,18 @@ static int cmd_subvol_list(int argc, char **argv) return 13; } - fd = open_file_or_dir(subvol); + ret = find_mount_root(subvol, &mnt); + if (ret < 0) { + fprintf(stderr, "ERROR: find_mount_root failed on %s: " + "%s\n", subvol, + strerror(-ret)); + return 12; + } + + fd = open_file_or_dir(mnt); if (fd < 0) { fprintf(stderr, "ERROR: can''t access ''%s''\n", subvol); + free(mnt); return 12; } @@ -412,6 +421,8 @@ static int cmd_subvol_list(int argc, char **argv) ret = btrfs_list_subvols(fd, filter_set, comparer_set, is_tab_result); + + free(mnt); if (ret) return 19; return 0; -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand jain
2012-Oct-19 06:23 UTC
[PATCH 3/4] Btrfs-progs: add method to filter snapshots by parent uuid
From: Anand Jain <anand.jain@oracle.com> Signed-off-by: Anand Jain <anand.jain@oracle.com> --- btrfs-list.c | 6 ++++++ btrfs-list.h | 1 + 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index 462e049..369500d 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -1144,6 +1144,11 @@ static int filter_topid_equal(struct root_info *ri, u64 data) return ri->top_id == data; } +static int filter_by_parent(struct root_info *ri, u64 data) +{ + return !uuid_compare(ri->puuid, (u8 *)data); +} + static btrfs_list_filter_func all_filter_funcs[] = { [BTRFS_LIST_FILTER_ROOTID] = filter_by_rootid, [BTRFS_LIST_FILTER_SNAPSHOT_ONLY] = filter_snapshot, @@ -1155,6 +1160,7 @@ static btrfs_list_filter_func all_filter_funcs[] = { [BTRFS_LIST_FILTER_CGEN_LESS] = filter_cgen_less, [BTRFS_LIST_FILTER_CGEN_EQUAL] = filter_cgen_equal, [BTRFS_LIST_FILTER_TOPID_EQUAL] = filter_topid_equal, + [BTRFS_LIST_FILTER_BY_PARENT] = filter_by_parent, }; struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void) diff --git a/btrfs-list.h b/btrfs-list.h index 64d89e1..a18a314 100644 --- a/btrfs-list.h +++ b/btrfs-list.h @@ -118,6 +118,7 @@ enum btrfs_list_filter_enum { BTRFS_LIST_FILTER_CGEN_LESS, BTRFS_LIST_FILTER_CGEN_MORE, BTRFS_LIST_FILTER_TOPID_EQUAL, + BTRFS_LIST_FILTER_BY_PARENT, BTRFS_LIST_FILTER_MAX, }; -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand jain
2012-Oct-19 06:23 UTC
[PATCH 4/4] Btrfs-progs: list only snapshots of the given subvol
From: Anand Jain <anand.jain@oracle.com> btrfs su list -s /btrfs ID 258 gen 6 cgen 6 top level 5 otime 2012-10-18 17:01:56 uuid f648cdda-4efa-6f45-bd6b-041a8ae1538e path ss1 ID 260 gen 8 cgen 8 top level 5 otime 2012-10-18 17:02:20 uuid ea8fdf85-8d3f-8946-b3af-ede510cdcf19 path ss2 ID 261 gen 9 cgen 9 top level 5 otime 2012-10-19 13:37:42 uuid 44560e56-3879-2146-8b24-e9048871892f path ss3 btrfs su list -s /btrfs/sv1 ID 258 gen 6 cgen 6 top level 5 otime 2012-10-18 17:01:56 uuid f648cdda-4efa-6f45-bd6b-041a8ae1538e path ss1 ID 261 gen 9 cgen 9 top level 5 otime 2012-10-19 13:37:42 uuid 44560e56-3879-2146-8b24-e9048871892f path ss3 btrfs su list -s /btrfs/sv2 ID 260 gen 8 cgen 8 top level 5 otime 2012-10-18 17:02:20 uuid ea8fdf85-8d3f-8946-b3af-ede510cdcf19 path ss2 Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-subvolume.c | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index f8beecc..c575720 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -307,6 +307,7 @@ static int cmd_subvol_list(int argc, char **argv) int ret; int c; char *subvol, *mnt = NULL; + struct root_info ri; int is_tab_result = 0; int is_list_all = 0; struct option long_options[] = { @@ -314,6 +315,7 @@ static int cmd_subvol_list(int argc, char **argv) {0, 0, 0, 0} }; + memset(&ri,''\0'',sizeof(ri)); filter_set = btrfs_list_alloc_filter_set(); comparer_set = btrfs_list_alloc_comparer_set(); @@ -419,10 +421,32 @@ static int cmd_subvol_list(int argc, char **argv) BTRFS_LIST_FILTER_TOPID_EQUAL, top_id); + if (strcmp(subvol, mnt) != 0) { + if (btrfs_list_is_filter_set(filter_set, BTRFS_LIST_FILTER_SNAPSHOT_ONLY) >= 0) { + ri.full_path = subvol+strlen(mnt)+1; + if (btrfs_get_a_subvol(fd, &ri)) { + fprintf(stderr, "ERROR: can''t find ''%s''\n", + ri.full_path); + close(fd); + free(mnt); + return 13; + } + btrfs_list_setup_filter(&filter_set, + BTRFS_LIST_FILTER_BY_PARENT, (u64)&ri.uuid); + } + } + ret = btrfs_list_subvols(fd, filter_set, comparer_set, is_tab_result); free(mnt); + if (ri.path) + free(ri.path); + if (ri.name) + free(ri.name); + if (ri.full_path) + free(ri.full_path); + if (ret) return 19; return 0; -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On fri, 19 Oct 2012 14:23:53 +0800, Anand jain wrote:> From: Anand Jain <anand.jain@oracle.com> > > This set of patch will make > btrfs su list -s <subvol> > to list only snapshot(s) of the given subvol. > > before: > btrfs su list -s /btrfs/sv1 > <nothing> > btrfs su list -s /btrfs > ID 258 gen 6 cgen 6 top level 5 otime 2012-10-18 17:01:56 uuid f648cdda-4efa-6f45-bd6b-041a8ae1538e path ss1 > ID 260 gen 8 cgen 8 top level 5 otime 2012-10-18 17:02:20 uuid ea8fdf85-8d3f-8946-b3af-ede510cdcf19 path ss2 > ID 261 gen 9 cgen 9 top level 5 otime 2012-10-19 13:37:42 uuid 44560e56-3879-2146-8b24-e9048871892f path ss3 > > with this patch: > btrfs su list -s /btrfs/sv1 > ID 258 gen 6 cgen 6 top level 5 otime 2012-10-18 17:01:56 uuid f648cdda-4efa-6f45-bd6b-041a8ae1538e path ss1 > ID 261 gen 9 cgen 9 top level 5 otime 2012-10-19 13:37:42 uuid 44560e56-3879-2146-8b24-e9048871892f path ss3Though the function implemented by your patch is very useful, you change the semantic of "-s", I think it is not allowed, or the programs that use "btrfs us list -s" may fail. I think it is better to add a new option. Thanks Miao> > btrfs su list -s /btrfs > ID 258 gen 6 cgen 6 top level 5 otime 2012-10-18 17:01:56 uuid f648cdda-4efa-6f45-bd6b-041a8ae1538e path ss1 > ID 260 gen 8 cgen 8 top level 5 otime 2012-10-18 17:02:20 uuid ea8fdf85-8d3f-8946-b3af-ede510cdcf19 path ss2 > ID 261 gen 9 cgen 9 top level 5 otime 2012-10-19 13:37:42 uuid 44560e56-3879-2146-8b24-e9048871892f path ss3 > > Anand Jain (4): > Btrfs-progs: provide method to check if filter is set > Btrfs-progs: fix irrelevant string in the subvol path > Btrfs-progs: add method to filter snapshots by parent uuid > Btrfs-progs: list only snapshots of the given subvol > > btrfs-list.c | 17 +++++++++++++++++ > btrfs-list.h | 3 +++ > cmds-subvolume.c | 39 +++++++++++++++++++++++++++++++++++++-- > 3 files changed, 57 insertions(+), 2 deletions(-) > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Rory Campbell-Lange
2012-Oct-19 08:37 UTC
Re: [PATCH 0/4] filter snapshot(s) by its parent uuid
On 19/10/12, Miao Xie (miaox@cn.fujitsu.com) wrote:> On fri, 19 Oct 2012 14:23:53 +0800, Anand jain wrote: > > From: Anand Jain <anand.jain@oracle.com> > > > > This set of patch will make > > btrfs su list -s <subvol> > > to list only snapshot(s) of the given subvol. > > > > before: > > btrfs su list -s /btrfs/sv1 > > <nothing>...> > with this patch: > > btrfs su list -s /btrfs/sv1 > > ID 258 gen 6 cgen 6 top level 5 otime 2012-10-18 17:01:56 uuid f648cdda-4efa-6f45-bd6b-041a8ae1538e path ss1 > > ID 261 gen 9 cgen 9 top level 5 otime 2012-10-19 13:37:42 uuid 44560e56-3879-2146-8b24-e9048871892f path ss3 > > Though the function implemented by your patch is very useful, you change the semantic of "-s", > I think it is not allowed, or the programs that use "btrfs us list -s" may fail.From my perspective as a user I would be grateful if the following changes in syntax for listing subvolumes could be considered: In addition to btrfs subvolume list [-apurts] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path> btrfs su list [-apurts] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path> List subvolumes (and snapshots) (and Anand''s patch to allow <path>/<subpath>) I believe the following shortcuts may be useful btrfs subvolumes [-apurts] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path>[</subpath>] btrfs sl [-apurts] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path>[</subpath>] Although from a technical perspective ''subvolume list'' may be logical, listing subvolumes (plural) seems like a different sort of operation to those relating to a subvolume (singular) for create/alter/show/delete/snapshot operations. -- Rory Campbell-Lange rory@campbell-lange.net -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Miao Xie
2012-Oct-19 08:59 UTC
Re: [PATCH 2/4] Btrfs-progs: fix irrelevant string in the subvol path
On fri, 19 Oct 2012 14:23:55 +0800, Anand jain wrote:> From: Anand Jain <anand.jain@oracle.com> > > btrfs su list -a /btrfs/sv1 > ID 256 gen 6 top level 5 path <FS_TREE>/sv1 > ID 258 gen 6 top level 5 path <FS_TREE>/ss1I don''t agree with this patch, because after applying this patch, the output of ''btrfs su list'' is the same as ''btrfs su list''. I hope ''btrfs su list'' just list the subvolumes in the specified path. In this way, the user can find the path of the subvolume easily (the specified path + the path in the result of ''btrfs su list''). Could you make it output the path which is relative to the path that the user specified? Thanks Miao> > Signed-off-by: Anand Jain <anand.jain@oracle.com> > --- > cmds-subvolume.c | 15 +++++++++++++-- > 1 files changed, 13 insertions(+), 2 deletions(-) > > diff --git a/cmds-subvolume.c b/cmds-subvolume.c > index a33c352..f8beecc 100644 > --- a/cmds-subvolume.c > +++ b/cmds-subvolume.c > @@ -306,7 +306,7 @@ static int cmd_subvol_list(int argc, char **argv) > u64 top_id; > int ret; > int c; > - char *subvol; > + char *subvol, *mnt = NULL; > int is_tab_result = 0; > int is_list_all = 0; > struct option long_options[] = { > @@ -398,9 +398,18 @@ static int cmd_subvol_list(int argc, char **argv) > return 13; > } > > - fd = open_file_or_dir(subvol); > + ret = find_mount_root(subvol, &mnt); > + if (ret < 0) { > + fprintf(stderr, "ERROR: find_mount_root failed on %s: " > + "%s\n", subvol, > + strerror(-ret)); > + return 12; > + } > + > + fd = open_file_or_dir(mnt); > if (fd < 0) { > fprintf(stderr, "ERROR: can''t access ''%s''\n", subvol); > + free(mnt); > return 12; > } > > @@ -412,6 +421,8 @@ static int cmd_subvol_list(int argc, char **argv) > > ret = btrfs_list_subvols(fd, filter_set, comparer_set, > is_tab_result); > + > + free(mnt); > if (ret) > return 19; > return 0; >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 10/19/2012 10:37 AM, Rory Campbell-Lange wrote:> From my perspective as a user I would be grateful if the following changes in > syntax for listing subvolumes could be considered: > > In addition to > > btrfs subvolume list [-apurts] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path> > btrfs su list [-apurts] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path> > List subvolumes (and snapshots) > (and Anand''s patch to allow <path>/<subpath>) > > I believe the following shortcuts may be useful > > btrfs subvolumes [-apurts] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path>[</subpath>] > btrfs sl [-apurts] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] <path>[</subpath>] > > Although from a technical perspective ''subvolume list'' may be logical, listing > subvolumes (plural) seems like a different sort of operation to those relating > to a subvolume (singular) for create/alter/show/delete/snapshot operations.+1 to this proposal (FWIW) - thanks for making the user interface more intuitive :) -- Lenz Grimmer <lenz@grimmer.com> - http://www.lenzg.net/