add show command to the subvol sub command
Subsystems (2)
v2 cover add show command to the subvol sub command
From: Anand Jain <[email protected]>
v1->v2: Rebased and merged with the newer patch (which are not yet in the git), and will now print few more parameters of the subvol.
Anand Jain (8):
Btrfs-progs: move open_file_or_dir() to utils.c
Btrfs-progs: Move printing outside of btrfs_list_subvols
Btrfs-progs: add parent uuid for snapshots
Btrfs-progs: move struct root_info to btrfs-list.h
Btrfs-progs: function to get root_info of a subvol
Btrfs-progs: provide method to check if filter is set
Btrfs-progs: add method to filter snapshots by parent uuid
Btrfs-progs: add show command to display detailed information about
the subvol
Makefile | 4 +- btrfs-list.c | 157 +++++++++++++++++++++++++++++++++--------------------- btrfs-list.h | 54 ++++++++++++++++++- btrfsctl.c | 7 ++- cmds-balance.c | 1 + cmds-inspect.c | 1 + cmds-qgroup.c | 1 + cmds-quota.c | 1 + cmds-subvolume.c | 133 ++++++++++++++++++++++++++++++++++++++++++++- commands.h | 3 - common.c | 46 ---------------- man/btrfs.8.in | 6 ++ utils.c | 30 ++++++++++- utils.h | 3 + 14 files changed, 326 insertions(+), 121 deletions(-) delete mode 100644 common.c
PATCH v2 1/8 Btrfs-progs: move open_file_or_dir() to utils.c
From: Anand Jain <[email protected]>
The definition of the function open_file_or_dir() is moved from common.c to utils.c in order to be able to share some common code between scrub and the device stats in the following step. That common code uses open_file_or_dir(). Since open_file_or_dir() makes use of the function dirfd(3), the required XOPEN version was raised from 6 to 7.
--- Makefile | 4 ++-- btrfsctl.c | 7 ++++--- cmds-balance.c | 1 + cmds-inspect.c | 1 + cmds-qgroup.c | 1 + cmds-quota.c | 1 + cmds-subvolume.c | 1 + commands.h | 3 --- common.c | 46 ---------------------------------------------- utils.c | 30 ++++++++++++++++++++++++++++-- utils.h | 3 +++ 11 files changed, 42 insertions(+), 56 deletions(-) delete mode 100644 common.c
Makefile +2 -2
@@ -41,8 +41,8 @@ all: version $(progs) manpages version: bash version.sh -btrfs: $(objects) btrfs.o help.o common.o $(cmds_objects) - $(CC) $(CFLAGS) -o btrfs btrfs.o help.o common.o $(cmds_objects) \ +btrfs: $(objects) btrfs.o help.o $(cmds_objects) + $(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \ $(objects) $(LDFLAGS) $(LIBS) -lpthread calc-size: $(objects) calc-size.o
btrfsctl.c +4 -3
@@ -63,7 +63,7 @@ static void print_usage(void)exit (1 ); } -static int open_file_or_dir (const char *fname) +static int btrfsctl_open_file_or_dir (const char *fname) {int ret;struct stat st;
@@ -91,6 +91,7 @@ static int open_file_or_dir(const char *fname) }return fd; } +int main (int ac,char **av) {char *fname =NULL ;
@@ -128,7 +129,7 @@ int main(int ac, char **av) snap_location =strdup (fullpath); snap_location =dirname (snap_location); - snap_fd =open_file_or_dir (snap_location); + snap_fd =btrfsctl_open_file_or_dir (snap_location); name =strdup (fullpath); name =basename (name);
@@ -238,7 +239,7 @@ int main(int ac, char **av) } name = fname; }else { - fd =open_file_or_dir (fname); + fd =btrfsctl_open_file_or_dir (fname); }if (name) {
cmds-balance.c +1 -0
@@ -28,6 +28,7 @@#include "volumes.h" #include "commands.h" +#include "utils.h" static const char *const balance_cmd_group_usage[] = {"btrfs [filesystem] balance <command> [options] <path>" ,
cmds-inspect.c +1 -0
@@ -22,6 +22,7 @@#include "kerncompat.h" #include "ioctl.h" +#include "utils.h" #include "commands.h" #include "btrfs-list.h"
cmds-qgroup.c +1 -0
@@ -24,6 +24,7 @@#include "ioctl.h" #include "commands.h" +#include "utils.h" static const char *const qgroup_cmd_group_usage[] = {"btrfs qgroup <command> [options] <path>" ,
cmds-quota.c +1 -0
@@ -23,6 +23,7 @@#include "ioctl.h" #include "commands.h" +#include "utils.h" static const char *const quota_cmd_group_usage[] = {"btrfs quota <command> [options] <path>" ,
cmds-subvolume.c +1 -0
@@ -32,6 +32,7 @@#include "ctree.h" #include "commands.h" #include "btrfs-list.h" +#include "utils.h" static const char *const subvolume_cmd_group_usage[] = {"btrfs subvolume <command> <args>" ,
commands.h +0 -3
@@ -79,9 +79,6 @@ void help_ambiguous_token(const char *arg, const struct cmd_group *grp);void help_command_group (const struct cmd_group *grp,int argc,char **argv); -/* common.c */ -int open_file_or_dir (const char *fname); -extern const struct cmd_group subvolume_cmd_group;extern const struct cmd_group filesystem_cmd_group;extern const struct cmd_group balance_cmd_group;
common.c deleted +0 -46
46 lines not on this page · raw message
utils.c +28 -2
@@ -16,8 +16,9 @@* Boston, MA 021110-1307, USA. */ -#define _XOPEN_SOURCE 600 -#define __USE_XOPEN2K +#define _XOPEN_SOURCE 700 +#define __USE_XOPEN2K8 +#define __XOPEN2K8/* due to an error in dirent.h, to get dirfd() */ #include <stdio.h> #include <stdlib.h> #ifndef __CHECKER__
@@ -1220,3 +1221,28 @@ scan_again:return 0 ; } +int open_file_or_dir (const char *fname) +{ +int ret; +struct stat st; +DIR *dirstream; +int fd; + + ret =stat (fname, &st); +if (ret <0 ) { +return -1 ; + } +if (S_ISDIR (st.st_mode)) { + dirstream =opendir (fname); +if (!dirstream) { +return -2 ; + } + fd =dirfd (dirstream); + }else { + fd =open (fname,O_RDWR ); + } +if (fd <0 ) { +return -3 ; + } +return fd; +}
utils.h +3 -0
@@ -19,6 +19,8 @@#ifndef __UTILS__#define __UTILS__ +#include "ctree.h" +#define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024) int make_btrfs(int fd, const char *device, const char *label,
@@ -46,4 +48,5 @@ int check_label(char *input);int get_mountpt (char *dev,char *mntpt,size_t size);int btrfs_scan_block_devices (int run_ioctl); +int open_file_or_dir (const char *fname);#endif
Signature · 1 line
1.7.1
PATCH v2 2/8 Btrfs-progs: Move printing outside of btrfs_list_subvols
In reply to Anand jainFrom: Anand Jain <[email protected]>
its better to have btrfs_list_subvols just return witout printing so that btrfs_list_subvols can be reused.
--- btrfs-list.c | 28 ++++++++++++++++++---------- btrfs-list.h | 2 +- cmds-subvolume.c | 4 ++-- 3 files changed, 21 insertions(+), 13 deletions(-)
btrfs-list.c +18 -10
@@ -1441,15 +1441,11 @@ static void print_all_volume_info(struct root_lookup *sorted_tree, } } -int btrfs_list_subvols (int fd,struct btrfs_list_filter_set *filter_set, -struct btrfs_list_comparer_set *comp_set, -int is_tab_result) +int btrfs_list_subvols (int fd,struct root_lookup *root_lookup) { -struct root_lookup root_lookup; -struct root_lookup root_sort;int ret; - ret =__list_subvol_search (fd, &root_lookup); + ret =__list_subvol_search (fd, root_lookup);if (ret) {fprintf (stderr,"ERROR: can't perform the search - %s\n" ,strerror (errno));
@@ -1460,16 +1456,28 @@ int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,* now we have an rbtree full of root_info objects, but we need to fill * in their path names within the subvol that is referencing each one. */ - ret =__list_subvol_fill_paths (fd, &root_lookup); -if (ret <0 ) -return ret; + ret =__list_subvol_fill_paths (fd, root_lookup); +return ret; +} +int btrfs_list_subvols_print (int fd,struct btrfs_list_filter_set *filter_set, +struct btrfs_list_comparer_set *comp_set, +int is_tab_result) +{ +struct root_lookup root_lookup; +struct root_lookup root_sort; +int ret; + + ret =btrfs_list_subvols (fd, &root_lookup); +if (ret) +return ret;__filter_and_sort_subvol (&root_lookup, &root_sort, filter_set, comp_set, fd);print_all_volume_info (&root_sort, is_tab_result);__free_all_subvolumn (&root_lookup); -return ret; + +return 0 ; } static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
btrfs-list.h +1 -1
@@ -98,7 +98,7 @@ int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,enum btrfs_list_comp_enum comparer, int is_descending); -int btrfs_list_subvols (int fd,struct btrfs_list_filter_set *filter_set, +int btrfs_list_subvols_print (int fd,struct btrfs_list_filter_set *filter_set,struct btrfs_list_comparer_set *comp_set,int is_tab_result);int btrfs_list_find_updated_files (int fd,u64 root_id,u64 oldest_gen);
cmds-subvolume.c +2 -2
@@ -406,7 +406,7 @@ static int cmd_subvol_list(int argc, char **argv)BTRFS_LIST_FILTER_TOPID_EQUAL , top_id); - ret =btrfs_list_subvols (fd, filter_set, comparer_set, + ret =btrfs_list_subvols_print (fd, filter_set, comparer_set, is_tab_result);if (ret)return 19 ;
@@ -613,7 +613,7 @@ static int cmd_subvol_get_default(int argc, char **argv)btrfs_list_setup_filter (&filter_set,BTRFS_LIST_FILTER_ROOTID , default_id); - ret =btrfs_list_subvols (fd, filter_set,NULL ,0 ); + ret =btrfs_list_subvols_print (fd, filter_set,NULL ,0 );if (ret)return 19 ;return 0 ;
Signature · 1 line
1.7.1
PATCH v2 3/8 Btrfs-progs: add parent uuid for snapshots
In reply to Anand jainFrom: Anand Jain <[email protected]>
--- btrfs-list.c | 32 +++++++++++++++++++++++++++----- btrfs-list.h | 1 + cmds-subvolume.c | 6 +++++- 3 files changed, 33 insertions(+), 6 deletions(-)
btrfs-list.c +27 -5
@@ -80,6 +80,7 @@ struct root_info {time_t otime;u8 uuid[BTRFS_UUID_SIZE ]; +u8 puuid[BTRFS_UUID_SIZE ];/* path from the subvol we live in to this root, including the * root's name. This is null until we do the extra lookup ioctl.
@@ -128,6 +129,11 @@ struct { .need_print = 0, }, { + .name = "parent UUID", + .column_name = "Parent UUID", + .need_print = 0, + }, + { .name = "uuid", .column_name = "UUID", .need_print = 0,
@@ -435,7 +441,7 @@ static struct root_info *root_tree_search(struct root_lookup *root_tree,static int update_root (struct root_lookup *root_lookup,u64 root_id,u64 ref_tree,u64 root_offset,u64 flags,u64 dir_id,char *name,int name_len,u64 ogen,u64 gen, -time_t ot,void *uuid) +time_t ot,void *uuid,void *puuid) {struct root_info *ri;
@@ -472,6 +478,8 @@ static int update_root(struct root_lookup *root_lookup, ri->otime = ot;if (uuid)memcpy (&ri->uuid, uuid,BTRFS_UUID_SIZE ); +if (puuid) +memcpy (&ri->puuid, puuid,BTRFS_UUID_SIZE );return 0 ; }
@@ -489,17 +497,18 @@ static int update_root(struct root_lookup *root_lookup,* gen: the current generation of the root * ot: the original time(create time) of the root * uuid: uuid of the root +* puuid: uuid of the root parent if any */ static int add_root (struct root_lookup *root_lookup,u64 root_id,u64 ref_tree,u64 root_offset,u64 flags,u64 dir_id,char *name,int name_len,u64 ogen,u64 gen, -time_t ot,void *uuid) +time_t ot,void *uuid,void *puuid) {struct root_info *ri;int ret; ret =update_root (root_lookup, root_id, ref_tree, root_offset, flags, - dir_id, name, name_len, ogen, gen, ot, uuid); + dir_id, name, name_len, ogen, gen, ot, uuid, puuid);if (!ret)return 0 ;
@@ -540,6 +549,9 @@ static int add_root(struct root_lookup *root_lookup,if (uuid)memcpy (&ri->uuid, uuid,BTRFS_UUID_SIZE ); +if (puuid) +memcpy (&ri->puuid, puuid,BTRFS_UUID_SIZE ); + ret =root_tree_insert (root_lookup, ri);if (ret) {printf ("failed to insert tree %llu\n" , (unsigned long long )root_id);
@@ -1022,6 +1034,7 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)int i;time_t t;u8 uuid[BTRFS_UUID_SIZE ]; +u8 puuid[BTRFS_UUID_SIZE ];root_lookup_init (root_lookup);memset (&args,0 ,sizeof (args));
@@ -1075,7 +1088,7 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)add_root (root_lookup, sh->objectid, sh->offset,0 ,0 , dir_id, name, name_len,0 ,0 ,0 , -NULL ); +NULL ,NULL ); }else if (sh->type ==BTRFS_ROOT_ITEM_KEY ) { ri = (struct btrfs_root_item *)(args.buf + off); gen =btrfs_root_generation (ri);
@@ -1085,15 +1098,17 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup) t = ri->otime.sec; ogen =btrfs_root_otransid (ri);memcpy (uuid, ri->uuid,BTRFS_UUID_SIZE ); +memcpy (puuid, ri->parent_uuid,BTRFS_UUID_SIZE ); }else { t =0 ; ogen =0 ;memset (uuid,0 ,BTRFS_UUID_SIZE ); +memset (puuid,0 ,BTRFS_UUID_SIZE ); }add_root (root_lookup, sh->objectid,0 , sh->offset, flags,0 ,NULL ,0 , ogen, - gen, t, uuid); + gen, t, uuid, puuid); } off += sh->len;
@@ -1347,6 +1362,13 @@ static void print_subvolume_column(struct root_info *subv,uuid_unparse (subv->uuid, uuidparse);printf ("%s" , uuidparse);break ; +case BTRFS_LIST_PUUID : +if (uuid_is_null (subv->puuid)) +strcpy (uuidparse,"-" ); +else +uuid_unparse (subv->puuid, uuidparse); +printf ("%s" , uuidparse); +break ;case BTRFS_LIST_PATH :BUG_ON (!subv->full_path);printf ("%s" , subv->full_path);
btrfs-list.h +1 -0
@@ -53,6 +53,7 @@ enum btrfs_list_column_enum {BTRFS_LIST_PARENT ,BTRFS_LIST_TOP_LEVEL ,BTRFS_LIST_OTIME , +BTRFS_LIST_PUUID ,BTRFS_LIST_UUID ,BTRFS_LIST_PATH , BTRFS_LIST_ALL,
cmds-subvolume.c +5 -1
@@ -280,6 +280,7 @@ static const char * const cmd_subvol_list_usage[] = {"-p print parent ID" ,"-a print all the subvolumes in the filesystem." ,"-u print the uuid of subvolumes (and snapshots)" , +"-q print the parent uuid of snapshots" ,"-t print the result as a table" ,"-s list snapshots only in the filesystem" , "-r list readonly subvolumes (including snapshots)",
@@ -319,7 +320,7 @@ static int cmd_subvol_list(int argc, char **argv) optind =1 ;while (1 ) { c =getopt_long (argc, argv, -"apsurg:c:t" , long_options,NULL ); +"apsuqrg:c:t" , long_options,NULL );if (c <0 )break ;
@@ -343,6 +344,9 @@ static int cmd_subvol_list(int argc, char **argv)case 'u' :btrfs_list_setup_print_column (BTRFS_LIST_UUID );break ; +case 'q' : +btrfs_list_setup_print_column (BTRFS_LIST_PUUID ); +break ;case 'r' : flags |=BTRFS_ROOT_SUBVOL_RDONLY ;break ;
Signature · 1 line
1.7.1
PATCH v2 4/8 Btrfs-progs: move struct root_info to btrfs-list.h
In reply to Anand jainFrom: Anand Jain <[email protected]>
--- btrfs-list.c | 47 ----------------------------------------------- btrfs-list.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 48 deletions(-)
btrfs-list.c +0 -47
@@ -46,53 +46,6 @@ struct root_lookup {struct rb_root root; }; -/* -* one of these for each root we find. -*/ -struct root_info { -struct rb_node rb_node; -struct rb_node sort_node; - -/* this root's id */ -u64 root_id; - -/* equal the offset of the root's key */ -u64 root_offset; - -/* flags of the root */ -u64 flags; - -/* the id of the root that references this one */ -u64 ref_tree; - -/* the dir id we're in from ref_tree */ -u64 dir_id; - -u64 top_id; - -/* generation when the root is created or last updated */ -u64 gen; - -/* creation generation of this root in sec*/ -u64 ogen; - -/* creation time of this root in sec*/ -time_t otime; - -u8 uuid[BTRFS_UUID_SIZE ]; -u8 puuid[BTRFS_UUID_SIZE ]; - -/* path from the subvol we live in to this root, including the -* root's name. This is null until we do the extra lookup ioctl. -*/ -char *path; - -/* the name of this root in the directory it lives in */ -char *name; - -char *full_path; -}; -struct {char *name;char *column_name;
btrfs-list.h +46 -1
53 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 5/8 Btrfs-progs: function to get root_info of a subvol
In reply to Anand jainFrom: Anand Jain <[email protected]>
--- btrfs-list.c | 37 +++++++++++++++++++++++++++++++++++++ btrfs-list.h | 1 + 2 files changed, 38 insertions(+), 0 deletions(-)
btrfs-list.c +37 -0
@@ -1455,6 +1455,43 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,return 0 ; } +int btrfs_get_subvol (int fd,struct root_info *the_ri) +{ +int ret =-1 ; +struct root_lookup rl; +struct rb_node *rbn; +struct root_info *ri; +u64 top_id =btrfs_list_get_path_rootid (fd); + +if (btrfs_list_subvols (fd, &rl)) +return 13 ; + + rbn =rb_first (&rl.root); +while (rbn) { + ri = rb_entry(rbn, struct root_info, rb_node); +resolve_root (&rl, ri, top_id); +if (!comp_entry_with_path (the_ri, ri,0 )) { +memcpy (the_ri, ri, offsetof(struct root_info , path)); +if (ri->path) + the_ri->path =strdup (ri->path); +else + the_ri->path =NULL ; +if (ri->name) + the_ri->name =strdup (ri->name); +else + the_ri->name =NULL ; +if (ri->full_path) + the_ri->full_path =strdup (ri->full_path); +else + the_ri->name =NULL ; + ret =0 ; + } + rbn =rb_next (rbn); + } +__free_all_subvolumn (&rl); +return ret; +} + static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh, struct btrfs_file_extent_item *item, u64 found_gen, u64 *cache_dirid,
btrfs-list.h +1 -0
@@ -151,3 +151,4 @@ int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);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_subvol (int fd,struct root_info *the_ri);
Signature · 1 line
1.7.1
PATCH v2 6/8 Btrfs-progs: provide method to check if filter is set
In reply to Anand jainFrom: Anand Jain <[email protected]>
--- btrfs-list.c | 11 +++++++++++ btrfs-list.h | 2 ++ 2 files changed, 13 insertions(+), 0 deletions(-)
btrfs-list.c +11 -0
@@ -1181,6 +1181,17 @@ void btrfs_list_free_filter_set(struct btrfs_list_filter_set *filter_set)free (filter_set); } +int btrfs_list_check_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) {
btrfs-list.h +2 -0
@@ -152,3 +152,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_subvol (int fd,struct root_info *the_ri); +int btrfs_list_check_filter_set (struct btrfs_list_filter_set *fset, +enum btrfs_list_filter_enum filter);
Signature · 1 line
1.7.1
PATCH v2 7/8 Btrfs-progs: add method to filter snapshots by parent uuid
In reply to Anand jainFrom: Anand Jain <[email protected]>
--- btrfs-list.c | 6 ++++++ btrfs-list.h | 1 + 2 files changed, 7 insertions(+), 0 deletions(-)
btrfs-list.c +6 -0
@@ -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 )
btrfs-list.h +1 -0
@@ -117,6 +117,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, };
Signature · 1 line
1.7.1
PATCH v2 8/8 Btrfs-progs: add show command to display detailed information about the subvol
In reply to Anand jainFrom: Anand Jain <[email protected]>
--- cmds-subvolume.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ man/btrfs.8.in | 6 +++ 2 files changed, 128 insertions(+), 0 deletions(-)
cmds-subvolume.c +122 -0
@@ -24,6 +24,7 @@#include <libgen.h> #include <limits.h> #include <getopt.h> +#include <uuid/uuid.h> #include "kerncompat.h" #include "ioctl.h"
@@ -704,6 +705,126 @@ static int cmd_find_new(int argc, char **argv)return 0 ; } +static const char *const cmd_subvol_show_usage[] = { +"btrfs subvolume show <subvol-path>" , +"Show more information of the subvolume" , +NULL +}; + +static int cmd_subvol_show (int argc,char **argv) +{ +int ret, fd; +char *subvol, *mnt =NULL ; +struct root_info get_ri; +char tstr[256 ]; +char uuidparse[37 ]; + +if (check_argc_exact (argc,2 )) +usage (cmd_subvol_show_usage); + + subvol =realpath (argv[1 ],0 ); +if (!subvol) { +fprintf (stderr,"ERROR: finding real path for '%s', %s\n" , + argv[1 ],strerror (errno)); +return 12 ; + } + + ret =test_issubvolume (subvol); +if (ret <0 ) { +fprintf (stderr,"ERROR: error accessing '%s'\n" , subvol); +free (subvol); +return 12 ; + } +if (!ret) { +fprintf (stderr,"ERROR: '%s' is not a subvolume\n" , subvol); +free (subvol); +return 13 ; + } + + ret =find_mount_root (subvol, &mnt); +if (ret <0 ) { +fprintf (stderr,"ERROR: find_mount_root failed on %s: " +"%s\n" , subvol,strerror (-ret)); +free (subvol); +return 12 ; + } +if (!strcmp (subvol, mnt)) +return 0 ; + +/* this will point to after the mnt/" */ + get_ri.full_path = subvol+strlen (mnt)+1 ; + +if (!strcmp (get_ri.full_path,"" )) +return 0 ; + + fd =open_file_or_dir (mnt); +if (fd <0 ) { +fprintf (stderr,"ERROR: can't access '%s'\n" , subvol); +return 12 ; + } + +if (btrfs_get_subvol (fd, &get_ri)) { +fprintf (stderr,"ERROR: can't find '%s'\n" , + get_ri.full_path); +close (fd); +return 13 ; + } + +/* print the info */ +printf ("%s/%s" , mnt, get_ri.full_path); +printf ("\n" ); + +if (uuid_is_null (get_ri.uuid)) +strcpy (uuidparse,"-" ); +else +uuid_unparse (get_ri.uuid, uuidparse); +printf ("\t" ); +printf ("uuid: \t\t\t%s" , uuidparse); +printf ("\n" ); + +if (get_ri.otime) +strftime (tstr,256 ,"%Y-%m-%d %X" , +localtime (&get_ri.otime)); +else +strcpy (tstr,"-" ); +printf ("\t" ); +printf ("Creation time: \t\t%s" , tstr); +printf ("\n" ); + +printf ("\t" ); +printf ("Object ID: \t\t%llu" , get_ri.root_id); +printf ("\n" ); + +printf ("\t" ); +printf ("Generation (Gen): \t%llu" , get_ri.gen); +printf ("\n" ); + +printf ("\t" ); +printf ("Gen at creation: \t%llu" , get_ri.ogen); +printf ("\n" ); + +printf ("\t" ); +printf ("Parent: \t\t%llu" , get_ri.ref_tree); +printf ("\n" ); + +printf ("\t" ); +printf ("Top Level: \t\t%llu" , get_ri.top_id); +printf ("\n" ); + +/* clean up */ +if (get_ri.path) +free (get_ri.path); +if (get_ri.name) +free (get_ri.name); +if (get_ri.full_path) +free (get_ri.full_path); + +close (fd); +free (mnt); +free (subvol); +return 0 ; +} +const struct cmd_group subvolume_cmd_group = { subvolume_cmd_group_usage,NULL , { {"create" , cmd_subvol_create, cmd_subvol_create_usage,NULL ,0 },
@@ -715,6 +836,7 @@ const struct cmd_group subvolume_cmd_group = { {"set-default" , cmd_subvol_set_default, cmd_subvol_set_default_usage, NULL, 0 }, { "find-new", cmd_find_new, cmd_find_new_usage, NULL, 0 }, + { "show", cmd_subvol_show, cmd_subvol_show_usage, NULL, 0 }, { 0, 0, 0, 0, 0 } } };
man/btrfs.8.in +6 -0
@@ -17,6 +17,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBsubvolume get-default\fP\fI <path>\fP .PP +\fBbtrfs\fP \fBsubvolume show\fP\fI <path>\fP +.PP \fBbtrfs\fP \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] \ [-s \fIstart\fR] [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> \ [<\fIfile\fR>|<\fIdir\fR>...]
@@ -160,6 +162,10 @@ Get the default subvolume of the filesystem \fI<path>\fR. The output format is similar to \fBsubvolume list\fR command. .TP +\fBsubvolume show\fR\fI <path>\fR +Show information of a given subvolume in the \fI<path>\fR. +.TP + \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] \ [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> [<\fIfile\fR>|<\fIdir\fR>...]
Signature · 1 line
1.7.1
v3 cover add show command to the subvol sub command
This is an attempt to make btrfs cli more end user friendly. And adds show subcommand to display all known (as of now) information of the given subvol including its snapshot(s).
The below patch:
"Btrfs-progs: accommodate different layout for printing subvol list"
obsoletes the previosuly submitted patch
"Btrfs-progs: make provision to print subvol list tree format"
Please provide your review comments. Thanks.
An example output:
First list out all the subvols/snapshots using the list subcommand.
btrfs su list /btrfs
ID 256 gen 10 top level 5 path sv1
ID 259 gen 6 top level 5 path sv1/snap
ID 260 gen 7 top level 5 path snap
ID 261 gen 8 top level 5 path sv2
ID 262 gen 9 top level 5 path sv1/snap2
ID 263 gen 10 top level 5 path sv1/snap3
Then use show subcommand to know all known information about the given subvol.
btrfs su show /btrfs/sv1
/btrfs/sv1
uuid: 508b12a5-ed2a-3942-af63-830967201070 Parent uuid: - Creation time: 2013-01-07 13:53:30 Object ID: 256 Generation (Gen): 10 Gen at creation: 5 Parent: 5 Top Level: 5 Snapshot(s): sv1/snap sv1/snap2 sv1/snap3
v2->v3: List snapshots of the given subvol if any.
Uses a more simple approach to obtain the snapshots.
Anand Jain (11):
Btrfs-progs: move open_file_or_dir() to utils.c
Btrfs-progs: Move printing outside of btrfs_list_subvols
Btrfs-progs: add parent uuid for snapshots
Btrfs-progs: move struct root_info to btrfs-list.h
Btrfs-progs: function to get root_info of a subvol
Btrfs-progs: provide method to check if filter is set
Btrfs-progs: add method to filter snapshots by parent uuid
Btrfs-progs: put find_mount_root() in commands.h
Btrfs-progs: maintain similar case in heading prefix
Btrfs-progs: accommodate different layout for printing subvol list
Btrfs-progs: add show to display all known parameters of the given
subvol
Makefile | 4 +- btrfs-list.c | 200 +++++++++++++++++++++++++++++++++++------------------- btrfs-list.h | 60 +++++++++++++++- btrfsctl.c | 7 +- cmds-balance.c | 1 + cmds-inspect.c | 1 + cmds-qgroup.c | 1 + cmds-quota.c | 1 + cmds-subvolume.c | 172 +++++++++++++++++++++++++++++++++++++++++++++- commands.h | 6 +- common.c | 46 ------------ man/btrfs.8.in | 6 ++ utils.c | 30 ++++++++- utils.h | 3 + 14 files changed, 405 insertions(+), 133 deletions(-) delete mode 100644 common.c
PATCH v3 1/11 Btrfs-progs: move open_file_or_dir() to utils.c
The definition of the function open_file_or_dir() is moved from common.c to utils.c in order to be able to share some common code between scrub and the device stats in the following step. That common code uses open_file_or_dir(). Since open_file_or_dir() makes use of the function dirfd(3), the required XOPEN version was raised from 6 to 7.
--- Makefile | 4 ++-- btrfsctl.c | 7 ++++--- cmds-balance.c | 1 + cmds-inspect.c | 1 + cmds-qgroup.c | 1 + cmds-quota.c | 1 + cmds-subvolume.c | 1 + commands.h | 3 --- common.c | 46 ---------------------------------------------- utils.c | 30 ++++++++++++++++++++++++++++-- utils.h | 3 +++ 11 files changed, 42 insertions(+), 56 deletions(-) delete mode 100644 common.c
Makefile +2 -2
@@ -41,8 +41,8 @@ all: version $(progs) manpages version: bash version.sh -btrfs: $(objects) btrfs.o help.o common.o $(cmds_objects) - $(CC) $(CFLAGS) -o btrfs btrfs.o help.o common.o $(cmds_objects) \ +btrfs: $(objects) btrfs.o help.o $(cmds_objects) + $(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \ $(objects) $(LDFLAGS) $(LIBS) -lpthread calc-size: $(objects) calc-size.o
btrfsctl.c +4 -3
@@ -63,7 +63,7 @@ static void print_usage(void)exit (1 ); } -static int open_file_or_dir (const char *fname) +static int btrfsctl_open_file_or_dir (const char *fname) {int ret;struct stat st;
@@ -91,6 +91,7 @@ static int open_file_or_dir(const char *fname) }return fd; } +int main (int ac,char **av) {char *fname =NULL ;
@@ -128,7 +129,7 @@ int main(int ac, char **av) snap_location =strdup (fullpath); snap_location =dirname (snap_location); - snap_fd =open_file_or_dir (snap_location); + snap_fd =btrfsctl_open_file_or_dir (snap_location); name =strdup (fullpath); name =basename (name);
@@ -238,7 +239,7 @@ int main(int ac, char **av) } name = fname; }else { - fd =open_file_or_dir (fname); + fd =btrfsctl_open_file_or_dir (fname); }if (name) {
cmds-balance.c +1 -0
@@ -28,6 +28,7 @@#include "volumes.h" #include "commands.h" +#include "utils.h" static const char *const balance_cmd_group_usage[] = {"btrfs [filesystem] balance <command> [options] <path>" ,
cmds-inspect.c +1 -0
@@ -22,6 +22,7 @@#include "kerncompat.h" #include "ioctl.h" +#include "utils.h" #include "commands.h" #include "btrfs-list.h"
cmds-qgroup.c +1 -0
@@ -24,6 +24,7 @@#include "ioctl.h" #include "commands.h" +#include "utils.h" static const char *const qgroup_cmd_group_usage[] = {"btrfs qgroup <command> [options] <path>" ,
cmds-quota.c +1 -0
@@ -23,6 +23,7 @@#include "ioctl.h" #include "commands.h" +#include "utils.h" static const char *const quota_cmd_group_usage[] = {"btrfs quota <command> [options] <path>" ,
cmds-subvolume.c +1 -0
@@ -32,6 +32,7 @@#include "ctree.h" #include "commands.h" #include "btrfs-list.h" +#include "utils.h" static const char *const subvolume_cmd_group_usage[] = {"btrfs subvolume <command> <args>" ,
commands.h +0 -3
@@ -79,9 +79,6 @@ void help_ambiguous_token(const char *arg, const struct cmd_group *grp);void help_command_group (const struct cmd_group *grp,int argc,char **argv); -/* common.c */ -int open_file_or_dir (const char *fname); -extern const struct cmd_group subvolume_cmd_group;extern const struct cmd_group filesystem_cmd_group;extern const struct cmd_group balance_cmd_group;
common.c deleted +0 -46
46 lines not on this page · raw message
utils.c +28 -2
@@ -16,8 +16,9 @@* Boston, MA 021110-1307, USA. */ -#define _XOPEN_SOURCE 600 -#define __USE_XOPEN2K +#define _XOPEN_SOURCE 700 +#define __USE_XOPEN2K8 +#define __XOPEN2K8/* due to an error in dirent.h, to get dirfd() */ #include <stdio.h> #include <stdlib.h> #ifndef __CHECKER__
@@ -1220,3 +1221,28 @@ scan_again:return 0 ; } +int open_file_or_dir (const char *fname) +{ +int ret; +struct stat st; +DIR *dirstream; +int fd; + + ret =stat (fname, &st); +if (ret <0 ) { +return -1 ; + } +if (S_ISDIR (st.st_mode)) { + dirstream =opendir (fname); +if (!dirstream) { +return -2 ; + } + fd =dirfd (dirstream); + }else { + fd =open (fname,O_RDWR ); + } +if (fd <0 ) { +return -3 ; + } +return fd; +}
utils.h +3 -0
@@ -19,6 +19,8 @@#ifndef __UTILS__#define __UTILS__ +#include "ctree.h" +#define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024) int make_btrfs(int fd, const char *device, const char *label,
@@ -46,4 +48,5 @@ int check_label(char *input);int get_mountpt (char *dev,char *mntpt,size_t size);int btrfs_scan_block_devices (int run_ioctl); +int open_file_or_dir (const char *fname);#endif
Signature · 1 line
1.7.1
PATCH v3 2/11 Btrfs-progs: Move printing outside of btrfs_list_subvols
In reply to Anand Jainits better to have btrfs_list_subvols just return witout printing so that btrfs_list_subvols can be reused.
--- btrfs-list.c | 28 ++++++++++++++++++---------- btrfs-list.h | 2 +- cmds-subvolume.c | 4 ++-- 3 files changed, 21 insertions(+), 13 deletions(-)
btrfs-list.c +18 -10
@@ -1441,15 +1441,11 @@ static void print_all_volume_info(struct root_lookup *sorted_tree, } } -int btrfs_list_subvols (int fd,struct btrfs_list_filter_set *filter_set, -struct btrfs_list_comparer_set *comp_set, -int is_tab_result) +int btrfs_list_subvols (int fd,struct root_lookup *root_lookup) { -struct root_lookup root_lookup; -struct root_lookup root_sort;int ret; - ret =__list_subvol_search (fd, &root_lookup); + ret =__list_subvol_search (fd, root_lookup);if (ret) {fprintf (stderr,"ERROR: can't perform the search - %s\n" ,strerror (errno));
@@ -1460,16 +1456,28 @@ int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,* now we have an rbtree full of root_info objects, but we need to fill * in their path names within the subvol that is referencing each one. */ - ret =__list_subvol_fill_paths (fd, &root_lookup); -if (ret <0 ) -return ret; + ret =__list_subvol_fill_paths (fd, root_lookup); +return ret; +} +int btrfs_list_subvols_print (int fd,struct btrfs_list_filter_set *filter_set, +struct btrfs_list_comparer_set *comp_set, +int is_tab_result) +{ +struct root_lookup root_lookup; +struct root_lookup root_sort; +int ret; + + ret =btrfs_list_subvols (fd, &root_lookup); +if (ret) +return ret;__filter_and_sort_subvol (&root_lookup, &root_sort, filter_set, comp_set, fd);print_all_volume_info (&root_sort, is_tab_result);__free_all_subvolumn (&root_lookup); -return ret; + +return 0 ; } static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
btrfs-list.h +1 -1
@@ -98,7 +98,7 @@ int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,enum btrfs_list_comp_enum comparer, int is_descending); -int btrfs_list_subvols (int fd,struct btrfs_list_filter_set *filter_set, +int btrfs_list_subvols_print (int fd,struct btrfs_list_filter_set *filter_set,struct btrfs_list_comparer_set *comp_set,int is_tab_result);int btrfs_list_find_updated_files (int fd,u64 root_id,u64 oldest_gen);
cmds-subvolume.c +2 -2
@@ -406,7 +406,7 @@ static int cmd_subvol_list(int argc, char **argv)BTRFS_LIST_FILTER_TOPID_EQUAL , top_id); - ret =btrfs_list_subvols (fd, filter_set, comparer_set, + ret =btrfs_list_subvols_print (fd, filter_set, comparer_set, is_tab_result);if (ret)return 19 ;
@@ -613,7 +613,7 @@ static int cmd_subvol_get_default(int argc, char **argv)btrfs_list_setup_filter (&filter_set,BTRFS_LIST_FILTER_ROOTID , default_id); - ret =btrfs_list_subvols (fd, filter_set,NULL ,0 ); + ret =btrfs_list_subvols_print (fd, filter_set,NULL ,0 );if (ret)return 19 ;return 0 ;
Signature · 1 line
1.7.1
PATCH v3 3/11 Btrfs-progs: add parent uuid for snapshots
In reply to Anand Jain--- btrfs-list.c | 32 +++++++++++++++++++++++++++----- btrfs-list.h | 1 + cmds-subvolume.c | 6 +++++- 3 files changed, 33 insertions(+), 6 deletions(-)
btrfs-list.c +27 -5
@@ -80,6 +80,7 @@ struct root_info {time_t otime;u8 uuid[BTRFS_UUID_SIZE ]; +u8 puuid[BTRFS_UUID_SIZE ];/* path from the subvol we live in to this root, including the * root's name. This is null until we do the extra lookup ioctl.
@@ -128,6 +129,11 @@ struct { .need_print = 0, }, { + .name = "parent UUID", + .column_name = "Parent UUID", + .need_print = 0, + }, + { .name = "uuid", .column_name = "UUID", .need_print = 0,
@@ -435,7 +441,7 @@ static struct root_info *root_tree_search(struct root_lookup *root_tree,static int update_root (struct root_lookup *root_lookup,u64 root_id,u64 ref_tree,u64 root_offset,u64 flags,u64 dir_id,char *name,int name_len,u64 ogen,u64 gen, -time_t ot,void *uuid) +time_t ot,void *uuid,void *puuid) {struct root_info *ri;
@@ -472,6 +478,8 @@ static int update_root(struct root_lookup *root_lookup, ri->otime = ot;if (uuid)memcpy (&ri->uuid, uuid,BTRFS_UUID_SIZE ); +if (puuid) +memcpy (&ri->puuid, puuid,BTRFS_UUID_SIZE );return 0 ; }
@@ -489,17 +497,18 @@ static int update_root(struct root_lookup *root_lookup,* gen: the current generation of the root * ot: the original time(create time) of the root * uuid: uuid of the root +* puuid: uuid of the root parent if any */ static int add_root (struct root_lookup *root_lookup,u64 root_id,u64 ref_tree,u64 root_offset,u64 flags,u64 dir_id,char *name,int name_len,u64 ogen,u64 gen, -time_t ot,void *uuid) +time_t ot,void *uuid,void *puuid) {struct root_info *ri;int ret; ret =update_root (root_lookup, root_id, ref_tree, root_offset, flags, - dir_id, name, name_len, ogen, gen, ot, uuid); + dir_id, name, name_len, ogen, gen, ot, uuid, puuid);if (!ret)return 0 ;
@@ -540,6 +549,9 @@ static int add_root(struct root_lookup *root_lookup,if (uuid)memcpy (&ri->uuid, uuid,BTRFS_UUID_SIZE ); +if (puuid) +memcpy (&ri->puuid, puuid,BTRFS_UUID_SIZE ); + ret =root_tree_insert (root_lookup, ri);if (ret) {printf ("failed to insert tree %llu\n" , (unsigned long long )root_id);
@@ -1022,6 +1034,7 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)int i;time_t t;u8 uuid[BTRFS_UUID_SIZE ]; +u8 puuid[BTRFS_UUID_SIZE ];root_lookup_init (root_lookup);memset (&args,0 ,sizeof (args));
@@ -1075,7 +1088,7 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)add_root (root_lookup, sh->objectid, sh->offset,0 ,0 , dir_id, name, name_len,0 ,0 ,0 , -NULL ); +NULL ,NULL ); }else if (sh->type ==BTRFS_ROOT_ITEM_KEY ) { ri = (struct btrfs_root_item *)(args.buf + off); gen =btrfs_root_generation (ri);
@@ -1085,15 +1098,17 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup) t = ri->otime.sec; ogen =btrfs_root_otransid (ri);memcpy (uuid, ri->uuid,BTRFS_UUID_SIZE ); +memcpy (puuid, ri->parent_uuid,BTRFS_UUID_SIZE ); }else { t =0 ; ogen =0 ;memset (uuid,0 ,BTRFS_UUID_SIZE ); +memset (puuid,0 ,BTRFS_UUID_SIZE ); }add_root (root_lookup, sh->objectid,0 , sh->offset, flags,0 ,NULL ,0 , ogen, - gen, t, uuid); + gen, t, uuid, puuid); } off += sh->len;
@@ -1347,6 +1362,13 @@ static void print_subvolume_column(struct root_info *subv,uuid_unparse (subv->uuid, uuidparse);printf ("%s" , uuidparse);break ; +case BTRFS_LIST_PUUID : +if (uuid_is_null (subv->puuid)) +strcpy (uuidparse,"-" ); +else +uuid_unparse (subv->puuid, uuidparse); +printf ("%s" , uuidparse); +break ;case BTRFS_LIST_PATH :BUG_ON (!subv->full_path);printf ("%s" , subv->full_path);
btrfs-list.h +1 -0
@@ -53,6 +53,7 @@ enum btrfs_list_column_enum {BTRFS_LIST_PARENT ,BTRFS_LIST_TOP_LEVEL ,BTRFS_LIST_OTIME , +BTRFS_LIST_PUUID ,BTRFS_LIST_UUID ,BTRFS_LIST_PATH , BTRFS_LIST_ALL,
cmds-subvolume.c +5 -1
@@ -280,6 +280,7 @@ static const char * const cmd_subvol_list_usage[] = {"-p print parent ID" ,"-a print all the subvolumes in the filesystem." ,"-u print the uuid of subvolumes (and snapshots)" , +"-q print the parent uuid of snapshots" ,"-t print the result as a table" ,"-s list snapshots only in the filesystem" , "-r list readonly subvolumes (including snapshots)",
@@ -319,7 +320,7 @@ static int cmd_subvol_list(int argc, char **argv) optind =1 ;while (1 ) { c =getopt_long (argc, argv, -"apsurg:c:t" , long_options,NULL ); +"apsuqrg:c:t" , long_options,NULL );if (c <0 )break ;
@@ -343,6 +344,9 @@ static int cmd_subvol_list(int argc, char **argv)case 'u' :btrfs_list_setup_print_column (BTRFS_LIST_UUID );break ; +case 'q' : +btrfs_list_setup_print_column (BTRFS_LIST_PUUID ); +break ;case 'r' : flags |=BTRFS_ROOT_SUBVOL_RDONLY ;break ;
Signature · 1 line
1.7.1
PATCH v3 4/11 Btrfs-progs: move struct root_info to btrfs-list.h
In reply to Anand Jain--- btrfs-list.c | 47 ----------------------------------------------- btrfs-list.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 48 deletions(-)
btrfs-list.c +0 -47
@@ -46,53 +46,6 @@ struct root_lookup {struct rb_root root; }; -/* -* one of these for each root we find. -*/ -struct root_info { -struct rb_node rb_node; -struct rb_node sort_node; - -/* this root's id */ -u64 root_id; - -/* equal the offset of the root's key */ -u64 root_offset; - -/* flags of the root */ -u64 flags; - -/* the id of the root that references this one */ -u64 ref_tree; - -/* the dir id we're in from ref_tree */ -u64 dir_id; - -u64 top_id; - -/* generation when the root is created or last updated */ -u64 gen; - -/* creation generation of this root in sec*/ -u64 ogen; - -/* creation time of this root in sec*/ -time_t otime; - -u8 uuid[BTRFS_UUID_SIZE ]; -u8 puuid[BTRFS_UUID_SIZE ]; - -/* path from the subvol we live in to this root, including the -* root's name. This is null until we do the extra lookup ioctl. -*/ -char *path; - -/* the name of this root in the directory it lives in */ -char *name; - -char *full_path; -}; -struct {char *name;char *column_name;
btrfs-list.h +46 -1
53 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v3 5/11 Btrfs-progs: function to get root_info of a subvol
In reply to Anand Jain--- btrfs-list.c | 37 +++++++++++++++++++++++++++++++++++++ btrfs-list.h | 1 + 2 files changed, 38 insertions(+), 0 deletions(-)
btrfs-list.c +37 -0
@@ -1455,6 +1455,43 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,return 0 ; } +int btrfs_get_subvol (int fd,struct root_info *the_ri) +{ +int ret =-1 ; +struct root_lookup rl; +struct rb_node *rbn; +struct root_info *ri; +u64 top_id =btrfs_list_get_path_rootid (fd); + +if (btrfs_list_subvols (fd, &rl)) +return 13 ; + + rbn =rb_first (&rl.root); +while (rbn) { + ri = rb_entry(rbn, struct root_info, rb_node); +resolve_root (&rl, ri, top_id); +if (!comp_entry_with_path (the_ri, ri,0 )) { +memcpy (the_ri, ri, offsetof(struct root_info , path)); +if (ri->path) + the_ri->path =strdup (ri->path); +else + the_ri->path =NULL ; +if (ri->name) + the_ri->name =strdup (ri->name); +else + the_ri->name =NULL ; +if (ri->full_path) + the_ri->full_path =strdup (ri->full_path); +else + the_ri->name =NULL ; + ret =0 ; + } + rbn =rb_next (rbn); + } +__free_all_subvolumn (&rl); +return ret; +} + static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh, struct btrfs_file_extent_item *item, u64 found_gen, u64 *cache_dirid,
btrfs-list.h +1 -0
@@ -151,3 +151,4 @@ int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);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_subvol (int fd,struct root_info *the_ri);
Signature · 1 line
1.7.1
PATCH v3 6/11 Btrfs-progs: provide method to check if filter is set
In reply to Anand Jain--- btrfs-list.c | 11 +++++++++++ btrfs-list.h | 2 ++ 2 files changed, 13 insertions(+), 0 deletions(-)
btrfs-list.c +11 -0
@@ -1181,6 +1181,17 @@ void btrfs_list_free_filter_set(struct btrfs_list_filter_set *filter_set)free (filter_set); } +int btrfs_list_check_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) {
btrfs-list.h +2 -0
@@ -152,3 +152,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_subvol (int fd,struct root_info *the_ri); +int btrfs_list_check_filter_set (struct btrfs_list_filter_set *fset, +enum btrfs_list_filter_enum filter);
Signature · 1 line
1.7.1
PATCH v3 7/11 Btrfs-progs: add method to filter snapshots by parent uuid
In reply to Anand Jain--- btrfs-list.c | 6 ++++++ btrfs-list.h | 1 + 2 files changed, 7 insertions(+), 0 deletions(-)
btrfs-list.c +6 -0
@@ -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 )
btrfs-list.h +1 -0
@@ -117,6 +117,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, };
Signature · 1 line
1.7.1
PATCH v3 8/11 Btrfs-progs: put find_mount_root() in commands.h
In reply to Anand Jain--- commands.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
commands.h +3 -0
@@ -103,3 +103,6 @@ int cmd_qgroup(int argc, char **argv);/* subvolume exported functions */ int test_issubvolume (char *path); + +/* send.c */ +int find_mount_root (const char *path,char **mount_root);
Signature · 1 line
1.7.1
PATCH v3 9/11 Btrfs-progs: maintain similar case in heading prefix
In reply to Anand JainA trivial fix
before this patch
btrfs su list -qu /btrfs
ID 256 gen 35 top level 5 parent UUID - uuid 60e54c4a-8136-3c43-a107-ea42052c6240 path sv1
ID 257 gen 35 top level 5 parent UUID 60e54c4a-8136-3c43-a107-ea42052c6240 uuid fdefa4a9-5b67-4f4c-8a11-c43acec51d43 path ss1
after this path
btrfs su list -qu /btrfs
ID 256 gen 35 top level 5 parent_uuid - uuid 60e54c4a-8136-3c43-a107-ea42052c6240 path sv1
ID 257 gen 35 top level 5 parent_uuid 60e54c4a-8136-3c43-a107-ea42052c6240 uuid fdefa4a9-5b67-4f4c-8a11-c43acec51d43 path ss1
--- btrfs-list.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
btrfs-list.c +1 -1
@@ -82,7 +82,7 @@ struct { .need_print = 0, }, { - .name = "parent UUID", + .name = "parent_uuid", .column_name = "Parent UUID", .need_print = 0, },
Signature · 1 line
1.7.1
PATCH v3 10/11 Btrfs-progs: accommodate different layout for printing subvol list
In reply to Anand JainCurrently we have name prefix (default) and table format to print the output of subvol list. Just these two formats does not cater to all the needs, for eg. the up coming show sub-command need a way to display all the known information of the given subvol. This patch will provide a way to extend the printing to other formats.
--- btrfs-list.c | 26 +++++++++++++++----------- btrfs-list.h | 3 +++ cmds-subvolume.c | 23 ++++++++++++++++++++--- 3 files changed, 38 insertions(+), 14 deletions(-)
btrfs-list.c +15 -11
@@ -54,12 +54,12 @@ struct { { .name = "ID", .column_name = "ID", - .need_print = 1, + .need_print = 0, }, { .name = "gen", .column_name = "Gen", - .need_print = 1, + .need_print = 0, }, { .name = "cgen",
@@ -74,7 +74,7 @@ struct { { .name = "top level", .column_name = "Top Level", - .need_print = 1, + .need_print = 0, }, { .name = "otime",
@@ -94,7 +94,7 @@ struct { { .name = "path", .column_name = "Path", - .need_print = 1, + .need_print = 0, }, { .name = NULL,
@@ -1414,21 +1414,25 @@ static void print_all_volume_info_tab_head() }static void print_all_volume_info (struct root_lookup *sorted_tree, -int is_tab_result) +int layout) {struct rb_node *n;struct root_info *entry; -if (is_tab_result) +if (layout ==BTRFS_LIST_LAYOUT_TABLE )print_all_volume_info_tab_head (); n =rb_first (&sorted_tree->root);while (n) { entry = rb_entry(n, struct root_info, sort_node); -if (is_tab_result) -print_single_volume_info_table (entry); -else +switch (layout) { +case BTRFS_LIST_LAYOUT_DEFAULT :print_single_volume_info_default (entry); +break ; +case BTRFS_LIST_LAYOUT_TABLE : +print_single_volume_info_table (entry); +break ; + } n =rb_next (n); } }
@@ -1454,7 +1458,7 @@ int btrfs_list_subvols(int fd, struct root_lookup *root_lookup)int btrfs_list_subvols_print (int fd,struct btrfs_list_filter_set *filter_set,struct btrfs_list_comparer_set *comp_set, -int is_tab_result) +int layout) {struct root_lookup root_lookup;struct root_lookup root_sort;
@@ -1466,7 +1470,7 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,__filter_and_sort_subvol (&root_lookup, &root_sort, filter_set, comp_set, fd); -print_all_volume_info (&root_sort, is_tab_result); +print_all_volume_info (&root_sort, layout);__free_all_subvolumn (&root_lookup);return 0 ;
btrfs-list.h +3 -0
@@ -18,6 +18,9 @@#include "kerncompat.h" +#define BTRFS_LIST_LAYOUT_DEFAULT 0 +#define BTRFS_LIST_LAYOUT_TABLE 1 +/* * one of these for each root we find. */
cmds-subvolume.c +20 -3
@@ -410,8 +410,18 @@ static int cmd_subvol_list(int argc, char **argv)BTRFS_LIST_FILTER_TOPID_EQUAL , top_id); - ret =btrfs_list_subvols_print (fd, filter_set, comparer_set, - is_tab_result); +/* by default we shall print the following columns*/ +btrfs_list_setup_print_column (BTRFS_LIST_OBJECTID ); +btrfs_list_setup_print_column (BTRFS_LIST_GENERATION ); +btrfs_list_setup_print_column (BTRFS_LIST_TOP_LEVEL ); +btrfs_list_setup_print_column (BTRFS_LIST_PATH ); + +if (is_tab_result) + ret =btrfs_list_subvols_print (fd, filter_set, comparer_set, +BTRFS_LIST_LAYOUT_TABLE ); +else + ret =btrfs_list_subvols_print (fd, filter_set, comparer_set, +BTRFS_LIST_LAYOUT_DEFAULT );if (ret)return 19 ;return 0 ;
@@ -617,7 +627,14 @@ static int cmd_subvol_get_default(int argc, char **argv)btrfs_list_setup_filter (&filter_set,BTRFS_LIST_FILTER_ROOTID , default_id); - ret =btrfs_list_subvols_print (fd, filter_set,NULL ,0 ); +/* by default we shall print the following columns*/ +btrfs_list_setup_print_column (BTRFS_LIST_OBJECTID ); +btrfs_list_setup_print_column (BTRFS_LIST_GENERATION ); +btrfs_list_setup_print_column (BTRFS_LIST_TOP_LEVEL ); +btrfs_list_setup_print_column (BTRFS_LIST_PATH ); + + ret =btrfs_list_subvols_print (fd, filter_set,NULL , +BTRFS_LIST_LAYOUT_DEFAULT );if (ret)return 19 ;return 0 ;
Signature · 1 line
1.7.1
PATCH v3 11/11 Btrfs-progs: add show to display all known parameters of the given subvol
In reply to Anand JainThis adds show sub-command to the btrfs subvol, which is to display all known parameters of the given subvol or snapshot. This command will also list out snapshots of the given subvol if there is any.
--- btrfs-list.c | 25 ++++++++- btrfs-list.h | 3 +- cmds-subvolume.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++- man/btrfs.8.in | 6 ++ 4 files changed, 175 insertions(+), 7 deletions(-)
btrfs-list.c +22 -3
@@ -1348,6 +1348,22 @@ static void print_subvolume_column(struct root_info *subv, } } +static void print_single_volume_info_raw (struct root_info *subv,char *raw_prefix) +{ +int i; + +for (i =0 ; i <BTRFS_LIST_ALL ; i++) { +if (!btrfs_list_columns[i].need_print) +continue ; + +if (raw_prefix); +printf ("%s" ,raw_prefix); + +print_subvolume_column (subv, i); + } +printf ("\n" ); +} +static void print_single_volume_info_table (struct root_info *subv) {int i;
@@ -1414,7 +1430,7 @@ static void print_all_volume_info_tab_head() }static void print_all_volume_info (struct root_lookup *sorted_tree, -int layout) +int layout,char *raw_prefix) {struct rb_node *n;struct root_info *entry;
@@ -1432,6 +1448,9 @@ static void print_all_volume_info(struct root_lookup *sorted_tree,case BTRFS_LIST_LAYOUT_TABLE :print_single_volume_info_table (entry);break ; +case BTRFS_LIST_LAYOUT_RAW : +print_single_volume_info_raw (entry, raw_prefix); +break ; } n =rb_next (n); }
@@ -1458,7 +1477,7 @@ int btrfs_list_subvols(int fd, struct root_lookup *root_lookup)int btrfs_list_subvols_print (int fd,struct btrfs_list_filter_set *filter_set,struct btrfs_list_comparer_set *comp_set, -int layout) +int layout,char *raw_prefix) {struct root_lookup root_lookup;struct root_lookup root_sort;
@@ -1470,7 +1489,7 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,__filter_and_sort_subvol (&root_lookup, &root_sort, filter_set, comp_set, fd); -print_all_volume_info (&root_sort, layout); +print_all_volume_info (&root_sort, layout, raw_prefix);__free_all_subvolumn (&root_lookup);return 0 ;
btrfs-list.h +2 -1
@@ -20,6 +20,7 @@#define BTRFS_LIST_LAYOUT_DEFAULT 0#define BTRFS_LIST_LAYOUT_TABLE 1 +#define BTRFS_LIST_LAYOUT_RAW 2/* * one of these for each root we find.
@@ -150,7 +151,7 @@ int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,int btrfs_list_subvols_print (int fd,struct btrfs_list_filter_set *filter_set,struct btrfs_list_comparer_set *comp_set, -int is_tab_result); +int layout,char *raw_prefix);int btrfs_list_find_updated_files (int fd,u64 root_id,u64 oldest_gen);int btrfs_list_get_default_subvolume (int fd,u64 *default_id);char *btrfs_list_path_for_root (int fd,u64 root);
cmds-subvolume.c +145 -3
180 lines not on this page · raw message
man/btrfs.8.in +6 -0
@@ -17,6 +17,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBsubvolume get-default\fP\fI <path>\fP .PP +\fBbtrfs\fP \fBsubvolume show\fP\fI <path>\fP +.PP \fBbtrfs\fP \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] \ [-s \fIstart\fR] [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> \ [<\fIfile\fR>|<\fIdir\fR>...]
@@ -160,6 +162,10 @@ Get the default subvolume of the filesystem \fI<path>\fR. The output format is similar to \fBsubvolume list\fR command. .TP +\fBsubvolume show\fR\fI <path>\fR +Show information of a given subvolume in the \fI<path>\fR. +.TP + \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] \ [-t \fIsize\fR] -[vf] <\fIfile\fR>|<\fIdir\fR> [<\fIfile\fR>|<\fIdir\fR>...]
Signature · 1 line
1.7.1
Any comments on this new sub-command, please. ?
Thanks, Anand
Quoted 81 lines · Anand Jain
This is an attempt to make btrfs cli more end user friendly. And adds show subcommand to display all known (as of now) information of the given subvol including its snapshot(s).
The below patch:
"Btrfs-progs: accommodate different layout for printing subvol list"
obsoletes the previosuly submitted patch
"Btrfs-progs: make provision to print subvol list tree format"Please provide your review comments. Thanks.
An example output:
First list out all the subvols/snapshots using the list subcommand.
btrfs su list /btrfs
ID 256 gen 10 top level 5 path sv1
ID 259 gen 6 top level 5 path sv1/snap
ID 260 gen 7 top level 5 path snap
ID 261 gen 8 top level 5 path sv2
ID 262 gen 9 top level 5 path sv1/snap2
ID 263 gen 10 top level 5 path sv1/snap3Then use show subcommand to know all known information about the given subvol.
btrfs su show /btrfs/sv1
/btrfs/sv1uuid: 508b12a5-ed2a-3942-af63-830967201070 Parent uuid: - Creation time: 2013-01-07 13:53:30 Object ID: 256 Generation (Gen): 10 Gen at creation: 5 Parent: 5 Top Level: 5 Snapshot(s): sv1/snap sv1/snap2 sv1/snap3
v2->v3: List snapshots of the given subvol if any.
Uses a more simple approach to obtain the snapshots.Anand Jain (11):
Btrfs-progs: moveopen_file_or_dir()toutils.c
Btrfs-progs: Move printing outside ofbtrfs_list_subvols
Btrfs-progs: add parent uuid for snapshots
Btrfs-progs: move structroot_infotobtrfs-list.h
Btrfs-progs: function to getroot_infoof a subvol
Btrfs-progs: provide method to check if filter is set
Btrfs-progs: add method to filter snapshots by parent uuid
Btrfs-progs: putfind_mount_root()incommands.h
Btrfs-progs: maintain similar case in heading prefix
Btrfs-progs: accommodate different layout for printing subvol list
Btrfs-progs: add show to display all known parameters of the given
subvolMakefile | 4 +- btrfs-list.c | 200 +++++++++++++++++++++++++++++++++++------------------- btrfs-list.h | 60 +++++++++++++++- btrfsctl.c | 7 +- cmds-balance.c | 1 + cmds-inspect.c | 1 + cmds-qgroup.c | 1 + cmds-quota.c | 1 + cmds-subvolume.c | 172 +++++++++++++++++++++++++++++++++++++++++++++- commands.h | 6 +- common.c | 46 ------------ man/btrfs.8.in | 6 ++ utils.c | 30 ++++++++- utils.h | 3 + 14 files changed, 405 insertions(+), 133 deletions(-)delete mode 100644
common.c--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Anand Jain
Any comments on this new sub-command, please. ?
Thanks, Anand
I am trying to use this new command. Very nice. However I tried to use it against the root of filesystem, without success:
The root of filesystem is under /var/btrfs; I used a subvolume as root:
$ cat /proc/self/mountinfo | grep sdc3 19 1 0:15 /__active / rw,noatime,nodiratime - btrfs /dev/sdc3 rw,space_cache 25 19 0:15 / /var/btrfs rw,noatime,nodiratime - btrfs /dev/sdc3 rw,space_cache
If I do:
$ #test 1 $ sudo ./btrfs su show /
I got nothing
If I do
$ #test 2 $ sudo ./btrfs su show /var/btrfs/
still, I got nothing
$ #test 3 $ sudo ./btrfs su show /var/btrfs/__active
I, finally, got:
/var/btrfs/__active
uuid: 835c96b8-c066-554b-9230-1c531e831ff6 Parent uuid: - Creation time: - Object ID: 256 Generation (Gen): 75774 Gen at creation: 0 Parent: 5 Top Level: 5 Snapshot(s):
I expected also from test1 and test2 something.
BR
G.Baroncelli
Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
Goffredo,
Thanks for the review.
Quoted 1 line
I expected also from test1 and test2 something.
actually it is working as intended. which is
to show more info of any item under btrfs su list output, and root itself won't be in the btrfs su list (unless -a option is used), otherwise any suggestion what is good to have for btrfs su show / ?
Anand
Quoted 58 lines · Goffredo Baroncelli
Quoted 6 lines · Anand Jain
Any comments on this new sub-command, please. ?
Thanks, Anand
I am trying to use this new command. Very nice. However I tried to use it against the root of filesystem, without success:
The root of filesystem is under
/var/btrfs; I used a subvolume as root:$ cat /proc/self/mountinfo | grep sdc3 19 1 0:15 /__active / rw,noatime,nodiratime - btrfs /dev/sdc3 rw,space_cache 25 19 0:15 / /var/btrfs rw,noatime,nodiratime - btrfs /dev/sdc3 rw,space_cacheIf I do:
$ #test 1 $ sudo ./btrfs su show /I got nothing
If I do
$ #test 2 $ sudo ./btrfs su show /var/btrfs/still, I got nothing
$ #test 3 $ sudo ./btrfs su show /var/btrfs/__activeI, finally, got:
/var/btrfs/__activeuuid: 835c96b8-c066-554b-9230-1c531e831ff6 Parent uuid: - Creation time: - Object ID: 256 Generation (Gen): 75774 Gen at creation: 0 Parent: 5 Top Level: 5 Snapshot(s):I expected also from test1 and test2 something.
BR
G.Baroncelli
Hi Anand
Quoted 5 lines · Anand Jain
Goffredo,
Thanks for the review.
Quoted 7 lines
Quoted 1 line
I expected also from test1 and test2 something.
actually it is working as intended. which is
to show more info of any item under btrfs su list output, and root itself won't be in the btrfs su list (unless -a option is used), otherwise any suggestion what is good to have for btrfs su show / ?
If I understood correctly, btrfs su show is capable to lists the subvolume snapshots. It could be useful to list the snapshot of the root subvolume.
Quoted 64 lines
Anand
Quoted 59 lines · Goffredo Baroncelli
Quoted 6 lines · Anand Jain
Any comments on this new sub-command, please. ?
Thanks, Anand
I am trying to use this new command. Very nice. However I tried to use it against the root of filesystem, without success:
The root of filesystem is under
/var/btrfs; I used a subvolume as root:$ cat /proc/self/mountinfo | grep sdc3 19 1 0:15 /__active / rw,noatime,nodiratime - btrfs /dev/sdc3 rw,space_cache 25 19 0:15 / /var/btrfs rw,noatime,nodiratime - btrfs /dev/sdc3 rw,space_cacheIf I do:
$ #test 1 $ sudo ./btrfs su show /I got nothing
If I do
$ #test 2 $ sudo ./btrfs su show /var/btrfs/still, I got nothing
$ #test 3 $ sudo ./btrfs su show /var/btrfs/__activeI, finally, got:
/var/btrfs/__active
uuid: 835c96b8-c066-554b-9230-1c531e831ff6
Parent uuid: -
Creation time: -
Object ID: 256
Generation (Gen): 75774
Gen at creation: 0
Parent: 5
Top Level: 5
Snapshot(s):I expected also from test1 and test2 something.
BR
G.Baroncelli
Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
Quoted 42 lines · Anand Jain
This is an attempt to make btrfs cli more end user friendly. And adds show subcommand to display all known (as of now) information of the given subvol including its snapshot(s).
The below patch:
"Btrfs-progs: accommodate different layout for printing subvol list"
obsoletes the previosuly submitted patch
"Btrfs-progs: make provision to print subvol list tree format"Please provide your review comments. Thanks.
An example output:
First list out all the subvols/snapshots using the list subcommand.
btrfs su list /btrfs
ID 256 gen 10 top level 5 path sv1
ID 259 gen 6 top level 5 path sv1/snap
ID 260 gen 7 top level 5 path snap
ID 261 gen 8 top level 5 path sv2
ID 262 gen 9 top level 5 path sv1/snap2
ID 263 gen 10 top level 5 path sv1/snap3Then use show subcommand to know all known information about the given subvol.
btrfs su show /btrfs/sv1
/btrfs/sv1uuid: 508b12a5-ed2a-3942-af63-830967201070 Parent uuid: - Creation time: 2013-01-07 13:53:30 Object ID: 256 Generation (Gen): 10 Gen at creation: 5 Parent: 5 Top Level: 5 Snapshot(s): sv1/snap sv1/snap2 sv1/snap3
Quoted 4 lines
v2->v3: List snapshots of the given subvol if any.
Uses a more simple approach to obtain the snapshots.
You have certainly been busy. However, your patches need to be rebased considering some of the patch-sets currently sent to the mailing list. If nothing else, I would appreciate it if you could rebase to David Sterba's set. And then there are the two patch-sets I submitted.
BTW, I do not claim anything except for the effort to scrapes these off the list to attempt getting btrfs-progs a bit more current with respect to bugfixes. I was going to include "su show" but your latest submission is a bit too much for now.
Gene
Gene,
I should do that in couple of days. Thanks.
Anand
Quoted 62 lines · Gene Czarcinski
Quoted 42 lines · Anand Jain
This is an attempt to make btrfs cli more end user friendly. And adds show subcommand to display all known (as of now) information of the given subvol including its snapshot(s).
The below patch:
"Btrfs-progs: accommodate different layout for printing subvol list"
obsoletes the previosuly submitted patch
"Btrfs-progs: make provision to print subvol list tree format"Please provide your review comments. Thanks.
An example output:
First list out all the subvols/snapshots using the list subcommand.
btrfs su list /btrfs
ID 256 gen 10 top level 5 path sv1
ID 259 gen 6 top level 5 path sv1/snap
ID 260 gen 7 top level 5 path snap
ID 261 gen 8 top level 5 path sv2
ID 262 gen 9 top level 5 path sv1/snap2
ID 263 gen 10 top level 5 path sv1/snap3Then use show subcommand to know all known information about the given subvol.
btrfs su show /btrfs/sv1
/btrfs/sv1
uuid: 508b12a5-ed2a-3942-af63-830967201070
Parent uuid: -
Creation time: 2013-01-07 13:53:30
Object ID: 256
Generation (Gen): 10
Gen at creation: 5
Parent: 5
Top Level: 5
Snapshot(s):
sv1/snap
sv1/snap2
sv1/snap3Quoted 4 lines
v2->v3: List snapshots of the given subvol if any.
Uses a more simple approach to obtain the snapshots.You have certainly been busy. However, your patches need to be rebased considering some of the patch-sets currently sent to the mailing list. If nothing else, I would appreciate it if you could rebase to David Sterba's set. And then there are the two patch-sets I submitted.
BTW, I do not claim anything except for the effort to scrapes these off the list to attempt getting btrfs-progs a bit more current with respect to bugfixes. I was going to include "su show" but your latest submission is a bit too much for now.
Gene
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
kindly note
The patch-set in this email-thread is now obsolete, since a newer patch-set[1] based on the git repo at
git://repo.or.cz/btrfs-progs-unstable/devel.git for-chris
has been submitted which IMO is easy and good for integration.
[1]
Subject: [PATCH 00/10] add show sub-command for btrfs subvol cli
Date: Wed, 23 Jan 2013 16:12:41 +0800
Thanks, Anand
Quoted 81 lines · Anand Jain
This is an attempt to make btrfs cli more end user friendly. And adds show subcommand to display all known (as of now) information of the given subvol including its snapshot(s).
The below patch:
"Btrfs-progs: accommodate different layout for printing subvol list"
obsoletes the previosuly submitted patch
"Btrfs-progs: make provision to print subvol list tree format"Please provide your review comments. Thanks.
An example output:
First list out all the subvols/snapshots using the list subcommand.
btrfs su list /btrfs
ID 256 gen 10 top level 5 path sv1
ID 259 gen 6 top level 5 path sv1/snap
ID 260 gen 7 top level 5 path snap
ID 261 gen 8 top level 5 path sv2
ID 262 gen 9 top level 5 path sv1/snap2
ID 263 gen 10 top level 5 path sv1/snap3Then use show subcommand to know all known information about the given subvol.
btrfs su show /btrfs/sv1
/btrfs/sv1uuid: 508b12a5-ed2a-3942-af63-830967201070 Parent uuid: - Creation time: 2013-01-07 13:53:30 Object ID: 256 Generation (Gen): 10 Gen at creation: 5 Parent: 5 Top Level: 5 Snapshot(s): sv1/snap sv1/snap2 sv1/snap3
v2->v3: List snapshots of the given subvol if any.
Uses a more simple approach to obtain the snapshots.Anand Jain (11):
Btrfs-progs: moveopen_file_or_dir()toutils.c
Btrfs-progs: Move printing outside ofbtrfs_list_subvols
Btrfs-progs: add parent uuid for snapshots
Btrfs-progs: move structroot_infotobtrfs-list.h
Btrfs-progs: function to getroot_infoof a subvol
Btrfs-progs: provide method to check if filter is set
Btrfs-progs: add method to filter snapshots by parent uuid
Btrfs-progs: putfind_mount_root()incommands.h
Btrfs-progs: maintain similar case in heading prefix
Btrfs-progs: accommodate different layout for printing subvol list
Btrfs-progs: add show to display all known parameters of the given
subvolMakefile | 4 +- btrfs-list.c | 200 +++++++++++++++++++++++++++++++++++------------------- btrfs-list.h | 60 +++++++++++++++- btrfsctl.c | 7 +- cmds-balance.c | 1 + cmds-inspect.c | 1 + cmds-qgroup.c | 1 + cmds-quota.c | 1 + cmds-subvolume.c | 172 +++++++++++++++++++++++++++++++++++++++++++++- commands.h | 6 +- common.c | 46 ------------ man/btrfs.8.in | 6 ++ utils.c | 30 ++++++++- utils.h | 3 + 14 files changed, 405 insertions(+), 133 deletions(-)delete mode 100644
common.c--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html