btrfs-progs: improve output of btrfs subvolume list command
Subsystems (2)
cover btrfs-progs: improve output of btrfs subvolume list command
Improvements to "subvolume list" command, with the goal to improve machine-readability. While the first three patches simply add new options (-A and --time-format), the last patch [PATCH 4/4] is more intrusive and changes the output format of the '-t' option. Consider it "my view of how tabular output of a linux command should look like" (see also comments on the commit).
Axel Burri (4):
btrfs-progs: add -A option for subvolume list (print all available
information)
btrfs-progs: add "flags" column for subvolume list (shows "readonly"
flag with -A)
btrfs-progs: add option "--time-format=short|iso|unix|locale" to
subvolume list
btrfs-progs: change -t option for subvolume list to print a simple
space-separated table (making it machine-readable)
Documentation/btrfs-subvolume.asciidoc | 5 ++ btrfs-list.c | 119 +++++++++++++++++++++++---------- btrfs-list.h | 2 + cmds-subvolume.c | 16 ++++- 4 files changed, 104 insertions(+), 38 deletions(-)
Signature · 1 line
2.4.9
PATCH 1/4 btrfs-progs: add -A option for subvolume list (print all available information)
--- Documentation/btrfs-subvolume.asciidoc | 2 ++ cmds-subvolume.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-)
Documentation/btrfs-subvolume.asciidoc +2 -0
@@ -114,6 +114,8 @@ print the UUID of the subvolume. print the parent uuid of subvolumes (and snapshots). -R:::: print the UUID of the sent subvolume, where the subvolume is the result of a receive operation +-A:::: +print all available subvolume information. -t:::: print the result as a table. -s::::
cmds-subvolume.c +5 -1
@@ -428,6 +428,7 @@ static const char * const cmd_subvol_list_usage[] = {"-u print the uuid of subvolumes (and snapshots)" ,"-q print the parent uuid of the snapshots" ,"-R print the uuid of the received snapshots" , +"-A print all available subvolume information" ,"-t print the result as a table" ,"-s list snapshots only in the filesystem" , "-r list readonly subvolumes (including snapshots)",
@@ -471,7 +472,7 @@ static int cmd_subvol_list(int argc, char **argv) }; c =getopt_long (argc, argv, -"acdgopqsurRG:C:t" , long_options,NULL ); +"acdgopqsurRAG:C:t" , long_options,NULL );if (c <0 )break ;
@@ -515,6 +516,9 @@ static int cmd_subvol_list(int argc, char **argv)case 'R' :btrfs_list_setup_print_column (BTRFS_LIST_RUUID );break ; +case 'A' : +btrfs_list_setup_print_column (BTRFS_LIST_ALL ); +break ;case 'r' : flags |=BTRFS_ROOT_SUBVOL_RDONLY ;break ;
Signature · 1 line
2.4.9
PATCH 2/4 btrfs-progs: add "flags" column for subvolume list (shows "readonly" flag with -A)
In reply to [email protected]--- btrfs-list.c | 14 ++++++++++++++ btrfs-list.h | 1 + 2 files changed, 15 insertions(+)
btrfs-list.c +14 -0
@@ -80,6 +80,11 @@ static struct { .need_print = 0, }, { + .name = "flags", + .column_name = "Flags", + .need_print = 0, + }, + { .name = "parent_uuid", .column_name = "Parent UUID", .need_print = 0,
@@ -1388,6 +1393,15 @@ static void print_subvolume_column(struct root_info *subv,uuid_unparse (subv->ruuid, uuidparse);printf ("%s" , uuidparse);break ; +case BTRFS_LIST_FLAGS : +if (subv->flags ==0 ) { +printf ("-" ); + }else { +/* comma-separated list of all available flags */ +if (subv->flags &BTRFS_ROOT_SUBVOL_RDONLY ) +printf ("readonly" ); + } +break ;case BTRFS_LIST_PATH :BUG_ON (!subv->full_path);printf ("%s" , subv->full_path);
btrfs-list.h +1 -0
@@ -119,6 +119,7 @@ enum btrfs_list_column_enum {BTRFS_LIST_PARENT ,BTRFS_LIST_TOP_LEVEL ,BTRFS_LIST_OTIME , +BTRFS_LIST_FLAGS ,BTRFS_LIST_PUUID ,BTRFS_LIST_RUUID , BTRFS_LIST_UUID,
Signature · 1 line
2.4.9
PATCH 3/4 btrfs-progs: add option "--time-format=short|iso|unix|locale" to subvolume list
In reply to [email protected]Affects time format of "otime". Supporting unix time and ISO8601 makes the output of "subvolume list" machine-readable.
Default is "short", keeping default output as it was before (I suggest changing the default to "iso", as with "short" is it not clear to the user if localtime or gmtime is printed, and it does not contain whitespace).
--- Documentation/btrfs-subvolume.asciidoc | 3 ++ btrfs-list.c | 65 +++++++++++++++++++++++++++++----- btrfs-list.h | 1 + cmds-subvolume.c | 10 ++++++ 4 files changed, 70 insertions(+), 9 deletions(-)
Documentation/btrfs-subvolume.asciidoc +3 -0
@@ -137,6 +137,9 @@ you can add \'\+' or \'-' in front of each items, \'+' means ascending, for --sort you can combine some items together by \',', just like -sort=+ogen,-gen,path,rootid. +--time-format=short|iso|unix|locale:::: +print times in format: short, ISO 8601, unix (seconds), or current locale. + *set-default* <id> <path>:: Set the subvolume of the filesystem <path> which is mounted as default.
btrfs-list.c +56 -9
92 lines not on this page · raw message
btrfs-list.h +1 -0
@@ -159,6 +159,7 @@ int btrfs_list_parse_sort_string(char *optarg,int btrfs_list_parse_filter_string (char *optarg,struct btrfs_list_filter_set **filters,enum btrfs_list_filter_enum type); +int btrfs_list_parse_time_format (const char *format);void btrfs_list_setup_print_column (enum btrfs_list_column_enum column);struct btrfs_list_filter_set *btrfs_list_alloc_filter_set (void );void btrfs_list_free_filter_set (struct btrfs_list_filter_set *filter_set);
cmds-subvolume.c +10 -0
@@ -443,6 +443,8 @@ static const char * const cmd_subvol_list_usage[] = {" list the subvolume in order of gen, ogen, rootid or path" ," you also can add '+' or '-' in front of each items." ," (+:ascending, -:descending, ascending default)" , +"--time-format=short|iso|unix|locale" , +" print timestamps in given format" , NULL, };
@@ -468,6 +470,7 @@ static int cmd_subvol_list(int argc, char **argv)int c;static const struct option long_options[] = { {"sort" , required_argument,NULL ,'S' }, + {"time-format" , required_argument,NULL ,'T' }, {NULL ,0 ,NULL ,0 } };
@@ -551,6 +554,13 @@ static int cmd_subvol_list(int argc, char **argv) goto out; }break ; +case 'T' : + ret =btrfs_list_parse_time_format (optarg); +if (ret) { + uerr =1 ; + goto out; + } +break ;default : uerr =1 ;
Signature · 1 line
2.4.9
PATCH 4/4 btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
In reply to [email protected]Old implementation used tabs "\t", and tried to work around problems by guessing amount of tabs needed (e.g. "\t\t" after top level", with buggy output as soon as empty uuids are printed). This will never work correctly, as tab width is a user-defined setting in the terminal.
Keep it simple and don't reimplement the wheel, for nice tabular output we have the "column" command from util-linux:
btrfs subvolume list -t <path> | column -t
--- btrfs-list.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-)
btrfs-list.c +12 -28
@@ -45,12 +45,12 @@ struct root_lookup { };static struct { -char *name; +char *name;/* machine-readable column identifier: [a-z_]+ */ char *column_name;int need_print; } btrfs_list_columns[] = { { - .name ="ID" , + .name ="id" , .column_name ="ID" , .need_print =0 , },
@@ -70,7 +70,7 @@ static struct { .need_print = 0, }, { - .name = "top level", + .name = "top_level", .column_name = "Top Level", .need_print = 0, },
@@ -1465,13 +1465,10 @@ static void print_single_volume_info_table(struct root_info *subv)if (!btrfs_list_columns[i].need_print)continue ; -print_subvolume_column (subv, i); - -if (i !=BTRFS_LIST_PATH ) -printf ("\t" ); +if (i !=0 ) +printf (" " ); -if (i ==BTRFS_LIST_TOP_LEVEL ) -printf ("\t" ); +print_subvolume_column (subv, i); }printf ("\n" ); }
@@ -1496,30 +1493,17 @@ static void print_single_volume_info_default(struct root_info *subv)static void print_all_volume_info_tab_head (void ) {int i; -int len; -char barrier[20 ]; - -for (i =0 ; i <BTRFS_LIST_ALL ; i++) { -if (btrfs_list_columns[i].need_print) -printf ("%s\t" , btrfs_list_columns[i].name); - -if (i ==BTRFS_LIST_ALL -1 ) -printf ("\n" ); - }for (i =0 ; i <BTRFS_LIST_ALL ; i++) { -memset (barrier,0 ,sizeof (barrier)); +if (!btrfs_list_columns[i].need_print) +continue ; -if (btrfs_list_columns[i].need_print) { - len =strlen (btrfs_list_columns[i].name); -while (len--) -strcat (barrier,"-" ); +if (i !=0 ) +printf (" " ); -printf ("%s\t" , barrier); - } -if (i ==BTRFS_LIST_ALL -1 ) -printf ("\n" ); +printf (btrfs_list_columns[i].name); } +printf ("\n" ); } static void print_all_volume_info(struct root_lookup *sorted_tree,
Signature · 1 line
2.4.9
Re: [PATCH 4/4] btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
Quoted 4 lines · On 2015-10-02 18:41, [email protected] wrote:
Old implementation used tabs "\t", and tried to work around problems by guessing amount of tabs needed (e.g. "\t\t" after top level", with buggy output as soon as empty uuids are printed). This will never work correctly, as tab width is a user-defined setting in the terminal.
Why not use string_table() and table_*() functions ?
Quoted 94 lines
Keep it simple and don't reimplement the wheel, for nice tabular output we have the "column" command from util-linux:
btrfs subvolume list -t <path> | column -t
Signed-off-by Axel Burri <[email protected]>--- btrfs-list.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-)btrfs-list.c +12
-28@@ -45,12 +45,12 @@ struct root_lookup { };static struct { -char *name; +char *name;/* machine-readable column identifier: [a-z_]+ */ char *column_name;int need_print; } btrfs_list_columns[] = { { - .name ="ID" , + .name ="id" , .column_name ="ID" , .need_print =0 , },@@ -70,7 +70,7 @@ static struct { .need_print = 0, }, { - .name = "top level", + .name = "top_level", .column_name = "Top Level", .need_print = 0, },@@ -1465,13 +1465,10 @@ static void print_single_volume_info_table(struct root_info *subv)if (!btrfs_list_columns[i].need_print)continue ; -print_subvolume_column (subv, i); - -if (i !=BTRFS_LIST_PATH ) -printf ("\t" ); +if (i !=0 ) +printf (" " ); -if (i ==BTRFS_LIST_TOP_LEVEL ) -printf ("\t" ); +print_subvolume_column (subv, i); }printf ("\n" ); }@@ -1496,30 +1493,17 @@ static void print_single_volume_info_default(struct root_info *subv)static void print_all_volume_info_tab_head (void ) {int i; -int len; -char barrier[20 ]; - -for (i =0 ; i <BTRFS_LIST_ALL ; i++) { -if (btrfs_list_columns[i].need_print) -printf ("%s\t" , btrfs_list_columns[i].name); - -if (i ==BTRFS_LIST_ALL -1 ) -printf ("\n" ); - }for (i =0 ; i <BTRFS_LIST_ALL ; i++) { -memset (barrier,0 ,sizeof (barrier)); +if (!btrfs_list_columns[i].need_print) +continue ; -if (btrfs_list_columns[i].need_print) { - len =strlen (btrfs_list_columns[i].name); -while (len--) -strcat (barrier,"-" ); +if (i !=0 ) +printf (" " ); -printf ("%s\t" , barrier); - } -if (i ==BTRFS_LIST_ALL -1 ) -printf ("\n" ); +printf (btrfs_list_columns[i].name); } +printf ("\n" ); } static void print_all_volume_info(struct root_lookup *sorted_tree,
Signature · 6 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5 -- gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
Re: [PATCH 4/4] btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
Quoted 8 lines · Goffredo Baroncelli
Quoted 4 lines · On 2015-10-02 18:41, [email protected] wrote:
Old implementation used tabs "\t", and tried to work around problems by guessing amount of tabs needed (e.g. "\t\t" after top level", with buggy output as soon as empty uuids are printed). This will never work correctly, as tab width is a user-defined setting in the terminal.
Why not use
string_table()and table_*() functions ?
Hem sorry, .... create_table() and table_*() functions (see string-table.h)
[...]
Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
Re: [PATCH 4/4] btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
In reply to Goffredo BaroncelliQuoted 8 lines · Goffredo Baroncelli
Quoted 4 lines · On 2015-10-02 18:41, [email protected] wrote:
Old implementation used tabs "\t", and tried to work around problems by guessing amount of tabs needed (e.g. "\t\t" after top level", with buggy output as soon as empty uuids are printed). This will never work correctly, as tab width is a user-defined setting in the terminal.
Why not use
string_table()and table_*() functions ?
string_table(), as well as all table functions by nature, needs to know the maximum size of all cells in a row before printing, and therefore buffers all the output before printing. It would eat up a lot of memory for large tables (it is not unusual to have 1000+ subvolumes in btrfs if you make heavy use of snapshotting). Furthermore, it would slow down things by not printing the output linewise.
Quoted 97 lines
Quoted 95 lines
Keep it simple and don't reimplement the wheel, for nice tabular output we have the "column" command from util-linux:
btrfs subvolume list -t <path> | column -t
Signed-off-by Axel Burri <[email protected]>--- btrfs-list.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-)btrfs-list.c +12
-28@@ -45,12 +45,12 @@ struct root_lookup { };static struct { -char *name; +char *name;/* machine-readable column identifier: [a-z_]+ */ char *column_name;int need_print; } btrfs_list_columns[] = { { - .name ="ID" , + .name ="id" , .column_name ="ID" , .need_print =0 , },@@ -70,7 +70,7 @@ static struct { .need_print = 0, }, { - .name = "top level", + .name = "top_level", .column_name = "Top Level", .need_print = 0, },@@ -1465,13 +1465,10 @@ static void print_single_volume_info_table(struct root_info *subv)if (!btrfs_list_columns[i].need_print)continue ; -print_subvolume_column (subv, i); - -if (i !=BTRFS_LIST_PATH ) -printf ("\t" ); +if (i !=0 ) +printf (" " ); -if (i ==BTRFS_LIST_TOP_LEVEL ) -printf ("\t" ); +print_subvolume_column (subv, i); }printf ("\n" ); }@@ -1496,30 +1493,17 @@ static void print_single_volume_info_default(struct root_info *subv)static void print_all_volume_info_tab_head (void ) {int i; -int len; -char barrier[20 ]; - -for (i =0 ; i <BTRFS_LIST_ALL ; i++) { -if (btrfs_list_columns[i].need_print) -printf ("%s\t" , btrfs_list_columns[i].name); - -if (i ==BTRFS_LIST_ALL -1 ) -printf ("\n" ); - }for (i =0 ; i <BTRFS_LIST_ALL ; i++) { -memset (barrier,0 ,sizeof (barrier)); +if (!btrfs_list_columns[i].need_print) +continue ; -if (btrfs_list_columns[i].need_print) { - len =strlen (btrfs_list_columns[i].name); -while (len--) -strcat (barrier,"-" ); +if (i !=0 ) +printf (" " ); -printf ("%s\t" , barrier); - } -if (i ==BTRFS_LIST_ALL -1 ) -printf ("\n" ); +printf (btrfs_list_columns[i].name); } +printf ("\n" ); } static void print_all_volume_info(struct root_lookup *sorted_tree,
Re: [PATCH 4/4] btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
In reply to a message not in the archiveQuoted 10 lines · Axel Burri
Quoted 7 lines · Goffredo Baroncelli
Quoted 4 lines · On 2015-10-02 18:41, [email protected] wrote:
Old implementation used tabs "\t", and tried to work around problems by guessing amount of tabs needed (e.g. "\t\t" after top level", with buggy output as soon as empty uuids are printed). This will never work correctly, as tab width is a user-defined setting in the terminal.
Quoted 8 lines
Quoted 1 line
Why not use
string_table()and table_*() functions ?
string_table(), as well as all table functions by nature, needs to know the maximum size of all cells in a row before printing, and therefore buffers all the output before printing. It would eat up a lot of memory for large tables (it is not unusual to have 1000+ subvolumes in btrfs if you make heavy use of snapshotting). Furthermore, it would slow down things by not printing the output linewise.
Assuming 200bytes per row (== subvolume) x 1000 subvolumes = 200kB... I don't think that this could be a problem, nor in terms of memory used nor in terms of speed: if you have 1000+ subvolumes the most time consuming activity is traversing the filesystem looking at the snapshot...
Quoted 99 lines
Quoted 98 lines
Quoted 96 lines
Keep it simple and don't reimplement the wheel, for nice tabular output we have the "column" command from util-linux:
btrfs subvolume list -t <path> | column -t
Signed-off-by Axel Burri <[email protected]>--- btrfs-list.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-)btrfs-list.c +12
-28@@ -45,12 +45,12 @@ struct root_lookup { };static struct { -char *name; +char *name;/* machine-readable column identifier: [a-z_]+ */ char *column_name;int need_print; } btrfs_list_columns[] = { { - .name ="ID" , + .name ="id" , .column_name ="ID" , .need_print =0 , },@@ -70,7 +70,7 @@ static struct { .need_print = 0, }, { - .name = "top level", + .name = "top_level", .column_name = "Top Level", .need_print = 0, },@@ -1465,13 +1465,10 @@ static void print_single_volume_info_table(struct root_info *subv)if (!btrfs_list_columns[i].need_print)continue ; -print_subvolume_column (subv, i); - -if (i !=BTRFS_LIST_PATH ) -printf ("\t" ); +if (i !=0 ) +printf (" " ); -if (i ==BTRFS_LIST_TOP_LEVEL ) -printf ("\t" ); +print_subvolume_column (subv, i); }printf ("\n" ); }@@ -1496,30 +1493,17 @@ static void print_single_volume_info_default(struct root_info *subv)static void print_all_volume_info_tab_head (void ) {int i; -int len; -char barrier[20 ]; - -for (i =0 ; i <BTRFS_LIST_ALL ; i++) { -if (btrfs_list_columns[i].need_print) -printf ("%s\t" , btrfs_list_columns[i].name); - -if (i ==BTRFS_LIST_ALL -1 ) -printf ("\n" ); - }for (i =0 ; i <BTRFS_LIST_ALL ; i++) { -memset (barrier,0 ,sizeof (barrier)); +if (!btrfs_list_columns[i].need_print) +continue ; -if (btrfs_list_columns[i].need_print) { - len =strlen (btrfs_list_columns[i].name); -while (len--) -strcat (barrier,"-" ); +if (i !=0 ) +printf (" " ); -printf ("%s\t" , barrier); - } -if (i ==BTRFS_LIST_ALL -1 ) -printf ("\n" ); +printf (btrfs_list_columns[i].name); } +printf ("\n" ); } static void print_all_volume_info(struct root_lookup *sorted_tree,
Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
Re: [PATCH 4/4] btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
Goffredo Baroncelli posted on Sat, 03 Oct 2015 19:41:33 +0200 as excerpted:
Quoted 22 lines · Axel Burri
Quoted 11 lines · Goffredo Baroncelli
Quoted 8 lines · On 2015-10-02 18:41, [email protected] wrote:
Quoted 5 lines
Old implementation used tabs "\t", and tried to work around problems by guessing amount of tabs needed (e.g. "\t\t" after top level", with buggy output as soon as empty uuids are printed). This will never work correctly, as tab width is a user-defined setting in the terminal.
Quoted 8 lines
Quoted 1 line
Why not use
string_table()and table_*() functions ?
string_table(), as well as all table functions by nature, needs to know the maximum size of all cells in a row before printing, and therefore buffers all the output before printing. It would eat up a lot of memory for large tables (it is not unusual to have 1000+ subvolumes in btrfs if you make heavy use of snapshotting). Furthermore, it would slow down things by not printing the output linewise.
Quoted 5 lines
Assuming 200bytes per row (== subvolume) x 1000 subvolumes = 200kB... I don't think that this could be a problem, nor in terms of memory used nor in terms of speed: if you have 1000+ subvolumes the most time consuming activity is traversing the filesystem looking at the snapshot...
Perhaps unfortunately, scaling to millions of snapshots/subvolumes really *is* expected by some people. You'd be surprised at the number of folks that setup automated per-minute snapshotting with no automated thinning, and expect to be able to keep several years' worth of snapshots, and then wonder why btrfs maintenance commands such as balance take weeks/months...
5 years * 365 days/year * 24 hours/day * 60 minutes/hour * 1 snapshot/ minute = ...
(years, days, hours, minutes cancel out, leaving snapshots... yeah, the math should be right)
2.6 million plus snapshots. And that's just one subvolume. Multiply that by a half dozen subvolumes...
Over 15 million snapshots. Multiply that by 200 bytes/snapshot...
Several gigs of buffer memory, now.
Obviously btrfs doesn't scale to that level now, and if it did, someone making the mistake of trying to get a listing of millions of snapshots would very likely change their mind before even hitting 10%...
But that's why actually processing line-by-line is important, so they'll actually /see/ what happened and ctrl-C it, instead of the program aborting as it runs into (for example) the 32-bit user/kernel memory barrier, without printing anything useful...
The line-by-line way... "Oops, that's waayyy too many snapshots to be practical, maybe I should start thinning..."
The buffer-it-all-way... "Oops, there's a bug in the program; it crashed."
Signature · 3 lines
Duncan - List replies preferred. No HTML msgs. "Every nonfree program has a lord, a master -- and if you use the program, he is your master." Richard Stallman
Re: [PATCH 4/4] btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
Quoted 36 lines · Duncan
Goffredo Baroncelli posted on Sat, 03 Oct 2015 19:41:33 +0200 as excerpted:
Quoted 22 lines · Axel Burri
Quoted 11 lines · Goffredo Baroncelli
Quoted 8 lines · On 2015-10-02 18:41, [email protected] wrote:
Quoted 5 lines
Old implementation used tabs "\t", and tried to work around problems by guessing amount of tabs needed (e.g. "\t\t" after top level", with buggy output as soon as empty uuids are printed). This will never work correctly, as tab width is a user-defined setting in the terminal.
Quoted 8 lines
Quoted 1 line
Why not use
string_table()and table_*() functions ?
string_table(), as well as all table functions by nature, needs to know the maximum size of all cells in a row before printing, and therefore buffers all the output before printing. It would eat up a lot of memory for large tables (it is not unusual to have 1000+ subvolumes in btrfs if you make heavy use of snapshotting). Furthermore, it would slow down things by not printing the output linewise.Quoted 5 lines
Assuming 200bytes per row (== subvolume) x 1000 subvolumes = 200kB... I don't think that this could be a problem, nor in terms of memory used nor in terms of speed: if you have 1000+ subvolumes the most time consuming activity is traversing the filesystem looking at the snapshot...
Perhaps unfortunately, scaling to millions of snapshots/subvolumes really *is* expected by some people. You'd be surprised at the number of folks that setup automated per-minute snapshotting with no automated thinning, and expect to be able to keep several years' worth of snapshots, and then wonder why btrfs maintenance commands such as balance take weeks/months...
[...]
Quoted 8 lines
Obviously btrfs doesn't scale to that level now, and if it did, someone making the mistake of trying to get a listing of millions of snapshots would very likely change their mind before even hitting 10%...
But that's why actually processing line-by-line is important, so they'll actually /see/ what happened and ctrl-C it, instead of the program aborting as it runs into (for example) the 32-bit user/kernel memory barrier, without printing anything useful...
Please Ducan, read the code.
*TODAY* "btrfs list" does a scan of all subvolumes storing information in memory !
This is the most time consuming activity (think traversing a filesystem with millions of snapshots)
*Then* "btrfs list" print the info.
So you are already blocked at the screen until all subvolume are read. And I repeat (re)processing the information requires less time than reading the information from the disk.
[....]
Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
Re: [PATCH 4/4] btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
Quoted 51 lines · Goffredo Baroncelli
Quoted 36 lines · Duncan
Goffredo Baroncelli posted on Sat, 03 Oct 2015 19:41:33 +0200 as excerpted:
Quoted 22 lines · Axel Burri
Quoted 11 lines · Goffredo Baroncelli
Quoted 8 lines · On 2015-10-02 18:41, [email protected] wrote:
Quoted 5 lines
Old implementation used tabs "\t", and tried to work around problems by guessing amount of tabs needed (e.g. "\t\t" after top level", with buggy output as soon as empty uuids are printed). This will never work correctly, as tab width is a user-defined setting in the terminal.
Quoted 8 lines
Quoted 1 line
Why not use
string_table()and table_*() functions ?
string_table(), as well as all table functions by nature, needs to know the maximum size of all cells in a row before printing, and therefore buffers all the output before printing. It would eat up a lot of memory for large tables (it is not unusual to have 1000+ subvolumes in btrfs if you make heavy use of snapshotting). Furthermore, it would slow down things by not printing the output linewise.Quoted 5 lines
Assuming 200bytes per row (== subvolume) x 1000 subvolumes = 200kB... I don't think that this could be a problem, nor in terms of memory used nor in terms of speed: if you have 1000+ subvolumes the most time consuming activity is traversing the filesystem looking at the snapshot...
Perhaps unfortunately, scaling to millions of snapshots/subvolumes really *is* expected by some people. You'd be surprised at the number of folks that setup automated per-minute snapshotting with no automated thinning, and expect to be able to keep several years' worth of snapshots, and then wonder why btrfs maintenance commands such as balance take weeks/months...
[...]
Quoted 8 lines
Obviously btrfs doesn't scale to that level now, and if it did, someone making the mistake of trying to get a listing of millions of snapshots would very likely change their mind before even hitting 10%...
But that's why actually processing line-by-line is important, so they'll actually /see/ what happened and ctrl-C it, instead of the program aborting as it runs into (for example) the 32-bit user/kernel memory barrier, without printing anything useful...
Please Ducan, read the code.
*TODAY* "btrfs list" does a scan of all subvolumes storing information in memory !
Quoted 8 lines
This is the most time consuming activity (think traversing a filesystem with millions of snapshots)
*Then* "btrfs list" print the info.
So you are already blocked at the screen until all subvolume are read. And I repeat (re)processing the information requires less time than reading the information from the disk.
[....]
A quick look at the code shows me that Goffredo is right here, as __list_subvol_search() always fetches ALL data from BTRFS_IOC_TREE_SEARCH, putting it into a rbtree for later processing (assemble full paths, sorting).
While there is certainly room for improvements here (assuming that BTRFS_IOC_TREE_SEARCH returns objectid's in sorted order, it would definitively be possible to produce line-by-line output), the code looks pretty elegant the way it is.
I still don't think it is wise to bloat things further just for printing nice tables. My impression is that "btrfs subvolume list" is human-readable enough without the '-t' flag, while the output with '-t' flag is much more machine-readable-friendly, and thus should have the highest possible performance. e.g.:
btrfs sub list -t / | (read th; while read $th ; do echo $gen; done) btrfs sub list -t | column -t
Again, this is just my opinion, being a "unix-purist". Maybe a good compromise would be to use a single "\t" instead of " " as column delimiter.
Re: [PATCH 4/4] btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
In reply to a message not in the archiveHi Axel,
On 2015-10-05 17:04, Axel Burri wrote:
[...]
Quoted 11 lines
A quick look at the code shows me that Goffredo is right here, as
__list_subvol_search()always fetches ALL data fromBTRFS_IOC_TREE_SEARCH, putting it into a rbtree for later processing (assemble full paths, sorting).While there is certainly room for improvements here (assuming that
BTRFS_IOC_TREE_SEARCHreturns objectid's in sorted order, it would definitively be possible to produce line-by-line output), the code looks pretty elegant the way it is.
Quoted 5 lines
I still don't think it is wise to bloat things further just for printing nice tables. My impression is that "btrfs subvolume list" is human-readable enough without the '-t' flag, while the output with '-t' flag is much more machine-readable-friendly, and thus should have the highest possible performance. e.g.:
I disagree, the "-t" mode is for the human; the non '-t' mode would be for machine (if you take the space as separator and the first word as key, with the exception of the path which starts from the "path " word and ends to the end of line); unfortunately "top level" is an exception. Anyway btrfs is not very machine-friendly (sic).
Compare the two output below:
$ sudo btrfs sub list -a / ID 257 gen 44309 top level 5 path <FS_TREE>/debian ID 289 gen 17415 top level 257 path debian/var/lib/machines ID 298 gen 35434 top level 5 path <FS_TREE>/debian-i32 ID 299 gen 43961 top level 5 path <FS_TREE>/boot ID 300 gen 39452 top level 5 path <FS_TREE>/debian-jessie
$ sudo btrfs sub list -at / ID gen top level path -- --- --------- ---- 257 44310 5 <FS_TREE>/debian 289 17415 257 debian/var/lib/machines 298 35434 5 <FS_TREE>/debian-i32 299 43961 5 <FS_TREE>/boot 300 39452 5 <FS_TREE>/debian-jessie
I think that is easy to declare the latter more "human" friendly.
BTW with the use of the table_* function the output become:
$ sudo ./btrfs sub list -at / ID gen top level path === ===== ========= ======================= 257 44311 5 <FS_TREE>/debian 289 17415 257 debian/var/lib/machines 298 35434 5 <FS_TREE>/debian-i32 299 43961 5 <FS_TREE>/boot 300 39452 5 <FS_TREE>/debian-jessie
$ sudo ./btrfs sub list -aptcguqR / ID gen cgen parent top level parent_uuid received_uuid uuid path === ===== ===== ====== ========= =========== ============= ==================================== ======================= 257 44313 7 5 5 - - 840c86cf-e78b-d54a-ab38-66662858812d <FS_TREE>/debian 289 17415 17415 257 257 - - 8b857250-3a3e-754d-810e-57342bbb2f56 debian/var/lib/machines 298 35434 35399 5 5 - - 1f38049b-b153-d741-b903-d2de6fd7b3fd <FS_TREE>/debian-i32 299 43961 35512 5 5 - - f9d52b6b-a6d1-8c45-a6cd-ddb68cf58062 <FS_TREE>/boot 300 39452 37744 5 5 - - 026e44bd-66d4-e341-9a14-0124acf79793 <FS_TREE>/debian-jessie
I right aligned each field with the exception of the path (which is left aligned).
I already prepared the patch which convert "btrfs sub list -t" to use the table_* function. If you want I can send it to you to extend/replace your patch #4.
BR
G.Baroncelli
Quoted 11 lines
btrfs sub list -t / | (read th; while read $th ; do echo $gen; done) btrfs sub list -t | column -t
Again, this is just my opinion, being a "unix-purist". Maybe a good compromise would be to use a single "\t" instead of " " as column delimiter.
Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
Re: [PATCH 4/4] btrfs-progs: change -t option for subvolume list to print a simple space-separated table (making it machine-readable)
Quoted 11 lines · Goffredo Baroncelli
Hi Axel,
On 2015-10-05 17:04, Axel Burri wrote:
[...]Quoted 5 lines
I still don't think it is wise to bloat things further just for printing nice tables. My impression is that "btrfs subvolume list" is human-readable enough without the '-t' flag, while the output with '-t' flag is much more machine-readable-friendly, and thus should have the highest possible performance. e.g.:
I disagree, the "-t" mode is for the human; the non '-t' mode would be for machine (if you take the space as separator and the first word as key, with the exception of the path which starts from the "path " word and ends to the end of line); unfortunately "top level" is an exception. Anyway btrfs is not very machine-friendly (sic).
That's what my patches are all about in the first place, to make it more machine-friendly :)
Quoted 8 lines
Compare the two output below:
$ sudo btrfs sub list -a / ID 257 gen 44309 top level 5 path <FS_TREE>/debian ID 289 gen 17415 top level 257 path debian/var/lib/machines ID 298 gen 35434 top level 5 path <FS_TREE>/debian-i32 ID 299 gen 43961 top level 5 path <FS_TREE>/boot ID 300 gen 39452 top level 5 path <FS_TREE>/debian-jessie
"grep-friendly"
Quoted 11 lines
$ sudo btrfs sub list -at / ID gen top level path -- --- --------- ---- 257 44310 5 <FS_TREE>/debian 289 17415 257 debian/var/lib/machines 298 35434 5 <FS_TREE>/debian-i32 299 43961 5 <FS_TREE>/boot 300 39452 5 <FS_TREE>/debian-jessie
Quoted 1 line
I think that is easy to declare the latter more "human" friendly.
Well yes, but in some ways the latter is also more machine-friendly, as there is less data to pipe and a whitespace-separated list is much easier to parse (of course the same applies to your table implementation below).
Problems here are:
- "top level" (whitespace, addressed in [PATCH 4/4])
- timestamp (-s) "YYYY-MM-DD HH:MM:SS" (whitspace and no timezone, addressed in [PATCH 3/4])
- path can contain whitespace (not _that_ important as it's always printed last).
Quoted 21 lines
BTW with the use of the table_* function the output become:
$ sudo ./btrfs sub list -at / ID gen top level path === ===== ========= ======================= 257 44311 5 <FS_TREE>/debian 289 17415 257 debian/var/lib/machines 298 35434 5 <FS_TREE>/debian-i32 299 43961 5 <FS_TREE>/boot 300 39452 5 <FS_TREE>/debian-jessie$ sudo ./btrfs sub list -aptcguqR / ID gen cgen parent top level parent_uuid received_uuid uuid path === ===== ===== ====== ========= =========== ============= ==================================== ======================= 257 44313 7 5 5 - - 840c86cf-e78b-d54a-ab38-66662858812d <FS_TREE>/debian 289 17415 17415 257 257 - - 8b857250-3a3e-754d-810e-57342bbb2f56 debian/var/lib/machines 298 35434 35399 5 5 - - 1f38049b-b153-d741-b903-d2de6fd7b3fd <FS_TREE>/debian-i32 299 43961 35512 5 5 - - f9d52b6b-a6d1-8c45-a6cd-ddb68cf58062 <FS_TREE>/boot 300 39452 37744 5 5 - - 026e44bd-66d4-e341-9a14-0124acf79793 <FS_TREE>/debian-jessie
Quoted 2 lines
I right aligned each field with the exception of the path (which is left aligned).
I already prepared the patch which convert "btrfs sub list -t" to use the table_* function. If you want I can send it to you to extend/replace your patch #4.
Looks promising, although I'd still not recommend it because of the increased memory/cpu requirements.
btrfs machine readable output [was Re: btrfs patches]
In reply to a message not in the archiveHi Axel,
I add CC:linux-btrfs because I think that what you are saying is important and it was discussed in ML.
[we are talking about the Axel patches to "btrfs sub list" command]
Quoted 7 lines · Axel Burri
Hi Goffredo
Don't get me wrong, I don't want to blame you (or anyone), actually I'm only arguing what I think is best for btrfs. I started to write those patches because btrfs-scriptability is pretty bad (there is also "btrfs sub show" which has pretty un-parseable output"), and I think this is very important for the success of btrfs, and no-one seemed to address this.
In the past, when I developed the "btrfs fi usage/btrfs dev usage" I put a lot of effort to have an output easily machine readable: one data per line, key without space; I remember the battle to have in the key "_" instead of space :-) However other people changed that to a more (human) readable output.
May be that I was wrong; I don't know.
However for sure, if I look to other projects:
- systemd: it uses some btrfs capability, but it uses the ioctl directly.
- snapper: it uses ioctl directly
So I have to conclude that it is not common to use btrfs (as progs) directly. Few times I noticed somebodies are working on a libbtrfs. May be this is a better approach.
Quoted 9 lines
I know that nowadays people expect to get shiny output from command-line tools, but IMHO it is much more important to have consistent machine-readable output before even thinking of human readability (since there are so many unix commands to translate it, e.g. "columns"). Now this is sadly not the case with btrfs-progs, and it's hard to change it when people are used to it. Note that when writing the patches I was also thinking of introducing some "--machine-readable" option, but this seemed so wrong to me...
I think that "--machine-readable" (or similar) is a better approach: the output of the btrfs command in the past is changed even drastically (give a look to my work on the mkfs.btrfs); but we could force us to have an output "backward compatible" and machine (programmer) friendly if a switch like "--machine-readable" is used.
[...]
Quoted 4 lines
Regards,
- Axel
BR
Goffredo
Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5